Do not create a thread when attaching

This commit is contained in:
Duncan Ogilvie 2020-10-19 22:56:11 +02:00
parent 885e290cc4
commit ce87d2bea8
2 changed files with 16 additions and 8 deletions

View File

@ -224,6 +224,9 @@ static NTSTATUS NTAPI DbgUiDebugActiveProcess_(IN HANDLE Process)
{ {
/* Tell the kernel to start debugging */ /* Tell the kernel to start debugging */
NTSTATUS Status = NtDebugActiveProcess(Process, NtCurrentTeb()->DbgSsReserved[1]); NTSTATUS Status = NtDebugActiveProcess(Process, NtCurrentTeb()->DbgSsReserved[1]);
return Status;
#if 0
if(NT_SUCCESS(Status)) if(NT_SUCCESS(Status))
{ {
/* Now break-in the process */ /* Now break-in the process */
@ -237,6 +240,7 @@ static NTSTATUS NTAPI DbgUiDebugActiveProcess_(IN HANDLE Process)
/* Return status */ /* Return status */
return Status; return Status;
#endif
} }
static NTSTATUS NTAPI DbgUiConnectToDbg_() static NTSTATUS NTAPI DbgUiConnectToDbg_()

View File

@ -78,7 +78,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
// Fix based on work by https://github.com/number201724 // Fix based on work by https://github.com/number201724
if(!WaitForDebugEvent(&DBGEvent, 100)) if(!WaitForDebugEvent(&DBGEvent, 100))
{ {
if (engineProcessIsNowDetached) if(engineProcessIsNowDetached)
{ {
DebugActiveProcessStop(dbgProcessInformation.dwProcessId); DebugActiveProcessStop(dbgProcessInformation.dwProcessId);
DebugAttachedToProcess = false; DebugAttachedToProcess = false;
@ -116,6 +116,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
{ {
case CREATE_PROCESS_DEBUG_EVENT: case CREATE_PROCESS_DEBUG_EVENT:
{ {
bool attachBreakpoint = false;
if(DBGFileHandle == NULL) //we didn't set the handle yet (initial process) if(DBGFileHandle == NULL) //we didn't set the handle yet (initial process)
{ {
DBGEntryPoint = DBGEvent.u.CreateProcessInfo.lpStartAddress; DBGEntryPoint = DBGEvent.u.CreateProcessInfo.lpStartAddress;
@ -130,6 +131,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
{ {
RtlMoveMemory(engineAttachedProcessDebugInfo, &dbgProcessInformation, sizeof PROCESS_INFORMATION); RtlMoveMemory(engineAttachedProcessDebugInfo, &dbgProcessInformation, sizeof PROCESS_INFORMATION);
} }
attachBreakpoint = true;
} }
if(DebugDebuggingDLL) //the DLL loader just started, set DLL names if(DebugDebuggingDLL) //the DLL loader just started, set DLL names
{ {
@ -186,6 +188,13 @@ __declspec(dllexport) void TITCALL DebugLoop()
if(DBGFileHandle) if(DBGFileHandle)
EngineCloseHandle(DBGFileHandle); //close file handle EngineCloseHandle(DBGFileHandle); //close file handle
// Call the attach breakpoint
if(attachBreakpoint)
{
myCustomBreakPoint = (fCustomBreakPoint)(DebugAttachedProcessCallBack);
myCustomBreakPoint();
}
} }
break; break;
@ -526,11 +535,6 @@ __declspec(dllexport) void TITCALL DebugLoop()
{ {
FirstBPX = false; FirstBPX = false;
DBGCode = DBG_CONTINUE; DBGCode = DBG_CONTINUE;
if(DebugAttachedToProcess)
{
myCustomBreakPoint = (fCustomBreakPoint)(DebugAttachedProcessCallBack);
myCustomBreakPoint();
}
if(engineAutoHideFromDebugger) if(engineAutoHideFromDebugger)
{ {
HideDebugger(dbgProcessInformation.hProcess, UE_HIDE_PEBONLY); HideDebugger(dbgProcessInformation.hProcess, UE_HIDE_PEBONLY);
@ -1174,7 +1178,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
{ {
break; break;
} }
if (engineProcessIsNowDetached) if(engineProcessIsNowDetached)
{ {
DebugActiveProcessStop(dbgProcessInformation.dwProcessId); DebugActiveProcessStop(dbgProcessInformation.dwProcessId);
DebugAttachedToProcess = false; DebugAttachedToProcess = false;