Esempio n. 1
0
    def discover_and_initialize_plugins(self):
        os.environ['AM_BUILTIN_PLUGINS'] = os.path.dirname(__file__)
        blacklist = Conf.plugin_blacklist.split(',')
        for search_dir in Conf.plugin_search_path.split(':'):
            search_dir = os.path.expanduser(search_dir)
            search_dir = os.path.expandvars(search_dir)
            for plugin_or_exception in load_plugins_from_dir(search_dir):
                if isinstance(plugin_or_exception, Exception):
                    l.info(plugin_or_exception)
                else:
                    plugin_or_exception: Type[BasePlugin]
                    plugin_conf_key = "plugin_%s_enabled" % plugin_or_exception.__name__

                    # see if we can't load this plugin because headless mode
                    if self.workspace is None and plugin_or_exception.REQUIRE_WORKSPACE:
                        # still note that we can use the url handlers
                        for action in plugin_or_exception.URL_ACTIONS:
                            register_url_action(action, UrlActionBinaryAware)
                    # see if the plugin is enabled or not
                    elif not any(dont in repr(plugin_or_exception) for dont in blacklist) and \
                            not (hasattr(Conf, plugin_conf_key) and getattr(Conf, plugin_conf_key) is False):
                        self.activate_plugin(plugin_or_exception)
                    else:
                        plugin_or_exception: Type[BasePlugin]
                        if (plugin_or_exception.REQUIRE_WORKSPACE and self.workspace is not None) \
                                or not plugin_or_exception.REQUIRE_WORKSPACE:
                            self.load_plugin(plugin_or_exception)
                            l.info("Blacklisted plugin %s",
                                   plugin_or_exception.get_display_name())
Esempio n. 2
0
    def activate_plugin(self, plugin_cls: Type[BasePlugin]):
        self.load_plugin(
            plugin_cls)  # just to be sure, also perform the sanity checks
        if self.get_plugin_instance(plugin_cls) is not None:
            return

        try:
            plugin = plugin_cls(self.workspace)
            self.active_plugins.append(plugin)
            plugin.__cached_toolbar_actions = [
            ]  # a hack, lol. really this could be a mapping on PluginManager but idc
            plugin.__cached_menu_actions = []  # as above

            if self.workspace is not None:
                for idx, (icon,
                          tooltip) in enumerate(plugin_cls.TOOLBAR_BUTTONS):
                    action = ToolbarAction(
                        icon, 'plugin %s toolbar %d' % (plugin_cls, idx),
                        tooltip,
                        functools.partial(self._dispatch_single, plugin,
                                          BasePlugin.handle_click_toolbar,
                                          False, idx))
                    plugin.__cached_toolbar_actions.append(action)
                    self.workspace._main_window._file_toolbar.add(action)

                if plugin_cls.MENU_BUTTONS:
                    self.workspace._main_window._plugin_menu.add(
                        MenuSeparator())
                for idx, text in enumerate(plugin_cls.MENU_BUTTONS):
                    action = MenuEntry(
                        text,
                        functools.partial(self._dispatch_single, plugin,
                                          BasePlugin.handle_click_menu, False,
                                          idx))
                    plugin.__cached_menu_actions.append(action)
                    self.workspace._main_window._plugin_menu.add(action)

                for dview in self.workspace.view_manager.views_by_category[
                        'disassembly']:
                    plugin.instrument_disassembly_view(dview)
                for cview in self.workspace.view_manager.views_by_category[
                        'pseudocode']:
                    plugin.instrument_code_view(cview)

                for action in plugin_cls.URL_ACTIONS:
                    DaemonClient.register_handler(
                        action,
                        functools.partial(self._dispatch_single, plugin,
                                          BasePlugin.handle_url_action, False,
                                          action))

            for action in plugin_cls.URL_ACTIONS:
                register_url_action(action, UrlActionBinaryAware)

        except Exception:
            l.warning("Plugin %s failed to activate:",
                      plugin_cls.get_display_name(),
                      exc_info=True)
        else:
            l.info("Activated plugin %s", plugin_cls.get_display_name())
 def _register_url_handlers(self):
     register_url_action('open_source_file', UrlActionOpenSourceFile)
     register_server_exposed_method("open_source_file", self.exposed_open_source_file)