41

Are there any tools available to take an already compiled .dll or .exe file that you know was compiled from C# or Visual Basic and obtain the original source code from it?

2
  • 1
    ILSpy is probably the best choice (IMHO)
    – jyz
    Mar 20, 2013 at 18:15
  • 1
    Because decompiling .net is very easy most .net code is protected or obfuscated. So in order to use any of the tools suggested in the answer you must remove this protection (if present) first.
    – Remko
    Mar 20, 2013 at 19:38

8 Answers 8

50

ILSpy is a great open-source decompiler.

ILSpy Features

  • Assembly browsing
  • IL Disassembly
  • Support C# 5.0 "async"
  • Decompilation to C#
  • Supports lambdas and 'yield return'
  • Shows XML documentation
  • Decompilation to VB
  • Saving of resources
  • Save decompiled assembly as .csproj
  • Search for types/methods/properties (substring)
  • Hyperlink-based type/method/property navigation
  • Base/Derived types navigation
  • Navigation history
  • BAML to XAML decompiler
  • Save Assembly as C# Project
  • Find usage of field/method
  • Extensible via plugins (MEF)
  • Assembly Lists
1
  • 1
    Combine it with this useful add-on for Visual Studio SourceFly so you can open ILSpy from Visual Studio. Though it doesn't support Visual Studio 2012 in its latest release.
    – Joseph
    Mar 22, 2013 at 4:48
25

I've used JetBrains dotPeek (free of charge) before with some success.

Any JetBrains software I've ever used has been very solid.

It is not quite the 'original source' but it is very readable C# - about the closest thing I would expect to get. Quote from their website:

What's Cool about dotPeek?

  1. Decompiling .NET 1.0-4.5 assemblies to C#
  2. Support for .dll, .exe, .zip, .vsix, .nupkg, and .winmd files
  3. Quick jump to a type, assembly, symbol, or type member
  4. Effortless navigation to symbol declarations, implementations, derived and base symbols, and more
  5. Accurate search for symbol usage with advanced presentation of search results
  6. Overview of inheritance chains
  7. Support for downloading code from source servers
  8. Syntax highlighting
  9. Complete keyboard support
  10. dotPeek is free!

The last point is free as in free beer, not as in free speech.

14

Recently I've been using dnSpy [forked from ILSpy by the creator(s) of de4dot] as my main tool for the decompiling and live debugging of .NET code

https://github.com/0xd4d/dnSpy


Main difference from ILSpy :

  • Uses dnLib to read assemblies (vs ILSpy's Mono.Cecil)

https://github.com/0xd4d/dnlib

dnlib was created because de4dot needed a robust .NET assembly library that could handle all types of obfuscated assemblies. de4dot used to use Mono.Cecil but since Mono.Cecil can't handle obfuscated assemblies, doesn't fully support mixed mode assemblies, doesn't read .NET assemblies the same way the CLR does and many other missing features de4dot needed, dnlib was a necessity. The API is similar because it made porting de4dot to dnlib a lot easier.

5
11

There is a free tool available called JustDecompile which does that.

Some features:

  • Creating a Visual Studio project from an assembly in order to export lost projects or obtain multiple classes without the need to copy and paste code. At present, JustDecompile is able to export decompiled code only to C#.
  • Exporting code directly from the command prompt
  • Quickly loading core .NET assemblies (.NET 2, .NET3.5, .NET 4, .NET 4.5, WinRT Metadata and Silverlight)
  • Directly editing assemblies loaded into the program
1
  • JustDecompile has a De4Dot Deobfuscator plugin that will help with obfuscated exe Aug 24, 2017 at 21:18
9

I have used .NET Reflector (Note: Commercial, but trial available) several times and quite like it:

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

1
  • 7
    Some examples of use cases would be a good addition to this answer. Currently, it is too vague to be of much use besides offering a tool and its website. Giving some real use examples helps define the product a little better.
    – JMcAfreak
    Mar 20, 2013 at 17:09
3

If you are interested into a decompiler on API level: https://code.google.com/p/facile-api/ (in Java though)

4
1

I would second the answer about ILSPY as being a really great.net decompiler. Also, checkout de4dot for deobfuscation. This is a cool writeup of it in action. http://blogs.cisco.com/security/talos/reversing-multilayer-net-malware

Compiled visual basic can be a different and painful animal. http://vrt-blog.snort.org/2014/08/discovering-dynamically-loaded-api-in.html?m=1

2
  • 1
    How is compiled Visual Basic (6) related to .NET? Mar 24, 2015 at 22:04
  • The original question asked about Visual Basic as well.
    – tyh
    Mar 25, 2015 at 18:47
-1

.NET assemblies (.exe and .dll) can be decompiled online at Decompiler.com

The author is affiliated with the mentioned website it appears (username: www.Decompiler.com).

3
  • "Post good, relevant answers, and if some (but not all) happen to be about your product or website, that’s okay. However, you must disclose your affiliation in your answers." Sep 21, 2020 at 5:52
  • @PawełŁukasik given the username, I think that qualifies as disclosure, no? But I'll also add a note, in case the username ever changes 😉 ... but I do find the answer lacking. I'll ask the other mods to have a look and ask their advice. I feel a downvote is enough, though.
    – 0xC0000022L
    Sep 28, 2020 at 19:45
  • @0xC0000022L I like things to be explicit, but agree it might have been enough. Thx for the edit anyway. Sep 29, 2020 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.