Fix detaching

This commit is contained in:
Duncan Ogilvie 2020-10-10 17:36:40 +02:00
parent 35fdd5684e
commit 885e290cc4
2 changed files with 17 additions and 32 deletions

View File

@ -12,8 +12,6 @@
#define UE_MODULEx86 0x2000;
#define UE_MODULEx64 0x2000;
static DWORD engineWaitForDebugEventTimeOut = INFINITE;
__declspec(dllexport) void TITCALL DebugLoop()
{
bool FirstBPX = true;
@ -78,8 +76,14 @@ __declspec(dllexport) void TITCALL DebugLoop()
while(!BreakDBG) //actual debug loop
{
// Fix based on work by https://github.com/number201724
if(!WaitForDebugEvent(&DBGEvent, engineWaitForDebugEventTimeOut))
if(!WaitForDebugEvent(&DBGEvent, 100))
{
if (engineProcessIsNowDetached)
{
DebugActiveProcessStop(dbgProcessInformation.dwProcessId);
DebugAttachedToProcess = false;
break;
}
if(WaitForSingleObject(dbgProcessInformation.hProcess, 0) == WAIT_OBJECT_0)
{
DBGEvent.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT;
@ -90,6 +94,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
}
else
{
// Regular timeout, wait again
continue;
}
}
@ -1169,6 +1174,12 @@ __declspec(dllexport) void TITCALL DebugLoop()
{
break;
}
if (engineProcessIsNowDetached)
{
DebugActiveProcessStop(dbgProcessInformation.dwProcessId);
DebugAttachedToProcess = false;
break;
}
if(!ThreaderGetThreadInfo(0, DBGEvent.dwThreadId)) //switch thread
DBGEvent.dwThreadId = dbgProcessInformation.dwThreadId;
}
@ -1195,5 +1206,5 @@ __declspec(dllexport) void TITCALL DebugLoopEx(DWORD TimeOut)
__declspec(dllexport) void TITCALL SetDebugLoopTimeOut(DWORD TimeOut)
{
engineWaitForDebugEventTimeOut = TimeOut;
__debugbreak();
}

View File

@ -575,34 +575,9 @@ __declspec(dllexport) bool TITCALL AttachDebugger(DWORD ProcessId, bool KillOnEx
__declspec(dllexport) bool TITCALL DetachDebugger(DWORD ProcessId)
{
typedef bool(WINAPI * fDebugActiveProcessStop)(DWORD dwProcessId);
fDebugActiveProcessStop myDebugActiveProcessStop;
LPVOID funcDebugActiveProcessStop = NULL;
bool FuncReturn = false;
RemoveAllBreakPoints(UE_OPTION_REMOVEALL);
if(ProcessId != NULL)
{
funcDebugActiveProcessStop = GetProcAddress(GetModuleHandleA("kernel32.dll"), "DebugActiveProcessStop");
if(funcDebugActiveProcessStop != NULL)
{
myDebugActiveProcessStop = (fDebugActiveProcessStop)(funcDebugActiveProcessStop);
FuncReturn = myDebugActiveProcessStop(ProcessId);
engineProcessIsNowDetached = true;
Sleep(250);
}
DebugAttachedToProcess = false;
if(FuncReturn)
{
return true;
}
else
{
return false;
}
}
return false;
engineProcessIsNowDetached = true; // Request detach
return true;
}
__declspec(dllexport) bool TITCALL DetachDebuggerEx(DWORD ProcessId)
@ -620,7 +595,6 @@ __declspec(dllexport) bool TITCALL DetachDebuggerEx(DWORD ProcessId)
SetThreadContext(hActiveThread, &myDBGContext);
EngineCloseHandle(hActiveThread);
}
ContinueDebugEvent(DBGEvent.dwProcessId, DBGEvent.dwThreadId, DBGCode);
ThreaderResumeProcess();
return DetachDebugger(ProcessId);
}