From 3265bcb5812a0801e77f01c21884793ee73ee2c3 Mon Sep 17 00:00:00 2001 From: ThePedroo Date: Fri, 8 Nov 2024 17:20:01 -0300 Subject: [PATCH] fix: module name in Zygiskd log This commit fixes the module name in Zygiskd log which would only show a letter. --- zygiskd/src/companion.c | 19 +++++++++++-------- zygiskd/src/companion.h | 2 +- zygiskd/src/dl.c | 4 ++-- zygiskd/src/main.c | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/zygiskd/src/companion.c b/zygiskd/src/companion.c index 5d4edc7..486b6fa 100644 --- a/zygiskd/src/companion.c +++ b/zygiskd/src/companion.c @@ -51,23 +51,26 @@ void *entry_thread(void *arg) { } /* WARNING: Dynamic memory based */ -void entry(int fd) { +void companion_entry(int fd) { LOGI("New companion entry.\n - Client fd: %d\n", fd); - char name[256]; - ssize_t ret = read_string(fd, name, sizeof(name)); - if (ret == -1) { + /* TODO: Use non-NULL string termination */ + char name[256 + 1]; + ssize_t name_length = read_string(fd, name, sizeof(name) - 1); + if (name_length == -1) { LOGE("Failed to read module name\n"); - ret = write_uint8_t(fd, 2); + ssize_t ret = write_uint8_t(fd, 2); ASSURE_SIZE_WRITE("ZygiskdCompanion", "name", ret, sizeof(uint8_t)); exit(0); } + name[name_length] = '\0'; - LOGI(" - Module name: `%.*s`\n", (int)ret, name); + LOGI(" - Module name: `%.*s`\n", (int)name_length, name); int library_fd = read_fd(fd); + ssize_t ret = 0; if (library_fd == -1) { LOGE("Failed to receive library fd\n"); @@ -83,7 +86,7 @@ void entry(int fd) { close(library_fd); if (module_entry == NULL) { - LOGI("No companion module entry for module: %.*s\n", (int)ret, name); + LOGI("No companion module entry for module: %.*s\n", (int)name_length, name); ret = write_uint8_t(fd, 0); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); @@ -120,7 +123,7 @@ void entry(int fd) { args->fd = client_fd; args->entry = module_entry; - LOGI("New companion request.\n - Module name: %.*s\n - Client fd: %d\n", (int)ret, name, args->fd); + LOGI("New companion request.\n - Module name: %.*s\n - Client fd: %d\n", (int)name_length, name, args->fd); ret = write_uint8_t(args->fd, 1); ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t)); diff --git a/zygiskd/src/companion.h b/zygiskd/src/companion.h index 1b931e8..f19c5a8 100644 --- a/zygiskd/src/companion.h +++ b/zygiskd/src/companion.h @@ -1,6 +1,6 @@ #ifndef COMPANION_H #define COMPANION_H -void entry(int fd); +void companion_entry(int fd); #endif /* COMPANION_H */ diff --git a/zygiskd/src/dl.c b/zygiskd/src/dl.c index 37aeec2..5018b0f 100644 --- a/zygiskd/src/dl.c +++ b/zygiskd/src/dl.c @@ -33,8 +33,6 @@ typedef struct AndroidDlextinfo { AndroidNamespace *library_namespace; } AndroidDlextinfo; -extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo); - typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( const char *name, const char *ld_library_path, @@ -45,6 +43,8 @@ typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( const void *caller_addr ); +extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo); + void *android_dlopen(char *path, int flags) { char *dir = dirname(path); struct AndroidDlextinfo info = { diff --git a/zygiskd/src/main.c b/zygiskd/src/main.c index 2fa7992..f1245cd 100644 --- a/zygiskd/src/main.c +++ b/zygiskd/src/main.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { } int fd = atoi(argv[2]); - entry(fd); + companion_entry(fd); return 0; }