-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathloadClass.js
More file actions
64 lines (48 loc) · 1.65 KB
/
loadClass.js
File metadata and controls
64 lines (48 loc) · 1.65 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
/**
适用对象:通用
作用:获取动态加载的类(loadClass)
参考:
*/
function hook() {
Java.perform(function () {
var dexclassLoader = Java.use("dalvik.system.DexClassLoader");
dexclassLoader.loadClass.overload('java.lang.String').implementation = function (name) {
var result = this.loadClass(name);
console.log(name);
// APP自己的Application时,想要hook的类一定是加载了的,否则时机过早会出现类找不到的情况。
if (name.indexOf("Application") != -1 && name != "android.app.Application") {
var application = Java.use(name);
console.log("application:" + application);
application.onCreate.implementation = function () {
//hookTargetClass(); //二选一均可
var ret = this.onCreate();
return ret;
}
}
return result;
}
var application = Java.use('android.app.Application');
console.log("application:" + application);
application.attach.overload('android.content.Context').implementation = function (context) {
console.log("application attach called");
var result = this.attach(context);
hookTargetClass();
return result;
}
application.onCreate.implementation = function () {
console.log("application onCreate called");
hookTargetClass(); //二选一均可
var result = this.onCreate();
return result;
}
});
}
function hookTargetClass() {
}
// 打印堆栈
function printStack() {
Java.perform(function () {
console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()));
});
}
setImmediate(hook());