├── 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
│ │ ├── java
│ │ │ ├── org
│ │ │ │ └── chickenhook
│ │ │ │ │ └── chickenbinder
│ │ │ │ │ ├── AppListener.java
│ │ │ │ │ ├── MainActivity.java
│ │ │ │ │ └── MainActivityKotlin.kt
│ │ │ └── com
│ │ │ │ └── android
│ │ │ │ └── server
│ │ │ │ └── wm
│ │ │ │ └── ActivityRecord.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── org
│ │ │ └── chickenhook
│ │ │ └── chickenbinder
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── org
│ │ └── chickenhook
│ │ └── chickenbinder
│ │ └── MainActivityTest.kt
├── proguard-rules.pro
└── build.gradle
├── binderhooks
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── org
│ │ │ │ └── chickenhook
│ │ │ │ └── binderhooks
│ │ │ │ ├── Logger.java
│ │ │ │ ├── proxyListeners
│ │ │ │ └── ProxyListener.java
│ │ │ │ ├── ProxyHook.java
│ │ │ │ ├── ParcelEditor.java
│ │ │ │ ├── BinderListener.java
│ │ │ │ ├── BinderHook.java
│ │ │ │ └── ServiceHooks.java
│ │ └── cpp
│ │ │ └── chickenbinder.cc
│ ├── test
│ │ └── java
│ │ │ └── org
│ │ │ └── chickenhook
│ │ │ └── binderhooks
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── org
│ │ └── chickenhook
│ │ └── binderhooks
│ │ └── ServiceHooksTest.java
├── proguard-rules.pro
├── build.gradle
└── CMakeLists.txt
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .github
└── FUNDING.yml
├── gradle.properties
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/binderhooks/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/binderhooks/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='ChickenBinder'
2 | include ':app'
3 | include ':binderhooks'
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ChickenBinder
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/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/ChickenHook/BinderHook/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/ChickenHook/BinderHook/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/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/binderhooks/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChickenHook/BinderHook/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 02 13:08:16 CEST 2020
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-5.6.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 |
--------------------------------------------------------------------------------
/app/src/main/java/org/chickenhook/chickenbinder/AppListener.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.chickenbinder;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.util.Log;
7 |
8 | public class AppListener extends BroadcastReceiver {
9 | @Override
10 | public void onReceive(Context context, Intent intent) {
11 | Log.d("AppListener", "App is going to be removed!");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/test/java/org/chickenhook/chickenbinder/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package org.chickenhook.chickenbinder
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/Logger.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.util.Log;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | public class Logger {
8 |
9 | public static void log(@NonNull String message) {
10 | Log.i("BinderHook", message);
11 | }
12 |
13 | public static void log(@NonNull String message, @NonNull Exception exception) {
14 | Log.i("BinderHook", message, exception);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/binderhooks/src/test/java/org/chickenhook/binderhooks/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
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 | }
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/proxyListeners/ProxyListener.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks.proxyListeners;
2 |
3 | import java.lang.reflect.InvocationHandler;
4 | import java.lang.reflect.Method;
5 |
6 | /**
7 | * Listener for interface hooking
8 | */
9 | public abstract class ProxyListener implements InvocationHandler {
10 |
11 | private Object obj;
12 |
13 | public void setObject(Object obj) {
14 | this.obj = obj;
15 | }
16 |
17 | @Override
18 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
19 | return invoke(obj, proxy, method, args);
20 | }
21 |
22 | public abstract Object invoke(Object original, Object proxy, Method method, Object[] args) throws Throwable;
23 | }
24 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/binderhooks/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 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 | custom: ['https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8UH5MBVYM3J36', 'bc1qvll2mp5ndwd4sgycu4ad2ken4clhjac7mdlcaj']
14 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/chickenhook/chickenbinder/MainActivityTest.kt:
--------------------------------------------------------------------------------
1 | package org.chickenhook.chickenbinder
2 |
3 | import androidx.test.espresso.Espresso.onView
4 | import androidx.test.espresso.action.ViewActions.click
5 | import androidx.test.espresso.matcher.ViewMatchers.withId
6 | import androidx.test.rule.ActivityTestRule
7 | import org.junit.Rule
8 | import org.junit.Test
9 |
10 | class MainActivityTest {
11 |
12 | @Rule
13 | @JvmField
14 | val activityTestRule = ActivityTestRule(MainActivityKotlin::class.java)
15 |
16 | @Test
17 | fun crashAndroidAPI29() {
18 | onView(withId(R.id.permissionTest)).perform(click())
19 | }
20 |
21 |
22 | @Test
23 | fun harmFulAppWarning() {
24 | onView(withId(R.id.packageManagerTest)).perform(click())
25 | }
26 |
27 | @Test
28 | fun windowManagerTest() {
29 | onView(withId(R.id.windowManagerTest)).perform(click())
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/ProxyHook.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.annotation.Nullable;
7 |
8 | import org.chickenhook.binderhooks.proxyListeners.ProxyListener;
9 |
10 | import java.lang.reflect.Field;
11 | import java.lang.reflect.Proxy;
12 |
13 | import static org.chickenhook.binderhooks.Logger.log;
14 |
15 | public class ProxyHook {
16 |
17 | public static boolean addHook(@Nullable Object host, @NonNull Field field, @NonNull Class> type, @NonNull ProxyListener proxyListener) throws IllegalAccessException {
18 | proxyListener.setObject(field.get(host));
19 | Object proxy = Proxy.newProxyInstance(Context.class.getClassLoader(), new Class[]{type}, proxyListener);
20 | try {
21 | field.set(host, proxy);
22 | log("ProxyHook [-] successfully added hook for <" + type + ">");
23 | return true;
24 | } catch (IllegalAccessException e) {
25 | log("ProxyHook [-] error while place proxy hook", e);
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
22 |
28 |
29 |
35 |
36 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | applicationId "org.chickenhook.chickenbinder"
11 | minSdkVersion 19
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation 'com.github.ChickenHook:RestrictionBypass:2.2'
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | implementation 'androidx.appcompat:appcompat:1.1.0'
33 | implementation 'androidx.core:core-ktx:1.2.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | implementation project(':binderhooks')
36 | testImplementation 'junit:junit:4.12'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
39 | androidTestImplementation 'androidx.test:rules:1.2.0'
40 | }
41 |
--------------------------------------------------------------------------------
/binderhooks/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group = 'com.github.ChickenHook'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | externalNativeBuild {
17 | cmake {
18 | cppFlags "-std=c++14"
19 | }
20 | }
21 | ndk {
22 | abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
23 | }
24 | consumerProguardFiles 'consumer-rules.pro'
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | externalNativeBuild {
34 | cmake {
35 | path "CMakeLists.txt"
36 | version "3.6.0"
37 | }
38 | }
39 |
40 | }
41 |
42 | dependencies {
43 | implementation fileTree(dir: 'libs', include: ['*.jar'])
44 | implementation 'com.github.ChickenHook:RestrictionBypass:2.2'
45 | implementation 'androidx.appcompat:appcompat:1.1.0'
46 | testImplementation 'junit:junit:4.12'
47 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
49 | }
50 |
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/ParcelEditor.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.os.Parcel;
4 |
5 | import androidx.annotation.NonNull;
6 |
7 | import static org.chickenhook.restrictionbypass.helpers.Reflection.getReflective;
8 |
9 | public class ParcelEditor {
10 |
11 | static long getNativePtr(@NonNull Parcel parcel) throws NoSuchFieldException, IllegalAccessException {
12 | return getReflective(parcel, "mNativePtr");
13 | }
14 |
15 | public static void dump(@NonNull Parcel parcel) throws NoSuchFieldException, IllegalAccessException {
16 | long parcel_pointer = getNativePtr(parcel);
17 | dump(parcel_pointer, parcel.dataSize());
18 | }
19 |
20 | public static native void dump(long addr, int size);
21 |
22 | public static byte[] read(@NonNull Parcel parcel, int offset, int size) throws NoSuchFieldException, IllegalAccessException {
23 | long parcel_pointer = getNativePtr(parcel);
24 | return read(parcel_pointer, offset, size);
25 | }
26 |
27 | public static native byte[] read(long addr, int offset, int size);
28 |
29 | public static void write(@NonNull Parcel parcel, int offset, @NonNull byte[] data) throws NoSuchFieldException, IllegalAccessException {
30 | long parcel_pointer = getNativePtr(parcel);
31 | write(parcel_pointer, offset, data);
32 | }
33 |
34 | public static native void write(long addr, int offset, @NonNull byte[] data);
35 |
36 | static {
37 | System.loadLibrary("chickenbinder");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/binderhooks/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.4.1)
7 |
8 | # Creates and names a library, sets it as either STATIC
9 | # or SHARED, and provides the relative paths to its source code.
10 | # You can define multiple libraries, and CMake builds them for you.
11 | # Gradle automatically packages shared libraries with your APK.
12 |
13 | add_library( # Sets the name of the library.
14 | chickenbinder
15 |
16 | # Sets the library as a shared library.
17 | SHARED
18 |
19 | # Provides a relative path to your source file(s).
20 | src/main/cpp/chickenbinder.cc)
21 |
22 |
23 | # Searches for a specified prebuilt library and stores the path as a
24 | # variable. Because CMake includes system libraries in the search path by
25 | # default, you only need to specify the name of the public NDK library
26 | # you want to add. CMake verifies that the library exists before
27 | # completing its build.
28 |
29 | find_library( # Sets the name of the path variable.
30 | log-lib
31 |
32 | # Specifies the name of the NDK library that
33 | # you want CMake to locate.
34 | log)
35 |
36 | # Specifies libraries CMake should link to your target library. You
37 | # can link multiple libraries, such as libraries you define in this
38 | # build script, prebuilt third-party libraries, or system libraries.
39 |
40 |
41 | target_link_libraries( # Specifies the target library.
42 | chickenbinder
43 | # Links the target library to the log library
44 | # included in the NDK.
45 | ${log-lib})
46 |
47 | target_include_directories(chickenbinder PRIVATE
48 | )
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/BinderListener.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.os.IBinder;
4 | import android.os.IInterface;
5 | import android.os.Parcel;
6 | import android.os.RemoteException;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.annotation.Nullable;
10 |
11 | import java.io.FileDescriptor;
12 |
13 | public abstract class BinderListener {
14 | @Nullable
15 | protected String getInterfaceDescriptor(@NonNull IBinder originalBinder) throws RemoteException {
16 | return originalBinder.getInterfaceDescriptor();
17 | }
18 |
19 | protected boolean pingBinder(@NonNull IBinder originalBinder) {
20 | return originalBinder.pingBinder();
21 | }
22 |
23 | protected boolean isBinderAlive(@NonNull IBinder originalBinder) {
24 | return originalBinder.isBinderAlive();
25 | }
26 |
27 | @Nullable
28 | protected IInterface queryLocalInterface(@NonNull IBinder originalBinder, @NonNull String descriptor) {
29 | return originalBinder.queryLocalInterface(descriptor);
30 | }
31 |
32 | protected void dump(@NonNull IBinder originalBinder, @NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
33 | originalBinder.dump(fd, args);
34 | }
35 |
36 | protected void dumpAsync(@NonNull IBinder originalBinder, @NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
37 | originalBinder.dumpAsync(fd, args);
38 | }
39 |
40 | protected abstract boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException;
41 |
42 | protected void linkToDeath(@NonNull IBinder originalBinder, @NonNull IBinder.DeathRecipient recipient, int flags) throws RemoteException {
43 | originalBinder.linkToDeath(recipient, flags);
44 | }
45 |
46 | protected boolean unlinkToDeath(@NonNull IBinder originalBinder, @NonNull IBinder.DeathRecipient recipient, int flags) {
47 | return originalBinder.unlinkToDeath(recipient, flags);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/server/wm/ActivityRecord.java:
--------------------------------------------------------------------------------
1 | package com.android.server.wm;
2 |
3 | import android.os.Binder;
4 | import android.os.IBinder;
5 | import android.os.IInterface;
6 | import android.os.Parcel;
7 | import android.os.RemoteException;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 |
12 | import java.io.FileDescriptor;
13 | import java.lang.ref.WeakReference;
14 |
15 | public class ActivityRecord {
16 |
17 |
18 | public static class Token implements IBinder {
19 | private final WeakReference weakActivity;
20 | private final String name;
21 |
22 | public Token() {
23 | name = "com.android.chrome";
24 | weakActivity = new WeakReference<>(new ActivityRecord());
25 | }
26 |
27 | @Nullable
28 | @Override
29 | public String getInterfaceDescriptor() throws RemoteException {
30 | return null;
31 | }
32 |
33 | @Override
34 | public boolean pingBinder() {
35 | return false;
36 | }
37 |
38 | @Override
39 | public boolean isBinderAlive() {
40 | return false;
41 | }
42 |
43 | @Nullable
44 | @Override
45 | public IInterface queryLocalInterface(@NonNull String descriptor) {
46 | return null;
47 | }
48 |
49 | @Override
50 | public void dump(@NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
51 |
52 | }
53 |
54 | @Override
55 | public void dumpAsync(@NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
56 |
57 | }
58 |
59 | @Override
60 | public boolean transact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
61 | return false;
62 | }
63 |
64 | @Override
65 | public void linkToDeath(@NonNull DeathRecipient recipient, int flags) throws RemoteException {
66 |
67 | }
68 |
69 | @Override
70 | public boolean unlinkToDeath(@NonNull DeathRecipient recipient, int flags) {
71 | return false;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/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/org/chickenhook/chickenbinder/MainActivity.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.chickenbinder;
2 |
3 | import android.Manifest;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import androidx.annotation.Nullable;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.core.app.ActivityCompat;
12 |
13 | import org.chickenhook.binderhooks.ServiceHooks;
14 | import org.chickenhook.binderhooks.proxyListeners.ProxyListener;
15 |
16 | import java.lang.reflect.InvocationTargetException;
17 | import java.lang.reflect.Method;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | @Override
22 | public void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 | Button packageManagerTestButton = findViewById(R.id.packageManagerTest);
26 | Button permissionTestButton = findViewById(R.id.permissionTest);
27 | Button windowManagerTestButton = findViewById(R.id.windowManagerTest);
28 |
29 | permissionTestButton.setOnClickListener(new View.OnClickListener() {
30 | @Override
31 | public void onClick(View v) {
32 | ActivityCompat.requestPermissions(
33 | MainActivity.this,
34 | new String[]{
35 | Manifest.permission.READ_CONTACTS
36 | },
37 | 1001
38 | );
39 | }
40 | });
41 |
42 | try {
43 | hook();
44 | } catch (Exception e) {
45 | Log.e("MainActivity", "Error while install hooks", e);
46 | }
47 | }
48 |
49 | private static final int START_FLAG_NATIVE_DEBUGGING = 1 << 1;
50 | private static final int START_FLAG_DEBUG = 1 << 1;
51 | private static final int START_FLAG_TRACK_ALLOCATION = 1 << 2;
52 |
53 | private void hook() throws InvocationTargetException, NoSuchMethodException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
54 | ServiceHooks.hookActivityManager(new ProxyListener() {
55 | @Override
56 | public Object invoke(Object orig, Object proxy, Method method, Object[] args) throws Throwable {
57 | if (method.getName().equals("startActivity") && args.length == 10) {
58 | args[args.length - 3] = ((int) args[args.length - 3]) |
59 | START_FLAG_DEBUG |
60 | START_FLAG_TRACK_ALLOCATION |
61 | START_FLAG_NATIVE_DEBUGGING;
62 | }
63 | return method.invoke(orig, args);
64 | }
65 | });
66 |
67 |
68 | ServiceHooks.hookActivityTaskManager(new ProxyListener() {
69 | @Override
70 | public Object invoke(Object orig, Object proxy, Method method, Object[] args) throws Throwable {
71 | if (method.getName().equals("startActivity") && args.length == 10) {
72 | args[args.length - 3] = ((int) args[args.length - 3]) |
73 | START_FLAG_DEBUG |
74 | START_FLAG_TRACK_ALLOCATION |
75 | START_FLAG_NATIVE_DEBUGGING;
76 | }
77 | return method.invoke(orig, args);
78 | }
79 | });
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/binderhooks/src/androidTest/java/org/chickenhook/binderhooks/ServiceHooksTest.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.app.AppOpsManager;
4 | import android.app.NotificationManager;
5 | import android.content.Context;
6 | import android.os.IBinder;
7 | import android.os.Parcel;
8 | import android.os.RemoteException;
9 | import android.system.Os;
10 |
11 | import androidx.annotation.NonNull;
12 | import androidx.annotation.Nullable;
13 | import androidx.test.platform.app.InstrumentationRegistry;
14 |
15 | import org.junit.Test;
16 |
17 | import static junit.framework.TestCase.assertTrue;
18 |
19 | public class ServiceHooksTest {
20 |
21 | @Test
22 | public void hookContentResolver() throws Exception {
23 | InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver(); // let android establish a connection to the service first
24 |
25 |
26 | assertTrue(ServiceHooks.hookContentResolver(new BinderListener() {
27 | @Override
28 | protected boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
29 | return originalBinder.transact(code, data, reply, flags);
30 | }
31 | }));
32 | }
33 |
34 | @Test
35 | public void hookNotificationManager() throws Exception {
36 | NotificationManager notificationManager = (NotificationManager) InstrumentationRegistry.getInstrumentation().getTargetContext().getSystemService(Context.NOTIFICATION_SERVICE);
37 | notificationManager.cancelAll(); // let android establish a connection to the service first
38 |
39 |
40 | assertTrue(ServiceHooks.hookNotificationManager(new BinderListener() {
41 | @Override
42 | protected boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
43 | return originalBinder.transact(code, data, reply, flags);
44 | }
45 | }));
46 | }
47 |
48 | @Test
49 | public void hookActivityManager() throws Exception {
50 | assertTrue(ServiceHooks.hookActivityManager(new BinderListener() {
51 | @Override
52 | protected boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
53 | return originalBinder.transact(code, data, reply, flags);
54 | }
55 | }));
56 | }
57 |
58 | @Test
59 | public void hookAppOpsManager() throws Exception {
60 | AppOpsManager appOpsManager = (AppOpsManager) InstrumentationRegistry.getInstrumentation().getTargetContext().getSystemService(Context.APP_OPS_SERVICE);
61 | appOpsManager.checkPackage(Os.getuid(), InstrumentationRegistry.getInstrumentation().getContext().getPackageName()); // let android establish a connection to the service first
62 |
63 |
64 | assertTrue(ServiceHooks.hookAppOpsManager(appOpsManager, new BinderListener() {
65 | @Override
66 | protected boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
67 | return originalBinder.transact(code, data, reply, flags);
68 | }
69 | }));
70 | }
71 |
72 | @Test
73 | public void hookPackageManager() throws Exception {
74 | assertTrue(ServiceHooks.hookPackageManager(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager(), new BinderListener() {
75 | @Override
76 | protected boolean transact(@NonNull IBinder originalBinder, int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
77 | return originalBinder.transact(code, data, reply, flags);
78 | }
79 | }));
80 | }
81 | }
--------------------------------------------------------------------------------
/binderhooks/src/main/cpp/chickenbinder.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | ///////////////////////// HELPERS
10 |
11 | void printHexBuffer2(const uint8_t *buf, int len) {
12 | char *str_buf = (char *) malloc(
13 | 3 * len + 1); // X is the number of bytes to be converted
14 |
15 | const uint8_t *pin = buf;
16 | const char *hex = "0123456789ABCDEF";
17 | char *pout = str_buf;
18 | int i = 0;
19 | for (; i < len - 1; ++i) {
20 | *pout++ = hex[(*pin >> 4) & 0xF];
21 | *pout++ = hex[(*pin++) & 0xF];
22 | *pout++ = ':';
23 | }
24 | *pout++ = hex[(*pin >> 4) & 0xF];
25 | *pout++ = hex[(*pin) & 0xF];
26 | *pout = 0;
27 |
28 | __android_log_print(ANDROID_LOG_DEBUG, "parcel", "%s", str_buf);
29 | free(str_buf);
30 | }
31 |
32 | // Log a large byte array by logging it incrementally in smaller chunks to overcome printf buffering issues
33 | void printHexBuffer(const char *title, const uint8_t *buf, unsigned int len) {
34 | __android_log_print(ANDROID_LOG_DEBUG, "parcel", "%s (%d bytes):", title, len);
35 | const int linewidth = 50;
36 | int loop = 0;
37 | int remainingSize = len;
38 |
39 | while (len != 0) {
40 | if (remainingSize < linewidth) {
41 | printHexBuffer2(&buf[loop * linewidth], remainingSize);
42 | break;
43 | } else {
44 | printHexBuffer2(&buf[loop * linewidth], linewidth);
45 | remainingSize -= linewidth;
46 | }
47 | loop++;
48 | }
49 | }
50 |
51 | void printHexBuffer(const uint8_t *buf, unsigned int len) {
52 | printHexBuffer("HEX", buf, len);
53 | }
54 |
55 | ///////////////////////// PARCEL
56 |
57 |
58 | uint8_t *GetData(jlong parcel_addr) {
59 | void **parcel = (void **) parcel_addr;
60 |
61 | /*for (int i = 0; i < 5; i++) {
62 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder", "Got parcel content <%p>",
63 | parcel[i]);
64 | }*/
65 | return static_cast(parcel[1]);
66 | }
67 |
68 | void JNICALL writeParcel(JNIEnv *env,
69 | jclass interface,
70 | jlong parcelAddr,
71 | int offset,
72 | jbyteArray toInsert) {
73 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder", "write parcel <%p>", parcelAddr);
74 | uint8_t *data = GetData(parcelAddr);
75 | env->GetByteArrayRegion(toInsert, 0, env->GetArrayLength(toInsert),
76 | reinterpret_cast(data + offset));
77 | }
78 |
79 |
80 | jobject JNICALL readParcel(JNIEnv *env,
81 | jclass interface,
82 | jlong parcelAddr,
83 | int offset,
84 | int size) {
85 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder", "read parcel <%p>", parcelAddr);
86 | uint8_t *data = GetData(parcelAddr);
87 | jbyteArray jarr = env->NewByteArray(size);
88 | env->SetByteArrayRegion(jarr, 0, size, reinterpret_cast(data + offset));
89 | return jarr;
90 | }
91 |
92 | static JNICALL void dumpParcel(
93 | JNIEnv *env,
94 | jclass interface,
95 | jlong parcelAddr,
96 | int size) {
97 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder", "dump parcel <%p>", parcelAddr);
98 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder",
99 | "---------------------------------------------------------------------------------------------------------------------------------------------");
100 |
101 |
102 | uint8_t *data = GetData(parcelAddr);
103 | printHexBuffer(data, size);
104 | __android_log_print(ANDROID_LOG_DEBUG, "chickenbinder",
105 | "---------------------------------------------------------------------------------------------------------------------------------------------");
106 | }
107 |
108 |
109 |
110 | ////////// JNI STUFF
111 |
112 |
113 | static const JNINativeMethod gMethods[] = {
114 | /*{"manipulateParcel", "(JII)J", (void *) manipulateParcel},
115 | {"readAddr", "()Ljava/lang/String;", (void *) Java_readAddr},*/
116 | {"dump", "(JI)V", (void *) &dumpParcel},
117 | {"read", "(JII)[B", (void *) &readParcel},
118 | {"write", "(JI[B)V", (void *) &writeParcel},
119 | };
120 | static const char *classPathName = "org/chickenhook/binderhooks/ParcelEditor";
121 |
122 | static int registerNativeMethods(JNIEnv *env, const char *className,
123 | JNINativeMethod *gMethods, int numMethods) {
124 | jclass clazz;
125 | clazz = env->FindClass(className);
126 | if (clazz == nullptr) {
127 | __android_log_print(ANDROID_LOG_DEBUG, "registerNativeMethods",
128 | "Native registration unable to find class '%s'", className);
129 | return JNI_FALSE;
130 | }
131 | if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
132 | __android_log_print(ANDROID_LOG_DEBUG, "registerNativeMethods",
133 | "Native registration unable to register natives...");
134 | return JNI_FALSE;
135 | }
136 | return JNI_TRUE;
137 | }
138 |
139 | jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
140 | JNIEnv *env = nullptr;
141 |
142 | if (vm->GetEnv((void **) (&env), JNI_VERSION_1_4) != JNI_OK) {
143 | return -1;
144 | }
145 |
146 |
147 | if (!registerNativeMethods(env, classPathName,
148 | (JNINativeMethod *) gMethods,
149 | sizeof(gMethods) / sizeof(gMethods[0]))) {
150 | return -1;
151 | }
152 | return JNI_VERSION_1_4;
153 | }
--------------------------------------------------------------------------------
/binderhooks/src/main/java/org/chickenhook/binderhooks/BinderHook.java:
--------------------------------------------------------------------------------
1 | package org.chickenhook.binderhooks;
2 |
3 | import android.os.IBinder;
4 | import android.os.IInterface;
5 | import android.os.Parcel;
6 | import android.os.RemoteException;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.annotation.Nullable;
10 |
11 | import java.io.FileDescriptor;
12 |
13 | import static org.chickenhook.binderhooks.Logger.log;
14 | import static org.chickenhook.restrictionbypass.helpers.Reflection.getReflective;
15 | import static org.chickenhook.restrictionbypass.helpers.Reflection.setReflective;
16 |
17 | public class BinderHook {
18 |
19 | public static boolean VERBOSE = false;
20 |
21 |
22 | /**
23 | * Add a binder hook for the given binder proxy
24 | *
25 | * @param binderProxy to be hooked
26 | * @param binderListener will be called for different binder interactions
27 | * @return true on success
28 | * @throws NoSuchFieldException if mRemote is not available
29 | * @throws IllegalAccessException if mRemote field cannot be accessed
30 | */
31 | public static boolean addHook(@Nullable Object binderProxy, @Nullable BinderListener binderListener) throws NoSuchFieldException, IllegalAccessException {
32 | if (binderProxy == null) {
33 | log("Unable to addHook - given binderProxy is null");
34 | return false;
35 | }
36 |
37 | if (binderListener == null) {
38 | log("Unable to addHook - given onBinderListener is null");
39 | return false;
40 | }
41 |
42 | /*for (Method m : binderProxy.getClass().getMethods()) {
43 | if (VERBOSE) log(binderProxy.getClass().getCanonicalName() + " Found method " + m);
44 | }*/
45 |
46 | IBinder mRemote = getReflective(binderProxy, "mRemote");
47 | if (mRemote == null) {
48 | log("Unable to addHook - retrieved mRemote is null");
49 | return false;
50 | }
51 |
52 | IBinder fakeBinder = new FakeBinder(binderProxy.getClass().getName(), mRemote, binderListener);
53 | setReflective(binderProxy, "mRemote", fakeBinder);
54 | log("Successfully added hook for <" + binderProxy.getClass().getName() + ">");
55 | return true;
56 | }
57 |
58 | public static class FakeBinder implements IBinder {
59 |
60 | private @NonNull
61 | BinderListener mBinderListener;
62 | private @NonNull
63 | IBinder mOriginalBinder;
64 | private @NonNull
65 | String mName;
66 |
67 | public FakeBinder(@NonNull String name, @NonNull IBinder originalBinder, @NonNull BinderListener binderListener) {
68 | mName = name;
69 | mOriginalBinder = originalBinder;
70 | mBinderListener = binderListener;
71 | }
72 |
73 |
74 | @Nullable
75 | @Override
76 | public String getInterfaceDescriptor() throws RemoteException {
77 | return mBinderListener.getInterfaceDescriptor(mOriginalBinder);
78 | }
79 |
80 | @Override
81 | public boolean pingBinder() {
82 | return mBinderListener.pingBinder(mOriginalBinder);
83 | }
84 |
85 | @Override
86 | public boolean isBinderAlive() {
87 | return mBinderListener.isBinderAlive(mOriginalBinder);
88 | }
89 |
90 | @Nullable
91 | @Override
92 | public IInterface queryLocalInterface(@NonNull String descriptor) {
93 | return mBinderListener.queryLocalInterface(mOriginalBinder, descriptor);
94 | }
95 |
96 | @Override
97 | public void dump(@NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
98 | mBinderListener.dump(mOriginalBinder, fd, args);
99 | }
100 |
101 | @Override
102 | public void dumpAsync(@NonNull FileDescriptor fd, @Nullable String[] args) throws RemoteException {
103 | mBinderListener.dumpAsync(mOriginalBinder, fd, args);
104 | }
105 |
106 | @Override
107 | public boolean transact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) throws RemoteException {
108 | if (VERBOSE) {
109 | try {
110 | log("Got transact call code: <" + code + "> data: <" + data + "> reply: <" + reply + "> flags: <" + flags + ">");
111 | doStackTrace();
112 | ParcelEditor.dump(data);
113 | } catch (Exception e) {
114 | log("Error while dump parcel", e);
115 | }
116 | }
117 | boolean res = mBinderListener.transact(mOriginalBinder, code, data, reply, flags);
118 | if (VERBOSE) {
119 | try {
120 | if (reply != null) {
121 | log("Got reply call code: <" + code + "> data: <" + data + "> reply: <" + reply + "> flags: <" + flags + ">");
122 | ParcelEditor.dump(reply);
123 | }
124 | } catch (Exception e) {
125 | log("Error while dump parcel", e);
126 | }
127 | }
128 | return res;
129 | }
130 |
131 | @Override
132 | public void linkToDeath(@NonNull DeathRecipient recipient, int flags) throws RemoteException {
133 | mBinderListener.linkToDeath(mOriginalBinder, recipient, flags);
134 | }
135 |
136 | @Override
137 | public boolean unlinkToDeath(@NonNull DeathRecipient recipient, int flags) {
138 | return mBinderListener.unlinkToDeath(mOriginalBinder, recipient, flags);
139 | }
140 | }
141 |
142 | static void doStackTrace() {
143 | try {
144 | throw new Exception("Trace");
145 | } catch (Exception e) {
146 | log("ProxyHook [+] trace [+] ", e);
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/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/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/org/chickenhook/chickenbinder/MainActivityKotlin.kt:
--------------------------------------------------------------------------------
1 | package org.chickenhook.chickenbinder
2 |
3 | import android.Manifest
4 | import android.os.Binder
5 | import android.os.Bundle
6 | import android.os.IBinder
7 | import android.os.Parcel
8 | import android.text.TextUtils
9 | import android.util.Log
10 | import android.widget.Button
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.core.app.ActivityCompat
13 | import org.chickenhook.binderhooks.BinderHook
14 | import org.chickenhook.binderhooks.BinderListener
15 | import org.chickenhook.binderhooks.Logger.log
16 | import org.chickenhook.binderhooks.ServiceHooks
17 |
18 |
19 | class MainActivityKotlin : AppCompatActivity() {
20 |
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContentView(R.layout.activity_main)
25 | addHooks()
26 | findViewById