From f845382471552f57f2fcc84ea171b2b788cae024 Mon Sep 17 00:00:00 2001 From: mr-tz Date: Tue, 30 Jan 2024 14:56:29 +0100 Subject: [PATCH] fix rule display and save functionality --- capa/ida/plugin/form.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index ddd4c4e0d..dcc1ca462 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -1073,9 +1073,7 @@ def load_capa_function_results(self): self.view_rulegen_features.load_features(all_file_features, all_function_features) - self.set_view_status_label( - f"capa rules: {settings.user[CAPA_SETTINGS_RULE_PATH]} ({settings.user[CAPA_SETTINGS_RULE_PATH]} rules)" - ) + self.set_view_status_label(f"capa rules: {settings.user[CAPA_SETTINGS_RULE_PATH]}") except Exception as e: logger.exception("Failed to render views (error: %s)", e) return False @@ -1324,10 +1322,17 @@ def save_function_analysis(self): idaapi.info("No rule to save.") return - path = Path(self.ask_user_capa_rule_file()) - if not path.exists(): + rule_file_path = self.ask_user_capa_rule_file() + if not rule_file_path: + # dialog canceled + return + + path = Path(rule_file_path) + if not path.parent.exists(): + logger.warning("Failed to save file: parent directory '%s' does not exist.", path.parent) return + logger.info("Saving rule to %s.", path) write_file(path, s) def slot_checkbox_limit_by_changed(self, state):