简体   繁体   English

如何测试如果Android apk在root设备中运行

[英]How to test If Android apk runs in rooted device

An Infosec team wanted to know if our app was executable on rooted Android devices. Infosec团队想知道我们的应用程序是否可以在root用户设备上执行。 We developed a solution for it and now want to test our app. 我们为它开发了一个解决方案,现在想测试我们的应用程序。 Are we able to replicate rooted devices online? 我们能够在线复制有根设备吗? If not, can anyone provide other ways to test our app? 如果没有,有人可以提供其他方法来测试我们的应用程序吗

Thanks in advance! 提前致谢!

I have written a few util functions to help me with determining if my app is running in root environment: 我编写了一些util函数来帮助我确定我的应用程序是否在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()
    }
}

I think the best idea is to use the rooted/ rootable android emulator. 我认为最好的想法是使用rooted / rootable android模拟器。 Here are few android emulators that you can download for windows pc. 这里有一些Android模拟器,你可以下载为Windows PC。

Links for rootable emulators rootable模拟器的链接

If you want to use the emulator provided by the android studio then i think you would have to create a new android emulator with API 22 (LOLLIPOP) or above using android studio and try rooting it with help of Kingroot app. 如果你想使用android studio提供的模拟器,那么我认为你必须使用android studio创建一个带有API 22(LOLLIPOP)或更高版本的新的Android模拟器,并尝试在Kingroot app的帮助下生成它。 This app helps you to root your device by directly installing on your device like an normal application. 此应用程序可帮助您通过直接在设备上安装(如普通应用程序)来设备。 This solution must work as it works on normal real devices. 此解决方案必须正常,因为它适用于普通的真实设备。 I have myself tried on the real devices but not on android emulator. 我自己试过真正的设备,但不是在Android模拟器上。

Hope this solves your query 希望这能解决您的疑问

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM