Add root manager detection, move package events

This commit is contained in:
frknkrc44 2025-08-19 15:29:21 +03:00
commit 432218626a
No known key found for this signature in database
GPG key ID: 784AE1CC0DCFD34F
5 changed files with 89 additions and 43 deletions

View file

@ -66,8 +66,10 @@ class Presets private constructor() {
if (appInfo != null) {
runCatching {
if (it.onReloadPreset(appInfo!!))
if (it.onReloadPreset(appInfo!!)) {
loggerFunction?.invoke("Package $packageName added into ${it.name}!")
addedInAList = true
}
}.onFailure { fail ->
loggerFunction?.invoke(fail.toString())
}

View file

@ -1,16 +1,10 @@
package icu.nullptr.hidemyapplist.common.presets
import android.content.pm.ApplicationInfo
import java.util.zip.ZipFile
class RootAppsPreset() : BasePreset("root_apps") {
override fun onAddExactPackages() {
// root managers
packageNames += arrayOf(
"me.weishu.kernelsu",
"com.rifsxd.ksunext",
"com.sukisu.ultra",
)
// rooted apps
packageNames += arrayOf(
"io.github.a13e300.ksuwebui",
@ -57,6 +51,10 @@ class RootAppsPreset() : BasePreset("root_apps") {
override fun onReloadPreset(appInfo: ApplicationInfo): Boolean {
val packageName = appInfo.packageName
if (packageNames.contains(packageName)) {
return false
}
// Iconify
if (packageName.startsWith("com.drdisagree.iconify")) {
packageNames.add(packageName)
@ -99,6 +97,33 @@ class RootAppsPreset() : BasePreset("root_apps") {
return true
}
ZipFile(appInfo.sourceDir).use { zipFile ->
if (findRootManagerFromLibs(zipFile)) {
packageNames.add(appInfo.packageName)
return true
}
}
return false
}
private fun findRootManagerFromLibs(zipFile: ZipFile): Boolean {
val entryNames = listOf(
"libkernelsu.so",
"libapd.so",
"libmagisk.so",
"libmmrl-kernelsu.so"
)
val architectures = listOf("arm64-v8a", "armeabi-v7a")
for (entry in entryNames) {
for (arch in architectures) {
if (zipFile.getEntry("lib/$arch/$entry") != null) {
return true
}
}
}
return false
}
}

View file

@ -16,6 +16,7 @@ import icu.nullptr.hidemyapplist.xposed.hook.PmsHookTarget28
import icu.nullptr.hidemyapplist.xposed.hook.PmsHookTarget30
import icu.nullptr.hidemyapplist.xposed.hook.PmsHookTarget33
import icu.nullptr.hidemyapplist.xposed.hook.PmsHookTarget34
import icu.nullptr.hidemyapplist.xposed.hook.PmsPackageEventsHook
import org.frknkrc44.hma_oss.common.BuildConfig
import java.io.File
import java.util.concurrent.ExecutorService
@ -150,6 +151,7 @@ class HMAService(val pms: IPackageManager) : IHMAService.Stub() {
}
frameworkHooks.add(ActivityHook(this))
frameworkHooks.add(PmsPackageEventsHook(this))
frameworkHooks.forEach(IFrameworkHook::load)
logI(TAG, "Hooks installed")

View file

@ -1,8 +1,6 @@
package icu.nullptr.hidemyapplist.xposed
import android.content.Intent
import android.content.pm.IPackageManager
import android.os.Build
import com.github.kyuubiran.ezxhelper.init.EzXHelperInit
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.getFieldByDesc
@ -34,39 +32,6 @@ class XposedEntry : IXposedHookZygoteInit, IXposedHookLoadPackage {
EzXHelperInit.initHandleLoadPackage(lpparam)
logI(TAG, "Hook entry")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
try {
findMethod("com.android.server.pm.BroadcastHelper") {
name == "sendPackageBroadcastAndNotify"
}.hookBefore { param ->
HMAService.instance?.handlePackageEvent(
param.args[0] as String?,
param.args[1] as String?
)
}
} catch (e: Throwable) {
findMethod("com.android.internal.content.PackageMonitor") {
name == "onReceive"
}.hookBefore { param ->
val intent = param.args[1] as Intent? ?: return@hookBefore
HMAService.instance?.handlePackageEvent(
intent.action,
intent.data?.encodedSchemeSpecificPart
)
}
}
} else {
findMethod("com.android.server.pm.PackageManagerService") {
name == "sendPackageBroadcast"
}.hookBefore { param ->
HMAService.instance?.handlePackageEvent(
param.args[0] as String?,
param.args[1] as String?
)
}
}
var serviceManagerHook: XC_MethodHook.Unhook? = null
serviceManagerHook = findMethod("android.os.ServiceManager") {
name == "addService"

View file

@ -0,0 +1,52 @@
package icu.nullptr.hidemyapplist.xposed.hook
import android.content.Intent
import android.os.Build
import com.github.kyuubiran.ezxhelper.utils.findMethod
import com.github.kyuubiran.ezxhelper.utils.hookBefore
import de.robv.android.xposed.XC_MethodHook
import icu.nullptr.hidemyapplist.xposed.HMAService
class PmsPackageEventsHook(private val service: HMAService) : IFrameworkHook {
private var hook: XC_MethodHook.Unhook? = null
override fun load() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
try {
hook = findMethod("com.android.server.pm.BroadcastHelper") {
name == "sendPackageBroadcastAndNotify"
}.hookBefore { param ->
service.handlePackageEvent(
param.args[0] as String?,
param.args[1] as String?
)
}
} catch (e: Throwable) {
hook = findMethod("com.android.internal.content.PackageMonitor") {
name == "onReceive"
}.hookBefore { param ->
val intent = param.args[1] as Intent? ?: return@hookBefore
service.handlePackageEvent(
intent.action,
intent.data?.encodedSchemeSpecificPart
)
}
}
} else {
hook = findMethod("com.android.server.pm.PackageManagerService") {
name == "sendPackageBroadcast"
}.hookBefore { param ->
service.handlePackageEvent(
param.args[0] as String?,
param.args[1] as String?
)
}
}
}
override fun unload() {
hook?.unhook()
hook = null
}
}