Support ADB shell if app shares its UID

This commit is contained in:
topjohnwu 2022-03-26 13:43:43 -07:00
parent d7ee4ef5f5
commit 4f52587586
2 changed files with 9 additions and 2 deletions

View File

@ -36,7 +36,7 @@ class SuRequestHandler(
// Never allow com.topjohnwu.magisk (could be malware) // Never allow com.topjohnwu.magisk (could be malware)
if (pkgInfo.packageName == BuildConfig.APPLICATION_ID) { if (pkgInfo.packageName == BuildConfig.APPLICATION_ID) {
Shell.cmd("(pm uninstall ${BuildConfig.APPLICATION_ID})& >/dev/null 2>&1").exec() Shell.cmd("(pm uninstall ${BuildConfig.APPLICATION_ID} >/dev/null 2>&1)&").exec()
return false return false
} }

View File

@ -19,6 +19,7 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.net.Uri import android.net.Uri
import android.os.Build.VERSION.SDK_INT import android.os.Build.VERSION.SDK_INT
import android.os.Process
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
@ -272,7 +273,13 @@ fun PackageManager.getPackageInfo(uid: Int, pid: Int): PackageInfo? {
if (pid <= 0) if (pid <= 0)
return null return null
// Try to find package name from PID // Try to find package name from PID
val proc = RootUtils.obj?.getAppProcess(pid) ?: return null val proc = RootUtils.obj?.getAppProcess(pid)
?: return if (uid == Process.SHELL_UID) {
// It is possible that some apps installed are sharing UID with shell.
// We will not be able to find a package from the active process list,
// because the client is forked from ADB shell, not any app process.
getPackageInfo("com.android.shell", flag)
} else null
val pkg = proc.pkgList[0] val pkg = proc.pkgList[0]
getPackageInfo(pkg, flag) getPackageInfo(pkg, flag)
} else { } else {