240 likes | 600 Views
Extending .Net Reflector: Writing Your own Add-ins. Jason Haley Seattle Code Camp 4 November 2008. Who is this guy?. Using .Net since Fall 2001 (beta 2) MCSD.Net Debris.Net: A .Net disassembler (in progress) .Net related link blog “Interesting Finds” Author of a few Reflector Add-ins
E N D
Extending .Net Reflector:Writing Your own Add-ins Jason Haley Seattle Code Camp 4 November 2008
Who is this guy? • Using .Net since Fall 2001 (beta 2) • MCSD.Net • Debris.Net: A .Net disassembler (in progress) • .Net related link blog “Interesting Finds” • Author of a few Reflector Add-ins • The team software guy, Open Seas
Ways to extend Reflector • Additional languages • Change the disassembler output • Display different assembly information • Add ‘missing’ functionality • Create new functionality
Demo Simplest Reflector Add-in
Agenda • Ways to Extend .Net Reflector • .Net Reflector Add-in Model Overview • Getting Started
Languages • Disassembler/Decompiler add-ins • Implement ILanguage, plus a few others • Often paired with a browser/viewer
Demo PowerShellLanguage
Viewers/Browsers • UI/Visual add-ins • WinForms Controls to display decompiler output
Demo ClassView, CodeModelView
Metadata applications • Provide useful extensions to Reflector • Use the assembly information in some way • Use other Reflector functionality
Demo Review
Agenda • Ways to Extend .Net Reflector • .Net Reflector Add-in Model Overview • Getting Started
Introducing the code model • Resides in Reflector.exe • Interface driven • Reflector namespace • Majority of non metadata interfaces • Managers • Reflector.CodeModel namespace • Contains the metadata interfaces • Reflector.CodeModel.Memory namespace • Contains some concrete objects
The visible parts • IAssemblyManager • Tree view of loaded assemblies • ICommandBarManager • Menus, Context Menus, Toolbar • ILanguageManager • Language drop down list on Toolbar • IPropertyPageManager • Dialog shown from View-> Options
Demo ReflectorUI
The not-so visible parts • IWindowManager • Access to StatusBar, ComandBars, Windows • IConfigurationManager • Access to cfg file storage • ITranslationManager • Access disassembler factory • ApplicationManager • Not used by add-ins, provides a IServiceProvider
Demo EnumAddin, ReflectorWrapper
Agenda • Ways to Extend .Net Reflector • .Net Reflector Add-in Model Overview • Getting Started
Writing your own add-in • Where to start • CodePlex site has articles and code • Existing add-ins • My addins page • Add-ins to start with • ClassViewer • CodeModelViewer
Reference Points I Use • Solution from CodePlex site • AssemblyCollection.Sort • Enum Addin • Boxing Count • Create Using • Code Shortcut • Open Zip
Tips for Creating Addins • Look at the source of similar addins • Reflector Add-in Starter Kit • Create a shortcut to the reflector.exe in bin directory • Add your add-in, then close it (generates the .cfg file) • Set bookmarks for testing • System.Diagnostics.Debugger.Break() • (Vista) Taskkill /im reflector.exe
Summary • Reflector.exe has the code model • Get the starter kit • Download the add-ins on CodePlex • Look at the code for existing add-ins • Create your own – big or small
Web Resources • .Net Reflector – http://www.red-gate.com/products/reflector/ • .Net Reflector Add-ins – http://codeplex.com/reflectoraddins/ • .Net Reflector Forum - http://www.red-gate.com/MessageBoard/viewforum.php?f=85 • My material – http://jasonhaley.com/addins/
Questions and Discussion • Any additional tips on using Reflector? • Any ideas on creating additional add-ins? • A few on my list: • Interface usage helper • Assembly reference mismatch finder • F# language • Other languages? • Obfuscation name mapper • Add-in manager modeled after Firefox