<?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>swigger's BLOG &#187; 开发</title>
	<atom:link href="http://www.swigger.net/archives/category/dev/feed" rel="self" type="application/rss+xml" />
	<link>http://www.swigger.net</link>
	<description>醉卧沙场君莫笑 古来征战几人回</description>
	<lastBuildDate>Tue, 24 Jan 2012 05:34:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>some notes for mac osx dev.</title>
		<link>http://www.swigger.net/archives/323.html</link>
		<comments>http://www.swigger.net/archives/323.html#comments</comments>
		<pubDate>Sun, 08 Jan 2012 08:06:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MAC]]></category>
		<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=323</guid>
		<description><![CDATA[set install_name for dylib g++ -install_name xxx.o -o xxx.dylib view install_name: method1: otool -L xxx.dylib see the first row. change install_name install_name_tool -change old.dylib new.dylib xxx.dylib pack libs lipo -create a_32.dylib a_64.dylib -output a.dylib]]></description>
			<content:encoded><![CDATA[<p>set install_name for dylib<br />
g++ -install_name xxx.o -o xxx.dylib</p>
<p>view install_name:<br />
method1:   otool -L xxx.dylib         see the first row.</p>
<p>change install_name<br />
install_name_tool -change old.dylib  new.dylib  xxx.dylib</p>
<p>pack libs<br />
lipo -create a_32.dylib a_64.dylib -output  a.dylib</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/323.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>calling task_for_pid on MAC OS X</title>
		<link>http://www.swigger.net/archives/262.html</link>
		<comments>http://www.swigger.net/archives/262.html#comments</comments>
		<pubDate>Fri, 01 Jul 2011 19:41:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MAC]]></category>
		<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=262</guid>
		<description><![CDATA[from mac 10.5 on, task_for_pid fails if the calling process has no root privilege. today I wrote a small app that needs this function, so I decided to make it run. Finding out the web , I found the result. There are something wrong or outdated on sites talk about it, so I wrote this [...]]]></description>
			<content:encoded><![CDATA[<p>from mac 10.5 on, task_for_pid fails if the calling process has no root privilege.</p>
<p>today I wrote a small app that needs this function, so I decided to make it run.</p>
<p>Finding out the web , I found the result.</p>
<p>There are something wrong or outdated on sites talk about it, so I wrote this article to helper those meet this problem.</p>
<p>Just follow these steps:</p>
<p>1. Find your .plist file in XCode and add a new entry “SecTaskAccess” and set it to string value “allowed”. Make sure the Info.plist file generated in your bundle actually has this value in it.</p>
<p>2. You need get a real code signing certificate NOT a self made one. Some websites are still talking making a self-signed certificate. This is outdated. An iphone certificate is OK while I think a MAC dev center certificate is better.</p>
<p>3. Make XCode sign the executable during the build process, or sign it yourself manually using the codesign command line utility.</p>
<p>4.Call the following method before making calls to task_for_pid()</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #339900;">#include &lt;Security/Authorization.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> acquireTaskportRight<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
OSStatus status<span style="color: #008080;">;</span>
AuthorizationItem taskport_item <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #FF0000;">&quot;system.privilege.taskport&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
AuthorizationRights rights <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span><span style="color: #0000dd;">1</span>, <span style="color: #000040;">&amp;</span>taskport_item<span style="color: #008000;">&#125;</span>, <span style="color: #000040;">*</span>out_rights <span style="color: #000080;">=</span> <span style="color: #0000ff;">NULL</span><span style="color: #008080;">;</span>
AuthorizationRef author<span style="color: #008080;">;</span>
AuthorizationFlags authorizationFlags <span style="color: #000080;">=</span> kAuthorizationFlagExtendRights <span style="color: #000040;">|</span> kAuthorizationFlagPreAuthorize	<span style="color: #000040;">|</span>
kAuthorizationFlagInteractionAllowed <span style="color: #000040;">|</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
status <span style="color: #000080;">=</span> AuthorizationCreate<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">NULL</span>,   kAuthorizationEmptyEnvironment, authorizationFlags, <span style="color: #000040;">&amp;</span>author<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>status <span style="color: #000040;">!</span><span style="color: #000080;">=</span> errAuthorizationSuccess<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>  <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>  <span style="color: #008000;">&#125;</span>
status <span style="color: #000080;">=</span> AuthorizationCopyRights<span style="color: #008000;">&#40;</span>author, <span style="color: #000040;">&amp;</span>rights, kAuthorizationEmptyEnvironment,
authorizationFlags, <span style="color: #000040;">&amp;</span>out_rights<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>status <span style="color: #000040;">!</span><span style="color: #000080;">=</span> errAuthorizationSuccess<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>  <span style="color: #0000ff;">return</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>  <span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>NOTE:</p>
<p>If you&#8217;re writing a command-line tool which has no info.plist file, you should make one and add the following arguments to your link command:</p>
<p>-sectcreate __TEXT   __info_plist  Info.plist.file.path</p>
<div>where Info.plist.file.path is the path to the Info.plist file.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/262.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>修改 vs2010 编译器使之支持u8&#8243;字符串”的形式</title>
		<link>http://www.swigger.net/archives/214.html</link>
		<comments>http://www.swigger.net/archives/214.html#comments</comments>
		<pubDate>Mon, 03 Jan 2011 07:28:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>
		<category><![CDATA[破解狂]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=214</guid>
		<description><![CDATA[vs有比较完善的unicode支持，从2005(或更早？)开始就支持源文件是utf-8，并且可以用中文做变量名函数名。（可以是可以，不推荐） 不过，也有一点很让人生气，就算源文件是utf-8编码的，编译时，他也会把utf-8转成主机的编码。所以，对于中文编码而言，如果源文件是 utf-8的并且有这样的内容，编译还是一样出问题： const char * test = "®"; tt.cpp(10) : warning C4566: character represented by universal-character-name '\u00AE' cannot be represented in the current code page (936) c++0x草案中有 u8&#8243;string literal” 形式的字符串，如果可以用这个，则问题解决，可惜的是，vs2010并不支持 u8-prefix string literal。当然，u和U也不支持。不过由于windows本身所说的unicode是utf-16 le，所以vc里L”string”就是u”string”。 如果才能让vc以持u8呢？写一个宏和字符串转化的类，在运行期转化是一个可行但比较折中的办法，这个办法最大的问题是依然不能在代码里写”®”这样的字串，因为编译期转成中文编码失败成?号，运行期转成utf-8还是问号。 当然，可以写 L”®”，这样这个u8类可以这样写： string to_utf8(const wchar_t*); #define U8(string)  to_utf8(string).c_str() 然后在用的地方写： U8(L”®”); 这样基本能用，但带来了一些运行期消耗。并且L的字符串也比较大。当然宏本身还可以改改，使得不需要写L，而是在预处理后加入L，但会带来额外的限制（想想U8(“hello” “world”)）。 能不能hack编译器加入u8的支持呢？经过一番研究，发现了点眉目。 首先，vc编译器编译的主要功能代码在c1xx.dll中。这个dll的x86版本位于 C:\Program Files (x86)\Microsoft Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<p>vs有比较完善的unicode支持，从2005(或更早？)开始就支持源文件是utf-8，并且可以用中文做变量名函数名。（可以是可以，不推荐）</p>
<p>不过，也有一点很让人生气，就算源文件是utf-8编码的，编译时，他也会把utf-8转成主机的编码。所以，对于中文编码而言，如果源文件是</p>
<p>utf-8的并且有这样的内容，编译还是一样出问题：</p>
<pre>const char * test = "®";
tt.cpp(10) : warning C4566: character represented by universal-character-name '\u00AE' cannot be represented in the current code page (936)</pre>
<p>c++0x草案中有 u8&#8243;string literal” 形式的字符串，如果可以用这个，则问题解决，可惜的是，vs2010并不支持 u8-prefix string literal。当然，u和U也不支持。不过由于windows本身所说的unicode是utf-16 le，所以vc里L”string”就是u”string”。</p>
<p>如果才能让vc以持u8呢？写一个宏和字符串转化的类，在运行期转化是一个可行但比较折中的办法，这个办法最大的问题是依然不能在代码里写”®”这样的字串，因为编译期转成中文编码失败成?号，运行期转成utf-8还是问号。</p>
<p>当然，可以写 L”®”，这样这个u8类可以这样写：</p>
<pre>string to_utf8(const wchar_t*);
#define U8(string)  to_utf8(string).c_str()</pre>
<p>然后在用的地方写：</p>
<p>U8(L”®”);</p>
<p>这样基本能用，但带来了一些运行期消耗。并且L的字符串也比较大。当然宏本身还可以改改，使得不需要写L，而是在预处理后加入L，但会带来额外的限制（想想U8(“hello” “world”)）。</p>
<p>能不能hack编译器加入u8的支持呢？经过一番研究，发现了点眉目。</p>
<p>首先，vc编译器编译的主要功能代码在c1xx.dll中。这个dll的x86版本位于 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\c1xx.dll。惊喜的是微软提供了它的pdb，这样分析它的行为就大大简化了。</p>
<p>经过研究发现，vc基本上函展开，获取token生成语法树是一次过的。</p>
<p>在关键函数</p>
<p>4F4C9430 GetTokenFromCurrentChar</p>
<p>处，会有一个循环，从一个全局变量中读取解析到的内容，然后构造出一个token。我们要做的就是hack这个过程，如果当前token符合 u8&#8243;string”的形式，则处理一遍字符串，转成8进制的串表示方法。</p>
<p>经过一番苦战成功后，结果如下：</p>

<div class="wp_syntax"><div class="code"><pre class="outline" style="font-family:monospace;">&nbsp;
tt.cpp:
&nbsp;
#define U8(str) u8##str
#define U16(str) L##str
&nbsp;
int main()
{
&nbsp;
U8(&quot;哈&quot;);
u8&quot;哈&quot;;
return 0;
}
&nbsp;
D:\temp&gt;cl /E tt.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.
&nbsp;
tt.cpp
#line 1 &quot;tt.cpp&quot;
int main()
{
&nbsp;
&quot;\345\223\210&quot;;
&quot;\345\223\210&quot;;
return 0;
}</pre></div></div>

<p>使用的办法是：</p>
<p>把原始的c1xx.dll重命名为c1xx_.dll，写了一个假的c1xx.dll，把导出函数的调用都重定位到c1xx_.dll。然后在GetTokenFromCurrentChar的循环开始处：</p>
<p>4F4C943E                                             8B3D 046C644F    MOV EDI,DWORD PTR DS:[Current_char]</p>
<p>写入一个跳转，跳转到自己的函数中检查是否需要替换字串。写完后变成：</p>
<p>4F4C943E                                             E8 4D7EB60E      CALL c1xx.asmReplCurCode<br />
4F4C9443                                             90               NOP</p>
<p>这个被调用的函数是这样的：<br />
__declspec(naked) void asmReplCurCode()<br />
{<br />
__asm<br />
{<br />
pushad;<br />
call ReplCurCode;<br />
popad;<br />
mov edi, [ptrCurChar];<br />
mov edi, [edi];<br />
ret;<br />
}<br />
}<br />
即用汇编做一个简单的包装，调用C++函数，然后完成被覆盖的代码要完成的事，然后ret回去。</p>
<p>ReplCurCode是这样的：</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> ReplCurCode<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>g_pred <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
g_pred <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">char</span> ch <span style="color: #000080;">=</span> <span style="color: #000040;">**</span> ptrCurChar<span style="color: #008080;">;</span>
<span style="color: #666666;">//note: in creating/using precompiled header mode, don't insert this code since it had done before.</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>ch <span style="color: #000080;">==</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #000040;">||</span> ch <span style="color: #000080;">==</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
replace <span style="color: #000080;">=</span> <span style="color: #000040;">*</span>ptrCurChar<span style="color: #008080;">;</span>
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> scode <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>#define __bultin_u8 1<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>1<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
match <span style="color: #000080;">=</span> scode <span style="color: #000040;">+</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>scode<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
<span style="color: #000040;">*</span>ptrCurChar <span style="color: #000080;">=</span> scode<span style="color: #008080;">;</span>
<span style="color: #0000ff;">return</span> <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>ptrCurChar <span style="color: #000080;">==</span> match<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #000040;">*</span>ptrCurChar <span style="color: #000080;">=</span> replace<span style="color: #008080;">;</span>
match <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
replace <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> src <span style="color: #000080;">=</span> <span style="color: #000040;">*</span>ptrCurChar<span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'#'</span> <span style="color: #000040;">&amp;&amp;</span> src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'d'</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">int</span> ff <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
string prefix<span style="color: #008080;">;</span>
<span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">isspace</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
prefix <span style="color: #000040;">+</span><span style="color: #000080;">=</span> src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #000040;">++</span> src<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'u'</span> <span style="color: #000040;">&amp;&amp;</span>  src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'8'</span> <span style="color: #000040;">&amp;&amp;</span> src<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'&quot;'</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #666666;">//so this is a U8 str.</span>
string sb<span style="color: #008080;">;</span>
<span style="color: #0000ff;">size_t</span> sz <span style="color: #000080;">=</span> TextProcess<span style="color: #008080;">::</span><span style="color: #007788;">unescape</span><span style="color: #008000;">&#40;</span>src<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span>, MAXLONG, sb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>src<span style="color: #008000;">&#91;</span>sz<span style="color: #000040;">+</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">'&quot;'</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
string st <span style="color: #000080;">=</span> TextProcess<span style="color: #008080;">::</span><span style="color: #007788;">escape</span><span style="color: #008000;">&#40;</span>sb.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, sb.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
string <span style="color: #000040;">&amp;</span> codestr <span style="color: #000080;">=</span> getPool<span style="color: #008000;">&#40;</span>prefix <span style="color: #000040;">+</span> st, src<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
match   <span style="color: #000080;">=</span> codestr.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> codestr.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
replace <span style="color: #000080;">=</span> src<span style="color: #000040;">+</span>sz<span style="color: #000040;">+</span><span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
<span style="color: #000040;">*</span>ptrCurChar <span style="color: #000080;">=</span> codestr.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>在首次处理的时候插入一个宏定义，这样代码中就可以知道编译器是不是修改支持了u8的功能。ptrCurChar是微软的c1xx.dll中的全局变量的地址，通过它知道当前要解析什么样的代码，解析完之后替换掉它，使得</p>
<p>u8&#8243;哈”</p>
<p>交给微软cl.exe解释的时候变成  ”\345\223\210&#8243; 当然下一次再跑到这里的时候，比较是不是解释完我设置的替换串了，是的话换回原始要解释的内容，当然是跳过了u8&#8243;哈”这个串的。</p>
<p>即： if(*ptrCurChar == match) *ptrCurChar = replace;</p>
<p>这样处理完了之后，vs2010就完美的支持u8&#8243;string”了。不过只能小范围内使用或写一些自己用的工具，对于大的团队而言，还是等微软下一个vs吧，也许那时就真正支持u8&#8243;literal string”了。</p>
<p>其实不只是 u8 literal string，这样改编译器，还能实现一些更有意思的东西。</p>
<p>dowload:  <a class="wpGallery" href="/soft/hack_c1xx.dll">hack_c1xx.dll </a></p>
<p>仅适用于原始md5为D05630986B03CBB28CD4D8E1BDD65831的c1xx.dll。</p>
<p>把原始c1xx.dll改名为c1xx_.dll，把hack_c1xx.dll改名为c1xx.dll</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/214.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Test unsigned drivers in windows vista/7 x64</title>
		<link>http://www.swigger.net/archives/208.html</link>
		<comments>http://www.swigger.net/archives/208.html#comments</comments>
		<pubDate>Thu, 23 Sep 2010 11:03:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=208</guid>
		<description><![CDATA[How to Disable Signature Enforcement during Development During the early stages of development, developers can disable enforcement in Windows so that driver signing is not necessary. The following options are available for developers to disable kernel mode code signing enforcement temporarily so that Windows Vista will load an unsigned driver. Attaching a kernel debugger. Attaching [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How to Disable Signature Enforcement during Development</strong></p>
<p>During the early stages of development, developers can disable enforcement in Windows so that driver signing is not necessary. The following options are available for developers to disable kernel mode code signing enforcement temporarily so that Windows Vista will load an unsigned driver.</p>
<ul>
<li><strong>Attaching a kernel debugger. </strong>Attaching an active kernel debugger to the target computer disables the enforcement of kernel mode signatures in Windows Vista and allows the driver to load.</li>
<li><strong>Using the F8 option. </strong>An F8 Advanced Boot Option introduced with Windows Vista—“Disable Driver Signature Enforcement”—is available to disable the kernel-signing enforcement only for the current boot session. This setting does not persist across boot sessions.</li>
<li><strong>Setting the boot configuration. </strong>A boot configuration setting is available in the Windows Vista Beta2 release that disables the enforcement of kernel mode signatures to be persisted across boot sessions.</li>
</ul>
<p>bcdedit /copy {current} /d “test_driver”<br />
set GUID={guid-returned-by-previous-command}<br />
bcdedit /set %GUID% loadoptions DDISABLE_INTEGRITY_CHECKS<br />
bcdedit /set %GUID% testsigning on<br />
bcdedit /set %GUID% nointegritychecks ON <strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/208.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在Debian Linux下编译第一个objc程序</title>
		<link>http://www.swigger.net/archives/202.html</link>
		<comments>http://www.swigger.net/archives/202.html#comments</comments>
		<pubDate>Wed, 11 Aug 2010 17:08:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=202</guid>
		<description><![CDATA[  首先，我们要安装相应的程序： apt-get install gcc gobjc gcc g++ gnustep libgnustep-gui-dev 然后编写一个hello.m文件： 连hello.m都是抄来的，哈哈，程序如下： #import &#60;Foundation/Foundation.h&#62; @interface HelloWorld : NSObject - (void) hello; @end @implementation HelloWorld - (void) hello { NSLog(@”hello world!”); } @end int main(void) { HelloWorld *hw = [[HelloWorld alloc] init]; [hw hello]; [hw release]; } 然后就是编译了： 编译成.o文件： gcc -fconstant-string-class=NSConstantString -I /usr/include/GNUstep/ -c hello.m 链接： [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<h1>首先，我们要安装相应的程序：</h1>
<p>apt-get install gcc gobjc gcc g++ gnustep libgnustep-gui-dev</p>
<h1>然后编写一个hello.m文件：</h1>
<p>连hello.m都是抄来的，哈哈，程序如下：</p>
<p>#import &lt;Foundation/Foundation.h&gt;</p>
<p>@interface HelloWorld : NSObject</p>
<p>- (void) hello;</p>
<p>@end</p>
<p>@implementation HelloWorld</p>
<p>- (void) hello {</p>
<p>NSLog(@”hello world!”);</p>
<p>}</p>
<p>@end</p>
<p>int main(void) {</p>
<p>HelloWorld *hw = [[HelloWorld alloc] init];</p>
<p>[hw hello];</p>
<p>[hw release];</p>
<p>}</p>
<h1>然后就是编译了：</h1>
<p>编译成.o文件：</p>
<p>gcc -fconstant-string-class=NSConstantString -I /usr/include/GNUstep/ -c hello.m</p>
<p>链接：</p>
<p>gcc hello.o -o hello -lgnustep-base</p>
<h1>一些方便的设置：</h1>
<p>在bashrc中添加一条：</p>
<p>alias objcc=’gcc -fconstant-string-class=NSConstantString -I /usr/include/GNUstep/ -lgnustep-base’</p>
<p>以上命令就简化啦：</p>
<p>objcc –o hello hello.m</p>
<h1>运行：</h1>
<p>$ ./hello</p>
<p>2010-08-12 01:03:23.930 hello[1642] hello world!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/202.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>用vs2010自带工具制作文件证书</title>
		<link>http://www.swigger.net/archives/193.html</link>
		<comments>http://www.swigger.net/archives/193.html#comments</comments>
		<pubDate>Sat, 08 May 2010 11:44:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=193</guid>
		<description><![CDATA[以便给自己的程序签名，呵呵。 当然，这样签 发的程序在别人那是不被信任的。除非把自己的根证书给别人安装。 用命令行，使用如下命令： makecert  -pe -ss swigger -n “CN=swigger.net” -sv swigger_root.pvk -r swigger_root.cer 这里会弹出框要求密码，输入密码 root_pwd 或其它密码。共输入3次，前两次设置，后一次验证。 makecert -is swigger -n “CN=swigger file sign” -$ commercial -ic swigger_root.cer -sv fs.pvk fs.cer 这里继续弹出要密码，设置为 pwd2 或其它密码。共输入三次，两次设置，一次确认。还会弹出第四次要密码，要输入上一步设置的密码 root_pwd （或其它值）。 cert2spc fs.cer fs.spc 以下两条命令的pwd2是第二步设置的密码，如果不是pwd2，要换成其它值。 pvk2pfx -pvk fs.pvk -pi pwd2 -spc fs.spc -pfx fs.pfx -f signtool sign /t http://timestamp.verisign.com/scripts/timstamp.dll  /v  [...]]]></description>
			<content:encoded><![CDATA[<p>以便给自己的程序签名，呵呵。</p>
<p>当然，这样签 发的程序在别人那是不被信任的。除非把自己的根证书给别人安装。</p>
<p>用命令行，使用如下命令：</p>
<p>makecert  -pe -ss swigger -n “CN=swigger.net” -sv swigger_root.pvk -r swigger_root.cer</p>
<p>这里会弹出框要求密码，输入密码 root_pwd 或其它密码。共输入3次，前两次设置，后一次验证。</p>
<p>makecert -is swigger -n “CN=swigger file sign” -$ commercial -ic swigger_root.cer -sv fs.pvk fs.cer</p>
<p>这里继续弹出要密码，设置为 pwd2 或其它密码。共输入三次，两次设置，一次确认。还会弹出第四次要密码，要输入上一步设置的密码 root_pwd （或其它值）。</p>
<p>cert2spc fs.cer fs.spc</p>
<p>以下两条命令的pwd2是第二步设置的密码，如果不是pwd2，要换成其它值。</p>
<p>pvk2pfx -pvk fs.pvk -pi pwd2 -spc fs.spc -pfx fs.pfx -f</p>
<p>signtool sign /t <a href="http://timestamp.verisign.com/scripts/timstamp.dll">http://timestamp.verisign.com/scripts/timstamp.dll</a>  /v  /f fs.pfx /p pwd2  filename.exe</p>
<p>签名完成后，把swigger_root.cer安装到受信用的根证书，就显示文件正常签名了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/193.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>为android 生成 native 程序</title>
		<link>http://www.swigger.net/archives/181.html</link>
		<comments>http://www.swigger.net/archives/181.html#comments</comments>
		<pubDate>Sun, 11 Apr 2010 10:02:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=181</guid>
		<description><![CDATA[  为android生成原生应用程序，不难啊。 初始条件：安装android的ndk，比如目前最新的 android-ndk-r3。(2010-03版) 我的目录结构： ~/android-ndk-r3 ~/android-ndk-r3/temp  这个是当前工作目录。 Step1: 写两个文件： hello.c： #include &#60;stdio.h&#62; &#160; int main&#40;&#41; &#123;     printf&#40;&#34;hello, world\n&#34;&#41;;     return 0; &#125; start.c #include &#60;stdlib.h&#62; extern int main&#40;int argc, char **argv&#41;; &#160; void _start&#40;int argc, char **argv&#41; &#123;     exit &#40;main &#40;argc, argv&#41;&#41;; &#125; Step2: compile [code] ../build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc \ -I ../build/platforms/android-3/arch-arm/usr/include/  -c hello.c [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>为android生成原生应用程序，不难啊。<br />
初始条件：安装android的ndk，比如目前最新的 android-ndk-r3。(2010-03版)<br />
我的目录结构：<br />
~/android-ndk-r3<br />
~/android-ndk-r3/temp  这个是当前工作目录。</p>
<p>Step1: 写两个文件：<br />
hello.c：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;hello, world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>start.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> _start<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    exit <span style="color: #009900;">&#40;</span>main <span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Step2: compile<br />
[code]<br />
../build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc \<br />
-I ../build/platforms/android-3/arch-arm/usr/include/  -c hello.c<br />
../build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc \<br />
-I ../build/platforms/android-3/arch-arm/usr/include/  -c start.c<br />
[/code]</p>
<p>Step3: link<br />
[code]<br />
../build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-ld --entry=_start \<br />
--dynamic-linker /system/bin/linker -nostdlib     -rpath /system/lib  \<br />
-L ../build/platforms/android-3/arch-arm/usr/lib/  \<br />
-rpath ../build/platforms/android-3/arch-arm/usr/lib/    \<br />
-lc -o hello hello.o start.o<br />
[/code]</p>
<p>Step4: execute:<br />
[code]<br />
adb push hello /data/hello<br />
adb shell<br />
cd /data<br />
chmod 755 ./hello<br />
./hello<br />
hello, world<br />
[/code]</p>
<p>值得注意的一点是，在/sdcard目录下，程序运行不起来。我一开始还以为是没编好呢。后来扔到/data目录下，才成功跑起来。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/181.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>调试XP/2k3的安装过程</title>
		<link>http://www.swigger.net/archives/170.html</link>
		<comments>http://www.swigger.net/archives/170.html#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:54:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=170</guid>
		<description><![CDATA[ 在安装的源盘根目录提供一个winnt.sif，写上： [SetupData] OsLoadOptions = “/noguiboot /fastdetect /debug /debugport=com1 /baudrate=115200 /break” 即可。 不过XP的setupldr.bin不支持这个，要win2k3的才行。（推荐sp1。sp2加载ramdisk有卡住bug）]]></description>
			<content:encoded><![CDATA[<p> 在安装的源盘根目录提供一个winnt.sif，写上：</p>
<p>[SetupData]<br />
OsLoadOptions = “/noguiboot /fastdetect /debug /debugport=com1 /baudrate=115200 /break”</p>
<p>即可。</p>
<p>不过XP的setupldr.bin不支持这个，要win2k3的才行。（推荐sp1。sp2加载ramdisk有卡住bug）</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/170.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>regsavekey (ntsavekey) 异常的调试过程</title>
		<link>http://www.swigger.net/archives/166.html</link>
		<comments>http://www.swigger.net/archives/166.html#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:41:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=166</guid>
		<description><![CDATA[结论非常简单，要先调用  NtInitializeRegistry. 参数见 wrk 中的 ntregapi.h 过程比较复杂，在smss.exe中用bootexecute启动的native程序里，调用 ntsavekey达不到想要的结果。 NtSaveKey会返回0，也就是没有错误。结果文件也会生成，生成的大小看起来也是对的。但是文件里面没有任何内容。所有字节都是0。 调试过程： 1. smss.exe启动的native程序是非常早的，可能是系统还有什么没准备好。试着替换其它程序而不是被smss.exe启动，来看看。 2. 替换winlogon.exe，发现能保存。 3. 替换 csrss.exe，发现也能保存。 4. 由于启动时候，smss创建csrss.exe ，后者再创建winlogon.exe。因此可以知道，在smss.exe调用native exe之后，启动csrss.exe之间，一定发生了什么事，使得ntsavekey在其前不能运行，其后可以运行。 5. 写一个简单的DLL，提供一个函数调用ntsavekey做测试，用lordpe把此DLL添加到smss.exe的依赖里。 6. WINDBG调试smss.exe启动native app后的路径，它每调几个函数就试下DLL中提供的函数看看ntsavekey是否正常。 7. 调试发现，在 NtInitializeRegistry之前，ntsavekey出现异常结果，之后，正常。 8. 结论： NtSaveKey需要用NtInitializeRegistry初始化注册表。]]></description>
			<content:encoded><![CDATA[<p>结论非常简单，要先调用  NtInitializeRegistry. 参数见 wrk 中的 ntregapi.h</p>
<p>过程比较复杂，在smss.exe中用bootexecute启动的native程序里，调用 ntsavekey达不到想要的结果。</p>
<p>NtSaveKey会返回0，也就是没有错误。结果文件也会生成，生成的大小看起来也是对的。但是文件里面没有任何内容。所有字节都是0。</p>
<p>调试过程：</p>
<p>1. smss.exe启动的native程序是非常早的，可能是系统还有什么没准备好。试着替换其它程序而不是被smss.exe启动，来看看。</p>
<p>2. 替换winlogon.exe，发现能保存。</p>
<p>3. 替换 csrss.exe，发现也能保存。</p>
<p>4. 由于启动时候，smss创建csrss.exe ，后者再创建winlogon.exe。因此可以知道，在smss.exe调用native exe之后，启动csrss.exe之间，一定发生了什么事，使得ntsavekey在其前不能运行，其后可以运行。</p>
<p>5. 写一个简单的DLL，提供一个函数调用ntsavekey做测试，用lordpe把此DLL添加到smss.exe的依赖里。</p>
<p>6. WINDBG调试smss.exe启动native app后的路径，它每调几个函数就试下DLL中提供的函数看看ntsavekey是否正常。</p>
<p>7. 调试发现，在 NtInitializeRegistry之前，ntsavekey出现异常结果，之后，正常。</p>
<p>8. 结论： NtSaveKey需要用NtInitializeRegistry初始化注册表。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/166.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>转载： windbg 如何在内核模式调试用户空间的程序</title>
		<link>http://www.swigger.net/archives/163.html</link>
		<comments>http://www.swigger.net/archives/163.html#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:31:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[开发]]></category>

		<guid isPermaLink="false">http://www.swigger.net/?p=163</guid>
		<description><![CDATA[1：使用!process 0 0 获取用户空间的所有的进程的信息  !process 0 0 **** NT ACTIVE PROCESS DUMP ****     PROCESS 80a02a60  Cid: 0002    Peb: 00000000  ParentCid: 0000     DirBase: 00006e05  ObjectTable: 80a03788  TableSize: 150.     Image: System  。。。。。 2：使用.process /p + 你需要断的应用程序的EProcess地址切换到应用程序的地址空间    例如：  .process  /p  0x80a02a60 3：重新加载user PDB文件      .reload /f /user 4：使用非侵入式的切换进程空间     .process /i /p 0x80a02a60 5：下应用层断点  bp        [...]]]></description>
			<content:encoded><![CDATA[<p>1：使用!process 0 0 获取用户空间的所有的进程的信息</p>
<p> !process 0 0</p>
<p>**** NT ACTIVE PROCESS DUMP ****<br />
    PROCESS 80a02a60  Cid: 0002    Peb: 00000000  ParentCid: 0000<br />
    DirBase: 00006e05  ObjectTable: 80a03788  TableSize: 150.<br />
    Image: System</p>
<p> 。。。。。</p>
<p>2：使用.process /p + 你需要断的应用程序的EProcess地址切换到应用程序的地址空间</p>
<p>   例如：</p>
<p> .process  /p  0x80a02a60</p>
<p>3：重新加载user PDB文件</p>
<p>     .reload /f /user</p>
<p>4：使用非侵入式的切换进程空间</p>
<p>    .process /i /p 0x80a02a60</p>
<p>5：下应用层断点  bp        bu      都可以</p>
<p>原文：<a href="http://blog.csdn.net/purplethunder/archive/2009/04/04/4048379.aspx">http://blog.csdn.net/purplethunder/archive/2009/04/04/4048379.aspx</a></p>
<p>另外顺便证下在windbg调试时强制调用一个函数：（设函数名是 test_reg）</p>
<p>r esp=esp-4 ; ed esp eip ; r eip = test_reg</p>
]]></content:encoded>
			<wfw:commentRss>http://www.swigger.net/archives/163.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

