Thursday, November 22, 2018

adb - How can run native executables compiled for ARM on unrooted Android devices?




Following this tutorial I have compiled a Hello World! ARM binary from C source using gcc. I want to run this program on my unrooted Android phone but I can't figure out an easy way to do it.


What I've tried:




  1. Copying hello to /sdcard and trying to run it from there. This doesn't work because the internal storage is mounted with the noexec flag.




  2. Copying hello to /data/local/ using cp hello /data/local/ or cat hello > /data/local/hello as explained here. This also doesn't work and I get a "permission denied" error.





  3. Installing a terminal emulator program such as Termux and using the Termux app to copy hello from /sdcard/hello to /data/data/com.termux/files/home, running chmod +x hello and then running ./hello from the Termux home directory within the Termux app. This works but is not a feasible solution.




Is there a better/easier way to run native ELF executables on an unrooted Android phone directly through ADB and doesn't involve installing any apps?



Answer




  1. In addition to noexec mount option, /sdcard is emulated filesystem with fixed file permissions. So files can't be set executable. But some file explorers like MiXplorer support executing binaries/scripts from /sdcard through /system/bin/sh.

  2. /data/local has permissions 0751, owner root.root 1, so normal apps can't access it. However from adb shell use /data/local/tmp which has user/group owner 2000 (aid_shell) 2 and selinux is also allowed 3. So you won't get permission denied.

  3. If you don't want to use PC, terminal emulator is the only option. On Termux you can also add /data/local/tmp (or a subdirectory) to $PATH by editing ~/.profile if you want to avoid placing binaries on multiple locations. But the directory should be world-readable and selinux must not be denying the access or execution of binaries.



No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...