2

当我们在 Visual Studio 2013 或 WinDbg 等调试器下启动应用程序时,Windows 将为其使用调试堆。但是,似乎可以关闭该行为,就像在 Visual Studio 2015 或 WinDbg 中使用-hd命令行开关启动时所做的那样。

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

如何确定使用 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然后我等待 Debugger Engine 模块被加载(

4

1 回答 1

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:

没有调试堆

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 不使用 dbgeng 函数,它使用 win32apis CreateProcessW (CreateFlags 0x7)

您可以运行依赖或 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:

在procdump上使用windbg在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
于 2016-11-08T16:45:52.053 回答