使用.NET Reflector插件FileDisassembler還原源碼

 
.NET Reflector,它是一個類瀏覽器和反編譯器,能夠分析程序集並向您展現它的全部祕密。.NET 框架向全世界引入了可用來分析任何基於 .NET 的代碼(不管它是單個類仍是完整的程序集)的反射概念。反射還能夠用來檢索有關特定程序集中包含的各類類、方法和屬性的信息。使用 .NET Reflector,您能夠瀏覽程序集的類和方法,能夠分析由這些類和方法生成的 Microsoft 中間語言 (MSIL),而且能夠反編譯這些類和方法並查看 C# 或 Visual Basic ?.NET 中的等價類和方法。

爲了演示 .NET Reflector 的工做方式,我將加載和分析前面已經顯示的 NUnitExample 程序集。下圖顯示了 .NET Reflector 中加載的該程序集。


在 .NET Reflector 內部,有各類可用來進一步分析該程序集的工具。要查看構成某個方法的 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 框架提供了許多執行相似操做的不一樣方法。例如,若是您須要從 XML 中讀取一組數據,則存在多種使用 XmlDocument、XPathNavigator 或 XmlReader 完成該工做的不一樣方法。經過使用 .NET Reflector,您能夠查看 Microsoft 在編寫數據集的 ReadXml 方法時使用了什麼,或者查看他們在從配置文件讀取數據時作了哪些工做。.NET Reflector 仍是一個瞭解如下最佳實施策略的優秀方法:建立諸如 HttpHandlers 或配置處理程序之類的對象,由於您能夠了解到 Microsoft 工做組其實是如何在框架中生成這些對象的。 .NET Reflector 由 Lutz Roeder 編寫 下載地址:http://www.aisto.com/roeder/dotnet 如今介紹一個它的插件。很是好用。還原源碼。! www.denisbauer.com/Downloads/Reflector.FileDisassembler.zip 這是插件下載地址! 打開Reflector,在view菜單下的Add-Ins,將dll添加到裏面便可! 而後加載一個dll。選中它。選擇Tools-File Disassembler打開右側File Disassembler窗口再選擇Generate 這樣就還原了源碼。但可不是徹底還原! 下面還有其它的Plug-In.NET Reflector Add-InsThis 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
相關文章
相關標籤/搜索