mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 09:27:47 +00:00
parent
39e714c6d8
commit
548d70f30c
@ -29,21 +29,31 @@ bool zygisk_enabled = false;
|
|||||||
#define SETMIR(b, part) snprintf(b, sizeof(b), "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
#define SETMIR(b, part) snprintf(b, sizeof(b), "%s/" MIRRDIR "/" #part, MAGISKTMP.data())
|
||||||
#define SETBLK(b, part) snprintf(b, sizeof(b), "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
#define SETBLK(b, part) snprintf(b, sizeof(b), "%s/" BLOCKDIR "/" #part, MAGISKTMP.data())
|
||||||
|
|
||||||
#define do_mount_mirror(part, flag) {\
|
#define do_mount_mirror(part) { \
|
||||||
SETMIR(buf1, part); \
|
SETMIR(buf1, part); \
|
||||||
SETBLK(buf2, part); \
|
SETBLK(buf2, part); \
|
||||||
unlink(buf2); \
|
unlink(buf2); \
|
||||||
mknod(buf2, S_IFBLK | 0600, st.st_dev); \
|
mknod(buf2, S_IFBLK | 0600, st.st_dev); \
|
||||||
xmkdir(buf1, 0755); \
|
xmkdir(buf1, 0755); \
|
||||||
xmount(buf2, buf1, me->mnt_type, flag, nullptr); \
|
int flags = 0; \
|
||||||
LOGI("mount: %s\n", buf1); \
|
auto opts = split_ro(me->mnt_opts, ",");\
|
||||||
|
for (string_view s : opts) { \
|
||||||
|
if (s == "ro") { \
|
||||||
|
flags |= MS_RDONLY; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
xmount(buf2, buf1, me->mnt_type, flags, nullptr); \
|
||||||
|
LOGI("mount: %s\n", buf1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define mount_mirror(part, flag) \
|
#define mount_mirror(part) \
|
||||||
if (MNT_DIR_IS("/" #part) && !MNT_TYPE_IS("tmpfs") && !MNT_TYPE_IS("overlay") && \
|
if (MNT_DIR_IS("/" #part) \
|
||||||
lstat(me->mnt_dir, &st) == 0) { \
|
&& !MNT_TYPE_IS("tmpfs") \
|
||||||
do_mount_mirror(part, flag); \
|
&& !MNT_TYPE_IS("overlay") \
|
||||||
break; \
|
&& lstat(me->mnt_dir, &st) == 0) { \
|
||||||
|
do_mount_mirror(part); \
|
||||||
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define link_mirror(part) \
|
#define link_mirror(part) \
|
||||||
@ -73,11 +83,11 @@ static void mount_mirrors() {
|
|||||||
parse_mnt("/proc/mounts", [&](mntent *me) {
|
parse_mnt("/proc/mounts", [&](mntent *me) {
|
||||||
struct stat st{};
|
struct stat st{};
|
||||||
do {
|
do {
|
||||||
mount_mirror(system, MS_RDONLY)
|
mount_mirror(system)
|
||||||
mount_mirror(vendor, MS_RDONLY)
|
mount_mirror(vendor)
|
||||||
mount_mirror(product, MS_RDONLY)
|
mount_mirror(product)
|
||||||
mount_mirror(system_ext, MS_RDONLY)
|
mount_mirror(system_ext)
|
||||||
mount_mirror(data, 0)
|
mount_mirror(data)
|
||||||
link_orig(cache)
|
link_orig(cache)
|
||||||
link_orig(metadata)
|
link_orig(metadata)
|
||||||
link_orig(persist)
|
link_orig(persist)
|
||||||
@ -96,7 +106,7 @@ static void mount_mirrors() {
|
|||||||
parse_mnt("/proc/mounts", [&](mntent *me) {
|
parse_mnt("/proc/mounts", [&](mntent *me) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (MNT_DIR_IS("/") && me->mnt_type != "rootfs"sv && stat("/", &st) == 0) {
|
if (MNT_DIR_IS("/") && me->mnt_type != "rootfs"sv && stat("/", &st) == 0) {
|
||||||
do_mount_mirror(system_root, MS_RDONLY)
|
do_mount_mirror(system_root)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -189,15 +189,25 @@ string &replace_all(string &str, string_view from, string_view to) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> split(const string& s, const string& delimiters) {
|
template <class T>
|
||||||
vector<string> result;
|
static auto split_impl(T s, T delims) {
|
||||||
|
vector<std::decay_t<T>> result;
|
||||||
size_t base = 0;
|
size_t base = 0;
|
||||||
size_t found;
|
size_t found;
|
||||||
while (true) {
|
while (true) {
|
||||||
found = s.find_first_of(delimiters, base);
|
found = s.find_first_of(delims, base);
|
||||||
result.push_back(s.substr(base, found - base));
|
result.push_back(s.substr(base, found - base));
|
||||||
if (found == string::npos) break;
|
if (found == string::npos)
|
||||||
|
break;
|
||||||
base = found + 1;
|
base = found + 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> split(const string &s, const string &delims) {
|
||||||
|
return split_impl<const string&>(s, delims);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string_view> split_ro(string_view s, string_view delims) {
|
||||||
|
return split_impl<string_view>(s, delims);
|
||||||
|
}
|
||||||
|
@ -159,7 +159,8 @@ uint32_t binary_gcd(uint32_t u, uint32_t v);
|
|||||||
int switch_mnt_ns(int pid);
|
int switch_mnt_ns(int pid);
|
||||||
int gen_rand_str(char *buf, int len, bool varlen = true);
|
int gen_rand_str(char *buf, int len, bool varlen = true);
|
||||||
std::string &replace_all(std::string &str, std::string_view from, std::string_view to);
|
std::string &replace_all(std::string &str, std::string_view from, std::string_view to);
|
||||||
std::vector<std::string> split(const std::string& s, const std::string& delimiters);
|
std::vector<std::string> split(const std::string &s, const std::string &delims);
|
||||||
|
std::vector<std::string_view> split_ro(std::string_view, std::string_view delims);
|
||||||
|
|
||||||
struct exec_t {
|
struct exec_t {
|
||||||
bool err = false;
|
bool err = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user