SIGN UP MEMBER LOGIN:    
ARTICLE

Protecting IL Code from unauthorised Disassembling

Posted by manish Mehta Articles | Security in .NET April 09, 2001
Microsoft .NET proved a mechanism where the code written in VB.NET, C# or any CLS compliant languages to generate MSIL (Microsoft Intermediate Language)code which targets the CLR and executes. This is an excellent mechanism to abstract the high level code from the underlying hardware.
Reader Level:

Microsoft .NET proved a mechanism where the code written in VB.NET, C# or any CLS compliant languages to generate MSIL (Microsoft Intermediate Language)code which targets the CLR and executes. This is an excellent mechanism to abstract the high level code from the underlying hardware.

What gets generated from the source file is a PE (Portable Executable) which will run on the CLR. Despite the advantages it offers, this mechanism faces a severe drawback of the MSIL which can get decompiled to the actual source code.

Microsoft tool ILDASM.EXE adds up to this problem by giving an option to output an .IL from an assembly, this file contains code resembling the actual source code hence posing a sever threat to the intelletual property of the company.

Lets understand this problem with an example

Class1.vb imports system

Namespace mynamespace
Class mclass
Shared Sub main()
console.writeline("hi from main")
End Sub
Public Function SayHi() As String
SayHi = "Hi from Function"
End Function
End Class
End Namespace 

This code when compiled generates a executable Class1.exe

vbc Class1.vb 

When you fire up ILDASM utility we can get to see the IL code which is read from the METADATA of the assembly.

To output .IL file from the assembly use the tool ILDASM

ILDASM Class1.exe /out=Class1.il 

The Class1.il file thus generated looks more then just junk code but a clear readable code properly structured and resembles the actual source code. This sample clearly shows the part of IL code generated from Class1.exe assembly. The method MAIN which prints "hi from Main" resembles the actual source code.

.method public static void main() il managed
{
// Code size 11 (0xb)
.maxstack 1
.locals init (
class System.Object[] V_0)
IL_0000: ldstr "hi from main"
IL_0005: call
void [mscorlib]System.Console::WriteLine(class System.String)
IL_000a: ret
}
// end of method mclass::main

Can an IL be reverse-engineered ?

Well, i think u must have guessed by now that reverse engineering code from IL is fairly straight forward.

Is there a way to protect the assembly from getting disassembled ?

Well, yes as for now the only method to protect the assembly is to use the tool ILASM with the /owner option.

Follow these steps to protect the assembly from getting disassembled

Step1: Generating IL ILDASM Class1.exe /out=Class1.il 

Step2: Setting the owner option ILASM /owner=abc Class1.il 

This will create the assembly Class1.exe with the owner as "abc", not try to open this assembly with ILDASM utility.

You will get a message saying "Copyrighted Material- can not disassemble"

This assembly can only be viewed by supplying the owner

ILDASM /owner=abc Class1.exe 

Once the compilers come with the /owner option, protecting the assembly will be much easier.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor