<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Yonsm.NET]]></title> 
<link>HTTP://WWW.Yonsm.NET/index.php</link> 
<description><![CDATA[SHARE YONSM'S IDEAS]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Yonsm.NET]]></copyright>
<item>
<link>HTTP://WWW.Yonsm.NET/read.php?13</link>
<title><![CDATA[CoBind - 拨通多个 ADSL 连接，大幅度提升网络速度]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Mon, 31 Aug 2009 09:15:34 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?13</guid> 
<description>
<![CDATA[ 
	<span style="color: #BBBBBB;">副题：在Windows Socket SPI 层实现客户端负载均衡<br/>翻出2005年的帖子，发现在今天看来依然还是好有创意啊……</span><br/><br/><p>程序实现了轮番邦定RAS拨号连接IP地址。要使CoBind生效，必须先注册它，且必须先按亮ScrollLock键。</p><p>代码示例，演示了Windows Socket SPI的使用，仅供参考： <a href="up/CoBind%201.0.54.242.rar"><font color="#ff6000">CoBind 1.0.54.242</font></a></p><p>有关WSP SPI的文章，请参看：<a href="http://www.xfocus.net/articles/200304/518.html"><font color="#8000ff">基于SPI的数据报过滤原理与实现</font></a></p><br/><br/>我这里指的是杭州的 ADSL，特点是，不支持绑定多重连接到同一个 IP 地址。但是可<span style="color: #FF0000;">以同一个用户名密码拨通多个连接，且不限速</span>（或能提供比一个连接更大的速度）。<br/><br/><a href="HTTP://WWW.Yonsm.NET/attachment.php?fid=33" target="_blank"><img src="HTTP://WWW.Yonsm.NET/attachment.php?fid=33" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>大致步骤：<br/>1.安装 RASPPPoE，设置 PPPoE 协议属性（本地连接->属性，PPPoE 属性），启用多个“线数（WAN 端点）”（虚拟设备），如4个。重新启动系统。<br/>2.建立多个 PPPoE 拨号连接，每个都能拨成功，此时已获取多个IP地址。但是，这并没有任何用处，因为绝大部分软件作为客户端上网时，都不会指定绑定某个 IP 地址的，系统总是选择最后拨通的那个连接来访问。气死！<br/>为了解决问题，就要使每个连接之前，自动轮番绑定所有可能的 IP。<br/>3.注册 CoBind.dll （RegSvr32.exe CoBind.dll），按亮 ScrollLock，CoBind 在每个程序访问网络时会弹出对话框提示，按需选择即可（默认一般确定即可）。（按亮ScrollLock仅仅是允许CoBind弹出提示，设置好后，下次无论是否按亮，均可生效）<br/>4.要卸载，请注销CoBind.dll（RegSvr32.exe /u CoBind.dll）。<br/><br/><br/>感谢 風の語 提供的方法，直接用Windows自带的PPPoE就拿拨通多个连接，方便多了。不用装 RasPPPoE 之类的:<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>发现在windows 2003可以不用装RASPPPoE的方法，（xp估计也可以，没试过）修改注册表里HKEY_LOCAL_MACHINE&#92;SYSTEM&#92;ControlSet001&#92;Control&#92;Class&#92;&#123;4D36E972-E325-11CE-BFC1-08002bE10318&#125;&#92;0004<br/>下的WanEndpoints的数值，修改为99，就可以同时连接99个PPPOE拨号，不过这么多个连接CPU要顶得住<br/>重新启动就可以在系统建立并连接多个PPPOE拨号了。<br/></div></div><br/><br/><br/><br/><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E6%258A%2580%25E5%25B7%25A7" rel="tag">技巧</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?448</link>
<title><![CDATA[调用 UnRAR.dll 解压缩RAR文件]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sat, 27 Dec 2008 16:35:39 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?448</guid> 
<description>
<![CDATA[ 
	CeleCmd 中把 TGZ 的解压缩功能用 RAR 解压缩替换了，发现RAR解压缩的代码非常简单。<br/><br/><div class="code"><br/>#include &quot;UnRAR.h&quot;<br/>#ifdef _UNICODE<br/>#define _ArcName ArcNameW<br/>#define STR_RARProcessFile TEXT(&quot;RARProcessFileW&quot;)<br/>#else<br/>#define _ArcName ArcName<br/>#define STR_RARProcessFile TEXT(&quot;RARProcessFile&quot;)<br/>#endif<br/>typedef HANDLE (PASCAL *PRAROpenArchiveEx)(struct RAROpenArchiveDataEx *ArchiveData);<br/>typedef INT (PASCAL *PRARReadHeader)(HANDLE hArc, struct RARHeaderData *HeaderData);<br/>typedef INT (PASCAL *PRARProcessFile)(HANDLE hArc, INT iOperation, PTSTR pwzDestPath, PTSTR pwzDestName);<br/>typedef INT (PASCAL *PRARCloseArchive)(HANDLE hArc);<br/>HRESULT RARX(PTSTR ptzSrcFile, PTSTR ptzDstDir)<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;HMODULE hLib = LoadLibrary(TEXT(&quot;UnRAR&quot;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (hLib == NULL)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ERROR_DLL_NOT_FOUND;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;PRAROpenArchiveEx pRAROpenArchiveEx = (PRAROpenArchiveEx) GetProcAddress(hLib, TEXT(&quot;RAROpenArchiveEx&quot;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;PRARReadHeader pRARReadHeader = (PRARReadHeader) GetProcAddress(hLib, TEXT(&quot;RARReadHeader&quot;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;PRARProcessFile pRARProcessFile = (PRARProcessFile) GetProcAddress(hLib, STR_RARProcessFile);<br/>&nbsp;&nbsp;&nbsp;&nbsp;PRARCloseArchive pRARCloseArchive = (PRARCloseArchive) GetProcAddress(hLib, TEXT(&quot;RARCloseArchive&quot;));<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (!pRAROpenArchiveEx &#124;&#124; !pRARReadHeader &#124;&#124; !pRARProcessFile &#124;&#124; !pRARCloseArchive)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hLib);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_NOINTERFACE;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;struct RAROpenArchiveDataEx od = &#123;0&#125;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;od._ArcName = ptzSrcFile;<br/>&nbsp;&nbsp;&nbsp;&nbsp;od.CmtBufSize = 16384;<br/>&nbsp;&nbsp;&nbsp;&nbsp;od.CmtBuf = (PSTR) UMemAlloc(od.CmtBufSize);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (od.CmtBuf == NULL)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hLib);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E_OUTOFMEMORY;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;od.OpenMode = RAR_OM_EXTRACT;<br/>&nbsp;&nbsp;&nbsp;&nbsp;HANDLE hArc = pRAROpenArchiveEx(&amp;od);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (od.OpenResult == S_OK)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struct RARHeaderData hd = &#123;0&#125;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((od.OpenResult = pRARReadHeader(hArc, &amp;hd)) == S_OK)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;od.OpenResult = pRARProcessFile(hArc, RAR_EXTRACT, ptzDstDir, NULL);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (od.OpenResult != S_OK)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;pRARCloseArchive(hArc);<br/>&nbsp;&nbsp;&nbsp;&nbsp;UMemFree(od.CmtBuf);<br/>&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hLib);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return od.OpenResult;<br/>&#125;<br/></div><br/><br/>以上代码 WM、PC 中通用，应该是通用。<br/><br/>要注意的一点是 16384 的 CmtBuf，在官方的Example中是局部变量，如果在 PPC 调用，且你已经用了不少的话，很可能溢出（VS2008建立的工程，默认STACK才64K，调大一点也OK）。我找了好久才找到原因。改成 Heap 内存就OK了。
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?440</link>
<title><![CDATA[CeleLib：UniBase, CeleReg, CeleUtil, CeleCtrl 等基础函数库]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Thu, 27 Nov 2008 13:53:25 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?440</guid> 
<description>
<![CDATA[ 
	把新近整理的基础代码整理一下，欢迎评估使用。<br/><br/>一、简要说明<br/><br/>1. CoStyle.doc 是代码风格文档。请参考 SourceStyler C++ 的 MFC 风格（部分规则已过期，未及时更新）。<br/><br/>2. UniLib.doc 是 UniBase 的说明文档，尚未更新到最新版本，请酌情参考。<br/><br/>3. CeleLib&#92;UniBase.h 是统一接口的平台库，这里提供的是 Windows 和 Windows Mobile 上的实现（请参看开头的编译注释）。<br/><br/>4. CeleLib&#92;CeleReg.h 是 Windows 和 Windows Mobile 上通用注册表操作类。<br/><br/>5. CeleLib&#92;CeleUtil.h 是 Windows Mobile 中使用的基础使用函数库。<br/><br/>6. CeleLib&#92;CeleCtrl.h 是 Windows Mobile 上的实用控件库，包括部分轻量级的控件、打开文件对话框和其它界面相关的类。<br/><br/>5. CeleLib&#92;CeleCfg.h 是基于 UniBase 的 INI 操作类（不支持 Section，这应该是最高效的 INI 操作类了）。<br/><br/>7. AppDef.h 是一个应用程序的基本宏定义。<br/><br/>8. Resource.h/Resource.rc 是资源文件框架。请使用 -n 命令编译。如果需要 Manifest，请定义好相应的 _M_IX86 或 _M_X64 宏。<br/><br/><br/>二、许可<br/><br/>1. Yonsm 保留这些代码的版权。<br/><br/>2. 任何人可以无偿使用这些代码。如果你使用了这写代码，请在软件界面、发布文档或者软件网站中写明“使用 Yonsm.NET 提供的部分代码”。<br/><br/>3. 任何人可以修改代码以供自己使用或重新发布。如果修改代码后重新发布，请在代码或者说明文档中提及“Yonsm.NET”。<br/><br/>4. Yonsm 不提供任何明示或隐含的担保。<br/><br/><br/>欢迎经常访问 <a href="http://WWW.Yonsm.NET" target="_blank">WWW.Yonsm.NET</a> 或许更新版本。<br/><br/><br/>Yonsm<br/>2009.04.25<br/>杭州<br/><br/><a href="/up/CeleLib.rar">点击这里下载文件</a><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?366</link>
<title><![CDATA[Thunk  Window Class Demo]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Mon, 10 Sep 2007 15:41:23 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?366</guid> 
<description>
<![CDATA[ 
	Generates __thiscall thunk to convert static funtion to member function.<br/><br/><br/><br/><div class="code"><br/><br/><br/>#include &lt;Windows.h&gt;<br/><br/>#if defined(_M_IX86)<br/>template &lt;typename T&gt; class CThunk<br/>&#123;<br/>private:<br/>#pragma pack(push, 1)<br/> &nbsp; &nbsp;BYTE m_bPopEcx; // POP EAX<br/> &nbsp; &nbsp;BYTE m_bPush; &nbsp; // PUSH pThis<br/> &nbsp; &nbsp;PVOID m_pThis; &nbsp;// <br/> &nbsp; &nbsp;BYTE m_bPushEcx;// PUSH EAX<br/><br/> &nbsp; &nbsp;//BYTE m_bJmp; &nbsp;// JMP pProc<br/> &nbsp; &nbsp;//INT m_iOffset;<br/><br/> &nbsp; &nbsp;BYTE m_bMovEax; // MOV EAX, tProc<br/> &nbsp; &nbsp;T m_tProc;<br/> &nbsp; &nbsp;WORD m_wJmpEax; // JMP EAX<br/>#pragma pack(pop)<br/><br/>public:<br/> &nbsp; &nbsp;PROC Init(PVOID pThis, T tProc)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_bPopEcx = 0x58;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_bPush = 0x68;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_pThis = pThis;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_bPushEcx = 0x50;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//m_bJmp = 0xE9;<br/> &nbsp; &nbsp; &nbsp; &nbsp;//m_iOffset = (INT) ((INT_PTR) pProc - ((INT_PTR) &amp;m_iOffset + sizeof(m_iOffset)));<br/> &nbsp; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_bMovEax = 0xB8;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_tProc = tProc;<br/> &nbsp; &nbsp; &nbsp; &nbsp;m_wJmpEax = 0xE0FF;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;return (PROC) this;<br/> &nbsp; &nbsp;&#125;<br/>&#125;;<br/>#else<br/>#error CThunk does not support this platform!<br/>#endif<br/><br/>class CMyWnd<br/>&#123;<br/>public:<br/> &nbsp; &nbsp;HWND m_hWnd;<br/><br/> &nbsp; &nbsp;typedef LRESULT (CALLBACK CMyWnd::*PWNDPROC)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);<br/> &nbsp; &nbsp;CThunk&lt;PWNDPROC&gt; m_tProc;<br/><br/>public:<br/> &nbsp; &nbsp;CMyWnd()<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;WNDCLASSEX wceClass = &#123;0&#125;;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;// Generate thunk data/code<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.lpfnWndProc = (WNDPROC) m_tProc.Init(this, &amp;CMyWnd::WindowProc);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.cbSize = sizeof(WNDCLASSEX);<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.style = CS_VREDRAW &#124; CS_HREDRAW;<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.hInstance = GetModuleHandle(NULL);<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.hCursor = LoadCursor(NULL, IDC_ARROW);<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.hbrBackground = (HBRUSH) COLOR_BTNSHADOW;<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.lpszClassName = TEXT(&quot;ThThunk&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;wceClass.hIconSm = NULL;<br/> &nbsp; &nbsp; &nbsp; &nbsp;RegisterClassEx(&amp;wceClass);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;CreateWindowEx(WS_EX_ACCEPTFILES &#124; WS_EX_APPWINDOW, TEXT(&quot;ThThunk&quot;), TEXT(&quot;ThThunk&quot;), WS_OVERLAPPEDWINDOW,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), 0);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(m_hWnd, SW_SHOW);<br/> &nbsp; &nbsp; &nbsp; &nbsp;UpdateWindow(m_hWnd);<br/> &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;switch (uMsg)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;case WM_NCCREATE:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_hWnd = hWnd;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;case WM_LBUTTONDOWN:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TCHAR tzText&#91;MAX_PATH&#93;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetWindowText(m_hWnd, tzText, MAX_PATH);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MessageBox(hWnd, tzText, tzText, MB_ICONINFORMATION);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;case WM_DESTROY:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostQuitMessage(0);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;default:<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;return DefWindowProc(hWnd, uMsg, wParam, lParam);<br/> &nbsp; &nbsp;&#125;<br/>&#125;;<br/><br/><br/><br/>INT APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)<br/>&#123;<br/> &nbsp; &nbsp;CMyWnd w;<br/><br/> &nbsp; &nbsp;MSG msg;<br/> &nbsp; &nbsp;while (GetMessage(&amp;msg, NULL, 0, 0))<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;TranslateMessage(&amp;msg);<br/> &nbsp; &nbsp; &nbsp; &nbsp;DispatchMessage(&amp;msg);<br/> &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;return 0;<br/>&#125;<br/></div><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?351</link>
<title><![CDATA[CeleCmd 1.2.360 代码]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sat, 04 Aug 2007 15:31:35 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?351</guid> 
<description>
<![CDATA[ 
	应该可以说非常精妙与高效，有兴趣不妨一观。其中有不少与Windows PC通用的代码，比如 Import 注册表脚本 Reg 文件的代码和利用ZLib解压缩Tar GZ压缩包的代码，实用性和适应性都非常好，写得也很简洁高效。<br/><br/>有关 CeleCommand 请参考：<a href="http://www.yonsm.net/read.php?329" target="_blank">http://www.yonsm.net/read.php?329</a><br/><br/><br/><br/>请勿将代码应用于商业用途。<br/><br/><a href="attachment.php?fid=26">点击这里下载文件</a><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a> , <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E5%2588%2586%25E4%25BA%25AB" rel="tag">分享</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?342</link>
<title><![CDATA[修改 psShutXP 使他的硬起功能生效]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sun, 24 Jun 2007 19:18:14 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?342</guid> 
<description>
<![CDATA[ 
	经验征得之，SetCleanRebootFlag 对于 HTC 系列的 PPC 无效。但一般的软件硬起，往往就用这个函数，psShutXP 也不例外。<br/><br/>我已经修改 psShutXP，让它的硬起功能真的“硬起”了。下面是分析 HTC ClearStorage 的关键代码（这很容易，但是要把这些代码挪动到 psShutXP 中，那不是一般的难啊——还好我搞定了：）。<br/><br/><div class="code"><br/>// HTC Cold Reboot<br/>.text:00011000 sub_11000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; CODE XREF: sub_11064+11Cp<br/>.text:00011000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; DATA XREF: .pdata:00014000o<br/>.text:00011000<br/>.text:00011000 var_8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = -8<br/>.text:00011000 var_4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = -4<br/>.text:00011000 arg_4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = &nbsp;4<br/>.text:00011000<br/>.text:00011000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#var_4&#93;!<br/>.text:00011004 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SUB &nbsp; &nbsp; SP, SP, #8<br/>.text:00011008 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LDR &nbsp; &nbsp; R0, =0x1012594<br/>.text:0001100C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; LR, #0<br/>.text:00011010 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R3, #0<br/>.text:00011014 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R2, #0<br/>.text:00011018 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R1, #0<br/>.text:0001101C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#8+var_4&#93;<br/>.text:00011020 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#8+var_8&#93;<br/>.text:00011024 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BL &nbsp; &nbsp; &nbsp;KernelIoControl<br/>.text:00011024<br/>.text:00011028 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ADD &nbsp; &nbsp; SP, SP, #8<br/>.text:0001102C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LDR &nbsp; &nbsp; PC, &#91;SP&#93;,#arg_4<br/>.text:0001102C<br/>.text:0001102C ; End of function sub_11000<br/>.text:0001102C<br/>.text:0001102C ; ---------------------------------------------------------------------------<br/>.text:00011030 dword_11030 &nbsp; &nbsp; DCD 0x1012594 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; DATA XREF: sub_11000+8r<br/><br/><br/><br/>// REEBOOT<br/>.text:00011034<br/>.text:00011034 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#var_4&#93;!<br/>.text:00011038 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R3, #0<br/>.text:0001103C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R2, #0<br/>.text:00011040 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R1, #0<br/>.text:00011044 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R0, #0xDF<br/>.text:00011048 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BL &nbsp; &nbsp; &nbsp;keybd_event<br/>.text:00011048<br/>.text:0001104C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R3, #0<br/>.text:00011050 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R2, #2<br/>.text:00011054 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R1, #0<br/>.text:00011058 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R0, #0xDF<br/>.text:0001105C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LDR &nbsp; &nbsp; LR, &#91;SP&#93;,#arg_4<br/>.text:00011060 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B &nbsp; &nbsp; &nbsp; keybd_event<br/>.text:00011060<br/></div><br/><br/>翻译成 C 代码：<br/><br/><div class="code"><br/>#define IOCTL_HAL_COLDBOOT_HTC 0x1012594 <br/>KernelIoControl(IOCTL_HAL_COLDBOOT_HTC, NULL, 0, NULL, 0, NULL);<br/>keybd_event(VK_OFF, 0, 0, 0);<br/>keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);<br/></div><br/><br/>其实后两句改成下面更好些：<br/><div class="code"><br/>#define IOCTL_HAL_REBOOT 0x101003C<br/>KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);<br/></div><br/><br/>修改过的程序在 Prophet 上验证通过。<br/><br/>乘胜追击，继续分析完全系统电源功能，找来 PowerOffWarning，得出如下：<br/><br/><div class="code"><br/>// 关闭 RIL，否则别人打你电话就变成了无信号状态，所谓超级飞行了。<br/>.text:00011478 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BL &nbsp; &nbsp; &nbsp;sub_11088 <br/><br/>// 完全关闭电源<br/>.text:0001147C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R3, #0x1000000<br/>.text:00011480 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORR &nbsp; &nbsp; R0, R3, #unk_12000<br/>.text:00011484 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; LR, #0<br/>.text:00011488 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R3, #0<br/>.text:0001148C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R2, #0<br/>.text:00011490 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MOV &nbsp; &nbsp; R1, #0<br/>.text:00011494 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#0x25C+var_258&#93;<br/>.text:00011498 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; STR &nbsp; &nbsp; LR, &#91;SP,#0x25C+var_25C&#93;<br/>.text:0001149C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BL &nbsp; &nbsp; &nbsp;KernelIoControl<br/>.text:0001149C<br/>.text:000114A0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BL &nbsp; &nbsp; &nbsp;GwesPowerOffSystem<br/></div><br/><br/>哈哈，今天一大收获，搞定两个问题，“业界”无公开的：）<br/><br/>下载我汉化修改过的<span style="color: #FF0000;">仅适合 HTC Prophet</span>（830等） QVGA 的 psShutXP（预计针对其它机型应该没有效果，这些都是私有的代码）：<br/><br/><a href="attachment/PSShutXP.rar">点击这里下载文件</a><br/><br/>修改后的 psShutXP，硬起功能有效。且关机命令不再是关闭屏幕，而是直接关闭电源（但是RIL，即电话模块，没通知运营商正常关闭，也没有通知应用程序保存数据。所以请使用关机命令前保存好数据）<br/><br/><br/>顺便体贴个 CeleCommand 中的各式各样的关机、重启、硬起代码：<br/><div class="code"><br/><br/><br/>#define IOCTL_HAL_REBOOT 0x101003C<br/>#define IOCTL_HAL_SHUTDOWN 0x1012000<br/>#define IOCTL_HAL_COLDBOOT 0x1012594<br/>extern &quot;C&quot; BOOL WINAPI SetCleanRebootFlag();<br/>extern &quot;C&quot; BOOL WINAPI GwesPowerOffSystem();<br/>extern &quot;C&quot; BOOL WINAPI ExitWindowsEx(UINT uFlags, DWORD dwReason);<br/>extern &quot;C&quot; BOOL KernelIoControl(DWORD dwIoControlCode, PVOID pInBuf, DWORD nInBufSize, PVOID pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned);<br/>HRESULT SHUT(PCTSTR ptzCmd)<br/>&#123;<br/> &nbsp;BOOL bResult;<br/> &nbsp;switch (UChrToUpper(*ptzCmd))<br/> &nbsp;&#123;<br/> &nbsp;case &#039;S&#039;:<br/> &nbsp; &nbsp;// HTC<br/> &nbsp; &nbsp;KernelIoControl(IOCTL_HAL_SHUTDOWN, NULL, 0, NULL, 0, NULL);<br/><br/> &nbsp;case &#039;G&#039;:<br/> &nbsp; &nbsp;bResult = GwesPowerOffSystem();<br/> &nbsp; &nbsp;break;<br/><br/> &nbsp;case &#039;P&#039;:<br/> &nbsp; &nbsp;bResult = ExitWindowsEx(EWX_POWEROFF, 0);<br/> &nbsp; &nbsp;break;<br/><br/> &nbsp;case &#039;K&#039;:<br/> &nbsp; &nbsp;keybd_event(VK_OFF, 0, KEYEVENTF_SILENT, 0);<br/> &nbsp; &nbsp;keybd_event(VK_OFF, 0, KEYEVENTF_SILENT &#124; KEYEVENTF_KEYUP, 0);<br/> &nbsp; &nbsp;bResult = TRUE;<br/> &nbsp; &nbsp;break;<br/><br/> &nbsp;case &#039;H&#039;:<br/> &nbsp; &nbsp;// HTC<br/> &nbsp; &nbsp;KernelIoControl(IOCTL_HAL_COLDBOOT, NULL, 0, NULL, 0, NULL);<br/><br/> &nbsp;case &#039;C&#039;:<br/> &nbsp; &nbsp;SetCleanRebootFlag();<br/><br/> &nbsp;case &#039;R&#039;:<br/> &nbsp; &nbsp;bResult = KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);<br/> &nbsp; &nbsp;break;<br/><br/> &nbsp;default:<br/> &nbsp; &nbsp;bResult = ExitWindowsEx(EWX_REBOOT, 0);<br/> &nbsp; &nbsp;break;<br/> &nbsp;&#125;<br/><br/> &nbsp;return !bResult;<br/>&#125;<br/><br/></div><br/>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?323</link>
<title><![CDATA[CodeZap - 给 EXE 添加额外代码的 C++ Engine]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Tue, 01 May 2007 18:53:41 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?323</guid> 
<description>
<![CDATA[ 
	给 EXE 添加节显示启动信息的代码多得很，CodeZap 这个最大的特色就是 C++ 写成的，且提供了比较独立美观的Z函数。只要了解 C/C++ 语言，就能写添加大量的代码，完全可以工程化操作。<br/><br/>CodeZap 简要说明<br/><br/>CodeZap 是用来给 PE 文件添加额外代码的 C++ SDK。您可以通过使用熟悉而且容易工程化的 C/C++ 语言来添加大量的可执行代码。<br/><br/>Codez 使用非常简单，你只要模仿 ZCode 函数，写出自己的 ZCode 即可。其中 ZCode 的要求如下：<br/><br/>1. ZCode 必须是 CDECL 调用规范。<br/>2. ZCode 函数最后的 __asm 块，除 #ifdef _DEBUG 包围的之外，必须保留。<br/>3. ZCode 中不能使用字符串常量。<br/>4. ZCode 中不能调用外部函数。<br/>5. ZCode 中可以调用 __forceinline 声明的函数。<br/>6. ZCode 中可以使用 CodeZap 中所有 Z 开头的函数。<br/>7. ZCode 中的 C++ 代码可以任意添加，只要符合前面的所有条件。<br/>8. 可以修改 &nbsp;#ifdef _DEBUG 中的汇编代码为你所所要情形。<br/>9. 可以修改函数的参数（基于上一条为前提）。<br/><br/><br/><span style="color: #FF0000;">基于以上要求， Viual Studio 2003/2005 中使用，必须在 Project 设置中，关闭缓冲区安全检查。否则将会生成的代码中会调用 security_cookie 函数，导致代码无法在目标文件中正确执行。<br/><br/>另外，用这些Z函数来写 ShellCode，也是非常高效的，比平时写 C/C++ 程序麻烦一点点而已。</span><br/><br/>CodeZap 调用示例：<br/>CodeZap(TEXT("C:&#92;&#92;ABC.CZ.exe"), TEXT("C:&#92;&#92;ABC.exe"), (PBYTE) ZCode);<br/><br/>Powered By Yonsm<br/><a href="http://WWW.Yonsm.NET" target="_blank">WWW.Yonsm.NET</a><br/>2007.4.31 <br/><br/><div class="code">接口函数：<br/>BOOL CodeZap(PCTSTR ptzDst, PCTSTR ptzSrc, PBYTE pbCode);<br/>ZAPI HMODULE ZGetKernelHandle();<br/>ZAPI HMODULE ZGetModuleHandle(PCTSTR ptzModule = NULL);<br/>ZAPI HMODULE ZSearchModuleHandle(PCTSTR ptzModule, PBYTE pbBase = (PBYTE) 0x70000000, PBYTE pbMax = (PBYTE) 0x80000000);<br/>ZAPI FARPROC ZGetProcAddress(HMODULE hModule, PCTSTR ptzProc);<br/></div><br/><br/><br/><div class="code"> ZCode 示例<br/>VOID CDECL ZCode()<br/>&#123;<br/>&nbsp;&nbsp;// KERNEL32<br/>&nbsp;&nbsp;HMODULE hKernel32 = ZGetKernelHandle();<br/><br/>&nbsp;&nbsp;// GetProcAddress<br/>&nbsp;&nbsp;TCHAR szGetProcAddress&#91;&#93; = &#123;&#039;G&#039;, &#039;e&#039;, &#039;t&#039;, &#039;P&#039;, &#039;r&#039;, &#039;o&#039;, &#039;c&#039;, &#039;A&#039;, &#039;d&#039;, &#039;d&#039;, &#039;r&#039;, &#039;e&#039;, &#039;s&#039;, &#039;s&#039;, 0&#125;;<br/>&nbsp;&nbsp;PGetProcAddress pGetProcAddress = (PGetProcAddress) ZGetProcAddress(hKernel32, szGetProcAddress);<br/>&nbsp;&nbsp;if (!pGetProcAddress) return;<br/><br/>&nbsp;&nbsp;// LoadLibrary<br/>&nbsp;&nbsp;CHAR szLoadLibrary&#91;&#93; = &#123;&#039;L&#039;, &#039;o&#039;, &#039;a&#039;, &#039;d&#039;, &#039;L&#039;, &#039;i&#039;, &#039;b&#039;, &#039;r&#039;, &#039;a&#039;, &#039;r&#039;, &#039;y&#039;, ZEND&#125;;<br/>&nbsp;&nbsp;PLoadLibrary pLoadLibrary = (PLoadLibrary) pGetProcAddress(hKernel32, szLoadLibrary);<br/>&nbsp;&nbsp;if (!pLoadLibrary) return;<br/><br/>&nbsp;&nbsp;// USER32<br/>&nbsp;&nbsp;TCHAR tzUser32&#91;&#93; = &#123;&#039;U&#039;, &#039;S&#039;, &#039;E&#039;, &#039;R&#039;, &#039;3&#039;, &#039;2&#039;, 0&#125;;<br/>&nbsp;&nbsp;HMODULE hUser32 = pLoadLibrary(tzUser32);<br/><br/>&nbsp;&nbsp;// MessageBox<br/>&nbsp;&nbsp;CHAR szMessageBox&#91;&#93; = &#123;&#039;M&#039;, &#039;e&#039;, &#039;s&#039;, &#039;s&#039;, &#039;a&#039;, &#039;g&#039;, &#039;e&#039;, &#039;B&#039;, &#039;o&#039;, &#039;x&#039;, ZEND&#125;;<br/>&nbsp;&nbsp;PMessageBox pMessageBox = (PMessageBox) pGetProcAddress(hUser32, szMessageBox);<br/><br/>&nbsp;&nbsp;TCHAR tzText&#91;&#93; = &#123;&#039;H&#039;, &#039;a&#039;, &#039;h&#039;, &#039;a&#039;, &#039;,&#039;, &#039; &#039;, &#039;I&#039;, &#039; &#039;, &#039;a&#039;, &#039;m&#039;, &#039; &#039;, &#039;C&#039;, &#039;o&#039;, &#039;d&#039;, &#039;e&#039;, &#039;Z&#039;, &#039;a&#039;, &#039;p&#039;, &#039;!&#039;, 0&#125;;<br/>&nbsp;&nbsp;TCHAR tzCaption&#91;&#93; = &#123;&#039;C&#039;, &#039;o&#039;, &#039;d&#039;, &#039;e&#039;, &#039;Z&#039;, &#039;a&#039;, &#039;p&#039;, 0&#125;;<br/>&nbsp;&nbsp;pMessageBox(NULL, tzText, tzCaption, MB_ICONINFORMATION);<br/><br/>&nbsp;&nbsp;__asm<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;JMP&nbsp;&nbsp;&nbsp;&nbsp;_ZCodeEnd;<br/><br/>_ZJumpOEP:<br/>&nbsp;&nbsp;&nbsp;&nbsp;// Jump to OEP: Jump delta will be fixed by CodeZap<br/>&nbsp;&nbsp;&nbsp;&nbsp;JMP&nbsp;&nbsp;&nbsp;&nbsp;$ + 5;<br/><br/>#ifndef _DEBUG<br/>&nbsp;&nbsp;&nbsp;&nbsp;// Put your own ASM code here<br/>&nbsp;&nbsp;&nbsp;&nbsp;PUSHAD;<br/>&nbsp;&nbsp;&nbsp;&nbsp;CALL&nbsp;&nbsp;ZCode;<br/>&nbsp;&nbsp;&nbsp;&nbsp;POPAD;<br/>#endif<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;JMP&nbsp;&nbsp;&nbsp;&nbsp;_ZJumpOEP;<br/>_ZCodeEnd:<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/></div><br/><br/><br/>下载：<br/><a href="attachment/CodeZap.rar">点击这里下载文件</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?322</link>
<title><![CDATA[Search module base   function address]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sat, 28 Apr 2007 13:08:06 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?322</guid> 
<description>
<![CDATA[ 
	Search module base (e.g.KERNEL32) & function address (e.g. GetProcAddress) (C++, NOT ASM).<br/><br/><div class="code"><br/>PVOID GetKernelBase()<br/>&#123;<br/> &nbsp;PBYTE pbBase = (PBYTE) 0x70000000;<br/>__Retry:<br/> &nbsp;__try<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;while (pbBase &lt; (PBYTE) 0x80000000)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;if (((PIMAGE_DOS_HEADER) pbBase)-&gt;e_magic == IMAGE_DOS_SIGNATURE)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;PIMAGE_NT_HEADERS pNTHdr = (PIMAGE_NT_HEADERS) (pbBase + ((PIMAGE_DOS_HEADER) pbBase)-&gt;e_lfanew);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (pNTHdr-&gt;Signature == IMAGE_NT_SIGNATURE)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PIMAGE_EXPORT_DIRECTORY pExpDir = (PIMAGE_EXPORT_DIRECTORY) (pbBase + pNTHdr-&gt;OptionalHeader.DataDirectory&#91;IMAGE_DIRECTORY_ENTRY_EXPORT&#93;.VirtualAddress);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PDWORD p = (PDWORD) (pbBase + pExpDir-&gt;Name);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((p&#91;0&#93; == &#039;NREK&#039;) &amp;&amp; (p&#91;1&#93; == &#039;23LE&#039;))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return pbBase;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;pbBase += 0x1000;<br/> &nbsp; &nbsp;&#125; &nbsp; &nbsp;<br/> &nbsp;&#125;<br/> &nbsp;__except (EXCEPTION_EXECUTE_HANDLER)<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;pbBase += 0x1000;<br/> &nbsp; &nbsp;goto __Retry;<br/> &nbsp;&#125;<br/> &nbsp;return NULL;<br/>&#125;<br/></div><br/><br/><div class="code">typedef FARPROC (WINAPI *PGBA)(HMODULE hModule, PCTSTR pszName);<br/><br/> &nbsp;// Lookup GetProcAddress funtion<br/> &nbsp;PGBA pGetProcAddress = NULL;<br/> &nbsp;PBYTE pbBase = (PBYTE) hKernel32;<br/> &nbsp;if (((PIMAGE_DOS_HEADER) pbBase)-&gt;e_magic == IMAGE_DOS_SIGNATURE)<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;PIMAGE_NT_HEADERS pNTHdr = (PIMAGE_NT_HEADERS) (pbBase + ((PIMAGE_DOS_HEADER) pbBase)-&gt;e_lfanew);<br/> &nbsp; &nbsp;if (pNTHdr-&gt;Signature == IMAGE_NT_SIGNATURE)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;PIMAGE_EXPORT_DIRECTORY pExpDir = (PIMAGE_EXPORT_DIRECTORY) (pbBase + pNTHdr-&gt;OptionalHeader.DataDirectory&#91;IMAGE_DIRECTORY_ENTRY_EXPORT&#93;.VirtualAddress);<br/> &nbsp; &nbsp; &nbsp;PDWORD pdwNames = (PDWORD) (pbBase + pExpDir-&gt;AddressOfNames);<br/> &nbsp; &nbsp; &nbsp;for (UINT i = 0; i &lt; pExpDir-&gt;NumberOfNames; i++)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;// GetProcAddress<br/> &nbsp; &nbsp; &nbsp; &nbsp;PDWORD p = (PDWORD) (pbBase + pdwNames&#91;i&#93;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (p &amp;&amp; (p&#91;0&#93; == &#039;PteG&#039;) &amp;&amp; (p&#91;1&#93; == &#039;Acor&#039;) &amp;&amp; (p&#91;2&#93; == &#039;erdd&#039;))<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PDWORD pdwFunctions = (PDWORD) (pbBase + pExpDir-&gt;AddressOfFunctions);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pGetProcAddress = (PGBA) (pbBase + pdwFunctions&#91;i&#93;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp;&#125;<br/></div><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?300</link>
<title><![CDATA[CeleSetup - ROM 定制扩展命令解释工具]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sun, 08 Apr 2007 16:20:28 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?300</guid> 
<description>
<![CDATA[ 
	欢迎使用 CeleSetup，它将使你能够轻松愉快地定制 Windows Mobile ROM，使您的 ROM 具备最好的扩充性和伸缩性！<br/><br/>一、特点<br/><br/>◎ 短小精干，运行迅速。<br/>◎ 支持常规的扩展设置命令。<br/>◎ 支持调用外部 EXE 和 DLL 函数。<br/>◎ 支持格式统一的命令行参数和命令文件。<br/>◎ 细微周到的功能支持。功能及其强大。<br/>◎ 源代码公开，方便更改定制。在源代码中增加扩展命令非常容易。<br/><br/>二、使用<br/><br/>◎ 本程序与 XCMD（专为 Windows XPE 而作，详细请看 bbs.wuyou.com 论坛） 具有类似的命令格式和功能，但 CeleSetup 只是为 Windows Mobile 初始化设置为专门做的，可以方便地 ROM 初始化当中的各种操作。<br/><br/>◎ 使用命令行参数：例如，要创建快捷方式，执行“CeleSetup.exe LINK %S&#92;程序&#92;测试程序.lnk,%W&#92;Test.exe”即可。<br/><br/>◎ 使用命令文件：例如，“CeleSetup.exe LOAD &#92;Storage Card&#92;*.cst”。<br/><br/>◎ 不用命令行参数，直接执行本程序，将显示版本信息。<br/><br/>◎ 命令参数支持宏替换（如“%W&#92;X.TXT”）；命令不区分大小写；尖括号“<>”内的参数表示必须输入，方括号“[]”内的表示可以省略。<br/><br/>◎ 命令文件中，支持以下宏替换（如果需要在参数中使用 % 本身，则需要用两个 % 代替，如 %1 要写成 %%1）：<br/><br/> &nbsp; &nbsp;%A=APPDATA，可能为 &#92;Application Data<br/> &nbsp; &nbsp;%D=DESKTOP，可能为 &#92;Windows&#92;Desktop<br/> &nbsp; &nbsp;%M=PERSONAL，可能为 &#92;My Documents<br/> &nbsp; &nbsp;%U=STARTUP，可能是 &#92;Windows&#92;StartUp<br/> &nbsp; &nbsp;%W=WINDOWS，可能是 &#92;Windows<br/> &nbsp; &nbsp;%P=PROGRAMS，可能是 &#92;Windwos&#92;程序<br/> &nbsp; &nbsp;%S=STARTMENU，可能是 &#92;WIndows&#92;“开始”菜单<br/> &nbsp; &nbsp;%F=PROGRAM FILES 可能是 &#92;Program Files<br/> &nbsp; &nbsp;%C=在命令文件中使用，表示命令文件所在的目录；在命令行中使用，表示 CeleSetup 所在目录<br/><br/>◎ 具体用法可以参考 Sample 中的 csx 文件，也可以参考我定制的最帅的 Prophet WM5 ROM：<a href="http://www.yonsm.net/read.php?302" target="_blank">http://www.yonsm.net/read.php?302</a>。<br/><br/>◎ 下面是一般性用法：<br/><br/> &nbsp;1. Windows Mobile 硬起后解释 InitFlashFiles.dat：创建系统目录；显示欢迎和屏幕调整界面；加载 CeleTask.lnk ->“CeleSetup.exe &#92;*”。<br/> &nbsp;2. CeleSetup 加载根目录下所有子目录下的 *.csx：自动扫描到我做的 CeleSetp.csx。<br/> &nbsp;3. CeleSetup.csx 内的命令：创建基本的快捷方式；解压缩 CeleSetup.tgz 压缩包中的文件到相应位置；注册 .csx 类型的扩展关联，以后在资源管理器中点击任何 .csx 文件就会自动被加载；加载 &#92;Storage&#92;* 和 &#92;Storage Card&#92;*，即扫描 SD 卡上的子目录中所有 .csx 文件。<br/> &nbsp;4. 在 SD 卡中放个 CeleCard.csx 和 CeleCard.reg，自动把卡上的软件的快捷方式添加到开始菜单->程序->工具中，并把相应的设置导入注册表中。<br/><br/><br/>三、命令<br/><br/>■ [LOAD ][文件路径&#124;目录&#92;*&#124;目录&#92;*.cst]<br/><br/> &nbsp;◎ 功能：按顺序逐条运行命令文件中的命令。<br/><br/> &nbsp;◎ 参数：指定文件的路径。如果省略，将自动搜索每个分区根目录中的 XCMD.INI（注意防止嵌套调用）。<br/><br/> &nbsp;◎ 示例：LOAD &#92;*<br/><br/> &nbsp;◎ 备注：<br/><br/> &nbsp; &nbsp;※ 每条命令单独一行。<br/> &nbsp; &nbsp;※ 命令是完全按顺序执行的。<br/> &nbsp; &nbsp;※ 不正确的命令或空行将忽略不计。<br/> &nbsp; &nbsp;※ 推荐使用 UNICODE 格式文本文件。<br/> &nbsp; &nbsp;※ 注释必须单独放一行，推荐使用“//”作为注释起始。<br/> &nbsp; &nbsp;※ 第一行和最后一行必须是空行或注释，否则可能将被忽略。<br/> &nbsp; &nbsp;※ 在命令文件中可以使用环境变量“%C”表示命令文件所在目录。<br/> &nbsp; &nbsp;※ 如果文件路径中的最后两个字符是“&#92;*”，则自动搜索该目录中所有子目录下的 *.cst 文件，如“LOAD &#92;*”。<br/> &nbsp; &nbsp;※ 如果文件路径中的含有通配符“*”或“?”，则自动搜索该目录中的匹配文件，如“LOAD &#92;Storage&#92;Cele*.cst”。<br/><br/>■ EXEC [=]<EXE 路径>[,参数]<br/><br/> &nbsp;◎ 功能：执行 EXE 程序。<br/><br/> &nbsp;◎ 参数：指定 EXE 路径和参数。<br/> &nbsp;<br/> &nbsp;◎ 示例：EXEC WCELoad.exe,/nogui "%C&#92;CeleSetup.cab"<br/><br/> &nbsp;◎ 备注：前导“=”表示等待执行完成。<br/><br/>■ CALL <DLL 路径>[,函数名称][,[#]参数1][,[#]参数2][,[#]参数3][,[#]参数4]<br/><br/> &nbsp;◎ 功能：调用 DLL 函数。<br/><br/> &nbsp;◎ 参数：指定 DLL 路径、函数名称和参数。如果省略函数名称，将调用“DllRegisterServer”。参数默认为 UNICODE 字符串，如果以“#”前导则表示整数；最多支持四个函数参数。<br/><br/> &nbsp;◎ 示例：CALL SHELL32.DLL,DllInstall,#1,I<br/><br/> &nbsp;◎ 备注：函数必须以 STDCALL 方式导出（不明白什么意思的话，就当没任何问题）。<br/><br/>■ REGI <HKLM&#124;HKCU&#124;HKCR&#124;HKU><&#92;子项&#92;>[键值][=[#]数据]<br/><br/> &nbsp;◎ 功能：设置或删除注册表数据。<br/><br/> &nbsp;◎ 参数：<br/><br/> &nbsp; &nbsp;※ 子项 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;所选 ROOTKEY 下注册表项的完整名。<br/><br/> &nbsp; &nbsp;※ 键值 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要操作的键值。如果省略，则操作默认键值；如果为“!”且没有“=”，则用于删除整个子项。<br/><br/> &nbsp; &nbsp;※ 数据 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要设置的数据。如果没有“=”则删除。如果前导“#”则表示 REG_DWORD 整数类型的数据，如“#0x20”；如果前导“@”则为 REG_BINARY，如“@23 34 90 255”；否则为字符串。<br/><br/> &nbsp;◎ 示例：REGI HKCU&#92;Control Panel&#92;Desktop&#92;Wallpaper=%SystemRoot%&#92;WALL.JPG<br/><br/> &nbsp;◎ 备注：请命令比较复杂，请仔细看说明。如果 RESCO 的注册表 DLL 插件 RRegShell.dll 存在，该命令还支持导入注册表文件，例如“REGI %C&#92;*.reg”。<br/><br/>■ FILE <文件路径>[<操作符>[目标路径]<br/><br/> &nbsp;◎ 功能：操作文件或目录。<br/><br/> &nbsp;◎ 参数：指定源文件路径和目标路径，支持通配符，可以用分号同时操作多个文件。操作符“-&#125;”、“=&#125;”分别对应移动、复制，没有操作符则表示删除操作。<br/><br/> &nbsp;◎ 示例：FILE &#92;Temp&#92;*.txt<br/><br/> &nbsp;◎ 备注：无。<br/><br/>■ LINK <快捷方式路径><,目标路径>[,运行参数][,图标路径][,图标索引]<br/><br/> &nbsp;◎ 功能：创建快捷方式。<br/><br/> &nbsp;◎ 参数：<br/><br/> &nbsp; &nbsp;※ 快捷方式路径 &nbsp; &nbsp; &nbsp;指定要生成的快捷方式的路径，不需要“.LNK”扩展名。<br/><br/> &nbsp; &nbsp;※ 目标路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;指定快捷方式的目标文件或目录。<br/><br/> &nbsp; &nbsp;※ 运行参数 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;目标程序运行参数。<br/><br/> &nbsp; &nbsp;※ 图标路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;快捷方式图标的路径。<br/><br/> &nbsp; &nbsp;※ 图标索引 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;快捷方式图标的在文件资源中的标识（不填写则默认）。<br/><br/> &nbsp;◎ 示例：LINK %S&#92;电话,CProg.exe,,ShellRes.dll,1024<br/><br/> &nbsp;◎ 备注：无。<br/><br/>■ XZIP <文件路径>[,目标目录]<br/><br/> &nbsp;◎ 功能：解压缩 TAR GZ 文件到指定目录。<br/><br/> &nbsp;◎ 参数：指定源文件路径和目标路径，如果没有目标目录，将解压缩到根目录。<br/><br/> &nbsp;◎ 示例：XZIP %C&#92;CeleSetup.tgz<br/><br/> &nbsp;◎ 备注：此命令用来解压缩文件到指定目录，从而避免 InitFlashFiles.dat 中大量的文件拷贝操作的命令。TAR GZ 格式可以用 WinRAR 来压缩，然后用 ArcConvert 转换成 TAR GZ 格式。<br/><br/>■ SEND <按键代码1[_&#124;^]>[,按键代码2][,按键代码3]...<br/><br/> &nbsp;◎ 功能：模拟按键。<br/><br/> &nbsp;◎ 参数：虚拟按键代码，如 VK_NUMLOCK，请参相关考编程文档。如果按键代码以“_”结束，则仅模拟按键按下；“^”则仅模拟按键弹起；否则模拟按下并弹起。很生动吧：）<br/><br/> &nbsp;◎ 示例：SEND 0x12_,0x09_,0x09^,0x12^<br/><br/> &nbsp;◎ 备注：上面的示例模拟 Alt+Tab。按键代码支持 16 进制，如“SEND 0x90”表示按下 NumLock 键。<br/><br/>■ WAIT <时间><br/><br/> &nbsp;◎ 功能：等待指定时间后再继续执行命令。<br/><br/> &nbsp;◎ 参数：指定时间，单位为毫秒。<br/><br/> &nbsp;◎ 示例：WAIT 2000<br/><br/> &nbsp;◎ 备注：可以在执行 SHELL 后等一段时间，然后执行“LOGO”命令关闭登录画面；或者执行其它操作。<br/><br/>■ KILL <进程名称><br/><br/> &nbsp;◎ 功能：强制终止指定的进程。<br/><br/> &nbsp;◎ 参数：进程名称，即 EXE 文件名（不包含路径）。<br/><br/> &nbsp;◎ 示例：KILL WinLogon<br/><br/> &nbsp;◎ 备注：此命令将终止与“进程名称”前部分匹配的所有进程，所以如果省略参数，可能将全部进程关闭。<br/><br/>■ SHUT [G&#124;P&#124;K&#124;H&#124;R]<br/><br/> &nbsp;◎ 功能：关闭、重起或硬起设备。<br/><br/> &nbsp;◎ 参数：关闭、重起或硬起设备。默认为重新启动。<br/><br/> &nbsp;◎ 示例：SHUT<br/><br/> &nbsp;◎ 备注：分别表示 GwesPowerOffSystem()/EWX_POWEROFF/keybd_event/SetCleanRebootFlag/KernelIoControl/EWX_REBOOT 方式执行。<br/><br/>■ XLOG [文件路径]<br/><br/> &nbsp;◎ 功能：启用日志文件。日志文件可以记录每条命令的执行结果，帮助用户验证命令文件的正确性。<br/><br/> &nbsp;◎ 参数：日志文件路径。<br/><br/> &nbsp;◎ 示例：LOGO &#92;CeleSetup.LOG<br/><br/> &nbsp;◎ 备注：此命令不能在命令行参数中使用（必须在命令文件中使用）。命令文件结束之前，必须调用一次不带参数的“XLOG”命令，以关闭日志文件。公开发布的 ROM 中建议不要启用日志文件。<br/><br/>■ BEEP [类型]<br/><br/> &nbsp;◎ 功能：播放通知声。<br/><br/> &nbsp;◎ 参数：声音类型。默认为 0，具体意义与 MessageBeep 相同，请查阅相关文档或实际尝试。<br/><br/> &nbsp;◎ 示例：BEEP<br/><br/> &nbsp;◎ 备注：无。<br/><br/>■ ECHO <提示文字>[,标题][,类型]<br/><br/> &nbsp;◎ 功能：弹出消息提示框。<br/><br/> &nbsp;◎ 参数：分别是提示文字和对话框标题；以及对话框类型，与 MessageBox 意义相同，比如下面是图标类型：<br/><br/> &nbsp; &nbsp; #define MB_ICONERROR &nbsp; &nbsp; &nbsp; &nbsp;0x10<br/> &nbsp; &nbsp; #define MB_ICONQUESTION &nbsp; &nbsp; 0x20<br/> &nbsp; &nbsp; #define MB_ICONWARNING &nbsp; &nbsp; &nbsp;0x30<br/> &nbsp; &nbsp; #define MB_ICONINFORMATION &nbsp;0x40<br/><br/> &nbsp;◎ 示例：LOGO &#92;CeleSetup.LOG<br/><br/> &nbsp;◎ 备注：此命令不能在命令行参数中使用（必须在命令文件中使用）。命令文件结束之前，必须调用一次不带参数的“XLOG”命令，以关闭日志文件。公开发布的 ROM 中建议不要启用日志文件。<br/><br/><br/>■ IFEX [!]<路径><,命令><br/><br/> &nbsp;◎ 功能：判断路径是否存在，决定是否执行命令。<br/><br/> &nbsp;◎ 参数：<br/><br/> &nbsp; &nbsp;※ 路径 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;判断路径是否存在。前导“!”表示不存在才执行。<br/><br/> &nbsp; &nbsp;※ 命令 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要执行的命令。<br/><br/> &nbsp;◎ 示例：IFEX &#92;ABC.ini SHUT<br/><br/> &nbsp;◎ 备注：本命令可以嵌套使用，判断多个条件。<br/><br/><br/>四、致谢<br/><br/>◎ 感谢 PANFANS 论坛 提供的讨论场所。<br/>◎ 感谢热心的 Kavana 的意见并制作了精美图标。<br/><br/>五、许可<br/><br/>◎ 本程序及其源代码是可以免费获取的。<br/>◎ 如果您使用或修改了其中任何的源代码，则必须把使用这些源代码的项目以及项目内的所有源代码和文档公开。否则禁止使用本程序源代码的任何部分。<br/>◎ 您可以复制、分发和传播无限制数量的软件产品，但您必须保证每一份复制、分发和传播都必须是完整和真实的，包括所有有关本软件产品的软件、电子文档，版权和商标宣言。<br/>◎ 作者特此申明对本软件产品之使用不提供任何保证，不对任何用户保证本软件产品的适用性，不保证无故障产生；亦不对任何用户使用此软件所遭遇到的任何理论上的或实际上的损失承担 责任。<br/>◎ 如果您使用本软件，即表示已经默认接受了此协议。<br/><br/><br/>要获取更多信息，请访问 <a href="http://WWW.YONSM.NET" target="_blank">WWW.YONSM.NET</a><br/><br/><br/>Yonsm<br/>Yonsm@163.com<br/><a href="http://WWW.Yonsm.NET" target="_blank">WWW.Yonsm.NET</a><br/>2007.4.2，杭州<br/><br/><br/>下载：<span style="color: #FF4500;">（已过期，请参看更强大的 CeleCommand）</span><br/><br/>更新了，提供 Setup DLL 的版本，这下要制作功能强大的 CAB 包方便多了，比HTC的什么CustomizeTools垃圾好多了。用来做CAB的SetupDLL，无穷强大。DLL自动加载&#92;*就是所有子目录中的.csx）<br/><br/><span style="color: #FF0000;">注意：仅在 O2 XDA Neo Pocket PC Phone WM5 中测试通过，但理论上适用于所有 Windows Mobile 系统，包括 Smartphone/ Pocket PC 2003/5.0/6.0</span><br/><br/><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a> , <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E6%2589%258B%25E6%259C%25BA" rel="tag">手机</a> , <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E5%2588%2586%25E4%25BA%25AB" rel="tag">分享</a>
]]>
</description>
</item><item>
<link>HTTP://WWW.Yonsm.NET/read.php?301</link>
<title><![CDATA[用 ZLib 解压缩 TAR GZ 的最简单的过程和代码]]></title> 
<author>Yonsm &lt;Yonsm@163.com&gt;</author>
<category><![CDATA[代码]]></category>
<pubDate>Sun, 01 Apr 2007 13:47:53 +0000</pubDate> 
<guid>HTTP://WWW.Yonsm.NET/read.php?301</guid> 
<description>
<![CDATA[ 
	看代码，不多说，应该很简单，由于 ZLib 的可移植性，所以在 PC 和 Windows Mobile 下不加修改即可便已通过。详细代码下载可以参考 CeleSetup 的帖子。<br/> <br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>#include "UniBase.h"<br/>#include "ZLib/ZLib.h"<br/>#pragma comment(lib, "ZLib/ZLib.lib")<br/><br/>// Values used in typeflag field<br/>#define REGTYPE &nbsp; &nbsp; &nbsp; '0' &nbsp; &nbsp; &nbsp; // regular file<br/>#define AREGTYPE &nbsp; &nbsp; &nbsp;'&#92;0' &nbsp; &nbsp; &nbsp;// regular file<br/>#define LNKTYPE &nbsp; &nbsp; &nbsp; '1' &nbsp; &nbsp; &nbsp; // link<br/>#define SYMTYPE &nbsp; &nbsp; &nbsp; '2' &nbsp; &nbsp; &nbsp; // reserved<br/>#define CHRTYPE &nbsp; &nbsp; &nbsp; '3' &nbsp; &nbsp; &nbsp; // character special<br/>#define BLKTYPE &nbsp; &nbsp; &nbsp; '4' &nbsp; &nbsp; &nbsp; // block special<br/>#define DIRTYPE &nbsp; &nbsp; &nbsp; '5' &nbsp; &nbsp; &nbsp; // directory<br/>#define FIFOTYPE &nbsp; &nbsp; &nbsp;'6' &nbsp; &nbsp; &nbsp; // FIFO special<br/>#define CONTTYPE &nbsp; &nbsp; &nbsp;'7' &nbsp; &nbsp; &nbsp; // reserved<br/><br/>// &nbsp;GNU tar extensions<br/>#define GNUTYPE_DUMPDIR &nbsp; 'D' &nbsp; &nbsp; &nbsp; // file names from dumped directory<br/>#define GNUTYPE_LONGLINK &nbsp;'K' &nbsp; &nbsp; &nbsp; // long link name<br/>#define GNUTYPE_LONGNAME &nbsp;'L' &nbsp; &nbsp; &nbsp; // long file name<br/>#define GNUTYPE_MULTIVOL &nbsp;'M' &nbsp; &nbsp; &nbsp; // continuation of file from another volume<br/>#define GNUTYPE_NAMES &nbsp; 'N' &nbsp; &nbsp; &nbsp; // file name that does not fit into main hdr<br/>#define GNUTYPE_SPARSE &nbsp; &nbsp;'S' &nbsp; &nbsp; &nbsp; // sparse file<br/>#define GNUTYPE_VOLHDR &nbsp; &nbsp;'V' &nbsp; &nbsp; &nbsp; // tape/volume hdr<br/><br/><br/>#define MAX_BLOCK 512<br/>#define MAX_FNAME 100<br/><br/>struct TARHDR<br/>&#123;<br/> &nbsp;CHAR name[100]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; 0<br/> &nbsp;CHAR mode[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 100<br/> &nbsp;CHAR uid[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 108<br/> &nbsp;CHAR gid[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 116<br/> &nbsp;CHAR size[12]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 124<br/> &nbsp;CHAR mtime[12]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 136<br/> &nbsp;CHAR chksum[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 148<br/> &nbsp;CHAR typeflag; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 156<br/> &nbsp;CHAR linkname[100]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 157<br/> &nbsp;CHAR magic[6]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 257<br/> &nbsp;CHAR version[2]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 263<br/> &nbsp;CHAR uname[32]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 265<br/> &nbsp;CHAR gname[32]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 297<br/> &nbsp;CHAR devmajor[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 329<br/> &nbsp;CHAR devminor[8]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 337<br/> &nbsp;CHAR prefix[155]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 345<br/>&#125;;<br/><br/>typedef union _TARBUF<br/>&#123;<br/> &nbsp;TARHDR hdr;<br/> &nbsp;CHAR buf[MAX_BLOCK];<br/>&#125;<br/>TARBUF, *PTARBUF;<br/><br/><br/>// Convert octal digits to INT<br/>INT GetOct(PSTR p,INT iWidth)<br/>&#123;<br/> &nbsp;INT iResult = 0;<br/> &nbsp;while (iWidth--)<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;CHAR c = *p++;<br/> &nbsp; &nbsp;if (c == 0)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;if (c == ' ')<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;continue;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;if (c < '0' &#124;&#124; c > '7')<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;return -1;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;iResult = iResult * 8 + (c - '0');<br/> &nbsp;&#125;<br/> &nbsp;return iResult;<br/>&#125;<br/><br/>INT XTar(PTSTR ptzCmd)<br/>&#123;<br/> &nbsp;PTSTR ptzOutDir = ptzCmd;<br/> &nbsp;for (; *ptzOutDir; ptzOutDir++)<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;if (*ptzOutDir == ',')<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;*ptzOutDir++ = 0;<br/> &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp;&#125;<br/><br/> &nbsp;CHAR szPath[MAX_BLOCK];<br/> &nbsp;UStrToAStr(szPath, ptzCmd, MAX_PATH);<br/> &nbsp;gzFile gz = gzopen(szPath,"rb");<br/> &nbsp;if (!gz)<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;return -1;<br/> &nbsp;&#125;<br/><br/> &nbsp;INT iGetHeader = 1;<br/> &nbsp;INT iRemaining = 0;<br/> &nbsp;BOOL bFail = FALSE;<br/> &nbsp;HANDLE hFile = NULL;<br/> &nbsp;TCHAR tzName[MAX_PATH];<br/> &nbsp;do<br/> &nbsp;&#123;<br/> &nbsp; &nbsp;TARBUF buf;<br/> &nbsp; &nbsp;INT iLen = gzread(gz, &buf, MAX_BLOCK);<br/> &nbsp; &nbsp;if (iLen < 0)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;return -2;<br/> &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;// Always expect complete blocks to process the tar information.<br/> &nbsp; &nbsp;if (iLen != MAX_BLOCK)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;bFail = TRUE;<br/> &nbsp; &nbsp; &nbsp;iRemaining = 0;<br/> &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;// If we have to get a tar header<br/> &nbsp; &nbsp;if (iGetHeader >= 1)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;// if we met the end of the tar or the end-of-tar block, we are done<br/> &nbsp; &nbsp; &nbsp;if (iLen == 0 &#124;&#124; buf.hdr.name[0] == 0)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp; &nbsp;if (iGetHeader == 1)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;UAStrToStr(tzName, buf.hdr.name, MAX_PATH);<br/> &nbsp; &nbsp; &nbsp; &nbsp;UStrRep(tzName, '/', '&#92;&#92;');<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;iGetHeader = 1;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp; &nbsp;// Act according to the type flag<br/> &nbsp; &nbsp; &nbsp;switch (buf.hdr.typeflag)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;case DIRTYPE:<br/> &nbsp; &nbsp; &nbsp; &nbsp;TCHAR tzPath[MAX_PATH];<br/> &nbsp; &nbsp; &nbsp; &nbsp;UStrPrint(tzPath, TEXT("%s&#92;&#92;%s&#92;&#92;"), ptzOutDir, tzName);<br/> &nbsp; &nbsp; &nbsp; &nbsp;UDirCreate(tzPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp;case REGTYPE:<br/> &nbsp; &nbsp; &nbsp;case AREGTYPE:<br/> &nbsp; &nbsp; &nbsp; &nbsp;iRemaining = GetOct(buf.hdr.size, 12);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (iRemaining == -1)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bFail = TRUE;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UStrPrint(tzPath, TEXT("%s&#92;&#92;%s"), ptzOutDir, tzName);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UDirCreate(tzPath);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hFile = UFileOpen(tzPath, UFILE_WRITE);<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;iGetHeader = 0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br/><br/> &nbsp; &nbsp; &nbsp;case GNUTYPE_LONGLINK:<br/> &nbsp; &nbsp; &nbsp;case GNUTYPE_LONGNAME:<br/> &nbsp; &nbsp; &nbsp; &nbsp;iRemaining = GetOct(buf.hdr.size, 12);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (iRemaining < 0 &#124;&#124; iRemaining >= MAX_BLOCK)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bFail = TRUE;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;iLen = gzread(gz, szPath, MAX_BLOCK);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (iLen < 0)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return -4;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (szPath[MAX_BLOCK - 1] != 0 &#124;&#124; (INT) strlen(szPath) > iRemaining)<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bFail = TRUE;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp; &nbsp;iGetHeader = 2;<br/> &nbsp; &nbsp; &nbsp; &nbsp;break;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;else<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;UINT uSize = (iRemaining > MAX_BLOCK) ? MAX_BLOCK : iRemaining;<br/> &nbsp; &nbsp; &nbsp;if (hFile)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;UFileWrite(hFile, &buf, uSize);<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp; &nbsp;iRemaining -= uSize;<br/> &nbsp; &nbsp;&#125;<br/><br/> &nbsp; &nbsp;if (iRemaining == 0)<br/> &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp;iGetHeader = 1;<br/> &nbsp; &nbsp; &nbsp;if (hFile)<br/> &nbsp; &nbsp; &nbsp;&#123;<br/> &nbsp; &nbsp; &nbsp; &nbsp;UFileClose(hFile);<br/> &nbsp; &nbsp; &nbsp; &nbsp;hFile = NULL;<br/> &nbsp; &nbsp; &nbsp;&#125;<br/> &nbsp; &nbsp;&#125;<br/> &nbsp;&#125;<br/> &nbsp;while (!bFail);<br/><br/> &nbsp;gzclose(gz);<br/> &nbsp;return 0;<br/>&#125;</div></div><br/>Tags - <a href="HTTP://WWW.Yonsm.NET/tag.php?tag=%25E7%25BC%2596%25E7%25A8%258B" rel="tag">编程</a>
]]>
</description>
</item>
</channel>
</rss>