From 2bc30e5c22859fd5df85d9dfdb9a182b5adbaac1 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 28 Oct 2017 16:12:01 +0800 Subject: [PATCH] Hide /magisk --- jni/daemon/bootstages.c | 6 ++++-- jni/include/magisk.h | 12 +++++++----- jni/magiskhide/proc_monitor.c | 6 ++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index 935d55254..ce661bee8 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -415,7 +415,7 @@ static void daemon_init() { unlinkat(sbin, entry->d_name, 0); } close(sbin); - mount("tmpfs", "/sbin", "tmpfs", 0, NULL); + xmount("tmpfs", "/sbin", "tmpfs", 0, NULL); sbin = xopen("/sbin", O_RDONLY | O_CLOEXEC); fchmod(sbin, 0755); fsetfilecon(sbin, "u:object_r:rootfs:s0"); @@ -430,7 +430,9 @@ static void daemon_init() { snprintf(buf2, PATH_MAX, "/sbin/%s", applet[i]); xsymlink("/root/magisk", buf2); } - xmkdir("/magisk", 0755); + xsymlink(MOUNTPOINT, FAKEPOINT); + close(root); + close(sbin); xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL); LOGI("* Mounting mirrors"); diff --git a/jni/include/magisk.h b/jni/include/magisk.h index fb8616247..4bb9deddb 100644 --- a/jni/include/magisk.h +++ b/jni/include/magisk.h @@ -22,17 +22,19 @@ #define UNBLOCKFILE "/dev/.magisk.unblock" #define DISABLEFILE "/cache/.disable_magisk" #define UNINSTALLER "/cache/magisk_uninstaller.sh" -#define MOUNTPOINT "/magisk" +#define CACHEMOUNT "/cache/magisk_mount" +#define MAGISKTMP "/dev/magisk" +#define MIRRDIR MAGISKTMP "/mirror" +#define BBPATH MAGISKTMP "/bin" +#define MOUNTPOINT MAGISKTMP "/img" +#define FAKEPOINT "/magisk" #define COREDIR MOUNTPOINT "/.core" #define HOSTSFILE COREDIR "/hosts" #define HIDELIST COREDIR "/hidelist" #define MAINIMG "/data/magisk.img" #define DATABIN "/data/magisk" #define MANAGERAPK DATABIN "/magisk.apk" -#define MAGISKTMP "/dev/magisk" -#define MIRRDIR MAGISKTMP "/mirror" -#define BBPATH MAGISKTMP "/bin" -#define CACHEMOUNT "/cache/magisk_mount" + #define SELINUX_PATH "/sys/fs/selinux/" #define SELINUX_ENFORCE SELINUX_PATH "enforce" diff --git a/jni/magiskhide/proc_monitor.c b/jni/magiskhide/proc_monitor.c index c48226b32..59e8925d1 100644 --- a/jni/magiskhide/proc_monitor.c +++ b/jni/magiskhide/proc_monitor.c @@ -125,11 +125,17 @@ static void hide_daemon(int pid) { free(line); } + xmount(NULL, "/", NULL, MS_REMOUNT, NULL); + unlink(FAKEPOINT); + exit: // Send resume signal kill(pid, SIGCONT); // Free up memory vec_destroy(&mount_list); + // Wait a while and link it back + sleep(10); + xsymlink(MOUNTPOINT, FAKEPOINT); _exit(0); }