17.07.2015 Views

Understanding .NET code obfuscation - Red Gate Software

Understanding .NET code obfuscation - Red Gate Software

Understanding .NET code obfuscation - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introducing <strong>obfuscation</strong>The .<strong>NET</strong> framework helps developers by managing memory usage, threads and exceptions for them,as well as providing other features that can help them write stable <strong>code</strong> faster. That’s great, but from anintellectual property point-of-view, it comes at a price.Traditionally, <strong>code</strong> written by developers was compiled to a binary format that computers could execute.That binary format had to target a specific CPU architecture and bitness, which could complicatereleases, and make it difficult for end-users to install your program. Crucially, however, once in a binaryform, it was very difficult to reverse-engineer it to obtain the original source <strong>code</strong>.In .<strong>NET</strong>, <strong>code</strong> is instead compiled to an Intermediate Language (IL) for distribution. Whenthe executable or DLL containing IL is run by an end-user, the .<strong>NET</strong> Just-In-Time compiler(JIT) is activated, and compiles the IL to binary format when it is needed. The advantage isthat you only have to distribute one version of the software; JIT will ensure that the resultingbinary targets the architecture of the user’s computer. The disadvantage is that decompilingthe distributed IL to obtain the source <strong>code</strong> is trivial.Decompilingthe distributedassembly istrivialDecompiling .<strong>NET</strong> <strong>code</strong>To demonstrate how easy it is to decompile IL, let’s take a look at a real example. This example usesan application called QueryBee (a <strong>Red</strong> <strong>Gate</strong> tutorial application) but the principle is the same for anyunobfuscated managed <strong>code</strong>.1. Open QueryBee.exe with <strong>Red</strong> <strong>Gate</strong>’s .<strong>NET</strong> Reflector or with Ildasm.exe to see the IL it contains:.method private hidebysig instance void m_ComboDatabase_TextChanged(object sender, class [mscorlib]System.EventArgs e) cil managed{.maxstack 8L_0000: nopL_0001: ldarg.0L_0002: ldfld class [System.Windows.Forms]System.Windows.Forms.Button QueryBee.ConnectForm::m_connectButtonL_0007: ldarg.0L_0008: ldfld class [System.Windows.Forms]System.Windows.Forms.ComboBox QueryBee.ConnectForm::m_ComboDatabaseL_000d: callvirt instance string [System.Windows.Forms]System.Windows.Forms.Control::get_Text()L_0012: ldstr ""L_0017: call bool [mscorlib]System.String::op_Inequality(string, string)L_001c: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Enabled(bool)L_0021: nopL_0022: ret}2. Use .<strong>NET</strong> Reflector to decompile the IL to C#, Visual Basic .<strong>NET</strong>, or any other managed language:If you investin .<strong>NET</strong> <strong>code</strong>,you need anobfuscatorprivate void m_ComboDatabase_TextChanged(object sender, EventArgs e){this.m_connectButton.Enabled = this.m_ComboDatabase.Text != "";}Note that the source <strong>code</strong> shown by .<strong>NET</strong> Reflector isn’t exactly the same as the original, butit is sufficiently similar that any developer can see how the <strong>code</strong> works.The conclusion should be clear: if your program has any intellectual property that yourcompany values (for example, algorithms that distinguish your product’s accuracy from itscompetitors), this ability is undesirable.Put simply, if your company invests in .<strong>NET</strong> <strong>code</strong>, you need an obfuscator to protect it.© <strong>Red</strong> <strong>Gate</strong> <strong>Software</strong>Oct. 24, 2011 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!