-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (70 loc) · 3.17 KB
/
script.js
File metadata and controls
73 lines (70 loc) · 3.17 KB
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
function HookingOptimizedVersion(classesToInspect){
// sort classesToInspect
classesToInspect.sort();
// var count_classes_total = classesToInspect.length;
// console.log("Total classes loaded: " + count_classes_total);
// // get package name
// var packageName = Java.use("android.app.ActivityThread").currentApplication().getApplicationContext().getPackageName();
// console.log("Package name: " + packageName);
// console.log("Total classes to inspect: " + classesToInspect.length);
classesToInspect.forEach(function(className){
// create a wrapper
try{
var hook = Java.use(className);
var methods = hook.class.getDeclaredMethods();
}
catch(e){
// console.log("Error in class : " +className + "=> " + e);
return;
}
// get all methods's name and remove duplicates (because we will use overloding to instrument methods having same name).
var parseMethods = [];
methods.forEach(function(method){
var method_name = method.getName();
if (!parseMethods.includes(method_name)){
parseMethods.push(method_name);
}
});
// instrument all methods one by one
parseMethods.forEach(function(method){
// validate if method is not undefined, otherwise frida gives error
if (typeof hook[method] != "undefined"){
// get all overloaded methods
var overloadMethods = hook[method].overloads;
var method_number = 1;
overloadMethods.forEach(function(overload){
if (method_number == 1){
var method_name = className + "." + method;
}
else{
var method_name = className + "." + method + "_" + method_number.toString();
}
send("methods " + method_name);
overload.implementation = function(...args){
// console.log("Entered: " + method_name);
send("enter " + method_name);
var ret = overload.call(this, ...args);
send("exit " + method_name);
// console.log("Exited: " + method_name);
return ret;
}
method_number += 1;
});
}
});
});
}
var Main = function () {
var data;
send("sendClass", ["hello"]);
recv('recvClass', function (value) {
data = value.payload;
// console.log('received bytes from python:', data, 'size:', data.length);
// console.log('..........received total classes from python:', data.length);
}).wait(); // block until python respond
let arr2 = data;
let count = data.length;
send("number " + (count).toString());
HookingOptimizedVersion(arr2);
};
Java.perform(Main);