Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain root access via su on the Android emulator

I need to get root access via su to lunch a TcpDump binary (I am working on a sort of android sniffer). I use this code :

try {
    Process process = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(process.getOutputStream());
    os = new DataOutputStream(process.getOutputStream());
    os.writeBytes("/data/local/tcpdump-arm -c 10 -s 0 -w /data/local/out.txt\n");
    os.writeBytes("exit\n");
    os.flush();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

It works perfectly on a rooted phone, but I want to achieve this in the emulator. By default you can't get root privileges via su on the emulator (although it's possible via adb shell).

I have found this post

But it doesn't work for me. I read somewhere this tip wont work with the curent revision of the sdk, but it doesn't say with which it will work. I try with sdk revision 10 and the avd run Android 2.1.

like image 581
a.b.d Avatar asked Apr 16 '11 14:04

a.b.d


People also ask

What is su in rooting?

su , on the other hand, is an acronym for switch user or substitute user. You are basically switching to a particular user and you need the password for the user you are switching to. Most often, the user account you switch to is the root account but it can be any account on the system.


2 Answers

Ok, I solve the problem by myself :/

It works with sdk revision 10 and in an avd 2.2. The problem with the tip I have followed previously is the remount step. Here is the list of commands working for me (extract from http://forum.xda-developers.com/showthread.php?t=821742) :

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
adb push su /system/xbin/su
adb shell chmod 06755 /system
adb shell chmod 06755 /system/xbin/su
adb install superuser.apk

You can get the su binary and the superuser app here : http://forum.xda-developers.com/showthread.php?t=682828

You have to do that each time you start the emulator.

like image 64
a.b.d Avatar answered Nov 13 '22 19:11

a.b.d


I was able to get superuser.apk to stay between reboots by deleting /system/app/SdkSetup.apk

I just checked again now and it was recreated, but I still have Superuser.apk between my reboots.

I would also recommend pushing a busybox binary along with su.

like image 25
preOtep Avatar answered Nov 13 '22 17:11

preOtep