{"id":1301,"date":"2023-03-18T10:31:26","date_gmt":"2023-03-18T02:31:26","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1301"},"modified":"2023-04-29T09:17:16","modified_gmt":"2023-04-29T01:17:16","slug":"android-checks-if-phone-is-rooted","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/18\/android-checks-if-phone-is-rooted\/","title":{"rendered":"Android\u68c0\u67e5\u624b\u673a\u662f\u5426\u88abroot"},"content":{"rendered":"<p>\u76ee\u524d\u6765\u8bf4Android\u5e73\u53f0\u5e76\u6ca1\u6709\u63d0\u4f9b\u80fd\u591froot\u68c0\u67e5\u7684\u5de5\u5177\u3002\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u5f0f\u6765\u5224\u65ad<\/p>\n<ul>\n<li>\u7cfb\u7edf\u662f\u5426\u5305\u542bsu\u6587\u4ef6<\/li>\n<li>su\u6587\u4ef6\u662f\u5426\u80fd\u591f\u6267\u884c<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<p>\u4f46\u662f\u8fd9\u4e24\u79cd\u68c0\u67e5\u65b9\u5f0f\u90fd\u5b58\u5728\u7f3a\u70b9\uff1a<\/p>\n<p>\uff081\uff09\u7b2c\u4e00\u79cd\u5b58\u5728\u8bef\u6d4b\u548c\u6f0f\u6d4b\u7684\u60c5\u51b5\uff0c\u6bd4\u5982su\u6ca1\u6709\u653e\u5230\u5e38\u89c4\u8def\u5f84\u4e0b\uff0c\u5c31\u5bb9\u6613\u6f0f\u6389\uff0c\u4f46\u662f\u8fd9\u79cd\u60c5\u51b5\u662f\u6709\u529e\u6cd5\u5c3d\u91cf\u89c4\u907f\uff08\u6216\u8005\u8bf4\u51cf\u5c0f\u8bef\u5dee\uff09\u7684\uff0c\u6bd4\u55bb\u8fd0\u884cwhich\u68c0\u67e5\uff0c\u6216\u8005\u904d\u5386shell\u4e2d\u6240\u6709\u7684\u73af\u5883\u53d8\u91cf\u7684PATH\uff1b\u8fd8\u6709\u4e00\u79cd\u60c5\u51b5\u662f\u624b\u673a\u6ca1\u6709root\u4f46\u662f\u5b58\u5728su\u6587\u4ef6\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e00\u822c\u51fa\u73b0\u5728\u624b\u673a\u66fe\u7ecf\u88abroot\u8fc7\uff0c\u4f46\u662f\u53c8\u8fdb\u884c\u4e86\u7cfb\u7edf\u8fd8\u539f\u64cd\u4f5c\u3002<br \/>\n\uff082\uff09\u800c\u7b2c\u4e8c\u79cd\uff0c\u6709\u53ef\u80fd\u68c0\u67e5\u4e0d\u51c6\u786e\uff0c\u6216\u8005\u4f1a\u6709\u5f39\u7a97\u63d0\u793a\u7528\u6237\u662f\u5426\u8981\u6388\u4e88root\u6743\u9650\u3002<\/p>\n<pre><code class=\"language-java\">public class RootUtil {\n    public static boolean isDeviceRooted() {\n        return checkRootBuildTags() || checkRootFile() || checkSuFile();\n    }\n\n    private static boolean checkRootBuildTags() {\n        String buildTags = android.os.Build.TAGS;\n        return buildTags != null &amp;&amp; buildTags.contains(&quot;test-keys&quot;);\n    }\n\n    private static boolean checkRootFile() {\n        String[] paths = { &quot;\/system\/app\/Superuser.apk&quot;, &quot;\/sbin\/su&quot;, &quot;\/system\/bin\/su&quot;, &quot;\/system\/xbin\/su&quot;, &quot;\/data\/local\/xbin\/su&quot;, &quot;\/data\/local\/bin\/su&quot;, &quot;\/system\/sd\/xbin\/su&quot;,\n                &quot;\/system\/bin\/failsafe\/su&quot;, &quot;\/data\/local\/su&quot;, &quot;\/su\/bin\/su&quot;};\n        for (String path : paths) {\n            if (new File(path).exists()) return true;\n        }\n        return false;\n    }\n\n    private static boolean checkSuFile() {\n        Process process = null;\n        try {\n            \/\/  \/system\/xbin\/which \u6216\u8005 \/system\/bin\/which\n            process = Runtime.getRuntime().exec(new String[]{&quot;which&quot;, &quot;su&quot;});\n            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));\n            if (in.readLine() != null) return true;\n            return false;\n        } catch (Throwable t) {\n            return false;\n        } finally {\n            if (process != null) process.destroy();\n        }\n    }\n\n}<\/code><\/pre>\n<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/blog.csdn.net\/niyingxunzong\/article\/details\/77371425\" title=\"Android\u68c0\u67e5\u624b\u673a\u662f\u5426\u88abroot\">Android\u68c0\u67e5\u624b\u673a\u662f\u5426\u88abroot<\/a><br \/>\n\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/1101380\/determine-if-running-on-a-rooted-device\" title=\"determine-if-running-on-a-rooted-device\">determine-if-running-on-a-rooted-device<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u524d\u6765\u8bf4Android\u5e73\u53f0\u5e76\u6ca1\u6709\u63d0\u4f9b\u80fd\u591froot\u68c0\u67e5\u7684\u5de5\u5177\u3002\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u5f0f\u6765\u5224\u65ad \u7cfb\u7edf\u662f\u5426\u5305\u542bsu\u6587\u4ef6  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[311],"tags":[],"class_list":["post-1301","post","type-post","status-publish","format-standard","hentry","category-android-advance"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1301"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1301\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}