From ef8d9be63373e75ab7ccdd1942bb01aca79500a0 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 3 Jun 2017 05:52:49 +0800 Subject: [PATCH] More improvements and fixes --- jni/daemon/bootstages.c | 26 +++++++++++++++++++++++--- jni/magiskhide/magiskhide.c | 4 +++- jni/utils/misc.c | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index 3dca31f41..b05d43cbd 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -505,17 +505,30 @@ void post_fs_data(int client) { if (access("/cache/data_bin", F_OK) == 0) { rm_rf(DATABIN); rename("/cache/data_bin", DATABIN); - system("mv /cache/stock_boot* /data"); // Lazy.... use bash glob.... } + // Magisk Manual Injector support + if (access("/data/local/tmp/magisk", F_OK) == 0) { + rm_rf(DATABIN); + rename("/data/local/tmp/magisk", DATABIN); + } + + // Lazy.... use shell blob + system("mv /data/magisk/stock_boot* /data;"); + // Merge images if (merge_img("/cache/magisk.img", MAINIMG)) goto unblock; if (merge_img("/data/magisk_merge.img", MAINIMG)) goto unblock; - if (access(MAINIMG, F_OK) == -1 && create_img(MAINIMG, 64)) - goto unblock; + int new_img = 0; + + if (access(MAINIMG, F_OK) == -1) { + if (create_img(MAINIMG, 64)) + goto unblock; + new_img = 1; + } LOGI("* Mounting " MAINIMG "\n"); // Mounting magisk image @@ -523,6 +536,13 @@ void post_fs_data(int client) { if (magiskloop == NULL) goto unblock; + if (new_img) { + mkdir(COREDIR, 0755); + mkdir(COREDIR "/post-fs-data.d", 0755); + mkdir(COREDIR "/service.d", 0755); + mkdir(COREDIR "/props", 0755); + } + // Run common scripts LOGI("* Running post-fs-data.d scripts\n"); exec_common_script("post-fs-data"); diff --git a/jni/magiskhide/magiskhide.c b/jni/magiskhide/magiskhide.c index b64fb1068..74f420d76 100644 --- a/jni/magiskhide/magiskhide.c +++ b/jni/magiskhide/magiskhide.c @@ -141,7 +141,9 @@ int magiskhide_main(int argc, char *argv[]) { } else if (strcmp(argv[1], "--rm") == 0 && argc > 2) { req = RM_HIDELIST; } else if (strcmp(argv[1], "--ls") == 0) { - FILE *fp = xfopen(HIDELIST, "r"); + FILE *fp = fopen(HIDELIST, "r"); + if (fp == NULL) + return 1; char buffer[512]; while (fgets(buffer, sizeof(buffer), fp)) { printf("%s", buffer); diff --git a/jni/utils/misc.c b/jni/utils/misc.c index 3b9924aeb..f70436f26 100644 --- a/jni/utils/misc.c +++ b/jni/utils/misc.c @@ -347,6 +347,8 @@ int clone_dir(const char *source, const char *target) { } int rm_rf(const char *target) { + if (access(target, F_OK) == -1) + return 0; struct stat buf; xlstat(target, &buf); char *next;