使用Reflector API获取反编译源代码
我正在寻找一些允许反编译 .NET 程序集以获取源代码的框架。
我知道 Reflector 提供了某种 API 来对程序集执行操作,当我使用它时,我似乎只得到 IL 指令,而不是实际的源代码。
我想做的是设置某种智能的未处理异常处理程序,这将使我得到失败的代码行(用于内部调试目的)。
使用 Reflector API 可以实现这一点吗?为此还有哪些其他工具可用?
I am looking for some framework that allows decompiling a .NET assembly to get the source code.
I know Reflector offers some sort of API to perform operations on assemblies, when i used it it seems that i only get back IL instructions and not actual source code.
What i would like to do is set some sort of smart unhandled exception handler, that will get me the failing lines of code (for internal debugging purposes).
Is this possible using the Reflector API? what other tools are available to this end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我写了几篇文章,可能对您有所帮助。
http://www.simple -talk.com/dotnet/.net-framework/-.net-reflector-meets-the-codedom/ 谈论如何为 Reflector 创建您自己的语言以进行拆卸。这对于 Reflector 将抛出的语言结构非常有用。
http:// www.simple-talk.com/dotnet/.net-tools/hosting-.net-reflector-in-your-own-application/ 讨论在您自己的代码中托管 Reflector 以使用 API。这将引导您完成在反射器中访问 API 并访问其逻辑的过程。
我希望这至少可以帮助您指明获得所需内容的方向。
I wrote a couple of articles that may be helpful for you in doing this.
http://www.simple-talk.com/dotnet/.net-framework/-.net-reflector-meets-the-codedom/ talks about creating your own language for Reflector to disassmeble to. This is useful for walking language structures that Reflector will throw up to.
http://www.simple-talk.com/dotnet/.net-tools/hosting-.net-reflector-in-your-own-application/ talks about hosting Reflector in your own code to use the API. This will step you through the process of accessing the API in reflector and accessing its logic.
I hope this helps at least point you in the direction to get what you need.
您可以查看(开源)ILSpy。由于他们能够满足您的要求,并且还提供源代码,因此您应该能够以此为起点。
You could take a look at the (Open Source) ILSpy. Since they are able to do what you require and they also provide source code, you should be able to take this as a starting point.
我不确定我是否理解您的需要,但是如果您想要有关异常发生位置的运行时信息,您可以使用
StackTrace
和StackFrame
类在 < code>System.Diagnostics 命名空间从调用堆栈中检索信息。但不幸的是,您不会获得明文形式的源代码。I´m not sure that I understand what you need, but if you want runtime information about where an exception occured, you can use the
StackTrace
andStackFrame
classes found in theSystem.Diagnostics
namespace to retreive information from the call stack. But unfortunately, you will not get the source code in clear text.