可能重复:
确定是否在root设备上运行
如何(以编程方式)确定Android设备是否:rooted运行软件或ROM的破解副本.
我的数据库中有一些敏感信息,我希望在手机被root用户时加密,即用户可以访问数据库.我怎么检测到?
pec*_*eps 37
生根检测是一种猫捉老鼠游戏,很难进行生根检测,适用于所有情况下的所有设备.
请参阅Android Root Beer https://github.com/scottyab/rootbeer以获取高级根检测,该检测还使用编译到.so本机库中的JNI和本机CPP代码.
如果您需要一些简单和基本的生根检测,请检查以下代码:
/**
* 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;
}
Run Code Online (Sandbox Code Playgroud)
可能并不总是正确的.2014年测试了~10台设备.
归档时间: |
|
查看次数: |
41011 次 |
最近记录: |