示例#1
0
        public void Load(IServiceProvider serviceProvider)
        {
            PluginFactory.Register(new ReflectorPlugin(this));

            _sp  = serviceProvider;
            _wm  = GetService <IWindowManager>();
            _ab  = GetService <IAssemblyBrowser>();
            _cbm = GetService <ICommandBarManager>();
            _am  = GetService <IAssemblyManager>();

            // IAssemblyManager exposes HotReplaceAssembly, but we want to support older Reflector versions
            _hotReplaceAssemblyMethod = _am.GetType().GetMethod("HotReplaceAssembly", BindingFlags.Instance | BindingFlags.Public);

            // Main Window
            _items         = new List <UIContext>();
            ReflexilWindow = new Forms.ReflexilWindow();
            _wm.Windows.Add(ReflexilWindowId, ReflexilWindow, ReflexilWindowText);

            // Main button
            AddButtonSeparatorIfNeeded(ReflectorToolsId);
            _items.Add(new ButtonUIContext(_cbm.CommandBars[ReflectorToolsId], ReflexilButtonText, MainButtonClick, BasePlugin.ReflexilImage));

            AddButtonSeparatorIfNeeded(ReflectorToolBarId);
            _items.Add(new ButtonUIContext(_cbm.CommandBars[ReflectorToolBarId], ReflexilButtonText, MainButtonClick, BasePlugin.ReflexilImage));

            using (var browserimages = new ImageList())
            {
                browserimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBrowserImages());
                browserimages.TransparentColor = Color.Green;

                using (var barimages = new ImageList())
                {
                    barimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBarImages());

                    // Menus
                    var typemenu        = AddMenu(ReflectorTypedecId);
                    var assemblymenu    = AddMenu(ReflectorAssemblyId);
                    var assemblyrefmenu = AddMenu(ReflectorAssemblyrefId);
                    var modulemenu      = AddMenu(ReflectorModuleId);
                    var methodmenu      = AddMenu(ReflectorMethoddecId);
                    var fieldmenu       = AddMenu(ReflectorFielddecId);
                    var propertymenu    = AddMenu(ReflectorPropertydecId);
                    var eventmenu       = AddMenu(ReflectorEventdecId);
                    var resmenu         = AddMenu(ReflectorResourceId);

                    var allmenus = new[]
                    { typemenu, assemblymenu, assemblyrefmenu, modulemenu, methodmenu, fieldmenu, propertymenu, eventmenu, resmenu };
                    var membersmenus = new[]
                    { assemblyrefmenu, typemenu, methodmenu, fieldmenu, propertymenu, eventmenu, resmenu };

                    // Type declaration menu
                    _items.Add(new SubMenuUIContext(typemenu, "Inject constructor", (sender, e) => Inject(InjectType.Constructor),
                                                    browserimages.Images[(int)EBrowserImages.PublicConstructor]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject event", (sender, e) => Inject(InjectType.Event),
                                                    browserimages.Images[(int)EBrowserImages.PublicEvent]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject field", (sender, e) => Inject(InjectType.Field),
                                                    browserimages.Images[(int)EBrowserImages.PublicField]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject method", (sender, e) => Inject(InjectType.Method),
                                                    browserimages.Images[(int)EBrowserImages.PublicMethod]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject property", (sender, e) => Inject(InjectType.Property),
                                                    browserimages.Images[(int)EBrowserImages.PublicProperty]));
                    _items.Add(new SubMenuUIContext(typemenu));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner class", (sender, e) => Inject(InjectType.Class),
                                                    browserimages.Images[(int)EBrowserImages.PublicClass]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner enum", (sender, e) => Inject(InjectType.Enum),
                                                    browserimages.Images[(int)EBrowserImages.PublicEnum]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner interface", (sender, e) => Inject(InjectType.Interface),
                                                    browserimages.Images[(int)EBrowserImages.PublicInterface]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner struct", (sender, e) => Inject(InjectType.Struct),
                                                    browserimages.Images[(int)EBrowserImages.PublicStructure]));

                    // Shared subitems for Assembly/Module
                    foreach (var menu in new[] { assemblymenu, modulemenu })
                    {
                        _items.Add(new SubMenuUIContext(menu, "Inject assembly reference",
                                                        (sender, e) => Inject(InjectType.AssemblyReference), browserimages.Images[(int)EBrowserImages.LinkedAssembly]));
                        _items.Add(new SubMenuUIContext(menu, "Inject class", (sender, e) => Inject(InjectType.Class),
                                                        browserimages.Images[(int)EBrowserImages.PublicClass]));
                        _items.Add(new SubMenuUIContext(menu, "Inject enum", (sender, e) => Inject(InjectType.Enum),
                                                        browserimages.Images[(int)EBrowserImages.PublicEnum]));
                        _items.Add(new SubMenuUIContext(menu, "Inject interface", (sender, e) => Inject(InjectType.Interface),
                                                        browserimages.Images[(int)EBrowserImages.PublicInterface]));
                        _items.Add(new SubMenuUIContext(menu, "Inject struct", (sender, e) => Inject(InjectType.Struct),
                                                        browserimages.Images[(int)EBrowserImages.PublicStructure]));
                        _items.Add(new SubMenuUIContext(menu, "Inject resource", (sender, e) => Inject(InjectType.Resource),
                                                        browserimages.Images[(int)EBrowserImages.Resources]));

                        _items.Add(new SubMenuUIContext(menu));
                        _items.Add(new SubMenuUIContext(menu, "Reload Reflexil object model", ReloadAssembly, barimages.Images[(int)EBarImages.Reload]));
                        if (_hotReplaceAssemblyMethod != null)
                        {
                            _items.Add(new SubMenuUIContext(menu, "Update Reflector object model", UpdateHostObjectModel, barimages.Images[(int)EBarImages.Reload]));
                        }

                        _items.Add(new SubMenuUIContext(menu));
                        _items.Add(new SubMenuUIContext(menu, "Obfuscator search...", SearchObfuscator, barimages.Images[(int)EBarImages.Search]));
                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Save as...", SaveAssembly, barimages.Images[(int)EBarImages.Save]));
                        _items.Add(new SubMenuUIContext(menu, "Verify", VerifyAssembly, barimages.Images[(int)EBarImages.Check]));
                    }

                    // Shared subitems for renaming/deleting
                    foreach (var menu in membersmenus)
                    {
                        if (menu == typemenu)
                        {
                            _items.Add(new SubMenuUIContext(menu));
                        }

                        _items.Add(new SubMenuUIContext(menu, "Delete", DeleteItem, barimages.Images[(int)EBarImages.Delete]));
                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));

                        if (_hotReplaceAssemblyMethod != null)
                        {
                            _items.Add(new SubMenuUIContext(menu));
                            _items.Add(new SubMenuUIContext(menu, "Update Reflector object model", UpdateHostObjectModel, barimages.Images[(int)EBarImages.Reload]));
                        }
                    }

                    _items.AddRange(allmenus);
                }
            }

            // Main events
            _ab.ActiveItemChanged += ActiveItemChanged;
            _am.AssemblyLoaded    += AssemblyLoaded;
            _am.AssemblyUnloaded  += AssemblyUnloaded;

            ReflexilWindow.HandleItem(_ab.ActiveItem);
        }
示例#2
0
        public void Load(IServiceProvider serviceProvider)
        {
            PluginFactory.Register(new CecilStudioPlugin(this));

            _sp  = serviceProvider;
            _wm  = GetService <IWindowManager>();
            _ab  = GetService <IAssemblyBrowser>();
            _cbm = GetService <IBarManager>();
            _am  = GetService <IAssemblyManager>();

            // Main Window
            _items         = new List <UIContext>();
            ReflexilWindow = new Forms.ReflexilWindow();
            var window = _wm.Windows.Add(ReflexilWindowId, ReflexilWindow, ReflexilWindowText);

            window.Image = BasePlugin.ReflexilImage;

            // Main button
            _items.Add(new ButtonUIContext(_cbm.Bars[BarNames.Toolbar]));
            _items.Add(new ButtonUIContext(_cbm.Bars[BarNames.Toolbar], ReflexilButtonText, MainButtonClick,
                                           BasePlugin.ReflexilImage));

            using (var browserimages = new ImageList())
            {
                browserimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBrowserImages());
                browserimages.TransparentColor = Color.Green;

                using (var barimages = new ImageList())
                {
                    barimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBarImages());

                    // Menus
                    var typemenu        = AddMenu(BarNames.TypeDefinitionBrowser.ToString());
                    var assemblymenu    = AddMenu(BarNames.AssemblyDefinitionBrowser.ToString());
                    var assemblyrefmenu = AddMenu(BarNames.AssemblyNameReferenceBrowser.ToString());
                    var modulemenu      = AddMenu(BarNames.ModuleDefinitionBrowser.ToString());
                    var methodmenu      = AddMenu(BarNames.MethodDefinitionBrowser.ToString());
                    var fieldmenu       = AddMenu(BarNames.FieldDefinitionBrowser.ToString());
                    var propertymenu    = AddMenu(BarNames.PropertyDefinitionBrowser.ToString());
                    var eventmenu       = AddMenu(BarNames.EventDefinitionBrowser.ToString());

                    var allmenus = new UIContext[]
                    { typemenu, assemblymenu, assemblyrefmenu, modulemenu, methodmenu, fieldmenu, propertymenu, eventmenu };
                    var membersmenus = new UIContext[] { assemblyrefmenu, typemenu, methodmenu, fieldmenu, propertymenu, eventmenu };

                    // Type declaration menu
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner class", (sender, e) => Inject(InjectType.Class),
                                                    browserimages.Images[(int)EBrowserImages.PublicClass]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner interface", (sender, e) => Inject(InjectType.Interface),
                                                    browserimages.Images[(int)EBrowserImages.PublicInterface]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner struct", (sender, e) => Inject(InjectType.Struct),
                                                    browserimages.Images[(int)EBrowserImages.PublicStructure]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner enum", (sender, e) => Inject(InjectType.Enum),
                                                    browserimages.Images[(int)EBrowserImages.PublicEnum]));
                    _items.Add(new SubMenuUIContext(typemenu));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject event", (sender, e) => Inject(InjectType.Event),
                                                    browserimages.Images[(int)EBrowserImages.PublicEvent]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject field", (sender, e) => Inject(InjectType.Field),
                                                    browserimages.Images[(int)EBrowserImages.PublicField]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject method", (sender, e) => Inject(InjectType.Method),
                                                    browserimages.Images[(int)EBrowserImages.PublicMethod]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject constructor", (sender, e) => Inject(InjectType.Constructor),
                                                    browserimages.Images[(int)EBrowserImages.PublicConstructor]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject property", (sender, e) => Inject(InjectType.Property),
                                                    browserimages.Images[(int)EBrowserImages.PublicProperty]));

                    // Shared subitems for Assembly/Module
                    foreach (var menu in new[] { assemblymenu, modulemenu })
                    {
                        _items.Add(new SubMenuUIContext(menu, "Inject class", (sender, e) => Inject(InjectType.Class),
                                                        browserimages.Images[(int)EBrowserImages.PublicClass]));
                        _items.Add(new SubMenuUIContext(menu, "Inject interface", (sender, e) => Inject(InjectType.Interface),
                                                        browserimages.Images[(int)EBrowserImages.PublicInterface]));
                        _items.Add(new SubMenuUIContext(menu, "Inject struct", (sender, e) => Inject(InjectType.Struct),
                                                        browserimages.Images[(int)EBrowserImages.PublicStructure]));
                        _items.Add(new SubMenuUIContext(menu, "Inject enum", (sender, e) => Inject(InjectType.Enum),
                                                        browserimages.Images[(int)EBrowserImages.PublicEnum]));
                        _items.Add(new SubMenuUIContext(menu, "Inject assembly reference",
                                                        (sender, e) => Inject(InjectType.AssemblyReference), browserimages.Images[(int)EBrowserImages.LinkedAssembly]));
                        _items.Add(new SubMenuUIContext(menu));
                        _items.Add(new SubMenuUIContext(menu, "Save as...", SaveAssembly, barimages.Images[(int)EBarImages.Save]));
                        _items.Add(new SubMenuUIContext(menu, "Obfuscator search...", SearchObfuscator, barimages.Images[(int)EBarImages.Search]));
                        _items.Add(new SubMenuUIContext(menu, "Reload", ReloadAssembly, barimages.Images[(int)EBarImages.Reload]));
                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Verify", VerifyAssembly, barimages.Images[(int)EBarImages.Check]));
                    }

                    // Shared subitems for renaming/deleting
                    foreach (var uiContext in membersmenus)
                    {
                        var menu = (MenuUIContext)uiContext;
                        if (menu == typemenu)
                        {
                            _items.Add(new SubMenuUIContext(menu));
                        }

                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Delete", DeleteItem, barimages.Images[(int)EBarImages.Delete]));
                    }

                    _items.AddRange(allmenus);
                }
            }

            // Main events
            _ab.ActiveItemChanged += ActiveItemChanged;

            ReflexilWindow.HandleItem(_ab.ActiveItem);
        }
示例#3
0
        /// <summary>
        /// Addin load method
        /// </summary>
        /// <param name="serviceProvider">Reflector service provider</param>
        public void Load(IServiceProvider serviceProvider)
        {
            PluginFactory.Register(new ReflectorPlugin(this));

            _sp  = serviceProvider;
            _wm  = GetService <IWindowManager>();
            _ab  = GetService <IAssemblyBrowser>();
            _cbm = GetService <ICommandBarManager>();
            _am  = GetService <IAssemblyManager>();

            CheckPrerequisites();

            // Main Window
            _items         = new List <UIContext>();
            ReflexilWindow = new Forms.ReflexilWindow();
            _wm.Windows.Add(ReflexilWindowId, ReflexilWindow, ReflexilWindowText);

            // Main button
            _items.Add(new ButtonUIContext(_cbm.CommandBars[ReflectorToolsId]));
            _items.Add(new ButtonUIContext(_cbm.CommandBars[ReflectorToolsId], ReflexilButtonText, Button_Click, BasePlugin.ReflexilImage));

            using (var browserimages = new ImageList())
            {
                browserimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBrowserImages());
                browserimages.TransparentColor = Color.Green;

                using (var barimages = new ImageList())
                {
                    barimages.Images.AddStrip(PluginFactory.GetInstance().GetAllBarImages());

                    // Menus
                    var typemenu        = AddMenu(ReflectorTypedecId);
                    var assemblymenu    = AddMenu(ReflectorAssemblyId);
                    var assemblyrefmenu = AddMenu(ReflectorAssemblyrefId);
                    var modulemenu      = AddMenu(ReflectorModuleId);
                    var methodmenu      = AddMenu(ReflectorMethoddecId);
                    var fieldmenu       = AddMenu(ReflectorFielddecId);
                    var propertymenu    = AddMenu(ReflectorPropertydecId);
                    var eventmenu       = AddMenu(ReflectorEventdecId);
                    var resmenu         = AddMenu(ReflectorResourceId);

                    var allmenus     = new UIContext[] { typemenu, assemblymenu, assemblyrefmenu, modulemenu, methodmenu, fieldmenu, propertymenu, eventmenu, resmenu };
                    var membersmenus = new UIContext[] { assemblyrefmenu, typemenu, methodmenu, fieldmenu, propertymenu, eventmenu, resmenu };

                    // Type declaration menu
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner class", (sender, e) => Inject(EInjectType.Class), browserimages.Images[(int)EBrowserImages.PublicClass]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner interface", (sender, e) => Inject(EInjectType.Interface), browserimages.Images[(int)EBrowserImages.PublicInterface]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner struct", (sender, e) => Inject(EInjectType.Struct), browserimages.Images[(int)EBrowserImages.PublicStructure]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject inner enum", (sender, e) => Inject(EInjectType.Enum), browserimages.Images[(int)EBrowserImages.PublicEnum]));
                    _items.Add(new SubMenuUIContext(typemenu));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject event", (sender, e) => Inject(EInjectType.Event), browserimages.Images[(int)EBrowserImages.PublicEvent]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject field", (sender, e) => Inject(EInjectType.Field), browserimages.Images[(int)EBrowserImages.PublicField]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject method", (sender, e) => Inject(EInjectType.Method), browserimages.Images[(int)EBrowserImages.PublicMethod]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject constructor", (sender, e) => Inject(EInjectType.Constructor), browserimages.Images[(int)EBrowserImages.PublicConstructor]));
                    _items.Add(new SubMenuUIContext(typemenu, "Inject property", (sender, e) => Inject(EInjectType.Property), browserimages.Images[(int)EBrowserImages.PublicProperty]));

                    // Shared subitems for Assembly/Module
                    foreach (var menu in new[] { assemblymenu, modulemenu })
                    {
                        _items.Add(new SubMenuUIContext(menu, "Inject class", (sender, e) => Inject(EInjectType.Class), browserimages.Images[(int)EBrowserImages.PublicClass]));
                        _items.Add(new SubMenuUIContext(menu, "Inject interface", (sender, e) => Inject(EInjectType.Interface), browserimages.Images[(int)EBrowserImages.PublicInterface]));
                        _items.Add(new SubMenuUIContext(menu, "Inject struct", (sender, e) => Inject(EInjectType.Struct), browserimages.Images[(int)EBrowserImages.PublicStructure]));
                        _items.Add(new SubMenuUIContext(menu, "Inject enum", (sender, e) => Inject(EInjectType.Enum), browserimages.Images[(int)EBrowserImages.PublicEnum]));
                        _items.Add(new SubMenuUIContext(menu, "Inject assembly reference", (sender, e) => Inject(EInjectType.AssemblyReference), browserimages.Images[(int)EBrowserImages.LinkedAssembly]));
                        _items.Add(new SubMenuUIContext(menu, "Inject resource", (sender, e) => Inject(EInjectType.Resource), browserimages.Images[(int)EBrowserImages.Resources]));
                        _items.Add(new SubMenuUIContext(menu));
                        _items.Add(new SubMenuUIContext(menu, "Save as...", (sender, e) => AssemblyHelper.SaveAssembly(GetCurrentAssemblyDefinition(), GetCurrentModuleOriginalLocation()), barimages.Images[(int)EBarImages.Save]));
                        _items.Add(new SubMenuUIContext(menu, "Obfuscator search...", (sender, e) => AssemblyHelper.SearchObfuscator(GetCurrentModuleOriginalLocation()), barimages.Images[(int)EBarImages.Search]));
                        _items.Add(new SubMenuUIContext(menu, "Reload", ReloadAssembly, barimages.Images[(int)EBarImages.Reload]));
                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Verify", (sender, e) => AssemblyHelper.VerifyAssembly(GetCurrentAssemblyDefinition(), GetCurrentModuleOriginalLocation()), barimages.Images[(int)EBarImages.Check]));
                    }

                    // Shared subitems for renaming/deleting
                    foreach (var uiContext in membersmenus)
                    {
                        var menu = (MenuUIContext)uiContext;
                        if (menu == typemenu)
                        {
                            _items.Add(new SubMenuUIContext(menu));
                        }

                        _items.Add(new SubMenuUIContext(menu, "Rename...", RenameItem, barimages.Images[(int)EBarImages.New]));
                        _items.Add(new SubMenuUIContext(menu, "Delete", DeleteMember, barimages.Images[(int)EBarImages.Delete]));
                    }

                    _items.AddRange(allmenus);
                }
            }

            // Main events
            _ab.ActiveItemChanged += ActiveItemChanged;
            _am.AssemblyLoaded    += AssemblyLoaded;
            _am.AssemblyUnloaded  += AssemblyUnloaded;

            PluginFactory.GetInstance().ReloadAssemblies(_am.Assemblies);
            ReflexilWindow.HandleItem(_ab.ActiveItem);
        }