Пример #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>();

            // 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 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(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, "Inject resource", (sender, e) => Inject(InjectType.Resource),
                                                        browserimages.Images[(int)EBrowserImages.Resources]));
                        _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;
            _am.AssemblyLoaded    += AssemblyLoaded;
            _am.AssemblyUnloaded  += AssemblyUnloaded;

            ReflexilWindow.HandleItem(_ab.ActiveItem);
        }
Пример #2
0
        /// <summary>
        /// Addin load method
        /// </summary>
        /// <param name="serviceProvider">Reflector service provider</param>
        public void Load(System.IServiceProvider serviceProvider)
        {
            PluginFactory.Register(new ReflectorPlugin(this));

            sp  = serviceProvider;
            wm  = GetService <IWindowManager>();
            ab  = GetService <IAssemblyBrowser>();
            cbm = GetService <ICommandBarManager>();
            am  = GetService <IAssemblyManager>();

            CheckFrameWorkVersion();

            // Main Window
            items          = new List <UIContext>();
            reflexilwindow = new Reflexil.Forms.ReflexilWindow();
            wm.Windows.Add(REFLEXIL_WINDOW_ID, reflexilwindow, REFLEXIL_WINDOW_TEXT);

            // Main button
            items.Add(new ButtonUIContext(cbm.CommandBars[REFLECTOR_TOOLS_ID]));
            items.Add(new ButtonUIContext(cbm.CommandBars[REFLECTOR_TOOLS_ID], REFLEXIL_BUTTON_TEXT, Button_Click, BasePlugin.ReflexilImage));

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

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

                    // Menus
                    var typemenu        = AddMenu(REFLECTOR_TYPEDEC_ID);
                    var assemblymenu    = AddMenu(REFLECTOR_ASSEMBLY_ID);
                    var assemblyrefmenu = AddMenu(REFLECTOR_ASSEMBLYREF_ID);
                    var modulemenu      = AddMenu(REFLECTOR_MODULE_ID);
                    var methodmenu      = AddMenu(REFLECTOR_METHODDEC_ID);
                    var fieldmenu       = AddMenu(REFLECTOR_FIELDDEC_ID);
                    var propertymenu    = AddMenu(REFLECTOR_PROPERTYDEC_ID);
                    var eventmenu       = AddMenu(REFLECTOR_EVENTDEC_ID);
                    var resmenu         = AddMenu(REFLECTOR_RESOURCE_ID);

                    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 (MenuUIContext menu in new MenuUIContext[] { 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 (MenuUIContext menu in membersmenus)
                    {
                        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 += this.ActiveItemChanged;
            am.AssemblyLoaded    += this.AssemblyLoaded;
            am.AssemblyUnloaded  += this.AssemblyUnloaded;

            PluginFactory.GetInstance().ReloadAssemblies(am.Assemblies);
            reflexilwindow.HandleItem(ab.ActiveItem);
        }