├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── cpp
│ │ │ ├── Hook
│ │ │ │ ├── Readme.md
│ │ │ │ ├── LogHex.h
│ │ │ │ ├── instruction
│ │ │ │ │ ├── MipsInstruction.cpp
│ │ │ │ │ ├── Mips64Instruction.cpp
│ │ │ │ │ ├── MipsInstruction.h
│ │ │ │ │ ├── Mips64Instruction.h
│ │ │ │ │ ├── Arm64Instruction.h
│ │ │ │ │ ├── Instruction.h
│ │ │ │ │ ├── Instruction.cpp
│ │ │ │ │ ├── ArmInstruction.h
│ │ │ │ │ ├── IntelDisasm.h
│ │ │ │ │ ├── ArmInstruction.cpp
│ │ │ │ │ ├── ThumbInstruction.h
│ │ │ │ │ ├── IntelInstruction.cpp
│ │ │ │ │ ├── IntelInstruction.h
│ │ │ │ │ ├── ThumbInstruction.cpp
│ │ │ │ │ ├── IntelDisasm.cpp
│ │ │ │ │ └── Arm64Instruction.cpp
│ │ │ │ ├── Helper.h
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── HookHelper.h
│ │ │ │ ├── LogHex.cpp
│ │ │ │ ├── Helper.cpp
│ │ │ │ ├── HookInfo.h
│ │ │ │ ├── main.cpp
│ │ │ │ └── HookHelper.cpp
│ │ │ └── jnihook
│ │ │ │ ├── fake_dlfcn.h
│ │ │ │ ├── VM.h
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── Main.cpp
│ │ │ │ ├── fake_dlfcn.cpp
│ │ │ │ ├── JniHook.h
│ │ │ │ └── JNIInterface.h
│ │ ├── java
│ │ │ └── xiaobai
│ │ │ │ └── com
│ │ │ │ └── jnihook
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── xiaobai
│ │ │ └── com
│ │ │ └── jnihook
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── xiaobai
│ │ └── com
│ │ └── jnihook
│ │ └── ExampleInstrumentedTest.java
├── CMakeLists.txt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── test.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── dictionaries
│ └── xiaobaiyey.xml
├── runConfigurations.xml
├── gradle.xml
├── codeStyles
│ └── Project.xml
└── misc.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── readme.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/test.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | jnihook
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/dictionaries/xiaobaiyey.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiaobaiyey/jnihook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/Readme.md:
--------------------------------------------------------------------------------
1 | ### 模块说明
2 | hook 方案来自F8的hook: (https://github.com/F8LEFT/FAInHook)[https://github.com/F8LEFT/FAInHook]
3 | Arm64hook 方案来自:(https://github.com/Rprop/And64InlineHook)[https://github.com/Rprop/And64InlineHook]
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.4.1)
7 | ADD_SUBDIRECTORY(src/main/cpp/jnihook)
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/cpp/jnihook/fake_dlfcn.h:
--------------------------------------------------------------------------------
1 | #ifndef DEXPOSED_DLFCN_H
2 | #define DEXPOSED_DLFCN_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | extern "C" {
9 |
10 | void *fake_dlopen(const char *libpath, int flags);
11 | void *fake_dlsym(void *handle, const char *name);
12 |
13 | };
14 | #endif //DEXPOSED_DLFCN_H
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/LogHex.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | class LogHex {
6 | public:
7 | static void PrintHex(const void *vdata, size_t size, const char *mark);
8 |
9 | static void PrintHexEx(const void *vdata, size_t size, size_t stride, const char *mark);
10 |
11 | static void DumpHex(const void *vdata, size_t size);
12 | };
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/xiaobai/com/jnihook/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package xiaobai.com.jnihook;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/instruction/MipsInstruction.cpp:
--------------------------------------------------------------------------------
1 | //===------------------------------------------------------------*- C++ -*-===//
2 | //
3 | // Created by F8LEFT on 2017/6/19.
4 | // Copyright (c) 2017. All rights reserved.
5 | //===----------------------------------------------------------------------===//
6 | //
7 | //===----------------------------------------------------------------------===//
8 |
9 |
10 | #include "MipsInstruction.h"
11 |
12 | bool MipsInstruction::createStub(HookInfo *info) {
13 | return false;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/instruction/Mips64Instruction.cpp:
--------------------------------------------------------------------------------
1 | //===------------------------------------------------------------*- C++ -*-===//
2 | //
3 | // Created by F8LEFT on 2017/6/19.
4 | // Copyright (c) 2017. All rights reserved.
5 | //===----------------------------------------------------------------------===//
6 | //
7 | //===----------------------------------------------------------------------===//
8 |
9 |
10 | #include "Mips64Instruction.h"
11 |
12 | bool Mips64Instruction::createStub(HookInfo *info) {
13 | return false;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/xiaobai/com/jnihook/MainActivity.java:
--------------------------------------------------------------------------------
1 | package xiaobai.com.jnihook;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | public class MainActivity extends AppCompatActivity {
8 |
9 | // Used to load the 'native-lib' library on application startup.
10 | static {
11 | System.loadLibrary("jnihook");
12 | }
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 |
19 | // Example of a call to a native method
20 | TextView tv = (TextView) findViewById(R.id.sample_text);
21 | tv.setText("hi");
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/instruction/MipsInstruction.h:
--------------------------------------------------------------------------------
1 | //===------------------------------------------------------------*- C++ -*-===//
2 | //
3 | // Created by F8LEFT on 2017/6/19.
4 | // Copyright (c) 2017. All rights reserved.
5 | //===----------------------------------------------------------------------===//
6 | // Instruction helper for mips
7 | //===----------------------------------------------------------------------===//
8 |
9 |
10 | #ifndef FAINHOOK_MIPSINSTRUCTION_H
11 | #define FAINHOOK_MIPSINSTRUCTION_H
12 |
13 | #include "Instruction.h"
14 |
15 | class MipsInstruction : public Instruction {
16 | public:
17 | ~MipsInstruction() {}
18 |
19 | bool createStub(HookInfo *info);
20 | };
21 |
22 |
23 | #endif //FAINHOOK_MIPSINSTRUCTION_H
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/instruction/Mips64Instruction.h:
--------------------------------------------------------------------------------
1 | //===------------------------------------------------------------*- C++ -*-===//
2 | //
3 | // Created by F8LEFT on 2017/6/19.
4 | // Copyright (c) 2017. All rights reserved.
5 | //===----------------------------------------------------------------------===//
6 | // Instruction Helper for mips64
7 | //===----------------------------------------------------------------------===//
8 |
9 |
10 | #ifndef FAINHOOK_MIPS64INSTRUCTION_H
11 | #define FAINHOOK_MIPS64INSTRUCTION_H
12 |
13 | #include "Instruction.h"
14 |
15 | class Mips64Instruction : public Instruction {
16 | public:
17 | ~Mips64Instruction() {}
18 |
19 | bool createStub(HookInfo *info);
20 | };
21 |
22 |
23 | #endif //FAINHOOK_MIPS64INSTRUCTION_H
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/xiaobai/com/jnihook/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package xiaobai.com.jnihook;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("xiaobai.com.jnihook", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/Helper.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @ name unpacker
3 | * @ author xiaobaiyey
4 | * @ email xiaobaiyey@outlook.com
5 | * @ time 2018/9/5 上午4:30
6 | * @ class this code copy from FAinline hook so just for study
7 | */
8 |
9 | #ifndef UNPACKER_HELPER_H
10 | #define UNPACKER_HELPER_H
11 |
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | class Helper {
19 | public:
20 | static bool isFunctionAddr(void *addr);
21 |
22 | /* remove write protect*/
23 | static bool unProtectMemory(void *addr, uint32_t size);
24 |
25 | /* add write protect*/
26 | static bool protectMemory(void *addr, uint32_t size);
27 |
28 | /* get a executable memory*/
29 | static void *createExecMemory(uint32_t size);
30 |
31 | Helper();
32 |
33 | ~Helper();
34 |
35 | private:
36 | std::vector alloc_memory_page_;
37 | void *current_page = nullptr;
38 | uint32_t page_ptr_ = 0;
39 |
40 | static uint32_t page_size;
41 | };
42 |
43 |
44 | #endif //UNPACKER_HELPER_H
45 |
--------------------------------------------------------------------------------
/app/src/main/cpp/jnihook/VM.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @ name jnihook
3 | * @ author xiaobaiyey
4 | * @ email xiaobaiyey@outlook.com
5 | * @ time 2018/10/31 11:16 AM
6 | * @ class describe
7 | */
8 |
9 | #ifndef JNIHOOK_VM_H
10 | #define JNIHOOK_VM_H
11 |
12 | #include
13 |
14 | class VM {
15 | public:
16 | static VM *getInstance();
17 |
18 |
19 | void hookLoadNativeLibary(void *newFunPtr, bool beforecall);
20 |
21 | const char *getClasstName(jclass clazz);
22 |
23 | const char *getObjectName(jobject object);
24 |
25 | /**
26 | * you must delete return value
27 | */
28 | char *getMethodName(jmethodID jmethodID1);
29 |
30 | /**
31 | * you must delete return value
32 | */
33 | char *getFiledName(jfieldID jfieldID1);
34 |
35 | void closeOptClass();
36 |
37 | void hookDexFileParse(void *newFunPtr, bool beforecall);
38 |
39 | public:
40 |
41 |
42 | private:
43 | VM();
44 |
45 | int getSdkVersion();
46 |
47 | void *Current();
48 |
49 | private:
50 | int sdk_version;
51 | void *vm_handle;
52 |
53 |
54 | };
55 |
56 |
57 | #endif //JNIHOOK_VM_H
58 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(ProjectName Hook)
2 |
3 | if (ANDROID_ABI MATCHES "armeabi(-v7a)?")
4 | set(INSTRUCTION instruction/Instruction.cpp
5 | instruction/ThumbInstruction.cpp
6 | instruction/ArmInstruction.cpp)
7 | elseif (ANDROID_ABI STREQUAL "arm64-v8a")
8 | set(INSTRUCTION instruction/Instruction.cpp
9 | instruction/Arm64Instruction.cpp)
10 | elseif (ANDROID_ABI MATCHES "x86(_64)?")
11 |
12 | set(INSTRUCTION instruction/Instruction.cpp
13 | instruction/IntelInstruction.cpp
14 | instruction/IntelDisasm.cpp)
15 | elseif (ANDROID_ABI STREQUAL "mips")
16 | set(INSTRUCTION instruction/Instruction.cpp
17 | instruction/MipsInstruction.cpp)
18 | elseif (ANDROID_ABI STREQUAL "mips64")
19 | set(INSTRUCTION instruction/Instruction.cpp
20 | instruction/Mips64Instruction.cpp)
21 | endif ()
22 |
23 | set(HOOKSRC HookHelper.cpp Helper.cpp)
24 |
25 | add_library(hooktest SHARED ${HOOKSRC} ${INSTRUCTION})
26 |
27 | #if(CMAKE_BUILD_TYPE MATCHES "Debug")
28 | # set(FA_EXTLIB log)
29 | #endif()
30 |
31 |
32 | #添加系统库文件
33 | find_library(log-lib
34 | log
35 | )
36 | find_library(dl-lib
37 | dl
38 | )
39 |
40 |
41 | target_link_libraries(hooktest
42 |
43 | ${log-lib}
44 | ${dl-lib}
45 | )
46 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "xiaobai.com.jnihook"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | externalNativeBuild {
13 | cmake {
14 | cppFlags "-std=c++11 -Wno-error=format-security"
15 | abiFilters "armeabi-v7a"
16 | }
17 | }
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | externalNativeBuild {
26 | cmake {
27 | path "CMakeLists.txt"
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | implementation 'com.android.support:appcompat-v7:28.0.0'
35 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
36 | testImplementation 'junit:junit:4.12'
37 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
38 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/instruction/Arm64Instruction.h:
--------------------------------------------------------------------------------
1 | //===------------------------------------------------------------*- C++ -*-===//
2 | //
3 | // Created by F8LEFT on 2017/6/19.
4 | // Copyright (c) 2017. All rights reserved.
5 | //===----------------------------------------------------------------------===//
6 | // instruction helper for arm64
7 | //===----------------------------------------------------------------------===//
8 |
9 |
10 | #ifndef FAINHOOK_ARM64INSTRUCTION_H
11 | #define FAINHOOK_ARM64INSTRUCTION_H
12 |
13 | #include "Instruction.h"
14 | #include
15 | #include
16 | #include
17 |
18 | #define FLOG_TAG "ARM64"
19 |
20 | #include
21 |
22 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, FLOG_TAG, __VA_ARGS__)
23 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, FLOG_TAG, __VA_ARGS__)
24 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, FLOG_TAG, __VA_ARGS__)
25 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, FLOG_TAG, __VA_ARGS__)
26 | #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, FLOG_TAG, __VA_ARGS__)
27 | #define A64_MAX_BACKUPS 256
28 |
29 | class Arm64Instruction : public Instruction {
30 | public:
31 | ~Arm64Instruction() {}
32 |
33 | bool createStub(HookInfo *info);
34 |
35 | bool createCallOriginalStub(HookInfo *info);
36 |
37 | private:
38 |
39 | bool repairCallOriginIns(HookInfo *info, uint8_t repair[], uint32_t &repairLen);
40 |
41 |
42 | };
43 |
44 |
45 | #endif //FAINHOOK_ARM64INSTRUCTION_H
46 |
--------------------------------------------------------------------------------
/app/src/main/cpp/jnihook/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 |
4 | # 添加hook库支持
5 | if (ANDROID_ABI MATCHES "armeabi(-v7a)?")
6 | set(INSTRUCTION ./../Hook/instruction/Instruction.cpp
7 | ./../Hook/instruction/ThumbInstruction.cpp
8 | ./../Hook/instruction/ArmInstruction.cpp)
9 | elseif (ANDROID_ABI STREQUAL "arm64-v8a")
10 | set(INSTRUCTION ./../Hook/instruction/Instruction.cpp
11 | ./../Hook/instruction/Arm64Instruction.cpp)
12 | elseif (ANDROID_ABI MATCHES "x86(_64)?")
13 |
14 | set(INSTRUCTION ./../Hook/instruction/Instruction.cpp
15 | ./../Hook/instruction/IntelInstruction.cpp
16 | ./../Hook/instruction/IntelDisasm.cpp)
17 | elseif (ANDROID_ABI STREQUAL "mips")
18 | set(INSTRUCTION ./../Hook/instruction/Instruction.cpp
19 | ./../Hook/instruction/MipsInstruction.cpp)
20 | elseif (ANDROID_ABI STREQUAL "mips64")
21 | set(INSTRUCTION ./../Hook/instruction/Instruction.cpp
22 | ./../Hook/instruction/Mips64Instruction.cpp)
23 | endif ()
24 | #添加hook库头文件支持
25 | include_directories(./../Hook)
26 |
27 | set(HOOKSRC ./../Hook/Helper.cpp
28 | ./../Hook/HookHelper.cpp
29 | ${INSTRUCTION})
30 |
31 |
32 | set(JNISRC JniHook.cpp main.cpp fake_dlfcn.cpp VM.cpp)
33 |
34 | add_library(jnihook
35 | SHARED
36 | ${HOOKSRC}
37 | ${JNISRC}
38 | )
39 | #添加系统库文件
40 | find_library(log-lib
41 | log
42 | )
43 | find_library(z-lib
44 | z
45 | )
46 | #链接静态库
47 |
48 | #生成文件
49 | target_link_libraries(jnihook
50 | ${log-lib}
51 | ${z-lib}
52 | )
53 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Hook/HookHelper.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @ name unpacker
3 | * @ author xiaobaiyey
4 | * @ email xiaobaiyey@outlook.com
5 | * @ time 2018/9/5 上午10:03
6 | * @ class describe
7 | */
8 |
9 | #ifndef UNPACKER_HOOKHELPER_H
10 | #define UNPACKER_HOOKHELPER_H
11 |
12 | #include