Skip to content

Commit 629a602

Browse files
Mattiwattimrexodia
authored andcommitted
Fix duplicate debuggee process and initial thread handles being kept around in the case that x64dbg is not attaching:
- CloseHandle() the fdProcessInfo->hProcess and fdProcessInfo->hThread handles and set them to NULL if CreateProcess was called (i.e. we are not attaching) just before entering the debug loop - cbCreateProcess(): set fdProcessInfo->hProcess, fdProcessInfo->hThread and varset("$hp") to the correct handles prior to doing anything else
1 parent c8e8b69 commit 629a602

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/dbg/debugger.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,10 @@ void cbTraceOverIntoTraceRecordStep()
13151315

13161316
static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
13171317
{
1318+
fdProcessInfo->hProcess = CreateProcessInfo->hProcess;
1319+
fdProcessInfo->hThread = CreateProcessInfo->hThread;
1320+
varset("$hp", (duint)fdProcessInfo->hProcess, true);
1321+
13181322
void* base = CreateProcessInfo->lpBaseOfImage;
13191323

13201324
char DebugFileName[deflen] = "";
@@ -2720,6 +2724,10 @@ static void debugLoopFunction(void* lpParameter, bool attach)
27202724
}
27212725
else
27222726
{
2727+
//close the process and thread handles we got back from CreateProcess, to prevent duplicating the ones we will receive in cbCreateProcess
2728+
CloseHandle(fdProcessInfo->hProcess);
2729+
CloseHandle(fdProcessInfo->hThread);
2730+
fdProcessInfo->hProcess = fdProcessInfo->hThread = nullptr;
27232731
DebugLoop();
27242732
}
27252733

0 commit comments

Comments
 (0)