From 06f78c20308f4d0503bbab4e98a27d7b1304c094 Mon Sep 17 00:00:00 2001 From: LeandroLP23 Date: Thu, 8 Oct 2026 22:22:01 +0200 Subject: [PATCH] test(libs): load every patched library with its imports bound ctest loads the libraries from libs/unpatched, so an import that nid_patcher renames out of another library's exports only shows when a title loads the patched prx. patched_libraries loads each patched .prx with LoadLibraryEx on Windows and dlopen(RTLD_NOW) on Linux, and depends on the libs target so the patched files are current. Co-Authored-By: Claude Opus 5.5 --- core/libs/CMakeLists.txt | 7 ++++++ core/libs/tests/PatchedLibraries.cpp | 36 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 core/libs/tests/PatchedLibraries.cpp diff --git a/core/libs/CMakeLists.txt b/core/libs/CMakeLists.txt index 04ef68e3e..5569c3a1b 100644 --- a/core/libs/CMakeLists.txt +++ b/core/libs/CMakeLists.txt @@ -131,6 +131,13 @@ endforeach() add_custom_target(libs DEPENDS ${PATCHED_OUTPUTS}) if(BUILD_TESTING) + add_test_executable(patched_libraries_tests tests/PatchedLibraries.cpp) + add_dependencies(patched_libraries_tests libs) + if(MINGW) + target_compile_options(patched_libraries_tests PRIVATE -fasynchronous-unwind-tables) + target_link_options(patched_libraries_tests PRIVATE -static -static-libgcc -static-libstdc++) + endif() + add_test(NAME patched_libraries COMMAND patched_libraries_tests ${PATCHED_DIR}) add_test_executable(guest_offline_imports_tests tests/GuestOfflineImports.cpp) target_include_directories(guest_offline_imports_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(guest_offline_imports_tests PRIVATE libSceHttp libSceNpEntitlementAccess libSceRudp libc) diff --git a/core/libs/tests/PatchedLibraries.cpp b/core/libs/tests/PatchedLibraries.cpp new file mode 100644 index 000000000..ec0b43273 --- /dev/null +++ b/core/libs/tests/PatchedLibraries.cpp @@ -0,0 +1,36 @@ +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + +int main(int argc, char** argv) { + if (argc != 2) { + std::fprintf(stderr, "usage: %s \n", argv[0]); + return 2; + } + int loaded = 0; + int failed = 0; + for (const auto& entry : std::filesystem::directory_iterator(argv[1])) { + if (entry.path().extension() != ".prx") continue; +#ifdef _WIN32 + if (LoadLibraryExW(entry.path().c_str(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH) != nullptr) { + ++loaded; + continue; + } + std::fprintf(stderr, "%s: LoadLibraryEx failed with error %lu\n", entry.path().filename().string().c_str(), GetLastError()); +#else + if (dlopen(entry.path().c_str(), RTLD_NOW | RTLD_LOCAL) != nullptr) { + ++loaded; + continue; + } + std::fprintf(stderr, "%s\n", dlerror()); +#endif + ++failed; + } + std::printf("%d patched libraries loaded, %d failed\n", loaded, failed); + return loaded > 0 && failed == 0 ? 0 : 1; +}