diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index fb80491ae..f3fa51a9b 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -757,6 +757,8 @@ void boot_complete(int client) { if (!pfs_done) return; + auto_start_magiskhide(); + if (access(MANAGERAPK, F_OK) == 0) { // Install Magisk Manager if exists rename(MANAGERAPK, "/data/magisk.apk"); diff --git a/native/jni/magiskhide/hide_utils.cpp b/native/jni/magiskhide/hide_utils.cpp index a5bdcda33..c08a8eacc 100644 --- a/native/jni/magiskhide/hide_utils.cpp +++ b/native/jni/magiskhide/hide_utils.cpp @@ -217,7 +217,7 @@ static void set_hide_config() { db_err(err); } -static inline void launch_err(int client, int code = DAEMON_ERROR) { +[[noreturn]] static void launch_err(int client, int code = DAEMON_ERROR) { if (code != HIDE_IS_ENABLED) hide_enabled = false; if (client >= 0) { @@ -280,10 +280,14 @@ int stop_magiskhide() { } void auto_start_magiskhide() { - db_settings dbs; - get_db_settings(dbs, HIDE_CONFIG); - if (dbs[HIDE_CONFIG]) { - new_daemon_thread([]{ launch_magiskhide(-1); }); + if (hide_enabled) { + pthread_kill(proc_monitor_thread, SIGZYGOTE); + } else if (SDK_INT >= 19) { + db_settings dbs; + get_db_settings(dbs, HIDE_CONFIG); + if (dbs[HIDE_CONFIG]) { + new_daemon_thread([]{ launch_magiskhide(-1); }); + } } } diff --git a/native/jni/magiskhide/magiskhide.h b/native/jni/magiskhide/magiskhide.h index aeb87c380..832d9e8e9 100644 --- a/native/jni/magiskhide/magiskhide.h +++ b/native/jni/magiskhide/magiskhide.h @@ -13,6 +13,7 @@ #include #define SIGTERMTHRD SIGUSR1 +#define SIGZYGOTE SIGUSR2 #define SAFETYNET_COMPONENT "com.google.android.gms/.droidguard.DroidGuardService" #define SAFETYNET_PROCESS "com.google.android.gms.unstable" diff --git a/native/jni/magiskhide/proc_monitor.cpp b/native/jni/magiskhide/proc_monitor.cpp index 28da53872..c9d92fa2e 100644 --- a/native/jni/magiskhide/proc_monitor.cpp +++ b/native/jni/magiskhide/proc_monitor.cpp @@ -155,6 +155,10 @@ static void inotify_event(int) { check_zygote(); } +static void check_zygote(int) { + check_zygote(); +} + // Workaround for the lack of pthread_cancel static void term_thread(int) { LOGD("proc_monitor: cleaning up\n"); @@ -312,6 +316,8 @@ void proc_monitor() { sigaction(SIGTERMTHRD, &act, nullptr); act.sa_handler = inotify_event; sigaction(SIGIO, &act, nullptr); + act.sa_handler = check_zygote; + sigaction(SIGZYGOTE, &act, nullptr); setup_inotify();