现在的位置: 首页 > 综合 > 正文

.Net反编译工具Reflector

2013年08月15日 ⁄ 综合 ⁄ 共 4070字 ⁄ 字号 评论关闭

 

俺一直在使用Reflector, 今天查了一下资料,看了有很多插件,所以记了下来!

其中俺只使用过

Reflector.ClassView.dll

Reflector.CodeSearch.dll

Reflector.ComLoader.dll

Reflector.FileDisassembler.dll

Tcdev.DsmPlugin.dll

可以参考:

http://www.codeplex.com/reflectoraddins/Release/ProjectReleases.aspx?ReleaseId=1805

 

也从网上摘录一些资料,以下转载自:

http://hi.baidu.com/blueskycaca/blog/item/28cc40d651e08cdaa044dfa4.html

http://www.cnblogs.com/cnmawei/archive/2007/06/15/784587.html

 

   
早就听说
Reflector这个强大的类库分析与反编译工具,不过一直没有很好的利用起来。最近使用Reflector解决了一个实际开发问题,现将其总结出来。

需求导入:项目是一个GIS项目,在项目中使用到了ESRI公司的Application
Development
Framework
中的一个WebControls控件,此控件的功能过于复杂,并且引用到了ArcGIS
Server
的很多COM组件。由于项目根本就没有使用ADF的任何服务器技术,但是也不得不跟着引用一些COM组件,更麻烦的是还得安装ADF(此组件可是有将近200M的庞然大物)。

项目经理需要我解决这种问题并且必须尽快解决,我当时也相应的考虑到了两个方案:

  1. 重新写一个类似的控件,此控件只做项目中用到的一些功能,至于其它功能以后再扩展;
  2. 利用ESRIWebControls控件,去掉对COM的所有引用,因为项目没有使用WebControls控件的任何服务器技术,也就无需COM引用

由于时间有限,所以决定采用第二种方案,一开始使用ILDASM分析了Web
Server
控件的一些类,发现过于类过于庞大。偶然想起了Reflector工具(我以前使用过Reflector工具分析过源代码,不过好久没用),以下是整个解决过程:

  1. 打开Reflector工具并且下载了一个FileDisassembler插件,FileDisassembler插件用于输出程序集的反编译结果到文件中。打开Reflector工具,并导入FileDisassembler插件。导入好后加载程序集将反编译结果输出到指定的文件夹中;

Reflector下载地址:http://www.aisto.com/roeder/dotnet
下载时必须输入用户名和Email地址,用户名中必须有空格;

FileDisassembler插件的下载地址:http://www.denisbauer.com/

  1. 使用VS.NET新建一个项目,根据文件夹结构新建相应的文件夹,导入所有的源文件和资源文件。使用FileDisassembler导出的资源文件为全名称,在实际的项目中必须根据namespace更改资源文件名且必须将“生成操作”更改为“嵌入的资源”,可以使用ILDASM查看metadata来决定资源文件名及所在的文件夹,编译并更改一些错误;
  1. 当编译好后,找到所有与COM有关的内容将其注释掉(因为以前使用过CCW/RCW技术),并做相应的更改,每更改一个class后,编译一次,直到去掉其相关引用为止;
  1. 更改完成后,需要对其进行重构,主要重构以下方面:
  • Rename,因为Reflector工具反编译时其变量名会根据类型来命名,如text1,text2,num1等;
  • 去掉goto语句,如果代码中有swtich语句时,Reflector工具会使用goto语句,严重影响程序逻辑其可读性;
  • Extract
    Method
    ,将过于长的method执行分解操作;

当重构完成后,应用到项目中,并更改相应的Register语句,testrun,结果是successful,从而也在最短的时间内完成

最近由于需要反编译一些C#写的程序,早就听说功能极为强大的反编译工具,Reflector。
     
我用的版本是4.1.84.0,感觉用起来很爽,以后弄到的几个很好用的DLL,我都反编译,并弄出源码了,为我省了不少工夫啊,反编译出来的除了定义的变量名不一样外,其余的简直是一模一样。
围绕它开发的插件也很多,用着真是开心!我还找到一个插件可以把源码导出到文件!更是爽!不过这个软件还不支持Unicode
,需要自己写一个转化程序,两个搭配起来用极爽!
     有兴趣的朋友也下载一个玩玩吧~ 哈哈! 由于使用过于简单,就不介绍软件使用了~

     下载地址
    http://www.aisto.com/roeder/dotnet/Download.aspx?File=Reflector

另外再提供一些Reflector的相关插件下载,enjoy!!!!

Reflector.FileDisassembler
This add-in can be used to
dump the disassembler output to files for any Reflector supported
language.
Website Download
Reflector.CodeMetrics
Analyses .NET assemblies and
shows design quality metrics. The menu item is registered under the "Tools"
menu.
Website Download
Reflector.SQL2005Browser
This add-in allows to browse
.NET assemblies stored in SQL Server 2005 (Yukon) databases.
Website Download
Reflector.DelphiLanguage
The Delphi view that is used
inside .NET Reflector provided as a language add-in.
Website Download
Reflector.McppLanguage
This add-in extends Reflector
with a Managed C++ language rendering module.
Website Download
Reflector.ChromeLanguage
This add-in extends Reflector
with a Chrome language rendering module.
Website Download
Reflector.Diff
This add-in shows differences between
two versions of the same assembly.
Website Download
Reflector.VisualStudio
This program is hosting .NET
Reflector inside the Visual Studio 2003 IDE. Run Reflector.VisualStudio.exe to
register the add-in with Visual Studio.
Website Download
Reflector.ClassView
Shows class definitions as plain
text with color coding. The menu item is registered under the "Tools" menu.

Website Download
Reflector.CodeModelView
This add-in shows the
underlying code model objects for a selected node in .NET Reflector. The menu
item is registered under the "Tools" menu.
Website Download
Reflector.FileGenerator
This add-in can be used to dump
the disassembler output to files for any Reflector supported language.
Download
Reflector.Graph
This add-in draws assembly dependency
graphs and IL graphs.
Website Download
Reflector.OpenRunningAssembly
Opens an assembly or
dependency from a process running on the system. The menu item is registered
under the "Tools" menu.
Website Download

插件FileGenerator
使用方法:
最开始下载了FileGenerator插件不知如何使用,后来经过摸索,还是学会使用了,所以拿来和大家分享。

FileGenerator插件的作用是:根据dll文件,把里面的源文件导出成文件,导出来的文件除了没有注释,变量名也变了,其它的可谓是没有
差别。对于一些比较好的控件,如果不是开源的,完全可以导出成文件,然后自己加上注释,少许修改,很好的利用起来。(不开源的dll,用起来也不放心啊)

先根据上面的地址下载FileGenerator并解压缩,然后运行Reflector.exe,然后点击View->Add-
Ins...,弹出一个窗口,然后点击Add->选择FileGenerator里面的唯一一个dll文件:
"FileGenerator.dll",点击close.
然后回到Reflector窗口,Tool->Generator File(s)...
右边就出现了插件的窗口,选中左边的dll文件,点击右边的导出文件,源代码就全部导出来了,真是爽啊!

 

抱歉!评论已关闭.