Add counter for new hooks, refactor PmsHookTarget34 a bit

This commit is contained in:
frknkrc44 2025-09-03 06:32:10 +03:00
commit d9d097547e
No known key found for this signature in database
GPG key ID: 784AE1CC0DCFD34F
4 changed files with 13 additions and 10 deletions

View file

@ -39,6 +39,7 @@ class AccessibilityHook(private val service: HMAService) : IFrameworkHook {
for (caller in callingApps) {
if (service.getEnabledSettingsPresets(caller).contains(AccessibilityPreset.NAME)) {
param.result = 0L
service.filterCount++
break
}
}
@ -53,6 +54,7 @@ class AccessibilityHook(private val service: HMAService) : IFrameworkHook {
for (caller in callingApps) {
if (service.getEnabledSettingsPresets(caller).contains(AccessibilityPreset.NAME)) {
param.result = java.util.ArrayList<AccessibilityServiceInfo>()
service.filterCount++
break
}
}
@ -62,7 +64,7 @@ class AccessibilityHook(private val service: HMAService) : IFrameworkHook {
}
override fun unload() {
hookList.forEach { it.unhook() }
hookList.forEach(XC_MethodHook.Unhook::unhook)
hookList.clear()
}
}

View file

@ -47,6 +47,7 @@ class ActivityHook(private val service: HMAService) : IFrameworkHook {
"@executeRequest: insecure query from $caller, target: ${intent?.component}"
)
param.result = fakeReturnCode
service.filterCount++
}
}.onFailure {
logE(TAG, "Fatal error occurred, ignore hook\n", it)

View file

@ -32,7 +32,7 @@ class ContentProviderHook(private val service: HMAService): IFrameworkHook {
val name = param.args[3] as String?
for (caller in callingApps) {
logD(TAG, "@call caller: $caller, method: $method, name: $name")
// logD(TAG, "@call caller: $caller, method: $method, name: $name")
when (method) {
"GET_global", "GET_secure", "GET_system" -> {
@ -43,6 +43,7 @@ class ContentProviderHook(private val service: HMAService): IFrameworkHook {
putString(Settings.NameValueTable.VALUE, replacement.value)
putInt("_generation_index", -1)
}
service.filterCount++
}
}
}

View file

@ -29,14 +29,13 @@ class PmsHookTarget34(private val service: HMAService) : IFrameworkHook {
}
}
private var hook: XC_MethodHook.Unhook? = null
private var exphook: XC_MethodHook.Unhook? = null
private val hookList = mutableSetOf<XC_MethodHook.Unhook>()
private var lastFilteredApp: AtomicReference<String?> = AtomicReference(null)
@Suppress("UNCHECKED_CAST")
override fun load() {
logI(TAG, "Load hook")
hook = findMethod("com.android.server.pm.AppsFilterImpl", findSuper = true) {
hookList += findMethod("com.android.server.pm.AppsFilterImpl", findSuper = true) {
name == "shouldFilterApplication"
}.hookBefore { param ->
runCatching {
@ -64,7 +63,7 @@ class PmsHookTarget34(private val service: HMAService) : IFrameworkHook {
}
// AOSP exploit - https://github.com/aosp-mirror/platform_frameworks_base/commit/5bc482bd99ea18fe0b4064d486b29d5ae2d65139
// Only 14 QPR2+ has this method
exphook = findMethodOrNull("com.android.server.pm.PackageManagerService", findSuper = true) {
findMethodOrNull("com.android.server.pm.PackageManagerService", findSuper = true) {
name == "getArchivedPackageInternal"
}?.hookBefore { param ->
runCatching {
@ -88,13 +87,13 @@ class PmsHookTarget34(private val service: HMAService) : IFrameworkHook {
logE(TAG, "Fatal error occurred, disable hooks", it)
unload()
}
}?.let {
hookList.add(it)
}
}
override fun unload() {
hook?.unhook()
hook = null
exphook?.unhook()
exphook = null
hookList.forEach(XC_MethodHook.Unhook::unhook)
hookList.clear()
}
}