mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 13:49:26 +08:00
opt: use il2cpp api to get LuaScriptMgr.get_Inst func
This commit is contained in:
@@ -21,10 +21,3 @@ target_compile_definitions(${CRACKER}
|
||||
PRIVATE ${SPDLOG_DEFINES} SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE
|
||||
PRIVATE SOL_USE_LUA_HPP
|
||||
)
|
||||
if (CMAKE_ANDROID_ARCH_ABI STREQUAL "x86")
|
||||
target_compile_definitions(${CRACKER} PRIVATE ARCH_X86)
|
||||
elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
|
||||
target_compile_definitions(${CRACKER} PRIVATE ARCH_ARMEABI_V7A)
|
||||
elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a")
|
||||
target_compile_definitions(${CRACKER} PRIVATE ARCH_ARM64_V8A)
|
||||
endif ()
|
||||
@@ -89,15 +89,43 @@ struct LuaScriptMgr_o {
|
||||
|
||||
using LuaScriptMgr_get_Inst = struct LuaScriptMgr_o*(*)();
|
||||
|
||||
#if defined(ARCH_X86)
|
||||
#define LuaScriptMgr_get_Inst_OFFSET 0x1076B15
|
||||
#elif defined(ARCH_ARM64_V8A)
|
||||
#define LuaScriptMgr_get_Inst_OFFSET 0x14BF998
|
||||
#elif defined(ARCH_ARMEABI_V7A)
|
||||
#define LuaScriptMgr_get_Inst_OFFSET 0xFE8894
|
||||
#else
|
||||
#warning "No architecture defined for il2cpp.hpp, assuming x86"
|
||||
#define LuaScriptMgr_get_Inst_OFFSET 0x1076B15
|
||||
#endif
|
||||
using Il2CppDomain = void;
|
||||
using Il2CppAssembly = void;
|
||||
using Il2CppImage = void;
|
||||
using Il2CppClass = void;
|
||||
|
||||
struct MethodInfo {
|
||||
void* methodPointer; // Il2CppMethodPointer
|
||||
void* invoker_method; // InvokerMethod
|
||||
const char* name;
|
||||
void* klass; // Il2CppClass*
|
||||
void* return_type; // const Il2CppType*
|
||||
void* parameters; // const ParameterInfo*
|
||||
union {
|
||||
void* rgctx_data; // const Il2CppRGCTXData*
|
||||
void* methodDefinition; // const Il2CppMethodDefinition*
|
||||
};
|
||||
union {
|
||||
void* genericMethod; // const Il2CppGenericMethod*
|
||||
void* genericContainer; // const Il2CppGenericContainer*
|
||||
};
|
||||
uint32_t token;
|
||||
uint16_t flags;
|
||||
uint16_t iflags;
|
||||
uint16_t slot;
|
||||
uint8_t parameters_count;
|
||||
uint8_t is_generic : 1;
|
||||
uint8_t is_inflated : 1;
|
||||
uint8_t wrapper_type : 1;
|
||||
uint8_t is_marshaled_from_native : 1;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
Il2CppDomain* il2cpp_domain_get();
|
||||
Il2CppAssembly** il2cpp_domain_get_assemblies(Il2CppDomain* domain, size_t* size);
|
||||
Il2CppImage* il2cpp_assembly_get_image(Il2CppAssembly *assembly);
|
||||
Il2CppClass* il2cpp_class_from_name(Il2CppImage* image, const char* namespaze, const char *name);
|
||||
MethodInfo* il2cpp_class_get_method_from_name(Il2CppClass *klass, const char* name, int argsCount);
|
||||
}
|
||||
|
||||
#endif //IL2CPPSTRUCT_HPP
|
||||
|
||||
@@ -32,10 +32,34 @@ void* Utils::get_so_base_address(const std::string& name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lua_State* Utils::get_lua_state() {
|
||||
void* il2cpp_base_addr = get_so_base_address("libil2cpp.so");
|
||||
static LuaScriptMgr_get_Inst get_lua_script_mgr_get_inst() {
|
||||
Il2CppDomain* domain = il2cpp_domain_get();
|
||||
size_t assembly_count = 0;
|
||||
Il2CppAssembly** assemblies = il2cpp_domain_get_assemblies(domain, &assembly_count);
|
||||
|
||||
LuaScriptMgr_get_Inst get_instance = reinterpret_cast<LuaScriptMgr_get_Inst>(PTR_ADD(il2cpp_base_addr, LuaScriptMgr_get_Inst_OFFSET));
|
||||
Il2CppClass* cls = nullptr;
|
||||
for (size_t i = 0; i < assembly_count; ++i) {
|
||||
Il2CppImage* image = il2cpp_assembly_get_image(assemblies[i]);
|
||||
Il2CppClass* klass = il2cpp_class_from_name(image, "", "LuaScriptMgr");
|
||||
if (klass != nullptr) {
|
||||
cls = klass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cls != nullptr) {
|
||||
MethodInfo* method_info = il2cpp_class_get_method_from_name(cls, "get_Inst", 0);
|
||||
if (method_info != nullptr) {
|
||||
auto method = reinterpret_cast<LuaScriptMgr_get_Inst>(method_info->methodPointer);
|
||||
SPDLOG_INFO("Found LuaScriptMgr.get_Inst at {}", (void*)method_info->methodPointer);
|
||||
return method;
|
||||
}
|
||||
}
|
||||
SPDLOG_ERROR("Failed to get LuaScriptMgr.get_Inst");
|
||||
throw std::runtime_error("Failed to get LuaScriptMgr.get_Inst");
|
||||
}
|
||||
|
||||
lua_State* Utils::get_lua_state() {
|
||||
LuaScriptMgr_get_Inst get_instance = get_lua_script_mgr_get_inst();
|
||||
struct LuaScriptMgr_o* lua_script_mgr = get_instance();
|
||||
|
||||
LuaInterface_LuaState_o* luaState = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user