Advertisement
Mr_hEx

Untitled

Jun 25th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.61 KB | None | 0 0
  1. Android for check root !!
  2. ------------------------
  3. package com.scottyab.rootbeer;
  4.  
  5. import android.content.Context;
  6. import android.content.pm.PackageManager;
  7. import android.os.Build;
  8. import com.facebook.appevents.AppEventsConstants;
  9. import com.scottyab.rootbeer.util.QLog;
  10. import java.io.BufferedReader;
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. import java.io.InputStreamReader;
  15. import java.util.ArrayList;
  16. import java.util.Arrays;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.NoSuchElementException;
  21. import java.util.Scanner;
  22.  
  23. public class RootBeer {
  24. private boolean loggingEnabled = true;
  25. private final Context mContext;
  26.  
  27. public RootBeer(Context context) {
  28. this.mContext = context;
  29. }
  30.  
  31. public boolean isRooted() {
  32. return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary("su") || checkForBinary("busybox") || checkForDangerousProps() || checkForRWPaths() || detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
  33. }
  34.  
  35. public boolean isRootedWithoutBusyBoxCheck() {
  36. return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary("su") || checkForDangerousProps() || checkForRWPaths() || detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
  37. }
  38.  
  39. public boolean detectTestKeys() {
  40. String buildTags = Build.TAGS;
  41. return buildTags != null && buildTags.contains("test-keys");
  42. }
  43.  
  44. public boolean detectRootManagementApps() {
  45. return detectRootManagementApps((String[]) null);
  46. }
  47.  
  48. public boolean detectRootManagementApps(String[] additionalRootManagementApps) {
  49. ArrayList<String> packages = new ArrayList<>();
  50. packages.addAll(Arrays.asList(Const.knownRootAppsPackages));
  51. if (additionalRootManagementApps != null && additionalRootManagementApps.length > 0) {
  52. packages.addAll(Arrays.asList(additionalRootManagementApps));
  53. }
  54. return isAnyPackageFromListInstalled(packages);
  55. }
  56.  
  57. public boolean detectPotentiallyDangerousApps() {
  58. return detectPotentiallyDangerousApps((String[]) null);
  59. }
  60.  
  61. public boolean detectPotentiallyDangerousApps(String[] additionalDangerousApps) {
  62. ArrayList<String> packages = new ArrayList<>();
  63. packages.addAll(Arrays.asList(Const.knownDangerousAppsPackages));
  64. if (additionalDangerousApps != null && additionalDangerousApps.length > 0) {
  65. packages.addAll(Arrays.asList(additionalDangerousApps));
  66. }
  67. return isAnyPackageFromListInstalled(packages);
  68. }
  69.  
  70. public boolean detectRootCloakingApps() {
  71. return detectRootCloakingApps((String[]) null) || (canLoadNativeLibrary() && !checkForNativeLibraryReadAccess());
  72. }
  73.  
  74. public boolean detectRootCloakingApps(String[] additionalRootCloakingApps) {
  75. ArrayList<String> packages = new ArrayList<>();
  76. packages.addAll(Arrays.asList(Const.knownRootCloakingPackages));
  77. if (additionalRootCloakingApps != null && additionalRootCloakingApps.length > 0) {
  78. packages.addAll(Arrays.asList(additionalRootCloakingApps));
  79. }
  80. return isAnyPackageFromListInstalled(packages);
  81. }
  82.  
  83. public boolean checkForSuBinary() {
  84. return checkForBinary("su");
  85. }
  86.  
  87. public boolean checkForMagiskBinary() {
  88. return checkForBinary("magisk");
  89. }
  90.  
  91. public boolean checkForBusyBoxBinary() {
  92. return checkForBinary("busybox");
  93. }
  94.  
  95. public boolean checkForBinary(String filename) {
  96. boolean result = false;
  97. for (String path : Const.suPaths) {
  98. String completePath = path + filename;
  99. if (new File(path, filename).exists()) {
  100. QLog.v(completePath + " binary detected!");
  101. result = true;
  102. }
  103. }
  104. return result;
  105. }
  106.  
  107. public void setLogging(boolean logging) {
  108. this.loggingEnabled = logging;
  109. QLog.LOGGING_LEVEL = logging ? 5 : 0;
  110. }
  111.  
  112. private String[] propsReader() {
  113. try {
  114. InputStream inputstream = Runtime.getRuntime().exec("getprop").getInputStream();
  115. if (inputstream == null) {
  116. return null;
  117. }
  118. return new Scanner(inputstream).useDelimiter("\\A").next().split("\n");
  119. } catch (IOException | NoSuchElementException e) {
  120. e.printStackTrace();
  121. return null;
  122. }
  123. }
  124.  
  125. private String[] mountReader() {
  126. try {
  127. InputStream inputstream = Runtime.getRuntime().exec("mount").getInputStream();
  128. if (inputstream == null) {
  129. return null;
  130. }
  131. return new Scanner(inputstream).useDelimiter("\\A").next().split("\n");
  132. } catch (IOException | NoSuchElementException e) {
  133. e.printStackTrace();
  134. return null;
  135. }
  136. }
  137.  
  138. private boolean isAnyPackageFromListInstalled(List<String> packages) {
  139. boolean result = false;
  140. PackageManager pm = this.mContext.getPackageManager();
  141. for (String packageName : packages) {
  142. try {
  143. pm.getPackageInfo(packageName, 0);
  144. QLog.e(packageName + " ROOT management app detected!");
  145. result = true;
  146. } catch (PackageManager.NameNotFoundException e) {
  147. }
  148. }
  149. return result;
  150. }
  151.  
  152. public boolean checkForDangerousProps() {
  153. Map<String, String> dangerousProps = new HashMap<>();
  154. dangerousProps.put("ro.debuggable", AppEventsConstants.EVENT_PARAM_VALUE_YES);
  155. dangerousProps.put("ro.secure", AppEventsConstants.EVENT_PARAM_VALUE_NO);
  156. boolean result = false;
  157. String[] lines = propsReader();
  158. if (lines == null) {
  159. return false;
  160. }
  161. for (String line : lines) {
  162. for (String key : dangerousProps.keySet()) {
  163. if (line.contains(key)) {
  164. String badValue = "[" + dangerousProps.get(key) + "]";
  165. if (line.contains(badValue)) {
  166. QLog.v(key + " = " + badValue + " detected!");
  167. result = true;
  168. }
  169. }
  170. }
  171. }
  172. return result;
  173. }
  174.  
  175. public boolean checkForRWPaths() {
  176. String[] lines;
  177. String[] lines2;
  178. String[] lines3 = mountReader();
  179. if (lines3 == null) {
  180. return false;
  181. }
  182. int length = lines3.length;
  183. boolean result = false;
  184. int i = 0;
  185. while (i < length) {
  186. String line = lines3[i];
  187. String[] args = line.split(" ");
  188. if (args.length < 4) {
  189. QLog.e("Error formatting mount line: " + line);
  190. lines = lines3;
  191. } else {
  192. String mountPoint = args[1];
  193. String mountOptions = args[3];
  194. String[] strArr = Const.pathsThatShouldNotBeWrtiable;
  195. int length2 = strArr.length;
  196. boolean result2 = result;
  197. int i2 = 0;
  198. while (i2 < length2) {
  199. String pathToCheck = strArr[i2];
  200. if (mountPoint.equalsIgnoreCase(pathToCheck)) {
  201. String[] split = mountOptions.split(",");
  202. int length3 = split.length;
  203. int i3 = 0;
  204. while (true) {
  205. if (i3 >= length3) {
  206. lines2 = lines3;
  207. break;
  208. }
  209. lines2 = lines3;
  210. if (split[i3].equalsIgnoreCase("rw")) {
  211. QLog.v(pathToCheck + " path is mounted with rw permissions! " + line);
  212. result2 = true;
  213. break;
  214. }
  215. i3++;
  216. lines3 = lines2;
  217. }
  218. } else {
  219. lines2 = lines3;
  220. }
  221. i2++;
  222. lines3 = lines2;
  223. }
  224. lines = lines3;
  225. result = result2;
  226. }
  227. i++;
  228. lines3 = lines;
  229. }
  230. return result;
  231. }
  232.  
  233. public boolean checkSuExists() {
  234. Process process = null;
  235. boolean z = false;
  236. try {
  237. Process process2 = Runtime.getRuntime().exec(new String[]{"which", "su"});
  238. if (new BufferedReader(new InputStreamReader(process2.getInputStream())).readLine() != null) {
  239. z = true;
  240. }
  241. if (process2 != null) {
  242. process2.destroy();
  243. }
  244. return z;
  245. } catch (Throwable th) {
  246. if (process != null) {
  247. process.destroy();
  248. }
  249. throw th;
  250. }
  251. }
  252.  
  253. public boolean checkForNativeLibraryReadAccess() {
  254. try {
  255. new RootBeerNative().setLogDebugMessages(this.loggingEnabled);
  256. return true;
  257. } catch (UnsatisfiedLinkError e) {
  258. return false;
  259. }
  260. }
  261.  
  262. public boolean canLoadNativeLibrary() {
  263. return new RootBeerNative().wasNativeLibraryLoaded();
  264. }
  265.  
  266. public boolean checkForRootNative() {
  267. if (!canLoadNativeLibrary()) {
  268. QLog.e("We could not load the native library to test for root");
  269. return false;
  270. }
  271. String[] paths = new String[Const.suPaths.length];
  272. for (int i = 0; i < paths.length; i++) {
  273. paths[i] = Const.suPaths[i] + "su";
  274. }
  275. RootBeerNative rootBeerNative = new RootBeerNative();
  276. try {
  277. rootBeerNative.setLogDebugMessages(this.loggingEnabled);
  278. if (rootBeerNative.checkForRoot(paths) > 0) {
  279. return true;
  280. }
  281. return false;
  282. } catch (UnsatisfiedLinkError e) {
  283. return false;
  284. }
  285. }
  286. }
  287.  
  288. ----------------------
  289. package com.scottyab.rootbeer;
  290.  
  291. import com.scottyab.rootbeer.util.QLog;
  292.  
  293. public class RootBeerNative {
  294. static boolean libraryLoaded;
  295.  
  296. public native int checkForRoot(Object[] objArr);
  297.  
  298. public native int setLogDebugMessages(boolean z);
  299.  
  300. static {
  301. libraryLoaded = false;
  302. try {
  303. System.loadLibrary("tool-checker");
  304. libraryLoaded = true;
  305. } catch (UnsatisfiedLinkError e) {
  306. QLog.e(e);
  307. }
  308. }
  309.  
  310. public boolean wasNativeLibraryLoaded() {
  311. return libraryLoaded;
  312. }
  313. }
  314. --------------------------
  315. mport android.os.Build;
  316. import com.scottyab.rootbeer.RootBeer;
  317. import java.io.File;
  318. import java.util.HashMap;
  319. import java.util.Map;
  320. import org.apache.cordova.CallbackContext;
  321. import org.apache.cordova.CordovaPlugin;
  322. import org.apache.cordova.LOG;
  323. import org.apache.cordova.PluginResult;
  324. import org.json.JSONArray;
  325. import org.json.JSONException;
  326.  
  327. public class IRoot extends CordovaPlugin {
  328. private final String LOG_TAG = "IRoot";
  329. private final boolean WITH = false;
  330.  
  331. private enum Action {
  332. ACTION_IS_ROOTED("isRooted"),
  333. ACTION_IS_ROOTED_REDBEER("isRootedRedBeer"),
  334. ACTION_IS_ROOTED_REDBEER_WITHOUT_BUSYBOX("isRootedRedBeerWithoutBusyBox");
  335.  
  336. private static final Map<String, Action> lookup = null;
  337. private final String name;
  338.  
  339. static {
  340. int i;
  341. lookup = new HashMap();
  342. for (Action a : values()) {
  343. lookup.put(a.getName(), a);
  344. }
  345. }
  346.  
  347. private Action(String name2) {
  348. this.name = name2;
  349. }
  350.  
  351. public String getName() {
  352. return this.name;
  353. }
  354.  
  355. public static Action get(String name2) {
  356. return lookup.get(name2);
  357. }
  358. }
  359.  
  360. private PluginResult error(String message, Throwable e) {
  361. LOG.e("IRoot", message, e);
  362. return new PluginResult(PluginResult.Status.ERROR, message);
  363. }
  364.  
  365. public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  366. Action act = Action.get(action);
  367. if (act == null) {
  368. this.cordova.getActivity().runOnUiThread(new Runnable() {
  369. public void run() {
  370. LOG.e("IRoot", "unknown action");
  371. callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "unknown action"));
  372. }
  373. });
  374. return false;
  375. }
  376. switch (act) {
  377. case ACTION_IS_ROOTED:
  378. this.cordova.getThreadPool().execute(new Runnable() {
  379. public void run() {
  380. PluginResult result;
  381. try {
  382. result = IRoot.this.checkIsRooted(args, callbackContext);
  383. } catch (Exception e) {
  384. result = new PluginResult(PluginResult.Status.ERROR, e.toString());
  385. }
  386. callbackContext.sendPluginResult(result);
  387. }
  388. });
  389. return true;
  390. case ACTION_IS_ROOTED_REDBEER:
  391. this.cordova.getThreadPool().execute(new Runnable() {
  392. public void run() {
  393. PluginResult result;
  394. try {
  395. result = IRoot.this.checkIsRootedRedBeer(args, callbackContext);
  396. } catch (Exception e) {
  397. result = new PluginResult(PluginResult.Status.ERROR, e.toString());
  398. }
  399. callbackContext.sendPluginResult(result);
  400. }
  401. });
  402. return true;
  403. case ACTION_IS_ROOTED_REDBEER_WITHOUT_BUSYBOX:
  404. this.cordova.getThreadPool().execute(new Runnable() {
  405. public void run() {
  406. PluginResult result;
  407. try {
  408. result = IRoot.this.checkIsRootedRedBeerWithoutBusyBox(args, callbackContext);
  409. } catch (Exception e) {
  410. result = new PluginResult(PluginResult.Status.ERROR, e.toString());
  411. }
  412. callbackContext.sendPluginResult(result);
  413. }
  414. });
  415. return true;
  416. default:
  417. this.cordova.getActivity().runOnUiThread(new Runnable() {
  418. public void run() {
  419. LOG.e("IRoot", "unknown action");
  420. callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "unknown action"));
  421. }
  422. });
  423. return false;
  424. }
  425. }
  426.  
  427. private boolean isDeviceRooted() {
  428. return checkBuildTags() || checkSuperUserApk() || checkFilePath();
  429. }
  430.  
  431. private boolean checkBuildTags() {
  432. String buildTags = Build.TAGS;
  433. return buildTags != null && buildTags.contains("test-keys");
  434. }
  435.  
  436. private boolean checkSuperUserApk() {
  437. return new File("/system/app/Superuser.apk").exists();
  438. }
  439.  
  440. private boolean checkFilePath() {
  441. for (String path : new String[]{"/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/data/local/su"}) {
  442. if (new File(path).exists()) {
  443. return true;
  444. }
  445. }
  446. return false;
  447. }
  448.  
  449. /* access modifiers changed from: private */
  450. public PluginResult checkIsRootedRedBeer(JSONArray args, CallbackContext callbackContext) {
  451. try {
  452. return new PluginResult(PluginResult.Status.OK, new RootBeer(this.cordova.getActivity().getApplicationContext()).isRooted());
  453. } catch (Exception e) {
  454. return error("Error", e);
  455. }
  456. }
  457.  
  458. /* access modifiers changed from: private */
  459. public PluginResult checkIsRootedRedBeerWithoutBusyBox(JSONArray args, CallbackContext callbackContext) {
  460. try {
  461. return new PluginResult(PluginResult.Status.OK, new RootBeer(this.cordova.getActivity().getApplicationContext()).isRootedWithoutBusyBoxCheck());
  462. } catch (Exception e) {
  463. return error("Error", e);
  464. }
  465. }
  466.  
  467. /* access modifiers changed from: private */
  468. public PluginResult checkIsRooted(JSONArray args, CallbackContext callbackContext) {
  469. boolean check;
  470. try {
  471. RootBeer rootBeer = new RootBeer(this.cordova.getActivity().getApplicationContext());
  472. if (!isDeviceRooted()) {
  473. getClass();
  474. if (!rootBeer.isRooted()) {
  475. check = false;
  476. return new PluginResult(PluginResult.Status.OK, check);
  477. }
  478. }
  479. check = true;
  480. return new PluginResult(PluginResult.Status.OK, check);
  481. } catch (Exception e) {
  482. return error("Error", e);
  483. }
  484. }
  485. }
  486. ---------------------------------------
  487. public final class Const {
  488. public static final String[] knownDangerousAppsPackages = {"com.koushikdutta.rommanager", "com.koushikdutta.rommanager.license", "com.dimonvideo.luckypatcher", "com.chelpus.lackypatch", "com.ramdroid.appquarantine", "com.ramdroid.appquarantinepro", "com.android.vending.billing.InAppBillingService.COIN", "com.chelpus.luckypatcher"};
  489. public static final String[] knownRootAppsPackages = {"com.noshufou.android.su", "com.noshufou.android.su.elite", "eu.chainfire.supersu", "com.koushikdutta.superuser", "com.thirdparty.superuser", "com.yellowes.su", "com.topjohnwu.magisk"};
  490. public static final String[] knownRootCloakingPackages = {"com.devadvance.rootcloak", "com.devadvance.rootcloakplus", "de.robv.android.xposed.installer", "com.saurik.substrate", "com.zachspong.temprootremovejb", "com.amphoras.hidemyroot", "com.amphoras.hidemyrootadfree", "com.formyhm.hiderootPremium", "com.formyhm.hideroot"};
  491. public static final String[] pathsThatShouldNotBeWrtiable = {"/system", "/system/bin", "/system/sbin", "/system/xbin", "/vendor/bin", "/sbin", "/etc"};
  492. public static final String[] suPaths = {"/data/local/", "/data/local/bin/", "/data/local/xbin/", "/sbin/", "/su/bin/", "/system/bin/", "/system/bin/.ext/", "/system/bin/failsafe/", "/system/sd/xbin/", "/system/usr/we-need-root/", "/system/xbin/", "/cache", "/data", "/dev"};
  493.  
  494. private Const() throws InstantiationException {
  495. throw new InstantiationException("This class is not for instantiation");
  496. }
  497. }
  498. ----------------------------------
  499. import com.facebook.appevents.AppEventsConstants;
  500.  
  501. public final class Utils {
  502. private Utils() throws InstantiationException {
  503. throw new InstantiationException("This class is not for instantiation");
  504. }
  505.  
  506. public static boolean isSelinuxFlagInEnabled() {
  507. String selinux = null;
  508. try {
  509. Class<?> c = Class.forName("android.os.SystemProperties");
  510. selinux = (String) c.getMethod("get", new Class[]{String.class}).invoke(c, new Object[]{"ro.build.selinux"});
  511. } catch (Exception e) {
  512. }
  513. return AppEventsConstants.EVENT_PARAM_VALUE_YES.equals(selinux);
  514. }
  515. }
  516. ---------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement