如何控制多进程调试
问题描述:
我正在用WinDbg分析AcroRd32.exe
。 AcroRd32.exe
有2个进程,其中一个(父-P)启动另一个进程(child-p)。我使用.childdbg 1
和|1s
等命令来调试这两个进程。如何控制多进程调试
我切换到child-p,然后切换回到father-p,使用条件断点监视kernel32.dll的CreateFileW
和ReadFile
API。在打开a.pdf
时,仅使用参数“C:\ a.pdf”调用CreateFileW
。我记得文件句柄CreateFileW
的返回值,使用条件断点来监视ReadFile
的参数,但是没有调用ReadFile
,返回值为CreateFileW
。然后与许多g
命令,混淆的事情来了,a.pdf
打开!
我很困惑。没有致电ReadFile
,PDF打开。 Acrobat Reader是如何做到的?我有两个假设,第一个,它使用一些像API一样的CreateFileMapping
;另一个(大部分),孩子 - P做它。
让我们来讨论第二个假设。当我调试father-p时,child-p没有挂起。它是如何打开(读取)文件的?
答
使用Rohitab API Monitor我看到第二个实例调用CreateFileW()
以及ReadFile()
与文件句柄:
既然是这样的话,它也必须能够找出同用WinDbg中的断点。如果没有确切的步骤来重现问题,我们将无法回答出现问题的情况,例如在你的断点的条件。
当我看着我的演练中,我觉得有以下可能出现的问题:
- 您使用的子进程的状态父进程的文件句柄,虽然子进程得到了新手柄
- 您正在设置错误进程的断点。断点是特定于流程的。
- 其他情况在断点的情况下是错误的。检查
.if
或j
命令。
这是我的演练,它显示了断点的命中。我在这里没有使用条件断点。
0:000> bp kernel32!CreateFileW
0:000> .childdbg 1
Processes created by the current process will be debugged
0:000> g
[...]
Breakpoint 0 hit
[...]
0:000> kb L1
# ChildEBP RetAddr Args to Child
00 0045f0d8 011d95b1 0023ca98 00000000 00000007 kernel32!CreateFileW
0:000> du 0023ca98
0023ca98 "d:\temp\a.pdf"
0:000> gu
0:000> r eax
eax=000000f0
0:000> *** Note that this is the wrong process, it's the father
0:000> *** We should not set a breakpoint with a condition of 0xF0 as the handle
0:000> *** Let's wait for the child process
0:000> bd 0
0:000> sxe cpr
0:000> g
[...]
ModLoad: 011c0000 013e5000 AcroRd32.exe
[...]
1:009> bl
1:009> |0s
[...]
0:000> bl
0 d Enable Clear 771a167f 0001 (0001) 0:**** kernel32!CreateFileW
0:000> |1s
[...]
1:009> bl
1:009> *** Did you note? Breakpoints are process specific
1:009> bp kernel32!CreateFileW
Bp expression 'kernel32!CreateFileW' could not be resolved, adding deferred bp
1:009> g
[...]
ntdll!LdrpDoDebuggerBreak+0x2c:
77850ed4 cc int 3
1:009> bl
1 e Disable Clear 771a167f 0001 (0001) 1:**** kernel32!CreateFileW
[...]
Breakpoint 1 hit
[...]
1:009> kb L1
# ChildEBP RetAddr Args to Child
00 002cedcc 771a775d 002cedec 002cede8 772e124c kernel32!CreateFileW
1:009> du 002cedec
002cedec "C:\Windows\Globalization\Sorting"
002cee2c "\sortdefault.nls"
1:009> *** wrong file
1:009> g
[...]
Breakpoint 0 hit
[...]
1:009> kb L1
# ChildEBP RetAddr Args to Child
00 0043da18 5f9b5cf0 06a12e68 80000000 00000001 kernel32!CreateFileW
1:009> du 06a12e68
06a12e68 "d:\temp\a.pdf"
1:009> gu
[...]
1:009> r eax
eax=000001cc
1:009> bp kernel32!readfile
1:009> bl
0 e Disable Clear 771a167f 0001 (0001) 1:**** kernel32!CreateFileW
1 e Disable Clear 771a3ef1 0001 (0001) 1:**** kernel32!ReadFile
1:009> bd 0
1:009> g
Breakpoint 1 hit
[...]
1:009> kb L1
# ChildEBP RetAddr Args to Child
00 0043da44 5f9b74be 000001cc 0043db64 00000008 kernel32!ReadFile
谢谢!!你的回答已经很好地解决了我的问题!作为一个初学者,谢谢你从我的心底多次帮助我解决问题。 – xupeng
@xupeng:不客气。 WinDbg很难学,我很高兴能分享我的知识 –