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;    }

NAMEsetuid - set user IDSYNOPSIS#include int setuid(uid_t uid);DESCRIPTIONIf 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 VALUEUpon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.ERRORSThe 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 noint checkResult = checkWhitelist();if (checkResult > 0){found = 1;break;}else if (checkResult < 0){// user hit noreturn 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



更多相关文章

  1. Android(安卓)Provider用法
  2. Android中背光系统架构
  3. Task和Activity相关
  4. android 系统属性
  5. Android(安卓)Design in Action —— 编与集
  6. 让应用程序具体相应权限
  7. android service 例子(电话录音和获取系统当前时间)
  8. Android系统内置应用更新或升级后被还原的原因
  9. MVP模式的Android(安卓)调用系统拍照,相册,剪裁,适配到7.0,修复拍照

随机推荐

  1. Android(安卓)studio 中 Gradle手动下载
  2. Android NDK
  3. Android TextView文字横向自动滚动(跑马
  4. [置顶] android ndk空指针导致CRASH的问
  5. android聊天列表实现
  6. Android ListView添加按钮后自身无响应.
  7. Android项目的目录结构详解
  8. Android加载Gif和ImageView的通用解决方
  9. Android GestureDetector
  10. Android_UI开发专题