mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 12:05:30 +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 reboot();
|
||||
void magisk_logging();
|
||||
void start_log_daemon();
|
||||
void setup_logfile(bool reset);
|
||||
|
||||
|
@ -149,6 +149,20 @@ static int magisk_log(int prio, const char *fmt, va_list ap) {
|
||||
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); }
|
||||
void magisk_logging() {
|
||||
log_cb.d = mlog(DEBUG);
|
||||
@ -158,16 +172,6 @@ void magisk_logging() {
|
||||
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() {
|
||||
int fds[2];
|
||||
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_C_INCLUDES := $(LOCAL_PATH)/xhook/libxhook/jni
|
||||
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_SRC_FILES := \
|
||||
xhook/libxhook/jni/xh_log.c \
|
||||
|
@ -48,7 +48,7 @@ enum : int {
|
||||
|
||||
int connect_daemon(bool create = false);
|
||||
|
||||
void android_logging();
|
||||
void magisk_logging();
|
||||
|
||||
// Daemon handlers
|
||||
void post_fs_data(int client);
|
||||
|
@ -81,7 +81,7 @@ static void inject_cleanup_wait() {
|
||||
__attribute__((constructor))
|
||||
static void inject_init() {
|
||||
if (char *env = getenv(INJECT_ENV_2)) {
|
||||
android_logging();
|
||||
magisk_logging();
|
||||
LOGD("zygisk: inject 2nd stage\n");
|
||||
active_threads = 1;
|
||||
unsetenv(INJECT_ENV_2);
|
||||
@ -100,7 +100,7 @@ static void inject_init() {
|
||||
active_threads++;
|
||||
new_daemon_thread(&unload_first_stage, env);
|
||||
} else if (getenv(INJECT_ENV_1)) {
|
||||
android_logging();
|
||||
magisk_logging();
|
||||
LOGD("zygisk: inject 1st stage\n");
|
||||
|
||||
char *ld = getenv("LD_PRELOAD");
|
||||
@ -128,7 +128,7 @@ static void inject_init() {
|
||||
// Start code for magiskd IPC
|
||||
|
||||
int app_process_main(int argc, char *argv[]) {
|
||||
android_logging();
|
||||
magisk_logging();
|
||||
|
||||
if (int fd = connect_daemon(); fd >= 0) {
|
||||
write_int(fd, ZYGISK_REQUEST);
|
||||
|
Loading…
Reference in New Issue
Block a user