hook_constructors

hook linker中的init和init_array

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function hook_constructor() {
if (Process.pointerSize == 4) {
var linker = Process.findModuleByName("linker");
} else {
var linker = Process.findModuleByName("linker64");
}

var addr_call_function = null;
var addr_g_ld_debug_verbosity = null;
var addr_async_safe_format_log = null;
var linker_log = null;
console.log("linker:", linker.base);
if (linker) {
var symbols = linker.enumerateSymbols();
for (var i = 0; i < symbols.length; i++) {
var name = symbols[i].name;
// console.log(name)
if (name.indexOf("call_function") >= 0) {
addr_call_function = symbols[i].address;
} else if (name.indexOf("g_ld_debug_verbosity") >= 0) {
addr_g_ld_debug_verbosity = symbols[i].address;

ptr(addr_g_ld_debug_verbosity).writeInt(2);
} else if (
name.indexOf("async_safe_format_log") >= 0 &&
name.indexOf("va_list") >= 0
) {
addr_async_safe_format_log = symbols[i].address;
console.log("addr_async_safe_format_log", addr_async_safe_format_log);
} else if (
name.indexOf("linker") >= 0 &&
name.indexOf("log") >= 0 &&
name.indexOf("va_list") < 0 &&
name.indexOf("cpp") < 0 &&
name.indexOf("logger") < 0
) {
console.log("name:", name);
linker_log = symbols[i].address;
}
}
}
// if(addr_async_safe_format_log){
// Interceptor.attach(addr_async_safe_format_log,{
// onEnter: function(args){
// this.log_level = args[0];
// this.tag = ptr(args[1]).readCString()
// this.fmt = ptr(args[2]).readCString()
// // console.log("this.fmt",this.fmt)
// if(this.fmt.indexOf("c-tor") >= 0 && this.fmt.indexOf('Done') < 0){
// console.log("c-tor")
// console.log(this.tag)
// console.log(this.fmt)
// console.log(ptr(args[3]))
// this.function_type = ptr(args[4]).readCString(), // func_type
// console.log(this.function_type)
// // this.so_path = ptr(args[5]).readCString();
// // console.log(this.so_path)
// // var strs = new Array(); //定义一数组
// // strs = this.so_path.split("/"); //字符分割
// // this.so_name = strs.pop();
// // this.func_offset = ptr(args[4]).sub(Module.findBaseAddress(this.so_name))
// // console.log("func_type:", this.function_type,
// // '\nso_name:',this.so_name,
// // '\nso_path:',this.so_path,
// // '\nfunc_offset:',this.func_offset
// // );
// }
// },
// onLeave: function(retval){

// }
// })
// }
if (linker_log) {
Interceptor.attach(linker_log, {
onEnter: function (args) {
this.log_level = args[0];
this.fmt = ptr(args[1]).readCString();
this.tag = ptr(args[2]).readCString();
// console.log("this.tag",this.tag)
if (
this.fmt.indexOf("Calling") >= 0 &&
this.fmt.indexOf("for") >= 0 &&
this.tag.indexOf("DT_INIT_ARRAY") >= 0
) {
// console.log("c-tor")
console.log("this.tag", this.tag);
console.log("this.fmt", this.fmt);
console.log("this.path", ptr(args[5]).readCString());
console.log("size:", args[3]);
(this.array_addr = ptr(args[4])), // func_type
console.log("array addr:", this.array_addr);
// this.so_path = ptr(args[5]).readCString();
// console.log(this.so_path)
// var strs = new Array(); //定义一数组
// strs = this.so_path.split("/"); //字符分割
// this.so_name = strs.pop();
// this.func_offset = ptr(args[4]).sub(Module.findBaseAddress(this.so_name))
// console.log("func_type:", this.function_type,
// '\nso_name:',this.so_name,
// '\nso_path:',this.so_path,
// '\nfunc_offset:',this.func_offset
// );
var libDexHelperaddr = Process.findModuleByName("libDexHelper.so");
console.log("libDexHelperaddr:", libDexHelperaddr.base);
this.pid = Process.getCurrentThreadId();
Stalker.follow(this.pid, {
events: {
// 暂时不需要这些 events
call: false,
ret: false,
exec: false,

block: false,
compile: false,
},
onReceive: function (events) {},

transform: function (iterator) {
var instruction = iterator.next();
const startAddress = instruction.address;
// console.log("instruction:",instruction)
// 从ida里面 找到 Java_com_baidu_searchbox_NativeBds_dae1 函数的 代码 在 0xE84 和 0x126C 之间
var isModule =
startAddress.compare(libDexHelperaddr.base) >= 0 &&
startAddress.compare(libDexHelperaddr.base.add(0x102638)) < 0;
do {
if (isModule) {
console.log(
instruction.address.sub(libDexHelperaddr.base) + "\t:\t" + instruction

// if(instruction.)
);
}
iterator.keep();
} while ((instruction = iterator.next()) !== null);
},

onCallSummary: function (summary) {},
});
}
},
onLeave: function (retval) {},
});
}
}
function main() {
hook_constructor();
}
setImmediate(main);
JAVASCRIPT

hook_constructors
http://showfaker.top/2024/03/20/hook-constructors/
作者
ShowFaker
发布于
2024年3月20日
许可协议