Code Disassembly and Reflection

One of the first tasks I was assigned when I started my new job was to recover some old source code that a contractor had developed for the company several years back. My company had working dll’s but no source code to make changes from. This was my first real exposure to Reflector and disassembling binary code. I’ll be honest, I got a real kick out of, the hacker mentality of my youth came flooding back but without any guilt because this was a legitimate (and legal) reason to disassemble code.

Since then, I’ve found Reflector to be an invaluable tool in a developer’s arsenal for the following scenarios:

  • Retrieving lost source code.
  • As a learning tool to peak into other, possibly more sophisticated code and code architecture.
  • To assist in troubleshooting third-party vendor software (which is certainly not immune to bugs).

These are just a few reasons, but all contribute to advancing your skill as a developer and worth to your client(s)/company.

Where can I get it and how much does it cost?

There probably are a couple out there, but I use Red Gate’s .NET Reflector which you can download a FREE copy.

Red Gate produces various other products that are useful, though many of them are not free.

How do I use it?

Glad you asked; Reflector is pretty easy to use. First, begin by opening Reflector, selecting File > Open and selecting a .NET based DLL that you would like to analyze. For demonstration, I will be using one of the nopCommerce DLL’s, Nop.Common.dll. (nopCommerce is a .NET open-source ecommerce project).

If the Disassemble panel is not already open, go ahead and open it now by right clicking on the assembly you just loaded, and selecting Disassemble.

By drilling down the tree-style panel on the left side, you can see all of the individual namespaces that comprise the DLL.

This takes a bit of digging, but with enough patience you can find what you are looking for. We will now select NopSolutions.NopCommerce.Common.Audit > LogManager to view the code in this class.

Next let’s move to the right side panel and scroll to the very bottom and click “Expand Methods”. This will allow us to see all of the code in the class. A nice touch is that you can view code in your language of preference, such as C# or VB.

You are now able to disassemble .NET code in a breeze, remember, “with great power, comes great responsibility”! Please make sure that whatever you are disassembling you have the right to disassemble it. Good luck on your next project.

Technorati code: zneh8mkst6

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s