我正在构建一个需要修改某些仿生方法(例如 getaddrinfo、__android_print)行为的项目。我已经能够使用独立编译器或使用 Cmake 将其直接包含在 Apk 中来创建挂钩库。我已经能够使用 setprop wrap.com.foo.bar 和 LD_PRELOAD 预加载共享库,它正在工作并且我得到了我想要的结果。但是,我想以编程方式预加载挂钩库,因此每次重新启动设备后,我都不需要执行 LD_PRELOAD(又名禁用 SELinux、root 设备、setprop)的特定步骤。
我尝试使用
// MainActivity
companion object {
System.load("/data/data/com.foo.bar/lib/libhookedmethod.so")
}
但我没有看到该方法被替换。
作为参考,钩子方法相当简单。这是一个极端的简化:
int __android_print(varargs a) {
int realmethod(...);
realmethod = dlsym("__android_print");
doStuff();
int res = realmethod(a) ;
return res;
}
同样,编译和使用 LD_PRELOAD 有效,但我想在不使用 LD_PRELOAD 的情况下实现它......任何有帮助!提前致谢