def render_capa_doc(self, doc): """render capa features specified in doc @param doc: capa result doc """ # inform model that changes are about to occur self.beginResetModel() for rule in rutils.capability_rules(doc): rule_name = rule["meta"]["name"] rule_namespace = rule["meta"].get("namespace") parent = CapaExplorerRuleItem(self.root_node, rule_name, rule_namespace, len(rule["matches"]), rule["source"]) for (location, match ) in doc["rules"][rule["meta"]["name"]]["matches"].items(): if rule["meta"]["scope"] == capa.rules.FILE_SCOPE: parent2 = parent elif rule["meta"]["scope"] == capa.rules.FUNCTION_SCOPE: parent2 = CapaExplorerFunctionItem(parent, location) elif rule["meta"]["scope"] == capa.rules.BASIC_BLOCK_SCOPE: parent2 = CapaExplorerBlockItem(parent, location) else: raise RuntimeError("unexpected rule scope: " + str(rule["meta"]["scope"])) self.render_capa_doc_match(parent2, match, doc) # inform model changes have ended self.endResetModel()
def render_capa_doc_by_function(self, doc): """ """ matches_by_function = {} for rule in rutils.capability_rules(doc): for ea in rule["matches"].keys(): ea = capa.ida.helpers.get_func_start_ea(ea) if ea is None: # file scope, skip rendering in this mode continue if not matches_by_function.get(ea, ()): # new function root matches_by_function[ea] = (CapaExplorerFunctionItem( self.root_node, ea, can_check=False), []) function_root, match_cache = matches_by_function[ea] if rule["meta"]["name"] in match_cache: # rule match already rendered for this function root, skip it continue match_cache.append(rule["meta"]["name"]) CapaExplorerRuleItem( function_root, rule["meta"]["name"], rule["meta"].get("namespace"), len(rule["matches"]), rule["source"], can_check=False, )
def render_capa_doc_by_function(self, doc): """ """ matches_by_function = {} for rule in rutils.capability_rules(doc): for ea in rule["matches"].keys(): ea = capa.ida.helpers.get_func_start_ea(ea) if ea is None: # file scope, skip for rendering in this mode continue if None is matches_by_function.get(ea, None): matches_by_function[ea] = CapaExplorerFunctionItem(self.root_node, ea, can_check=False) CapaExplorerRuleItem( matches_by_function[ea], rule["meta"]["name"], rule["meta"].get("namespace"), len(rule["matches"]), rule["source"], can_check=False, )
def render_capa_doc_by_program(self, doc): """ """ for rule in rutils.capability_rules(doc): rule_name = rule["meta"]["name"] rule_namespace = rule["meta"].get("namespace") parent = CapaExplorerRuleItem( self.root_node, rule_name, rule_namespace, len(rule["matches"]), rule["source"] ) for (location, match) in doc["rules"][rule["meta"]["name"]]["matches"].items(): if rule["meta"]["scope"] == capa.rules.FILE_SCOPE: parent2 = parent elif rule["meta"]["scope"] == capa.rules.FUNCTION_SCOPE: parent2 = CapaExplorerFunctionItem(parent, location) elif rule["meta"]["scope"] == capa.rules.BASIC_BLOCK_SCOPE: parent2 = CapaExplorerBlockItem(parent, location) else: raise RuntimeError("unexpected rule scope: " + str(rule["meta"]["scope"])) self.render_capa_doc_match(parent2, match, doc)