hook SetUnhandledExceptionFilter for debug build

This commit is contained in:
FunkyFr3sh 2023-06-29 21:13:04 +02:00
parent f352aedc59
commit 087f41ce11
7 changed files with 39 additions and 5 deletions

View file

@ -10,6 +10,7 @@
double g_dbg_frame_time = 0;
DWORD g_dbg_frame_count = 0;
LPTOP_LEVEL_EXCEPTION_FILTER g_dbg_exception_filter;
static LONGLONG g_dbg_counter_start_time = 0;
static double g_dbg_counter_freq = 0.0;
@ -74,6 +75,9 @@ int dbg_exception_handler(EXCEPTION_POINTERS* exception)
filename);
}
if (g_dbg_exception_filter)
return g_dbg_exception_filter(exception);
return EXCEPTION_EXECUTE_HANDLER;
}
#endif

View file

@ -25,10 +25,10 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
case DLL_PROCESS_ATTACH:
{
#if _DEBUG
#ifdef _DEBUG
dbg_init();
TRACE("cnc-ddraw = %p\n", hDll);
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
g_dbg_exception_filter = SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)dbg_exception_handler);
#endif
g_ddraw_module = hDll;

View file

@ -54,6 +54,7 @@ LOADLIBRARYEXAPROC real_LoadLibraryExA = LoadLibraryExA;
LOADLIBRARYEXWPROC real_LoadLibraryExW = LoadLibraryExW;
GETDISKFREESPACEAPROC real_GetDiskFreeSpaceA = GetDiskFreeSpaceA;
COCREATEINSTANCEPROC real_CoCreateInstance = CoCreateInstance;
SETUNHANDLEDEXCEPTIONFILTERPROC real_SetUnhandledExceptionFilter = SetUnhandledExceptionFilter;
static HOOKLIST g_hooks[] =
{
@ -567,12 +568,14 @@ void hook_init()
void hook_early_init()
{
/*
#ifdef _DEBUG && _MSC_VER
hook_patch_iat(GetModuleHandle(NULL), FALSE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_CoCreateInstance, (PVOID)fake_CoCreateInstance);
DetourAttach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
DetourTransactionCommit();
*/
#endif
hook_patch_iat(GetModuleHandle(NULL), FALSE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
hook_patch_iat(GetModuleHandle("XIIIGame.dll"), FALSE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance); //Hooligans
@ -633,6 +636,17 @@ void hook_exit()
hook_revert((HOOKLIST*)&g_hooks);
}
#ifdef _DEBUG && _MSC_VER
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
DetourTransactionCommit();
hook_patch_iat(GetModuleHandle(NULL), TRUE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
real_SetUnhandledExceptionFilter(g_dbg_exception_filter);
#endif
hook_patch_iat(GetModuleHandle(NULL), TRUE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
hook_patch_iat(GetModuleHandle("XIIIGame.dll"), TRUE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance); //Hooligans
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateA", (PROC)fake_DirectInputCreateA);

View file

@ -1076,3 +1076,13 @@ HRESULT WINAPI fake_CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD
return real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
}
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI fake_SetUnhandledExceptionFilter(
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
{
LPTOP_LEVEL_EXCEPTION_FILTER old = g_dbg_exception_filter;
g_dbg_exception_filter = lpTopLevelExceptionFilter;
return old;
//return real_SetUnhandledExceptionFilter(lpTopLevelExceptionFilter);
}