Android源码定制(一) 制作完全Root版本[已验证]

感谢"污师傅"对Android源码编译的指导~ 撒花!

感觉“强哥”提供那么棒棒的教材~ (报名可以联系我)

本博客几乎完全抄袭https://www.jianshu.com/p/b7b0361aca34,只是自己手写了一遍~做个记录


广告:学习爬虫进阶, “补全浏览器环境”、“网页风控绕过”、“Android抓不到包”、“算法搞不定”联系小胖,报名“大数据安全”班级,让你快速学会上述风控对抗技能~

微信:cjh-18888 (小胖)

0. 操作环境

编译版本编译分支目标设备目标代号操作系统
QP1A.190711.019android-10.0.0_r1Pixelsailfishubuntu18.04

1. 修改文件

>1. su.cpp

修改/aosp10/system/extras/su/su.cpp

// 注释掉第83-84行
// uid_t current_uid = getuid();
// if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");

>2. fs_config.cpp

修改/aosp10/system/core/libcutils/fs_config.cpp

// the following files have enhanced capabilities and ARE included
// in user builds.
// 添加下面代码至212行处,注意标点符号不要漏掉
{ 06755, AID_ROOT,      AID_ROOT,      0, "system/bin/su" },

>3. com_android_internal_os_Zygote.cpp

/aosp10/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

// 修改542行处,注释掉DropCapabilitiesBoundingSet方法体
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) {
//         ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
//               "your kernel is compiled with file capabilities support");
//       } else {
//         fail_fn(CREATE_ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s", i, strerror(errno)));
//       }
//     }
//   }
}

>4.main.cpp

修改/aosp10/system/core/adb/daemon/main.cpp

// 修改should_drop_capabilities_bounding_set返回false
static bool should_drop_capabilities_bounding_set() {
    if (ALLOW_ADBD_ROOT || is_device_unlocked()) {
        if (__android_log_is_debuggable()) {
            return false;
        }
    }
//    return true;
    return false;
}

>5. selinux.cpp

修改/aosp10/system/core/init/selinux.cpp

// 修改IsEnforcing方法返回false, 注释掉StatusFromCmdline方法
// EnforcingStatus StatusFromCmdline() {
//     EnforcingStatus status = SELINUX_ENFORCING;

//     import_kernel_cmdline(false,
//                           [&](const std::string& key, const std::string& value, bool in_qemu) {
//                               if (key == "androidboot.selinux" && value == "permissive") {
//                                   status = SELINUX_PERMISSIVE;
//                               }
//                           });

//     return status;
// }

bool IsEnforcing() {
    // if (ALLOW_PERMISSIVE_SELINUX) {
        // return StatusFromCmdline() == SELINUX_ENFORCING;
    // }
    // return true;
    return false;
}

2. 编译刷机测试

切换到源码编译目录

cd /aosp10/
//因为修改了Android原有API的 (frameworks/base/下面的代码),须要update frameworks/base/api/current.txt。不然编译被中断
make update-api 
source build/envsetup.sh
lunch 16
make -j100
// make -j100 , 是使用后100线程操作,使劲燥~

当看到#### build completed successfully (05:57 (mm:ss)) ####字符串的时候,我们的源码就编译好了~

然后就可以去刷机了~

adb reboot bootloader
cd ~/aosp10/out/target/product/sailfish
fastboot flashall -w
// -w 是双清
添加微信交流群, 联系微信:cjh-18888