|
15 | 15 | #include <WinTrust.h> |
16 | 16 | #include <SoftPub.h> |
17 | 17 | #include <Psapi.h> |
| 18 | +#include <SharedUtil.Misc.h> |
18 | 19 |
|
19 | 20 | #define STEAM_GTASA_APP_ID "12120" |
20 | 21 |
|
@@ -46,6 +47,33 @@ struct HandleDeleter |
46 | 47 |
|
47 | 48 | using HandleScope = std::unique_ptr<std::remove_pointer_t<HANDLE>, HandleDeleter>; |
48 | 49 |
|
| 50 | +namespace |
| 51 | +{ |
| 52 | +DWORD GetProcessBaseName(HANDLE process, LPWSTR buffer, DWORD bufferLength) |
| 53 | +{ |
| 54 | + using ModuleBaseNameFn = DWORD(WINAPI*)(HANDLE, HMODULE, LPWSTR, DWORD); |
| 55 | + ModuleBaseNameFn moduleBaseNameFn = nullptr; |
| 56 | + |
| 57 | + if (HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); kernel32 != nullptr) |
| 58 | + { |
| 59 | + if (SharedUtil::TryGetProcAddress(kernel32, "K32GetModuleBaseNameW", moduleBaseNameFn) || |
| 60 | + SharedUtil::TryGetProcAddress(kernel32, "GetModuleBaseNameW", moduleBaseNameFn)) |
| 61 | + { |
| 62 | + return moduleBaseNameFn(process, nullptr, buffer, bufferLength); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + HMODULE psapi = GetModuleHandleW(L"psapi.dll"); |
| 67 | + if (psapi == nullptr) |
| 68 | + psapi = LoadLibraryW(L"psapi.dll"); |
| 69 | + |
| 70 | + if (psapi != nullptr && SharedUtil::TryGetProcAddress(psapi, "GetModuleBaseNameW", moduleBaseNameFn)) |
| 71 | + return moduleBaseNameFn(process, nullptr, buffer, bufferLength); |
| 72 | + |
| 73 | + return 0; |
| 74 | +} |
| 75 | +} // namespace |
| 76 | + |
49 | 77 | struct SignerInfo |
50 | 78 | { |
51 | 79 | SignerInfo(HCRYPTMSG Msg) |
@@ -325,7 +353,7 @@ static bool IsSteamProcess(DWORD pid) |
325 | 353 |
|
326 | 354 | wchar_t processName[MAX_PATH]; |
327 | 355 |
|
328 | | - if (!GetModuleBaseNameW(process, nullptr, processName, sizeof(processName) / sizeof(wchar_t))) |
| 356 | + if (GetProcessBaseName(process, processName, static_cast<DWORD>(sizeof(processName) / sizeof(processName[0]))) == 0) |
329 | 357 | return false; |
330 | 358 |
|
331 | 359 | if (wcsicmp(processName, L"steam.exe") != 0) |
@@ -380,7 +408,10 @@ bool CSteamClient::Load() |
380 | 408 | static auto pAddDllDirectory = ([]() -> decltype(&AddDllDirectory) { |
381 | 409 | if (const HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); kernel32 != nullptr) |
382 | 410 | { |
383 | | - return reinterpret_cast<decltype(&AddDllDirectory)>(static_cast<void*>(GetProcAddress(kernel32, "AddDllDirectory"))); |
| 411 | + decltype(&AddDllDirectory) addDllDirectory = nullptr; |
| 412 | + if (!SharedUtil::TryGetProcAddress(kernel32, "AddDllDirectory", addDllDirectory)) |
| 413 | + return nullptr; |
| 414 | + return addDllDirectory; |
384 | 415 | } |
385 | 416 |
|
386 | 417 | return nullptr; |
@@ -439,10 +470,8 @@ bool CSteamClient::Load() |
439 | 470 | } |
440 | 471 |
|
441 | 472 | releaseLibraryLock.reset(); |
442 | | - |
443 | | - Native::CreateInterface = reinterpret_cast<decltype(Native::CreateInterface)>(static_cast<void*>(GetProcAddress(dll, "CreateInterface"))); |
444 | 473 |
|
445 | | - if (!Native::CreateInterface) |
| 474 | + if (!SharedUtil::TryGetProcAddress(dll, "CreateInterface", Native::CreateInterface)) |
446 | 475 | { |
447 | 476 | FreeLibrary(dll); |
448 | 477 | return false; |
|
0 commit comments