mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 18:15:30 +00:00
Make Zygisk 1st class citizen
This commit is contained in:
parent
c252a50fd7
commit
2b17c77195
@ -11,7 +11,7 @@ ifdef B_MAGISK
|
|||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := magisk
|
LOCAL_MODULE := magisk
|
||||||
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap
|
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties libutils libphmap libxhook
|
||||||
LOCAL_C_INCLUDES := jni/include
|
LOCAL_C_INCLUDES := jni/include
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
@ -33,23 +33,13 @@ 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 ($(DISABLE_ZYGISK),1)
|
|
||||||
LOCAL_SRC_FILES += magiskhide/proc_monitor.cpp
|
|
||||||
LOCAL_CPPFLAGS := -DENABLE_INJECT=0
|
|
||||||
else
|
|
||||||
LOCAL_STATIC_LIBRARIES += libxhook
|
|
||||||
LOCAL_SRC_FILES += \
|
|
||||||
zygisk/entry.cpp \
|
zygisk/entry.cpp \
|
||||||
zygisk/utils.cpp \
|
zygisk/utils.cpp \
|
||||||
zygisk/hook.cpp \
|
zygisk/hook.cpp \
|
||||||
zygisk/memory.cpp
|
zygisk/memory.cpp
|
||||||
LOCAL_CPPFLAGS := -DENABLE_INJECT=1
|
|
||||||
endif
|
LOCAL_LDLIBS := -llog
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
|
@ -20,11 +20,9 @@ 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;
|
||||||
}
|
}
|
||||||
@ -48,4 +46,3 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
return call_applet(argc, argv);
|
return call_applet(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,3 @@ void su_daemon_handler(int client, ucred *credential);
|
|||||||
// MagiskHide
|
// MagiskHide
|
||||||
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
|
|
||||||
int remote_check_hide(int uid, const char *process);
|
|
||||||
void remote_request_hide();
|
|
||||||
#endif
|
|
||||||
|
@ -299,12 +299,6 @@ int launch_magiskhide(bool late_props) {
|
|||||||
if (late_props)
|
if (late_props)
|
||||||
hide_late_sensitive_props();
|
hide_late_sensitive_props();
|
||||||
|
|
||||||
#if !ENABLE_INJECT
|
|
||||||
// Start monitoring
|
|
||||||
if (new_daemon_thread(&proc_monitor))
|
|
||||||
return DAEMON_ERROR;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hide_state = true;
|
hide_state = true;
|
||||||
update_hide_config();
|
update_hide_config();
|
||||||
|
|
||||||
@ -322,9 +316,6 @@ 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_INJECT
|
|
||||||
pthread_kill(monitor_thread, SIGTERMTHRD);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hide_state = false;
|
hide_state = false;
|
||||||
@ -334,9 +325,6 @@ 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_INJECT
|
|
||||||
pthread_kill(monitor_thread, SIGALRM);
|
|
||||||
#endif
|
|
||||||
hide_late_sensitive_props();
|
hide_late_sensitive_props();
|
||||||
} else {
|
} else {
|
||||||
db_settings dbs;
|
db_settings dbs;
|
||||||
@ -375,22 +363,3 @@ bool is_hide_target(int uid, string_view process, int max_len) {
|
|||||||
}
|
}
|
||||||
return false;
|
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
|
|
||||||
|
@ -62,17 +62,6 @@ 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:
|
|
||||||
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);
|
write_int(client, res);
|
||||||
@ -107,13 +96,9 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
hide_unmount();
|
hide_unmount();
|
||||||
execvp(argv[2], argv + 2);
|
execvp(argv[2], argv + 2);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
} else {
|
||||||
#if 0 && !ENABLE_INJECT
|
|
||||||
else if (opt == "test"sv)
|
|
||||||
test_proc_monitor();
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
int fd = connect_daemon();
|
int fd = connect_daemon();
|
||||||
@ -169,28 +154,3 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
return_code:
|
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 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
|
|
||||||
|
@ -21,16 +21,6 @@ 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);
|
||||||
|
|
||||||
#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
|
// Utility functions
|
||||||
void crawl_procfs(const std::function<bool (int)> &fn);
|
void crawl_procfs(const std::function<bool (int)> &fn);
|
||||||
void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn);
|
void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn);
|
||||||
@ -54,8 +44,6 @@ enum {
|
|||||||
RM_HIDELIST,
|
RM_HIDELIST,
|
||||||
LS_HIDELIST,
|
LS_HIDELIST,
|
||||||
HIDE_STATUS,
|
HIDE_STATUS,
|
||||||
REMOTE_CHECK_HIDE,
|
|
||||||
REMOTE_DO_HIDE
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -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, ...) \
|
#define DCL_HOOK_FUNC(ret, func, ...) \
|
||||||
ret (*old_##func)(__VA_ARGS__); \
|
ret (*old_##func)(__VA_ARGS__); \
|
||||||
ret new_##func(__VA_ARGS__)
|
ret new_##func(__VA_ARGS__)
|
||||||
|
Loading…
Reference in New Issue
Block a user