From 8ffa8ea2c883a1c6f1d4dae39b4a87852508fdcc Mon Sep 17 00:00:00 2001 From: Michael Hunhoff Date: Wed, 25 Aug 2021 15:40:12 -0600 Subject: [PATCH] explorer: small performance boost to rule generator search functionality --- CHANGELOG.md | 1 + capa/ida/plugin/view.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a21eed..b46afeed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ - explorer: add additional filter logic when displaying matches by function #686 @mike-hunhoff - explorer: remove duplicate check when saving file #687 @mike-hunhoff - explorer: update IDA extractor to use non-canon mnemonics #688 @mike-hunhoff +- explorer: small performance boost to rule generator search functionality #742 @mike-hunhoff ### Development diff --git a/capa/ida/plugin/view.py b/capa/ida/plugin/view.py index 3986114a..13879b07 100644 --- a/capa/ida/plugin/view.py +++ b/capa/ida/plugin/view.py @@ -856,10 +856,13 @@ class CapaExplorerRulegenFeatures(QtWidgets.QTreeWidget): if data: to_match = data.get_value_str() if not to_match or text.lower() not in to_match.lower(): - o.setHidden(True) + if not o.isHidden(): + o.setHidden(True) continue - o.setHidden(False) - o.setExpanded(True) + if o.isHidden(): + o.setHidden(False) + if o.childCount() and not o.isExpanded(): + o.setExpanded(True) else: self.show_all_items() @@ -871,8 +874,10 @@ class CapaExplorerRulegenFeatures(QtWidgets.QTreeWidget): """iteratively show and expand an item and its' parents""" while _o: visited.append(_o) - _o.setHidden(False) - _o.setExpanded(True) + if _o.isHidden(): + _o.setHidden(False) + if _o.childCount() and not _o.isExpanded(): + _o.setExpanded(True) _o = _o.parent() for o in iterate_tree(self): @@ -885,7 +890,8 @@ class CapaExplorerRulegenFeatures(QtWidgets.QTreeWidget): if o_ea == "": # ea may be empty, hide by default - o.setHidden(True) + if not o.isHidden(): + o.setHidden(True) continue o_ea = int(o_ea, 16) @@ -896,7 +902,8 @@ class CapaExplorerRulegenFeatures(QtWidgets.QTreeWidget): show_item_and_parents(o) else: # made it here, hide by default - o.setHidden(True) + if not o.isHidden(): + o.setHidden(True) # resize the view for UX resize_columns_to_content(self.header())