Look Without Asking
There are times where you want to know how something works but you can’t seem to find the source code. For instance, I was recently researching the A* algorithm and stumbled upon a great applet which seemed to do exactly what I wanted. Unfortunately, while the author published the applet and a javadoc about the underlying code he neglected to publish the source code itself. So what does a developer do? Roll up your sleeves and boot up your favorite decompiler!
What’s a decompiler
A decompiler takes compiled code and attempts to divine the source code which generated it. For languages such as Java and C# it turns out this is relatively easy due to the bytecode layer sitting between source code and machine language. As such there are decompilers which can produce code which looks almost exactly like the original.
Why would I want to do this?
It’s simple really. Reading descriptions or pseudocode is useful but sometimes you need to see the real deal. Unfortunately not everyone makes their code available. For instance, when someone writes a game and distributes it via Java webstart he may not release the code alongside it. In these circumstances it’s possible to download the jar file and decompile it to check things out.
A possibly less contentious example is if you work in a large company. If you are working with compiled code written by another team in your company using a decompiler is a legitimate way to find out more about your peer’s work. Oftentimes this is many orders of magnitude faster than tracking down the original author or scouring outdated documents.
Please be mindful when choosing to decompile someone’s code. I’m not a lawyer and cannot provide you any advice as to the legal status of this action. If possible try to gain access to the source code through the author directly instead.
Now What?
So let’s talk about some tools. For Java I’ve settled on the handy JD-GUI. It’s incredibly easy to use, simply point it to a jar file and voila. Unfortunately, it doesn’t have many features either, so if anyone knows of a better tool please let me know in the comments. It would be a great project (and an eternal service to the community) to create an improved decompiler for Java. Perhaps something more along the lines of our next tool…
If you’re writing in C# then please check out .NET Reflector. This tool is simply amazing, and I really wish there was an equivalent for Java. It combines the decompilation with reflection… genius!! Using this tool it’s possible to load several assemblies and jump around the code following method invocations, etc. I use this tool every day at work and would not be able to get things done without it.
In the past, when I heard about decompiling code I often thought of hackers in poorly lit rooms doing something illegal. The truth is that’s not the case. A decompiler is an important and useful tool which should be part of any developer’s tool chain, so check it out!
Related posts:
Hello, my name is Alex Schearer. I grew up in New York and currently live in Seattle. 
Just like how Superman can see through solid objects, you can now see through bytecode!
Haha yep, computers are cool!