You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Co-authored-by: vvb2060 <vvb2060@gmail.com> Co-authored-by: topjohnwu <topjohnwu@gmail.com>
36 lines
978 B
C++
36 lines
978 B
C++
#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,
|
|
};
|