Support system_ext
This commit is contained in:
parent
44b7a3c3f1
commit
8ca5a048d6
@ -33,16 +33,23 @@ extern void auto_start_magiskhide();
|
|||||||
#define SETMIR(b, part) sprintf(b, "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
#define SETMIR(b, part) sprintf(b, "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
||||||
#define SETBLK(b, part) sprintf(b, "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
#define SETBLK(b, part) sprintf(b, "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
||||||
|
|
||||||
#define mount_mirror(part, flag) { \
|
#define mount_mirror(part, flag) \
|
||||||
xstat(me->mnt_fsname, &st); \
|
else if (DIR_IS(part) && me->mnt_type != "tmpfs"sv && lstat(me->mnt_dir, &st) == 0) { \
|
||||||
SETMIR(buf1, part); \
|
SETMIR(buf1, part); \
|
||||||
SETBLK(buf2, part); \
|
SETBLK(buf2, part); \
|
||||||
mknod(buf2, (st.st_mode & S_IFMT) | 0600, st.st_rdev); \
|
mknod(buf2, S_IFBLK | 0600, st.st_dev); \
|
||||||
xmkdir(buf1, 0755); \
|
xmkdir(buf1, 0755); \
|
||||||
xmount(buf2, buf1, me->mnt_type, flag, nullptr); \
|
xmount(buf2, buf1, me->mnt_type, flag, nullptr); \
|
||||||
LOGI("mount: %s\n", buf1); \
|
LOGI("mount: %s\n", buf1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define link_mirror(part) \
|
||||||
|
SETMIR(buf1, part); \
|
||||||
|
if (access("/system/" #part, F_OK) == 0 && access(buf1, F_OK) != 0) { \
|
||||||
|
xsymlink("./system/" #part, buf1); \
|
||||||
|
LOGI("link: %s\n", buf1); \
|
||||||
|
}
|
||||||
|
|
||||||
static bool magisk_env() {
|
static bool magisk_env() {
|
||||||
LOGI("* Initializing Magisk environment\n");
|
LOGI("* Initializing Magisk environment\n");
|
||||||
|
|
||||||
@ -58,12 +65,12 @@ static bool magisk_env() {
|
|||||||
const char *alt_bin[] = { "/cache/data_adb/magisk", "/data/magisk", buf1 };
|
const char *alt_bin[] = { "/cache/data_adb/magisk", "/data/magisk", buf1 };
|
||||||
for (auto alt : alt_bin) {
|
for (auto alt : alt_bin) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(alt, &st) != -1) {
|
if (lstat(alt, &st) == 0) {
|
||||||
if (S_ISLNK(st.st_mode)) {
|
if (S_ISLNK(st.st_mode)) {
|
||||||
unlink(alt);
|
unlink(alt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rm_rf(DATABIN);;
|
rm_rf(DATABIN);
|
||||||
cp_afc(alt, DATABIN);
|
cp_afc(alt, DATABIN);
|
||||||
rm_rf(alt);
|
rm_rf(alt);
|
||||||
break;
|
break;
|
||||||
@ -81,9 +88,6 @@ static bool magisk_env() {
|
|||||||
|
|
||||||
sprintf(buf1, "%s/" MODULEMNT, MAGISKTMP.data());
|
sprintf(buf1, "%s/" MODULEMNT, MAGISKTMP.data());
|
||||||
xmkdir(buf1, 0755);
|
xmkdir(buf1, 0755);
|
||||||
// TODO: Remove. Backwards compatibility for old manager
|
|
||||||
sprintf(buf1, "%s/" INTLROOT "/img", MAGISKTMP.data());
|
|
||||||
xsymlink("./modules", buf1);
|
|
||||||
|
|
||||||
// Directories in /data/adb
|
// Directories in /data/adb
|
||||||
xmkdir(DATABIN, 0755);
|
xmkdir(DATABIN, 0755);
|
||||||
@ -92,24 +96,16 @@ static bool magisk_env() {
|
|||||||
xmkdir(SECURE_DIR "/service.d", 0755);
|
xmkdir(SECURE_DIR "/service.d", 0755);
|
||||||
|
|
||||||
LOGI("* Mounting mirrors");
|
LOGI("* Mounting mirrors");
|
||||||
bool system_as_root = false;
|
|
||||||
struct stat st;
|
|
||||||
parse_mnt("/proc/mounts", [&](mntent *me) {
|
parse_mnt("/proc/mounts", [&](mntent *me) {
|
||||||
if (DIR_IS(system_root)) {
|
struct stat st;
|
||||||
mount_mirror(system_root, MS_RDONLY);
|
if (0) {}
|
||||||
SETMIR(buf1, system);
|
mount_mirror(system, MS_RDONLY)
|
||||||
xsymlink("./system_root/system", buf1);
|
mount_mirror(vendor, MS_RDONLY)
|
||||||
LOGI("link: %s\n", buf1);
|
mount_mirror(product, MS_RDONLY)
|
||||||
system_as_root = true;
|
mount_mirror(system_ext, MS_RDONLY)
|
||||||
} else if (!system_as_root && DIR_IS(system)) {
|
mount_mirror(data, 0)
|
||||||
mount_mirror(system, MS_RDONLY);
|
else if (SDK_INT >= 24 && DIR_IS(proc) && !strstr(me->mnt_opts, "hidepid=2")) {
|
||||||
} else if (DIR_IS(vendor)) {
|
|
||||||
mount_mirror(vendor, MS_RDONLY);
|
|
||||||
} else if (DIR_IS(product)) {
|
|
||||||
mount_mirror(product, MS_RDONLY);
|
|
||||||
} else if (DIR_IS(data) && me->mnt_type != "tmpfs"sv) {
|
|
||||||
mount_mirror(data, 0);
|
|
||||||
} else if (SDK_INT >= 24 && DIR_IS(proc) && !strstr(me->mnt_opts, "hidepid=2")) {
|
|
||||||
xmount(nullptr, "/proc", nullptr, MS_REMOUNT, "hidepid=2,gid=3009");
|
xmount(nullptr, "/proc", nullptr, MS_REMOUNT, "hidepid=2,gid=3009");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -117,20 +113,12 @@ static bool magisk_env() {
|
|||||||
SETMIR(buf1, system);
|
SETMIR(buf1, system);
|
||||||
SETMIR(buf2, system_root);
|
SETMIR(buf2, system_root);
|
||||||
if (access(buf1, F_OK) != 0 && access(buf2, F_OK) == 0) {
|
if (access(buf1, F_OK) != 0 && access(buf2, F_OK) == 0) {
|
||||||
// Pre-init mirrors
|
|
||||||
xsymlink("./system_root/system", buf1);
|
xsymlink("./system_root/system", buf1);
|
||||||
LOGI("link: %s\n", buf1);
|
LOGI("link: %s\n", buf1);
|
||||||
}
|
}
|
||||||
SETMIR(buf1, vendor);
|
link_mirror(vendor);
|
||||||
if (access(buf1, F_OK) != 0) {
|
link_mirror(product);
|
||||||
xsymlink("./system/vendor", buf1);
|
link_mirror(system_ext);
|
||||||
LOGI("link: %s\n", buf1);
|
|
||||||
}
|
|
||||||
SETMIR(buf1, product);
|
|
||||||
if (access("/system/product", F_OK) == 0 && access(buf1, F_OK) != 0) {
|
|
||||||
xsymlink("./system/product", buf1);
|
|
||||||
LOGI("link: %s\n", buf1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable/remove magiskhide, resetprop
|
// Disable/remove magiskhide, resetprop
|
||||||
if (SDK_INT < 19) {
|
if (SDK_INT < 19) {
|
||||||
|
Loading…
Reference in New Issue
Block a user