<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>MITHUN SHANBHAG's blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mithuns/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mithuns/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 05:19:43 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Links to exception-handling resources</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/links-to-exception-handling-resources</link>
      <pubDate>Wed, 09 Jan 2013 14:51:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2013/01/09/links-to-exception-handling-resources/</guid>
      <description><![CDATA[&nbsp;
In-depth Articles-

[Matt Pietrek]&nbsp;Internals of SEH.
[Matt Pietrek]&nbsp;Vectored...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p><strong>In-depth Articles-</strong></p>
<ul>
<li>[<a href="https://blogs.msdn.com/matt_pietrek/">Matt Pietrek</a>]&nbsp;<a href="https://www.microsoft.com/msj/0197/exception/exception.aspx">Internals of SEH.</a></li>
<li>[<a href="https://blogs.msdn.com/matt_pietrek/">Matt Pietrek</a>]&nbsp;<a href="https://msdn.microsoft.com/msdnmag/issues/01/09/hood/">Vectored Exception Handling.</a></li>
<li>[<a href="https://blogs.msdn.com/cbrumme/">Chris Brumme</a>]&nbsp;<a href="https://blogs.msdn.com/cbrumme/archive/2003/10/01/51524.aspx">Managed Exception Model</a>.</li>
<li>[<a href="https://www.jorgon.freeserve.co.uk/">Jeremy Gordon</a>]&nbsp;<a href="https://win32assembly.online.fr/Exceptionhandling.html">SEH for assembler programmers.</a></li>
<li>[Gaurav Khanna]&nbsp;<a href="https://blogs.msdn.com/b/dotnet/archive/2009/05/14/how-clr-maps-seh-exceptions-to-managed-exception-types.aspx">How CLR maps SEH exceptions to managed exception types.</a></li>
</ul>
<p><strong>Tips and Tricks-</strong></p>
<ul>
<li>[<a href="https://blogs.msdn.com/oldnewthing">Raymond Chen</a>]&nbsp;<a href="https://blogs.msdn.com/oldnewthing/archive/2006/08/21/710754.aspx">Sucking the exception pointers&nbsp;from a stack trace.</a></li>
<li>[<a href="https://blogs.msdn.com/jmstall">Mike Stall</a>]&nbsp;<a href="https://blogs.msdn.com/jmstall/archive/2005/01/18/355697.aspx">Finding where unmanaged exceptions come from.</a></li>
<li>[<a href="https://blogs.msdn.com/greggm">Gregg Miskelly</a>]&nbsp;<a href="https://blogs.msdn.com/greggm/archive/2004/08/25/220360.aspx">Debugging an UEF</a>.</li>
<li>[<a href="https://www.nynaeve.net/">Skywing</a>]&nbsp;<a href="https://www.nynaeve.net/?p=23">Debugging a custom UEF</a>.</li>
<li>[MSDN]&nbsp;<a title="Identifying original culprit stack when UEF is on stack" href="https://support.microsoft.com/kb/313109">Identifying original culprit stack when UEF is on stack</a>.</li>
<li>[<a title="Zhanli" href="https://blogs.msdn.com/b/zhanli/">Zhanli</a>]&nbsp;<a title="Adding vectored handlers and UEFs" href="https://blogs.msdn.com/b/zhanli/archive/2010/06/25/c-tips-addvectoredexceptionhandler-addvectoredcontinuehandler-and-setunhandledexceptionfilter.aspx">Adding vectored handlers and UEFs</a>.</li>
</ul>
<p><strong>Misc-</strong></p>
<ul>
<li>[<a href="https://blogs.msdn.com/cbrumme/">Chris Brumme</a>]&nbsp;<a href="https://blogs.msdn.com/cbrumme/archive/2003/04/15/51345.aspx">Unhandled Exceptions</a>.</li>
<li>[Gaurav Khanna]&nbsp;<a title="Unhandled exception processing in the CLR" href="https://msdn.microsoft.com/en-us/magazine/cc793966.aspx">Unhandled exception processing in the CLR</a>.</li>
<li>[<a href="https://www.nynaeve.net/">Skywing</a>]&nbsp;<a href="https://www.nynaeve.net/?p=43">Beware of Custom UEFs in DLLs</a>.</li>
<li>[<a href="https://www.nynaeve.net/">Skywing</a>]&nbsp;<a href="https://www.nynaeve.net/?p=44">You might be using UEFs without even knowing it</a>.</li>
<li>[Andrew Pardoe]&nbsp;<a href="https://msdn.microsoft.com/en-us/magazine/dd419661.aspx">Handling corrupted state exceptions</a></li>
<li>[Andrew Pardoe]&nbsp;<a href="https://blogs.msdn.com/b/dotnet/archive/2009/04/28/threadabortexception.aspx">ThreadAbortException</a></li>
<li>[Gaurav Khanna]&nbsp;<a href="https://blogs.msdn.com/b/dotnet/archive/2009/02/05/catch-rethrow-and-filters-why-you-should-care.aspx">Catch, Rethrow and filters - Why you should care</a></li>
<li>[Mike Magruder]&nbsp;<a href="https://blogs.msdn.com/b/dotnet/archive/2009/08/25/the-good-and-the-bad-of-exception-filters.aspx">The good and the bad of exception filters</a></li>
<li>[Andrew Pardoe]&nbsp;<a href="https://blogs.msdn.com/b/dotnet/archive/2009/02/19/why-catch-exception-empty-catch-is-bad.aspx">Why catch(Exception)/empty catch is bad</a></li>
</ul>
<p><strong>References-</strong></p>
<ul>
<li>[MSDN]&nbsp;<a href="https://msdn.microsoft.com/en-us/library/swezty51.aspx">SEH (C++ reference)</a></li>
<li>[<a href="https://msdn2.microsoft.com/">MSDN</a>]&nbsp;<a href="https://msdn2.microsoft.com/en-us/library/ms680657.aspx">SEH</a></li>
<li>[MSDN]&nbsp;<a title="Exception Handling (x64)" href="https://msdn.microsoft.com/en-us/library/1eyas8tf">Exception Handling (x64)</a></li>
<li>[MSDN]&nbsp;<a title="Managed Exceptions" href="https://msdn.microsoft.com/en-us/library/ms173160(v=vs.110)">Managed Exceptions</a></li>
<li>[MSDN]&nbsp;<a title="Managed Exceptions (development guide)" href="https://msdn.microsoft.com/en-us/library/5b2yeyab(v=vs.110)">Managed Exceptions (development guide)</a></li>
<li>[MSDN]&nbsp;<a href="https://msdn.microsoft.com/en-us/library/aa260767(v=VS.60).aspx">Search and unwind algorithm reference</a></li>
</ul>
<p>&nbsp;</p>
<p><strong></strong>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Links to MDA resources</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/links-to-mda-resources</link>
      <pubDate>Fri, 03 Aug 2012 18:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2012/08/03/links-to-mda-resources/</guid>
      <description><![CDATA[&nbsp;
&nbsp;
In-depth Articles-

[MSDN] Let CLR find bugs for you with MDAs

Tips and...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>In-depth Articles-</strong></p>
<ul>
<li>[MSDN] <a title="Let CLR find bugs for you with MDAs" href="https://msdn.microsoft.com/en-us/magazine/cc163606.aspx">Let CLR find bugs for you with MDAs</a></li>
</ul>
<p><strong>Tips and Tricks-</strong></p>
<ul>
<li>[Thomas Lai] <a title="How to disable a specific MDA" href="https://blogs.msdn.com/b/tlai/archive/2006/06/15/how-to-disable-a-specific-mda.aspx">How to disable a specific MDA</a></li>
</ul>
<p><strong>Misc-</strong></p>
<ul>
<li>[Mike Stall] <a title="MDAs are cool" href="https://blogs.msdn.com/b/jmstall/archive/2005/11/10/introducing-mdas.aspx">MDAs are cool</a>.</li>
<li>[Thottam Sriram] <a title="Managed Debugging Assistants (MDAs)" href="https://blogs.msdn.com/b/thottams/archive/2006/10/20/managed-debugging-assistants-mda-s.aspx">Managed Debugging Assistants (MDAs)</a>.</li>
</ul>
<p><strong>References-</strong></p>
<ul>
<li>[MSDN] <a title="MDA reference" href="https://msdn.microsoft.com/en-us/library/d21c150d(v=vs.110)">MDA reference</a></li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<hr style="width: 1000px;" width="1000" />
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Profiler and NGEN’ed images.</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/profiler-and-ngened-images</link>
      <pubDate>Tue, 22 Mar 2011 12:16:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2011/03/22/profiler-and-ngened-images/</guid>
      <description><![CDATA[[NOTE: This is a repost from my old blog www.debugtricks.com. The old blog no longer exists and I'll...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: verdana,geneva;"><span style="font-size: small;">[<strong>NOTE</strong>: This is a repost from my old blog <a href="https://www.debugtricks.com">www.debugtricks.com</a>. The old blog no longer exists and I'll be migrating my old posts over to this blog.] </span></span></p>
<p><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p><span style="font-family: verdana,geneva;"><span style="font-size: small;"><span style="font-weight: bold;">Question</span>: How does the runtime (CLR) decide which flavor of a module to load while profiling? Under what circumstances will it load the profiler-enhanced ngen&rsquo;ed images? When does it load regular ngen&rsquo;ed images? Can I use specific profiler event-masks to control the runtime&rsquo;s behavior? I&rsquo;m totally confused. Help!&nbsp; </span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;">&nbsp;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;"><span style="font-weight: bold;">Answer</span>: Pictures speak more than words&hellip;&hellip;&hellip;&hellip;</span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p style="margin: 0in; font-size: 11pt;"><span style="font-family: verdana,geneva;"><span style="font-size: small;"></span></span></p>
<p><span style="font-size: small;"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/55/05/8015.NGENProfiling.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-55-05/8015.NGENProfiling.png" border="0" /></span></p>
<p><span style="font-size: small;">&nbsp;</span></p>
<p><span style="font-size: small;">&nbsp;</span></p>
<p><span style="font-size: small;">&nbsp;</span></p>
<p><span style="font-size: small;">&nbsp;</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Image File Execution Options (IFEO)</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/image-file-execution-options-ifeo</link>
      <pubDate>Wed, 24 Mar 2010 11:54:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2010/03/24/image-file-execution-options-ifeo/</guid>
      <description><![CDATA[[NOTE: This is a repost from my old blog www.debugtricks.com. The old blog no longer exists and I'll...]]></description>
      <content:encoded><![CDATA[<p style="margin-left: 5pt">[<strong>NOTE</strong>: This is a repost from my old blog <a href="https://www.debugtricks.com">www.debugtricks.com</a>. The old blog no longer exists and I'll be migrating my old posts over to this blog.]</p>
<p style="margin-left: 5pt">&nbsp;Image File Execution options provides you with a mechanism to always launch an executable directly under the debugger. This is extremely useful if you ever need to investigate issues in the executable's startup code (services especially). You can set the IFEO options directly via the registry or indirectly using the Gflags tools (available with the <a href="https://www.microsoft.com/whdc/devtools/debugging/default.mspx">Window debugging toolkit</a>).&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">You need to create a registry key and populate it with a value as follows - </p>
<div sizset="0" sizcache="3" style="margin-left: 5pt">
<table border="0" style="border-collapse:collapse">
<colgroup><col style="width: 60px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col style="width: 568px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col></colgroup>
<tbody valign="top">
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>Key<strong>&nbsp; </strong></p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><strong>"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<span style="background-color: #ffff00;">&lt;executable&gt;</span>"</strong></p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>Value<strong>&nbsp; </strong></p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><strong>Debugger : REG_SZ : <span style="background-color: #ffff00;">&lt;full-path to your favorite debugger&gt;</span></strong></p>
</td>
</tr>
</tbody>
</table>
&nbsp;&nbsp;&nbsp;</div>
<p style="margin-left: 5pt">You do not need the full path to the application, only the exe name will suffice. However you do need the full path to the debugger.&nbsp; As an example, we look at launching notepad under ntsd, you would be creating the following - </p>
<div sizset="1" sizcache="3" style="margin-left: 5pt">
<table border="0" style="border-collapse:collapse">
<colgroup><col style="width: 60px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col style="width: 567px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col></colgroup>
<tbody valign="top">
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>Key<strong>&nbsp; </strong></p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><strong>"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe"</strong></p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>Value<strong>&nbsp; </strong></p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><strong>Debugger : REG_SZ : "c:\dbg\ntsd.exe -g"</strong></p>
</td>
</tr>
</tbody>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
<p style="margin-left: 5pt">&nbsp;</p>
<p style="margin-left: 5pt">You can also use Gflags to set IFEO too - </p>
<p style="margin-left: 5pt"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/55/05/0572.gflags.gif" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x550/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-55-05/0572.gflags.gif" border="0" />&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>How does IFEO work?&nbsp;</strong></span>&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><a href="https://msdn2.microsoft.com/en-us/library/ms682425.aspx">Kernel32!CreateProcess</a> when called without the DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS <a href="https://msdn2.microsoft.com/en-us/library/ms684863.aspx">creation flags</a>, checks the registry to see if IFEO has been set on the executable that it is launching. If yes, then it simply prepends the debugger path to the executable name, effectively getting the executable to launch under the debugger. If you do not specify the correct path to the debugger, then you'll probably get greeted with a "file not found" error. In our notepad/ntsd example above, Kernel32!CreateProcess ends up invoking - </p>
<p style="margin-left: 32pt"><strong>"c:\dbg\ntsd.exe -g&nbsp; notepad.exe"&nbsp;</strong>&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">Now ntsd eventually launches notepad under the debugger by calling Kernel32!CreateProcess with one of the following creation flags - DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS. The presence of any of these creation flags forces Kernel32!CreateProcess to bypass IFEO options this time around (else we would have been running into an endless loop) and actually launch the executable under the debugger.&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">&nbsp; &nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>IFEO and 64 bit -&nbsp;</strong></span>&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">A word of caution - For 32 bit executable running in the WOW on X64 machines, your natural tendency might be to create the registry key in the syswow node - </p>
<p style="margin-left: 32pt"><strong>"HKLM\SOFTWARE\<span style="background-color: #ffff00;">Wow6432Node</span>\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<span style="background-color: #ffff00;">&lt;executable&gt;</span>"&nbsp;</strong>&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt">However Gregg Miskelly <a href="https://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx">notes that</a> you should set the IFEO corresponding to the bit-ness to the application calling into kernel32!CreateProcess to launch the executable -&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 32pt"><span style="font-size:10pt"><em>"On Win 64, there are two copies of HKEY_LOCAL_MACHINE\Software (one for 32-bit apps, and one for 64-bit apps), and therefore there are two copies of these options. However, where the operating system looks isn't dependant on the bit-ness of the application that is going to be debugged (which is what you would probably expect). Instead, it is dependent on the bit-ness of the application that called CreateProcess." </em></span></p>
<p style="margin-left: 32pt">&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>Other IFEO caveats -&nbsp; </strong></span></p>
<p style="margin-left: 5pt">Raymond Chen notes the following caveat in <a href="https://blogs.msdn.com/oldnewthing/archive/2007/07/02/3652873.aspx">his blog entry</a>&nbsp; - </p>
<p style="margin-left: 32pt"><span style="font-size:10pt"><em>"If you passed special parameters via the STARTUPINFO structure, those parameters get passed to the debugger. And the PROCESS_INFO that is returned by the CreateProcess function describes the debugger, not the process being debugged." </em></span></p>
<p style="margin-left: 5pt">&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>IFEO and Managed debuggers - </strong></span></p>
<p style="margin-left: 5pt">IFEO can only be used for native or interop debugging, but not for managed debugging. Mike Stall has an <a href="https://blogs.msdn.com/jmstall/archive/2006/02/16/ifeo-managed-debugging.aspx">excellent blog entry</a> that describes in great detail exactly why. The gist is this - Managed debuggers like Mdbg/cordbg/VS.NET use ICorDebug::CreateProcess to launch managed executables under the debugger. However for managed debugging, the debugger should call ICorDebug::CreateProcess without the DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS creation flags (<a href="https://msdn2.microsoft.com/en-us/library/ms232508.aspx">this is publicly documented</a>). This API internally ends up calling Kernel32!CreateProcess without the DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS creation flags. This leads to the endless loop that I described above. Is this an ICorDebug API design flaw?&nbsp; Not really. Just an oversight in my opinion - The API designers missed one scenario. Maybe in the next version of the CLR this will be fixed (I do not know for sure). </p>
<p style="margin-left: 5pt">&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>Some excellent resources on IFEO - </strong></span></p>
<div sizset="2" sizcache="3" style="margin-left: 5pt">
<table border="0" style="border-collapse:collapse">
<colgroup><col style="width: 137px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col style="width: 490px;"></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col><col></col></colgroup>
<tbody valign="top">
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>[<a href="https://msdn2.microsoft.com/">MSDN</a>]</p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  solid #a3a3a3 1.0pt; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><a href="https://msdn2.microsoft.com/en-us/library/a329t4ed(vs.71).aspx">Launching the debugger automatically</a> (How to launch VS debugger using IFEO)</p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>[<a href="https://blogs.msdn.com/jmstall">Mike Stall</a>]</p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>&nbsp;<a href="https://blogs.msdn.com/jmstall/archive/2006/02/16/ifeo-managed-debugging.aspx">IFEO and managed debugging</a></p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>[<a href="https://blogs.msdn.com/oldnewthing">Raymond Chen</a>]</p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><a href="https://blogs.msdn.com/oldnewthing/archive/2007/07/02/3652873.aspx">Image File Execution options just inserts the debugger in front of the command line</a></p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>[<a href="https://blogs.msdn.com/greggm/">Gregg Miskelly</a>]</p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p><a href="https://blogs.msdn.com/greggm/archive/2005/02/21/377663.aspx">Inside 'Image File Execution Options' debugging</a></p>
</td>
</tr>
<tr>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  solid #a3a3a3 1.0pt; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>[<a href="https://blogs.msdn.com/junfeng">Junfeng Zhang</a>]</p>
</td>
<td style="padding-top: 5px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px; border-top:  none; border-left:  none; border-bottom:  solid #a3a3a3 1.0pt; border-right:  solid #a3a3a3 1.0pt">
<p>&nbsp;<a href="https://blogs.msdn.com/junfeng/archive/2004/04/28/121871.aspx">Image File Execution Options</a> (talks about the other not-so-well documented IFEO options)</p>
</td>
</tr>
</tbody>
</table>
</div>
<p style="margin-left: 32pt">&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>Exercise for reader - </strong></span></p>
<p style="margin-left: 5pt">Does IFEO work with other Win32 APIs like ShellExecute, CreateProcessAsUser, CreateProcessWithLogonW and CreateProcessWithTokenW? </p>
<p style="margin-left: 5pt">&nbsp;&nbsp;&nbsp;</p>
<p style="margin-left: 5pt"><span style="text-decoration: underline;"><strong>TIP of the day - </strong></span></p>
<p style="margin-left: 5pt"><strong>Question </strong>- System services can launch before the user has a chance to log on. So how do you debug the startup code of these system services? </p>
<p style="margin-left: 5pt"><strong>Answer </strong>- Put the machine under kernel Debugger (KD), use IFEO to launch the service under NTSD (use ntsd's&nbsp; "-d" option to pipe the ntsd output to KD) and reboot the machine. When the system service launches, it will be launched under ntsd.&nbsp; The ntsd debugger will automatically cause it break into KD when it encounters the initial loader breakpoint. The debugging session will begin in user mode automatically (yipee!). After you are done debugging, switch control to KD by issuing ".breakin" command. </p>
<p style="margin-left: 5pt">&nbsp; &nbsp;</p>
<p style="margin-left: 5pt">&nbsp; &nbsp;</p>
<p style="margin-left: 5pt">&nbsp; &nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>[Random] How to quickly view a binary's embedded manifest?</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/random-how-to-quickly-view-a-binarys-embedded-manifest</link>
      <pubDate>Wed, 16 Dec 2009 11:13:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2009/12/16/random-how-to-quickly-view-a-binarys-embedded-manifest/</guid>
      <description><![CDATA[&nbsp;
The "sigcheck" tool from sysinternals is of great help here. Use the "-m" option to view the...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri">The "sigcheck" tool from sysinternals is of great help here. Use the "-m" option to view the embedded manifest.</P>
<P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Arial" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Arial" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Sigcheck v1.63 - File version and signature viewer</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Copyright (C) 2004-2009 Mark Russinovich</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Sysinternals - <A href="https://www.sysinternals.com/" mce_href="https://www.sysinternals.com/">www.sysinternals.com</A></P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">usage: <A href="file://live.sysinternals.com/tools/sigcheck.exe" mce_href="file://live.sysinternals.com/tools/sigcheck.exe">\\live.sysinternals.com\tools\sigcheck.exe</A> [-a][-h][-i][-e][-n][[-s]|[-v]|[-m]][-q][-r][-u][-c catalog file] &lt;file or directory&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-a Show extended version information</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-c Look for signature in the specified catalog file</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-e Scan executable images only (regardless of their extension)</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-h Show file hashes</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-i Show catalog name and image signers</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="BACKGROUND: yellow; mso-highlight: yellow">-m Dump manifest</SPAN></P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-n Only show file version number</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-q Quiet (no banner)</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-r Check for certificate revocation</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-s Recurse subdirectories</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-u Show unsigned files only</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">-v Csv output</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri">Here is an example. We'll use the sigcheck tool on notepad. </P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">C:\&gt;<A href="file://live.sysinternals.com/tools/sigcheck.exe" mce_href="file://live.sysinternals.com/tools/sigcheck.exe">\\live.sysinternals.com\tools\sigcheck.exe</A> -m c:\Windows\notepad.exe</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Sigcheck v1.63 - File version and signature viewer</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Copyright (C) 2004-2009 Mark Russinovich</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">Sysinternals - <A href="https://www.sysinternals.com/" mce_href="https://www.sysinternals.com/">www.sysinternals.com</A></P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">c:\windows\notepad.exe:</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Verified:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Signed</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Signing date:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>5:30 AM 11/2/2006</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Publisher:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Microsoft Corporation</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Description:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Notepad</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Product:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Microsoft« Windows« Operating System</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Version:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>6.0.6000.16386</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>File version:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>6.0.6000.16386 (vista_rtm.061101-2205)</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="BACKGROUND: yellow; mso-highlight: yellow"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Manifest:</SPAN></P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;!-- Copyright (c) Microsoft Corporation --&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;assemblyIdentity</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>name="Microsoft.Windows.Shell.notepad"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>processorArchitecture="amd64"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>version="5.1.0.0"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>type="win32"/&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;description&gt;Windows Shell&lt;/description&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;dependency&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;dependentAssembly&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;assemblyIdentity</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>type="win32"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>name="Microsoft.Windows.Common-Controls"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>version="6.0.0.0"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>processorArchitecture="*"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>publicKeyToken="6595b64144ccf1df"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>language="*"</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>/&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/dependentAssembly&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;/dependency&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;security&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;requestedPrivileges&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;requestedExecutionLevel level="asInvoker" uiAccess="false"/&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;/requestedPrivileges&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/security&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;/trustInfo&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'">&lt;/assembly&gt;</P>
<P style="FONT-SIZE: 9pt; MARGIN: 0in; COLOR: blue; FONT-FAMILY: 'Courier New'" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri">FYI - You can "net use" into <A href="file://live.sysinternals.com/tools">\\live.sysinternals.com\tools</A> and use all the sysinternals tools like process explorer, process monitor etc. Isn't that cool?</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>
<P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>SeImpersonatePrivilege</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/seimpersonateprivilege</link>
      <pubDate>Tue, 03 Jul 2007 16:35:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2007/07/03/seimpersonateprivilege/</guid>
      <description><![CDATA[&nbsp;
NOTE - I wrote this up more than a year back and for some mysterious reasons forgot to post...]]></description>
      <content:encoded><![CDATA[<P><STRONG><EM></EM></STRONG>&nbsp;</P>
<P><STRONG>NOTE</STRONG> <EM>- I wrote this up more than a year back and for some mysterious reasons forgot to post it! Much of what is written here applies to Vista UAC accounts as well.</EM> </P>
<P><EM><STRONG>QUESTION</STRONG> - Under Windows Server 2003, can a "limited user" impersonate an "administrator"? </EM></P>
<P><STRONG><EM>ANSWER</EM></STRONG> –&nbsp; As you are aware, there are four impersonation levels, each of which indicates the degree to which one user can impersonate another – <EM>SecurityAnonymous, SecurityIdentification, SecurityImpersonation, and SecurityDelegation</EM>. A limited user on Windows Server 2003 (or UAC admin on vista) needs SE_IMPERSONATE_PRIVILEGE enabled in order to impersonate the context of an "administrator" at any level above "SecurityIdentification". </P>
<P>Consider this snippet of code executed in the context of a limited user (non-admin). An admin's token is first obtained and duplicated to create an impersonation token at security level "<EM>SecurityImpersonation</EM>". The limited user then attempts to impersonate the admin. If impersonation succeeds, then it tries some operation that requires admin privileges (In this case, creating a key under HKLM\Software\Microsoft with write access).&nbsp;&nbsp;</P>
<P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; WIDTH: 491.4pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt" cellSpacing=0 cellPadding=0 width=655 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 491.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=655>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'">void</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"> wmain ()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>HANDLE<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>hPrivToken ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>HANDLE<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>hPrivTokenImperson ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> ( 0 == LogonUser( L"administrator", L"MyMachine", L"MyPassWord",<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&amp; hPrivToken ) )<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wprintf( L"Failed to logon admin. Last Error = %d\n",<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>GetLastError() ) ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> ( 0 == DuplicateTokenEx( hPrivToken, TOKEN_QUERY | TOKEN_IMPERSONATE, NULL, <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SecurityImpersonation, TokenImpersonation, <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&amp; hPrivTokenImperson ) )<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wprintf( L"Failed to obtain impersonation token. Last Error = %d\n", <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>GetLastError() ) ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> ( 0 == SetThreadToken( NULL, hPrivTokenImperson ) )<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wprintf( L"Failed to impersonate administrator. Last Error = %d\n",<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>GetLastError() ) ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> ;<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">// Do something that requires admin privileges…………<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> ( ERROR_SUCCESS != RegCreateKeyEx( HKEY_LOCAL_MACHINE, <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>L"Software\\Microsoft\\RandomKey", 0, NULL, <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>NULL, &amp; hKey, &amp; dwDisposition ) )<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wprintf( L"RegCreateKeyEx FAILED. Last Error = %d\n", <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>GetLastError() ) ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wprintf( L"RegCreateKeyEx SUCCEEDED.\n" ) ;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>SetThreadToken( NULL, NULL ) ; <SPAN style="COLOR: green">// revert back<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'">}</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Comic Sans MS'"><o:p></o:p></SPAN></P></TD></TR></TBODY></TABLE></P>
<P>Under Windows XP, the limited user is successfully able to impersonate the admin at level <EM>SecurityImpersonation</EM>. However on Windows 2003 and Vista things are a bit different because of the security changes related to SE_IMPERSONATE_PRIVILEGE that I described above. Although the first call to SetThreadToken() succeeds, the impersonation is being sneakily carried out at level <EM>SecurityIdentification.</EM> As a result of which your privileged operation (writing to HKLM in this case) fails with an access-denied error. Sweet! On Windows Server 2003 and above, the ability to impersonate at <EM>SecurityImpersonation </EM>and above is given only to Network Service, Local Service, Local System and Administrators (On Vista you need to be running elevated as well to have SE_IMPERSONATE_PRIVILEGE enabled in the token). </P>
<P>&nbsp; &nbsp;</P>
<P>&nbsp; &nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>DllImportAttribute.PreserveSig vs PreserveSigAttribute</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/dllimportattribute-preservesig-vs-preservesigattribute</link>
      <pubDate>Sun, 06 May 2007 17:48:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2007/05/06/dllimportattribute-preservesig-vs-preservesigattribute/</guid>
      <description><![CDATA[DllImportAttribute.PreserveSig - 

Mainly used in PInvoke Signatures 
By default, while using...]]></description>
      <content:encoded><![CDATA[<P><SPAN style="COLOR: black; FONT-FAMILY: Trebuchet MS; TEXT-DECORATION: underline"><STRONG>DllImportAttribute.PreserveSig - </STRONG></SPAN></P>
<UL>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">Mainly used in PInvoke Signatures</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman"> </SPAN></SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">By default, while using DllImportAttribute to p-invoke, the DllImportAttribute.PreserveSig is set to true.</SPAN> </SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">If false: Converts returned HRESULTS from unmanaged signature to managed exceptions if they are not S_OK.</SPAN> </SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">If true: Does not convert returned HRESULT to exceptions.</SPAN> </SPAN></LI></UL>
<P>&nbsp; &nbsp;</P>
<P><SPAN style="COLOR: black; FONT-FAMILY: Trebuchet MS; TEXT-DECORATION: underline"><STRONG>PreserveSigAttribute (pseudo custom attribute)– </STRONG></SPAN></P>
<UL>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">This is mainly used in COM interface definitions in managed code.</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman"> </SPAN></SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">By default, for COM interface methods, the CLR does HRESULT to exception transformations (opposite behavior to that of pinvoke).</SPAN> </SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">If attribute applied: Does not convert returned HRESULT to exceptions.</SPAN> </SPAN></LI>
<LI><SPAN style="COLOR: black"><SPAN style="FONT-FAMILY: Trebuchet MS">If attribute not applied: Default behavior of HRESULT to exception transformations.</SPAN> </SPAN></LI></UL>
<P><SPAN style="COLOR: black"></SPAN>My short-term memory is bad and I tend to forget things as soon as I learn them. So I&nbsp;jotted this down&nbsp;while I was reading <A class="" href="https://blogs.msdn.com/Adam_Nathan/" mce_href="https://blogs.msdn.com/Adam_Nathan/">Adam Nathan</A>'s excellent <A class="" href="https://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X/ref=pd_bbs_sr_2/103-9191626-3131844?ie=UTF8&amp;s=books&amp;qid=1182554096&amp;sr=8-2" mce_href="https://www.amazon.com/NET-COM-Complete-Interoperability-Guide/dp/067232170X/ref=pd_bbs_sr_2/103-9191626-3131844?ie=UTF8&amp;s=books&amp;qid=1182554096&amp;sr=8-2">manuscript on COM interop</A>. Hope you find this tidbit useful as well.&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;</P>
<P>&nbsp; &nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Why does ICorDebug::SetManagedHandler() return E_NOINTERFACE?</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/why-does-icordebugsetmanagedhandler-return-e_nointerface</link>
      <pubDate>Fri, 22 Dec 2006 23:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2006/12/22/why-does-icordebugsetmanagedhandler-return-e_nointerface/</guid>
      <description><![CDATA[&nbsp;
Since I have no&nbsp;energy to type a&nbsp;long post today (sigh), I'll spare you the gory...]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">Since I have no&nbsp;energy to type a&nbsp;long post today (sigh), I'll spare you the gory details on the cause of this error.&nbsp;Here are the&nbsp;main reasons why you would be seeing this error - </P>
<UL>
<LI>While expecting to debug a v2.0.xxxx managed app, you have forgotten to implement ICorDebugManagedCallback<STRONG>2 </STRONG>in your managed callback handler. The managed callback handler must implement both ICorDebugManagedCallback and ICorDebugManagedCallback<STRONG>2</STRONG> in such cases.</LI></UL>
<P mce_keep="true">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 0.5in; BORDER-LEFT: medium none; WIDTH: 437.4pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=583 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 437.4pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=583>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">class</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> ManagedEngine : <SPAN style="COLOR: blue">public</SPAN> ICorDebugManagedCallback, <B style="mso-bidi-font-weight: normal"><SPAN style="BACKGROUND: yellow; COLOR: blue; mso-highlight: yellow">public</SPAN><SPAN style="BACKGROUND: yellow; mso-highlight: yellow"> ICorDebugManagedCallback2</SPAN><o:p></o:p></B></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P></TD></TR></TBODY></TABLE></P>
<P mce_keep="true">&nbsp;</P>
<UL>
<LI>While implementing QueryInterace(..), you probably forgot to account for ICorDebugManagedCallback<STRONG>2</STRONG>.</LI></UL>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 0.5in; BORDER-LEFT: medium none; WIDTH: 6.15in; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=590 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 6.15in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=590>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">HRESULT <SPAN style="COLOR: blue">__stdcall</SPAN> ManagedEngine::QueryInterface(<SPAN style="COLOR: blue">const</SPAN> IID &amp; iid, <SPAN style="COLOR: blue">void</SPAN>** ppv)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN> (iid == IID_IUnknown)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* ppv = <SPAN style="COLOR: blue">static_cast</SPAN>&lt;ICorDebugManagedCallback*&gt;(<SPAN style="COLOR: blue">this</SPAN>); <SPAN style="COLOR: green">// original implementation<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else</SPAN> <SPAN style="COLOR: blue">if</SPAN> (iid == IID_ICorDebugManagedCallback)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* ppv = <SPAN style="COLOR: blue">static_cast</SPAN>&lt;ICorDebugManagedCallback*&gt;(<SPAN style="COLOR: blue">this</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="BACKGROUND: yellow; COLOR: blue; mso-highlight: yellow">else</SPAN><SPAN style="BACKGROUND: yellow; mso-highlight: yellow"> <SPAN style="COLOR: blue">if</SPAN> (iid == IID_ICorDebugManagedCallback2)<o:p></o:p></SPAN></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 8pt; BACKGROUND: yellow; FONT-FAMILY: 'Courier New'; mso-no-proof: yes; mso-highlight: yellow"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* ppv = <SPAN style="COLOR: blue">static_cast</SPAN>&lt;ICorDebugManagedCallback2*&gt;(<SPAN style="COLOR: blue">this</SPAN>);</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">else<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>* ppv = NULL;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> E_NOINTERFACE;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">reinterpret_cast</SPAN>&lt;IUnknown*&gt;(*ppv)-&gt;AddRef();<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">return</SPAN> S_OK;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN><o:p></o:p></P></TD></TR></TBODY></TABLE></P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Pay attention to the calling convention!</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/pay-attention-to-the-calling-convention</link>
      <pubDate>Mon, 11 Dec 2006 23:25:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2006/12/11/pay-attention-to-the-calling-convention/</guid>
      <description><![CDATA[&nbsp;
Ever seen this run-time failure? - "The value of ESP was not properly saved across a...]]></description>
      <content:encoded><![CDATA[<FONT size=2>
<P mce_keep="true">&nbsp;</P>
<P>Ever seen this run-time failure? - "<STRONG>The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention</STRONG>"</P>
<P>Whenever I get sloppy, I tend to write awful code as shown below - </P><FONT size=1>
<P></FONT><FONT size=1>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 0.2in; BORDER-LEFT: medium none; WIDTH: 513pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=684 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 513pt; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=684>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">FARPROC pDllFunc = NULL;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">HRESULT (* pDllGetReqRuntimeVer) (LPWSTR, LPWSTR, DWORD, DWORD*);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">HMODULE hModuleMscoree = LoadLibrary(L<SPAN style="COLOR: maroon">"mscoree.dll"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">if</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">(NULL != hModuleMscoree)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>pDllFunc = GetProcAddress(hModuleMscoree, <SPAN style="COLOR: maroon">"GetRequestedRuntimeVersion"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(NULL != pDllFunc)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>pDllGetReqRuntimeVer = (HRESULT(*)(LPWSTR, LPWSTR, DWORD, DWORD*))pDllFunc;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>hr = pDllGetReqRuntimeVer(<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>thrParam-&gt;cmdLineSw.pwszImage,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>wszDebuggeeVer,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: blue">sizeof</SPAN>(wszDebuggeeVer)/<SPAN style="COLOR: blue">sizeof</SPAN>(wszDebuggeeVer[0]),<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>&amp; dws);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN><o:p></o:p></P></TD></TR></TBODY></TABLE></P></FONT>
<P>When sloppy, I forget to use the correct calling convention while declaring function pointers. Then I run into the above run-time error while calling into various functions exported by dlls (mscoree!GetRequestedRuntimeVersion in above example). Most Win32 APIs are declared as <STRONG>__stdcall</STRONG> which expects the "<STRONG>callee</STRONG>" to cleanup the stack. I compile with /Gd (uses <STRONG>__cdecl</STRONG> as default convention). Because I forgot of mark the function pointer with <STRONG>__stdcall</STRONG>, the run-time is now expecting the "<STRONG>caller</STRONG>" to cleanup the stack. Fortunately I'm bailed out by the above run time check. To correct this the, function pointer must be declared and used as follows -</P>
<P mce_keep="true">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 border=1 class="MsoTableGrid">
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD class="" style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; WIDTH: 6.95in; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=667>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">FARPROC pDllFunc = NULL;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">HRESULT (<SPAN style="COLOR: blue"><STRONG>__stdcall</STRONG></SPAN> * pDllGetReqRuntimeVer) (LPWSTR, LPWSTR, DWORD, DWORD*);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">HMODULE hModuleMscoree = LoadLibrary(L<SPAN style="COLOR: maroon">"mscoree.dll"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">if</SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">(NULL != hModuleMscoree)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>pDllFunc = GetProcAddress(hModuleMscoree, <SPAN style="COLOR: maroon">"GetRequestedRuntimeVersion"</SPAN>);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">if</SPAN>(NULL != pDllFunc)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>pDllGetReqRuntimeVer = (HRESULT(<SPAN style="COLOR: blue"><STRONG>__stdcall</STRONG></SPAN> *)(LPWSTR, LPWSTR, DWORD, DWORD*))pDllFunc;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>hr = pDllGetReqRuntimeVer(<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>thrParam-&gt;cmdLineSw.pwszImage,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wszDebuggeeVer,<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">sizeof</SPAN>(wszDebuggeeVer)/<SPAN style="COLOR: blue">sizeof</SPAN>(wszDebuggeeVer[0]),<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&amp; dws);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</SPAN><o:p></o:p></P></TD></TR></TBODY></TABLE></P>
<P mce_keep="true">&nbsp;</P>
<P>Given below are the native disassemblies (function prolog and epilog) when you use <STRONG>__cdecl </STRONG>and <STRONG>__stdcall</STRONG> respectively. As you can see, for the function marked as <STRONG>__cdecl</STRONG>, the "<STRONG>caller</STRONG>" is cleaning up the stack. While the "<STRONG>callee</STRONG>" does the needful when <STRONG>__stdcall</STRONG> is used.</P>
<P><STRONG>When using __cdecl</STRONG>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>esi,esp <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB3<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>lea<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax,[dws] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB9<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DBA<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>80h<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DBF<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>lea<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ecx,[ebp-168h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC5<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ecx<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC6<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>edx,dword ptr [ebp-48h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC9<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax,dword ptr [edx+10h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DCC<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DCD<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>call<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dword ptr [ebp-61Ch] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DD3<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>add<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>esp,10h<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><STRONG><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Wingdings; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">ß</SPAN></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">----------- stack is cleaned by caller!</SPAN></STRONG></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DD6<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>cmp<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>esi,esp <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DD8<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>call<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>@ILT+840(__RTC_CheckEsp) (41134Dh) <STRONG><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Wingdings; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">ß</SPAN></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">------ The run time check</SPAN></STRONG></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><STRONG><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes"></SPAN></STRONG></SPAN><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DDD<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dword ptr [ebp-18h],eax <o:p></o:p></SPAN></P>
<P mce_keep="true">
<P mce_keep="true">&nbsp;</P>
<P><STRONG>When using __stdcall</STRONG>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB1<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>esi,esp <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB3<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>lea<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax,[dws] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DB9<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DBA<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>80h<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DBF<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>lea<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ecx,[ebp-168h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC5<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>ecx<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC6<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>edx,dword ptr [ebp-48h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DC9<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax,dword ptr [edx+10h] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DCC<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>push<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>eax<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DCD<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>call<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dword ptr [ebp-61Ch] <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DD3<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>cmp<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>esi,esp <STRONG><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Wingdings; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">ß</SPAN></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">--------- At this stage callee has already cleaned up stack</SPAN></STRONG><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DD5<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>call<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>@ILT+840(__RTC_CheckEsp) (41134Dh) <STRONG><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: Wingdings; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">ß</SPAN></SPAN><SPAN style="FONT-SIZE: 8pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-no-proof: yes">------ The run time check</SPAN></STRONG><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">00412DDA<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>mov<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>dword ptr [ebp-18h],eax</SPAN></P>
<P mce_keep="true">&nbsp;</P>
<P>I should be paying more attention to the calling conventions and&nbsp;instead of&nbsp;relying on this run-time check. But it is nice to have this safety net.</P>
<P mce_keep="true">&nbsp;</P></FONT>]]></content:encoded>
    </item>
    <item>
      <title>Quote of the day!</title>
      <link>https://docs.microsoft.com/archive/blogs/mithuns/quote-of-the-day</link>
      <pubDate>Fri, 08 Dec 2006 20:13:00 GMT</pubDate>
      <dc:creator><![CDATA[Mithun Shanbhag]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mithuns/2006/12/08/quote-of-the-day/</guid>
      <description><![CDATA[When I score goals&nbsp;I'm great, when&nbsp;I don't&nbsp;I'm fat.
- Ronaldo]]></description>
      <content:encoded><![CDATA[<P mce_keep="true">When I score goals&nbsp;I'm great, when&nbsp;I don't&nbsp;I'm fat.</P>
<P>- <A class="" href="https://soccernet.espn.go.com/news/story?id=395013&amp;cc=5901" mce_href="https://soccernet.espn.go.com/news/story?id=395013&amp;cc=5901">Ronaldo</A></P>]]></content:encoded>
    </item>
  </channel>
</rss>