Reverse engineer .Net assembly to a debuggable Visual Studio Project
This article was originally published for www.prowareness.com and could be located at http://www.prowareness.com/blog/reverse-engineer-net-assembly-to-a-debuggable-visual-studio-project/
I have always wanted to build tools supporting the command like switches like the classic CONVERT command with switches like /FS:, /CvtArea:, and so on. Couple of years back when I had to build one, I was in a hurry and my options for command line switch parsing (regex, or string splitting), didn’t look bright, back then; I went ahead with the regular string args array with no switches. For instance mine was like myprogram.exe ‘filename’ ‘30’, instead of the classic switch style command invoke myprogram.exe /filename:foo.file /iterations:30. Yeah I know it was the past, and we wouldn’t want to retrospect always. Besides, nobody would have even noticed the work that would have gone behind such an effort because we all seem to like the GUI most of the time, but hey what about self content.
This time, while I was playing with the command line options of CAT.Net and FxCop, and I thought why not just disassemble and study their command line switch parser. These programs must have been written on .Net. So, I opened up CatNetCmd.exe in JustDecompile, created a project out of it. Arguments.cs was the file I was after. Very neat command line switch parsing with SwitchHandler delegate. Well, so I had my first console application with switch enabled command line arguments. Ildasm.exe was the widely known option during the days of Inside C#, then came along .Net reflector (freeware then, commercial now). I seem to be biased to JustDecompile though, because of the Search, Ctrl+Click for Find Usages, Click to Go to Definition, on demand dll load prompt, and the Create Project… option that I present here.
Download the Free. For everyone. Forever JustDecompile from Telerik – http://www.telerik.com/products/decompiler.aspx. I am going to show you, how to create a Project out of CAT.Net, which is by default installed to C:\Program Files (x86)\Microsoft\CAT.NET\.
1. Right click CATNetCmd.exe and select Open with JustDecompile.
2. Once the assembly is loaded in JustDecompile, just right click and just click Create Project…
Well, Well, Well, Open the solution file, and start debugging already!
Btw, if you are up against command line parsing, and looking for a ready made solution, try https://commandline.codeplex.com/.