无名商城论坛

搜索
查看: 332|回复: 0

[其他技术] [HC]Android判断APP是否拥有root权限

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
32464
发表于 2022-5-8 18:39:29 | 显示全部楼层 |阅读模式
应用判断是否具有root权限,只需要看能否在data分区创建文件,如果能够在data分区创建文件,那么应用具有root权限

public static boolean upgradeRootPermission( ) {  
   Process process = null;  
   DataOutputStream os = null;  
   try {  

    Log.i("roottest", "try it");
    String cmd = "touch /data/roottest.txt";
       process = Runtime.getRuntime().exec("su"); //切换到root帐号  
       os = new DataOutputStream(process.getOutputStream());  
       os.writeBytes(cmd + "\n");  
       os.writeBytes("exit\n");  
       os.flush();  
       process.waitFor();  
   } catch (Exception e) {  
       return false;  
   } finally {  
       try {  
           if (os != null) {  
               os.close();  
           }  
           process.destroy();  
       } catch (Exception e) {  
       }  
   }  
   return true;  
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表