使用 vmware + windbg 就可以调试 windows 内核了,但是我喜欢还开上 bochs ,使用 bochs 很方便灵活。
vmware 里的 guest OS 作为被调试对象,Host OS 里使用 windbg 作为调试者
guest OS 和 Host OS 通过 serial port 以 named pipe 方式作为联线。
一、在我的 vmware 上装上了两个 windows: vista 32 和最新的 windows 7 64bit-beta
本来是只想装 windows 7 64bit - beta 版玩的,但是 bochs 装上 windows 7 64bit-beta 老有问题装不上,只能装上 vista32 了。
1、vmware 的设置
打开相应 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 的设置就好了。
2、windbg 的使用
在桌面上建一个便捷方式,命令行是:
"C:\Program Files\Debugging Tools for Windows 64-bit\windbg.exe" -b -k com:port=\\.\pipe\com_1,baud=115200,pipe
这样在开启 vmware 中的 vista 后运行这个便捷方式,windbg 与 guest OS "vista" 就建立成联线方式。
二、guest OS - vista 中设定
1、在 bootmgr 中下断点
vista 及后续的 windows 已经取消了 ntldr 模块进行引导,转而以 bootmgr 模块进行引导系统。
在 vista 中要设定在哪个部分进行调试。
vista 可调试部分有 4 个: bootmgr 模块、 winload 模块、WinResume 模块以及 windows 内核模块 Nt 模块
可以在这4个模块下断点进行调式
在提示命令成功后,这样就在 vista 中的 bootmgr 模块建立起可调试的机制。
在运行 vista 时到达 bootmgr 时就停止加载,vmware 中是黑屏,它正等待 serial port 的响应,
运行 windbg 后,windbg 就和 vista 中的 bootmgr 建立起联线了
下面是我的 windbg 的响应信息:
-----------------------------------------------------------------------------------------------------------------------------------------
Microsoft (R) Windows Debugger Version 6.9.0003.113 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
Opened \\.\pipe\com_1
Waiting to reconnect...
BD: Boot Debugger Initialized
Connected to Windows Boot Debugger 6000 x86 compatible target, ptr64 FALSE
Kernel Debugger connection established. (Initial Breakpoint requested)
Symbol search path is: *** Invalid ***
****************************************************************************
* Symbol loading may be unreliable without a symbol search path. *
* Use .symfix to have the debugger choose a symbol path. *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************
Executable search path is:
*********************************************************************
* Symbols can not be loaded because symbol path is not initialized. *
* *
* The Symbol Path can be set by: *
* using the _NT_SYMBOL_PATH environment variable. *
* using the -y <symbol_path> argument when starting the debugger. *
* using .sympath and .sympath+ *
*********************************************************************
*** ERROR: Module load completed but symbols could not be loaded for bootmgr
Windows Boot Debugger Kernel Version 6000 UP Free x86 compatible
Primary image base = 0x00400000 Loaded module list = 0x004ffff8
System Uptime: not available
Break instruction exception - code 80000003 (first chance)
bootmgr+0x37ea4:
00437ea4 cc int 3
这段信息中,看到:
(1) Opened \\.\pipe\com_1
打开了 serial port
(2) Symbol search path is: *** Invalid ***
符号不可用
(3) Primary image base = 0x00400000 Loaded module list = 0x004ffff8
bootmgr 被加载到基地址是 0x00400000