注入一台ArmV8架构的5.1版本手机,替换eglswapbuffer函数,来获取eglswapbuffer的调用次数。
完整代码见github
注入系列笔记:
ELF格式分析
so文件加载流程
Inject和Hook
使用
准备:
- 一台root的android设备
 - ndk编译环境
 
分别开2个终端来查看日志:
- adb logcat | grep INJECT
 - adb logcat | grep ELFHooker
如果其他日志太多了可以用adb logcat -c来清理一下日志 
然后在新的终端中执行:
- git clone
 - cd jni
 - ndk-build
 - cd ../libs/arm64-v8a/ (or ../libs/armeabi// if your device is 32-bit)
 - adb push .* /data/local/tmp
 - adb shell
 - su
 - cd /data/local/tmp
 - chmod 755 inject
 - chmod 755 libelfHooker.so
 
找到/system/bin/surfaceflinger这个进程的pid:
- ps | grep surfaceflinger
 - ./inject -p 
-l /data/local/tmp/libelfHooker.so 
查看日志输出:

 
参考
Lody’s elfHook
 Android中的so注入(inject)和挂钩(hook) - For both x86 and arm
