From d8c997788d987a1652709cc6f7cf3d395ab46cf6 Mon Sep 17 00:00:00 2001 From: HanSoBored Date: Wed, 8 Apr 2026 13:22:11 +0700 Subject: [PATCH] refactor(il2cpp): use memkit_xdl wrappers instead of raw xdl calls - Replace xdl_open() with memkit_xdl_open() (2 call sites) - Replace xdl_sym() with memkit_xdl_sym() - Replace xdl_dsym() with memkit_xdl_dsym() - Remove direct #include "xdl.h" from il2cpp.c - Export XDL flag constants (XDL_DEFAULT, XDL_TRY_FORCE_LOAD, XDL_ALWAYS_FORCE_LOAD, XDL_NON_SYM, XDL_FULL_PATHNAME, XDL_DI_DLINFO) in memkit.h so consumers don't need xdl.h This enforces a clean architectural boundary where il2cpp.c only depends on memkit.h, not the underlying xDL library directly. --- include/memkit.h | 18 ++++++++++++++++++ src/il2cpp.c | 15 +++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/memkit.h b/include/memkit.h index 9f79f0f..03173c2 100644 --- a/include/memkit.h +++ b/include/memkit.h @@ -167,6 +167,24 @@ typedef struct { */ typedef struct memkit_addr_ctx memkit_addr_ctx_t; +// ============================================================================ +// XDL FLAG CONSTANTS +// ============================================================================ + +/* memkit_xdl_open() flags */ +#define XDL_DEFAULT 0x00 +#define XDL_TRY_FORCE_LOAD 0x01 +#define XDL_ALWAYS_FORCE_LOAD 0x02 + +/* memkit_xdl_addr_to_symbol4() flags */ +#define XDL_NON_SYM 0x01 + +/* memkit_xdl_iterate() flags */ +#define XDL_FULL_PATHNAME 0x01 + +/* xdl_dlinfo() selector */ +#define XDL_DI_DLINFO 1 + // ============================================================================ // XDL WRAPPER API - PHASE 1: CORE DISCOVERY // ============================================================================ diff --git a/src/il2cpp.c b/src/il2cpp.c index b7064b5..0b0a456 100644 --- a/src/il2cpp.c +++ b/src/il2cpp.c @@ -5,7 +5,6 @@ #include #include "memkit.h" -#include "xdl.h" // ============================================================================ // IL2CPP: STATIC STATE (Thread-Safe via C11 Atomics) @@ -21,10 +20,10 @@ static atomic_bool g_initialized = ATOMIC_VAR_INIT(false); bool memkit_il2cpp_init(void) { bool expected = false; - // Only the first thread (CAS succeeds) executes xdl_open + // Only the first thread (CAS succeeds) executes memkit_xdl_open // atomic_compare_exchange_strong: 100% thread-safe, lock-free if (atomic_compare_exchange_strong(&g_initialized, &expected, true)) { - g_il2cpp_handle = xdl_open("libil2cpp.so", XDL_DEFAULT); + g_il2cpp_handle = memkit_xdl_open("libil2cpp.so", XDL_DEFAULT); } // Wait briefly if another thread is still opening the handle (rare case) @@ -60,16 +59,16 @@ void* memkit_il2cpp_resolve(const char* symbol_name) { // If handle is NULL, try to open directly if (!g_il2cpp_handle) { - g_il2cpp_handle = xdl_open("libil2cpp.so", XDL_DEFAULT); + g_il2cpp_handle = memkit_xdl_open("libil2cpp.so", XDL_DEFAULT); if (!g_il2cpp_handle) { return NULL; } } // Resolve the symbol using XDL - // xdl_sym searches in .dynsym (dynamic symbol table) + // memkit_xdl_sym searches in .dynsym (dynamic symbol table) // This is where most exported functions live - return xdl_sym(g_il2cpp_handle, symbol_name, NULL); + return memkit_xdl_sym(g_il2cpp_handle, symbol_name, NULL); } // ============================================================================ @@ -89,10 +88,10 @@ void* memkit_il2cpp_resolve_symtab(const char* symbol_name) { return NULL; } - // Use xdl_dsym to search only in .symtab section + // Use memkit_xdl_dsym to search only in .symtab section // This is useful for: // - Stripped symbols // - Internal/private functions // - Debug symbols - return xdl_dsym(g_il2cpp_handle, symbol_name, NULL); + return memkit_xdl_dsym(g_il2cpp_handle, symbol_name, NULL); }