-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathNIMClient.js
More file actions
77 lines (60 loc) · 2.15 KB
/
NIMClient.js
File metadata and controls
77 lines (60 loc) · 2.15 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
74
75
76
77
/**
适用对象:通用
作用:通过hook NIMClient获取App中的appkey
参考:
*/
var targetClass = "com.netease.nimlib.sdk.NIMClient";
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;
}
}
// 这里一般找不到
if (name === targetClass) {
console.log("got targetClass: ", targetClass);
}
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() {
var cls = Java.use(targetClass);
if (cls) {
console.log(cls);
cls.init.implementation = function (context, loginInfo, sDKOptions) {
console.log(targetClass + ".init() \n\tSDKOptions: ", sDKOptions.appKey.value, sDKOptions.sdkStorageRootPath.value);
printStack();
return this.init(context, loginInfo, sDKOptions);
}
}
}
// 打印堆栈
function printStack() {
console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()));
}
setImmediate(hook());