Friday, June 17, 2011

Helpful tools for the weary programmer Part 2

Hi All,

This is the second part of my review of the tools I use in my daily work. If you likes the first part you will surely like the second.

Code decompilation or disassembly
The third category of useful tools are disassembly tools. If I were to make this post couple of months ago it would probably contain only Red-Gate Reflector but recently Red-Gate decided to charge money for even the basic version of Reflector so I will survey two alternative tools which are currently in the beta stage. 

The first tool comes from the guys at #Develop and is called ILSpy. ILSpy can take a compiled .NET assembly and regenerate the original code (or at least something close to the original). In the current beta it can show you the code in both C# and IL and it is quite accurate in the generated code. You can save the generated code to a code file easily from the menu. ILSpy supports search and navigation directly from the code editor and browsing of dependent dlls. One of the big tests of a decompiler is the ability to decompile itself which ILSpy does perfectly.

Another contender to the crown comes from the guys at JetBrains (the ones who make ReSharper) in the form of dotPeek. The UI of dotPeek looks similar to ILSpy (and to Reflector) but offers richer menus. I found it somewhat difficult to navigate through the code editor and had to search through the context menu items. At times the navigation didn't work at all. The generated code was quite accurate and at some places clearer than the code generated by ILSpy. It had no difficulty in decompiling itself 

The third tool comes from Telerik and is called justDecompile. Currently it is in the Beta stage and free. The UI is again similar although somewhat slick. I didn't manage to get any useful data with this tool as it failed to decompile even the simplest of codes. It is clearly not ready for real user but definitively worth to keep in mind.

This list cannot be complete without ILDasm (the tool that comes with .NET, search ildasm in your Everything). I like this tool because you are able to view the manifest of a dll in a convenient way. You can also use it to check the dependencies of a specific dll but only for one level. The biggest disadvantages of this tool is that the code is decompiled into IL and there is no easy navigation between assemblies or even within the same assembly.

ILSpy decompilation of the Object class

dotPeek decompilation of the Object class

justDecompile decompilation of the Object class

Snooping/Spying a running application
You probably know the following scenario: you add some control to your application and see it well in the designer but when the application is run it is nowhere to be found,or a scrollbar appears out of nowhere and you have no idea which control shows it. It is simple to see the dynamic structure of your running application while it runs using one of the following tools:
Spy++ for Win32 based applications (anything which is GDI based and not drawn by DirectX). This tool is installed with Visual Studio and is easy to use. When you run it, it shows all the window handles of your top level windows in a tree and you can drill down to the smallest of windows (in GDI everything is a window). You can highlight a certain window by using its handle or find a certain window by pointing at it with the mouse (using the find target tool). When the window is found you can track all the messages sent to that window.

If you try to use Spy on a WPF application you will have a surprise on your hands. Any WPF Window contains only one GDI window because the rendering is done internally using DirectX. In order to inspect a WPF application I use a different tool called Snoop. This tool is essentially like Spy (but somewhat closer to Firebug). Pointing Snoop on a WPF application will give you the full Visual Tree of this application. For each item in this tree you will be able to see and sometimes edit its properties. Snoop will also tell you who set each property so you will finally be able to see which animation stuck the height of your button.

Snooping justDecompile which decompiles the Object class

These are the main tools I use in my daily work. I very much recommend that you try each of the mentioned tools at least once to see if it is useful for you.

Thank you for reading