ProcDump是否使用调试堆?

时间:2016-11-07 22:17:03

标签: debugging windbg procdump

当我们在Visual Studio 2013或WinDbg等调试器下启动应用程序时,Windows将使用调试堆。但是,似乎可以关闭该行为,因为在使用-hd命令行开关启动时,它在Visual Studio 2015或WinDbg中完成。

现在有ProcDump,它的行为就像一个调试器;事实上,它可以作为AE事后调试器安装-i开关。

如何判断使用ProcDump的-x开关运行应用程序是否会使用调试堆?似乎没有一个命令行选项来改变行为,我不确定它是否会尊重_NO_DEBUG_HEAP环境变量。

我认为调试器会使用IDebugClient5::CreateProcess2()IDebugClient5::CreateProcessAndAttach2()来启动进程。它会通过_DEBUG_CREATE_PROCESS_OPTIONS CreateFlags可以设置DEBUG_CREATE_PROCESS_NO_DEBUG_HEAP标记。

所以我使用WinDbg并在WinDbg下启动了ProcDump。然后我等待加载调试器引擎模块(sxe ld dbgeng),以便我可以设置断点并观察它 - 但该模块从未被加载。

1 个答案:

答案 0 :(得分:2)

cdb -c "!gflag;q" procdump.exe -x procdump.exe | grep -i -A 5 ntglob
Current NtGlobalFlag contents: 0x00000070
    htc - Enable heap tail checking
    hfc - Enable heap free checking
    hpc - Enable heap parameter checking
quit:

没有debugheap

cdb -hd -c "!gflag;q" procdump.exe -x procdump.exe | grep -i -A 5 ntglob
Current NtGlobalFlag contents: 0x00000000
quit:

如果使用debugheap ntdll!还是使用RtlDebugAllocateHeap

脚本内容

cat testdbgheap.txt
bp ntdll!RtlDebugAllocateHeap "kb4;q"
g

使用dbgheap

cdb -c "$$>a< testdbgheap.txt" -o -g procdump.exe -x foo.dmp "c:\Windows\System32\NETSTAT.EXE" -a
Microsoft (R) Windows Debugger Version 10.0.10586.567 X86
CommandLine: procdump.exe -x foo.dmp "c:\Windows\System32\NETSTAT.EXE" -a
ProcDump v7.1 - Writes process dump files
0:000> cdb: Reading initial command '$$>a< testdbgheap.txt'
ChildEBP RetAddr  Args to Child
0022f788 76eda376 00320000 40000062 0000000c ntdll!RtlDebugAllocateHeap
0022f86c 76ea5ae0 0000000c 00000000 00000000 ntdll!RtlpAllocateHeap+0xc4
0022f8f0 0096f5f1 00320000 40000060 0000000c ntdll!RtlAllocateHeap+0x23a
WARNING: Stack unwind information not available. Following frames may be wrong.
0022f910 0096fca0 0000000c 00000000 00000000 procdump+0xf5f1
quit:

没有调试堆

cdb -hd -c "$$>a< testdbgheap.txt" -o -g procdump.exe -x foo.dmp "c:\Windows\System32\NETSTAT.EXE" -a
Microsoft (R) Windows Debugger Version 10.0.10586.567 X86
CommandLine: procdump.exe -x foo.dmp "c:\Windows\System32\NETSTAT.EXE" -a
ProcDump v7.1 - Writes process dump files
0:000> cdb: Reading initial command '$$>a< testdbgheap.txt'
[23:12:29] Dump 1 initiated: foo.dmp\NETSTAT.EXE_161108_231229.dmp
Active Connections
  Proto  Local Address          Foreign Address        State
  TCP    192.168.43.171:49464   stackoverflow:https    ESTABLISHED
[23:12:29] Dump count not reached.
0:000> q
quit:

procdump不使用它使用win32apis的dbgeng函数 CreateProcessW(CreateFlags 0x7)

你可以运行depends或dumpbin / imports来确定模块

dumpbin /imports procdump.exe | grep -i process
                    4 EnumProcessModules
                   C6 DebugActiveProcessStop
                   A8 CreateProcessW
                  1C0 GetCurrentProcess
                  380 OpenProcess
                  1DF GetExitCodeProcess
                  4C0 TerminateProcess
                  396 Process32FirstW
                  398 Process32NextW
                   C5 DebugActiveProcess
                  119 ExitProcess
                  24C GetProcessId
                  1C1 GetCurrentProcessId
                  3C3 ReadProcessMemory
                  304 IsProcessorFeaturePresent
                  24A GetProcessHeap
                  1A4 GetWindowThreadProcessId
                  212 OpenProcessToken

休息时叠加

cdb -c "bp kernel32!CreateProcessW \"ddu /c 1 @esp lc;q\";g" procdump.exe -x . netstat -a
| grep -i quit -B 11
0178e340  00000000
0178e344  012acc30 ""netstat"  -a"
0178e348  00000000
0178e34c  00000000
0178e350  00000000
0178e354  00000007 CreateSuspended | debug process | debug only this
0178e358  00000000
0178e35c  00000000
0178e360  0178e3a0 "D" = 0x44 = sizeof(startupinfo)
0178e364  0178e390 ""
0178e368  00000000
quit:

UPDATE使用windbg检查子进程procdump over procdump

cdb -hd -g -o -c“!handle 0 f Process; .tlist; q”procdump -x。计算值

Microsoft (R) Windows Debugger Version 10.0.10586.567 X86

CommandLine: procdump -x . calc

ProcDump v7.1 - Writes process dump files

0:000> cdb: Reading initial command '!handle 0 f Process;.tlist;q'

Handle e8
  Type          Process
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  Object Specific Information
    Process Id  2836
    Parent Process  2900
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1 handles of type Process
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 0n2860 cdb.exe
 0n2900 procdump.exe
 0n2836 calc.exe