获取 Android 应用的“root”权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21596397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:47:47  来源:igfitidea点击:

Getting 'root" permission for Android App

androidrootandroid-kernel

提问by ik024

I would like to know how can we get root permission from android app? Are there any app out there in android market?

我想知道我们如何从 android 应用程序获得 root 权限?android 市场上有没有应用程序?

I tried out the below line of code to list out files but nothing happened

我尝试了下面的代码行来列出文件,但什么也没发生

Process process = Runtime.getRuntime().exec(new String[] { "su", "-", "root"});

I tried to give TEST_FACTORY permission in my manifest file but I got an error "permitted to system app"

我试图在我的清单文件中授予 TEST_FACTORY 权限,但出现错误“允许系统应用程序”

How can I make my app system app?

如何制作我的应用系统应用?

I want help to get started with these stuff (make app if possible to get root permission) any help on this is very much appreciated. Thanks in advance :)

我需要帮助来开始使用这些东西(如果可能的话,制作应用程序以获得 root 权限)对此的任何帮助都非常感谢。提前致谢 :)

采纳答案by Johannes H.

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

首先:请注意,您只能使用 su 执行 shell 命令(=您只能以 root 身份使用 shell 命令,而不能使用 java 代码)。

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

第二:不确定这是否适用于所有 su 应用程序,但这是su我手机上的帮助消息:

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.

这意味着:您必须运行su -c something(或su -c something - root,但root无论如何都是默认值)。本质上这在大多数 Linux 系统上等于 su,除了守护进程之外,因为在常规 linux 系统上没有守护进程 ahndling su 调用。

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.

如果其他 su 命令的行为不同(这是可能的),则将流打开到 shell,执行su,评估它的返回代码,然后继续执行其他命令,最后执行更安全exit

回答by Nir Hartmann

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

这里有一个很好的答案 - ANDROID:如何在 Android 应用程序中获得 root 访问权限?

"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"

“据我所知,你只能使用 root 权限运行命令行命令。你可以使用我制作的这个通用类,它在你的代码中包装了 root 访问权限:http: //muzikant-android.blogspot.com/2011/ 02/how-to-get-root-access-and-execute.html"