<?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>零度x&#039;s blog &#187; 字符串</title>
	<atom:link href="http://www.lingdux.com/tag/%e5%ad%97%e7%ac%a6%e4%b8%b2/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lingdux.com</link>
	<description>Take it slowly,it&#039;s OK,it&#039;s OK.</description>
	<lastBuildDate>Wed, 04 Aug 2010 01:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>驱动学习笔记&#8211;字符串</title>
		<link>http://www.lingdux.com/2009/23.html</link>
		<comments>http://www.lingdux.com/2009/23.html#comments</comments>
		<pubDate>Tue, 26 May 2009 20:08:47 +0000</pubDate>
		<dc:creator>零度x</dc:creator>
				<category><![CDATA[驱动学习]]></category>
		<category><![CDATA[字符串]]></category>
		<category><![CDATA[学习]]></category>
		<category><![CDATA[程序]]></category>
		<category><![CDATA[笔记]]></category>
		<category><![CDATA[编写]]></category>
		<category><![CDATA[驱动]]></category>

		<guid isPermaLink="false">http://www.lingdux.com/?p=23</guid>
		<description><![CDATA[在驱动编程中，处理字符串最好用UNICODE_STRING，UNICODE_STRING是一个结构，查看MSDN如下：

typedef struct _UNICODE_STRING{

USHORT length;\\字符串的长度

<span class="readmore"><a href="http://www.lingdux.com/2009/23.html" title="驱动学习笔记&#8211;字符串">阅读全文——共1424字</a></span>]]></description>
			<content:encoded><![CDATA[<p>在驱动编程中，处理字符串最好用UNICODE_STRING，UNICODE_STRING是一个结构，查看MSDN如下：</p>
<p>typedef struct _UNICODE_STRING{</p>
<p>USHORT length;\\字符串的长度</p>
<p>USHORT MaxnumLength;\\整个缓冲区的最大长度</p>
<p>PWSTR Buffer;\\缓冲</p>
<p>}UNICODE_STRING *PUNICODE_STRING;</p>
<p>字符串不是以00结尾，而是用一个结构来指定字符串的长度。</p>
<p>DDK提供了一个函数用于初始化字符串</p>
<p>VOID RtlInitUnicodeString(</p>
<p>IN OUT PUNICODE_STRING DestiantionString,//定义的字符串结构指针</p>
<p>IN PCWSTR SourceString//字符串</p>
<p>);</p>
<p><span id="more-23"></span></p>
<p>创建好一个工程框架，在框架中加入下面代码：</p>
<p>UNICODE_STRING mystr;//定义字符串</p>
<p>RtlInitUnicodeString(&amp;mystr,L&#8221;<a href="http://www.lingdux.com" target="_blank">www.lingdux.com</a>&#8220;);//字符串初始化</p>
<p>DbgPrint(&#8220;%wZ&#8221;,&amp;mystr);//打印字符串</p>
<p>加载驱动，用DEBUG View 成功看到结果<a href="http://www.lingdux.com" target="_blank">www.lingdux.com</a></p>
<p>接下来在定义一个字符串结构,把字符串copy到新的结构</p>
<p>要为新的字符串初始化，并且分配空间</p>
<p>ddk提供了一个函数来分配空间</p>
<p>PVOID ExAllocatePool(<br />
    IN POOL_TYPE  <em>PoolType</em>,//分页方式<br />
    IN SIZE_T  <em>NumberOfBytes//大小</em><br />
    );</p>
<p>用下面的函数copy字符串</p>
<p>VOID RtlInitUnicodeString(</p>
<p>IN OUT PUNICODE_STRING destinationString,//目标字符串指针</p>
<p>IN PUNICODE_STRING SourceString//源字符串指针</p>
<p>);</p>
<p>UNICODE_STRING mynewstr;//定义字符串</p>
<p>mynewstr.Buffer=(PWSTR)ExAllocatePool(PagedPool,256);//分配内存空间</p>
<p>RtlInitUnicodeString(&amp;mynewstr,&amp;mystr);//copy字符串</p>
<p>DbgPrint(&#8220;%wZ&#8221;,&amp;mynewstr);//打印字符串</p>
<p>载入驱动后用Debug Viwe成功截获到两个<a href="http://www.lingdux.com">www.lingdux.com</a></p>
<p>最终代码如下</p>
<p>#include &lt;ntddk.h&gt;<br />
VOID Unload(IN PDRIVER_OBJECT DriverObject)<br />
{<br />
}<br />
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)<br />
{<br />
 UNICODE_STRING mystr;<br />
 UNICODE_STRING mynewstr;<br />
 RtlInitUnicodeString(&amp;mystr,L&#8221;<a href="http://www.lingdux.com" target="_blank">www.lingdux.com</a>&#8220;);<br />
 DbgPrint(&#8220;%wZ&#8221;,&amp;mystr);<br />
 mynewstr.Buffer=(PWSTR)ExAllocatePool(PagedPool,256);<br />
 RtlCopyUnicodeString(&amp;mynewstr,&amp;mystr);<br />
 DbgPrint(&#8220;%wZ&#8221;,&amp;mynewstr);<br />
 DriverObject-&gt;DriverUnload=Unload;<br />
 return STATUS_SUCCESS;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lingdux.com/2009/23.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
