From d3ee91c1f5cf7eeacbb091c28e248bc3b88d5a6e Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:20:49 +0000 Subject: [PATCH] Fix crash in silver-bun (#679) --- primedev/thirdparty/silver-bun/module.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/primedev/thirdparty/silver-bun/module.cpp b/primedev/thirdparty/silver-bun/module.cpp index 4b9330e0..84f4da9e 100644 --- a/primedev/thirdparty/silver-bun/module.cpp +++ b/primedev/thirdparty/silver-bun/module.cpp @@ -15,11 +15,21 @@ //----------------------------------------------------------------------------- CModule::CModule(HMODULE hModule) { - m_pModuleBase = reinterpret_cast(hModule); + MODULEINFO mInfo {0}; + + if (hModule && hModule != INVALID_HANDLE_VALUE) + GetModuleInformation(GetCurrentProcess(), hModule, &mInfo, sizeof(MODULEINFO)); + + m_nModuleSize = static_cast(mInfo.SizeOfImage); + m_pModuleBase = reinterpret_cast(mInfo.lpBaseOfDll); + + if (!m_nModuleSize || !m_pModuleBase) + return; CHAR szModuleName[MAX_PATH]; DWORD dwSize = GetModuleFileNameA(hModule, szModuleName, sizeof(szModuleName)); - m_ModuleName = strrchr(szModuleName, '\\') + 1; + char* chLast = strrchr(szModuleName, '\\'); + m_ModuleName = chLast == nullptr ? szModuleName : chLast + 1; Init();