diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 82b91610d..52c76e694 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -11,7 +11,7 @@ ifdef B_MAGISK include $(CLEAR_VARS) LOCAL_MODULE := magisk -LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap +LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap libxhook LOCAL_C_INCLUDES := jni/include LOCAL_SRC_FILES := \ @@ -33,23 +33,13 @@ LOCAL_SRC_FILES := \ su/su.cpp \ su/connect.cpp \ su/pts.cpp \ - su/su_daemon.cpp - -LOCAL_LDLIBS := -llog -LOCAL_CPPFLAGS := -DENABLE_INJECT=$(ENABLE_INJECT) - -ifeq ($(DISABLE_ZYGISK),1) -LOCAL_SRC_FILES += magiskhide/proc_monitor.cpp -LOCAL_CPPFLAGS := -DENABLE_INJECT=0 -else -LOCAL_STATIC_LIBRARIES += libxhook -LOCAL_SRC_FILES += \ + su/su_daemon.cpp \ zygisk/entry.cpp \ zygisk/utils.cpp \ zygisk/hook.cpp \ zygisk/memory.cpp -LOCAL_CPPFLAGS := -DENABLE_INJECT=1 -endif + +LOCAL_LDLIBS := -llog include $(BUILD_EXECUTABLE) diff --git a/native/jni/core/applets.cpp b/native/jni/core/applets.cpp index 28b5f004c..9f837b5a4 100644 --- a/native/jni/core/applets.cpp +++ b/native/jni/core/applets.cpp @@ -20,11 +20,9 @@ static int call_applet(int argc, char *argv[]) { return (*applet_main[i])(argc, argv); } } -#if ENABLE_INJECT if (str_starts(base, "app_process")) { return app_process_main(argc, argv); } -#endif fprintf(stderr, "%s: applet not found\n", base.data()); return 1; } @@ -48,4 +46,3 @@ int main(int argc, char *argv[]) { return call_applet(argc, argv); } - diff --git a/native/jni/include/daemon.hpp b/native/jni/include/daemon.hpp index 59061d3bd..53dc6afc9 100644 --- a/native/jni/include/daemon.hpp +++ b/native/jni/include/daemon.hpp @@ -57,9 +57,3 @@ void su_daemon_handler(int client, ucred *credential); // MagiskHide void auto_start_magiskhide(bool late_props); int stop_magiskhide(); - -#if ENABLE_INJECT -// For injected process to access daemon -int remote_check_hide(int uid, const char *process); -void remote_request_hide(); -#endif diff --git a/native/jni/magiskhide/hide_utils.cpp b/native/jni/magiskhide/hide_utils.cpp index 47396b1dc..a18d8ef60 100644 --- a/native/jni/magiskhide/hide_utils.cpp +++ b/native/jni/magiskhide/hide_utils.cpp @@ -299,12 +299,6 @@ int launch_magiskhide(bool late_props) { if (late_props) hide_late_sensitive_props(); -#if !ENABLE_INJECT - // Start monitoring - if (new_daemon_thread(&proc_monitor)) - return DAEMON_ERROR; -#endif - hide_state = true; update_hide_config(); @@ -322,9 +316,6 @@ int stop_magiskhide() { LOGI("* Disable MagiskHide\n"); uid_proc_map.clear(); hide_set.clear(); -#if !ENABLE_INJECT - pthread_kill(monitor_thread, SIGTERMTHRD); -#endif } hide_state = false; @@ -334,9 +325,6 @@ int stop_magiskhide() { void auto_start_magiskhide(bool late_props) { if (hide_enabled()) { -#if !ENABLE_INJECT - pthread_kill(monitor_thread, SIGALRM); -#endif hide_late_sensitive_props(); } else { db_settings dbs; @@ -375,22 +363,3 @@ bool is_hide_target(int uid, string_view process, int max_len) { } return false; } - -#if !ENABLE_INJECT -void test_proc_monitor() { - if (procfp == nullptr && (procfp = opendir("/proc")) == nullptr) - exit(1); - proc_monitor(); -} -#endif - -#if ENABLE_INJECT -int check_uid_map(int client) { - if (!hide_enabled()) - return 0; - - int uid = read_int(client); - string process = read_string(client); - return is_hide_target(uid, process) ? 1 : 0; -} -#endif diff --git a/native/jni/magiskhide/magiskhide.cpp b/native/jni/magiskhide/magiskhide.cpp index fccf4d1ac..54f024cd0 100644 --- a/native/jni/magiskhide/magiskhide.cpp +++ b/native/jni/magiskhide/magiskhide.cpp @@ -62,17 +62,6 @@ void magiskhide_handler(int client, ucred *cred) { case HIDE_STATUS: res = hide_enabled() ? HIDE_IS_ENABLED : HIDE_NOT_ENABLED; break; -#if ENABLE_INJECT - case REMOTE_CHECK_HIDE: - res = check_uid_map(client); - break; - case REMOTE_DO_HIDE: - kill(cred->pid, SIGSTOP); - write_int(client, 0); - hide_daemon(cred->pid); - close(client); - return; -#endif } write_int(client, res); @@ -107,13 +96,9 @@ int magiskhide_main(int argc, char *argv[]) { hide_unmount(); execvp(argv[2], argv + 2); exit(1); - } -#if 0 && !ENABLE_INJECT - else if (opt == "test"sv) - test_proc_monitor(); -#endif - else + } else { usage(argv[0]); + } // Send request int fd = connect_daemon(); @@ -169,28 +154,3 @@ int magiskhide_main(int argc, char *argv[]) { return_code: return req == HIDE_STATUS ? (code == HIDE_IS_ENABLED ? 0 : 1) : code != DAEMON_SUCCESS; } - -#if ENABLE_INJECT -int remote_check_hide(int uid, const char *process) { - int fd = connect_daemon(); - write_int(fd, MAGISKHIDE); - write_int(fd, REMOTE_CHECK_HIDE); - write_int(fd, uid); - write_string(fd, process); - int res = read_int(fd); - close(fd); - return res; -} - -void remote_request_hide() { - int fd = connect_daemon(); - write_int(fd, MAGISKHIDE); - write_int(fd, REMOTE_DO_HIDE); - - // Should receive SIGSTOP before reading anything - // During process stop, magiskd will cleanup our mount ns - read_int(fd); - - close(fd); -} -#endif diff --git a/native/jni/magiskhide/magiskhide.hpp b/native/jni/magiskhide/magiskhide.hpp index d9fb26e13..453ee040e 100644 --- a/native/jni/magiskhide/magiskhide.hpp +++ b/native/jni/magiskhide/magiskhide.hpp @@ -21,16 +21,6 @@ int add_list(int client); int rm_list(int client); void ls_list(int client); -#if !ENABLE_INJECT -// Process monitoring -extern pthread_t monitor_thread; -[[noreturn]] void proc_monitor(); -[[noreturn]] void test_proc_monitor(); -#else -// Response whether target process should be hidden -int check_uid_map(int client); -#endif - // Utility functions void crawl_procfs(const std::function &fn); void crawl_procfs(DIR *dir, const std::function &fn); @@ -54,8 +44,6 @@ enum { RM_HIDELIST, LS_HIDELIST, HIDE_STATUS, - REMOTE_CHECK_HIDE, - REMOTE_DO_HIDE }; enum { diff --git a/native/jni/zygisk/hook.cpp b/native/jni/zygisk/hook.cpp index 00b1ac285..6a8281edb 100644 --- a/native/jni/zygisk/hook.cpp +++ b/native/jni/zygisk/hook.cpp @@ -114,6 +114,12 @@ string get_class_name(JNIEnv *env, jclass clazz) { // ----------------------------------------------------------------- +// TODOs +int remote_check_hide(int uid, const char *process) { return 0; } +void remote_request_hide() {} + +// ----------------------------------------------------------------- + #define DCL_HOOK_FUNC(ret, func, ...) \ ret (*old_##func)(__VA_ARGS__); \ ret new_##func(__VA_ARGS__)