mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 07:01:53 +00:00
Use a better function to read through files
This commit is contained in:
@@ -263,9 +263,10 @@ bool init_list() {
|
||||
|
||||
// Migrate old hide list into database
|
||||
if (access(LEGACY_LIST, R_OK) == 0) {
|
||||
auto tmp = file_to_vector(LEGACY_LIST);
|
||||
for (auto &s : tmp)
|
||||
add_list(s.c_str());
|
||||
file_readline(LEGACY_LIST, [](string_view &s) -> bool {
|
||||
add_list(s.data());
|
||||
return true;
|
||||
});
|
||||
unlink(LEGACY_LIST);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,41 +97,36 @@ static bool is_pid_safetynet_process(const int pid) {
|
||||
}
|
||||
|
||||
static void hide_daemon(int pid) {
|
||||
LOGD("hide_daemon: handling PID=[%d]\n", pid);
|
||||
|
||||
char buffer[4096];
|
||||
vector<string> mounts;
|
||||
|
||||
manage_selinux();
|
||||
clean_magisk_props();
|
||||
|
||||
if (switch_mnt_ns(pid))
|
||||
goto exit;
|
||||
|
||||
LOGD("hide_daemon: handling PID=[%d]\n", pid);
|
||||
manage_selinux();
|
||||
clean_magisk_props();
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%d", pid);
|
||||
chdir(buffer);
|
||||
|
||||
mounts = file_to_vector("mounts");
|
||||
// Unmount dummy skeletons and /sbin links
|
||||
for (auto &s : mounts) {
|
||||
file_readline("mounts", [&](string_view &s) -> bool {
|
||||
if (str_contains(s, "tmpfs /system/") || str_contains(s, "tmpfs /vendor/") ||
|
||||
str_contains(s, "tmpfs /sbin")) {
|
||||
sscanf(s.c_str(), "%*s %4096s", buffer);
|
||||
sscanf(s.data(), "%*s %4096s", buffer);
|
||||
lazy_unmount(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Re-read mount infos
|
||||
mounts = file_to_vector("mounts");
|
||||
return true;
|
||||
});
|
||||
|
||||
// Unmount everything under /system, /vendor, and data mounts
|
||||
for (auto &s : mounts) {
|
||||
file_readline("mounts", [&](string_view &s) -> bool {
|
||||
if ((str_contains(s, " /system/") || str_contains(s, " /vendor/")) &&
|
||||
(str_contains(s, system_block) || str_contains(s, vendor_block) || str_contains(s, data_block))) {
|
||||
sscanf(s.c_str(), "%*s %4096s", buffer);
|
||||
(str_contains(s, system_block) || str_contains(s, vendor_block) ||
|
||||
str_contains(s, data_block))) {
|
||||
sscanf(s.data(), "%*s %4096s", buffer);
|
||||
lazy_unmount(buffer);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
exit:
|
||||
// Send resume signal
|
||||
|
||||
Reference in New Issue
Block a user