@@ -45,7 +45,7 @@ public class RootShell {
4545
4646 public static boolean debugMode = false ;
4747
48- public static final String version = "RootShell v1.3 " ;
48+ public static final String version = "RootShell v1.4 " ;
4949
5050 /**
5151 * Setting this to false will disable the handler that is used
@@ -141,6 +141,7 @@ public void commandOutput(int id, String line) {
141141 commandWait (RootShell .getShell (false ), command );
142142
143143 } catch (Exception e ) {
144+ RootShell .log ("Exception: " + e );
144145 return false ;
145146 }
146147
@@ -152,11 +153,22 @@ public void commandOutput(int id, String line) {
152153
153154 result .clear ();
154155
156+ command = new Command (0 , false , cmdToExecute + file ) {
157+ @ Override
158+ public void commandOutput (int id , String line ) {
159+ RootShell .log (line );
160+ result .add (line );
161+
162+ super .commandOutput (id , line );
163+ }
164+ };
165+
155166 try {
156167 RootShell .getShell (true ).add (command );
157168 commandWait (RootShell .getShell (true ), command );
158169
159170 } catch (Exception e ) {
171+ RootShell .log ("Exception: " + e );
160172 return false ;
161173 }
162174
@@ -176,20 +188,22 @@ public void commandOutput(int id, String line) {
176188
177189 /**
178190 * @param binaryName String that represent the binary to find.
191+ * @param singlePath boolean that represents whether to return a single path or multiple.
179192 *
180193 * @return <code>List<String></code> containing the locations the binary was found at.
181194 */
182- public static List <String > findBinary (final String binaryName ) {
183- return findBinary (binaryName , null );
195+ public static List <String > findBinary (String binaryName , boolean singlePath ) {
196+ return findBinary (binaryName , null , singlePath );
184197 }
185198
186199 /**
187200 * @param binaryName <code>String</code> that represent the binary to find.
188201 * @param searchPaths <code>List<String></code> which contains the paths to search for this binary in.
202+ * @param singlePath boolean that represents whether to return a single path or multiple.
189203 *
190204 * @return <code>List<String></code> containing the locations the binary was found at.
191205 */
192- public static List <String > findBinary (final String binaryName , List <String > searchPaths ) {
206+ public static List <String > findBinary (final String binaryName , List <String > searchPaths , boolean singlePath ) {
193207
194208 final List <String > foundPaths = new ArrayList <String >();
195209
@@ -228,12 +242,16 @@ public void commandOutput(int id, String line) {
228242 }
229243 };
230244
231- RootShell .getShell (false ).add (cc );
245+ cc = RootShell .getShell (false ).add (cc );
232246 commandWait (RootShell .getShell (false ), cc );
233247
248+ if (foundPaths .size () > 0 && singlePath ) {
249+ break ;
250+ }
234251 }
235252
236253 found = !foundPaths .isEmpty ();
254+
237255 } catch (Exception e ) {
238256 RootShell .log (binaryName + " was not found, more information MAY be available with Debugging on." );
239257 }
@@ -251,6 +269,11 @@ public void commandOutput(int id, String line) {
251269 if (RootShell .exists (path + binaryName )) {
252270 RootShell .log (binaryName + " was found here: " + path );
253271 foundPaths .add (path );
272+
273+ if (foundPaths .size () > 0 && singlePath ) {
274+ break ;
275+ }
276+
254277 } else {
255278 RootShell .log (binaryName + " was NOT found here: " + path );
256279 }
@@ -394,14 +417,14 @@ public void commandOutput(int id, String line) {
394417 */
395418 public static boolean isBusyboxAvailable ()
396419 {
397- return (findBinary ("busybox" )).size () > 0 ;
420+ return (findBinary ("busybox" , true )).size () > 0 ;
398421 }
399422
400423 /**
401424 * @return <code>true</code> if su was found.
402425 */
403426 public static boolean isRootAvailable () {
404- return (findBinary ("su" )).size () > 0 ;
427+ return (findBinary ("su" , true )).size () > 0 ;
405428 }
406429
407430 /**
0 commit comments