2019-05-27 07:29:43 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2019-07-16 08:08:28 +00:00
|
|
|
#include <vector>
|
2020-04-19 09:35:28 +00:00
|
|
|
#include <libgen.h>
|
2019-05-27 07:29:43 +00:00
|
|
|
|
2020-03-09 08:50:30 +00:00
|
|
|
#include <magisk.hpp>
|
|
|
|
#include <magiskpolicy.hpp>
|
|
|
|
#include <utils.hpp>
|
2020-04-12 12:34:56 +00:00
|
|
|
#include <socket.hpp>
|
2019-05-27 07:29:43 +00:00
|
|
|
|
2020-03-09 08:50:30 +00:00
|
|
|
#include "init.hpp"
|
|
|
|
#include "magiskrc.inc"
|
2019-05-27 07:29:43 +00:00
|
|
|
|
|
|
|
#ifdef USE_64BIT
|
|
|
|
#define LIBNAME "lib64"
|
|
|
|
#else
|
|
|
|
#define LIBNAME "lib"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2020-04-26 06:19:36 +00:00
|
|
|
static vector<string> rc_list;
|
2019-07-16 08:08:28 +00:00
|
|
|
|
2020-04-19 09:35:28 +00:00
|
|
|
static void patch_init_rc(const char *src, const char *dest, const char *tmp_dir) {
|
|
|
|
FILE *rc = xfopen(dest, "we");
|
|
|
|
file_readline(src, [=](string_view line) -> bool {
|
2019-06-26 06:31:59 +00:00
|
|
|
// Do not start vaultkeeper
|
|
|
|
if (str_contains(line, "start vaultkeeper")) {
|
|
|
|
LOGD("Remove vaultkeeper\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Do not run flash_recovery
|
|
|
|
if (str_starts(line, "service flash_recovery")) {
|
|
|
|
LOGD("Remove flash_recovery\n");
|
|
|
|
fprintf(rc, "service flash_recovery /system/bin/xxxxx\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Else just write the line
|
|
|
|
fprintf(rc, "%s", line.data());
|
|
|
|
return true;
|
|
|
|
});
|
2019-07-16 08:08:28 +00:00
|
|
|
|
|
|
|
fprintf(rc, "\n");
|
|
|
|
|
|
|
|
// Inject custom rc scripts
|
2020-04-26 06:19:36 +00:00
|
|
|
for (auto &script : rc_list) {
|
|
|
|
// Replace template arguments of rc scripts with dynamic paths
|
|
|
|
replace_all(script, "${MAGISKTMP}", tmp_dir);
|
|
|
|
fprintf(rc, "\n%s\n", script.data());
|
|
|
|
}
|
2019-07-16 08:08:28 +00:00
|
|
|
rc_list.clear();
|
|
|
|
|
|
|
|
// Inject Magisk rc scripts
|
2019-07-15 04:56:21 +00:00
|
|
|
char pfd_svc[16], ls_svc[16], bc_svc[16];
|
2019-07-15 00:41:51 +00:00
|
|
|
gen_rand_str(pfd_svc, sizeof(pfd_svc));
|
|
|
|
gen_rand_str(ls_svc, sizeof(ls_svc));
|
|
|
|
gen_rand_str(bc_svc, sizeof(bc_svc));
|
2019-06-26 06:31:59 +00:00
|
|
|
LOGD("Inject magisk services: [%s] [%s] [%s]\n", pfd_svc, ls_svc, bc_svc);
|
2020-04-26 06:19:36 +00:00
|
|
|
fprintf(rc, MAGISK_RC, tmp_dir, pfd_svc, ls_svc, bc_svc);
|
2020-04-19 09:35:28 +00:00
|
|
|
|
|
|
|
fclose(rc);
|
|
|
|
clone_attr(src, dest);
|
2019-06-26 06:31:59 +00:00
|
|
|
}
|
2019-05-27 07:29:43 +00:00
|
|
|
|
2020-04-01 11:39:28 +00:00
|
|
|
static void load_overlay_rc(const char *overlay) {
|
|
|
|
auto dir = open_dir(overlay);
|
|
|
|
if (!dir) return;
|
|
|
|
|
|
|
|
int dfd = dirfd(dir.get());
|
2019-07-16 08:08:28 +00:00
|
|
|
// Do not allow overwrite init.rc
|
2020-04-01 11:39:28 +00:00
|
|
|
unlinkat(dfd, "init.rc", 0);
|
2020-04-26 06:19:36 +00:00
|
|
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
2019-07-16 08:08:28 +00:00
|
|
|
if (strend(entry->d_name, ".rc") == 0) {
|
|
|
|
LOGD("Found rc script [%s]\n", entry->d_name);
|
2020-04-01 11:39:28 +00:00
|
|
|
int rc = xopenat(dfd, entry->d_name, O_RDONLY | O_CLOEXEC);
|
2020-04-26 06:19:36 +00:00
|
|
|
rc_list.push_back(fd_full_read(rc));
|
2019-07-16 08:08:28 +00:00
|
|
|
close(rc);
|
2020-04-01 11:39:28 +00:00
|
|
|
unlinkat(dfd, entry->d_name, 0);
|
2019-07-16 08:08:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 04:34:02 +00:00
|
|
|
bool MagiskInit::patch_sepolicy(const char *file) {
|
2019-10-20 11:13:03 +00:00
|
|
|
bool patch_init = false;
|
2020-05-21 13:48:02 +00:00
|
|
|
sepolicy *sepol = nullptr;
|
2019-05-27 07:29:43 +00:00
|
|
|
|
|
|
|
if (access(SPLIT_PLAT_CIL, R_OK) == 0) {
|
|
|
|
LOGD("sepol: split policy\n");
|
2019-10-20 11:13:03 +00:00
|
|
|
patch_init = true;
|
2019-05-27 07:29:43 +00:00
|
|
|
} else if (access("/sepolicy", R_OK) == 0) {
|
|
|
|
LOGD("sepol: monolithic policy\n");
|
2020-05-21 13:48:02 +00:00
|
|
|
sepol = sepolicy::from_file("/sepolicy");
|
2019-05-27 07:29:43 +00:00
|
|
|
} else {
|
|
|
|
LOGD("sepol: no selinux\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-20 05:15:12 +00:00
|
|
|
if (access(SELINUX_VERSION, F_OK) != 0) {
|
|
|
|
// Mount selinuxfs to communicate with kernel
|
|
|
|
xmount("selinuxfs", SELINUX_MNT, "selinuxfs", 0, nullptr);
|
|
|
|
mount_list.emplace_back(SELINUX_MNT);
|
|
|
|
}
|
2019-10-20 11:13:03 +00:00
|
|
|
|
|
|
|
if (patch_init)
|
2020-05-21 13:48:02 +00:00
|
|
|
sepol = sepolicy::from_split();
|
2019-10-20 11:13:03 +00:00
|
|
|
|
2020-05-21 13:48:02 +00:00
|
|
|
sepol->magisk_rules();
|
2019-12-13 11:05:12 +00:00
|
|
|
|
|
|
|
// Custom rules
|
2020-11-03 07:20:38 +00:00
|
|
|
if (!custom_rules_dir.empty()) {
|
|
|
|
if (auto dir = open_dir(custom_rules_dir.data())) {
|
|
|
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
|
|
|
auto rule = custom_rules_dir + "/" + entry->d_name + "/sepolicy.rule";
|
|
|
|
if (access(rule.data(), R_OK) == 0) {
|
|
|
|
LOGD("Loading custom sepolicy patch: %s\n", rule.data());
|
|
|
|
sepol->load_rule_file(rule.data());
|
|
|
|
}
|
2019-12-13 11:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 13:48:02 +00:00
|
|
|
sepol->to_file(file);
|
|
|
|
delete sepol;
|
2019-05-27 07:29:43 +00:00
|
|
|
|
|
|
|
// Remove OnePlus stupid debug sepolicy and use our own
|
|
|
|
if (access("/sepolicy_debug", F_OK) == 0) {
|
|
|
|
unlink("/sepolicy_debug");
|
|
|
|
link("/sepolicy", "/sepolicy_debug");
|
|
|
|
}
|
|
|
|
|
2019-10-20 11:13:03 +00:00
|
|
|
return patch_init;
|
2019-05-27 07:29:43 +00:00
|
|
|
}
|
2019-06-22 10:14:33 +00:00
|
|
|
|
2020-01-09 15:42:27 +00:00
|
|
|
static void recreate_sbin(const char *mirror, bool use_bind_mount) {
|
|
|
|
auto dp = xopen_dir(mirror);
|
|
|
|
int src = dirfd(dp.get());
|
|
|
|
char buf[4096];
|
|
|
|
for (dirent *entry; (entry = xreaddir(dp.get()));) {
|
|
|
|
string sbin_path = "/sbin/"s + entry->d_name;
|
2019-12-06 20:31:49 +00:00
|
|
|
struct stat st;
|
|
|
|
fstatat(src, entry->d_name, &st, AT_SYMLINK_NOFOLLOW);
|
|
|
|
if (S_ISLNK(st.st_mode)) {
|
|
|
|
xreadlinkat(src, entry->d_name, buf, sizeof(buf));
|
2020-01-09 15:42:27 +00:00
|
|
|
xsymlink(buf, sbin_path.data());
|
2019-12-06 20:31:49 +00:00
|
|
|
} else {
|
|
|
|
sprintf(buf, "%s/%s", mirror, entry->d_name);
|
|
|
|
if (use_bind_mount) {
|
2020-01-09 15:42:27 +00:00
|
|
|
auto mode = st.st_mode & 0777;
|
2019-12-06 20:31:49 +00:00
|
|
|
// Create dummy
|
|
|
|
if (S_ISDIR(st.st_mode))
|
2020-01-09 15:42:27 +00:00
|
|
|
xmkdir(sbin_path.data(), mode);
|
2019-12-06 20:31:49 +00:00
|
|
|
else
|
2020-01-09 15:42:27 +00:00
|
|
|
close(xopen(sbin_path.data(), O_CREAT | O_WRONLY | O_CLOEXEC, mode));
|
2019-12-06 20:31:49 +00:00
|
|
|
|
2020-01-09 15:42:27 +00:00
|
|
|
xmount(buf, sbin_path.data(), nullptr, MS_BIND, nullptr);
|
|
|
|
} else {
|
|
|
|
xsymlink(buf, sbin_path.data());
|
|
|
|
}
|
2019-12-06 20:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 05:16:20 +00:00
|
|
|
static string magic_mount_list;
|
2019-07-17 06:54:52 +00:00
|
|
|
|
2020-02-21 08:49:58 +00:00
|
|
|
static void magic_mount(const string &sdir, const string &ddir = "") {
|
|
|
|
auto dir = xopen_dir(sdir.data());
|
2020-04-19 09:35:28 +00:00
|
|
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
2020-02-21 08:49:58 +00:00
|
|
|
string src = sdir + "/" + entry->d_name;
|
|
|
|
string dest = ddir + "/" + entry->d_name;
|
2019-07-16 08:08:28 +00:00
|
|
|
if (access(dest.data(), F_OK) == 0) {
|
|
|
|
if (entry->d_type == DT_DIR) {
|
|
|
|
// Recursive
|
2020-02-21 08:49:58 +00:00
|
|
|
magic_mount(src, dest);
|
2019-07-16 08:08:28 +00:00
|
|
|
} else {
|
|
|
|
LOGD("Mount [%s] -> [%s]\n", src.data(), dest.data());
|
|
|
|
xmount(src.data(), dest.data(), nullptr, MS_BIND, nullptr);
|
2019-11-19 05:16:20 +00:00
|
|
|
magic_mount_list += dest;
|
|
|
|
magic_mount_list += '\n';
|
2019-07-16 08:08:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 09:35:28 +00:00
|
|
|
#define ROOTMIR MIRRDIR "/system_root"
|
|
|
|
#define ROOTBLK BLOCKDIR "/system_root"
|
2020-04-12 12:34:56 +00:00
|
|
|
#define MONOPOLICY "/sepolicy"
|
|
|
|
#define LIBSELINUX "/system/" LIBNAME "/libselinux.so"
|
2020-04-19 09:35:28 +00:00
|
|
|
#define NEW_INITRC "/system/etc/init/hw/init.rc"
|
2020-04-12 12:34:56 +00:00
|
|
|
|
2019-09-22 09:20:51 +00:00
|
|
|
void SARBase::patch_rootdir() {
|
2020-04-19 06:19:19 +00:00
|
|
|
char tmp_dir[16];
|
|
|
|
const char *sepol;
|
2020-04-19 01:50:25 +00:00
|
|
|
|
2020-04-19 06:19:19 +00:00
|
|
|
char *p;
|
|
|
|
if (access("/sbin", F_OK) == 0) {
|
|
|
|
p = tmp_dir + sprintf(tmp_dir, "%s", "/sbin");
|
|
|
|
sepol = "/sbin/.se";
|
|
|
|
} else {
|
2020-04-19 09:35:28 +00:00
|
|
|
p = tmp_dir + sprintf(tmp_dir, "%s", "/dev/");
|
|
|
|
p += gen_rand_str(p, 8);
|
2020-04-19 06:19:19 +00:00
|
|
|
xmkdir(tmp_dir, 0);
|
|
|
|
sepol = "/dev/.se";
|
|
|
|
}
|
2020-04-12 12:34:56 +00:00
|
|
|
|
2020-10-27 03:46:15 +00:00
|
|
|
setup_tmp(tmp_dir);
|
2020-04-19 01:50:25 +00:00
|
|
|
chdir(tmp_dir);
|
2020-11-03 07:20:38 +00:00
|
|
|
mount_rules_dir(BLOCKDIR, MIRRDIR);
|
2019-06-24 08:21:33 +00:00
|
|
|
|
|
|
|
// Mount system_root mirror
|
2020-04-01 05:41:25 +00:00
|
|
|
struct stat st;
|
|
|
|
xstat("/", &st);
|
2019-12-09 07:44:49 +00:00
|
|
|
xmkdir(ROOTMIR, 0755);
|
2020-04-01 05:41:25 +00:00
|
|
|
mknod(ROOTBLK, S_IFBLK | 0600, st.st_dev);
|
2020-04-19 01:50:25 +00:00
|
|
|
strcpy(p, "/" ROOTBLK);
|
|
|
|
if (xmount(tmp_dir, ROOTMIR, "ext4", MS_RDONLY, nullptr))
|
|
|
|
xmount(tmp_dir, ROOTMIR, "erofs", MS_RDONLY, nullptr);
|
|
|
|
*p = '\0';
|
2019-06-24 08:21:33 +00:00
|
|
|
|
2020-04-12 12:34:56 +00:00
|
|
|
// Recreate original sbin structure if necessary
|
2020-04-19 01:50:25 +00:00
|
|
|
if (tmp_dir == "/sbin"sv)
|
2020-04-12 12:34:56 +00:00
|
|
|
recreate_sbin(ROOTMIR "/sbin", true);
|
2019-06-26 04:34:02 +00:00
|
|
|
|
2019-07-16 08:08:28 +00:00
|
|
|
// Patch init
|
2019-12-06 20:31:49 +00:00
|
|
|
int src = xopen("/init", O_RDONLY | O_CLOEXEC);
|
2020-09-02 09:49:32 +00:00
|
|
|
auto init = raw_data::read(src);
|
|
|
|
int patch_count = init.patch({
|
2020-05-04 05:49:54 +00:00
|
|
|
make_pair(SPLIT_PLAT_CIL, "xxx"), /* Force loading monolithic sepolicy */
|
|
|
|
make_pair(MONOPOLICY, sepol) /* Redirect /sepolicy to custom path */
|
|
|
|
});
|
2019-07-16 08:08:28 +00:00
|
|
|
xmkdir(ROOTOVL, 0);
|
2020-05-04 05:49:54 +00:00
|
|
|
int dest = xopen(ROOTOVL "/init", O_CREAT | O_WRONLY | O_CLOEXEC, 0);
|
2019-07-16 08:08:28 +00:00
|
|
|
xwrite(dest, init.buf, init.sz);
|
2020-04-19 09:35:28 +00:00
|
|
|
fclone_attr(src, dest);
|
|
|
|
close(src);
|
2019-06-26 04:34:02 +00:00
|
|
|
close(dest);
|
|
|
|
|
2020-05-04 05:49:54 +00:00
|
|
|
if (patch_count != 2 && access(LIBSELINUX, F_OK) == 0) {
|
2019-06-26 04:34:02 +00:00
|
|
|
// init is dynamically linked, need to patch libselinux
|
2020-09-02 09:49:32 +00:00
|
|
|
auto lib = raw_data::read(LIBSELINUX);
|
|
|
|
lib.patch({make_pair(MONOPOLICY, sepol)});
|
2020-04-19 09:35:28 +00:00
|
|
|
xmkdirs(dirname(ROOTOVL LIBSELINUX), 0755);
|
2020-05-04 05:49:54 +00:00
|
|
|
dest = xopen(ROOTOVL LIBSELINUX, O_CREAT | O_WRONLY | O_CLOEXEC, 0);
|
2019-07-16 08:08:28 +00:00
|
|
|
xwrite(dest, lib.buf, lib.sz);
|
2019-06-26 04:34:02 +00:00
|
|
|
close(dest);
|
2020-04-19 09:35:28 +00:00
|
|
|
clone_attr(LIBSELINUX, ROOTOVL LIBSELINUX);
|
2019-06-26 04:34:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 08:08:28 +00:00
|
|
|
// sepolicy
|
2020-04-19 06:19:19 +00:00
|
|
|
patch_sepolicy(sepol);
|
2019-06-26 06:31:59 +00:00
|
|
|
|
2020-04-26 06:19:36 +00:00
|
|
|
// Restore backup files
|
2020-04-12 12:34:56 +00:00
|
|
|
struct sockaddr_un sun;
|
|
|
|
int sockfd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
|
|
if (connect(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET)) == 0) {
|
2020-04-20 05:15:12 +00:00
|
|
|
LOGD("ACK init daemon to write backup files\n");
|
|
|
|
// Let daemon know where tmp_dir is
|
2020-04-19 01:50:25 +00:00
|
|
|
write_string(sockfd, tmp_dir);
|
2020-04-20 05:15:12 +00:00
|
|
|
// Wait for daemon to finish restoring files
|
2020-04-01 11:39:28 +00:00
|
|
|
int ack;
|
2020-04-12 12:34:56 +00:00
|
|
|
read(sockfd, &ack, sizeof(ack));
|
2020-04-01 11:39:28 +00:00
|
|
|
} else {
|
|
|
|
LOGD("Restore backup files locally\n");
|
|
|
|
restore_folder(ROOTOVL, overlays);
|
|
|
|
overlays.clear();
|
|
|
|
}
|
2020-04-12 12:34:56 +00:00
|
|
|
close(sockfd);
|
2020-04-26 06:19:36 +00:00
|
|
|
|
|
|
|
// Handle overlay.d
|
|
|
|
load_overlay_rc(ROOTOVL);
|
2020-04-01 11:39:28 +00:00
|
|
|
if (access(ROOTOVL "/sbin", F_OK) == 0) {
|
2020-05-07 09:30:43 +00:00
|
|
|
// Move files in overlay.d/sbin into tmp_dir
|
|
|
|
mv_path(ROOTOVL "/sbin", ".");
|
2019-07-16 08:08:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Patch init.rc
|
2020-04-19 09:35:28 +00:00
|
|
|
if (access("/init.rc", F_OK) == 0) {
|
|
|
|
patch_init_rc("/init.rc", ROOTOVL "/init.rc", tmp_dir);
|
|
|
|
} else {
|
|
|
|
// Android 11's new init.rc
|
|
|
|
xmkdirs(dirname(ROOTOVL NEW_INITRC), 0755);
|
|
|
|
patch_init_rc(NEW_INITRC, ROOTOVL NEW_INITRC, tmp_dir);
|
|
|
|
}
|
2019-07-16 08:08:28 +00:00
|
|
|
|
|
|
|
// Mount rootdir
|
2020-02-21 08:49:58 +00:00
|
|
|
magic_mount(ROOTOVL);
|
2020-04-12 12:34:56 +00:00
|
|
|
dest = xopen(ROOTMNT, O_WRONLY | O_CREAT | O_CLOEXEC, 0);
|
2019-11-19 05:16:20 +00:00
|
|
|
write(dest, magic_mount_list.data(), magic_mount_list.length());
|
2019-07-17 06:54:52 +00:00
|
|
|
close(dest);
|
2020-04-12 12:34:56 +00:00
|
|
|
|
|
|
|
chdir("/");
|
2019-06-24 08:21:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 07:20:38 +00:00
|
|
|
#define TMP_MNTDIR "/dev/mnt"
|
|
|
|
#define TMP_RULESDIR "/.backup/.sepolicy.rules"
|
|
|
|
|
|
|
|
void RootFSInit::setup_rootfs() {
|
|
|
|
// Handle custom sepolicy rules
|
|
|
|
xmkdir(TMP_MNTDIR, 0755);
|
|
|
|
mount_rules_dir("/dev/block", TMP_MNTDIR);
|
|
|
|
// Preserve custom rule path
|
|
|
|
if (!custom_rules_dir.empty()) {
|
|
|
|
string rules_dir = "./" + custom_rules_dir.substr(sizeof(TMP_MNTDIR));
|
|
|
|
xsymlink(rules_dir.data(), TMP_RULESDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (patch_sepolicy("/sepolicy")) {
|
|
|
|
auto init = raw_data::mmap_rw("/init");
|
|
|
|
init.patch({ make_pair(SPLIT_PLAT_CIL, "xxx") });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle overlays
|
|
|
|
if (access("/overlay.d", F_OK) == 0) {
|
|
|
|
LOGD("Merge overlay.d\n");
|
|
|
|
load_overlay_rc("/overlay.d");
|
|
|
|
mv_path("/overlay.d", "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
patch_init_rc("/init.rc", "/init.p.rc", "/sbin");
|
|
|
|
rename("/init.p.rc", "/init.rc");
|
|
|
|
|
|
|
|
// Create hardlink mirror of /sbin to /root
|
|
|
|
mkdir("/root", 0750);
|
|
|
|
clone_attr("/sbin", "/root");
|
|
|
|
link_path("/sbin", "/root");
|
|
|
|
|
|
|
|
// Dump magiskinit as magisk
|
|
|
|
int fd = xopen("/sbin/magisk", O_WRONLY | O_CREAT, 0755);
|
|
|
|
write(fd, self.buf, self.sz);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2020-10-27 03:46:15 +00:00
|
|
|
void MagiskProxy::start() {
|
2020-11-03 07:20:38 +00:00
|
|
|
// Mount rootfs as rw to do post-init rootfs patches
|
|
|
|
xmount(nullptr, "/", nullptr, MS_REMOUNT, nullptr);
|
|
|
|
|
|
|
|
// Backup stuffs before removing them
|
2020-10-27 03:46:15 +00:00
|
|
|
self = raw_data::read("/sbin/magisk");
|
|
|
|
config = raw_data::read("/.backup/.magisk");
|
2020-11-03 07:20:38 +00:00
|
|
|
char custom_rules_dir[64];
|
|
|
|
custom_rules_dir[0] = '\0';
|
|
|
|
xreadlink(TMP_RULESDIR, custom_rules_dir, sizeof(custom_rules_dir));
|
2019-06-22 10:14:33 +00:00
|
|
|
|
|
|
|
unlink("/sbin/magisk");
|
|
|
|
rm_rf("/.backup");
|
|
|
|
|
2020-10-27 03:46:15 +00:00
|
|
|
setup_tmp("/sbin");
|
2019-06-22 10:14:33 +00:00
|
|
|
|
|
|
|
// Create symlinks pointing back to /root
|
2020-01-09 15:42:27 +00:00
|
|
|
recreate_sbin("/root", false);
|
2019-06-22 10:14:33 +00:00
|
|
|
|
2020-11-03 07:20:38 +00:00
|
|
|
if (custom_rules_dir[0])
|
|
|
|
xsymlink(custom_rules_dir, "/sbin/" RULESDIR);
|
|
|
|
|
|
|
|
// Tell magiskd to remount rootfs
|
2019-06-22 10:14:33 +00:00
|
|
|
setenv("REMOUNT_ROOT", "1", 1);
|
|
|
|
execv("/sbin/magisk", argv);
|
|
|
|
}
|