您的位置:首页 > 其它

深入解析Windows操作系统(Windows Internals) 4th Edition 读书笔记 - 第一章 概念和工具(三)

2009-04-19 20:17 603 查看
本篇内容:内核源码,内核调试,常用工具。

1.3 挖掘Windows内部机理

研究方法
书中提到本书的许多信息是通过阅读Windows源代码,以及与开发人员交谈的基础上获得的。作为读者,当然不会有这么有利的条件。但是,幸运的是,现在Windows内核的源代码已经可以通过某种途径从微软网站下载到。这一点要归功于开源运动,但同时也体现了微软的诚意。我本人的机器上就有一份Windows Research Kernel的源代码。这是一份可以编译并且可以在Windows Server 2003 SP1上实际运行的代码。在阅读有关章节时,适时地参考一下源代码,一定有事半功倍的效果。

这份源代码的readme.txt里,赫然发现这样的文字:
Two of the best existing sources for documentation of the NTOS kernel are
Microsoft Windows Internals, 4th Ed 2005, Mark Russinovich and David Solomon
The Windows Curriculum Resource Kit (CRK)
http://www.msdnaa.net/curriculum/pfv.aspx?ID=6191
原来这本书竟然是这份内核源代码最好的文档之一,妙哉!

为了更好地阅读这份源代码,我使用了understand源代码阅读工具。关于undestand,参见我的另一篇文章(http://blog.csdn.net/qwang24/archive/2009/04/11/4064975.aspx)。

除了直接阅读源代码,还可以使用很多工具来挖掘Windows内部机理。书中列出了所有用到的工具及来源,摘录一份:

Tool
Image Name
Origin
Startup Programs Viewer
AUTORUNS
http://www.sysinternals.com
Dependency Walker
DEPENDS
Support Tools, Platform SDK
DLL List
LISTDLLS
http://www.sysinternals.com
EFS Information Dumper
EFSDUMP
http://www.sysinternals.com*
File Monitor
FILEMON
http://www.sysinternals.com
Global Flags
GFLAGS
Support Tools
Handle Viewer
HANDLE
http://www.sysinternals.com
Junction tool
JUNCTION
http://www.sysinternals.com
Kernel debuggers
WINDBG, KD
Debugging tools, Platform SDK, Windows DDK
Live Kernel Debugging
LIVEKD
http://www.sysinternals.com
Logon Sessions
LOGINSESSIONS
http://www.sysinternals.com
Object Viewer
WINOBJ
http://www.sysinternals.com
Open Handles
OH
Resource kits
Page Fault Monitor
PFMON
Support Tools, Resource kits, Platform SDK
Pending File Moves
PENDMOVES
http://www.sysinternals.com
Performance tool
PERFMON.MSC
Windows built-in tool
PipeList tool
PIPELIST
http://www.sysinternals.com
Pool Monitor
POOLMON
Support Tools, Windows DDK
Process Explorer
PROCEXP
http://www.sysinternals.com
Get SID tool
PSGETSID
http://www.sysinternals.com
Process Statistics
PSTAT
Support Tools, Windows 2000 Resource kits, Platform SDK, http://www.reskit.com
Process Viewer
PVIEWER (in the Support Tools) or PVIEW (in the Platform SDK)
Platform SDK
Quick Slice
QSLICE
Windows 2000 resource kits
Registry Monitor
REGMON
http://www.sysinternals.com
Service Control
SC
Windows XP, Platform SDK, Windows 2000 resource kits
Task (Process) List
TLIST
Debugging tools
Task Manager
TASKMGR
Windows built-in tool
TDImon
TDIMON
http://www.sysinternals.com
内核调试
内核调试是探索Windows内部机理的重要方法。内核调试工具:
l Windows调试工具箱(包括著名的WinDBG)
l LiveKD (systernals.com)
l SoftIce (Compuware Numega)
实际上近年来国人编写的syser kernel debugger也是一款优秀的内核调试工具,优于SoftIce。

Windows调试工具箱提供的内核调试有两种:命令行版本(kd.exe)和图形用户界面(GUI)版本:Windbg.exe。其命令集完全相同。它们支持三种类型的内核调试:
l 分析崩溃转储文件(即dump文件)
l 连接到一个正在运行的系统上。要示有两台计算机(目标计算机和控制主机。也可以使用虚拟机,只需一台计算机即可。)
l 连接到本地系统(Windows XP和Windows Server 2003)。这种方式只能查看系统状态。

调试符号路径设置:
srv*c:/symbols*http://msdl.microsoft.com/download/symbols

Platform SDK
Platform SDK包含了编译和链接Windows应用程序需要的文档、头文件和库文件。以前一直不知道这些头文件及库文件和Visual C++带的有什么区别,书中给出了解释:Platform SDK所带的头文件符合Windows操作系统最新版,而Visual C++带的头文件只是Visual C++刚发布时的版本,可能会过时。Platform SDK提供的Windows API头文件及一些实用工具对于考察Windows内部机理有很大帮助。

DDK(设备驱动程序驱动开发工具)
DDK也是考察Windows内部机理的丰富的信息源。主要体现在其详细的内核函数和机制的文档、相应的头文件(定义了关键的内部数据结构和常数)、内部例程的接口定义。

实验
本节的实验是使用内核调试工具显示内核数据结构。主要命令:
dt nt!_* (显示所有以下划线开头的符号名)
dt nt!_*interrupt* (显示所中断对象的结构名)
dt nt!_kinterrupt (显示_kinterrupt结构)

以下是我自己的机器上运行的结果
lkd> dt nt!_*interrupt*
ntoskrnl!_KINTERRUPT
ntoskrnl!_KINTERRUPT_MODE
ntoskrnl!_KINTERRUPT
lkd> dt nt!_kinterrupt
+0x000 Type : Int2B
+0x002 Size : Int2B
+0x004 InterruptListEntry : _LIST_ENTRY
+0x00c ServiceRoutine : Ptr32 unsigned char
+0x010 ServiceContext : Ptr32 Void
+0x014 SpinLock : Uint4B
+0x018 TickCount : Uint4B
+0x01c ActualLock : Ptr32 Uint4B
+0x020 DispatchAddress : Ptr32 void
+0x024 Vector : Uint4B
+0x028 Irql : UChar
+0x029 SynchronizeIrql : UChar
+0x02a FloatingSave : UChar
+0x02b Connected : UChar
+0x02c Number : Char
+0x02d ShareVector : UChar
+0x030 Mode : _KINTERRUPT_MODE
+0x034 ServiceCount : Uint4B
+0x038 DispatchCount : Uint4B
+0x03c DispatchCode : [106] Uint4B

如果想看Windows Research Kernel中关于_KINTERRUPT结构的定义,使用前面提到的understand,很容易找到。它位于base/ntos/inc/ke.h中,如下图:



与上述内核调试工具中显示的完全一致。如果是AMD64处理器,这个结构会多三个字段。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐