Potentially fix crash on Win10 when device-hiding is enabled

pull/184/head
Peter Repukat 2 years ago
parent 6888381b41
commit b96e15f6f7

@ -186,8 +186,12 @@ void HidHide::UnPatchHook(const std::string& name, HMODULE module)
if (!address) {
spdlog::error("failed to unpatch \"{}\"", name);
}
auto bytes = ORIGINAL_BYTES.at(name);
std::string bytes;
if (Settings::isWin10 && ORIGINAL_BYTES_WIN10.contains(name)) {
bytes = ORIGINAL_BYTES_WIN10.at(name);
} else {
bytes = ORIGINAL_BYTES.at(name);
}
DWORD dw_old_protect, dw_bkup;
const auto len = bytes.size();
VirtualProtect(address, len, PAGE_EXECUTE_READWRITE, &dw_old_protect); // Change permissions of memory..

@ -85,6 +85,11 @@ class HidHide {
{"HidP_GetButtonCaps", "\x48\x83\xEC\x48\x49"},
};
static inline const std::map<std::string, std::string> ORIGINAL_BYTES_WIN10 = {
{"SetupDiEnumDeviceInfo", "\x40\x53\x56\x57\x41\x54\x41\x55"},
{"SetupDiGetClassDevsW", "\x48\x8B\xC4\x48\x89\x58\x08"},
};
static inline const std::vector<uint8_t> JUMP_INSTR_OPCODES = {
0xE9,
0xE8,

@ -23,6 +23,12 @@ limitations under the License.
#include <locale>
#include <codecvt>
#ifdef WIN32
#define NOMINMAX
#include <Windows.h>
#endif
namespace Settings {
inline struct Launch {
@ -56,6 +62,7 @@ inline bool extendedLogging = false;
inline std::filesystem::path settings_path_ = "";
inline bool checkIsUwp(const std::wstring& launch_path)
{
if (launch_path.find(L"://") != std::wstring::npos) {
@ -68,6 +75,45 @@ inline bool checkIsUwp(const std::wstring& launch_path)
return false;
}
#ifdef WIN32
inline bool isWin10 = false;
typedef LONG NTSTATUS, *PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)
typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
inline RTL_OSVERSIONINFOW GetRealOSVersion()
{
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
if (hMod) {
RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
if (fxPtr != nullptr) {
RTL_OSVERSIONINFOW rovi = {0};
rovi.dwOSVersionInfoSize = sizeof(rovi);
if (STATUS_SUCCESS == fxPtr(&rovi)) {
return rovi;
}
}
}
RTL_OSVERSIONINFOW rovi = {0};
return rovi;
}
inline void checkWinVer()
{
auto VN = GetRealOSVersion();
isWin10 = VN.dwBuildNumber < 22000;
if (isWin10) {
spdlog::info("Running on Windows 10");
} else {
spdlog::info("Running on Windows 11");
}
}
#endif
inline void Parse(std::wstring arg1)
{
if (!arg1.ends_with(L".json")) {

@ -158,6 +158,7 @@ int main(int argc, char* argv[])
argsv += i == 1 ? args[i] : std::wstring(L" ") + args[i];
}
Settings::Parse(argsv);
Settings::checkWinVer();
SteamTarget target;
#else // Code below is broken now due to parse requiring std::wstring instead of std:string. Sorry.
std::string argsv = "";

Loading…
Cancel
Save