一. vmware 下安装:windows 7 ultimate x86 中文版
1、vmware (请使用尽可能新的版本以对tools的支持) 的设置
打开相应 vmware 虚拟机上的 “Virtaul Machine Settings”---> “Hardware”选项中 ----> 点击 “Add” 添加一个串口设备 Seiall Port ----> “Next” ----> 在 Serial Port 里选中“Output to named pipe” ----> “next” ----> “Finish”
最后,回到 “Virtual Machine Settings”页面时,在“I/O Mode” 里选中“Yield CPU on poll” 这样 vmware 的设置就好了。
注意看清楚:Serial Port 1还是Serial Port 2,接下来会用到。
2、windbg 的使用
创建windbg.exe所在目录的环境变量后,在桌面写个批处理,保存为vmware_win7.bat 内容如下:
在桌面上建一个便捷方式,命令行是:
windbg -b -k com:port=//./pipe/com_1,baud=115200,pipe
这样在开启 vmware 中的 windows 7 后运行这个便捷方式,windbg 与 guest OS “win7” 就建立成联线方式。
二、guest OS - win7 中设定
1、在 bootmgr 中下断点
在 vista 及后续的 windows 已经取消了 ntldr 模块管理引导,转而以 bootmgr 模块管理引导系统。
在我的 windows 7中要设定在哪个部分进行调试。
windws 7 可调试部分有 4 个:bootmgr 模块、winload 模块、WinResume 模块以及 windows 内核模块 Nt 模块
可以在上述的 4 个模块下断点进行调式
(1) 以管理员身份运行“命令提示符”
(2) 在“命令提示符”窗口中,输入以下命令:
bcdedit /set {bootmgr} bootdebug on
bcdedit /set {bootmgr} debugtype serial
bcdedit /set {bootmgr} debugport 1
bcdedit /set {bootmgr} baudrate 115200
注意一个细节,bcdedit /set {bootmgr} debugport 1这一行最后的1 对应Serial Port 1,
所以如果是Serial Port 2 则设置为bcdedit /set {bootmgr} debugport 2 否则连不上。
bcdedit /set {bootmgr} bootdebug on |
在提示命令成功后,这样就在 windows7 中的 bootmgr 模块建立起可调试的机制。
在运行 windows7 时到达 bootmgr 时就停止加载,vmware 中是黑屏,它正等待 serial port 的响应,
运行 windbg 后,windbg 就和 windws 7 中的 bootmgr 建立起联线了
下面是我的 windbg 在 bootmgr 模式下断点的响应信息:
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.
Opened //./pipe/com_1
Waiting to reconnect...
BD: Boot Debugger Initialized
Connected to Windows Boot Debugger 7600 x86 compatible target at (Mon May 9 13:25:27.631 2011 (GMT+8)), ptr64 FALSE
Kernel Debugger connection established. (Initial Breakpoint requested)
Symbol search path is: SRV*c:/symbols*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows Boot Debugger Kernel Version 7600 UP Free x86 compatible
Machine Name:
Primary image base = 0x00400000 Loaded module list = 0x00491b80
System Uptime: not available
Break instruction exception - code 80000003 (first chance)
bootmgr!RtlpBreakWithStatusInstruction:
004436bc cc int 3
;====================================
Primary image base = 0x00400000 Loaded module list = 0x00491b80
bootmgr 被加载到基地址是 0x00400000
bootmgr!RtlpBreakWithStatusInstruction:
目前处在 bootmgr 模块中
查看:
kd> x bootmgr!*
00430724 bootmgr!TpmApiAuthSessCreateOSAP = <no type information>
0045dc5c bootmgr!CmpGetIndexElementSize = <no type information>
004689a4 bootmgr!RcConsoleBaudRates = <no type information>
004356cd bootmgr!OsxmlBrowser::~OsxmlBrowser = <no type information>
00437683 bootmgr!XslStylesheet::getContents = <no type information>
0040d032 bootmgr!BlockIoPcatConventionalInt13 = <no type information>
00420202 bootmgr!BlLogData = <no type information>
0041cda5 bootmgr!NetClose = <no type information>
0043bf31 bootmgr!XslTemplate::getContents = <no type information>
0042ab94 bootmgr!MmTrSelectPageTableMappingAddress = <no type information>
0041796b bootmgr!FileIoOpen = <no type information>
......
2、在 winload 模块下断点
同样在“命令提示符”中使用命令
bcdedit /enum |
这条命令显示当前可用模块的 GUID
Microsoft Windows [版本 6.1.7600]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:/Windows/system32>bcdedit /enum
Windows 启动管理器
--------------------
标识符 {bootmgr}
device partition=C:
description Windows Boot Manager
locale zh-CN
inherit {globalset