Win32 debugging API pay attention to memory leak (Select Blog from Liquidx)

xiaoxiao2021-03-05  23

I have recently learned the Win32 debug API, I wrote some things, and I learned something. For example, use a.exe to do Debugger, B.exe makes Debuggee. General tutorial is like writing a.exe: process_information pi; startupinfo si; debug_event DE; DWORD DWCONTINUESTATUS; DWORD DWEXCENUM = 0; // Abnormal number GetStartupInfo (& Si); CreateProcess ("B.EXE", 0, 0, 0, 0, Debug_Process, 0, 0, & Si, & Pi); While (WaitfordebugEvent (& de, INFINITE)) {dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED; if (de.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) {break; end // debugee} else if (de.dwDebugEventCode == EXCEPTION_DEBUG_EVENT) {dwExceptionNum ; // should be noted that if the first abnormality (dwExceptionNum == 1) dwContinueStatus = DBG_CONTINUE;} ... ContinueDebugEvent (de.dwProcessId, de.dwThreadId, dwContinueStatus);} CloseHandle (pi.hThread); CloseHandle (pi.hProcess); the above procedure seems to be no problem. But I found in debugging, after B.EXE, as long as A.EXE is not closed, B.exe can't delete the name, this shows A. The B.exe file handle is opened, but it has not been closed. After repeated research, the problem is finally found, the rewriting procedure is as follows: While (WaitFordeBugevent (& de, infinite)) {dwcontinuestUS = DBG_EXCEPTION_NOT_HANDLED; if (de.dwdebugeventcode == EXIT_PROCESS_DEBUG_EVENT) {break; end // debugee} else if (de.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT) {// Handle to the process's image file CloseHandle (de.u.CreateProcessInfo.hFile); // Handle to the process CloseHandle ( de.u.createProcessInfo.hprocess);

转载请注明原文地址:https://www.9cbs.com/read-37015.html

New Post(0)