示例#1
0
    def init(self):
        """
        Initialize plugin:
        """
        self._client_config = load_config()
        self._fcc = None
        if self._client_config is not None:
            self._fcc = FCatalogClient(\
                    (self._client_config.remote_host,\
                    self._client_config.remote_port),\
                    self._client_config.db_name,\
                    self._client_config.exclude_pattern)

        # Make sure that self._client config is built, even if it doesn't have
        # any fields inside:
        if self._client_config is None:
            self._client_config = ClientConfig()

        # Set up menus:
        ui_path = "Edit/"
        self.menu_contexts = []
        self.menu_contexts.append(
            add_menu_item(ui_path, "FCatalog: Configure",
                          self._show_conf_form))

        self.menu_contexts.append(
            add_menu_item(ui_path, "FCatalog: Commit Functions",
                          self._commit_funcs))
        self.menu_contexts.append(
            add_menu_item(ui_path, "FCatalog: Find Similars",
                          self._find_similars))
        self.menu_contexts.append(
            add_menu_item(ui_path, "FCatalog: Clean IDB", self._clean_idb))

        return idaapi.PLUGIN_KEEP
示例#2
0
    def _show_conf_form(self, arg):
        """
        Show the configuration form and update configuration values according
        to user choices.
        """
        # Create form
        cf = ConfForm()

        # Compile (in order to populate the controls)
        cf.Compile()

        # Populate form fields with current configuration values:
        if self._client_config.remote_host is not None:
            cf.host.value = self._client_config.remote_host
        if self._client_config.remote_port is not None:
            cf.port.value = str(self._client_config.remote_port)
        if self._client_config.db_name is not None:
            cf.db_name.value = self._client_config.db_name
        if self._client_config.exclude_pattern is not None:
            cf.exclude_pattern.value = self._client_config.exclude_pattern

        # Execute the form
        res = cf.Execute()
        if res == 1:
            # User pressed OK:

            is_conf_good = True

            # Extract host:
            host = cf.host.value
            if len(host) == 0:
                host = None
                is_conf_good = False
            self._client_config.remote_host = host

            # Extract port:
            try:
                port = int(cf.port.value)
            except ValueError:
                port = None
                is_conf_good = False
            self._client_config.remote_port = port

            # Extract db name:
            db_name = cf.db_name.value
            if len(db_name) == 0:
                db_name = None
                is_conf_good = False
            self._client_config.db_name = db_name

            # Extract exclude_pattern
            exclude_pattern = cf.exclude_pattern.value
            if len(exclude_pattern) == 0:
                exclude_pattern = None
            self._client_config.exclude_pattern = exclude_pattern

            if is_conf_good:
                save_config(self._client_config)
                self._fcc = FCatalogClient(\
                        (self._client_config.remote_host,\
                        self._client_config.remote_port),\
                        self._client_config.db_name,\
                        self._client_config.exclude_pattern)
                print('Configuration successful.')
            else:
                print('Invalid configuration.')
                self._fcc = None

        # Dispose the form
        cf.Free()