Frida so层中的hook
前言
so 中会接触到的东西:系统库函数、加密算法、jni 调用、系统调用、自定义算法
如何 hook
so hook 只需要得到一个地址,有函数地址就能 hook 与主动调用,与 java 层的 hook 一致。
得到函数地址的方式
- 通过 frida 提供的 api 来得到,该函数必须有符号的才可以
- 通过计算得到地址:so 基址+函数在 so 中的偏移[+1]
演示代码如下
const moduleName = 'libnative-lib.so'
let baseAddr = Module.findBaseAddress(moduleName)
let sub_99C0 = baseAddr.add(0x99c0 + 1)
Interceptor.attach(funcPtr, {
onEnter: function (args) {
// ...
},
onLeave: function (retval) {
// ...
},
})
API
枚举导入表
const improts = Module.enumerateImports('libencryptlib.so')
for (const iterator of improts) {
console.log(JSON.stringify(iterator))
// {"type":"function","name":"__cxa_atexit","module":"/apex/com.android.runtime/lib64/bionic/libc.so","address":"0x778957bd34"}
}
枚举导出表
const exports = Module.enumerateExports('libencryptlib.so')
for (const iterator of exports) {
console.log(JSON.stringify(iterator))
// {"type":"letiable","name":"_ZTSx","address":"0x74d594b1c0"}
}