You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user