@@ -45,7 +45,7 @@ public class RootShell {
4545
4646 public static boolean debugMode = false ;
4747
48- public static final String version = "RootShell v1.2 " ;
48+ public static final String version = "RootShell v1.3 " ;
4949
5050 /**
5151 * Setting this to false will disable the handler that is used
@@ -176,29 +176,50 @@ public void commandOutput(int id, String line) {
176176
177177 /**
178178 * @param binaryName String that represent the binary to find.
179+ *
179180 * @return <code>List<String></code> containing the locations the binary was found at.
180181 */
181182 public static List <String > findBinary (final String binaryName ) {
183+ return findBinary (binaryName , null );
184+ }
185+
186+ /**
187+ * @param binaryName <code>String</code> that represent the binary to find.
188+ * @param searchPaths <code>List<String></code> which contains the paths to search for this binary in.
189+ *
190+ * @return <code>List<String></code> containing the locations the binary was found at.
191+ */
192+ public static List <String > findBinary (final String binaryName , List <String > searchPaths ) {
193+
194+ final List <String > foundPaths = new ArrayList <String >();
195+
182196 boolean found = false ;
183197
184- final List <String > list = new ArrayList <String >();
185- String [] places = {
186- "/sbin/" , "/system/bin/" , "/system/xbin/" , "/data/local/xbin/" ,
187- "/data/local/bin/" , "/system/sd/xbin/" , "/system/bin/failsafe/" , "/data/local/"
188- };
198+ if (searchPaths == null )
199+ {
200+ searchPaths = RootShell .getPath ();
201+ }
189202
190203 RootShell .log ("Checking for " + binaryName );
191204
192205 //Try to use stat first
193206 try {
194- for (final String path : places ) {
207+ for (String path : searchPaths ) {
208+
209+ if (!path .endsWith ("/" ))
210+ {
211+ path += "/" ;
212+ }
213+
214+ final String currentPath = path ;
215+
195216 Command cc = new Command (0 , false , "stat " + path + binaryName ) {
196217 @ Override
197218 public void commandOutput (int id , String line ) {
198219 if (line .contains ("File: " ) && line .contains (binaryName )) {
199- list .add (path );
220+ foundPaths .add (currentPath );
200221
201- RootShell .log (binaryName + " was found here: " + path );
222+ RootShell .log (binaryName + " was found here: " + currentPath );
202223 }
203224
204225 RootShell .log (line );
@@ -212,49 +233,33 @@ public void commandOutput(int id, String line) {
212233
213234 }
214235
215- found = !list .isEmpty ();
236+ found = !foundPaths .isEmpty ();
216237 } catch (Exception e ) {
217238 RootShell .log (binaryName + " was not found, more information MAY be available with Debugging on." );
218239 }
219240
220241 if (!found ) {
221242 RootShell .log ("Trying second method" );
222243
223- for (String where : places ) {
224- if (RootShell .exists (where + binaryName )) {
225- RootShell .log (binaryName + " was found here: " + where );
226- list .add (where );
227- found = true ;
228- } else {
229- RootShell .log (binaryName + " was NOT found here: " + where );
244+ for (String path : searchPaths ) {
245+
246+ if (!path .endsWith ("/" ))
247+ {
248+ path += "/" ;
230249 }
231- }
232- }
233250
234- if (!found ) {
235- RootShell .log ("Trying third method" );
236-
237- try {
238- List <String > paths = RootShell .getPath ();
239-
240- if (paths != null ) {
241- for (String path : paths ) {
242- if (RootShell .exists (path + "/" + binaryName )) {
243- RootShell .log (binaryName + " was found here: " + path );
244- list .add (path );
245- } else {
246- RootShell .log (binaryName + " was NOT found here: " + path );
247- }
248- }
251+ if (RootShell .exists (path + binaryName )) {
252+ RootShell .log (binaryName + " was found here: " + path );
253+ foundPaths .add (path );
254+ } else {
255+ RootShell .log (binaryName + " was NOT found here: " + path );
249256 }
250- } catch (Exception e ) {
251- RootShell .log (binaryName + " was not found, more information MAY be available with Debugging on." );
252257 }
253258 }
254259
255- Collections .reverse (list );
260+ Collections .reverse (foundPaths );
256261
257- return list ;
262+ return foundPaths ;
258263 }
259264
260265 /**
@@ -520,6 +525,7 @@ private static void commandWait(Shell shell, Command cmd) throws Exception {
520525 while (!cmd .isFinished ()) {
521526
522527 RootShell .log (version , shell .getCommandQueuePositionString (cmd ));
528+ RootShell .log (version , "Processed " + cmd .totalOutputProcessed + " of " + cmd .totalOutput + " output from command." );
523529
524530 synchronized (cmd ) {
525531 try {
0 commit comments