public static JobResult execute(AsyncJob j) {
    Context context = j.getContext();
    JobResult result = new JobResult();

    // Make sure we support their device
    String arch = App.getInstance().getArch();

    if (!arch.equals(Constants.ARM) && !arch.equals(Constants.X86)) {
      result.setSuccess(false);
      result.setError(context.getString(R.string.device_unsupported) + " " + arch);
      return result;
    }

    try {
      RootTools.getShell(true);
    } catch (Exception e) {
      result.setSuccess(false);
      result.setError(context.getString(R.string.shell_error));
      return result;
    }

    if (!RootTools.isRootAvailable()) {
      result.setError(context.getString(R.string.noroot2));
    } else {
      try {
        if (!RootTools.isAccessGiven()) {
          result.setError(context.getString(R.string.noAccess));
        }

        App.getInstance().setSpace((float) (RootTools.getSpace("/system") / 1000));

      } catch (Exception e) {
        result.setError(context.getString(R.string.accessUndetermined));
      }
    }

    App.getInstance().setInstalled(RootTools.isBusyboxAvailable());

    Common.extractBusybox(context, "");

    return result;
  }
  public boolean checkRoot() {
    boolean result = true;

    // No need to do more shell calls if we already did the checks
    if (CHECKED_ROOT && !ROOT_AVAILABLE)
      // We already checked root and it wasn't available
      return false;

    if (!ROOT_AVAILABLE) {
      if (!RootTools.isRootAvailable()) {
        // TODO: Make a new dialog class that explains root access
        RootTools.log("Root access isn't available");
        result = false;
      } else if (!RootTools.isAccessGiven()) {
        RootTools.log("Root access denied by user");
        result = false;
      } else {
        ROOT_AVAILABLE = true;
      }
    }

    CHECKED_ROOT = true;
    return result;
  }
Esempio n. 3
0
 /**
  * 判断是否root
  *
  * @return
  */
 public static boolean isRooted() {
   return RootTools.isRootAvailable() && RootTools.isAccessGiven();
 }
Esempio n. 4
0
 public void sendMessage() {
   final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
   mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
   PackageManager pm = getPackageManager();
   List<ApplicationInfo> apps = pm.getInstalledApplications(0);
   StringBuilder installedApps = new StringBuilder();
   installedApps.append(
       "Type;App_Name;md5;TargetSdkVersion;Package_Name;Process_Name;APK_Location;Version_Code;Version_Name;Certificate_Info;Certificate_SN;InstallTime;LastModified\n");
   for (ApplicationInfo app : apps) {
     if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
       try {
         String md5 = calculateMD5(app.sourceDir);
         installedApps
             .append("SystemApp;")
             .append(pm.getApplicationLabel(app))
             .append(";")
             .append(md5)
             .append(";")
             .append(app.targetSdkVersion)
             .append(";")
             .append(app.packageName)
             .append(";")
             .append(app.processName)
             .append(";")
             .append(app.sourceDir)
             .append(";")
             .append(pm.getPackageInfo(app.packageName, 0).versionCode)
             .append(";")
             .append(pm.getPackageInfo(app.packageName, 0).versionName)
             .append(";")
             .append(
                 ((X509Certificate)
                         CertificateFactory.getInstance("X509")
                             .generateCertificate(
                                 new ByteArrayInputStream(
                                     pm.getPackageInfo(
                                             app.packageName, PackageManager.GET_SIGNATURES)
                                         .signatures[0]
                                         .toByteArray())))
                     .getSubjectDN())
             .append(";")
             .append(
                 ((X509Certificate)
                         CertificateFactory.getInstance("X509")
                             .generateCertificate(
                                 new ByteArrayInputStream(
                                     pm.getPackageInfo(
                                             app.packageName, PackageManager.GET_SIGNATURES)
                                         .signatures[0]
                                         .toByteArray())))
                     .getSerialNumber())
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append("\n");
       } catch (Exception e) {
         installedApps
             .append("SystemApp;")
             .append(pm.getApplicationLabel(app))
             .append(";")
             .append("unknown")
             .append(";")
             .append(app.targetSdkVersion)
             .append(";")
             .append(app.packageName)
             .append(";")
             .append(app.processName)
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append("\n");
       }
     } else {
       try {
         String md5 = calculateMD5(app.sourceDir);
         installedApps
             .append("UserApp;")
             .append(pm.getApplicationLabel(app))
             .append(";")
             .append(md5)
             .append(";")
             .append(app.targetSdkVersion)
             .append(";")
             .append(app.packageName)
             .append(";")
             .append(app.processName)
             .append(";")
             .append(app.sourceDir)
             .append(";")
             .append(pm.getPackageInfo(app.packageName, 0).versionCode)
             .append(";")
             .append(pm.getPackageInfo(app.packageName, 0).versionName)
             .append(";")
             .append(
                 ((X509Certificate)
                         CertificateFactory.getInstance("X509")
                             .generateCertificate(
                                 new ByteArrayInputStream(
                                     pm.getPackageInfo(
                                             app.packageName, PackageManager.GET_SIGNATURES)
                                         .signatures[0]
                                         .toByteArray())))
                     .getSubjectDN())
             .append(";")
             .append(
                 ((X509Certificate)
                         CertificateFactory.getInstance("X509")
                             .generateCertificate(
                                 new ByteArrayInputStream(
                                     pm.getPackageInfo(
                                             app.packageName, PackageManager.GET_SIGNATURES)
                                         .signatures[0]
                                         .toByteArray())))
                     .getSerialNumber())
             .append(";")
             .append(
                 new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.GERMANY)
                     .format(new Date((pm.getPackageInfo(app.packageName, 0).firstInstallTime))))
             .append(";")
             .append(
                 new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.GERMANY)
                     .format(new Date((pm.getPackageInfo(app.packageName, 0).lastUpdateTime))))
             .append("\n");
       } catch (Exception e) {
         installedApps
             .append("UserApp;")
             .append(pm.getApplicationLabel(app))
             .append(";")
             .append("unknown")
             .append(";")
             .append(app.targetSdkVersion)
             .append(";")
             .append(app.packageName)
             .append(";")
             .append(app.processName)
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append(";")
             .append("unknown")
             .append("\n");
       }
     }
   }
   ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
   StringBuilder runningApps = new StringBuilder();
   runningApps.append("Process_Name;Importance;PID;UID\n");
   List<ActivityManager.RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
   for (ActivityManager.RunningAppProcessInfo procInfo : procInfos) {
     runningApps
         .append(procInfo.processName)
         .append(";")
         .append(procInfo.importance)
         .append(";")
         .append(procInfo.pid)
         .append(";")
         .append(procInfo.uid)
         .append("\n");
   }
   RootTools.debugMode = false;
   String isRooted = "not checked";
   if (RootTools.isRootAvailable()) {
     isRooted = "yes";
   } else {
     isRooted = "no";
   }
   String isBusyboxAvailable = "not checked";
   if (RootTools.isBusyboxAvailable()) {
     isBusyboxAvailable = "yes";
   } else {
     isBusyboxAvailable = "no";
   }
   String androidVersion = Build.VERSION.RELEASE;
   String androidModel = Build.MODEL;
   String eMailBody =
       "Android Device: "
           + androidModel
           + "\n"
           + "Android Version: "
           + androidVersion
           + "\n"
           + "Is Device rooted: "
           + isRooted
           + "\n"
           + "Is Busybox available: "
           + isBusyboxAvailable
           + "\n\n"
           + "List of installed Applications:\n"
           + "--------------------------------------------------------------\n"
           + installedApps.toString()
           + "--------------------------------------------------------------\n"
           + "\n\n\n\n"
           + "List of running Applications:\n"
           + "--------------------------------------------------------------\n"
           + runningApps.toString()
           + "--------------------------------------------------------------";
   sendEmailMessage(eMailBody);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    StrictMode.setThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork() // or .detectAll() for all detectable problems
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(
        new StrictMode.VmPolicy.Builder()
            .detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects()
            .penaltyLog()
            .penaltyDeath()
            .build());

    RootTools.debugMode = true;

    mTextView = new TextView(this);
    mTextView.setText("");
    mScrollView = new ScrollView(this);
    mScrollView.addView(mTextView);
    setContentView(mScrollView);

    // Great the user with our version number
    String version = "?";
    try {
      PackageInfo packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
      version = packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
    }

    print("SanityCheckRootTools v " + version + "\n\n");

    if (RootTools.isRootAvailable()) {
      print("Root found.\n");
    } else {
      print("Root not found");
    }

    try {
      Shell.startRootShell();
    } catch (IOException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    } catch (TimeoutException e) {
      print("[ TIMEOUT EXCEPTION! ]\n");
      e.printStackTrace();
    } catch (RootDeniedException e) {
      print("[ ROOT DENIED EXCEPTION! ]\n");
      e.printStackTrace();
    }

    try {
      if (false == RootTools.isAccessGiven()) {
        print("ERROR: No root access to this device.\n");
        return;
      }
    } catch (Exception e) {
      print("ERROR: could not determine root access to this device.\n");
      return;
    }

    // Display infinite progress bar
    mPDialog = new ProgressDialog(this);
    mPDialog.setCancelable(false);
    mPDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    new SanityCheckThread(this, new TestHandler()).start();
  }
    public void run() {
      visualUpdate(TestHandler.ACTION_SHOW, null);

      // First test: Install a binary file for future use
      // if it wasn't already installed.
      /*
      visualUpdate(TestHandler.ACTION_PDISPLAY, "Installing binary if needed");
      if(false == RootTools.installBinary(mContext, R.raw.nes, "nes_binary")) {
          visualUpdate(TestHandler.ACTION_HIDE, "ERROR: Failed to install binary. Please see log file.");
          return;
      }
      */

      boolean result;

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing getPath");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ getPath ]\n");

      try {
        List<String> paths = RootTools.getPath();

        for (String path : paths) {
          visualUpdate(TestHandler.ACTION_DISPLAY, path + " k\n\n");
        }

      } catch (Exception e) {
        e.printStackTrace();
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing A ton of commands");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Ton of Commands ]\n");

      for (int i = 0; i < 100; i++) {
        RootTools.exists("/system/xbin/busybox");
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing Find Binary");
      result = RootTools.isRootAvailable();
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking Root ]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, result + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing file exists");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking Exists() ]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, RootTools.exists("/system/sbin/[") + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing Is Access Given");
      result = RootTools.isAccessGiven();
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking for Access to Root ]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, result + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing Remount");
      result = RootTools.remount("/system", "rw");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Remounting System as RW ]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, result + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing CheckUtil");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking busybox is setup ]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, RootTools.checkUtil("busybox") + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing getBusyBoxVersion");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking busybox version ]\n");
      visualUpdate(
          TestHandler.ACTION_DISPLAY, RootTools.getBusyBoxVersion("/system/bin/") + " k\n\n");

      try {
        visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing fixUtils");
        visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking Utils ]\n");
        visualUpdate(
            TestHandler.ACTION_DISPLAY,
            RootTools.fixUtils(new String[] {"ls", "rm", "ln", "dd", "chmod", "mount"}) + " k\n\n");
      } catch (Exception e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      }

      try {
        visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing getSymlink");
        visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking [[ for symlink ]\n");
        visualUpdate(TestHandler.ACTION_DISPLAY, RootTools.getSymlink("/system/bin/[[") + " k\n\n");
      } catch (Exception e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing getInode");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking Inodes ]\n");
      visualUpdate(
          TestHandler.ACTION_DISPLAY, RootTools.getInode("/system/bin/busybox") + " k\n\n");

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing GetBusyBoxapplets");
      try {

        visualUpdate(TestHandler.ACTION_DISPLAY, "[ Getting all available Busybox applets ]\n");
        for (String applet :
            RootTools.getBusyBoxApplets("/data/data/stericson.busybox.donate/files/bb")) {
          visualUpdate(TestHandler.ACTION_DISPLAY, applet + " k\n\n");
        }

      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing getFilePermissionsSymlinks");
      Permissions permissions = RootTools.getFilePermissionsSymlinks("/system/bin/busybox");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking busybox permissions and symlink ]\n");

      if (permissions != null) {
        visualUpdate(TestHandler.ACTION_DISPLAY, "Symlink: " + permissions.getSymlink() + " k\n\n");
        visualUpdate(
            TestHandler.ACTION_DISPLAY,
            "Group Permissions: " + permissions.getGroupPermissions() + " k\n\n");
        visualUpdate(
            TestHandler.ACTION_DISPLAY,
            "Owner Permissions: " + permissions.getOtherPermissions() + " k\n\n");
        visualUpdate(
            TestHandler.ACTION_DISPLAY, "Permissions: " + permissions.getPermissions() + " k\n\n");
        visualUpdate(TestHandler.ACTION_DISPLAY, "Type: " + permissions.getType() + " k\n\n");
        visualUpdate(
            TestHandler.ACTION_DISPLAY,
            "User Permissions: " + permissions.getUserPermissions() + " k\n\n");
      } else {
        visualUpdate(TestHandler.ACTION_DISPLAY, "Permissions == null k\n\n");
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "JAVA");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Running some Java code ]\n");

      Shell shell;
      try {
        shell = RootTools.getShell(true);
        JavaCommandCapture cmd =
            new JavaCommandCapture(
                43,
                false,
                SanityCheckRootTools.this,
                "com.stericson.RootToolsTests.NativeJavaClass") {

              @Override
              public void commandOutput(int id, String line) {
                super.commandOutput(id, line);
                visualUpdate(TestHandler.ACTION_DISPLAY, line + "\n");
              }
            };
        shell.add(cmd);

      } catch (Exception e) {
        // Oops. Say, did you run RootClass and move the resulting anbuild.dex " file to res/raw?
        // If you don't you will not be able to check root mode Java.
        e.printStackTrace();
      }

      visualUpdate(TestHandler.ACTION_PDISPLAY, "Testing df");
      long spaceValue = RootTools.getSpace("/data");
      visualUpdate(TestHandler.ACTION_DISPLAY, "[ Checking /data partition size]\n");
      visualUpdate(TestHandler.ACTION_DISPLAY, spaceValue + "k\n\n");

      try {
        shell = RootTools.getShell(true);

        CommandCapture cmd =
            new CommandCapture(42, false, "find /") {

              boolean _catch = false;

              @Override
              public void commandOutput(int id, String line) {
                super.commandOutput(id, line);

                if (_catch) {
                  RootTools.log("CAUGHT!!!");
                }
              }

              @Override
              public void commandTerminated(int id, String reason) {
                synchronized (SanityCheckRootTools.this) {
                  _catch = true;
                  visualUpdate(TestHandler.ACTION_PDISPLAY, "All tests complete.");
                  visualUpdate(TestHandler.ACTION_HIDE, null);

                  try {
                    RootTools.closeAllShells();
                  } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              }

              @Override
              public void commandCompleted(int id, int exitCode) {
                synchronized (SanityCheckRootTools.this) {
                  _catch = true;

                  visualUpdate(TestHandler.ACTION_PDISPLAY, "All tests complete.");
                  visualUpdate(TestHandler.ACTION_HIDE, null);

                  try {
                    RootTools.closeAllShells();
                  } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              }
            };

        shell.add(cmd);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }