检测为绕过root检测已打开怎么解决

由于项目需要root安装软件,并且希望在合适的时候引导用户去开启root安装,故需要检测手机是否root。
最基本的判断如下,直接运行一个底层命令。(参考)
也可参考csdn&&
* check whether has root permission
public static boolean checkRootPermission() {
return execCommand("echo root", true, false).result == 0;
* execute shell commands
* @param commands
command array
* @param isRoot
whether need to run with root
* @param isNeedResultMsg
whether need result msg
* @return &ul&
&li&if isNeedResultMsg is false, {@link CommandResult#successMsg}
is null and {@link CommandResult#errorMsg} is null.&/li&
&li&if {@link CommandResult#result} is -1, there maybe some
excepiton.&/li&
public static CommandResult execCommand(String[] commands, boolean isRoot,
boolean isNeedResultMsg) {
int result = -1;
if (commands == null || commands.length == 0) {
return new CommandResult(result, null, null);
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = null;
StringBuilder errorMsg = null;
DataOutputStream os = null;
process = Runtime.getRuntime().exec(
isRoot ? COMMAND_SU : COMMAND_SH);
os = new DataOutputStream(process.getOutputStream());
for (String command : commands) {
if (command == null) {
// donnot use os.writeBytes(commmand), avoid chinese charset
os.write(command.getBytes());
os.writeBytes(COMMAND_LINE_END);
os.flush();
os.writeBytes(COMMAND_EXIT);
os.flush();
result = process.waitFor();
// get command result
if (isNeedResultMsg) {
successMsg = new StringBuilder();
errorMsg = new StringBuilder();
successResult = new BufferedReader(new InputStreamReader(
process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (os != null) {
os.close();
if (successResult != null) {
successResult.close();
if (errorResult != null) {
errorResult.close();
} catch (IOException e) {
e.printStackTrace();
if (process != null) {
process.destroy();
return new CommandResult(result, successMsg == null ? null
: successMsg.toString(), errorMsg == null ? null
: errorMsg.toString());
* result of command,
* &li&{@link CommandResult#result} means result of command, 0 means normal,
* else means error, same to excute in linux shell&/li&
* &li&{@link CommandResult#successMsg} means success message of command
* result&/li&
* &li&{@link CommandResult#errorMsg} means error message of command result&/li&
* @author Trinea
public static class CommandResult {
/** result of command **/
public int
/** success message of command result **/
public String successM
/** error message of command result **/
public String errorM
public CommandResult(int result) {
this.result =
public CommandResult(int result, String successMsg, String errorMsg) {
this.result =
this.successMsg = successM
this.errorMsg = errorM
* execute shell command, default return result msg
* @param command
* @param isRoot
whether need to run with root
* @see ShellUtils#execCommand(String[], boolean, boolean)
public static CommandResult execCommand(String command, boolean isRoot) {
return execCommand(new String[] { command }, isRoot, true);
但是这会带来一个问题,每次判断是否root都会弹出一个root请求框。这是十分不友好的一种交互方式,而且,用户如果选择取消,有部分手机是判断为非root的。
这是方法一。交互不友好,而且有误判。
在这个情况下,为了不弹出确认框,考虑到一般root手机都会有一些的特殊文件夹,比如/system/bin/su,/system/xbin/su,里面存放有相关的权限控制文件。
因此只要手机中有一个文件夹存在就判断这个手机root了。
然后经过测试,这种方法在大部分手机都可行。
代码如下:
/** 判断是否具有ROOT权限 ,此方法对有些手机无效,比如小米系列 */
public static boolean isRoot() {
boolean res = false;
if ((!new File("/system/bin/su").exists())
&& (!new File("/system/xbin/su").exists())) {
res = false;
res = true;
} catch (Exception e) {
res = false;
这是方法二。交互友好,但是有误判。
后来测试的过程中发现部分国产,比如小米系列,有这个文件夹,但是系统是未root的,判断成了已root。经过分析,这是由于小米有自身的权限控制系统而导致。
考虑到小米手机有大量的用户群,这个问题必须解决,所以不得不寻找第三种方案。
从原理着手,小米手机无论是否root,应该都是具有相关文件的。但是无效的原因应该是,文件设置了相关的权限。导致用户组无法执行相关文件。
从这个角度看,就可以从判断文件的权限入手。
先看下linux的文件权限吧。
linux文件权限详细可参考《鸟叔的linux私房菜》
只需要在第二种方法的基础上,再另外判断文件拥有者对这个文件是否具有可执行权限(第4个字符的状态),就基本可以确定手机是否root了。
在已root手机上(三星i9100 android 4.4),文件权限(x或者s,s权限,可参考)如下
未root手机,大部分手机没有这两个文件夹,小米手机有这个文件夹。未root小米手机权限如下(由于手头暂时没有小米手机,过几天补上,或者有同学帮忙补上,那真是感激不尽)。
【等待补充图片】
代码如下:
/** 判断手机是否root,不弹出root请求框&br/& */
public static boolean isRoot() {
String binPath = "/system/bin/su";
String xBinPath = "/system/xbin/su";
if (new File(binPath).exists() && isExecutable(binPath))
return true;
if (new File(xBinPath).exists() && isExecutable(xBinPath))
return true;
return false;
private static boolean isExecutable(String filePath) {
Process p = null;
p = Runtime.getRuntime().exec("ls -l " + filePath);
// 获取返回内容
BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String str = in.readLine();
Log.i(TAG, str);
if (str != null && str.length() &= 4) {
char flag = str.charAt(3);
if (flag == 's' || flag == 'x')
return true;
} catch (IOException e) {
e.printStackTrace();
if(p!=null){
p.destroy();
return false;
这种方法基本可以判断所有的手机,而且不弹出root请求框。这才是我们需要的,perfect。
方法三,交互友好,基本没有误判。
以下是apk以及相关源代码,大家可以下载apk看下运行效果
ROOT检测APK下载地址:
ROOT检测代码下载:或者
如果有手机使用方法三无法判断,欢迎提出。
也欢迎大家提出其他的更好的办法。
阅读(...) 评论()手机已经Root了。但是钛备份还显现“请检查您的ROM已经ROOT并且包含BusyBox,再重新运行”_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
手机已经Root了。但是钛备份还显现“请检查您的ROM已经ROOT并且包含BusyBox,再重新运行”
手机:索爱X10版本:2.1.正确来说2.0.A.0.504手机已经按照软件(SuperOneClick1.5)Root而且手机里面也出现了权限管理,但是安装了钛备份,打开就说“请检查您的ROM已经ROOT并且包含BusyBox,再重新运行”。。。我晕了。第二个就是上网管家的应用问题,权限管...
我有更好的答案
请允许,有的软件运行的时候会提示的,
采纳率:49%
为您推荐:
换一换
回答问题,赢新手礼包出于安全原因,我们的应用程序不建议在已经root的设备上运行,所以需要检测是否设备已经root,以提示用户若继续使用会存在风险。
那么root了会有什么风险呢,为什么不root就没有风险,又怎么来检查手机是否root了?
我们先来了解下Android安全机制:
Android安全架构是基于Linux多用户机制的访问控制。应用程序在默认的情况下不可以执行其他应用程序,包括读或写用户的私有数据(如联系人数据或email数据),读或写另一个应用程序的文件。
一个应用程序的进程就是一个安全的沙盒(在受限的安全环境中运行应用程序,在沙盒中的所有改动对操作系统不会造成任何危害)。它不能干扰其它应用程序,除非显式地声明了“permissions”,以便它能够获取基本沙盒所不具备的额外的能力。
每一个Android应用程序都会在安装时就分配一个独有的Linux用户ID,这就为它建立了一个沙盒,使其不能与其他应用程序进行接触。这个用户ID会在安装时分配给它,并在该设备上一直保持同一个数值。
所有的Android应用程序必须用证书进行签名认证,而这个证书的私钥是由开发者保有的。该证书可以用以识别应用程序的作者。签名影响安全性的最重要的方式是通过决定谁可以进入基于签名的permisssions,以及谁可以share 用户IDs。通过这样的机制,在不考虑root用户的情况下,每个应用都是相互隔离的,实现了一定的安全。
为什么要把root排除在外,才能说应用的隔离是安全的呢?
在Linux操作系统中,root的权限是最高的,也被称为超级权限的拥有者。
在系统中,每个文件、目录和进程,都归属于某一个用户,没有用户许可其它普通用户是无法操作的,但对root除外。
root用户的特权性还表现在:root可以超越任何用户和用户组来对文件或目录进行读取、修改或删除(在系统正常的许可范围内);对可执行程序的执行、终止;对硬件设备的添加、创建和移除等;也可以对文件和目录进行属主和权限进行修改,以适合系统管理的需要(因为root是系统中权限最高的特权用户);root是超越任何用户和用户组的,基于用户ID的权限机制的沙盒是隔离不了它的。
接下来了解下root的方式
通常可以分为2种:
1,不完全Root
2,完全Root
目前获取Android root 权限常用方法是通过各种系统漏洞,替换或添加SU程序到设备,获取Root权限,而在获取root权限以后,会装一个程序用以提醒用户是否给予程序最高权限,可以一定程度上防止恶意软件,通常会使用Superuser或者 SuperSU ,这种方法通常叫做“不完全Root”。
而 “完全ROOT”是指,替换设备原有的ROM,以实现取消secure设置。
root检测的方法
下面介绍下root检测的各种方法:
1,查看系统是否测试版
我们可以查看发布的系统版本,是test-keys(测试版),还是release-keys(发布版)。
可以先在adb shell中运行下命令查看:
root@android:/
ro.build.tags=release-keys
这个返回结果“release-keys”,代表此系统是正式发布版。
在代码中的检测方法如下:
public static boolean checkDeviceDebuggable(){
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
Log.i(LOG_TAG,"buildTags="+buildTags);
return true;
return false;
若是非官方发布版,很可能是完全root的版本,存在使用风险。
可是在实际情况下,我遇到过某些厂家的正式发布版本,也是test-keys,可能大家对这个标识也不是特别注意吧。所以具体是否使用,还要多考虑考虑呢。也许能解决问题,也许会给自己带来些麻烦。
2,检查是否存在Superuser.apk
Superuser.apk是一个被广泛使用的用来root安卓设备的软件,所以可以检查这个app是否存在。
检测方法如下:
public static boolean checkSuperuserApk(){
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
Log.i(LOG_TAG,"/system/app/Superuser.apk exist");
return true;
} catch (Exception e) { }
return false;
3,检查su命令
su是Linux下切换用户的命令,在使用时不带参数,就是切换到超级用户。通常我们获取root权限,就是使用su命令来实现的,所以可以检查这个命令是否存在。
有三个方法来测试su是否存在:
1)检测在常用目录下是否存在su
public static boolean checkRootPathSU()
File f=null;
final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"};
for(int i=0;i&kSuSearchPaths.i++)
f=new File(kSuSearchPaths[i]+"su");
if(f!=null&&f.exists())
Log.i(LOG_TAG,"find su in : "+kSuSearchPaths[i]);
return true;
}catch(Exception e)
e.printStackTrace();
return false;
这个方法是检测常用目录,那么就有可能漏过不常用的目录。
所以就有了第二个方法,直接使用shell下的命令来查找。
2)使用which命令查看是否存在su
which是linux下的一个命令,可以在系统PATH变量指定的路径中搜索某个系统命令的位置并且返回第一个搜索结果。
这里,我们就用它来查找su。
public static boolean checkRootWhichSU() {
String[] strCmd = new String[] {"/system/xbin/which","su"};
ArrayList&String& execResult = executeCommand(strCmd);
if (execResult != null){
Log.i(LOG_TAG,"execResult="+execResult.toString());
return true;
Log.i(LOG_TAG,"execResult=null");
return false;
其中调用了一个函数 executeCommand(),是执行linux下的shell命令。具体实现如下:
public static ArrayList&String& executeCommand(String[] shellCmd){
String line = null;
ArrayList&String& fullResponse = new ArrayList&String&();
Process localProcess = null;
Log.i(LOG_TAG,"to shell exec which for find su :");
localProcess = Runtime.getRuntime().exec(shellCmd);
} catch (Exception e) {
return null;
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
while ((line = in.readLine()) != null) {
Log.i(LOG_TAG,"–& Line received: " + line);
fullResponse.add(line);
} catch (Exception e) {
e.printStackTrace();
Log.i(LOG_TAG,"–& Full response was: " + fullResponse);
return fullR
然而,这个方法也存在一个缺陷,就是需要系统中存在which这个命令。我在测试过程中,就遇到有的Android系统中没有这个命令,所以,这也不是一个完全有保障的方法,倒是可以和上一个方法(在常用路径下查找)进行组合,能提升成功率。
这种查找命令的方式,还有一种缺陷,就是可能系统中存在su,但是已经失效的情况。例如,我曾经root过,后来又取消了,就可能出现这种情况:有su这个文件,但是当前设备不是root的。
3)执行su,看能否获取到root权限
由于上面两种查找方法都存在可能查不到的情况,以及有su文件与设备root的差异,所以,有这第三中方法:我们执行这个命令su。这样,系统就会在PATH路径中搜索su,如果找到,就会执行,执行成功后,就是获取到真正的超级权限了。
具体代码如下:
public static synchronized boolean checkGetRootAuth()
Process process = null;
DataOutputStream os = null;
Log.i(LOG_TAG,"to exec su");
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("exit\n");
os.flush();
int exitValue = process.waitFor();
Log.i(LOG_TAG, "exitValue="+exitValue);
if (exitValue == 0)
return true;
return false;
} catch (Exception e)
Log.i(LOG_TAG, "Unexpected error - Here is what I know: "
+ e.getMessage());
return false;
if (os != null)
os.close();
process.destroy();
} catch (Exception e)
e.printStackTrace();
这种检测su的方法,应该是最靠谱的,不过,也有个问题,就是在已经root的设备上,会弹出提示框,请求给app开启root权限。这个提示不太友好,可能用户会不喜欢。
如果想安静的检测,可以用上两种方法的组合;如果需要尽量安全的检测到,还是执行su吧。
4,执行busybox
Android是基于Linux系统的,可是在终端Terminal中操作,会发现一些基本的命令都找不到。这是由于Android系统为了安全,将可能带来风险的命令都去掉了,最典型的,例如su,还有find、mount等。对于一个已经获取了超级权限的人来讲,这是很不爽的事情,所以,便要想办法加上自己需要的命令了。一个个添加命令也麻烦,有一个很方便的方法,就是使用被称为“嵌入式Linux中的瑞士军刀”的Busybox。简单的说BusyBox就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令。
所以若设备root了,很可能Busybox也被安装上了。这样我们运行busybox测试也是一个好的检测方法。
public static synchronized boolean checkBusybox()
Log.i(LOG_TAG,"to exec busybox df");
String[] strCmd = new String[] {"busybox","df"};
ArrayList&String& execResult = executeCommand(strCmd);
if (execResult != null){
Log.i(LOG_TAG,"execResult="+execResult.toString());
return true;
Log.i(LOG_TAG,"execResult=null");
return false;
} catch (Exception e)
Log.i(LOG_TAG, "Unexpected error - Here is what I know: "
+ e.getMessage());
return false;
5,访问/data目录,查看读写权限
在Android系统中,有些目录是普通用户不能访问的,例如 /data、/system、/etc 等。
我们就已/data为例,来进行读写访问。本着谨慎的态度,我是先写入一个文件,然后读出,查看内容是否匹配,若匹配,才认为系统已经root了。
public static synchronized boolean checkAccessRootData()
Log.i(LOG_TAG,"to write /data");
String fileContent = "test_ok";
Boolean writeFlag = writeFile("/data/su_test",fileContent);
if (writeFlag){
Log.i(LOG_TAG,"write ok");
Log.i(LOG_TAG,"write failed");
Log.i(LOG_TAG,"to read /data");
String strRead = readFile("/data/su_test");
Log.i(LOG_TAG,"strRead="+strRead);
if(fileContent.equals(strRead)){
return true;
return false;
} catch (Exception e)
Log.i(LOG_TAG, "Unexpected error - Here is what I know: "
+ e.getMessage());
return false;
上面的代码,调用了两个函数:writeFile()写文件,readFile()读文件,下面是具体实现:
public static Boolean writeFile(String fileName,String message){
FileOutputStream fout = new FileOutputStream(fileName);
byte [] bytes = message.getBytes();
fout.write(bytes);
fout.close();
return true;
catch(Exception e){
e.printStackTrace();
return false;
public static String readFile(String fileName){
File file = new File(fileName);
FileInputStream fis= new FileInputStream(file);
byte[] bytes = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len=fis.read(bytes))&0){
bos.write(bytes, 0, len);
String result = new String(bos.toByteArray());
Log.i(LOG_TAG, result);
} catch (Exception e) {
e.printStackTrace();
return null;
这里说句题外话,我最初是想使用shell命令来写文件:
echo "test_ok" & /data/su_test
可是使用executeCommand()来调用执行这个命令,结果连文件都没有创建出来。在多次失败后才想到:应该是这个shell命令涉及到了重定向(例如本例中,将本来应该屏幕输出的信息转而写入文件中),才导致的失败。这个重定向应该是需要写代码获取数据流来自己实现。不过,既然要写代码使用数据流,那么我可以更简单的直接写文件,就没有去尝试用代码来实现重定向了。
由于每种方法各有其特色与缺陷,所以我最终将这些方法加起来了。注意,检查su的3种方法,不必都使用上,可以选第一二种查找的方法,或者选第三种执行的方法。
组合调用的代码如下:
private static String LOG_TAG = CheckRoot.class.getName();
public static boolean isDeviceRooted() {
if (checkDeviceDebuggable()){return true;}
if (checkSuperuserApk()){return true;}
if (checkBusybox()){return true;}
if (checkAccessRootData()){return true;}
if (checkGetRootAuth()){return true;}
return false;
本文已收录于以下专栏:
相关文章推荐
判断手机是否具有ROOT限
许多机友新购来的Android机器没有破解过Root权限,无...
app发布后,一些root用户可能会修改我们应用的一些信息,如传感器获得的数据,那么这些用户的数据就不在具有参考价值,应该被单独列出,
以方便数据的分析,所以就有了本文。
下面是检测Android设备...
系统Root检测 -
/system/bin/su & /system/xbin/su
【1】破解手机ROOT权限的原理,就是在手机的/system/bin和/system/xb...
第1章 Root的基本原理Android的内核就是Linux,所以Android获取root其实和Linux获取root权限是一回事儿。你想在Linux下获取root权限的时候就是执行sudo或者su...
方法一:(不弹框)
public static boolean isRootSystem() {
if (systemRootState == kSystemRootStateEnable) {
**方法一:(不弹框)
判断文件存在的形式判断是否已经root
private final static int kSystemRootStateUnknow = -1;
封装了一个类,代码如下:
public class ShellCommand {
private Boolean can_
public SH ...
检测安卓手机是否已经Root/**
* 反编译支付宝SDK得到的判断root的方法,并增加了对‘/su/bin/’目录的判断
* Created by cyb on
关于android中root权限的相关判断与获取,我咋这里做一下笔记。
首先是判断手机是否有root权限:
* 判断当前手机是否有ROOT权限
* @retur...
android (linux)很多命令需要root权限才能执行,比如说查看系统目录文件等,如果我们的程序需要用到查看此类文件或执行系统命令,就必须先获取Root权限。
他的最新文章
讲师:李江龙
讲师:司徒正美
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)怎么查看手机是否Root超简单教程
稿源:中国站长站
手机查看root的方式以前一般是推荐进入工程模式去查看,比较麻烦,也让出入安卓的小白来说会有点惊恐,怕变砖头,及时那样的话,也不会变砖头的哈。
如果你手机已经root了。你手机基本上会显示一些信息来证明你的手机已经获取了root权限,反之就是没有
方式一:授权管理软件的安装,这个如果不是自己本人的安装或者仅仅是刷入rom就有的话,那这个图标也可以代表你已经获取了root权限
这个软件会根据不同的ROOT工具有所区别,大致名字都是supersu权限管理之类的
方式二:日常需要root软件使用时会提示root权限的获取,反之则是没有,想反的会提示没有获取ROOT权限没有获取之类(可以试试QQ的截图功能)
方式三:安装一个360优化大师,查看硬件设施的时候,也会显示你手机的ROOT权限
有好的文章希望站长之家帮助分享推广,猛戳这里
本网页浏览已超过3分钟,点击关闭或灰色背景,即可回到网页

我要回帖

更多关于 防root检测 的文章

 

随机推荐