ChatGPT解决这个技术问题 Extra ChatGPT

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

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?

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 ...
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/JustDecompileEngine

U
Umar Farooq Khawaja

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.


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?
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.
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. x
Where is FileDisassembler ? :/
It work for .Net framework only. any tool which work for .Net core 3.0 exe ?
D
Daniel

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


I'm using 2.2 and it supports decompiling to IL, VB.NET, and C#. I found this very useful.
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.
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.
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!
ILSpy is the best one
V
VoteCoffee

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


Reflector is like 35$. Breaking the bank I know, but its worth 10x that.
It's worth adding Telerik JustDecompile to the list of free .NET assembly decompilers, too. telerik.com/justdecompile
@StingyJack: Great, looks like they heard you! It's now actually 10 the price at $368 if you want the VS2012 disassembler. :/
I dont hold it against them for making money, but ILSpy (mentioned) in @Daniel's answer is what I am using now.
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-source
P
ProfK

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.


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.1
so dotPeek is totally free or they have restrictions for paid version?. i couldnt see any information on jetbrains website regarding it.
k
kodefuguru

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


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.
I tried all the solutions here in this post and JustDecompile was the only one that works perfectly for me.
y
yoyo

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):

Select Start > All Programs > Visual Studio 2013 > Visual Studio Tools. Double-click on Developer Command Prompt for VS2013. Run "ildasm" from the resulting command prompt. 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.


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?
I never claimed ildasm was the best option out there, only that it's available and it works. ¯_(ツ)_/¯
Nope, 'fraid not.
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.
L
Luke Halliwell

You want reflector.


N
Noteworthy

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.


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#.
P
Patrick from NDepend team

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.