static int SysError(const char* buffer) { #ifdef WIN32 HWND wnd = FindWindow(L"grcWindow", nullptr); #if !defined(COMPILING_LAUNCH) && !defined(COMPILING_CONSOLE) if (CoreIsDebuggerPresent()) #else if (IsDebuggerPresent()) #endif { __debugbreak(); } #if !defined(COMPILING_LAUNCH) && !defined(COMPILING_CONSOLE) && !defined(IS_FXSERVER) json o = json::object(); o["message"] = buffer; o["file"] = std::get<0>(g_thisError); o["line"] = std::get<1>(g_thisError); o["sigHash"] = std::get<2>(g_thisError); FILE* f = _wfopen(MakeRelativeCitPath(L"cache\\error-pickup").c_str(), L"wb"); if (f) { fprintf(f, "%s", o.dump().c_str()); fclose(f); #ifdef _DEBUG assert(!"breakpoint time"); #endif return -1; } #endif MessageBoxA(wnd, buffer, "Fatal Error", MB_OK | MB_ICONSTOP); #ifdef _DEBUG assert(!"breakpoint time"); #endif TerminateProcess(GetCurrentProcess(), 1); #else fprintf(stderr, "%s", buffer); abort(); #endif return 0; }
void LSP_InitializeHooks() { HWND shellWindow = GetShellWindow(); GetWindowThreadProcessId(shellWindow, &explorerPid); MH_CreateHookApi(L"kernelbase.dll", "RegOpenKeyExA", ProcessLSPRegOpenKeyExA, (void**)&g_origRegOpenKeyExA); if (CoreIsDebuggerPresent()) { MH_CreateHookApi(L"ntdll.dll", "NtQueryInformationProcess", NtQueryInformationProcessHook, (void**)&origQIP); MH_CreateHookApi(L"ntdll.dll", "NtClose", NtCloseHook, (void**)&origClose); } MH_EnableHook(MH_ALL_HOOKS); }