mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-18 23:48:29 +00:00
Make xhook log as Magisk
This commit is contained in:
parent
5754782a4e
commit
bade4f2c6a
@ -8,7 +8,6 @@ extern int DAEMON_STATE;
|
|||||||
|
|
||||||
void unlock_blocks();
|
void unlock_blocks();
|
||||||
void reboot();
|
void reboot();
|
||||||
void magisk_logging();
|
|
||||||
void start_log_daemon();
|
void start_log_daemon();
|
||||||
void setup_logfile(bool reset);
|
void setup_logfile(bool reset);
|
||||||
|
|
||||||
|
@ -149,6 +149,20 @@ static int magisk_log(int prio, const char *fmt, va_list ap) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to override external C library logging
|
||||||
|
extern "C" int magisk_log_print(int prio, const char *tag, const char *fmt, ...) {
|
||||||
|
char buf[4096];
|
||||||
|
auto len = strlcpy(buf, tag, sizeof(buf));
|
||||||
|
// Prevent format specifications in the tag
|
||||||
|
std::replace(buf, buf + len, '%', '_');
|
||||||
|
snprintf(buf + len, sizeof(buf) - len, ": %s", fmt);
|
||||||
|
va_list argv;
|
||||||
|
va_start(argv, fmt);
|
||||||
|
int ret = magisk_log(prio, buf, argv);
|
||||||
|
va_end(argv);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#define mlog(prio) [](auto fmt, auto ap){ return magisk_log(ANDROID_LOG_##prio, fmt, ap); }
|
#define mlog(prio) [](auto fmt, auto ap){ return magisk_log(ANDROID_LOG_##prio, fmt, ap); }
|
||||||
void magisk_logging() {
|
void magisk_logging() {
|
||||||
log_cb.d = mlog(DEBUG);
|
log_cb.d = mlog(DEBUG);
|
||||||
@ -158,16 +172,6 @@ void magisk_logging() {
|
|||||||
log_cb.ex = nop_ex;
|
log_cb.ex = nop_ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define alog(prio) [](auto fmt, auto ap){ \
|
|
||||||
return __android_log_vprint(ANDROID_LOG_##prio, "Magisk", fmt, ap); }
|
|
||||||
void android_logging() {
|
|
||||||
log_cb.d = alog(DEBUG);
|
|
||||||
log_cb.i = alog(INFO);
|
|
||||||
log_cb.w = alog(WARN);
|
|
||||||
log_cb.e = alog(ERROR);
|
|
||||||
log_cb.ex = nop_ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void start_log_daemon() {
|
void start_log_daemon() {
|
||||||
int fds[2];
|
int fds[2];
|
||||||
if (pipe2(fds, O_CLOEXEC) == 0) {
|
if (pipe2(fds, O_CLOEXEC) == 0) {
|
||||||
|
2
native/jni/external/Android.mk
vendored
2
native/jni/external/Android.mk
vendored
@ -365,7 +365,7 @@ include $(CLEAR_VARS)
|
|||||||
LOCAL_MODULE:= libxhook
|
LOCAL_MODULE:= libxhook
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/xhook/libxhook/jni
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/xhook/libxhook/jni
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||||
LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden
|
LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden -D__android_log_print=magisk_log_print
|
||||||
LOCAL_CONLYFLAGS := -std=c11
|
LOCAL_CONLYFLAGS := -std=c11
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
xhook/libxhook/jni/xh_log.c \
|
xhook/libxhook/jni/xh_log.c \
|
||||||
|
@ -48,7 +48,7 @@ enum : int {
|
|||||||
|
|
||||||
int connect_daemon(bool create = false);
|
int connect_daemon(bool create = false);
|
||||||
|
|
||||||
void android_logging();
|
void magisk_logging();
|
||||||
|
|
||||||
// Daemon handlers
|
// Daemon handlers
|
||||||
void post_fs_data(int client);
|
void post_fs_data(int client);
|
||||||
|
@ -81,7 +81,7 @@ static void inject_cleanup_wait() {
|
|||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
static void inject_init() {
|
static void inject_init() {
|
||||||
if (char *env = getenv(INJECT_ENV_2)) {
|
if (char *env = getenv(INJECT_ENV_2)) {
|
||||||
android_logging();
|
magisk_logging();
|
||||||
LOGD("zygisk: inject 2nd stage\n");
|
LOGD("zygisk: inject 2nd stage\n");
|
||||||
active_threads = 1;
|
active_threads = 1;
|
||||||
unsetenv(INJECT_ENV_2);
|
unsetenv(INJECT_ENV_2);
|
||||||
@ -100,7 +100,7 @@ static void inject_init() {
|
|||||||
active_threads++;
|
active_threads++;
|
||||||
new_daemon_thread(&unload_first_stage, env);
|
new_daemon_thread(&unload_first_stage, env);
|
||||||
} else if (getenv(INJECT_ENV_1)) {
|
} else if (getenv(INJECT_ENV_1)) {
|
||||||
android_logging();
|
magisk_logging();
|
||||||
LOGD("zygisk: inject 1st stage\n");
|
LOGD("zygisk: inject 1st stage\n");
|
||||||
|
|
||||||
char *ld = getenv("LD_PRELOAD");
|
char *ld = getenv("LD_PRELOAD");
|
||||||
@ -128,7 +128,7 @@ static void inject_init() {
|
|||||||
// Start code for magiskd IPC
|
// Start code for magiskd IPC
|
||||||
|
|
||||||
int app_process_main(int argc, char *argv[]) {
|
int app_process_main(int argc, char *argv[]) {
|
||||||
android_logging();
|
magisk_logging();
|
||||||
|
|
||||||
if (int fd = connect_daemon(); fd >= 0) {
|
if (int fd = connect_daemon(); fd >= 0) {
|
||||||
write_int(fd, ZYGISK_REQUEST);
|
write_int(fd, ZYGISK_REQUEST);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user