upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index f4ecc0de2..77545d3f6 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -1082,14 +1082,20 @@ void* Loader::resolve_forwarder(const std::string& spec, Binding& binding, int d
1082 return nullptr; // the bundled module exists and does not export it; don't look for a host namesake 1082 return nullptr; // the bundled module exists and does not export it; don't look for a host namesake
1083 } 1083 }
1084 1084
1085 HMODULE h = LoadLibraryExA(module.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); 1085 // A module the shims own (xgameruntime.dll, gameinput.dll, d3d12_xs.dll, xmem.dll) never binds to a host
1086 if (!h) return nullptr; 1086 // namesake: xgameruntime.dll and gameinput.dll exist on the PC too, and a call into the real Gaming Services
1087 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header(h); 1087 // runtime would bypass the offline shims the same way a direct host load would (owns_dll, registry.cpp).
1088 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(static_cast<WORD>(ordinal)) : symbol.c_str()); 1088 if (!shims::owns_dll(shim_key)) {
1089 if (!p) return nullptr; 1089 HMODULE h = LoadLibraryExA(module.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
1090 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p)); 1090 if (!h) return nullptr;
1091 binding = Binding::Host; 1091 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header(h);
1092 return reinterpret_cast<void*>(p); 1092 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(static_cast<WORD>(ordinal)) : symbol.c_str());
1093 if (!p) return nullptr;
1094 if (prefer_host_copy(shim_key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p));
1095 binding = Binding::Host;
1096 return reinterpret_cast<void*>(p);
1097 }
1098 return nullptr;
1093} 1099}
1094 1100
1095void* Loader::resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal) { 1101void* Loader::resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal) {
@@ -1117,13 +1123,18 @@ void* Loader::resolve(Module& m, const std::string& dll, const std::string& name
1117 } 1123 }
1118 } 1124 }
1119 // Host Windows: system DLLs and API sets. LOAD_LIBRARY_SEARCH_SYSTEM32 keeps the game folder out of the search. 1125 // Host Windows: system DLLs and API sets. LOAD_LIBRARY_SEARCH_SYSTEM32 keeps the game folder out of the search.
1120 if (HMODULE h = LoadLibraryExA(dll.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)) { 1126 // A shim-owned module is skipped: xgameruntime.dll and gameinput.dll have real PC namesakes in System32, and an
1121 if (prefer_host_copy(key)) redirect_pc_to_file_header(h); // before any mapped code can throw through it 1127 // unregistered import must end unimplemented, exactly as GetProcAddress on the pseudo-handle returns NULL
1122 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(ordinal) : name.c_str()); 1128 // (library_loader.cpp). Binding it to Gaming Services would also leave the process online-capable.
1123 if (p) { 1129 if (!shims::owns_dll(key)) {
1124 if (prefer_host_copy(key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p)); 1130 if (HMODULE h = LoadLibraryExA(dll.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)) {
1125 m.imports.push_back({dll, sym, Binding::Host}); 1131 if (prefer_host_copy(key)) redirect_pc_to_file_header(h); // before any mapped code can throw through it
1126 return reinterpret_cast<void*>(p); 1132 FARPROC p = GetProcAddress(h, by_ordinal ? MAKEINTRESOURCEA(ordinal) : name.c_str());
1133 if (p) {
1134 if (prefer_host_copy(key)) redirect_pc_to_file_header_at(reinterpret_cast<const void*>(p));
1135 m.imports.push_back({dll, sym, Binding::Host});
1136 return reinterpret_cast<void*>(p);
1137 }
1127 } 1138 }
1128 } 1139 }
1129 m.imports.push_back({dll, sym, Binding::Unimplemented}); 1140 m.imports.push_back({dll, sym, Binding::Unimplemented});