[Android Software/Hacking General [Developers Only]] wladimir_tm:
[Root AVD] Rooting Android Emulator (inc. 'x86_64') with SuperSU installable ZIP

maybe be useful for any..)

& !! of course GREAT THANKS to [MENTION=631273]Chainfire[/MENTION] for amazing work !! &

#########################################

example result:

[IMG="L"]http://xdaforums.com/attachment.php?attachmentid=3056947&stc=1&d=1418206134[/IMG][IMG="su"]http://xdaforums.com/attachment.php?attachmentid=3056948&stc=1&d=1418206134[/IMG]

preface

tried before Genymotion, but ..

wish to FULL control my emu ;)

//& really some performance issues, especially in comparison with x64 arch! )

read&try before some methods, but no any satisfied;

especially with AVD x86_64 based system images

so 'at last' - go to "primary sources" of SU http://su.chainfire.eu :), and there

significantly http://su.chainfire.eu/#embed-exploit

so - accord to [MENTION=631273]Chainfire[/MENTION] rec:

Manual for rooting any version of AVD (emu) with SuperSU installable ZIP

in this example:

host machine:

NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\Win
dowsPowerShell\v1.0\;C:\Program Files\PuTTY;C:\adb;c:\Program Files\Java\jdk1.8.0_25\bin;C:\Users\admin\AppData\Local\An
droid\android-sdk\platform-tools;C:\Users\admin\AppData\Local\Android\android-sdk\tools;C:\Users\admin\.android\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2a07
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

"d:\SU237" used 'as working dir'

"UPDATE-SuperSU-v2.37.zip" - last ver of installable ZIP at this moment :) )

"x86L_64r" - testing AVD:

d:\SU237>android list avd
Available Android Virtual Devices:
...
---------
Name: x86L_64r
Device: Nexus 4 (Google)
Path: C:\Users\admin\.android\avd\x86L_64r.avd
Target: Android 5.0 (API level 21)
Tag/ABI: default/x86_64
Skin: WXGA720
Sdcard: 200M

WXGA720 - my favorite skin ;)

emu = emulator

acc. = according to

addit. = additional(ly)

rec. = recommendations

etc. ;)

0. of course - "sdk tools have to be installed & AVD have to be created"

1. download last ver of SuperSU installable ZIP

2. unpack the content of "UPDATE-SuperSU-v*.**.zip" to supersu folder 'in working dir':

d:\SU237>tree /f
Folder PATH listing for volume D
Volume serial number is 2**
D:.
│
└───supersu
├───arm
│ chattr
│ chattr.pie
│ libsupol.so
│ su
│ supolicy
│
├───arm64
│ libsupol.so
│ su
│ supolicy
│
├───armv7
│ chattr.pie
│ libsupol.so
│ su
│ supolicy
│
├───common
│ 99SuperSUDaemon
│ install-recovery.sh
│ Superuser.apk
│
├───META-INF
│ │ CERT.RSA
│ │ CERT.SF
│ │ MANIFEST.MF
│ │
│ └───com
│ └───google
│ └───android
│ update-binary
│ updater-script
│
├───mips
│ chattr.pie
│ libsupol.so
│ su
│ supolicy
│
├───mips64
│ libsupol.so
│ su
│ supolicy
│
├───x64
│ libsupol.so
│ su
│ supolicy
│
└───x86
chattr
chattr.pie
libsupol.so
su
supolicy

d:\SU237>

3. start AVD

usually using '*.bat' file for starting AVD - as in this case addit. params can be used ;)

for example 'my' "x86L_64r.bat":

cmd /k "emulator -cpu-delay 0 -cache ./cache -no-boot-anim -partition-size 900 -gpu on -verbose -shell -accel on -scale 0.5 -avd x86L_64r"

for details about params - of course look at:

http://developer.android.com/tools/help/emulator.html

http://developer.android.com/tools/devices/managing-avds-cmdline.html

addit. "-partition-size 900" - is due to often (esp. at def. params of sys partitions API <= 19 )

- there are no any free space on system partitions -- so 'rooting can not be done ("have no space for copying req. files"))'; for exmpl:

---------
Name: x86jb412
Device: Nexus S (Google)
Path: C:\Users\admin\.android\avd\x86jb412.avd
Target: Android 4.1.2 (API level 16)
Tag/ABI: default/x86
Skin: WXGA720
Sdcard: 50M

C:\Users\admin\Desktop>adb shell
root@android:/ # df
df
Filesystem Size Used Free Blksize
/dev 441M 68K 441M 4096
/mnt/secure 441M 0K 441M 4096
/mnt/asec 441M 0K 441M 4096
/mnt/obb 441M 0K 441M 4096
[B][COLOR="Red"]/system 264M 264M 0K 4096[/COLOR][/B]
/data 388M 8M 379M 4096
/cache 64M 1M 62M 4096
/mnt/sdcard 196M 6K 196M 512
/mnt/secure/asec 196M 6K 196M 512
root@android:/ #

4. enter CMD (or in shell)) commands:

adb remount
adb shell mount -o rw,remount -t rootfs rootfs
adb shell mkdir /tmp
adb shell mkdir /tmp/supersu
adb push supersu /tmp/supersu
adb shell sh /tmp/supersu/META-INF/com/google/android/update-binary dummy 1 /tmp/supersu/supersu.zip
adb shell su -v
adb shell su -V
adb shell stop
ping -n 5 -w 1000 127.0.0.1
adb shell start
ping -n 15 -w 1000 127.0.0.1
adb shell daemonsu --daemon

comments:

adb remount // -- (re)mount system writeable

adb shell mount -o rw,remount -t rootfs rootfs // -- (re)mount "/" as writeable for creating req following dirs -- acc. to [MENTION=631273]Chainfire[/MENTION] rec. "Last but not least, /tmp should be writable." above

adb shell mkdir /tmp

adb shell mkdir /tmp/supersu

adb push supersu /tmp/supersu //-- transfer folder 'supersu' into emu

adb shell sh /tmp/supersu/META-INF/com/google/android/update-binary dummy 1 /tmp/supersu/supersu.zip //-- last param '/tmp/supersu/supersu.zip' can be ignored due to absence of toolbox or busybox at native emu - but that is 'no deal at all')

//-- example log of execution: - look at attach 'example_adb_log.txt'

adb shell su -v //-- check ver of su binary

adb shell su -V //-- check ver of su binary

adb shell stop //-- for SuperSU appear at "App drawer" - need 'restart emulator' --- and ("after updrading") -- SuperSU appear in "App drawer" )

ping -n 5 -w 1000 127.0.0.1 //-- timeout

adb shell start

ping -n 15 -w 1000 127.0.0.1 //-- timeout; after restarting (esp. at ARM arch!)

adb shell daemonsu --daemon //-- su daemon do need to be started! :) // another case: adb shell daemonsu --auto-daemon &

^C = CTRL+C - for exit from terminal ;)

additionally:

adb shell am start -n eu.chainfire.supersu/.MainActivity

-- to open SuperSU app 'from adb':)

adb shell su --self-test

--self-test //-- from "- Various logs (very important)" http://xdaforums.com/apps/supersu/support-update-failures-t2907365

adb shell su -h

-- help (interesting) ;)

telnet localhost 5554

-- to control emu from console ))

for example - 'kill' emu (close instance)

or resize window (window scale 0.5)

+addit. Using the Emulator Console http://developer.android.com/tools/devices/emulator.html#console

------------

to save created (rooted) system image -- you can look at 'verbose view' of console (*.bat file) started emu

and there find like:

...
emulator: Mapping 'system' partition image to C:\Users\admin\AppData\Local\Temp\\AndroidEmulator\TMPF1D7.tmp
...

(exmpl. - attach "verbose_cmd.txt")

so (at moment of working emu!; of course when you close the emu - this file will be deleted! - http://developer.android.com/tools/devices/emulator.html#temporaryimages)

- just copy this "*.tmp" file to another place and use it "as your rooted system image!" ;)