- fixed first/second chance exceptions

This commit is contained in:
mr.exodia 2013-10-12 17:42:00 +02:00
parent 8b1a465059
commit 14a3692b11
17 changed files with 43 additions and 52 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -117,7 +117,6 @@
#define UE_CH_ALLEVENTS 22
#define UE_CH_SYSTEMBREAKPOINT 23
#define UE_CH_UNHANDLEDEXCEPTION 24
#define UE_CH_AFTERUNHANDLEDEXCEPTION 25
#define UE_OPTION_HANDLER_RETURN_HANDLECOUNT 1
#define UE_OPTION_HANDLER_RETURN_ACCESS 2

View File

@ -117,7 +117,6 @@
#define UE_CH_ALLEVENTS 22
#define UE_CH_SYSTEMBREAKPOINT 23
#define UE_CH_UNHANDLEDEXCEPTION 24
#define UE_CH_AFTERUNHANDLEDEXCEPTION 25
#define UE_OPTION_HANDLER_RETURN_HANDLECOUNT 1
#define UE_OPTION_HANDLER_RETURN_ACCESS 2

View File

@ -258,6 +258,10 @@ const
UE_CH_LOADDLL = 18;
UE_CH_UNLOADDLL = 19;
UE_CH_OUTPUTDEBUGSTRING = 20;
UE_CH_AFTEREXCEPTIONPROCESSING = 21;
UE_CH_ALLEVENTS = 22;
UE_CH_SYSTEMBREAKPOINT = 23;
UE_CH_UNHANDLEDEXCEPTION = 24;
UE_FUNCTION_STDCALL = 1;
UE_FUNCTION_CCALL = 2;

View File

@ -116,6 +116,8 @@ UE_CH_UNLOADDLL = 19
UE_CH_OUTPUTDEBUGSTRING = 20
UE_CH_AFTEREXCEPTIONPROCESSING = 21
UE_CH_ALLEVENTS = 22
UE_CH_SYSTEMBREAKPOINT = 23
UE_CH_UNHANDLEDEXCEPTION = 24
UE_OPTION_HANDLER_RETURN_HANDLECOUNT = 1
UE_OPTION_HANDLER_RETURN_ACCESS = 2

View File

@ -94,6 +94,9 @@ UE_CH_UNLOADDLL EQU 19
UE_CH_OUTPUTDEBUGSTRING EQU 20
UE_CH_AFTEREXCEPTIONPROCESSING EQU 21
UE_CH_ALLEVENTS EQU 22
UE_CH_SYSTEMBREAKPOINT EQU 23
UE_CH_UNHANDLEDEXCEPTION EQU 24
UE_OPTION_HANDLER_RETURN_HANDLECOUNT EQU 1
UE_OPTION_HANDLER_RETURN_ACCESS EQU 2
UE_OPTION_HANDLER_RETURN_FLAGS EQU 3

View File

@ -105,6 +105,10 @@ UE_CH_EXITPROCESS = 17
UE_CH_LOADDLL = 18
UE_CH_UNLOADDLL = 19
UE_CH_OUTPUTDEBUGSTRING = 20
UE_CH_AFTEREXCEPTIONPROCESSING = 21
UE_CH_ALLEVENTS = 22
UE_CH_SYSTEMBREAKPOINT = 23
UE_CH_UNHANDLEDEXCEPTION = 24
UE_OPTION_HANDLER_RETURN_HANDLECOUNT = 1
UE_OPTION_HANDLER_RETURN_ACCESS = 2

View File

@ -15528,10 +15528,6 @@ __declspec(dllexport) void TITCALL SetCustomHandler(DWORD ExceptionId, LPVOID Ca
{
DBGCustomHandler->chUnhandledException = (ULONG_PTR)CallBack;
}
else if(ExceptionId == UE_CH_AFTERUNHANDLEDEXCEPTION)
{
DBGCustomHandler->chAfterUnhandledException = (ULONG_PTR)CallBack;
}
else if(ExceptionId == UE_CH_ALLEVENTS)
{
DBGCustomHandler->chEverythingElse = (ULONG_PTR)CallBack;
@ -16959,7 +16955,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
else if(DBGEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
{
bool firstchance=false;
//bool firstchance=false;
if(DBGCustomHandler->chEverythingElse != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chEverythingElse);
@ -16972,19 +16968,20 @@ __declspec(dllexport) void TITCALL DebugLoop()
DBGCustomHandler->chEverythingElse = NULL;
}
}
if(DBGEvent.u.Exception.dwFirstChance == FALSE)
if(DBGEvent.u.Exception.dwFirstChance == FALSE) //second chance exception
{
if(!enginePassAllExceptions)
{
firstchance=true;
DBGCode = DBG_CONTINUE;
}
else
{
DBGCode = DBG_EXCEPTION_NOT_HANDLED;
DBGCode = DBG_EXCEPTION_NOT_HANDLED; //let debuggee handle the exception
}
RtlMoveMemory(&TerminateDBGEvent, &DBGEvent, sizeof DEBUG_EVENT);
}
//handle different exception codes
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_BREAKPOINT)
{
/*if(DBGCustomHandler->chBreakPoint != NULL)
@ -17266,18 +17263,6 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
else if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_SINGLE_STEP)
{
/*if(DBGCustomHandler->chSingleStep != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chSingleStep);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chSingleStep = NULL;
}
}*/
if(ResetBPX == true || ResetHwBPX == true || ResetMemBPX == true)
{
DBGCode = DBG_CONTINUE;
@ -17535,7 +17520,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
EngineCloseHandle(hActiveThread);
}
}
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED || firstchance)
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED)
{
if(DBGCustomHandler->chSingleStep != NULL)
{
@ -17739,8 +17724,9 @@ __declspec(dllexport) void TITCALL DebugLoop()
{
DBGCode = DBG_EXCEPTION_NOT_HANDLED;
}
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED || firstchance)
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED)
{
//TODO: re-set memory breakpoint?
if(DBGCustomHandler->chPageGuard != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chPageGuard);
@ -17773,18 +17759,6 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
else if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_ILLEGAL_INSTRUCTION)
{
if(DBGCustomHandler->chIllegalInstruction != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chIllegalInstruction);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chIllegalInstruction = NULL;
}
}
MaximumBreakPoints = 0;
for(MaximumBreakPoints = 0; MaximumBreakPoints < BreakPointSetCount; MaximumBreakPoints++)
{
@ -17980,6 +17954,21 @@ __declspec(dllexport) void TITCALL DebugLoop()
{
DBGCode = DBG_EXCEPTION_NOT_HANDLED;
}
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED) //call custom handler
{
if(DBGCustomHandler->chIllegalInstruction != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chIllegalInstruction);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chIllegalInstruction = NULL;
}
}
}
}
else if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
{
@ -18093,7 +18082,9 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
}
}
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED || firstchance)
//post exception handling (for debugger exceptions)
if(DBGCode==DBG_EXCEPTION_NOT_HANDLED)
{
if(DBGCustomHandler->chUnhandledException != NULL)
{
@ -18107,19 +18098,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
DBGCustomHandler->chUnhandledException = NULL;
}
}
if(DBGCustomHandler->chAfterUnhandledException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chAfterUnhandledException);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chAfterUnhandledException = NULL;
}
}
}
if(DBGCustomHandler->chAfterException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chAfterException);
@ -18133,6 +18113,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
}
}
//after handling of debug codes
if(engineResumeProcessIfNoThreadIsActive)
{
if(!ThreaderIsAnyThreadActive())

View File

@ -164,7 +164,6 @@ typedef struct
ULONG_PTR chAfterException;
ULONG_PTR chSystemBreakpoint;
ULONG_PTR chUnhandledException;
ULONG_PTR chAfterUnhandledException;
} CustomHandler, *PCustomHandler;
typedef struct
@ -391,7 +390,6 @@ typedef struct HOOK_ENTRY
#define UE_CH_ALLEVENTS 22
#define UE_CH_SYSTEMBREAKPOINT 23
#define UE_CH_UNHANDLEDEXCEPTION 24
#define UE_CH_AFTERUNHANDLEDEXCEPTION 25
#define UE_OPTION_HANDLER_RETURN_HANDLECOUNT 1
#define UE_OPTION_HANDLER_RETURN_ACCESS 2

View File

@ -13,4 +13,4 @@ The following things have been fixed/added (list might be incomplete):
- smaller and faster DLL loaders
- supports multiple calling conventions (including the callbacks)
- MinGW import libraries
- fixed exception handling