Android越狱,Root检知

下面贴的代码处理机制比较山寨,其实应该使用谷歌的safetyNet API,然而这个东西在国内不一定可以使用,自求多福。

public boolean isDeviceRooted(){
//第一种情况,需要用真机确认。
        String buildTags = Build.TAGS;
//        if(buildTags!=null && buildTags.contains("test-keys")){
//            Log.d("isDeviceRooted1","1");
//            return true;
//        }

        File file = new File("/system/app/Superuser.apk");
        if(file.exists()){
            Log.d("isDeviceRooted2","2");
            return true;
        }

        if(new ExecShellForRoot().executeCommand(ExecShellForRoot.SHELL_CMD.check_su_binary)!=null){
            Log.d("isDeviceRooted3","3");
            return true;
        }
        return false;
    }

 

public class ExecShellForRoot {
    private static String LOG_TAG = ExecShellForRoot.class.getName();

    public static enum SHELL_CMD {
        check_su_binary(new String[]{"/system/xbin/which", "su"}),;
        String[] command;

        SHELL_CMD(String[] command) {
            this.command = command;
        }
    }

    public ArrayList<String> executeCommand(SHELL_CMD shellCmd) {
        String line = null;
        ArrayList<String> fullResponse = new ArrayList<>();
        Process localProcess = null;
        try {
            localProcess = Runtime.getRuntime().exec(shellCmd.command);
        } catch (Exception e) {
            return null;
        }
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(localProcess.getOutputStream()));
        BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
        try {
            while ((line = in.readLine()) != null) {
                LogUtility.debug(ExecShellForRoot.class, "execeuteCommand", "Line received:" + line);
                fullResponse.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return fullResponse;
    }
}

 

转载于:https://my.oschina.net/u/3760785/blog/1600611

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值