Better bytes support in C++

This commit is contained in:
topjohnwu
2023-06-06 17:11:42 -07:00
parent f8c38eab74
commit 5e2ef1b7f4
12 changed files with 89 additions and 75 deletions
+3 -1
View File
@@ -244,7 +244,9 @@ void MagiskInit::patch_ro_root() {
int src = xopen("/init", O_RDONLY | O_CLOEXEC);
mmap_data init("/init");
// Force disable early mount on original init
init.patch({ make_pair("android,fstab", "xxx") });
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);
+6 -2
View File
@@ -13,7 +13,9 @@ void FirstStageInit::prepare() {
restore_ramdisk_init();
auto init = mmap_data("/init", true);
// Redirect original init to magiskinit
init.patch({ make_pair(INIT_PATH, REDIR_PATH) });
for (size_t off : init.patch(INIT_PATH, REDIR_PATH)) {
LOGD("Patch @ %08zX [" INIT_PATH "] -> [" REDIR_PATH "]\n", off);
}
}
void LegacySARInit::first_stage_prep() {
@@ -22,7 +24,9 @@ void LegacySARInit::first_stage_prep() {
int dest = xopen("/data/init", O_CREAT | O_WRONLY, 0);
{
mmap_data init("/init");
init.patch({ make_pair(INIT_PATH, REDIR_PATH) });
for (size_t off : init.patch(INIT_PATH, REDIR_PATH)) {
LOGD("Patch @ %08zX [" INIT_PATH "] -> [" REDIR_PATH "]\n", off);
}
write(dest, init.buf(), init.sz());
fclone_attr(src, dest);
close(dest);