Skip to content

Commit 2017303

Browse files
committed
Latest updates
1 parent ef504e0 commit 2017303

5 files changed

Lines changed: 90 additions & 20 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:1.5.0'
11+
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
1212
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
1313
}
1414
}
@@ -21,7 +21,7 @@ apply plugin: 'com.android.library'
2121

2222
android {
2323
compileSdkVersion 23
24-
buildToolsVersion "23.0.2"
24+
buildToolsVersion "25.0.0"
2525

2626
defaultConfig {
2727
minSdkVersion 11
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Dec 12 12:38:44 CET 2015
1+
#Sat Jun 17 19:54:51 EDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip

src/main/java/com/stericson/RootShell/RootShell.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class RootShell {
4545

4646
public static boolean debugMode = false;
4747

48-
public static final String version = "RootShell v1.4";
48+
public static final String version = "RootShell v1.6";
4949

5050
/**
5151
* Setting this to false will disable the handler that is used
@@ -375,6 +375,19 @@ public static Shell getShell(boolean root) throws IOException, TimeoutException,
375375
* @throws TimeoutException if this operation times out. (cannot determine if access is given)
376376
*/
377377
public static boolean isAccessGiven() {
378+
return isAccessGiven(0, 3);
379+
}
380+
381+
/**
382+
* Control how many time of retries should request
383+
*
384+
* @param timeout The timeout
385+
* @param retries The number of retries
386+
*
387+
* @return <code>true</code> if your app has been given root access.
388+
* @throws TimeoutException if this operation times out. (cannot determine if access is given)
389+
*/
390+
public static boolean isAccessGiven(int timeout, int retries) {
378391
final Set<String> ID = new HashSet<String>();
379392
final int IAG = 158;
380393

@@ -392,8 +405,9 @@ public void commandOutput(int id, String line) {
392405
}
393406
};
394407

395-
Shell.startRootShell().add(command);
396-
commandWait(Shell.startRootShell(), command);
408+
Shell shell = Shell.startRootShell(timeout, retries);
409+
shell.add(command);
410+
commandWait(shell, command);
397411

398412
//parse the userid
399413
for (String userid : ID) {
@@ -413,11 +427,23 @@ public void commandOutput(int id, String line) {
413427
}
414428

415429
/**
416-
* @return <code>true</code> if BusyBox or Toybox was found.
430+
* @return <code>true</code> if BusyBox was found.
417431
*/
418432
public static boolean isBusyboxAvailable()
419433
{
420-
return (findBinary("busybox", true)).size() > 0 || (findBinary("toybox", true)).size() > 0;
434+
return isBusyboxAvailable(false);
435+
}
436+
437+
/**
438+
* @return <code>true</code> if BusyBox or Toybox was found.
439+
*/
440+
public static boolean isBusyboxAvailable(boolean includeToybox)
441+
{
442+
if(includeToybox) {
443+
return (findBinary("busybox", true)).size() > 0 || (findBinary("toybox", true)).size() > 0;
444+
} else {
445+
return (findBinary("busybox", true)).size() > 0;
446+
}
421447
}
422448

423449
/**

src/main/java/com/stericson/RootShell/containers/RootClass.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ public AnnotationsFinder() throws IOException {
148148
} catch (InterruptedException e) {
149149
}
150150

151-
File rawFolder = new File("res" + File.separator + "raw");
151+
String strRawFolder = "res" + File.separator + "raw";
152+
if (builtPath.toString().startsWith("build")); //Check if running in AndroidStudio
153+
strRawFolder = "src" + File.separator + "main" + File.separator + "res" + File.separator + "raw";
154+
155+
File rawFolder = new File(strRawFolder);
152156
if (!rawFolder.exists()) {
153157
rawFolder.mkdirs();
154158
}
@@ -157,14 +161,14 @@ public AnnotationsFinder() throws IOException {
157161
if (onWindows) {
158162
cmd = new String[]{
159163
"cmd", "/C",
160-
"dx --dex --output=res" + File.separator + "raw" + File.separator + "anbuild.dex "
164+
"dx --dex --output=" + strRawFolder + File.separator + "anbuild.dex "
161165
+ builtPath + File.separator + "anbuild.jar"
162166
};
163167
} else {
164168
cmd = new String[]{
165169
getPathToDx(),
166170
"--dex",
167-
"--output=res" + File.separator + "raw" + File.separator + "anbuild.dex",
171+
"--output=" + strRawFolder + File.separator + "anbuild.dex",
168172
builtPath + File.separator + "anbuild.jar"
169173
};
170174
}
@@ -175,12 +179,18 @@ public AnnotationsFinder() throws IOException {
175179
} catch (InterruptedException e) {
176180
}
177181
}
178-
System.out.println("All done. ::: anbuild.dex should now be in your project's res" + File.separator + "raw" + File.separator + " folder :::");
182+
System.out.println("All done. ::: anbuild.dex should now be in your project's src" + File.separator + "main" + File.separator + "res" + File.separator + "raw" + File.separator + " folder :::");
179183
}
180184

181185
protected void lookup(File path, List<File> fileList) {
182-
String desourcedPath = path.toString().replace("src" + File.separator, "");
183-
File[] files = path.listFiles();
186+
String desourcedPath = path.toString().replace("src" + File.separator, "").replace("main" + File.separator + "java" + File.separator, "");
187+
188+
File[] files = path.listFiles(new FileFilter() {
189+
@Override
190+
public boolean accept(File file) {
191+
return true;
192+
}
193+
});
184194
for (File file : files) {
185195
if (file.isDirectory()) {
186196
if (-1 == file.getAbsolutePath().indexOf(AVOIDDIRPATH)) {
@@ -257,6 +267,8 @@ protected String getPathToDx() throws IOException {
257267
if (splitFileName[1].contains("W")) {
258268
char[] fileNameChars = splitFileName[1].toCharArray();
259269
fileName = String.valueOf(fileNameChars[0]);
270+
} else if (splitFileName[1].contains("rc")) {
271+
continue; //Do not use release candidates
260272
} else {
261273
fileName = splitFileName[1];
262274
}
@@ -309,6 +321,12 @@ public boolean accept(File pathname) {
309321
foundPath = eclipsePath;
310322
}
311323
}
324+
if (null == foundPath) {
325+
File androidStudioPath = new File("build" + File.separator + "intermediates" + File.separator + "classes" + File.separator + "debug"); // Android Studio
326+
if (androidStudioPath.isDirectory()) {
327+
foundPath = androidStudioPath;
328+
}
329+
}
312330

313331
return foundPath;
314332
}
@@ -327,4 +345,4 @@ public static void main(String[] args) {
327345
displayError(e);
328346
}
329347
}
330-
}
348+
}

src/main/java/com/stericson/RootShell/execution/Command.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.stericson.RootShell.RootShell;
2626

2727
import android.content.Context;
28+
import android.os.Build;
2829
import android.os.Bundle;
2930
import android.os.Handler;
3031
import android.os.Looper;
@@ -171,12 +172,37 @@ protected final void finishCommand() {
171172
public final String getCommand() {
172173
StringBuilder sb = new StringBuilder();
173174

174-
for (int i = 0; i < command.length; i++) {
175-
if (i > 0) {
175+
if(javaCommand) {
176+
String filePath = context.getFilesDir().getPath();
177+
178+
for (int i = 0; i < command.length; i++) {
179+
/*
180+
* TODO Make withFramework optional for applications
181+
* that do not require access to the fw. -CFR
182+
*/
183+
//export CLASSPATH=/data/user/0/ch.masshardt.emailnotification/files/anbuild.dex ; app_process /system/bin
184+
if (Build.VERSION.SDK_INT > 22) {
185+
//dalvikvm command is not working in Android Marshmallow
186+
sb.append(
187+
"export CLASSPATH=" + filePath + "/anbuild.dex;"
188+
+ " app_process /system/bin "
189+
+ command[i]);
190+
} else {
191+
sb.append(
192+
"dalvikvm -cp " + filePath + "/anbuild.dex"
193+
+ " com.android.internal.util.WithFramework"
194+
+ " com.stericson.RootTools.containers.RootClass "
195+
+ command[i]);
196+
}
197+
198+
sb.append('\n');
199+
}
200+
}
201+
else {
202+
for (int i = 0; i < command.length; i++) {
203+
sb.append(command[i]);
176204
sb.append('\n');
177205
}
178-
179-
sb.append(command[i]);
180206
}
181207

182208
return sb.toString();

0 commit comments

Comments
 (0)