Giter VIP home page Giter VIP logo

roottools's People

Contributors

draekko avatar friederbluemle avatar fusion avatar hacker1024 avatar johnnphillips avatar lukasz-kalnik-gcx avatar ms202202 avatar odemolliens avatar quanmltya avatar stericson avatar thenetstriker avatar varunchitre15 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roottools's Issues

multiple warnings on the library

since this library no longer have a jar file, when adding this code into another project it produces warnings that I usually use in order to help avoiding NPE:

"Potential null pointer access: The variable command may be null ..."

please check them out and see if it's really possible that NPE can be caused, or at least make the code avoid those warnings.

Root any phone?

I am new to developing and want to learn more. This is not the only area I am interested in but have been trying to learn about this area. I have been trying to find a way to root the zte warp elite n9518 but have had very little luck in finding anything would love some advice on how to start and go about finding a way to do this have even thought about putting a thing on my page but i wanted a place or some code to work from. sorry if this is not where i should have put this but again i didnt know where to start.

Found possible Typo/Bug

In RootTools.java:
retry should be passed through to the startShell and startRootShell function call.

public static Shell getShell(boolean root, int timeout, int retry) throws IOException, TimeoutException, RootDeniedException {
        if (root)
            return Shell.startRootShell(timeout);
        else
            return Shell.startShell(timeout);
    }

Suggested solution:

public static Shell getShell(boolean root, int timeout, int retry) throws IOException, TimeoutException, RootDeniedException {
        if (root)
            return Shell.startRootShell(timeout, retry);
        else
            return Shell.startShell(timeout, retry);
    }

Or explain why you dont pass it through in comments

ClassNotFoundException thrown when executing a JavaCommandCapture command

I followed the directions on the RootTools usage and run Java as root wiki pages, but when I load my app with the following in onCreate() I get a ClassNotFoundException: com.stericson.RootTools.containers.RootClass:

import com.stericson.RootTools.RootTools;
import com.stericson.RootTools.containers.RootClass;
import com.stericson.RootTools.exceptions.RootDeniedException;
import com.stericson.RootTools.execution.CommandCapture;
import com.stericson.RootTools.execution.JavaCommandCapture;
import com.stericson.RootTools.execution.Shell;
...
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

RootTools.debugMode = true; //ON
RootTools.log("roottools is logging");
RootTools.handlerEnabled = false;

Shell shell;
try {
    shell = RootTools.getShell(true);
    JavaCommandCapture cmd = new JavaCommandCapture(
            43,
            false,
            this,
            "com.mycompany.TestActivity.RootToolsTest") {

        @Override
        public void commandOutput(int id, String line) {
            super.commandOutput(id, line);

        }
    };
    shell.add(cmd);
} catch (Exception e) {
    e.printStackTrace();
}

...
@RootClass.Candidate
private class RootToolsTest{
public RootToolsTest(){
Log.d("RootToolsTest", "testing a Java class run as root");
}
}

The same thing happened when I tried RootTools' test class com.stericson.RootToolsTests.NativeJavaClass. I've tried a number of configurations for the placement and inclusion of the RootTools.jar file (most notably ensuring that the RootTools jar is checked for export and moved to the top of the order and export list in Eclipse) but the ClassNotFoundException persists. The exact logcat output follows:

06-02 07:27:45.529: D/RootTools v3.4(5165): roottools is logging
06-02 07:27:45.529: D/RootTools v3.4(5165): Starting Root Shell!
06-02 07:27:45.539: D/RootTools v3.4(5165): Starting shell: su
06-02 07:27:46.409: D/RootTools v3.4(5165): CommandHandler not created
06-02 07:27:46.429: D/RootTools v3.4(5165): Executing: dalvikvm -cp /data/data
/com.hdradio.fmdelverrooted/files/anbuild.dex com.android.internal.util.WithFramework
com.stericson.RootTools.containers.RootClass
com.hdradio.fmdelver.core.DelverActivity.RootToolsTest
06-02 07:27:46.749: D/Command(5165): ID: 43, java.lang.ClassNotFoundException:
com.stericson.RootTools.containers.RootClass
06-02 07:27:46.759: D/Command(5165): ID: 43,at java.lang.Class.classForName(Native Method)
06-02 07:27:46.759: D/Command(5165): ID: 43,at java.lang.Class.forName(Class.java:217)
06-02 07:27:46.759: D/Command(5165): ID: 43,at java.lang.Class.forName(Class.java:172)
06-02 07:27:46.769: D/Command(5165): ID: 43,at
com.android.internal.util.WithFramework.main(WithFramework.java:36)
06-02 07:27:46.769: D/Command(5165): ID: 43,at dalvik.system.NativeStart.main(Native
Method)
06-02 07:27:46.769: D/Command(5165): ID: 43, Caused by: java.lang.NoClassDefFoundError:
com/stericson/RootTools/containers/RootClass
06-02 07:27:46.769: D/Command(5165): ID: 43, ... 5 more
06-02 07:27:46.769: D/Command(5165): ID: 43, Caused by: java.lang.ClassNotFoundException:
com.stericson.RootTools.containers.RootClass
06-02 07:27:46.769: D/Command(5165): ID: 43,at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-02 07:27:46.769: D/Command(5165): ID: 43,at
java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-02 07:27:46.769: D/Command(5165): ID: 43, at
java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-02 07:27:46.769: D/Command(5165): ID: 43, ... 5 more
06-02 07:27:46.979: D/RootTools v3.4(5165): Command 43 finished.

My .classpath looks like:

My development system configuration is as follows: OS: Mac OS X 10.9.2 Eclipse: Kepler ADT: 22.3 RootTools Version: 3.4

and my target platform: Android: 4.1.1 Model: Sony Xperia E C1504 (rooted using SRSRoot and the 'Gandalf' exploit) Firmware: Stock Kernel Xperia E C1505_11.3.A.0.47 (supposed to work for C1504 as well)

Any ideas why Android can't find the com.stericson.RootTools.containers.RootClass class?

Don't apply retries to use deny

I don't like the fact that my retries setting also applies to the user pressing "Deny". It seems that this is something apps should respect.

RootTools create zombie process

config : RootTools 3.4 on GT-S5830i android 2.3.6.

I assume this is related to http://bugs.java.com/view_bug.do?bug_id=6474073

Code:

@Override
public void onResume() {
    super.onResume();
    d("onResume");
    assertDeviceDontHaveRoot();
}

protected void assertDeviceDontHaveRoot(){
    final BaseActivity context = this;
    d("assertDeviceDontHaveRoot");
    Runnable runnable =  new Runnable() {
        @Override
        public void run() {
            final boolean  gotRoot = RootTools.isRootAvailable() || RootTools.isBusyboxAvailable() || RootTools.isAccessGiven();

            if (!gotRoot) {
                return;
            }

            Runnable forceCloseBecauseIsRoot = new Runnable() {
                @Override
                public void run() {
                        Utils.Dialog.show(....., new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                BaseActivity.this.finish();
                            }
                        });
                }// END run 
            }; // END forceCloseBecauseIsRoot

            context.runOnUiThread(forceCloseBecauseIsRoot);

        }//END run
    }; // END runnable

    context.runOnSecondaryThread(runnable);
}

after a few run:

adb shell ps

 app_67    2848  1     147600 15096 ffffffff 00000000 S com.example.app
 app_67    2961  1     151116 16120 ffffffff 00000000 S com.example.app
 app_67    3173  1     153052 16796 ffffffff 00000000 S com.example.app
 app_67    3237  1     153052 16796 ffffffff 00000000 S com.example.app
 app_67    3253  1     153052 16796 ffffffff 00000000 S com.example.app
 app_67    3462  1     158708 17544 ffffffff 00000000 S com.example.app
 app_67    3480  1     158300 17628 ffffffff 00000000 S com.example.app
 app_67    3494  1     162432 17664 ffffffff 00000000 S com.example.app
 app_67    3627  1     170720 18256 ffffffff 00000000 S com.example.app
 app_67    3659  1     174816 18652 ffffffff 00000000 S com.example.app
 app_67    3691  1     173840 18568 ffffffff 00000000 S com.example.app

SIGSEGV on switching context

SuperSU v2.16
RootTool v3.5
Nexus 7 with Android 5.0, patched kernel (from Chainfire)

D/RootTools v3.5( 3069): Context is different than open shell, switching context...
D/RootTools v3.5( 3069): Starting Root Shell!
D/RootTools v3.5( 3069): Starting shell: su
D/RootTools v3.5( 3069): Context: u:r:system_app:s0
D/RootTools v3.5( 3069): Timeout: 25000
D/RootTools v3.5( 3069): Closing shell
D/RootTools v3.5( 3069): Read all output
D/RootTools v3.5( 3069): Shell destroyed
--------- beginning of crash
F/libc ( 3259): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 3259 (daemonsu)
E/ ( 183): ptrace attach failed: Permission denied
W/System.err( 3069): com.stericson.RootTools.exceptions.RootDeniedException: Root Access Denied
W/System.err( 3069): at com.stericson.RootTools.execution.Shell.(Shell.java:168)
W/System.err( 3069): at com.stericson.RootTools.execution.Shell.startRootShell(Shell.java:558)
W/System.err( 3069): at com.stericson.RootTools.execution.Shell.switchRootShellContext(Shell.java:626)
W/System.err( 3069): at com.stericson.RootTools.execution.Shell.startRootShell(Shell.java:570)
W/System.err( 3069): at com.stericson.RootTools.RootTools.getShell(RootTools.java:376)
W/System.err( 3069): at com.stericson.RootTools.RootTools.getShell(RootTools.java:393)
W/System.err( 3069): at com.think_android.apps.appmonster.base.service.RootUninstallIntentService.silentUninstall(RootUninstallIntentService.java:99)
W/System.err( 3069): at com.think_android.apps.appmonster.base.service.RootUninstallIntentService.handleActionUninstallApp(RootUninstallIntentService.java:58)
W/System.err( 3069): at com.think_android.apps.appmonster.base.service.RootUninstallIntentService.onHandleIntent(RootUninstallIntentService.java:51)
W/System.err( 3069): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
W/System.err( 3069): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 3069): at android.os.Looper.loop(Looper.java:135)
W/System.err( 3069): at android.os.HandlerThread.run(HandlerThread.java:61)

Command Output only reading first line

Using the code below will result in only the first line of the output being displayed.

 Command command = new Command(0, "cat anyfile")
 {
                @Override
                public void commandCompleted(int arg0, int arg1) {

                }

                @Override
                public void commandOutput(int arg0, String line) {
                                Log.i("stuff: ", line);
                            }

                @Override
                public void commandTerminated(int arg0, String arg1) {

                }
        }
        RootTools.getShell(true).add(command);

RootTools ' kill failed: EPERM (Operation not permitted)' Problem

My App Freez When i Use RootTools Commands
i write a simple Code Like :

            RootTools.debugMode = true;  

            if (RootTools.isRootAvailable())
             {
                 print("Root found.\n");
             }
             else
             {
                 print("Root not found");
             }

And My AndroidManifest.xml Have Default Code.

But My logCat Showing This Errors (Tag = 'System' ) :

    libcore.io.ErrnoException: kill failed: EPERM (Operation not permitted)
at libcore.io.Posix.kill(Native Method)
at libcore.io.ForwardingOs.kill(ForwardingOs.java:81)
at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:260)
at com.stericson.RootShell.execution.Shell.<init>(Shell.java:195)
at com.stericson.RootShell.execution.Shell.startRootShell(Shell.java:848)
at com.stericson.RootShell.RootShell.getShell(RootShell.java:300)
at com.stericson.RootShell.RootShell.getShell(RootShell.java:337)
at com.stericson.RootShell.RootShell.getShell(RootShell.java:347)
at com.stericson.RootShell.RootShell.exists(RootShell.java:156)
at com.stericson.RootShell.RootShell.exists(RootShell.java:112)
at com.stericson.RootShell.RootShell.findBinary(RootShell.java:251)
at com.stericson.RootShell.RootShell.findBinary(RootShell.java:183)
at com.stericson.RootShell.RootShell.isRootAvailable(RootShell.java:404)
at com.stericson.RootTools.RootTools.isRootAvailable(RootTools.java:650)
at ir.BLT.instagramdownloader.MainActivity.Copy_From_Insta_Cach(MainActivity.java:806)
at ir.BLT.instagramdownloader.MainActivity.onOptionsItemSelected(MainActivity.java:767)
at android.app.Activity.onMenuItemSelected(Activity.java:2609)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1056)
at    com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
 at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:315)
at com.android.internal.view.menu.ActionMenuPresenter$OverflowPopup.onItemClick(ActionMenuPres    enter.java:798)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1223)
at android.widget.ListView.performItemClick(ListView.java:4506)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2967)
at android.widget.AbsListView$1.run(AbsListView.java:3653)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)

Run in Htc One X , Android 4.2.2 (Rooted), SU app = SuperSU.

commandOutput is not called in every lines

I'm working with roottols 4.
If I call "getevent" command and I pass the "touch_dev" device the "commandOutput" doesn't return me every lines. Especially if I make single tap. And with "gpio-keys" device it returns nothing.
However with the terminal emulator app it works well.

CODE: ("device" for me is "/dev/input/event5" but if you run "getevent" in adb shell you can find your "touch_dev" device)

private Command command; 

 public GetTouch(String device)
    {
        command = new Command(0, 0, "getevent " + device)
        {
            @Override
            public void commandOutput(int id, String line)
            {
                System.out.println(line);
            }

            @Override
            public void commandTerminated(int id, String reason)
            {
                // TODO Auto-generated method stub
            }

            @Override
            public void commandCompleted(int id, int exitCode)
            {
                // TODO Auto-generated method stub
            }

        };
    }

 public void run() throws RootDeniedException
    {
        try
        {
            RootTools.getShell(true).add(command);
        } 
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (TimeoutException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
    }

Not possible to receive binary output from stdout

Hi,

I've been using the library for a while now, but recently I needed to call the screencap command which outputs the screenshot to either a file or stdout. I'd like to use stdout so I don't have the IO overhead, but the Command class automatically converts the data to Strings, deleting line seperators and other important info.

I was wondering how I could work around the issue or if there is a library that does allow binary output

commandOutput not being executed

public Boolean getState(int number) {
        final String[] response = new String[1];
        Log.d("GET1", "num: "+number);
        Command getStateCmd = new Command(0, "cat /sys/devices/system/cpu/cpu" + number + "/online") {
            @Override
            public void commandOutput(int id, String line) {
                response[0] = line;
                Log.d("GET2", "line: "+line);
                super.commandOutput(id, line);
            }
            @Override
            public void commandCompleted(int id, int exitcode) {
                Log.d("GET2", "exitcode: " + exitcode);
                super.commandCompleted(id, exitcode);
            }
            @Override
            public void commandTerminated(int id, String reason) {
                Log.d("GET2", "reason: " + reason);
                super.commandTerminated(id, reason);
            }
        };
        try {
            RootTools.getShell(true).add(getStateCmd);
        }catch (IOException | RootDeniedException | TimeoutException ex) {
            ex.printStackTrace();
        }

        Log.d("GET3", "response: "+response[0]);

Logcat returns:

03-20 23:22:26.679 32757-32757/? D/GET1: num: 1
03-20 23:22:37.564 32757-32757/? D/GET3: response: null

It looks like that none of command* methods being executed.

Roottols is making me unable to open a file?

I have an App that copies and modifies permissions of a file. But then when I try to read said file I get permission denied.

java.io.FileNotFoundException: /data/data/com.lstupenengo.primeraapp/files/xx: open failed: EACCES (Permission denied)

How can I know when RootTools is finished?

My code:

RootTools.copyFile("/data/data/com.xxx/" + file, getFilesDir() +"/"+ file, true, false);
        CommandCapture cmd = new CommandCapture(0,"chmod 777 "+getFilesDir()+"/"+file);
        try {
            RootTools.getShell(true).add(cmd);
        } catch (TimeoutException | RootDeniedException | IOException e) {
            e.printStackTrace();
            Log.e("Root "+file, "Fallo");
        }

       File fts = new File(getFilesDir()+"/"+file);
       FileInputStream fis = new FileInputStream(fts); //Here I get my error.

Logcat

12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ java.io.FileNotFoundException: /data/data/com.lstupenengo.primeraapp/files/xx: open failed: EACCES (Permission denied)
12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:418)
12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:78)
12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.myFTP.upload(myFTP.java:80)
12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.FirstRunService.upload(FirstRunService.java:75)
12-18 16:23:41.874  30092-30806/com.lstupenengo.primeraapp W/System.err﹕ at com.lstupenengo.primeraapp.FirstRunService.onHandleIntent(FirstRunService.java:47)

libcore.io.ErrnoException: kill failed: ESRCH (No such process)

I saw theses in the logcat.

Similar issue to https://code.google.com/p/roottools/issues/detail?id=49
but, still re-producing on version 3.4 on gt-p7310 android 4.0.4, NOT rooted

05-09 12:06:27.633: I/System(15680): Failed to destroy process 15802
05-09 12:06:27.673: I/System(15680): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
05-09 12:06:27.673: I/System(15680):    at libcore.io.Posix.kill(Native Method)
05-09 12:06:27.673: I/System(15680):    at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
05-09 12:06:27.673: I/System(15680):    at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:257)
05-09 12:06:27.673: I/System(15680):    at com.stericson.RootTools.execution.Shell$3.run(Shell.java:449)
05-09 12:06:27.673: I/System(15680):    at java.lang.Thread.run(Thread.java:856)
05-09 12:06:27.683: D/ActionBarSherlock(15680): [getActionBar]
[....]
05-09 12:06:27.833: D/ActionBarSherlock(15680): [getActionBar]
05-09 12:06:27.833: I/System(15680): Failed to destroy process 15816
05-09 12:06:27.843: I/System(15680): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
05-09 12:06:27.843: I/System(15680):    at libcore.io.Posix.kill(Native Method)
05-09 12:06:27.843: I/System(15680):    at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
05-09 12:06:27.843: I/System(15680):    at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:257)
05-09 12:06:27.843: I/System(15680):    at com.stericson.RootTools.execution.Shell$3.run(Shell.java:449)
05-09 12:06:27.843: I/System(15680):    at java.lang.Thread.run(Thread.java:856)
[more similar ErrnoException]

maybe this can help you:
https://groups.google.com/forum/#!topic/android-developers/VcjXWBosQ88

Wiki update

Hi! I´ve updated this part of the Usage page on the wiki and I think that the first part o Running root commands should be updated too since there is no CommandCapture option.

Should it be updated from

CommandCapture command = new CommandCapture(0, "echo this is a command", "echo this is another command");
RootTools.getShell(true).add(command).waitForFinish();

to

Command command = new Command(0, "settings put secure user_setup_complete 0", "settings put global device_provisioned 0");
RootTools.getShell(true).add(command);

I don't mind updating this part but I want to know first if I´m doing something wrong or CommanCapture belogs to a legacy version of the library 😄

access to Process for manual pipe handling

I'd like to manually handle stdin/stdout/sterr and just want to start a process as root.
It would be great if you could add a method to start start a Process as root and return the resulting "Process" Object.

Issue on Nexus 10 JB4.3 - SEGV_MAPERR

What steps will reproduce the problem?

  1. Call "RootTools.RootTools.isRootAvailable()" in a separate thread in "onResume()" of Activity.

What is the expected output? What do you see instead?

The device root value is returned, but then there are a series of SEGV_MAPERR in the DDMS logs.
This happens everytime.

What version of the product are you using? On what operating system?

RootTools 3.0 on Nexus 10, Android 4.3, Build No JWR66Y

What happened to "waitForFinish" ?

I haven't updated the library in a while.
I want to perform some root operations via a background thread, and found out this function is missing.

What should I use instead?
How can I perform multiple commands, and wait for all to finish?

N

N

Couldn't switch context on official L

Hi there,

I'm using the current latest stable version of roottools and I can't switch context using this code:

RootTools.getShell(true, ShellContext.UNTRUSTED_APP).add(cc);

Regardless what ShellContext constant I use, I still only get the normal init context as the output of id is like this: uid=0(root) gid=0(root) context=u:r:init:s0

I tested this on Nexus 5 with CFAR and latest SuperSU with LPX21O.

Error when using proguard

I am getting the following errors witth either (its random) the RootTools.isAccessGiven() or RootTools.exists(...) functions, this works fine when the application is run in debug, but when built for release with proguard e.t.c, the following occurs, on a stock (except root) nexus 10 and nexus 5, doesnt appear specific to those devices. This happens with 3.5 and with the master from git.

root tools is excluded from proguard, and i am using the very latest build tools and sdk.

11-08 16:03:00.783 10200-10315/? E/RootTools v3.5﹕ Waiting for a command to be executed in a shell that is not executing and not reading!
Command: id
11-08 16:03:00.783 10200-10315/? W/System.err﹕ java.lang.Exception
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at dalvik.system.VMStack.getThreadStackTrace(Native Method)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at java.lang.Thread.getStackTrace(Thread.java:579)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at com.stericson.RootTools.internal.RootToolsInternalMethods.commandWait(SourceFile:1484)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at com.stericson.RootTools.internal.RootToolsInternalMethods.exists(SourceFile:430)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at com.stericson.RootTools.RootTools.exists(SourceFile:202)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at nz.org.winters.android.gnfastcharge.r.b(SourceFile:115)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at nz.org.winters.android.gnfastcharge.IntentReceiver_.onHandleIntent(SourceFile:91)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
11-08 16:03:00.783 10200-10315/? W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:61)

Extremely slow

HTC One Sense 6, 5.0.2
Updated from 3.4 to 4.2 and now all commands are very slow taking ~2 seconds.
Code example:
https://gist.github.com/Mikanoshi/a2f4a6de794f403f2297

Debug log:

03-06 09:12:56.519: D/RootShell v1.3(24730): CommandHandler created
03-06 09:12:56.519: D/RootShell v1.3(24730): Using Existing Shell!
03-06 09:12:56.529: D/RootShell v1.3(24730): Executing: cat /sys/class/leds/button-backlight/currents with context: NORMAL
03-06 09:12:56.529: D/RootShell v1.3(24730): Waiting for output to be processed. 0 Of 1
03-06 09:12:56.609: D/Command(24730): ID: 0, 20
03-06 09:12:56.609: D/RootShell v1.3(24730): CommandHandler created
03-06 09:12:56.609: D/RootShell v1.3(24730): Using Existing Shell!
03-06 09:12:56.619: D/RootShell v1.3(24730): Executing: stat -c '%u' /sys/class/leds/button-backlight/currents with context: NORMAL
03-06 09:12:58.531: D/RootShell v1.3(24730): Read all output
03-06 09:12:58.531: D/RootShell v1.3(24730): Command 0 finished.
03-06 09:12:58.531: D/RootShell v1.3(24730): Waiting for output to be processed. 0 Of 1
03-06 09:12:58.531: D/Command(24730): ID: 0, 10253
03-06 09:12:58.541: D/RootShell v1.3(24730): Using Existing Shell!
03-06 09:12:58.541: D/RootShell v1.3(24730): CommandHandler created
03-06 09:12:58.541: D/RootShell v1.3(24730): Executing: chmod 644 /sys/class/leds/button-backlight/currents
03-06 09:12:58.541: D/RootShell v1.3(24730): echo 0 > /sys/class/leds/button-backlight/currents
03-06 09:12:58.541: D/RootShell v1.3(24730): chmod 444 /sys/class/leds/button-backlight/currents with context: NORMAL
03-06 09:13:00.544: D/RootShell v1.3(24730): Read all output
03-06 09:13:00.544: D/RootShell v1.3(24730): Command 0 finished.
03-06 09:13:00.544: D/RootShell v1.3(24730): Read all output
03-06 09:13:00.544: D/RootShell v1.3(24730): Command 0 finished.

Is something wrong with executing commands like that? This is the same code with RootTools 3.5:

03-06 17:32:31.466: D/RootTools v3.5(20683): CommandHandler created
03-06 17:32:31.466: D/RootTools v3.5(20683): Using Existing Shell!
03-06 17:32:31.486: D/RootTools v3.5(20683): Executing: cat /sys/class/leds/button-backlight/currents
03-06 17:32:31.486: D/RootTools v3.5(20683): Command 0 finished.
03-06 17:32:31.556: D/RootTools v3.5(20683): CommandHandler created
03-06 17:32:31.556: D/RootTools v3.5(20683): Using Existing Shell!
03-06 17:32:31.566: D/RootTools v3.5(20683): Executing: stat -c '%u' /sys/class/leds/button-backlight/currents
03-06 17:32:31.566: D/RootTools v3.5(20683): Using Existing Shell!
03-06 17:32:31.566: D/RootTools v3.5(20683): CommandHandler created
03-06 17:32:31.566: D/RootTools v3.5(20683): Command 0 finished.
03-06 17:32:31.576: D/RootTools v3.5(20683): Executing: chmod 644 /sys/class/leds/button-backlight/currents
03-06 17:32:31.576: D/RootTools v3.5(20683): echo 0 > /sys/class/leds/button-backlight/currents
03-06 17:32:31.576: D/RootTools v3.5(20683): chmod 444 /sys/class/leds/button-backlight/currents
03-06 17:32:31.596: D/RootTools v3.5(20683): Command 0 finished.

Root tools completely trashes cm 10.2 on i9300 (4.3)

I set up a little test app that does nothing but test
if(RootTools.isRootAvailable()&&RootTools.isAccessGiven()).

Outcome:
The Superuser-App opens, but immediately crashes. After that Trebuchet (the launcher app on cm 10.2), the settings app and system-ui crash. This bug is permanent, even after uninstalling the app via adb, clearing cache and dalvik-cache, rebooting. The only way to "untrash" the system is to reinstall the rom or wipe data.
(All that without even being granted root, i didn't even know that was possible.)
(Video example: http://youtu.be/z_jp2xcTWu0)

OS: 4.3
version:3.4

Fail to run RootClass

Every time I run RootClass on the root of my project I get a null exception. Tried it on RootTools sources and got the same error.

Discovering root class annotations...
 Found annotated class:  class NativeJavaClass
##ERR##null##
java.lang.NullPointerException
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:172)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:165)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:165)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:165)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:165)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.lookup(RootClass.java:165)
        at com.stericson.RootTools.containers.RootClass$AnnotationsFinder.<init>(RootClass.java:68)
        at com.stericson.RootTools.containers.RootClass.main(RootClass.java:286)

I'm using version 3.4, running Java 8 and my machine runs Linux. Does anyone have a clue to what's wrong?

Crash on Android 5.x

I get a lot of errors from users only for Galaxy Note 3/4 with Android 5.x
Program crash after calling RootTools.isRootAvailable () or RootTools.isAccessGiven () (one of them is a mistake, I do not know).

That is a mistake that sent a Galaxy Note 3:


Build fingerprint: 'samsung/hltexx/hlte:5.0/LRX21V/N9005XXUGPOF3:user/release-keys'
Revision: '8'
ABI: 'arm'
pid: 15988, tid: 16141, name: .* >>> com.android.* <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x605
r0 fffffaa0 r1 b4eff054 r2 00000005 r3 00000000
r4 b4f69300 r5 bdea9a88 r6 000005cd r7 b4efca44
r8 00000605 r9 aaca1600 sl b4f69300 fp b4f07884
ip b5d9ede8 sp bdea9988 lr b4e17caf pc b4c62150 cpsr a0030010

backtrace:
#00 pc 000aa150 /system/lib/libart.so (art::arm::ArmContext::FillCalleeSaves(art::StackVisitor const&)+72)
#1 pc 0025fcad /system/lib/libart.so (art::StackVisitor::WalkStack(bool)+236)
#2 pc 00263d03 /system/lib/libart.so (art::Thread::DumpJavaStack(std::__1::basic_ostream<char, std::__1::char_traits >&) const+78)
#3 pc 0026ece5 /system/lib/libart.so (art::ThreadList::DumpLocked(std::__1::basic_ostream<char, std::__1::char_traits >&)+56)
#4 pc 0025640d /system/lib/libart.so (art::AbortState::Dump(std::1::basic_ostream<char, std::1::char_traits >&)+300)
#5 pc 002567ef /system/lib/libart.so (art::Runtime::Abort()+82)
#6 pc 000ad8ef /system/lib/libart.so (art::LogMessage::~LogMessage()+590)
#7 pc 00181e71 /system/lib/libart.so (art::IndirectReferenceTable::IndirectReferenceTable(unsigned int, unsigned int, art::IndirectRefKind)+408)
#8 pc 001c420f /system/lib/libart.so (art::JNIEnvExt::JNIEnvExt(art::Thread
, art::JavaVMExt
)+30)
#9 pc 002667f5 /system/lib/libart.so (art::Thread::Init(art::ThreadList
, art::JavaVMExt
)+232)
#10 pc 0026870d /system/lib/libart.so (art::Thread::CreateCallback(void*)+108)
#11 pc 000137bb /system/lib/libc.so (__pthread_start(void*)+30)
#12 pc 0001189b /system/lib/libc.so (__start_thread+6)

P.S. Used RootTools 4.2
P.P.S. Translated by Google

AndroidStudio

I get the following error ( I guess it's a Java7 problem ):

  Error Code:
    1
  Output:
    Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.processClass(Main.java:704)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
        at com.android.dx.command.dexer.Main.access$300(Main.java:83)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    ...while parsing com/stericson/RootShell/containers/RootClass$1.class

    1 error; aborting


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Hide root in app that use this tools.. Possible??

Hi, an italian TV broadcaster has implemented in it apps this library to identify rooted phone and for blocks it apps if root is present..
There are any way to hide or bypass the root check of this library for having a full working apps??

Because I try RootCloak, but not work.. Maybe adding custom keywords and commands to hide? Where are all commands/keywords that this library search for identify a rooted phone??

Thanks a lot,
BoGnY

Gradle repo

Hi, could you maintain a repo for your releases?
It's very handy to add it into project by single line of code
compile 'org.stericson:roottools:4.2.0'

RootTools.isAccessGiven() request root access many times (4)

RootTools.isAccessGiven() request root access for about 4 times if user denies the root permission each time. This will disturb user.
I think the num of retry when calling rootShell should be configurable!
For example RootTools.isAccessGiven(int retryNum)
Any suggestions?

java.lang.IllegalStateException: Unable to add commands to a closed shell

I'm getting the RootTools shell and executing commands like so:

RootTools.getShell(true).add(cmd);

and sometimes (not always, and not reproduceably) it throws the error mentioned above.

In the same code, I'm performing various other root commands, using other RootTools functions (copyFile, remount), and also explicitly running some commands with Runtime.getRuntime().exec(), both before and after this call. But I'm only explicitly calling getShell once. How can I fix/work around this issue? I can check to see if the shell that getShell returns is closed, but I don't know how to get an open shell in that case.

Bootloop

I'm running root command from com.android.internal.policy.impl.PhoneWindowManager.systemBooted().
It works fine for me and numerous other users, but some have this error that causes bootloop:

W/Watchdog(28990): *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in handler on ui thread (android.ui)
D/Process (28990): killProcess, pid=28990
W/Watchdog(28990): ui thread stack trace:
W/Watchdog(28990):     at java.lang.Object.wait(Native Method)
D/Process (28990): com.android.server.Watchdog.run:581 <bottom of call stack> <bottom of call stack>
W/Watchdog(28990):     at java.lang.Thread.join(Thread.java:786)
W/Watchdog(28990):     at java.lang.Thread.join(Thread.java:744)
W/Watchdog(28990):     at com.stericson.RootShell.execution.Shell.<init>(Shell.java:187)
W/Watchdog(28990):     at com.stericson.RootShell.execution.Shell.startRootShell(Shell.java:848)
W/Watchdog(28990):     at com.stericson.RootShell.execution.Shell.startRootShell(Shell.java:834)
W/Watchdog(28990):     at com.stericson.RootShell.execution.Shell.startRootShell(Shell.java:826)
W/Watchdog(28990):     at com.stericson.RootShell.RootShell.isAccessGiven(RootShell.java:372)
W/Watchdog(28990):     at com.stericson.RootTools.RootTools.isAccessGiven(RootTools.java:616)
W/Watchdog(28990):     at com.sensetoolbox.six.mods.WakeGesturesMods$10$1.run(WakeGesturesMods.java:637)
W/Watchdog(28990):     at android.os.Handler.handleCallback(Handler.java:739)
W/Watchdog(28990):     at android.os.Handler.dispatchMessage(Handler.java:95)
W/Watchdog(28990):     at android.os.Looper.loop(Looper.java:155)
W/Watchdog(28990):     at android.os.HandlerThread.run(HandlerThread.java:61)
W/Watchdog(28990):     at com.android.server.ServiceThread.run(ServiceThread.java:46)
W/Watchdog(28990): *** GOODBYE!

Any way to fix this or is it too early on boot and only delay will help?

How to finish a command

If I execute a set of commands, commandCompleted is never called. Do I have to call it manually? I tried adding a exit\n command, but that does not solve the problem either. Following works, but it's just a workaround. How is meant to be used correctly?

Command command = new Command(0, true, getCommandSu(), "ps\n", "echo EXIT") {
        @Override
        public void commandOutput(int id, String line) {
            // use cmd output...

            // finish command
            if (line.equals("EXIT"))
                commandFinished();
        }

        @Override
        public void commandCompleted(int id, int exitCode) {
            L.d("COMPLETED (" + exitCode + ")");
        }
    };
    shell.runCommand(command);
    while (!command.isFinished()) {
        Thread.sleep(50);
    }

Cannot resolve symbol 'CommandCapture'

I'm trying to create a root app and I found out about RootTools.

https://github.com/Stericson/RootTools/releases

I went ahead and downloaded the RootTools.jar

I followed this guide to import RootTools.jar

In your project, choose File menu > Project Structure (there's a bug
in 0.4.4 and this menu item won't have a title at all; it still works)

Modules > choose your module > Dependencies > + button > File dependency > choose your library from the file picker. That file needs
to be somewhere beneath the root directory of your projet; the libs
directory is fine.

I now put

CommandCapture command = new CommandCapture(0, "cp -f " + sourceLocation + " " + targetLocation);
RootTools.getShell(true).add(command);

Inside my code, the issue with this is that CommandCapture is highlighted in red and I get an issue saying that this symbol is not resolved

http://i.imgur.com/x2wlu46.png

This is my whole code so far.

package dgameman1.com.emojiupdaterroot;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;

import com.stericson.RootTools.RootTools;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       // final Spinner emojiSpinner = (Spinner) findViewById(R.id.emojiSpinner);
        final Button updateEmojiButton = (Button) findViewById(R.id.updateEmojiButton);

        updateEmojiButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    CommandCapture command = new CommandCapture(0, "cp -f " + sourceLocation + " " + targetLocation);
                    RootTools.getShell(true).add(command);
                } catch (IOException e) {
                }
            }
        });
    }
}

java.io.IOException: Error running exec().

This related to #12, but the exception is different (and FC my app) in this special use case.

steps:

  • RootTools version 3.4 on gt-p7310 android 4.0.4, NOT rooted.
  • uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17"
    
  • call RootTools from activity.OnResume in a secondary thread.
  • install the apk from a local file on the device (mail attachement)
  • once installed, open the application from the installer "success" screen
  • go to android laucher home
  • re-open the app from shortcut.
  • -> app FC

NOTE:

  • if you install the apk using adb/IDE the error cannot reproduce.

.

05-09 14:06:23.283 I/System  (26621): Failed to destroy process 27465
05-09 14:06:23.293 I/System  (26621): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
05-09 14:06:23.293 I/System  (26621):   at libcore.io.Posix.kill(Native Method)
05-09 14:06:23.293 I/System  (26621):   at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
05-09 14:06:23.293 I/System  (26621):   at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:257)
05-09 14:06:23.293 I/System  (26621):   at com.stericson.RootTools.execution.Shell$3.run(Shell.java:449)
05-09 14:06:23.293 I/System  (26621):   at java.lang.Thread.run(Thread.java:856)
05-09 14:06:23.403 W/System.err(26621): java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: [ANDROID_SOCKET_zygote=14, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=13,66560, VIBE_PIPE_PATH=/dev/pipes]
05-09 14:06:23.403 W/System.err(26621):     at java.lang.ProcessManager.exec(ProcessManager.java:211)
05-09 14:06:23.403 W/System.err(26621):     at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
05-09 14:06:23.403 W/System.err(26621):     at com.stericson.RootTools.execution.Shell.<init>(Shell.java:68)
05-09 14:06:23.403 W/System.err(26621):     at com.stericson.RootTools.execution.Shell.startRootShell(Shell.java:501)
05-09 14:06:23.403 W/System.err(26621):     at com.stericson.RootTools.execution.Shell.startRootShell(Shell.java:483)
05-09 14:06:23.403 W/System.err(26621):     at com.stericson.RootTools.internal.RootToolsInternalMethods.isAccessGiven(RootToolsInternalMethods.java:775)
05-09 14:06:23.403 W/System.err(26621):     at com.stericson.RootTools.RootTools.isAccessGiven(RootTools.java:537)
05-09 14:06:23.403 W/System.err(26621):     at com.example.MyBaseActivity$1.run(MyBaseActivity.java:52)
05-09 14:06:23.403 W/System.err(26621):     at java.lang.Thread.run(Thread.java:856)
05-09 14:06:23.403 W/System.err(26621): Caused by: java.io.IOException: Permission denied
05-09 14:06:23.403 W/System.err(26621):     at java.lang.ProcessManager.exec(Native Method)
05-09 14:06:23.403 W/System.err(26621):     at java.lang.ProcessManager.exec(ProcessManager.java:209)
05-09 14:06:23.403 W/System.err(26621):     ... 8 more

reproduce releases

How can I build a RootTools.jar release file?
the tasks build or assembleRelease just produce files like './RootShell/build/intermediates/bundles/release/classes.jar'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.