gpt4 book ai didi

android - 如何测试 Android apk 是否在 root 设备中运行

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:52 24 4
gpt4 key购买 nike

一个 Infosec 团队想知道我们的应用程序是否可以在已获得 root 权限的 Android 设备上执行。我们为它开发了一个解决方案,现在想测试我们的应用程序。我们可以在线复制 root 设备吗?如果没有,谁能提供其他方法来测试我们的应用程序?

提前致谢!

最佳答案

我编写了一些实用函数来帮助我确定我的应用程序是否在根环境中运行:

private fun isDeviceRooted(): Boolean {
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3()
}

private fun checkRootMethod1(): Boolean {
val buildTags = android.os.Build.TAGS
return buildTags != null && buildTags.contains("test-keys")
}

private fun checkRootMethod2(): Boolean {
val paths = arrayOf("/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su")
for (path in paths) {
if (File(path).exists()) return true
}
return false
}

private fun checkRootMethod3(): Boolean {
var process: Process? = null
return try {
process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
val `in` = BufferedReader(InputStreamReader(process!!.inputStream))
`in`.readLine() != null
} catch (t: Throwable) {
false
} finally {
process?.destroy()
}
}

关于android - 如何测试 Android apk 是否在 root 设备中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55095047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com