From 7ad288f30e43a0e3dc035d3945928a56a87bb9bb Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 28 Dec 2018 16:26:43 +0100 Subject: [PATCH] Fix debug event timeout feature + add extra check if the debuggee was terminated Details: https://github.com/x64dbg/x64dbg/issues/2087 --- TitanEngine/TitanEngine.Debugger.DebugLoop.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp index cdc6328..56f35e0 100644 --- a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp +++ b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp @@ -77,7 +77,23 @@ __declspec(dllexport) void TITCALL DebugLoop() while(!BreakDBG) //actual debug loop { - WaitForDebugEvent(&DBGEvent, engineWaitForDebugEventTimeOut); + // Fix based on work by https://github.com/number201724 + if(!WaitForDebugEvent(&DBGEvent, engineWaitForDebugEventTimeOut)) + { + if(WaitForSingleObject(dbgProcessInformation.hProcess, 0) == WAIT_OBJECT_0) + { + DBGEvent.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT; + DBGEvent.dwProcessId = dbgProcessInformation.dwProcessId; + DBGEvent.dwThreadId = dbgProcessInformation.dwThreadId; + if(!GetExitCodeProcess(dbgProcessInformation.hProcess, &DBGEvent.u.ExitProcess.dwExitCode)) + DBGEvent.u.ExitProcess.dwExitCode = 0xFFFFFFFF; + } + else + { + continue; + } + } + if(engineExecutePluginCallBack) { ExtensionManagerPluginDebugCallBack(&DBGEvent, UE_PLUGIN_CALL_REASON_EXCEPTION);