<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Florent Clairambault &#187; File Disassembler</title>
	<atom:link href="http://florent.clairambault.fr/tag/file-disassembler/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 20:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Inside Sharepoint</title>
		<link>http://florent.clairambault.fr/inside-sharepoint?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=inside-sharepoint</link>
		<comments>http://florent.clairambault.fr/inside-sharepoint#comments</comments>
		<pubDate>Tue, 04 Aug 2009 20:55:01 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.NET Reflector]]></category>
		<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[File Disassembler]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Sharepoint 2007]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1397</guid>
		<description><![CDATA[I recently took the time to take a look inside the Microsoft.Sharepoint.dll using reflector. I&#8217;m not sure I have the right to do that. And I&#8217;m pretty sure I don&#8217;t have the right to publish any code extracted from it, so I won&#8217;t show any. Using SPSite(s) and SPWeb(s) If you do some timing on [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took the time to take a look inside the Microsoft.Sharepoint.dll <a href="http://florent.clairambault.fr/net-reflector-file-disassembler">using reflector</a>. I&#8217;m <a href="http://stackoverflow.com/questions/906746/is-it-legal-to-use-reflector-to-analyze-binaries-when-the-owner-forbids-a-viewing">not sure I have the right to do that</a>. And I&#8217;m pretty sure I don&#8217;t have the right to publish any code extracted from it, so I won&#8217;t show any.</p>
<p><strong>Using SPSite(s) and SPWeb(s)</strong><br />
If you do some timing on the SPWeb creation call (SPSite.OpenWeb), you will find out that it&#8217;s freaking fast (less then 1 ms on my server). The reason is that the most heavy object, the SPRequest class, is shared among SPWebs of a SPSite. The Dispose call only &#8220;Invalidate&#8221; the SPWeb, and if this SPWeb is the owner of the SPRequest (which is SPContext.Current.Web object in most of the cases), it releases it. </p>
<p>Personnaly, I like to have something like that when I use a particular SPWeb along my code in a WebPart :</p>

<div class="wp_codebox"><table><tr id="p13975"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p1397code5"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> SPWeb _rootWeb<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> SPWeb RootWeb <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _rootWeb <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RootWeb</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _rootWeb <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>  
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _rootWeb<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span> _toDispose <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnUnLoad<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> var disp <span style="color: #0600FF; font-weight: bold;">in</span> _toDispose <span style="color: #008000;">&#41;</span>
        disp<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>But the code above won&#8217;t make you gain a 1 ms compared to this code (which is shorter and potentially safer, you don&#8217;t need to dispose everything) :</p>

<div class="wp_codebox"><table><tr id="p13976"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1397code6"><pre class="csharp" style="font-family:monospace;">var rootWeb <span style="color: #008000;">=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">try</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Your code</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">finally</span> <span style="color: #008000;">&#123;</span>
     <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> rootWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
         rootWeb<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If you had to access some more indirect objects, you certainly should keep the code showed earlier. For instance to use a SuperToken Web :</p>

<div class="wp_codebox"><table><tr id="p13977"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p1397code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> SPSite _stSite<span style="color: #008000;">;</span>
SPSite STSite <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _stSite <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPSite<span style="color: #008000;">&#40;</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span>, SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SystemAccount</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UserToken</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Site</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _stSite <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _stSite<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> SPWeb _stWeb<span style="color: #008000;">;</span>
SPWeb STWeb <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            _stWeb <span style="color: #008000;">=</span> STSite<span style="color: #008000;">.</span><span style="color: #0000FF;">OpenWeb</span><span style="color: #008000;">&#40;</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">!=</span> SPContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Web</span> <span style="color: #008000;">&#41;</span>
                _toDispose<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span> _stWeb <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _stWeb<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span> _toDispose <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>IDisposable<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnUnLoad<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span> var disp <span style="color: #0600FF; font-weight: bold;">in</span> _toDispose <span style="color: #008000;">&#41;</span>
        disp<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Here, opening these new SPSite and SPWeb takes 200 ms on my server. Making sure this only happen once per webpart (or better, per page) can really boost your performances.</p>
<p><strong>The SPRequest object</strong><br />
Well&#8230; I was very disapointed, the SPRequest object references an SPRequestInternalClass from the Microsoft.Sharepoint.Library assembly which only uses interrop COM+ methods. So, it&#8217;s basically wrapping COM+ methods. The SPRequest does a lot of exception handling and it keeps track of where (with the stacktrace) it has been created and the size of the &#8220;unmanaged stack&#8221;.</p>
<p><strong>Optimization</strong><br />
I like how they did their code. It&#8217;s pretty optimized (they even use a bunch of gotos). But sometimes there is some weird things and I don&#8217;t know if it&#8217;s the compiler&#8217;s or the developer&#8217;s fault. If you look at the code, they have an SPRequestManager.SPRequestsPerThreadWarning property, which gets (in the Registry, at &#8220;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings\LocalSPRequestWarnCount&#8221;) the max number of opened SPRequest objects opened before logging it (or 8 if this entry doesn&#8217;t exist), that takes twice the amount of code it would normaly require.</p>
<p><strong>The limit of disassembling</strong><br />
The most frustrating part is there are tons of really important methods that are obfuscated (and that .Net reflector doesn&#8217;t disassemble, it could at least give the IL code in comments). I just have :</p>

<div class="wp_codebox"><table><tr id="p13978"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1397code8"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> xxx<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// This item is obfuscated and can not be translated.</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>For instance, I really would have liked to see how works the SPList.Update() method, but it&#8217;s also obfuscated. </p>
<p><strong>You should explore it too</strong><br />
In the Microsoft.Office.Server.Search assembly, you will also find some pretty interesting things. If you look how works the standard search webparts, well you will be pretty disapointed. The advanced search uses an internal (in the C# meaning) shared object.</p>
<p>Before doing your own webpart, you should take a look at the overriden methods of some sharepoint webparts. It can show you, for instance, how to create your own toolparts. In my last project, I used a stupid text property instead of using a DropDownList in a ToolPart, I was very disappointed with myself when I discovered this.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/inside-sharepoint/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net Reflector + File Disassembler</title>
		<link>http://florent.clairambault.fr/net-reflector-file-disassembler?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=net-reflector-file-disassembler</link>
		<comments>http://florent.clairambault.fr/net-reflector-file-disassembler#comments</comments>
		<pubDate>Wed, 29 Jul 2009 20:45:41 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.NET Reflector]]></category>
		<category><![CDATA[File Disassembler]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1357</guid>
		<description><![CDATA[.Net reflector is a really good tool. You can see the content of any assembly very easily. But it&#8217;s not really easy to see the full content of a class, or a library with it. The File Disassembler add-in is a totally crazy stuff. You can take any assembly and totally disassemble it. It even [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.red-gate.com/products/reflector/">.Net reflector</a> is a really good tool. You can see the content of any assembly very easily. But it&#8217;s not really easy to see the full content of a class, or a library with it.</p>
<p>The <a href="http://www.denisbauer.com/NETTools/FileDisassembler.aspx">File Disassembler</a> add-in is a totally crazy stuff. You can take any assembly and totally disassemble it. It even creates the .csproj so that you just have to open the project in Visual Studio. But don&#8217;t get too excited if the code is obfuscated you will get some &#8220;empty&#8221; methods with just this comment :</p>

<div class="wp_codebox"><table><tr id="p135710"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1357code10"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// This item is obfuscated and can not be translated.</span></pre></td></tr></table></div>

<p>By the way. As you can see from the .net reflector video, you can register in the context menu for any DLL and EXE assembly by executing it with the /register parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/net-reflector-file-disassembler/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.341 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-07-29 16:38:15 -->
