From 6a1ea4ffff542ebd516df6f71944f6cb08af78f9 Mon Sep 17 00:00:00 2001 From: LA_DI_DA <11174151+0O0o0oOoO00@users.noreply.github.com> Date: Sat, 22 Mar 2025 00:14:10 +0800 Subject: [PATCH] add: add judgments for 32-bit and 64-bit for patchelf --- blcrack/patchelf/CMakeLists.txt | 8 +++++++- blcrack/patchelf/patchelf.cc | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/blcrack/patchelf/CMakeLists.txt b/blcrack/patchelf/CMakeLists.txt index 08504e563..981484b8c 100644 --- a/blcrack/patchelf/CMakeLists.txt +++ b/blcrack/patchelf/CMakeLists.txt @@ -6,4 +6,10 @@ file(GLOB_RECURSE PATCHELF_SRCS ) add_executable(${PATCHELF} ${PATCHELF_SRCS}) target_link_libraries(${PATCHELF} PRIVATE cxxopts::cxxopts) -target_link_options(${PATCHELF} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/patchelf.map) \ No newline at end of file +target_link_options(${PATCHELF} PRIVATE -Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/patchelf.map) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + target_compile_definitions(${PATCHELF} PRIVATE USE_64) +else() + target_compile_definitions(${PATCHELF} PRIVATE USE_32) +endif() diff --git a/blcrack/patchelf/patchelf.cc b/blcrack/patchelf/patchelf.cc index 6f2fc1557..983bf5c9d 100644 --- a/blcrack/patchelf/patchelf.cc +++ b/blcrack/patchelf/patchelf.cc @@ -2732,14 +2732,19 @@ static void patchElf() { namespace fs = std::filesystem; -using ElfFile32 = ElfFile; +#ifdef USE_64 +using Elf = ElfFile; +#endif // USE_64 +#ifdef USE_32 +using Elf = ElfFile; +#endif // USE_32 void do_local_patch(const std::string& game_lib_dir) { fs::path lib_dir(game_lib_dir); auto libtolua_file = lib_dir / "libtolua.so"; auto libtolua_backup_file = lib_dir / "libtolua.so.bak"; - ElfFile32 libtolua(readFile(libtolua_file)); + Elf libtolua(readFile(libtolua_file)); auto curr_needed = libtolua.getNeededLibs(); for (const auto& lib : curr_needed) { @@ -2765,7 +2770,7 @@ void do_local_depatch(const std::string& game_lib_dir) { return; } - ElfFile32 libtolua(readFile(libtolua_file)); + Elf libtolua(readFile(libtolua_file)); auto curr_needed = libtolua.getNeededLibs(); for (const auto& lib : curr_needed) {