文件资源管理器中的根访问权限
我正在编写一个文件浏览器,它将能够使用根访问权限修改系统文件,但我遇到了一些问题。
我现在正在做的是授予我的应用程序根访问权限,但执行“su”不起作用。 如果我在 adb shell 中设置文件夹的权限,该应用程序可以正常工作,但我认为 root 浏览不依赖于 chmod。
谁能告诉我是否有一种正确的方法可以让我的应用程序像具有 root 权限一样工作?
I'm writing a file explorer which will be capable of modifying system files with root access, but I came across some problems.
What I'm doing now is to grant my app root access, but executing "su" doesn't work.
If I set permissions to the folder in adb shell, the app works fine but I think root browsing doesn't rely on chmods.
Can anyone tell me is there a proper way to make my app work as if it were with root privileges?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以 root 身份运行 Android 应用程序进程(其 dalvik VM 和本机库)是极其困难的,并且由于多种原因而不建议,这不仅包括安全性,还包括必须加载系统库的私有副本而不是使用共享库而导致的内存浪费。当您像正常应用程序启动一样从 zygote 继承非特权进程时,只读副本可用。
在某些 root 手机上,非官方的“su”黑客攻击的作用是让您启动一个帮助程序进程,该进程以 root 身份运行,而您的应用程序进程仍然没有特权。它不会更改调用它的应用程序的用户 ID - 事实上,在设计上确实没有任何机制可以在类 UNIX 操作系统上执行此操作。
一旦您拥有特权帮助进程,您就需要通过某些进程间通信方式(例如 stdin/stdout 或 unix 域套接字)与其进行通信,以让它代表您执行文件操作。手机上的 shell 甚至可以用作辅助应用程序 - 文件管理器需要执行的大部分操作都可以使用“cat”命令来实现。官方地说,这些都不是一个稳定的 API,但无论如何,应用程序可访问的“su” hack 并不在官方 Android 中,因此整个项目一开始就深陷“不受支持”的领域。
Running an android application process (its dalvik VM and native libraries) as root is extremely difficult to achieve, and inadvisable for a number of reasons including not just security but memory waste resulting from having to load private copies of system libraries instead of using the shared read-only copies available when you inherit an unprivileged process from zygote as in a normal application launch.
What the unofficial "su" hack on some rooted phones does is lets you launch a helper process which runs as root while your application process remains unprivileged. It does not change the userid of the application calling it - indeed, there really isn't by design any mechanism for doing that on unix-like operating systems.
Once you have a privileged helper process, you would then need to communicate with it via some means of interprocess communication such as its stdin/stdout or unix domain sockets to have it do file operations on your behalf. The shell present on the phone could probably even be used as the helper application - most of what a file manager needs to do can be implemented with the 'cat' command. Officially, none of this is a stable API, but then an application-accesable "su" hack isn't in official android anyway, so the whole project is deep in "unsupported" territory to begin with.
Root 访问会创建一个新进程,因此您的应用程序没有 root 权限。
root权限唯一能做的事情就是执行命令,所以,你必须了解android的命令,很多命令是基于Linux的,比如
cp
、ls
等等。使用此代码执行命令并获取输出:
文件资源管理器的用法:
获取文件列表:
读取文本文件:
复制文件(
cp
命令在某些设备上不起作用):删除文件(
rm
命令在某些设备上不起作用):Root access creates a new Process, so, your app does not have root privileges.
The unique thing you can do with root privileges is execute commands, so, you have to know the commands of android, many of commands is based on Linux, like
cp
,ls
and more.Use this code for execute commands and get output:
Usages for a file explorer:
Get list of files:
Read text file:
Copy file (
cp
command not working on some devices):Delete file (
rm
command not working on some devices):