Android修改源码实现root

简介: Android修改源码实现root

userdebug 和 user 版本

1. 关闭 selinux

system/core

diff -- git a / init / selinux . cpp b / init / selinux . cpp
 
index 5 a0255acd .. 787917274 100644
 
--- a / init / selinux . cpp
 
+++ b / init / selinux . cpp
 
@@ - 104 , 6 + 104 , 8 @@ EnforcingStatus StatusFromCmdline () {
 
}
 
bool IsEnforcing () {
 
+ return false ;
 
+
 
if ( ALLOW_PERMISSIVE_SELINUX ) {
 
return StatusFromCmdline () == SELINUX_ENFORCING ;
 
}


3. 修改 su.cpp ,注释用户组权限检测


system/extras/su/su.cpp
 
diff -- git a / su / su . cpp b / su / su . cpp
 
index 1 a1ab6bf .. af3d2a68 100644
 
--- a / su / su . cpp
 
+++ b / su / su . cpp
 
@@ - 80 , 8 + 80 , 8 @@ void extract_uidgids ( const char* uidgids , uid_t * uid , gid_t *
 
gid , gid_t * gids , i
 
}
 
int main ( int argc , char** argv ) {
 
- uid_t current_uid = getuid ();
 
- if ( current_uid != AID_ROOT && current_uid != AID_SHELL ) error ( 1 , 0 , "not
allowed" );
 
+ //uid_t current_uid = getuid();
 
+ //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not
allowed");
 
// Handle -h and --help.
 
++ argv ;


4. 给 su 文件默认授予 root 权限


system/core/libcutils/fs_config.cpp
 
diff -- git a / libcutils / fs_config . cpp b / libcutils / fs_config . cpp
 
index 5805 a4d19 .. 92e93 e76f 100644
 
--- a / libcutils / fs_config . cpp
 
+++ b / libcutils / fs_config . cpp
 
@@ - 86 , 7 + 86 , 7 @@ static const struct fs_path_config android_dirs [] = {
 
{ 00751 , AID_ROOT , AID_SHELL , 0 , "system/bin" },
 
{ 00755 , AID_ROOT , AID_ROOT , 0 , "system/etc/ppp" },
 
{ 00755 , AID_ROOT , AID_SHELL , 0 , "system/vendor" },
 
- { 00750 , AID_ROOT , AID_SHELL , 0 , "system/xbin" }, + { 00755 , AID_ROOT , AID_SHELL , 0 , "system/xbin" },
 
{ 00751 , AID_ROOT , AID_SHELL , 0 , "system/apex/*/bin" },
 
{ 00751 , AID_ROOT , AID_SHELL , 0 , "system_ext/bin" },
 
{ 00751 , AID_ROOT , AID_SHELL , 0 , "system_ext/apex/*/bin" },
 
@@ - 190 , 7 + 190 , 7 @@ static const struct fs_path_config android_files [] = {
 
// the following two files are INTENTIONALLY set-uid, but they
 
// are NOT included on user builds.
 
{ 06755 , AID_ROOT , AID_ROOT , 0 , "system/xbin/procmem" },
 
- { 04750 , AID_ROOT , AID_SHELL , 0 , "system/xbin/su" },
 
+ { 06755 , AID_ROOT , AID_SHELL , 0 , "system/xbin/su" },
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
 
diff -- git a / core / jni / com_android_internal_os_Zygote . cpp
 
b / core / jni / com_android_internal_os_Zygote . cpp
 
index 9 eede83e21e5 .. 694 eec2a40ac 100644
 
--- a / core / jni / com_android_internal_os_Zygote . cpp
 
+++ b / core / jni / com_android_internal_os_Zygote . cpp
 
@@ - 656 , 6 + 656 , 7 @@ static void EnableKeepCapabilities ( fail_fn_t fail_fn ) {
 
}
 
static void DropCapabilitiesBoundingSet ( fail_fn_t fail_fn ) {
 
+ /*
 
for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;
 
if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) {
 
if (errno == EINVAL) {
 
@@ -666,6 +667,7 @@ static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
 
}
 
}
 
}
 
+ */
 
}
kernel/security/commoncap.c
 
diff -- git a / security / commoncap . c b / security / commoncap . c
 
index f86557a8e43f6 .. 19124 dd6239a1 100644
 
--- a / security / commoncap . c
 
+++ b / security / commoncap . c
 
@@ - 1147 , 12 + 1147 , 12 @@ int cap_task_setnice ( struct task_struct * p , int nice )
 
static int cap_prctl_drop ( unsigned long cap )
 
{
 
struct cred * new ;
 
-
 
+ /*
 
if (!ns_capable(current_user_ns(), CAP_SETPCAP))
 
return -EPERM;
 
if (!cap_valid(cap))
 
return -EINVAL;
 
-
 
+*/
 
new = prepare_creds ();
 
if ( ! new )
 
return - ENOMEM ;


5. user 版本需要把 su 编进系统


或者build/make/target/product/base_system.mk 
 
build/core
 
diff -- git a / target / product / base_system . mk b / target / product / base_system . mk
 
index 4569 bceff9 .. 5 c8eaaa87c 100644
 
--- a / target / product / base_system . mk
 
+++ b / target / product / base_system . mk
 
@@ - 273 , 6 + 273 , 7 @@ PRODUCT_PACKAGES += \
 
wificond \
 
wifi . rc \
 
wm \
 
+ su \
 
# VINTF data for system image
 
PRODUCT_PACKAGES += \
 
@@ - 378 , 7 + 379 , 6 @@ PRODUCT_PACKAGES_DEBUG : = \
 
ss \
 
start_with_lockagent \
 
strace \
 
- su \
 
sanitizer - status \
 
tracepath \
 
tracepath6 \


目录
相关文章
|
12天前
|
JSON Java API
Android 深入Http(5)从Retrofit源码来看Http,最新Android开发面试解答
Android 深入Http(5)从Retrofit源码来看Http,最新Android开发面试解答
|
12天前
|
API Android开发 C++
【字节跳动大牛系列教学】Android源码剖析之Framwork层消息传递
【字节跳动大牛系列教学】Android源码剖析之Framwork层消息传递
|
14天前
|
Android开发
在android源码中编译ADW_Launcher
在android源码中编译ADW_Launcher
15 2
|
14天前
|
开发工具 Android开发 git
Windows下载android2.2完整源码(转)
Windows下载android2.2完整源码(转)
30 3
|
14天前
|
Java 开发工具 Android开发
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
18 4
|
14天前
|
Java Android开发
Android12 双击power键启动相机源码解析
Android12 双击power键启动相机源码解析
29 0
|
14天前
|
Android开发
Android 高通平台集成无源码apk示例
Android 高通平台集成无源码apk示例
24 0
|
14天前
|
Android开发
Android修改默认system/bin/下可执行程序拥有者和权限,使用实例,只有root和系统app权限才能执行某个命令。
Android修改默认system/bin/下可执行程序拥有者和权限,使用实例,只有root和系统app权限才能执行某个命令。 【5月更文挑战第2天】
23 0
|
14天前
|
Java Android开发
Android 设置系统时区的源码追踪
Android 设置系统时区的源码追踪
15 1
|
Android开发
【Android 应用开发】Android 上实现非root的 Traceroute -- 非Root权限下移植可执行二进制文件 脚本文件(二)
【Android 应用开发】Android 上实现非root的 Traceroute -- 非Root权限下移植可执行二进制文件 脚本文件(二)
223 0
【Android 应用开发】Android 上实现非root的 Traceroute -- 非Root权限下移植可执行二进制文件 脚本文件(二)