Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
app: deps: dexkit 2.0.0-rc4
Browse files Browse the repository at this point in the history
* also fixed AllowUpdateSystemApp
  • Loading branch information
YuKongA committed Oct 8, 2023
1 parent 37b5d4a commit 387027f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 133 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/yuk/miuiXXL/hooks/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
}

"com.miui.packageinstaller" -> {
AllowUpdateSystemApp().handleLoadPackage(lpparam)
initHooks(
RemovePackageInstallerAds,
AllowUpdateSystemApp,
ShowMoreApkInfo,
DisableCountCheck,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@ package com.yuk.miuiXXL.hooks.modules.guardprovider
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage
import io.luckypray.dexkit.DexKitBridge
import java.lang.reflect.Method
import org.luckypray.dexkit.DexKitBridge

class AntiDefraudAppManager : IXposedHookLoadPackage {

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
System.loadLibrary("dexkit")
DexKitBridge.create(lpparam.appInfo.sourceDir)?.use { bridge ->

val map = mapOf(
"AntiDefraudAppManager" to setOf("AntiDefraudAppManager", "https://flash.sec.miui.com/detect/app"),
)

val resultMap = bridge.batchFindMethodsUsingStrings {
queryMap(map)
val bridge = DexKitBridge.create(lpparam.appInfo.sourceDir) ?: throw NullPointerException("DexKitBridge.create() failed")
bridge.findMethod {
matcher {
usingStrings = listOf("AntiDefraudAppManager", "https://flash.sec.miui.com/detect/app")
}

val antiDefraudAppManager = resultMap["AntiDefraudAppManager"]!!
assert(antiDefraudAppManager.size == 1)
val antiDefraudAppManagerDescriptor = antiDefraudAppManager.first()
val antiDefraudAppManagerMethod: Method = antiDefraudAppManagerDescriptor.getMethodInstance(lpparam.classLoader)
antiDefraudAppManagerMethod.createHook {
replace {
return@replace null
}
}.firstOrNull()?.getMethodInstance(lpparam.classLoader)?.createHook {
replace {
return@replace null
}
bridge.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@ package com.yuk.miuiXXL.hooks.modules.packageinstaller

import android.content.pm.ApplicationInfo
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.yuk.miuiXXL.hooks.modules.BaseHook
import com.yuk.miuiXXL.utils.KotlinXposedHelper.findClassOrNull
import com.yuk.miuiXXL.utils.KotlinXposedHelper.hookBeforeMethod
import com.yuk.miuiXXL.utils.XSharedPreferences.getBoolean
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XposedBridge
import de.robv.android.xposed.callbacks.XC_LoadPackage
import org.luckypray.dexkit.DexKitBridge
import java.lang.reflect.Method
import java.lang.reflect.Modifier

object AllowUpdateSystemApp : BaseHook() {
override fun init() {
class AllowUpdateSystemApp : IXposedHookLoadPackage {

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!getBoolean("packageinstaller_allow_update_system_app", false)) return
var letter = 'a'
for (i in 0..25) {
try {
val classIfExists = "j2.${letter}".findClassOrNull()
classIfExists?.let {
it.methodFinder().filterByParamCount(1).filterByParamTypes(ApplicationInfo::class.java, Boolean::class.java).first().createHook {
returnConstant(false)
}
}
} catch (t: Throwable) {
letter++
System.loadLibrary("dexkit")
val bridge = DexKitBridge.create(lpparam.appInfo.sourceDir) ?: throw NullPointerException("DexKitBridge.create() failed")
bridge.findMethod {
matcher {
modifiers = Modifier.PUBLIC or Modifier.STATIC
paramTypes = listOf("android.content.pm.ApplicationInfo")
returnType = "boolean"
}
}

try {
"android.os.SystemProperties".hookBeforeMethod("getBoolean", String::class.java, Boolean::class.java) {
if (it.args[0] == "persist.sys.allow_sys_app_update") it.result = true
}.forEach {
XposedBridge.log(it.name)
it.getMethodInstance(lpparam.classLoader).createHook {
returnConstant(false)
}
} catch (_: Exception) {
}
bridge.close()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,45 @@ import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinde
import com.yuk.miuiXXL.utils.XSharedPreferences.getBoolean
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage
import io.luckypray.dexkit.DexKitBridge
import org.luckypray.dexkit.DexKitBridge
import java.lang.reflect.Method

class RemoveMacroBlacklist : IXposedHookLoadPackage {

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!getBoolean("securitycenter_remove_macro_blacklist", false)) return
System.loadLibrary("dexkit")
DexKitBridge.create(lpparam.appInfo.sourceDir)?.use { bridge ->

val classMap = mapOf(
"Macro" to setOf("pref_gb_unsupport_macro_apps", "gb_game_gunsight", "com.tencent.tmgp.sgame"),
"Macro1" to setOf("key_macro_toast", "content://com.xiaomi.macro.MacroStatusProvider/game_macro_change"),
)

val methodMap = mapOf(
"Macro2" to setOf("pref_gb_unsupport_macro_apps"),
)

val resultClassMap = bridge.batchFindClassesUsingStrings {
queryMap(classMap)
}

val resultMethodMap = bridge.batchFindMethodsUsingStrings {
queryMap(methodMap)
}

val macro = resultClassMap["Macro"]!!
assert(macro.size == 1)
val macroDescriptor = macro.first()
val macroClass: Class<*> = macroDescriptor.getClassInstance(lpparam.classLoader)
macroClass.methodFinder().filterByReturnType(Boolean::class.java).filterByParamCount(1).first().createHook {
returnConstant(false)
val bridge = DexKitBridge.create(lpparam.appInfo.sourceDir) ?: throw NullPointerException("DexKitBridge.create() failed")
bridge.findClass {
matcher {
usingStrings = listOf("pref_gb_unsupport_macro_apps", "gb_game_gunsight", "com.tencent.tmgp.sgame")
}

val macro1 = resultClassMap["Macro1"]!!
assert(macro1.size == 1)
val macro1Descriptor = macro1.first()
val macro1Class: Class<*> = macro1Descriptor.getClassInstance(lpparam.classLoader)
macro1Class.methodFinder().filterByReturnType(Boolean::class.java).filterByParamCount(2).first().createHook {
returnConstant(true)
}

val macro2 = resultMethodMap["Macro2"]!!
assert(macro2.isNotEmpty())
var macro2Descriptor = macro2[0]
var macroMethod: Method = macro2Descriptor.getMethodInstance(lpparam.classLoader)
if (macroMethod.returnType != ArrayList::class.java) {
macro2Descriptor = macro2[1]
macroMethod = macro2Descriptor.getMethodInstance(lpparam.classLoader)
}.firstOrNull()?.getInstance(lpparam.classLoader)!!.methodFinder().filterByReturnType(Boolean::class.java).filterByParamCount(1).first().createHook {
returnConstant(false)
}
bridge.findClass {
matcher {
usingStrings = listOf("key_macro_toast", "content://com.xiaomi.macro.MacroStatusProvider/game_macro_change")
}
macroMethod.createHook {
returnConstant(ArrayList<String>())
}.firstOrNull()?.getInstance(lpparam.classLoader)!!.methodFinder().filterByReturnType(Boolean::class.java).filterByParamCount(2).first().createHook {
returnConstant(true)
}
val macro = bridge.findMethod {
matcher {
usingStrings = listOf("pref_gb_unsupport_macro_apps")
}

}
assert(macro.isNotEmpty())
var macroDescriptor = macro[0]
var macroMethod: Method = macroDescriptor.getMethodInstance(lpparam.classLoader)
if (macroMethod.returnType != ArrayList::class.java) {
macroDescriptor = macro[1]
macroMethod = macroDescriptor.getMethodInstance(lpparam.classLoader)
}
macroMethod.createHook {
returnConstant(ArrayList<String>())
}
bridge.close()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,40 @@ import com.github.kyuubiran.ezxhelper.finders.FieldFinder.`-Static`.fieldFinder
import com.yuk.miuiXXL.utils.XSharedPreferences.getBoolean
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage
import io.luckypray.dexkit.DexKitBridge
import miui.drm.DrmManager
import org.luckypray.dexkit.DexKitBridge
import java.io.File
import java.lang.reflect.Method

class FuckValidateTheme2 : IXposedHookLoadPackage {

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!getBoolean("thememanager_fuck_validate_theme", false)) return
System.loadLibrary("dexkit")
DexKitBridge.create(lpparam.appInfo.sourceDir)?.use { bridge ->

val map = mapOf(
"DrmResult" to setOf(
"theme", "ThemeManagerTag", "/system", "check rights isLegal:"
),
"LargeIcon" to setOf(
"apply failed", "/data/system/theme/large_icons/", "default_large_icon_product_id", "largeicons", "relativePackageList is empty"
),
)

val resultMap = bridge.batchFindMethodsUsingStrings {
queryMap(map)
System.loadLibrary("dexkit")
val bridge = DexKitBridge.create(lpparam.appInfo.sourceDir) ?: throw NullPointerException("DexKitBridge.create() failed")
bridge.findMethod {
matcher {
usingStrings = listOf("theme", "ThemeManagerTag", "/system", "check rights isLegal:")
}

val drmResult = resultMap["DrmResult"]!!
assert(drmResult.size == 1)
val drmResultDescriptor = drmResult.first()
val drmResultMethod: Method = drmResultDescriptor.getMethodInstance(lpparam.classLoader)
drmResultMethod.createHook {
after {
it.result = DrmManager.DrmResult.DRM_SUCCESS
}
}.firstOrNull()?.getMethodInstance(lpparam.classLoader)?.createHook {
returnConstant(DrmManager.DrmResult.DRM_SUCCESS)
}
bridge.findMethod {
matcher {
usingStrings = listOf("apply failed", "/data/system/theme/large_icons/", "default_large_icon_product_id", "largeicons", "relativePackageList is empty")
}

val largeIcon = resultMap["LargeIcon"]!!
assert(largeIcon.size == 1)
val largeIconDescriptor = largeIcon.first()
val largeIconMethod: Method = largeIconDescriptor.getMethodInstance(lpparam.classLoader)
largeIconMethod.createHook {
before {
val resource = it.thisObject.javaClass.fieldFinder()
.filterByType(loadClass("com.android.thememanager.basemodule.resource.model.Resource", lpparam.classLoader)).first()
val productId =
it.thisObject.objectHelper().getObjectOrNull(resource.name)!!.objectHelper().invokeMethodBestMatch("getProductId").toString()
val strPath = "/storage/emulated/0/Android/data/com.android.thememanager/files/MIUI/theme/.data/rights/theme/${productId}-largeicons.mra"
val file = File(strPath)
val fileParent = file.parentFile!!
if (!fileParent.exists()) fileParent.mkdirs()
file.createNewFile()
}
}.firstOrNull()?.getMethodInstance(lpparam.classLoader)?.createHook {
before {
val resource = it.thisObject.javaClass.fieldFinder().filterByType(loadClass("com.android.thememanager.basemodule.resource.model.Resource", lpparam.classLoader)).first()
val productId = it.thisObject.objectHelper().getObjectOrNull(resource.name)!!.objectHelper().invokeMethodBestMatch("getProductId").toString()
val strPath = "/storage/emulated/0/Android/data/com.android.thememanager/files/MIUI/theme/.data/rights/theme/${productId}-largeicons.mra"
val file = File(strPath)
val fileParent = file.parentFile!!
if (!fileParent.exists()) fileParent.mkdirs()
file.createNewFile()
}
}
bridge.close()
}

}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
agp = "8.1.2"
dexKit = "1.1.8"
dexKit = "2.0.0-rc4"
ezXHelper = "2.0.7"
xposed-api = "82"
kotlin = "1.9.10"

[libraries]
dexKit = { module = "org.luckypray:DexKit", version.ref = "dexKit" }
dexKit = { module = "org.luckypray:dexkit", version.ref = "dexKit" }
ezXHelper = { module = "com.github.kyuubiran:EzXHelper", version.ref = "ezXHelper" }
xposed-api = { module = "de.robv.android.xposed:api", version.ref = "xposed-api" }

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 12 08:04:26 GMT+08:00 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 387027f

Please sign in to comment.