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

10

295

I wrote a C# application for a client a couple of years ago, but I no longer have the source code. All I have is the EXE that I deployed on the client's PC. Is there a way I can generate C# source code from the EXE?

Stellastellar answered 7/10, 2008 at 18:27 Comment(2)
Ok. Look here ... Teleriks JustDecompile actually decompiled the DLL's that Red Gates Reflector completely screwed up ... there were numerous issues with Reflector ... JustDecompile ... flawless so far ...Filomenafiloplume
I have been using JustDecompile for quite a long time and it is really good at decompiling and package the source files as a ready to compile csproject. It is really active in development and there seems to be no open issues in their repo github.com/telerik/JustDecompileEngineIfc
S
211

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.

Skolnik answered 7/10, 2008 at 18:28 Comment(5)
My copy of Reflector has an "Export..." option and I have no plug-ins installed. It creates a VS project with all the source code and resources. So why is everyone suggesting FileDisassembler? It is better?Tabbatha
Lucas: Out of the box, I have not seen reflector able to do this. FileDisassembler has always been the only way. This may have changed in recent history though I guess. I will check it out.Skolnik
LIFE SAVER! dumb ass TFS deleted my project. Although I did tell TFS to delete itself but didnt expect it to remove the project from the local file system. thanks all the same. xWrapping
Where is FileDisassembler ? :/Moslem
It work for .Net framework only. any tool which work for .Net core 3.0 exe ?Zapateado
T
169

When Red Gate said there would no longer be a free version of .Net Reflector, I started using ILSpy and Telerik's JustDecompile. I have found ILSpy to decompile more accurately than JustDecompile (which is still in Beta). Red Gate has changed their decision and still have a free version of .Net Reflector, but now I like ILSpy.

From the ILSpy website (https://github.com/icsharpcode/ILSpy/):

ILSpy is the open-source .NET assembly browser and decompiler.

ILSpy Features

  • Assembly browsing
  • IL Disassembly
  • Decompilation to C#
  • Supports lambdas and 'yield return'
  • Shows XML documentation
  • Saving of resources
  • 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)

Update:

April 15, 2012, ILSpy 2.0 was released. New features compared with version 1.0:

  • Assembly Lists
  • Support for decompiling Expression trees
  • Support for lifted operatores on nullables
  • Decompile to Visual Basic
  • Search for multiple strings separated by space (searching for "Assembly manager" in ILSpy.exe would find AssemblyListManager)
  • Clicking on a local variable will highlight all other occurrences of that variable
  • Ctrl+F can be used to search within the decompiled code view

Update:

  • ILSpy 2.1 supports async/await decompilation
Torrey answered 5/10, 2011 at 16:38 Comment(5)
I'm using 2.2 and it supports decompiling to IL, VB.NET, and C#. I found this very useful.Sama
It seems Telerik is interested in collecting questionable information from the computer running on it and ILSpy cannot be compiled from sources. Also ILSpy binary mixes up variable names and puts some strange characters in the source code.Altagraciaaltaic
Note that ILSpy includes a Visual Studio add-in. For ILSpy 2.4 I added the ability to navigate from your Visual Studio source code direct to the decompiled output. Unfortunately there were some late-breaking fixes that are now merged to the ILSpy mainline but did not make the 2.4 release.Forehanded
Brilliant! There's a software company that charge people £100 a time for them to use a "special" tool on your sever in order to fix issues. Managed to get a copy of the tool they used while connected, and then managed to use ILSpy very easily to get the tool unlocking password. No more ripping off customers!Balk
ILSpy is the best onePulmonary
F
70

Reflector is no longer free in general, but they do offer it for free to open source developers: http://reflectorblog.red-gate.com/2013/07/open-source/

But a few companies like DevExtras and JetBrains have created free alternatives:

DevExtras CodeReflect

JetBrains DotPeek

Farceuse answered 7/6, 2011 at 13:40 Comment(6)
Reflector is like 35$. Breaking the bank I know, but its worth 10x that.Annulet
actually the alternatives listed here work better than Reflector, at least for some kinds of obfuscation.Bossism
It's worth adding Telerik JustDecompile to the list of free .NET assembly decompilers, too. telerik.com/justdecompileCostive
@StingyJack: Great, looks like they heard you! It's now actually 10 the price at $368 if you want the VS2012 disassembler. :/Kosher
I dont hold it against them for making money, but ILSpy (mentioned) in @Daniel's answer is what I am using now.Annulet
It now costs $100 for the standard version and $200 for the version that integrates with Visual Studios. That's a heck of an inflation rate. Although they do offer stuff for free to open source developers: reflectorblog.red-gate.com/2013/07/open-sourceSama
P
39

Reflector and the File Disassembler add-in from Denis Bauer. It actually produces source projects from assemblies, where Reflector on its own only displays the disassembled source.

ADDED: My latest favourite is JetBrains' dotPeek.

Pooley answered 7/10, 2008 at 18:32 Comment(2)
I like that dotPeek allows working with an entire folder easily, but as of today they only decompile to c#. Most other decompilers also do vb and IL. It also only supports up to Net 4.5 whereas Telerik supports 4.5.1Sama
so dotPeek is totally free or they have restrictions for paid version?. i couldnt see any information on jetbrains website regarding it.Blockbusting
T
30

Telerik JustDecompile is free and has a feature to create projects from .NET assemblies.

Translation answered 15/8, 2011 at 19:16 Comment(2)
Telerik offers the ability to decompile to VB.NET, IL, or C#.NET which I found useful. It also auto-selects the framework and has a plug-in available for deobfuscicating. Also, it support .NET 4.5.1. Seems pretty good.Sama
I tried all the solutions here in this post and JustDecompile was the only one that works perfectly for me.Sorgo
F
29

I'm surprised no one has mentioned Microsoft's ildasm. It may not be as pretty as ILSpy or Reflector, but it comes with Visual Studio so many developers already have it.

To run it (assuming VS 2013, should be similar for other versions):

  1. Select Start > All Programs > Visual Studio 2013 > Visual Studio Tools.
  2. Double-click on Developer Command Prompt for VS2013.
  3. Run "ildasm" from the resulting command prompt.
  4. In the tool, select File > Open and open your executable or DLL.

Now you can navigate the DLL structure. Double-click on class members to see the IL. Use File > Dump to export IL to a file.

Forehanded answered 24/3, 2015 at 17:24 Comment(4)
I find IL DASM to be a bit barbaric. It shows the tree , but when right clicking does nothing I find that insane. Plus the Dump of the export to file is basically garbage. Look at it, how it that even remotely helpful?Moslem
I never claimed ildasm was the best option out there, only that it's available and it works. ¯_(ツ)_/¯Forehanded
Nope, 'fraid not.Forehanded
I was really surprised that dotPeek would not let me search the whole Assembly for a string I knew was in there. ildasm may not be pretty but at least it has a dump option that helped me locate the class that contained the string I was looking for.Emulsoid
N
15

You want reflector.

Nystrom answered 7/10, 2008 at 18:28 Comment(0)
S
12

I'm surprised no one has mentioned dnSpy. dnSpy is a debugger and .NET assembly editor. You can use it to edit and debug assemblies even if you don't have any source code available.

Main features:

  • Debug .NET and Unity assemblies
  • Edit .NET and Unity assemblies
  • Light and dark themes

It is open source and one of most widely used reverse engineering tool for dot net.

Skillful answered 28/9, 2020 at 8:53 Comment(1)
not sure why I got downvoted, I am simply listing a tool which is used by most dotnet reverse engineers today. And IMHO, it does answers the question the question which is getting the source code of an app compiled in C#.Skillful
D
8

There are various .NET / C# Decompilers available nowadays (2022):

  • ILSpy for everyone [free OSS C# IL multi-platforms]
  • dotPeek for convenient decompilation [free C# IL]
  • dnSpy for gurus, security and hackers [free OSS C# VB IL]
  • JustDecompile for everyone [free OSS C# VB IL] (continued as CodemerxDecompile)
  • IldAsm for nostalgia [free IL]
  • .NET Reflector for history [commercial unsupported C# VB IL MC++]

My preference goes to ILSpy because it is free, OSS, very fast (compared to others), so well maintained it is even used by Visual Studio and decompiled code is accurate. This blog post In the Jungle of .NET Decompilers explains in details all these .NET decompilers.

Dilan answered 17/3, 2022 at 5:48 Comment(0)
B
2

CodemerxDecompile is the continuation of JustDecompile. It uses the same engine but updated for the latest versions of the .NET framework. And it is truly multi-platform running on Windows, Mac and Linux employing AvaloniaUI.

Sadly, JustDecompile has been abandoned for years now. There has been no release with new features since 2017. Lately the open source decompilation engine was removed from gitHub too.

The original team revived it with CodemerxDecompile stepping on the last public version of the open source decompilation engine and building on top of it.

Bourgeoisie answered 21/3 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.