A .Net Disassembler/Decompiler

A .net disassembler/decompiler

Have you looked at Reflector?

http://www.red-gate.com/products/reflector/

Best tool to decompile a C# .Net 1.1 application

Usually I use dnSpy or ILSpy.

You can try one of the following .Net decompiler (listed in no particular order)

  • dnSpy --- C# / VB / IL --- https://github.com/dnSpy/dnSpy
  • JustDecompile --- C# / VB / IL --- http://www.telerik.com/products/decompiler.aspx
  • ILSpy --- C# / IL --- https://github.com/icsharpcode/ILSpy
  • dotPeek --- C# / IL --- http://www.jetbrains.com/decompiler
  • .NET CodeReflect --- C# / VB / IL --- http://www.devextras.com/decompiler
  • DisSharp Decompiler --- C# / VB / IL --- http://netdecompiler.com/
  • Assembly Analyzer --- http://asmanalyzer.codeplex.com/

Here are also some IL decompiler for the real hardcore developer :-)

  • Dotnet IL Editor --- http://sourceforge.net/projects/dile/
  • MSIL Disassembler --- http://msdn.microsoft.com/en-us/library/f7dy01k1%28v=vs.80%29.aspx

You may also find some useful information on these answers:

  • Something better than .NET Reflector?
  • Open Source Alternatives to Reflector?

C# Decompilers?

It's mostly true. A very clever programmer named Lutz Roeder wrote an excellent decompiler named Reflector (now owned by redgate). It's quite good at translating IL back to either C# or VB.NET code. It isn't complete magic, it cannot

  • translate constants back to their constant identifier
  • recover the names of local variables
  • decompile anonymous methods except in their intermediate form
  • decompile iterators, as above
  • decompile lambdas, as above
  • decompile the code that uses the promised C# 5 async and await keywords, as above
  • recover the comments in your code.

And has a few bugs that makes it resort to goto statements or fall over. It is otherwise very useful as a debugging aid, helping you discover and diagnose bugs in code you didn't write. There are no documented cases of anyone using it to start a successful business from pirated source code obtained through decompilation. It works too well for that.

It has otherwise started a lively market segment for 'obfuscators', tools that rewrite the contents of an assembly to make it hard to decompile it. Typical strategies are to rewrite identifiers so they become very hard to interpret and/or to tinker with the structure of the assembly so a decompiler will crash but the CLR will not. Redgate, the current owner of Reflector, also sells an obfuscator. There is one included with Visual Studio paid licenses, called 'Dotfuscator Community Edition'. No idea how good it is, this never gets put to the test.

Just using lots of lambdas and iterators in your code is already an excellent way to obfuscate your code. Reverse-engineering it to the original code is very difficult. That Lutz gave up on Reflector at the exact same time he did is not a coincidence, that's when C# became too hard to decompile reliably.

How do I decompile a .NET EXE into readable C# source code?

Reflector and its add-in FileDisassembler.

Reflector will allow to see the source code. FileDisassembler will allow you to convert it into a VS solution.

Is there any C# decompiler that can show the coding almost identically to how it was written?

That is impossible, since there are lots of ways to get the same IL from different code. For example, there is no way to know if an extension method was called fluent-style vs explicit on the declaring type. There is no way to know if LINQ vs regular code was used. All manner of implicit operations may or may not be there. Removed code may or may not have been there. Many primitives (including enums) up-to-and-including 4 bytes are indistinguishable once they are IL.

If you want the actual code, legally obtain the original code.

How to decompile ASP.NET / C# Web Application

Following David's advice, I managed to get the application running from decompiled assemblies. Here's the process I followed to get it working

  1. I had already decompiled the various assemblies into projects using a Reflector (on a trial).
  2. I created a blank Web forms application in Visual Studio
  3. I added the .aspx pages from the website to the project through visual studio
  4. Then added the .cs files from the decompiled 'application.dll' project (since this is the website project within the solution. Some files had to be renamed to match the codebehind references in the `.aspx. files
  5. Each additional project e.g. applicationCore.dll was then added to the solution
  6. Each project's references needed to be updated and references to the newly added projects must be added to the startup project
  7. Since the website was built so long ago, there were 1,000's of syntax errors. The easiest way to resolve them was to use Notepad++ and the Find and Replace. To be safe, I did this file-by-file by following the errors from Visual Studio rather than a batch find and replace
  8. When trying to build I noticed errors where required assemblies were missing so I changed the build output directory of the sub-projects to the bin folder of the web project
  9. I added the connection strings and settings from the original website's web.config. I did this line by line to make sure I didn't break anything and so that I could trace the result of each addition
  10. Finally I had a successful build!

Additional Steps
There were also syntax errors which I assumed were due to the decompiling process. Some external references needed to be added and there were slight changes due to the age of the project e.g. asp:AjaxScriptControl changed to asp:ScriptControl (after adding the package using Nuget). I also had to install Crystal Reports for this application and will have to purchase a Telerik licence as there are UI components being used (although I'll see if I can use an open / native alternative as I work through the app).

I've logged in using credentials (I did have to set the correct start page) and tried a few basic CRUD operations. There are silly issues that have to be resolved e.g. the authentication doesn't work properly and there's no redirect if you access a protected page but these things are relatively minor compared to the issues I faced initially.

What I must say is each error was resolved using questions and answers from this site! This was all completed in just under 6 hours.



Related Topics



Leave a reply



Submit