-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhook_overloads.js
29 lines (25 loc) · 1.01 KB
/
hook_overloads.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
function hookOverloads(className, func) {
var clazz = Java.use(className);
var overloads = clazz[func].overloads;
for (var i in overloads) {
if (overloads[i].hasOwnProperty('argumentTypes') || overloads[i]['argumentTypes'] != undefined) {
var parameters = [];
var curArgumentTypes = overloads[i].argumentTypes, args = [], argLog = '[';
for (var j in curArgumentTypes) {
var cName = curArgumentTypes[j].className;
parameters.push(cName);
argLog += "'(" + cName + ") ' + v" + j + ",";
args.push('v' + j);
}
argLog += ']';
var script = "var ret = this." + func + '(' + args.join(',') + ") || '';\n"
+ "console.log(JSON.stringify(" + argLog + "));\n"
+ "return ret;"
args.push(script);
clazz[func].overload.apply(this, parameters).implementation = Function.apply(null, args);
}
}
}
Java.perform(function() {
hookOverloads('java.lang.StringBuilder', '$init');
})