add: Android 9 support (#117)

This commit makes ReZygisk load Zygisk libraries directly, not utilizing memfd, as it doesn't exist in older versions of Android.
This commit is contained in:
Reveny
2025-03-22 23:12:24 +01:00
committed by GitHub
parent bc6cf67c7b
commit 92e2f528a9
5 changed files with 34 additions and 32 deletions
+13 -1
View File
@@ -6,6 +6,7 @@
#include <android/dlext.h>
#include "dl.h"
#include "files.hpp"
#include "logging.h"
extern "C" [[gnu::weak]] struct android_namespace_t*
@@ -50,11 +51,22 @@ void* DlopenMem(int fd, int flags) {
.library_fd = fd
};
auto* handle = android_dlopen_ext("/jit-cache-zygisk", flags, &info);
/* INFO: We need to find the path of the fd since passing "" to android_dlopen_ext
will not work and passing the original "jit-cache-zygisk" will cause a detection again. */
char path[PATH_MAX];
if (get_path_from_fd(fd, path, sizeof(path)) != 0) {
LOGE("Failed to get path for fd: %d", fd);
return NULL;
}
LOGD("Path for fd %d: %s", fd, path);
auto *handle = android_dlopen_ext(path, flags, &info);
if (handle) {
LOGV("dlopen fd %d: %p", fd, handle);
} else {
LOGE("dlopen fd %d: %s", fd, dlerror());
}
return handle;
}
+15
View File
@@ -120,3 +120,18 @@ sDIR make_dir(DIR *dp) {
sFILE make_file(FILE *fp) {
return sFILE(fp, [](FILE *fp){ return fp ? fclose(fp) : 1; });
}
int get_path_from_fd(int fd, char *buf, size_t size) {
if (fd < 0 || !buf || size == 0) return -1;
/* NOTE: We assume that the path is always at /data/adb/modules/xxx
which should never be longer than 128 chars. */
char proc_path[128];
snprintf(proc_path, sizeof(proc_path), "/proc/self/fd/%d", fd);
ssize_t len = readlink(proc_path, buf, size - 1);
if (len == -1) return -1;
buf[len] = '\0';
return 0;
}