windbg+vmware+win7 内核

来源:互联网 发布:芒果tv软件下载 编辑:程序博客网 时间:2024/04/19 23:44

一. 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
bcdedit /set {bootmgr} debugtype serial
bcdedit /set {bootmgr} debugport 1
bcdedit /set {bootmgr} baudrate 115200

在提示命令成功后,这样就在 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                 {globalsettings}
debugtype               Serial
debugport               2
baudrate                115200
bootdebug               Yes
default                 {current}
resumeobject            {8bf63dd6-79ea-11e0-9d42-db726cb22836}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Windows 启动加载器
-------------------
标识符                  {current}
device                  partition=C:
path                    /Windows/system32/winload.exe
description             Windows 7
locale                  zh-CN
inherit                 {bootloadersettings}
recoverysequence        {8bf63dd8-79ea-11e0-9d42-db726cb22836}
recoveryenabled         Yes
osdevice                partition=C:
systemroot              /Windows
resumeobject            {8bf63dd6-79ea-11e0-9d42-db726cb22836}
nx                      OptIn

 

3、在内核模块 Nt 模块下断点

  打开 windws 7 的“控制面板”----> “管理工具” ---> “系统配置” ---> 打开“引导”页面 ---> 点击“高级选项”

  ----> 在高级启动选项里,选中“调试” ----> 点击“确定”就行了。

注意端口的选择同上。com1或com2对应。

  这样就在 nt 模块下了断点


Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

Opened //./pipe/com_1
Waiting to reconnect...
Connected to Windows 7 7600 x86 compatible target at (Mon May  9 14:37:37.001 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 7 Kernel Version 7600 MP (1 procs) Free x86 compatible
Product: WinNt, suite: TerminalServer SingleUserTS
Built by: 7600.16385.x86fre.win7_rtm.090713-1255
Machine Name:
Kernel base = 0x83c47000 PsLoadedModuleList = 0x83d8f810
Debug session time: Mon May  9 14:37:32.656 2011 (GMT+8)
System Uptime: 0 days 0:00:04.828
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:
83cb2394 cc              int     3
kd> g
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:
83cb2394 cc              int     3
kd> g
KDTARGET: Refreshing KD connection



三、 windbg 加载符号


  在 windbg 的 "File" ---> "Symbol File path" ---> 设定为: SRV*d:/symbols*http://msdl.microsoft.com/download/symbols

  回到 windbg 命令行,使用命令 .reload 命令,可以自动加载符号

 

 相关命令:

C:/Users>bcdedit /?

BCDEDIT - 启动配置数据存储编辑器

Bcdedit.exe 命令行工具用于修改启动配置数据存储。
启动配置数据存储包含启动配置参数并控制操作系统的启动方式。这些参数以前位于
Boot.ini 文件中(在基于 BIOS 的操作系统中)或位于稳定 RAM 项中(在基于可扩展
固件接口的操作系统中)。可以使用 Bcdedit.exe 在启动配置数据存储中添加、删除、
编辑和附加项。

有关命令和选项的详细信息,请键入 bcdedit.exe /? <command>。
例如,若要显示有关 /createstore 命令的详细信息,请键入:

     bcdedit.exe /? /createstore

有关本帮助文件中按字母顺序排列的主题列表,请运行 "bcdedit /? TOPICS"。

对存储执行的命令
================================
/createstore    新建空的启动配置数据存储。
/export         将系统存储的内容导出到文件。以后可以使用该文件还原系统
                存储的状态。
/import         使用 /export 命令创建的备份文件来还原系统存储的状态。

/sysstore       设置系统存储设备(仅影响 EFI 系统,在重新启动后不再有效,
                且仅用于系统存储设备不确定的情况下)。

对存储中的项执行的命令
===========================================
/copy           复制存储中的项。
/create         在存储中新建项。
/delete         删除存储中的项。
/mirror         创建存储中项的镜像。

运行 bcdedit /? ID 可获得有关这些命令使用的标识符的信息。

对项选项执行的命令
======================================
/deletevalue    删除存储中的项选项。
/set            设置存储中的项选项值。

运行 bcdedit /? TYPES 可获得这些命令使用的数据类型的列表。
运行 bcdedit /? FORMATS 可获得有效数据格式的列表。

控制输出的命令
============================
/enum           列出存储中的项。
/v              命令行选项,完整显示项标识符,而不是使用已知标识符的名称。

                单独使用命令 /v 可完整显示活动类型的项标识符。

单独运行 "bcdedit" 等同于运行 "bcdedit /enum ACTIVE"。

控制启动管理器的命令
======================================
/bootsequence   为启动管理器设置一次性启动序列。
/default        设置启动管理器将使用的默认项。
/displayorder   设置启动管理器显示多重引导菜单的顺序。
/timeout        设置启动管理器的超时值。
/toolsdisplayorder  设置启动管理器显示工具菜单的顺序。

控制启动应用程序紧急管理服务的命令
==========================================================================
/bootems        启用或禁用启动应用程序的紧急管理服务。
/ems            启用或禁用操作系统项的紧急管理服务。
/emssettings    设置全局紧急管理服务参数。

控制调试的命令
==============================
/bootdebug      启用或禁用启动应用程序的启动调试。
/dbgsettings    设置全局调试程序参数。
/debug          启用或禁用操作系统项的内核调试。
/hypervisorsettings  设置虚拟机监控程序的参数。

 

C:/Users>bcdedit /set /?

此命令设置引导配置数据存储中的项选项值。

bcdedit [/store <filename>] /set [{<id>}] <datatype> <value> [ /addfirst | /addlast | /remove ]

    <filename>  指定要使用的存储。如果未指定此选项,则使用系统存储。
                有关详细信息,请运行 "bcdedit /? store"。

    <id>        指定要修改的项的标识符。如果未指定,则使用 {current}。
                有关标识符的详细信息,请运行 "bcdedit /? ID"。

    <datatype>  指定将创建或修改的选项数据类型。
                有关数据类型的详细信息,请运行 "bcdedit /? TYPES"。

    <value>     指定应分配给该选项的值。<value> 的格式取决于指定的数据类型。
                有关数据格式的详细信息,请运行 "bcdedit /? FORMATS"。

  /addfirst     仅当数据类型是对象列表时才能使用此开关。
                将指定的项标识符添加到列表的顶部。
                如果已指定此开关,则只能指定一个项标识符。
                如果所指定的标识符已在列表中,请将它移到列表顶部。

    /addlast    仅当数据类型是对象列表时才能使用此开关。
                将指定的项标识符添加到列表的结尾。
                如果已指定此开关,则只能指定一个项标识符。
                如果所指定的标识符已在列表中,它将被移到列表结尾。

    /remove     仅当数据类型是对象列表时才能使用此开关。
                请从列表中删除指定的项标识符。
                如果已指定此开关,则只能指定一个项标识符。
                如果此标识符不在列表中,则操作无效。
                如果正在删除最后一项,则此数据类型值也将被删除。

示例:

对于指定的操作系统项,下列命令将应用程序设备设置到 C: 分区:

    注意: 使用 "hd_partiton=" 语法显式禁用自动 VHD 检测,并
          创建与启动虚拟机兼容的项目,例如,

    bcdedit /store Foocd /set {default} device hd_partition=F:

对于指定的操作系统项,下列命令将操作系统设备设置到 VHD 文件(C:/vdisks/vdisk01.vhd)

    bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} osdevice vhd=[C:]/vdisks/disk01.vhd

对于指定的操作系统项,下列命令将应用程序路径设置到 /windows/system32/winload.exe
:

    bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} path /windows/system32/winload.exe

对于当前的操作系统启动项,下列命令将 NX 策略设置到 OptIn。

    bcdedit /set nx optin
   
C:/Users>bcdedit  /? ID

标识符

很多 Bcdedit 命令需要标识符。标识符可以唯一标识存储中包含的项。标识符采取
全局唯一标识符的形式,或称为 GUID。GUID 具有以下格式,其中每个“x”代表
一个十六进制数。

    {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

例如:

    {d2b69192-8f14-11da-a31f-ea816ab185e9}

破折号(-)的放置以及 GUID 开头和结尾的括号是必需的。

已知标识符可以标识多个项。如果某个项具有已知标识符,则 BCDedit 将其显示
在输出中,除非使用了 /v 命令行开关。
有关详细信息,请运行 "bcdedit /? /v"。

已知标识符如下所示:

    {bootmgr}               指定 Windows 启动管理器项。

    {fwbootmgr}             指定固件启动管理器项,特别是在实现可扩展固件

                            接口(EFI)规格的系统上。

    {memdiag}               指定内存诊断应用程序项。

    {ntldr}                 指定可用于启动早于 Windows Vista 版本的操作
                            系统的 OS 加载程序(Ntldr)。


    {current}               指定与当前运行的操作系统的操作系统启动项

                            对应的虚拟标识符。

    {default}               指定与启动管理器默认应用程序项对应的虚拟
                            标识符。

    {ramdiskoptions}        包含启动管理器所需的其他的 RAM 磁盘设备
                            选项。

    {dbgsettings}           包含可由任意启动应用程序项继承的全局调试
                            程序设置。

    {emssettings}           包含可由任意启动应用程序项继承的全局紧急
                            管理服务设置。

    {badmemory}             包含可由任意启动应用程序项继承的全局 RAM
                            故障列表。

    {globalsettings}        包含所有启动应用程序项应继承的全局设置的
                            集合。

    {bootloadersettings}    包含所有 Windows 启动加载程序应用程序项
                            应继承的全局设置的集合。

    {resumeloadersettings}  包含所有 Windows 从休眠状态恢复应用程序项
                            应继承的全局设置的集合。

    {hypervisorsettings}    包含可由任意 OS 加载程序项继承的虚拟机
                            监控程序设置。
   


参考:http://www.mouseos.com/win7/windbg.html

 

引导分析:http://mirror.href.com/thestarman/asm/mbr/Win2kmbr.htm

http://mirror.href.com/thestarman/asm/mbr/index.html