<?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>随.心.所.记 &#187; 异常</title>
	<atom:link href="http://www.realdodo.com/tag/%e5%bc%82%e5%b8%b8/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.realdodo.com</link>
	<description>享受生活的乐趣与烦恼</description>
	<lastBuildDate>Fri, 25 Jun 2010 18:49:41 +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>彻底杜绝可恶的缓冲区溢出错误！</title>
		<link>http://www.realdodo.com/2007/02/16/164/</link>
		<comments>http://www.realdodo.com/2007/02/16/164/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 15:13:00 +0000</pubDate>
		<dc:creator>realdodo</dc:creator>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[内存]]></category>
		<category><![CDATA[异常]]></category>
		<category><![CDATA[程序]]></category>

		<guid isPermaLink="false">http://www.realdodo.com/2007/02/16/164/</guid>
		<description><![CDATA[缓冲区溢出是困扰程序员多年的痼疾，特别是使用C语言的程序员，面对毫无保证可言的内存指针，既不能实时检查内存区域的真实大小，也不能避免内存使用者有意或无意的缓冲区溢出操作，实在是非常的无奈。就算是C++的程序员，其实境遇也好不到哪里去，比如STL里的vector，在使用operator []和迭代器来访问数据成员时同样是得不到保证的，一切只能靠自觉。 那么，在数据安全性要求非常高的情况下，有没有办法彻底杜绝这种缓冲区溢出问题呢？值得欣慰的是，Windows 2000及以上操作系统提供的内存访问控制机制能帮忙解决问题。 以下，我实现了一个简单地C++类来封装一段绝对安全的内存，由于其中并没有真正依赖任何的C++特性，改装成C函数也是轻而易举的事情，所以实际上，这是Windows平台上的一种通用解决方案。 首先我们来回顾一下Windows的内存保护机制。 Windows采用虚拟地址的方式把真实的物理内存空间划分成很多的虚拟的段，每一个段的大小固定（典型值为0&#215;1000），并可以为其设置相应的访问权限。默认的内存访问权限是可读写不可执行，不过我们可以使用VirtualAlloc或VirtualProtect来改变这种权限，例如改成完全不能访问或可执行等等，具体可以参考MSDN中对这两个函数的说明。如果将内存的访问权限设为PAGE_NOACCESS，那么任何针对这个区域的读写操作都会抛出异常，也就是大家常见的“无法访问”异常。这个异常可以用C++的try&#8230;catch(&#8230;)&#8230;捕捉，也可以用__try&#8230;__except(&#8230;)&#8230;捕捉（这个是推荐用法，但是用起来麻烦），在C语言里还可以用setjmp()/longjmp()来检测，所以只要捕到这个异常也就检测出缓冲区溢出问题，接下来如何处理就完全由程序员自己控制了。 特别值得一提的是VirtualAlloc的一些用法和注意事项。通过改变第三个参数flAllocationType，它不但可以用来申请内存，还可以保留一段内存为未来使用。不过VirtualAlloc并不是万能的，它申请空间时会自动根据段的大小进行对齐，而且访问权限也只能针对一个段来设定，而不能给更小的内存区域设定访问权限。 所以为了使用不可访问的内存作为缓冲区的保护区域，在实际使用时，不可访问区域大小为段的大小，权限设置为PAGE_NOACCESS，而中间一段区域权限设置为PAGE_READWRITE，其中可读写缓冲区的尾部与不可访问区域相接，头部则用0xDD填充，作为保护。将可读写的缓冲区尾部与不可访问区域相接是考虑到缓冲区溢出多发生在尾部，这也意味着，头部的缓冲区溢出问题必须用手动检查的方式来验证。 在这里，不能不说一下这种方案的缺陷：会造成较大的内存损耗。在最坏的情况下，且段的大小为0&#215;1000（4K），这种方案将多消耗约12KB的内存用于保护可读写区域，所以它只适合于保护最为核心、最为关键的内存区域，而不能像new一样随意使用。 我将这些功能封装在一个SafeMemory类中，它的使用方法如下： SafeMemory buffer(3000); // Alloc 3000 bytes safe memory. try &#8230;{ foo(buffer.Get()); // Some function use the buffer. buffer.Validate(); // Validate the header. } catch (&#8230;) &#8230;{ // Buffer over-run! } 以下是完整的源代码。 首先是SafeMemory.h #ifndef _SAFE_MEMORY_H_ #define _SAFE_MEMORY_H_ /**//** Manage the memory and make no-access memory gaps before and after the buffer. */ class SafeMemory &#8230;{ static const BYTE DangerousDataValue = 0xDD; /**//**&#60; The old value in dangerous data area, which is writable but invalid. */ public: explicit SafeMemory(size_t size); ~SafeMemory(); /**//** [...]]]></description>
			<content:encoded><![CDATA[<p>缓冲区溢出是困扰程序员多年的痼疾，特别是使用C语言的程序员，面对毫无保证可言的内存指针，既不能实时检查内存区域的真实大小，也不能避免内存使用者有意或无意的缓冲区溢出操作，实在是非常的无奈。就算是C++的程序员，其实境遇也好不到哪里去，比如STL里的vector，在使用operator []和迭代器来访问数据成员时同样是得不到保证的，一切只能靠自觉。<br />
那么，在数据安全性要求非常高的情况下，有没有办法彻底杜绝这种缓冲区溢出问题呢？值得欣慰的是，Windows 2000及以上操作系统提供的内存访问控制机制能帮忙解决问题。<br />
以下，我实现了一个简单地C++类来封装一段绝对安全的内存，由于其中并没有真正依赖任何的C++特性，改装成C函数也是轻而易举的事情，所以实际上，这是Windows平台上的一种通用解决方案。</p>
<p>首先我们来回顾一下Windows的内存保护机制。<br />
Windows采用虚拟地址的方式把真实的物理内存空间划分成很多的虚拟的段，每一个段的大小固定（典型值为0&#215;1000），并可以为其设置相应的访问权限。默认的内存访问权限是可读写不可执行，不过我们可以使用VirtualAlloc或VirtualProtect来改变这种权限，例如改成完全不能访问或可执行等等，具体可以参考MSDN中对这两个函数的说明。如果将内存的访问权限设为PAGE_NOACCESS，那么任何针对这个区域的读写操作都会抛出异常，也就是大家常见的“无法访问”异常。这个异常可以用C++的try&#8230;catch(&#8230;)&#8230;捕捉，也可以用__try&#8230;__except(&#8230;)&#8230;捕捉（这个是推荐用法，但是用起来麻烦），在C语言里还可以用setjmp()/longjmp()来检测，所以只要捕到这个异常也就检测出缓冲区溢出问题，接下来如何处理就完全由程序员自己控制了。<br />
特别值得一提的是VirtualAlloc的一些用法和注意事项。通过改变第三个参数flAllocationType，它不但可以用来申请内存，还可以保留一段内存为未来使用。不过VirtualAlloc并不是万能的，它申请空间时会自动根据段的大小进行对齐，而且访问权限也只能针对一个段来设定，而不能给更小的内存区域设定访问权限。</p>
<p>所以为了使用不可访问的内存作为缓冲区的保护区域，在实际使用时，不可访问区域大小为段的大小，权限设置为PAGE_NOACCESS，而中间一段区域权限设置为PAGE_READWRITE，其中可读写缓冲区的尾部与不可访问区域相接，头部则用0xDD填充，作为保护。将可读写的缓冲区尾部与不可访问区域相接是考虑到缓冲区溢出多发生在尾部，这也意味着，头部的缓冲区溢出问题必须用手动检查的方式来验证。</p>
<p>在这里，不能不说一下这种方案的缺陷：会造成较大的内存损耗。在最坏的情况下，且段的大小为0&#215;1000（4K），这种方案将多消耗约12KB的内存用于保护可读写区域，所以它只适合于保护最为核心、最为关键的内存区域，而不能像new一样随意使用。</p>
<p>我将这些功能封装在一个SafeMemory类中，它的使用方法如下：</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: #e6e6e6 none repeat scroll 0% 50%; width: 95%;">
<div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #000000">SafeMemory buffer(</span><span style="COLOR: #000000">3000</span><span style="COLOR: #000000">); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Alloc 3000 bytes safe memory.</span><span style="COLOR: #008000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br />
<img id="_64_173_Open_Image" onclick="this.style.display='none'; document.getElementById('_64_173_Open_Text').style.display='none'; document.getElementById('_64_173_Closed_Image').style.display='inline'; document.getElementById('_64_173_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_64_173_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_64_173_Closed_Text').style.display='none'; document.getElementById('_64_173_Open_Image').style.display='inline'; document.getElementById('_64_173_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_64_173_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_64_173_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> foo(buffer.Get()); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Some function use the buffer.</span><span style="COLOR: #008000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /></span><span style="COLOR: #000000"> buffer.Validate(); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Validate the header.</span><span style="COLOR: #008000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" /></span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (&#8230;)<br />
<img id="_187_213_Open_Image" onclick="this.style.display='none'; document.getElementById('_187_213_Open_Text').style.display='none'; document.getElementById('_187_213_Closed_Image').style.display='inline'; document.getElementById('_187_213_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_187_213_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_187_213_Closed_Text').style.display='none'; document.getElementById('_187_213_Open_Image').style.display='inline'; document.getElementById('_187_213_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_187_213_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_187_213_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> Buffer over-run!</span><span style="COLOR: #008000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" /></span><span style="COLOR: #000000">}</span></span></div>
</div>
<p>以下是完整的源代码。<br />
首先是SafeMemory.h</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: #e6e6e6 none repeat scroll 0% 50%; width: 95%;">
<div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #000000"><span style="COLOR: #0000ff">#ifndef</span> _SAFE_MEMORY_H_<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> _SAFE_MEMORY_H_</span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img id="_49_135_Open_Image" onclick="this.style.display='none'; document.getElementById('_49_135_Open_Text').style.display='none'; document.getElementById('_49_135_Closed_Image').style.display='inline'; document.getElementById('_49_135_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_49_135_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_49_135_Closed_Text').style.display='none'; document.getElementById('_49_135_Open_Image').style.display='inline'; document.getElementById('_49_135_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_49_135_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_49_135_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> Manage the memory and make no-access memory gaps before</span></span></div>
<div><span id="_49_135_Open_Text"><span style="COLOR: #008000"> and after the buffer.<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" /> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> SafeMemory<br />
<img id="_154_858_Open_Image" onclick="this.style.display='none'; document.getElementById('_154_858_Open_Text').style.display='none'; document.getElementById('_154_858_Closed_Image').style.display='inline'; document.getElementById('_154_858_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_154_858_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_154_858_Closed_Text').style.display='none'; document.getElementById('_154_858_Open_Image').style.display='inline'; document.getElementById('_154_858_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_154_858_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_154_858_Open_Text"><span style="COLOR: #000000">{<br />
<img id="_206_336_Open_Image" onclick="this.style.display='none'; document.getElementById('_206_336_Open_Text').style.display='none'; document.getElementById('_206_336_Closed_Image').style.display='inline'; document.getElementById('_206_336_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_206_336_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_206_336_Closed_Text').style.display='none'; document.getElementById('_206_336_Open_Image').style.display='inline'; document.getElementById('_206_336_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> BYTE DangerousDataValue </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0xDD</span><span style="COLOR: #000000">; </span><span id="_206_336_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_206_336_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*&lt; The old value in dangerous data area,<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" align="top" /> which is writable but invalid. </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">explicit</span><span style="COLOR: #000000"> SafeMemory(size_t size);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">SafeMemory();<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img id="_409_484_Open_Image" onclick="this.style.display='none'; document.getElementById('_409_484_Open_Text').style.display='none'; document.getElementById('_409_484_Closed_Image').style.display='inline'; document.getElementById('_409_484_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_409_484_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_409_484_Closed_Text').style.display='none'; document.getElementById('_409_484_Open_Image').style.display='inline'; document.getElementById('_409_484_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> </span><span id="_409_484_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_409_484_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> Get safe memory.<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> @return The pointer to safe memory.<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" align="top" /> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> Get()<br />
<img id="_507_559_Open_Image" onclick="this.style.display='none'; document.getElementById('_507_559_Open_Text').style.display='none'; document.getElementById('_507_559_Closed_Image').style.display='inline'; document.getElementById('_507_559_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_507_559_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_507_559_Closed_Text').style.display='none'; document.getElementById('_507_559_Open_Image').style.display='inline'; document.getElementById('_507_559_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> </span><span id="_507_559_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_507_559_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> buffer_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> pageSize_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> offset_;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" align="top" /> }</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Validate() </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> (&#8230;);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br />
<img id="_630_659_Open_Image" onclick="this.style.display='none'; document.getElementById('_630_659_Open_Text').style.display='none'; document.getElementById('_630_659_Closed_Image').style.display='inline'; document.getElementById('_630_659_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_630_659_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_630_659_Closed_Text').style.display='none'; document.getElementById('_630_659_Open_Image').style.display='inline'; document.getElementById('_630_659_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> BYTE </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> buffer_; </span><span id="_630_659_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_630_659_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*&lt; Virtual memory buffer. </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img id="_686_729_Open_Image" onclick="this.style.display='none'; document.getElementById('_686_729_Open_Text').style.display='none'; document.getElementById('_686_729_Closed_Image').style.display='inline'; document.getElementById('_686_729_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_686_729_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_686_729_Closed_Text').style.display='none'; document.getElementById('_686_729_Open_Image').style.display='inline'; document.getElementById('_686_729_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> DWORD offset_; </span><span id="_686_729_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_686_729_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*&lt; Offset from the beginning of a page. </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img id="_756_805_Open_Image" onclick="this.style.display='none'; document.getElementById('_756_805_Open_Text').style.display='none'; document.getElementById('_756_805_Closed_Image').style.display='inline'; document.getElementById('_756_805_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_756_805_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_756_805_Closed_Text').style.display='none'; document.getElementById('_756_805_Open_Image').style.display='inline'; document.getElementById('_756_805_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> DWORD totalPageCnt_; </span><span id="_756_805_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_756_805_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*&lt; Total page number of read-writable buffer. </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img id="_832_856_Open_Image" onclick="this.style.display='none'; document.getElementById('_832_856_Open_Text').style.display='none'; document.getElementById('_832_856_Closed_Image').style.display='inline'; document.getElementById('_832_856_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_832_856_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_832_856_Closed_Text').style.display='none'; document.getElementById('_832_856_Open_Image').style.display='inline'; document.getElementById('_832_856_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> DWORD pageSize_; </span><span id="_832_856_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_832_856_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*&lt; System page size. </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" />}</span></span><span style="COLOR: #000000">;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> ifndef _SAFE_MEMORY_H_</span></div>
</div>
<p>然后是SafeMemory.cpp</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: #e6e6e6 none repeat scroll 0% 50%; width: 95%;">
<div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #000000"><span style="COLOR: #0000ff">#include</span> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">windows.h</span><span style="COLOR: #000000">&gt;<br />
</span><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #000000"><span style="COLOR: #0000ff">#include</span> </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">tchar.h</span><span style="COLOR: #000000">&gt;</span><br />
<span style="COLOR: #000000"><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #0000ff">#include</span> </span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">SafeMemory.h</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" />SafeMemory::SafeMemory(size_t size)<br />
<img id="_82_702_Open_Image" onclick="this.style.display='none'; document.getElementById('_82_702_Open_Text').style.display='none'; document.getElementById('_82_702_Closed_Image').style.display='inline'; document.getElementById('_82_702_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_82_702_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_82_702_Closed_Text').style.display='none'; document.getElementById('_82_702_Open_Image').style.display='inline'; document.getElementById('_82_702_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_82_702_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_82_702_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> SYSTEM_INFO info;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> ::GetSystemInfo(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">info);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> pageSize_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> info.dwPageSize;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> totalPageCnt_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> size </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"> pageSize_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> offset_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> totalPageCnt_ </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pageSize_ </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> size;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> buffer_ </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> reinterpret_cast</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">BYTE</span><span style="COLOR: #000000">*&gt;</span><span style="COLOR: #000000">(<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> ::VirtualAlloc(NULL,<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> pageSize_ </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (totalPageCnt_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">),<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> MEM_RESERVE,<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> PAGE_NOACCESS));<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> ::VirtualAlloc(buffer_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> pageSize_, pageSize_ </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> totalPageCnt_, </span></span></div>
<div><span id="_82_702_Open_Text"><span style="COLOR: #000000"> MEM_COMMIT, PAGE_READWRITE);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> ::FillMemory(buffer_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> pageSize_,<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> offset_,<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> DangerousDataValue);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" />}</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" />SafeMemory::</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">SafeMemory()<br />
<img id="_731_807_Open_Image" onclick="this.style.display='none'; document.getElementById('_731_807_Open_Text').style.display='none'; document.getElementById('_731_807_Closed_Image').style.display='inline'; document.getElementById('_731_807_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_731_807_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_731_807_Closed_Text').style.display='none'; document.getElementById('_731_807_Open_Image').style.display='inline'; document.getElementById('_731_807_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_731_807_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_731_807_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> ::VirtualFree(buffer_, pageSize_ </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> (totalPageCnt_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">), MEM_RELEASE);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" />}</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img id="_810_891_Open_Image" onclick="this.style.display='none'; document.getElementById('_810_891_Open_Text').style.display='none'; document.getElementById('_810_891_Closed_Image').style.display='inline'; document.getElementById('_810_891_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_810_891_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_810_891_Closed_Text').style.display='none'; document.getElementById('_810_891_Open_Image').style.display='inline'; document.getElementById('_810_891_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_810_891_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="_810_891_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> Validate the memory. If the dangerous data is modified, throw exception.<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" /> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> SafeMemory::Validate() </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> (&#8230;)<br />
<img id="_933_1227_Open_Image" onclick="this.style.display='none'; document.getElementById('_933_1227_Open_Text').style.display='none'; document.getElementById('_933_1227_Closed_Image').style.display='inline'; document.getElementById('_933_1227_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" alt="" align="top" /><img id="_933_1227_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_933_1227_Closed_Text').style.display='none'; document.getElementById('_933_1227_Open_Image').style.display='inline'; document.getElementById('_933_1227_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" alt="" align="top" /></span><span id="_933_1227_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_933_1227_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> BYTE </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> buffer_ </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> pageSize_;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (DWORD i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> offset_; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)<br />
<img id="_1021_1225_Open_Image" onclick="this.style.display='none'; document.getElementById('_1021_1225_Open_Text').style.display='none'; document.getElementById('_1021_1225_Closed_Image').style.display='inline'; document.getElementById('_1021_1225_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_1021_1225_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1021_1225_Closed_Text').style.display='none'; document.getElementById('_1021_1225_Open_Image').style.display='inline'; document.getElementById('_1021_1225_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> </span><span id="_1021_1225_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_1021_1225_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (DangerousDataValue </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> buffer[i])<br />
<img id="_1076_1219_Open_Image" onclick="this.style.display='none'; document.getElementById('_1076_1219_Open_Text').style.display='none'; document.getElementById('_1076_1219_Closed_Image').style.display='inline'; document.getElementById('_1076_1219_Closed_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" alt="" align="top" /><img id="_1076_1219_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('_1076_1219_Closed_Text').style.display='none'; document.getElementById('_1076_1219_Open_Image').style.display='inline'; document.getElementById('_1076_1219_Open_Text').style.display='inline';" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" alt="" align="top" /> </span><span id="_1076_1219_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">&#8230;</span><span id="_1076_1219_Open_Text"><span style="COLOR: #000000">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> This code will generate a memory access exception.</span><span style="COLOR: #008000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /></span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> static_cast</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">DWORD</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(buffer_[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" alt="" align="top" /> </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" align="top" /> }</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" align="top" /> }</span></span><span style="COLOR: #000000"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" alt="" align="top" />}</span></span></div>
</div>
<p>所有代码在Windows XP SP2 + Visual Studio.Net 2003下面调试通过。</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save">分享/收藏</a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.realdodo.com/2007/02/16/164/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
