removed exception handlers for callbacks (this is dangerous)

This commit is contained in:
Mr. eXoDia 2015-04-17 00:36:47 +02:00
parent b9dd68f5c7
commit 268c684125
2 changed files with 58 additions and 372 deletions

View File

@ -45,8 +45,6 @@ LPVOID StepOutCallBack = NULL;
// Global.Debugger.functions:
long DebugLoopInSecondThread(LPVOID InputParameter)
{
__try
{
if(InputParameter == NULL) //IsFileDll
{
InitDebugExW(expertDebug.szFileName, expertDebug.szCommandLine, expertDebug.szCurrentFolder, expertDebug.EntryCallBack);
@ -56,12 +54,7 @@ long DebugLoopInSecondThread(LPVOID InputParameter)
InitDLLDebugW(expertDebug.szFileName, expertDebug.ReserveModuleBase, expertDebug.szCommandLine, expertDebug.szCurrentFolder, expertDebug.EntryCallBack);
}
DebugLoop();
return(NULL);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
return(-1);
}
return NULL;
}
void DebuggerReset()
@ -94,14 +87,8 @@ void StepOutStepCallBack()
else
{
typedef void(TITCALL * fCustomBreakPoint)();
__try
{
((fCustomBreakPoint)StepOutCallBack)();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
}
else
StepOver(StepOutStepCallBack);

View File

@ -89,15 +89,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chDebugEvent != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chDebugEvent);
__try
{
myCustomHandler(&DBGEvent);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chDebugEvent = NULL;
}
}
//Debug event
switch(DBGEvent.dwDebugEventCode)
@ -169,15 +162,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chCreateProcess != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chCreateProcess);
__try
{
myCustomHandler(&DBGEvent.u.CreateProcessInfo);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chCreateProcess = NULL;
}
}
EngineCloseHandle(DBGFileHandle); //close file handle
}
@ -194,15 +180,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chExitProcess != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chExitProcess);
__try
{
myCustomHandler(&DBGEvent.u.ExitProcess);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chExitProcess = NULL;
}
}
}
break;
@ -237,15 +216,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chCreateThread != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chCreateThread);
__try
{
myCustomHandler(&DBGEvent.u.CreateThread);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chCreateThread = NULL;
}
}
}
break;
@ -255,26 +227,12 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chExitThread != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chExitThread);
__try
{
myCustomHandler(&DBGEvent.u.ExitThread);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chExitThread = NULL;
}
}
if(engineExitThreadOneShootCallBack != NULL)
{
myCustomHandler = (fCustomHandler)(engineExitThreadOneShootCallBack);
__try
{
myCustomHandler(&DBGEvent.u.ExitThread);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
engineExitThreadOneShootCallBack = NULL;
}
@ -355,14 +313,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(ptrLibrarianData->bpxType == UE_ON_LIB_LOAD || ptrLibrarianData->bpxType == UE_ON_LIB_ALL)
{
myCustomHandler = (fCustomHandler)(ptrLibrarianData->bpxCallBack);
__try
{
myCustomHandler(&DBGEvent.u.LoadDll);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
LibrarianRemoveBreakPoint(ptrLibrarianData->szLibraryName, ptrLibrarianData->bpxType);
}
if(ptrLibrarianData->bpxSingleShoot)
{
LibrarianRemoveBreakPoint(ptrLibrarianData->szLibraryName, ptrLibrarianData->bpxType);
@ -381,15 +332,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chLoadDll != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chLoadDll);
__try
{
myCustomHandler(&DBGEvent.u.LoadDll);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chLoadDll = NULL;
}
}
}
break;
@ -399,15 +343,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chUnloadDll != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chUnloadDll);
__try
{
myCustomHandler(&DBGEvent.u.UnloadDll);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chUnloadDll = NULL;
}
}
//library breakpoint
hLoadedLibData = (PLIBRARY_ITEM_DATAW)LibrarianGetLibraryInfoEx(DBGEvent.u.UnloadDll.lpBaseOfDll);
@ -424,14 +361,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(ptrLibrarianData->bpxType == UE_ON_LIB_UNLOAD || ptrLibrarianData->bpxType == UE_ON_LIB_ALL)
{
myCustomHandler = (fCustomHandler)(ptrLibrarianData->bpxCallBack);
__try
{
myCustomHandler(&DBGEvent.u.UnloadDll);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
LibrarianRemoveBreakPoint(ptrLibrarianData->szLibraryName, ptrLibrarianData->bpxType);
}
if(ptrLibrarianData->bpxSingleShoot)
{
LibrarianRemoveBreakPoint(ptrLibrarianData->szLibraryName, ptrLibrarianData->bpxType);
@ -472,15 +402,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chOutputDebugString != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chOutputDebugString);
__try
{
myCustomHandler(&DBGEvent.u.DebugString);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chOutputDebugString = NULL;
}
}
}
break;
@ -491,15 +414,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chEverythingElse != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chEverythingElse);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chEverythingElse = NULL;
}
}
if(DBGEvent.u.Exception.dwFirstChance == FALSE) //second chance exception
{
//NOTE: unclear behavious of ->Pass<- all exceptions (not to debuggee, but to debugger)
@ -569,14 +485,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
//execute callback
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)FoundBreakPoint.ExecuteCallBack);
__try
{
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(FoundBreakPoint.BreakPointType != UE_SINGLESHOOT)
{
@ -597,15 +506,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chBreakPoint != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chBreakPoint);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chBreakPoint = NULL;
}
}
}
else //system breakpoint
{
@ -614,15 +516,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DebugAttachedToProcess)
{
myCustomBreakPoint = (fCustomBreakPoint)(DebugAttachedProcessCallBack);
__try
{
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
if(engineAutoHideFromDebugger)
{
HideDebugger(dbgProcessInformation.hProcess, UE_HIDE_PEBONLY);
@ -644,15 +539,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chSystemBreakpoint != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chSystemBreakpoint);
__try
{
myCustomHandler(&DBGEvent);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chSystemBreakpoint = NULL;
}
}
}
}
}
@ -684,17 +572,10 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(engineStepCount == 0)
{
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
__try
{
engineStepActive = false;
engineStepCallBack = NULL;
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
SingleStep(engineStepCount, engineStepCallBack);
@ -720,17 +601,10 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(engineStepCount == 0)
{
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
__try
{
engineStepActive = false;
engineStepCallBack = NULL;
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
SingleStep(engineStepCount, engineStepCallBack);
@ -749,17 +623,10 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(engineStepCount == 0)
{
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
__try
{
engineStepActive = false;
engineStepCallBack = NULL;
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
SingleStep(engineStepCount, engineStepCallBack);
@ -781,14 +648,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
myDBGContext.EFlags |= UE_TRAP_FLAG;
SetThreadContext(hActiveThread, &myDBGContext);
myCustomHandler = (fCustomHandler)(DebugRegister[0].DrxCallBack);
__try
{
myCustomHandler((void*)myDBGContext.Dr0);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(DebugRegister[0].DrxEnabled)
{
memcpy(&DebugRegisterX, &DebugRegister[0], sizeof(HARDWARE_DATA));
@ -810,14 +670,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
myDBGContext.EFlags |= UE_TRAP_FLAG;
SetThreadContext(hActiveThread, &myDBGContext);
myCustomHandler = (fCustomHandler)(DebugRegister[1].DrxCallBack);
__try
{
myCustomHandler((void*)myDBGContext.Dr1);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(DebugRegister[1].DrxEnabled)
{
memcpy(&DebugRegisterX, &DebugRegister[1], sizeof(HARDWARE_DATA));
@ -839,14 +692,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
myDBGContext.EFlags |= UE_TRAP_FLAG;
SetThreadContext(hActiveThread, &myDBGContext);
myCustomHandler = (fCustomHandler)(DebugRegister[2].DrxCallBack);
__try
{
myCustomHandler((void*)myDBGContext.Dr2);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(DebugRegister[2].DrxEnabled)
{
memcpy(&DebugRegisterX, &DebugRegister[2], sizeof(HARDWARE_DATA));
@ -868,14 +714,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
myDBGContext.EFlags |= UE_TRAP_FLAG;
SetThreadContext(hActiveThread, &myDBGContext);
myCustomHandler = (fCustomHandler)(DebugRegister[3].DrxCallBack);
__try
{
myCustomHandler((void*)myDBGContext.Dr3);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(DebugRegister[3].DrxEnabled)
{
memcpy(&DebugRegisterX, &DebugRegister[3], sizeof(HARDWARE_DATA));
@ -909,17 +748,10 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(engineStepCount == 0)
{
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
__try
{
engineStepActive = false;
engineStepCallBack = NULL;
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
SingleStep(engineStepCount, engineStepCallBack);
@ -931,15 +763,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chSingleStep != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chSingleStep);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chSingleStep = NULL;
}
}
}
}
break;
@ -988,15 +813,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
ResetMemBPX = true;
}
myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try
{
myCustomHandler((void*)bpaddr);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else if(FoundBreakPoint.BreakPointType == UE_MEMORY_READ) //READ
{
if(FoundBreakPoint.MemoryBpxRestoreOnHit != 1) //do not restore the memory breakpoint
@ -1015,15 +833,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 0) //read operation
{
myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try
{
myCustomHandler((void*)bpaddr);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else //no read operation, restore breakpoint
{
myDBGContext.EFlags |= UE_TRAP_FLAG;
@ -1051,15 +862,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 1) //write operation
{
myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try
{
myCustomHandler((void*)bpaddr);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else //no write operation, restore breakpoint
{
myDBGContext.EFlags |= UE_TRAP_FLAG;
@ -1089,15 +893,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress == DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[1]) //exception address == read address
{
myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try
{
myCustomHandler((void*)bpaddr);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else //no execute operation, restore breakpoint
{
myDBGContext.EFlags |= UE_TRAP_FLAG;
@ -1130,15 +927,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chPageGuard != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chPageGuard);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chPageGuard = NULL;
}
}
}
}
break;
@ -1148,15 +938,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chAccessViolation != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chAccessViolation);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chAccessViolation = NULL;
}
}
}
break;
@ -1202,14 +985,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
//execute callback
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)FoundBreakPoint.ExecuteCallBack);
__try
{
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
if(FoundBreakPoint.BreakPointType != UE_SINGLESHOOT)
{
@ -1231,15 +1007,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chIllegalInstruction != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chIllegalInstruction);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chIllegalInstruction = NULL;
}
}
}
}
break;
@ -1249,15 +1018,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chNonContinuableException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chNonContinuableException);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chNonContinuableException = NULL;
}
}
}
break;
@ -1266,15 +1028,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chArrayBoundsException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chArrayBoundsException);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chArrayBoundsException = NULL;
}
}
}
break;
@ -1283,15 +1038,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chFloatDenormalOperand != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chFloatDenormalOperand);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chFloatDenormalOperand = NULL;
}
}
}
break;
@ -1300,15 +1048,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chFloatDevideByZero != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chFloatDevideByZero);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chFloatDevideByZero = NULL;
}
}
}
break;
@ -1317,15 +1058,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chIntegerDevideByZero != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chIntegerDevideByZero);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chIntegerDevideByZero = NULL;
}
}
}
break;
@ -1334,15 +1068,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chIntegerOverflow != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chIntegerOverflow);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chIntegerOverflow = NULL;
}
}
}
break;
@ -1351,15 +1078,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chPrivilegedInstruction != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chPrivilegedInstruction);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chPrivilegedInstruction = NULL;
}
}
}
break;
}
@ -1374,30 +1094,16 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chUnhandledException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chUnhandledException);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chUnhandledException = NULL;
}
}
}
//general after-exception callback (includes debugger exceptions)
if(DBGCustomHandler->chAfterException != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chAfterException);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chAfterException = NULL;
}
}
}
break;
@ -1412,15 +1118,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGCustomHandler->chRipEvent != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chRipEvent);
__try
{
myCustomHandler(&DBGEvent);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chRipEvent = NULL;
}
}
}
break;
}