﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Ay's Blog@CNSSUESTC-随笔分类-操作系统&amp;&amp;内核</title><link>http://www.cppblog.com/ay19880703/category/8298.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 31 Oct 2011 11:46:27 GMT</lastBuildDate><pubDate>Mon, 31 Oct 2011 11:46:27 GMT</pubDate><ttl>60</ttl><item><title>WINDBG的堆调试--了解HEAP组织</title><link>http://www.cppblog.com/ay19880703/archive/2011/10/30/159364.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sun, 30 Oct 2011 11:05:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2011/10/30/159364.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/159364.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2011/10/30/159364.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/159364.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/159364.html</trackback:ping><description><![CDATA[
		<p>@作者: ay @文章出处: <a href="http://cnss-ay.com/" target="_blank">cnss-ay的博客</a><font color="#ff0000">@Notice: 转载请注明出处！若文章显示不完整，可以到文章出处阅读。</font></p>
		<h1>HEAP的概念</h1>
		<p>堆栈堆栈，在操作系统内存中有两种存储空间，一个是堆，一个是栈。堆主要用于存储用户动态分配的变量，而栈呢，则是存储我们程序过程中的临时变量。当然栈的作用远不止用作存储变量，但这不是我们这篇文章的讨论内容。</p>
		<p> </p>
		<p>堆（HEAP）的分配，使用，回收都是通过微软的API来管理的，最常见的API是malloc和new。在往底层走一点呢，这两个函数都会调用HeapAlloc（RtlAllocateHeap）。同样的相关函数还有HeapFree用来释放堆，HeapCreate用来创建自己的私有堆。下面是这些函数的调用链：</p>
		<p>HeapCreate-&gt;RtlCreateHeap-&gt;ZwAllocateVirtualMemory  (这里会直接申请一大片内存,至于申请多大内存,由进程PEB结构中的字段觉得，HeapSegmentReserve字段指出要申请多大的虚拟内存，HeapSegmentCommit指明要提交多大内存，对虚拟内存的申请和提交概念不清楚的童鞋，请参见windows核心编程相关内容~)</p>
		<p>HeapAlloc-&gt;RtlAllocateHeap（至于这里申请的内存，由于HeapCreate已经申请了一大片内存，堆管理器这片内存中划分一块出来以满足申请的需要。这一步申请操作是堆管理器自己维护的，<font color="#ff0000">仅当申请内存不够的时候才会再次调用ZwAllocateVirtualMemory</font> ）</p>
		<p>HeapFree-&gt;RtlFreeHeap （对于释放的内存，堆管理器只是简单的把这块内存标志位已释放让后加入到空闲列表中，<font color="#ff0000">仅当空闲的内存达到一定阀值的时候会调用ZwFreeVirtualMeMory</font> ）</p>
		<p>HeapDestroy-&gt;RtlDestroyHeap-&gt;ZwFreeVirtualMeMory   （销毁我们申请的堆）</p>
		<h1>如何找到我们的HEAP信息？</h1>
		<p>WINDBG观察堆</p>
		<p>源码：</p>
		<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d5c33111-de2a-4819-a5af-d446f98a496a" class="wlWriterEditableSmartContent">
				<pre name="code" class="c:collapse">#include "windows.h"

int main()
{
	HANDLE heap_handle = HeapCreate( NULL , 0x1000 , 0x2000 ) ;

	char *buffer = (char*)HeapAlloc(heap_handle , NULL , 128) ;

	char *buffer1 = (char*)HeapAlloc(heap_handle , NULL , 121) ;

	HeapFree(heap_handle, 0 , buffer ) ;
	HeapFree(heap_handle, 0 , buffer1 ) ;

	HeapDestroy( heap_handle) ;
	return 0 ;
}</pre>
		</div>
		<p>该源码生成编译生成heap.exe，然后用windbg调试这个程序，在main函数下断，紧接着执行第五行语句，执行结果如下</p>
		<p>0:000&gt; p<br />eax=002e1ca0 ebx=00000000 ecx=6d29b6f0 edx=00000000 esi=00000001 edi=01033374<br />eip=01031012 esp=0022fe8c ebp=0022feac iopl=0         nv up ei pl nz na po nc<br />cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202<br />heap!main+0x12:<br />01031012 ff150c200301    call    dword ptr [heap!_imp__HeapCreate (0103200c)] ds:0023:0103200c={kernel32!HeapCreateStub (769a29d7)}<br /></p>
		<p>0:000&gt; p<br />eax=<font color="#ff0000">002c0000</font> ebx=00000000 ecx=77429897 edx=77498500 esi=00000001 edi=01033374<br />eip=01031018 esp=0022fe98 ebp=0022feac iopl=0         nv up ei pl nz na pe nc<br />cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206<br />heap!main+0x18:<br />01031018 8945fc          mov     dword ptr [ebp-4],eax ss:0023:0022fea8=6d222201<br />0:000&gt; !heap <br />Index   Address  Name      Debugging options enabled<br />  1:   00300000                <br />  2:   00010000                <br />  3:   00020000                <br />  4:   002e0000                <br />  5:   <font color="#ff0000">002c0000</font>       </p>
		<p>HeapCreate执行的返回值存放在eax处，这个函数返回了一个堆句柄：0x002c0000。用!heap命令查看可以看到第五个堆就是我们创建的堆句柄了。</p>
		<p>每个进程都存在多个堆，我们也可以通过PEB结构来得到进程中存在的堆，结果和!heap命令显示的内容是一样的。</p>
		<p>heap!_PEB<br />   +0x018 ProcessHeap      : 0x00300000 Void         ; 进程的默认堆<br />   +0x068 NtGlobalFlag     : 0                                       ; 这个标志位记录了当前堆调试模式,0为普通调试模式<br />   +0x078 HeapSegmentReserve : 0x100000          ; 进程在新建堆的时候默认申请的虚拟内存大小<br />   +0x07c HeapSegmentCommit : 0x2000               ; 进程在每次申请提交的虚拟内存大小，在提交的内存用完后，进程会又在一次提交HeapSegmentCommit中指定的内存大小<br />   +0x080 HeapDeCommitTotalFreeThreshold : 0x10000    ; 当释放的内存大小大于这个阀值，就进行内存解除提交操作<br />   +0x084 HeapDeCommitFreeBlockThreshold : 0x1000     ;  当一次性释放的块大小超过这个阀值，就进行内存解除提交操作，<font color="#ff0000">只有当满足这两个条件时才会调用ZwFreeVirtualMeMory 释放物理内存<br /></font>   +0x088 NumberOfHeaps    : 5                                               ; 当前进程的堆数目,这个数目对应着!heap命令的堆显示个数<br />   +0x08c MaximumNumberOfHeaps : 0x10                          ; 进程所能运行的最大堆数目,若堆数目超过这个值估计HeapCreate就失败了吧<br />   +0x090 ProcessHeaps     : 0x77498500  -&gt; 0x00300000 Void ;存储堆句柄的数组,这里我们可以得到进程的所有堆句柄</p>
		<p>我们可以输入如下命令来查看现有的堆句柄</p>
		<p>0:000&gt; dd 0x77498500  <br />77498500  <font color="#ff0000">00300000 00010000 00020000 002e0000</font><br />77498510  <font color="#ff0000">002c0000</font> 00000000 00000000 00000000<br />77498520  00000000 00000000 00000000 00000000<br />77498530  00000000 00000000 00000000 00000000<br />77498540  00000000 77498340 7749bb08 77498220<br />77498550  00000000 00000000 00000000 00000000<br />77498560  77498220 00317bd0 00000000 00000000<br />77498570  00000000 00000000 00000000 00000000<br /></p>
		<p>可以看得到这里面的内容和!heap命令的输出结果是一样的</p>
		<p>而堆句柄的存放范围,从MaximumNumberOfHeaps 上来看,就是77498500-77498540这0x40个字节，因为每个堆句柄占4个字节，0x10个堆句柄的存放空间就是0x40。</p>
		<h1>HEAP的组织结构</h1>
		<p>堆的管理，我们可以理解为一个内存池，它申请一大块空间，然后负责接管应用程序的申请释放等请求。只有在创建堆，释放堆（注意！是释放堆，不是堆中的空间！）在这之前，我们需要对堆有关的数据结构做一些解释</p>
		<p>我这里观察到的HEAP结构，HEAP_SEGMENT结构和HEAP_ENTRY结构都和软件调试里面描述的不一样，当年奎哥写软件调试的时候估计还没用上WIN7吧。。。我的演示系统是WIN7</p>
		<p>HeapCreate函数返回的堆句柄其实就是一个指向堆管理结构的指针，每个堆都会涉及到这样三个结构：HEAP,HEAP_SEGMENT,HEAP_ENTRY</p>
		<p>HEAP_ENTRY结构：</p>
		<p>在堆管理中，每一块申请下来的内存都会有下面所示的固定模式：</p>
		<table border="1" cellpadding="2" cellspacing="0" width="400">
				<tbody>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_ENTRY（8 bytes）</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">我们new或malloc分配的空间</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">固定填充空间</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p>这个结构用来记录所分配的空间的信息，包括用户申请的空间，填充的空间，所在的段号等等信息。所以我们new或者malloc的地址减去8就指向该结构。第三部分的固定填充空间是为了内存对齐而生成的，当然这部分空间还有一部分是用来额外记录这块内存的其它信息，这里就不详细做介绍了。</p>
		<p>HEAP_SEGMENT结构：</p>
		<p>我们可以这么认为，堆申请内存的大小是以段为单位的，当新建一个堆的时候，系统会默认为这个堆分配一个段叫0号段，通过刚开始的new和malloc分配的空间都是在这个段上分配的，当这个段用完的时候，如果当初创建堆的时候指明了HEAP_GROWABLE这个标志，那么系统会为这个堆在再分配一个段，这个时候新分配的段就称为1号段了，以下以此类推。每个段的开始初便是HEAP_SEGMENT结构的首地址，由于这个结构也是申请的一块内存，所以它前面也会有个HEAP_ENTRY结构：</p>
		<table border="1" cellpadding="2" cellspacing="0" width="400">
				<tbody>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_ENTRY（8 bytes）</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_SEGMENT</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_ENTRY（8 bytes）</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">我们new或malloc分配的空间</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">固定填充空间</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p>HEAP_SEGMENT结构会记录段的一些基本信息，该段申请的大小，已经提交内存的大小，第一个HEAP_ENTRY结构的入口点。（我观察看貌似段申请的内存并不会一次性全部提交，而是每次提交一个页的大小，比如一个段大小2个页，那么它会先提交一个页内存，若用完了再提交一个页的内存，若内存还用完了那就新建一个段，这个新建的段也会是先提交一个页内存。）但是0号段很特别，<font color="#ff0000">这个段的起始地址就是堆句柄指针指向的值，也就是说，</font><font color="#ff0000">HeapCreate返回的堆句柄总是指向0号段，为什么呢？因为HEAP结构是HEAP_ENTRY,HEAP_SEGMENT的合体加长版~</font></p>
		<p>HEAP结构：</p>
		<p>HEAP结构则是记录了这个堆的信息，这个结构可以找到HEAP_SEGMENT链表入口，空闲内存链表的入口，内存分配粒度等等信息。HEAP的首地址便是堆句柄的值，但是堆句柄的值又是0号段的首地址也是堆句柄，何解？其实很简单，0号段的HEAP_SEGMENT就在HEAP结构里面，HEAP结构类定义如这样：</p>
		<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:abcf8a25-3d48-4f22-9494-d5bf7c4da176" class="wlWriterEditableSmartContent">
				<pre name="code" class="c">struct _HEAP

{

_HEAP_ENTRY Entry ; //HEAP_ENTRY结构，用来描述存储HEAP内存块大小等信息的

_HEAP_SEGMENT Segment ;  //0号段的首地址

……  //对于该HEAP的描述信息

} ;
</pre>
		</div>
		<p>在我们看来，内存组织结构应该如下所示：</p>
		<table border="1" cellpadding="2" cellspacing="0" width="402">
				<tbody>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_ENTRY（8 bytes）</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP_SEGMENT</p>
								</td>
						</tr>
						<tr>
								<td valign="top" width="400">
										<p align="center">HEAP</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p>更确切的说，HEAP结构中本身就包含了HEAP_ENTRY和HEAP_SEGMENT，HEAP_ENTRY结构是HEAP的第一个数据成员，HEAP_SEGMENT是它第二个数据成员。而对于HEAP_SEGMENT,它的第一个数据成员便是HEAP_ENTRY。这里为了方便理解，才在内存组织结构中把它们拆开展示。（注：这里是win7的情况，和软件调试这本书中所描述的有一些差异，也属正常现象，毕竟这部分结构微软并未公开）</p>
		<h1>用WINDBG观察HEAP结构</h1>
		<p>在之前已经演示了如何从PEB结构中找到所有的堆句柄，可以看到<font color="#ff0000">002c0000</font>便是我们创建的句柄。然后我们执示例程序的第7行代码。执行完后结果如下：</p>
		<p>0:000&gt; p<br />eax=002c0000 ebx=00000000 ecx=77429897 edx=77498500 esi=00000001 edi=01033374<br />eip=01031026 esp=0022fe8c ebp=0022feac iopl=0         nv up ei pl nz na pe nc<br />cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206<br />heap!main+0x26:<br />01031026 ff1500200301    call    dword ptr [heap!_imp__HeapAlloc (01032000)] ds:0023:01032000={ntdll!RtlAllocateHeap (774120b5)}<br />0:000&gt; p<br />eax=002c0590 ebx=00000000 ecx=774134b4 edx=002c0180 esi=00000001 edi=01033374<br />eip=0103102c esp=0022fe98 ebp=0022feac iopl=0         nv up ei pl zr na pe nc<br />cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246<br />heap!main+0x2c:<br />0103102c 8945f0          mov     dword ptr [ebp-10h],eax ss:0023:0022fe9c={heap!envp (0103301c)}<br /></p>
		<p>可以看到EAX保存的返回值为002c0590。我们通过两种途径来观察我们申请的内存，通过!heap命令观察和通过dt命令观察</p>
		<h2>
		</h2>
		<h2>通过!heap命令观察</h2>
		<h2>
		</h2>
		<h1>
		</h1>
		<h1>
		</h1>
		<p>输入命令!heap –a 2c0590得到的结果如下：</p>
		<p>0:000&gt; !heap -a 2c0000<br /><font style="background-color: #9bbb59" color="#000000">Index   Address  Name      Debugging options enabled<br />  5:   002c0000 <br />    Segment at 002c0000 to 002c2000 (00001000 bytes committed)<br />    Flags:                00001000<br />    ForceFlags:           00000000<br />    Granularity:          8 bytes<br />    Segment Reserve:      00100000<br />    Segment Commit:       00002000<br />    DeCommit Block Thres: 00000200<br />    DeCommit Total Thres: 00002000<br />    Total Free Size:      0000013a<br />    Max. Allocation Size: 7ffdefff<br />    Lock Variable at:     002c0138<br />    Next TagIndex:        0000<br />    Maximum TagIndex:     0000<br />    Tag Entries:          00000000<br />    PsuedoTag Entries:    00000000<br />    Virtual Alloc List:   002c00a0<br />    Uncommitted ranges:   002c0090<br />            002c1000: 00001000  (4096 bytes)<br />    FreeList[ 00 ] at 002c00c4: 002c0618 . 002c0618  <br />        002c0610: 00088 . 009d0 [100] - free</font></p>
		<p>
				<font style="background-color: #c0504d">    Segment00 at 002c0000:<br />        Flags:           00000000<br />        Base:            002c0000<br />        First Entry:     002c0588<br />        Last Entry:      002c2000<br />        Total Pages:     00000002<br />        Total UnCommit:  00000001<br />        Largest UnCommit:00000000<br />        UnCommitted Ranges: (1)</font>
		</p>
		<p>
				<font style="background-color: #cccccc">    Heap entries for Segment00 in Heap 002c0000<br />        002c0000: 00000 . 00588 [101] - busy (587)<br />        <font color="#ff0000">002c0588: 00588 . 00088 [101] - busy (80)</font><br />        002c0610: 00088 . 009d0 [100]<br />        002c0fe0: 009d0 . 00020 [111] - busy (1d)<br />        002c1000:      00001000      - uncommitted bytes.</font>
		</p>
		<p>这个命令分别提炼出了HEAP（绿色区域）,HEAP_SEGMENT（红色区域）和HEAP_ENTRY（灰色区域）结构中的信息。虽然在灰色区域中，我们找不到2c0590，但是找到了一个2c0588，这个正是2c0590-8的结果，也就是说最右边的地址是每个HEAP_ENTRY的首地址，接着00588这个字段表示了前面一个HEAP_ENTRY所占用的大小，后面的0088表示这个内存块的总大小，即我们申请的内存+HEAP_ENTRY（128+8=0x80+0x8=0x88），[101]是这块内存的标志位，最右边一位为1表示该内存块被占用。然后busy（80）就是解释说这块内存是被占用的（非空闲的），它申请的内存为0x80，转化成十进制正好就是我们申请的128字节大小。</p>
		<p>
				<font color="#ff0000">但是这里用dt _HEAP_ENTRY 2c0588命令却没办法查看对应的结构信息，真是怪哉，有篇博文也提到win2008中HEAP相关结构也有变，看来到NT6后，HEAP结构变得不小，起码windbg中直接dt HEAP_ENTRY是无法原始数据的了，貌似对HEAP_ENTRY做了编码。</font>
				<br />
		</p>
		<h2>通过dt命令观察</h2>
		<p>同样的，已知HEAP的首地址，那么先从HEAP下手好了，dt _HEAP 002c0000可以显示HEAP的数据结构</p>
		<p>ntdll!_HEAP<br />   +0x000 Entry            : _HEAP_ENTRY<br /><font style="background-color: #cccccc">   +0x008 SegmentSignature : 0xffeeffee   <br />   +0x00c SegmentFlags     : 0<br />   +0x010 SegmentListEntry : _LIST_ENTRY [ 0x2c00a8 - 0x2c00a8 ]<br />   +0x018 Heap             : 0x002c0000 _HEAP<br />   +0x01c BaseAddress      : 0x002c0000 Void<br />   +0x020 NumberOfPages    : 2<br />   <font color="#ff0000">+0x024 FirstEntry       : 0x002c0588 _HEAP_ENTRY</font><br />   +0x028 LastValidEntry   : 0x002c2000 _HEAP_ENTRY<br />   +0x02c NumberOfUnCommittedPages : 1<br />   +0x030 NumberOfUnCommittedRanges : 1<br />   +0x034 SegmentAllocatorBackTraceIndex : 0<br />   +0x036 Reserved         : 0<br />   +0x038 UCRSegmentList   : _LIST_ENTRY [ 0x2c0ff0 - 0x2c0ff0 ]</font><br />   +0x040 Flags            : 0x1000<br />   +0x044 ForceFlags       : 0<br />   +0x048 CompatibilityFlags : 0<br />   +0x04c EncodeFlagMask   : 0x100000<br />   +0x050 Encoding         : _HEAP_ENTRY<br />   +0x058 PointerKey       : 0x17c06e63<br />   +0x05c Interceptor      : 0<br />   +0x060 VirtualMemoryThreshold : 0xfe00<br />   +0x064 Signature        : 0xeeffeeff<br />   +0x068 SegmentReserve   : 0x100000<br />   +0x06c SegmentCommit    : 0x2000<br />   +0x070 DeCommitFreeBlockThreshold : 0x200<br />   +0x074 DeCommitTotalFreeThreshold : 0x2000<br />   +0x078 TotalFreeSize    : 0x13a<br />   +0x07c MaximumAllocationSize : 0x7ffdefff<br />   +0x080 ProcessHeapsListIndex : 5<br />   +0x082 HeaderValidateLength : 0x138<br />   +0x084 HeaderValidateCopy : (null) <br />   +0x088 NextAvailableTagIndex : 0<br />   +0x08a MaximumTagIndex  : 0<br />   +0x08c TagEntries       : (null) <br />   +0x090 UCRList          : _LIST_ENTRY [ 0x2c0fe8 - 0x2c0fe8 ]<br />   +0x098 AlignRound       : 0xf<br />   +0x09c AlignMask        : 0xfffffff8<br />   +0x0a0 VirtualAllocdBlocks : _LIST_ENTRY [ 0x2c00a0 - 0x2c00a0 ]<br />   +0x0a8 SegmentList      : _LIST_ENTRY [ 0x2c0010 - 0x2c0010 ]<br />   +0x0b0 AllocatorBackTraceIndex : 0<br />   +0x0b4 NonDedicatedListLength : 0<br />   +0x0b8 BlocksIndex      : 0x002c0150 Void<br />   +0x0bc UCRIndex         : (null) <br />   +0x0c0 PseudoTagEntries : (null) <br />   +0x0c4 FreeLists        : _LIST_ENTRY [ 0x2c0618 - 0x2c0618 ]<br />   +0x0cc LockVariable     : 0x002c0138 _HEAP_LOCK<br />   +0x0d0 CommitRoutine    : 0x17c06e63     long  +17c06e63<br />   +0x0d4 FrontEndHeap     : (null) <br />   +0x0d8 FrontHeapLockCount : 0<br />   +0x0da FrontEndHeapType : 0 ''<br />   +0x0dc Counters         : _HEAP_COUNTERS<br />   +0x130 TuningParameters : _HEAP_TUNING_PARAMETERS<br />就如本文前面所述的，第一个字段是HEAP_ENTRY结构，接着应该是HEAP_SEGMENT，这里只不过把HEAP_SEGMENT结构的字段展开了，可以dt _HEAP_SEGMENT来观察下这个结构的字段</p>
		<p>0:000&gt; dt _heap_segment<br />ntdll!_HEAP_SEGMENT<br />   +0x000 Entry            : _HEAP_ENTRY<br />   +0x008 SegmentSignature : Uint4B<br />   +0x00c SegmentFlags     : Uint4B<br />   +0x010 SegmentListEntry : _LIST_ENTRY<br />   +0x018 Heap             : Ptr32 _HEAP<br />   +0x01c BaseAddress      : Ptr32 Void<br />   +0x020 NumberOfPages    : Uint4B<br />   +0x024 FirstEntry       : Ptr32 _HEAP_ENTRY<br />   +0x028 LastValidEntry   : Ptr32 _HEAP_ENTRY<br />   +0x02c NumberOfUnCommittedPages : Uint4B<br />   +0x030 NumberOfUnCommittedRanges : Uint4B<br />   +0x034 SegmentAllocatorBackTraceIndex : Uint2B<br />   +0x036 Reserved         : Uint2B<br />   +0x038 UCRSegmentList   : _LIST_ENTRY</p>
		<p>可以看到HEAP结构中灰色部分是和HEAP_SEGMENT结构中的字段是重复的，也就是说灰色部分字段便是HEAP_SEGMENT结构。在HEAP_SEGMENT结构中，我们可以找到FirstEntry字段，这里指的便是我们的分配的内存，不过HEAP_ENTRY结构无法观察，这里便没办法枚举出所有的HEAP_ENTRY结构了，但是说一下思路：</p>
		<p>每个HEAP_ENTRY和它对应的内存我们可以称为一个内存块，计算下一个内存块需要用到现有内存块中的2个字段，Size和UnsedBytes，Size的值乘上粒度（就是0:000&gt; !heap -a 2c0000命令显示的信息中的Granularity: 8 bytes字段，这里是8字节），下一个内存块地址就是 <font style="background-color: #cccccc">本内存块地址+Size*8+UnsedBytes</font>。当然这里的粒度可以通过HEAP字段中的AlignMask 字段算出来。</p>
		<h1>
		</h1>
		<h1>HEAP的分配粒度</h1>
		<p>在HEAP结构中指明了分配粒度，这个分配粒度是说每次堆分配的时候，都以这个粒度为最小单位，这里看到粒度为8字节。所以这里就有了第二次分配内存的实验，我们让程序执行第9行，然后用!heap -a 002c0000观察分配情况</p>
		<p>Heap entries for Segment00 in Heap 002c0000<br />    002c0000: 00000 . 00588 [101] - busy (587)<br />    002c0588: 00588 . 00088 [101] - busy (80)<br />    <font color="#ff0000">002c0610: 00088 . 00088 [101] - busy (79)</font><br />    002c0698: 00088 . 00948 [100]<br />    002c0fe0: 00948 . 00020 [111] - busy (1d)<br />    002c1000:      00001000      - uncommitted bytes.</p>
		<p>
				<font color="#ff0000">这里可以看出多出了一个占用块，大小是0x79（121） bytes，但是实际分配的大小还是0x 88 （128）bytes，这是因为系统是以8 bytes为粒度分配的，所以为这块121 bytes的内存自动填充了7个字节，可见申请121 bytes和申请128 bytes所使用的空间是一样的。</font>
		</p>
		<h1>HEAP的释放和销毁</h1>
		<p>执行了11行和12行的代码后，堆中的内容分别如下：</p>
		<p>
				<strong>执行11行代码的堆情况</strong>
		</p>
		<p>FreeList[ 00 ] at 002c00c4: 002c06a0 . 002c0590  <br />    002c0588: 00588 . 00088 [100] – free   <font color="#ff0000">；空闲列表中多出了一块内存</font><br />    002c0698: 00088 . 00948 [100] – free   <font color="#ff0000">；空闲内存，空闲空间为948</font></p>Heap entries for Segment00 in Heap 002c0000<br />002c0000: 00000 . 00588 [101] - busy (587)<br />002c0588: 00588 . 00088 [100]   <font color="#ff0000">；原先的这块内存释放掉了</font><br />002c0610: 00088 . 00088 [101] - busy (79)<br />002c0698: 00088 . 00948 [100]    <font color="#ff0000">; 空闲内存</font><br />002c0fe0: 00948 . 00020 [111] - busy (1d)<br />002c1000: 00001000 - uncommitted bytes. 
<p><strong>执行12行代码的堆情况</strong></p><p>FreeList[ 00 ] at 005c00c4: 005c0590 . 005c0590  <br />    005c0588: 00588 . 00a58 [100] – free <font color="#ff0000">；回收了buffer1的内存后，由于由于空闲内存是连续的，所以直接合并成一块内存。可以看到之前内存free空间是948，现在合并了以后便是948+88+88=a58,也就是当前内存大小</font></p><p>Heap entries for Segment00 in Heap 005c0000<br />    005c0000: 00000 . 00588 [101] - busy (587)<br />    005c0588: 00588 . 00a58 [100]<br />    005c0fe0: 00a58 . 00020 [111] - busy (1d)<br />    005c1000:      00001000      - uncommitted bytes.<br /></p><p>最后执行14行代码,对堆进行释放,释放后我们通过!heap也可以看到只有4个堆了,我们申请的堆被释放了.</p>0:000&gt; !heap <br />Index Address Name Debugging options enabled<br />1: 00300000 <br />2: 00010000 <br />3: 00020000 <br />4: 002e0000 <br /><p> </p><p>至于HEAP_ENTRY结构的问题,有时间在调试看看是怎么回事吧~另外，这里说明下，new和malloc内部都会调用HeapAlloc来申请内存，但是堆句柄从哪来呢？它会检测_crtheap变量是否为空，若不为空则拿_crtheap变量来作为自己的堆句柄去调用HeapAlloc</p><p>参考：</p><p>软件调试    张奎银</p><p>MSDN    </p><p><a href="http://doxygen.reactos.org/" target="_blank">React OS</a></p><img src ="http://www.cppblog.com/ay19880703/aggbug/159364.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2011-10-30 19:05 <a href="http://www.cppblog.com/ay19880703/archive/2011/10/30/159364.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>内核下进行浮点运算</title><link>http://www.cppblog.com/ay19880703/archive/2009/06/06/86940.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sat, 06 Jun 2009 12:19:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/06/06/86940.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/86940.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/06/06/86940.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/86940.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/86940.html</trackback:ping><description><![CDATA[
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">    KFLOATING_SAVE saveData ;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    NTSTATUS status;<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">double</span><span style="color: rgb(0, 0, 0);"> tem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> , sum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">  ;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(128, 128, 128);">/////////</span><span style="color: rgb(0, 128, 0);">/开启浮点运算环境</span><span style="color: rgb(128, 128, 128);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(128, 128, 128);"></span><span style="color: rgb(0, 0, 0);">    status </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> KeSaveFloatingPointState(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">saveData);<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( </span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);"> NT_SUCCESS(status))<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">浮点运算操作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(128, 128, 128);">/////////</span><span style="color: rgb(0, 128, 0);">/关闭浮点运算环境</span><span style="color: rgb(128, 128, 128);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(128, 128, 128);"></span><span style="color: rgb(0, 0, 0);">    KeRestoreFloatingPointState(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">saveData);</span></div>
		<br />
		<br />内核下进行浮点运算很特殊~~<br />正确操作应该向上面代码一样<br /><br />在贴个抄来的内核sleep()函数<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> KeSleep(ULONG uMiniseconds)<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">    KTIMER ktimer;<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">    LARGE_INTEGER liTimerout;<br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">    liTimerout.QuadPart</span><span style="color: rgb(0, 0, 0);">=-</span><span style="color: rgb(0, 0, 0);">(LONG)(uMiniseconds</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">10000</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);">    KeInitializeTimer(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ktimer);<br /></span><span style="color: rgb(0, 128, 128);">7</span> <span style="color: rgb(0, 0, 0);">    KeWaitForSingleObject(</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ktimer,Executive,KernelMode,FALSE,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">liTimerout);<br /></span><span style="color: rgb(0, 128, 128);">8</span> <span style="color: rgb(0, 0, 0);">}</span></div><br />不过效率貌似有待改进....有时间在说吧~~那个xxxdelay函数也可以的<br /><img src ="http://www.cppblog.com/ay19880703/aggbug/86940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-06-06 20:19 <a href="http://www.cppblog.com/ay19880703/archive/2009/06/06/86940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>内核部分笔记  ---  在内核下把文件的内容写入内存中  </title><link>http://www.cppblog.com/ay19880703/archive/2009/06/06/86938.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sat, 06 Jun 2009 12:12:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/06/06/86938.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/86938.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/06/06/86938.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/86938.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/86938.html</trackback:ping><description><![CDATA[
		<br />
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">    NTSTATUS Status ;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    HANDLE fhandle ;<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">    UNICODE_STRING     ConfigFileName ;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    OBJECT_ATTRIBUTES  objAttr  ;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    IO_STATUS_BLOCK    ioStatusBlock ; <br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    FILE_STANDARD_INFORMATION FileInfo ;<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">    LONG  BytesRead ;<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">    UCHAR </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">buf  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> NULL ;<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    RtlInitUnicodeString( </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ConfigFileName, FilePath ) ;  <br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    InitializeObjectAttributes(<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">objAttr,<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ConfigFileName,<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        OBJ_CASE_INSENSITIVE </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> OBJ_KERNEL_HANDLE,<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        NULL,<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">        NULL ) ;<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">    Status </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ZwCreateFile(<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">fhandle ,<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">        SYNCHRONIZE </span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);"> FILE_READ_DATA,<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">objAttr,<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ioStatusBlock,<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">        NULL,<br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        FILE_ATTRIBUTE_NORMAL,<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">,<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">        FILE_OPEN_IF,<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        FILE_SYNCHRONOUS_IO_NONALERT,<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">        NULL,<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">        ) ;<br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( </span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">NT_SUCCESS(Status) )<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">    {<br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">        DbgPrint(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Create file filed \n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) ;<br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">BufferAddress </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> NULL ;<br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">BufferSize </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);">    Status </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ZwQueryInformationFile(fhandle,<br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ioStatusBlock,<br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">FileInfo,<br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(FILE_STANDARD_INFORMATION),<br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 0, 0);">        FileStandardInformation);<br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">注意  这里只取了低32位.一般文件大不过4G </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    BytesRead </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> FileInfo.EndOfFile.LowPart ;<br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">    buf </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExAllocatePool(PagedPool  , BytesRead) ;<br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">NdisAllocateMemory(&amp;buf,BytesRead,TAG);</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 0, 0);">    ZwReadFile(<br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">        fhandle ,<br /></span><span style="color: rgb(0, 128, 128);">53</span> <span style="color: rgb(0, 0, 0);">        NULL , <br /></span><span style="color: rgb(0, 128, 128);">54</span> <span style="color: rgb(0, 0, 0);">        NULL ,<br /></span><span style="color: rgb(0, 128, 128);">55</span> <span style="color: rgb(0, 0, 0);">        NULL ,<br /></span><span style="color: rgb(0, 128, 128);">56</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">ioStatusBlock ,<br /></span><span style="color: rgb(0, 128, 128);">57</span> <span style="color: rgb(0, 0, 0);">        buf ,<br /></span><span style="color: rgb(0, 128, 128);">58</span> <span style="color: rgb(0, 0, 0);">        BytesRead , <br /></span><span style="color: rgb(0, 128, 128);">59</span> <span style="color: rgb(0, 0, 0);">        NULL ,<br /></span><span style="color: rgb(0, 128, 128);">60</span> <span style="color: rgb(0, 0, 0);">        NULL <br /></span><span style="color: rgb(0, 128, 128);">61</span> <span style="color: rgb(0, 0, 0);">        ) ;<br /></span><span style="color: rgb(0, 128, 128);">62</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">63</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">BufferAddress </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> buf ;<br /></span><span style="color: rgb(0, 128, 128);">64</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">BufferSize </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> BytesRead ;<br /></span><span style="color: rgb(0, 128, 128);">65</span> <span style="color: rgb(0, 0, 0);">    ZwClose(fhandle) ;</span></div>
		<br />
		<br />这个功能只不过是在内核下分配个内存  然后把文件内容读到内存中<br />要记得释放空间啊   我的代码中没释放分配的内存<br /><img src ="http://www.cppblog.com/ay19880703/aggbug/86938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-06-06 20:12 <a href="http://www.cppblog.com/ay19880703/archive/2009/06/06/86938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于jmp相对跳的一道程序分析</title><link>http://www.cppblog.com/ay19880703/archive/2009/02/13/73681.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Thu, 12 Feb 2009 18:11:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/02/13/73681.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/73681.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/02/13/73681.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/73681.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/73681.html</trackback:ping><description><![CDATA[
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="ProgId" content="Word.Document" />
		<meta name="Generator" content="Microsoft Word 11" />
		<meta name="Originator" content="Microsoft Word 11" />
		<link rel="File-List" href="file:///C:%5CUsers%5Cay%5CAppData%5CLocal%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
		<link rel="Edit-Time-Data" href="file:///C:%5CUsers%5Cay%5CAppData%5CLocal%5CTemp%5Cmsohtml1%5C01%5Cclip_editdata.mso" />
		<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
		<o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="chmetcnv">
		</o:smarttagtype>
		<o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName">
		</o:smarttagtype>
		<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
		<!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
		<!--[if !mso]><object
 classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]-->
		<style>
				<!--
 /* Font Definitions */
 @font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 680460288 22 0 262145 0;}
@font-face
	{font-family:微软雅黑;
	panose-1:2 11 5 3 2 2 4 2 2 4;
	mso-font-charset:134;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-2147483001 705641554 22 0 262175 0;}
@font-face
	{font-family:"\@微软雅黑";
	panose-1:2 11 5 3 2 2 4 2 2 4;
	mso-font-charset:134;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-2147483001 705641554 22 0 262175 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 680460288 22 0 262145 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-520078593 -1073717157 41 0 66047 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
		</style>
		<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">夜深人静，嘿嘿</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">只有这个时候才有时间静下来看点东西</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">前几天在看</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">16</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">位汇编语言程序设计</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<st1:personname productid="王爽" w:st="on">
						<span style="font-size: 14pt; font-family: 微软雅黑;">王爽</span>
				</st1:personname>
				<span style="font-size: 14pt; font-family: 微软雅黑;">老师写的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">写得真的很好</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">不是卖广告哈</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">资源共享嘛</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">遇到一个问题</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">通过这个问题发现能深刻理解到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令很具内涵的一些内容</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">甚欢</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">乃著此文以记之</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">程序如下：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">assume
cs:codesg<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">codesg
segment<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax,<st1:chmetcnv unitname="C" sourcevalue="4" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">4c</st1:chmetcnv>00h<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>int 21h<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">start
:<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax,0<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s:<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>nop<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>nop<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov di,offset s </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这里应该是计算</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对于</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">segment</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处的偏移量，赋值给</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">di<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov si,offset s2 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">计算</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s2</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对于</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">segment</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处的偏移，保存到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">si<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax , cs:[si]<span style="">  </span></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">将</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个字节指令内容读入</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ax</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">（注意，基址是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">cs</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">哦</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">不是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ds</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov cs:[di],ax<span style="">   </span></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">将</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ax</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">内容写到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处，也就是填充上边那</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">2</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">nop<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s0:<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>jmp short s </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">，那么这个时候位于</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处指令应该是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s1 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">；接着执行应该是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> mov ax</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">，</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">然后</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">int 21 <o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s1:<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax,0 <o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>int 21h<span style="">  
</span><o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax,0<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s2:<span style="">  </span><o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>jmp short s1<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>nop<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">codesg
ends<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">end
start<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">结果发现我推测的跟执行的内容完全不一样</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">……</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">晕厥</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ING~<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">又过了一天</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">一觉醒来想了想这个结果</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">哈哈</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">恍然大悟</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">书上的例子用的是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">windows</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">自带的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">debug</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">调试</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">……</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">我也只会用这个了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">……</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">用</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">windbg</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">太麻烦</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> od</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">好像只能开</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">32</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">位的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">只能截图看了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<!--[if gte vml 1]><v:shapetype
 id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
 path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:292.5pt;
 height:174pt'>
 <v:imagedata src="file:///C:\Users\ay\AppData\Local\Temp\msohtml1\01\clip_image001.gif"
  o:title="ab"/>
</v:shape><![endif]-->
						<!--[if !vml]-->
						<img src="http://www.cppblog.com/images/cppblog_com/ay19880703/ab.bmp" alt="ab.bmp" width="390" border="0" height="232" />
						<br />
						<!--[endif]-->
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令在被编译器编译的时候会自动计算跳转时指针与目的地址的偏移量</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">然后通过加减</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ip</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个数值实现跳转的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是说</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这指令实现的是相对位移跳转，跳到哪那是编译器编译的时候就计算好的了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">我们来看看</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0016</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个地方的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> EBF0 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个指令对应的汇编语句应该是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s <o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">S</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">是在</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0008</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">所以反编译的结果是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> jmp 0008<span style="">  </span></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">没错</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">跟我们的语句没出入</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">那么我们可以看看机器码</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
BEF0<span style="">  </span>BE</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> F0</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">代表相对位移</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">以补码形式保存</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">那么我们计算下发现</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">F0</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对应的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">进制是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">-16 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是说要往后跳</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">16</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个字节（注意是字节，</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">8bit</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">一个字节哦</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0016</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个是我们执行到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">时</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">cs</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ip</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">的地址，也就是取指令的地址</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
						<span lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">注意这个时候我们已经取出</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个指令了</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">那么</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">IP</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指针应该</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">+2</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指向</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0018</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个位置了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">往后跳</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">16</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个字节</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> 1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0018 – 10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">（</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">进制就是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">16</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">咯）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> = 1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0008<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">应该是跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0008</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个位置上了</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">正好就是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对应的位置</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">那么我们看看</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0020</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个指令</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> EBF<st1:chmetcnv unitname="F" sourcevalue="6" hasspace="True" negative="False" numbertype="1" tcsc="0" w:st="on">6<span style="">  </span>F</st1:chmetcnv>6</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">是跳转的相对位移</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">补码形式存放</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">换算成</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">进制就是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">-10<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">想象下当程序执行到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s0</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">那个时候</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处的那</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">2</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">nop</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令已经被填充成</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">EBF6</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">根据相对位移的计算</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style=""> </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个时候程序运行的步骤应该是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">通过</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">跳转到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0008</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">地址（这个时候下一个指令对应的机器码是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">BEF0</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">取出下一个指令</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> IP+2<span style="">  </span></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个时候</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">IP</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指向</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<st1:chmetcnv unitname="a" sourcevalue="0" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">
						<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">000a</span>
				</st1:chmetcnv>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">执行</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">BEF6</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个指令（向后跳</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">个字节）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是应该跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<st1:chmetcnv unitname="a" sourcevalue="0" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">
						<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">000a</span>
				</st1:chmetcnv>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> – a</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">（</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">10</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">16</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">进制表示）</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> = 1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0000<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是说这个时候</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令应该是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> jmp 0000 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">segment</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">开始处而不是跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s1</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">接着应该是执行</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>mov ax,<st1:chmetcnv unitname="C" sourcevalue="4" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">4c</st1:chmetcnv>00h<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">   </span>int 21h<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">实际调试的结果也是这样的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">如下图示</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 33.9pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<!--[if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style='width:495pt;
 height:245.25pt'>
 <v:imagedata src="file:///C:\Users\ay\AppData\Local\Temp\msohtml1\01\clip_image002.png"
  o:title="sa"/>
</v:shape><![endif]-->
						<!--[if !vml]-->
						<img src="http://www.cppblog.com/images/cppblog_com/ay19880703/sa.bmp" alt="sa.bmp" width="660" border="0" height="327" />
						<br />
						<!--[endif]-->
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">看到没</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">执行</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp 0008 </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp s</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">以后然后就是跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1814</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">：</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">0000</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">处</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">而不是跳到</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">s1</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对应的那个偏移处</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">接着就是跟我们想的一样</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">执行了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> mov ax</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">，</span>
				<st1:chmetcnv unitname="C" sourcevalue="4" hasspace="False" negative="False" numbertype="1" tcsc="0" w:st="on">
						<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">4c</span>
				</st1:chmetcnv>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">00h </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">然后就</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">int 21h</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<img src="http://www.cppblog.com/images/cppblog_com/ay19880703/aabb.bmp" alt="aabb.bmp" width="647" border="0" height="330" />
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是说我们</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">的地址记录的是相对偏移量</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这个程序也说明了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">的地址是在运行时计算出来的而不是编译器一开始就硬编码进去的</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">不过当然也有硬编码进去的跳转指令啦</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~~</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">好像是</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp
far </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">地址吧</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">忘了的说</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">只不过小小阐明下</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">jmp</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">相对跳的执行流程和细节部分</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">这样也有个小小启示就是以后用相对跳的时候小心咯</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">貌似</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">shellcode</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">编写或者改内核代码的时候可以注意下</span>
				<span style="font-size: 14pt; font-family: Tahoma;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">跳转的相对地址最好计算出来表直接就来个偏移</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">一不小心机子就当掉了</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<span style="">  </span>
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">哇咔咔</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~<o:p></o:p></span>
		</p>
		<p class="MsoNormal" style="text-indent: 27pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
<img src ="http://www.cppblog.com/ay19880703/aggbug/73681.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-02-13 02:11 <a href="http://www.cppblog.com/ay19880703/archive/2009/02/13/73681.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windbg学习笔记 FOR 内核调试(四) -- PspTerminateThreadByPointer</title><link>http://www.cppblog.com/ay19880703/archive/2009/02/03/72907.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Tue, 03 Feb 2009 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/02/03/72907.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72907.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/02/03/72907.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72907.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72907.html</trackback:ping><description><![CDATA[
		<font size="2" face="Tahoma">      近日事情颇多 喝茶拉 吃好吃的还有看电影啊~磨去不少时间,甚欢.难得放假回家 一直被拉出去也没看什么东西 前段时间刚跟鼠仙讨论了下 我跑去看了下进程保护的一些东东,但是肤浅的很 就研究了下WRK的一些代码 发现关闭进程都跟这个PspTerminateThreadByPointer函数有关,NtProcess的代码很简单,就是得到进程的EPROCESS 然后遍历它的线程链表 接着就一个个用</font>
		<font size="2" face="Tahoma">PspTerminateThreadByPointer</font>
		<font size="2" face="Tahoma">
		</font>
		<font size="2" face="Tahoma">函数挂掉就OK  也就是说想要保护进程 挂钩个</font>
		<font size="2" face="Tahoma">PspTerminateThreadByPointer</font>
		<font size="2" face="Tahoma">
		</font>
		<font size="2" face="Tahoma">效果还是很理想的    反正拿这个去实现R3下进程保护应该绰绰有余了<br />为了练习下windbg的使用 准备随便跟下我们的</font>
		<font size="2" face="Tahoma">
		</font>
		<font size="2" face="Tahoma">PspTerminateThreadByPointer</font>
		<font size="2" face="Tahoma">
		</font>
		<font size="2" face="Tahoma">函数 </font>
		<font size="2" face="Tahoma">冰刃刚下速度太慢了 我就用任务管理器试验的 呵呵 <br /><br />首先开虚拟机,然后一阵啰嗦的操作后进入正题<br /><br />先给我们的函数下个断<br />kd&gt; bp nt!PspTerminateThreadByPointer<br /><br />我们bl看看<br />kd&gt; bl<br /> 0 e 805c9b8e     0001 (0001) nt!PspTerminateThreadByPointer<br /><br />OK 成功了 然后打开任务管理器 在随便打开个程序  INSTDRV.exe  (平时加载驱动用的,呵呵)<br /><br />然后拿任务管理器做掉这个进程 HOHO~~<br /><br />Breakpoint 0 hit<br />nt!PspTerminateThreadByPointer:<br />805c9b8e 8bff            mov     edi,edi<br /><br />断下来了  汇编显示的是这个函数的第一条语句 不过这个命令无任何意义<br /><br />拿k指令看看函数堆栈<br /><br />kd&gt; k<br />ChildEBP RetAddr  <br />f7932d28 805c9d8b nt!PspTerminateThreadByPointer<br />f7932d54 8053e648 nt!NtTerminateProcess+0xd5<br />f7932d54 7c92e4f4 nt!KiFastCallEntry+0xf8<br />0007f73c 7c92de5c ntdll!KiFastSystemCallRet<br />0007f740 7c801e3a ntdll!ZwTerminateProcess+0xc<br /><br />喃~函数堆栈是个好东西  呵呵  那么我们结束进程的过程就清楚了 由于后面的函数堆栈没法显示 不知道为什么 反正差不多的调用流程就是这样<br /></font>
		<font size="2" face="Tahoma">ZwTerminateProcess-</font>
		<font size="2" face="Tahoma">
		</font>
		<font size="2" face="Tahoma">NtTerminateProcess</font>
		<font size="2" face="Tahoma">-</font>
		<font size="2" face="Tahoma">PspTerminateThreadByPointer 中间那2个函数干嘛用的我就不太清楚了   反了下</font>
		<font size="2" face="Tahoma"> ZwTerminateProcess</font>
		<font size="2" face="Tahoma">
				<br />kd&gt; uf nt!zwterminateprocess<br />nt!ZwTerminateProcess:<br />805001bc b801010000      mov     eax,101h<br />805001c1 8d542404        lea     edx,[esp+4]<br />805001c5 9c              pushfd<br />805001c6 6a08            push    8<br />805001c8 e8c4e20300      call    nt!KiSystemService (8053e491)<br />805001cd c20800          ret     8</font>
		<font size="2" face="Tahoma">
				<br />
				<br />
		</font>
		<font size="2" face="Tahoma">nt!KiSystemService这个函数好像是跟SSDT有关 估计就是跑去找NtProcess的地址的吧 那么中间那2个函数可以自己意淫一下应该就是</font>
		<font size="2" face="Tahoma">进行用户态和内核态之间的切换了~ <br /></font>
		<font size="2" face="Tahoma">不知道是不是这样的  希望哪位大牛可以解答下小弟的推测正确与否~</font>
		<font size="2" face="Tahoma"> 在此谢过~!<br /><br />然后单步调试开始了 嘿嘿 为了方便看 我重新断了次(之前拿r指令开了显示寄存器信息开关了 呵呵)<br />Breakpoint 0 hit<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b8e esp=f7932d2c ebp=f7932d54 iopl=0         nv up ei ng nz na pe cy<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000287<br />nt!PspTerminateThreadByPointer:<br />805c9b8e 8bff            mov     edi,edi<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b90 esp=f7932d2c ebp=f7932d54 iopl=0         nv up ei ng nz na pe cy<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000287<br />nt!PspTerminateThreadByPointer+0x2:<br />805c9b90 55              push    ebp<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b91 esp=f7932d28 ebp=f7932d54 iopl=0         nv up ei ng nz na pe cy<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000287<br />nt!PspTerminateThreadByPointer+0x3:<br />805c9b91 8bec            mov     ebp,esp<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b93 esp=f7932d28 ebp=f7932d28 iopl=0         nv up ei ng nz na pe cy<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000287<br />nt!PspTerminateThreadByPointer+0x5:<br />805c9b93 83ec0c          sub     esp,0Ch ; 貌似是切换栈了~<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b96 esp=f7932d1c ebp=f7932d28 iopl=0         nv up ei ng nz ac po nc<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000292<br />nt!PspTerminateThreadByPointer+0x8:<br />805c9b96 834df8ff        or      dword ptr [ebp-8],0FFFFFFFFh ss:0010:f7932d20=00000008<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b9a esp=f7932d1c ebp=f7932d28 iopl=0         nv up ei ng nz na pe nc<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000286<br />nt!PspTerminateThreadByPointer+0xc:<br />805c9b9a 56              push    esi <br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b9b esp=f7932d18 ebp=f7932d28 iopl=0         nv up ei ng nz na pe nc<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000286<br />nt!PspTerminateThreadByPointer+0xd:<br />805c9b9b 57              push    edi ; 注意这里 原来的esi在ebp+8处<br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=8130dda8<br />eip=805c9b9c esp=f7932d14 ebp=f7932d28 iopl=0         nv up ei ng nz na pe nc<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000286<br />nt!PspTerminateThreadByPointer+0xe:<br />805c9b9c 8b7d08          mov     edi,dword ptr [ebp+8] ss:0010:f7932d30=81308da8<br />;喃~他把原来esi的值传给edi了 <br />kd&gt; t<br />eax=81308da8 ebx=81299020 ecx=00000000 edx=00000000 esi=81308da8 edi=81308da8<br />eip=805c9b9f esp=f7932d14 ebp=f7932d28 iopl=0         nv up ei ng nz na pe nc<br />cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000286<br />nt!PspTerminateThreadByPointer+0x11:<br />805c9b9f 8db748020000    lea     esi,[edi+248h] <br />;wrk上有条语句如下<br /> if (Thread-&gt;CrossThreadFlags<br />    &amp; PS_CROSS_THREAD_FLAGS_BREAK_ON_TERMINATION) <br />然后根据这个 lea     esi,[edi+248h] 命令看来 貌似edi指向的是个ETHREAD结构 应为<br />ETHREAD偏移248处就是这个CrossThreadFlags成员变量<br />kd&gt; dt _ethread<br />ntdll!_ETHREAD<br />   +0x000 Tcb              : _KTHREAD<br />   [...]<br />   +0x248 CrossThreadFlags : Uint4B<br />   [...]<br />那么就是说edi存放的是ethread的地址,上个命令<br />mov     edi,dword ptr [ebp+8]就是把原esi的值传给edi的 <br />可见第一个参数是保存在esi中的   那我们来看看这个ethread的结构<br />现在edi中存放的是ethread的地址<br />kd&gt; r esi<br />esi=81308da8<br /><br />然后<br />kd&gt; dt _ethread 81308da8<br />ntdll!_ETHREAD<br />   +0x000 Tcb              : _KTHREAD<br />   [...]<br />   +0x1d0 ExitStatus       : 0<br />   [...]<br />   +0x220 ThreadsProcess   : 0x81299020 _EPROCESS<br />   [...]<br />找到  ThreadsProcess  它的值是 0x81299020 这个就是线程对应的进程结构地址<br />kd&gt; dt _eprocess 0x81299020<br />ntdll!_EPROCESS<br />   +0x000 Pcb              : _KPROCESS<br />   [...]<br />   +0x174 ImageFileName    : [16]  "INSTDRV.EXE"<br />   [...]<br />看~"INSTDRV.EXE"是我们要结束的那个进程吧~呵呵<br />PspTerminateThreadByPointer的函数原型是这样的<br />NTSTATUS<br />PspTerminateThreadByPointer(<br />    IN PETHREAD Thread,<br />    IN NTSTATUS ExitStatus,<br />    IN BOOLEAN DirectTerminate<br />    )<br />第一个参数就是要做掉的线程结构 要结束进程得把这个进程下所有线程挂掉 刚我们断下PspTerminateThreadByPointer 拿第一个指向的结构一路跟踪过来就找到了这个"INSTDRV.EXE" eprocess <br />神奇吧~HOHO~<br /><br />到这里我一度很是奇怪,咋个参数传递不都是通过栈传递的吗  <br />我发现PspTerminateThreadByPointer的函数调用好像是第一个参数在esi里面<br />第二个参数不知道是不是在edi里面 那么~~第三个参数在哪....<br /><br />我好像之前有略过一篇文章说到这个windows堆栈传递忘了是那篇文章了...<br /><br />一会要去T球了 暂时打住...<br />汇编好多指令不懂...先去修炼内功先...再好好研究这个函数吧 呵呵<br />                                                                                                                                                 __ay.字<br /><br /><br /></font>
		<font size="2" face="Tahoma">
				<br />
				<br />
		</font>
<img src ="http://www.cppblog.com/ay19880703/aggbug/72907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-02-03 15:16 <a href="http://www.cppblog.com/ay19880703/archive/2009/02/03/72907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>修改setenv.bat,省的每次编译驱动的时候老要打文件夹名,在build</title><link>http://www.cppblog.com/ay19880703/archive/2009/02/01/72768.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sun, 01 Feb 2009 10:24:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/02/01/72768.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72768.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/02/01/72768.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72768.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72768.html</trackback:ping><description><![CDATA[之前早想改了  没时间闲下来看  其实很是简单  <br />做个备忘省的以后重装了我好改回来<br /><br />先是去那个什么Windows XP x86 Checked Build Environment快捷方式那看了下发现它的启动参数如下<br />/k D:\WinDDK\6001.18002\bin\setenv.bat D:\WinDDK\6001.18002\ chk x86 WXP<br /><br />看到setenv.bat了吧 其实都是这个东西在处理编译<br />略看了下执行流程 然后把这个文件的倒数几行处加点批处理语句就达到目的了 呵呵<br /><br />[...]<br />:end<br />set _FreeBuild=<br />REM set _AMD64bit=<br />set _IA64bit=<br />set _HalBuild=<br />set _ddkspec=<br />set _title=<br />set _BscMake=<br />set _VersionedHeaders=<br />set _LatestOsTarget=<br /><font color="#ff0000">cd 你要的目录<br />build</font><br />exit /b 0<br /><br /><br />这样你直接点那个快捷方式就可以直接进你的编译目录下了<br />省去了每次编译要进目录 还有输入build这些麻烦的动作 <br />舒服了不少<br /><img src ="http://www.cppblog.com/ay19880703/aggbug/72768.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-02-01 18:24 <a href="http://www.cppblog.com/ay19880703/archive/2009/02/01/72768.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>老把寄存器弄混~~特此记下这些  From 百度百科</title><link>http://www.cppblog.com/ay19880703/archive/2009/02/01/72765.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sun, 01 Feb 2009 08:39:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/02/01/72765.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72765.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/02/01/72765.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72765.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72765.html</trackback:ping><description><![CDATA[　　80386的寄存器资料  省的我看汇编的时候都不知道寄存器咋个用~<br />
　　寄存器都是32-bits宽。<br />
　　<b>A、通用寄存器 </b><br />
　　下面介绍通用寄存器及其习惯用法。顾名思义，通用寄存器是那些你可以根据自己的意愿使用的寄存器，修改他们的值通常不会对计算机的运行造成很大的影响。通用寄存器最多的用途是计算。 <br />
　　EAX<b>(accumulator)</b>：通用寄存器。相对其他寄存器，在进行运算方面比较常用。在保护模式中，也可以作为内存偏移指针（此时，DS作为段 寄存器或选择器） <br />
　　EBX<b>(base)</b>：通用寄存器。通常作为内存偏移指针使用（相对于EAX、ECX、EDX），DS是默认的段寄存器或选择器。在保护模式中，同样可以起这个作用。 <br />
　　ECX<b>(count)</b>：通用寄存器。通常用于特定指令的计数。在保护模式中，也可以作为内存偏移指针（此时，DS作为 寄存器或段选择器）。<br />
　　EDX<b>(data)</b>：通用寄存器。在某些运算中作为EAX的溢出寄存器（例如乘、除）。在保护模式中，也可以作为内存偏移指针（此时，DS作为段 寄存器或选择器）。 <br />
　　同AX分为AH&amp;AL一样，上述寄存器包括对应的16-bit分组和8-bit分组。 <br />
　　<b>B、用作内存指针的特殊寄存器</b><br />
　　ESI<b>（Source Index）</b>：通常在内存操作指令中作为“源地址指针”使用。当然，ESI可以被装入任意的数值，但通常没有人把它当作通用寄存器来用。DS是默认段寄存器或选择器。 <br />
　　EDI<b>（Destination Index）</b><b></b>：通常在内存操作指令中作为“目的地址指针”使用。当然，EDI也可以被装入任意的数值，但通常没有人把它当作通用寄存器来用。DS是默认段寄存器或选择器。 <br />
　　EBP<b>（Base Pointer）</b>：这也是一个作为指针的寄存器。通常，它被高级语言编译器用以建造‘堆栈帧'来保存函数或过程的局部变量，不过，还是那句话，你可以在其中保存你希望的任何数据。SS是它的默认段寄存器或选择器。 <br />
　　注意，这三个寄存器没有对应的8-bit分组。换言之，你可以通过SI、DI、BP作为别名访问他们的低16位，却没有办法直接访问他们的低8位。 <br />
　　C、段选择器：<br />
　　实模式下的段寄存器到保护模式下摇身一变就成了选择器。不同的是，实模式下的“段寄存器”是16-bit的，而保护模式下的选择器是32-bit的。 <br />
　　CS<b>（Code Segment）</b> 代码段，或代码选择器。同IP寄存器(稍后介绍)一同指向当前正在执行的那个地址。处理器执行时从这个寄存器指向的段（实模式）或内存（保护模式）中获取指令。除了跳转或其他分支指令之外，你无法修改这个寄存器的内容。 <br />
　　DS<b>（Data Segment）</b> 数据段，或数据选择器。这个寄存器的低16
bit连同ESI一同指向的指令将要处理的内存。同时，所有的内存操作指令
默认情况下都用它指定操作段(实模式)或内存(作为选择器，在保护模式。这个寄存器可以被装入任意数值，然而在这么做的时候需要小心一些。方法是，首先把
数据送给AX，然后再把它从AX传送给DS(当然，也可以通过堆栈来做). <br />
　　ES<b>（Extra Segment）</b> 附加段，或附加选择器。这个寄存器的低16 bit连同EDI一同指向的指令将要处理的内存。同样的，这个寄存器可以被装入任意数值，方法和DS类似。 <br />
　　FS F段或F选择器(推测F可能是Free?)。可以用这个寄存器作为默认段寄存器或选择器的一个替代品。它可以被装入任何数值，方法和DS类似。 <br />
　　GS G段或G选择器(G的意义和F一样，没有在Intel的文档中解释)。它和FS几乎完全一样。 <br />
　　SS<b>（Stack Segment）</b> 堆栈段或堆栈选择器。这个寄存器的低16
bit连同ESP一同指向下一次堆栈操作(push和pop)所要使用的堆栈地址。这个寄存器也可以被装入任意数值，你可以通过入栈和出栈操作来给他赋
值，不过由于堆栈对于很多操作有很重要的意义，因此，不正确的修改有可能造成对堆栈的破坏。 <br />
　　* 注意 一定不要在初学汇编的阶段把这些寄存器弄混。他们非常重要，而一旦你掌握了他们，你就可以对他们做任意的操作了。段寄存器，或选择器，在没有指定的情况下都是使用默认的那个。这句话在现在看来可能有点稀里糊涂，不过你很快就会在后面知道如何去做。 <br />
　　指令指针寄存器：<br />
　　EIP<b>(Instruction Pointer)</b> 这个寄存器非常的重要。这是一个32位宽的寄存器 ，同CS一同指向即将执行的那条指令的地址。不能够直接修改这个寄存器的值，修改它的唯一方法是跳转或分支指令。(CS是默认的段或选择器) <br /><br />
　　<img src ="http://www.cppblog.com/ay19880703/aggbug/72765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-02-01 16:39 <a href="http://www.cppblog.com/ay19880703/archive/2009/02/01/72765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟群内某大牛聊天笔记...... FOR PspCidTable</title><link>http://www.cppblog.com/ay19880703/archive/2009/01/26/72607.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Mon, 26 Jan 2009 13:04:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/01/26/72607.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72607.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/01/26/72607.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72607.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72607.html</trackback:ping><description><![CDATA[仅自己做备忘...<br /><br /><br />问题1.pspcidtable不是全局变量吗?咋个不能声明直接用?<br />结论:<br />因为它没有导出...  其实那个SSDT的结构能用是因为它导出了的...<br /><br />问题2.(在windbg调试第三篇的补充内容那.....)<br /><br />问题3.咋个,以及为什么那个HANDLE的值,TableCode的指针和对象体的指针低2位都要是0?<br />结论:<br />为了内存对齐~ 这样,内存以4字节一单位划分,指针的值是内存地址 必须能被4整除,所以指针的开始2位必须为0(必须为4的倍数) 搜索内存的时候就以4字节为单位搜索 减少搜索时间<br /><br />感悟1:<br /><br />
       if (*(PUSHORT)cPtr == 0x35FF &amp;&amp; *(pOpcode + 6) == 0xE8)<br />
       {<br />
         pPspCidTable = **(PVOID **)(pOpcode + 2);<br />
         break;<br />
       }<br />这个代码是在PsLookUpProcessByProcessId的函数内定位pspcidtable<br />我反了下这个PsLookUpProcessByProcessId函数<br /><br />kd&gt; uf nt!PsLookUpProcessByProcessId<br />nt!PsLookupProcessByProcessId:<br />......<br />805ca42e ff35<font color="#ff0000">e0b25580</font>    push    dword ptr [nt!PspCidTable (8055b2e0)]<br />805ca434 e84bb50300      call    nt!ExMapHandleToPointer (80605984)<br />......<br /><br />大概就是内存特征定位吧 哈哈 红色标注的地方就是pspcidtable的地址拉<br />也就是说在整个函数中,pspcidtable的地址前面是0xff35 后面是 0xe8<br />通过这个特征找到0xff35和 0xe8之间的这8字节的数据就是pspcidtable的地址<br />当然拉看起来不像是吧  内存存放顺序跟我们看的不一样 是以2字节为单位 压栈压进去的<br />所以逻辑上的顺序和内存上的顺序是正好相反的<br />所以红色字体以2个字节倒着排过来就是 8055b2e0 <br />我们拿windbg看看<br />kd&gt; dd pspcidtable<br /><font color="#ff0000">8055b2e0 </font> e1000860 00000002 00000000 00000000<br /><br />看 果然是pspcidtable的地址 神奇阿~~<br /><br />感悟2:<br />记得 &lt;&lt;基于pspCidTable的进程检测技术&gt;&gt;这篇牛文里面说过获取pspcidtable的方法还有一个 就是<br />KdEnableDebugger-&gt;KdInitSystem-&gt;KdDebuggerDataBlock<br />-&gt;KDDEBUGGER_DATA32-&gt;PspCidTable <br />这个流程 其实跟那个PsLookUpProcessByProcessId差不多 都是内存定位<br />但是我们群的牛哥哥说了个更加易用的方法~<br /><br />#define GetVar( x )        (*(PULONG)((*(PULONG)0xffdff034) + (ULONG)(x)))<br />PspCidTable = GetVar(0x80);<br /><br />就这么简单....  原理很简单...  0xffdff000是KPCR这个结构变量的地址<br />那么0x34就是KdVersionBlock 成员变量在该结构中的偏移<br />但是在0xffdff034指向的地方对应有个结构_DBGKD_GET_VERSION64 <br />可惜的是这个结构只有0x28字节大小 但是....嘿嘿  这个结构后面藏着N多超级重要的内核变量<br />我们的pspcidtable这个变量其实就在这个结构起始位置的0x80字节偏移处~<br />如此一来 我拿sp3的xp系统调试如下:<br />kd&gt; dd 0xffdff034<br />ffdff034  80546b38 8003f400 8003f000 80042000<br /><br />kd&gt; dd 80546b38+0x80<br />80546bb8  <font color="#ff0000">8055b2e0</font> 00000000 8055d708 00000000<br /><br />kd&gt; dd pspcidtable<br /><font color="#ff0000">8055b2e0</font>  e1000860 00000002 00000000 00000000<br /><br />其实0xffdff034指向的地方对应的结构体应该就是传说中的KDDEBUGGER_DATA32这个结构(windbg看了下说没这个符号...)  <br />typedef struct _KDDEBUGGER_DATA32 {<br />
     DBGKD_DEBUG_DATA_HEADER32 Header;<br />
     ULONG    KernBase;<br />
     ULONG    BreakpointWithStatus;      // address of breakpoint<br />
     ULONG    SavedContext;<br />
     USHORT    ThCallbackStack;         // offset in thread data<br />
     USHORT    NextCallback;          // saved pointer to next callback frame<br />
     USHORT    FramePointer;          // saved frame pointer<br />
     USHORT    PaeEnabled:1;<br />
     ULONG    KiCallUserMode;         // kernel routine<br />
     ULONG    KeUserCallbackDispatcher;    // address in ntdll<br /><br />
     ULONG    PsLoadedModuleList;<br />
     ULONG    PsActiveProcessHead;<br />
     ULONG    PspCidTable;         // &lt;--------- What we need!!<br />
     //...<br />
     ULONG    MmLoadedUserImageList;<br />
} KDDEBUGGER_DATA32, *PKDDEBUGGER_DATA32;<br />大概就是这样的 呵呵 里面保存着比较重要的变量比如pspcidtable PsActiveProcessHead<br /> PsLoadedModuleList等等  重要的是这个地址貌似是硬编码进去的 也就是说好像只要是NT内核的机器这个地址是不会变的,什么?根据?嘿嘿... <br />据某老外文献记载:<br />; Start of the architecturally defined section of the PCR. This section<br />
; may be directly addressed by vendor/platform specific HAL code and will<br />
; not change from version to version of NT.<br /> <br />看没看没 反正我sp3上机器可以 的确是这个地址 没错<br /><br /><br /><br />                                                                                                            <font size="2" face="Tahoma">   __ay.字</font><br />涉及到的学习资料<br />http://bbs.pediy.com/showthread.php?p=13746<br />http://www.0GiNr.com/<br />http://bbs.pediy.com/showthread.php?t=73028<br />futo 抹句柄表<br />Rootkits.com  opc0de<br /><br /><br /><br /><img src ="http://www.cppblog.com/ay19880703/aggbug/72607.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-01-26 21:04 <a href="http://www.cppblog.com/ay19880703/archive/2009/01/26/72607.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windbg学习笔记 FOR 内核调试(三) --进程句柄表HANDLE_TABLE</title><link>http://www.cppblog.com/ay19880703/archive/2009/01/25/72574.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Sun, 25 Jan 2009 09:43:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/01/25/72574.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72574.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/01/25/72574.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72574.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72574.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Normal  0    7.8 磅  0  2    false  false  false                                          MicrosoftInternetExplorer4 		  		st1\:*{behav...&nbsp;&nbsp;<a href='http://www.cppblog.com/ay19880703/archive/2009/01/25/72574.html'>阅读全文</a><img src ="http://www.cppblog.com/ay19880703/aggbug/72574.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-01-25 17:43 <a href="http://www.cppblog.com/ay19880703/archive/2009/01/25/72574.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windbg学习笔记 FOR 内核调试(二)</title><link>http://www.cppblog.com/ay19880703/archive/2009/01/24/72527.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Fri, 23 Jan 2009 16:51:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/01/24/72527.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72527.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/01/24/72527.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72527.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72527.html</trackback:ping><description><![CDATA[
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="ProgId" content="Word.Document" />
		<meta name="Generator" content="Microsoft Word 11" />
		<meta name="Originator" content="Microsoft Word 11" />
		<link rel="File-List" href="file:///C:%5CUsers%5Cay%5CAppData%5CLocal%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
		<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Normal</w:View>
  <w:Zoom>0</w:Zoom>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
		<!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
		<style>
				<!--
 /* Font Definitions */
 @font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 680460288 22 0 262145 0;}
@font-face
	{font-family:微软雅黑;
	panose-1:2 11 5 3 2 2 4 2 2 4;
	mso-font-charset:134;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-2147483001 705641554 22 0 262175 0;}
@font-face
	{font-family:"\@微软雅黑";
	panose-1:2 11 5 3 2 2 4 2 2 4;
	mso-font-charset:134;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-2147483001 705641554 22 0 262175 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 680460288 22 0 262145 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-520078593 -1073717157 41 0 66047 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
		</style>
		<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
		<p class="MsoNormal" style="text-indent: 30pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">最近终于把车考过去了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,windbg</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">的学习耽搁了好多</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">前几天每天都在练车</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">搞死我了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">不过还好在海边练</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">景色很宜人</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">舒服</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~HOHO<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal" style="text-indent: 30pt;">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-indent: 30pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">上次说啥来着</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">?<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal" style="text-indent: 30pt;">
				<span style="font-size: 14pt; font-family: 微软雅黑;">哦</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">对了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">就是这几个命令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">堆栈显示指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">kb , kp, kP , kv<br /></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">反汇编指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">u,uf<br /></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">跟踪指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">T,TA,TB,TC<br /></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">执行相关指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">P,PA,PC<br /></span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">跟踪查看指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">WT<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">这些差不多了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">到时候调试篇忘记了会把这些命令说明插进去</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~HOHO </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这里仅做个整理</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">堆栈显示指令</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">k
[b|p|P|v]<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">在内核调试的时候</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,k</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">命令用来显示内核栈的内容</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">先说说内核栈用来干嘛的</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">看了些资料个人理解是这样的</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">比如我们的代码运行时</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">肯定会有函数</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">函数然后还会调用函数</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">但是系统如何记录是哪个父函数调用了这个子函数</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">在子函数调用之前整个状态又是怎样的</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">其实系统是利用了堆栈记录的</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">栈这个东西好阿</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> 
</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">先进后出</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">最近调用的函数记录在最顶层</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">函数执行完后就从栈内弹出之前记录的参数</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">如果调用函数</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">一样的把函数压进栈内就好了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">这样一来</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">一旦子函数执行完</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">从栈内弹出的第一个函数肯定是该子函数的老爹</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">我们可以看上层堆栈的状态等等</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">功能大家慢慢去体会吧</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">我也没用过</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> 
</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">不好说什么</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">下面说些细节的东西</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">b<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">显示传给函数的前三个参数</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">p<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">显示传给函数的全部参数</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">P(</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">大写</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">)<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">跟上面那个一样</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">只不过是显示形式不同而已</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">V<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">外加显示一些额外的信息</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">u
[f]<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">反汇编指令</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">嘿嘿</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">超级有用的指令哟</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">虽然说内核很多东西很复杂</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">认识偶尔小小反下也是可以的</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">u<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">反汇编当前寄存器指向的代码</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">uf
</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">函数名</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">(</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">比如</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">nt!ZwCreateFile)<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">反汇编指定的函数</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">t
[r]<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">单步跟踪</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<u4:p>
								</u4:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">r</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">打开指显示寄存器的详细信息</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">状态的开关</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">(</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">下面指令一样有效</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">在用</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">次就会关闭哦</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~)<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">ta
</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">地址</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">让程序执行到指定地址</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">tb
<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">让程序运行到分支语句时停止</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">tc<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">让程序运行到下一个函数调用停止</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">p
[r]<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">单步执行一跳指令</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">r</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">打开指显示寄存器的详细信息</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">状态的开关</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">(</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">下面指令一样有效</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">在用</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">1</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">次就会关闭哦</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~)<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">pa<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">让程序执行到指定地址</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">pc<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">让程序执行到函数调用就停止</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">wt<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal" style="text-align: left;" align="left">
				<span style="font-size: 14pt; font-family: 微软雅黑;">
						<!--[if gte mso 9]><xml>
 <u5:WordDocument>
  <u5:View>Normal</u5:View>
  <u5:Zoom>0</u5:Zoom>
  <u5:PunctuationKerning/>
  <u5:DrawingGridVerticalSpacing>7.8 磅</u5:DrawingGridVerticalSpacing>
  <u5:DisplayHorizontalDrawingGridEvery>0</u5:DisplayHorizontalDrawingGridEvery>
  <u5:DisplayVerticalDrawingGridEvery>2</u5:DisplayVerticalDrawingGridEvery>
  <u5:ValidateAgainstSchemas/>
  <u5:SaveIfXMLInvalid>false</u5:SaveIfXMLInvalid>
  <u5:IgnoreMixedContent>false</u5:IgnoreMixedContent>
  <u5:AlwaysShowPlaceholderText>false</u5:AlwaysShowPlaceholderText>
  <u5:Compatibility>
   <u5:SpaceForUL/>
   <u5:BalanceSingleByteDoubleByteWidth/>
   <u5:DoNotLeaveBackslashAlone/>
   <u5:ULTrailSpace/>
   <u5:DoNotExpandShiftReturn/>
   <u5:AdjustLineHeightInTable/>
   <u5:BreakWrappedTables/>
   <u5:SnapToGridInCell/>
   <u5:WrapTextWithPunct/>
   <u5:UseAsianBreakRules/>
   <u5:DontGrowAutofit/>
   <u5:UseFELayout/>
  </u5:Compatibility>
  <u5:BrowserLevel>MicrosoftInternetExplorer4</u5:BrowserLevel>
 </u5:WordDocument>
</xml><![endif]-->
						<!--[if gte mso 9]><xml>
 <u5:LatentStyles DefLockedState="false" LatentStyleCount="156">  </u5:LatentStyles>
</xml><![endif]-->在想查看指定函数的信息而又不想单步通过该函数时很有用。可以到函数的起始地址并执行</span>
				<span style="font-size: 14pt;">
				</span>
				<strong>
						<span style="font-size: 14pt; font-family: Tahoma; font-weight: normal;" lang="EN-US">wt</span>
				</strong>
				<strong>
						<span style="font-size: 14pt;" lang="EN-US">
						</span>
				</strong>
				<span style="font-size: 14pt; font-family: 微软雅黑;">命令。</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">(</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">摘自翻译文档</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">)</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u4:p> </u4:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">
						<!--[if gte mso 9]><xml>
 <u6:WordDocument>
  <u6:View>Normal</u6:View>
  <u6:Zoom>0</u6:Zoom>
  <u6:PunctuationKerning/>
  <u6:DrawingGridVerticalSpacing>7.8 磅</u6:DrawingGridVerticalSpacing>
  <u6:DisplayHorizontalDrawingGridEvery>0</u6:DisplayHorizontalDrawingGridEvery>
  <u6:DisplayVerticalDrawingGridEvery>2</u6:DisplayVerticalDrawingGridEvery>
  <u6:ValidateAgainstSchemas/>
  <u6:SaveIfXMLInvalid>false</u6:SaveIfXMLInvalid>
  <u6:IgnoreMixedContent>false</u6:IgnoreMixedContent>
  <u6:AlwaysShowPlaceholderText>false</u6:AlwaysShowPlaceholderText>
  <u6:Compatibility>
   <u6:SpaceForUL/>
   <u6:BalanceSingleByteDoubleByteWidth/>
   <u6:DoNotLeaveBackslashAlone/>
   <u6:ULTrailSpace/>
   <u6:DoNotExpandShiftReturn/>
   <u6:AdjustLineHeightInTable/>
   <u6:BreakWrappedTables/>
   <u6:SnapToGridInCell/>
   <u6:WrapTextWithPunct/>
   <u6:UseAsianBreakRules/>
   <u6:DontGrowAutofit/>
   <u6:UseFELayout/>
  </u6:Compatibility>
  <u6:BrowserLevel>MicrosoftInternetExplorer4</u6:BrowserLevel>
 </u6:WordDocument>
</xml><![endif]-->
						<!--[if gte mso 9]><xml>
 <u7:LatentStyles DefLockedState="false" LatentStyleCount="156">  </u7:LatentStyles>
</xml><![endif]-->这个感觉用处不是很大</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">.</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">不细细研究了</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal" style="text-align: left;" align="left">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<br style="" />
						<!--[if !supportLineBreakNewLine]-->
						<br style="" />
						<!--[endif]-->
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p>
						</u3:p>----------------------------------------------------------------------------<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US"> 
<u3:p></u3:p></span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">Ps:</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">很多人不清楚到底</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">p</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令和</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">t</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令有什么区别</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">其实很简单</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">p</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令执行到函数时把这个当做一个指令来执行</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">也就是说不会进入函数执行</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">,</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">但是</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">t</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">指令会进入到函数里面执行</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">就这么简单</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">~~</span>
				<span style="font-size: 14pt;" lang="EN-US">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: 微软雅黑;">基础指令就到这里了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">  </span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">过段时间开始记点调试的东东了</span>
				<span style="font-size: 14pt;">
				</span>
				<span style="font-size: 14pt; font-family: 微软雅黑;">呵呵</span>
				<span style="font-size: 14pt;">
						<span lang="EN-US">
								<u3:p>
								</u3:p>
								<o:p>
								</o:p>
						</span>
				</span>
		</p>
		<u4:p>
		</u4:p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u3:p> </u3:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<u4:p>
						</u4:p>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt; font-family: Tahoma;" lang="EN-US">
						<u4:p> </u4:p>
				</span>
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-size: 14pt;" lang="EN-US">
						<o:p> </o:p>
				</span>
		</p>
<img src ="http://www.cppblog.com/ay19880703/aggbug/72527.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-01-24 00:51 <a href="http://www.cppblog.com/ay19880703/archive/2009/01/24/72527.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windbg学习笔记 FOR 内核调试(一)</title><link>http://www.cppblog.com/ay19880703/archive/2009/01/16/72181.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Fri, 16 Jan 2009 08:23:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2009/01/16/72181.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/72181.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2009/01/16/72181.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/72181.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/72181.html</trackback:ping><description><![CDATA[      放假回家就下定决心要把windbg搞定 否则以后的内核之路该咋走啊~呵呵 今天就网上零零碎碎的记了些命令用法  看了别人的调试教程 <br />个人总结下<br /><br />----------------------------------------------------------------------------<br />!drvobj 你的驱动对象 [标志位]<br />说明:这个指令可以查看驱动对象的具体信息 我们知道每个驱动程序在内核中都会对应一个驱动对象的结构,其实上面所说的驱动对象就是你的驱动名字,比如我要找aynet.sys这个驱动程序的驱动对象结构,那么我就!drvobj aynet 就好啦~<br />标志位是用来告诉windbg具体要显示什么内容的,标志位可以组合使用<br /><dl><dt>Bit 0 (0x1) 
</dt><dd>显示所有跟这个驱动对象相关联的设备对象信息</dd><dt>Bit 1 (0x2) 
</dt><dd>显示所有跟这个驱动想关的派遣例程信息</dd><dt>Bit 2 (0x4) 
</dt><dd>显示这个驱动对象的详细信息 (需要标志位0)</dd><dt>ps: !object 可以查看对象的详细信息 比如该内核对象是什么内核对象(文件,进程等)</dt><dd>类似用法还有!handle(就是!后面跟结构名)等等<br /></dd><dt>----------------------------------------------------------------------------<br /></dt></dl>dt name<br />说明:dt用来查看本地|全局|结构变量内容的 , name是指你的变量类型是什么,你要看_DEVICE_OBJECT这个结构变量就直接打 dt _DEVICE_OBJECT  查看变量就直接输变量名<br />----------------------------------------------------------------------------<br />下面说说下断点的指令<br />bp 地址<br />在地址处下断点 也可以是函数名(其实函数名就对应着地址)<br />打个比方bp aynet!DriverEntry 说明在aynet这个驱动程序的driverentry函数处下断 也就是程序一执行到这里windbg就自动断下来了<br />还有个bu指令 延迟下断点 格式跟bp差不多<br /><br />bm 匹配值<br />bm指令用于匹配模式下断点 比如说bm aynet!Driver* 可以把aynet驱动下所有跟Driver* 模式匹配的函数断下 <font color="#000000">但是注意~需要符号表的支持</font><br /><br />ba 变量名<br />可以对内存访问下断点 比如说你程序里有个aynet驱动程序a变量,总被莫名其妙的修改了,那么你可以设置 ba aynet!a ,当这个a值被修改的时候就可以被windbg断下来了<br /><br />还有其他常用命令比如<br />BL（List）列举断点，BC（Clear）清除断点，BE（Enable）启用断点，BD（Disable）禁止断点<br />这些很简单 就不累述了<br />----------------------------------------------------------------------------<br />注:一下指令区分大小<br />显示内存数据相关指令<br />格式:d[*] 变量名/地址<br />da--asc字符显示<br />db--byte&amp;asc字符显示<br />dc--双字节&amp;asc字符显示<br />dd--双字节变量显示<br />dD--双精浮点数显示<br />df--单精浮点数显示<br />dp--四字节数值显示<br />du--unicode字符显示<br />dw--字符(2个字节)显示<br />dW--字符和asc字符显示<br />dyb--二进制显示<br />dyd--二进制和双字节显示<br />举个例子:(注:xx是变量名 )<br />kd&gt; dd xx      //双字节显示(即16进制)<br />8055b260  610f0f64 00000002 00000000 00000000<br />8055b270  00000000 00000000 00000000 00000000<br />8055b280  00000000 00000000 00000000 00000000<br />8055b290  00000000 00000000 00000000 00000000<br />8055b2a0  00000000 00000000 00000000 00000000<br />8055b2b0  00000000 00000000 00000000 00000000<br />8055b2c0  00000000 00000000 00000000 00000000<br />8055b2d0  00000000 00000000 00000000 00000000<br />kd&gt; da xx  //asc字符显示<br />8055b260  "`."<br />kd&gt; du xx  //unicode字符显示<br />8055b260  "..."<br /><br />附加:<br />dv <br />查看本地变量用~<br /><br />看内存内容的时候就会用到这个命令了~呵呵<br />----------------------------------------------------------------------------<br />今天就学了这么多 <br />剩下的明天在看 呵呵 <br />下次要说的内容是<br />堆栈显示指令kb , kp, kP , kv<br />反汇编指令 u,uf<br />跟踪指令 T,TA,TB,TC<br />执行相关指令 P,PA,PC<br />跟踪查看指令 WT<br />先记下来~省的我忘了~<br />要调试也就大概就用到这些命令了吧 以后就开始记我的调试过程了~<br /><br /><br /><img src ="http://www.cppblog.com/ay19880703/aggbug/72181.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2009-01-16 16:23 <a href="http://www.cppblog.com/ay19880703/archive/2009/01/16/72181.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>个人总结NDIS中NDIS_PACKET,NDIS_BUFFER的关系</title><link>http://www.cppblog.com/ay19880703/archive/2008/09/18/62233.html</link><dc:creator>__ay</dc:creator><author>__ay</author><pubDate>Thu, 18 Sep 2008 15:25:00 GMT</pubDate><guid>http://www.cppblog.com/ay19880703/archive/2008/09/18/62233.html</guid><wfw:comment>http://www.cppblog.com/ay19880703/comments/62233.html</wfw:comment><comments>http://www.cppblog.com/ay19880703/archive/2008/09/18/62233.html#Feedback</comments><slash:comments>13</slash:comments><wfw:commentRss>http://www.cppblog.com/ay19880703/comments/commentRss/62233.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ay19880703/services/trackbacks/62233.html</trackback:ping><description><![CDATA[
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">   <br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> NDIS_PACKET结构的定义  <br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">typedef </span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> _NDIS_PACKET  <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">NDIS_PACKET_PRIVATE Private;  <br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">这个其实是一个链表结构,Private.Head指向第一个链表,Private.Tail指向最后一个  <br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">以下有关于这个结构的解释  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">union  <br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> For Connection-less miniports   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">UCHAR MiniportReserved[</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(PVOID)];  <br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">UCHAR WrapperReserved[</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(PVOID)];  <br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">};  <br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">   <br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> For de-serialized miniports. And by implication conn-oriented miniports.   <br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> This is for the send-path only. Packets indicated will use WrapperReserved   <br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> instead of WrapperReservedEx   <br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">UCHAR MiniportReservedEx[</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(PVOID)];  <br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">UCHAR WrapperReservedEx[</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(PVOID)];  <br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">};  <br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">UCHAR MacReserved[</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 255);">sizeof</span><span style="color: rgb(0, 0, 0);">(PVOID)];  <br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">};  <br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">};  <br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);">ULONG_PTR Reserved[</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">]; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> For compatibility with Win95   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">UCHAR ProtocolReserved[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">];  <br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 0, 0);">} NDIS_PACKET, </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">PNDIS_PACKET, </span><span style="color: rgb(0, 0, 0);">**</span><span style="color: rgb(0, 0, 0);">PPNDIS_PACKET;  <br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> NDIS_PACKET_PRIVATE 的定义  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">typedef </span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> _NDIS_PACKET_PRIVATE  <br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);">{  <br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 0, 0);">UINT PhysicalCount; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> number of physical pages in packet.   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">UINT TotalLength; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Total amount of data in the packet.   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">PNDIS_BUFFER Head; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 链表指针,指向第一个  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">PNDIS_BUFFER Tail; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 链表指针,</span><span style="color: rgb(0, 128, 0);">指向最后一个  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> if Head is NULL the chain is empty; Tail doesn\'t have to be NULL also   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 0, 0);">PNDIS_PACKET_POOL Pool; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> so we know where to free it back to   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">UINT Count;  <br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">ULONG Flags;  <br /></span><span style="color: rgb(0, 128, 128);">53</span> <span style="color: rgb(0, 0, 0);">BOOLEAN ValidCounts;  <br /></span><span style="color: rgb(0, 128, 128);">54</span> <span style="color: rgb(0, 0, 0);">UCHAR NdisPacketFlags; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> See fPACKET_xxx bits below   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">55</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">USHORT NdisPacketOobOffset;  <br /></span><span style="color: rgb(0, 128, 128);">56</span> <span style="color: rgb(0, 0, 0);">} NDIS_PACKET_PRIVATE, </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> PNDIS_PACKET_PRIVATE;  <br /></span><span style="color: rgb(0, 128, 128);">57</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">58</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">NDIS_BUFFER定义 其实就是一个内存描述符</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">59</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">60</span> <span style="color: rgb(0, 0, 0);">typedef </span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> _NDIS_BUFFER {  <br /></span><span style="color: rgb(0, 128, 128);">61</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> _NDIS_BUFFER </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">Next; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">指向下一个节点的指针</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">62</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">PVOID VirtualAddress;      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">指向报文首地址</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">63</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">PNDIS_BUFFER_POOL Pool;  <br /></span><span style="color: rgb(0, 128, 128);">64</span> <span style="color: rgb(0, 0, 0);">UINT Length;               </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">报文数据长度</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">65</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">UINT Signature;  <br /></span><span style="color: rgb(0, 128, 128);">66</span> <span style="color: rgb(0, 0, 0);">} NDIS_BUFFER, </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> PNDIS_BUFFER;  </span></div>
		<br />
		<span style="font-size: 18pt;">注释写的很清楚了  那么他们的关系还是不清楚的话看看附图</span>
		<br />
		<br />
		<img src="http://www.cppblog.com/images/cppblog_com/ay19880703/20080916_8425060735764a4ac365BwN1S6RW4ZtZ.gif" border="0" />
		<br />
		<br />
		<span style="font-size: 12pt;"> 
好了  这样一来我们的思路大概清楚了  NDIS_PACKET只不过是一个关于NDIS_BUFFER链表的结构  在NDIS_PACKET中的成
员Private中有指向第一个NDIS_BUFFER的指针和指向最后一个NDIS_BUFFER的指针  分别是Private.Head
和Private.Tail     而NDIS_BUFFER中就记录了我们数据包的地址和下一个NDIS_BUFFER的地址 
 操作有很多种方法   由于这些结构体本来对我们是不透明的   
所以最安全的方法是用MS提供的一系列函数来操作NDIS_PACKET和NDIS_BUFFER  <br /><br />
    还是拿个例子好说话吧</span>
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">NDIS_STATUS status ;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">    PNDIS_BUFFER NdisBuffer ;<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">    UINT TotalPacketLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> , copysize </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> , DataOffset </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> , PhysicalBufferCount  ,  BufferCount   ;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">    PUCHAR mybuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> NULL ,tembuffer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> NULL ;  <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">假设这个是在PtReceive等函数中得到的PACKET</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">NdisQueryPacket(packet                     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">我们先得到第一个NDISBUFFER 的指针   </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        , </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">PhysicalBufferCount              <br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">        , </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">BufferCount                           <br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">        ,</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">NdisBuffer                               </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">NdisBuffer就是指向链表头</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        , </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">TotalPacketLength<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">        );<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 128, 0);">其实也可以不用那么麻烦 直接  NdisBuffer = packet-&gt;Private.Head ;就可以取得第一个BUFFER了<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">    status </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> NdisAllocateMemory( </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">mybuffer, </span><span style="color: rgb(0, 0, 0);">2048</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, HighestAcceptableMax );  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">分配我们自己的内存块</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( status </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> NDIS_STATUS_SUCCESS )<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> NDIS_STATUS_FAILURE ;<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">    NdisZeroMemory( mybuffer, </span><span style="color: rgb(0, 0, 0);">2048</span><span style="color: rgb(0, 0, 0);"> ) ;<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">    NdisQueryBufferSafe(  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">取得NDIS_BUFFER描述符中数据的首地址和大小</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">                                NdisBuffer,<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">                                </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">tembuffer,<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">                                </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">copysize,<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">                                NormalPagePriority<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">    );  <br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">     <br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">将数据复制到我们的内存中</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    NdisMoveMemory(mybuffer, tembuffer, copysize) ;<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">    DataOffset </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> copysize ;<br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">    {<br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 128, 0);">                也可以这样操作而不用NdisGetNextBuffer<br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 128, 0);">        if(NdisBuffer-&gt;Next == packet-&gt;Private.Tail )<br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 128, 0);">            break ;<br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 128, 0);">        NdisBuffer = NdisBuffer-&gt;Next ;<br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 128, 0);">        if(pmdl == NULL )<br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 128, 0);">           break ;<br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 128, 0);">           </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获得下一个NDIS_BUFFER的的指针</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    NdisGetNextBuffer(NdisBuffer , </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">NdisBuffer ) ;<br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 0, 0);">        如果指针是NULL  那么表示到链表尾了<br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( NdisBuffer </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> NULL )<br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);"> ;<br /></span><span style="color: rgb(0, 128, 128);">53</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">54</span> <span style="color: rgb(0, 0, 0);">    NdisQueryBufferSafe(<br /></span><span style="color: rgb(0, 128, 128);">55</span> <span style="color: rgb(0, 0, 0);">                                NdisBuffer,<br /></span><span style="color: rgb(0, 128, 128);">56</span> <span style="color: rgb(0, 0, 0);">                                </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">tembuffer,<br /></span><span style="color: rgb(0, 128, 128);">57</span> <span style="color: rgb(0, 0, 0);">                                </span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">copysize,<br /></span><span style="color: rgb(0, 128, 128);">58</span> <span style="color: rgb(0, 0, 0);">                                NormalPagePriority<br /></span><span style="color: rgb(0, 128, 128);">59</span> <span style="color: rgb(0, 0, 0);">                                ) ;<br /></span><span style="color: rgb(0, 128, 128);">60</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">61</span> <span style="color: rgb(0, 0, 0);">    NdisMoveMemory( mybuffer </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> DataOffset , tembuffer, copysize) ;<br /></span><span style="color: rgb(0, 128, 128);">62</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">63</span> <span style="color: rgb(0, 0, 0);">    DataOffset </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> copysize  ;<br /></span><span style="color: rgb(0, 128, 128);">64</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">65</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">66</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">67</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">OK  我们要的数据就全部都在我们申请的内存mybuffer 数据大小为DataOffset</span></div>
		<br />    <br /><span style="font-size: 18pt;">  </span><br /><br /><img src ="http://www.cppblog.com/ay19880703/aggbug/62233.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ay19880703/" target="_blank">__ay</a> 2008-09-18 23:25 <a href="http://www.cppblog.com/ay19880703/archive/2008/09/18/62233.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>