Files
AnyPS5/core/libs/tests/PatchedLibraries.cpp
T
LeandroLP23andClaude Opus 5.5 06f78c2030 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 <noreply@anthropic.com>
2026-10-09 09:05:19 +02:00

37 lines
1.1 KiB
C++

#include <cstdio>
#include <filesystem>
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
int main(int argc, char** argv) {
if (argc != 2) {
std::fprintf(stderr, "usage: %s <patched libraries directory>\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;
}