<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4691487066079235488</id><updated>2024-09-05T06:09:18.336+08:00</updated><category term="Information"/><category term="Reversing and Analyzing"/><category term="Hackers Delight"/><category term="Bookmark"/><title type='text'>Nono Liang&#39;s Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-8621132985512100921</id><published>2014-05-08T10:42:00.000+08:00</published><updated>2014-05-08T13:51:53.123+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bookmark"/><title type='text'>Enabling client certificate verification 懶人包</title><content type='html'>&lt;a href=&quot;http://wiki.egee-see.org/index.php/Simple_Apache-SSL_integration_and_DN-based_authentication&quot;&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Apache&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://wiki.egee-see.org/index.php/Simple_Apache-SSL_integration_and_DN-based_authentication&quot;&gt;http://wiki.egee-see.org/index.php/Simple_Apache-SSL_integration_and_DN-based_authentication&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Describe valid client DN list in text file&lt;br /&gt;
&lt;br /&gt;
&lt;dd style=&quot;background-color: white; line-height: 19.049999237060547px; margin-bottom: 0.1em; margin-left: 2em;&quot;&gt;&lt;ul style=&quot;line-height: 1.5em; list-style-image: url(http://wiki.egee-see.org/skins/monobook/bullet.gif); list-style-type: square; margin: 0.3em 0px 0px 1.5em; padding: 0px;&quot;&gt;
&lt;li style=&quot;margin-bottom: 0.1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;The resource can be reached only by specified clientâ€™s DNs&lt;br /&gt;The list of clientâ€™s DNs can be put in any file and in this example&amp;nbsp;&lt;i&gt;/etc/httpd/see-grid.users&lt;/i&gt;&amp;nbsp;is used. This is the example of file contents&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); line-height: 1.1em; padding: 1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;  /C=RS/O=AEGIS/OU=Institute of Physics Belgrade/CN=Neda Svraka:xxj31ZMTZzkVA
  /C=RS/O=AEGIS/OU=Institute of Physics Belgrade/CN=Branimir Ackovic:xxj31ZMTZzkVA
  /C=RS/O=AEGIS/OU=Institute of Physics Belgrade/CN=Antun Balaz:xxj31ZMTZzkVA
  /C=RS/O=AEGIS/OU=Institute of Physics Belgrade/CN=Dusan Vudragovic:xxj31ZMTZzkVA
&lt;/span&gt;&lt;/pre&gt;
&lt;div style=&quot;line-height: 1.5em; margin-bottom: 0.5em; margin-top: 0.4em;&quot;&gt;
&lt;/div&gt;
&lt;/dd&gt;&lt;dd style=&quot;background-color: white; line-height: 19.049999237060547px; margin-bottom: 0.1em; margin-left: 2em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;Note that&amp;nbsp;&lt;b&gt;FakeBasicAuth&lt;/b&gt;&amp;nbsp;must have &quot;&lt;b&gt;:xxj31ZMTZzkVA&lt;/b&gt;&quot; as a suffix for every DN. In this case&amp;nbsp;&lt;i&gt;/etc/httpd/conf/httpd.conf&lt;/i&gt;&amp;nbsp;file should contain following lines&lt;/span&gt;&lt;/dd&gt;&lt;br /&gt;
&lt;div style=&quot;line-height: 1.5em; margin-bottom: 0.5em; margin-top: 0.4em;&quot;&gt;
&lt;/div&gt;
&lt;pre style=&quot;background-color: #f9f9f9; border: 1px dashed rgb(47, 111, 171); line-height: 1.1em; padding: 1em;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;  &lt;directory html=&quot;&quot; see-grid=&quot;&quot; var=&quot;&quot; www=&quot;&quot;&gt;
       SSLRequireSSL
       SSLVerifyClient      require
       SSLVerifyDepth       5
       SSLOptions           +FakeBasicAuth
       AuthName             &quot;SEE-GRID Authentication&quot;
       AuthType             Basic
       AuthUserFile         /etc/httpd/see-grid.users
       require              valid-user
  &lt;/directory&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;a href=&quot;http://www.iis.net/configreference/system.webserver/security/authentication/iisclientcertificatemappingauthentication&quot;&gt;IIS&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.iis.net/configreference/system.webserver/security/authentication/iisclientcertificatemappingauthentication&quot;&gt;http://www.iis.net/configreference/system.webserver/security/authentication/iisclientcertificatemappingauthentication&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Describe valid client base64 encoded certificate in XML file&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;a href=&quot;http://www.chesterproductions.net.nz/blogs/it/code/configuring-client-certificate-authentication-with-tomcat-and-java/537/&quot;&gt;Tomcat&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.chesterproductions.net.nz/blogs/it/code/configuring-client-certificate-authentication-with-tomcat-and-java/537/&quot;&gt;http://www.chesterproductions.net.nz/blogs/it/code/configuring-client-certificate-authentication-with-tomcat-and-java/537/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Put valid client certificate to server side key store&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;a href=&quot;http://blog.nategood.com/client-side-certificate-authentication-in-ngi&quot;&gt;Nginx&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://blog.nategood.com/client-side-certificate-authentication-in-ngi&quot;&gt;http://blog.nategood.com/client-side-certificate-authentication-in-ngi&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Write validator by yourself&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;color: #333333; font-weight: normal; margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;Configuring nginx&lt;/span&gt;&lt;/h2&gt;
&lt;pre style=&quot;color: #333333; line-height: 24px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;server {
    listen        443;
    ssl on;
    server_name example.com;

    ssl_certificate      /etc/nginx/certs/server.crt;
    ssl_certificate_key  /etc/nginx/certs/server.key;
    ssl_client_certificate /etc/nginx/certs/ca.crt;
    ssl_verify_client optional;

    location / {
        root           /var/www/example.com/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME /var/www/example.com/lib/Request.class.php;
        fastcgi_param  VERIFIED $ssl_client_verify;
        fastcgi_param  DN $ssl_client_s_dn;
        include        fastcgi_params;
    }
}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;color: #333333; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;First, we pass in the&amp;nbsp;&lt;code&gt;$ssl_client_verify&lt;/code&gt;&amp;nbsp;variable as the&lt;code&gt;VERIFIED&lt;/code&gt;&amp;nbsp;parameter. This is useful when we are allowing authenticated and unauthenticated requests. When the client certificate was able to be verified against our CA cert, this will have the value of&amp;nbsp;&lt;code&gt;SUCCESS&lt;/code&gt;. Otherwise, the value will be&amp;nbsp;&lt;code&gt;NONE&lt;/code&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;Second, you&#39;ll notice we pass the&amp;nbsp;&lt;code&gt;$ssl_client_s_dn&lt;/code&gt;&amp;nbsp;variable to the&lt;code&gt;DN&lt;/code&gt;&amp;nbsp;parameter. This will provide &quot;the line subject DN of client certificate for established SSL-connection&quot;. The Common Name part of this certificate may be of most interest for you. Here is an example value for DN...&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;color: #333333; line-height: 24px;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;/C=US/ST=Florida/L=Orlando/O=CLIENT NAME/CN=CLIENT NAME&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;color: #333333; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;Nginx also provides the option to pass in the entire client certificate via&lt;code&gt;$ssl_client_cert&lt;/code&gt;&amp;nbsp;or&amp;nbsp;&lt;code&gt;$ssl_client_cert_raw&lt;/code&gt;. For more details on the SSL options available to you in nginx, checkout the&amp;nbsp;&lt;a href=&quot;http://wiki.nginx.org/NginxHttpSslModule&quot; style=&quot;color: #333333;&quot;&gt;Nginx Http SSL Module Wiki&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #333333; font-family: Petrona, serif; font-size: 16px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;http://redmine.lighttpd.net/boards/2/topics/3684&quot;&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Lighttpd&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://redmine.lighttpd.net/boards/2/topics/3684&quot;&gt;http://redmine.lighttpd.net/boards/2/topics/3684&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Write validator by yourself&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; color: #484848;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;I had client side SSL working a few months ago, though now it&#39;s broken for me and I can&#39;t get it to work. Would be grateful if you could share your notes.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #484848;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;To get the SSL_CLIENT_S_DN_CN passed through to my applications, I had the following config:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #484848;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;$SERVER[&quot;socket&quot;] == &quot;192.168.1.65:8443&quot; {&lt;br /&gt;ssl.engine = &quot;enable&quot;,&lt;br /&gt;ssl.pemfile = &quot;/path/to/cert.pem&quot;,&lt;br /&gt;ssl.ca-file = &quot;/path/to/crtchain.crt&quot;,&lt;br /&gt;ssl.verifyclient.activate = &quot;enable&quot;,&lt;br /&gt;ssl.verifyclient.enforce = &quot;enable&quot;,&lt;br /&gt;ssl.verifyclient.depth = 2,&lt;br /&gt;ssl.verifyclient.exportcert = &quot;enable&quot;,&lt;br /&gt;ssl.verifyclient.username = &quot;SSL_CLIENT_S_DN_CN&quot;&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #484848;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;Then in my application I could fetch the SSL_CLIENT_S_DN_CN by querying the request environment variables, eg:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #484848;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;request.env[&#39;REMOTE_USER&#39;]&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #484848; font-family: &#39;Lucida Grande&#39;, verdana, arial, helvetica, sans-serif; font-size: 12px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/8621132985512100921/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/8621132985512100921' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8621132985512100921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8621132985512100921'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2014/05/bookmark-one-to-one-client-certificate.html' title='Enabling client certificate verification 懶人包'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-7263048039414501385</id><published>2010-03-14T16:35:00.007+08:00</published><updated>2010-10-25T14:15:27.192+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>Constructor</title><content type='html'>g++&lt;br /&gt;&lt;a style=&quot;&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8bFafEjlUOlCmzg6ErgLjOrYB9WGAYH8zpVVs-28VojGAd5p1vYkUY1f-55zWH2PJ0ySHfo6zuHLU_uSOlEmz-8zNXTmQPlQf0uTck_PEQQC2-fvFtQvw0ORN0CmxXKT_j2dNUVFLiyU/s1600-h/constructor_g++.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 159px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8bFafEjlUOlCmzg6ErgLjOrYB9WGAYH8zpVVs-28VojGAd5p1vYkUY1f-55zWH2PJ0ySHfo6zuHLU_uSOlEmz-8zNXTmQPlQf0uTck_PEQQC2-fvFtQvw0ORN0CmxXKT_j2dNUVFLiyU/s320/constructor_g++.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5448409031164259746&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;vc++&lt;br /&gt;&lt;a style=&quot;&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXh3CoI1QxhoA8dvLhd16jbFrSgQYiUjP_u_mQZ4ZWs769UegjkflNKF3Tz7zJyvMMkgppjZOVVVZpsR8Opuip3rnLpeGvl88LupwPEDEI6eT8dvvXZjN5xLp2ZiagwMY-EsOIJMVCdPQ/s1600-h/constructor.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 162px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXh3CoI1QxhoA8dvLhd16jbFrSgQYiUjP_u_mQZ4ZWs769UegjkflNKF3Tz7zJyvMMkgppjZOVVVZpsR8Opuip3rnLpeGvl88LupwPEDEI6eT8dvvXZjN5xLp2ZiagwMY-EsOIJMVCdPQ/s320/constructor.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5448405492899945682&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Derived constructor -&gt; Base constructor -&gt; Derived &lt;span class=&quot;blsp-spelling-error&quot; id=&quot;SPELLING_ERROR_0&quot;&gt;vtable&lt;/span&gt; ready</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/7263048039414501385/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/7263048039414501385' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7263048039414501385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7263048039414501385'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2010/03/derived-vtable-ready.html' title='Constructor'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8bFafEjlUOlCmzg6ErgLjOrYB9WGAYH8zpVVs-28VojGAd5p1vYkUY1f-55zWH2PJ0ySHfo6zuHLU_uSOlEmz-8zNXTmQPlQf0uTck_PEQQC2-fvFtQvw0ORN0CmxXKT_j2dNUVFLiyU/s72-c/constructor_g++.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-3855604757211858664</id><published>2009-08-25T00:31:00.006+08:00</published><updated>2010-10-25T14:15:45.916+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>另一個 call stack 還原法</title><content type='html'>http://fruitfoxlu.blogspot.com/2009/03/nt-insider-windbg3.html&lt;br /&gt;&lt;br /&gt;Royce 大師教的 call stack 還原法</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/3855604757211858664/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/3855604757211858664' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3855604757211858664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3855604757211858664'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2009/08/httpfruitfoxlu.html' title='另一個 call stack 還原法'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-3771020687940962347</id><published>2009-08-03T00:58:00.003+08:00</published><updated>2010-10-25T14:14:57.841+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>Rvalue References</title><content type='html'>http://fsfoundry.org/codefreak/2009/05/19/i-like-to-move-it/</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/3771020687940962347/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/3771020687940962347' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3771020687940962347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3771020687940962347'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2009/08/rvalue-references.html' title='Rvalue References'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-6469787711903175961</id><published>2008-07-21T00:58:00.003+08:00</published><updated>2010-10-25T14:16:38.964+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>Dependency does matter</title><content type='html'>&lt;span xmlns=&quot;&quot;&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;話說每一版的Milestone build前夕總免不了要爆個大問題.這次比較有趣的大概就是XXListen突然倒地不起.但時間緊迫,當時只能緊急撤掉可疑的修改讓它撐下去.但是欠債總是要還的,這版第一個build一出來,魔王又重生了&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;程式一執行就掛了,連first chance的call stack都讓人一頭霧水&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;CommandLine: C:\Builds\XXA_15.1.1007_PrivateBuild \XXListen.exe&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;Symbol search path is: SRV*C:\Symbols*http://myfault.kicks-ass.net;C:\PrivateBuilds\Symbols&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;Executable search path is: C:\Builds\XXA_15.1.1007_PrivateBuild \&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;ModLoad: 00400000 004f5000   XXListen.exe&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;…&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;(c9c.24c): &lt;span style=&quot;color:red;&quot;&gt;Break instruction exception - code 80000003 (first chance)&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eax=00351eb4 ebx=7ffda000 ecx=00000004 edx=00000010 esi=00351f48 edi=00351eb4&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eip=7c92120e esp=0022fb20 ebp=0022fc94 iopl=0         nv up ei pl nz na po nc&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;ntdll!DbgBreakPoint:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;7c92120e cc              int     3&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; kv&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;ChildEBP RetAddr  Args to Child            &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022fb1c 7c95e612 7ffdf000 7ffda000 00000000 &lt;span style=&quot;color: rgb(0, 112, 192);&quot;&gt;ntdll!DbgBreakPoint (FPO: [0,0,0])&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022fc94 7c94108f 0022fd30 7c920000 0022fce0 &lt;span style=&quot;color: rgb(0, 112, 192);&quot;&gt;ntdll!LdrpInitializeProcess+0xffa (FPO: [Non-Fpo])&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022fd1c 7c92e437 0022fd30 7c920000 00000000 &lt;span style=&quot;color: rgb(0, 112, 192);&quot;&gt;ntdll!_LdrpInitialize+0x183 (FPO: [Non-Fpo])&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00000000 00000000 00000000 00000000 00000000&lt;span style=&quot;color: rgb(0, 112, 192);&quot;&gt; ntdll!KiUserApcDispatcher+0x7&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; .ecxr&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;Unable to get exception context, HRESULT 0x8000FFFF&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;原來是因為連crt的exception handler都還沒種進去就掛了,只有ntdll!_except_handler3&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022fd0c: ntdll!_except_handler3+0 (7c92e900)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;  CRT scope  1, filter: ntdll!_LdrpInitialize+1d5 (7c95f0f6)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                func:   ntdll!_LdrpInitialize+1e6 (7c95f10c)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;  CRT scope  0, func:   ntdll!_LdrpInitialize+249 (7c95f158)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;因為最外層的exception handler把現場破壞得太嚴重了,所以一定得攔在exception發生前…費盡千辛萬苦終於發現掛在這行&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; p&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eax=0ce590be ebx=0022f78c ecx=00000000 edx=000ce590 esi=656806d0 edi=00000000&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eip=65634f25 esp=0022f774 ebp=0022f9a8 iopl=0         nv up ei pl zr na pe nc&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;XXSOCK!XXSsockApp::InitInstance+0x155:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;65634f25 68a0066865      &lt;span style=&quot;color:red;&quot;&gt;push    offset XXSOCK!g_ppszIPList (656806a0)&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; p&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;(6a0.5f4): &lt;span style=&quot;color:red;&quot;&gt;Stack overflow - code c00000fd (first chance)&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;First chance exceptions are reported before any exception handling.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;This exception may be expected and handled.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eax=00033018 ebx=00230000 ecx=00000002 edx=00000001 esi=002300d4 edi=00000004&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eip=7c935401 esp=00033000 ebp=00033030 iopl=0         nv up ei pl zr na pe nc&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;ntdll!RtlpLocateActivationContextSection+0x150:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 22pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;7c935401 56              push    esi&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;push也會出事??!! Stack明明就可讀可寫啊&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;    00030000 : &lt;span style=&quot;color:red;&quot;&gt;00031000 - 001ff000&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                    Type     00020000 MEM_PRIVATE&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                    Protect  00000004 &lt;span style=&quot;color:red;&quot;&gt;PAGE_READWRITE&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                    State    00001000 MEM_COMMIT&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                    Usage    RegionUsageStack&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 11pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;                    Pid.Tid  6a0.5f4&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;等到冷靜下來仔細一看…不對啊…明明是單步執行怎麼一次跳好幾步? 這顯示問題不一定是那行push造成,也可能是後續被跳過無法下斷點的那幾行之一造成的.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;65634eeb&lt;/span&gt; 8b0da0066865    mov     ecx,dword ptr [XXSOCK!g_ppszIPList (656806a0)]&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;65634ef1&lt;/span&gt; 83c428          add     esp,28h&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; p&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eax=0ce590be ebx=0022f78c ecx=37fdeebe edx=000ce590 esi=656806d0 edi=00000000&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eip=65634eeb esp=0022f74c ebp=0022f9a8 iopl=0         nv up ei pl nz na pe nc&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;TMSOCK!CTmsockApp::InitInstance+0x11b:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;65634eeb &lt;/span&gt;8b0da0066865    mov     ecx,dword ptr [XXSOCK!g_ppszIPList (656806a0)] ds:0023:656806a0=00000000&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; p&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eax=0ce590be ebx=0022f78c ecx=00000000 edx=000ce590 esi=656806d0 edi=00000000&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;eip=65634f25 esp=0022f774 ebp=0022f9a8 iopl=0         nv up ei pl zr na pe nc&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;TMSOCK!CTmsockApp::InitInstance+0x155:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;65634f25&lt;/span&gt; 68a0066865      push    offset TMSOCK!g_ppszIPList (656806a0)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;連Windbg都不可信,正打算用OllyICE試試的時候…老天還是待我不薄,因為這時候的call stack像樣多了&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033030 7c93532a ntdll!RtlpLocateActivationContextSection+0x150&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033060 7c93528d ntdll!RtlpFindNextActivationContextSection+0x61&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033078 7c935571 ntdll!RtlpFindFirstActivationContextSection+0x41&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000330c4 7c935cc9 ntdll!RtlFindActivationContextSectionString+0x8e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033188 7c935b8a ntdll!RtlDecodeSystemPointer+0x9e7&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000332f0 7c936748 ntdll!RtlDosApplyFileIsolationRedirection_Ustr+0x267&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003337c 7c936698 ntdll!LdrGetDllHandleEx+0xc9&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033398 7c80e524 ntdll!LdrGetDllHandle+0x18&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000333e8 7c80e63b kernel32!GetModuleHandleForUnicodeString+0x1d&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003386c 7c80e4ec kernel32!BasepGetModuleHandleExW+0x18e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033884 7c80b750 kernel32!GetModuleHandleW+0x29&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033890 0060c192 kernel32!GetModuleHandleA+0x2d&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003389c 0060c1e8 libNetCtrl!_decode_pointer+0x3f&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338a8 0060c30d libNetCtrl!__set_flsgetvalue+0x1e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338b8 0060a6c8 libNetCtrl!_getptd_noexit+0x15&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338bc 0060e786 libNetCtrl!_errno+0x5&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338c4 0060c08b libNetCtrl!_get_winmajor+0x10&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338e0 0060c19d libNetCtrl!_use_encode_pointer+0x1b&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338e8 0060c1e8 libNetCtrl!_decode_pointer+0x4a&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338f4 0060c30d libNetCtrl!__set_flsgetvalue+0x1e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;等等…這不太像是個call stack的起點呀… 完整的call stack呢?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033030 7c93532a ntdll!RtlpLocateActivationContextSection+0x150&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033060 7c93528d ntdll!RtlpFindNextActivationContextSection+0x61&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033078 7c935571 ntdll!RtlpFindFirstActivationContextSection+0x41&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000330c4 7c935cc9 ntdll!RtlFindActivationContextSectionString+0x8e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033188 7c935b8a ntdll!RtlDecodeSystemPointer+0x9e7&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000332f0 7c936748 ntdll!RtlDosApplyFileIsolationRedirection_Ustr+0x267&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003337c 7c936698 ntdll!LdrGetDllHandleEx+0xc9&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033398 7c80e524 ntdll!LdrGetDllHandle+0x18&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000333e8 7c80e63b kernel32!GetModuleHandleForUnicodeString+0x1d&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003386c 7c80e4ec kernel32!BasepGetModuleHandleExW+0x18e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033884 7c80b750 kernel32!GetModuleHandleW+0x29&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00033890 0060c192 kernel32!GetModuleHandleA+0x2d&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0003389c 0060c1e8 libNetCtrl!_decode_pointer+0x3f&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;000338a8 0060c30d libNetCtrl!__set_flsgetvalue+0x1e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338b8 0060a6c8 libNetCtrl!_getptd_noexit+0x15&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338bc 0060e786 libNetCtrl!_errno+0x5&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338c4 0060c08b libNetCtrl!_get_winmajor+0x10&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338e0 0060c19d libNetCtrl!_use_encode_pointer+0x1b&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338e8 0060c1e8 libNetCtrl!_decode_pointer+0x4a&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000338f4 0060c30d libNetCtrl!__set_flsgetvalue+0x1e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;…&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe250 0060e786 libNetCtrl!_errno+0x5&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe258 0060c08b libNetCtrl!_get_winmajor+0x10&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe274 0060c19d libNetCtrl!_use_encode_pointer+0x1b&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe27c 0060c1e8 libNetCtrl!_decode_pointer+0x4a&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe288 0060c30d libNetCtrl!__set_flsgetvalue+0x1e&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;;font-size:10pt;color:red;&quot;  &gt;000fe298 0060a6c8 libNetCtrl!_getptd_noexit+0x15&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;上面兩塊簡直像鬼打牆一樣出現了幾萬次,原來stack overflow是它造成的.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;裡面出現了libNetCtrl!_errno,看來像是個error handler…好樣的,error handler寫出error…&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;讓我想到Dr.Watson crash之後又生出一個Dr.Watson前仆後繼的情景&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;(其作者Don Corbitt很久前就於空難中過世了,基於尊敬在下得說實話:Dr.Watson雖有小瑕疵但還是很好用)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;接下來就直接攔在這個error handler的進入點,來看到底是誰造成第一個error啟動了這場災難&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4b4 0060a6c8 libNetCtrl!_getptd_noexit&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4b8 0060e786 libNetCtrl!_errno+0x5&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4c0 0060c08b libNetCtrl!_get_winmajor+0x10&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4dc 0060c126 libNetCtrl!_use_encode_pointer+0x1b&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4e4 0060c151 libNetCtrl!_encode_pointer+0x4a&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f4ec 00616393 libNetCtrl!_encoded_null+0x7&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f520 0060eaf4 libNetCtrl!__crtMessageBoxA+0xe&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f544 00607c19 libNetCtrl!_NMSG_WRITE+0x162&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f55c 006040e9 &lt;span style=&quot;color:red;&quot;&gt;libNetCtrl!malloc&lt;/span&gt;+0x2f&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0022f574 0060298b libNetCtrl!NetLocalMachine::LoadAdapters+0x19&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;終於找到了,不過怎麼是malloc?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c01 33f6            &lt;span style=&quot;color:red;&quot;&gt;xor     esi,esi&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c03 393598fa6100    &lt;span style=&quot;color:red;&quot;&gt;cmp     dword ptr [libNetCtrl!_crtheap (0061fa98)],esi&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c09 8bfd            mov     edi,ebp&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c0b 7518            jne     libNetCtrl!malloc+0x3b (00607c25)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c0d e8206f0000      call    libNetCtrl!_FF_MSGBANNER (0060eb32)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c12 6a1e            push    1Eh&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c14 e8796d0000      &lt;span style=&quot;color:red;&quot;&gt;call    libNetCtrl!_NMSG_WRITE (0060e992)&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;00607c19 68ff000000      push    0FFh&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;原來是因為&quot;libnetctrl!_crtheap&quot;等於0,跑進了malloc裡一開頭的error handling block&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0:000&amp;gt; dd &lt;span style=&quot;color:red;&quot;&gt;libNetCtrl!_crtheap&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;0061fa98  &lt;span style=&quot;color:red;&quot;&gt;00000000&lt;/span&gt; 00000000 00000000 00000000&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;為啥是0咧? 從VC裡附的crt source可以知道,只要_DllMainCRTStartup有被呼叫,此DLL對應的crt heap就應該被建立好了.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;這麼說…_DllMainCRTStartup沒有被呼叫?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;// 為說明而做了簡化,雙底線和單底線版本的差異與本主題無關,可以把它們看成一樣&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;#define _DllMainCRTStartup __DllMainCRTStartup&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;__declspec(noinline)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;BOOL __cdecl&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;__DllMainCRTStartup&lt;/span&gt;(&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;HANDLE  hDllHandle,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;DWORD   dwReason,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;LPVOID  lpreserved&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;if ( dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH ) {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;…&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;if ( retcode )&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 99pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;retcode =&lt;span style=&quot;color:red;&quot;&gt; _CRT_INIT(hDllHandle, dwReason, lpreserved)&lt;/span&gt;;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;呼叫DllMainCRTStartup是Executable loader的責任耶…還好,之前曾經在路上撿到一份pseudo code,裡面說Loader大致是這樣運作的:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;NTLoadDLL(DLL)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;if (!AlreadyLoad(DLL) {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;MapDLL(DLL);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;if (IsDLL()){&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 99pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;RecirsivelyLoadDependencyDLL();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;InsertDLLInitRoutineToList();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;If (&lt;span style=&quot;color:red;&quot;&gt;All_Implicitly_Linked_DLL_Loaded&lt;/span&gt;()) {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 99pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;&lt;span style=&quot;color:red;&quot;&gt;RunTheInitRoutineList&lt;/span&gt;();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 77pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;也就是說,只有當所有隱式連結的DLL都已載入完畢時,各DLL的_DllMainCRTStartup(精確來說,是該DLL的PE header內標記的Entry point)才會被整批逐一執行.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;而libNetCtrl.dll是XXListen.exe隱式連接的DLL之一,當它被XXSock.dll載入時,Loader認為XXListen.exe尚有未完全載入的DLL(libNetCtrl.dll就是其中之一囉),&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;所以並沒有執行libNetCtrl.dll的_ DllMainCRTStartup. 沒有Main就沒有_CRT_INIT,沒有_CRT_INIT就沒有_crtheap可以用.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;這三個project之間的關係可以用下面的pseudo code來理解:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;XXListen.cpp:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;void main()&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 66pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;fun_in_DLL1();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 66pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;fun_in_DLL2();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;DLL1.cpp (就是XXSOck.dll):&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;typedef void (*_fun_in_DLL2)(void);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;class _obj_in_DLL1 {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;_obj_in_DLL1() {&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;fun_in_DLL2 = GetProcAddress(LoadLibraryA(&quot;DLL2.dll&quot;), &quot;fun_in_DLL2&quot;));&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;fun_in_DLL2();&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;} obj_in_DLL1;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;extern &quot;C&quot; void fun_in_DLL1(void)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 55pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;printf(&quot;fun_in_DLL1\n&quot;);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;與DLL2.cpp(也就是libNetCtrl.dll):&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;extern &quot;C&quot; void fun_in_DLL2(void)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 66pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;printf(&quot;fun_in_DLL2\n&quot;);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 66pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;malloc(65536);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 33pt;&quot;&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;然後令XXListen依賴DLL1與DLL2,但不對DLL1標記其依賴DLL2的事實&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;這樣等於向Loader宣稱DLL1和DLL2沒有互相依賴關係,所以該先執行誰的DllMain都可以.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;若是Loader先執行DLL2的DllMain就天下太平,但若哪天它決定先執行DLL1的DllMain,問題就爆發了.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;附帶一提,目前以路上撿來的那份pseudo code內容來看,&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;Loader將會把眾DllMain們按照他們的&lt;span style=&quot;color:red;&quot;&gt;所屬DLL出現在Import Table內的順序,以先出現先執行的原則&lt;/span&gt;執行之.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;倘若這行為永遠不變,還是存在一個變數,就是連結器又該如何決定兩個不互相依賴的DLL,誰該在前而誰又該在後?&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size:10pt;&quot;&gt;總之這兩個變數就是讓這問題時而出現時而消失的元凶.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/6469787711903175961/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/6469787711903175961' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/6469787711903175961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/6469787711903175961'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2008/07/dependency-does-matter_848.html' title='Dependency does matter'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-4876354547102677614</id><published>2007-12-02T01:04:00.005+08:00</published><updated>2010-10-25T14:15:46.914+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>Stack, a locker without lock</title><content type='html'>&lt;div&gt;A function 呼叫 B function, 並傳遞了兩個 4-byte 參數. 但當 B function 要取用的時候, 參數在 stack 裡被歸零了!&lt;/div&gt;&lt;br /&gt;&lt;div&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBowMMsXgc6H8Ne5BivktewwkiMo48bvpl61wVkNZYq8qQifwp3RllnZO8ptYQwrYAt8Lw4sYY9lhDBCEpDB4wxfVt_lf0MjhTi5iT2bG6k5_9aasrP4SNBCZO99rNfTkfsdnt8mGkavc/s1600-r/1.jpg&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5139053162049279474&quot; style=&quot;margin: 0px auto 10px; display: block; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV9Zwx8TXO4xPmqkNrI2uBA49TH6n4oYQZpyppN4KPOMTY-sfoL8Nvtf_rHAeAivH6peXsovn7k0y2i7fNDkxIc4owNUjcR-8xOJuBc8jZ3cvGLHqFEW6WwSenNSqmncolDWbymG876d0/s400/1.jpg&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt; &lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/4876354547102677614/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/4876354547102677614' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4876354547102677614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4876354547102677614'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/12/stack-locker-without-lock.html' title='Stack, a locker without lock'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV9Zwx8TXO4xPmqkNrI2uBA49TH6n4oYQZpyppN4KPOMTY-sfoL8Nvtf_rHAeAivH6peXsovn7k0y2i7fNDkxIc4owNUjcR-8xOJuBc8jZ3cvGLHqFEW6WwSenNSqmncolDWbymG876d0/s72-c/1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-1760153295795344924</id><published>2007-12-01T22:17:00.003+08:00</published><updated>2010-10-25T14:15:47.820+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>goto CLEANUP or TRAP</title><content type='html'>這幾天犯了一個嚴重的錯誤, 害 XXXNT 在 64-bit Vista 上一執行就會 GPF&lt;br /&gt;&lt;br /&gt;void foo()&lt;br /&gt;{&lt;br /&gt;　if (something is wrong)&lt;br /&gt;　goto CLEANUP;&lt;br /&gt;　char *ptr = NULL;&lt;br /&gt;　ptr = new char [100];&lt;br /&gt;CLEANUP:&lt;br /&gt;　if (ptr) delete [] ptr;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;這段 code 會被編譯成:&lt;br /&gt;&lt;br /&gt;　cmp something_is_wrong&lt;br /&gt;　je CLEANUP1&lt;br /&gt;　push 64h&lt;br /&gt;　call operator new&lt;br /&gt;　add esp,4&lt;br /&gt;　jmp CLEANUP2&lt;br /&gt;CLEANUP1:&lt;br /&gt;　mov eax, dword ptr [esp+4]&lt;br /&gt;CLEANUP2:&lt;br /&gt;　test eax,eax&lt;br /&gt;　je END&lt;br /&gt;　push eax&lt;br /&gt;　call operator delete&lt;br /&gt;　add esp,4&lt;br /&gt;END:&lt;br /&gt;　xor eax,eax&lt;br /&gt;　ret&lt;br /&gt;&lt;br /&gt;也就是說, 假如真的執行到了 goto 指令, 則將存取到 esp+4 這塊記憶體, 而其內容並非我們所想像的 NULL, 因此將會引發不可預期的後果.&lt;br /&gt;&lt;br /&gt;幸好, 當 VC8 的 compile warning level 開到 /W4 的時候, 這種 code 將會引發一個 C4701 warning</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/1760153295795344924/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/1760153295795344924' title='1 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/1760153295795344924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/1760153295795344924'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/12/once-upon-goto-cleanup.html' title='goto CLEANUP or TRAP'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-8623894799588374381</id><published>2007-10-14T01:00:00.002+08:00</published><updated>2013-02-17T22:05:03.428+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>Kernel object deadlock hunting</title><content type='html'>&lt;span style=&quot;font-size: 85%;&quot;&gt;這報告的知識都是取之於網路, 所以我打算回饋一下...&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;https://dl.dropbox.com/u/83844437/Windbg%20tricks.pptx&quot;&gt;&lt;span style=&quot;font-size: 85%;&quot;&gt;Kernel object deadlock hunting&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-size: 85%;&quot;&gt;&lt;br /&gt;&lt;br /&gt;當 event 或 semaphore 這種不具 ownership 紀錄的 Windows kernel object 發生 deadlock, 怎麼找出咬住該 object 的執行緒?&lt;br /&gt;只要運氣夠好, 還是有機會把它揪出來!&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/8623894799588374381/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/8623894799588374381' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8623894799588374381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8623894799588374381'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/10/kernel-object-deadlock-hunting.html' title='Kernel object deadlock hunting'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-7253929079760075173</id><published>2007-09-11T01:36:00.002+08:00</published><updated>2010-10-25T14:15:50.625+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>When operator new and delete are overwritten</title><content type='html'>&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;上個禮拜, 本 team 的強者查理大大發現了一個 Vista 上的 Crash... 其 Dump 可謂匪夷所思&lt;br /&gt;&lt;br /&gt;我們首次到手的 Dump, call stack 長這樣:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;# 1 Id: d30.fd4 Suspend: 1 Teb: 7ffde000 Unfrozen&lt;br /&gt;ChildEBP RetAddr Args to Child&lt;br /&gt;029fc564 773a1d37 01390000 006d5748 029fc60c ntdll!RtlpCoalesceFreeBlocks+0x26d&lt;br /&gt;029fc65c 773a1c21 006d5748 006d5750 006d5750 ntdll!RtlpFreeHeap+0x1e2&lt;br /&gt;029fc678 75d97a7e 01390000 00000000 006d5748 ntdll!RtlFreeHeap+0x14e&lt;br /&gt;029fc68c 1000d343 01390000 00000000 006d5750 kernel32!HeapFree+0x14&lt;br /&gt;029fc6cc 1000961b 006d5750 1bdb284a 029fc798 libXXXXXSecure!free+0x6e&lt;br /&gt;029fc73c 10008c5a 46e56fb6 00000d30 00000fd4 libXXXXXSecure!LogWriteW+0xeb&lt;br /&gt;029fe778 10008d7f 00000008 01390c08 00000154 libXXXXXSecure!vdprintfW+0x1da&lt;br /&gt;029fe7a0 10008edf 00000008 01390c08 00000154 libXXXXXSecure!dprintfW+0x2f&lt;br /&gt;029fe7b8 100090a8 1bdb0952 75d97b60 773a2f1d libXXXXXSecure!CDebugLogW::EnterDebugLog+0x1f&lt;br /&gt;029fe7e4 10025a05 1002f274 00000154 1002f398 libXXXXXSecure!CDebugLogW::CDebugLogW+0x158&lt;br /&gt;029fec40 0044bcd6 1bc66186 00000000 006ad738 libXXXXXSecure!TSECURE::clearTGPTempDir+0x45&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;3 Id: d30.51c Suspend: 1 Teb: 7ffdc000 Unfrozen&lt;br /&gt;ChildEBP RetAddr Args to Child&lt;br /&gt;03ebf92c 773a06a0 7737b18c 00000338 00000000 ntdll!KiFastSystemCallRet&lt;br /&gt;03ebf930 7737b18c 00000338 00000000 00000000 ntdll!NtWaitForSingleObject+0xc&lt;br /&gt;03ebf994 7737b071 00000000 00000000 01390000 ntdll!RtlpWaitOnCriticalSection+0x154&lt;br /&gt;03ebf9bc 77368f4a 01390130 03eb9ea4 01390000 ntdll!RtlEnterCriticalSection+0x152&lt;br /&gt;03ebfaa0 773a214c 00000214 00000220 0139039c ntdll!RtlpAllocateHeap+0x15c&lt;br /&gt;03ebfb18 10018acb 01390000 00000008 00000214 ntdll!RtlAllocateHeap+0x1e3&lt;br /&gt;03ebfb58 1001133a 00000214 00000214 00000000 libXXXXXSecure!_calloc_impl+0xc4&lt;br /&gt;03ebfb70 1000daf3 00000001 00000214 00000000 libXXXXXSecure!_calloc_crt+0x13&lt;br /&gt;03ebfb90 1000dbaa 10000000 00000002 00000000 libXXXXXSecure!_CRT_INIT+0x17b&lt;br /&gt;03ebfbd0 1000dc64 10000000 773aa604 10000000 libXXXXXSecure!__DllMainCRTStartup+0x59&lt;br /&gt;03ebfbd8 773aa604 10000000 00000002 00000000 libXXXXXSecure!_DllMainCRTStartup+0x1d&lt;br /&gt;03ebfbf8 7737ab3b 1000dc47 10000000 00000002 ntdll!LdrpCallInitRoutine+0x14&lt;br /&gt;03ebfc98 7737a954 03ebfd24 03eb9904 00000000 ntdll!LdrpInitializeThread+0x149&lt;br /&gt;03ebfd00 7737a980 03ebfd24 77340000 00000000 ntdll!_LdrpInitialize+0x21d&lt;br /&gt;03ebfd10 00000000 03ebfd24 77340000 00000000 ntdll!LdrInitializeThunk+0x10&lt;br /&gt;&lt;br /&gt;列出這兩個 Thread 主要是因為, 我們一度以為 Vista 環境中竟然平行執行 DllMainCRTStartup 及 mainCRTStartup...&lt;br /&gt;&lt;br /&gt;但後來發現_CRT_INIT 的 dwReason 參數, 它並非我們所想像的 DLL_PROCESS_ATTACH(1) 而是 DLL_THREAD_ATTACH(2).&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;03ebfb90 1000dbaa 10000000 &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;00000002&lt;/span&gt; 00000000 libXXXXXSecure!_CRT_INIT+0x17b&lt;br /&gt;&lt;br /&gt;也就是說, 這根 Thread 根本是來擾亂視聽的, 它其實正常運作中, 只不過被 crashed thread 所 own 住的 Heap lock 給卡住了而已.&lt;br /&gt;&lt;br /&gt;所以我們似乎可以把重心全部放在 fd4 這根 thread 上.&lt;br /&gt;&lt;br /&gt;此外, 感謝查理大的指示, 我們還擁有一個很重要的線索, 就是該 crash 的 process 會間接 include 到一個&lt;br /&gt;&lt;br /&gt;overwrite 掉 operator new 及 delete 的 header file:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;static inline void* operator new(size_t size)&lt;br /&gt;{&lt;br /&gt;void* ptr = ::HeapAlloc(::GetProcessHeap(), 0, size);&lt;br /&gt;if (!ptr)&lt;br /&gt;{&lt;br /&gt;_THROW_NCEE(std::bad_alloc, &quot;Insufficient memory&quot;);&lt;br /&gt;}&lt;br /&gt;return ptr;&lt;br /&gt;}&lt;br /&gt;static inline void operator delete(void* ptr) { ::HeapFree(::GetProcessHeap(), 0, ptr); }&lt;br /&gt;&lt;br /&gt;我們幾乎可以確定問題一定是由它造成的, 但接下來我們想知道的是:&lt;br /&gt;&lt;br /&gt;問題到底是怎麼造成的呢? 它真的會 overwrite 掉 CRT 當中對 operator new 及 delete 的實作嗎?&lt;br /&gt;&lt;br /&gt;於是我們追進 crashed thread 所呼叫的 free() 當中, 可以看到它操作的是 _crtheap (由 _head_init@CRT 所建立)&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;libXXXXXSecure!free:&lt;br /&gt;1000d2d5 6a0c push 0Ch&lt;br /&gt;1000d2d7 68f8220310 push offset libXXXXXSecure!_CT??_R0?AVout_of_rangestd+0x2b8 (100322f8)&lt;br /&gt;1000d2dc e837910000 call libXXXXXSecure!__SEH_prolog4 (10016418)&lt;br /&gt;1000d2e1 8b7508 mov esi,dword ptr [ebp+8]&lt;br /&gt;1000d2e4 85f6 test esi,esi&lt;br /&gt;1000d2e6 7475 je libXXXXXSecure!free+0x88 (1000d35d)&lt;br /&gt;1000d2e8 833da08d031003 cmp dword ptr [libXXXXXSecure!__active_heap (10038da0)],3&lt;br /&gt;1000d2ef 7543 jne libXXXXXSecure!free+0x5f (1000d334)&lt;br /&gt;1000d2f1 6a04 push 4&lt;br /&gt;1000d2f3 e8ed850000 call libXXXXXSecure!_lock (100158e5)&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;1000d337 ff35f4880310 push dword ptr [libXXXXXSecure!&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;_crtheap&lt;/span&gt; (100388f4)]&lt;br /&gt;1000d33d ff1514b00210 call dword ptr [libXXXXXSecure!_imp__HeapFree (1002b014)]&lt;br /&gt;&lt;br /&gt;由此可見, 該 header file 並沒有 overwrite 掉 CRT 當中的 operator delete 實作.&lt;br /&gt;&lt;br /&gt;那 operator new 呢? 我們追進 basic_string::_Copy &gt; basic_string::allocate &gt; std::_Allocate &gt; operator new,&lt;br /&gt;&lt;br /&gt;可以看到其實作如下:&lt;br /&gt;&lt;br /&gt;libXXXXXSecure!operator new:&lt;br /&gt;10025d10 55 push ebp&lt;br /&gt;10025d11 8bec mov ebp,esp&lt;br /&gt;10025d13 83ec10 sub esp,10h&lt;br /&gt;10025d16 8b4508 mov eax,dword ptr [ebp+8]&lt;br /&gt;10025d19 50 push eax&lt;br /&gt;10025d1a 6a00 push 0&lt;br /&gt;10025d1c ff1518b00210 call dword ptr [libXXXXXSecure!_imp__GetProcessHeap (1002b018)]&lt;br /&gt;10025d22 50 push eax&lt;br /&gt;10025d23 ff1544b00210 call dword ptr [libXXXXXSecure!_imp__HeapAlloc (1002b044)]&lt;br /&gt;...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;很明顯地, 它是被 overwrite 掉之後的結果.&lt;br /&gt;&lt;br /&gt;平平都是 include 那個 overwrite header file, 為啥 operator new 被蓋掉了, 但 operator delete 卻沒有?&lt;br /&gt;&lt;br /&gt;我們展開呼叫了 operator delete 的 LogWriteW:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:courier new;font-size:85%;&quot;  &gt;100095fc e8fffaffff call libXXXXXSecure!Send (10009100)&lt;br /&gt;10009601 397c2448 cmp dword ptr [esp+48h],edi&lt;br /&gt;10009605 8ad8 mov bl,al&lt;br /&gt;10009607 c744241044bc0210 mov dword ptr [esp+10h],offset libXXXXXSecure!CCmdProtocol::`vftable&#39; (1002bc44)&lt;br /&gt;1000960f 720d jb libXXXXXSecure!LogWriteW+0xee (1000961e)&lt;br /&gt;10009611 8b442434 mov eax,dword ptr [esp+34h]&lt;br /&gt;10009615 50 push eax&lt;br /&gt;10009616 e864350000 call libXXXXXSecure!operator delete (1000cb7f)&lt;br /&gt;&lt;br /&gt;它理應要呼叫 CCmdProtocol::~CCmdProtocol() 來做 cleanup 動作, 但因為被 optimize 的緣故, 此處只出現了一個 delete,&lt;br /&gt;&lt;br /&gt;而且這個 delete 忽略掉 overwrite function, 仍舊與 CRT 的實作相連結, 這應該算是個 optimization error 吧...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;所謂禍不單行, 取消掉 libLogClient 的 optimization 之後, 程式仍然會 crash...&lt;br /&gt;&lt;br /&gt;這次的 Dump, crashed thread 的 call stack 如下:&lt;br /&gt;&lt;br /&gt;# 1 Id: 820.f94 Suspend: 1 Teb: 7ffdd000 Unfrozen&lt;br /&gt;ChildEBP RetAddr Args to Child&lt;br /&gt;02bfe684 773a1d37 002f0000 01670c38 02bfe72c ntdll!RtlpCoalesceFreeBlocks+0x35&lt;br /&gt;02bfe77c 773a1c21 01670c38 01670c40 773a2f1d ntdll!RtlpFreeHeap+0x1e2&lt;br /&gt;02bfe798 75d97a7e 002f0000 00000000 01670c38 ntdll!RtlFreeHeap+0x14e&lt;br /&gt;02bfe7ac 10027f56 002f0000 00000000 01670c40 kernel32!HeapFree+0x14&lt;br /&gt;02bfe7c0 10002ffa 01670c40 02bfea20 01670c40 libXXXXXSecure!operator delete+0x16&lt;br /&gt;02bfe7d4 10002f7d 67c8f9a4 02bfea0c 02bfec34 libXXXXXSecure!std::auto_ptr&lt;wchar_t&gt;::~auto_ptr&lt;wchar_t&gt;+0x1a&lt;br /&gt;02bfe7f0 10025d18 67c8f214 003a0043 0050005c libXXXXXSecure!CDebugLogW::~CDebugLogW+0x4d&lt;br /&gt;02bfec40 0044bcd6 67dbc520 00000000 0031d738 libXXXXXSecure!TSECURE::clearTGPTempDir+0x1a8&lt;br /&gt;&lt;br /&gt;出現了 auto_ptr object... 顯然又是個 new/delete 不相符造成的 crash&lt;br /&gt;&lt;br /&gt;以同樣的方法追進去, 可以看到這次 operator delete 被 overwrite 掉了, 但 operator new 並沒有&lt;br /&gt;&lt;br /&gt;原來是因為 CDebugLogW::~CDebugLogW 的實作放在 header file 裡, 而 CDebugLogW::CDebugLogW 的實作放在另一個 library 內.&lt;br /&gt;&lt;br /&gt;從這個例子我們可以看到, 這種寫法會造成建解構函式分別採用到不同的 CRT function 實作.&lt;/wchar_t&gt;&lt;/wchar_t&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/7253929079760075173/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/7253929079760075173' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7253929079760075173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7253929079760075173'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/09/when-operator-new-and-delete-are.html' title='When operator new and delete are overwritten'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-949431692610170457</id><published>2007-04-08T15:59:00.002+08:00</published><updated>2010-10-25T14:15:44.125+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reversing and Analyzing"/><title type='text'>crackme2.exe in Makkakko tutorial</title><content type='html'>&lt;a href=&quot;http://algo.csie.nctu.edu.tw/%7Ehcliang/crackme/1.exe&quot;&gt;下載&lt;/a&gt;&lt;br /&gt;1. 攔 USER32!GetDlgItemTextA, 可知序號將被存入 0x0040217E.&lt;br /&gt;&lt;br /&gt;2. 在 0x0040217E 處設存取中斷點, 可知序號將經過下列加工:&lt;br /&gt;a. 所有英文小寫字母轉大寫&lt;br /&gt;b. 跟 &quot;Messing_in_bytes&quot; 這 16 bytes 做 XOR.&lt;br /&gt;&lt;br /&gt;3. 把 XOR 完之後的 16 bytes 跟下面 byte sequence 比對:&lt;br /&gt;1f, 2c, 37, 36, 3b, 3d, 28, 19, 69, 6e, 5f, 62, 79, 74, 65, 73&lt;br /&gt;若超過兩個 byte 以上相異, 則序號不合法.</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/949431692610170457/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/949431692610170457' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/949431692610170457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/949431692610170457'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/04/crackme2exe-in-makkakko-tutorial.html' title='crackme2.exe in Makkakko tutorial'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-3114137302048978612</id><published>2007-03-27T01:56:00.003+08:00</published><updated>2010-10-25T14:14:58.527+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>攻擊 Tor 的匿名性</title><content type='html'>Tor 的匿名性再度被攻擊 (&lt;a href=&quot;http://www.cs.colorado.edu/department/publications/reports/docs/CU-CS-1025-07.pdf&quot;&gt;原文&lt;/a&gt;)&lt;br /&gt;攻擊的技巧在於利用了 Tor entrance/non-entrance algorithm 均傾向選擇 uptime 高且頻寬大的 onion router 作為下一站.&lt;br /&gt;而上述資訊是由各 onion router 自行評估公告, 攻擊者可謊報以爭取同時成為 Entrance 及 Exit node, 並可由收到 request 的時間據以判斷自己是否如願.</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/3114137302048978612/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/3114137302048978612' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3114137302048978612'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3114137302048978612'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/03/tor.html' title='攻擊 Tor 的匿名性'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-5326399210096042450</id><published>2007-03-24T15:25:00.003+08:00</published><updated>2010-10-25T14:15:00.025+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>Google Analytics</title><content type='html'>&lt;p&gt;Google Analytics&lt;/p&gt;&lt;p&gt;分析你的網頁點擊狀況&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.google.com/analytics&quot;&gt;http://www.google.com/analytics&lt;/a&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/5326399210096042450/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/5326399210096042450' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/5326399210096042450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/5326399210096042450'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/03/google-analytics.html' title='Google Analytics'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-4322096169152603195</id><published>2007-02-26T02:47:00.003+08:00</published><updated>2010-10-25T14:15:01.678+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>Firefox 2.0.0.x 及 IE 6,7 共有的 onUnload 漏洞</title><content type='html'>若在 onUnload 事件處理函數當中透過 document.write() 寫入 script, 則 IE 和 Firefox 都會執行之. &lt;div&gt;&lt;br /&gt;&lt;div&gt;由於輸入新 URL 亦將觸發 onUnload 事件, 攻擊者可透過上述 script 構造出 phishing 頁面.&lt;/div&gt;&lt;div&gt;不過攻擊者將不知道 User 究竟想連到哪裡, 所以他只能瞎猜或總是構造出某個特定頁面, 希望可以矇對.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;但 Firefox 的漏洞更糟糕, 它使得攻擊者得以取得 User 欲前往的 URL.&lt;/div&gt;&lt;div&gt;原因是 Firefox 不但執行了該 script, 還以新的 context 執行之, 也就是說, 倘若我們在該 script 當中修改了 location 屬性, 則 Firefox 不但將導向至新 location, 還會夾帶 Referer tag, 當中正是 User 欲前往的 URL.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;Proof of concept: &lt;a href=&quot;http://lcamtuf.coredump.cx/ietrap/&quot;&gt;IE&lt;/a&gt;, &lt;a href=&quot;http://lcamtuf.coredump.cx/ietrap/ff/&quot;&gt;Firefox&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/4322096169152603195/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/4322096169152603195' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4322096169152603195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4322096169152603195'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/firefox-200x-ie-67-onunload.html' title='Firefox 2.0.0.x 及 IE 6,7 共有的 onUnload 漏洞'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-8623334915580002087</id><published>2007-02-26T02:00:00.003+08:00</published><updated>2010-10-25T14:15:02.591+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>UPX file parser vulnerable</title><content type='html'>&lt;a href=&quot;http://esupport.trendmicro.com/support/viewxml.do?ContentID=EN-1034289&quot;&gt;http://esupport.trendmicro.com/support/viewxml.do?ContentID=EN-1034289&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;需要換 pattern</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/8623334915580002087/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/8623334915580002087' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8623334915580002087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8623334915580002087'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/upx-file-parser-vulnerable.html' title='UPX file parser vulnerable'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-824582686099505749</id><published>2007-02-26T00:30:00.003+08:00</published><updated>2010-10-25T14:15:03.194+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>如何不區分實虛部地表示一個複數</title><content type='html'>1965 年 Walter Penney 提出以 (i-1) 為 base 的複數表示法. &lt;a href=&quot;http://portal.acm.org/citation.cfm?id=321264.321274&quot;&gt;[1]&lt;/a&gt;&lt;br /&gt;以該 base 表示一個複數的時候, 各 digit 數值非 0 即 1, 他同時証明了任一複數基於該 base 的表示法唯一.&lt;br /&gt;2000 年被再度發現以 (-i-1) 亦可造出另一套表示法 &lt;a href=&quot;http://ieeexplore.ieee.org/search/searchresult.jsp?SortField=Score&amp;amp;SortOrder=desc&amp;amp;ResultCount=25&amp;amp;maxdoc=100&amp;amp;coll1=ieeejrns&amp;amp;coll2=ieejrns&amp;amp;coll3=ieeecnfs&amp;amp;coll4=ieecnfs&amp;amp;coll5=ieeestds&amp;amp;coll6=preprint&amp;amp;coll7=books&amp;amp;srchres=1&amp;amp;isonlybook=yes&amp;amp;history=yes&amp;amp;queryText=%28Towards+implementation+of+a+binary+number+system+for+complex+numbers%3CIN%3Emetadata%29&amp;amp;oldqrytext=%28%28towards+implementation+of+a+binary+number+system+for+complex%29%3Cin%3Emetadata%29&amp;amp;radiobutton=cit&quot;&gt;[2]&lt;/a&gt; , 而且証明了 (-i+1) 及 (i+1) 不行, 並整理了基於 (i-1) 表示法時, 數字的運算方法.&lt;br /&gt;&lt;br /&gt;使用這表示法所表示的數字到底長怎樣呢? 以 (i-1)-base 為例:&lt;br /&gt;&lt;br /&gt;1: 1&lt;br /&gt;2: 1100&lt;br /&gt;3: 1101&lt;br /&gt;4: 111010000&lt;br /&gt;4+i: 111010011</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/824582686099505749/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/824582686099505749' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/824582686099505749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/824582686099505749'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/blog-post_26.html' title='如何不區分實虛部地表示一個複數'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-9167129772125743155</id><published>2007-02-22T19:00:00.003+08:00</published><updated>2010-10-25T14:15:04.097+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>Snort 2.6.1 存在緩衝區溢出漏洞</title><content type='html'>以下這些版本存在緩衝區溢出漏洞&lt;br /&gt;&lt;br /&gt;Snort 2.6.1, 2.6.1.1, and 2.6.1.2&lt;br /&gt;Snort 2.7.0 beta 1&lt;br /&gt;&lt;br /&gt;緩衝區溢出問題被發現於 ReassembleSMBWriteX() (smb_andx_decode.c) 和 ReassenbleDCERPCRequest() (dcerpc.c) 當中.&lt;br /&gt;&lt;br /&gt;其中 ReassenbleDCERPCRequest() 溢寫的緩衝區位於 data segment 內 (global variable - u_int8_t DecodeBuffer[65535] in decode.c).&lt;br /&gt;&lt;br /&gt;ReassembleSMBWriteX() 溢寫的緩衝區位於 stack 內 (local variable - SMB_WRITEX_REQ temp_writeX in ReassembleSMBWriteX()).</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/9167129772125743155/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/9167129772125743155' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/9167129772125743155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/9167129772125743155'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/snort-261.html' title='Snort 2.6.1 存在緩衝區溢出漏洞'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-8403650788019456438</id><published>2007-02-13T00:59:00.004+08:00</published><updated>2010-10-25T14:15:14.458+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>ICMP flood 判例</title><content type='html'>&lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;本文轉載自司法院判決書資料庫, 此處僅節錄判決結果及主要原因並隱去所有姓名, 如有不妥請來信告知刪除&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;【裁判字號】 93,易,1310&lt;br /&gt;【裁判日期】 931215&lt;br /&gt;【裁判案由】 妨害電腦使用罪&lt;br /&gt;【裁判全文】&lt;br /&gt;臺灣高雄地方法院刑事判決 九十三年度易字第一三一０號&lt;br /&gt;　　 公　訴　人　臺灣高雄地方法院檢察署檢察官&lt;br /&gt;　　 被　　　告　○○○　男　.&lt;br /&gt;右列被告因妨害電腦使用罪案件，經檢察官提起公訴（九十三年度偵字第一四二五九號），本院判決如左：&lt;br /&gt;主 文&lt;br /&gt;○○○無罪。&lt;br /&gt;理 由&lt;br /&gt;&lt;br /&gt;一、(略)&lt;br /&gt;二、(略)&lt;br /&gt;三、(略)&lt;br /&gt;四、(略)&lt;br /&gt;五、經查：本件系爭二點ＩＰ位址間封包有互相傳送之現象，並非僅由被告網咖店之ＩＰ址二一一‧七二‧二三‧一二四往告訴人之ＩＰ址為六一‧二二一‧一八一‧一六一傳送；且發生此種現象之原因很多，若有通訊協定之設定也會造成封包 回傳，此外，線上遊戲或聊天室如有執行ＩＣＭＰ程式，亦可能發生此種現象，而本件無法知道哪一方有執行ＩＣＭＰ程式等情，業據證人中華電信網路維運部門系統工程師ＹＹＹ於本院審理時證述明確。另告訴人所經營之「ＸＸＸＸＸ」網咖店之電腦，確實於九十三年三月二十九日下午三時三十分間，因封包互傳而造成網路有阻塞，且被告之二一一．七二．二三．一二四ＩＰ位址有時為封包之來源位址（執行ICMP Echo），有時為封包之目的位址（執行ICMP Reply）等情，亦有中華電信公司之檢測數據資料影本一紙在卷可稽，核與前揭證人之證詞相符，應堪信為真實。而被告與告訴人均為網咖業者亦為被告及告訴人所互相供承在卷。則衡諸前揭說明，ＩＣＭＰ之ＤＯＳ攻擊可由駭客經由正常網路之使用而發動，且被告及告訴人所經營之網咖復為不特定多數人得以使用電腦網路之營業處所，則本件既無法證明是由何人啟動封包互傳之機制，是否該ＩＣＭＰ之ＤＯＳ攻擊係由被告所經營之網咖店之ＩＰ址為二一一．七二．二三．一二四上之電腦所啟動，已有可疑，況且縱令該ＩＣＭＰ之ＤＯＳ攻擊係由被告所經營之網咖店之電腦所發動，但被告所經營者既為網咖店，使用被告電腦者乃不特定之多數人，如無實據，亦難僅以ＩＰ址為六一．二二一．一八一．一六一、ＩＰ址為二一一．七二．二三．一二四二點之間有封包互傳之情形，即排除駭客利用被告或告訴人所經營網咖店之電腦進行ＩＣＭＰ之ＤＯＳ攻擊之可能，而遽認係被告利用曾為告訴人處理網際網路之設置，而設定封包互傳之通訊協定以電腦程式干擾告訴人之電腦或相關設備之犯行係被告所為。況告訴人亦自承被告係於四年前為告訴人處理網際網路之問題，此亦為被告所不爭，則事隔四年之久，被告如何記得四年前所為網際網路設定，實有可疑，此外復查無其他積極證據足資證明被告有何以電腦程式干擾他人電腦或相關設備之犯行，參酌前揭二之說明，實難對被告率以干擾電腦或相關設備罪相繩。&lt;br /&gt;六、(略)</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/8403650788019456438/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/8403650788019456438' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8403650788019456438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8403650788019456438'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/icmp-flood.html' title='ICMP flood 判例'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-6657525623122965821</id><published>2007-02-11T15:21:00.002+08:00</published><updated>2010-10-25T14:14:08.602+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-2</title><content type='html'>2-2 只用到加(減)法與基本邏輯運算的式子&lt;br /&gt;&lt;br /&gt;本節選錄一系列只用到加(減)法與基本邏輯運算的式子.&lt;br /&gt;&lt;br /&gt;a.&lt;br /&gt;&lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9TX7EBrFPB7jtem4229nvMLW7IoC6bRdz-EtALT7lb49hyphenhyphenV5ATILP4vN5xgaHcAjxvNoEzyG5dRzrGE7B5OCDESj3c2QsiR1gXPdCmigOND3kF7tAi-5H-hQFBcnB-zwRFX_geUQcZko/s1600-h/Eqn1.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176768557586514&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9TX7EBrFPB7jtem4229nvMLW7IoC6bRdz-EtALT7lb49hyphenhyphenV5ATILP4vN5xgaHcAjxvNoEzyG5dRzrGE7B5OCDESj3c2QsiR1gXPdCmigOND3kF7tAi-5H-hQFBcnB-zwRFX_geUQcZko/s320/Eqn1.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(譯註: by definition of 2&#39;s complement) &lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;b.&lt;br /&gt;&lt;/div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXN8NUSJB3yWntXmdlD8vQRsvyXD9WYjebrfaZHizihu1SxfcbunfnRkQEJdh2vCFnRR0wK7iz7xq_-dbAziNIhNzBftTNWm75FcT0qVYGKIgTwFOiFbHBkpxJCdS6lEWEiHqxgcPcm2o/s1600-h/Eqn2.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176772852553826&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXN8NUSJB3yWntXmdlD8vQRsvyXD9WYjebrfaZHizihu1SxfcbunfnRkQEJdh2vCFnRR0wK7iz7xq_-dbAziNIhNzBftTNWm75FcT0qVYGKIgTwFOiFbHBkpxJCdS6lEWEiHqxgcPcm2o/s320/Eqn2.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: -x = -(NOT(NOT(x-1))+1) = -(-NOT(x-1)) = NOT(x-1) )&lt;br /&gt;&lt;br /&gt;c.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMFB9rx3dsMskkKuNjnV9-8kATQ0KCgtZ6e6l8wAc1imuaXeS0JwL0zOba5UJ1NJmfj9iuC6O5dC7Fg__WtDoPE7hgV_cnxsG5jmRkc3Dd2G1jK0su8-GsNg_TsiwegMge0bXtsmE8xX8/s1600-h/Eqn3.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176777147521138&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMFB9rx3dsMskkKuNjnV9-8kATQ0KCgtZ6e6l8wAc1imuaXeS0JwL0zOba5UJ1NJmfj9iuC6O5dC7Fg__WtDoPE7hgV_cnxsG5jmRkc3Dd2G1jK0su8-GsNg_TsiwegMge0bXtsmE8xX8/s320/Eqn3.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by a.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;d.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLkGXD-Z9q0Rh3CIbayTTYmIPCDTvgwVVm0_gYlLyslADl-FUL5VdU2jFOIyxl8-PQHEAJYuphhPlkRKgN5vlvjvY93hyin-sfSv2FkC80S4ucfaLWD4QDgFysCCSHLlO9H7-0DWIhWY0/s1600-h/Eqn4.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176777147521154&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLkGXD-Z9q0Rh3CIbayTTYmIPCDTvgwVVm0_gYlLyslADl-FUL5VdU2jFOIyxl8-PQHEAJYuphhPlkRKgN5vlvjvY93hyin-sfSv2FkC80S4ucfaLWD4QDgFysCCSHLlO9H7-0DWIhWY0/s320/Eqn4.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(譯註: by a.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;e.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZHHmX1AwylsOBa2W89m-lGcVJoxHRFS_z3-iUjWv5RBRTxMN5kICi7NjfgMtgiveDu0F-FvP-zkawB-bz8jdiuOENCXhXDBHtTvPOxJbM6TUEp3mLwT47kqTW-4LSDS8-lT6rkSnPM7s/s1600-h/Eqn5.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176777147521170&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZHHmX1AwylsOBa2W89m-lGcVJoxHRFS_z3-iUjWv5RBRTxMN5kICi7NjfgMtgiveDu0F-FvP-zkawB-bz8jdiuOENCXhXDBHtTvPOxJbM6TUEp3mLwT47kqTW-4LSDS8-lT6rkSnPM7s/s320/Eqn5.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(譯註: by c.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;f.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH7zsrCvZMAU50KY7hdZ7ETKTZykmP_H3k1QsbfFQr180AXkEscPfAfp_HZ_LfR40Un3L01Nr0rQkmgIwRw7Xz2ARsLG8fT1-c3ck_aDt_YVkoQj6FnrZTNsvZgjqv230OUjl8OCvw6Do/s1600-h/Eqn6.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176953241180322&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH7zsrCvZMAU50KY7hdZ7ETKTZykmP_H3k1QsbfFQr180AXkEscPfAfp_HZ_LfR40Un3L01Nr0rQkmgIwRw7Xz2ARsLG8fT1-c3ck_aDt_YVkoQj6FnrZTNsvZgjqv230OUjl8OCvw6Do/s320/Eqn6.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(譯註: x+y = x-(-y) = x-(NOT(y)+1) = x-NOT(y)-1) &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;g.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRlPGuJJOjPyquIuv-Tjoifx-cIc9U37qfMFqqJz6n2pyuD5Iii4LLBVdSHC9eacZyCoN0k3QO69nXlshPM39KdhYlAuMEEOKw2ZYbI3YN5vAGorOW7ZyG6aAVZ7sDeT9hyphenhyphenY4pmR1iP6Q/s1600-h/Eqn7.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176957536147634&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRlPGuJJOjPyquIuv-Tjoifx-cIc9U37qfMFqqJz6n2pyuD5Iii4LLBVdSHC9eacZyCoN0k3QO69nXlshPM39KdhYlAuMEEOKw2ZYbI3YN5vAGorOW7ZyG6aAVZ7sDeT9hyphenhyphenY4pmR1iP6Q/s320/Eqn7.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(譯註: (x XOR y) = x+y with carry bits ignored,&lt;/p&gt;&lt;p&gt;2(x AND y) = carry bits )&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;h.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh42K-w00zxP9QF16JeMKP25m5ZaBTiviAC9cIK08Ah1jyXu7mNlMIwFoAf6FKsh8Yt0utJu51M9FZKQ3fhUV0xMZ8xqKQqJBDDjb9sOPwrsKogUqbxln8K0QVSXz17XFBMkm047cZFohI/s1600-h/Eqn8.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176957536147650&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh42K-w00zxP9QF16JeMKP25m5ZaBTiviAC9cIK08Ah1jyXu7mNlMIwFoAf6FKsh8Yt0utJu51M9FZKQ3fhUV0xMZ8xqKQqJBDDjb9sOPwrsKogUqbxln8K0QVSXz17XFBMkm047cZFohI/s320/Eqn8.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: (x OR y) = x+y - (x AND y) )&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;i.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuWvP0sT_owA1pdXOa7aPRT57FRFRyCMLcNag_G5k3adD8fWtM9gHSA_gJwdVo3_e2BzUuIlvP3Z5z9mfWnc0zOx6qpWbqlNJkspF9Wvm8jm9RqEmdWZjp_AiqIe1pisTW0u07afZP5Kc/s1600-h/Eqn9.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176961831114962&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuWvP0sT_owA1pdXOa7aPRT57FRFRyCMLcNag_G5k3adD8fWtM9gHSA_gJwdVo3_e2BzUuIlvP3Z5z9mfWnc0zOx6qpWbqlNJkspF9Wvm8jm9RqEmdWZjp_AiqIe1pisTW0u07afZP5Kc/s320/Eqn9.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by g. and h.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;j.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg09UKcf0qaSldUS21C9kSacGppKfQwNRfzfCTlnS8ABsKGkVyHK1BWfLzuW2_9LGJ_Xt4GY5epViVHXjF2BPV4t5dBTrGhHkn2zSpaMAYtK2qZltVzUb9ogQ8cWNN5qMXsMNIDLHhrvsU/s1600-h/Eqn10.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030176961831114978&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg09UKcf0qaSldUS21C9kSacGppKfQwNRfzfCTlnS8ABsKGkVyHK1BWfLzuW2_9LGJ_Xt4GY5epViVHXjF2BPV4t5dBTrGhHkn2zSpaMAYtK2qZltVzUb9ogQ8cWNN5qMXsMNIDLHhrvsU/s320/Eqn10.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(譯註: by a.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;k.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmmy5I4cueMeCV1frT-4bub7f6fatEqoywiI3YcgHxi1G-Jt5LBk2k90iqYkbm7mMHJxgTRRTrpHeUpebnM3oc93Ave3kwijRE0JsTwmYmhNhpbgnfLKHwA2UJAqyIe10uiU0EimTE6SY/s1600-h/Eqn11.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177176579479794&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmmy5I4cueMeCV1frT-4bub7f6fatEqoywiI3YcgHxi1G-Jt5LBk2k90iqYkbm7mMHJxgTRRTrpHeUpebnM3oc93Ave3kwijRE0JsTwmYmhNhpbgnfLKHwA2UJAqyIe10uiU0EimTE6SY/s320/Eqn11.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;(譯註: (x XOR y) = x-y with borrow bits ignored, &lt;/p&gt;&lt;p&gt;2(NOT(x) AND y) = borrow bits)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;l.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidD1y2V37_l33gM0ZyNyMxinKj9zp0w_-fG7lDD0w6T3-AHz10V4KuOaE50cHGtSlp3eIF54PKKO3KIDyj1X-lNDBuuhx6r8cgPHLp8urXwrmhqsxnAO-8HGYiHooopzNG5BSr3CV4VoM/s1600-h/Eqn12.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177180874447106&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidD1y2V37_l33gM0ZyNyMxinKj9zp0w_-fG7lDD0w6T3-AHz10V4KuOaE50cHGtSlp3eIF54PKKO3KIDyj1X-lNDBuuhx6r8cgPHLp8urXwrmhqsxnAO-8HGYiHooopzNG5BSr3CV4VoM/s320/Eqn12.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: first calculate 1-0 parts, then minus the 0-1 parts)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;m.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrWa8IsVO3hDPnf56ilHhmXDjOlBwJxF3ko79b-yNu_t5w4jXMOtzuDDQWYQgzuYfUFB7P4k23bd5UJ7GSeFkBFvW1fVMslqZDVaTaElf8S4nJ3S5BWxWjA9c1cICqO2P3Ij91kjsG0Lw/s1600-h/Eqn13.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177180874447122&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrWa8IsVO3hDPnf56ilHhmXDjOlBwJxF3ko79b-yNu_t5w4jXMOtzuDDQWYQgzuYfUFB7P4k23bd5UJ7GSeFkBFvW1fVMslqZDVaTaElf8S4nJ3S5BWxWjA9c1cICqO2P3Ij91kjsG0Lw/s320/Eqn13.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by k. and l.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;n.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0V_jzryUosD4tY_AXS4BbYnuV5376HKCHmsvUKqwVqrqDgI9mnsT1dx8pR02xF6PXB3dYwIvCt9jfBDUF5y4ZtxZ7v7PgzxNJRHSkMfzofSgiTAy_OCmfjRwDQoskviCBBLvpaAww9gk/s1600-h/Eqn14.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177185169414434&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0V_jzryUosD4tY_AXS4BbYnuV5376HKCHmsvUKqwVqrqDgI9mnsT1dx8pR02xF6PXB3dYwIvCt9jfBDUF5y4ZtxZ7v7PgzxNJRHSkMfzofSgiTAy_OCmfjRwDQoskviCBBLvpaAww9gk/s320/Eqn14.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by definition of XOR)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;o.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1FGCa4yrjeBG4VIYXNyYsaA5bXnLHTkkTjHSQvyeDId-OUyAc1RAW9pSUkoKE57TDTiLDZhLydxhq4keYUrn8ARsIAUHMlmLyfaowvoQeasSlK82pDZo3DSysp-yi0Z3c7vMZIVjyIio/s1600-h/Eqn15.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177185169414450&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1FGCa4yrjeBG4VIYXNyYsaA5bXnLHTkkTjHSQvyeDId-OUyAc1RAW9pSUkoKE57TDTiLDZhLydxhq4keYUrn8ARsIAUHMlmLyfaowvoQeasSlK82pDZo3DSysp-yi0Z3c7vMZIVjyIio/s320/Eqn15.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;(譯註: (x AND NOT(y)) = the mask where x(i)=1 AND y(i)=0)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;p.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9Dh7JQ3D92fKDk9STgOAPTvNmuwGxluz7ibjnQsfSGJMQPs-x19AbvCHAyflbyDTs7zqIjYcGmDj0fejx1JiobjYjhPjGV__F33CiTXWVDwen-QAxNjaeNbNpZyMLElrzyYjW9OHzFKk/s1600-h/Eqn16.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177301133531458&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9Dh7JQ3D92fKDk9STgOAPTvNmuwGxluz7ibjnQsfSGJMQPs-x19AbvCHAyflbyDTs7zqIjYcGmDj0fejx1JiobjYjhPjGV__F33CiTXWVDwen-QAxNjaeNbNpZyMLElrzyYjW9OHzFKk/s320/Eqn16.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;q.&lt;br /&gt;&lt;/p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqp6O7zv9UezV0-7D6ZR0qjjHnqEYcKfi_9JR8-rlIF4ZrSYTHd1dYBj8g1FNLBAEGzuQ994_ZQGCn7PR1pN09XWEbfCSIfR-7Q0qJbN4Vjn-ccRxpqBRjrCS2xhvCgVpGvnSPV_VJ5P0/s1600-h/Eqn17.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177314018433362&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqp6O7zv9UezV0-7D6ZR0qjjHnqEYcKfi_9JR8-rlIF4ZrSYTHd1dYBj8g1FNLBAEGzuQ994_ZQGCn7PR1pN09XWEbfCSIfR-7Q0qJbN4Vjn-ccRxpqBRjrCS2xhvCgVpGvnSPV_VJ5P0/s320/Eqn17.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: NOT(x-y) = -(x-y)-1 = y-x-1)&lt;br /&gt;&lt;br /&gt;r.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2b9KwL_RUCKt4-hA3wo1hh-CGxAhIh4hxwlzgrj2dAvlce2uKsyEy1s7iVgiEOK83x22sYwgRxL1PDvkoDtViUxugm2xc6BwBj0bdb1xOlsEpTLvlhSSJ2BFS6boOv5NwEfY4ZXDefsE/s1600-h/Eqn18.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177318313400674&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2b9KwL_RUCKt4-hA3wo1hh-CGxAhIh4hxwlzgrj2dAvlce2uKsyEy1s7iVgiEOK83x22sYwgRxL1PDvkoDtViUxugm2xc6BwBj0bdb1xOlsEpTLvlhSSJ2BFS6boOv5NwEfY4ZXDefsE/s320/Eqn18.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by q. - NOT(x) = -x-1)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;s.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsg5MJl3f1yBi-q7vHonhkRyXMIBgnYm3Q2bsonFUpBNLCSY4d5L5TbzhQRS6YsQPxwuSyxjUWnCyIRKdsGaArs5QBelhK6G1YQuqDam_9Vz64oGGkaQVmTKaULOhSBzWlFsW8lyf449A/s1600-h/Eqn19.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177318313400690&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsg5MJl3f1yBi-q7vHonhkRyXMIBgnYm3Q2bsonFUpBNLCSY4d5L5TbzhQRS6YsQPxwuSyxjUWnCyIRKdsGaArs5QBelhK6G1YQuqDam_9Vz64oGGkaQVmTKaULOhSBzWlFsW8lyf449A/s320/Eqn19.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: NOT(x XOR y) &lt;/p&gt;&lt;p&gt;= NOT((x OR y) - (x AND y)) &lt;/p&gt;&lt;p&gt;= (x AND y) - (x OR y) -1)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;t.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjkY2kdy3yrNzNayAle5SyuKlfS5iHawtbck_lvZxFzc041a8_Xm-ntNPkeziKCpn5W-dgjZl6nXVzakZJA4zuWhMj0NHNTG8brJMp-ISp25V1mi0PNj9OxcZuS3yMGFLnZenVJ84BuFc/s1600-h/Eqn20.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177318313400706&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjkY2kdy3yrNzNayAle5SyuKlfS5iHawtbck_lvZxFzc041a8_Xm-ntNPkeziKCpn5W-dgjZl6nXVzakZJA4zuWhMj0NHNTG8brJMp-ISp25V1mi0PNj9OxcZuS3yMGFLnZenVJ84BuFc/s320/Eqn20.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by s.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;u.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIac-ixjJ_saR9OcGv2Y9nuXgNGL7dbnUfq2niYhEvKnlQtVvd4UHK5U2pfMfSbJfiz6G6rAXSIroZP_ngrv9fC78RkKwbmgvAb_-N2AjEpxOQrsOWFCdY-N_LPPN0ocXxI1-qWEHNFYI/s1600-h/Eqn21.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177408507713938&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIac-ixjJ_saR9OcGv2Y9nuXgNGL7dbnUfq2niYhEvKnlQtVvd4UHK5U2pfMfSbJfiz6G6rAXSIroZP_ngrv9fC78RkKwbmgvAb_-N2AjEpxOQrsOWFCdY-N_LPPN0ocXxI1-qWEHNFYI/s320/Eqn21.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by o.)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;v.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfkAUVuCbHj7oOrwoXi-WjKmrtiPVjuPXVTbefhxQFM1ODOXwBxFjXOul95tC0F0pM4cUvEVLWdncz8wvcMbSp1Lj0y1e4M2OQUgMP0M3x34YIbVBrWpbw42cX9epxRLUYsv1tj08Uiwk/s1600-h/Eqn22.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5030177408507713954&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfkAUVuCbHj7oOrwoXi-WjKmrtiPVjuPXVTbefhxQFM1ODOXwBxFjXOul95tC0F0pM4cUvEVLWdncz8wvcMbSp1Lj0y1e4M2OQUgMP0M3x34YIbVBrWpbw42cX9epxRLUYsv1tj08Uiwk/s320/Eqn22.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt; (譯註: by p. (x AND y)&lt;/p&gt;&lt;p&gt;= (x - (x AND NOT(y)))&lt;/p&gt;&lt;p&gt;= x + (NOT(x AND NOT(y)) + 1)&lt;/p&gt;&lt;p&gt;= x + (NOT(x) OR y) + 1&lt;/p&gt;&lt;p&gt;= (NOT(x) OR y) + NOT(NOT(x)) + 1&lt;/p&gt;&lt;p&gt;= (NOT(x) OR y) - NOT(x) ) &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;(d) 式可以循換地套用, 例如 -NOT(-NOT(x)) = x + 2, 依此類推. 同樣地, (e) 式也一樣: -NOT(-NOT(-x)) = x - 2. 我們可以利用這兩招對 x 任意增減任意常數.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;(f) 式是 (j) 式的共軛式, (j) 式是使用加法來計算減法的常見技巧.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;(g) 式跟 (h) 式出自 HAKMEN. (g) 式首先忽略進位地計算 x+y, 再補上忽略掉的進位.&lt;/p&gt;&lt;p&gt;對於兩個各位元獨立, 且為0與為1機率同高的亂數, 計算其加法的時候, 已被證明任一位元上發生進位的機率為 0.5. 當使用 (g) 式來計算兩數和的話, 任一位元上發生進位的機率小於 0.5.&lt;/p&gt;&lt;p&gt;(譯註: 原文此處估計為機率大於 0.25 且小於 0.5, 但證明不嚴謹故此處僅保留部份結論) &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;(k), (l) 式與 (g), (h) 式是共軛式. (k) 式首先忽略借位地計算 x-y (該借位的位元憑空加1, 不實際借位), 再扣回忽略掉的借位.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;(n) 式只使用三種運算(AND, OR 跟減) 來實作 XOR 運算, 花費三個指令. 若只用 AND, OR 跟 NOT 的話, 須花費四個指令: (x XOR y) = (x OR y) AND NOT(x AND y).&lt;/p&gt;&lt;p&gt;與此相似, (u), (v) 兩式分別使用三種運算來實作 OR 跟 AND 運算, 花費三個指令.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/6657525623122965821/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/6657525623122965821' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/6657525623122965821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/6657525623122965821'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-2.html' title='Hackers Delight 2-2'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9TX7EBrFPB7jtem4229nvMLW7IoC6bRdz-EtALT7lb49hyphenhyphenV5ATILP4vN5xgaHcAjxvNoEzyG5dRzrGE7B5OCDESj3c2QsiR1gXPdCmigOND3kF7tAi-5H-hQFBcnB-zwRFX_geUQcZko/s72-c/Eqn1.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-2582509147863446802</id><published>2007-02-10T14:57:00.003+08:00</published><updated>2010-10-25T14:15:05.017+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Information"/><title type='text'>Cisco 捨棄 CTA, 改採微軟 NAP client</title><content type='html'>九月份 Cisco 和微軟公佈了整合 NAC(Cisco) 跟 NAP(Microsoft) 的新一代 NAC &lt;a href=&quot;http://www.microsoft.com/presspass/events/ssc/docs/CiscoMSNACWP.pdf&quot;&gt;系統架構&lt;/a&gt;.&lt;br /&gt;此後, 對於安裝了 Windows Vista 及 Longhorn 的電腦, 將直接使用其內建的 NAP client 取代原先 CTA 的功能.&lt;br /&gt;未來 CTA 將主要被用來支援非 Windows 平台, Cisco 甚至即將&lt;a href=&quot;http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;articleId=9010881&amp;amp;pageNumber=1&quot;&gt;公開其原始碼&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;與 Cisco &lt;a href=&quot;http://www.ringline.com.tw/epaper/forum940203.htm&quot;&gt;前一代&lt;/a&gt; NAC 相比, 除了改採 NAP client 之外, 最顯著的差異在於整合了微軟的 Health certificate infrastructure. NAP client 將向 HRA (Health Registration Authority) server 回報自己的狀態以索取 Health Certificate, 屆時再以此 Certificate 當作通行證向 ACS 申請網路存取的權限.</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/2582509147863446802/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/2582509147863446802' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/2582509147863446802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/2582509147863446802'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/cisco-cta-nap-client.html' title='Cisco 捨棄 CTA, 改採微軟 NAP client'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-3392295708220488000</id><published>2007-02-07T13:29:00.002+08:00</published><updated>2010-10-25T14:14:09.103+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-1 (5/5)</title><content type='html'>總和以上流程, 可以得到以下式子:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5028784032162510274&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW_Yv-Ftj5JTAw5r5fsv-gYim2Z00WuoDW3DfO5QkWXks5Cg30gEcvasx8luLMF_ARYx3VErt9TPh4dzJ9LxIPvg-l7Qx4hOZFHuUFYmYUWawbNqAeyIecIZAovx7-ZrWn78_oJ91h6ks/s320/Eqn1.gif&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;br /&gt;(譯註: 原文附上了C語言的實作原始碼, 我想這裡就免了吧)&lt;br /&gt;&lt;br /&gt;如果你的處理器算除法很慢, 但是可以很快地計算尾端0-位元序列長度函數 ntz(x), 前端0-位元序列長度函數 nlz(x), 或1-位元個數函數 pop(x). 則上述式組中的最後一式, 可以代換為下列任一式:&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5028784345695122898&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqEUyD34RhiEEoIwv0NdDtkanF0wO5uJcCkqumAoGl0xEJt2dfAX8HuJHURjxdodEaxodVhdoLWUtSh7X9ELA7tpe_eMmR4RNCTw0wp326d2FUm1uDK52G4r3QCddDT4i4LTslMuY2Vhc/s320/Eqn2.gif&quot; border=&quot;0&quot; /&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/3392295708220488000/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/3392295708220488000' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3392295708220488000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/3392295708220488000'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-1-55.html' title='Hackers Delight 2-1 (5/5)'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiW_Yv-Ftj5JTAw5r5fsv-gYim2Z00WuoDW3DfO5QkWXks5Cg30gEcvasx8luLMF_ARYx3VErt9TPh4dzJ9LxIPvg-l7Qx4hOZFHuUFYmYUWawbNqAeyIecIZAovx7-ZrWn78_oJ91h6ks/s72-c/Eqn1.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-4255958572731288043</id><published>2007-02-06T22:32:00.002+08:00</published><updated>2010-10-25T14:14:09.969+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-1 (4/5)</title><content type='html'>根據此定理, 我們可以推得 - 想要透過基本運算序列來關閉最左的1-位元是不可能的, 因為某個1-位元是否應該被關閉, 取決於它的左側是否還有其他的1-位元. 觀察其左側位元的需求是絕對無法迴避的, 也因此不可能透過右至左計算法達成.&lt;br /&gt;&lt;br /&gt;同理, 想要透過基本運算序列來對一個 word 右移, 旋轉, 左移不定位元, 或計算當中的尾端0-位元序列長度, 都是不可能的. (計算尾端0-位元序列長度時, 輸出的最右位元取決於序列長度的奇偶性, 該性質是不可能只看輸入的最右位元就能決定的)&lt;br /&gt;&lt;br /&gt;(譯註: 左移不定位元之所以無法達成, 可透過以下觀察得証: 令輸入當中的最右1-位元為第 x 號位元, 則輸出的第 x 號位元究竟是1還是0, 取決於左移量是否為0, 而想判斷左移量是否為0, 只看左移量的第 x 號位元或其右的位元是絕對不足以判定的)&lt;br /&gt;&lt;br /&gt;對於上述的位元運算技巧, 有一個特別的應用: 輸入一個數字, 輸出下一個比它大, 而且含有等量 1-位元的數字. 這技巧可以幫助我們在利用數字來表示子集合的情形下, 窮舉所有相同大小的子集合.&lt;br /&gt;&lt;br /&gt;(譯註: 原文很囉唆地說明了用數字來表示子集合的方法, 以下簡單帶過)&lt;br /&gt;想要表示一個子集合, 我們可以把元素宇集存入序列當中, 如此一來每個子集合可以透過一個唯一個數字來表示: 數字當中的 i 號位元為1的時候, 代表該子集內包含 i 號元素.&lt;br /&gt;&lt;br /&gt;R. W. Gosper 提出了一個演算法達成了上述的功能. 令 x 為輸入的數字, 該演算法的概念是尋找 x 當中最右的連續1-位元以及其右的0-位元序列, 並&quot;增加&quot;其數值直到含有等量的1-位元為止.&lt;br /&gt;&lt;br /&gt;例如, 輸入 xxx0 1111 0000 (xxx 表示任意位元), 輸出 xxx1 0000 0111. 該演算法首先透過 s = x AND (-x) 來找出最右的1-位元. 在本例中得到的是 0000 0001 0000.&lt;br /&gt;然後把它加入 x 得到 r (譯註: r 當中少了 n-1 個1-位元, n 代表連續1-位元的長度). 在本例中 r=xxx1 0000 0000.&lt;br /&gt;&lt;br /&gt;接著, 我們必須補上少了的 n-1 個1-位元, 首先計算 r XOR x, 將造出一個有著 n+1 個1-位元的數字. 在本例中 r XOR x = 0001 1111 0000. 很明顯這數字又有了太多的1-位元, 我們將它除以 s, 可消去右側的0-位元序列, 最後再右移兩位元使得當中的1-位元個數為 n-1.&lt;br /&gt;&lt;br /&gt;把這個拼拼湊湊造出來的, 有著 n-1 個置右1-位元序列的數字, 和 r 做 OR 運算就可以得到最終的輸出.</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/4255958572731288043/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/4255958572731288043' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4255958572731288043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/4255958572731288043'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-1-45.html' title='Hackers Delight 2-1 (4/5)'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-7280551631293835912</id><published>2007-02-06T00:06:00.002+08:00</published><updated>2010-10-25T14:14:10.418+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-1 (3/5)</title><content type='html'>定理一 . 一個函數 f: word -&gt; word 可由能同時計算的加, 減, AND, OR, NOT指令序列所實作, 若且為若 其輸出的 word 當中, 每一個位元都只和所有運算元的對應位元, 或其右的位元有關聯.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;(譯注: 例如 f1(x,y) = x AND (SHL(y, 1)) 可由基本運算序列達成: x AND (SHL(y, 1)) = x AND (y + y). 而 f2(x,y) = x AND (SHR(y, 1)) 就辦不到)&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;換句話說, 想像你嘗試計算某函數輸出當中的最右位元, 如果你能夠只看每個運算元的最右位元就能夠計算出來, 而且, 當你嘗試計算右二位元時, 也能只看各運算元的最右及右二位元就能獲得答案, 如此依此類推地嘗試計算.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;如果你能夠在上述的限制之下完成計算, 那麼這個函數必定可以可由能同時計算的加, 減, AND, OR, NOT指令序列所實作, 反之則不行.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;定理當中, &quot;反之不行&quot;的部分, 証明相當容易.&lt;/div&gt;&lt;div&gt;因為加, 減, AND, OR, NOT指令有個共通的特性, 它們都是即使施以上述限制(以後將以 &quot;右至左計算法&quot; 代稱之), 也能夠進行計算的指令. 所以這些指令的任意組合, 也必定能夠以右至左計算法完成.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;而另一個方向的証明, 我們以一個例子來非嚴謹證明之.&lt;/div&gt;&lt;div&gt;假設有一個函數 f 能使用右至左計算法得到輸出, 並假設輸出當中的 2 號 (右 3) 位元定義如下:&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5028085722019788194&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir1_Jr-cgr5YyISQrKCNVw0jcmHLRj-dgW5TN-vjSpBKsgF1mzHkDuhzZOE3JLbt3Tvlw2Qv4cSPscSTo3fQGavgQM-QzFxWApgNJOc-BV2NiUpGs3OoIzJ7IzcPJXKV2Z8pUIMSvruTY/s320/Eqn5.gif&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;我們可以透過下面的方法這樣計算該位元:&lt;/p&gt;&lt;p&gt;首先計算出 SHL(x, 2) (譯註: = (x+x+x+x)), SHL(y, 1) 以及 2 號位元的遮罩 &lt;/p&gt;&lt;p&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5028085790739264946&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiCqqVVUiFfkD_xwIN6_ftueR8j1LqHPMqChs4SGz0FBesk5ajAp9U1__kvTTP4nhyxM1stzdknpqJHwAcHebXIkxjVO_-FuHrXMDJorhDhqDoIPzT6rku7KOXDUzy_UhF0J9-D6iKdE0/s320/Eqn6.gif&quot; border=&quot;0&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;計算 (列 1 OR (列 2 AND 列 3)) AND 列 4 將得到一個輸出, 當中的 2 號位元就是我們想計算的 r_2. 對於其他位元我們可以如法泡製造出它們各自的計算式, 然後和 2 號位元同步地進行運算. 等 32 個輸出被同步地計算完成之後, 再把它們全部 OR 起來即可得到最終輸出.&lt;/p&gt;&lt;p&gt;很容易可以觀察出來, 任何可使用右至左計算法達成的函數, 都能夠以上述的方法造出 32 個基本運算序列並平行計算之, 定理一得証.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/7280551631293835912/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/7280551631293835912' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7280551631293835912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/7280551631293835912'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-1-35.html' title='Hackers Delight 2-1 (3/5)'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir1_Jr-cgr5YyISQrKCNVw0jcmHLRj-dgW5TN-vjSpBKsgF1mzHkDuhzZOE3JLbt3Tvlw2Qv4cSPscSTo3fQGavgQM-QzFxWApgNJOc-BV2NiUpGs3OoIzJ7IzcPJXKV2Z8pUIMSvruTY/s72-c/Eqn5.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-8743000855885501713</id><published>2007-02-04T10:55:00.002+08:00</published><updated>2010-10-25T14:14:11.399+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-1 (2/5)</title><content type='html'>使用下面式子可指示出數字內最右為1的位元以及其右的連續0-位元, 如果根本沒有為1的位元存在, 本式輸出零 (例如 01011000 =&gt; 00001111)&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027507262939460962&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzoztLasflxQexyqrc2ORKlqZ8gu7c9F4Ib2Al_O1QdgB3WHQS5UqBZ1P77LYSYHKd2M1MYucTrjoSA8RvZkEzKc7kNWrF8HpK_qdXKjU8_Uq_4WTVOmsHhxDcMo-A7sQRK1OgQcHR0cA/s320/Eqn1.gif&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;br /&gt;使用下面式子可延伸數字內最右為1的位元, 如果根本沒有為1的位元存在, 本式輸出全1 (例如 01011000 =&gt; 01011111)&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027507353133774194&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRjZ-gUd_eVgxrlQeVXYxcH7JgfdbDqwtp6efDAp7HiGRi6ure5U12IC91qFxyygT2XaE3FRfWrHWMqnQQ3HYqfCdHJVVhxM1vzmLN6LB9HjFy3qSUsU92f-r6-1QeILoYWTjJGx2BVho/s320/Eqn2.gif&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;br /&gt;使用下面式子可關閉最右的連續1-位元序列 (例如: 01011000 =&gt; 01000000)&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK-5bCiQBRPTJryEFuNgaGVE-j1qJ_5RlnxVwmjIDgzUHBVq1cnzOn4mwvhBlniIHANO_Rkm0WIrZFTJAeRWFTKLBQ6BlkBvFMo1PoX_XaJKwl_vh6CNyoteu2076N3rYNkolG6Ds2QZ8/s1600-h/Eqn3.gif&quot;&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027507443328087426&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK-5bCiQBRPTJryEFuNgaGVE-j1qJ_5RlnxVwmjIDgzUHBVq1cnzOn4mwvhBlniIHANO_Rkm0WIrZFTJAeRWFTKLBQ6BlkBvFMo1PoX_XaJKwl_vh6CNyoteu2076N3rYNkolG6Ds2QZ8/s320/Eqn3.gif&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;這式子亦可用來判斷一個非負整數是否為 2^j - 2^k, j&gt;=k&gt;=0 型. 將數字帶入本式之後檢查是否為0即可.&lt;br /&gt;&lt;br /&gt;以上所有式子都有對應的共軛型. 把每個式子的用途描述裡的1和0交換, 然後把式子裡的x-1用x+1取代, x+1用x-1取代, -x用NOT(x+1)取代, AND用OR取代, OR用AND取代, 但維持x跟NOT(x)不變. 轉換後的式子將達成轉換後的用途. 以本節第一個式子為例&lt;br /&gt;&lt;br /&gt;用下面式子可以關閉word裡最右為0的位元, 如果根本沒有該位元, 本式將輸出全1 (例如: 10100111 =&gt; 10101111)&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027507546407302546&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNAmQOdP4t_u7Qr2lGmfiN-8QQuw__ypOrXCncNkUrexHpLCnn-Y3AE3nKZWGz4b2KbNeoT6pawteU3hkL_GS70fjMuvzcMpar6GpBj6tSMj_uZAwLPTqc0r-zpObgYwSRfjngiQ22lAk/s320/Eqn4.gif&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;譯注: 令 f(x) 為原式, f&#39;(x) 為共軛式, 則 f&#39;(x) = NOT(f(NOT(x)) 據此可推得上述的取代規則&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/8743000855885501713/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/8743000855885501713' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8743000855885501713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/8743000855885501713'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-1-25.html' title='Hackers Delight 2-1 (2/5)'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzoztLasflxQexyqrc2ORKlqZ8gu7c9F4Ib2Al_O1QdgB3WHQS5UqBZ1P77LYSYHKd2M1MYucTrjoSA8RvZkEzKc7kNWrF8HpK_qdXKjU8_Uq_4WTVOmsHhxDcMo-A7sQRK1OgQcHR0cA/s72-c/Eqn1.gif" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4691487066079235488.post-903204828836924497</id><published>2007-02-04T00:54:00.002+08:00</published><updated>2010-10-25T14:14:14.577+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackers Delight"/><title type='text'>Hackers Delight 2-1 (1/5)</title><content type='html'>2-1 操縱最右位元&lt;br /&gt;&lt;br /&gt;這節提到的式子, 有些看其來沒啥用, 但在後面的章節會陸續找到它們可應用之處&lt;br /&gt;&lt;br /&gt;下面式子將把word內 (譯注: 本書所述的word大小為32位元) 最右為1的位元關閉, 當最右為1的位元根本不存在的時候, 本式輸出零 (例如: 01011000 =&gt; 01010000)&lt;br /&gt;&lt;br /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027360465252250882&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG34Ut0-Mza8UE7Sk11LGE6KhJLoCIGuiv28zwrbmKIoP8bdN-OKxC1G0cNyjA19o-ytGg7MkjVFsFukM1lanmD4aLD8DmeEH2Lr7az-LDQdJtz_G-XnR_SguPcKAvMRJ5rZfYRigm0Eo/s320/Eqn1.gif&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;該式亦可用來偵測一個無號整數是否為power of 2. 把數字帶入該式之後再判斷輸出是否為0即可.&lt;br /&gt;下面這個式子可用來偵測一個無號整數是否為2^n-1型 (包含0跟全1)&lt;br /&gt;&lt;/p&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027360564036498706&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHdvD_y-71fdRRoRzHAJzVSuxndXRkY10NaokHIiTofH0Nxq0AeyDDdHz_8JvAL-xufijpEjNyvgxUkPHb80ki5tFJwD886eHZyeNwNXeyjZJYkKzE8ExZjyp_QqLNbuxBl2lV4MAqyh0/s320/Eqn2.gif&quot; border=&quot;0&quot; /&gt;&lt;a style=&quot;&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXBq_RCw0FZ2N-PyiYCPnJ3i_WdRT7EKXJEI_K-5ZXlzQJphmBFUEB-DnR8Id4m659bx7QSCPPP-vWnQl2G_dUuGcKOuOIZkDi6iwxodNWtY3v0I6TdD53XYTHDlezXeHg32bQFuI51hI/s1600-h/Eqn2.gif&quot;&gt;&lt;/a&gt; &lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;下面這個式子可以孤立最右為1的位元, 如果根本沒有為1的位元, 本式輸出零 (例如 01011000 =&gt; 00001000)&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027360156014605554&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPegjvkZrAipay4e3IqxK4H7QenJhLoOBsylNo_-J8hI3v73TLryQpU-6s91mWjMNz1avvzVm-wW7WZjfAnv_dp6FMuz9Q93yKHF2aqlvHQYB7LFPOSqbu7eoawczjz89lF2jj6EwrsjE/s320/Eqn3.gif&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;下面這個式子可以孤立最右為0的位元, 如果根本沒有為0的位元, 本式輸出零. (例如 01011000 =&gt; 00001000)&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027360692885517602&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg-gLCw-2dtN5LI1bBvfjSoc7hWhluTEsJY1XW0eo4bAqYOEfOb8wsptaO-y-7A40YM_AKxsxTtUGpvpaX3gTPaGyKAJFx7XHwnyOh_xwSrv1iJFrf73UJ0eXAewg4ufjXOZRKaOy7QKA/s320/Eqn5.gif&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;使用下列任一式可產生找出數字最右的連續0-位元串, 如果輸入為零則輸出全1 (例如01011000 =&gt; 00000111)&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027362750174852402&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEHjoizuJ6V0ywctWhSr2WFkkX7dFHfZ-w6xCidNx0pB1ZcTlAkH-T9K1aU2RDfXYgujzd2Nh4G30unpnNn5LUZjT2dSn82F5tjXnSy494iNeU9GUOskUo3gIDOlQWQb3FmoBah0whTuc/s320/Eqn5.gif&quot; border=&quot;0&quot; /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027363003577922882&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil3TgIM6vWQdsYpCnljTvFF_mwCYhKIXnPpvlitlskE11035PEArEXwXNQuyGhMwCzgfNvO4jLag7JD7XzEbgfwPooc-oLqCppxdGhdpcXEcXoLC1yNHRjosvQM6usOS88xa-qCUm_YjM/s320/Eqn6.gif&quot; border=&quot;0&quot; /&gt;&lt;img id=&quot;BLOGGER_PHOTO_ID_5027363089477268818&quot; style=&quot;display: block; margin: 0px auto 10px; text-align: center;&quot; alt=&quot;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOe_rb1FwvchHNhpdyOPMvSkLo0VtMb4urwfynW0dK3SDR8Zg9Y7BEovLhZrXRHW76pawwt3hBR0rzMc1gyWxvxA_54zVePBm-yMMjczyo5pYaaUu971K4vt7jVcSvZlOF91QyJ3gnNdg/s320/Eqn7.gif&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;當中第一式可以切割成能同時計算的多個指令 (譯注: 原因詳見本節定理1)&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nono-liang.blogspot.com/feeds/903204828836924497/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4691487066079235488/903204828836924497' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/903204828836924497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4691487066079235488/posts/default/903204828836924497'/><link rel='alternate' type='text/html' href='http://nono-liang.blogspot.com/2007/02/hackers-delight-2-1-15.html' title='Hackers Delight 2-1 (1/5)'/><author><name>Nono Liang</name><uri>http://www.blogger.com/profile/14465591315569088592</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG34Ut0-Mza8UE7Sk11LGE6KhJLoCIGuiv28zwrbmKIoP8bdN-OKxC1G0cNyjA19o-ytGg7MkjVFsFukM1lanmD4aLD8DmeEH2Lr7az-LDQdJtz_G-XnR_SguPcKAvMRJ5rZfYRigm0Eo/s72-c/Eqn1.gif" height="72" width="72"/><thr:total>0</thr:total></entry></feed>