From b611ddeb6e4f837c8728a01a8c53f696bc192610 Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Tue, 1 Sep 2020 16:12:50 -0600 Subject: [PATCH 1/3] ida: use ida-settings to persist rules directory closes #268 --- capa/ida/plugin/form.py | 21 +++++++++++++++------ setup.py | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index 26498370..d2c6d531 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -12,6 +12,7 @@ import logging import collections import idaapi +import ida_settings from PyQt5 import QtGui, QtCore, QtWidgets import capa.main @@ -25,6 +26,7 @@ from capa.ida.plugin.model import CapaExplorerDataModel from capa.ida.plugin.proxy import CapaExplorerSortFilterProxyModel logger = logging.getLogger("capa") +settings = ida_settings.IDASettings("capa") class CapaExplorerForm(idaapi.PluginForm): @@ -303,12 +305,16 @@ class CapaExplorerForm(idaapi.PluginForm): def load_capa_results(self): """ run capa analysis and render results in UI """ if not self.rule_path: - rule_path = self.ask_user_directory() - if not rule_path: - capa.ida.helpers.inform_user_ida_ui("You must select a rules directory to use for analysis.") - logger.warning("no rules directory selected. nothing to do.") - return - self.rule_path = rule_path + if "rule_path" in settings: + self.rule_path = settings["rule_path"] + else: + rule_path = self.ask_user_directory() + if not rule_path: + capa.ida.helpers.inform_user_ida_ui("You must select a rules directory to use for analysis.") + logger.warning("no rules directory selected. nothing to do.") + return + self.rule_path = rule_path + settings.user["rule_path"] = rule_path logger.info("-" * 80) logger.info(" Using rules from %s." % self.rule_path) @@ -520,6 +526,9 @@ class CapaExplorerForm(idaapi.PluginForm): if not rule_path: logger.warning("no rules directory selected. nothing to do.") return + self.rule_path = rule_path + settings.user["rule_path"] = rule_path + if 1 == idaapi.ask_yn(1, "Run analysis now?"): self.reload() diff --git a/setup.py b/setup.py index de7481fc..0460eeb5 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ import sys import setuptools # halo==0.0.30 is the last version to support py2.7 -requirements = ["six", "tqdm", "pyyaml", "tabulate", "colorama", "termcolor", "ruamel.yaml", "wcwidth", "halo==0.0.30"] +requirements = ["six", "tqdm", "pyyaml", "tabulate", "colorama", "termcolor", "ruamel.yaml", "wcwidth", "halo==0.0.30", "ida-settings=1.0.1"] if sys.version_info >= (3, 0): # py3 From ea6698e27a4dff0e6f89ad94226af088393fd630 Mon Sep 17 00:00:00 2001 From: William Ballenthin Date: Tue, 1 Sep 2020 17:52:29 -0600 Subject: [PATCH 2/3] pep8 --- setup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0460eeb5..4f6867be 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,18 @@ import sys import setuptools # halo==0.0.30 is the last version to support py2.7 -requirements = ["six", "tqdm", "pyyaml", "tabulate", "colorama", "termcolor", "ruamel.yaml", "wcwidth", "halo==0.0.30", "ida-settings=1.0.1"] +requirements = [ + "six", + "tqdm", + "pyyaml", + "tabulate", + "colorama", + "termcolor", + "ruamel.yaml", + "wcwidth", + "halo==0.0.30", + "ida-settings=1.0.1", +] if sys.version_info >= (3, 0): # py3 From 3d6d38c4fb284badf7e55dab7a7e592457c0e8d3 Mon Sep 17 00:00:00 2001 From: William Ballenthin Date: Tue, 1 Sep 2020 17:53:10 -0600 Subject: [PATCH 3/3] setup: fix ida-settings spec --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4f6867be..0c5158fd 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ requirements = [ "ruamel.yaml", "wcwidth", "halo==0.0.30", - "ida-settings=1.0.1", + "ida-settings==1.0.1", ] if sys.version_info >= (3, 0):