fix: module name in Zygiskd log

This commit fixes the module name in Zygiskd log which would only show a letter.
This commit is contained in:
ThePedroo
2024-11-08 17:20:01 -03:00
parent c4ab77ed9e
commit 3265bcb581
4 changed files with 15 additions and 12 deletions

View File

@@ -51,23 +51,26 @@ void *entry_thread(void *arg) {
} }
/* WARNING: Dynamic memory based */ /* WARNING: Dynamic memory based */
void entry(int fd) { void companion_entry(int fd) {
LOGI("New companion entry.\n - Client fd: %d\n", fd); LOGI("New companion entry.\n - Client fd: %d\n", fd);
char name[256]; /* TODO: Use non-NULL string termination */
ssize_t ret = read_string(fd, name, sizeof(name)); char name[256 + 1];
if (ret == -1) { ssize_t name_length = read_string(fd, name, sizeof(name) - 1);
if (name_length == -1) {
LOGE("Failed to read module name\n"); 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)); ASSURE_SIZE_WRITE("ZygiskdCompanion", "name", ret, sizeof(uint8_t));
exit(0); 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); int library_fd = read_fd(fd);
ssize_t ret = 0;
if (library_fd == -1) { if (library_fd == -1) {
LOGE("Failed to receive library fd\n"); LOGE("Failed to receive library fd\n");
@@ -83,7 +86,7 @@ void entry(int fd) {
close(library_fd); close(library_fd);
if (module_entry == NULL) { 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); ret = write_uint8_t(fd, 0);
ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t)); ASSURE_SIZE_WRITE("ZygiskdCompanion", "module_entry", ret, sizeof(uint8_t));
@@ -120,7 +123,7 @@ void entry(int fd) {
args->fd = client_fd; args->fd = client_fd;
args->entry = module_entry; 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); ret = write_uint8_t(args->fd, 1);
ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t)); ASSURE_SIZE_WRITE("ZygiskdCompanion", "client_fd", ret, sizeof(uint8_t));

View File

@@ -1,6 +1,6 @@
#ifndef COMPANION_H #ifndef COMPANION_H
#define COMPANION_H #define COMPANION_H
void entry(int fd); void companion_entry(int fd);
#endif /* COMPANION_H */ #endif /* COMPANION_H */

View File

@@ -33,8 +33,6 @@ typedef struct AndroidDlextinfo {
AndroidNamespace *library_namespace; AndroidNamespace *library_namespace;
} AndroidDlextinfo; } AndroidDlextinfo;
extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo);
typedef AndroidNamespace *(*AndroidCreateNamespaceFn)( typedef AndroidNamespace *(*AndroidCreateNamespaceFn)(
const char *name, const char *name,
const char *ld_library_path, const char *ld_library_path,
@@ -45,6 +43,8 @@ typedef AndroidNamespace *(*AndroidCreateNamespaceFn)(
const void *caller_addr const void *caller_addr
); );
extern void *android_dlopen_ext(const char *filename, int flags, const AndroidDlextinfo *extinfo);
void *android_dlopen(char *path, int flags) { void *android_dlopen(char *path, int flags) {
char *dir = dirname(path); char *dir = dirname(path);
struct AndroidDlextinfo info = { struct AndroidDlextinfo info = {

View File

@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
} }
int fd = atoi(argv[2]); int fd = atoi(argv[2]);
entry(fd); companion_entry(fd);
return 0; return 0;
} }