user672009
user672009

Reputation: 4585

Root commands library

Right now I'm doing something like below to execute commands as root. But the whole thing seemed a bit manual so I googled a bit and found roottools. Is that the recommended way to go or is there something better?

I want to be able to wait for commands to finish, read output and ret val's.

    public static void deleteSystemApp(Context context, String app)
    {
            final String MOUNT_RW = "mount -o remount,rw -t rfs /dev/stl5 /system; \n";
            final String MOUNT_RO = "mount -o remount,ro -t rfs /dev/stl5 /system; \n";
            final String RM_APP = "rm -rf " + app + "; \n";
            Process process;
            try
            {
                    process = Runtime.getRuntime().exec("su");
                    DataOutputStream os = new DataOutputStream(process.getOutputStream());
                    os.writeBytes(MOUNT_RW);
                    Toast.makeText(context, RM_APP, Toast.LENGTH_SHORT).show();
                    //os.writeBytes(RM_APP);
                    os.writeBytes(MOUNT_RO);
            }
            catch(IOException e)
            {
                    e.printStackTrace();
            }
    }

Update regarding the issue pointed out by Chris Stratton: I was already urlencoding my app argument to ensure that nobody could pass something like "something; rm -rf /" or "something && rm -rf /" and wipe the device. But upon further consideration I completely dropped the idea about sanitizing arguments. And deleted that part of my code. Why?

  1. Why would anyone want to do this to their own device?
  2. If someone else is able to pass malicious arguments the device is already compromised.

Upvotes: 0

Views: 374

Answers (1)

EvZ
EvZ

Reputation: 12179

Original description:

RootTools provides rooted developers a standardized set of tools for use in the development of rooted applications. In the end, we will accomplish this by providing developers with robust, easy-to-use libraries that will drastically improve development times as well as promote code reuse. This project is open to any proven developer that feels they have something to contribute. By pitching in together we can streamline our own processes, improve the effectiveness of our apps, learn new techniques, and provide a better experience for our users.

As you might understand RootTools provides rooted developers a standardized set of tools for use in the development of rooted applications. If you need non-standard tools right your own or modify the source code of RootTools. Usually this library will cover all your needs. I used it in few projects and was very happy about it.

Good luck.

Upvotes: 2

Related Questions