Skip to content

Commit

Permalink
Change our unhandled exception filter to a vectored exception handler.
Browse files Browse the repository at this point in the history
That is, *one that actually works*. That's how easy it would have been.
  • Loading branch information
nmlgc committed Aug 27, 2017
1 parent 46f3033 commit ef129a5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 57 deletions.
42 changes: 1 addition & 41 deletions thcrap/src/exception.cpp
Expand Up @@ -9,17 +9,6 @@

#include "thcrap.h"

/// Detour chains
/// -------------
typedef LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter_type(
LPTOP_LEVEL_EXCEPTION_FILTER
);

DETOUR_CHAIN_DEF(SetUnhandledExceptionFilter);
/// -------------

static LPTOP_LEVEL_EXCEPTION_FILTER lpOrigFilter = NULL;

void log_context_dump(PCONTEXT ctx)
{
if(!ctx) {
Expand Down Expand Up @@ -67,39 +56,10 @@ LONG WINAPI exception_filter(LPEXCEPTION_POINTERS lpEI)
"===\n"
"\n"
);
if(lpOrigFilter) {
lpOrigFilter(lpEI);
}
return EXCEPTION_CONTINUE_SEARCH;
}

LPTOP_LEVEL_EXCEPTION_FILTER WINAPI exception_SetUnhandledExceptionFilter(
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
)
{
// Don't return our own filter, since this might cause an infinite loop if
// the game process caches it.
LPTOP_LEVEL_EXCEPTION_FILTER ret = chain_SetUnhandledExceptionFilter(
lpTopLevelExceptionFilter
);
lpOrigFilter = lpTopLevelExceptionFilter;
return ret == exception_filter ? NULL : ret;
}

void exception_init(void)
{
SetUnhandledExceptionFilter(exception_filter);
}

void exception_mod_detour(void)
{
detour_chain("kernel32.dll", 1,
"SetUnhandledExceptionFilter", exception_SetUnhandledExceptionFilter, &chain_SetUnhandledExceptionFilter,
NULL
);
}

void exception_exit(void)
{
SetUnhandledExceptionFilter(lpOrigFilter);
AddVectoredExceptionHandler(1, exception_filter);
}
9 changes: 0 additions & 9 deletions thcrap/src/exception.h
Expand Up @@ -9,13 +9,4 @@

#pragma once

// Our custom exception filter function.
LONG WINAPI exception_filter(LPEXCEPTION_POINTERS lpEI);

LPTOP_LEVEL_EXCEPTION_FILTER WINAPI exception_SetUnhandledExceptionFilter(
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
);

void exception_init(void);
void exception_mod_detour(void);
void exception_exit(void);
7 changes: 0 additions & 7 deletions thcrap/thcrap.def
Expand Up @@ -54,13 +54,6 @@ EXPORTS

dialog_mod_detour

; Exception handler
; -----------------
exception_filter
exception_init
exception_mod_detour
exception_exit

; Globals
; -------
PROJECT_NAME
Expand Down

0 comments on commit ef129a5

Please sign in to comment.