.net程序反编译工具(ILSpy)

本文导读:ILSpy反编译工具的使用。不过,ILspy需要在电脑上安装.NET Framework 4.0。ILspy可以将一个dll文件转换为C#或VB语言。ILspy对于单个文件可以保存为.cs文件或.vb文件,当文件较多时,可以选择保存为项目文件。C#语句可被ILspy反编译出来,并可支持yield return语句和 lambdas表达式的反编译。

以前一直使用reflector来查看.net类库的一些信息,不过,自2011年2月份开始,reflector就开始转向收费软件了,所以爱好免费软件的开发者们转而开发自己的反编译软件。于是ILspy就因运而生了。ILSPY这个开源工具的目的就是代替reflector的,它反编译出的代码和reflector差不多。

SharpDevelop 是除Visual Studio外,另一个可选择的唯一的.NET开放工具,并且它是开源的。它提供的功能也相当不错,几乎就是在重写Visual Studio。最新的版本中,直接增加了对Visual Studio的解决方安案文件和项目文件的支持。ILSpy是SharpDevelop小组的反编译工具,也是开放源代码的,下面介绍一下它的调试器和反编译器。

 

ILspy的界面截图

 

ILSpy的界面与Reflector相似,左边以树型控件显示程序集和它的类型,右边是对应的源代码。基础的反编译功能,与Reflector相比,丝毫不差,甚至有时候用Reflector无法反编译(因为加密)的程序集,用ILSpy可以反编译。
 

ILspy需要在电脑上安装.NET Framework 4.0.
 
 
ILspy常用的几个功能
 

基础的类型反编译功能都具备

现在只支持把源代码反编译为C#和IL语言,不支持VB。

效果图为:

ILSpy的代码保存功能

当点击一个类型时,选择File->Save Code会反编译当前的类型并保存到指定的文件中,当选择程序集时,Save Code保存为一个项目(csproj)文件,并且把它所有的类型加到这个项目中。

 

ILSpy的调试器功能

这里要说的调试器,不是指Visual Studio的源码级别的调试器,而是指程序集的调试器。Reflector有个Addin,可以直接附加在Visual Studio中,调试第三方的类型库,而不需要把第三方的类型库反编译后,以源码的形式添加到项目中。

ILSpy也有这个功能,直接对第三方的程序集进行调试,有两种选项

如果第三方类型库是可执行程序(EXE),可以用Debug an executable来启动这个程序。

如果第三方类型库是程序集(DLL),可以用Attach to running application来附加,以启动程序集的调试。

 

从上图中已经可以看出它的用法,和调试源代码一样。在需要监视变量值的方法的地方,设置断点,当程序运行到此时,就可以通过监视窗体来观察变量的值。

这两者的区别是,Attach to a running application调试时,如果代码经过编译器优化,则监视器会无法得到它的值。

如图所示,无法显示正在调试的变量num的值,因为代码已经经过优化。官方推荐的方式是Debug an executable


与在Visual Studio中调试.NET源代码一样,你可以Step into,Step over,continue,同时状态栏会显示就绪(stand by),运行中(running),正在调试(debugging)。

除了调试程序集的C#/VB形式的代码之外,也可以以IL代码形式调试,如下图所示

ILSpy的debugger是以插件形式存在的,请确保包含ILSpy.Debugger的Plugin。

 

不过调试.NET程序集一定需要PDB文件才可以。然而ILSpy却没有产生PDB文件(no PDB files are generated),而且它不可以调试ASP.NET Web application和Web 服务。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ILSpy 是一个开源的.NET反编译工具,简洁强大易用是它的特征。在绝大多数情况下,它都能很好的完成你对未知程序集内部代码的探索。 ILSpy .NET Decompiler Download Binaries Download Source View On GitHub ILSpy is the open-source .NET assembly browser and decompiler. Development started after Red Gate announced that the free version of .NET Reflector would cease to exist by end of February 2011. ILSpy requires the .NET Framework 4.0. Important links: Discussion forum Issue Tracker ILSpy plugin list Build server Release History Want to know when major new features are added? When a new stable version is released? Follow us on Twitter! 6/5/2016 Version 2.4 4/9/2016 Version 2.3.2 7/13/2015 Version 2.3.1 3/9/2015 Version 2.3 6/29/2014 Version 2.2 6/3/2012 Version 2.1 4/15/2012 Version 2.0 2/16/2012 2.0 Beta 7/16/2011 Version 1.0 5/29/2011 Beta 5/4/2011 M3 4/13/2011 M2 2/24/2011 M1 (Milestone 1) Release 2/16/2011 First Preview 2/4/2011 Development Starts (github repository created) ILSpy Features Assembly browsing IL Disassembly Support C# 5.0 “async” Decompilation to C# Supports lambdas and ‘yield return’ Shows XML documentation Decompilation to VB Saving of resources Save decompiled assembly as .csproj 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) Assembly Lists ILSpy - Further Down the Road Bookmarks Debugger Eusebiu’s blog Support C# 4.0 “dynamic” Add casts where required to make C# overload resolution call the correct method Support for fixed fields (“struct A { public unsafe fixed int Field[10]; }”) Decompiling ILSpy with itself and recompiling the result should result in a working ILSpy copy Assembly editing capabilities (similar to Reflexil) Blog Posts on ILSpy Development Daniel Grunwald’s blog David Srbecky’s blog Siegfried Pammer’s blog Eusebiu Marcu’s blog Screencasts, Demo & How To Videos Overview of features in ILSpy Build 296 Resolution: 720p Screenshots Viewing IL (Build 199) Image Navigating Types (Build 199) Image Saving Resources (Build 199) Image Decompiling a Type to C# (Build 199) Image Decompiling method with ‘yield return’ (Build 528) Image Project maintained by icsharpcodeHosted on GitHub Pages — Theme by orderedlist

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值