Android如何判断系统是否已经被Root

前言

  • 实体手机的Root本文不讨论,只讨论Android模拟器的Root问题。
  • 在Android模拟器上运行的APP有时会提示:“设备已Root,使用软件可能存在安全风险”
  • 本文分析在Android模拟器系统中如何解决这个问题。

App检测Android系统是否已经Root的几种方法

1 判断系统内是否包含 su

/**
 * 是否存在su命令,并且有执行权限
 *
 * @return 存在su命令,并且有执行权限返回true
 */
public static boolean isSuEnable() {
    File file = null;
    String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};
    try {
        for (String path : paths) {
            file = new File(path + "su");
            if (file.exists() && file.canExecute()) {
                Log.i(TAG, "find su in : " + path);
                return true;
            }
        }
    } catch (Exception x) {
        x.printStackTrace();
    }
    return false;
}

2 判断系统内是否包含 busybox

/**
 * 是否存在busybox命令,并且有执行权限
 *
 * @return 存在busybox命令,并且有执行权限返回true
 */
public static boolean isSuEnable() {
    File file = null;
    String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};
    try {
        for (String path : paths) {
            file = new File(path + "busybox");
            if (file.exists() && file.canExecute()) {
                Log.i(TAG, "find su in : " + path);
                return true;
            }
        }
    } catch (Exception x) {
        x.printStackTrace();
    }
    return false;
}

3. 检测系统内是否安装了Superuser.apk之类的App

    public static boolean checkSuperuserApk(){
        try {
            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;
    }

4. 检测系统是否为测试版

在系统adb shell中执行:

# cat /system/build.prop | grep ro.build.tags
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的版本,存在使用风险。

5. 检测系统挂载目录权限

检测Android 沙盒目录文件或文件夹读取权限(在Android系统中,有些目录是普通用户不能访问的,例如 /data、/system、/etc 等;比如微信沙盒目录下的文件或文件夹权限是否正常)

6 判断ro.debuggable属性和ro.secure属性

默认手机出厂后ro.debuggable属性应该为0,ro.secure应该为1。意思就是系统版本要为user版本。

  • 9
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小馬佩德罗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值