无名 发表于 2022-5-8 18:39:29

[HC]Android判断APP是否拥有root权限

应用判断是否具有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;
}
http://cdn.u1.huluxia.com/g3/M01/3C/39/wKgBOV3LjKmAJv45AABo3Uvlgtw993.jpg
页: [1]
查看完整版本: [HC]Android判断APP是否拥有root权限