├── .DS_Store ├── README.md ├── ThumbHooked.mp4 ├── jni ├── .DS_Store ├── Android.mk ├── Application.mk ├── InlineHook │ ├── .DS_Store │ ├── Android.mk │ ├── Ihook.c │ ├── Ihook.h │ ├── fixPCOpcode.c │ ├── fixPCOpcode.h │ ├── ihookstub.s │ └── ihookstubthumb.s └── Interface │ ├── .DS_Store │ ├── Android.mk │ └── InlineHook.cpp ├── libs └── armeabi-v7a │ └── libInlineThumbHook.so ├── notThumbHooked.mp4 ├── obj └── local │ └── armeabi-v7a │ ├── libIHook.a │ ├── libInlineArmHook.so │ ├── libInlineHook.so │ ├── libInlineThumbHook.so │ └── objs │ ├── IHook │ ├── IHook.o │ ├── IHook.o.d │ ├── fixPCOpcode.o │ ├── fixPCOpcode.o.d │ ├── ihookstub.o │ └── ihookstubthumb.o │ ├── InlineArmHook │ ├── InlineHook.o │ └── InlineHook.o.d │ ├── InlineHook │ ├── InlineHook.o │ └── InlineHook.o.d │ └── InlineThumbHook │ ├── InlineHook.o │ └── InlineHook.o.d ├── thumb-2-example.apk ├── thumb-2-example.zip ├── thumb-2-example ├── libnative-lib.idb └── libnative-lib.so ├── thumbhook.pdf └── todo.txt /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the example of my [Android Inline Hook Project](https://github.com/GToad/Android_Inline_Hook.git) in thumb mode. So I will only update that repo. 2 | 3 | The target APP is `thumb-2-example.apk` and our .so file has already been compiled in `/libs/armeabi-v7a/libInlineThumbHook.so`. 4 | 5 | In this APP, you should wait for more than 30 seconds and it will show `Enough. You Win!` in the middle of the screen. After the example `libInlineThumbHook.so` is effective, the register R0 will be set to 0x333 (>10) so you will get `Enough. You Win!` immediately. 6 | 7 | `notThumbHooked.mp4` shows the APP run in a normal environment. 8 | 9 | `ThumbHooked.mp4` shows the APP run in a hooked environment. 10 | 11 | The pictures of effect are showed below: 12 | 13 | ![](https://gtoad.github.io/img/in-post/post-android-native-hook-practice/notThumbHooked.png) 14 | ![](https://gtoad.github.io/img/in-post/post-android-native-hook-practice/ThumbHooked.png) 15 | 16 | # Android Inline Hook 17 | 18 | This project make an Android .so file that can automatically do some native hook works. 19 | 20 | It mainly use Android Inline Hook, not PLT Hook. 21 | 22 | If you can read Chinese or wanna see more picture, I've wrote some articles about this repo and the first one is the main article. `I highly recommend you to read the articles before reading the code.` These article will save you a lot of time, I promise. 23 | 24 | 1. [Android Inline Hook Practice](https://gtoad.github.io/2018/07/06/Android-Native-Hook-Practice/) 25 | 2. [Opcode Fix In Android Inline Hook](https://gtoad.github.io/2018/07/13/Android-Inline-Hook-Fix/) 26 | 3. [An Introduction to Android Native Hook](https://gtoad.github.io/2018/07/05/Android-Native-Hook/) 27 | 28 | # How To Use 29 | 30 | The only thing you have to change is the code in `InlineHook.cpp`. 31 | 32 | You can name the `__attribute__((constructor)) ModifyIBored()` function at your will and change the follow arg in it: 33 | 34 | 1. `pModuleBaseAddr` is the address of your target so. 35 | 2. `target_offset` is the offset of your hook point in the target so. 36 | 3. `is_target_thumb` shows the hook point's CPU mode. You can know this information in the work of reversing before the hook work. 37 | 38 | `EvilHookStubFunctionForIBored` function is the thing you really wanna do when the hook works. You can name at your will, but keep the arg `(pt_regs *regs)`. It brings you the power to control the registers, like set r0 to 0x333 : `regs->uregs[0]=0x333;`. 39 | 40 | After you finish the args above, just `ndk-build` and you will get your .so file. 41 | 42 | # Example 43 | 44 | I've make some examples in other repo, it includes code and the target APK file. 45 | 46 | 1. [thumb-2 example](https://github.com/GToad/Android_Inline_Hook_Thumb_Example.git) 47 | 2. [arm32 example](https://github.com/GToad/Android_Inline_Hook_Arm_Example.git) 48 | 49 | # Contact 50 | 51 | I believe that this project still has some problems. If you find some bugs or have some problems, you can send e-mail to `gtoad1994@aliyun.com`. I wish we can fix it together! 52 | 53 | # Reference 54 | 55 | [Game Security Lab of Tencent](http://gslab.qq.com/portal.php?mod=view&aid=168) 56 | 57 | [Ele7enxxh's Blog](http://ele7enxxh.com/Android-Arm-Inline-Hook.html) 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /ThumbHooked.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/ThumbHooked.mp4 -------------------------------------------------------------------------------- /jni/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/jni/.DS_Store -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | include $(call all-subdir-makefiles) -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi-v7a 2 | APP_STL := gnustl_static 3 | APP_CPPFLAGS += -fexceptions -------------------------------------------------------------------------------- /jni/InlineHook/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/jni/InlineHook/.DS_Store -------------------------------------------------------------------------------- /jni/InlineHook/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_CXXFLAGS += -g -O0 7 | LOCAL_ARM_MODE := arm 8 | LOCAL_MODULE := IHook 9 | LOCAL_SRC_FILES := IHook.c ihookstub.s ihookstubthumb.s fixPCOpcode.c 10 | LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog 11 | 12 | include $(BUILD_STATIC_LIBRARY) 13 | -------------------------------------------------------------------------------- /jni/InlineHook/Ihook.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/jni/InlineHook/Ihook.c -------------------------------------------------------------------------------- /jni/InlineHook/Ihook.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GToad/Android_Inline_Hook_Thumb_Example/84af85b113536d431b25110567f5784d750edd3b/jni/InlineHook/Ihook.h -------------------------------------------------------------------------------- /jni/InlineHook/fixPCOpcode.c: -------------------------------------------------------------------------------- 1 | #include "fixPCOpcode.h" 2 | 3 | //这里的代码建议看文章:《Android Inline Hook中的指令修复详解》(https://gtoad.github.io/2018/07/13/Android-Inline-Hook-Fix/) 4 | 5 | enum INSTRUCTION_TYPE { 6 | // B