Search in sources :

Example 1 with IPlugin

use of com.google.security.zynamics.binnavi.api2.plugins.IPlugin in project binnavi by google.

the class CGraphWindowMenuBar method dipose.

/**
   * Frees allocated resources.
   */
public void dipose() {
    m_synchronizer.dispose();
    m_selectionMenu.dispose();
    final List<IGraphMenuPlugin> plugins = Lists.newArrayList();
    for (final IPlugin<IPluginInterface> plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IGraphMenuPlugin) {
            plugins.add((IGraphMenuPlugin) plugin);
        }
    }
    for (final IGraphMenuPlugin plugin : plugins) {
        try {
            plugin.closed(m_model.getGraphFrame());
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
            final String innerMessage = "E00106: " + "Plugin caused an unexpected exception";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
            NaviErrorDialog.show(m_model.getParent(), innerMessage, innerDescription, exception);
        }
    }
    m_pluginsMenu.dispose();
}
Also used : IPluginInterface(com.google.security.zynamics.binnavi.api2.IPluginInterface) IGraphMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IGraphMenuPlugin)

Example 2 with IPlugin

use of com.google.security.zynamics.binnavi.api2.plugins.IPlugin in project binnavi by google.

the class CPluginsMenu method fillPluginsMenu.

/**
   * Creates the menu items of the Plugins menu.
   */
private void fillPluginsMenu() {
    final List<IGraphMenuPlugin> plugins = new ArrayList<IGraphMenuPlugin>();
    for (@SuppressWarnings("rawtypes") final IPlugin plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IGraphMenuPlugin) {
            plugins.add((IGraphMenuPlugin) plugin);
        }
    }
    add(CActionProxy.proxy(new CActionGraphScripting(m_model.getGraphPanel())));
    add(CActionProxy.proxy(new CActionOpenLogConsole()));
    addSeparator();
    for (final IGraphMenuPlugin plugin : plugins) {
        extendPluginMenu(plugin);
    }
}
Also used : CActionOpenLogConsole(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CActionOpenLogConsole) ArrayList(java.util.ArrayList) CActionGraphScripting(com.google.security.zynamics.binnavi.Gui.GraphWindows.Actions.CActionGraphScripting) IGraphMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IGraphMenuPlugin) IPlugin(com.google.security.zynamics.binnavi.api2.plugins.IPlugin)

Example 3 with IPlugin

use of com.google.security.zynamics.binnavi.api2.plugins.IPlugin in project binnavi by google.

the class CModuleNodeMenuBuilder method addPluginMenus.

/**
   * Adds the plugin-generated menus to the context menu.
   *
   * @param menu The context menu where the menu items are added.
   */
private void addPluginMenus(final JComponent menu) {
    final List<IModuleMenuPlugin> plugins = new ArrayList<>();
    for (final IPlugin<IPluginInterface> plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IModuleMenuPlugin) {
            plugins.add((IModuleMenuPlugin) plugin);
        }
    }
    boolean addedSeparator = false;
    for (final IModuleMenuPlugin plugin : plugins) {
        try {
            final List<JComponent> menuItems = plugin.extendModuleMenu(getPluginModules());
            if (menuItems != null) {
                for (final JComponent menuItem : menuItems) {
                    if (!addedSeparator) {
                        menu.add(new JSeparator());
                        addedSeparator = true;
                    }
                    menu.add(menuItem);
                }
            }
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
            final String innerMessage = "E00093: " + "Plugin caused an unexpected exception";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
            NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
        }
    }
}
Also used : IPluginInterface(com.google.security.zynamics.binnavi.api2.IPluginInterface) IModuleMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IModuleMenuPlugin) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) JSeparator(javax.swing.JSeparator)

Example 4 with IPlugin

use of com.google.security.zynamics.binnavi.api2.plugins.IPlugin in project binnavi by google.

the class CAbstractMenuBuilder method createPluginsMenu.

/**
   * Creates the plugin menu.
   * 
   * @return The created menu.
   */
private JMenu createPluginsMenu() {
    final List<IMainWindowMenuPlugin> plugins = new ArrayList<IMainWindowMenuPlugin>();
    for (@SuppressWarnings("rawtypes") final IPlugin plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IMainWindowMenuPlugin) {
            plugins.add((IMainWindowMenuPlugin) plugin);
        }
    }
    final JMenu menu = new JMenu("Plugins");
    menu.setMnemonic('U');
    menu.add(CActionProxy.proxy(new CActionOpenScriptingDialog(getParent())));
    menu.add(CActionProxy.proxy(new CActionOpenLogConsole()));
    menu.addSeparator();
    menu.add(CActionProxy.proxy(new CPluginManagementAction(getParent())));
    menu.add(CActionProxy.proxy(new CPluginsReloadAction()));
    menu.addSeparator();
    for (final IMainWindowMenuPlugin plugin : plugins) {
        // ESCA-JAVA0166: Catch Exception because we are calling a plugin function.
        try {
            final List<JMenuItem> menus = plugin.extendPluginMenu();
            for (final JMenuItem m : menus) {
                menu.add(m);
            }
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
            final String innerMessage = "E00092: " + "Plugin caused an unexpected exception";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
            NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
        }
    }
    return menu;
}
Also used : CActionOpenLogConsole(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CActionOpenLogConsole) ArrayList(java.util.ArrayList) IMainWindowMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IMainWindowMenuPlugin) IPlugin(com.google.security.zynamics.binnavi.api2.plugins.IPlugin) CPluginsReloadAction(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CPluginsReloadAction) CActionOpenScriptingDialog(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CActionOpenScriptingDialog) CPluginManagementAction(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CPluginManagementAction) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 5 with IPlugin

use of com.google.security.zynamics.binnavi.api2.plugins.IPlugin in project binnavi by google.

the class PluginLoaderThread method runExpensiveCommand.

@Override
protected void runExpensiveCommand() throws Exception {
    setDescription("Loading JAR files");
    final Set<File> jarFiles = JarLoader.collectJars(rootPath);
    JarLoader.loadJars(jarFiles, this);
    final Set<File> scriptFiles = ScriptLoader.collectScripts(rootPath);
    ScriptLoader.init(scriptFiles, pluginInterface, this);
    final List<IPlugin<T>> scriptPlugins = registry.getPlugins();
    for (final String pluginPath : pluginPaths) {
        final Set<File> pluginFiles = PluginLoader.collectPluginFiles(pluginPath);
        final LoadResult<T> plugins = PluginLoader.loadPlugins(pluginPath, pluginFiles, this);
        for (final Pair<String, Throwable> failedPlugin : plugins.getFailedPlugins()) {
            CUtilityFunctions.logException(failedPlugin.second());
            final String message = "E00007: " + "Loading a plugin failed";
            final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not load the plugin file file '%s' because the plugin " + "caused an exception.", failedPlugin.first()), new String[] { "The plugin file contains a bug that caused the exception" }, new String[] { "The plugin file was not loaded and the functionality of " + "the script will not be available in BinNavi" });
            NaviErrorDialog.show(parent, message, description, failedPlugin.second());
        }
        for (final Pair<IPlugin<T>, PluginStatus> pair : plugins.getLoadedPlugins()) {
            final IPlugin<T> plugin = pair.first();
            final PluginStatus status = pair.second();
            if (status != PluginStatus.Valid) {
                showError(plugins, plugin, status);
            }
        }
        PluginInitializer.initializePlugins(pluginInterface, registry, plugins.getLoadedPlugins(), configFile);
        for (final IPlugin<T> plugin : scriptPlugins) {
            try {
                plugin.init(pluginInterface);
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
                registry.removePlugin(plugin, DisabledPluginReason.ThrewOnInit);
            }
        }
        for (final Pair<IPlugin<T>, DisabledPluginReason> disabledPair : registry.getDisabledPlugins()) {
            final IPlugin<T> plugin = disabledPair.first();
            final DisabledPluginReason reason = disabledPair.second();
            if (reason == DisabledPluginReason.ThrewOnInit) {
                final String message = "E00102: " + "Error during plugin initialization";
                final String description = CUtilityFunctions.createDescription(String.format("BinNavi could not initialize the plugin '%s' because the plugin " + "caused an exception.", plugin.getName()), new String[] { "A bug in the plugin caused an exception." }, new String[] { "The plugin could not be initialized properly and was removed " + "from the list of loaded plugins." });
                NaviErrorDialog.show(parent, message, description);
            }
        }
    }
}
Also used : IPlugin(com.google.security.zynamics.binnavi.api2.plugins.IPlugin) PluginStatus(com.google.security.zynamics.binnavi.Plugins.PluginStatus) DisabledPluginReason(com.google.security.zynamics.binnavi.Plugins.DisabledPluginReason) File(java.io.File)

Aggregations

IPlugin (com.google.security.zynamics.binnavi.api2.plugins.IPlugin)7 ArrayList (java.util.ArrayList)6 IPluginInterface (com.google.security.zynamics.binnavi.api2.IPluginInterface)4 JComponent (javax.swing.JComponent)3 JSeparator (javax.swing.JSeparator)3 IGraphMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IGraphMenuPlugin)2 CActionOpenLogConsole (com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CActionOpenLogConsole)2 JMenuItem (javax.swing.JMenuItem)2 ICriteriaSelectionPlugin (com.google.security.zynamics.binnavi.API.plugins.ICriteriaSelectionPlugin)1 IMainWindowMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IMainWindowMenuPlugin)1 IModuleMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IModuleMenuPlugin)1 IProjectFolderMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IProjectFolderMenuPlugin)1 IProjectMenuPlugin (com.google.security.zynamics.binnavi.API.plugins.IProjectMenuPlugin)1 ICriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.ICriteriumCreator)1 CIndegreeCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.InDegrees.CIndegreeCriteriumCreator)1 CColorCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.NodeColor.CColorCriteriumCreator)1 COutdegreeCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.OutDegree.COutdegreeCriteriumCreator)1 CSelectionCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Selection.CSelectionCriteriumCreator)1 CTagCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Tag.CTagCriteriumCreator)1 CTextCriteriumCreator (com.google.security.zynamics.binnavi.Gui.CriteriaDialog.Conditions.Text.CTextCriteriumCreator)1