将 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
Converting IL to C# code
提问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
回答by BC.
You should just use .NET Reflectorif you have the assembly. Also try the file gen addon.
如果你有程序集,你应该只使用.NET Reflector。还可以尝试文件 gen 插件。
回答by JoshBerke
回答by John Saunders
回答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 宣布该项目(链接关闭)。