Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Android for check root !!
- ------------------------
- package com.scottyab.rootbeer;
- import android.content.Context;
- import android.content.pm.PackageManager;
- import android.os.Build;
- import com.facebook.appevents.AppEventsConstants;
- import com.scottyab.rootbeer.util.QLog;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.NoSuchElementException;
- import java.util.Scanner;
- public class RootBeer {
- private boolean loggingEnabled = true;
- private final Context mContext;
- public RootBeer(Context context) {
- this.mContext = context;
- }
- public boolean isRooted() {
- return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary("su") || checkForBinary("busybox") || checkForDangerousProps() || checkForRWPaths() || detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
- }
- public boolean isRootedWithoutBusyBoxCheck() {
- return detectRootManagementApps() || detectPotentiallyDangerousApps() || checkForBinary("su") || checkForDangerousProps() || checkForRWPaths() || detectTestKeys() || checkSuExists() || checkForRootNative() || checkForMagiskBinary();
- }
- public boolean detectTestKeys() {
- String buildTags = Build.TAGS;
- return buildTags != null && buildTags.contains("test-keys");
- }
- public boolean detectRootManagementApps() {
- return detectRootManagementApps((String[]) null);
- }
- public boolean detectRootManagementApps(String[] additionalRootManagementApps) {
- ArrayList<String> packages = new ArrayList<>();
- packages.addAll(Arrays.asList(Const.knownRootAppsPackages));
- if (additionalRootManagementApps != null && additionalRootManagementApps.length > 0) {
- packages.addAll(Arrays.asList(additionalRootManagementApps));
- }
- return isAnyPackageFromListInstalled(packages);
- }
- public boolean detectPotentiallyDangerousApps() {
- return detectPotentiallyDangerousApps((String[]) null);
- }
- public boolean detectPotentiallyDangerousApps(String[] additionalDangerousApps) {
- ArrayList<String> packages = new ArrayList<>();
- packages.addAll(Arrays.asList(Const.knownDangerousAppsPackages));
- if (additionalDangerousApps != null && additionalDangerousApps.length > 0) {
- packages.addAll(Arrays.asList(additionalDangerousApps));
- }
- return isAnyPackageFromListInstalled(packages);
- }
- public boolean detectRootCloakingApps() {
- return detectRootCloakingApps((String[]) null) || (canLoadNativeLibrary() && !checkForNativeLibraryReadAccess());
- }
- public boolean detectRootCloakingApps(String[] additionalRootCloakingApps) {
- ArrayList<String> packages = new ArrayList<>();
- packages.addAll(Arrays.asList(Const.knownRootCloakingPackages));
- if (additionalRootCloakingApps != null && additionalRootCloakingApps.length > 0) {
- packages.addAll(Arrays.asList(additionalRootCloakingApps));
- }
- return isAnyPackageFromListInstalled(packages);
- }
- public boolean checkForSuBinary() {
- return checkForBinary("su");
- }
- public boolean checkForMagiskBinary() {
- return checkForBinary("magisk");
- }
- public boolean checkForBusyBoxBinary() {
- return checkForBinary("busybox");
- }
- public boolean checkForBinary(String filename) {
- boolean result = false;
- for (String path : Const.suPaths) {
- String completePath = path + filename;
- if (new File(path, filename).exists()) {
- QLog.v(completePath + " binary detected!");
- result = true;
- }
- }
- return result;
- }
- public void setLogging(boolean logging) {
- this.loggingEnabled = logging;
- QLog.LOGGING_LEVEL = logging ? 5 : 0;
- }
- private String[] propsReader() {
- try {
- InputStream inputstream = Runtime.getRuntime().exec("getprop").getInputStream();
- if (inputstream == null) {
- return null;
- }
- return new Scanner(inputstream).useDelimiter("\\A").next().split("\n");
- } catch (IOException | NoSuchElementException e) {
- e.printStackTrace();
- return null;
- }
- }
- private String[] mountReader() {
- try {
- InputStream inputstream = Runtime.getRuntime().exec("mount").getInputStream();
- if (inputstream == null) {
- return null;
- }
- return new Scanner(inputstream).useDelimiter("\\A").next().split("\n");
- } catch (IOException | NoSuchElementException e) {
- e.printStackTrace();
- return null;
- }
- }
- private boolean isAnyPackageFromListInstalled(List<String> packages) {
- boolean result = false;
- PackageManager pm = this.mContext.getPackageManager();
- for (String packageName : packages) {
- try {
- pm.getPackageInfo(packageName, 0);
- QLog.e(packageName + " ROOT management app detected!");
- result = true;
- } catch (PackageManager.NameNotFoundException e) {
- }
- }
- return result;
- }
- public boolean checkForDangerousProps() {
- Map<String, String> dangerousProps = new HashMap<>();
- dangerousProps.put("ro.debuggable", AppEventsConstants.EVENT_PARAM_VALUE_YES);
- dangerousProps.put("ro.secure", AppEventsConstants.EVENT_PARAM_VALUE_NO);
- boolean result = false;
- String[] lines = propsReader();
- if (lines == null) {
- return false;
- }
- for (String line : lines) {
- for (String key : dangerousProps.keySet()) {
- if (line.contains(key)) {
- String badValue = "[" + dangerousProps.get(key) + "]";
- if (line.contains(badValue)) {
- QLog.v(key + " = " + badValue + " detected!");
- result = true;
- }
- }
- }
- }
- return result;
- }
- public boolean checkForRWPaths() {
- String[] lines;
- String[] lines2;
- String[] lines3 = mountReader();
- if (lines3 == null) {
- return false;
- }
- int length = lines3.length;
- boolean result = false;
- int i = 0;
- while (i < length) {
- String line = lines3[i];
- String[] args = line.split(" ");
- if (args.length < 4) {
- QLog.e("Error formatting mount line: " + line);
- lines = lines3;
- } else {
- String mountPoint = args[1];
- String mountOptions = args[3];
- String[] strArr = Const.pathsThatShouldNotBeWrtiable;
- int length2 = strArr.length;
- boolean result2 = result;
- int i2 = 0;
- while (i2 < length2) {
- String pathToCheck = strArr[i2];
- if (mountPoint.equalsIgnoreCase(pathToCheck)) {
- String[] split = mountOptions.split(",");
- int length3 = split.length;
- int i3 = 0;
- while (true) {
- if (i3 >= length3) {
- lines2 = lines3;
- break;
- }
- lines2 = lines3;
- if (split[i3].equalsIgnoreCase("rw")) {
- QLog.v(pathToCheck + " path is mounted with rw permissions! " + line);
- result2 = true;
- break;
- }
- i3++;
- lines3 = lines2;
- }
- } else {
- lines2 = lines3;
- }
- i2++;
- lines3 = lines2;
- }
- lines = lines3;
- result = result2;
- }
- i++;
- lines3 = lines;
- }
- return result;
- }
- public boolean checkSuExists() {
- Process process = null;
- boolean z = false;
- try {
- Process process2 = Runtime.getRuntime().exec(new String[]{"which", "su"});
- if (new BufferedReader(new InputStreamReader(process2.getInputStream())).readLine() != null) {
- z = true;
- }
- if (process2 != null) {
- process2.destroy();
- }
- return z;
- } catch (Throwable th) {
- if (process != null) {
- process.destroy();
- }
- throw th;
- }
- }
- public boolean checkForNativeLibraryReadAccess() {
- try {
- new RootBeerNative().setLogDebugMessages(this.loggingEnabled);
- return true;
- } catch (UnsatisfiedLinkError e) {
- return false;
- }
- }
- public boolean canLoadNativeLibrary() {
- return new RootBeerNative().wasNativeLibraryLoaded();
- }
- public boolean checkForRootNative() {
- if (!canLoadNativeLibrary()) {
- QLog.e("We could not load the native library to test for root");
- return false;
- }
- String[] paths = new String[Const.suPaths.length];
- for (int i = 0; i < paths.length; i++) {
- paths[i] = Const.suPaths[i] + "su";
- }
- RootBeerNative rootBeerNative = new RootBeerNative();
- try {
- rootBeerNative.setLogDebugMessages(this.loggingEnabled);
- if (rootBeerNative.checkForRoot(paths) > 0) {
- return true;
- }
- return false;
- } catch (UnsatisfiedLinkError e) {
- return false;
- }
- }
- }
- ----------------------
- package com.scottyab.rootbeer;
- import com.scottyab.rootbeer.util.QLog;
- public class RootBeerNative {
- static boolean libraryLoaded;
- public native int checkForRoot(Object[] objArr);
- public native int setLogDebugMessages(boolean z);
- static {
- libraryLoaded = false;
- try {
- System.loadLibrary("tool-checker");
- libraryLoaded = true;
- } catch (UnsatisfiedLinkError e) {
- QLog.e(e);
- }
- }
- public boolean wasNativeLibraryLoaded() {
- return libraryLoaded;
- }
- }
- --------------------------
- mport android.os.Build;
- import com.scottyab.rootbeer.RootBeer;
- import java.io.File;
- import java.util.HashMap;
- import java.util.Map;
- import org.apache.cordova.CallbackContext;
- import org.apache.cordova.CordovaPlugin;
- import org.apache.cordova.LOG;
- import org.apache.cordova.PluginResult;
- import org.json.JSONArray;
- import org.json.JSONException;
- public class IRoot extends CordovaPlugin {
- private final String LOG_TAG = "IRoot";
- private final boolean WITH = false;
- private enum Action {
- ACTION_IS_ROOTED("isRooted"),
- ACTION_IS_ROOTED_REDBEER("isRootedRedBeer"),
- ACTION_IS_ROOTED_REDBEER_WITHOUT_BUSYBOX("isRootedRedBeerWithoutBusyBox");
- private static final Map<String, Action> lookup = null;
- private final String name;
- static {
- int i;
- lookup = new HashMap();
- for (Action a : values()) {
- lookup.put(a.getName(), a);
- }
- }
- private Action(String name2) {
- this.name = name2;
- }
- public String getName() {
- return this.name;
- }
- public static Action get(String name2) {
- return lookup.get(name2);
- }
- }
- private PluginResult error(String message, Throwable e) {
- LOG.e("IRoot", message, e);
- return new PluginResult(PluginResult.Status.ERROR, message);
- }
- public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- Action act = Action.get(action);
- if (act == null) {
- this.cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- LOG.e("IRoot", "unknown action");
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "unknown action"));
- }
- });
- return false;
- }
- switch (act) {
- case ACTION_IS_ROOTED:
- this.cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- PluginResult result;
- try {
- result = IRoot.this.checkIsRooted(args, callbackContext);
- } catch (Exception e) {
- result = new PluginResult(PluginResult.Status.ERROR, e.toString());
- }
- callbackContext.sendPluginResult(result);
- }
- });
- return true;
- case ACTION_IS_ROOTED_REDBEER:
- this.cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- PluginResult result;
- try {
- result = IRoot.this.checkIsRootedRedBeer(args, callbackContext);
- } catch (Exception e) {
- result = new PluginResult(PluginResult.Status.ERROR, e.toString());
- }
- callbackContext.sendPluginResult(result);
- }
- });
- return true;
- case ACTION_IS_ROOTED_REDBEER_WITHOUT_BUSYBOX:
- this.cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- PluginResult result;
- try {
- result = IRoot.this.checkIsRootedRedBeerWithoutBusyBox(args, callbackContext);
- } catch (Exception e) {
- result = new PluginResult(PluginResult.Status.ERROR, e.toString());
- }
- callbackContext.sendPluginResult(result);
- }
- });
- return true;
- default:
- this.cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- LOG.e("IRoot", "unknown action");
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "unknown action"));
- }
- });
- return false;
- }
- }
- private boolean isDeviceRooted() {
- return checkBuildTags() || checkSuperUserApk() || checkFilePath();
- }
- private boolean checkBuildTags() {
- String buildTags = Build.TAGS;
- return buildTags != null && buildTags.contains("test-keys");
- }
- private boolean checkSuperUserApk() {
- return new File("/system/app/Superuser.apk").exists();
- }
- private boolean checkFilePath() {
- 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"}) {
- if (new File(path).exists()) {
- return true;
- }
- }
- return false;
- }
- /* access modifiers changed from: private */
- public PluginResult checkIsRootedRedBeer(JSONArray args, CallbackContext callbackContext) {
- try {
- return new PluginResult(PluginResult.Status.OK, new RootBeer(this.cordova.getActivity().getApplicationContext()).isRooted());
- } catch (Exception e) {
- return error("Error", e);
- }
- }
- /* access modifiers changed from: private */
- public PluginResult checkIsRootedRedBeerWithoutBusyBox(JSONArray args, CallbackContext callbackContext) {
- try {
- return new PluginResult(PluginResult.Status.OK, new RootBeer(this.cordova.getActivity().getApplicationContext()).isRootedWithoutBusyBoxCheck());
- } catch (Exception e) {
- return error("Error", e);
- }
- }
- /* access modifiers changed from: private */
- public PluginResult checkIsRooted(JSONArray args, CallbackContext callbackContext) {
- boolean check;
- try {
- RootBeer rootBeer = new RootBeer(this.cordova.getActivity().getApplicationContext());
- if (!isDeviceRooted()) {
- getClass();
- if (!rootBeer.isRooted()) {
- check = false;
- return new PluginResult(PluginResult.Status.OK, check);
- }
- }
- check = true;
- return new PluginResult(PluginResult.Status.OK, check);
- } catch (Exception e) {
- return error("Error", e);
- }
- }
- }
- ---------------------------------------
- public final class Const {
- 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"};
- 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"};
- 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"};
- public static final String[] pathsThatShouldNotBeWrtiable = {"/system", "/system/bin", "/system/sbin", "/system/xbin", "/vendor/bin", "/sbin", "/etc"};
- 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"};
- private Const() throws InstantiationException {
- throw new InstantiationException("This class is not for instantiation");
- }
- }
- ----------------------------------
- import com.facebook.appevents.AppEventsConstants;
- public final class Utils {
- private Utils() throws InstantiationException {
- throw new InstantiationException("This class is not for instantiation");
- }
- public static boolean isSelinuxFlagInEnabled() {
- String selinux = null;
- try {
- Class<?> c = Class.forName("android.os.SystemProperties");
- selinux = (String) c.getMethod("get", new Class[]{String.class}).invoke(c, new Object[]{"ro.build.selinux"});
- } catch (Exception e) {
- }
- return AppEventsConstants.EVENT_PARAM_VALUE_YES.equals(selinux);
- }
- }
- ---------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement