2010-08-06 84 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

相關問題