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 就是用来管理其他用户是否有权限使用超级管理员身份的运行应用程序的系统软件。
安装SuperUser 后,会替换掉 /system/bin/su 文件,
SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569
一个软件获取Root 权限之后,能给其他应用程序 Root 权限吗?
能
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;
- }
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 用户的身份运行程序时,都放行。
su 源代码 下载地址:http://download.csdn.net/detail/jinzhu117/4821630
SuperUser 源代码下载地址:http://download.csdn.net/detail/jinzhu117/4821569
来源:http://blog.csdn.net/jinzhu117/article/details/8233255