From 838f3cc01ec926d0ff249b3b2e5812e83a38f62d Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 17 Jun 2018 05:16:52 +0800 Subject: [PATCH] Simplify hiding conditions --- native/jni/magiskhide/proc_monitor.c | 22 +++++----------------- native/jni/utils/misc.c | 2 ++ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/native/jni/magiskhide/proc_monitor.c b/native/jni/magiskhide/proc_monitor.c index bf367009a..76f4fb04a 100644 --- a/native/jni/magiskhide/proc_monitor.c +++ b/native/jni/magiskhide/proc_monitor.c @@ -63,7 +63,6 @@ static void lazy_unmount(const char* mountpoint) { static void hide_daemon(int pid) { LOGD("hide_daemon: start unmount for pid=[%d]\n", pid); - strcpy(argv0, "hide_daemon"); char *line, buffer[PATH_MAX]; struct vector mount_list; @@ -90,19 +89,9 @@ static void hide_daemon(int pid) { has_cache = 0; } - // Unmout cache mounts - if (has_cache) { - vec_for_each(&mount_list, line) { - if (strstr(line, cache_block) && (strstr(line, " /system/") || strstr(line, " /vendor/"))) { - sscanf(line, "%*s %4096s", buffer); - lazy_unmount(buffer); - } - } - } - - // Unmount dummy skeletons, /sbin links + // Unmount dummy skeletons and /sbin links vec_for_each(&mount_list, line) { - if (strstr(line, "tmpfs /system") || strstr(line, "tmpfs /vendor") || strstr(line, "tmpfs /sbin")) { + if (strstr(line, "tmpfs /system/") || strstr(line, "tmpfs /vendor/") || strstr(line, "tmpfs /sbin")) { sscanf(line, "%*s %4096s", buffer); lazy_unmount(buffer); } @@ -115,20 +104,19 @@ static void hide_daemon(int pid) { vec_init(&mount_list); file_to_vector(buffer, &mount_list); - // Unmount any loop mounts + // Unmount everything under /system, /vendor, and loop mounts vec_for_each(&mount_list, line) { - if (strstr(line, "/dev/block/loop")) { + if (strstr(line, "/dev/block/loop") || strstr(line, " /system/") || strstr(line, " /vendor/")) { sscanf(line, "%*s %4096s", buffer); lazy_unmount(buffer); } free(line); } + vec_destroy(&mount_list); exit: // Send resume signal kill(pid, SIGCONT); - // Free up memory - vec_destroy(&mount_list); _exit(0); } diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 4c85b6a7b..636c3df16 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -87,6 +87,8 @@ int check_data() { /* All the string should be freed manually!! */ int file_to_vector(const char* filename, struct vector *v) { + if (access(filename, R_OK) != 0) + return 1; char *line = NULL; size_t len = 0; ssize_t read;