-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrace_native.js
42 lines (38 loc) · 1.31 KB
/
trace_native.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
function processJniOnLoad(libraryName) {
const funcSym = "JNI_OnLoad";
const funcPtr = Module.findExportByName(libraryName, funcSym);
console.log("[+] Hooking " + funcSym + "() @ " + funcPtr + "...");
// jint JNI_OnLoad(JavaVM *vm, void *reserved);
var funcHook = Interceptor.attach(funcPtr, {
onEnter: function (args) {
const vm = args[0];
const reserved = args[1];
console.log("[+] " + funcSym + "(" + vm + ", " + reserved + ") called");
},
onLeave: function (retval) {
console.log("[+]\t= " + retval);
}
});
}
function waitForLibLoading(libraryName) {
var isLibLoaded = false;
Interceptor.attach(Module.findExportByName(null, "android_dlopen_ext"), {
onEnter: function (args) {
var libraryPath = Memory.readCString(args[0]);
if (libraryPath.includes(libraryName)) {
console.log("[+] Loading library " + libraryPath + "...");
isLibLoaded = true;
}
},
onLeave: function (args) {
if (isLibLoaded) {
processJniOnLoad(libraryName);
isLibLoaded = false;
}
}
});
}
Java.perform(function() {
const libraryName = "libwhatsapp.so";
waitForLibLoading(libraryName);
});