2010-08-06 50 views

回答

26

生根检测是一种猫捉老鼠游戏,很难在所有情况下都能在所有设备上进行生根检测。

如果您仍然需要一些基本的生根检测检查下面的代码:

/** 
    * Checks if the device is rooted. 
    * 
    * @return <code>true</code> if the device is rooted, <code>false</code> otherwise. 
    */ 
    public static boolean isRooted() { 

    // get from build info 
    String buildTags = android.os.Build.TAGS; 
    if (buildTags != null && buildTags.contains("test-keys")) { 
     return true; 
    } 

    // check if /system/app/Superuser.apk is present 
    try { 
     File file = new File("/system/app/Superuser.apk"); 
     if (file.exists()) { 
     return true; 
     } 
    } catch (Exception e1) { 
     // ignore 
    } 

    // try executing commands 
    return canExecuteCommand("/system/xbin/which su") 
     || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su"); 
    } 

    // executes a command on the system 
    private static boolean canExecuteCommand(String command) { 
    boolean executedSuccesfully; 
    try { 
     Runtime.getRuntime().exec(command); 
     executedSuccesfully = true; 
    } catch (Exception e) { 
     executedSuccesfully = false; 
    } 

    return executedSuccesfully; 
    } 

也许并不总是正确。在2014年测试了约10台设备。

+4

你的意思是植根于增加了Superuser.apk的特定工具?由于大多数检查都可以规避,所以没有一种可靠的编程方法来确定设备是否已经生根。 – dljava 2013-04-04 11:56:00

+1

我一直在我的产品中使用此检查,但最近Nexus 7.1报告所有这些错误(不安装'which'命令),并且SuperSu未安装在/ system/app文件夹中。 – Graeme 2014-04-07 09:59:14

+0

可能你应该也看看http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device – 2016-01-22 14:24:41

1

official licensing guide说:

A limitation of the legacy copy-protection mechanism on Android Market is that applications using it can be installed only on compatible devices that provide a secure internal storage environment. For example, a copy-protected application cannot be downloaded from Market to a device that provides root access, and the application cannot be installed to a device's SD card.

看来,你会从使用传统的警察保护,以防止你的应用程序被安装在已解锁装置受益。

您可能会发布一个单独的版本,该版本可以安装在具有加密数据库的根设备上。

+0

但是他们如何检测设备是否生根?正如hackbod(Android开发人员)提到的那样,无法检测到。 http://stackoverflow.com/questions/3576989/how-can-you-detect-if-the-device-is-rooted-in-the-app – 2011-10-11 03:34:30

5

如果信息很敏感,您应该只对所有用户进行加密。否则,用户可以安装您的应用程序,然后根据数据写入后读取您的数据库。

+0

问题是,如果你的内容是媒体内容(mp3,mp4) ,甚至是最初加密的,并且您想要在媒体播放器中播放,您需要在某个时刻使用临时解密文件,这可以在根用户设备上访问。 – 2011-10-11 03:33:52

相关问题