1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| void MagiskInit::patch_ro_root() { mount_list.emplace_back("/data"); parse_config_file();
string tmp_dir; if (access("/sbin", F_OK) == 0) { tmp_dir = "/sbin"; } else { tmp_dir = "/debug_ramdisk"; xmkdir("/data/debug_ramdisk", 0); xmount("/debug_ramdisk", "/data/debug_ramdisk", nullptr, MS_MOVE, nullptr); } setup_tmp(tmp_dir.data()); chdir(tmp_dir.data());
if (tmp_dir == "/sbin") { xmkdir(ROOTMIR, 0755); xmount("/", ROOTMIR, nullptr, MS_BIND, nullptr); recreate_sbin(ROOTMIR "/sbin", true); xumount2(ROOTMIR, MNT_DETACH); } else { xmount("/data/debug_ramdisk", "/debug_ramdisk", nullptr, MS_MOVE, nullptr); rmdir("/data/debug_ramdisk"); }
xrename("overlay.d", ROOTOVL);
extern bool avd_hack; if (avd_hack) { int src = xopen("/init", O_RDONLY | O_CLOEXEC); mmap_data init("/init"); for (size_t off : init.patch("android,fstab", "xxx")) { LOGD("Patch @ %08zX [android,fstab] -> [xxx]\n", off); } int dest = xopen(ROOTOVL "/init", O_CREAT | O_WRONLY | O_CLOEXEC, 0); xwrite(dest, init.buf(), init.sz()); fclone_attr(src, dest); close(src); close(dest); }
load_overlay_rc(ROOTOVL); if (access(ROOTOVL "/sbin", F_OK) == 0) { mv_path(ROOTOVL "/sbin", "."); }
if (access(NEW_INITRC, F_OK) == 0) { xmkdirs(dirname(ROOTOVL NEW_INITRC), 0755); patch_init_rc(NEW_INITRC, ROOTOVL NEW_INITRC, tmp_dir.data()); } else { patch_init_rc("/init.rc", ROOTOVL "/init.rc", tmp_dir.data()); }
extract_files(false);
if (access("/sepolicy.unlocked", F_OK) == 0) { patch_sepolicy("/sepolicy.unlocked", ROOTOVL "/sepolicy.unlocked"); } else if ((access(SPLIT_PLAT_CIL, F_OK) != 0 && access("/sepolicy", F_OK) == 0) || !hijack_sepolicy()) { patch_sepolicy("/sepolicy", ROOTOVL "/sepolicy"); }
magic_mount(ROOTOVL); int dest = xopen(ROOTMNT, O_WRONLY | O_CREAT, 0); write(dest, magic_mount_list.data(), magic_mount_list.length()); close(dest);
chdir("/"); }
|