<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>火星信息安全研究院WinDbg</title>
	<atom:link href="http://www.h4ck.org.cn/tag/windbg/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.h4ck.org.cn</link>
	<description>Hack-Crack  信息安全 【Institute Of Information Serurity From Mars】</description>
	<lastBuildDate>Sat, 04 Feb 2012 13:59:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>从RegQueryValueExA到ZwQueryValueKey</title>
		<link>http://www.h4ck.org.cn/2011/09/from-regqueryvalueexa-to-zwqueryvaluekey/</link>
		<comments>http://www.h4ck.org.cn/2011/09/from-regqueryvalueexa-to-zwqueryvaluekey/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 03:49:33 +0000</pubDate>
		<dc:creator>obaby</dc:creator>
				<category><![CDATA[程序设计『Programing』]]></category>
		<category><![CDATA[WinDbg]]></category>
		<category><![CDATA[驱动开发]]></category>

		<guid isPermaLink="false">http://www.h4ck.org.cn/?p=3105</guid>
		<description><![CDATA[从RegQueryValueExA到ZwQueryValueKey]]></description>
			<content:encoded><![CDATA[<p>对于注册表的REG_MULTI_SZ类型的数据个人感觉一直比较蛋疼，一个是因为在Delphi下竟然没有相关的函数，第二个是因为对于这类型的数据在使用ssdt hook修改数据的时候出现了很多问题。</p>
<p>为了明白到底是怎么处理的，于是就把相关的调用流程跟踪了一遍。至于是什么程序调用的这里就不提了，直接贴代码吧。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">103B29D8</span>    8B4C24 <span style="color: #0000ff;">18</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x18</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B29DC</span>    8B3D 34F0EE10   <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ds</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span>&amp;lt<span style="color: #666666; font-style: italic;">;&amp;amp;ADVAPI32.RegQuer&amp;gt;; ADVAPI32.RegQueryValueExA</span>
<span style="color: #adadad; font-style: italic;">103B29E2</span>    <span style="color: #0000ff;">894424</span> <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B29E6</span>    8D4424 <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B29EA</span>    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B29EB</span>    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B29ED</span>    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B29EF</span>    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B29F1</span>    <span style="color: #0000ff;">68</span> 088FFD10     <span style="color: #00007f; font-weight: bold;">push</span> iTunes_1<span style="color: #339933;">.</span>10FD8F08                   <span style="color: #666666; font-style: italic;">; ASCII &quot;SystemBiosVersion&quot;</span>
<span style="color: #adadad; font-style: italic;">103B29F6</span>    <span style="color: #0000ff;">51</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ecx</span>
<span style="display:block;background-color: #ffc;"><span style="color: #adadad; font-style: italic;">103B29F7</span>    FFD7            <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #00007f;">edi</span></span><span style="color: #adadad; font-style: italic;">103B29F9</span>    85C0            <span style="color: #00007f; font-weight: bold;">test</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B29FB</span>    <span style="color: #0000ff;">75</span> <span style="color: #0000ff;">48</span>           <span style="color: #00007f; font-weight: bold;">jnz</span> XiTunes_1<span style="color: #339933;">.</span>103B2A45
<span style="color: #adadad; font-style: italic;">103B29FD</span>    8B5424 <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A01</span>    <span style="color: #0000ff;">52</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">edx</span>
<span style="color: #adadad; font-style: italic;">103B2A02</span>    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A03</span>    E8 7820CDFF     <span style="color: #00007f; font-weight: bold;">call</span> iTunes_1<span style="color: #339933;">.</span>10084A80
<span style="color: #adadad; font-style: italic;">103B2A08</span>    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A09</span>    FF15 84FEEE10   <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ds</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span>&amp;lt<span style="color: #666666; font-style: italic;">;&amp;amp;KERNEL32.HeapAlloc&amp;gt;&amp;gt;; ntdll.RtlAllocateHeap</span>
<span style="color: #adadad; font-style: italic;">103B2A0F</span>    8B4C24 <span style="color: #0000ff;">18</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x18</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A13</span>    8BF0            <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A15</span>    8D4424 <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A19</span>    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A1A</span>    <span style="color: #0000ff;">56</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">esi</span>
<span style="color: #adadad; font-style: italic;">103B2A1B</span>    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B2A1D</span>    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B2A1F</span>    <span style="color: #0000ff;">68</span> 088FFD10     <span style="color: #00007f; font-weight: bold;">push</span> iTunes_1<span style="color: #339933;">.</span>10FD8F08                   <span style="color: #666666; font-style: italic;">; ASCII &quot;SystemBiosVersion&quot;</span>
<span style="color: #adadad; font-style: italic;">103B2A24</span>    <span style="color: #0000ff;">51</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ecx</span>
<span style="display:block;background-color: #ffc;"><span style="color: #adadad; font-style: italic;">103B2A25</span>    FFD7            <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #00007f;">edi</span></span></pre></td></tr></table></div>

<p>这里是应用层的第一次调用，在调用的时候第一次并没有分配相应的缓冲区来存放数据。这次调用的根本目的是为了获取注册表中对应的数据的大小。<br />
<span id="more-3105"></span><br />
跟入call之后可以看到如下的代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">77DA6ECC</span>            <span style="color: #339933;">.</span>  8D8D 6CFFFFFF <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x94</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">77DA6ED2</span>            <span style="color: #339933;">.</span>  898D 58FFFFFF <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0xA8</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">ecx</span>
<span style="color: #adadad; font-style: italic;">77DA6ED8</span>            <span style="color: #339933;">.</span>  0F85 <span style="color: #0000ff;">66730000</span> <span style="color: #00007f; font-weight: bold;">jnz</span> ADVAPI32<span style="color: #339933;">.</span>77DAE244
<span style="color: #adadad; font-style: italic;">77DA6EDE</span>            &amp;gt<span style="color: #666666; font-style: italic;">;  8B35 2814DA77 mov esi,dword ptr ds:[&amp;lt;&amp;amp;ntdll.NtQueryVal&amp;gt;;  ntdll.ZwQueryValueKey</span>
<span style="color: #adadad; font-style: italic;">77DA6EE4</span>            <span style="color: #339933;">.</span>  8D85 5CFFFFFF <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0xA4</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">77DA6EEA</span>            <span style="color: #339933;">.</span>  <span style="color: #0000ff;">50</span>            <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">77DA6EEB</span>            <span style="color: #339933;">.</span>  BF <span style="color: #0000ff;">90000000</span>   <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x90</span>
<span style="color: #adadad; font-style: italic;">77DA6EF0</span>            <span style="color: #339933;">.</span>  <span style="color: #0000ff;">57</span>            <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">edi</span>
<span style="color: #adadad; font-style: italic;">77DA6EF1</span>            <span style="color: #339933;">.</span>  8D85 6CFFFFFF <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x94</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">77DA6EF7</span>            <span style="color: #339933;">.</span>  <span style="color: #0000ff;">50</span>            <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">77DA6EF8</span>            <span style="color: #339933;">.</span>  6A <span style="color: #0000ff;">02</span>         <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x2</span>
<span style="color: #adadad; font-style: italic;">77DA6EFA</span>            <span style="color: #339933;">.</span>  <span style="color: #0000ff;">53</span>            <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebx</span>
<span style="color: #adadad; font-style: italic;">77DA6EFB</span>            <span style="color: #339933;">.</span>  FFB5 50FFFFFF <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0xB0</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">77DA6F01</span>            &amp;gt<span style="color: #666666; font-style: italic;">;  FFD6          call esi</span></pre></td></tr></table></div>

<p>上面的代码依旧处于advapi32.dll中，而经过这次调用就到了ntdll.dll中。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">7C92D950</span> ntdll<span style="color: #339933;">.</span>ZwQueryValueKey          B8 B1000000     <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0xB1</span>
<span style="color: #adadad; font-style: italic;">7C92D955</span>                                BA 0003FE7F     <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x7FFE0300</span>
<span style="color: #adadad; font-style: italic;">7C92D95A</span>                                FF12            <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ds</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edx</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">7C92D95C</span>                                C2 <span style="color: #0000ff;">1800</span>         <span style="color: #00007f; font-weight: bold;">retn</span> <span style="color: #0000ff;">0x18</span></pre></td></tr></table></div>

<p>再次跟入之后就到了应用层的最底层了。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">7C92E4F0</span> ntdll<span style="color: #339933;">.</span>KiFastSystemCall             8BD4            <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #00007f;">esp</span>
<span style="color: #adadad; font-style: italic;">7C92E4F2</span>                                    0F34            sysenter
<span style="color: #adadad; font-style: italic;">7C92E4F4</span> ntdll<span style="color: #339933;">.</span>KiFastSystemCallRet          C3              <span style="color: #00007f; font-weight: bold;">retn</span></pre></td></tr></table></div>

<p>调用sysenter进入到ring 0继续运行，到这里应用层就无法跟踪下去了。但是在内核中通过ssdt hook得到数据的时候数据已经经过了几次调用了，所以看到的并不是直接从应用层传下来的数据。</p>
<p>而应用层在调用的过程中ntdll.dll第一次请求的数据长度为0&#215;90，所以刚开始每次在调试驱动的时候看到数据都是0&#215;90感觉有点奇怪。</p>
<p><img title="reg" src="http://www.h4ck.org.cn/wp-content/uploads//2011/09/reg.png" alt="" width="380" height="302" /></p>
<p>为了使上层分配的空间能够容纳要返回的数据，所以此时应该修正调用ZwQueryValueKey得到的resultlength的长度。并且返回STATUS_BUFFER_OVERFLOW。之所以返回这个是由ntdll.dll来决定的，执行完之后ntdll.dll会通过返回值来重新请求长度，相关代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">77DA6F01</span>                                   &amp;gt<span style="color: #666666; font-style: italic;">; /FFD6          call esi</span>
<span style="color: #adadad; font-style: italic;">77DA6F03</span>                                   <span style="color: #339933;">.</span> |83BD 64FFFFFF&amp;gt<span style="color: #666666; font-style: italic;">;cmp dword ptr ss:[ebp-0x9C],0x0</span>
<span style="color: #adadad; font-style: italic;">77DA6F0A</span>                                   <span style="color: #339933;">.</span> |<span style="color: #0000ff;">8985</span> 68FFFFFF <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x98</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">77DA6F10</span>                                   <span style="color: #339933;">.</span> |8B85 60FFFFFF <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0xA0</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">77DA6F16</span>                                   <span style="color: #339933;">.</span> |0F85 63B40100 <span style="color: #00007f; font-weight: bold;">jnz</span> ADVAPI32<span style="color: #339933;">.</span>77DC237F
<span style="color: #adadad; font-style: italic;">77DA6F1C</span>                                   &amp;gt<span style="color: #666666; font-style: italic;">; |81BD 68FFFFFF&amp;gt;cmp dword ptr ss:[ebp-0x98],0x80000005</span>
<span style="color: #adadad; font-style: italic;">77DA6F26</span>                                   <span style="color: #339933;">.</span> |0F84 EB0A0000 <span style="color: #00007f; font-weight: bold;">je</span> ADVAPI32<span style="color: #339933;">.</span>77DA7A17</pre></td></tr></table></div>

<p>0&#215;80000005对应的就是STATUS_BUFFER_OVERFLOW，那么此时ntdll.dll会尝试再次获取。</p>
<p>直到获取成功，而这时在应用层得到的错误码为EA，表示还有更多的数据。但是在没有hook的时候返回的状态却是成功的。至于为什么刚开始感觉比较困惑，后来查看了一下reactos的源代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">Status <span style="color: #339933;">=</span> NtQueryValueKey<span style="color: #009900;">&#40;</span> hKey<span style="color: #339933;">,</span>
lpValueName<span style="color: #339933;">,</span>
KeyValueInformationClass<span style="color: #339933;">,</span>
KeyValueInformation<span style="color: #339933;">,</span>
BufferLength<span style="color: #339933;">,</span>
<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>ResultLength
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// A return value of STATUS_BUFFER_TOO_SMALL would mean that there</span>
<span style="color: #666666; font-style: italic;">// was not enough room for even the known (i.e. fixed length portion)</span>
<span style="color: #666666; font-style: italic;">// of the structure.</span>
<span style="color: #666666; font-style: italic;">//</span>
ASSERT<span style="color: #009900;">&#40;</span> Status <span style="color: #339933;">!=</span> STATUS_BUFFER_TOO_SMALL <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span> Status <span style="color: #339933;">==</span> STATUS_BUFFER_OVERFLOW <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span>
<span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>ARGUMENT_PRESENT<span style="color: #009900;">&#40;</span> lpData <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  STATUS_BUFFER_OVERFLOW means that the API returned all the</span>
<span style="color: #666666; font-style: italic;">//  information in the fixed portion of the structure</span>
<span style="color: #666666; font-style: italic;">//  KEY_VALUE_BASIC_INFORMATION or KEY_VALUE_PARTIAL_INFORMATION,</span>
<span style="color: #666666; font-style: italic;">//  but not the value name or the value data.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  If KeyValueInformationClass is equal to KeyValueBasicInformation</span>
<span style="color: #666666; font-style: italic;">//  then the API would return the value name. But since we are not</span>
<span style="color: #666666; font-style: italic;">//  interested in the value name (it was supplied by the client), we</span>
<span style="color: #666666; font-style: italic;">//  can assume that the API succeeded.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//  If KeyValueInformationClass is equal to KeyValuePartialInformation</span>
<span style="color: #666666; font-style: italic;">//  then the API would return the value data. But lpData == NULL</span>
<span style="color: #666666; font-style: italic;">//  means that the client is not interested on the value data, but</span>
<span style="color: #666666; font-style: italic;">//  just on its size. For this reason, we can also assume that the</span>
<span style="color: #666666; font-style: italic;">//  API succeeded.</span>
<span style="color: #666666; font-style: italic;">//</span>
Status <span style="color: #339933;">=</span> STATUS_SUCCESS<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>虽然缓冲区不够，但是此时用户并不关心数据。所以此时只返回大小就可以了。然而程序在实际的调用过程中使用的类型为KeyValuePartialInformation。所以按照通常的情况在调用的时候返回STATUS_BUFFER_OVERFLOW，但是实际的情况并不是预想的那样。在应用层程序调用完成之后会返回0xEA，而不是成功。而这个返回码却会导致应用程序不会第二次获取注册表的内容。虽然得到的数据长度是正确的，但是由于返回的错误码导致程序不再读取，代码如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">103B29F7</span>                                    FFD7            <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #00007f;">edi</span>
<span style="color: #adadad; font-style: italic;">103B29F9</span>                                    85C0            <span style="color: #00007f; font-weight: bold;">test</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B29FB</span>                                    <span style="color: #0000ff;">75</span> <span style="color: #0000ff;">48</span>           <span style="color: #00007f; font-weight: bold;">jnz</span> XiTunes_1<span style="color: #339933;">.</span>103B2A45
<span style="color: #adadad; font-style: italic;">103B29FD</span>                                    8B5424 <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A01</span>                                    <span style="color: #0000ff;">52</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">edx</span>
<span style="color: #adadad; font-style: italic;">103B2A02</span>                                    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A03</span>                                    E8 7820CDFF     <span style="color: #00007f; font-weight: bold;">call</span> iTunes_1<span style="color: #339933;">.</span>10084A80
<span style="color: #adadad; font-style: italic;">103B2A08</span>                                    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A09</span>                                    FF15 84FEEE10   <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ds</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span>&amp;lt<span style="color: #666666; font-style: italic;">;&amp;amp;KERNEL32.HeapAlloc&amp;gt;]          ; ntdll.RtlAllocateHeap</span>
<span style="color: #adadad; font-style: italic;">103B2A0F</span>                                    8B4C24 <span style="color: #0000ff;">18</span>       <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x18</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A13</span>                                    8BF0            <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A15</span>                                    8D4424 <span style="color: #0000ff;">14</span>       <span style="color: #00007f; font-weight: bold;">lea</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> <span style="color: #00007f;">ss</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x14</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #adadad; font-style: italic;">103B2A19</span>                                    <span style="color: #0000ff;">50</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
<span style="color: #adadad; font-style: italic;">103B2A1A</span>                                    <span style="color: #0000ff;">56</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">esi</span>
<span style="color: #adadad; font-style: italic;">103B2A1B</span>                                    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B2A1D</span>                                    6A <span style="color: #0000ff;">00</span>           <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0x0</span>
<span style="color: #adadad; font-style: italic;">103B2A1F</span>                                    <span style="color: #0000ff;">68</span> 088FFD10     <span style="color: #00007f; font-weight: bold;">push</span> Tunes_1<span style="color: #339933;">.</span>10FD8F08                             <span style="color: #666666; font-style: italic;">; ASCII &quot;SystemBiosVersion&quot;</span>
<span style="color: #adadad; font-style: italic;">103B2A24</span>                                    <span style="color: #0000ff;">51</span>              <span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ecx</span>
<span style="color: #adadad; font-style: italic;">103B2A25</span>                                    FFD7            <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #00007f;">edi</span></pre></td></tr></table></div>

<p>检测的Eax中的数值，如果不是0（STATUS_SUCESS）那么就不再尝试读取了，所以现在要想让他读取就只能改掉这个跳转。但是这并不是我想采用的方式。于是hook就在这个地方卡壳了，既要让程序能够获取到真正的长度还要让状态为成功。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>RtlCompareUnicodeString<span style="color: #009900;">&#40;</span>ValueName<span style="color: #339933;">,&amp;</span>MySystemBiosVersion<span style="color: #339933;">,</span>TRUE<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Length <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>DataLength<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #208080;">0x0C</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
						<span style="color: #009900;">&#123;</span>
							<span style="color: #666666; font-style: italic;">//*ResultLength = pFackSystemBiosVersion-&gt;DataLength;							memcpy(valueInfoP-&gt;Data,pFackSystemBiosVersion-&gt;Data,Length-0x0C);</span>
							valueInfoP<span style="color: #339933;">-&gt;</span>TitleIndex <span style="color: #339933;">=</span> pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>TitleIndex<span style="color: #339933;">;</span>							valueInfoP<span style="color: #339933;">-&gt;</span>Type <span style="color: #339933;">=</span> pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>Type<span style="color: #339933;">;</span>							valueInfoP<span style="color: #339933;">-&gt;</span>DataLength <span style="color: #339933;">=</span> Length<span style="color: #339933;">-</span><span style="color: #208080;">0x0C</span><span style="color: #339933;">;</span>
							<span style="color: #339933;">*</span>ResultLength <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>DataLength<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #208080;">0x0C</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							status <span style="color: #339933;">=</span> STATUS_BUFFER_OVERFLOW<span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
&nbsp;
						KdPrint<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;REG Changed:: SystemBiosVersion Befor: %ws , After: %ws <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
							valueInfoP<span style="color: #339933;">-&gt;</span>Data<span style="color: #339933;">,</span>
							pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>Data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						memcpy<span style="color: #009900;">&#40;</span>valueInfoP<span style="color: #339933;">-&gt;</span>Data<span style="color: #339933;">,</span>pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>Data<span style="color: #339933;">,</span>pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>DataLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						valueInfoP<span style="color: #339933;">-&gt;</span>TitleIndex <span style="color: #339933;">=</span> pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>TitleIndex<span style="color: #339933;">;</span>
						valueInfoP<span style="color: #339933;">-&gt;</span>Type <span style="color: #339933;">=</span> pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>Type<span style="color: #339933;">;</span>
						valueInfoP<span style="color: #339933;">-&gt;</span>DataLength <span style="color: #339933;">=</span> pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>DataLength<span style="color: #339933;">;</span>
						<span style="color: #666666; font-style: italic;">//valueInfoP-&gt;Data[1] = pFackSystemBiosVersion-&gt;Data[1];				</span>
						<span style="color: #666666; font-style: italic;">//(PKEY_VALUE_PARTIAL_INFORMATION)KeyValueInformation = valueInfoP;</span>
						<span style="color: #339933;">*</span>ResultLength <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pFackSystemBiosVersion<span style="color: #339933;">-&gt;</span>DataLength<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #208080;">0x0C</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						status <span style="color: #339933;">=</span> STATUS_SUCCESS<span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这段代码修改的方式是按照正常的读取方式修改的，但是却并没有达到想要的效果，如果谁知道为什么还望不吝赐教。</p>
<p>&nbsp;<br />
<h3>相关文章</h3>
<ul class="related_posts">
<li><a href="http://www.h4ck.org.cn/2011/05/syser-kernel-debugger-v1-99-1900-1217/" title="Syser Kernel Debugger v1.99.1900.1217" rel="bookmark inlinks">Syser Kernel Debugger v1.99.1900.1217</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-6/" title="驱动开发学习笔记（3-6）–Four-F的驱动开发教程-全功能的驱动程序分析" rel="bookmark inlinks">驱动开发学习笔记（3-6）–Four-F的驱动开发教程-全功能的驱动程序分析</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/03/vs2008-wdk/" title="VS2008+WDK 驱动开发环境设置向导" rel="bookmark inlinks">VS2008+WDK 驱动开发环境设置向导</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop1/" title="驱动开发学习笔记（1）-调试环境调试器设置【WinDbg】" rel="bookmark inlinks">驱动开发学习笔记（1）-调试环境调试器设置【WinDbg】</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-4/" title="驱动开发学习笔记（3-4）–Four-F的驱动开发教程-最简单的设备驱动程序" rel="bookmark inlinks">驱动开发学习笔记（3-4）–Four-F的驱动开发教程-最简单的设备驱动程序</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2010/04/system-version-check/" title="检测系统是否为检查版本（Checked）" rel="bookmark inlinks">检测系统是否为检查版本（Checked）</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-7/" title="驱动开发学习笔记（3-7）–Four-F的驱动开发教程-系统内存堆" rel="bookmark inlinks">驱动开发学习笔记（3-7）–Four-F的驱动开发教程-系统内存堆</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/05/windows-driver-debug-via-ida-pro/" title="IDA 6.1调试驱动" rel="bookmark inlinks">IDA 6.1调试驱动</a><span class="count">( 4 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.h4ck.org.cn/2011/09/from-regqueryvalueexa-to-zwqueryvaluekey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinDbg命令手册</title>
		<link>http://www.h4ck.org.cn/2010/04/windbg-helper/</link>
		<comments>http://www.h4ck.org.cn/2010/04/windbg-helper/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 00:26:42 +0000</pubDate>
		<dc:creator>obaby</dc:creator>
				<category><![CDATA[破解/汇编『Crack/Asm』]]></category>
		<category><![CDATA[WinDbg]]></category>
		<category><![CDATA[驱动开发]]></category>

		<guid isPermaLink="false">http://www.h4ck.org.cn/?p=1539</guid>
		<description><![CDATA[Click here to read~ 相关文章 驱动开发学习笔记（3-7）–Four-F的驱动开发教程-系统内存堆( 0 ) Syser Kernel Debugger v1.99.1900.1217( 0 ) 检测系统是否为检查版本（Checked）( 0 ) IDA 6.1调试驱动( 4 ) 键盘过滤驱动勘误《寒江独钓》( 0 ) 驱动开发学习笔记（3-4）–Four-F的驱动开发教程-最简单的设备驱动程序( 0 ) USB over Network (Server) &#038; VMWare WorkStation 7.1 BSOD( 0 ) 驱动开发学习笔记（2）-开发环境和第一个sys驱动( 0 )]]></description>
			<content:encoded><![CDATA[<p><a rel="lightbox" href="http://www.h4ck.org.cn/wp-content/uploads//2010/04/windbg.png" title="windbg"><img title="windbg" src="http://www.h4ck.org.cn/wp-content/uploads//2010/04/windbg.png" alt="" width="568" height="442" /></a></p>
<p><a href="https://docs.google.com/fileview?id=0BxbuJneToYvMNWMxMTI2ODgtZjQxMy00MDdjLWI4ZTItYTlmYzVlYzQwMmQ4&amp;hl=zh_CN">Click here to read~</a><br />
<h3>相关文章</h3>
<ul class="related_posts">
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-8/" title="驱动开发学习笔记（3-8）–Four-F的驱动开发教程-后备列表" rel="bookmark inlinks">驱动开发学习笔记（3-8）–Four-F的驱动开发教程-后备列表</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/09/from-regqueryvalueexa-to-zwqueryvaluekey/" title="从RegQueryValueExA到ZwQueryValueKey" rel="bookmark inlinks">从RegQueryValueExA到ZwQueryValueKey</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-7/" title="驱动开发学习笔记（3-7）–Four-F的驱动开发教程-系统内存堆" rel="bookmark inlinks">驱动开发学习笔记（3-7）–Four-F的驱动开发教程-系统内存堆</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-6/" title="驱动开发学习笔记（3-6）–Four-F的驱动开发教程-全功能的驱动程序分析" rel="bookmark inlinks">驱动开发学习笔记（3-6）–Four-F的驱动开发教程-全功能的驱动程序分析</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/10/inf-1/" title="驱动开发学习笔记（4-1）–INF文件-1" rel="bookmark inlinks">驱动开发学习笔记（4-1）–INF文件-1</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/05/windows-driver-debug-via-ida-pro/" title="IDA 6.1调试驱动" rel="bookmark inlinks">IDA 6.1调试驱动</a><span class="count">( 4 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/05/hello-world-2/" title="Hello Apple" rel="bookmark inlinks">Hello Apple</a><span class="count">( 2 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop2/" title="驱动开发学习笔记（2）-开发环境和第一个sys驱动" rel="bookmark inlinks">驱动开发学习笔记（2）-开发环境和第一个sys驱动</a><span class="count">( 0 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.h4ck.org.cn/2010/04/windbg-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>驱动开发学习笔记（1）-调试环境调试器设置【WinDbg】</title>
		<link>http://www.h4ck.org.cn/2009/09/driverdevelop1/</link>
		<comments>http://www.h4ck.org.cn/2009/09/driverdevelop1/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 04:37:50 +0000</pubDate>
		<dc:creator>obaby</dc:creator>
				<category><![CDATA[程序设计『Programing』]]></category>
		<category><![CDATA[WinDbg]]></category>
		<category><![CDATA[驱动开发]]></category>

		<guid isPermaLink="false">http://www.h4ck.org.cn/?p=228</guid>
		<description><![CDATA[从今天开始正式开始学习开发驱动，很多的东西可能都需要慢慢开始把。现在的感觉依旧是学艺不精。东西学的太多太杂。
 记录下这些东西怕用的时候会忘了。也不知道该怎么办了。
 1.驱动程序安装
 工具：srvinstw.exe
猛击此处下载！

工具使用简单明了，也就没不要记录了。需要注意的是在file path这里只能手工输入，如果浏览的话只能看到exe文件。]]></description>
			<content:encoded><![CDATA[<p>从今天开始正式开始学习开发驱动，很多的东西可能都需要慢慢开始把。现在的感觉依旧是学艺不精。东西学的太多太杂。<br />
记录下这些东西怕用的时候会忘了。也不知道该怎么办了。<br />
1.驱动程序安装<br />
工具：srvinstw.exe<br />
<a href="http://d.namipan.com/d/d06de549163a3305de603b260f347f8c9b18a09501530000">猛击此处下载！</a></p>
<p>工具使用简单明了，也就没不要记录了。需要注意的是在file path这里只能手工输入，如果浏览的话只能看到exe文件。<br />
<span id="more-228"></span><br />
<img title="installservice" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/installservice.jpg" alt="installservice" width="451" height="329" /></p>
<p>驱动类型为设备驱动，启动类型手动，便于自己启动或者暂停服务。安装服务后就可以用net命令启动了</p>
<p>2.单机调试工具DebugView</p>
<p><a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx">猛击此处下载！ </a></p>
<p>运行DebugView，选中选项中的Capture Kernel</p>
<p><img title="DebugView" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/DebugView.jpg" alt="DebugView" width="492" height="307" /></p>
<p>现在可以直接net start first了，first为服务名称。</p>
<p>效果图如下</p>
<p><img title="debug2" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/debug2.jpg" alt="debug2" width="759" height="506" /></p>
<p>3.双机调试WinDbg</p>
<p>环境： VMware+Windbg</p>
<p>1）.首先设置虚拟机中的调试模式：修改boot.ini修改原文件加入下面的调试信息，修改后如下：</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>boot loader<span style="">&#93;</span></span>
<span style="color: #000099;">timeout</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">30</span>
<span style="color: #000099;">default</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">multi<span style="">&#40;</span>0<span style="">&#41;</span>disk<span style="">&#40;</span>0<span style="">&#41;</span>rdisk<span style="">&#40;</span>0<span style="">&#41;</span>partition<span style="">&#40;</span>1<span style="">&#41;</span>\WINDOWS</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>operating systems<span style="">&#93;</span></span>
multi<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>disk<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>rdisk<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>partition<span style="">&#40;</span><span style="">1</span><span style="">&#41;</span>\WINDOWS<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Microsoft Windows XP Professional&quot;</span> /noexecute<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">optin /fastdetect</span>
multi<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>disk<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>rdisk<span style="">&#40;</span><span style="">0</span><span style="">&#41;</span>partition<span style="">&#40;</span><span style="">1</span><span style="">&#41;</span>\WINDOWS<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Microsoft Windows XP Professional&quot;</span> /noexecute<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">optin /fastdetect /debug /debugport=com1 /baudrate=115200</span></pre></div></div>

<p>2）.下载安装WinDbg，<a href="http://msdl.microsoft.com/download/symbols/debuggers/dbg_x86_6.11.1.404.msi">猛击此处下载Windbg！</a><br />
修改Windbg启动参数，这里直接创建一个bat文件，将下面的内容写入就可以了。</p>
<p>windbg.exe -b -k com:port=\\.\pipe\com_1,baud=115200,pipe</p>
<p>3）.虚拟机管道设置</p>
<p>修改虚拟机的Setting选项，不要启动虚拟机Edit virtual machine settings&gt;&gt;hardware&gt;&gt;add&gt;&gt;Add</p>
<p>Add Hardware Wizard&gt;&gt;HardWare types&gt;&gt;Serial Port(串口)&gt;&gt;Output to named pipe.</p>
<p><img title="pipe" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/pipe.jpg" alt="pipe" width="625" height="481" /></p>
<p>最后一部需要修改第三个框内为The other end is an application。如下图</p>
<p><img title="pipe2" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/pipe2.jpg" alt="pipe2" width="629" height="477" /></p>
<p>到此位置设置就算完成了，在启动虚拟机后选择调试模式，然后运行建立的批处理来启动WinDbg。</p>
<p>程序中断在了驱动中的int3 断点。F5继续运行就可以启动系统了。</p>
<p>符号表路径设置</p>
<p>srv*c:\symbols*http://msdl.microsoft.com/download/symbols;C:\DDK\objchk_wxp_x86\i386</p>
<p>分号后面为自己写的驱动的对应路径。</p>
<p>原源码路径设置为自己驱动的路径就可以了。左侧的代码为书中的源代码。</p>
<p><img class="alignleft size-large wp-image-235" title="debug3" src="http://www.h4ck.org.cn/wp-content/uploads/2009/09/debug3-1024x617.jpg" alt="debug3" width="1024" height="617" /><br />
<h3>相关文章</h3>
<ul class="related_posts">
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-3/" title="驱动开发学习笔记（3-3）–Four-F的驱动开发教程-服务" rel="bookmark inlinks">驱动开发学习笔记（3-3）–Four-F的驱动开发教程-服务</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-2/" title="驱动开发学习笔记（3-2）--Four-F的驱动开发教程-内核模式驱动程序基础" rel="bookmark inlinks">驱动开发学习笔记（3-2）&#8211;Four-F的驱动开发教程-内核模式驱动程序基础</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2010/03/vs2008-wdk-ddkwizard-win-7/" title="VS2008 、WDK 和DDKWizard搭建Win 7驱动开发环境" rel="bookmark inlinks">VS2008 、WDK 和DDKWizard搭建Win 7驱动开发环境</a><span class="count">( 5 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/06/advanced-windows-kernel-debugging-with-vmware-and-ida%e2%80%99s-gdb-debugger/" title="使用VMWare GDB和IDA调试Windows内核" rel="bookmark inlinks">使用VMWare GDB和IDA调试Windows内核</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2009/09/driverdevelop3-1/" title="驱动开发学习笔记（3-1）--Four-F的驱动开发教程-前言" rel="bookmark inlinks">驱动开发学习笔记（3-1）&#8211;Four-F的驱动开发教程-前言</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2010/04/system-version-check/" title="检测系统是否为检查版本（Checked）" rel="bookmark inlinks">检测系统是否为检查版本（Checked）</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2011/01/easysys-0-3-2-6-for-vs2008wdk7/" title="EasySYS 0.3.2.6 for vs2008/WDK7" rel="bookmark inlinks">EasySYS 0.3.2.6 for vs2008/WDK7</a><span class="count">( 0 )</span></li>
<li><a href="http://www.h4ck.org.cn/2010/11/win7-remote-debug-via-windbg/" title="Win7 Remote Debug via WinDbg" rel="bookmark inlinks">Win7 Remote Debug via WinDbg</a><span class="count">( 0 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.h4ck.org.cn/2009/09/driverdevelop1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

