mirror of https://github.com/x64dbg/TitanEngine
fix multi-thread breakpoint deletion race condition
This commit is contained in:
parent
f6c9698fd7
commit
8072f96a26
|
|
@ -589,6 +589,30 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
||||||
{
|
{
|
||||||
if(DebugAttachedToProcess || !FirstBPX) //program generated a breakpoint exception
|
if(DebugAttachedToProcess || !FirstBPX) //program generated a breakpoint exception
|
||||||
{
|
{
|
||||||
|
ULONG_PTR exceptionAddress = (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress;
|
||||||
|
unsigned char currentByte = 0xCC;
|
||||||
|
MemoryReadSafe(dbgProcessInformation.hProcess, (void*)exceptionAddress, ¤tByte, 1, nullptr);
|
||||||
|
|
||||||
|
if(currentByte != 0xCC)
|
||||||
|
{
|
||||||
|
//breakpoint was deleted - the byte is no longer 0xCC
|
||||||
|
//reset IP to exception address and continue gracefully
|
||||||
|
DBGCode = DBG_CONTINUE;
|
||||||
|
hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId);
|
||||||
|
CONTEXT myDBGContext;
|
||||||
|
myDBGContext.ContextFlags = ContextControlFlags;
|
||||||
|
GetThreadContext(hActiveThread, &myDBGContext);
|
||||||
|
#if defined(_WIN64)
|
||||||
|
myDBGContext.Rip = exceptionAddress;
|
||||||
|
#else
|
||||||
|
myDBGContext.Eip = (DWORD)exceptionAddress;
|
||||||
|
#endif
|
||||||
|
SetThreadContext(hActiveThread, &myDBGContext);
|
||||||
|
EngineCloseHandle(hActiveThread);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//byte is still 0xCC - this is a real int3 in the original code!!
|
||||||
DBGCode = DBG_EXCEPTION_NOT_HANDLED;
|
DBGCode = DBG_EXCEPTION_NOT_HANDLED;
|
||||||
if(DBGCustomHandler->chBreakPoint != NULL)
|
if(DBGCustomHandler->chBreakPoint != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -596,6 +620,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
||||||
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
|
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else //system breakpoint
|
else //system breakpoint
|
||||||
{
|
{
|
||||||
FirstBPX = false;
|
FirstBPX = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue