Android安全检查之Root环境检测
16lz
2021-01-24
当进入APP的时候检测提示用户
/** * Is rooted boolean. * * @return the boolean */ public static boolean isRooted() { // nexus 5x "/su/bin/" String[] paths = {"/system/xbin/", "/system/bin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"}; try { for (int i = 0; i < paths.length; i++) { String path = paths[i] + "su"; if (new File(path).exists()) { String execResult = exec(new String[]{"ls", "-l", path}); Log.d("cyb", "isRooted=" + execResult); if (TextUtils.isEmpty(execResult) || execResult.indexOf("root") == execResult.lastIndexOf("root")) { return false; } return true; } } } catch (Exception e) { e.printStackTrace(); } return false; } private static String exec(String[] exec) { String ret = ""; ProcessBuilder processBuilder = new ProcessBuilder(exec); try { Process process = processBuilder.start(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { ret += line; } process.getInputStream().close(); process.destroy(); } catch (Exception e) { e.printStackTrace(); } return ret; }
更多相关文章
- Android消息提示框和对话框
- android 摄像头(我想在类里面直接编辑UI界面,但是老是提示空指针,麻
- 安卓自定义属性,Android(安卓)studio无法提示,只提示3个
- Android打造万能适配器--RecyclerView
- error: resource android:attr/fontVariationSettings resource
- Android(安卓)app 权限
- 定制自己的 Android(安卓)Dialog 信息提示对话框
- Android(安卓)Activity基础概念
- android 键盘属性设置总结