Click here to monitor SSC

Laila Lotfi

.NET tools Brand Manager & Simple-Talk Editor

Back from the Dead - Recovering your Source

Published Thursday, November 05, 2009 4:36 PM

In this guest editorial, our very own Chris Allen brings us the first of hopefully many Thoughts from the Help Desk. As Halloween has just gone by, he decided it would be appropriate to discuss black magic, a frightening thought, and how to bring your source code back from the dead.

Attention all developers! Unless you're using a military-grade code-protection environment or a seriously sophisticated code-protection tool, your code is vulnerable to decompilation and disassembly; in short: all your source are belong to us. But everyone knows this, right? I didn't think I'd need to give anyone a wakeup call but, as I found out recently on the help-desk, there's still a smattering of people who still think compilation equals obfuscation. I have some sympathy with such n00bs; I can still remember the awe in which I held the first decompiler I ever used- one for the Psion's EPOC language. I wondered how on earth it was possible to reverse the process of compilation; Type and Data Flow Analysis sounded like so much black magic. But, as in law, ignorance is no defense. It will always be the case that dynamic code is vulnerable to decompilation and discovery (with the honorable exceptions above), and this is especially true with interpreted languages. So, I write this so that we can all draw a line under any illusions we've clung to, deal with this fact of developer life and then - embrace it! Soon enough, you'll be very glad of it - for example, recently my colleague gave me a small application that did a great job of customizing our SQL Compare engine. He only had the runtime assembly and had lost the source code but I really needed to understand what he had done - one quick flick of the wrist later and Reflector had not only recovered the source, but had created the Visual Studio project for it too (I *really* love that feature)! And I've heard many other stories about why Reflector is so useful - the one comment that sticks in my mind is from the developer who said, "If it wasn't for Reflector, I'd be doing a different job".

So how does this 'Dark Art' work? As I say- code has always been vulnerable and "reversible" but, until the invention of the technology behind intermediate languages (such as the .NET languages), the job of reversing the code was akin to decryption (think WWII, "Enigma" code-breaking; better still, don't think - just watch the film :-) ).  Intermediate languages don't directly generate the machine code (which is the really hard bit to reverse-engineer)- they generate "IL", each line of which has a reasonably clear derivation (often a one-to-one correspondence with source code, in fact). This intermediate level of code is generally relatively easy to pull apart, and if you find this technology a little frightening, it's maybe comforting to know that decompilation is not an exact science. There isn't a 100% one-to-one correspondence and, sometimes, decompilation is equivalent to the classic Halting problem. It's still hard to do very well, but we think we're still on top of the game. Welcome to Reflector Pro.

-Guest post by Chris Allen

by Laila

Comments

 

wkhazzard said:

My most memorable reverse engineering was when ADO.NET began including membership and role providers, they made the SQL role provider 2-tiered so it couldn't be used from a web application that had to traverse a middle tier for security reasons.

We reverse engineered the SQL role provider for ADO.NET, split the SQL-specific code off into a separate assembly. Then we exposed those interfaces through .NET remoting (this was pre-WCF) for access from the web tier. Voila! The ADO.NET SQL role provider was now n-tier friendly.
November 9, 2009 5:41 AM
 

slaphead99 said:

Cool post- thanks! Did you use .NET Reflector?
December 21, 2009 11:01 AM
You need to sign in to comment on this blog

About Laila

I'm working for the .NET Tools division at Red Gate. These days, I'm spending most of my time working on SmartAssembly (.NET obfuscator, error reporting and feature usage reporting tool), and I'm currently looking to speak to anyone who has used the product for its error reporting technology. My email address: editor@red-gate.com
<November 2009>
SuMoTuWeThFrSa
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. Wesley David... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across and started getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...