1

I was able to run a console app (compiled with NDK) on a rooted Android phone, but can't run it on a non-rooted phone.

I tried:

adb push MyApp /mnt/sdcard/temp
adb shell
cd /mnt/sdcard/temp
chmod a+x MyApp

but chmod did not work and the file remained non-executable:

tulip:/mnt/sdcard/temp $ ls -l
total 33904
-rw-rw---- 1 root sdcard_rw 34713488 2023-10-05 19:49 MyApp

The files are uploaded as root, but the commands are executed as shell:

adb shell "id"                                                                                                       
uid=2000(shell) gid=2000(shell) groups=2000(shell),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:shell:s0...
0

1 Answer 1

1

tl;dr: You're trying to do root-things without root. Getting root in android is extremely difficult and dangerous. Given the scope of your question, I would not recommend that you continue attempting what you're asking about.

Just so you're aware...

  1. "root" in *nix-based environments (including android) is the singular user that has absolute authority.
  2. "rooting" your phone means you have the ability to run commands as "root".
  3. If you're not "root", security restrictions will not allow you to perform certain tasks... like changing permissions on files.
  4. If you look at the file permissions, the file is owned by "root", and the "sdcard_rw" group. Unless you're the owner you have no permissions to modify the permissions on that file. You cannot set the execute permission on that file without ownership and/or root permissions. Since you're not root, and you're not the file owner, you're out of luck.
  5. If you're simply trying to side-load a valid app... you'll need to enable installing apps from 3rd parties in the phone's security settings... and use an appropriate installer to install the .apk to the device. If the apk contains things that would violate the security checks of the device, (like an app that contains some sort of exploit or requires elevated permissions outside the normal scope of what an app can do) you're out-of-luck.
  6. If you force your phone to accept whatever you want to do... you'll need to essentially hack/exploit your phone in some way that would give you elevated permissions. Be careful when attempting to exploit a phone... as you can modify certain bits that would no longer pass the security checks of the bootloader... which might give you root access temporarily, but will also make it no longer able to boot after power-cycling the phone.
3
  • I noticed that file MyApp is owned by root. All the files that I push with adb are owned by root, right?
    – Alexey Starinsky
    Commented Oct 5, 2023 at 20:22
  • That may be true... but when you attempt to run commands... you're not root.
    – TheCompWiz
    Commented Oct 5, 2023 at 21:19
  • I also tried this adb shell "cd /mnt/sdcard/temp && chmod a+x AwlTest && ls -l", but without a success. So files are uploaded as root but the commands are executed as not root.
    – Alexey Starinsky
    Commented Oct 6, 2023 at 5:25

Not the answer you're looking for? Browse other questions tagged .