From 6f41d9855b03373fb62da0b87cb980b9867505eb Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 8 Sep 2018 23:15:58 -0400 Subject: [PATCH] Randomize service names Fix Aniplex Game detections. Close #502, close #513 --- native/jni/core/magiskinit.c | 8 ++++++- native/jni/include/magiskrc.h | 43 ++++++++++++++--------------------- native/jni/utils/misc.c | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/native/jni/core/magiskinit.c b/native/jni/core/magiskinit.c index 1a81d0e07..1bb8564bf 100644 --- a/native/jni/core/magiskinit.c +++ b/native/jni/core/magiskinit.c @@ -292,7 +292,13 @@ static int dump_magiskrc(const char *path, mode_t mode) { int fd = creat(path, mode); if (fd < 0) return 1; - xwrite(fd, magiskrc, sizeof(magiskrc)); + char startup_svc[8], late_start_svc[8], rc[sizeof(magiskrc) + 100]; + gen_rand_str(startup_svc, sizeof(startup_svc)); + do { + gen_rand_str(late_start_svc, sizeof(late_start_svc)); + } while (strcmp(startup_svc, late_start_svc) == 0); + int size = sprintf(rc, magiskrc, startup_svc, startup_svc, late_start_svc); + xwrite(fd, rc, size); close(fd); return 0; } diff --git a/native/jni/include/magiskrc.h b/native/jni/include/magiskrc.h index 6fce007eb..fca8af782 100644 --- a/native/jni/include/magiskrc.h +++ b/native/jni/include/magiskrc.h @@ -1,48 +1,39 @@ #include "magisk.h" #include "magiskpolicy.h" -const char magiskrc[] = - -// Triggers +static const char magiskrc[] = "on post-fs-data\n" " start logd\n" " load_persist_props\n" " rm "UNBLOCKFILE"\n" -" start magisk_startup\n" +" start %s\n" " wait "UNBLOCKFILE" 10\n" " rm "UNBLOCKFILE"\n" "\n" +"service %s /sbin/magisk --startup\n" +" user root\n" +" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" +" oneshot\n" +"\n" + +"service %s /sbin/magisk --service\n" +" class late_start\n" +" user root\n" +" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" +" oneshot\n" +"\n" + #if 0 "on property:sys.boot_completed=1\n" " start magisk_bc\n" "\n" -#endif - -// Services - -"service magisk_daemon /sbin/magisk --daemon\n" -" user root\n" -" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" -" oneshot\n" -"\n" - -"service magisk_startup /sbin/magisk --startup\n" -" user root\n" -" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" -" oneshot\n" -"\n" - -"service magisk_service /sbin/magisk --service\n" -" class late_start\n" -" user root\n" -" seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" -" oneshot\n" -"\n" "service magisk_bc /sbin/magisk --boot-complete\n" " user root\n" " seclabel u:r:"SEPOL_PROC_DOMAIN":s0\n" " oneshot\n" ; +#endif +; diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 54e6fd2be..422a52577 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -373,7 +373,7 @@ void wait_till_exists(const char *target) { } void gen_rand_str(char *buf, int len) { - const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."; + const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; int urandom; if (access("/dev/urandom", R_OK) == 0) { urandom = xopen("/dev/urandom", O_RDONLY | O_CLOEXEC);