su 在安卓上是如何工作的?它工作的先决条件是什么?什么是在 Android 上生根?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10028032/
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
How does su work on android? And what are the pre-requisites for it to work? What is rooting on Android?
提问by mk..
Possible Duplicate : what does the su mean: process = Runtime.getRuntime().exec("su");
可能重复:su 是什么意思:process = Runtime.getRuntime().exec("su");
I am tired trying all the different things yet i am still unsuccessful in understanding when will su work. What is rooting a device in Android? Someone please please help me with this.
我已经厌倦了尝试所有不同的事情,但我仍然无法理解 su 何时起作用。什么是在 Android 中生根设备?请有人帮我解决这个问题。
I replied to the following question. The solution i posted there, i tested and also it worked.
我回答了以下问题。我在那里发布的解决方案,我进行了测试并且它也有效。
Adding full permission for a image file in android.
Here is my question :
这是我的问题:
I tried Following.
我试过关注。
Copied su.
复制苏。
Installed SuperUser.apk,
安装 SuperUser.apk,
From program i called su and then using the newly created process i performed the required operations.
我从程序中调用了 su,然后使用新创建的进程执行了所需的操作。
This has 2 results.
这有 2 个结果。
1) When the device is rooted(like executing Permanent root option in z4root), It works, it changes the system file permissions.
1)当设备被root时(如在z4root中执行永久root选项),它起作用,它改变了系统文件权限。
2) When device is not rooted, It doesnot work.
2)当设备没有root时,它不起作用。
Kindly explain what extra thing does z4root performs which makes the task possible. Explain in brief please.
请解释 z4root 执行哪些额外的操作使任务成为可能。请简要说明。
Let me know if my question is not clear. Thanks a ton..
如果我的问题不清楚,请告诉我。万分感谢..
回答by matix2267
What z4root (or any other rooting program) does it runs some exploit to change its own uid (user-id) to 0 (root). You can think of it as of performing some kind of hack and tricking kernel into thinking it actually has the right to be root (then if z4root was a virus it could do everything with your phone from installing keyloggers to bricking it). Of course if it is possible to trick kernel in such a way to give you root access it is considered a security vulnerability (any app could do that and perform some malicious stuff) and usually gets fixed in future kernel updates (that's why z4root may not work if you upgrade your firmware).
z4root(或任何其他生根程序)运行了一些漏洞,将自己的 uid(用户 ID)更改为 0(root)。您可以将其视为执行某种黑客行为并诱使内核认为它实际上具有成为 root 的权利(那么如果 z4root 是一种病毒,它可以对您的手机执行任何操作,从安装键盘记录器到将其变砖)。当然,如果有可能以这种方式欺骗内核以授予您 root 访问权限,则它被认为是一个安全漏洞(任何应用程序都可以这样做并执行一些恶意操作)并且通常会在未来的内核更新中得到修复(这就是为什么 z4root 可能不会如果您升级固件,则工作)。
When z4root has set its uid to 0 it does the following: remounts /system
partition as writable (by default it's read-only), copies over su binary, Superuser.apk and busybox and then remounts /system
back as read-only.
当 z4root 将其 uid 设置为 0 时,它会执行以下操作:/system
将分区重新挂载为可写(默认情况下它是只读的),复制 su 二进制文件、Superuser.apk 和 busybox,然后重新挂载/system
为只读。
So how does the su binary give you root access without doing "the hack" thing when normally applications have same uid as parent process? This is because su binary has set-uidflag set and is always ran as uid 0 (root).
那么当通常应用程序与父进程具有相同的 uid 时,su 二进制文件如何在不做“黑客”操作的情况下为您提供 root 访问权限?这是因为 su 二进制文件设置了 set-uid标志并且总是作为 uid 0 (root) 运行。
Now, if you have copied su binary over to /system/bin
then you must have had root access which means you just forgot to change owner/permissions (chown root:root /system/bin/su; chmod 6755 /system/bin/su
) but you still need root access to do that.
现在,如果您已将 su 二进制文件复制到,/system/bin
那么您必须具有 root 访问权限,这意味着您只是忘记更改所有者/权限 ( chown root:root /system/bin/su; chmod 6755 /system/bin/su
) 但您仍然需要 root 访问权限才能执行此操作。
回答by Jeremy
When you root a device you overwrite or modify the OS image in the ROM to give you elevated permissions. Installing applications in user mode cannot possibly give you a privilege escalation in any version of Linux anywhere. If any user could make themselves root by "copying su" there would be no such thing as security.
当您对设备进行 root 时,您会覆盖或修改 ROM 中的操作系统映像以授予您提升的权限。在用户模式下安装应用程序不可能在任何地方的任何版本的 Linux 中提供特权升级。如果任何用户都可以通过“复制 su”使自己成为 root,那么就没有安全性之类的东西。
回答by Nanne
I'm not sure what you're asking, but it seems a simple thing. You're trying to become "super user", or do stuff with superuser rights. You can only do this if you have the actual rights to do so, given to the user-account currently running on your device. Normally you don't have that right.
我不确定你在问什么,但这似乎很简单。您正在尝试成为“超级用户”,或者使用超级用户权限进行操作。只有在您拥有当前在设备上运行的用户帐户的实际权限时,您才能执行此操作。通常你没有那个权利。
Keep in mind that "superuser" is the same as "root"
请记住,“超级用户”与“root”相同
- If you "root" your device it means you give yourself the right to become superuser. You can do stuff that requires to be super user: "su" is one of those commands, as it says "log me in as superuser". You obviously need superuser permissions to become that user.
- If you haven't rooted the device, you don't have the rights to do the stuff superuser can. So calling
su
won't work.
- 如果您“root”了您的设备,则意味着您有权成为超级用户。你可以做一些需要超级用户的事情:“su”是这些命令之一,因为它说“以超级用户身份登录我”。您显然需要超级用户权限才能成为该用户。
- 如果您还没有植根设备,则您无权执行超级用户可以执行的操作。所以打电话是
su
不行的。
So you can only do root
stuff if you've rooted
your device.
因此,只有root
拥有rooted
设备,您才能做事。