use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Iptables method doInstallScripts.
/**
* Really install init-script (copies it from app RAW directory)
* @param src_file String matching source init-script
* @param dst_file String matching destination init-script
*/
private static void doInstallScripts(String src_file, String dst_file) {
Shell shell;
try {
shell = Shell.startRootShell();
} catch (IOException e) {
Log.e("Shell", "Unable to get shell");
return;
}
if (shell != null) {
String CMD = String.format("cp %s %s", src_file, dst_file);
SimpleCommand command1 = new SimpleCommand("mount -o remount,rw /system");
SimpleCommand command2 = new SimpleCommand(CMD);
CMD = String.format("chmod 0755 %s", dst_file);
SimpleCommand command3 = new SimpleCommand(CMD);
SimpleCommand command4 = new SimpleCommand("mount -o remount,ro /system");
try {
shell.add(command1).waitForFinish();
shell.add(command2).waitForFinish();
shell.add(command3).waitForFinish();
shell.add(command4).waitForFinish();
} catch (IOException e) {
Log.e("Shell", "Unable to run simple command");
} catch (TimeoutException e) {
Log.e("Shell", "Error while closing the Shell");
} finally {
try {
shell.close();
} catch (IOException e) {
}
}
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.
the class Shell method execCommand.
public String execCommand(String Command, boolean waitForFinish, boolean logCommand) throws FailedExecuteCommand {
final SimpleCommand command = new SimpleCommand(Command);
try {
Log.i(TAG, Command);
if (waitForFinish) {
this.add(command).waitForFinish();
} else {
this.add(command);
}
String output = command.getOutput();
if (logCommand)
logCommand(command);
Log.i(TAG, output);
if (command.getExitCode() != 0) {
throw new Exception("Exit-Code not 0");
}
return output;
} catch (Exception e) {
if (logCommand)
logCommand(command);
Log.i(TAG, "Failed: " + command.getOutput());
throw new FailedExecuteCommand(command);
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project Rashr by DsLNeXuS.
the class Toolbox method toggleAdbDaemon.
/**
* TODO: Not tested!
*
* @param toggle
* @throws IOException
* @throws TimeoutException
* @throws BrokenBusyboxException
*/
public void toggleAdbDaemon(boolean toggle) throws FailedExecuteCommand {
SimpleCommand disableAdb = new SimpleCommand("setprop persist.service.adb.enable 0", "stop adbd");
SimpleCommand enableAdb = new SimpleCommand("setprop persist.service.adb.enable 1", "stop adbd", "sleep 1", "start adbd");
if (toggle) {
shell.execCommand(enableAdb);
} else {
shell.execCommand(disableAdb);
}
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Toolbox method copyFile.
/**
* Copys a file to a destination. Because cp is not available on all android devices, we use dd
* or cat.
*
* @param source
* example: /data/data/org.adaway/files/hosts
* @param destination
* example: /system/etc/hosts
* @param remountAsRw
* remounts the destination as read/write before writing to it
* @param preserveFileAttributes
* tries to copy file attributes from source to destination, if only cat is available
* only permissions are preserved
* @return true if it was successfully copied
* @throws BrokenBusyboxException
* @throws IOException
* @throws TimeoutException
*/
public boolean copyFile(String source, String destination, boolean remountAsRw, boolean preservePermissions) throws BrokenBusyboxException, IOException, TimeoutException {
/*
* dd can only copy files, but we can not check if the source is a file without invoking
* shell commands, because from Java we probably have no read access, thus we only check if
* they are ending with trailing slashes
*/
if (source.endsWith("/") || destination.endsWith("/")) {
throw new FileNotFoundException("dd can only copy files!");
}
// remount destination as read/write before copying to it
if (remountAsRw) {
if (!remount(destination, "RW")) {
Log.d(RootCommands.TAG, "Remounting failed! There is probably no need to remount this partition!");
}
}
// get permissions of source before overwriting
String permissions = null;
if (preservePermissions) {
permissions = getFilePermissions(source);
}
boolean commandSuccess = false;
SimpleCommand ddCommand = new SimpleCommand("dd if=" + source + " of=" + destination);
shell.add(ddCommand).waitForFinish();
if (ddCommand.getExitCode() == 0) {
commandSuccess = true;
} else {
// try cat if dd fails
SimpleCommand catCommand = new SimpleCommand("cat " + source + " > " + destination);
shell.add(catCommand).waitForFinish();
if (catCommand.getExitCode() == 0) {
commandSuccess = true;
}
}
// set back permissions from source to destination
if (preservePermissions) {
setFilePermissions(destination, permissions);
}
// remount destination back to read only
if (remountAsRw) {
if (!remount(destination, "RO")) {
Log.d(RootCommands.TAG, "Remounting failed! There is probably no need to remount this partition!");
}
}
return commandSuccess;
}
use of org.sufficientlysecure.rootcommands.command.SimpleCommand in project orWall by EthACKdotOrg.
the class Iptables method removeIniScript.
/**
* Removes init-script.
*/
public static void removeIniScript(Context context) {
Shell shell;
try {
shell = Shell.startRootShell();
} catch (IOException e) {
Log.e("Shell", "Unable to get shell");
return;
}
if (shell != null) {
SimpleCommand command1 = new SimpleCommand("mount -o remount,rw /system");
SimpleCommand command2 = new SimpleCommand("rm -f " + DST_FILE);
SimpleCommand command3 = new SimpleCommand("mount -o remount,ro /system");
try {
shell.add(command1).waitForFinish();
shell.add(command2).waitForFinish();
shell.add(command3).waitForFinish();
} catch (IOException e) {
Log.e("Shell", "Unable to run simple command");
} catch (TimeoutException e) {
Log.e("Shell", "Error while closing the Shell");
} finally {
Preferences.setEnforceInitScript(context, false);
try {
shell.close();
} catch (IOException e) {
}
}
}
}
Aggregations