Skip to content

Commit e5468a4

Browse files
authored
hook before init_array
1 parent 716e823 commit e5468a4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [`Memory scan`](#memory-scan)
1919
* [`Stalker`](#stalker)
2020
* [`Cpp Demangler`](#cpp-demangler)
21+
* [`Early hook`](#early-hook)
2122

2223
</details>
2324

@@ -2227,6 +2228,52 @@ TODO
22272228
<br>[⬆ Back to top](#table-of-contents)
22282229

22292230

2231+
#### Early hook
2232+
2233+
Set hooks before DT_INIT_ARRAY ( [source](https://cs.android.com/android/platform/superproject/+/master:bionic/linker/linker_soinfo.cpp;l=386;drc=android-8.0.0_r1?q=call_constructor&ss=android%2Fplatform%2Fsuperproject) )
2234+
2235+
```js
2236+
let base;
2237+
let do_dlopen = null;
2238+
let call_ctor = null;
2239+
const target_lib_name = 'targetlib.so';
2240+
2241+
Process.findModuleByName('linker64').enumerateSymbols().forEach(sym => {
2242+
if (sym.name.indexOf('do_dlopen') >= 0) {
2243+
do_dlopen = sym.address;
2244+
} else if (sym.name.indexOf('call_constructor') >= 0) {
2245+
call_ctor = sym.address;
2246+
}
2247+
})
2248+
2249+
Interceptor.attach(do_dlopen, function () {
2250+
var what = this.context['x0'].readUtf8String();
2251+
if (what.indexOf(target_lib_name) >= 0) {
2252+
Interceptor.attach(call_ctor, function () {
2253+
Interceptor.detachAll();
2254+
console.log('loading target');
2255+
const module = Process.findModuleByName(target_lib_name);
2256+
2257+
console.log(module.base);
2258+
base = module.base;
2259+
// DoStuff
2260+
})
2261+
}
2262+
})
2263+
```
2264+
2265+
2266+
Credit: [iGio90](https://github.com/iGio90)
2267+
2268+
2269+
<details>
2270+
<summary>Output example</summary>
2271+
TODO
2272+
</details>
2273+
2274+
<br>[⬆ Back to top](#table-of-contents)
2275+
2276+
22302277

22312278

22322279

0 commit comments

Comments
 (0)