tor-commits
Threads by month
- ----- 2025 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
October 2017
- 17 participants
- 2004 discussions

[orbot/master] remove RootCommands library as we don't need it now
by n8fr8@torproject.org 14 Oct '17
by n8fr8@torproject.org 14 Oct '17
14 Oct '17
commit 632824bd5fb42da69584f439e1df570d39203a48
Author: n8fr8 <nathan(a)freitas.net>
Date: Sat Oct 14 12:17:36 2017 -0400
remove RootCommands library as we don't need it now
---
RootCommands/.gitignore | 33 -
RootCommands/build.gradle | 28 -
RootCommands/src/main/AndroidManifest.xml | 13 -
.../org/sufficientlysecure/rootcommands/Mount.java | 58 --
.../sufficientlysecure/rootcommands/Remounter.java | 191 -----
.../rootcommands/RootCommands.java | 50 --
.../org/sufficientlysecure/rootcommands/Shell.java | 350 ---------
.../rootcommands/SystemCommands.java | 122 ---
.../sufficientlysecure/rootcommands/Toolbox.java | 824 ---------------------
.../rootcommands/command/Command.java | 170 -----
.../rootcommands/command/ExecutableCommand.java | 65 --
.../rootcommands/command/SimpleCommand.java | 43 --
.../command/SimpleExecutableCommand.java | 45 --
.../rootcommands/util/BrokenBusyboxException.java | 32 -
.../sufficientlysecure/rootcommands/util/Log.java | 83 ---
.../util/RootAccessDeniedException.java | 32 -
.../util/UnsupportedArchitectureException.java | 30 -
.../rootcommands/util/Utils.java | 105 ---
18 files changed, 2274 deletions(-)
diff --git a/RootCommands/.gitignore b/RootCommands/.gitignore
deleted file mode 100644
index afa9dfc4..00000000
--- a/RootCommands/.gitignore
+++ /dev/null
@@ -1,33 +0,0 @@
-#Android specific
-bin
-gen
-obj
-libs/armeabi
-lint.xml
-local.properties
-release.properties
-ant.properties
-*.class
-*.apk
-
-#Gradle
-.gradle
-build
-gradle.properties
-gradlew
-gradlew.bat
-gradle
-
-#Maven
-target
-pom.xml.*
-
-#Eclipse
-.project
-.classpath
-.settings
-.metadata
-
-#IntelliJ IDEA
-.idea
-*.iml
diff --git a/RootCommands/build.gradle b/RootCommands/build.gradle
deleted file mode 100644
index 7cfab726..00000000
--- a/RootCommands/build.gradle
+++ /dev/null
@@ -1,28 +0,0 @@
-apply plugin: 'com.android.library'
-
-android {
- compileSdkVersion 25
- buildToolsVersion "25"
-
- sourceSets {
- main {
- jni.srcDirs = []
- }
- }
-
- defaultConfig {
- minSdkVersion 9
- targetSdkVersion 25
- versionCode 1
- versionName "1.0"
-
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
-}
-
-
diff --git a/RootCommands/src/main/AndroidManifest.xml b/RootCommands/src/main/AndroidManifest.xml
deleted file mode 100644
index ee9b1995..00000000
--- a/RootCommands/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.sufficientlysecure.rootcommands"
- android:versionCode="3"
- android:versionName="1.2" >
-
- <uses-sdk
- android:minSdkVersion="7"
- android:targetSdkVersion="17" />
-
- <application />
-
-</manifest>
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Mount.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Mount.java
deleted file mode 100644
index 6f5ef787..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Mount.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class Mount {
- protected final File mDevice;
- protected final File mMountPoint;
- protected final String mType;
- protected final Set<String> mFlags;
-
- Mount(File device, File path, String type, String flagsStr) {
- mDevice = device;
- mMountPoint = path;
- mType = type;
- mFlags = new HashSet<String>(Arrays.asList(flagsStr.split(",")));
- }
-
- public File getDevice() {
- return mDevice;
- }
-
- public File getMountPoint() {
- return mMountPoint;
- }
-
- public String getType() {
- return mType;
- }
-
- public Set<String> getFlags() {
- return mFlags;
- }
-
- @Override
- public String toString() {
- return String.format("%s on %s type %s %s", mDevice, mMountPoint, mType, mFlags);
- }
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java
deleted file mode 100644
index 00d4e2cd..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Remounter.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.util.ArrayList;
-import java.util.Locale;
-
-import org.sufficientlysecure.rootcommands.command.SimpleCommand;
-import org.sufficientlysecure.rootcommands.util.Log;
-
-//no modifier, this means it is package-private. Only our internal classes can use this.
-class Remounter {
-
- private Shell shell;
-
- public Remounter(Shell shell) {
- super();
- this.shell = shell;
- }
-
- /**
- * This will take a path, which can contain the file name as well, and attempt to remount the
- * underlying partition.
- * <p/>
- * For example, passing in the following string:
- * "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately
- * being remounted. However, keep in mind that the longer the path you supply, the more work
- * this has to do, and the slower it will run.
- *
- * @param file
- * file path
- * @param mountType
- * mount type: pass in RO (Read only) or RW (Read Write)
- * @return a <code>boolean</code> which indicates whether or not the partition has been
- * remounted as specified.
- */
- protected boolean remount(String file, String mountType) {
-
- // if the path has a trailing slash get rid of it.
- if (file.endsWith("/") && !file.equals("/")) {
- file = file.substring(0, file.lastIndexOf("/"));
- }
- // Make sure that what we are trying to remount is in the mount list.
- boolean foundMount = false;
- while (!foundMount) {
- try {
- for (Mount mount : getMounts()) {
- Log.d(RootCommands.TAG, mount.getMountPoint().toString());
-
- if (file.equals(mount.getMountPoint().toString())) {
- foundMount = true;
- break;
- }
- }
- } catch (Exception e) {
- Log.e(RootCommands.TAG, "Exception", e);
- return false;
- }
- if (!foundMount) {
- try {
- file = (new File(file).getParent()).toString();
- } catch (Exception e) {
- Log.e(RootCommands.TAG, "Exception", e);
- return false;
- }
- }
- }
- Mount mountPoint = findMountPointRecursive(file);
-
- Log.d(RootCommands.TAG, "Remounting " + mountPoint.getMountPoint().getAbsolutePath()
- + " as " + mountType.toLowerCase(Locale.US));
- final boolean isMountMode = mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US));
-
- if (!isMountMode) {
- // grab an instance of the internal class
- try {
- SimpleCommand command = new SimpleCommand("busybox mount -o remount,"
- + mountType.toLowerCase(Locale.US) + " " + mountPoint.getDevice().getAbsolutePath()
- + " " + mountPoint.getMountPoint().getAbsolutePath(),
- "toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " "
- + mountPoint.getDevice().getAbsolutePath() + " "
- + mountPoint.getMountPoint().getAbsolutePath(), "mount -o remount,"
- + mountType.toLowerCase(Locale.US) + " "
- + mountPoint.getDevice().getAbsolutePath() + " "
- + mountPoint.getMountPoint().getAbsolutePath(),
- "/system/bin/toolbox mount -o remount," + mountType.toLowerCase(Locale.US) + " "
- + mountPoint.getDevice().getAbsolutePath() + " "
- + mountPoint.getMountPoint().getAbsolutePath());
-
- // execute on shell
- shell.add(command).waitForFinish();
-
- } catch (Exception e) {
- }
-
- mountPoint = findMountPointRecursive(file);
- }
-
- if (mountPoint != null) {
- Log.d(RootCommands.TAG, mountPoint.getFlags() + " AND " + mountType.toLowerCase(Locale.US));
- if (mountPoint.getFlags().contains(mountType.toLowerCase(Locale.US))) {
- Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
- return true;
- } else {
- Log.d(RootCommands.TAG, mountPoint.getFlags().toString());
- }
- } else {
- Log.d(RootCommands.TAG, "mountPoint is null");
- }
- return false;
- }
-
- private Mount findMountPointRecursive(String file) {
- try {
- ArrayList<Mount> mounts = getMounts();
- for (File path = new File(file); path != null;) {
- for (Mount mount : mounts) {
- if (mount.getMountPoint().equals(path)) {
- return mount;
- }
- }
- }
- return null;
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (Exception e) {
- Log.e(RootCommands.TAG, "Exception", e);
- }
- return null;
- }
-
- /**
- * This will return an ArrayList of the class Mount. The class mount contains the following
- * property's: device mountPoint type flags
- * <p/>
- * These will provide you with any information you need to work with the mount points.
- *
- * @return <code>ArrayList<Mount></code> an ArrayList of the class Mount.
- * @throws Exception
- * if we cannot return the mount points.
- */
- protected static ArrayList<Mount> getMounts() throws Exception {
-
- final String tempFile = "/data/local/RootToolsMounts";
-
- // copy /proc/mounts to tempfile. Directly reading it does not work on 4.3
- Shell shell = Shell.startRootShell();
- Toolbox tb = new Toolbox(shell);
- tb.copyFile("/proc/mounts", tempFile, false, false);
- tb.setFilePermissions(tempFile, "777");
- shell.close();
-
- LineNumberReader lnr = null;
- lnr = new LineNumberReader(new FileReader(tempFile));
- String line;
- ArrayList<Mount> mounts = new ArrayList<Mount>();
- while ((line = lnr.readLine()) != null) {
-
- Log.d(RootCommands.TAG, line);
-
- String[] fields = line.split(" ");
- mounts.add(new Mount(new File(fields[0]), // device
- new File(fields[1]), // mountPoint
- fields[2], // fstype
- fields[3] // flags
- ));
- }
- lnr.close();
-
- return mounts;
- }
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java
deleted file mode 100644
index 25576281..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/RootCommands.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import org.sufficientlysecure.rootcommands.util.Log;
-
-public class RootCommands {
- public static boolean DEBUG = false;
- public static int DEFAULT_TIMEOUT = 10000;
-
- public static final String TAG = "RootCommands";
-
- /**
- * General method to check if user has su binary and accepts root access for this program!
- *
- * @return true if everything worked
- */
- public static boolean rootAccessGiven() {
- boolean rootAccess = false;
-
- try {
- Shell rootShell = Shell.startRootShell();
-
- Toolbox tb = new Toolbox(rootShell);
- if (tb.isRootAccessGiven()) {
- rootAccess = true;
- }
-
- rootShell.close();
- } catch (Exception e) {
- Log.e(TAG, "Problem while checking for root access!", e);
- }
-
- return rootAccess;
- }
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java
deleted file mode 100644
index 8091dee6..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Shell.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks, Jeremy Lakeman (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.sufficientlysecure.rootcommands.command.Command;
-import org.sufficientlysecure.rootcommands.util.Log;
-import org.sufficientlysecure.rootcommands.util.RootAccessDeniedException;
-import org.sufficientlysecure.rootcommands.util.Utils;
-
-public class Shell implements Closeable {
- private final Process shellProcess;
- private final BufferedReader stdOutErr;
- private final DataOutputStream outputStream;
- private final List<Command> commands = new ArrayList<Command>();
- private boolean close = false;
-
- private static final String LD_LIBRARY_PATH = System.getenv("LD_LIBRARY_PATH");
- private static final String token = "F*D^W@#FGF";
-
- /**
- * Start root shell
- *
- * @param customEnv
- * @param baseDirectory
- * @return
- * @throws IOException
- */
- public static Shell startRootShell(ArrayList<String> customEnv, String baseDirectory)
- throws IOException, RootAccessDeniedException {
- Log.d(RootCommands.TAG, "Starting Root Shell!");
-
- // On some versions of Android (ICS) LD_LIBRARY_PATH is unset when using su
- // We need to pass LD_LIBRARY_PATH over su for some commands to work correctly.
- if (customEnv == null) {
- customEnv = new ArrayList<String>();
- }
- customEnv.add("LD_LIBRARY_PATH=" + LD_LIBRARY_PATH);
-
- Shell shell = new Shell(Utils.getSuPath(), customEnv, baseDirectory);
-
- return shell;
- }
-
- /**
- * Start root shell without custom environment and base directory
- *
- * @return
- * @throws IOException
- */
- public static Shell startRootShell() throws IOException, RootAccessDeniedException {
- return startRootShell(null, null);
- }
-
- /**
- * Start default sh shell
- *
- * @param customEnv
- * @param baseDirectory
- * @return
- * @throws IOException
- */
- public static Shell startShell(ArrayList<String> customEnv, String baseDirectory)
- throws IOException {
- Log.d(RootCommands.TAG, "Starting Shell!");
- Shell shell = new Shell("sh", customEnv, baseDirectory);
- return shell;
- }
-
- /**
- * Start default sh shell without custom environment and base directory
- *
- * @return
- * @throws IOException
- */
- public static Shell startShell() throws IOException {
- return startShell(null, null);
- }
-
- /**
- * Start custom shell defined by shellPath
- *
- * @param shellPath
- * @param customEnv
- * @param baseDirectory
- * @return
- * @throws IOException
- */
- public static Shell startCustomShell(String shellPath, ArrayList<String> customEnv,
- String baseDirectory) throws IOException {
- Log.d(RootCommands.TAG, "Starting Custom Shell!");
- Shell shell = new Shell(shellPath, customEnv, baseDirectory);
-
- return shell;
- }
-
- /**
- * Start custom shell without custom environment and base directory
- *
- * @param shellPath
- * @return
- * @throws IOException
- */
- public static Shell startCustomShell(String shellPath) throws IOException {
- return startCustomShell(shellPath, null, null);
- }
-
- private Shell(String shell, ArrayList<String> customEnv, String baseDirectory)
- throws IOException, RootAccessDeniedException {
- Log.d(RootCommands.TAG, "Starting shell: " + shell);
-
- // start shell process!
- shellProcess = Utils.runWithEnv(shell, customEnv, baseDirectory);
-
- // StdErr is redirected to StdOut, defined in Command.getCommand()
- stdOutErr = new BufferedReader(new InputStreamReader(shellProcess.getInputStream()));
- outputStream = new DataOutputStream(shellProcess.getOutputStream());
-
- outputStream.write("echo Started\n".getBytes());
- outputStream.flush();
-
- while (true) {
- String line = stdOutErr.readLine();
- if (line == null)
- throw new RootAccessDeniedException(
- "stdout line is null! Access was denied or this executeable is not a shell!");
- if ("".equals(line))
- continue;
- if ("Started".equals(line))
- break;
-
- destroyShellProcess();
- throw new IOException("Unable to start shell, unexpected output \"" + line + "\"");
- }
-
- new Thread(inputRunnable, "Shell Input").start();
- new Thread(outputRunnable, "Shell Output").start();
- }
-
- private Runnable inputRunnable = new Runnable() {
- public void run() {
- try {
- writeCommands();
- } catch (IOException e) {
- Log.e(RootCommands.TAG, "IO Exception", e);
- }
- }
- };
-
- private Runnable outputRunnable = new Runnable() {
- public void run() {
- try {
- readOutput();
- } catch (IOException e) {
- Log.e(RootCommands.TAG, "IOException", e);
- } catch (InterruptedException e) {
- Log.e(RootCommands.TAG, "InterruptedException", e);
- }
- }
- };
-
- /**
- * Destroy shell process considering that the process could already be terminated
- */
- private void destroyShellProcess() {
- try {
- // Yes, this really is the way to check if the process is
- // still running.
- shellProcess.exitValue();
- } catch (IllegalThreadStateException e) {
- // Only call destroy() if the process is still running;
- // Calling it for a terminated process will not crash, but
- // (starting with at least ICS/4.0) spam the log with INFO
- // messages ala "Failed to destroy process" and "kill
- // failed: ESRCH (No such process)".
- shellProcess.destroy();
- }
-
- Log.d(RootCommands.TAG, "Shell destroyed");
- }
-
- /**
- * Writes queued commands one after another into the opened shell. After an execution a token is
- * written to seperate command output on read
- *
- * @throws IOException
- */
- private void writeCommands() throws IOException {
- try {
- int commandIndex = 0;
- while (true) {
- DataOutputStream out;
- synchronized (commands) {
- while (!close && commandIndex >= commands.size()) {
- commands.wait();
- }
- out = this.outputStream;
- }
- if (commandIndex < commands.size()) {
- Command next = commands.get(commandIndex);
- next.writeCommand(out);
- String line = "\necho " + token + " " + commandIndex + " $?\n";
- out.write(line.getBytes());
- out.flush();
- commandIndex++;
- } else if (close) {
- out.write("\nexit 0\n".getBytes());
- out.flush();
- Log.d(RootCommands.TAG, "Closing shell");
- shellProcess.waitFor();
- out.close();
- return;
- } else {
- Thread.sleep(50);
- }
- }
- } catch (InterruptedException e) {
- Log.e(RootCommands.TAG, "interrupted while writing command", e);
- }
- }
-
- /**
- * Reads output line by line, seperated by token written after every command
- *
- * @throws IOException
- * @throws InterruptedException
- */
- private void readOutput() throws IOException, InterruptedException {
- Command command = null;
-
- // index of current command
- int commandIndex = 0;
- while (true) {
- String lineStdOut = stdOutErr.readLine();
-
- // terminate on EOF
- if (lineStdOut == null)
- break;
-
- if (command == null) {
-
- // break on close after last command
- if (commandIndex >= commands.size()) {
- if (close)
- break;
- continue;
- }
-
- // get current command
- command = commands.get(commandIndex);
- }
-
- int pos = lineStdOut.indexOf(token);
- if (pos > 0) {
- command.processOutput(lineStdOut.substring(0, pos));
- }
- if (pos >= 0) {
- lineStdOut = lineStdOut.substring(pos);
- String fields[] = lineStdOut.split(" ");
- int id = Integer.parseInt(fields[1]);
- if (id == commandIndex) {
- command.setExitCode(Integer.parseInt(fields[2]));
-
- // go to next command
- commandIndex++;
- command = null;
- continue;
- }
- }
- command.processOutput(lineStdOut);
- }
- Log.d(RootCommands.TAG, "Read all output");
- shellProcess.waitFor();
- stdOutErr.close();
- destroyShellProcess();
-
- while (commandIndex < commands.size()) {
- if (command == null) {
- command = commands.get(commandIndex);
- }
- command.terminated("Unexpected Termination!");
- commandIndex++;
- command = null;
- }
- }
-
- /**
- * Add command to shell queue
- *
- * @param command
- * @return
- * @throws IOException
- */
- public Command add(Command command) throws IOException {
- if (close)
- throw new IOException("Unable to add commands to a closed shell");
- synchronized (commands) {
- commands.add(command);
- // set shell on the command object, to know where the command is running on
- command.addedToShell(this, (commands.size() - 1));
- commands.notifyAll();
- }
-
- return command;
- }
-
- /**
- * Close shell
- *
- * @throws IOException
- */
- public void close() throws IOException {
- synchronized (commands) {
- this.close = true;
- commands.notifyAll();
- }
- }
-
- /**
- * Returns number of queued commands
- *
- * @return
- */
- public int getCommandsSize() {
- return commands.size();
- }
-
-}
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java
deleted file mode 100644
index 355e6952..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/SystemCommands.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import android.annotation.TargetApi;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.location.LocationManager;
-import android.os.PowerManager;
-import android.provider.Settings;
-
-/**
- * This methods work when the apk is installed as a system app (under /system/app)
- */
-public class SystemCommands {
- Context context;
-
- public SystemCommands(Context context) {
- super();
- this.context = context;
- }
-
- /**
- * Get GPS status
- *
- * @return
- */
- public boolean getGPS() {
- return ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE))
- .isProviderEnabled(LocationManager.GPS_PROVIDER);
- }
-
- /**
- * Enable/Disable GPS
- *
- * @param value
- */
- @TargetApi(8)
- public void setGPS(boolean value) {
- ContentResolver localContentResolver = context.getContentResolver();
- Settings.Secure.setLocationProviderEnabled(localContentResolver,
- LocationManager.GPS_PROVIDER, value);
- }
-
- /**
- * TODO: Not ready yet
- */
- @TargetApi(8)
- public void reboot() {
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- pm.reboot("recovery");
- pm.reboot(null);
-
- // not working:
- // reboot(null);
- }
-
- /**
- * Reboot the device immediately, passing 'reason' (may be null) to the underlying __reboot
- * system call. Should not return.
- *
- * Taken from com.android.server.PowerManagerService.reboot
- */
- // public void reboot(String reason) {
- //
- // // final String finalReason = reason;
- // Runnable runnable = new Runnable() {
- // public void run() {
- // synchronized (this) {
- // // ShutdownThread.reboot(mContext, finalReason, false);
- // try {
- // Class<?> clazz = Class.forName("com.android.internal.app.ShutdownThread");
- //
- // // if (mReboot) {
- // Method method = clazz.getMethod("reboot", Context.class, String.class,
- // Boolean.TYPE);
- // method.invoke(null, context, null, false);
- //
- // // if (mReboot) {
- // // Method method = clazz.getMethod("reboot", Context.class, String.class,
- // // Boolean.TYPE);
- // // method.invoke(null, mContext, mReason, mConfirm);
- // // } else {
- // // Method method = clazz.getMethod("shutdown", Context.class, Boolean.TYPE);
- // // method.invoke(null, mContext, mConfirm);
- // // }
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // }
- //
- // }
- // };
- // // ShutdownThread must run on a looper capable of displaying the UI.
- // mHandler.post(runnable);
- //
- // // PowerManager.reboot() is documented not to return so just wait for the inevitable.
- // // synchronized (runnable) {
- // // while (true) {
- // // try {
- // // runnable.wait();
- // // } catch (InterruptedException e) {
- // // }
- // // }
- // // }
- // }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java
deleted file mode 100644
index fe8d2b4c..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/Toolbox.java
+++ /dev/null
@@ -1,824 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.concurrent.TimeoutException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.sufficientlysecure.rootcommands.command.ExecutableCommand;
-import org.sufficientlysecure.rootcommands.command.Command;
-import org.sufficientlysecure.rootcommands.command.SimpleCommand;
-import org.sufficientlysecure.rootcommands.util.BrokenBusyboxException;
-import org.sufficientlysecure.rootcommands.util.Log;
-
-import android.os.StatFs;
-import android.os.SystemClock;
-
-/**
- * All methods in this class are working with Androids toolbox. Toolbox is similar to busybox, but
- * normally shipped on every Android OS. You can find toolbox commands on
- * https://github.com/CyanogenMod/android_system_core/tree/ics/toolbox
- *
- * This means that these commands are designed to work on every Android OS, with a _working_ toolbox
- * binary on it. They don't require busybox!
- *
- */
-public class Toolbox {
- private Shell shell;
-
- /**
- * All methods in this class are working with Androids toolbox. Toolbox is similar to busybox,
- * but normally shipped on every Android OS.
- *
- * @param shell
- * where to execute commands on
- */
- public Toolbox(Shell shell) {
- super();
- this.shell = shell;
- }
-
- /**
- * Checks if user accepted root access
- *
- * (commands: id)
- *
- * @return true if user has given root access
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public boolean isRootAccessGiven() throws BrokenBusyboxException, TimeoutException, IOException {
- SimpleCommand idCommand = new SimpleCommand("id");
- shell.add(idCommand).waitForFinish();
-
- if (idCommand.getOutput().contains("uid=0")) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * This command class gets all pids to a given process name
- */
- private class PsCommand extends Command {
- private String processName;
- private ArrayList<String> pids;
- private String psRegex;
- private Pattern psPattern;
-
- public PsCommand(String processName) {
- super("ps");
- this.processName = processName;
- pids = new ArrayList<String>();
-
- /**
- * regex to get pid out of ps line, example:
- *
- * <pre>
- * root 24736 1 12140 584 ffffffff 40010d14 S /data/data/org.adaway/files/blank_webserver
- * ^\\S \\s ([0-9]+) .* processName $
- * </pre>
- */
- psRegex = "^\\S+\\s+([0-9]+).*" + Pattern.quote(processName) + "$";
- psPattern = Pattern.compile(psRegex);
- }
-
- public ArrayList<String> getPids() {
- return pids;
- }
-
- public String getPidsString() {
- StringBuilder sb = new StringBuilder();
- for (String s : pids) {
- sb.append(s);
- sb.append(" ");
- }
-
- return sb.toString();
- }
-
- @Override
- public void output(int id, String line) {
- // general check if line contains processName
- if (line.contains(processName)) {
- Matcher psMatcher = psPattern.matcher(line);
-
- // try to match line exactly
- try {
- if (psMatcher.find()) {
- String pid = psMatcher.group(1);
- // add to pids list
- pids.add(pid);
- Log.d(RootCommands.TAG, "Found pid: " + pid);
- } else {
- Log.d(RootCommands.TAG, "Matching in ps command failed!");
- }
- } catch (Exception e) {
- Log.e(RootCommands.TAG, "Error with regex!", e);
- }
- }
- }
-
- @Override
- public void afterExecution(int id, int exitCode) {
- }
-
- }
-
- /**
- * This method can be used to kill a running process
- *
- * (commands: ps, kill)
- *
- * @param processName
- * name of process to kill
- * @return <code>true</code> if process was found and killed successfully
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public boolean killAll(String processName) throws BrokenBusyboxException, TimeoutException,
- IOException {
- Log.d(RootCommands.TAG, "Killing process " + processName);
-
- PsCommand psCommand = new PsCommand(processName);
- shell.add(psCommand).waitForFinish();
-
- // kill processes
- if (!psCommand.getPids().isEmpty()) {
- // example: kill -9 1234 1222 5343
- SimpleCommand killCommand = new SimpleCommand("kill -9 "
- + psCommand.getPidsString());
- shell.add(killCommand).waitForFinish();
-
- if (killCommand.getExitCode() == 0) {
- return true;
- } else {
- return false;
- }
- } else {
- Log.d(RootCommands.TAG, "No pid found! Nothing was killed!");
- return false;
- }
- }
-
- /**
- * Kill a running executable
- *
- * See README for more information how to use your own executables!
- *
- * @param executableName
- * @return
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public boolean killAllExecutable(String executableName) throws BrokenBusyboxException,
- TimeoutException, IOException {
- return killAll(ExecutableCommand.EXECUTABLE_PREFIX + executableName + ExecutableCommand.EXECUTABLE_SUFFIX);
- }
-
- /**
- * This method can be used to to check if a process is running
- *
- * @param processName
- * name of process to check
- * @return <code>true</code> if process was found
- * @throws IOException
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * (Could not determine if the process is running)
- */
- public boolean isProcessRunning(String processName) throws BrokenBusyboxException,
- TimeoutException, IOException {
- PsCommand psCommand = new PsCommand(processName);
- shell.add(psCommand).waitForFinish();
-
- // if pids are available process is running!
- if (!psCommand.getPids().isEmpty()) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Checks if binary is running
- *
- * @param binaryName
- * @return
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public boolean isBinaryRunning(String binaryName) throws BrokenBusyboxException,
- TimeoutException, IOException {
- return isProcessRunning(ExecutableCommand.EXECUTABLE_PREFIX + binaryName
- + ExecutableCommand.EXECUTABLE_SUFFIX);
- }
-
- /**
- * Ls command to get permissions or symlinks
- */
- private class LsCommand extends Command {
- private String fileName;
- private String permissionRegex;
- private Pattern permissionPattern;
- private String symlinkRegex;
- private Pattern symlinkPattern;
-
- private String symlink;
- private String permissions;
-
- public String getSymlink() {
- return symlink;
- }
-
- public String getPermissions() {
- return permissions;
- }
-
- public LsCommand(String file) {
- super("ls -l " + file);
-
- // get only filename:
- this.fileName = (new File(file)).getName();
- Log.d(RootCommands.TAG, "fileName: " + fileName);
-
- /**
- * regex to get pid out of ps line, example:
- *
- * <pre>
- * with busybox:
- * lrwxrwxrwx 1 root root 15 Aug 13 12:14 dev/stdin -> /proc/self/fd/0
- *
- * with toolbox:
- * lrwxrwxrwx root root 15 Aug 13 12:14 stdin -> /proc/self/fd/0
- *
- * Regex:
- * ^.*?(\\S{10}) .* $
- * </pre>
- */
- permissionRegex = "^.*?(\\S{10}).*$";
- permissionPattern = Pattern.compile(permissionRegex);
-
- /**
- * regex to get symlink
- *
- * <pre>
- * -> /proc/self/fd/0
- * ^.*?\\-\\> \\s+ (.*) $
- * </pre>
- */
- symlinkRegex = "^.*?\\-\\>\\s+(.*)$";
- symlinkPattern = Pattern.compile(symlinkRegex);
- }
-
- /**
- * Converts permission string from ls command to numerical value. Example: -rwxrwxrwx gets
- * to 777
- *
- * @param permissions
- * @return
- */
- private String convertPermissions(String permissions) {
- int owner = getGroupPermission(permissions.substring(1, 4));
- int group = getGroupPermission(permissions.substring(4, 7));
- int world = getGroupPermission(permissions.substring(7, 10));
-
- return "" + owner + group + world;
- }
-
- /**
- * Calculates permission for one group
- *
- * @param permission
- * @return value of permission string
- */
- private int getGroupPermission(String permission) {
- int value = 0;
-
- if (permission.charAt(0) == 'r') {
- value += 4;
- }
- if (permission.charAt(1) == 'w') {
- value += 2;
- }
- if (permission.charAt(2) == 'x') {
- value += 1;
- }
-
- return value;
- }
-
- @Override
- public void output(int id, String line) {
- // general check if line contains file
- if (line.contains(fileName)) {
-
- // try to match line exactly
- try {
- Matcher permissionMatcher = permissionPattern.matcher(line);
- if (permissionMatcher.find()) {
- permissions = convertPermissions(permissionMatcher.group(1));
-
- Log.d(RootCommands.TAG, "Found permissions: " + permissions);
- } else {
- Log.d(RootCommands.TAG, "Permissions were not found in ls command!");
- }
-
- // try to parse for symlink
- Matcher symlinkMatcher = symlinkPattern.matcher(line);
- if (symlinkMatcher.find()) {
- /*
- * TODO: If symlink points to a file in the same directory the path is not
- * absolute!!!
- */
- symlink = symlinkMatcher.group(1);
- Log.d(RootCommands.TAG, "Symlink found: " + symlink);
- } else {
- Log.d(RootCommands.TAG, "No symlink found!");
- }
- } catch (Exception e) {
- Log.e(RootCommands.TAG, "Error with regex!", e);
- }
- }
- }
-
- @Override
- public void afterExecution(int id, int exitCode) {
- }
-
- }
-
- /**
- * @param file
- * String that represent the file, including the full path to the file and its name.
- * @param followSymlinks
- * @return File permissions as String, for example: 777, returns null on error
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- *
- */
- public String getFilePermissions(String file) throws BrokenBusyboxException, TimeoutException,
- IOException {
- Log.d(RootCommands.TAG, "Checking permissions for " + file);
-
- String permissions = null;
-
- if (fileExists(file)) {
- Log.d(RootCommands.TAG, file + " was found.");
-
- LsCommand lsCommand = new LsCommand(file);
- shell.add(lsCommand).waitForFinish();
-
- permissions = lsCommand.getPermissions();
- }
-
- return permissions;
- }
-
- /**
- * Sets permission of file
- *
- * @param file
- * absolute path to file
- * @param permissions
- * String like 777
- * @return true if command worked
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public boolean setFilePermissions(String file, String permissions)
- throws BrokenBusyboxException, TimeoutException, IOException {
- Log.d(RootCommands.TAG, "Set permissions of " + file + " to " + permissions);
-
- SimpleCommand chmodCommand = new SimpleCommand("chmod " + permissions + " " + file);
- shell.add(chmodCommand).waitForFinish();
-
- if (chmodCommand.getExitCode() == 0) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * This will return a String that represent the symlink for a specified file.
- *
- * @param file
- * The path to the file to get the Symlink for. (must have absolute path)
- *
- * @return A String that represent the symlink for a specified file or null if no symlink
- * exists.
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public String getSymlink(String file) throws BrokenBusyboxException, TimeoutException,
- IOException {
- Log.d(RootCommands.TAG, "Find symlink for " + file);
-
- String symlink = null;
-
- LsCommand lsCommand = new LsCommand(file);
- shell.add(lsCommand).waitForFinish();
-
- symlink = lsCommand.getSymlink();
-
- return symlink;
- }
-
- /**
- * 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;
- }
-
- public static final int REBOOT_HOTREBOOT = 1;
- public static final int REBOOT_REBOOT = 2;
- public static final int REBOOT_SHUTDOWN = 3;
- public static final int REBOOT_RECOVERY = 4;
-
- /**
- * Shutdown or reboot device. Possible actions are REBOOT_HOTREBOOT, REBOOT_REBOOT,
- * REBOOT_SHUTDOWN, REBOOT_RECOVERY
- *
- * @param action
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public void reboot(int action) throws BrokenBusyboxException, TimeoutException, IOException {
- if (action == REBOOT_HOTREBOOT) {
- killAll("system_server");
- // or: killAll("zygote");
- } else {
- String command;
- switch (action) {
- case REBOOT_REBOOT:
- command = "reboot";
- break;
- case REBOOT_SHUTDOWN:
- command = "reboot -p";
- break;
- case REBOOT_RECOVERY:
- command = "reboot recovery";
- break;
- default:
- command = "reboot";
- break;
- }
-
- SimpleCommand rebootCommand = new SimpleCommand(command);
- shell.add(rebootCommand).waitForFinish();
-
- if (rebootCommand.getExitCode() == -1) {
- Log.e(RootCommands.TAG, "Reboot failed!");
- }
- }
- }
-
- /**
- * This command checks if a file exists
- */
- private class FileExistsCommand extends Command {
- private String file;
- private boolean fileExists = false;
-
- public FileExistsCommand(String file) {
- super("ls " + file);
- this.file = file;
- }
-
- public boolean isFileExists() {
- return fileExists;
- }
-
- @Override
- public void output(int id, String line) {
- if (line.trim().equals(file)) {
- fileExists = true;
- }
- }
-
- @Override
- public void afterExecution(int id, int exitCode) {
- }
-
- }
-
- /**
- * Use this to check whether or not a file exists on the filesystem.
- *
- * @param file
- * String that represent the file, including the full path to the file and its name.
- *
- * @return a boolean that will indicate whether or not the file exists.
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- *
- */
- public boolean fileExists(String file) throws BrokenBusyboxException, TimeoutException,
- IOException {
- FileExistsCommand fileExistsCommand = new FileExistsCommand(file);
- shell.add(fileExistsCommand).waitForFinish();
-
- if (fileExistsCommand.isFileExists()) {
- return true;
- } else {
- return false;
- }
- }
-
- public abstract class WithPermissions {
- abstract void whileHavingPermissions();
- }
-
- /**
- * Execute user defined Java code while having temporary permissions on a file
- *
- * @param file
- * @param withPermissions
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public void withPermission(String file, String permission, WithPermissions withPermissions)
- throws BrokenBusyboxException, TimeoutException, IOException {
- String oldPermissions = getFilePermissions(file);
-
- // set permissions (If set to 666, then Dalvik VM can also write to that file!)
- setFilePermissions(file, permission);
-
- // execute user defined code
- withPermissions.whileHavingPermissions();
-
- // set back to old permissions
- setFilePermissions(file, oldPermissions);
- }
-
- /**
- * Execute user defined Java code while having temporary write permissions on a file using chmod
- * 666
- *
- * @param file
- * @param withWritePermissions
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public void withWritePermissions(String file, WithPermissions withWritePermissions)
- throws BrokenBusyboxException, TimeoutException, IOException {
- withPermission(file, "666", withWritePermissions);
- }
-
- /**
- * Sets system clock using /dev/alarm
- *
- * @param millis
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public void setSystemClock(final long millis) throws BrokenBusyboxException, TimeoutException,
- IOException {
- withWritePermissions("/dev/alarm", new WithPermissions() {
-
- @Override
- void whileHavingPermissions() {
- SystemClock.setCurrentTimeMillis(millis);
- }
- });
- }
-
- /**
- * Adjust system clock by offset using /dev/alarm
- *
- * @param offset
- * @throws BrokenBusyboxException
- * @throws TimeoutException
- * @throws IOException
- */
- public void adjustSystemClock(final long offset) throws BrokenBusyboxException,
- TimeoutException, IOException {
- withWritePermissions("/dev/alarm", new WithPermissions() {
-
- @Override
- void whileHavingPermissions() {
- SystemClock.setCurrentTimeMillis(System.currentTimeMillis() + offset);
- }
- });
- }
-
- /**
- * This will take a path, which can contain the file name as well, and attempt to remount the
- * underlying partition.
- *
- * For example, passing in the following string:
- * "/system/bin/some/directory/that/really/would/never/exist" will result in /system ultimately
- * being remounted. However, keep in mind that the longer the path you supply, the more work
- * this has to do, and the slower it will run.
- *
- * @param file
- * file path
- * @param mountType
- * mount type: pass in RO (Read only) or RW (Read Write)
- * @return a <code>boolean</code> which indicates whether or not the partition has been
- * remounted as specified.
- */
- public boolean remount(String file, String mountType) {
- // Recieved a request, get an instance of Remounter
- Remounter remounter = new Remounter(shell);
- // send the request
- return (remounter.remount(file, mountType));
- }
-
- /**
- * This will tell you how the specified mount is mounted. rw, ro, etc...
- *
- * @param The
- * mount you want to check
- *
- * @return <code>String</code> What the mount is mounted as.
- * @throws Exception
- * if we cannot determine how the mount is mounted.
- */
- public String getMountedAs(String path) throws Exception {
- ArrayList<Mount> mounts = Remounter.getMounts();
- if (mounts != null) {
- for (Mount mount : mounts) {
- if (path.contains(mount.getMountPoint().getAbsolutePath())) {
- Log.d(RootCommands.TAG, (String) mount.getFlags().toArray()[0]);
- return (String) mount.getFlags().toArray()[0];
- }
- }
-
- throw new Exception();
- } else {
- throw new Exception();
- }
- }
-
- /**
- * Check if there is enough space on partition where target is located
- *
- * @param size
- * size of file to put on partition
- * @param target
- * path where to put the file
- *
- * @return true if it will fit on partition of target, false if it will not fit.
- */
- public boolean hasEnoughSpaceOnPartition(String target, long size) {
- try {
- // new File(target).getFreeSpace() (API 9) is not working on data partition
-
- // get directory without file
- String directory = new File(target).getParent().toString();
-
- StatFs stat = new StatFs(directory);
- long blockSize = stat.getBlockSize();
- long availableBlocks = stat.getAvailableBlocks();
- long availableSpace = availableBlocks * blockSize;
-
- Log.i(RootCommands.TAG, "Checking for enough space: Target: " + target
- + ", directory: " + directory + " size: " + size + ", availableSpace: "
- + availableSpace);
-
- if (size < availableSpace) {
- return true;
- } else {
- Log.e(RootCommands.TAG, "Not enough space on partition!");
- return false;
- }
- } catch (Exception e) {
- // if new StatFs(directory) fails catch IllegalArgumentException and just return true as
- // workaround
- Log.e(RootCommands.TAG, "Problem while getting available space on partition!", e);
- return true;
- }
- }
-
- /**
- * TODO: Not tested!
- *
- * @param toggle
- * @throws IOException
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public void toggleAdbDaemon(boolean toggle) throws BrokenBusyboxException, TimeoutException,
- IOException {
- 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.add(enableAdb).waitForFinish();
- } else {
- shell.add(disableAdb).waitForFinish();
- }
- }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java
deleted file mode 100644
index 33e0f196..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/Command.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks, Jeremy Lakeman (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.command;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.concurrent.TimeoutException;
-
-import org.sufficientlysecure.rootcommands.RootCommands;
-import org.sufficientlysecure.rootcommands.Shell;
-import org.sufficientlysecure.rootcommands.util.BrokenBusyboxException;
-import org.sufficientlysecure.rootcommands.util.Log;
-
-public abstract class Command {
- final String command[];
- boolean finished = false;
- boolean brokenBusyboxDetected = false;
- int exitCode;
- int id;
- int timeout = RootCommands.DEFAULT_TIMEOUT;
- Shell shell = null;
-
- public Command(String... command) {
- this.command = command;
- }
-
- public Command(int timeout, String... command) {
- this.command = command;
- this.timeout = timeout;
- }
-
- /**
- * This is called from Shell after adding it
- *
- * @param shell
- * @param id
- */
- public void addedToShell(Shell shell, int id) {
- this.shell = shell;
- this.id = id;
- }
-
- /**
- * Gets command string executed on the shell
- *
- * @return
- */
- public String getCommand() {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < command.length; i++) {
- // redirect stderr to stdout
- sb.append(command[i] + " 2>&1");
- sb.append('\n');
- }
- Log.d(RootCommands.TAG, "Sending command(s): " + sb.toString());
- return sb.toString();
- }
-
- public void writeCommand(OutputStream out) throws IOException {
- out.write(getCommand().getBytes());
- }
-
- public void processOutput(String line) {
- Log.d(RootCommands.TAG, "ID: " + id + ", Output: " + line);
-
- /*
- * Try to detect broken toolbox/busybox binaries (see
- * https://code.google.com/p/busybox-android/issues/detail?id=1)
- *
- * It is giving "Value too large for defined data type" on certain file operations (e.g. ls
- * and chown) in certain directories (e.g. /data/data)
- */
- if (line.contains("Value too large for defined data type")) {
- Log.e(RootCommands.TAG, "Busybox is broken with high probability due to line: " + line);
- brokenBusyboxDetected = true;
- }
-
- // now execute specific output parsing
- output(id, line);
- }
-
- public abstract void output(int id, String line);
-
- public void processAfterExecution(int exitCode) {
- Log.d(RootCommands.TAG, "ID: " + id + ", ExitCode: " + exitCode);
-
- afterExecution(id, exitCode);
- }
-
- public abstract void afterExecution(int id, int exitCode);
-
- public void commandFinished(int id) {
- Log.d(RootCommands.TAG, "Command " + id + " finished.");
- }
-
- public void setExitCode(int code) {
- synchronized (this) {
- exitCode = code;
- finished = true;
- commandFinished(id);
- this.notifyAll();
- }
- }
-
- /**
- * Close the shell
- *
- * @param reason
- */
- public void terminate(String reason) {
- try {
- shell.close();
- Log.d(RootCommands.TAG, "Terminating the shell.");
- terminated(reason);
- } catch (IOException e) {
- }
- }
-
- public void terminated(String reason) {
- setExitCode(-1);
- Log.d(RootCommands.TAG, "Command " + id + " did not finish, because of " + reason);
- }
-
- /**
- * Waits for this command to finish and forwards exitCode into afterExecution method
- *
- * @param timeout
- * @throws TimeoutException
- * @throws BrokenBusyboxException
- */
- public void waitForFinish() throws TimeoutException, BrokenBusyboxException {
- synchronized (this) {
- while (!finished) {
- try {
- this.wait(timeout);
- } catch (InterruptedException e) {
- Log.e(RootCommands.TAG, "InterruptedException in waitForFinish()", e);
- }
-
- if (!finished) {
- finished = true;
- terminate("Timeout");
- throw new TimeoutException("Timeout has occurred.");
- }
- }
-
- if (brokenBusyboxDetected) {
- throw new BrokenBusyboxException();
- }
-
- processAfterExecution(exitCode);
- }
- }
-
-}
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/ExecutableCommand.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/ExecutableCommand.java
deleted file mode 100644
index d6c8e610..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/ExecutableCommand.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.command;
-
-import java.io.File;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.os.Build;
-
-public abstract class ExecutableCommand extends Command {
- public static final String EXECUTABLE_PREFIX = "lib";
- public static final String EXECUTABLE_SUFFIX = "_exec.so";
-
- /**
- * This class provides a way to use your own binaries!
- *
- * Include your own executables, renamed from * to lib*_exec.so, in your libs folder under the
- * architecture directories. Now they will be deployed by Android the same way libraries are
- * deployed!
- *
- * See README for more information how to use your own executables!
- *
- * @param context
- * @param executableName
- * @param parameters
- */
- public ExecutableCommand(Context context, String executableName, String parameters) {
- super(getLibDirectory(context) + File.separator + EXECUTABLE_PREFIX + executableName
- + EXECUTABLE_SUFFIX + " " + parameters);
- }
-
- /**
- * Get full path to lib directory of app
- *
- * @return dir as String
- */
- @SuppressLint("NewApi")
- private static String getLibDirectory(Context context) {
- if (Build.VERSION.SDK_INT >= 9) {
- return context.getApplicationInfo().nativeLibraryDir;
- } else {
- return context.getApplicationInfo().dataDir + File.separator + "lib";
- }
- }
-
- public abstract void output(int id, String line);
-
- public abstract void afterExecution(int id, int exitCode);
-
-}
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleCommand.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleCommand.java
deleted file mode 100644
index 9049040f..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleCommand.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.command;
-
-public class SimpleCommand extends Command {
- private StringBuilder sb = new StringBuilder();
-
- public SimpleCommand(String... command) {
- super(command);
- }
-
- @Override
- public void output(int id, String line) {
- sb.append(line).append('\n');
- }
-
- @Override
- public void afterExecution(int id, int exitCode) {
- }
-
- public String getOutput() {
- return sb.toString();
- }
-
- public int getExitCode() {
- return exitCode;
- }
-
-}
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleExecutableCommand.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleExecutableCommand.java
deleted file mode 100644
index 95d2faef..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/command/SimpleExecutableCommand.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.command;
-
-import android.content.Context;
-
-public class SimpleExecutableCommand extends ExecutableCommand {
- private StringBuilder sb = new StringBuilder();
-
- public SimpleExecutableCommand(Context context, String executableName, String parameters) {
- super(context, executableName, parameters);
- }
-
- @Override
- public void output(int id, String line) {
- sb.append(line).append('\n');
- }
-
- @Override
- public void afterExecution(int id, int exitCode) {
- }
-
- public String getOutput() {
- return sb.toString();
- }
-
- public int getExitCode() {
- return exitCode;
- }
-
-}
\ No newline at end of file
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/BrokenBusyboxException.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/BrokenBusyboxException.java
deleted file mode 100644
index e982b242..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/BrokenBusyboxException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.util;
-
-import java.io.IOException;
-
-public class BrokenBusyboxException extends IOException {
- private static final long serialVersionUID = 8337358201589488409L;
-
- public BrokenBusyboxException() {
- super();
- }
-
- public BrokenBusyboxException(String detailMessage) {
- super(detailMessage);
- }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java
deleted file mode 100644
index a25fbf4c..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Log.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.util;
-
-import org.sufficientlysecure.rootcommands.RootCommands;
-
-/**
- * Wraps Android Logging to enable or disable debug output using Constants
- *
- */
-public final class Log {
-
- public static void v(String tag, String msg) {
- if (RootCommands.DEBUG) {
- android.util.Log.v(tag, msg);
- }
- }
-
- public static void v(String tag, String msg, Throwable tr) {
- if (RootCommands.DEBUG) {
- android.util.Log.v(tag, msg, tr);
- }
- }
-
- public static void d(String tag, String msg) {
- if (RootCommands.DEBUG) {
- android.util.Log.d(tag, msg);
- }
- }
-
- public static void d(String tag, String msg, Throwable tr) {
- if (RootCommands.DEBUG) {
- android.util.Log.d(tag, msg, tr);
- }
- }
-
- public static void i(String tag, String msg) {
- if (RootCommands.DEBUG) {
- android.util.Log.i(tag, msg);
- }
- }
-
- public static void i(String tag, String msg, Throwable tr) {
- if (RootCommands.DEBUG) {
- android.util.Log.i(tag, msg, tr);
- }
- }
-
- public static void w(String tag, String msg) {
- android.util.Log.w(tag, msg);
- }
-
- public static void w(String tag, String msg, Throwable tr) {
- android.util.Log.w(tag, msg, tr);
- }
-
- public static void w(String tag, Throwable tr) {
- android.util.Log.w(tag, tr);
- }
-
- public static void e(String tag, String msg) {
- android.util.Log.e(tag, msg);
- }
-
- public static void e(String tag, String msg, Throwable tr) {
- android.util.Log.e(tag, msg, tr);
- }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/RootAccessDeniedException.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/RootAccessDeniedException.java
deleted file mode 100644
index 35f353d1..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/RootAccessDeniedException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.util;
-
-import java.io.IOException;
-
-public class RootAccessDeniedException extends IOException {
- private static final long serialVersionUID = 9088998884166225540L;
-
- public RootAccessDeniedException() {
- super();
- }
-
- public RootAccessDeniedException(String detailMessage) {
- super(detailMessage);
- }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/UnsupportedArchitectureException.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/UnsupportedArchitectureException.java
deleted file mode 100644
index 96ad0309..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/UnsupportedArchitectureException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.util;
-
-public class UnsupportedArchitectureException extends Exception {
- private static final long serialVersionUID = 7826528799780001655L;
-
- public UnsupportedArchitectureException() {
- super();
- }
-
- public UnsupportedArchitectureException(String detailMessage) {
- super(detailMessage);
- }
-
-}
diff --git a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java b/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java
deleted file mode 100644
index 87f32bbc..00000000
--- a/RootCommands/src/main/java/org/sufficientlysecure/rootcommands/util/Utils.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik(a)dominikschuermann.de>
- * Copyright (c) 2012 Michael Elsdörfer (Android Autostarts)
- * Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Adam Shanks (RootTools)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.sufficientlysecure.rootcommands.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.sufficientlysecure.rootcommands.RootCommands;
-
-public class Utils {
- /*
- * The emulator and ADP1 device both have a su binary in /system/xbin/su, but it doesn't allow
- * apps to use it (su app_29 $ su su: uid 10029 not allowed to su).
- *
- * Cyanogen used to have su in /system/bin/su, in newer versions it's a symlink to
- * /system/xbin/su.
- *
- * The Archos tablet has it in /data/bin/su, since they don't have write access to /system yet.
- */
- static final String[] BinaryPlaces = { "/data/bin/", "/system/bin/", "/system/xbin/", "/sbin/",
- "/data/local/xbin/", "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/",
- "/data/local/" };
-
- /**
- * Determine the path of the su executable.
- *
- * Code from https://github.com/miracle2k/android-autostarts, use under Apache License was
- * agreed by Michael Elsdörfer
- */
- public static String getSuPath() {
- for (String p : BinaryPlaces) {
- File su = new File(p + "su");
- if (su.exists()) {
- Log.d(RootCommands.TAG, "su found at: " + p);
- return su.getAbsolutePath();
- } else {
- Log.v(RootCommands.TAG, "No su in: " + p);
- }
- }
- Log.d(RootCommands.TAG, "No su found in a well-known location, " + "will just use \"su\".");
- return "su";
- }
-
- /**
- * This code is adapted from java.lang.ProcessBuilder.start().
- *
- * The problem is that Android doesn't allow us to modify the map returned by
- * ProcessBuilder.environment(), even though the docstring indicates that it should. This is
- * because it simply returns the SystemEnvironment object that System.getenv() gives us. The
- * relevant portion in the source code is marked as "// android changed", so presumably it's not
- * the case in the original version of the Apache Harmony project.
- *
- * Note that simply passing the environment variables we want to Process.exec won't be good
- * enough, since that would override the environment we inherited completely.
- *
- * We needed to be able to set a CLASSPATH environment variable for our new process in order to
- * use the "app_process" command directly. Note: "app_process" takes arguments passed on to the
- * Dalvik VM as well; this might be an alternative way to set the class path.
- *
- * Code from https://github.com/miracle2k/android-autostarts, use under Apache License was
- * agreed by Michael Elsdörfer
- */
- public static Process runWithEnv(String command, ArrayList<String> customAddedEnv,
- String baseDirectory) throws IOException {
-
- Map<String, String> environment = System.getenv();
- String[] envArray = new String[environment.size()
- + (customAddedEnv != null ? customAddedEnv.size() : 0)];
- int i = 0;
- for (Map.Entry<String, String> entry : environment.entrySet()) {
- envArray[i++] = entry.getKey() + "=" + entry.getValue();
- }
- if (customAddedEnv != null) {
- for (String entry : customAddedEnv) {
- envArray[i++] = entry;
- }
- }
-
- Process process;
- if (baseDirectory == null) {
- process = Runtime.getRuntime().exec(command, envArray, null);
- } else {
- process = Runtime.getRuntime().exec(command, envArray, new File(baseDirectory));
- }
- return process;
- }
-}
1
0
commit 6ca89b30ba892998b063a871e0c0ec13da55a460
Author: n8fr8 <nathan(a)freitas.net>
Date: Sat Oct 14 12:18:01 2017 -0400
remove old manifest
---
AndroidManifest.xml | 133 ----------------------------------------------------
1 file changed, 133 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
deleted file mode 100644
index fd25aca4..00000000
--- a/AndroidManifest.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.torproject.android"
- android:versionName="15.2.0-alpha-1"
- android:versionCode="15200001"
- android:installLocation="auto"
- >
- <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
- <!--
- <permission android:name="org.torproject.android.MANAGE_TOR"
- android:label="@string/permission_manage_tor_label"
- android:description="@string/permission_manage_tor_description"
- android:protectionLevel="signature"/>
-
- <uses-permission android:name="org.torproject.android.MANAGE_TOR"/>
- -->
-
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
-
- <application android:name="org.torproject.android.OrbotApp" android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:description="@string/app_description"
- android:configChanges="locale|orientation|screenSize"
- android:theme="@style/DefaultTheme"
- android:allowBackup="false"
- android:allowClearUserData="true"
- android:persistent="true"
- android:stopWithTask="false"
- android:largeHeap="false"
- >
-
- <activity android:name=".OrbotMainActivity"
- android:configChanges="orientation|screenSize"
- android:excludeFromRecents="true"
- android:launchMode="singleTop"
- >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
-
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.BROWSABLE" />
- <data android:scheme="bridge" />
- </intent-filter>
-
- <intent-filter>
- <category android:name="android.intent.category.DEFAULT" />
- <action android:name="org.torproject.android.REQUEST_HS_PORT" />
- </intent-filter>
- <intent-filter>
- <category android:name="android.intent.category.DEFAULT" />
- <action android:name="org.torproject.android.START_TOR" />
- </intent-filter>
-
- </activity>
-
- <!--
- This is for ensuring the background service still runs when/if the app is swiped away
- -->
- <activity
- android:name=".service.DummyActivity"
- android:theme="@android:style/Theme.Translucent"
- android:enabled="true"
- android:allowTaskReparenting="true"
- android:noHistory="true"
- android:excludeFromRecents="true"
- android:alwaysRetainTaskState="false"
- android:stateNotNeeded="true"
- android:clearTaskOnLaunch="true"
- android:finishOnTaskLaunch="true"
-
- />
-
- <activity
- android:name=".vpn.VPNEnableActivity" android:label="@string/app_name" android:exported="false"
- android:theme="@android:style/Theme.Translucent"
- />
-
-
- <activity android:name="org.torproject.android.ui.PromoAppsActivity" android:exported="false"/>
-
-
- <activity android:name=".settings.SettingsPreferences" android:label="@string/app_name"/>
- <activity android:name=".settings.AppManager" android:label="@string/app_name"/>
-
- <service
- android:name=".service.TorService"
- android:enabled="true"
- android:permission="android.permission.BIND_VPN_SERVICE"
- android:stopWithTask="false" >
- </service>
-
- <receiver
- android:name=".service.StartTorReceiver"
- android:exported="true">
- <intent-filter>
- <action android:name="org.torproject.android.intent.action.START" />
- </intent-filter>
- </receiver>
-
- <receiver android:name="org.torproject.android.OnBootReceiver"
- android:enabled="true" android:exported="true"
-
- >
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- <category android:name="android.intent.category.HOME" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.QUICKBOOT_POWERON" />
- <category android:name="android.intent.category.HOME" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MEDIA_MOUNTED"/>
- <category android:name="android.intent.category.HOME" />
- </intent-filter>
- </receiver>
-
- <!--
- <service android:name="org.torproject.android.vpn.OrbotVpnService"
- android:permission="android.permission.BIND_VPN_SERVICE">
- <intent-filter>
- <action android:name="android.net.VpnService"/>
- </intent-filter>
- </service>
- -->
-</application>
-</manifest>
1
0
commit c4867ba8d296c29a1c665e5e3929711ba76b6895
Author: n8fr8 <nathan(a)freitas.net>
Date: Sat Oct 14 12:18:15 2017 -0400
update Makefile to target NDK 4.9
---
external/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/external/Makefile b/external/Makefile
index 5090e941..86e20d6b 100644
--- a/external/Makefile
+++ b/external/Makefile
@@ -24,7 +24,7 @@ endif
# Android NDK setup
ANDROID_NDK_HOME ?= /opt/android-ndk
NDK_PLATFORM_LEVEL ?= 16
-NDK_TOOLCHAIN_VERSION=4.8
+NDK_TOOLCHAIN_VERSION=4.9
APP_ABI ?= armeabi
NDK_ABI ?= $(APP_ABI)
@@ -63,7 +63,7 @@ NDK_TOOLCHAIN_BASE=$(ANDROID_NDK_HOME)/toolchains/$(NDK_TOOLCHAIN)/prebuilt/$(ND
# include Android's build flags
TARGET_ARCH_ABI = $(APP_ABI)
-include $(ANDROID_NDK_HOME)/toolchains/$(NDK_TOOLCHAIN)/setup.mk
+#include $(ANDROID_NDK_HOME)/toolchains/$(NDK_TOOLCHAIN)/setup.mk
CC := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-gcc --sysroot=$(NDK_SYSROOT)
CXX := $(NDK_TOOLCHAIN_BASE)/bin/$(HOST)-g++ --sysroot=$(NDK_SYSROOT)
1
0
commit 01176b1d38b0f32c5efba1f5841b255c407cc4f6
Author: n8fr8 <nathan(a)freitas.net>
Date: Sat Oct 14 12:19:17 2017 -0400
big refactor for multiple reasons
- implement LICENSE display in About dialog
- remove root transproxy features
- general crufty stuff cleanup
---
.../org/torproject/android/OrbotMainActivity.java | 67 +-
.../android/settings/SettingsPreferences.java | 70 --
.../java/org/torproject/android/ui/AppManager.java | 4 +-
app/src/main/res/layout/layout_about.xml | 39 +-
app/src/main/res/values/strings.xml | 2 +-
build.gradle | 2 +-
orbotservice/build.gradle | 2 +-
.../org/torproject/android/service/TorService.java | 216 +----
.../android/service/transproxy/TorTransProxy.java | 997 ---------------------
.../android/service/vpn/OrbotVpnManager.java | 2 -
.../service/{transproxy => vpn}/TorifiedApp.java | 2 +-
orbotservice/src/main/res/values/strings.xml | 10 +-
settings.gradle | 2 +-
13 files changed, 69 insertions(+), 1346 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 0e9e2f72..013c9b43 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -5,6 +5,7 @@ package org.torproject.android;
import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@@ -64,6 +65,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
+import android.text.Html;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
@@ -534,7 +536,16 @@ public class OrbotMainActivity extends AppCompatActivity
}
TextView versionName = (TextView)view.findViewById(R.id.versionName);
- versionName.setText(version);
+ versionName.setText(version);
+
+ TextView aboutOther = (TextView)view.findViewById(R.id.aboutother);
+
+ try
+ {
+ String aboutText = readFromAssets(this,"LICENSE");
+ aboutOther.setText(Html.fromHtml(aboutText));
+ }
+ catch (Exception e){}
new AlertDialog.Builder(this)
.setTitle(getString(R.string.button_about))
@@ -542,6 +553,20 @@ public class OrbotMainActivity extends AppCompatActivity
.show();
}
+ public static String readFromAssets(Context context, String filename) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(filename)));
+
+ // do reading, usually loop until end of file reading
+ StringBuilder sb = new StringBuilder();
+ String mLine = reader.readLine();
+ while (mLine != null) {
+ sb.append(mLine); // process line
+ mLine = reader.readLine();
+ }
+ reader.close();
+ return sb.toString();
+ }
+
/**
* This is our attempt to REALLY exit Orbot, and stop the background service
@@ -724,8 +749,6 @@ public class OrbotMainActivity extends AppCompatActivity
String action = intent.getAction();
Log.d(TAG, "handleIntents " + action);
- //String type = intent.getType();
-
if (action == null)
return;
@@ -944,31 +967,7 @@ public class OrbotMainActivity extends AppCompatActivity
if (request == REQUEST_SETTINGS && response == RESULT_OK)
{
OrbotApp.forceChangeLanguage(this);
- if (data != null && data.getBooleanExtra("transproxywipe", false))
- {
-
- boolean result = flushTransProxy();
-
- if (result)
- {
-
- Toast.makeText(this, R.string.transparent_proxy_rules_flushed_, Toast.LENGTH_SHORT).show();
-
- }
- else
- {
-
- Toast.makeText(this, R.string.you_do_not_have_root_access_enabled, Toast.LENGTH_SHORT).show();
-
- }
-
- }
- else if (torStatus == TorServiceConstants.STATUS_ON)
- {
- updateTransProxy();
- // Toast.makeText(this, R.string.you_may_need_to_stop_and_start_orbot_for_settings_change_to_be_enabled_, Toast.LENGTH_SHORT).show();
- }
}
else if (request == REQUEST_VPN)
{
@@ -1184,19 +1183,7 @@ public class OrbotMainActivity extends AppCompatActivity
sendIntentToService(TorServiceConstants.CMD_VPN_CLEAR);
}
- private boolean flushTransProxy ()
- {
- sendIntentToService(TorServiceConstants.CMD_FLUSH);
- return true;
- }
-
- private boolean updateTransProxy ()
- {
- sendIntentToService(TorServiceConstants.CMD_UPDATE_TRANS_PROXY);
- return true;
- }
-
- @Override
+ @Override
protected void onResume() {
super.onResume();
diff --git a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
index adacba72..9078b100 100644
--- a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
+++ b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
@@ -9,7 +9,6 @@ import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
-import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
@@ -19,7 +18,6 @@ import android.util.Log;
import org.torproject.android.OrbotApp;
import org.torproject.android.R;
-import org.torproject.android.service.transproxy.TorTransProxy;
import org.torproject.android.ui.AppManager;
import org.torproject.android.service.util.TorServiceUtils;
@@ -30,14 +28,7 @@ public class SettingsPreferences
extends PreferenceActivity implements OnPreferenceClickListener {
private static final String TAG = "SettingsPreferences";
- private CheckBoxPreference prefCBTransProxy = null;
- private CheckBoxPreference prefcBTransProxyAll = null;
- private CheckBoxPreference prefcbTransTethering = null;
-
- private Preference prefTransProxyFlush = null;
-
private Preference prefTransProxyApps = null;
- private CheckBoxPreference prefRequestRoot = null;
private ListPreference prefLocale = null;
protected void onCreate(Bundle savedInstanceState) {
@@ -47,9 +38,6 @@ public class SettingsPreferences
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- prefRequestRoot = (CheckBoxPreference) findPreference("has_root");
- prefRequestRoot.setOnPreferenceClickListener(this);
-
prefLocale = (ListPreference) findPreference("pref_default_locale");
prefLocale.setOnPreferenceClickListener(this);
Languages languages = Languages.get(this);
@@ -76,38 +64,9 @@ public class SettingsPreferences
}
});
- prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent");
- prefcBTransProxyAll = (CheckBoxPreference) findPreference("pref_transparent_all");
- prefcbTransTethering = (CheckBoxPreference) findPreference("pref_transparent_tethering");
-
- prefTransProxyFlush = (Preference) findPreference("pref_transproxy_flush");
- prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference arg0) {
-
- Intent data = new Intent();
- data.putExtra("transproxywipe", true);
- setResult(RESULT_OK, data);
-
- finish();
- return false;
- }
-
- });
-
prefTransProxyApps = findPreference("pref_transparent_app_list");
prefTransProxyApps.setOnPreferenceClickListener(this);
- prefCBTransProxy.setOnPreferenceClickListener(this);
- prefcBTransProxyAll.setOnPreferenceClickListener(this);
-
- prefCBTransProxy.setEnabled(prefRequestRoot.isChecked());
- prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
- prefcbTransTethering.setEnabled(prefCBTransProxy.isChecked());
-
- if (prefCBTransProxy.isChecked())
- prefTransProxyApps.setEnabled((!prefcBTransProxyAll.isChecked()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
@@ -120,37 +79,8 @@ public class SettingsPreferences
public boolean onPreferenceClick(Preference preference) {
setResult(RESULT_OK);
-
- if (preference == prefRequestRoot)
- {
- if (prefRequestRoot.isChecked())
- {
- try {
- TorTransProxy.testRoot();
- prefCBTransProxy.setEnabled(true);
- }
- catch (Exception e)
- {
- Log.d(OrbotApp.TAG,"root not yet enabled");
- }
-
- }
- }
- else if (preference == prefTransProxyApps)
- {
- startActivity(new Intent(this, AppManager.class));
-
- }
- else
- {
- prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
- prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
-
-
- }
-
return true;
}
diff --git a/app/src/main/java/org/torproject/android/ui/AppManager.java b/app/src/main/java/org/torproject/android/ui/AppManager.java
index d59eeac2..803061d3 100644
--- a/app/src/main/java/org/torproject/android/ui/AppManager.java
+++ b/app/src/main/java/org/torproject/android/ui/AppManager.java
@@ -13,9 +13,8 @@ import java.util.StringTokenizer;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.R;
import org.torproject.android.service.util.TorServiceUtils;
-import org.torproject.android.service.transproxy.TorifiedApp;
+import org.torproject.android.service.vpn.TorifiedApp;
-import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
@@ -23,7 +22,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
-import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
diff --git a/app/src/main/res/layout/layout_about.xml b/app/src/main/res/layout/layout_about.xml
index 82f30790..4ac8a431 100644
--- a/app/src/main/res/layout/layout_about.xml
+++ b/app/src/main/res/layout/layout_about.xml
@@ -54,25 +54,6 @@
android:textColorLink="#ffffff"
android:paddingLeft="15px"
android:textColor="#ffffff" />
- <TextView android:text="License: "
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingTop="15px"
- android:paddingLeft="15px"
- android:textStyle="bold"
- android:textColor="#00ff00" />
- <TextView android:text="@string/the_tor_license"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingLeft="15px"
- android:textColor="#ffffff" />
- <TextView android:text="@string/https_torproject_org"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:autoLink="web"
- android:textColorLink="#ffffff"
- android:paddingLeft="15px"
- android:textColor="#ffffff" />
<TextView android:text="@string/third_party_software"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@@ -114,7 +95,23 @@
android:autoLink="web"
android:textColorLink="#ffffff"
android:paddingLeft="15px"
- android:textColor="#ffffff" />
- </LinearLayout>
+ android:textColor="#ffffff" />
+
+ <TextView android:text="License: "
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="15px"
+ android:paddingLeft="15px"
+ android:textStyle="bold"
+ android:textColor="#00ff00" />
+ <TextView
+ android:id="@+id/aboutother"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:autoLink="web"
+ android:textColorLink="#ffffff"
+ android:paddingLeft="15px"
+ android:textColor="#ffffff" />
+ </LinearLayout>
</ScrollView>
</LinearLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 41b9e816..89d72a60 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -61,7 +61,7 @@
<string name="btn_cancel">Cancel</string>
<!--Welcome Wizard strings (DJH)-->
<string name="wizard_details">Some Orbot Details</string>
- <string name="wizard_details_msg">Orbot is an open-source application that contains Tor, LibEvent and Polipo. It provides a local HTTP proxy (8118) and a SOCKS proxy (9050) into the Tor network. Orbot also has the ability, on rooted device, to send all internet traffic through Tor.</string>
+ <string name="wizard_details_msg">Orbot is an open-source application that contains Tor, Obfs4Proxy, BadVPN Tun2Socks, LibEvent and Polipo. It provides a local HTTP proxy (8118) and a SOCKS proxy (9050) into the Tor network. Orbot also has the ability, on rooted device, to send all internet traffic through Tor.</string>
<string name="wizard_permissions_root">Permission Granted</string>
<string name="wizard_permissions_stock">Orbot Permissions</string>
<string name="wizard_premissions_msg_root">Excellent! We\'ve detected that you have root permissions enabled for Orbot. We will use this power wisely.</string>
diff --git a/build.gradle b/build.gradle
index f6627fcf..8674409c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.2'
+ classpath 'com.android.tools.build:gradle:2.3.3'
}
}
diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle
index e46037f5..12407532 100644
--- a/orbotservice/build.gradle
+++ b/orbotservice/build.gradle
@@ -28,8 +28,8 @@ android {
dependencies {
compile project(':jsocksAndroid')
- compile project(':RootCommands')
compile 'com.android.support:appcompat-v7:25.0.0'
+ compile 'com.jrummyapps:android-shell:1.0.1'
compile fileTree(dir: 'libs', include: ['*.jar','*.so'])
testCompile 'junit:junit:4.12'
}
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
index 17000a9d..597e59e2 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -38,12 +38,12 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
-import org.sufficientlysecure.rootcommands.Shell;
-import org.sufficientlysecure.rootcommands.command.SimpleCommand;
+import com.jrummyapps.android.shell.CommandResult;
+import com.jrummyapps.android.shell.Shell;
+
import org.torproject.android.control.ConfigEntry;
import org.torproject.android.control.TorControlConnection;
-import org.torproject.android.service.transproxy.TorTransProxy;
-import org.torproject.android.service.transproxy.TorifiedApp;
+import org.torproject.android.service.vpn.TorifiedApp;
import org.torproject.android.service.util.DummyActivity;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorResourceInstaller;
@@ -104,8 +104,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private boolean isTorUpgradeAndConfigComplete = false;
private File fileControlPort;
-
- private TorTransProxy mTransProxy;
private boolean mConnectivity = true;
private int mNetworkType = -1;
@@ -127,17 +125,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public static File fileTor;
public static File filePolipo;
public static File fileObfsclient;
- public static File fileXtables;
public static File fileTorRc;
private File mHSBasePath;
- private Shell mShell;
- private Shell mShellPolipo;
-
-
private ArrayList<Bridge> alBridges = null;
-
private static final Uri HS_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers/hs");
private static final Uri COOKIE_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers.cookie/cookie");
@@ -410,10 +402,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
requestTorRereadConfig();
} else if (action.equals(CMD_NEWNYM)) {
newIdentity();
- } else if (action.equals(CMD_FLUSH)) {
- flushTransparentProxyRules();
- } else if (action.equals(CMD_UPDATE_TRANS_PROXY)) {
- processTransparentProxying();
} else if (action.equals(CMD_VPN)) {
startVPNService();
} else if (action.equals(CMD_VPN_CLEAR)) {
@@ -442,6 +430,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
stopTor();
+ /**
try
{
mShell.close();
@@ -449,7 +438,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
catch (IOException ioe)
{
Log.d(TAG, "Error closing shell",ioe);
- }
+ }**/
super.onDestroy();
}
@@ -477,11 +466,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
//stop the foreground priority and make sure to remove the persistant notification
stopForeground(true);
- if (Prefs.useRoot() && Prefs.useTransparentProxying())
- {
- disableTransparentProxy();
- }
-
sendCallbackLogMessage(getString(R.string.status_disabled));
}
catch (Exception e)
@@ -516,12 +500,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
conn = null;
}
+ /**
if (mShellPolipo != null)
{
mShellPolipo.close();
//logNotice("Polipo exited with value: " + exitValue);
- }
+ }**/
}
@@ -560,12 +545,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
appBinHome = getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE);
appCacheHome = getDir(TorServiceConstants.DIRECTORY_TOR_DATA,Application.MODE_PRIVATE);
- mShell = Shell.startShell();
+ //mShell = Shell.startShell();
fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY);
filePolipo = new File(appBinHome, TorServiceConstants.POLIPO_ASSET_KEY);
fileObfsclient = new File(appBinHome, TorServiceConstants.OBFSCLIENT_ASSET_KEY);
- fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY);
fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY);
mHSBasePath = new File(
@@ -802,12 +786,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (mPortHTTP != -1)
runPolipoShellCmd();
- if (Prefs.useRoot() && Prefs.useTransparentProxying())
- {
- disableTransparentProxy();
- enableTransparentProxy();
- }
-
// Tor is running, update new .onion names at db
ContentResolver mCR = getApplicationContext().getContentResolver();
Cursor hidden_services = mCR.query(HS_CONTENT_URI, hsProjection, null, null, null);
@@ -868,126 +846,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
}
- private boolean flushTransparentProxyRules () {
-
- try {
- if (Prefs.useRoot()) {
- if (mTransProxy == null)
- mTransProxy = new TorTransProxy(this, fileXtables);
-
- try {
- mTransProxy.flushTransproxyRules(this);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
-
- return true;
- } else {
- return false;
- }
- }
- catch (IOException ioe)
- {
- return false;
- }
- }
-
- /*
- * activate means whether to apply the users preferences
- * or clear them out
- *
- * the idea is that if Tor is off then transproxy is off
- */
- private boolean enableTransparentProxy () throws Exception
- {
-
- if (mTransProxy == null)
- {
- mTransProxy = new TorTransProxy(this, fileXtables);
-
- }
-
- SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- String transProxy = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
- String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
-
- if (transProxy.indexOf(':')!=-1) //we just want the port for this
- transProxy = transProxy.split(":")[1];
-
- if (dnsPort.indexOf(':')!=-1) //we just want the port for this
- dnsPort = dnsPort.split(":")[1];
-
- mTransProxy.setTransProxyPort(Integer.parseInt(transProxy));
- mTransProxy.setDNSPort(Integer.parseInt(dnsPort));
-
- int code = 0; // Default state is "okay"
-
- if(Prefs.transparentProxyAll())
- {
- code = mTransProxy.setTransparentProxyingAll(this, true);
- }
- else
- {
- ArrayList<TorifiedApp> apps = TorTransProxy.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext()));
-
- code = mTransProxy.setTransparentProxyingByApp(this,apps, true);
- }
-
- debug ("TorTransProxy resp code: " + code);
-
- if (code == 0)
- {
- if (Prefs.transparentTethering())
- {
- showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
-
- mTransProxy.enableTetheringRules(this);
-
-
- }
- else
- {
- showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
-
- }
- }
- else
- {
- showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
-
- }
-
- return true;
- }
-
- /*
- * activate means whether to apply the users preferences
- * or clear them out
- *
- * the idea is that if Tor is off then transproxy is off
- */
- private boolean disableTransparentProxy () throws Exception
- {
-
- debug ("Transparent Proxying: disabling...");
-
- if (mTransProxy == null)
- mTransProxy = new TorTransProxy(this, fileXtables);
-
- mTransProxy.setTransparentProxyingAll(this, false);
-
- ArrayList<TorifiedApp> apps = TorTransProxy.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext()));
- mTransProxy.setTransparentProxyingByApp(this, apps, false);
-
- mTransProxy.closeShell();
- mTransProxy = null;
-
- return true;
- }
-
private boolean runTorShellCmd() throws Exception
{
boolean result = true;
@@ -1055,13 +915,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private int exec (String cmd, boolean wait) throws Exception
{
+ CommandResult shellResult = Shell.run(cmd);
+ shellResult.isSuccessful();
+ debug("CMD: " + cmd + "; SUCCESS=" + shellResult.isSuccessful());
+
+ /**
SimpleCommand command = new SimpleCommand(cmd);
mShell.add(command);
-
if (wait)
command.waitForFinish();
-
return command.getExitCode();
+ **/
+ return shellResult.exitCode;
}
private void updatePolipoConfig () throws FileNotFoundException, IOException
@@ -1092,12 +957,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
String polipoConfigPath = new File(appBinHome, POLIPOCONFIG_ASSET_KEY).getCanonicalPath();
String cmd = (filePolipo.getCanonicalPath() + " -c " + polipoConfigPath);
- if (mShellPolipo != null)
- mShellPolipo.close();
-
- mShellPolipo = Shell.startShell();
- SimpleCommand cmdPolipo = new SimpleCommand(cmd);
- mShellPolipo.add(cmdPolipo);
+ CommandResult shellResult = Shell.run(cmd);
sendCallbackLogMessage(getString(R.string.privoxy_is_running_on_port_) + mPortHTTP);
@@ -1277,28 +1137,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
-
-
-
-
-
- public void processTransparentProxying() {
- try{
- if (Prefs.useRoot())
- {
- if (Prefs.useTransparentProxying()){
- enableTransparentProxy();
- } else {
- disableTransparentProxy();
- }
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
public String getInfo (String key) {
try {
if(conn !=null){
@@ -1587,25 +1425,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor);
}
- try {
-
- if (mConnectivity)
- {
- if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh())
- {
-
-
- disableTransparentProxy();
- enableTransparentProxy();
-
- }
- }
-
- } catch (Exception e) {
- logException ("error updating state after network restart",e);
- }
-
-
}
@@ -2045,7 +1864,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
{
debug ("clearing VPN Proxy");
Prefs.putUseVpn(false);
- processTransparentProxying();
Intent intentVpn = new Intent(this,TorVpnService.class);
intentVpn.setAction("stop");
diff --git a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java b/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java
deleted file mode 100644
index 8d37bd9b..00000000
--- a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorTransProxy.java
+++ /dev/null
@@ -1,997 +0,0 @@
-package org.torproject.android.service.transproxy;
-
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-
-import org.sufficientlysecure.rootcommands.Shell;
-import org.sufficientlysecure.rootcommands.command.SimpleCommand;
-import org.torproject.android.service.OrbotConstants;
-import org.torproject.android.service.util.Prefs;
-import org.torproject.android.service.TorService;
-import org.torproject.android.service.TorServiceConstants;
-
-public class TorTransProxy implements TorServiceConstants {
-
- private String mSysIptables = null;
- private TorService mTorService = null;
- private File mFileXtables = null;
-
- private final static String ALLOW_LOCAL = " ! -d 127.0.0.1";
-
- private int mTransProxyPort = TOR_TRANSPROXY_PORT_DEFAULT;
- private int mDNSPort = TOR_DNS_PORT_DEFAULT;
-
- private Shell mShell;
-
- public TorTransProxy (TorService torService, File fileXTables) throws IOException
- {
- mTorService = torService;
- mFileXtables = fileXTables;
-
- // start root shell
- mShell = Shell.startRootShell();
-
- }
-
- public static boolean testRoot () throws IOException
- {
- Runtime.getRuntime().exec("su");
- return true;
- }
-
- public void setTransProxyPort (int transProxyPort)
- {
- mTransProxyPort = transProxyPort;
- }
-
- public void setDNSPort (int dnsPort)
- {
- mDNSPort = dnsPort;
- }
-
- public String getIpTablesPath (Context context)
- {
-
- String ipTablesPath = null;
-
- if (Prefs.useSystemIpTables())
- {
- ipTablesPath = findSystemIPTables();
- }
- else
- {
- ipTablesPath = mFileXtables.getAbsolutePath();
- ipTablesPath += " iptables"; //append subcommand since we are using xtables now
-
- }
-
- return ipTablesPath;
- }
-
- public String getIp6TablesPath (Context context)
- {
-
- String ipTablesPath = null;
-
- if (Prefs.useSystemIpTables())
- {
- ipTablesPath = findSystemIP6Tables();
- }
- else
- {
- ipTablesPath = mFileXtables.getAbsolutePath();
- ipTablesPath += " ip6tables"; //append subcommand since we are using xtables now
-
- }
-
- return ipTablesPath;
-
- }
-
- private String findSystemIPTables ()
- {
- if (mSysIptables == null) {
- //if the user wants us to use the built-in iptables, then we have to find it
- File fileIpt = new File("/system/xbin/iptables");
-
- if (fileIpt.exists())
- mSysIptables = fileIpt.getAbsolutePath();
- else {
-
- fileIpt = new File("/system/bin/iptables");
-
- if (fileIpt.exists())
- mSysIptables = fileIpt.getAbsolutePath();
- }
- }
-
- return mSysIptables;
- }
-
-
-
- private String findSystemIP6Tables ()
- {
-
- //if the user wants us to use the built-in iptables, then we have to find it
- File fileIpt = new File("/system/xbin/ip6tables");
-
- if (fileIpt.exists())
- mSysIptables = fileIpt.getAbsolutePath();
- else
- {
-
- fileIpt = new File("/system/bin/ip6tables");
-
- if (fileIpt.exists())
- mSysIptables = fileIpt.getAbsolutePath();
- }
-
-
- return mSysIptables;
- }
-
- /*
- public int flushIptablesAll(Context context) throws Exception {
-
- String ipTablesPath = getIpTablesPath(context);
-
- final StringBuilder script = new StringBuilder();
-
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(" -F || exit\n");
-
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(" -F || exit\n");
-
- String[] cmd = {script.toString()};
- code = TorServiceUtils.doShellCommand(cmd, res, true, true);
- String msg = res.toString();
-
- TorService.logMessage(cmd[0] + ";errCode=" + code + ";resp=" + msg);
-
-
- return code;
-
- }*/
-
- /*
- public static int purgeIptablesByApp(Context context, TorifiedApp[] apps) throws Exception {
-
- //restoreDNSResolvConf(); //not working yet
-
- String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
-
- final StringBuilder script = new StringBuilder();
-
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- for (int i = 0; i < apps.length; i++)
- {
- //flush nat for every app
- script.append(ipTablesPath);
- script.append(" -t nat -m owner --uid-owner ");
- script.append(tApp.getUid());
- script.append(" -F || exit\n");
- public static ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs)
- {
-
- String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, "");
- String[] tordApps;
-
- StringTokenizer st = new StringTokenizer(tordAppString,"|");
- tordApps = new String[st.countTokens()];
- int tordIdx = 0;
- while (st.hasMoreTokens())
- {
- tordApps[tordIdx++] = st.nextToken();
- }
-
- Arrays.sort(tordApps);
-
- //else load the apps up
- PackageManager pMgr = context.getPackageManager();
-
- List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);
-
- Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
-
- ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>();
-
- ApplicationInfo aInfo = null;
-
- int appIdx = 0;
- TorifiedApp app = null;
-
- while (itAppInfo.hasNext())
- {
- aInfo = itAppInfo.next();
-
- app = new TorifiedApp();
-
- try {
- PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
-
- if (pInfo != null && pInfo.requestedPermissions != null)
- {
- for (String permInfo:pInfo.requestedPermissions)
- {
- if (permInfo.equals("android.permission.INTERNET"))
- {
- app.setUsesInternet(true);
-
- }
- }
-
- }
-
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
- {
- //System app
- app.setUsesInternet(true);
- }
-
-
- if (!app.usesInternet())
- continue;
- else
- {
- apps.add(app);
- }
-
-
- app.setEnabled(aInfo.enabled);
- app.setUid(aInfo.uid);
- app.setUsername(pMgr.getNameForUid(app.getUid()));
- app.setProcname(aInfo.processName);
- app.setPackageName(aInfo.packageName);
-
- try
- {
- app.setName(pMgr.getApplicationLabel(aInfo).toString());
- }
- catch (Exception e)
- {
- app.setName(aInfo.packageName);
- }
-
-
- //app.setIcon(pMgr.getApplicationIcon(aInfo));
-
- // check if this application is allowed
- if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
- app.setTorified(true);
- }
- else
- {
- app.setTorified(false);
- }
-
- appIdx++;
- }
-
- Collections.sort(apps);
-
- return apps;
- }
-
-
- script.append(ipTablesPath);
- script.append(" -t filter -m owner --uid-owner ");
- script.append(tApp.getUid());
- script.append(" -F || exit\n");
-
- }
-
-
- String[] cmd = {script.toString()};
- code = TorServiceUtils.doShellCommand(cmd, res, true, true);
- String msg = res.toString();
- logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
-
-
- return code;
-
- }*/
-
-
- /*
- // 9/19/2010 - NF This code is in process... /etc path on System partition
- // is read-only on Android for now.
- public static int redirectDNSResolvConf () throws Exception
- {
- StringBuilder script = new StringBuilder();
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- //mv resolv.conf to resolve.conf.bak
- String cmd = "mv /etc/resolv.conf /etc/resolv.conf.bak";
- script.append(cmd);
-
- //create new resolve.conf pointing to localhost/127.0.0.1
- cmd = "echo \"nameserver 127.0.0.1\" > /etc/resolv.conf";
- script.append(cmd);
-
- String[] cmdFlush = {script.toString()};
- code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true);
- //String msg = res.toString(); //get stdout from command
-
-
- return code;
- }
-
- public static int restoreDNSResolvConf () throws Exception
- {
- StringBuilder script = new StringBuilder();
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- //mv resolv.conf to resolve.conf.bak
- String cmd = "mv /etc/resolv.conf.bak /etc/resolv.conf";
- script.append(cmd);
- script.append(" || exit\n");
-
- String[] cmdFlush = {script.toString()};
- code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true);
- //String msg = res.toString(); //get stdout from command
-
- return code;
- }
- */
- /*
- public int testOwnerModule(Context context, String ipTablesPath) throws Exception
- {
-
- TorBinaryInstaller.assertIpTablesBinaries(context, false);
-
- boolean runRoot = true;
- boolean waitFor = true;
-
- int torUid = context.getApplicationInfo().uid;
-
- StringBuilder script = new StringBuilder();
-
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- // Allow everything for Tor
- script.append(ipTablesPath);
- script.append(" -A OUTPUT");
- script.append(" -t filter");
- script.append(" -m owner --uid-owner ");
- script.append(torUid);
- script.append(" -j ACCEPT");
- script.append(" || exit\n");
-
- script.append(ipTablesPath);
- script.append(" -D OUTPUT");
- script.append(" -t filter");
- script.append(" -m owner --uid-owner ");
- script.append(torUid);
- script.append(" -j ACCEPT");
- script.append(" || exit\n");
-
- String[] cmdAdd = {script.toString()};
-
- code = TorServiceUtils.doShellCommand(cmdAdd, res, runRoot, waitFor);
- String msg = res.toString();
-
- if (mTorService != null)
- logMessage(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
-
-
- return code;
- }
- */
-
- /*
- public int clearTransparentProxyingByApp (Context context, ArrayList<TorifiedApp> apps) throws Exception
- {
- boolean runRoot = true;
- boolean waitFor = true;
-
- String ipTablesPath = getIpTablesPath(context);
-
- StringBuilder script = new StringBuilder();
-
- StringBuilder res = new StringBuilder();
- int code = -1;
-
- String chainName = "ORBOT";
- String jumpChainName = "OUTPUT";
-
- script.append(ipTablesPath);
- script.append(" --flush ").append(chainName); //delete previous user-defined chain
- script.append(" || exit\n");
-
- script.append(ipTablesPath);
- script.append(" -D ").append(jumpChainName);
- script.append(" -j ").append(chainName);
- script.append(" || exit\n");
-
- script.append(ipTablesPath);
- script.append(" -X ").append(chainName); //delete previous user-defined chain
- script.append(" || exit\n");
-
- String[] cmdAdd = {script.toString()};
-
- code = TorServiceUtils.doShellCommand(cmdAdd, res, runRoot, waitFor);
- String msg = res.toString();
-
- logMessage(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
-
- return code;
- }*/
-
- public int setTransparentProxyingByApp(Context context, ArrayList<TorifiedApp> apps, boolean enableRule) throws Exception
- {
- String ipTablesPath = getIpTablesPath(context);
-
- //StringBuilder script = new StringBuilder();
-
- String action = " -A ";
- String srcChainName = "OUTPUT";
-
- if (!enableRule)
- action = " -D ";
-
- //run the delete commands in a separate process as it might error out
- //String[] cmdExecClear = {script.toString()};
- //code = TorServiceUtils.doShellCommand(cmdExecClear, res, runRoot, waitFor);
-
- //reset script
-
- int lastExit = -1;
- StringBuilder script;
-
-
- // Same for DNS
- script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -p udp");
- //script.append(" -m owner --uid-owner ");
- //script.append(tApp.getUid());
- //script.append(" -m udp --dport ");
- script.append(" --dport ");
- script.append(STANDARD_DNS_PORT);
- script.append(" -j REDIRECT --to-ports ");
- script.append(mDNSPort);
- executeCommand (script.toString());
-
- // Allow everything for Tor
-
- //build up array of shell cmds to execute under one root context
- for (TorifiedApp tApp:apps)
- {
-
- if (((!enableRule) || tApp.isTorified())
- && (!tApp.getUsername().equals(TOR_APP_USERNAME))
- ) //if app is set to true
- {
-
-
- logMessage("transproxy for app: " + tApp.getUsername() + " (" + tApp.getUid() + "): enable=" + enableRule);
-
- dropAllIPv6Traffic(context, tApp.getUid(),enableRule);
-
- script = new StringBuilder();
-
- // Allow loopback
- /**
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -m owner --uid-owner ");
- script.append(tApp.getUid());
- script.append(" -o lo");
- script.append(" -j ACCEPT");
-
- executeCommand (shell, script.toString());
- script = new StringBuilder();
- **/
-
- // Set up port redirection
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(ALLOW_LOCAL);
- script.append(" -m owner --uid-owner ");
- script.append(tApp.getUid());
- script.append(" -m tcp --syn");
- script.append(" -j REDIRECT --to-ports ");
- script.append(mTransProxyPort);
-
- executeCommand (script.toString());
-
-
- script = new StringBuilder();
-
- // Reject all other outbound packets
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -m owner --uid-owner ");
- script.append(tApp.getUid());
- script.append(ALLOW_LOCAL);
- script.append(" -j REJECT");
-
- lastExit = executeCommand (script.toString());
-
-
- }
- }
-
- return lastExit;
- }
-
- private int executeCommand (String cmdString) throws Exception {
-
- SimpleCommand command = new SimpleCommand(cmdString);
-
- mShell.add(command).waitForFinish();
-
- logMessage("Command Exec: " + cmdString);
- logMessage("Output: " + command.getOutput());
- logMessage("Exit code: " + command.getExitCode());
-
- return 0;
- }
-
- public void closeShell () throws IOException
- {
- mShell.close();
- }
-
- public int enableTetheringRules (Context context) throws Exception
- {
-
- String ipTablesPath = getIpTablesPath(context);
-
- StringBuilder script = new StringBuilder();
-
- String[] hwinterfaces = {"usb0","wl0.1"};
-
-
- int lastExit = -1;
-
- for (int i = 0; i < hwinterfaces.length; i++)
- {
-
- script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -t nat -A PREROUTING -i ");
- script.append(hwinterfaces[i]);
- script.append(" -p udp --dport 53 -j REDIRECT --to-ports ");
- script.append(mDNSPort);
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
-
- script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -t nat -A PREROUTING -i ");
- script.append(hwinterfaces[i]);
- script.append(" -p tcp -j REDIRECT --to-ports ");
- script.append(mTransProxyPort);
-
- lastExit = executeCommand (script.toString());
- script = new StringBuilder();
-
-
- }
-
- return lastExit;
- }
-
- private void logMessage (String msg)
- {
- if (mTorService != null)
- mTorService.debug(msg);
- }
-
-
-
- public int fixTransproxyLeak (Context context) throws Exception
- {
- String ipTablesPath = getIpTablesPath(context);
-
- StringBuilder script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -I OUTPUT ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 -p tcp -m tcp --tcp-flags ACK,FIN ACK,FIN -j DROP");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -I OUTPUT ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 -p tcp -m tcp --tcp-flags ACK,RST ACK,RST -j DROP");
-
- int lastExit = executeCommand (script.toString());
- script = new StringBuilder();
-
- return lastExit;
-
- }
-
- public int dropAllIPv6Traffic (Context context, int appUid, boolean enableDrop) throws Exception {
-
- String action = " -A ";
- String chain = "OUTPUT";
-
- if (!enableDrop)
- action = " -D ";
-
- String ip6tablesPath = getIp6TablesPath(context);
-
- StringBuilder script;
-
- script = new StringBuilder();
- script.append(ip6tablesPath);
- script.append(action);
- script.append(chain);
-
- if (appUid != -1)
- {
- script.append(" -m owner --uid-owner ");
- script.append(appUid);
- }
-
- script.append(" -j DROP");
-
- int lastExit = executeCommand (script.toString());
-
- return lastExit;
- }
-
- /*
- public int clearAllIPv6Filters (Context context) throws Exception
- {
-
- String ip6tablesPath = getIp6TablesPath(context);
- Shell shell = Shell.startRootShell();
-
- StringBuilder script;
-
- script = new StringBuilder();
- script.append(ip6tablesPath);
- script.append(" -t filter");
- script.append(" -F OUTPUT");
- int lastExit = executeCommand (shell, script.toString());
-
- shell.close();
-
- return lastExit;
- }*/
-
- public int flushTransproxyRules (Context context) throws Exception {
- int exit = -1;
-
- String ipTablesPath = getIpTablesPath(context);
-
- StringBuilder script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -t nat ");
- script.append(" -F ");
-
- executeCommand (script.toString());
-
- script = new StringBuilder();
- script.append(ipTablesPath);
- script.append(" -t filter ");
- script.append(" -F ");
- executeCommand (script.toString());
-
- dropAllIPv6Traffic(context,-1,false);
- dropAllIPv6Traffic(context,-1,false);
-
-
- return exit;
- }
-
- public int setTransparentProxyingAll(Context context, boolean enable) throws Exception
- {
-
- String action = " -A ";
- String srcChainName = "OUTPUT";
-
- if (!enable)
- action = " -D ";
-
- dropAllIPv6Traffic(context,-1,enable);
-
- String ipTablesPath = getIpTablesPath(context);
-
-
- int torUid = context.getApplicationInfo().uid;
-
- StringBuilder script = new StringBuilder();
-
- // Allow everything for Tor
-
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -m owner --uid-owner ");
- script.append(torUid);
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- // Allow loopback
-
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -o lo");
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- // Set up port redirection
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(ALLOW_LOCAL); //allow access to localhost
- script.append(" -m owner ! --uid-owner ");
- script.append(torUid);
- script.append(" -m tcp --syn");
- script.append(" -j REDIRECT --to-ports ");
- script.append(mTransProxyPort);
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- // Same for DNS
- script.append(ipTablesPath);
- script.append(" -t nat");
- script.append(action).append(srcChainName);
- script.append(" -p udp");
- script.append(ALLOW_LOCAL); //allow access to localhost
- script.append(" -m owner ! --uid-owner ");
- script.append(torUid);
- //script.append(" -m udp --dport ");
- script.append(" --dport ");
- script.append(STANDARD_DNS_PORT);
- script.append(" -j REDIRECT --to-ports ");
- script.append(mDNSPort);
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
-
- /**
- if (Prefs.useDebugLogging())
- {
- //XXX: Comment the following rules for non-debug builds
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p udp");
- script.append(" --dport ");
- script.append(STANDARD_DNS_PORT);
- script.append(" -j LOG");
- script.append(" --log-prefix='ORBOT_DNSLEAK_PROTECTION'");
- script.append(" --log-uid");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(" -j LOG");
- script.append(" --log-prefix='ORBOT_TCPLEAK_PROTECTION'");
- script.append(" --log-uid");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- }**/
-
- //allow access to transproxy port
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(" -m tcp");
- script.append(" --dport ").append(mTransProxyPort);
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- //allow access to local HTTP port
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(" -m tcp");
- script.append(" --dport ").append(mTorService.getHTTPPort());
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- //allow access to local SOCKS port
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p tcp");
- script.append(" -m tcp");
- script.append(" --dport ").append(mTorService.getSOCKSPort());
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- //allow access to local DNS port
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -p udp");
- script.append(" -m udp");
- script.append(" --dport ").append(mDNSPort);
- script.append(" -j ACCEPT");
-
- executeCommand (script.toString());
- script = new StringBuilder();
-
- // Reject all other packets
- script.append(ipTablesPath);
- script.append(" -t filter");
- script.append(action).append(srcChainName);
- script.append(" -m owner ! --uid-owner ");
- script.append(torUid);
- script.append(ALLOW_LOCAL); //allow access to localhost
- script.append(" -j REJECT");
-
- int lastExit = executeCommand (script.toString());
-
- // fixTransproxyLeak (context);
-
- return lastExit;
- }
-
-
- public static ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs)
- {
-
- String tordAppString = prefs.getString(OrbotConstants.PREFS_KEY_TORIFIED, "");
- String[] tordApps;
-
- StringTokenizer st = new StringTokenizer(tordAppString,"|");
- tordApps = new String[st.countTokens()];
- int tordIdx = 0;
- while (st.hasMoreTokens())
- {
- tordApps[tordIdx++] = st.nextToken();
- }
-
- Arrays.sort(tordApps);
-
- //else load the apps up
- PackageManager pMgr = context.getPackageManager();
-
- List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);
-
- Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
-
- ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>();
-
- ApplicationInfo aInfo = null;
-
- int appIdx = 0;
- TorifiedApp app = null;
-
- while (itAppInfo.hasNext())
- {
- aInfo = itAppInfo.next();
-
- app = new TorifiedApp();
-
- try {
- PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
-
- if (pInfo != null && pInfo.requestedPermissions != null)
- {
- for (String permInfo:pInfo.requestedPermissions)
- {
- if (permInfo.equals("android.permission.INTERNET"))
- {
- app.setUsesInternet(true);
-
- }
- }
-
- }
-
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
- {
- //System app
- app.setUsesInternet(true);
- }
-
-
- if (!app.usesInternet())
- continue;
- else
- {
- apps.add(app);
- }
-
-
- app.setEnabled(aInfo.enabled);
- app.setUid(aInfo.uid);
- app.setUsername(pMgr.getNameForUid(app.getUid()));
- app.setProcname(aInfo.processName);
- app.setPackageName(aInfo.packageName);
-
- try
- {
- app.setName(pMgr.getApplicationLabel(aInfo).toString());
- }
- catch (Exception e)
- {
- app.setName(aInfo.packageName);
- }
-
-
- //app.setIcon(pMgr.getApplicationIcon(aInfo));
-
- // check if this application is allowed
- if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
- app.setTorified(true);
- }
- else
- {
- app.setTorified(false);
- }
-
- appIdx++;
- }
-
- Collections.sort(apps);
-
- return apps;
- }
-
-}
diff --git a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
index ea072504..3d54e888 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java
@@ -38,7 +38,6 @@ import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
import org.torproject.android.service.R;
import org.torproject.android.service.TorServiceConstants;
-import org.torproject.android.service.transproxy.TorifiedApp;
import org.torproject.android.service.util.TorServiceUtils;
import java.io.BufferedReader;
@@ -46,7 +45,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.InetAddress;
diff --git a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorifiedApp.java b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
similarity index 98%
rename from orbotservice/src/main/java/org/torproject/android/service/transproxy/TorifiedApp.java
rename to orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
index c786905d..c72ebe3b 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/transproxy/TorifiedApp.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/vpn/TorifiedApp.java
@@ -1,4 +1,4 @@
-package org.torproject.android.service.transproxy;
+package org.torproject.android.service.vpn;
import android.content.Context;
import android.content.SharedPreferences;
diff --git a/orbotservice/src/main/res/values/strings.xml b/orbotservice/src/main/res/values/strings.xml
index 59fcb771..27760d16 100644
--- a/orbotservice/src/main/res/values/strings.xml
+++ b/orbotservice/src/main/res/values/strings.xml
@@ -112,7 +112,7 @@
<string name="wizard_tips_fdroid">Find all Guardian Project apps on F-Droid</string>
<string name="wizard_tips_fdroid_org">Find all Guardian Project apps on https://f-droid.org</string>
<!--Transparent Proxy screen-->
- <string name="wizard_transproxy_title">Transparent Proxying</string>
+ <string name="wizard_transproxy_title">Tunneled Apps</string>
<string name="wizard_transproxy_msg">This allows your apps to automatically run through the Tor network without any configuration.</string>
<string name="wizard_transproxy_hint">(Check this box if you have no idea what we are talking about)</string>
<string name="wizard_transproxy_none">None</string>
@@ -286,14 +286,6 @@
<string name="please_disable_this_app_in_android_settings_apps_if_you_are_having_problems_with_orbot_">"Please disable this app in Android->Settings->Apps if you are having problems with Orbot: "</string>
<string name="app_conflict">App Conflict</string>
-
- <string name="pref_transproxy_refresh_title">Transproxy Auto-Refresh</string>
- <string name="pref_transproxy_refresh_summary">Re-apply Transproxy rules when the network state changes</string>
-
- <string name="pref_transproxy_flush_title">Transproxy FORCE REMOVE</string>
- <string name="pref_transproxy_flush_summary">Tap here to flush all transproxy network rules NOW</string>
- <string name="transparent_proxy_rules_flushed_">Transparent proxy rules flushed!</string>
- <string name="you_do_not_have_root_access_enabled">You do not have ROOT access enabled</string>
<string name="you_may_need_to_stop_and_start_orbot_for_settings_change_to_be_enabled_">You may need to stop and start Orbot for settings change to be enabled.</string>
<string name="menu_vpn">VPN</string>
diff --git a/settings.gradle b/settings.gradle
index 7453139d..9984a03e 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1,2 @@
-include ':jsocksAndroid', ':orbotservice', ':RootCommands'
+include ':jsocksAndroid', ':orbotservice'
include ':app'
1
0
commit 70693bfc6a47ca92393f9ed5486234230aa66c6f
Author: n8fr8 <nathan(a)freitas.net>
Date: Sat Oct 14 12:18:57 2017 -0400
update to 4.9 NDK biuld
---
orbotservice/src/main/jni/Application.mk | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/orbotservice/src/main/jni/Application.mk b/orbotservice/src/main/jni/Application.mk
index 554a462d..20921781 100644
--- a/orbotservice/src/main/jni/Application.mk
+++ b/orbotservice/src/main/jni/Application.mk
@@ -1,4 +1,4 @@
APP_ABI := armeabi x86
APP_PLATFORM := android-16
APP_STL := stlport_static
-NDK_TOOLCHAIN_VERSION := 4.8
+NDK_TOOLCHAIN_VERSION := 4.9
1
0

[translation/tails-greeter-2_completed] Update translations for tails-greeter-2_completed
by translation@torproject.org 14 Oct '17
by translation@torproject.org 14 Oct '17
14 Oct '17
commit c52e8d8ef2f4e9f9994e4cc3563ab58c30c8d20b
Author: Translation commit bot <translation(a)torproject.org>
Date: Sat Oct 14 15:50:31 2017 +0000
Update translations for tails-greeter-2_completed
---
es/es.po | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/es/es.po b/es/es.po
index 7371aee38..984fe840e 100644
--- a/es/es.po
+++ b/es/es.po
@@ -210,7 +210,7 @@ msgstr "Conectar directamente a la red Tor (predeterminado) "
#: ../data/greeter.ui.h:42
msgid "Configure a Tor bridge or local proxy"
-msgstr "Configurar un puente de Tor o un proxy local"
+msgstr "Configura un puente Tor o un proxy local"
#: ../data/greeter.ui.h:43
msgid "Disable all networking"
1
0

[translation/tails-greeter-2] Update translations for tails-greeter-2
by translation@torproject.org 14 Oct '17
by translation@torproject.org 14 Oct '17
14 Oct '17
commit 8537c71cb74c050d18f78ead11a026bf92d42ae1
Author: Translation commit bot <translation(a)torproject.org>
Date: Sat Oct 14 15:50:25 2017 +0000
Update translations for tails-greeter-2
---
es/es.po | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/es/es.po b/es/es.po
index 7371aee38..984fe840e 100644
--- a/es/es.po
+++ b/es/es.po
@@ -210,7 +210,7 @@ msgstr "Conectar directamente a la red Tor (predeterminado) "
#: ../data/greeter.ui.h:42
msgid "Configure a Tor bridge or local proxy"
-msgstr "Configurar un puente de Tor o un proxy local"
+msgstr "Configura un puente Tor o un proxy local"
#: ../data/greeter.ui.h:43
msgid "Disable all networking"
1
0

[tor-messenger-build/master] meek seems to have change dirname and bin location
by arlo@torproject.org 13 Oct '17
by arlo@torproject.org 13 Oct '17
13 Oct '17
commit 71f1f59dea8c69e89648d05e863a482714f998da
Author: Arlo Breault <arlolra(a)gmail.com>
Date: Fri Oct 13 18:26:30 2017 -0400
meek seems to have change dirname and bin location
---
projects/tor-messenger/build.osx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/projects/tor-messenger/build.osx b/projects/tor-messenger/build.osx
index f344153..59ed644 100755
--- a/projects/tor-messenger/build.osx
+++ b/projects/tor-messenger/build.osx
@@ -27,8 +27,8 @@ sed -i 's/^ControlPort .*/ControlPort [% c("var/tor_control_port") %]/' TorBrows
sed -i 's/\(ClientTransportPlugin meek exec\) [^ ]\+ -- /\1 /' TorBrowser.app/Contents/Resources/TorBrowser/Tor/torrc-defaults
# trac 17476
-rm -Rf TorBrowser.app/Contents/Resources/TorBrowser/Tor/PluggableTransports/TorBrowser.app.meek-http-helper/
-rm -f TorBrowser.app/Contents/Resources/TorBrowser/Tor/PluggableTransports/meek-client-torbrowser
+rm -Rf TorBrowser.app/Contents/Resources/TorBrowser/Tor/PluggableTransports/template-profile.meek-http-helper/
+rm -f TorBrowser.app/Contents/MacOS/Tor/PluggableTransports/meek-client-torbrowser
mkdir -p $rootdir/TorMessenger.app/Contents/Resources/distribution/extensions/
mv tor-launcher(a)torproject.org $rootdir/TorMessenger.app/Contents/Resources/distribution/extensions/
1
0

[translation/tails-openpgp-applet_completed] Update translations for tails-openpgp-applet_completed
by translation@torproject.org 13 Oct '17
by translation@torproject.org 13 Oct '17
13 Oct '17
commit e17756ad5249f45b5471083b21a017531937d357
Author: Translation commit bot <translation(a)torproject.org>
Date: Fri Oct 13 20:19:01 2017 +0000
Update translations for tails-openpgp-applet_completed
---
fr/openpgp-applet.pot | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fr/openpgp-applet.pot b/fr/openpgp-applet.pot
index 9b2ba8b39..9d1514134 100644
--- a/fr/openpgp-applet.pot
+++ b/fr/openpgp-applet.pot
@@ -12,7 +12,7 @@ msgstr ""
"Project-Id-Version: The Tor Project\n"
"Report-Msgid-Bugs-To: tails(a)boum.org\n"
"POT-Creation-Date: 2017-08-05 15:07-0400\n"
-"PO-Revision-Date: 2017-09-26 15:00+0000\n"
+"PO-Revision-Date: 2017-10-13 20:07+0000\n"
"Last-Translator: French language coordinator <french.coordinator(a)rbox.me>\n"
"Language-Team: French (http://www.transifex.com/otf/torproject/language/fr/)\n"
"MIME-Version: 1.0\n"
1
0

[translation/tails-openpgp-applet] Update translations for tails-openpgp-applet
by translation@torproject.org 13 Oct '17
by translation@torproject.org 13 Oct '17
13 Oct '17
commit 1ebec842b86d2c284302a66d9b20b8ee30e4e6f2
Author: Translation commit bot <translation(a)torproject.org>
Date: Fri Oct 13 20:18:55 2017 +0000
Update translations for tails-openpgp-applet
---
fr/openpgp-applet.pot | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fr/openpgp-applet.pot b/fr/openpgp-applet.pot
index 9b2ba8b39..9d1514134 100644
--- a/fr/openpgp-applet.pot
+++ b/fr/openpgp-applet.pot
@@ -12,7 +12,7 @@ msgstr ""
"Project-Id-Version: The Tor Project\n"
"Report-Msgid-Bugs-To: tails(a)boum.org\n"
"POT-Creation-Date: 2017-08-05 15:07-0400\n"
-"PO-Revision-Date: 2017-09-26 15:00+0000\n"
+"PO-Revision-Date: 2017-10-13 20:07+0000\n"
"Last-Translator: French language coordinator <french.coordinator(a)rbox.me>\n"
"Language-Team: French (http://www.transifex.com/otf/torproject/language/fr/)\n"
"MIME-Version: 1.0\n"
1
0