-
Notifications
You must be signed in to change notification settings - Fork 206
/
hook_init_array.js
59 lines (50 loc) · 1.92 KB
/
hook_init_array.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function hook_init_array() {
//console.log("hook_constructor",Process.pointerSize);
if (Process.pointerSize == 4) {
var linker = Process.findModuleByName("linker");
}else if (Process.pointerSize == 8) {
var linker = Process.findModuleByName("linker64");
}
var addr_call_array = null;
if (linker) {
var symbols = linker.enumerateSymbols();
for (var i = 0; i < symbols.length; i++) {
var name = symbols[i].name;
if (name.indexOf("call_array") >= 0) {
addr_call_array = symbols[i].address;
}
}
}
if (addr_call_array) {
Interceptor.attach(addr_call_array, {
onEnter: function (args) {
this.type = ptr(args[0]).readCString();
//console.log(this.type,args[1],args[2],args[3])
if (this.type == "DT_INIT_ARRAY") {
this.count = args[2];
//this.addrArray = new Array(this.count);
this.path = ptr(args[3]).readCString();
var strs = new Array(); //定义一数组
strs = this.path.split("/"); //字符分割
this.filename = strs.pop();
if(this.count > 0){
console.log("path : ", this.path);
console.log("filename : ", this.filename);
}
for (var i = 0; i < this.count; i++) {
console.log("offset : init_array["+i+"] = ", ptr(args[1]).add(Process.pointerSize*i).readPointer().sub(Module.findBaseAddress(this.filename)));
//插入hook init_array代码
}
}
},
onLeave: function (retval) {
}
});
}
}
function main() {
if (Java.androidVersion == "8.1.0") {
hook_init_array();
}
}
setImmediate(main);