Android 如何找到根设备?
我一直在尝试查找某个设备是否为根设备,如果该设备为根设备,我不希望安装我的应用程序Android 如何找到根设备?,android,android-activity,su,root,Android,Android Activity,Su,Root,我一直在尝试查找某个设备是否为根设备,如果该设备为根设备,我不希望安装我的应用程序 private boolean isRooted() { return findBinary("su"); } public static boolean findBinary(String binaryName) { boolean found = false; if (!found) { String[] places = { "/sbin/", "/system/bin/", "/sy
private boolean isRooted() {
return findBinary("su");
}
public static boolean findBinary(String binaryName) {
boolean found = false;
if (!found) {
String[] places = { "/sbin/", "/system/bin/", "/system/xbin/",
"/data/local/xbin/", "/data/local/bin/",
"/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/" };
for (String where : places) {
if (new File(where + binaryName).exists()) {
found = true;
break;
}
}
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
Log.e("ERROR", "Unable to find icon for package '"
+ "apk found");
found = true;
}
} catch (Exception e1) {
// ignore
}
}
return found;
}
但我认为这些方法不足以找到根设备,因为有工具可以隐藏apk,并且可以重命名或删除su文件。有没有其他方法或建议可以100%可靠地找到根设备?
我试图编辑su,但什么也做不到。这只是口头的说法还是真的有可能做到?提前谢谢
***编辑***:
我使用“隐藏我的根”应用程序来隐藏SU二进制文件以及superuser.apk。我可以使用“隐藏我的根”应用程序使我的根设备看起来像无根设备。因此,我可以说,该源代码是防错的,并且不完全可靠,无法找到根设备。
请告诉我是否有任何其他方法可以找到根设备 我是这样做的:
/*
* Run su command on device
* @throws IOException, InterruptedException
*/
private static boolean suRun() throws IOException, InterruptedException
{
try {
Process su = null;
su = Runtime.getRuntime().exec(new String[] {"su","-c","exit"});
su.waitFor();
InputStream in = su.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
String suOutput = bufferedReader.readLine();
if (suOutput == null)
{
return true;
}
else
{
return false;
}
} catch (Exception ex)
{
return false;
}
}
public static boolean isPhoneRooted() {
// check if /system/app/Superuser.apk is present and can run su
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists() && suRun()) {
Log.d("Blocking Service", "ROOTED PHONE DETECTED");
return true;
}
}
catch (Throwable e1) {
// ignore
}
return false;
}
我是这样做的:
/*
* Run su command on device
* @throws IOException, InterruptedException
*/
private static boolean suRun() throws IOException, InterruptedException
{
try {
Process su = null;
su = Runtime.getRuntime().exec(new String[] {"su","-c","exit"});
su.waitFor();
InputStream in = su.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
String suOutput = bufferedReader.readLine();
if (suOutput == null)
{
return true;
}
else
{
return false;
}
} catch (Exception ex)
{
return false;
}
}
public static boolean isPhoneRooted() {
// check if /system/app/Superuser.apk is present and can run su
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists() && suRun()) {
Log.d("Blocking Service", "ROOTED PHONE DETECTED");
return true;
}
}
catch (Throwable e1) {
// ignore
}
return false;
}
从ShellInterface调用isRooted()
isRooted()取决于三个因素中的大多数
public static boolean isRooted() {
return isRooted1() ? (isRooted2() || isRooted3()) : (isRooted2() && isRooted3());
}
private static boolean isRooted1() {
Process mProcess = null;
boolean mRoot;
try {
// This is executing on terminal
mProcess = Runtime.getRuntime().exec("su");
mRoot = true;
// If the execute successfully then it return to true
} catch (Exception e) {
// if is not successfully then it return to false
mRoot = false;
} finally {
if (mProcess != null) {
try {
mProcess.destroy();
} catch (Exception ignored) {
}
}
}
return mRoot;
}
private static boolean isRooted2() {
String buildTags = Build.TAGS;
return buildTags !=null && buildTags.contains("test-keys");
}
private static boolean isRooted3() {
boolean mRoot = false;
boolean found = false;
if (!found) {
String[] places = {"/sbin/", "/system/bin/","/system/xbin",
"/data/local/xbin","/system/sd/xbin","/data/local"
};
for (String path : places){
if (new File(path+"su").exists()) {
mRoot = true;
found = true;
}
}
}
return mRoot;
}
从ShellInterface调用isRooted()
isRooted()取决于三个因素中的大多数
public static boolean isRooted() {
return isRooted1() ? (isRooted2() || isRooted3()) : (isRooted2() && isRooted3());
}
private static boolean isRooted1() {
Process mProcess = null;
boolean mRoot;
try {
// This is executing on terminal
mProcess = Runtime.getRuntime().exec("su");
mRoot = true;
// If the execute successfully then it return to true
} catch (Exception e) {
// if is not successfully then it return to false
mRoot = false;
} finally {
if (mProcess != null) {
try {
mProcess.destroy();
} catch (Exception ignored) {
}
}
}
return mRoot;
}
private static boolean isRooted2() {
String buildTags = Build.TAGS;
return buildTags !=null && buildTags.contains("test-keys");
}
private static boolean isRooted3() {
boolean mRoot = false;
boolean found = false;
if (!found) {
String[] places = {"/sbin/", "/system/bin/","/system/xbin",
"/data/local/xbin","/system/sd/xbin","/data/local"
};
for (String path : places){
if (new File(path+"su").exists()) {
mRoot = true;
found = true;
}
}
}
return mRoot;
}
您可以使用google play服务中的API。这是android pay使用的,不仅用于根检测,还用于检查与android CTS的兼容性。您可以使用google play服务的API。这是android pay使用的,不仅用于根检测,还用于检查与android CTS的兼容性。可能重复@golu:请尝试理解我的问题,我想知道一些可靠的方法,而不是这个,就像buildtags。但是buildtags并不适用于所有设备。如果你认为你的问题与标记的重复问题不同,那么你也应该在帖子中提及原因。@Golu:希望你现在理解我的问题@Golu:可能的重复问题请试着理解我的问题,我想知道一些可靠的方法,而不是这个,就像buildtags。但是buildtags并不适用于所有设备。如果你认为你的问题与标记的副本不同,那么你也应该在帖子中提及原因。@Golu:希望你现在明白我的问题了