I am trying to dump a process, say calc.exe
When I run my program I get
Program received signal SIGSEGV, Segmentation fault.
0x0000000000401640 in MiniDumpWriteDump ()
Here is the code
#include <windows.h>
#include <dbghelp.h>
int main(){
HANDLE hFile = CreateFileA(
"calc.dmp",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
DWORD procID = 196;
HANDLE hProc = OpenProcess(
PROCESS_ALL_ACCESS,
FALSE,
procID
);
MiniDumpWriteDump(
hProc,
procID,
hFile,
MiniDumpWithFullMemory,
NULL,
NULL,
NULL
);
CloseHandle(hFile);
}
You example works on 32 bit and 64 bit windows, but it has to be compiled with the same "bitness" (64 bit on 64 bit Windows, 32 bit on 32 bit Windows).
I only added a window enumeration and a way to supply a procID as an argument. The functions that return values should be checked for errors.
Compilation notes
Tested on Linux with Mingw64. Fedora Linux has packages here. I copied the 64 bit
dbghelp.dll
from Windows Server 2008 Windows/system32 to the source folder.objdump -f
can confirm whether the dll is 64 or 32 bit. The compile line was something likeLinks