将 IL 转换为 C# 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/648051/
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-04 11:40:21  来源:igfitidea点击:

Converting IL to C# code

c#.net

提问by Embedd_Khurja

I need to convert the IL to c# code. I have an assembly and I am reading this assembly. I get MethodBody from MethodInfo and the methodbody has a method GetILAsByteArraY() which returns a byte array now I want to convert this IL to C# code. Please help me out in solving this.

我需要将 IL 转换为 c# 代码。我有一个程序集,我正在阅读这个程序集。我从 MethodInfo 获取 MethodBody 并且 methodbody 有一个方法 GetILAsByteArraY() ,它返回一个字节数组,现在我想将此 IL 转换为 C# 代码。请帮我解决这个问题。

采纳答案by jason

Don't reinvent the wheel; use Lutz Roeder's .NET Reflector.

不要重新发明轮子;使用 Lutz Roeder 的.NET Reflector

回答by Pontus Gagge

Let's see if I manage to get it in first: .NET Reflector! This really should be a FAQ...

让我们看看我是否能够首先获得它:.NET Reflector!这真的应该是一个常见问题...

回答by Ward Werbrouck

Can't you do this with Reflector?

你不能用Reflector做到这一点吗?

You can load an assembly and view it as VB.net/C#/IL...

您可以加载程序集并将其视为 VB.net/C#/IL...

回答by BC.

You should just use .NET Reflectorif you have the assembly. Also try the file gen addon.

如果你有程序集,你应该只使用.NET Reflector。还可以尝试文件 gen 插件。

回答by JoshBerke

There is no tool in the BCL that will do this; however, there is a great tool called Reflector, which you can write your own add-ins for. So you could probally use this to get the data you want.

BCL 中没有工具可以做到这一点;但是,有一个很棒的工具叫做Reflector,您可以为它编写自己的加载项。所以你可能会用它来获取你想要的数据。

回答by John Saunders

Reflectordoes this. Perhaps you could use Reflector against Reflector and learn how it handles the problem.

反射器就是这样做的。也许您可以使用 Reflector 来对抗 Reflector 并了解它如何处理问题。

You might also say why you want to do this - there may be a better solution to your overall problem.

您可能还会说为什么要这样做 - 可能有更好的解决方案来解决您的整体问题。

回答by John Saunders

Let me be the first to suggest you grab a copy of Red Gate's Reflector.

让我成为第一个建议您获取 Red Gate's Reflector 副本的人。

回答by Achilles

Maybe you should try Dis# if you don't wanna re-invent the wheel... It's almost the best tool in converting the code NetDASM has a tool that lets you convert C# to IL. maybe you should take a look at that.

如果您不想重新发明轮子,也许您应该尝试 Dis#...它几乎是转换代码的最佳工具 NetDASM 有一个工具可以让您将 C# 转换为 IL。也许你应该看看那个。

回答by Javed S

Re-Inventing the wheel surely a better way to learn! you will have to create your own class that would convert iL to C#.This requires the knowledge of Intermediate language.

重新发明轮子肯定是一种更好的学习方式!您必须创建自己的类,将 iL 转换为 C#。这需要中级语言的知识。

I assume you have already converted the Byte Array to IL instructions just like we see in ildasm.exe,Using Reflection.Emit.OpCodes,OpCode.OperandType,BitConvertor.ReadByte(),BitConvertor.ReadInt32 etc.

我假设您已经将字节数组转换为 IL 指令,就像我们在 ildasm.exe 中看到的那样,使用 Reflection.Emit.OpCodes,OpCode.OperandType,BitConvertor.ReadByte(),BitConvertor.ReadInt32 等。

回答by Julien Roncaglia

If you want to do it yourself, you could start from the old Cecil.Decompiler and enhance it, see the source codeand an old post of Jb. Evain announcing the project(Link down).

如果你想自己做,可以从旧的Cecil.Decompiler开始,增强它,查看源代码Jb的一个旧帖子。Evain 宣布该项目(链接关闭)。