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:
Copying
helloto/sdcardand trying to run it from there. This doesn't work because the internal storage is mounted with thenoexecflag.Copying
helloto/data/local/usingcp hello /data/local/orcat hello > /data/local/helloas explained here. This also doesn't work and I get a "permission denied" error.Installing a terminal emulator program such as Termux and using the Termux app to copy
hellofrom/sdcard/helloto/data/data/com.termux/files/home, runningchmod +x helloand then running./hellofrom 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
- In addition to
noexecmount option,/sdcardis emulated filesystem with fixed file permissions. So files can't be set executable. But some file explorers like MiXplorer support executing binaries/scripts from/sdcardthrough/system/bin/sh. /data/localhas permissions0751, ownerroot.root1, so normal apps can't access it. However fromadb shelluse/data/local/tmpwhich has user/group owner2000(aid_shell) 2 and selinux is also allowed 3. So you won't get permission denied.- 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$PATHby editing~/.profileif 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