mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Stop embedding magisk in magiskinit
This commit is contained in:
@ -174,6 +174,13 @@ static void magic_mount(const string &sdir, const string &ddir = "") {
|
||||
}
|
||||
}
|
||||
|
||||
static void patch_socket_name(const char *path) {
|
||||
char rstr[16];
|
||||
gen_rand_str(rstr, sizeof(rstr));
|
||||
auto bin = mmap_data::rw(path);
|
||||
bin.patch({ make_pair(MAIN_SOCKET, rstr) });
|
||||
}
|
||||
|
||||
#define ROOTMIR MIRRDIR "/system_root"
|
||||
#define MONOPOLICY "/sepolicy"
|
||||
#define NEW_INITRC "/system/etc/init/hw/init.rc"
|
||||
@ -280,9 +287,19 @@ void SARBase::patch_rootdir() {
|
||||
patch_init_rc(NEW_INITRC, ROOTOVL NEW_INITRC, tmp_dir.data());
|
||||
}
|
||||
|
||||
// Extract magisk
|
||||
{
|
||||
auto magisk = mmap_data::ro("magisk.xz");
|
||||
unlink("magisk.xz");
|
||||
int fd = xopen("magisk", O_WRONLY | O_CREAT, 0755);
|
||||
unxz(fd, magisk.buf, magisk.sz);
|
||||
close(fd);
|
||||
patch_socket_name("magisk");
|
||||
}
|
||||
|
||||
// Mount rootdir
|
||||
magic_mount(ROOTOVL);
|
||||
int dest = xopen(ROOTMNT, O_WRONLY | O_CREAT | O_CLOEXEC, 0);
|
||||
int dest = xopen(ROOTMNT, O_WRONLY | O_CREAT, 0);
|
||||
write(dest, magic_mount_list.data(), magic_mount_list.length());
|
||||
close(dest);
|
||||
|
||||
@ -335,15 +352,23 @@ void MagiskProxy::start() {
|
||||
// Backup stuffs before removing them
|
||||
self = mmap_data::ro("/sbin/magisk");
|
||||
config = mmap_data::ro("/.backup/.magisk");
|
||||
auto magisk = mmap_data::ro("/sbin/magisk.xz");
|
||||
char custom_rules_dir[64];
|
||||
custom_rules_dir[0] = '\0';
|
||||
xreadlink(TMP_RULESDIR, custom_rules_dir, sizeof(custom_rules_dir));
|
||||
|
||||
unlink("/sbin/magisk");
|
||||
unlink("/sbin/magisk.xz");
|
||||
rm_rf("/.backup");
|
||||
|
||||
setup_tmp("/sbin");
|
||||
|
||||
// Extract magisk
|
||||
int fd = xopen("/sbin/magisk", O_WRONLY | O_CREAT, 0755);
|
||||
unxz(fd, magisk.buf, magisk.sz);
|
||||
close(fd);
|
||||
patch_socket_name("/sbin/magisk");
|
||||
|
||||
// Create symlinks pointing back to /root
|
||||
recreate_sbin("/root", false);
|
||||
|
||||
|
Reference in New Issue
Block a user