diff options
| author | Nolan Cotter <186326284+NolanCotter@users.noreply.github.com> | 2026-11-22 12:46:24 -0700 |
|---|---|---|
| committer | Nolan Cotter <186326284+NolanCotter@users.noreply.github.com> | 2026-11-22 16:41:17 -0700 |
| commit | 7cd6aa7c934268d941c1437dbc507f80080c957d (patch) | |
| tree | 13b71b41129f573ac947119e71b661a22ad7cedf /runtime/src/pe_loader.cpp | |
| parent | d2dbb0b69002e6e410119fd690da8d315ef51779 (diff) | |
loader/tools: review fixes for import routing and the inventory
pe_loader: resolve() and resolve_forwarder() key the DLL name with
dll_key() — lower-case, trailing '.' dropped, ".dll" added when there
is no extension — the file-name rule LoadLibrary applies. Without it an
import naming "GameInput" or "gameinput.dll." missed the shim and
owns_dll lookups while LoadLibraryExA still bound a host namesake.
registry: xaudio2_9.dll ordinals 8-10 classify as hresult (host table
measured: XAudio2CreateV2_9 / WithVersionInfo / WithSharedContexts);
the redist's ordinal table is unconfirmed and stays other.
import_inventory: classify parity for the #1 ordinals; the delay-import
directory (entry 13) is read with the loader's checks; the descriptor
table stops at Name == 0 and unreadable names fail like read_string;
host-bound imports report as host instead of unimplemented thunk
(owns_dll ported); thunk tables deduplicate by RVA under a global cap.
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 | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index 77545d3f6..5d0386ec0 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -1038,6 +1038,19 @@ void Loader::parse_exports(Module& m) { | |||
| 1038 | } | 1038 | } |
| 1039 | } | 1039 | } |
| 1040 | 1040 | ||
| 1041 | // The file-name rule LoadLibrary applies to a bare module name, the same normalisation library_loader.cpp's | ||
| 1042 | // module_name() uses: lower-case, a trailing '.' dropped, ".dll" added when there is no extension. Without it an | ||
| 1043 | // import naming "GameInput" or "gameinput.dll." misses the shim and owns_dll lookups while LoadLibraryExA still | ||
| 1044 | // binds the real System32 module. | ||
| 1045 | std::string dll_key(std::string name) { | ||
| 1046 | const size_t slash = name.find_last_of("\\/"); | ||
| 1047 | if (slash != std::string::npos) name.erase(0, slash + 1); | ||
| 1048 | name = lower(name); | ||
| 1049 | if (!name.empty() && name.back() == '.') name.pop_back(); | ||
| 1050 | else if (name.find('.') == std::string::npos) name += ".dll"; | ||
| 1051 | return name; | ||
| 1052 | } | ||
| 1053 | |||
| 1041 | // Follows a forwarder string to the module and export it names. Bundled modules are searched first, with or without | 1054 | // Follows a forwarder string to the module and export it names. Bundled modules are searched first, with or without |
| 1042 | // the extension, because a forwarder may point at another mapped module; system DLLs go through LoadLibraryEx, whose | 1055 | // the extension, because a forwarder may point at another mapped module; system DLLs go through LoadLibraryEx, whose |
| 1043 | // own GetProcAddress already follows its forwarders. Errors are "not found": the caller decides what to bind. | 1056 | // own GetProcAddress already follows its forwarders. Errors are "not found": the caller decides what to bind. |
| @@ -1049,8 +1062,7 @@ void* Loader::resolve_forwarder(const std::string& spec, Binding& binding, int d | |||
| 1049 | 1062 | ||
| 1050 | // A forwarder can name a module the loader shims. Shims take precedence over a bundled or host copy, exactly as | 1063 | // A forwarder can name a module the loader shims. Shims take precedence over a bundled or host copy, exactly as |
| 1051 | // they do for a direct import in resolve(); without this, a forwarded xmem or d3d12_xs call becomes a failure thunk. | 1064 | // they do for a direct import in resolve(); without this, a forwarded xmem or d3d12_xs call becomes a failure thunk. |
| 1052 | std::string shim_key = lower(module); | 1065 | std::string shim_key = dll_key(module); |
| 1053 | if (shim_key.size() < 4 || shim_key.compare(shim_key.size() - 4, 4, ".dll") != 0) shim_key += ".dll"; | ||
| 1054 | if (void* p = shims::find(shim_key, symbol)) { | 1066 | if (void* p = shims::find(shim_key, symbol)) { |
| 1055 | binding = Binding::Shim; | 1067 | binding = Binding::Shim; |
| 1056 | return p; | 1068 | return p; |
| @@ -1099,7 +1111,7 @@ void* Loader::resolve_forwarder(const std::string& spec, Binding& binding, int d | |||
| 1099 | } | 1111 | } |
| 1100 | 1112 | ||
| 1101 | void* Loader::resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal) { | 1113 | void* Loader::resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal) { |
| 1102 | std::string key = lower(dll); | 1114 | std::string key = dll_key(dll); |
| 1103 | std::string sym = by_ordinal ? "#" + std::to_string(ordinal) : name; | 1115 | std::string sym = by_ordinal ? "#" + std::to_string(ordinal) : name; |
| 1104 | 1116 | ||
| 1105 | if (void* p = shims::find(key, sym)) { | 1117 | if (void* p = shims::find(key, sym)) { |