操作步骤如下:
首先确认已经安装好 WinDbg , VMware , 虚拟操作系统,我这里以 WinDbg 6.12.0002.633 X86 ,
VMware 6.5 , Windows XP Professional SP3 为例说明。
下载 DriverMonitor 这个工具软件,方便加载驱动程序到系统。
为虚拟操作系统添加一个 Serial Port ,串行端口选择 “输出到命名管道”,模式选择
//./pipe/com_1
This end is the server
The other end is an application
将编译好的工程文件,整个文件夹拷贝到真实机器,包括 .cpp .h objchk_wxp_x86/i386/ 文件夹下的 .pdb .sys 文件。
修改虚拟机的 boot.ini 文件:
“我的电脑” -> "系统属性" -> “高级” ->"启动和故障恢复 " -> "设置" ->"系统启动" -> "要手动编辑启动选项,请单击“编辑”" ->
打开编辑,在 [operating systems] 段后加入新的一行
multi(0)disk(0)rdisk(0)partition(1)/WINDOWS="Microsoft Windows XP Professional" /fastdetect /debugport=com1 /baudrate=115200
在真实机器上找到 WinDbg 安装目录下的 windbg.exe 右键一个快捷方式,增加参数,完整目标名如下 :
C:/WinDDK/7600.16385.1/Debuggers/windbg.exe -b -k com:pipe,port=//./pipe/com_1,resets=0
现在启动虚拟操作系统,如下
选择 [启用调试程序].
现在执行刚才创建的 WinDbg快捷方式,WinDbg 会与 虚拟操作系统通过串口进行通信。
WinDbg 的 Command 窗口显示连通成功:
Microsoft (R) Windows Debugger Version 6.12.0002.633 X86Copyright (c) Microsoft Corporation. All rights reserved.
Opened //./pipe/com_1Waiting to reconnect...Connected to Windows XP 2600 x86 compatible target at (Thu Jan 27 17:17:55.656 2011 (UTC + 8:00)), ptr64 FALSEKernel Debugger connection established. (Initial Breakpoint requested)Symbol search path is: SRV*c:/symcache*http://msdl.microsoft.com/download/symbols;D:/Test7/NT_Driver/objchk_wxp_x86/i386Executable search path is: Windows XP Kernel Version 2600 MP (1 procs) Free x86 compatibleBuilt by: 2600.xpsp.080413-2111Machine Name:Kernel base = 0x804d8000 PsLoadedModuleList = 0x8055e720System Uptime: not availableWARNING: Inaccessible path: 'C:/Documents and Settings/Administrator/桌面/Test2/NT_Driver'Break instruction exception - code 80000003 (first chance)******************************************************************************** ** You are seeing this message because you pressed either ** CTRL+C (if you run kd.exe) or, ** CTRL+BREAK (if you run WinDBG), ** on your debugger machine's keyboard. ** ** THIS IS NOT A BUG OR A SYSTEM CRASH ** ** If you did not intend to break into the debugger, press the "g" key, then ** press the "Enter" key now. This message might immediately reappear. If it ** does, press "g" and "Enter" again. ** ********************************************************************************nt!RtlpBreakWithStatusInstruction:8052c5dc cc int 3
现在添加 源文件 和 符号文件 目录
File -> Symbol Search Path -> Browse
"D:/Test7/NT_Driver/objchk_wxp_x86/i386" 把 Reload 勾上
File -> Open Source File ->Driver.cpp
现在以 DriverEntry 和 HelloDDKUnload 函数为例,设置断点,在 command 中输入 " bu HelloDDK!DriverEntry "
bu HelloDDK!HelloDDKUnload
好了,现在输入 g 回车,让操作系统加载起来。
现在在虚拟操作系统里面运行 DriverMonitor ,选择编译好的 sys 文件
点击 Go 按钮,这时候 真实机器 的 WinDbg 收到消息,转到 DriverEntry 入口函数停止下来。注意粉红色的标记
command 窗口显示函数信息:
--GetMcast: 6501a8c0 81f29e00Breakpoint 0 hithelloddk!DriverEntry:f8bb2e90 8bff mov edi,edi
这个时候就可以 按 F10 一步一步执行函数,或按 F11 跳进函数内部查看执行过程。或者按 F5 直接执行到下一个断点处。
下面点击 DriverMonitor 的 stop 按钮。
执行的代码会以高亮显示,command 窗口会打印 KdPrint 的字符串
Enter DriverUnload // <-------------helloddk!HelloDDKUnload+0x15:f8bb2725 8b4508 mov eax,dword ptr [ebp+8]