You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Refactor zygisk to use native bridge to inject
Co-authored-by: vvb2060 <vvb2060@gmail.com> Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
35
native/src/zygisk/native_bridge.cpp
Normal file
35
native/src/zygisk/native_bridge.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <android/dlext.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unwind.h>
|
||||
|
||||
#include <magisk.hpp>
|
||||
#include "../core/core.hpp"
|
||||
|
||||
// The reference layout of this struct
|
||||
// https://cs.android.com/android/platform/superproject/main/+/main:art/libnativebridge/include/nativebridge/native_bridge.h
|
||||
struct NativeBridgeCallbacks {
|
||||
uint32_t version;
|
||||
void *padding[5];
|
||||
bool (*isCompatibleWith)(uint32_t);
|
||||
};
|
||||
|
||||
static bool is_compatible_with(uint32_t) {
|
||||
auto name = get_prop(NBPROP);
|
||||
android_dlextinfo info = {
|
||||
.flags = ANDROID_DLEXT_FORCE_LOAD
|
||||
};
|
||||
void *handle = android_dlopen_ext(name.data(), RTLD_LAZY, &info);
|
||||
if (handle) {
|
||||
auto entry = reinterpret_cast<void (*)(void *)>(dlsym(handle, "zygisk_inject_entry"));
|
||||
if (entry) {
|
||||
entry(handle);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" [[maybe_unused]] NativeBridgeCallbacks NativeBridgeItf{
|
||||
.version = 2,
|
||||
.padding = {},
|
||||
.isCompatibleWith = &is_compatible_with,
|
||||
};
|
||||
Reference in New Issue
Block a user