forked from CreditTone/hooker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
str_mp4.js
154 lines (142 loc) · 5.89 KB
/
str_mp4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function methodInBeat(invokeId, timestamp, methodName, executor) {
var startTime = timestamp;
var androidLogClz = Java.use("android.util.Log");
var exceptionClz = Java.use("java.lang.Exception");
var threadClz = Java.use("java.lang.Thread");
var stackInfo = androidLogClz.getStackTraceString(exceptionClz.$new());
console.log("------------start:" + invokeId + ",objectHash:" + executor + ",thread:" + threadClz.currentThread().getId() + ",timestamp:" + startTime + "---------------");
console.log(methodName);
console.log(stackInfo.substring(20));
console.log("------------end:" + invokeId + ",usedtime:" + (new Date().getTime() - startTime) + "---------------\n");
};
//https://github.com/frida/frida/issues/503 bug补丁
function stringBuilderToStringPatch(stringBuilderObj) {
var str = '';
var length = stringBuilderObj.length();
for (var i = 0; i < length; i++) {
str += stringBuilderObj.charAt(i);
}
return str;
}
function getHead(str, len) {
if (str.length > len) {
return str.substring(0, len) + "...... length:" + str.length;
} else {
return str;
}
}
var containRegExps = new Array(RegExp(/mp4/))
var notContainRegExps = new Array(RegExp(/\.jpg$/))
function check(stringJavaObject) {
var str = stringJavaObject.toString();
if (! (str && str.match)) {
return false;
}
for (var i = 0; i < containRegExps.length; i++) {
if (!str.match(containRegExps[i])) {
return false;
}
}
for (var i = 0; i < notContainRegExps.length; i++) {
if (str.match(notContainRegExps[i])) {
return false;
}
}
return true;
}
Java.perform(function() {
var androidLogClz = Java.use("android.util.Log");
var exceptionClz = Java.use("java.lang.Exception");
var java_lang_StringBuilder_clz = Java.use('java.lang.StringBuilder');
var java_lang_StringBuilder_clz_toString_9ogt = java_lang_StringBuilder_clz.toString.overload();
var java_lang_StringBuilder_clz_substring = java_lang_StringBuilder_clz.substring.overload('int', 'int');
java_lang_StringBuilder_clz_toString_9ogt.implementation = function() {
var thErr = undefined;
var stringJavaObject = undefined;
try {
var startTime = new Date().getTime();
stringJavaObject = java_lang_StringBuilder_clz_toString_9ogt.call(this);
if (check(stringJavaObject)) {
var headTxt = getHead(stringJavaObject, 500);
var invokeId = Math.random().toString(36).slice( - 8);
var executor = this.hashCode();
methodInBeat(invokeId, startTime, "Detecting " + headTxt + " in stacks:", executor);
}
} catch(err) {
thErr = err;
} finally {
if (thErr) {
stringJavaObject = stringBuilderToStringPatch(this);
}
return stringJavaObject;
}
};
var java_lang_StringBuffer_clz = Java.use('java.lang.StringBuffer');
var java_lang_StringBuffer_clz_toString_9ogt = java_lang_StringBuffer_clz.toString.overload();
java_lang_StringBuffer_clz_toString_9ogt.implementation = function() {
var thErr = undefined;
var stringJavaObject = undefined;
try {
var startTime = new Date().getTime();
stringJavaObject = java_lang_StringBuffer_clz_toString_9ogt.call(this);
if (check(stringJavaObject)) {
var headTxt = getHead(stringJavaObject, 500);
var invokeId = Math.random().toString(36).slice( - 8);
var executor = this.hashCode();
methodInBeat(invokeId, startTime, "Detecting " + headTxt + " in stacks:", executor);
}
} catch(err) {
thErr = err;
} finally {
if (thErr) {
stringJavaObject = stringBuilderToStringPatch(this);
}
return stringJavaObject;
}
};
var java_lang_String_clz = Java.use('java.lang.String');
var java_lang_String_clz_init_a8vt = java_lang_String_clz.$init.overload('[B', 'int', 'int', 'int');
java_lang_String_clz_init_a8vt.implementation = function(v0, v1, v2, v3) {
var stringJavaObject = undefined;
var thErr = undefined;
try {
var startTime = new Date().getTime();
ret = java_lang_String_clz_init_a8vt.call(this, v0, v1, v2, v3);
if (check(stringJavaObject)) {
var headTxt = getHead(stringJavaObject, 500);
var invokeId = Math.random().toString(36).slice( - 8);
var executor = this.hashCode();
methodInBeat(invokeId, startTime, "Detecting " + headTxt + " in stacks:", executor);
}
} catch(err) {
thErr = err;
} finally {
if (thErr) {
throw exceptionClz.$new('' + thErr);
}
return stringJavaObject;
}
};
var java_lang_String_clz_init_1fva = java_lang_String_clz.$init.overload('[B', 'int', 'int', 'java.nio.charset.Charset');
java_lang_String_clz_init_1fva.implementation = function(v0, v1, v2, v3) {
var stringJavaObject = undefined;
var thErr = undefined;
try {
var startTime = new Date().getTime();
stringJavaObject = java_lang_String_clz_init_1fva.call(this, v0, v1, v2, v3);
if (check(stringJavaObject)) {
var headTxt = getHead(stringJavaObject, 500);
var invokeId = Math.random().toString(36).slice( - 8);
var executor = this.hashCode();
methodInBeat(invokeId, startTime, "Detecting " + headTxt + " in stacks:", executor);
}
} catch(err) {
thErr = err;
} finally {
if (thErr) {
throw exceptionClz.$new('' + thErr);
}
return stringJavaObject;
}
};
});