Fix hide on Android 9~10

This commit is contained in:
Nullptr 2022-08-25 13:45:49 +08:00
commit 6bfc0f5098
No known key found for this signature in database
3 changed files with 46 additions and 14 deletions

View file

@ -35,7 +35,7 @@ fun String.execute(currentWorkingDir: File = file("./")): String {
val minSdkVer by extra(24)
val targetSdkVer by extra(33)
val appVerName by extra("3.0.0")
val appVerName by extra("3.0.0-Beta")
val serviceVerCode by extra(83)
val minBackupVerCode by extra(65)

View file

@ -21,7 +21,6 @@ class PmsHookLegacy(private val service: HMAService) : IFrameworkHook {
}
private val hooks = mutableSetOf<XC_MethodHook.Unhook>()
private fun XC_MethodHook.Unhook.yes() = hooks.add(this)
@Suppress("UNCHECKED_CAST")
private fun removeList(
@ -105,13 +104,13 @@ class PmsHookLegacy(private val service: HMAService) : IFrameworkHook {
}
for (method in pmMethods) when (method.name) {
"getAllPackages"
-> removeList(method, false, listOf()).yes()
-> hooks += removeList(method, false, listOf())
"getInstalledPackages",
"getInstalledApplications",
"getPackagesHoldingPermissions",
"queryInstrumentation"
-> removeList(method, true, listOf("packageName")).yes()
-> hooks += removeList(method, true, listOf("packageName"))
"getPackageInfo",
"getPackageGids",
@ -120,24 +119,27 @@ class PmsHookLegacy(private val service: HMAService) : IFrameworkHook {
"getInstallerPackageName",
"getLaunchIntentForPackage",
"getLeanbackLaunchIntentForPackage"
-> setResult(method, null).yes()
-> hooks += setResult(method, null)
"queryIntentActivities",
"queryIntentActivityOptions",
"queryIntentReceivers",
"queryIntentServices",
"queryIntentContentProviders"
-> removeList(method, true, listOf("activityInfo", "packageName")).yes()
-> hooks += removeList(method, true, listOf("activityInfo", "packageName"))
"getActivityInfo",
"resolveActivity",
"resolveActivityAsUser"
-> resolveIntent(method, null).yes()
-> hooks += resolveIntent(method, null)
"getPackageUid"
-> setResult(method, -1).yes()
-> hooks += setResult(method, -1)
}
}
override fun unload() = hooks.forEach(XC_MethodHook.Unhook::unhook)
override fun unload() {
hooks.forEach(XC_MethodHook.Unhook::unhook)
hooks.clear()
}
}

View file

@ -1,8 +1,10 @@
package icu.nullptr.hidemyapplist.xposed.hook
import android.annotation.TargetApi
import android.content.pm.ResolveInfo
import android.os.Build
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.hookAfter
import com.github.kyuubiran.ezxhelper.utils.hookBefore
import de.robv.android.xposed.XC_MethodHook
import icu.nullptr.hidemyapplist.common.Constants
@ -18,12 +20,13 @@ class PmsHookTarget28(private val service: HMAService) : IFrameworkHook {
private const val TAG = "PmsHookTarget28"
}
private var hook: XC_MethodHook.Unhook? = null
private val hooks = mutableListOf<XC_MethodHook.Unhook>()
@Suppress("UNCHECKED_CAST")
override fun load() {
logI(TAG, "Load hook")
hook = findMethod(service.pms::class.java, findSuper = true) {
name == "filterAppAccessLPr"
hooks += findMethod(service.pms::class.java, findSuper = true) {
name == "filterAppAccessLPr" && parameterTypes.size == 5
}.hookBefore { param ->
runCatching {
val callingUid = param.args[1] as Int
@ -45,10 +48,37 @@ class PmsHookTarget28(private val service: HMAService) : IFrameworkHook {
unload()
}
}
hooks += findMethod(service.pms::class.java, findSuper = true) {
name == "applyPostResolutionFilter"
}.hookAfter { param ->
runCatching {
val callingUid = param.args[3] as Int
if (callingUid == Constants.UID_SYSTEM) return@hookAfter
val callingApps = Utils.binderLocalScope {
service.pms.getPackagesForUid(callingUid)
} ?: return@hookAfter
val list = param.result as MutableCollection<ResolveInfo>
val listToRemove = mutableSetOf<ResolveInfo>()
for (resolveInfo in list) {
for (caller in callingApps) {
val targetApp = resolveInfo.resolvePackageName
if (service.shouldHide(caller, targetApp)) {
logI(TAG, "@Filter caller: $callingUid $caller, target: $targetApp")
listToRemove.add(resolveInfo)
break
}
}
}
list.removeAll(listToRemove)
}.onFailure {
logE(TAG, "Fatal error occurred, disable hooks", it)
unload()
}
}
}
override fun unload() {
hook?.unhook()
hook = null
hooks.forEach(XC_MethodHook.Unhook::unhook)
hooks.clear()
}
}