diff options
| author | Nolan Cotter <186326284+NolanCotter@users.noreply.github.com> | 2026-11-22 17:53:08 -0700 |
|---|---|---|
| committer | Nolan Cotter <186326284+NolanCotter@users.noreply.github.com> | 2026-11-22 17:53:08 -0700 |
| commit | f95bea1d8869f3ce4a162897efcf009f1c6af4bf (patch) | |
| tree | dbc23f57467a7bfbd68b729e523bc5e7c05d09a6 /runtime/src/pe_loader.cpp | |
| parent | 309052ad31a1ab9d6728930ae782c790985a2f46 (diff) | |
shims/loader: GetModuleFileName answers for the mapped images
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>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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) { | |||
| 556 | return static_cast<Loader*>(ctx)->owns_module_handle(module); | 556 | return static_cast<Loader*>(ctx)->owns_module_handle(module); |
| 557 | } | 557 | } |
| 558 | 558 | ||
| 559 | void* bundled_main_module(void* ctx) { | ||
| 560 | return static_cast<Loader*>(ctx)->main_module(); | ||
| 561 | } | ||
| 562 | |||
| 563 | const std::filesystem::path* bundled_module_path(void* ctx, void* module) { | ||
| 564 | return static_cast<Loader*>(ctx)->module_path_for(module); | ||
| 565 | } | ||
| 566 | |||
| 559 | const shims::BundledModuleOps kBundledOps{ | 567 | const shims::BundledModuleOps kBundledOps{ |
| 560 | &bundled_find_loaded, | 568 | &bundled_find_loaded, |
| 561 | &bundled_load, | 569 | &bundled_load, |
| 562 | &bundled_get_proc, | 570 | &bundled_get_proc, |
| 563 | &bundled_owns_handle, | 571 | &bundled_owns_handle, |
| 572 | &bundled_main_module, | ||
| 573 | &bundled_module_path, | ||
| 564 | }; | 574 | }; |
| 565 | } // namespace | 575 | } // namespace |
| 566 | 576 | ||
| @@ -730,6 +740,19 @@ bool Loader::owns_module_handle(void* module_handle) const { | |||
| 730 | return false; | 740 | return false; |
| 731 | } | 741 | } |
| 732 | 742 | ||
| 743 | void* Loader::main_module() const { | ||
| 744 | std::lock_guard lock(mutex_); | ||
| 745 | return order_.empty() ? nullptr : static_cast<void*>(order_.front()->base); | ||
| 746 | } | ||
| 747 | |||
| 748 | const std::filesystem::path* Loader::module_path_for(void* module_handle) const { | ||
| 749 | std::lock_guard lock(mutex_); | ||
| 750 | if (!module_handle) return order_.empty() ? nullptr : &order_.front()->path; | ||
| 751 | for (Module* m : order_) | ||
| 752 | if (m->base == module_handle) return &m->path; | ||
| 753 | return nullptr; | ||
| 754 | } | ||
| 755 | |||
| 733 | // x64 has no frame-pointer chain to fall back on: without its .pdata registered, an exception raised in (or passing | 756 | // x64 has no frame-pointer chain to fall back on: without its .pdata registered, an exception raised in (or passing |
| 734 | // through) a mapped image can't be dispatched past that frame, and the process dies. Images the system loader maps | 757 | // through) a mapped image can't be dispatched past that frame, and the process dies. Images the system loader maps |
| 735 | // are found through its own module list; ours are VirtualAlloc'd, so they are registered as dynamic function tables. | 758 | // are found through its own module list; ours are VirtualAlloc'd, so they are registered as dynamic function tables. |