Obtain Root Access via Su on the Android Emulator

Obtain root access via su on the Android emulator

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.

how to get root access on android 2.3 emulator

On the emulator provided with the SDK r10, you can get a root shell executing "adb shell" from your host computer. Once you have such root shell, you cat follow this steps to get a command that can log you as root from the terminal emulator:

# Remount /data to allow executables and setuids on it
mount -o remount,rw /dev/block/mtdblock1 /data

# There's no "cp" command on Android
cat /system/bin/sh > /data/su

# Give setuid permissions to the shell
chmod 7755 /data/su

Now, from the emulator, just run "/data/su" and that's it, you're root.

The normal "/system/xbin/su" command included in the SDK performs internal user id checks, so these commands...

mount -o remount,rw /dev/block/mtdblock0 /system
chmod 7755 /system/xbin/su

...just won't work. There's no way to trick /system/xbin/su to allow the normal user (UID 10018 in my case) to become root.

Please note that dealing with setuid programs can be a security risk (not higher than having a universal "su" command, though). Use this solution at your own risk.

How can I get root access on an Android 7.0 emulator?

I'm writing the json files to /data/data//files using context.getFilesDir().getPath() + "/" + fileName

That is internal storage, not external storage.

Use adb shell run-as ... ??? to run commands as your app's user, which will allow those commands to access internal storage. Here, ... is the application ID of your app, and ??? is a command.

So, for example, to list the contents of a typical location for getFilesDir() for an app whose user ID is com.foo.bar, use:

adb shell run-as com.foo.bar ls /data/data/com.foo.bar/files

This only works for debuggable apps.



Related Topics



Leave a reply



Submit