为了确保Android应用程序的安全性,许多开发人员都会在应用程序中添加root检测代码。然而,有时这些代码可能会无法正常工作。以下是一些可能导致root检测失效的原因:
1.使用通用的root检测代码,这些代码可能已经被黑客熟知,并且可以轻易地规避检测。
例如,以下是使用Java编写的常见root检测代码:
public static boolean isRooted() {
return checkRootMethod1() || checkRootMethod2() || checkRootMethod3() || checkRootMethod4();
}
private static boolean checkRootMethod1() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains("test-keys");
}
private static boolean checkRootMethod2() {
String[] paths = { "/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 (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}
private static boolean checkRootMethod3() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
private static boolean checkRootMethod4() {
return android.os.Build.VERSION.SDK_INT >= 17 && new File("/system/xbin/su").exists();
}
这个代码段向用户返回是否在root的设备上运行的布尔值。然而,它存在一个