Randomize service names

Fix Aniplex Game detections.
Close #502, close #513
This commit is contained in:
topjohnwu 2018-09-08 23:15:58 -04:00
parent 2d7c1da741
commit 6f41d9855b
3 changed files with 25 additions and 28 deletions

View File

@ -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;
}

View File

@ -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
;

View File

@ -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);