From 3068738a70f281aef810a90271f770574c02f3e1 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 7 Nov 2016 23:57:21 +0800 Subject: [PATCH] MagiskHide small tweak --- jni/magiskhide.c | 31 +++++++++++++++++++------------ scripts/magic_mask.sh | 3 +++ zip_static/common/magiskhide/add | 2 ++ zip_static/common/magiskhide/rm | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/jni/magiskhide.c b/jni/magiskhide.c index 23451dc5f..657c18f13 100644 --- a/jni/magiskhide.c +++ b/jni/magiskhide.c @@ -12,6 +12,9 @@ #include #include +#define LOGFILE "/cache/magisk.log" +#define HIDELIST "/magisk/.core/magiskhide/hidelist" + FILE *logfile; int i, list_size; char **hide_list = NULL; @@ -111,7 +114,7 @@ void update_list(const char *listpath) { hide_list = file_to_str_arr(hide_fp, &list_size); pthread_mutex_unlock(&mutex); fclose(hide_fp); - fprintf(logfile, "MagiskHide: Update process/package list:\n"); + if (list_size) fprintf(logfile, "MagiskHide: Update process/package list:\n"); for(i = 0; i < list_size; i++) fprintf(logfile, "MagiskHide: %s\n", hide_list[i]); } @@ -129,18 +132,22 @@ void *monitor_list(void *listpath) { // Initial load update_list((char*) listpath); - int inotifyFd; + int inotifyFd = -1; char buffer[512]; - inotifyFd = inotify_init(); - if (inotifyFd == -1) - exit(1); - if (inotify_add_watch(inotifyFd, (char*) listpath, IN_ATTRIB | IN_MODIFY) == -1) - exit(1); - while(1) { - if (read(inotifyFd, buffer, 512) == -1) - exit(1); + if (inotifyFd == -1 || read(inotifyFd, buffer, 512) == -1) { + close(inotifyFd); + inotifyFd = inotify_init(); + if (inotifyFd == -1) { + fprintf(logfile, "MagiskHide: Unable to watch %s\n", listpath); + exit(1); + } + if (inotify_add_watch(inotifyFd, (char*) listpath, IN_MODIFY) == -1) { + fprintf(logfile, "MagiskHide: Unable to watch %s\n", listpath); + exit(1); + } + } update_list((char*) listpath); } @@ -162,13 +169,13 @@ int main(int argc, char **argv, char **envp) { close(STDOUT_FILENO); close(STDERR_FILENO); - logfile = fopen("/cache/magisk.log", "a+"); + logfile = fopen(LOGFILE, "a+"); setbuf(logfile, NULL); pthread_t list_monitor; pthread_mutex_init(&mutex, NULL); - pthread_create(&list_monitor, NULL, monitor_list, "/magisk/.core/magiskhide/hidelist"); + pthread_create(&list_monitor, NULL, monitor_list, HIDELIST); char buffer[512]; FILE *p = popen("while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done", "r"); diff --git a/scripts/magic_mask.sh b/scripts/magic_mask.sh index e1a67e363..36c9d3d93 100644 --- a/scripts/magic_mask.sh +++ b/scripts/magic_mask.sh @@ -233,6 +233,9 @@ case $1 in # Only for multirom! # log_print "** Magisk post-fs mode running..." + + # Cleanup previous stuffs... + rm -rf /cache/magisk /cache/magisk_merge /cache/magiskhide.log unblock ;; diff --git a/zip_static/common/magiskhide/add b/zip_static/common/magiskhide/add index 0a7677ff2..31feddbda 100644 --- a/zip_static/common/magiskhide/add +++ b/zip_static/common/magiskhide/add @@ -5,5 +5,7 @@ HIDELIST=/magisk/.core/magiskhide/hidelist if [ ! -z "$1" ]; then if [ $(grep -c "^$1$" $HIDELIST) -eq "0" ]; then echo "$1" >> $HIDELIST + set `/data/busybox/ps -o pid,args | grep "$1" | grep -v "grep"` + kill "$1" fi fi diff --git a/zip_static/common/magiskhide/rm b/zip_static/common/magiskhide/rm index 515d638ba..4ed4eb633 100644 --- a/zip_static/common/magiskhide/rm +++ b/zip_static/common/magiskhide/rm @@ -3,7 +3,7 @@ HIDELIST=/magisk/.core/magiskhide/hidelist if [ ! -z "$1" ]; then - mv $HIDELIST $HIDELIST.tmp + cp -af $HIDELIST $HIDELIST.tmp cat $HIDELIST.tmp | grep -v "^$1$" > $HIDELIST rm -f $HIDELIST.tmp set `/data/busybox/ps -o pid,args | grep "$1" | grep -v "grep"`