improve: port ptracer to C

This commit ports the C++ to C99 from zygisk-ptracer code, allowing a ~3x size reduce in its binary.
This commit is contained in:
ThePedroo
2025-04-14 19:32:49 -03:00
parent 1a3f497e1a
commit b94ea0c5f5
21 changed files with 1739 additions and 1690 deletions

View File

@@ -65,7 +65,7 @@
return -1; \
}
#define write_func_def(type) \
#define write_func_def(type) \
ssize_t write_## type(int fd, type val)
#define read_func_def(type) \

View File

@@ -58,34 +58,6 @@ static enum Architecture get_arch(void) {
exit(1);
}
int create_library_fd(const char *restrict so_path) {
int so_fd = open(so_path, O_RDONLY);
if (so_fd == -1) {
LOGE("Failed opening so file: %s\n", strerror(errno));
return -1;
}
off_t so_size = lseek(so_fd, 0, SEEK_END);
if (so_size == -1) {
LOGE("Failed getting so file size: %s\n", strerror(errno));
close(so_fd);
return -1;
}
if (lseek(so_fd, 0, SEEK_SET) == -1) {
LOGE("Failed seeking so file: %s\n", strerror(errno));
close(so_fd);
return -1;
}
return so_fd;
}
/* WARNING: Dynamic memory based */
static void load_modules(enum Architecture arch, struct Context *restrict context) {
context->len = 0;
@@ -138,7 +110,7 @@ static void load_modules(enum Architecture arch, struct Context *restrict contex
errno = 0;
} else continue;
int lib_fd = create_library_fd(so_path);
int lib_fd = open(so_path, O_RDONLY | O_CLOEXEC);
if (lib_fd == -1) {
LOGE("Failed loading module `%s`\n", name);
@@ -556,12 +528,6 @@ void zygiskd_start(char *restrict argv[]) {
break;
}
if (write_string(client_fd, context.modules[i].name) == -1) {
LOGE("Failed writing module name.\n");
break;
}
}
break;