├── lib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── guolei
│ │ │ └── lib
│ │ │ └── pcompat
│ │ │ ├── PCompat.java
│ │ │ └── ReflectHelper.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── guolei
│ │ │ └── lib
│ │ │ └── pcompat
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── guolei
│ │ └── lib
│ │ └── pcompat
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── lib_method_1
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── guolei
│ │ │ └── support_p_java
│ │ │ └── PCompat.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── guolei
│ │ │ └── support_p_java
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── guolei
│ │ └── support_p_java
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── lib_method_2
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ ├── jniLibs
│ │ │ ├── x86
│ │ │ │ └── libvHook.so
│ │ │ ├── armeabi
│ │ │ │ └── libvHook.so
│ │ │ └── armeabi-v7a
│ │ │ │ └── libvHook.so
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── guolei
│ │ │ │ └── support_p_native
│ │ │ │ └── PCompat.java
│ │ └── cpp
│ │ │ ├── v_hook.h
│ │ │ └── native.cpp
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── guolei
│ │ │ └── support_p_native
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── guolei
│ │ └── support_p_native
│ │ └── ExampleInstrumentedTest.java
├── CMakeLists.txt
├── proguard-rules.pro
└── build.gradle
├── 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
│ │ ├── jniLibs
│ │ │ ├── x86
│ │ │ │ ├── libtest2.so
│ │ │ │ └── libsubstrate.so
│ │ │ └── armeabi-v7a
│ │ │ │ ├── libtest2.so
│ │ │ │ └── libsubstrate.so
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── support_p
│ │ │ │ ├── ReflectionHelper.java
│ │ │ │ └── MainActivity.java
│ │ └── cpp
│ │ │ ├── native-lib.cpp
│ │ │ └── substrate.h
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── support_p
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── support_p
│ │ └── ExampleInstrumentedTest.java
├── CMakeLists.txt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── art
├── diff_main_c.png
├── toclass_符号.png
├── diff_fake_dlfcn.png
├── setclassloader_符号.png
├── create_from_artmethod.png
├── class_getdeclaredfield.png
└── GetDeclaredMethodInternal.png
├── .gitmodules
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── caches
│ └── build_file_checksums.ser
├── markdown-navigator
│ └── profiles_settings.xml
├── vcs.xml
├── runConfigurations.xml
├── checkstyle-idea.xml
├── gradle.xml
├── misc.xml
├── codeStyles
│ └── Project.xml
└── markdown-navigator.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.MD
└── gradlew
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib_method_1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib_method_2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .externalNativeBuild/
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
3 | //':lib_method_1', ':lib_method_2',
4 |
--------------------------------------------------------------------------------
/art/diff_main_c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/diff_main_c.png
--------------------------------------------------------------------------------
/art/toclass_符号.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/toclass_符号.png
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib
3 |
4 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "Native_Hook"]
2 | path = Native_Hook
3 | url = https://github.com/Guolei1130/Native_Hook
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | support_p
3 |
4 |
--------------------------------------------------------------------------------
/art/diff_fake_dlfcn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/diff_fake_dlfcn.png
--------------------------------------------------------------------------------
/art/setclassloader_符号.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/setclassloader_符号.png
--------------------------------------------------------------------------------
/art/create_from_artmethod.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/create_from_artmethod.png
--------------------------------------------------------------------------------
/lib_method_1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib_method_1
3 |
4 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib_method_2
3 |
4 |
--------------------------------------------------------------------------------
/art/class_getdeclaredfield.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/class_getdeclaredfield.png
--------------------------------------------------------------------------------
/art/GetDeclaredMethodInternal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/art/GetDeclaredMethodInternal.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libtest2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/x86/libtest2.so
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libsubstrate.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/x86/libsubstrate.so
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libtest2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/armeabi-v7a/libtest2.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib_method_1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/jniLibs/x86/libvHook.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/x86/libvHook.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libsubstrate.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/jniLibs/armeabi-v7a/libsubstrate.so
--------------------------------------------------------------------------------
/lib_method_2/src/main/jniLibs/armeabi/libvHook.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/armeabi/libvHook.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/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/Guolei1130/android_p_no_sdkapi_support/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/Guolei1130/android_p_no_sdkapi_support/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/Guolei1130/android_p_no_sdkapi_support/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/Guolei1130/android_p_no_sdkapi_support/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/lib_method_2/src/main/jniLibs/armeabi-v7a/libvHook.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Guolei1130/android_p_no_sdkapi_support/HEAD/lib_method_2/src/main/jniLibs/armeabi-v7a/libvHook.so
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Sep 14 14:39:11 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/java/com/guolei/support_p_native/PCompat.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_native;
2 |
3 | /**
4 | * Created by Android Studio.
5 | * User: guolei
6 | * Email: 1120832563@qq.com
7 | * Date: 2018/10/6
8 | * Time: 2:30 PM
9 | * Desc:
10 | */
11 | public class PCompat {
12 |
13 | static {
14 | System.loadLibrary("native_hook");
15 | }
16 |
17 | public native void nativeHook(String fullPath);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/support_p/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.support_p;
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 |
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/lib/src/test/java/com/guolei/lib/pcompat/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.lib.pcompat;
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 | }
--------------------------------------------------------------------------------
/lib_method_1/src/test/java/com/guolei/support_p_java/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_java;
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 | }
--------------------------------------------------------------------------------
/lib_method_2/src/test/java/com/guolei/support_p_native/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_native;
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 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/cpp/v_hook.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by vipkid on 2018/9/19.
3 | //
4 |
5 | #ifndef VK_HOOK_V_HOOK_H
6 | #define VK_HOOK_V_HOOK_H
7 |
8 | #include
9 |
10 | #define _extern extern "C" __attribute__((__visibility__("default")))
11 |
12 | #ifdef __cplusplus
13 | extern "C" {
14 | #endif
15 |
16 | extern void *v_dlopen(const char *filename, int flags);
17 | extern void *v_dlsym(void *handle, const char *symbol);
18 | extern int v_dlclose(void *handle);
19 | extern void v_hook_function(void *symbol, void *replace, void **result);
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
24 |
25 | #endif
26 |
27 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/lib_method_2/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 |
4 | file(GLOB cpp_source_files "src/main/cpp/*.cpp")
5 | file(GLOB c_source_files "src/main/cpp/*.c")
6 | file(GLOB h_source_files "src/main/cpp/*.hpp")
7 |
8 | add_library( # Sets the name of the library.
9 | native_hook
10 |
11 | # Sets the library as a shared library.
12 | SHARED
13 |
14 | # Provides a relative path to your source file(s).
15 | ${c_source_files}
16 | ${cpp_source_files}
17 | ${hpp_source_files}
18 | )
19 |
20 | find_library(
21 | log-lib
22 | log )
23 |
24 |
25 | target_link_libraries( # Specifies the target library.
26 | native_hook
27 | ${log-lib}
28 | )
--------------------------------------------------------------------------------
/app/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.4.1)
3 | set(libs_DIR src/main/jniLibs/${ANDROID_ABI})
4 | link_directories(${libs_DIR})
5 |
6 | add_library( # Sets the name of the library.
7 | native-lib
8 |
9 | # Sets the library as a shared library.
10 | SHARED
11 |
12 | src/main/cpp/native-lib.cpp )
13 |
14 | target_link_libraries( # Specifies the target library.
15 | native-lib
16 | substrate
17 | test2
18 | )
19 |
20 | find_library( # Sets the name of the path variable.
21 | log-lib
22 | log )
23 |
24 |
25 | target_link_libraries( # Specifies the target library.
26 | native-lib
27 | ${log-lib}
28 | )
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/lib/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 |
--------------------------------------------------------------------------------
/lib_method_1/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 |
--------------------------------------------------------------------------------
/lib_method_2/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/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/support_p/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.support_p;
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 |
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.example.support_p", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lib_method_1/src/main/java/com/guolei/support_p_java/PCompat.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_java;
2 |
3 |
4 | import android.os.Build;
5 |
6 | import java.lang.reflect.Field;
7 |
8 | /**
9 | * Author: guolei
10 | * Email: 1120832563@qq.com
11 | * Date: 2018/10/6
12 | * Time: 2:09 PM
13 | * Desc:
14 | */
15 | public class PCompat {
16 |
17 | public static void compat(Class reflectionHelperClz) {
18 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
19 | try {
20 | Class classClz = Class.class;
21 | Field classLoaderField = classClz.getDeclaredField("classLoader");
22 | classLoaderField.setAccessible(true);
23 | classLoaderField.set(reflectionHelperClz, null);
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33 | }
34 |
--------------------------------------------------------------------------------
/lib/src/androidTest/java/com/guolei/lib/pcompat/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.lib.pcompat;
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("com.guolei.lib.pcompat.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib_method_1/src/androidTest/java/com/guolei/support_p_java/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_java;
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("com.guolei.support_p_java.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib_method_2/src/androidTest/java/com/guolei/support_p_native/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.guolei.support_p_native;
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("com.guolei.support_p_native.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib_method_1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:28.0.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/lib_method_2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | externalNativeBuild {
26 | cmake {
27 | path "CMakeLists.txt"
28 | }
29 | }
30 |
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 |
36 | implementation 'com.android.support:appcompat-v7:28.0.0'
37 | testImplementation 'junit:junit:4.12'
38 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/support_p/ReflectionHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.support_p;
2 |
3 | import android.util.Log;
4 | import java.lang.reflect.Field;
5 | import java.lang.reflect.Method;
6 |
7 | public class ReflectionHelper {
8 |
9 | private static final String TAG = ReflectionHelper.class.getSimpleName();
10 |
11 | public static void testMethod() {
12 | try {
13 | Class clz = Class.forName("android.app.ActivityThread");
14 | Method method = clz.getDeclaredMethod("getIntentBeingBroadcast");
15 | method.setAccessible(true);
16 | method.invoke(null);
17 | Log.e(TAG, "testMethod: 反射成功");
18 | } catch (Exception e) {
19 | e.printStackTrace();
20 | Log.e(TAG, "testMethod: 反射失败");
21 | }
22 | }
23 |
24 | public static void testField() {
25 | try {
26 | Class clz = Class.forName("android.app.ActivityThread");
27 | Field field = clz.getDeclaredField("TAG");
28 | field.setAccessible(true);
29 | field.get(null);
30 | Log.e(TAG, "testField: 反射成功");
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | Log.e(TAG, "testField: 反射失败");
34 | }
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/guolei/lib/pcompat/PCompat.java:
--------------------------------------------------------------------------------
1 | package com.guolei.lib.pcompat;
2 |
3 | import android.os.Build;
4 |
5 | import java.lang.reflect.Field;
6 |
7 | /**
8 | * Created by Android Studio.
9 | * User: guolei
10 | * Email: 1120832563@qq.com
11 | * Date: 2019/2/17
12 | * Time: 10:25 AM
13 | * Desc:
14 | */
15 | public class PCompat {
16 | public static void compat(Class reflectionHelperClz) {
17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
18 | try {
19 | Class classClz = Class.class;
20 | Field classLoaderField = classClz.getDeclaredField("classLoader");
21 | classLoaderField.setAccessible(true);
22 | classLoaderField.set(reflectionHelperClz, null);
23 | } catch (Exception e) {
24 | e.printStackTrace();
25 | }
26 | }
27 | }
28 |
29 | public static void useDefaultReflectHelperClass() {
30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
31 | try {
32 | Class classClz = Class.class;
33 | Field classLoaderField = classClz.getDeclaredField("classLoader");
34 | classLoaderField.setAccessible(true);
35 | classLoaderField.set(ReflectHelper.class, null);
36 | } catch (Exception e) {
37 | e.printStackTrace();
38 | }
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
28 |
29 |
36 |
37 |
44 |
45 |
51 |
52 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.support_p"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | externalNativeBuild {
13 | cmake {
14 | cppFlags "-frtti -fexceptions -std=c++11"
15 | }
16 | }
17 | ndk {
18 | abiFilters 'armeabi-v7a','x86'
19 | }
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | externalNativeBuild {
28 | cmake {
29 | path "CMakeLists.txt"
30 | }
31 | }
32 | afterEvaluate {
33 | if (project.hasProperty("assembleDebug")) {
34 | assembleDebug.doLast(new Action() {
35 | @Override
36 | void execute(Task task) {
37 | println("do last")
38 | }
39 | })
40 | }
41 | }
42 | }
43 |
44 | dependencies {
45 | implementation fileTree(dir: 'libs', include: ['*.jar'])
46 | implementation 'com.android.support:appcompat-v7:28.0.0'
47 | implementation 'com.android.support:support-fragment:28.0.0'
48 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
49 | testImplementation 'junit:junit:4.12'
50 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
51 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
52 | implementation 'com.github.Guolei1130:android_p_no_sdkapi_support:0.1.1'
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/lib_method_2/src/main/cpp/native.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by guolei on 2018/10/6.
3 | //
4 | #include
5 | #include
6 | #include
7 | #include "v_hook.h"
8 |
9 | extern "C" {
10 |
11 | extern void *v_dlopen(const char *filename, int flags);
12 | extern void *v_dlsym(void *handle, const char *symbol);
13 | extern int v_dlclose(void *handle);
14 | extern void v_hook_function(void *symbol, void *replace, void **result);
15 | }
16 |
17 | class ObjPtr {
18 | public:
19 | uintptr_t reference_;
20 | };
21 |
22 | void (*setClassLoader)(void *pClass, void *new_cl);
23 | ObjPtr (*toClass)(jclass global_jclss);
24 |
25 | char* jstringToChar(JNIEnv* env, jstring jstr) {
26 | char* rtn = NULL;
27 | jclass clsstring = env->FindClass("java/lang/String");
28 | jstring strencode = env->NewStringUTF("GB2312");
29 | jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B");
30 | jbyteArray barr = (jbyteArray) env->CallObjectMethod(jstr, mid, strencode);
31 | jsize alen = env->GetArrayLength(barr);
32 | jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
33 | if (alen > 0) {
34 | rtn = (char*) malloc(alen + 1);
35 | memcpy(rtn, ba, alen);
36 | rtn[alen] = 0;
37 | }
38 | env->ReleaseByteArrayElements(barr, ba, 0);
39 | return rtn;
40 | }
41 |
42 | extern "C" void makeHiddenApiAccessable(JNIEnv *env,jstring classPath) {
43 | void *libart = v_dlopen("/system/lib/libart.so", RTLD_NOW);
44 | if (libart != NULL) {
45 | *(void **) (&toClass) = v_dlsym(libart, "_ZN3art16WellKnownClasses7ToClassEP7_jclass");
46 | *(void **) (&setClassLoader) =
47 | v_dlsym(libart, "_ZN3art6mirror5Class14SetClassLoaderENS_6ObjPtrINS0_11ClassLoaderEEE");
48 | jclass cls = env->FindClass(jstringToChar(env,classPath));
49 | ObjPtr op = toClass(cls);
50 | setClassLoader((void *) op.reference_, NULL);
51 | v_dlclose(libart);
52 | }
53 | }
54 |
55 | extern "C"
56 | JNIEXPORT void JNICALL
57 | Java_com_guolei_support_1p_1native_PCompat_nativeHook(JNIEnv *env,
58 | jobject instance,
59 | jstring classPath_) {
60 | const char *classPath = env->GetStringUTFChars(classPath_, 0);
61 |
62 | makeHiddenApiAccessable(env,classPath_);
63 |
64 | env->ReleaseStringUTFChars(classPath_, classPath);
65 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/support_p/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.support_p;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.view.View.OnClickListener;
7 | import android.widget.TextView;
8 | import java.lang.reflect.Field;
9 | import java.lang.reflect.Method;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | // Used to load the 'native-lib' library on application startup.
14 | static {
15 | System.loadLibrary("substrate");
16 | System.loadLibrary("test2");
17 | System.loadLibrary("native-lib");
18 | }
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 |
25 | // Example of a call to a native method
26 | TextView tv = (TextView) findViewById(R.id.sample_text);
27 | tv.setText(stringFromJNI());
28 |
29 | // getLifecycle()
30 |
31 | ReflectionHelper.testMethod();
32 | ReflectionHelper.testField();
33 | findViewById(R.id.test_method).setOnClickListener(new OnClickListener() {
34 | @Override
35 | public void onClick(View v) {
36 | try {
37 | Class clz = Class.forName("android.app.ActivityThread");
38 | Method method = clz.getDeclaredMethod("getIntentBeingBroadcast");
39 | method.setAccessible(true);
40 | method.invoke(null);
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | }
44 | }
45 | });
46 |
47 | findViewById(R.id.test_field).setOnClickListener(new OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | try {
51 | Class clz = Class.forName("android.app.ActivityThread");
52 | Field field = clz.getDeclaredField("TAG");
53 | field.setAccessible(true);
54 | field.get(null);
55 | } catch (Exception e) {
56 | e.printStackTrace();
57 | }
58 | }
59 | });
60 |
61 | findViewById(R.id.reflection_helper).setOnClickListener(new OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | testJavaPojie();
65 | }
66 | });
67 |
68 | findViewById(R.id.test_reflection_helper).setOnClickListener(new OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | ReflectionHelper.testMethod();
72 | ReflectionHelper.testField();
73 | }
74 | });
75 | }
76 |
77 | private void testJavaPojie() {
78 | try {
79 | Class reflectionHelperClz = Class.forName("com.example.support_p.ReflectionHelper");
80 | Class classClz = Class.class;
81 | Field classLoaderField = classClz.getDeclaredField("classLoader");
82 | classLoaderField.setAccessible(true);
83 | classLoaderField.set(reflectionHelperClz, null);
84 | } catch (Exception e) {
85 | e.printStackTrace();
86 | }
87 | }
88 |
89 | /**
90 | * A native method that is implemented by the 'native-lib' native library,
91 | * which is packaged with this application.
92 | */
93 | public native String stringFromJNI();
94 | }
95 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/guolei/lib/pcompat/ReflectHelper.java:
--------------------------------------------------------------------------------
1 | package com.guolei.lib.pcompat;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 |
7 | /**
8 | * Created by Android Studio.
9 | * User: guolei
10 | * Email: 1120832563@qq.com
11 | * Date: 2019/2/17
12 | * Time: 10:39 AM
13 | * Desc:
14 | */
15 | public class ReflectHelper {
16 |
17 | public static Class> forName(String className) throws ClassNotFoundException {
18 | return Class.forName(className);
19 | }
20 |
21 | public static Class> forName(String className, boolean initialize, ClassLoader classLoader)
22 | throws ClassNotFoundException {
23 | return Class.forName(className, initialize, classLoader);
24 | }
25 |
26 | public static Field[] getFields(Class> clz) {
27 | return clz.getFields();
28 | }
29 |
30 | public static Field getField(Class> clz, String name) throws NoSuchFieldException {
31 | return clz.getField(name);
32 | }
33 |
34 | public static Field[] getDeclaredFields(Class> clz) {
35 | return clz.getDeclaredFields();
36 | }
37 |
38 | public static Field getDeclaredField(Class> clz, String name) throws NoSuchFieldException {
39 | return clz.getDeclaredField(name);
40 | }
41 |
42 | public static Method[] getMethods(Class> clz) {
43 | return clz.getMethods();
44 | }
45 |
46 | public static Method getMethod(Class> clz, String name, Class>... parameterType)
47 | throws NoSuchMethodException {
48 | return clz.getMethod(name, parameterType);
49 | }
50 |
51 | public static Method[] getDeclaredMethods(Class> clz) {
52 | return clz.getDeclaredMethods();
53 | }
54 |
55 | public static Method getDeclaredMethod(Class> clz, String name, Class>... parameterType)
56 | throws NoSuchMethodException {
57 | return clz.getDeclaredMethod(name, parameterType);
58 | }
59 |
60 | public static Object invokeStaticMethod(Class> clz, Object instance,
61 | String methodName, Object... params)
62 | throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
63 | Method method;
64 | if (params == null) {
65 | method = clz.getMethod(methodName);
66 | } else {
67 | Class> types[] = new Class[params.length];
68 | for (int i = 0; i < params.length; i++) {
69 | types[i] = params[i].getClass();
70 | }
71 | method = clz.getMethod(methodName, types);
72 | }
73 | return method.invoke(instance, params);
74 | }
75 |
76 | public static Object invokeMethod(Class> clz, Object instance,
77 | String methodName, Object... params)
78 | throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
79 | Method method;
80 | if (params == null) {
81 | method = clz.getDeclaredMethod(methodName);
82 | } else {
83 | Class> types[] = new Class[params.length];
84 | for (int i = 0; i < params.length; i++) {
85 | types[i] = params[i].getClass();
86 | }
87 | method = clz.getDeclaredMethod(methodName, types);
88 | }
89 | return method.invoke(instance, params);
90 | }
91 |
92 | public static Object getStaticFieldValue(Class> clz, String fieldName)
93 | throws NoSuchFieldException, IllegalAccessException {
94 | Field field = clz.getField(fieldName);
95 | return field.get(null);
96 | }
97 |
98 | public static Object getFieldValue(Class> clz, Object instance, String fieldName)
99 | throws NoSuchFieldException, IllegalAccessException {
100 | Field field = clz.getDeclaredField(fieldName);
101 | return field.get(instance);
102 | }
103 |
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.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 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 | #include "substrate.h"
8 |
9 | #define TAG_NAME "test2:test_cplusplus"
10 | #define log_error(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG_NAME, (const char *) fmt, ##args)
11 | #define log_info(fmt, args...) __android_log_print(ANDROID_LOG_INFO, TAG_NAME, (const char *) fmt, ##args)
12 |
13 | extern "C" {
14 | extern void *fake_dlopen(const char *filename, int flags);
15 | extern void *fake_dlsym(void *handle, const char *symbol);
16 | extern void fake_dlclose(void *handle);
17 | extern void MSHookFunction(void *symbol, void *replace, void **result);
18 | }
19 |
20 | extern "C" {
21 | int hookForP();
22 | int hookForPMethod();
23 | int hookForPField();
24 |
25 | void makeHiddenApiAccessable(JNIEnv *env);
26 | }
27 |
28 |
29 | extern "C" JNIEXPORT jstring
30 | JNICALL
31 | Java_com_example_support_1p_MainActivity_stringFromJNI(
32 | JNIEnv *env,
33 | jobject /* this */) {
34 | std::string hello = "Hello from C++";
35 | // makeHiddenApiAccessable(env);
36 | return env->NewStringUTF(hello.c_str());
37 | }
38 |
39 | extern "C" int hookForP() {
40 | hookForPMethod();
41 | hookForPField();
42 | return 0;
43 | }
44 |
45 | class ObjPtr {
46 | public:
47 | uintptr_t reference_;
48 | };
49 |
50 | ObjPtr
51 | (*sys_GetDeclaredMethodInternal)(void *self, jobject kclass, jstring name, jobjectArray args);
52 |
53 | void *(*executableGetArtMethod)(void *ex);
54 |
55 | ObjPtr myGetDeclaredMethodInternal(void *self, jobject kclass, jstring name, jobjectArray args) {
56 | ObjPtr res = sys_GetDeclaredMethodInternal(self, kclass, name, args);
57 | if (res.reference_ != 0) {
58 | void *pMethod = executableGetArtMethod((void *) (res.reference_));
59 | reinterpret_cast(pMethod)[1] &= 0xcfffffff;
60 | }
61 | return res;
62 | }
63 |
64 |
65 | extern "C" int hookForPMethod() {
66 | void *libc = fake_dlopen("/system/lib/libart.so", RTLD_NOW);
67 | if (libc != NULL) {
68 | void *p = fake_dlsym(libc, "_ZN3art6mirror5Class25GetDeclaredMethodInternalILNS_11Poin"
69 | "terSizeE4ELb0EEENS_6ObjPtrINS0_6MethodEEEPNS_6ThreadENS4_IS1_EENS4_INS0_6StringEEEN"
70 | "S4_INS0_11ObjectArrayIS1_EEEE");
71 | if (p != NULL) {
72 | MSHookFunction(p,
73 | reinterpret_cast(myGetDeclaredMethodInternal),
74 | reinterpret_cast(&sys_GetDeclaredMethodInternal));
75 | }
76 | *(void **) (&executableGetArtMethod) =
77 | fake_dlsym(libc, "_ZN3art6mirror10Executable12GetArtMethodEv");
78 | fake_dlclose(libc);
79 |
80 | } //if
81 |
82 | return 1;
83 | }
84 |
85 |
86 | void *(*sys_CreateFromArtField)(void *, void *, bool);
87 |
88 | void *myCreateFromArtField(void *self, void *field, bool force_resolve) {
89 | log_error("=================== %s", "myCreateFromArtField");
90 | void *result = sys_CreateFromArtField(self, field, force_resolve);
91 | return result;
92 | }
93 |
94 | // hidden的,方案不靠谱
95 | extern "C" int hookForPField() {
96 | void *libart = fake_dlopen("/system/lib/libart.so", RTLD_NOW);
97 | if (libart != NULL) {
98 | // CreateFromArtMethod这个方法是hidden的,找不到,方案三field的切入点找不到
99 | void *CreateFromArtField = fake_dlsym(libart,
100 | "_ZN3art6mirror5Field18CreateFromArtFieldILNS_11PointerSizeE8ELb1EEEPS1_PNS_6ThreadEPNS_8ArtFieldEb");
101 | if (CreateFromArtField != NULL) {
102 | MSHookFunction(CreateFromArtField,
103 | reinterpret_cast(myCreateFromArtField),
104 | reinterpret_cast(&sys_CreateFromArtField));
105 | log_error("hook field %p,%p", myCreateFromArtField, sys_CreateFromArtField);
106 | } else {
107 | log_error("p is null");
108 | }
109 | fake_dlclose(libart);
110 |
111 | } //if
112 |
113 | return 1;
114 | }
115 |
116 | void (*setClassLoader)(void *pClass, void *new_cl);
117 | ObjPtr (*toClass)(jclass global_jclss);
118 |
119 | extern "C" void makeHiddenApiAccessable(JNIEnv *env) {
120 | void *libart = fake_dlopen("/system/lib/libart.so", RTLD_NOW);
121 | if (libart != NULL) {
122 | *(void **) (&toClass) = fake_dlsym(libart, "_ZN3art16WellKnownClasses7ToClassEP7_jclass");
123 | *(void **) (&setClassLoader) =
124 | fake_dlsym(libart, "_ZN3art6mirror5Class14SetClassLoaderENS_6ObjPtrINS0_11ClassLoaderEEE");
125 | jclass cls = env->FindClass("com/example/support_p/ReflectionHelper");
126 | ObjPtr op = toClass(cls);
127 | setClassLoader((void *) op.reference_, NULL);
128 | }
129 | }
130 |
131 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 |
2 | # 如何使用这个库
3 |
4 | 原先想的是只介绍一下原理,但是有的同学好像看了之后还不会使用。因此,接入了jitpack以便使用。
5 |
6 | Add it in your root build.gradle at the end of repositories:
7 |
8 | ```
9 | allprojects {
10 | repositories {
11 | ...
12 | maven { url 'https://jitpack.io' }
13 | }
14 | }
15 |
16 | ```
17 | Step 2. Add the dependency
18 |
19 | ```
20 | dependencies {
21 | implementation 'com.github.Guolei1130:android_p_no_sdkapi_support:0.1.1'
22 | }
23 |
24 | ```
25 |
26 | ### 用法
27 |
28 | 1. 可以用PCompat#compat(Class reflectionHelperClz) 将所有的反射操作,用reflectionHelperClz这个类去执行即可
29 | 2. 可以用PCompat#useDefaultReflectHelperClass 所有的反射操作,用ReflectHelper去操作j也可以
30 |
31 |
32 | [Android P 调用隐藏API限制原理](https://mp.weixin.qq.com/s/sktB0x5yBexkn4ORQ1YofA)
33 |
34 | [突破Android P(Preview 1)对调用隐藏API限制的方法](https://mp.weixin.qq.com/s/4k3DBlxlSO2xNNKqjqUdaQ)
35 |
36 | [java_lang_Class.cc](https://android.googlesource.com/platform/art/+/android-9.0.0_r5/runtime/native/java_lang_Class.cc)
37 |
38 | ### 前言
39 |
40 | Android P对非SDK API的使用做了限制,导致在Android P上会出现一些状况。在很早前预览版本刚出来的时候,360团队就出了两篇文章。
41 | [Android P 调用隐藏API限制原理](https://mp.weixin.qq.com/s/sktB0x5yBexkn4ORQ1YofA) 以及
42 | [突破Android P(Preview 1)对调用隐藏API限制的方法](https://mp.weixin.qq.com/s/4k3DBlxlSO2xNNKqjqUdaQ)
43 |
44 | 限制方式三种:
45 | * 反射
46 | * 直接调用
47 | * jni调用
48 |
49 | 这一篇文章就是根据上面的文章来的。
50 |
51 | ### 方法一(不建议)
52 |
53 | 使用Provided(CompileOnly)的方式去解决调用限制,只能解决反射调用的问题,而无法解决直接调用或者jni调用的方式。不建议使用
54 |
55 | ### 方法二(不建议)
56 |
57 | 这个方法二对应的是360文章中的方法三。主要代码如下。
58 |
59 | ```
60 | class ObjPtr {
61 | public:
62 | uintptr_t reference_;
63 | };
64 |
65 | ObjPtr
66 | (*sys_GetDeclaredMethodInternal)(void *self, jobject kclass, jstring name, jobjectArray args);
67 |
68 | void *(*executableGetArtMethod)(void *ex);
69 |
70 | ObjPtr myGetDeclaredMethodInternal(void *self, jobject kclass, jstring name, jobjectArray args) {
71 | ObjPtr res = sys_GetDeclaredMethodInternal(self, kclass, name, args);
72 | if (res.reference_ != 0) {
73 | void *pMethod = executableGetArtMethod((void *) (res.reference_));
74 | reinterpret_cast(pMethod)[1] &= 0xcfffffff;
75 | }
76 | return res;
77 | }
78 |
79 |
80 | extern "C" int hookForPMethod() {
81 | void *libc = fake_dlopen("/system/lib/libart.so", RTLD_NOW);
82 | if (libc != NULL) {
83 | void *p = fake_dlsym(libc, "_ZN3art6mirror5Class25GetDeclaredMethodInternalILNS_11Poin"
84 | "terSizeE4ELb0EEENS_6ObjPtrINS0_6MethodEEEPNS_6ThreadENS4_IS1_EENS4_INS0_6StringEEEN"
85 | "S4_INS0_11ObjectArrayIS1_EEEE");
86 | if (p != NULL) {
87 | MSHookFunction(p,
88 | reinterpret_cast(myGetDeclaredMethodInternal),
89 | reinterpret_cast(&sys_GetDeclaredMethodInternal));
90 | }
91 | *(void **) (&executableGetArtMethod) =
92 | fake_dlsym(libc, "_ZN3art6mirror10Executable12GetArtMethodEv");
93 | fake_dlclose(libc);
94 |
95 | } //if
96 |
97 | return 1;
98 | }
99 | ```
100 |
101 | 其中,fake_dlopen、fake_dlsym 使用的是[Nougat_dlfunctions](https://github.com/Guolei1130/Nougat_dlfunctions),主要是Android 7.0以上对dlopen、dlsym等函数做了限制。因此用这个库。而MSHookFunction,则是大名鼎鼎的[cydiasubstrate](http://www.cydiasubstrate.com/)。
102 |
103 |
104 | 
105 |
106 | 上面的代码只解决了反射方法的问题。我按照这种思路去解决字段问题的时候发现。
107 |
108 | 
109 |
110 | 
111 |
112 | GetDeclaredField是inline的,无法切入。而CreateFromArtField又是hidden的,也不好切入。
113 |
114 |
115 | 
116 |
117 | 因此,放弃了这种方法。
118 |
119 | ### 方法三(可用,但是有更好的)
120 |
121 | 这里对应的方法三,对应的是360文章中的方法二,也就是修改classloader的方式。代码如下。
122 |
123 | ```
124 | void (*setClassLoader)(void *pClass, void *new_cl);
125 | ObjPtr (*toClass)(jclass global_jclss);
126 |
127 | extern "C" void makeHiddenApiAccessable(JNIEnv *env) {
128 | void *libart = fake_dlopen("/system/lib/libart.so", RTLD_NOW);
129 | if (libart != NULL) {
130 | *(void **) (&toClass) = fake_dlsym(libart, "_ZN3art16WellKnownClasses7ToClassEP7_jclass");
131 | *(void **) (&setClassLoader) =
132 | fake_dlsym(libart, "_ZN3art6mirror5Class14SetClassLoaderENS_6ObjPtrINS0_11ClassLoaderEEE");
133 | jclass cls = env->FindClass("com/example/support_p/ReflectionHelper");
134 | ObjPtr op = toClass(cls);
135 | setClassLoader((void *) op.reference_, NULL);
136 | }
137 | }
138 |
139 | ```
140 |
141 | 没错,代码就是这么点。这样,我们就可以在ReflectionHelper中调用非公开API了。但是这里会依赖Nougat_dlfunctions这个库。
142 |
143 |
144 | 
145 | 
146 |
147 | ### 方法四(超级好)
148 |
149 | 既然是修改classloader,那么我们为什么不在java层修改呢。代码如下。
150 |
151 | ```
152 | private void testJavaPojie() {
153 | try {
154 | Class reflectionHelperClz = Class.forName("com.example.support_p.ReflectionHelper");
155 | Class classClz = Class.class;
156 | Field classLoaderField = classClz.getDeclaredField("classLoader");
157 | classLoaderField.setAccessible(true);
158 | classLoaderField.set(reflectionHelperClz, null);
159 | } catch (Exception e) {
160 | e.printStackTrace();
161 | }
162 | }
163 | ```
164 |
165 | 而这里用的相关反射只是light级别的,没有什么影响。反而代码量超小,也不依赖其他。
166 |
167 | ### 方法五(超级好+1)
168 |
169 | 这个方案来自 @区长 大神
170 |
171 | 方法四还是存在一点问题。如果以后把classloader加入到深灰或者黑名单,那就僵硬了。所以,我们不用反射,直接用unsafe去修改。代码这就不贴了。为了得到classloader的偏移量,我们写一个和Class结构一样的类,用这个类得到的classLoader的偏移量和Class是一样的。
172 |
173 | 补充:
174 |
175 | ### 方法6
176 |
177 | [田维术](https://zhuanlan.zhihu.com/p/59455212)
178 |
179 | VMRuntime.setHiddenApiExemptions 方法
180 |
181 |
182 | ### 注意:
183 |
184 | 如果我们用修改ClassLoader的方式的话,那么ReflectionHelper类中只能反射调用非公开API,注意了。
185 |
186 | [代码在这里,觉得好的给个star吧](https://github.com/Guolei1130/android_p_no_sdkapi_support)
187 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/cpp/substrate.h:
--------------------------------------------------------------------------------
1 | /* Cydia Substrate - Powerful Code Insertion Platform
2 | * Copyright (C) 2008-2013 Jay Freeman (saurik)
3 | */
4 |
5 | /* GNU Lesser General Public License, Version 3 {{{ */
6 | /*
7 | * Substrate is free software: you can redistribute it and/or modify it under
8 | * the terms of the GNU Lesser General Public License as published by the
9 | * Free Software Foundation, either version 3 of the License, or (at your
10 | * option) any later version.
11 | *
12 | * Substrate is distributed in the hope that it will be useful, but WITHOUT
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 | * License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public License
18 | * along with Substrate. If not, see .
19 | **/
20 | /* }}} */
21 |
22 | #ifndef SUBSTRATE_H_
23 | #define SUBSTRATE_H_
24 |
25 | #ifdef __APPLE__
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 | #include
30 | #ifdef __cplusplus
31 | }
32 | #endif
33 |
34 | #include
35 | #include
36 | #endif
37 |
38 | #include
39 | #include
40 |
41 | #define _finline \
42 | inline __attribute__((__always_inline__))
43 | #define _disused \
44 | __attribute__((__unused__))
45 |
46 | #ifdef __cplusplus
47 | #define _default(value) = value
48 | #else
49 | #define _default(value)
50 | #endif
51 |
52 | #ifdef __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | bool MSHookProcess(pid_t pid, const char *library);
57 |
58 | typedef const void *MSImageRef;
59 |
60 | MSImageRef MSGetImageByName(const char *file);
61 | void *MSFindSymbol(MSImageRef image, const char *name);
62 |
63 | void MSHookFunction(void *symbol, void *replace, void **result);
64 |
65 | #ifdef __APPLE__
66 | #ifdef __arm__
67 | __attribute__((__deprecated__))
68 | IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
69 | #endif
70 | void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result);
71 | #endif
72 |
73 | #ifdef __ANDROID__
74 | #include
75 | void MSJavaHookClassLoad(JNIEnv *jni, const char *name, void (*callback)(JNIEnv *, jclass, void *), void *data _default(NULL));
76 | void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID methodID, void *function, void **result);
77 | void MSJavaBlessClassLoader(JNIEnv *jni, jobject loader);
78 |
79 | typedef struct MSJavaObjectKey_ *MSJavaObjectKey;
80 | MSJavaObjectKey MSJavaCreateObjectKey();
81 | void MSJavaReleaseObjectKey(MSJavaObjectKey key);
82 | void *MSJavaGetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key);
83 | void MSJavaSetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key, void *value, void (*clean)(void *, JNIEnv *, void *) _default(NULL), void *data _default(NULL));
84 | #endif
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #ifdef __cplusplus
91 |
92 | #ifdef __APPLE__
93 |
94 | namespace etl {
95 |
96 | template
97 | struct Case {
98 | static char value[Case_ + 1];
99 | };
100 |
101 | typedef Case Yes;
102 | typedef Case No;
103 |
104 | namespace be {
105 | template
106 | static Yes CheckClass_(void (Checked_::*)());
107 |
108 | template
109 | static No CheckClass_(...);
110 | }
111 |
112 | template
113 | struct IsClass {
114 | void gcc32();
115 |
116 | static const bool value = (sizeof(be::CheckClass_(0).value) == sizeof(Yes::value));
117 | };
118 |
119 | }
120 |
121 | #ifdef __arm__
122 | template
123 | __attribute__((__deprecated__))
124 | static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) {
125 | return reinterpret_cast(MSHookMessage(_class, sel, reinterpret_cast(imp), prefix));
126 | }
127 | #endif
128 |
129 | template
130 | static inline void MSHookMessage(Class _class, SEL sel, Type_ *imp, Type_ **result) {
131 | return MSHookMessageEx(_class, sel, reinterpret_cast(imp), reinterpret_cast(result));
132 | }
133 |
134 | template
135 | static inline Type_ &MSHookIvar(id self, const char *name) {
136 | Ivar ivar(class_getInstanceVariable(object_getClass(self), name));
137 | void *pointer(ivar == NULL ? NULL : reinterpret_cast(self) + ivar_getOffset(ivar));
138 | return *reinterpret_cast(pointer);
139 | }
140 |
141 | #define MSAddMessage0(_class, type, arg0) \
142 | class_addMethod($ ## _class, @selector(arg0), (IMP) &$ ## _class ## $ ## arg0, type);
143 | #define MSAddMessage1(_class, type, arg0) \
144 | class_addMethod($ ## _class, @selector(arg0:), (IMP) &$ ## _class ## $ ## arg0 ## $, type);
145 | #define MSAddMessage2(_class, type, arg0, arg1) \
146 | class_addMethod($ ## _class, @selector(arg0:arg1:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $, type);
147 | #define MSAddMessage3(_class, type, arg0, arg1, arg2) \
148 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $, type);
149 | #define MSAddMessage4(_class, type, arg0, arg1, arg2, arg3) \
150 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $, type);
151 | #define MSAddMessage5(_class, type, arg0, arg1, arg2, arg3, arg4) \
152 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $, type);
153 | #define MSAddMessage6(_class, type, arg0, arg1, arg2, arg3, arg4, arg5) \
154 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $, type);
155 | #define MSAddMessage7(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
156 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $, type);
157 | #define MSAddMessage8(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
158 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $ ## arg7 ## $, type);
159 |
160 | #define MSHookMessage0(_class, arg0) \
161 | MSHookMessage($ ## _class, @selector(arg0), MSHake(_class ## $ ## arg0))
162 | #define MSHookMessage1(_class, arg0) \
163 | MSHookMessage($ ## _class, @selector(arg0:), MSHake(_class ## $ ## arg0 ## $))
164 | #define MSHookMessage2(_class, arg0, arg1) \
165 | MSHookMessage($ ## _class, @selector(arg0:arg1:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $))
166 | #define MSHookMessage3(_class, arg0, arg1, arg2) \
167 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $))
168 | #define MSHookMessage4(_class, arg0, arg1, arg2, arg3) \
169 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $))
170 | #define MSHookMessage5(_class, arg0, arg1, arg2, arg3, arg4) \
171 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $))
172 | #define MSHookMessage6(_class, arg0, arg1, arg2, arg3, arg4, arg5) \
173 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $))
174 | #define MSHookMessage7(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \
175 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $))
176 | #define MSHookMessage8(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
177 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $ ## arg7 ## $))
178 |
179 | #define MSRegister_(name, dollar, colon) \
180 | namespace { static class C_$ ## name ## $ ## dollar { public: _finline C_$ ## name ## $ ##dollar() { \
181 | MSHookMessage($ ## name, @selector(colon), MSHake(name ## $ ## dollar)); \
182 | } } V_$ ## name ## $ ## dollar; } \
183 |
184 | #define MSIgnore_(name, dollar, colon)
185 |
186 | #define MSMessage_(extra, type, _class, name, dollar, colon, call, args...) \
187 | static type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args); \
188 | MSHook(type, name ## $ ## dollar, _class self, SEL _cmd, ## args) { \
189 | Class const _cls($ ## name); \
190 | type (* const _old)(_class, SEL, ## args, ...) = reinterpret_cast(_ ## name ## $ ## dollar); \
191 | typedef type (*msgSendSuper_t)(struct objc_super *, SEL, ## args, ...); \
192 | msgSendSuper_t const _spr(::etl::IsClass::value ? reinterpret_cast(&objc_msgSendSuper_stret) : reinterpret_cast(&objc_msgSendSuper)); \
193 | return _$ ## name ## $ ## dollar call; \
194 | } \
195 | extra(name, dollar, colon) \
196 | static _finline type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args)
197 |
198 | /* for((x=1;x!=7;++x)){ echo -n "#define MSMessage${x}_(extra, type, _class, name";for((y=0;y!=x;++y));do echo -n ", sel$y";done;for((y=0;y!=x;++y));do echo -n ", type$y, arg$y";done;echo ") \\";echo -n " MSMessage_(extra, type, _class, name,";for((y=0;y!=x;++y));do if [[ $y -ne 0 ]];then echo -n " ##";fi;echo -n " sel$y ## $";done;echo -n ", ";for((y=0;y!=x;++y));do echo -n "sel$y:";done;echo -n ", (_cls, _old, _spr, self, _cmd";for((y=0;y!=x;++y));do echo -n ", arg$y";done;echo -n ")";for((y=0;y!=x;++y));do echo -n ", type$y arg$y";done;echo ")";} */
199 |
200 | #define MSMessage0_(extra, type, _class, name, sel0) \
201 | MSMessage_(extra, type, _class, name, sel0, sel0, (_cls, _old, _spr, self, _cmd))
202 | #define MSMessage1_(extra, type, _class, name, sel0, type0, arg0) \
203 | MSMessage_(extra, type, _class, name, sel0 ## $, sel0:, (_cls, _old, _spr, self, _cmd, arg0), type0 arg0)
204 | #define MSMessage2_(extra, type, _class, name, sel0, sel1, type0, arg0, type1, arg1) \
205 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $, sel0:sel1:, (_cls, _old, _spr, self, _cmd, arg0, arg1), type0 arg0, type1 arg1)
206 | #define MSMessage3_(extra, type, _class, name, sel0, sel1, sel2, type0, arg0, type1, arg1, type2, arg2) \
207 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $, sel0:sel1:sel2:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2), type0 arg0, type1 arg1, type2 arg2)
208 | #define MSMessage4_(extra, type, _class, name, sel0, sel1, sel2, sel3, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \
209 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $, sel0:sel1:sel2:sel3:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3), type0 arg0, type1 arg1, type2 arg2, type3 arg3)
210 | #define MSMessage5_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
211 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $, sel0:sel1:sel2:sel3:sel4:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4)
212 | #define MSMessage6_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \
213 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $, sel0:sel1:sel2:sel3:sel4:sel5:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)
214 | #define MSMessage7_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6) \
215 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6)
216 | #define MSMessage8_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, sel7, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6, type7, arg7) \
217 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $ ## sel7 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:sel7:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7)
218 |
219 | #define MSInstanceMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, _class *, _class, ## args)
220 | #define MSInstanceMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, _class *, _class, ## args)
221 | #define MSInstanceMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, _class *, _class, ## args)
222 | #define MSInstanceMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, _class *, _class, ## args)
223 | #define MSInstanceMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, _class *, _class, ## args)
224 | #define MSInstanceMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, _class *, _class, ## args)
225 | #define MSInstanceMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, _class *, _class, ## args)
226 | #define MSInstanceMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, _class *, _class, ## args)
227 | #define MSInstanceMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, _class *, _class, ## args)
228 |
229 | #define MSClassMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, Class, $ ## _class, ## args)
230 | #define MSClassMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, Class, $ ## _class, ## args)
231 | #define MSClassMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, Class, $ ## _class, ## args)
232 | #define MSClassMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, Class, $ ## _class, ## args)
233 | #define MSClassMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, Class, $ ## _class, ## args)
234 | #define MSClassMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, Class, $ ## _class, ## args)
235 | #define MSClassMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, Class, $ ## _class, ## args)
236 | #define MSClassMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, Class, $ ## _class, ## args)
237 | #define MSClassMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, Class, $ ## _class, ## args)
238 |
239 | #define MSInstanceMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, _class *, _class, ## args)
240 | #define MSInstanceMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, _class *, _class, ## args)
241 | #define MSInstanceMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, _class *, _class, ## args)
242 | #define MSInstanceMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, _class *, _class, ## args)
243 | #define MSInstanceMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, _class *, _class, ## args)
244 | #define MSInstanceMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, _class *, _class, ## args)
245 | #define MSInstanceMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, _class *, _class, ## args)
246 | #define MSInstanceMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, _class *, _class, ## args)
247 | #define MSInstanceMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, _class *, _class, ## args)
248 |
249 | #define MSClassMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, Class, $ ## _class, ## args)
250 | #define MSClassMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, Class, $ ## _class, ## args)
251 | #define MSClassMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, Class, $ ## _class, ## args)
252 | #define MSClassMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, Class, $ ## _class, ## args)
253 | #define MSClassMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, Class, $ ## _class, ## args)
254 | #define MSClassMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, Class, $ ## _class, ## args)
255 | #define MSClassMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, Class, $ ## _class, ## args)
256 | #define MSClassMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, Class, $ ## _class, ## args)
257 | #define MSClassMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, Class, $ ## _class, ## args)
258 |
259 | #define MSOldCall(args...) \
260 | _old(self, _cmd, ## args)
261 | #define MSSuperCall(args...) \
262 | _spr(& (struct objc_super) {self, class_getSuperclass(_cls)}, _cmd, ## args)
263 |
264 | #define MSIvarHook(type, name) \
265 | type &name(MSHookIvar(self, #name))
266 |
267 | #define MSClassHook(name) \
268 | @class name; \
269 | static Class $ ## name = objc_getClass(#name);
270 | #define MSMetaClassHook(name) \
271 | @class name; \
272 | static Class $$ ## name = object_getClass($ ## name);
273 |
274 | #endif/*__APPLE__*/
275 |
276 | template
277 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) {
278 | return MSHookFunction(
279 | reinterpret_cast(symbol),
280 | reinterpret_cast(replace),
281 | reinterpret_cast(result)
282 | );
283 | }
284 |
285 | template
286 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace) {
287 | return MSHookFunction(symbol, replace, reinterpret_cast(NULL));
288 | }
289 |
290 | template
291 | static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) {
292 | value = reinterpret_cast(MSFindSymbol(image, name));
293 | }
294 |
295 | template
296 | static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) {
297 | Type_ *symbol;
298 | MSHookSymbol(symbol, name);
299 | return MSHookFunction(symbol, replace, result);
300 | }
301 |
302 | template
303 | static inline void MSHookFunction(MSImageRef image, const char *name, Type_ *replace, Type_ **result = NULL) {
304 | Type_ *symbol;
305 | MSHookSymbol(symbol, name, image);
306 | return MSHookFunction(symbol, replace, result);
307 | }
308 |
309 | #endif
310 |
311 | #ifdef __ANDROID__
312 |
313 | #ifdef __cplusplus
314 |
315 | template
316 | static inline void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID method, Type_ (*replace)(JNIEnv *, Kind_, Args_...), Type_ (**result)(JNIEnv *, Kind_, ...)) {
317 | return MSJavaHookMethod(
318 | jni, _class, method,
319 | reinterpret_cast(replace),
320 | reinterpret_cast(result)
321 | );
322 | }
323 |
324 | #endif
325 |
326 | static inline void MSAndroidGetPackage(JNIEnv *jni, jobject global, const char *name, jobject &local, jobject &loader) {
327 | jclass Context(jni->FindClass("android/content/Context"));
328 | jmethodID Context$createPackageContext(jni->GetMethodID(Context, "createPackageContext", "(Ljava/lang/String;I)Landroid/content/Context;"));
329 | jmethodID Context$getClassLoader(jni->GetMethodID(Context, "getClassLoader", "()Ljava/lang/ClassLoader;"));
330 |
331 | jstring string(jni->NewStringUTF(name));
332 | local = jni->CallObjectMethod(global, Context$createPackageContext, string, 3);
333 | loader = jni->CallObjectMethod(local, Context$getClassLoader);
334 | }
335 |
336 | static inline jclass MSJavaFindClass(JNIEnv *jni, jobject loader, const char *name) {
337 | jclass Class(jni->FindClass("java/lang/Class"));
338 | jmethodID Class$forName(jni->GetStaticMethodID(Class, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"));
339 |
340 | jstring string(jni->NewStringUTF(name));
341 | jobject _class(jni->CallStaticObjectMethod(Class, Class$forName, string, JNI_TRUE, loader));
342 | if (jni->ExceptionCheck())
343 | return NULL;
344 |
345 | return reinterpret_cast(_class);
346 | }
347 |
348 | _disused static void MSJavaCleanWeak(void *data, JNIEnv *jni, void *value) {
349 | jni->DeleteWeakGlobalRef(reinterpret_cast(value));
350 | }
351 |
352 | #endif
353 |
354 | #define MSHook(type, name, args...) \
355 | _disused static type (*_ ## name)(args); \
356 | static type $ ## name(args)
357 |
358 | #define MSJavaHook(type, name, arg0, args...) \
359 | _disused static type (*_ ## name)(JNIEnv *jni, arg0, ...); \
360 | static type $ ## name(JNIEnv *jni, arg0, ## args)
361 |
362 | #ifdef __cplusplus
363 | #define MSHake(name) \
364 | &$ ## name, &_ ## name
365 | #else
366 | #define MSHake(name) \
367 | &$ ## name, (void **) &_ ## name
368 | #endif
369 |
370 | #define SubstrateConcat_(lhs, rhs) \
371 | lhs ## rhs
372 | #define SubstrateConcat(lhs, rhs) \
373 | SubstrateConcat_(lhs, rhs)
374 |
375 | #ifdef __APPLE__
376 | #define SubstrateSection \
377 | __attribute__((__section__("__TEXT, __substrate")))
378 | #else
379 | #define SubstrateSection \
380 | __attribute__((__section__(".substrate")))
381 | #endif
382 |
383 | #ifdef __APPLE__
384 | #define MSFilterCFBundleID "Filter:CFBundleID"
385 | #define MSFilterObjC_Class "Filter:ObjC.Class"
386 | #endif
387 |
388 | #define MSFilterLibrary "Filter:Library"
389 | #define MSFilterExecutable "Filter:Executable"
390 |
391 | #define MSConfig(name, value) \
392 | extern const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection = name "=" value;
393 |
394 | #ifdef __cplusplus
395 | #define MSInitialize \
396 | static void _MSInitialize(void); \
397 | namespace { static class $MSInitialize { public: _finline $MSInitialize() { \
398 | _MSInitialize(); \
399 | } } $MSInitialize; } \
400 | static void _MSInitialize()
401 | #else
402 | #define MSInitialize \
403 | __attribute__((__constructor__)) static void _MSInitialize(void)
404 | #endif
405 |
406 | #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation"
407 | #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit"
408 | #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"
409 | #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit"
410 |
411 | #endif//SUBSTRATE_H_
412 |
--------------------------------------------------------------------------------