<?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/%e7%a8%8b%e5%ba%8f/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>
		<item>
		<title>驱动学习笔记&#8211;&#8221;hello world&#8221;</title>
		<link>http://www.lingdux.com/2009/17.html</link>
		<comments>http://www.lingdux.com/2009/17.html#comments</comments>
		<pubDate>Mon, 25 May 2009 19:56:59 +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>

		<guid isPermaLink="false">http://www.lingdux.com/?p=17</guid>
		<description><![CDATA[编译环境用xp下VC6+DDK

新建一个文件夹当作工程目录，路径是E:\lingdux\

从别的工程copy过来两个文件，

<span class="readmore"><a href="http://www.lingdux.com/2009/17.html" title="驱动学习笔记&#8211;&#8221;hello world&#8221;">阅读全文——共1121字</a></span>]]></description>
			<content:encoded><![CDATA[<p>编译环境用xp下VC6+DDK</p>
<p>新建一个文件夹当作工程目录，路径是E:\lingdux\</p>
<p>从别的工程copy过来两个文件，</p>
<p>一个是makefile，它用来指定文件之间的依赖关系，确定项目中哪些文件时需要重新编译的，那些事已经编译过的。里面的内容不用改，直接默认就OK</p>
<p>另一个是source，它用来保存一些配置信息，内容如下：</p>
<p>TARGETNAME=lingdux  这句用来指定目标程序存放的路径</p>
<p>TARGETTYPE=DRIVER 这句是指定目标类型，DRIVER为驱动程序</p>
<p>TARGETPATH=Driver 这句指定编译时的中间文件存放的路径</p>
<p>SOURCES=lingdux.c  这句指定了源文件</p>
<p>在工程目录想创建一个空文件命名lingdux.c，双击用VC6打开，开始写代码～！</p>
<p>遵循C语言，只有一个入口函数DriverEntry，有两个参数</p>
<p>NTSTATUS Driver Entry(IN PDRIVER_OBJECT DriverObject, 第一个是PDRIVER_OBJECT类型 系统进程调用的驱动对象<br />
                            IN OUNICODE_STRING RegistryPath)  第二个是IN OUNICODE_STRING类型  字符串类型，注册路径</p>
<p>返回值类型为NTSTATUS，系统状态。</p>
<p>输出函数为DbgPrint()，包含的头文件是ntddk.h <span id="more-17"></span></p>
<p>编写完成后，发现这个驱动程序没有退出功能,系统加载后不能停止，重新启动后才能再次加载，不利于调试，下面就添加一个退出功能。</p>
<p>DriverObject-&gt;DriverUnload=Unload 为驱动对象注册一个卸载例程指定一个空函数</p>
<p>在驱动停止的时候被调用，用于删除一些设备对象，符号链接，释放驱动加载的资源。</p>
<p>VOID Unload(IN PDRIVER_OBJECT DriverObject)</p>
<p>{</p>
<p>}</p>
<p>完整代码如下：</p>
<p>#include &lt;ntddk.h&gt;<br />
VOID Unload(IN PDRIVER_OBJECT DriverObject)<br />
{<br />
}</p>
<p>NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)<br />
{<br />
 DriverObject-&gt;DriverUnload=Unload;<br />
 DbgPrint(&#8220;Hello World!&#8221;);<br />
 return STATUS_SUCCESS;<br />
}</p>
<p>保存以上代码，然后打开DDK，路径选择工程目录，运行build命令，</p>
<p>编译出来的驱动文件为E:\lingdux\driver\i386\lingdux.sys</p>
<p>用coderui的驱动加载工具加载</p>
<p><img class="aligncenter size-full wp-image-18" title="jiazai" src="http://www.lingdux.com/wp-content/uploads/2009/05/jiazai.jpg" alt="jiazai" width="441" height="164" /></p>
<p>用debug viwe成功截获到输出</p>
<p><img class="aligncenter size-full wp-image-19" title="jiehuo" src="http://www.lingdux.com/wp-content/uploads/2009/05/jiehuo.jpg" alt="jiehuo" width="500" height="302" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lingdux.com/2009/17.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
