From f95bea1d8869f3ce4a162897efcf009f1c6af4bf Mon Sep 17 00:00:00 2001 From: Nolan Cotter <186326284+NolanCotter@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:53:08 -0700 Subject: shims/loader: GetModuleFileName answers for the mapped images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetModuleFileName was host-bound, so a mapped image asking for its own path got gta6rt.exe's. The bundled-module ops now expose the main image and each module's load path: GetModuleFileNameA/W return the mapped module's path (the exe for a null handle, any bundled module for its base) and GetModuleFileName falls through to the host otherwise. GetModuleHandle(nullptr) answers the mapped exe's base the same way. A unix-absolute stored path is spelled Z:\... under Wine. First use measured: the package's game_scarlett_master.exe (a payload verification probe, not the engine) took its own module path as the scan root and verified the full 1.0.2.1 payload through the file layer — 104/104 files, 223,534,748,018 bytes, rpf 22/22, ttpf 57/57, png 5/5, dll 16/16, bad magic 0 — verdict PASS, exit 0. Tested: clang-cl 20 + xwin cross-build clean; loader_test 87 checks, xs_proxy_mock_test PASS under Wine. AI-assisted. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- runtime/src/pe_loader.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'runtime/src/pe_loader.cpp') diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index 5d0386ec0..278444c6f 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp @@ -556,11 +556,21 @@ bool bundled_owns_handle(void* ctx, void* module) { return static_cast(ctx)->owns_module_handle(module); } +void* bundled_main_module(void* ctx) { + return static_cast(ctx)->main_module(); +} + +const std::filesystem::path* bundled_module_path(void* ctx, void* module) { + return static_cast(ctx)->module_path_for(module); +} + const shims::BundledModuleOps kBundledOps{ &bundled_find_loaded, &bundled_load, &bundled_get_proc, &bundled_owns_handle, + &bundled_main_module, + &bundled_module_path, }; } // namespace @@ -730,6 +740,19 @@ bool Loader::owns_module_handle(void* module_handle) const { return false; } +void* Loader::main_module() const { + std::lock_guard lock(mutex_); + return order_.empty() ? nullptr : static_cast(order_.front()->base); +} + +const std::filesystem::path* Loader::module_path_for(void* module_handle) const { + std::lock_guard lock(mutex_); + if (!module_handle) return order_.empty() ? nullptr : &order_.front()->path; + for (Module* m : order_) + if (m->base == module_handle) return &m->path; + return nullptr; +} + // x64 has no frame-pointer chain to fall back on: without its .pdata registered, an exception raised in (or passing // through) a mapped image can't be dispatched past that frame, and the process dies. Images the system loader maps // are found through its own module list; ours are VirtualAlloc'd, so they are registered as dynamic function tables. -- cgit v1.2.3