Android 手机Root 原理解析
来源:互联网 发布:音效 知乎 编辑:程序博客网 时间:2024/04/30 10:51
Root 手机的原理 ?
Root 是Linux 等类Unix 系统的超级管理员用户账户,手机Root 也就是系统破解(在 iOS 设备中叫做“越狱”),当手机被Root ,其他用户就可以以超级管理员的身份运行程序。
Root 的原理是 修改系统的/system/bin/su 文件
su 源代码 下载地址:http://download.csdn.net/detail/jinzhu117/4821630
SuperUser 是什么?
SuperUser 是用来管理用户Root 权限的软件。当手机被Root 之后,相当于所有的用户都有了以Root 用户的身份运行只能Root 用户才能执行的程序和命令,用户可以任意的修改系统密码,删除系统重要文件等等,系统变得非常不安全,SuperUser 就是用来管理其他用户是否有权限使用超级管理员身份的运行应用程序的系统软件。当有用户(程序)想以root 权限 或者以root 权限执行命令及程序时,su.c 会先启动SuperUser ,询问用户是否给予该程序(用户)Root 权限,如果给则将该进程设置为root
安装SuperUser 后,会替换掉 /system/bin/su 文件,
SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569
一个软件获取Root 权限之后,能给其他应用程序 Root 权限吗?
能
1.把su.c 替换成自己修改后的su.c
2.把共享应用程序的UserId.
Root 手机?
其实就是修改系统的/system/bin/su 文件
应用获得Root 权限
Root 之前,只有Root 用户才能以超级管理员的权限运行应用程序,看su.c 的代码:
- if (myuid != AID_ROOT && myuid != AID_SHELL) {
- fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
- return 1;
- }
- if(setgid(gid) || setuid(uid)) {
- fprintf(stderr,"su: permission denied\n");
- return 1;
- }
- NAME
- setuid - set user ID
- SYNOPSIS
- #include <unistd.h>
- int setuid(uid_t uid);
- DESCRIPTION
- If the process has appropriate privileges, setuid() shall set the real user ID, effective user ID, and the saved set-user-ID of the calling process to uid.
- If the process does not have appropriate privileges, but uid is equal to the real user ID or the saved set-user-ID, setuid() shall set the effective user ID to uid; the real user ID and saved set-user-ID shall remain unchanged.
- The setuid() function shall not affect the supplementary group list in any way.
- RETURN VALUE
- Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.
- ERRORS
- The setuid() function shall fail, return -1, and set errno to the corresponding value if one or more of the following are true:
- [EINVAL]
- The value of the uid argument is invalid and not supported by the implementation.
- [EPERM]
- The process does not have appropriate privileges and uid does not match the real user ID or the saved set-user-ID.
Root 之后,使用SuperUser 管理系统的Root 权限,SuperUser 有一个白名单,白名单中都是允许以使用超级管理员的用户。
- if (!checkWhitelist())
- {
- char sysCmd[1024];
- sprintf(sysCmd, "am start -a android.intent.action.MAIN -n com.koushikdutta.superuser/com.koushikdutta.superuser.SuperuserRequestActivity --ei uid %d --ei pid %d > /dev/null", g_puid, ppid);
- if (system(sysCmd))
- return executionFailure("am.");
- int found = 0;
- int i;
- for (i = 0; i < 10; i++)
- {
- sleep(1);
- // 0 means waiting for user input
- // > 0 means yes/always
- // < 0 means no
- int checkResult = checkWhitelist();
- if (checkResult > 0)
- {
- found = 1;
- break;
- }
- else if (checkResult < 0)
- {
- // user hit no
- return permissionDenied();
- }
- }
Root 之后,自己写一个程序,替换系统的su.c 文件,当其他应用程序想以 Root 用户的身份运行程序时,都放行。
看完之后可以试着回答下面几个问题:
1,Root 是什么?
2,Android 手机Root 的原理?
3,什么是SuperUser ?
4,su.c 的作用?
5,setUid() 和setGid() 的左右?
su 源代码 下载地址:http://download.csdn.net/detail/jinzhu117/4821630
SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569
转自http://blog.csdn.net/jinzhu117/article/details/8233255
- Android 手机Root 原理解析
- Android 手机Root 原理解析
- Android 手机Root 原理解析
- Android手机Root原理
- Android手机Root授权原理细节全解析
- Android手机Root授权原理细节全解析
- Android手机Root授权原理细节全解析
- Android手机Root授权原理细节全解析
- 判断手机是否ROOT 代码实现+ Android 操作系统 获取Root权限 原理解析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android手机一键Root原理分析
- Android--手机一键Root原理分析
- Android手机一键Root原理分析
- 如今年轻人买房靠爸妈成潮流,海南房地产网为您只招
- monit 监控并自动重启服务
- html开篇设计英语
- 新生赛3 1003 字符串最小表示法题目
- c++ const class trick
- Android 手机Root 原理解析
- 斐波那契数列的实现(改进)
- IplImage转QImage的代码
- ios应用内跳转到appstore里评分
- 定义者权限和调用者权限的区别
- string实现
- Java:String和Date、Timestamp之间的转换
- cmake 学习笔记
- Redis源码-数据结构之Adlist双端链表