-1

I am developing an embedded application and I need allow the device owner to root and unroot the device on demand.

I am able to root the device by running the following shell commands through a special version of SU which is stored in the rom:

chown 0.0 /system/xbin/su
chmod 06755 /system/xbin/su

chown 0.0 /system/xbin/busybox
chmod 0755 /system/xbin/busybox

I now need to be able to reverse the rooting process. I therefore need to revert the owner and permissions on the two files. The problem is I'm not sure what the default permissions and owners are on an unrooted android device.

Can anybody help?!

LairdPleng
  • 948
  • 3
  • 9
  • 28

2 Answers2

0

You can read the permission bits by running the command ls -l on the directory where su and busybox are located and then have static fields to set the permissions back to their defaults.

Before running your program, run these commands in a shell (terminal on the device, or through adb shell)

cd /system/xbin
ls -l

...output here.... su
...output here.... busybox

Code (once you know the default owner and permissions):

public class RootAndUnroot{
private static String[] DEF_SU = {"0X.X", "0XXX"}; //Initialize these to the values found above
private static String[] DEF_BUSYBOX = {"0Y.Y", "0YYY"};
...
private void revertRoot(){
    setPermissions("/system/xbin/busybox", DEF_BUSYBOX);
    setPermissions("/system/xbin/su", DEF_SU);
}
cnexus
  • 454
  • 1
  • 3
  • 14
0
stat {dir/file}

Should show you what you need to know, other than that I am also wondering what the digit's are for before the usual 755, 644, 777 deal, though I know on Linux its similar but like this 0755, 0644, 0777. I still don't know what the 0 is for, or why they have say 06755, the answer to that may very well help me get postgresql permission to open sockets.

I am wrong 644 is rw,r,r; you'll see. Please some one correct me or tell me if I am right, but I think its owner|group|other and 1 is read, 2 is write, 3 is read/write which is 1 + 2 =3, and 4 is execute so 4+3=7 which is read/write/execute so if you just want others to only read you give it 771, 0771 (as for android 06771, I don't understand) 0|7|7|1 , Owner|group|other , Owner=7 |group=7 | other =1 so if you only want the owner to read and write but not execute say for a user name x-man you would:

chown x-man:[group] /home/x-man/somefile

-and then-

chmod 0310 /home/x-man/somefile

Which would allow the owner to read/write, group members (say 'cust-asist') could read, and others could not access.