<?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:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-1812985003737084262</id><updated>2010-03-04T11:07:28.651-05:00</updated><title type='text'>Bing Xia's Blog</title><subtitle type='html'>When it comes to debugging, a single byte could give you a clue.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.bytetalk.net/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default?start-index=26&amp;max-results=25'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>47</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-966242600238162814</id><published>2010-03-03T15:10:00.004-05:00</published><updated>2010-03-03T18:43:11.453-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>How to load OpenSSL source code into Visual Studio</title><content type='html'>I tried to step into OpenSSL source code to resolve some issue. I built the debug version of the library. However, as I tried to step into the source code in the Visual Studio, the source code could not be found even if I had specified the Debug Source Files in the Visual Studio. The same thing happened in WinDBG. Then I realized that it might have something to do with the compiler options. From the MSDN, one of compiler options is&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;/ZI&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;Produces a program database, as described above, in a format that supports the Edit and Continue feature. If you want to use Edit and Continue debugging, you must use this option. Because most optimizations are incompatible with Edit and Continue, using /ZI disables any #pragma optimize statements in your code.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then I added this option to the OpenSSL makefile and built the debug version of the library again. I could load the OpenSSL source code into the Visual Studio since then.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-966242600238162814?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/966242600238162814/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/03/how-to-load-openssl-source-code-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/966242600238162814'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/966242600238162814'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/03/how-to-load-openssl-source-code-into.html' title='How to load OpenSSL source code into Visual Studio'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-1945595594754779679</id><published>2010-02-19T14:21:00.003-05:00</published><updated>2010-02-19T14:45:15.546-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>How to verify OpenSSL DSA signature using .NET Crypto</title><content type='html'>The DSA signature generated by OpenSSL cannot be verified using .NET crypto API. The error message indicates the DSA signature length is not 40 bytes. The DSA signature generated by .NET crypto API cannot be verified using OpenSSL, either. The error has something to do with ASN.1 encoding routines. Obviously, both errors are due to the different encoding schemes used to encode the generated signature. From the error message, it seems that OpenSSL uses ASN.1 encoding. There is no mention in MSDN regarding to the DSA signature encoding scheme used in .NET crypto. Thank to the article by Jeffrey Walton -- &lt;a href="http://www.codeproject.com/KB/security/CryptoInteropSign.aspx?msg=3240277#xx3240277xx"&gt;Cryptographic Interoperability: Digital Signatures&lt;/a&gt;. .NET crypto uses P1363 to encode the DSA signature. Besides, the article also provides very useful AnsKeyBuilder and AsnKeyParser classes, which make the conversion from P1363 to ASN.1, and vise versa pretty trivial.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-1945595594754779679?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/1945595594754779679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/02/how-to-verify-openssl-dsa-signature.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1945595594754779679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1945595594754779679'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/02/how-to-verify-openssl-dsa-signature.html' title='How to verify OpenSSL DSA signature using .NET Crypto'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-8358464587148568663</id><published>2010-01-27T17:46:00.003-05:00</published><updated>2010-01-27T17:57:40.555-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rx'/><category scheme='http://www.blogger.com/atom/ns#' term='PLINQ'/><title type='text'>Learn PLINQ and Rx</title><content type='html'>I am learning some new features in .NET 4.0 -- PLINQ and Reactive Extensions these days. The following links are used in my reading. As I keep learning, I would add more links as long as I consider the article is useful.&lt;br /&gt;&lt;br /&gt;PLINQ:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163329.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc163329.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc872852.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc872852.aspx&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/pfxteam/archive/2008/06/11/8592301.aspx"&gt;http://blogs.msdn.com/pfxteam/archive/2008/06/11/8592301.aspx&lt;/a&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt; Rx:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://rxwiki.wikidot.com/"&gt;http://rxwiki.wikidot.com/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-8358464587148568663?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/8358464587148568663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/01/learn-plinq-and-rx.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8358464587148568663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8358464587148568663'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/01/learn-plinq-and-rx.html' title='Learn PLINQ and Rx'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-7900258778668252435</id><published>2010-01-22T14:22:00.004-05:00</published><updated>2010-01-22T14:32:53.024-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG'/><category scheme='http://www.blogger.com/atom/ns#' term='Assembly'/><title type='text'>How to edit memory in WinDBG (Cont)</title><content type='html'>I just ran into another good blog by Roberto Farah regarding to how to edit memory using WinDBG and its usefulness -- &lt;a href="http://www.1bit.com.br/content.1bit/weblog/windbg_lp"&gt;WinDbg Live Programming: Fazendo um log das chamadas à MessageBox&lt;/a&gt;. Unfortunately, I do not understand the language used in the blog. However, the blog is just too good to ignore. I redo it on my own and add my own comment on it.&lt;br /&gt;&lt;br /&gt;The blog shows how to capture the message text for the MessageBoxW and write it to the debugger console by editing the instruction in the memory.&lt;br /&gt;&lt;br /&gt;Allocate 1000 bytes of memory. It would return the starting address of the allocated memory.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; .dvalloc 1000&lt;br /&gt;Allocated 1000 bytes starting at 00340000&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Add CRLF in unicode to the beginning of the memory.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; r $t0=0x00340000&lt;br /&gt;0:000&gt; ezu $t0 "\r\n"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Check the memory does start with CRLF.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; db $t0 L0xF&lt;br /&gt;00340000  0d 00 0a 00 00 00 00 00-00 00 00 00 00 00 00     ...............&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Start editing the memory right after CRLF. Since the string is in unicode, 6 bytes are required. First push EAX onto the stack and call OutputDebugStringW, then push CRLF onto the stack and call OutputDebugStringW, finally add a debugbreak.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; r $t1=$t0+0x6&lt;br /&gt;0:000&gt; a $t1&lt;br /&gt;00340006 push eax&lt;br /&gt;00340007 call kernel32!OutputDebugStringW&lt;br /&gt;0034000c push 0x00340000&lt;br /&gt;00340011 call kernel32!OutputDebugStringW&lt;br /&gt;00340016 int 3&lt;br /&gt;00340017&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Check the memory after editing&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; u $t1&lt;br /&gt;00340006 50              push    eax&lt;br /&gt;00340007 e8f9b3517c      call    kernel32!OutputDebugStringW (7c85b405)&lt;br /&gt;0034000c 6800003400      push    340000h&lt;br /&gt;00340011 e8efb3517c      call    kernel32!OutputDebugStringW (7c85b405)&lt;br /&gt;00340016 cc              int     3&lt;br /&gt;00340017 0000            add     byte ptr [eax],al&lt;br /&gt;00340019 0000            add     byte ptr [eax],al&lt;br /&gt;0034001b 0000            add     byte ptr [eax],al&lt;br /&gt;&lt;br /&gt;0:000&gt; db $t0&lt;br /&gt;00340000  0d 00 0a 00 00 00 50 e8-f9 b3 51 7c 68 00 00 34  ......P...Q|h..4&lt;br /&gt;00340010  00 e8 ef b3 51 7c cc 00-00 00 00 00 00 00 00 00  ....Q|..........&lt;br /&gt;00340020  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;00340030  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;00340040  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;00340050  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;00340060  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;00340070  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Set a breakpoint at the beginning of MessageBoxExW. At the breakpoint, store EIP to $t2, the second parameter to EAX, and the new address to EIP.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; bp user32!MessageBoxExW "r $t2=@eip;r eax=poi(@esp+8);r eip=$t1;g"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Set a breakpoint at the debugbreak. When the new instructions have been executed, restore the original EIP.&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; bp $t0+0x16 "r eip=$t2;g"&lt;br /&gt;0:000&gt; g&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The following is the source code.&lt;br /&gt;int _tmain(int argc, _TCHAR* argv[])&lt;br /&gt;{&lt;br /&gt;      wchar_t wzBuffer[128];&lt;br /&gt;      DWORD dwInterval = 1000, dwCount = 3;&lt;br /&gt;&lt;br /&gt;       for(DWORD a = 0 ; a &lt; dwCount ; a++)&lt;br /&gt;      {&lt;br /&gt;              wsprintf(wzBuffer, L"This is message box%d", a);&lt;br /&gt;              MessageBox(NULL, wzBuffer, L"LOG", MB_OK);&lt;br /&gt;              Sleep(dwInterval);&lt;br /&gt;      }&lt;br /&gt;      return 0;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-7900258778668252435?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/7900258778668252435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/01/how-to-edit-memory-in-windbg-cont.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7900258778668252435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7900258778668252435'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/01/how-to-edit-memory-in-windbg-cont.html' title='How to edit memory in WinDBG (Cont)'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-6265072059400971903</id><published>2010-01-21T11:11:00.004-05:00</published><updated>2010-01-21T11:19:18.464-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG'/><category scheme='http://www.blogger.com/atom/ns#' term='Assembly'/><title type='text'>How to edit memory in WinDBG</title><content type='html'>The blog by Roberto Farah -- &lt;a href="http://blogs.msdn.com/debuggingtoolbox/archive/2010/01/06/special-command-editing-memory-with-a-eb-ed-ew-eza-ezu.aspx"&gt;Special Command—Editing memory with a, eb, ed, ew, eza, ezu&lt;/a&gt; provides a pretty good example on how to edit memory using WinDBG. Of course, the same techniques could be used in reverse engineering as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-6265072059400971903?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/6265072059400971903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/01/how-to-edit-memory-in-windbg.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6265072059400971903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6265072059400971903'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/01/how-to-edit-memory-in-windbg.html' title='How to edit memory in WinDBG'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-7521810123520236500</id><published>2010-01-06T12:29:00.003-05:00</published><updated>2010-01-06T12:36:06.143-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Kernel'/><title type='text'>Understand Pool Consumption</title><content type='html'>The blog -- &lt;a href="http://blogs.msdn.com/ntdebugging/archive/2006/12/18/Understanding-Pool-Consumption-and-Event-ID_3A00_--2020-or-2019.aspx"&gt;Understanding Pool Consumption and Event ID: 2020 or 2019&lt;/a&gt; by Tate provides pretty good information on the kernel pool and how to trouble-shoot its consumption.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-7521810123520236500?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/7521810123520236500/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2010/01/understanding-pool-consumption-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7521810123520236500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7521810123520236500'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2010/01/understanding-pool-consumption-and.html' title='Understand Pool Consumption'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-5112485841624923385</id><published>2009-10-24T12:07:00.020-04:00</published><updated>2009-10-24T21:50:31.591-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG'/><title type='text'>Heap corruption in managed code</title><content type='html'>It has been reported that the SSH server would crash during download when the client changed the max packet size from 30000 to 50000. It seemed to be a classic example of buffer overflow.&lt;br /&gt;&lt;br /&gt;My initial suspect was the heap corruption due to the buffer overflow.&lt;br /&gt;&lt;br /&gt;The SSH server is written in C# with its data access and crypto library in native C++. When I used the &lt;a href="http://www.microsoft.com/DownLoads/details.aspx?familyid=C4A25AB9-649D-4A1B-B4A7-C9D8B095DF18&amp;amp;displaylang=en"&gt;Application Verifier&lt;/a&gt; with full page heap enabled, the windbg showed the following error.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;(1244.1004): &lt;span style="color: rgb(255, 0, 0);"&gt;Access violation - code c0000005&lt;/span&gt; (first chance)&lt;br /&gt;First chance exceptions are reported before any exception handling.&lt;br /&gt;This exception may be expected and handled.&lt;br /&gt;eax=21630953 ebx=00000000 ecx=02f2b024 edx=00000000 esi=02efae5c edi=09f6f0ec&lt;br /&gt;eip=09b5b6eb esp=09f6efdc ebp=09f6f0fc iopl=0         nv up ei pl zr na pe nc&lt;br /&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246&lt;br /&gt;Missing image name, possible paged-out or corrupt data.&lt;br /&gt;&lt;unloaded_mib1.dll&gt;+0x9b5b6ea:&lt;br /&gt;09b5b6eb ff505c          call    dword ptr [eax+5Ch]  ds:0023:216309af=????????&lt;br /&gt;&lt;/unloaded_mib1.dll&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:019&gt; kb&lt;br /&gt;ChildEBP RetAddr  Args to Child&lt;br /&gt;WARNING: Frame IP not in any known module. Following frames may be wrong.&lt;br /&gt;09f6f0fc 09b5a602 02f02ba0 02f68a50 02f2b024 &lt;unloaded_mib1.dll&gt;+0x9b5b6ea&lt;br /&gt;*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\3de5bd01124463d7862bd173af90bc83\System.ni.dll&lt;br /&gt;09f6f410 7a57ee09 0148c220 02efad80 02f30b08 &lt;unloaded_mib1.dll&gt;+0x9b5a601&lt;br /&gt;09f6f448 7a581eba 02f689f8 792f5681 00000000 System_ni+0x13ee09&lt;br /&gt;09f6f460 79e71b4c 09f6f480 0147fb6a 09f6f4f0 System_ni+0x141eba&lt;br /&gt;09f6f470 79e821b9 09f6f540 00000000 09f6f510 mscorwks!CallDescrWorker+0x33&lt;br /&gt;09f6f4f0 79e96531 09f6f540 00000000 09f6f510 mscorwks!CallDescrWorkerWithHandler+0xa3&lt;br /&gt;09f6f630 79e96564 79241ff0 09f6f764 09f6f684 mscorwks!MethodDesc::CallDescr+0x19c&lt;br /&gt;09f6f64c 79e96582 79241ff0 09f6f764 09f6f684 mscorwks!MethodDesc::CallTargetWorker+0x1f&lt;br /&gt;09f6f664 79f6a259 09f6f684 80acc23f 02a3a6b8 mscorwks!MethodDescCallSite::CallWithValueTypes_RetArgSlot+0x1a&lt;br /&gt;09f6f830 79f6a3ae 09f6f8c0 80acc2ef 02f68a40 mscorwks!ExecuteCodeWithGuaranteedCleanupHelper+0x9f&lt;br /&gt;*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\7124a40b9998f7b63c86bd1a2125ce26\mscorlib.ni.dll&lt;br /&gt;09f6f8e0 792f5577 09f6f884 02f30b6c 02f689d8 mscorwks!ReflectionInvocation::ExecuteCodeWithGuaranteedCleanup+0x10f&lt;br /&gt;09f6f8fc 792e01c5 00000000 02f30b6c 02f30b08 mscorlib_ni+0x235577&lt;br /&gt;09f6f914 7a5825b1 00000000 00000000 00000000 mscorlib_ni+0x2201c5&lt;br /&gt;09f6f930 7a57ed70 02f30b08 00000000 00000000 System_ni+0x1425b1&lt;br /&gt;09f6f95c 7a5824b4 00000000 02f30b08 00000000 System_ni+0x13ed70&lt;br /&gt;09f6f994 7928cdc4 02f2c39c 00000060 00000000 System_ni+0x1424b4&lt;br /&gt;09f6f9b4 79e71b4c 02f2c39c 09f6f9d8 0147fb6a mscorlib_ni+0x1ccdc4&lt;br /&gt;09f6f9c8 79e821b9 09f6fb64 00000001 09f6fb58 mscorwks!CallDescrWorker+0x33&lt;br /&gt;09f6fa48 79e8281f 09f6fb64 00000001 09f6fb58 mscorwks!CallDescrWorkerWithHandler+0xa3&lt;br /&gt;09f6fa68 79e82860 09f6fb60 00000001 09f6fb58 mscorwks!DispatchCallBody+0x1e&lt;br /&gt;&lt;/unloaded_mib1.dll&gt;&lt;/unloaded_mib1.dll&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:019&gt; !clrstack&lt;br /&gt;OS Thread Id: 0x1004 (19)&lt;br /&gt;ESP       EIP&lt;br /&gt;09f6efdc 09b5b6eb SSHServerAPI.Transport.Core._ProcessReadPacket(SSHCommonAPI.SSH2BufferStream, Byte[], Byte[])&lt;br /&gt;09f6f10c 09b5a602 SSHServerAPI.Transport.Core._OnPacketRecv(System.IAsyncResult)&lt;br /&gt;09f6f418 7a57ee09 System.Net.LazyAsyncResult.Complete(IntPtr)&lt;br /&gt;09f6f450 7a581eba System.Net.ContextAwareResult.CompleteCallback(System.Object)&lt;br /&gt;09f6f458 792f5681 System.Threading.ExecutionContext.runTryCode(System.Object)&lt;br /&gt;09f6f884 79e71b4c [HelperMethodFrame_PROTECTOBJ: 09f6f884] System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)&lt;br /&gt;09f6f8ec 792f5577 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)&lt;br /&gt;09f6f908 792e01c5 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)&lt;br /&gt;09f6f920 7a5825b1 System.Net.ContextAwareResult.Complete(IntPtr)&lt;br /&gt;09f6f938 7a57ed70 System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)&lt;br /&gt;09f6f968 7a5824b4 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)&lt;br /&gt;09f6f9a0 7928cdc4 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)&lt;br /&gt;09f6fb40 79e71b4c [GCFrame: 09f6fb40]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It indicated an access violation exception at 09b5b6eb. It seemed that EAX had been overwritten somewhere before. The stack trace did not provide any very useful clue on the location where the buffer overflow occurred. However, from the stack trace, the access violation seemed to happen in the SSH server managed code layer.&lt;br /&gt;&lt;br /&gt;Then I used the SOS command - VerifyHeap to verify the integrity of the managed heap.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:019&gt; !VerifyHeap&lt;br /&gt;-verify will only produce output if there are errors in the heap&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;object 02efae5c: bad member 02f2b024 at 02efae84&lt;/span&gt;&lt;br /&gt;curr_object : 02efae5c&lt;br /&gt;Last good object: 02efae2c&lt;br /&gt;----------------&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:019&gt; !do 02efae5c&lt;note:&gt;&lt;br /&gt;Name: SSHServerAPI.Transport.Core&lt;br /&gt;MethodTable: 09205efc&lt;br /&gt;EEClass: 09b43250&lt;br /&gt;Size: 180(0xb4) bytes&lt;br /&gt;(C:\ftp.server.7.5\debug\SSHServerAPI.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;...&lt;br /&gt;79333470  40001df       20        System.Byte[]  0 instance 02f22760 m_buffer&lt;br /&gt;79333470  40001e0       24        System.Byte[]  0 instance 02f19e9c m_ReadBuf&lt;br /&gt;09206af8  40001e1       28 ....SSH2BufferStream  0 instance 02f2b024 m_ReadStream&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:019&gt; !do 02f2b024&lt;note:&gt;&lt;br /&gt;Invalid object&lt;br /&gt;&lt;/note:&gt;&lt;/note:&gt;&lt;/span&gt;&lt;br /&gt;It indicated that m_ReadStream had been corrupted.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:019&gt; dd 02f2b024 L1&lt;br /&gt;02f2b024  21630953&lt;br /&gt;&lt;br /&gt;0:019&gt; !dumpheap -type SSH2BufferStream&lt;br /&gt;Address       MT     Size&lt;br /&gt;02efde10 09206af8       60&lt;br /&gt;02f05340 09206af8       60&lt;br /&gt;02f14eec 09206af8       60&lt;br /&gt;02f15074 09206af8       60&lt;br /&gt;02f15304 09206af8       60&lt;br /&gt;02f154a0 09206af8       60&lt;br /&gt;02f15840 09206af8       60&lt;br /&gt;02f15ae0 09206af8       60&lt;br /&gt;object 02f2b024: does not have valid MT&lt;br /&gt;curr_object : 02f2b024&lt;br /&gt;Last good object: 02f22760&lt;br /&gt;----------------&lt;br /&gt;total 8 objects&lt;br /&gt;Statistics:&lt;br /&gt;MT    Count    TotalSize Class Name&lt;br /&gt;09206af8        8          480 SSHCommonAPI.SSH2BufferStream&lt;br /&gt;Total 8 objects&lt;br /&gt;&lt;br /&gt;0:019&gt; !do 02f15ae0&lt;br /&gt;Name: SSHCommonAPI.SSH2BufferStream&lt;br /&gt;MethodTable: &lt;span style="color: rgb(255, 0, 0);"&gt;09206af8&lt;/span&gt;&lt;br /&gt;EEClass: 09b45adc&lt;br /&gt;Size: 60(0x3c) bytes&lt;br /&gt;(C:\ftp.server.7.5\debug\SSHCommonAPI.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;7933061c  400018a        4        System.Object  0 instance 00000000 __identity&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:019&gt; dd 02f15ae0 L1&lt;br /&gt;02f15ae0 &lt;span style="color: rgb(255, 0, 0);"&gt; 09206af8 &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Internally, a managed object starts with 8 bytes of metadata -- first 4 bytes for the sync block index, and the next 4 bytes for the method table address. It seems that the address of a managed object in the windbg points to its method table address. So by comparing the method table addresses between an invalid object and valid one, it confirmed that the method table address of m_ReadStream at 02f2b024 had been overwritten.&lt;br /&gt;&lt;br /&gt;Since right above m_ReadStream is m_ReadBuf. It happens to be a byte array. Even more, the array size has been hard-coded to 35000. When I changed its size to 40000, the SSH server no longer crashed during download. It looked like that the buffer overflow of m_ReadBuf was the culprit. Then I tried to understand where and how in the code the buffer overflow happened. I found that m_ReadBuf was solely used to read client responses. During download, each client response would be much smaller that 35000. So m_ReadBuf should not be overflowed.&lt;br /&gt;&lt;br /&gt;Now the question is why there was no crash in the server when m_ReadBuf size was changed from 35000 to 40000.&lt;br /&gt;&lt;br /&gt;One possible explanation could be that when the m_ReadBuf size was 35000, the overflow happened to overwrite the next object; when the m_ReadBuf size is 40000, the next object was moved back by 5000 bytes, so when the overflow happened, it just overwrote some unused memory, and therefore there was no crash!&lt;br /&gt;&lt;br /&gt;Since a managed object in the managed heap starts with its method table address, which would not be changed throughout its lifetime, so a data breakpoint could be used to break the code when the method table address is overwritten. By this way, the stack trace would display the exact location when the overflow occurs.&lt;br /&gt;&lt;br /&gt;The following steps were used to set a data breakpoint.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:022&gt; !dumpheap -type SSHServerAPI.SFTP.Subsystem&lt;br /&gt;Address       MT     Size&lt;br /&gt;02f1af4c 0920af7c       84&lt;br /&gt;total 1 objects&lt;br /&gt;Statistics:&lt;br /&gt;MT    Count    TotalSize Class Name&lt;br /&gt;0920af7c        1           84 SSHServerAPI.SFTP.Subsystem&lt;br /&gt;Total 1 objects&lt;br /&gt;&lt;br /&gt;0:022&gt; !dumpmt -md 0920af7c&lt;br /&gt;EEClass: 0a1d64b4&lt;br /&gt;Module: 02534164Name: SSHServerAPI.SFTP.Subsystem&lt;br /&gt;mdToken: 02000033  (C:\ftp.server.7.5\debug\SSHServerAPI.dll)&lt;br /&gt;BaseSize: 0x54&lt;br /&gt;ComponentSize: 0x0&lt;br /&gt;Number of IFaces in IFaceMap: 1Slots in VTable: 72&lt;br /&gt;--------------------------------------&lt;br /&gt;MethodDesc Table&lt;br /&gt;Entry MethodDesc      JIT Name&lt;br /&gt;...&lt;br /&gt;06ad4691   0920ad10     NONE SSHServerAPI.SFTP.Subsystem.FXP_Read()&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:022&gt; !bpmd -md 0920ad10&lt;br /&gt;MethodDesc = 0920ad10&lt;br /&gt;Adding pending breakpoints...&lt;br /&gt;sxe -c "!bpmd -notification;g" clrn&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First, set a managed breakpoint at SSHServerAPI.SFTP.Subsystem.FXP_Read, which is a core function for download.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:022&gt; g&lt;br /&gt;Closing _RecordsetPtr (m_rset)Closing _RecordsetPtr (m_rset)ModLoad: 605d0000 605d9000   C:\WINDOWS\system32\mslbui.dll&lt;br /&gt;(111c.f2c): CLR notification exception - code e0444143 (first chance)&lt;br /&gt;JITTED SSHServerAPI!SSHServerAPI.SFTP.Subsystem.FXP_Read()&lt;br /&gt;Setting breakpoint: bp 0A446030 [SSHServerAPI.SFTP.Subsystem.FXP_Read()]&lt;br /&gt;bp 0A446030&lt;br /&gt;Breakpoint: JIT notification received for method SSHServerAPI.SFTP.Subsystem.FXP_Read().&lt;br /&gt;Breakpoint 0 hit&lt;br /&gt;eax=0920ad10 ebx=00000000 ecx=02f05e9c edx=00000002 esi=09e6ef64 edi=02f001f4&lt;br /&gt;eip=0a446030 esp=09e6ecec ebp=09e6edd8 iopl=0         nv up ei pl nz na pe nc&lt;br /&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206&lt;br /&gt;&lt;unloaded_mib1.dll&gt;+0xa44602f:&lt;br /&gt;0a446030 55              push    ebp&lt;br /&gt;&lt;br /&gt;0:018&gt; !dumpheap -type SSHServerAPI.Transport.Core&lt;br /&gt;Address       MT     Size&lt;br /&gt;02efae04 09205efc      180      ThinLock owner 6 (0132efa0) Recursive 0&lt;br /&gt;02f224d8 09205efc      180&lt;br /&gt;total 2 objects&lt;br /&gt;Statistics:&lt;br /&gt;MT    Count    TotalSize Class Name&lt;br /&gt;09205efc        2          360 SSHServerAPI.Transport.Core&lt;br /&gt;Total 2 objects&lt;br /&gt;&lt;br /&gt;0:018&gt; !do 02efae04&lt;br /&gt;Name: SSHServerAPI.Transport.Core&lt;br /&gt;MethodTable: 09205efc&lt;br /&gt;EEClass: 09b42cac&lt;br /&gt;Size: 180(0xb4) bytes&lt;br /&gt;(C:\ftp.server.7.5\debug\SSHServerAPI.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;...&lt;br /&gt;79333470  40001df       20        System.Byte[]  0 instance 02f1064c m_buffer&lt;br /&gt;79333470  40001e0       24        System.Byte[]  0 instance 02f07d88 m_ReadBuf&lt;br /&gt;09206af8  40001e1       28 ....SSH2BufferStream  0 instance 02f18f10 m_ReadStream&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:018&gt; !do 02f18f10&lt;br /&gt;Name: SSHCommonAPI.SSH2BufferStream&lt;br /&gt;MethodTable: 09206af8&lt;br /&gt;EEClass: 09b45538&lt;br /&gt;Size: 60(0x3c) bytes&lt;br /&gt;(C:\ftp.server.7.5\debug\SSHCommonAPI.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;7933061c  400018a        4        System.Object  0 instance 00000000 __identity&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:018&gt; ba w4 02f18f10&lt;br /&gt;&lt;/unloaded_mib1.dll&gt;&lt;/span&gt;&lt;br /&gt;When the breakpoint hit, retrieved the address of m_ReadStream, checked whether the object was still valid, and then set a data breakpoint on its first four bytes, which contained the address of its method table.&lt;br /&gt;&lt;br /&gt;There were two instances of SSHServerAPI.Transport.Core, the same steps could be used to set a data breakpoint.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:018&gt; g&lt;br /&gt;Breakpoint 1 hit&lt;br /&gt;eax=00000058 ebx=02f18f04 ecx=7ae6d4c1 edx=0000000c esi=02f18ef4 edi=041429f8&lt;br /&gt;eip=0fb76a99 esp=09e6e604 ebp=00000010 iopl=0         nv up ei pl nz na po nc&lt;br /&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202&lt;br /&gt;*** WARNING: Unable to verify checksum for C:\ftp.server.7.5\debug\IPSLIBEAY32.dll&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;IPSLIBEAY32!AES_cbc_encrypt+0xc9&lt;/span&gt;:&lt;br /&gt;0fb76a99 42              inc     edx&lt;br /&gt;&lt;br /&gt;0:018&gt; !do 02efae04&lt;note:&gt;&lt;br /&gt;Name: SSHServerAPI.Transport.Core&lt;br /&gt;MethodTable: 09205efc&lt;br /&gt;EEClass: 09b42cac&lt;br /&gt;Size: 180(0xb4) bytes&lt;br /&gt;(C:\ftp.server.7.5\debug\SSHServerAPI.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;...&lt;br /&gt;79333470  40001df       20        System.Byte[]  0 instance 02f1064c m_buffer&lt;br /&gt;79333470  40001e0       24        System.Byte[]  0 instance 02f07d88 m_ReadBuf&lt;br /&gt;09206af8  40001e1       28 ....SSH2BufferStream  0 instance 02f18f10 m_ReadStream&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:018&gt; !do 02f18f10&lt;note:&gt;&lt;br /&gt;Invalid object&lt;br /&gt;&lt;/note:&gt;&lt;/note:&gt;&lt;/span&gt;&lt;br /&gt;When the breakpoint hit, checked that m_ReadStream was indeed no longer valid.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:018&gt; kb&lt;br /&gt;ChildEBP RetAddr  Args to Child&lt;br /&gt;09e6e600 79e71bb0 0000000e 0148c220 0fbc98b0 IPSLIBEAY32!AES_cbc_encrypt+0xc9&lt;br /&gt;09e6e62c 0fb95fb7 0413a158 02f10664 000088b0 mscorwks!GetThreadGeneric+0xe&lt;br /&gt;09e6e64c 0fb96bfa 05c97af0 02f10654 05c97b20 IPSLIBEAY32!EVP_aes_192_ecb+0x37&lt;br /&gt;09e6e65c 0fb96b79 05c97af0 02f10664 0413a158 IPSLIBEAY32!EVP_EncryptUpdate+0x12a&lt;br /&gt;09e6e670 79e71d71 09e6e6a8 00000008 0132efa0 IPSLIBEAY32!EVP_EncryptUpdate+0xa9&lt;br /&gt;09e6e68c 79e71d8b 05c97af0 02f10664 09e6e730 mscorwks!PInvokeCalliWorker+0x35&lt;br /&gt;09e6e7b8 7c929fef 0148c220 02fd788c 02fd78c8 mscorwks!PInvokeCalliReturnFromCall&lt;br /&gt;09e6e818 02fd76f8 02fd76f8 02fd7358 02fd7358 ntdll!RtlAcquireResourceShared+0x120&lt;br /&gt;WARNING: Frame IP not in any known module. Following frames may be wrong.&lt;br /&gt;09e6e824 02fd7358 02fd7358 00000000 00000000 &lt;unloaded_mib1.dll&gt;+0x2fd76f7&lt;br /&gt;09e6e828 02fd7358 00000000 00000000 02fd76f8 &lt;unloaded_mib1.dll&gt;+0x2fd7357&lt;br /&gt;09e6e82c 00000000 00000000 02fd76f8 02fd71a4 &lt;unloaded_mib1.dll&gt;+0x2fd7357&lt;br /&gt;&lt;br /&gt;0:018&gt; !clrstack&lt;br /&gt;OS Thread Id: 0xf2c (18)&lt;br /&gt;ESP       EIP&lt;br /&gt;09e6e6fc 0fb76a99 [PInvokeCalliFrame: 09e6e6fc]&lt;br /&gt;09e6e71c 09b59311 UtilAPI.SymmetricTransform.TransformBlock(Byte[], Int32, Int32, Byte[], Int32)&lt;br /&gt;09e6e75c 09b587d6 SSHServerAPI.Transport.Core.SendPacket(SSHCommonAPI.Transport.PacketOut)&lt;br /&gt;09e6e9c8 0a1ebc7e SSHServerAPI.Transport.Channel.SendSSHPackets(SSHCommonAPI.SSH2BufferStream ByRef)&lt;br /&gt;09e6ea7c 0a1eb6c1 SSHServerAPI.Transport.Channel.SendPacket(SSHCommonAPI.SFTP.SFTPPacket)&lt;br /&gt;09e6eb70 0a4465ed SSHServerAPI.SFTP.Subsystem.FXP_Read()&lt;br /&gt;09e6ecf0 0a1eabb0 SSHServerAPI.SFTP.Subsystem.DispathPacket()&lt;br /&gt;09e6ede0 0a1ea5c7 SSHServerAPI.SFTP.Subsystem.ProcessData(SSHCommonAPI.SSH2BufferStream)&lt;br /&gt;09e6ef0c 0a1ea0fa SSHServerAPI.Transport.Channel.ChannelData(SSHCommonAPI.SSH2BufferStream)&lt;br /&gt;09e6ef94 0a1e9e79 SSHServerAPI.Transport.PacketDispatch.HandleChannelData()&lt;br /&gt;09e6efcc 0a1e7a89 SSHServerAPI.Transport.PacketDispatch._ChannelDispatch()&lt;br /&gt;09e6f01c 09b5bb59 SSHServerAPI.Transport.PacketDispatch.Process(SSHCommonAPI.SSH2BufferStream, Byte[], Byte[])&lt;br /&gt;09e6f064 09b5b7cb SSHServerAPI.Transport.Core._ProcessReadPacket(SSHCommonAPI.SSH2BufferStream, Byte[], Byte[])&lt;br /&gt;09e6f18c 09b5a72a SSHServerAPI.Transport.Core._OnPacketRecv(System.IAsyncResult)&lt;br /&gt;09e6f498 7a57ee09 System.Net.LazyAsyncResult.Complete(IntPtr)&lt;br /&gt;09e6f4d0 7a581eba System.Net.ContextAwareResult.CompleteCallback(System.Object)&lt;br /&gt;09e6f4d8 792f5681 System.Threading.ExecutionContext.runTryCode(System.Object)&lt;br /&gt;09e6f904 79e71b4c [HelperMethodFrame_PROTECTOBJ: 09e6f904]&lt;br /&gt;System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)&lt;br /&gt;09e6f96c 792f5577 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,&lt;br /&gt;System.Threading.ContextCallback, System.Object)&lt;br /&gt;09e6f988 792e01c5 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)&lt;br /&gt;09e6f9a0 7a5825b1 System.Net.ContextAwareResult.Complete(IntPtr)&lt;br /&gt;09e6f9b8 7a57ed70 System.Net.LazyAsyncResult.ProtectedInvokeCallback(System.Object, IntPtr)&lt;br /&gt;09e6f9e8 7a5824b4 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)&lt;br /&gt;09e6fa20 7928cdc4 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)&lt;br /&gt;09e6fbc0 79e71b4c [GCFrame: 09e6fbc0]&lt;br /&gt;&lt;/unloaded_mib1.dll&gt;&lt;/unloaded_mib1.dll&gt;&lt;/unloaded_mib1.dll&gt;&lt;/span&gt;&lt;br /&gt;From the stack trace, it seemed that the overwrite happened during AES encryption. Now I have the exact location where the overwrite occurred!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:018&gt; uf IPSLIBEAY32!AES_cbc_encrypt&lt;br /&gt;IPSLIBEAY32!AES_cbc_encrypt:&lt;br /&gt;0fb769d0 55              push    ebp&lt;br /&gt;0fb769d1 57              push    edi&lt;br /&gt;0fb769d2 56              push    esi&lt;br /&gt;0fb769d3 53              push    ebx&lt;br /&gt;0fb769d4 83ec1c          sub     esp,1Ch&lt;br /&gt;0fb769d7 837c244401      cmp     dword ptr [esp+44h],1 &lt;span style="font-style: italic;"&gt;; a flag&lt;/span&gt;&lt;br /&gt;0fb769dc 8b7c2430        mov     edi,dword ptr [esp+30h] &lt;span style="font-style: italic;"&gt;; input buffer&lt;/span&gt;&lt;br /&gt;0fb769e0 8b5c2434        mov     ebx,dword ptr [esp+34h] &lt;span style="font-style: italic;"&gt;; output buffer&lt;/span&gt;&lt;br /&gt;0fb769e4 8b6c2438        mov     ebp,dword ptr [esp+38h] &lt;span style="font-style: italic;"&gt;; length&lt;/span&gt;&lt;br /&gt;0fb769e8 8b742440        mov     esi,dword ptr [esp+40h]&lt;br /&gt;0fb769ec 0f848f000000    je      IPSLIBEAY32!AES_cbc_encrypt+0xb1 (0fb76a81)&lt;br /&gt;...&lt;br /&gt;IPSLIBEAY32!AES_cbc_encrypt+0xc0:&lt;br /&gt;0fb76a90 8a0432          mov     al,byte ptr [edx+esi]&lt;br /&gt;0fb76a93 32043a          xor     al,byte ptr [edx+edi]&lt;br /&gt;0fb76a96 88041a          mov     byte ptr [edx+ebx],al&lt;br /&gt;0fb76a99 42              inc     edx&lt;br /&gt;0fb76a9a 83fa0f          cmp     edx,0Fh&lt;br /&gt;0fb76a9d 76f1            jbe     IPSLIBEAY32!AES_cbc_encrypt+0xc0 (0fb76a90)&lt;br /&gt;&lt;br /&gt;IPSLIBEAY32!AES_cbc_encrypt+0xcf:&lt;br /&gt;0fb76a9f ebc5            jmp     IPSLIBEAY32!AES_cbc_encrypt+0x96 (0fb76a66)&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;0:018&gt; r&lt;br /&gt;eax=00000058 ebx=02f18f04 ecx=7ae6d4c1 edx=0000000c esi=02f18ef4 edi=041429f8&lt;br /&gt;eip=0fb76a99 esp=09e6e604 ebp=00000010 iopl=0         nv up ei pl nz na po nc&lt;br /&gt;cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202&lt;br /&gt;IPSLIBEAY32!AES_cbc_encrypt+0xc9:&lt;br /&gt;0fb76a99 42              inc     edx&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;From the assembly, EDX was the counter, EDI was the input buffer, and EBX was the output buffer. From the instruction at 0fb76a96, (EDX+EBX) = (0000000c+02f18f04) = 02f18f10. And 02f18f10 happened to be the address for m_ReadStream. So somehow during the encryption, the output buffer had been written out of its boundary.&lt;br /&gt;&lt;br /&gt;With those information, I traced the code again and found during the AES CBC mode encryption, the output ciphertext sometimes could be longer than the input plaintext. However, the code assumed that the input plaintext and output ciphertext would always have the same length. So when the ciphertext was longer than the input plaintext, the output buffer would be written out of its boundary.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-5112485841624923385?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/5112485841624923385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/10/heap-corruption-in-managed-code.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/5112485841624923385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/5112485841624923385'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/10/heap-corruption-in-managed-code.html' title='Heap corruption in managed code'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-4491974192900847944</id><published>2009-10-16T09:43:00.006-04:00</published><updated>2009-10-16T10:27:07.911-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG tips'/><title type='text'>Debug a child process</title><content type='html'>Sometimes the debugee is a child process, which could only be launched by its parent process.&lt;br /&gt;&lt;br /&gt;The following two cases need to be considered.&lt;br /&gt;First, the parent process could be launched directly, such as the command prompt. In that case, windbg -o processname could be used to debug its all child process. For instance, &lt;a href="http://www.bytetalk.net/2009/03/why-did-dllregisterserver-return.html"&gt;Why did DllRegisterServer return 80070006?&lt;/a&gt; provides an example on how to debug a specific child process launched by the command prompt.&lt;br /&gt;&lt;br /&gt;Second, the parent process could not be launched directly, such as services. In that case, the windbg meta-command .childdbg (Debug Child Processes) could be used.&lt;br /&gt;&lt;br /&gt;For instance, to debug aspnet_wp.exe -- an IIS worker process from its startup, the following steps could be used.&lt;br /&gt;1. iisreset&lt;br /&gt;It will kill the aspnet_wp.exe.&lt;br /&gt;2. attach windbg to inetinfo.exe&lt;br /&gt;3. .childdbg 1&lt;br /&gt;It will enable child process debugging in the windbg.&lt;br /&gt;4. send an asp .net request to IIS&lt;br /&gt;IIS will launch aspnet_wp.exe when the first asp .net request comes in.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-4491974192900847944?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/4491974192900847944/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/10/debug-child-process.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/4491974192900847944'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/4491974192900847944'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/10/debug-child-process.html' title='Debug a child process'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-1191640512684063363</id><published>2009-10-08T14:02:00.003-04:00</published><updated>2009-11-05T13:31:26.834-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio'/><title type='text'>Pseudo-registers for Visual Studio IDE</title><content type='html'>The post by Gregg -- &lt;a href="http://blogs.msdn.com/greggm/archive/2004/12/11/279978.aspx"&gt;Whidbey Debugger pseudo-register - $user&lt;/a&gt; introduces a new pseudo-register -- $user. The pseudo-register provides "loads of information about the debuggee user" and is helpful when it comes to debugging security related issues. Besides, '@err,hr' will print the last win32 error formatted as an error message. It is also very handy.&lt;br /&gt;&lt;br /&gt;The post by Kenny Kerr -- &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd252945.aspx"&gt;X64 Debugging With Pseudo Variables And Format Specifiers&lt;/a&gt; provides a more comprehensive list of pseudo-registers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-1191640512684063363?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/1191640512684063363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/10/pseudo-registers-for-visual-studio-ide.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1191640512684063363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1191640512684063363'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/10/pseudo-registers-for-visual-studio-ide.html' title='Pseudo-registers for Visual Studio IDE'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-4590422700348006888</id><published>2009-09-30T10:42:00.009-04:00</published><updated>2009-09-30T23:27:01.047-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>WCF Service application hangs</title><content type='html'>Ad Hoc Transfer (AHT) is a WCF ASP .NET application. When performing multiple downloads -- about 10 files from the FireFox, sometimes a transfer would pause ~30 seconds or more before download begins or in the middle of the download.&lt;br /&gt;&lt;br /&gt;There could be various reasons for a WCF service application to hang.&lt;br /&gt;&lt;br /&gt;From the size of memory dump, there was nothing out of ordinary, so the hang might not be related to the memory issue.&lt;br /&gt;&lt;br /&gt;One possible reason could be WCF connection pool exhausion described in the post -- &lt;a href="http://www.infosysblogs.com/microsoft/2009/06/troubleshooting_wcf_service_ap.html"&gt;Troubleshooting WCF Service application hangs&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:033&gt; !dumpheap -type ServiceThrottle -short&lt;br /&gt;02ebe87c&lt;br /&gt;02f2b6e0&lt;br /&gt;02f2d4ac &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:033&gt; !do 02ebe87c&lt;br /&gt;Name: System.ServiceModel.Dispatcher.ServiceThrottle&lt;br /&gt;MethodTable: 0f1ea548&lt;br /&gt;EEClass: 0ee51f20&lt;br /&gt;Size: 36(0x24) bytes&lt;br /&gt;(C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;0f1ea58c  400371d        4 ...cher.FlowThrottle  0 instance 02ebe93c calls &lt;span style="color: rgb(255, 0, 0);"&gt;; maxConcurrentCalls&lt;/span&gt;&lt;br /&gt;0f1ea58c  400371e        8 ...cher.FlowThrottle  0 instance 02ebea34 sessions &lt;span style="color: rgb(255, 0, 0);"&gt;; maxConcurrentSessions&lt;/span&gt;&lt;br /&gt;0f1a6020  400371f        c ...her.QuotaThrottle  0 instance 00000000 dynamic&lt;br /&gt;0f1ea58c  4003720       10 ...cher.FlowThrottle  0 instance 00000000 instanceContexts&lt;br /&gt;0f1e9bb0  4003721       14 ...l.ServiceHostBase  0 instance 02ebe674 host&lt;br /&gt;793044cc  4003722       1c       System.Boolean  1 instance        1 isActive&lt;br /&gt;7933061c  4003723       18        System.Object  0 instance 02ebe8a0 thisLock&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:033&gt; !do 02ebea34&lt;br /&gt;Name: System.ServiceModel.Dispatcher.FlowThrottle&lt;br /&gt;MethodTable: 0f1ea58c&lt;br /&gt;EEClass: 0ee51f8c&lt;br /&gt;Size: 36(0x24) bytes&lt;br /&gt;(C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;79332c4c  40034f5       18         System.Int32  1 instance       &lt;span style="color: rgb(255, 0, 0);"&gt;10 capacity&lt;/span&gt;&lt;br /&gt;79332c4c  40034f6       1c         System.Int32  1 instance        &lt;span style="color: rgb(255, 0, 0);"&gt;8 count&lt;/span&gt;&lt;br /&gt;7933061c  40034f7        4        System.Object  0 instance 02ebea58 mutex&lt;br /&gt;7931e960  40034f8        8 ...ding.WaitCallback  0 instance 02ebea14 release&lt;br /&gt;00000000  40034f9        c                       0 instance 02ebea64 waiters&lt;br /&gt;79330a00  40034fa       10        System.String  0 instance 02ebe99c propertyName&lt;br /&gt;79330a00  40034fb       14        System.String  0 instance 02ebe9d8 configName&lt;br /&gt;&lt;br /&gt;0:033&gt; !do 02ebe674&lt;br /&gt;Name: System.ServiceModel.ServiceHost&lt;br /&gt;MethodTable: 0f1ef2b4&lt;br /&gt;EEClass: 0ee55db4&lt;br /&gt;Size: 140(0x8c) bytes&lt;br /&gt;(C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)&lt;br /&gt;Fields:&lt;br /&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;br /&gt;...&lt;br /&gt;System.Object  0 instance 00000000 singletonInstance 79331840  40032cd       7c          System.Type  0 instance &lt;span style="color: rgb(255, 0, 0);"&gt;02ebe660 serviceType&lt;/span&gt;&lt;br /&gt;0f1ea7dc  40032ce       80 ...ontractCollection  0 instance 02ebed1c reflectedContracts&lt;br /&gt;7932c8e0  40032cf       84   System.IDisposable  0 instance 00000000 disposableInstance&lt;br /&gt;&lt;br /&gt;0:033&gt; !do 02ebe660&lt;br /&gt;Name: System.RuntimeType&lt;br /&gt;MethodTable: 79331b80&lt;br /&gt;EEClass: 790eddd8&lt;br /&gt;Size: 20(0x14) bytes&lt;br /&gt;Type MethodTable: 10fe7104&lt;br /&gt;Type Name: &lt;span style="color: rgb(255, 0, 0);"&gt;WSFTPWebService.WSFTPWebService&lt;/span&gt;&lt;br /&gt;(C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)&lt;br /&gt;Fields:&lt;br /&gt;...&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Since the capacity is still larger than the count, so WCF connection pool exhaustion should not be the reason.&lt;br /&gt;&lt;br /&gt;Since the hang only happens in multiple downloads, another possible reason could be the thread synchronization issue. From the code, it seems that in multiple downloads, the same WCF proxy is used for all the download requests among different threads. The MSDN site does not mention that the ClientBase class is thread-safe. However, in the code, the thread-safe assumption has been made and no calls to WCF proxy API have been synchronized among threads. So the possible fix would be to synchronize the call to WCF proxy API.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-4590422700348006888?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/4590422700348006888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/wcf-service-application-hangs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/4590422700348006888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/4590422700348006888'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/wcf-service-application-hangs.html' title='WCF Service application hangs'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-2846287137363539755</id><published>2009-09-25T11:25:00.006-04:00</published><updated>2009-09-25T20:40:03.702-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Assembly'/><title type='text'>Counterfactual Debugging: Data Ordering</title><content type='html'>The post -- &lt;a href="http://www.dumpanalysis.org/blog/index.php/2009/09/15/counterfactual-debugging-data-ordering/"&gt;Counterfactual Debugging: Data Ordering&lt;/a&gt; by Dmitry Vostokov provides an interesting exercise on how to understand &lt;a href="http://www.dumpanalysis.org/blog/index.php/2009/09/11/counterfactual-debugging-dereference-fixpoints/"&gt;Dereference Fixpoints&lt;/a&gt; issue from the assembly code level.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-2846287137363539755?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/2846287137363539755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/counterfactual-debugging-data-ordering.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/2846287137363539755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/2846287137363539755'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/counterfactual-debugging-data-ordering.html' title='Counterfactual Debugging: Data Ordering'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-7120284321291417738</id><published>2009-09-24T12:30:00.004-04:00</published><updated>2009-09-24T12:40:29.924-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG'/><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>Mixed DLL Loading Problem</title><content type='html'>The post -- &lt;a href="http://blogs.msdn.com/tess/archive/2007/03/12/net-hang-case-study-the-gc-loader-lock-deadlock-a-story-of-mixed-mode-dlls.aspx"&gt;NET Hang Case Study: The GC-Loader Lock Deadlock (a story of mixed mode dlls)&lt;/a&gt; by Tess Ferrandez provides a good study case for &lt;a href="http://msdn.microsoft.com/en-us/library/aa290048%28VS.71%29.aspx"&gt;mixed dll loading problem&lt;/a&gt;. Besides, it also shows some useful WinDBG tips, such as how to detect the deadlock caused by the mixed dll, how to tell whether GC has been triggered and which thread triggered it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-7120284321291417738?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/7120284321291417738/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/post-net-hang-case-study-gc-loader-lock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7120284321291417738'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/7120284321291417738'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/post-net-hang-case-study-gc-loader-lock.html' title='Mixed DLL Loading Problem'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-3676231574011848557</id><published>2009-09-21T12:46:00.004-04:00</published><updated>2009-09-24T12:30:11.200-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ETW'/><title type='text'>ETW Introduction and Overview</title><content type='html'>With the advent of Vista and Windows 7, ETW (Event Tracing for Windows) would become more and more widely used in debugging and instrumenting the applications. The following links provide some useful information regarding to what ETW is and how to enable ETW for troubleshooting,&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/ntdebugging/archive/2009/08/27/etw-introduction-and-overview.aspx"&gt;ETW Introduction and Overview&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blogs.msdn.com/ntdebugging/archive/2009/09/08/exploring-and-decoding-etw-providers-using-event-log-channels.aspx"&gt;Exploring and Decoding ETW Providers using Event Log Channels&lt;/a&gt;.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-3676231574011848557?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/3676231574011848557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/etw-introduction-and-overview.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3676231574011848557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3676231574011848557'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/etw-introduction-and-overview.html' title='ETW Introduction and Overview'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-3533020138190579454</id><published>2009-09-17T14:10:00.008-04:00</published><updated>2009-09-18T17:30:36.223-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Enable WCF debugging trace and message logs</title><content type='html'>WCF debugging trace and message logs are sometimes very crucial in resolving WCF related issues. To enable the trace and message logs, the application configuration would be modified as following,&lt;br /&gt;&lt;ol&gt;&lt;li&gt;within [system.serviceModel] and [/system.serviceModel] tags,  add [diagnostics]          [messageLogging maxMessagesToLog="30000"&lt;br /&gt;                     logEntireMessage="true"&lt;br /&gt;                     logMessagesAtServiceLevel="true"&lt;br /&gt;                     logMalformedMessages="true"&lt;br /&gt;                     logMessagesAtTransportLevel="true"]        &lt;br /&gt;     [/messageLogging]&lt;br /&gt; [/diagnostics]&lt;/li&gt;&lt;li&gt;within [configuration] and [/configuration] tags, add [system.diagnostics]&lt;br /&gt;   [sources]&lt;br /&gt;       [source name="System.ServiceModel" switchValue="Verbose, ActivityTracing" propagateActivity="true" ]&lt;br /&gt;           [listeners]&lt;br /&gt;               [add name="xml" /]&lt;br /&gt;           [/listeners]&lt;br /&gt;       [/source]&lt;br /&gt;       [source name="System.ServiceModel.MessageLogging" switchValue="Verbose"]&lt;br /&gt;           [listeners]&lt;br /&gt;               [add name="xml" /]&lt;br /&gt;           [/listeners]&lt;br /&gt;       [/source]&lt;br /&gt;   [/sources]&lt;br /&gt;   [sharedListeners]&lt;br /&gt;       [add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="WCFTracing.svclog" /]&lt;br /&gt;   [/sharedListeners]&lt;br /&gt;   [trace autoflush="true" /]&lt;br /&gt;[/system.diagnostics]&lt;/li&gt;&lt;/ol&gt;After modifying the configuration file, make sure the process hosting the WCF proxy or service has the write permission to the folder where the trace and message log file will reside.&lt;br /&gt;&lt;br /&gt;After the trace and message log file is generated, the &lt;a href="http://msdn.microsoft.com/en-us/library/ms732023.aspx"&gt;Service Trace Viewer&lt;/a&gt; could be used to analyze the trace and log file.&lt;br /&gt;&lt;br /&gt;Here is a &lt;a href="http://msdn.microsoft.com/en-us/library/aa751795.aspx"&gt;tutorial&lt;/a&gt; on how to use the Service Trace Viewer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-3533020138190579454?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/3533020138190579454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/enable-wcf-debugging-trace-and-message.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3533020138190579454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3533020138190579454'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/enable-wcf-debugging-trace-and-message.html' title='Enable WCF debugging trace and message logs'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-8362092013686947090</id><published>2009-09-01T11:03:00.003-04:00</published><updated>2009-09-01T11:19:54.365-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>Function keys for a command-prompt ninja</title><content type='html'>The following function keys might improve the usability of the command prompt.&lt;br /&gt;&lt;br /&gt;F1 retypes the previous command one character at a time&lt;br /&gt;F2 brings up a dialog and asks “Enter the char to copy up to:”&lt;br /&gt;F3 retypes the last command in full&lt;br /&gt;F4 brings up a dialog and asks “Enter char to delete up to:”&lt;br /&gt;F5 as for F3&lt;br /&gt;F6 Print EOF character (Ctrl+Z)&lt;br /&gt;F7 brings up a dialog of all the recent command history&lt;br /&gt;F8 brings up each of the most recent commands, one at a time&lt;br /&gt;F9 brings up a dialog and asks “Enter command number:”&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-8362092013686947090?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/8362092013686947090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/09/tricks-for-command-prompt-ninja.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8362092013686947090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8362092013686947090'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/09/tricks-for-command-prompt-ninja.html' title='Function keys for a command-prompt ninja'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-9087546589301489527</id><published>2009-07-31T16:43:00.016-04:00</published><updated>2009-08-01T09:40:46.678-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>WCF web service failed with 0x8007007E</title><content type='html'>&lt;div style="text-align: left;"&gt;The WCF web service I worked on failed with the following error message when I tried to launch it from IIS:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;&lt;span&gt;The specified module could not be found. (Exception from HRESULT: 0x8007007E).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;From the previous encounter, I was pretty sure that it must have something to do with WrapperUtilAPI.dll. The library written in managed C++ serves as the bridge between the managed and unmanaged code.&lt;br /&gt;&lt;br /&gt;Since the web service is in the managed code, I first tried the &lt;a href="http://msdn.microsoft.com/en-us/library/e74a18c4%28VS.80%29.aspx"&gt;Fusion log viewer&lt;/a&gt; to see whether there had been any assembly binding error. Except that the web service module itself did not show in the log viewer, there had been no assembly binding error for all other dependent modules, such as WrapperUtilAPI.dll:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic;"&gt;The operation was successful.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Bind result: hr = 0x0. The operation completed successfully.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It seemed that the culprit was from the unmanaged code. Then I used &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx"&gt;Process Monitor&lt;/a&gt; to record the activities from aspnet_wp.exe when I tried to launch the web service through it.&lt;br /&gt;&lt;br /&gt;For a DLL to load successfully, the following operation sequence should take place,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;QueryOpen    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wsftp.webservicehost\89b3cfc4\ab5fbeff\assembly\dl3\f9b47a83\007d695c_3011ca01\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\site\bin\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\bin\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\wbem\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Microsoft SQL Server\90\Tools\Binn\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Ipswitch\Common\ftpaccess.dll    SUCCESS&lt;br /&gt;QueryOpen    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wsftp.webservicehost\89b3cfc4\ab5fbeff\assembly\dl3\f9b47a83\007d695c_3011ca01\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\site\bin\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\bin\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\wbem\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Microsoft SQL Server\90\Tools\Binn\ftpaccess.dll    NAME NOT FOUND&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;QueryOpen&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;    &lt;/span&gt;C:\Program Files\Ipswitch\Common\ftpaccess.dll&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   SUCCESS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;CreateFile    &lt;/span&gt;C:\Program Files\Ipswitch\Common\ftpaccess.dll&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   SUCCESS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;CloseFile    &lt;/span&gt;C:\Program Files\Ipswitch\Common\ftpaccess.dll&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   SUCCESS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;Load Image&lt;/span&gt;    C:\Program Files\Ipswitch\Common\ftpaccess.dll&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   SUCCESS&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;QueryOpen will try to locate a module using the DLL search path.&lt;br /&gt;&lt;br /&gt;While looking through the log from Process Monitor, I noticed the following lines,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;QueryOpen    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wsftp.webservicehost\89b3cfc4\ab5fbeff\assembly\dl3\f9b47a83\007d695c_3011ca01\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\site\bin\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Perl\bin\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\wbem\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Microsoft SQL Server\90\Tools\Binn\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Ipswitch\Common\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Support Tools\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\Ipswitch\Common\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\MinGW\bin\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\Program Files\QuickTime\QTSystem\zlib1.dll    NAME NOT FOUND&lt;br /&gt;QueryOpen    C:\WINDOWS\system32\windowspowershell\v1.0\zlib1.dll    NAME NOT FOUND&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;QueryOpen    &lt;/span&gt;C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;zlib1.dll&lt;/span&gt;    &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;NAME NOT FOUND&lt;/span&gt;&lt;br /&gt;CloseFile    C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e    SUCCESS&lt;br /&gt;CloseFile    C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e    SUCCESS&lt;br /&gt;CloseFile    C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e    SUCCESS&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;CloseFile    &lt;/span&gt;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\wsftp.webservicehost\89b3cfc4\ab5fbeff\assembly\dl3\f9b47a83\007d695c_3011ca01\&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;WrapperUtilAPI.DLL&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;   SUCCESS&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;It seemed that the application tried to load zlib1.dll. However, the module could not be found in the DLL search path. Therefore, instead of loading zlib1.dll, the application closed WrapperUtilAPI.dll, which had been loaded early.&lt;br /&gt;&lt;br /&gt;Since I was pretty sure that zlib1.dll had to be loaded so that WrapperUtilAPI.dll could be loaded successfully, and its location was not in the PATH environment variable and the DLL search path. So at the point, the root cause seemed to be the failure to load zlib1.dll. Then I copied it to the location on the DLL search path, the web service could be launched from IIS.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-9087546589301489527?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/9087546589301489527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/07/wcf-webservice-failed-with-0x8007007e.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/9087546589301489527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/9087546589301489527'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/07/wcf-webservice-failed-with-0x8007007e.html' title='WCF web service failed with 0x8007007E'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-3412624677867541747</id><published>2009-07-29T19:41:00.006-04:00</published><updated>2009-08-01T09:50:56.205-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>How to Bind to a custom App.Config file?</title><content type='html'>One of questions I ever had when I worked on the ISAPI extension was where to store the configuration file. The ISAPI extension is in unmanaged code hosted in IIS via dllhost.exe. It will interact with the backend managed code by COM interop. The manged code will create WCF proxies to communicate to the WCF web service. Therefore, the configuration file will be required by the WCF code to load the information regarding to the contract, binding, endpoint, and client behavior. A naive solution is to use dllhost.exe.config in the Windows system directory. Fortunately, the article by Ohad -- &lt;a href="http://weblogs.asp.net/israelio/archive/2005/01/10/349825.aspx"&gt;Binding to a custom App.Config file&lt;/a&gt; provides a useful information to solve the problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-3412624677867541747?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/3412624677867541747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/07/how-to-bind-to-custom-appconfig-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3412624677867541747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/3412624677867541747'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/07/how-to-bind-to-custom-appconfig-file.html' title='How to Bind to a custom App.Config file?'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-6748832013887858440</id><published>2009-07-22T17:39:00.004-04:00</published><updated>2009-07-22T19:02:27.687-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>Build and debug ISAPI extension</title><content type='html'>I have built and debugged an &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;ISAPI&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;DLL&lt;/span&gt; before. However, it still gave me a little bit hard time today when I tried to debug an &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;ISAPI&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;DLL&lt;/span&gt; which I built by myself. The article by &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;Mehdi&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;Mousav&lt;/span&gt; -- &lt;a href="http://www.codeproject.com/KB/ISAPI/isapi_extensions.aspx"&gt;What is an &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;ISAPI&lt;/span&gt; Extension?&lt;/a&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;provies&lt;/span&gt; a pretty good coverage on this topic. The setup of &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;ISAP&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;DLL&lt;/span&gt; in &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;IIS&lt;/span&gt; is straightforward -- copy the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;DLL&lt;/span&gt; to the folder which can be accessed from the URL, such as http://Domain/DLLPath. For the author of the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;ISAPI&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;DLL&lt;/span&gt;, one caveat is the module definition file (.def). The &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;ISAPI&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;DLL&lt;/span&gt; needs to be built with it; otherwise, the &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;ISAPI&lt;/span&gt; extension &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_17"&gt;APIs&lt;/span&gt; will not be visible to an &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_18"&gt;IIS&lt;/span&gt; worker process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-6748832013887858440?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/6748832013887858440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/07/build-and-debug-isapi-extension.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6748832013887858440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6748832013887858440'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/07/build-and-debug-isapi-extension.html' title='Build and debug ISAPI extension'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-76840946387700107</id><published>2009-07-07T16:27:00.004-04:00</published><updated>2009-07-07T16:35:10.401-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='64-bit'/><title type='text'>Obtain stack limit of WOW64 process</title><content type='html'>A WOW64 process is a 32-bit process running on x64 Windows. The article -- &lt;a href="http://www.dumpanalysis.org/blog/index.php/2009/07/07/raw-stack-dump-of-wow64-process/"&gt;Raw Stack Dump of WOW64 Process&lt;/a&gt; by Dmitry Vostokov explains several ways to retrieve the stack limit of a thread from TEB for a WOW64 process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-76840946387700107?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/76840946387700107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/07/obtain-stack-limit-of-wow64-process.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/76840946387700107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/76840946387700107'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/07/obtain-stack-limit-of-wow64-process.html' title='Obtain stack limit of WOW64 process'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-2604277246415058247</id><published>2009-07-07T00:21:00.003-04:00</published><updated>2009-07-07T00:28:09.113-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Assembly'/><title type='text'>Hunt for parameters of a function</title><content type='html'>The article -- &lt;a href="http://www.dumpanalysis.org/blog/index.php/2009/07/06/hunting-for-a-driver/"&gt;Hunting for a Driver&lt;/a&gt; by Dmitry Vostokov illustrates a useful approach to discover the parameters of a function.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-2604277246415058247?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/2604277246415058247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/07/discover-parameters-of-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/2604277246415058247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/2604277246415058247'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/07/discover-parameters-of-function.html' title='Hunt for parameters of a function'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-6035393617820796789</id><published>2009-06-03T10:15:00.003-04:00</published><updated>2009-06-03T10:27:10.629-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MSIL'/><title type='text'>MSIL tutorials</title><content type='html'>The following is some useful links to MSIL tutorials.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://weblogs.asp.net/kennykerr/archive/tags/Introduction+to+MSIL/default.aspx"&gt;Introduction to MSIL&lt;/a&gt; by Kenny Kerr&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc301368.aspx"&gt;ILDASM is Your New Best Friend&lt;/a&gt; by John Robbins&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeguru.com/csharp/.net/net_general/il/article.php/c4635"&gt;MSIL Tutorial&lt;/a&gt; by Alex F&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-6035393617820796789?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/6035393617820796789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/06/msil-tutorials.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6035393617820796789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/6035393617820796789'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/06/msil-tutorials.html' title='MSIL tutorials'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-8826973219361021603</id><published>2009-05-15T16:04:00.017-04:00</published><updated>2009-05-16T13:19:39.273-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Assembly'/><title type='text'>Calling conventions</title><content type='html'>The calling convention of a function answers the following questions,&lt;br /&gt;&lt;ul&gt;&lt;li&gt;How parameters are passed into a function&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Who cleans up the stack on function return&lt;/li&gt;&lt;/ul&gt;The following lists common x86 function calling conventions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Win32 (Stdcall)&lt;/span&gt;: The parameters are pushed onto the stack from right to left. The called function cleans up the stack.&lt;br /&gt;&lt;br /&gt;01003540 push    esi&lt;br /&gt;01003541 lea     eax,[ebp-62Ch]&lt;br /&gt;01003547 push    eax&lt;br /&gt;01003548 call    module!func (01001058)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Native C++ (Thiscall)&lt;/span&gt;: "this" pointer is passed via ECX; the rest of parameters are pushed onto the stack from right to left. The called function cleans up the stack.&lt;br /&gt;&lt;br /&gt;00413586   mov     eax,dword ptr [ebp+0Ch]&lt;br /&gt;00413589   push    eax&lt;br /&gt;0041358a   mov     ecx,dword ptr [ebp+8]&lt;br /&gt;0041358d   push    ecx&lt;br /&gt;0041358e   mov     ecx,dword ptr [ebp-14h] &lt;span style="font-style: italic;"&gt;; store "this" to ECX&lt;/span&gt;&lt;br /&gt;00413591   call    module!func (00411505)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;COM (Stdcall for C++)&lt;/span&gt;: The parameters are pushed onto the stack from right to left, include "this" pointer, i.e. "this" pointer is pushed onto the stack as the first parameter. The called function cleans up the stack.&lt;br /&gt;&lt;br /&gt;01002ffe    mov    ecx,dword ptr [eax] &lt;span style="font-style: italic;"&gt;; ecx="this"-&gt;lpvtbl&lt;/span&gt;&lt;br /&gt;01003000 push   ebx&lt;br /&gt;01003001 push   offset 01002c7c&lt;br /&gt;01003006 push   eax &lt;span style="font-style: italic;"&gt;; "this" as 1st parameter&lt;/span&gt;&lt;br /&gt;01003007 call      dword ptr [ecx] &lt;span style="font-style: italic;"&gt;; [ecx]=QueryInterface, [ecx+4]=AddRef, [ecx+8]=Release&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Fastcall&lt;/span&gt;: First two parameters are passed in via ECX and EDX; the rest are pushed onto the stack from right to left. The called function cleans up the stack.&lt;br /&gt;&lt;br /&gt;0100248e mov     edx,eax &lt;span style="font-style: italic;"&gt;; 2nd parameter&lt;/span&gt;&lt;br /&gt;01002490 mov    ecx,edi  &lt;span style="font-style: italic;"&gt;; 1st parameter&lt;/span&gt;&lt;br /&gt;01002492 call      module!func (01002445)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Cdecl&lt;/span&gt;: The parameters are pushed onto the stack from right to left. The calling function cleans up the stack.&lt;br /&gt;&lt;br /&gt;01002490 push    eax&lt;br /&gt;01002491 push    offset 0100118c&lt;br /&gt;01002496 call    module!func (010026c5)&lt;br /&gt;0100249b pop     ecx &lt;span style="font-style: italic;"&gt;; pop 1st parameter&lt;/span&gt;&lt;br /&gt;0100249c pop     ecx &lt;span style="font-style: italic;"&gt;; pop 2nd parameter&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;.NET Framework&lt;/span&gt;: The .NET Framework uses the fastcall calling convention. The first two paramters are passed via ECX and EDX. For an instance method, "this" pointer is passed via ECX as the first paramter.&lt;br /&gt;&lt;br /&gt;There are three methods to dispatch a method call.&lt;br /&gt;&lt;br /&gt;Interface-based dispatch:&lt;br /&gt;mov    ecx,edi  &lt;span style="font-style: italic;"&gt;; move "this" pointer into ecx      &lt;/span&gt;&lt;br /&gt;mov    eax,dword ptr [ecx]   &lt;span style="font-style: italic;"&gt;; move "TypeHandle" into eax&lt;/span&gt;&lt;br /&gt;mov    eax,dword ptr [eax+0Ch]  &lt;span style="font-style: italic;"&gt;; move IVMap into eax at offset 12&lt;/span&gt;&lt;br /&gt;mov    eax,dword ptr [eax+30h]  &lt;span style="font-style: italic;"&gt;; move the ifc impl start slot into eax&lt;/span&gt;&lt;br /&gt;call      dword ptr [eax]  &lt;span style="font-style: italic;"&gt;; call method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Direct dispatch:&lt;br /&gt;mov    ecx,esi    &lt;span style="font-style: italic;"&gt;; move "this" pointer into ecx&lt;/span&gt;&lt;br /&gt;cmp    dword ptr [ecx],ecx &lt;span style="font-style: italic;"&gt;  ; compare and set flags&lt;/span&gt;&lt;br /&gt;call     dword ptr ds:[009552D8h] &lt;span style="font-style: italic;"&gt;; directly call method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Virtual dispatch:&lt;br /&gt;mov    ecx,esi &lt;span style="font-style: italic;"&gt;  ; move "this" pointer into ecx&lt;/span&gt;&lt;br /&gt;mov    eax,dword ptr [ecx]   &lt;span style="font-style: italic;"&gt;; acquire the MethodTable address&lt;/span&gt;&lt;br /&gt;call      dword ptr [eax+44h]   &lt;span style="font-style: italic;"&gt;; dispatch to the method at offset 0x44&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;(Excerpted from &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx"&gt;Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects&lt;/a&gt;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-8826973219361021603?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/8826973219361021603/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/05/annotated-0x86-assembly-method-call.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8826973219361021603'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/8826973219361021603'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/05/annotated-0x86-assembly-method-call.html' title='Calling conventions'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-1477828403983107859</id><published>2009-05-09T14:03:00.010-04:00</published><updated>2009-05-12T16:26:45.948-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WinDBG'/><title type='text'>Debug a service application from startup</title><content type='html'>The article -- &lt;a href="http://msdn.microsoft.com/en-us/library/cc267835.aspx"&gt;Debugging a Service Application&lt;/a&gt; provides pretty detailed information on debugging a service application. However, besides  adding a &lt;span style="font-style: italic;"&gt;ProgramName&lt;/span&gt; registry key under &lt;span style="font-style: italic;"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options&lt;/span&gt;, where &lt;span style="font-style: italic;"&gt;ProgramName&lt;/span&gt; is the name of the service application's executable file,  and adjusting the service application timeout by adding or modifying a DWORD value called &lt;span style="font-style: italic;"&gt;ServicesPipeTimeout&lt;/span&gt; under &lt;span style="font-style: italic;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control&lt;/span&gt;, in my recent experience, I have found that the following two items should be aware of as well.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;For WinDBG GUI to pop up, &lt;span style="font-style: italic;"&gt;Allow service to interact with desktop&lt;/span&gt; option should be enabled for the service application.&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_KNndr5Wl6Fw/SgX-YlxiPNI/AAAAAAAAADQ/Ci5NLYkE464/s1600-h/option.bmp"&gt;&lt;img style="cursor: pointer; width: 354px; height: 400px;" src="http://4.bp.blogspot.com/_KNndr5Wl6Fw/SgX-YlxiPNI/AAAAAAAAADQ/Ci5NLYkE464/s400/option.bmp" alt="" id="BLOGGER_PHOTO_ID_5333949032100412626" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServicesPipeTimeout&lt;/span&gt; could affect the Windows startup time. For instance, when I changed its value to 86,400,000 (24 hours), it took my XP box about one day to fully start up! When I changed its value to 600,000 (10 minutes), it took my XP box about 10 minutes to fully start up.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-1477828403983107859?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/1477828403983107859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/05/debug-service-application-from-startup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1477828403983107859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1477828403983107859'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/05/debug-service-application-from-startup.html' title='Debug a service application from startup'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_KNndr5Wl6Fw/SgX-YlxiPNI/AAAAAAAAADQ/Ci5NLYkE464/s72-c/option.bmp' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-1417983765679608406</id><published>2009-05-06T13:13:00.004-04:00</published><updated>2009-05-06T14:11:12.414-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Static data members in inheritance</title><content type='html'>A static data member means that one copy of data would be shared among all instances of the same class. It is true even when inheritance is involved.&lt;br /&gt;&lt;br /&gt;class base&lt;br /&gt;{&lt;br /&gt;public: static wchar_t * s_pName;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;wchar_t * base::s_pName = L"base";&lt;br /&gt;&lt;br /&gt;class derived1 : public base { };&lt;br /&gt;&lt;br /&gt;class derived2 : public base { };&lt;br /&gt;&lt;br /&gt;int _tmain(int argc, _TCHAR* argv[])&lt;br /&gt;{&lt;br /&gt; derived1 d1;&lt;br /&gt;d1.s_pName = L"derived1";&lt;br /&gt;&lt;br /&gt; derived2 d2;&lt;br /&gt;d2.s_pName = L"derived2";&lt;br /&gt;&lt;br /&gt; wprintf(L"%s\n", d1.s_pName);&lt;br /&gt; wprintf(L"%s\n", d2.s_pName);&lt;br /&gt;&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Since s_pName is a static data member in the base class, all the instances of the derived classes share one copy of the data member. Therefore, the output of the above program would be as following,&lt;br /&gt;&lt;br /&gt;derived2&lt;br /&gt;derived2.&lt;br /&gt;&lt;br /&gt;Obviously, it is not a desirable output for the instances of derived1 class. To overcome this limitation, we could use a so-called "mixin-style" base class. I replace the angle brackets for a template with square brackets.&lt;br /&gt;&lt;br /&gt;template[class T]&lt;br /&gt;class base&lt;br /&gt;{&lt;br /&gt;public: static wchar_t * s_pName;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;template[class T] wchar_t * base[T]::s_pName = L"base";&lt;br /&gt;&lt;br /&gt;class derived1 : public base[derived1] { };&lt;br /&gt;&lt;br /&gt;class derived2 : public base[derived2] { };&lt;br /&gt;&lt;br /&gt;int _tmain(int argc, _TCHAR* argv[])&lt;br /&gt;{&lt;br /&gt; derived1 d1;&lt;br /&gt; d1.s_pName = L"derived1";&lt;br /&gt;&lt;br /&gt; derived2 d2;&lt;br /&gt; d2.s_pName = L"derived2";&lt;br /&gt;&lt;br /&gt; wprintf(L"%s\n", d1.s_pName);&lt;br /&gt; wprintf(L"%s\n", d2.s_pName);&lt;br /&gt;&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The base class is turned into a template. The template part of the base class ensures that each derived class gets a different s_pName. The output from the above program would be as following,&lt;br /&gt;&lt;br /&gt;derived1&lt;br /&gt;derived2.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-1417983765679608406?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/1417983765679608406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/05/static-data-members-in-inheritance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1417983765679608406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/1417983765679608406'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/05/static-data-members-in-inheritance.html' title='Static data members in inheritance'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1812985003737084262.post-990670301669946747</id><published>2009-05-06T10:29:00.008-04:00</published><updated>2009-05-06T19:32:46.859-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Miscellanous'/><title type='text'>Why did PEM_read_bio_PrivateKey fail to load a key in FIPS mode?</title><content type='html'>My former manager told me that PEM_read_bio_PrivateKey failed to load a private key generated via OpenSSL commandline in FIPS mode. So I tried to load the key he sent to me using a simple test application.  When not in FIPS mode, PEM_read_bio_PrivateKey worked fine. However, when in FIPS mode, I got the error -- "error:0608008D:digital envelope routines:EVP_DigestInit:disabled for fips". The error was consistent to what he had told me. Then I asked him whether he used any non-FIPS algorithm during the key generation. The answer was no.&lt;br /&gt;&lt;br /&gt;Then I set a breakpoint at  PEM_read_bio_PrivateKey and stepped into the function. After several rounds of code tracing, I had the following stacktrace.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; kb&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;ChildEBP RetAddr  Args to Child       &lt;br /&gt;0012f0d8 0fb43d0c 0fbc9ab0 &lt;span style="color: rgb(255, 0, 0);"&gt;0fbbef38 &lt;/span&gt;0012f5ec LIBEAY32!EVP_BytesToKey+0x10&lt;br /&gt;0012f5cc 0fb43503 0012f5e8 0091ee40 0012f610 LIBEAY32!PEM_do_header+0xcc&lt;br /&gt;0012f614 0fb46281 0012fa50 0012fa58 0012fa4c LIBEAY32!PEM_bytes_read_bio+0xe3&lt;br /&gt;0012fa60 0041146d 0091c258 00000000 00000000 LIBEAY32!PEM_read_bio_PrivateKey+0x51&lt;br /&gt;0012ff68 00411b18 00000001 003d4c58 003d59d8 openssl_loadkey!wmain+0x7d&lt;br /&gt;0012ffb8 0041195f 0012fff0 7c817077 0115f6f2 openssl_loadkey!__tmainCRTStartup+0x1a8&lt;br /&gt;0012ffc0 7c817077 0115f6f2 0115f77e 7ffdf000 openssl_loadkey!wmainCRTStartup+0xf&lt;br /&gt;0012fff0 00000000 00411082 00000000 78746341 kernel32!BaseProcessStart+0x23&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;EVP_BytesToKey would return error. It caused PEM_read_bio_PrivateKey to fail to load the key. The second parameter of EVP_BytesToKey is a pointer to EVP_MD.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;0:000&gt; ln 0fbbef38&lt;br /&gt;(0fbbef38)   LIBEAY32!md5_md   |  (0fbbef80)   LIBEAY32!sha_md&lt;br /&gt;Exact matches:&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;LIBEAY32!md5_md&lt;/span&gt; = struct env_md_st&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For some reason, MD5 was passed into the function. Since MD5 is a non-FIPS algorithm, in FIPS mode, it would be disabled in OpenSSL library. Then the question was where MD5 came from. When looking at the OpenSSL source code, I found that when a key file contains a header, PEM_read_bio_PrivateKey would read the header and retrieve the encryption cipher, then it would try to generate the key using EVP_BytesToKey by passing MD5 as its second parameter. Since MD5 is hard-coded as the second parameter, any key file containing a header which specifies an encryption cipher would fail to be loaded in FIPS mode. It is definitely a defect in the OpenSSL code. Until the fix, the workaround is not to generate a key with a header containing an encryption cipher. The OpenSSL versions we used in testing are openssl-0.9.7m and openssl-0.9.8j.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1812985003737084262-990670301669946747?l=www.bytetalk.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.bytetalk.net/feeds/990670301669946747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.bytetalk.net/2009/05/why-did-pemreadbioprivatekey-fail-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/990670301669946747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1812985003737084262/posts/default/990670301669946747'/><link rel='alternate' type='text/html' href='http://www.bytetalk.net/2009/05/why-did-pemreadbioprivatekey-fail-to.html' title='Why did PEM_read_bio_PrivateKey fail to load a key in FIPS mode?'/><author><name>bxia</name><uri>http://www.blogger.com/profile/13262666423559414651</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09243653802358226527'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>