mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
use dladdr to get base on android
This commit is contained in:
parent
9661693e72
commit
b072c6bc31
1 changed files with 21 additions and 10 deletions
|
@ -6,13 +6,11 @@
|
|||
#if defined(GEODE_IS_ANDROID32)
|
||||
|
||||
static auto constexpr NEW_SYM = "_Znwj";
|
||||
static constexpr uintptr_t MENULAYER_SCENE = 0x309068 - 0x10000;
|
||||
static constexpr uintptr_t STRING_EMPTY = 0xaa1c48 - 0x10000 - 0xc; // the internal struct size
|
||||
|
||||
#elif defined(GEODE_IS_ANDROID64)
|
||||
|
||||
static auto constexpr NEW_SYM = "_Znwm";
|
||||
static constexpr uintptr_t MENULAYER_SCENE = 0x6a62ec - 0x100000;
|
||||
static constexpr uintptr_t STRING_EMPTY = 0x12d8568 - 0x100000 - 0x18; // the internal struct size
|
||||
|
||||
#endif
|
||||
|
@ -22,19 +20,32 @@ static auto constexpr DELETE_SYM = "_ZdlPv";
|
|||
// 2.2 addition
|
||||
// zmx please fix this
|
||||
|
||||
namespace geode::base {
|
||||
uintptr_t get() {
|
||||
static uintptr_t base = (reinterpret_cast<uintptr_t>(&MenuLayer::scene) - MENULAYER_SCENE) & (~0x1);
|
||||
// static uintptr_t base = reinterpret_cast<uintptr_t>(dlopen("libcocos2dcpp.so", RTLD_NOW));
|
||||
return base;
|
||||
}
|
||||
}
|
||||
|
||||
static void* getLibHandle() {
|
||||
static void* handle = dlopen("libcocos2dcpp.so", RTLD_LAZY | RTLD_NOLOAD);
|
||||
return handle;
|
||||
}
|
||||
|
||||
namespace geode::base {
|
||||
uintptr_t get() {
|
||||
static std::uintptr_t basePtr = 0u;
|
||||
if (basePtr == 0u) {
|
||||
auto handle = getLibHandle();
|
||||
|
||||
// JNI_OnLoad is present on all versions of GD
|
||||
auto sym = dlsym(handle, "JNI_OnLoad");
|
||||
assert(sym != nullptr);
|
||||
|
||||
Dl_info p;
|
||||
auto dlAddrRes = dladdr(sym, &p);
|
||||
assert(dlAddrRes != 0);
|
||||
|
||||
basePtr = reinterpret_cast<std::uintptr_t>(p.dli_fbase);
|
||||
}
|
||||
|
||||
return basePtr;
|
||||
}
|
||||
}
|
||||
|
||||
static void* gdOperatorNew(size_t size) {
|
||||
static auto fnPtr = reinterpret_cast<void*(*)(size_t)>(dlsym(getLibHandle(), NEW_SYM));
|
||||
return fnPtr(size);
|
||||
|
|
Loading…
Reference in a new issue