<?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>Dot Net Thoughts &#187; IL</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/il/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>thoughts about .Net, WPF, Sharepoint, Javascript and more.</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:59:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Exploring IL Assembler</title>
		<link>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/</link>
		<comments>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 17:56:20 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IL]]></category>
		<category><![CDATA[ILASM]]></category>
		<category><![CDATA[ILDASM]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=726</guid>
		<description><![CDATA[One of colleague once asked a question to me, like what is the risk by distributing the windows application without obfuscating it. The only problem I found is user can use some tools like .Net Reflector and explore our assemblies. But few days before I found some nice .Net Framework tools, ildasm.exe and ilasm.exe, IL [...]]]></description>
			<content:encoded><![CDATA[<p>One of colleague once asked a question to me, like what is the risk by distributing the windows application without obfuscating it. The only problem I found is user can use some tools like .Net Reflector and explore our assemblies. But few days before I found some nice .Net Framework tools, ildasm.exe and ilasm.exe, IL Disassembler and IL Assembler respectively. These tools are available with .Net Framework SDKs. These tools can used to generate IL code for .Net assemblies and re-create assemblies from IL code. You can achieve it in code via .Net Reflection.Emit namespace. (In Community Techdays @ Cochin, one session is on Reflection.Emit. Don&#8217;t miss it.) As it is a vast topic I am only explaining basics <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Generate IL code using ILDASM.exe</strong></p>
<ol>
<li>First create a HelloWorld.cs and compile it to HelloWorld.exe</li>
<pre class="brush: csharp;">
using System;

public class HelloWorld
{
static int Main(string[] args)
	{
Console.WriteLine(&quot;Hello World&quot;);
		return(0);
	}
}
</pre>
<li>Use <code>csc.exe</code>to compile the cs file to exe. &#8211; <code>csc HelloWorld.cs</code></li>
<li>Use <code>ildasm.exe HelloWorld.Exe</code> to view the IL Code. You can find ILDASM in the Microsoft .Net SDK Path
<p><div id="attachment_724" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/ildasm.png"><img class="size-medium wp-image-724" title="ILDASM - Exploring HelloWorld.exe " src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/ildasm-300x285.png" alt="ILDASM - Exploring HelloWorld.exe " width="300" height="285" /></a><p class="wp-caption-text">ILDASM - Exploring HelloWorld.exe </p></div></li>
<li>To generate the IL code use Select Dump option from File Menu or Press Ctrl+D. It will asks for a location to save the IL code.
<p><div id="attachment_722" class="wp-caption alignnone" style="width: 208px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code1.png"><img class="size-full wp-image-722" title="IL Code Generated" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code1.png" alt="IL Code Generated" width="198" height="108" /></a><p class="wp-caption-text">IL Code Generated</p></div></li>
<li>Use any Editor to modify the IL code. You can find all the string values ( &#8220;Hello World&#8221; in this example ) as it is in the IL code. Modify it.( I am modifying it as &#8220;Hello World from IL Code&#8221;).
<p><div id="attachment_725" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/Notepad_IL.png"><img class="size-medium wp-image-725" title="IL Code - Notepad" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/Notepad_IL-300x150.png" alt="IL Code - Notepad" width="300" height="150" /></a><p class="wp-caption-text">IL Code - Notepad</p></div></li>
</ol>
<p>So we created the IL code and modified.<br />
<strong>Generate Assembly from IL code using ILASM.exe</strong></p>
<ol>
<li>Invoke the ILASM.exe with IL file as the parameter. <code>ilasm helloworld_il.il</code></li>
<li>It will show some details about assembling the IL code to assembly. And if the operation is successful you will get an exe in the location with HelloWorld_IL.exe.
<p><div id="attachment_723" class="wp-caption alignnone" style="width: 310px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code3.png"><img class="size-medium wp-image-723" title="Assembling the IL code to EXE" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/01/IL_Code3-300x151.png" alt="Assembling the IL code to EXE" width="300" height="151" /></a><p class="wp-caption-text">Assembling the IL code to EXE</p></div></li>
<li>If you invoke the exe from command prompt it will display the modified string instead of Hello World.(In this example &#8220;Hello World from IL Code&#8221;).</li>
</ol>
<p>You can do more if you know how IL works. Happy IL Programming <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/01/18/exploring-il-assembler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
