├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── scuzoutao
│ │ └── androidsimplehook
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ └── res
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── ic_launcher_foreground.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── values-night
│ │ └── themes.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ │ └── xml
│ │ ├── backup_rules.xml
│ │ └── data_extraction_rules.xml
│ └── test
│ └── java
│ └── com
│ └── scuzoutao
│ └── androidsimplehook
│ └── ExampleUnitTest.kt
├── build.gradle
├── buildSrc
├── build.gradle
└── src
│ └── main
│ └── kotlin
│ └── com
│ └── hook
│ └── sample
│ └── transformers
│ ├── MMHook.kt
│ ├── MMHookConfig.kt
│ └── MMHookTransformer.kt
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── tools
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
└── java
└── com
└── hook
└── sample
└── instrument
└── ShadowPrivacyApi.java
/.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 | local.properties
16 | .idea/
17 | build
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidSimpleHook
2 | 基于滴滴Booster项目的 Transform API 进行二次开发,封装成易于使用的 Hook 框架,让你敲最少的代码完成自定义的 Hook 操作
3 |
4 | # hook 框架实现
5 | hook 框架的实现依托于 booster 封装的 api,相应代码在 buildSrc 中,同时 hookConfig 的配置也是在 buildSrc 中进行配置,至于 hook 后的目标方法,跟 hookConfig 保持一致就行
6 |
7 | # 示例功能
8 | 1. 配置化的方法 hook ( done )
9 | 2. 配置化的 try-catch 工具( doing )
10 | 3. plugin化,使用只需要 apply plugin + 配置配置文件 ( doing )
11 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | namespace 'com.scuzoutao.androidsimplehook'
8 | compileSdk 33
9 |
10 | defaultConfig {
11 | applicationId "com.scuzoutao.androidsimplehook"
12 | minSdk 24
13 | targetSdk 33
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | }
33 | }
34 |
35 | dependencies {
36 |
37 | implementation 'androidx.core:core-ktx:1.9.0'
38 | implementation 'androidx.appcompat:appcompat:1.6.1'
39 | implementation 'com.google.android.material:material:1.10.0'
40 | testImplementation 'junit:junit:4.13.2'
41 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
42 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
43 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/scuzoutao/androidsimplehook/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.scuzoutao.androidsimplehook
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.scuzoutao.androidsimplehook", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
15 |
16 |
--------------------------------------------------------------------------------
/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/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidSimpleHook
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/scuzoutao/androidsimplehook/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.scuzoutao.androidsimplehook
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id 'com.android.application' version '7.2.2' apply false
4 | id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
5 | }
--------------------------------------------------------------------------------
/buildSrc/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlinVersion = '1.8.10'
3 | ext.boosterVersion = '4.15.0'
4 | repositories {
5 |
6 | google()
7 | mavenCentral()
8 | maven {
9 | allowInsecureProtocol = true
10 | url "http://nexus:8081/repository/android-public/"
11 | }
12 | maven { url 'https://jitpack.io' }
13 | }
14 | dependencies {
15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
16 | }
17 | }
18 |
19 | apply plugin: 'java'
20 | apply plugin: 'maven-publish'
21 | apply plugin: 'kotlin'
22 | apply plugin: 'kotlin-kapt'
23 |
24 | repositories {
25 |
26 | google()
27 | mavenCentral()
28 | maven {
29 | allowInsecureProtocol = true
30 | url "http://nexus:8081/repository/android-public/"
31 | }
32 | maven { url 'https://jitpack.io' }
33 | }
34 |
35 | dependencies {
36 | implementation gradleApi()
37 | implementation localGroovy()
38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
39 | implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
40 | testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
41 | testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
42 | kapt "com.google.auto.service:auto-service:1.0"
43 |
44 | implementation "com.didiglobal.booster:booster-task-spi:$boosterVersion"
45 | implementation "com.didiglobal.booster:booster-transform-asm:$boosterVersion"
46 | implementation "com.didiglobal.booster:booster-android-instrument:$boosterVersion"
47 | implementation "com.didiglobal.booster:booster-android-api:$boosterVersion"
48 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/com/hook/sample/transformers/MMHook.kt:
--------------------------------------------------------------------------------
1 | package com.hook.sample.transformers
2 |
3 | import org.objectweb.asm.tree.MethodInsnNode
4 |
5 | /**
6 | * @description
7 | * @author zoutao
8 | * @since 2023/2/9 星期四 14:52
9 | */
10 |
11 | class HookConfig(val hookClassList: List)
12 |
13 | data class HookClass(
14 | val needHookClass: String,
15 | val afterHookClass: String,
16 | val hookMethods: List,
17 | val doNotHookPackages: List = emptyList()
18 | ) {
19 | constructor(
20 | needHookClass: String,
21 | afterHookClass: String,
22 | hookMethod: HookMethod,
23 | doNotHookPackages: List = emptyList()
24 | ) : this(
25 | needHookClass,
26 | afterHookClass,
27 | listOf(hookMethod),
28 | doNotHookPackages
29 | )
30 | }
31 |
32 | data class HookMethod(
33 | val methodName: String,
34 | val methodDesc: String = "",
35 | val methodFilter: ((methodNode: MethodInsnNode) -> Boolean) = { _ -> true },
36 | )
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/com/hook/sample/transformers/MMHookConfig.kt:
--------------------------------------------------------------------------------
1 | package com.hook.sample.transformers
2 |
3 | val hookConfig = HookConfig(
4 | listOf(
5 | HookClass(
6 | needHookClass = "android/app/ActivityManager",
7 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
8 | hookMethod = HookMethod(methodName = "getRunningAppProcesses")
9 | ),
10 | HookClass(
11 | needHookClass = "android/bluetooth/BluetoothAdapter",
12 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
13 | hookMethod = HookMethod(methodName = "getBondedDevices")
14 | ),
15 | HookClass(
16 | needHookClass = "android/location/LocationManager",
17 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
18 | hookMethods = listOf(
19 | HookMethod(methodName = "getLastLocation"),
20 | HookMethod(methodName = "getLastKnownLocation"),
21 | HookMethod(
22 | methodName = "requestLocationUpdates",
23 | methodFilter = { methodNode -> !methodNode.desc.contains("LocationRequest") }
24 | ),
25 | HookMethod("requestSingleUpdate")
26 | )
27 | ),
28 | HookClass(
29 | needHookClass = "java/net/NetworkInterface",
30 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
31 | hookMethods = listOf(
32 | HookMethod(methodName = "getNetworkInterfaces"),
33 | HookMethod(methodName = "getHardwareAddress"),
34 | )
35 | ),
36 | HookClass(
37 | needHookClass = "android/content/pm/PackageManager",
38 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
39 | hookMethods = listOf(
40 | HookMethod(methodName = "getInstalledPackages"),
41 | HookMethod(methodName = "getInstalledApplications"),
42 | HookMethod(methodName = "queryIntentActivities"),
43 | HookMethod(methodName = "getPackagesForUid"),
44 | )
45 | ),
46 | HookClass(
47 | needHookClass = "java/lang/Runtime",
48 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
49 | hookMethod = HookMethod(methodName = "exec"),
50 | ),
51 | HookClass(
52 | needHookClass = "android/hardware/SensorManager",
53 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
54 | hookMethods = listOf(
55 | HookMethod(
56 | methodName = "getDefaultSensor",
57 | methodDesc = "(I)Landroid/hardware/Sensor;"
58 | ),
59 | HookMethod(methodName = "registerListener"),
60 | )
61 | ),
62 | HookClass(
63 | needHookClass = "android/provider/Settings\$System",
64 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
65 | hookMethod = HookMethod(methodName = "getString")
66 | ),
67 | HookClass(
68 | needHookClass = "android/telephony/TelephonyManager",
69 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
70 | hookMethods = listOf(
71 | HookMethod(methodName = "getDeviceId"),
72 | HookMethod(methodName = "getLine1Number"),
73 | HookMethod(methodName = "getSubscriberId"),
74 | HookMethod(methodName = "getMeid"),
75 | HookMethod(methodName = "listen"),
76 | HookMethod(methodName = "getSimSerialNumber"),
77 | HookMethod(methodName = "getManufacturerCode")
78 | )
79 | ),
80 | HookClass(
81 | needHookClass = "android/net/wifi/WifiManager",
82 | afterHookClass = "com/hook/sample/instrument/ShadowPrivacyApi",
83 | hookMethods = listOf(
84 | HookMethod(methodName = "getConnectionInfo"),
85 | )
86 | )
87 | )
88 | )
89 |
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/com/hook/sample/transformers/MMHookTransformer.kt:
--------------------------------------------------------------------------------
1 | package com.hook.sample.transformers
2 |
3 | import com.didiglobal.booster.kotlinx.asIterable
4 | import com.didiglobal.booster.transform.TransformContext
5 | import com.didiglobal.booster.transform.asm.ClassTransformer
6 | import com.google.auto.service.AutoService
7 | import org.objectweb.asm.Opcodes
8 | import org.objectweb.asm.tree.ClassNode
9 | import org.objectweb.asm.tree.MethodInsnNode
10 |
11 | /**
12 | * @description
13 | * @author zoutao
14 | * @since 2023/2/9 星期四 14:53
15 | */
16 | @AutoService(ClassTransformer::class)
17 | class MMHookTransformer : ClassTransformer {
18 | override fun transform(context: TransformContext, klass: ClassNode): ClassNode {
19 | klass.methods.forEach { method ->
20 | method.instructions?.iterator()?.asIterable()
21 | ?.filterIsInstance(MethodInsnNode::class.java)?.let { methodInsnNode ->
22 | for (i in methodInsnNode.indices) {
23 | val methodNode = methodInsnNode[i]
24 | //检查owner,先匹配当前方法调用的 owner,根据 owner 找到 HookClass,找不到则说明不需要hook
25 | val hookClass = hookConfig.hookClassList.firstOrNull {
26 | //1. owner要匹配,2. 当前处理的 class 不能是 afterHookClass,3. 当前处理的 class 不能在过滤的包中
27 | (methodNode.owner == it.needHookClass || context.klassPool[it.needHookClass].isAssignableFrom(
28 | methodNode.owner
29 | )) &&
30 | klass.name != it.afterHookClass &&
31 | it.doNotHookPackages.none { doNotHookPackage ->
32 | klass.name.startsWith(
33 | doNotHookPackage
34 | )
35 | }
36 | }
37 | hookClass ?: continue
38 |
39 | //检查方法类型不匹配,https://blog.csdn.net/LuoZheng4698729/article/details/104971966
40 | if (methodNode.opcode != Opcodes.INVOKESTATIC && methodNode.opcode != Opcodes.INVOKEVIRTUAL && methodNode.opcode != Opcodes.INVOKEINTERFACE) {
41 | continue
42 | }
43 |
44 | //检查方法名、方法描述不匹配,或者方法名、方法描述被过滤
45 | var methodNeedHook = false
46 | for (index in hookClass.hookMethods.indices) {
47 | val hookMethod = hookClass.hookMethods[index]
48 | if (hookMethod.methodName == methodNode.name
49 | && (hookMethod.methodDesc == methodNode.desc || hookMethod.methodDesc.isEmpty())
50 | && hookMethod.methodFilter(methodNode)
51 | ) {
52 | methodNeedHook = true
53 | break
54 | }
55 | }
56 | if (!methodNeedHook) {
57 | continue
58 | }
59 |
60 | //开始hook
61 | methodNode.owner = hookClass.afterHookClass
62 | //对象方法、接口方法需要调整为static方法
63 | if (methodNode.opcode != Opcodes.INVOKESTATIC) {
64 | methodNode.desc =
65 | methodNode.desc.replace("(", "(L${hookClass.needHookClass};")
66 | }
67 | methodNode.opcode = Opcodes.INVOKESTATIC
68 | methodNode.itf = false
69 | }
70 | }
71 | }
72 | return klass
73 | }
74 | }
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scuzoutao/AndroidSimpleHook/d1e46ed3a830681fa0f32fbf6f370887d959c113/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jul 08 16:52:51 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 |
16 | rootProject.name = "AndroidSimpleHook"
17 | include ':app'
18 | include ':tools'
19 |
--------------------------------------------------------------------------------
/tools/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tools/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 |
5 | defaultConfig {
6 | ndk {
7 | abiFilters "armeabi-v7a"
8 | }
9 | }
10 |
11 | buildTypes {
12 | release {
13 | minifyEnabled false
14 | consumerProguardFiles 'proguard-rules.pro'
15 | }
16 | }
17 |
18 | }
19 |
20 | dependencies {
21 | api fileTree(dir: 'libs', include: ['*.jar'])
22 | implementation 'androidx.core:core-ktx:1.10.0'
23 | implementation 'androidx.core:core:1.10.0'
24 | implementation 'androidx.appcompat:appcompat:1.6.1'
25 | }
26 |
--------------------------------------------------------------------------------
/tools/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 |
--------------------------------------------------------------------------------
/tools/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/tools/src/main/java/com/hook/sample/instrument/ShadowPrivacyApi.java:
--------------------------------------------------------------------------------
1 | package com.hook.sample.instrument;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.ActivityManager;
5 | import android.app.PendingIntent;
6 | import android.bluetooth.BluetoothAdapter;
7 | import android.bluetooth.BluetoothDevice;
8 | import android.content.ContentResolver;
9 | import android.content.Intent;
10 | import android.content.pm.ApplicationInfo;
11 | import android.content.pm.PackageInfo;
12 | import android.content.pm.PackageManager;
13 | import android.content.pm.ResolveInfo;
14 | import android.hardware.Sensor;
15 | import android.hardware.SensorEventListener;
16 | import android.hardware.SensorListener;
17 | import android.hardware.SensorManager;
18 | import android.location.Criteria;
19 | import android.location.Location;
20 | import android.location.LocationListener;
21 | import android.location.LocationManager;
22 | import android.net.wifi.WifiInfo;
23 | import android.net.wifi.WifiManager;
24 | import android.os.Handler;
25 | import android.os.Looper;
26 | import android.provider.Settings;
27 | import android.telephony.PhoneStateListener;
28 | import android.telephony.TelephonyManager;
29 | import android.text.TextUtils;
30 | import android.util.Log;
31 |
32 | import androidx.annotation.NonNull;
33 | import androidx.annotation.Nullable;
34 |
35 | import java.io.File;
36 | import java.io.IOException;
37 | import java.net.NetworkInterface;
38 | import java.net.SocketException;
39 | import java.util.ArrayList;
40 | import java.util.Collections;
41 | import java.util.Enumeration;
42 | import java.util.HashSet;
43 | import java.util.List;
44 | import java.util.Set;
45 |
46 |
47 | @SuppressLint("MissingPermission")
48 | public class ShadowPrivacyApi {
49 | private static final String TAG = "HOOK_ShadowPrivacyApi";
50 | public static boolean needHook = true;
51 |
52 | /**
53 | * BluetoothAdapter
54 | **/
55 | public static Set getBondedDevices(BluetoothAdapter adapter) {
56 | Log.i(TAG, "BluetoothAdapter#getBondedDevices() hooked");
57 | return new HashSet<>();
58 | }
59 |
60 | public static String getString(ContentResolver resolver, String name) {
61 | if (TextUtils.equals(Settings.Secure.ANDROID_ID, name)) {
62 | Log.i(TAG, "Settings$System#getString() protected");
63 | return "";
64 | }
65 |
66 | return Settings.System.getString(resolver, name);
67 | }
68 |
69 | public static List getRunningAppProcesses(ActivityManager activityManager) {
70 | if (needHook) {
71 | Log.e(TAG, "ActivityManager#getRunningAppProcesses() hooked!");
72 | return new ArrayList<>();
73 |
74 | }
75 | return activityManager.getRunningAppProcesses();
76 | }
77 |
78 | public static Location getLastLocation(LocationManager locationManager) {
79 | Log.i(TAG, "getLastLocation");
80 | return needHook ? new Location("gps") : locationManager.getLastKnownLocation("gps");
81 | }
82 |
83 | public static Location getLastKnownLocation(LocationManager locationManager, String provider) {
84 | Log.i(TAG, "getLastKnownLocation");
85 | return needHook ? new Location("gps") : locationManager.getLastKnownLocation(provider);
86 | }
87 |
88 | public static void requestLocationUpdates(LocationManager locationManager, String provider, long minTime,
89 | float minDistance, LocationListener listener) {
90 | Log.i(TAG, "requestLocationUpdates 1");
91 | if (!needHook) {
92 | locationManager.requestLocationUpdates(provider, minTime, minDistance, listener);
93 | }
94 | }
95 |
96 | public static void requestLocationUpdates(LocationManager locationManager, String provider, long minTime,
97 | float minDistance, LocationListener listener, Looper looper) {
98 | Log.i(TAG, "requestLocationUpdates 2");
99 | if (!needHook) {
100 | locationManager.requestLocationUpdates(provider, minTime, minDistance, listener, looper);
101 | }
102 | }
103 |
104 | public static void requestLocationUpdates(LocationManager locationManager, long minTime, float minDistance,
105 | Criteria criteria, LocationListener listener, Looper looper) {
106 | Log.i(TAG, "requestLocationUpdates 3");
107 | if (!needHook) {
108 | locationManager.requestLocationUpdates(minTime, minDistance, criteria, listener, looper);
109 | }
110 | }
111 |
112 | public static void requestLocationUpdates(LocationManager locationManager, String provider, long minTime,
113 | float minDistance, PendingIntent intent) {
114 | Log.i(TAG, "requestLocationUpdates 4");
115 | if (!needHook) {
116 | locationManager.requestLocationUpdates(provider, minTime, minDistance, intent);
117 | }
118 | }
119 |
120 | public static void requestLocationUpdates(LocationManager locationManager, long minTime, float minDistance,
121 | Criteria criteria, PendingIntent intent) {
122 | Log.i(TAG, "requestLocationUpdates 5");
123 | if (!needHook) {
124 | locationManager.requestLocationUpdates(minTime, minDistance, criteria, intent);
125 | }
126 | }
127 |
128 | public static void requestSingleUpdate(LocationManager locationManager, String provider, LocationListener listener,
129 | Looper looper) {
130 | Log.i(TAG, "requestSingleUpdate 1");
131 | if (!needHook) {
132 | locationManager.requestSingleUpdate(provider, listener, looper);
133 | }
134 | }
135 |
136 | public static void requestSingleUpdate(LocationManager locationManager, Criteria criteria, LocationListener listener,
137 | Looper looper) {
138 | Log.i(TAG, "requestSingleUpdate 2");
139 | if (!needHook) {
140 | locationManager.requestSingleUpdate(criteria, listener, looper);
141 | }
142 | }
143 |
144 | public static void requestSingleUpdate(LocationManager locationManager, String provider, PendingIntent intent) {
145 | Log.i(TAG, "requestSingleUpdate 3");
146 | if (!needHook) {
147 | locationManager.requestSingleUpdate(provider, intent);
148 | }
149 | }
150 |
151 | public static void requestSingleUpdate(LocationManager locationManager, Criteria criteria, PendingIntent intent) {
152 | Log.i(TAG, "requestSingleUpdate 4");
153 | if (!needHook) {
154 | locationManager.requestSingleUpdate(criteria, intent);
155 | }
156 | }
157 |
158 | public static Enumeration getNetworkInterfaces() throws SocketException {
159 | if (!needHook) {
160 | Log.e(TAG, "NetworkInterface#getNetworkInterfaces() is not hooked");
161 | return NetworkInterface.getNetworkInterfaces();
162 | }
163 |
164 | Log.i(TAG, "hook getNetworkInterfaces");
165 | return Collections.emptyEnumeration();
166 | }
167 |
168 | public static byte[] getHardwareAddress(NetworkInterface networkInterface) throws SocketException {
169 | if (!needHook) {
170 | return networkInterface.getHardwareAddress();
171 | }
172 | Log.i(TAG, "hook getHardwareAddress");
173 | throw new SocketException("ShadowNetworkInterface: hook!");
174 | }
175 |
176 | @NonNull
177 | public static List getInstalledPackages(PackageManager packageManager, int flags) {
178 | if (needHook) {
179 | Log.e(TAG, "getInstalledPackages hooked");
180 | return new ArrayList<>();
181 | }
182 | return packageManager.getInstalledPackages(flags);
183 | }
184 |
185 | @NonNull
186 | public static List getInstalledApplications(PackageManager packageManager, int flags) {
187 | if (needHook) {
188 | Log.e(TAG, "getInstalledApplications hooked");
189 | return new ArrayList<>();
190 | }
191 | return packageManager.getInstalledApplications(flags);
192 | }
193 |
194 |
195 | @NonNull
196 | public static List queryIntentActivities(PackageManager packageManager, @NonNull Intent intent, int flags) {
197 | if (needHook) {
198 | Log.e(TAG, "queryIntentActivities hooked");
199 | return new ArrayList<>();
200 | }
201 | return packageManager.queryIntentActivities(intent, flags);
202 | }
203 |
204 | @Nullable
205 | public static String[] getPackagesForUid(PackageManager packageManager, int uid) {
206 | if (needHook) {
207 | Log.e(TAG, "getPackagesForUid hooked");
208 | return null;
209 | }
210 | return packageManager.getPackagesForUid(uid);
211 | }
212 |
213 | public static Process exec(Runtime runtime, String command) throws IOException {
214 | // 放行 PhoneUtils#Rom#check
215 | if (needHook && (command != null && !command.startsWith("getprop"))) {
216 | Log.e(TAG, "java.lang.Runtime hooked");
217 | throw new IOException();
218 | }
219 | return runtime.exec(command);
220 | }
221 |
222 | public static Process exec(Runtime runtime, String cmdarray[]) throws IOException {
223 | if (needHook) {
224 | Log.e(TAG, "java.lang.Runtime hooked");
225 | throw new IOException();
226 | }
227 | return runtime.exec(cmdarray);
228 | }
229 |
230 | public static Process exec(Runtime runtime, String command, String[] envp) throws IOException {
231 | if (needHook) {
232 | Log.e(TAG, "java.lang.Runtime hooked");
233 | throw new IOException();
234 | }
235 | return runtime.exec(command, envp);
236 | }
237 |
238 | public static Process exec(Runtime runtime, String command, String[] envp, File dir)
239 | throws IOException {
240 | if (needHook) {
241 | Log.e(TAG, "java.lang.Runtime hooked");
242 | throw new IOException();
243 | }
244 | return runtime.exec(command, envp, dir);
245 | }
246 |
247 | public static Process exec(Runtime runtime, String[] cmdarray, String[] envp) throws IOException {
248 | if (needHook) {
249 | Log.e(TAG, "java.lang.Runtime hooked");
250 | throw new IOException();
251 | }
252 | return runtime.exec(cmdarray, envp);
253 | }
254 |
255 | public static Process exec(Runtime runtime, String[] cmdarray, String[] envp, File dir)
256 | throws IOException {
257 | if (needHook) {
258 | Log.e(TAG, "java.lang.Runtime hooked");
259 | throw new IOException();
260 | }
261 | return runtime.exec(cmdarray, envp, dir);
262 | }
263 |
264 |
265 | public static Sensor getDefaultSensor(SensorManager sensorManager, int type) {
266 | if (needHook) {
267 | return null;
268 | } else {
269 | return sensorManager.getDefaultSensor(type);
270 | }
271 | }
272 |
273 | public static boolean registerListener(SensorManager sensorManager, SensorListener listener, int sensors) {
274 | if (!needHook) {
275 | return sensorManager.registerListener(listener, sensors);
276 | }
277 | Log.d(TAG, "registerListener hooked");
278 | return false;
279 | }
280 |
281 | public static boolean registerListener(SensorManager sensorManager, SensorListener listener, int sensors, int rate) {
282 | if (!needHook) {
283 | return sensorManager.registerListener(listener, sensors, rate);
284 | }
285 | Log.d(TAG, "registerListener hooked");
286 | return false;
287 | }
288 |
289 | public static boolean registerListener(SensorManager sensorManager, SensorEventListener listener, Sensor sensor, int samplingPeriodUs) {
290 | if (!needHook) {
291 | return sensorManager.registerListener(listener, sensor, samplingPeriodUs);
292 | }
293 | Log.d(TAG, "registerListener hooked");
294 | return false;
295 | }
296 |
297 | public static boolean registerListener(SensorManager sensorManager, SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs) {
298 | if (!needHook) {
299 | return sensorManager.registerListener(listener, sensor, samplingPeriodUs, maxReportLatencyUs);
300 | }
301 | Log.d(TAG, "registerListener hooked");
302 | return false;
303 | }
304 |
305 | public static boolean registerListener(SensorManager sensorManager, SensorEventListener listener, Sensor sensor, int samplingPeriodUs, Handler handler) {
306 | if (!needHook) {
307 | return sensorManager.registerListener(listener, sensor, samplingPeriodUs, handler);
308 | }
309 | Log.d(TAG, "registerListener hooked");
310 | return false;
311 | }
312 |
313 | public static boolean registerListener(SensorManager sensorManager, SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) {
314 | if (!needHook) {
315 | return sensorManager.registerListener(listener, sensor, samplingPeriodUs, maxReportLatencyUs, handler);
316 | }
317 | Log.d(TAG, "registerListener hooked");
318 | return false;
319 | }
320 |
321 |
322 | public static String getDeviceId(TelephonyManager telephonyManager) {
323 | return "Others";
324 | }
325 |
326 | public static String getDeviceId(TelephonyManager telephonyManager, int slotIndex) {
327 | return "Others";
328 | }
329 |
330 | public static String getLine1Number(TelephonyManager telephonyManager) {
331 | return "Others";
332 | }
333 |
334 | public static String getLine1Number(TelephonyManager telephonyManager, int subId) {
335 | return "Others";
336 | }
337 |
338 | public static String getSubscriberId(TelephonyManager telephonyManager) {
339 | return "Others";
340 | }
341 |
342 | public static String getSubscriberId(TelephonyManager telephonyManager, int subId) {
343 | return "Others";
344 | }
345 |
346 | public static String getMeid(TelephonyManager telephonyManager) {
347 | Log.e(TAG, "TelephonyManager#getMeid() hooked");
348 | return "";
349 | }
350 |
351 | public static String getMeid(TelephonyManager telephonyManager, int slotIndex) {
352 | Log.e(TAG, "TelephonyManager#getMeid(slotIndex) hooked");
353 | return "";
354 | }
355 |
356 | public static void listen(TelephonyManager telephonyManager, PhoneStateListener listener, int events) {
357 | Log.e(TAG, "TelephonyManager#listen() hooked");
358 | }
359 |
360 | public static String getSimSerialNumber(TelephonyManager telephonyManager) {
361 | Log.e(TAG, "TelephonyManager#getSimSerialNumber() hooked");
362 | return "";
363 | }
364 |
365 | public static String getSimSerialNumber(TelephonyManager telephonyManager, int subId) {
366 | Log.e(TAG, "TelephonyManager#getSimSerialNumber(subId) hooked");
367 | return "";
368 | }
369 |
370 | public static String getManufacturerCode(TelephonyManager telephonyManager) {
371 | Log.e(TAG, "TelephonyManager#getManufacturerCode() hooked");
372 | return "";
373 | }
374 |
375 | public static String getManufacturerCode(TelephonyManager telephonyManager, int slotIndex) {
376 | Log.e(TAG, "TelephonyManager#getManufacturerCode(slotIndex) hooked");
377 | return "";
378 | }
379 |
380 | @Nullable
381 | public static WifiInfo getConnectionInfo(WifiManager wifiManager) {
382 | if (!needHook) {
383 | Log.e(TAG, "WifiManager#getConnectionInfo() not hooked");
384 | return wifiManager.getConnectionInfo();
385 | }
386 | Log.e(TAG, "WifiManager#getConnectionInfo() hooked");
387 | return null;
388 | }
389 | }
390 |
--------------------------------------------------------------------------------