public void queryAll() { setVersion(); setKernelVersion(); try { isRecoveryMode = !AdbUtility.isMounted("/system"); } catch (Exception e) { } }
public static void antiRic() { try { Scanner scan = new Scanner(AdbUtility.run("ps")); String path = ""; String pid = ""; while (scan.hasNextLine()) { String line = scan.nextLine(); if (line.contains("bin/ric")) { String[] fields = line.split("\\s+"); pid = fields[1]; path = fields[fields.length - 1]; } } scan.close(); if (path.length() > 0) { MyLogger.getLogger().info("Stopping ric service"); AdbUtility.run( "su -c 'mount -o remount,rw / && mv " + path + " " + path + "c && mount -o remount,ro / && kill -9 " + pid + "'"); MyLogger.getLogger().info("ric service stopped successfully"); } } catch (Exception e) { } }
public boolean hasSU() { try { return AdbUtility.hasSU(); } catch (Exception e) { return false; } }
public static long rawBackup(String source, String destination) { String md5source = getMD5(source); String result = ""; long transferred = 0L; try { result = AdbUtility.run( "su -c 'dd if=" + source + " of=" + destination + " && sync && sync && sync && sync'"); } catch (Exception e) { } if (!result.contains("bytes transferred")) return 0L; Scanner sc = new Scanner(result); while (sc.hasNextLine()) { String line = sc.nextLine(); if (line.contains("bytes")) { transferred = Long.parseLong(line.split(" ")[0]); } } String md5destination = getMD5(destination); if (!md5source.equals(md5destination)) return 0L; return transferred; }
public void doBusyboxHelper() throws Exception { if (!isBusyboxInstalled(false)) { AdbUtility.push(getBusybox(false), GlobalConfig.getProperty("deviceworkdir") + "/busybox"); FTShell shell = new FTShell("busyhelper"); shell.run(true); } }
public static String getKernelVersion(boolean hasbusybox) { try { String result = ""; if (!hasbusybox) { AdbUtility.push( Devices.getCurrent().getBusybox(false), GlobalConfig.getProperty("deviceworkdir") + "/busybox1", false); AdbUtility.run("chmod 755 " + GlobalConfig.getProperty("deviceworkdir") + "/busybox1"); result = run(GlobalConfig.getProperty("deviceworkdir") + "/busybox1 uname -r"); run("rm -r " + GlobalConfig.getProperty("deviceworkdir") + "/busybox1"); } else result = run("busybox uname -r"); return result; } catch (Exception e) { return ""; } }
public static boolean isConnected() { try { MyLogger.getLogger().debug("Testing if device is connected"); return AdbUtility.getDevices().hasMoreElements(); } catch (Exception e) { return false; } }
public static String getMD5(String source) { try { String md5 = AdbUtility.run("su -c 'busybox md5sum " + source + "'") .split(" ")[0] .toUpperCase() .trim(); if (md5 == null) return ""; if (md5.length() != 32) md5 = ""; return md5; } catch (Exception e) { return ""; } }
public static void doRootpsneuter() { try { AdbUtility.push( Devices.getCurrent().getBusybox(false), GlobalConfig.getProperty("deviceworkdir") + "/busybox"); Shell shell = new Shell("busyhelper"); shell.run(true); AdbUtility.push( "." + fsep + "custom" + fsep + "root" + fsep + "psneuter.tar.uue", GlobalConfig.getProperty("deviceworkdir")); shell = new Shell("rootit"); MyLogger.getLogger().info("Running part1 of Root Exploit, please wait"); shell.run(false); Devices.waitForReboot(true); MyLogger.getLogger().info("Running part2 of Root Exploit"); shell = new Shell("rootit2"); shell.run(false); MyLogger.getLogger().info("Finished!."); MyLogger.getLogger().info("Root should be available after reboot!"); } catch (Exception e) { MyLogger.getLogger().error(e.getMessage()); } }
protected IStatus run(IProgressMonitor monitor) { try { AdbUtility.push(bbpath, GlobalConfig.getProperty("deviceworkdir")); FTShell shell = new FTShell("busyhelper"); shell.run(false); shell = new FTShell("instbusybox"); shell.setProperty("BUSYBOXINSTALLPATH", Devices.getCurrent().getBusyBoxInstallPath()); shell.runRoot(); MyLogger.getLogger() .info( "Installed version of busybox : " + Devices.getCurrent().getInstalledBusyboxVersion(true)); MyLogger.getLogger().info("Finished"); return Status.OK_STATUS; } catch (Exception e) { e.printStackTrace(); MyLogger.getLogger().error(e.getMessage()); return Status.CANCEL_STATUS; } }
public static long getSizeOf(String source) { String result = ""; try { result = AdbUtility.run("su -c 'busybox stat " + source + "'"); } catch (Exception e) { result = ""; } if (!result.contains("Size")) return 0L; Scanner sc = new Scanner(result); while (sc.hasNextLine()) { String line = sc.nextLine(); if (line.contains("Size")) { return Long.parseLong( line.substring(line.indexOf("Size"), line.indexOf("Blocks")) .replace("Size:", "") .trim()); } } return 0L; }
protected IStatus run(IProgressMonitor monitor) { try { DeviceEntry ent = new DeviceEntry(platform); if (!new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "cert.properties") .exists()) throw new Exception("cert.properties is missing"); Properties p = new Properties(); try { p.load( new FileInputStream( new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "cert.properties"))); } catch (Exception ex) { } String bootwrite = ""; Enumeration<Object> e = p.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (p.getProperty(key).equals(phonecert)) { bootwrite = key; break; } } if (bootwrite.length() == 0) throw new Exception("Phone certificate not identified"); bootwrite = "bootwrite_" + bootwrite + "SL"; if (!new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + bootwrite) .exists()) throw new Exception(bootwrite + " is missing"); if (!new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "fixPart") .exists()) throw new Exception("fixPart is missing"); if (!new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "mapper_2.6.29.ko") .exists()) throw new Exception("mapper_2.6.29.ko is missing"); if (platform.equals("X10")) if (!new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "mapper_2.6.29-00054-g5f01537.ko") .exists()) throw new Exception("mapper_2.6.29-00054-g5f01537.ko is missing"); MyLogger.getLogger().info("Waiting for device to reboot"); Devices.waitForReboot(false); if (!Devices.getCurrent().getKernelVersion().equals("2.6.29-00054-g5f01537") && !Devices.getCurrent().getKernelVersion().equals("2.6.29")) throw new Exception("Kernel does not match a compatible one"); if (!Devices.getCurrent().hasRoot()) throw new Exception("Device must be rooted first"); String mapper = "mapper_" + Devices.getCurrent().getKernelVersion() + ".ko"; AdbUtility.push( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + "fixPart", GlobalConfig.getProperty("deviceworkdir")); FTShell fixpart = new FTShell( new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "shells" + File.separator + "runfixPart")); String output = fixpart.runRoot(); if (!output.contains("success")) throw new Exception("Error applying fixpart: " + output); MyLogger.getLogger().info("Successfully applied fixPart. Rebooting"); Devices.getCurrent().reboot(); Devices.waitForReboot(false); AdbUtility.push( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + mapper, GlobalConfig.getProperty("deviceworkdir")); AdbUtility.push( ent.getDeviceDir() + File.separator + "blu" + File.separator + "files" + File.separator + bootwrite, GlobalConfig.getProperty("deviceworkdir")); FTShell runbootwrite = new FTShell( new File( ent.getDeviceDir() + File.separator + "blu" + File.separator + "shells" + File.separator + "runbootwrite")); runbootwrite.setProperty("KVER", Devices.getCurrent().getKernelVersion()); runbootwrite.setProperty("BOOTWRITEBIN", bootwrite); output = runbootwrite.runRoot(); if (!output.contains("success")) throw new Exception("Error applying fixpart: " + output); MyLogger.getLogger() .info("Successfully applied bootwrite. Bootloader should be unlocked. Rebooting"); Devices.getCurrent().reboot(); return Status.OK_STATUS; } catch (Exception e) { e.printStackTrace(); MyLogger.getLogger().error(e.getMessage()); return Status.CANCEL_STATUS; } }
public boolean isBusyboxInstalled(boolean force) { if (hasBusybox == null || force) hasBusybox = (AdbUtility.getBusyboxVersion(getBusyBoxInstallPath()).length() > 0); return hasBusybox.booleanValue(); }
public boolean hasRoot() { if (AdbUtility.hasRootNative(false)) return AdbUtility.hasRootNative(false); return AdbUtility.hasRootPerms(); }
public String getSerial() { return AdbUtility.getDevices().nextElement(); }
private void setKernelVersion() { _entry.setProperty("kernel.version", AdbUtility.getKernelVersion(isBusyboxInstalled(false))); }
public String getInstalledBusyboxVersion(boolean force) { if (Devices.getCurrent().isBusyboxInstalled(force)) { return AdbUtility.getBusyboxVersion(getBusyBoxInstallPath()); } else hasBusybox = false; return "N/A"; }
public static void setCurrent(String device) { AdbUtility.init(); _current = (DeviceEntry) props.get(device); _current.queryAll(); }
public static boolean HasOneAdbConnected() { return AdbUtility.isConnected(); }