如何将 .NET EXE 反编译为可读的 C# 源代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/179741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:49:53  来源:igfitidea点击:

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

c#.netreverse-engineeringdecompiling

提问by MusiGenesis

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?

几年前我为客户编写了一个 C# 应用程序,但我不再拥有源代码。我所拥有的只是我在客户端 PC 上部署的 EXE。有没有办法从 EXE 生成 C# 源代码?

采纳答案by GEOCHET

Reflectorand its add-in FileDisassembler.

Reflector及其插件FileDisassembler

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

反射器将允许查看源代码。FileDisassembler 将允许您将其转换为 VS 解决方案。

回答by Luke Halliwell

You want reflector.

你想要反射器

回答by ProfK

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

Reflector 和来自 Denis Bauer的File Disassembler插件。它实际上从程序集生成源项目,其中 Reflector 本身仅显示反汇编的源。

ADDED: My latest favourite is JetBrains' dotPeek.

补充:我最近最喜欢的是 JetBrains 的dotPeek

回答by arc

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/

Reflector 通常不再免费,但他们确实向开源开发人员免费提供:http: //reflectorblog.red-gate.com/2013/07/open-source/

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

但是像 DevExtras 和 JetBrains 这样的一些公司已经创建了免费的替代品:

DevExtras CodeReflect

DevExtras CodeReflect

JetBrains DotPeek

JetBrains DotPeek

回答by kodefuguru

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

Telerik JustDecompile是免费的,并且具有从 .NET 程序集创建项目的功能。

回答by Daniel

When Red Gate said there would no longer be a free version of .Net Reflector, I started using ILSpyand 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.

当 Red Gate 说不再有免费版本的 .Net Reflector 时,我开始使用ILSpy和 Telerik 的JustDecompile。我发现 ILSpy 比 JustDecompile(仍处于 Beta 版)更准确地反编译。Red Gate 改变了他们的决定,仍然有一个免费版本的 .Net Reflector,但现在我喜欢 ILSpy。

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

从 ILSpy 网站(https://github.com/icsharpcode/ILSpy/):

ILSpyis the open-source .NET assembly browser and decompiler.

ILSpy是开源的 .NET 程序集浏览器和反编译器。

ILSpy Features

ILSpy 功能

  • 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)
  • 装配浏览
  • IL 拆解
  • 反编译为 C#
  • 支持 lambdas 和“收益回报”
  • 显示 XML 文档
  • 节约资源
  • 搜索类型/方法/属性(子字符串)
  • 基于超链接的类型/方法/属性导航
  • 基本/派生类型导航
  • 导航历史
  • BAML 到 XAML 反编译器
  • 将程序集另存为 C# 项目
  • 查找字段/方法的用法
  • 可通过插件扩展 (MEF)

Update:

更新:

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

2012年4月15日,ILSpy 2.0发布。与 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
  • 装配清单
  • 支持反编译表达式树
  • 支持可空值的提升运算符
  • 反编译为 Visual Basic
  • 搜索以空格分隔的多个字符串(在ILSpy.exe 中搜索“Assembly manager”会找到AssemblyListManager)
  • 单击局部变量将突出显示该变量的所有其他出现
  • Ctrl+F 可用于在反编译代码视图中进行搜索

Update:

更新:

  • ILSpy 2.1 supports async/await decompilation
  • ILSpy 2.1 支持 async/await 反编译

回答by 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.

我很惊讶没有人提到微软的ildasm。它可能不如 ILSpy 或 Reflector 漂亮,但它随 Visual Studio 一起提供,因此许多开发人员已经拥有它。

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

运行它(假设 VS 2013,其他版本应该类似):

  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.
  1. 选择开始 > 所有程序 > Visual Studio 2013 > Visual Studio 工具。
  2. 双击 VS2013 的开发人员命令提示符。
  3. 从结果命令提示符运行“ildasm”。
  4. 在该工具中,选择文件 > 打开并打开您的可执行文件或 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.

现在您可以浏览 DLL 结构。双击班级成员以查看 IL。使用 File > Dump 将 IL 导出到文件。