diff options
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)) { |