Getting 'root\" permission for Android App

拥有回忆 提交于 2019-11-28 11:22:53

First: note that you can only execute shell commands using su (= you can only use shell commands as root, not java code).

Second: Not sure if this applies to all su apps out there, but this is the help message of su on my phone:

Usage: su [options] [--] [-] [LOGIN] [--] [args...]

Options:  
  --daemon                      start the su daemon agent  
  -c, --command COMMAND         pass COMMAND to the invoked shell  
  -h, --help                    display this help message and exit  
  -, -l, --login                pretend the shell to be a login shell  
  -m, -p,  
  --preserve-environment        do not change environment variables  
  -s, --shell SHELL             use SHELL instead of the default /system/bin/sh  
  -u                            display the multiuser mode and exit  
  -v, --version                 display version number and exit  
  -V                            display version code and exit,  
                                this is used almost exclusively by Superuser.apk  

This means: you have to run su -c something (or su -c something - root, but rootis the default anyway). essentially this is equal to su on most Linux systems, except the daemon-thing, as there is no daemon ahndling su calls on regular linux systems.

If other su commands behave differently (which is possible), it's more secure to open a stream to a shell, execute su, evaluate it's return code, then proceed to execute other commands, finally execute exit.

Nir Hartmann

Theres a good answer here - ANDROID: How to gain root access in an Android application?

"As far as I know, you can only run command-line commands using root privileges. You can use this generic class I made that wraps the root access in your code: http://muzikant-android.blogspot.com/2011/02/how-to-get-root-access-and-execute.html"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!