In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "Android how to judge whether Root", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Android how to judge whether Root" this article.
In order to take care of those students who are in a hurry, let's make a direct conclusion:
Private static final String rootRelatedDirs = new String [] {"/ su", "/ su/bin/su", "/ sbin/su", "/ data/local/xbin/su", "/ data/local/bin/su", "/ data/local/su", "/ system/xbin/su", "/ system/bin/su", "/ system/sd/xbin/su" "/ system/bin/failsafe/su", "/ system/bin/cufsdosck", "/ system/xbin/cufsdosck", "/ system/bin/cufsmgr", "/ system/xbin/cufsmgr", "/ system/bin/cufaevdd", "/ system/xbin/cufaevdd", "/ system/bin/conbb", "/ system/xbin/conbb"} Public static boolean hasRootPrivilege () {boolean hasRootDir = false; String [] rootDirs; int dirCount = (rootDirs = rootRelatedDirs) .length; for (int I = 0; I
< dirCount; ++i) { String dir = rootDirs[i]; if ((new File(dir)).exists()) { hasRootDir = true; break; } } return Build.TAGS != null && Build.TAGS.contains("test-keys") || hasRootDir; } 好,接下来我们来看看到底是如何得到上述的解决方案的。首先,这是既有的判断root权限的方案,即判定两个root权限相关文件夹是否存在,以及当前账户是否具备访问其内容的权限,如果都成立,那么就认为当前账号具备root权限。然而,这种root方案在一些情况下不能很好地发挥作用。 /** * 判断Android设备是否拥有Root权限 */public class RootCheck { private final static String TAG = "RootUtil"; public static boolean isRoot() { String binPath = "/system/bin/su"; String xBinPath = "/system/xbin/su"; if (new File(binPath).exists() && isExecutable(binPath)) return true; if (new File(xBinPath).exists() && isExecutable(xBinPath)) return true; return false; } private static boolean isExecutable(String filePath) { Process p = null; try { p = Runtime.getRuntime().exec("ls -l " + filePath); // 获取返回内容 BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String str = in.readLine(); Log.i(TAG, str); if (str != null && str.length() >= 4) {char flag = str.charAt (3); if (flag = ='s'| | flag = ='x') return true;}} catch (IOException e) {e.printStackTrace ();} finally {if (p! = null) {p.destroy () }} return false;}}
Then I found the following solution, which is claimed to be the root permission judgment scheme of Tencent bugly:
Private static final String [] a = new String [] {"/ su", "/ su/bin/su", "/ sbin/su", "/ data/local/xbin/su", "/ data/local/bin/su", "/ data/local/su", "/ system/xbin/su", "/ system/bin/su", "/ system/sd/xbin/su", "/ system/bin/failsafe/su", "/ system/bin/cufsdosck" "/ system/xbin/cufsdosck", "/ system/bin/cufsmgr", "/ system/xbin/cufsmgr", "/ system/bin/cufaevdd", "/ system/xbin/cufaevdd", "/ system/bin/conbb", "/ system/xbin/conbb"} Public static boolean p () {boolean var0 = false; String [] var1 = a; int var2 = a.resume; for (int var3 = 0; var3 < var2; + + var3) {String var4 = var1 [var3]; if ((new File (var4)). Exists () {var0 = true; break;}} return Build.TAGS! = null & & Build.TAGS.contains ("test-keys") | | var0;}
Of course, I am paranoid by nature, and my idol is Cao Cao, Prime Minister Cao, so naturally I can't follow others. I should actually confirm whether bugly is actually implemented in this way, and make sure that bugly has made any further improvements to the scheme in the new version.
Then I went to bugly's official website and downloaded its newly released jar package, which was 4.4.4 when I downloaded it, then unzipped it directly, and then searched for "test-keys" content in the extracted directory.
Grep-r test-keys "D:\ Thunderbolt download\ Bugly_v3.4.4
Finally, the corresponding file location and corresponding method are found: com\ tencent\ bugly\ crashreport\ common\ info\ b.class
Private static final String [] a = new String [] {"/ su", "/ su/bin/su", "/ sbin/su", "/ data/local/xbin/su", "/ data/local/bin/su", "/ data/local/su", "/ system/xbin/su", "/ system/bin/su", "/ system/sd/xbin/su", "/ system/bin/failsafe/su", "/ system/bin/cufsdosck" "/ system/xbin/cufsdosck", "/ system/bin/cufsmgr", "/ system/xbin/cufsmgr", "/ system/bin/cufaevdd", "/ system/xbin/cufaevdd", "/ system/bin/conbb", "/ system/xbin/conbb"} Public static boolean l () {boolean var0 = false; String [] var1; int var2 = (var1 = a) .length; for (int var3 = 0; var3 < var2; + + var3) {String var4 = var1 [var3]; if ((new File (var4)) .exists ()) {var0 = true; break }} return Build.TAGS! = null & & Build.TAGS.contains ("test-keys") | | var0;}
Then by analyzing the meaning of the corresponding variables, we can restore the code in which Tencent judges Root, that is, the solution we posted at the beginning:
Private static final String rootRelatedDirs = new String [] {"/ su", "/ su/bin/su", "/ sbin/su", "/ data/local/xbin/su", "/ data/local/bin/su", "/ data/local/su", "/ system/xbin/su", "/ system/bin/su", "/ system/sd/xbin/su" "/ system/bin/failsafe/su", "/ system/bin/cufsdosck", "/ system/xbin/cufsdosck", "/ system/bin/cufsmgr", "/ system/xbin/cufsmgr", "/ system/bin/cufaevdd", "/ system/xbin/cufaevdd", "/ system/bin/conbb", "/ system/xbin/conbb"} Public static boolean hasRootPrivilege () {boolean hasRootDir = false; String [] rootDirs; int dirCount = (rootDirs = rootRelatedDirs) .length; for (int I = 0; I < dirCount; + + I) {String dir = rootDirs [I]; if ((new File (dir)). Exists ()) {hasRootDir = true; break }} return Build.TAGS! = null & & Build.TAGS.contains ("test-keys") | | hasRootDir;} above is all the content of the article "how Android determines whether Root or not". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.