mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-17 17:18:29 +00:00
Guard all injection features behind a global flag
This commit is contained in:
parent
1860e5d133
commit
e8ba671fc2
@ -4,11 +4,14 @@ LOCAL_PATH := $(call my-dir)
|
|||||||
# Binaries
|
# Binaries
|
||||||
########################
|
########################
|
||||||
|
|
||||||
|
# Global toggle for the WIP zygote injection features
|
||||||
|
ENABLE_INJECT := 0
|
||||||
|
|
||||||
ifdef B_MAGISK
|
ifdef B_MAGISK
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := magisk
|
LOCAL_MODULE := magisk
|
||||||
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libxhook
|
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils
|
||||||
LOCAL_C_INCLUDES := jni/include
|
LOCAL_C_INCLUDES := jni/include
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
@ -22,7 +25,6 @@ LOCAL_SRC_FILES := \
|
|||||||
core/restorecon.cpp \
|
core/restorecon.cpp \
|
||||||
core/module.cpp \
|
core/module.cpp \
|
||||||
magiskhide/magiskhide.cpp \
|
magiskhide/magiskhide.cpp \
|
||||||
magiskhide/proc_monitor.cpp \
|
|
||||||
magiskhide/hide_utils.cpp \
|
magiskhide/hide_utils.cpp \
|
||||||
magiskhide/hide_policy.cpp \
|
magiskhide/hide_policy.cpp \
|
||||||
resetprop/persist_properties.cpp \
|
resetprop/persist_properties.cpp \
|
||||||
@ -30,12 +32,21 @@ LOCAL_SRC_FILES := \
|
|||||||
su/su.cpp \
|
su/su.cpp \
|
||||||
su/connect.cpp \
|
su/connect.cpp \
|
||||||
su/pts.cpp \
|
su/pts.cpp \
|
||||||
su/su_daemon.cpp \
|
su/su_daemon.cpp
|
||||||
|
|
||||||
|
LOCAL_LDLIBS := -llog
|
||||||
|
LOCAL_CPPFLAGS := -DENABLE_INJECT=$(ENABLE_INJECT)
|
||||||
|
|
||||||
|
ifeq ($(ENABLE_INJECT),1)
|
||||||
|
LOCAL_STATIC_LIBRARIES += libxhook
|
||||||
|
LOCAL_SRC_FILES += \
|
||||||
inject/entry.cpp \
|
inject/entry.cpp \
|
||||||
inject/utils.cpp \
|
inject/utils.cpp \
|
||||||
inject/hook.cpp
|
inject/hook.cpp
|
||||||
|
else
|
||||||
|
LOCAL_SRC_FILES += magiskhide/proc_monitor.cpp
|
||||||
|
endif
|
||||||
|
|
||||||
LOCAL_LDLIBS := -llog
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
@ -20,10 +20,11 @@ static int call_applet(int argc, char *argv[]) {
|
|||||||
return (*applet_main[i])(argc, argv);
|
return (*applet_main[i])(argc, argv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if ENABLE_INJECT
|
||||||
if (str_starts(base, "app_process")) {
|
if (str_starts(base, "app_process")) {
|
||||||
return app_process_main(argc, argv);
|
return app_process_main(argc, argv);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
fprintf(stderr, "%s: applet not found\n", base.data());
|
fprintf(stderr, "%s: applet not found\n", base.data());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ void su_daemon_handler(int client, ucred *credential);
|
|||||||
void auto_start_magiskhide(bool late_props);
|
void auto_start_magiskhide(bool late_props);
|
||||||
int stop_magiskhide();
|
int stop_magiskhide();
|
||||||
|
|
||||||
|
#if ENABLE_INJECT
|
||||||
// For injected process to access daemon
|
// For injected process to access daemon
|
||||||
int remote_check_hide(int uid, const char *process);
|
int remote_check_hide(int uid, const char *process);
|
||||||
void remote_request_hide();
|
void remote_request_hide();
|
||||||
|
#endif
|
||||||
|
@ -20,7 +20,7 @@ map<int, vector<string_view>> uid_proc_map; /* uid -> list of process */
|
|||||||
// Locks the variables above
|
// Locks the variables above
|
||||||
pthread_mutex_t hide_state_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t hide_state_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
static pthread_t monitor_thread;
|
static pthread_t monitor_thread;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ int launch_magiskhide(bool late_props) {
|
|||||||
if (late_props)
|
if (late_props)
|
||||||
hide_late_sensitive_props();
|
hide_late_sensitive_props();
|
||||||
|
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
// Start monitoring
|
// Start monitoring
|
||||||
if (new_daemon_thread(&proc_monitor))
|
if (new_daemon_thread(&proc_monitor))
|
||||||
return DAEMON_ERROR;
|
return DAEMON_ERROR;
|
||||||
@ -313,7 +313,7 @@ int stop_magiskhide() {
|
|||||||
LOGI("* Disable MagiskHide\n");
|
LOGI("* Disable MagiskHide\n");
|
||||||
uid_proc_map.clear();
|
uid_proc_map.clear();
|
||||||
hide_set.clear();
|
hide_set.clear();
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
pthread_kill(monitor_thread, SIGTERMTHRD);
|
pthread_kill(monitor_thread, SIGTERMTHRD);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -325,7 +325,7 @@ int stop_magiskhide() {
|
|||||||
|
|
||||||
void auto_start_magiskhide(bool late_props) {
|
void auto_start_magiskhide(bool late_props) {
|
||||||
if (hide_enabled()) {
|
if (hide_enabled()) {
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
pthread_kill(monitor_thread, SIGALRM);
|
pthread_kill(monitor_thread, SIGALRM);
|
||||||
#endif
|
#endif
|
||||||
hide_late_sensitive_props();
|
hide_late_sensitive_props();
|
||||||
@ -337,7 +337,7 @@ void auto_start_magiskhide(bool late_props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
void test_proc_monitor() {
|
void test_proc_monitor() {
|
||||||
if (procfp == nullptr && (procfp = opendir("/proc")) == nullptr)
|
if (procfp == nullptr && (procfp = opendir("/proc")) == nullptr)
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -345,6 +345,7 @@ void test_proc_monitor() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_INJECT
|
||||||
int check_uid_map(int client) {
|
int check_uid_map(int client) {
|
||||||
mutex_guard lock(hide_state_lock);
|
mutex_guard lock(hide_state_lock);
|
||||||
|
|
||||||
@ -377,3 +378,4 @@ int check_uid_map(int client) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -62,6 +62,7 @@ void magiskhide_handler(int client, ucred *cred) {
|
|||||||
case HIDE_STATUS:
|
case HIDE_STATUS:
|
||||||
res = hide_enabled() ? HIDE_IS_ENABLED : HIDE_NOT_ENABLED;
|
res = hide_enabled() ? HIDE_IS_ENABLED : HIDE_NOT_ENABLED;
|
||||||
break;
|
break;
|
||||||
|
#if ENABLE_INJECT
|
||||||
case REMOTE_CHECK_HIDE:
|
case REMOTE_CHECK_HIDE:
|
||||||
res = check_uid_map(client);
|
res = check_uid_map(client);
|
||||||
break;
|
break;
|
||||||
@ -71,6 +72,7 @@ void magiskhide_handler(int client, ucred *cred) {
|
|||||||
hide_daemon(cred->pid);
|
hide_daemon(cred->pid);
|
||||||
close(client);
|
close(client);
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
write_int(client, res);
|
write_int(client, res);
|
||||||
@ -106,7 +108,7 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
execvp(argv[2], argv + 2);
|
execvp(argv[2], argv + 2);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#if 0 && ENABLE_PTRACE_MONITOR
|
#if 0 && !ENABLE_INJECT
|
||||||
else if (opt == "test"sv)
|
else if (opt == "test"sv)
|
||||||
test_proc_monitor();
|
test_proc_monitor();
|
||||||
#endif
|
#endif
|
||||||
@ -168,6 +170,7 @@ return_code:
|
|||||||
return req == HIDE_STATUS ? (code == HIDE_IS_ENABLED ? 0 : 1) : code != DAEMON_SUCCESS;
|
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 remote_check_hide(int uid, const char *process) {
|
||||||
int fd = connect_daemon();
|
int fd = connect_daemon();
|
||||||
write_int(fd, MAGISKHIDE);
|
write_int(fd, MAGISKHIDE);
|
||||||
@ -190,3 +193,4 @@ void remote_request_hide() {
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -14,21 +14,20 @@
|
|||||||
#define SIGTERMTHRD SIGUSR1
|
#define SIGTERMTHRD SIGUSR1
|
||||||
#define ISOLATED_MAGIC "isolated"
|
#define ISOLATED_MAGIC "isolated"
|
||||||
|
|
||||||
// Global toggle for ptrace monitor
|
|
||||||
#define ENABLE_PTRACE_MONITOR 0
|
|
||||||
|
|
||||||
// CLI entries
|
// CLI entries
|
||||||
int launch_magiskhide(bool late_props);
|
int launch_magiskhide(bool late_props);
|
||||||
int stop_magiskhide();
|
int stop_magiskhide();
|
||||||
int add_list(int client);
|
int add_list(int client);
|
||||||
int rm_list(int client);
|
int rm_list(int client);
|
||||||
void ls_list(int client);
|
void ls_list(int client);
|
||||||
int check_uid_map(int client);
|
|
||||||
|
|
||||||
#if ENABLE_PTRACE_MONITOR
|
#if !ENABLE_INJECT
|
||||||
// Process monitoring
|
// Process monitoring
|
||||||
[[noreturn]] void proc_monitor();
|
[[noreturn]] void proc_monitor();
|
||||||
[[noreturn]] void test_proc_monitor();
|
[[noreturn]] void test_proc_monitor();
|
||||||
|
#else
|
||||||
|
// Response whether target process should be hidden
|
||||||
|
int check_uid_map(int client);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user