.net reflector,它是一個類瀏覽器和反編譯器,可以分析程序集并向您展示它的所有秘密。.net 框架向全世界引入了可用來分析任何基于 .net 的代碼(無論它是單個類還是完整的程序集)的反射概念。反射還可以用來檢索有關(guān)特定程序集中包含的各種類、方法和屬性的信息。使用 .net reflector,您可以瀏覽程序集的類和方法,可以分析由這些類和方法生成的 microsoft 中間語言 (msil),并且可以反編譯這些類和方法并查看 c# 或 visual basic ?.net 中的等價類和方法。 ![]() 在 .net reflector 內(nèi)部,有各種可用來進一步分析該程序集的工具。要查看構(gòu)成某個方法的 msil,請單擊該方法并從菜單中選擇 disassembler。 除了能夠查看 msil 以外,您還可以通過選擇 tools 菜單下的 decompiler 來查看該方法的 c# 形式。通過在 languages 菜單下更改您的選擇,您還可以查看該方法被反編譯到 visual basic .net 或 delphi 以后的形式。以下為 .net reflector 生成的代碼: public void hashtableaddtest(){ hashtable hashtable1; hashtable1 = new hashtable(); hashtable1.add("key1", "value1"); hashtable1.add("key2", "value2"); assert.areequal("value1", hashtable1["key1"], "wrong object returned!"); assert.areequal("value2", hashtable1["key2"], "wrong object returned!"); } 前面的代碼看起來非常像我為該方法實際編寫的代碼。以下為該程序集中的實際代碼: public void hashtableaddtest(){ hashtable ht = new hashtable(); ht.add("key1", "value1"); ht.add("key2", "value2"); assert.areequal("value1", ht["key1"], "wrong object returned!"); assert.areequal("value2", ht["key2"], "wrong object returned!"); } 盡管上述代碼中存在一些小的差異,但它們在功能上是完全相同的。 雖然該示例是一種顯示實際代碼與反編譯代碼之間對比的好方法,但在我看來,它并不代表 .net reflector 所具有的最佳用途 — 分析 .net 框架程序集和方法。.net 框架提供了許多執(zhí)行類似操作的不同方法。例如,如果您需要從 xml 中讀取一組數(shù)據(jù),則存在多種使用 xmldocument、xpathnavigator 或 xmlreader 完成該工作的不同方法。通過使用 .net reflector,您可以查看 microsoft 在編寫數(shù)據(jù)集的 readxml 方法時使用了什么,或者查看他們在從配置文件讀取數(shù)據(jù)時做了哪些工作。.net reflector 還是一個了解以下最佳實施策略的優(yōu)秀方法:創(chuàng)建諸如 httphandlers 或配置處理程序之類的對象,因為您可以了解到 microsoft 工作組實際上是如何在框架中生成這些對象的。 .net reflector 由 lutz roeder 編寫 下載地址:http://www.aisto.com/roeder/dotnet 現(xiàn)在介紹一個它的插件。非常好用。還原源碼。! www.denisbauer.com/downloads/reflector.filedisassembler.zip 這是插件下載地址! 打開reflector,在view菜單下的add-ins,將dll添加到里面即可! 然后加載一個dll。選中它。選擇tools-file disassembler打開右側(cè)file disassembler窗口再選擇generate 這樣就還原了源碼。但可不是完全還原! 下面還有其它的plug-in .net reflector add-ins this website lists add-ins for .net reflector. after downloading one of the add-ins copy the files to the same directory as your reflector.exe file and load them via the add-ins command under the view menu. you can download reflector here. -------------------------------------------------------------------------------- reflector.filedisassembler this add-in can be used to dump the disassembler output to files for any reflector supported language. 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. it also supports method ranking and type ranking. website -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- reflector.mbunit this add-in allows loading and executing mbunit unit test fixtures in reflector. the source code is provided online. website -------------------------------------------------------------------------------- disclaimer: the content of this website is provided "as is" with no warranties, and confers no rights. |