Skip to content

Commit

Permalink
Update default.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayush-Goel-04 committed Aug 19, 2023
1 parent 8a0e61b commit d3972f0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions capa/render/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pickle
import collections
from pathlib import Path

import tabulate

Expand Down Expand Up @@ -85,8 +86,13 @@ def render_capabilities(doc: rd.ResultDocument, ostream: StringIO):
"""

def load_rules_prevalence(filename: str) -> dict:
with open(filename, "rb") as pickle_file:
return pickle.load(pickle_file)
try:
with Path(filename).open("rb") as pickle_file:
return pickle.load(pickle_file)
except FileNotFoundError:
raise FileNotFoundError(f"File '{filename}' not found.")
except Exception as e:
raise RuntimeError(f"An error occurred while loading '{filename}': {e}")

subrule_matches = find_subrule_matches(doc)
rules_prevalence = load_rules_prevalence("./assets/rules_prevalence.pickle")
Expand All @@ -101,7 +107,7 @@ def load_rules_prevalence(filename: str) -> dict:
count = len(rule.matches)
matches = f"({count} matches)" if count > 1 else ""

rule_prevalence = float(rules_prevalence.get(rule.meta.name + "\n", 0))
rule_prevalence = float(rules_prevalence.get(rule.meta.name + "\n", 0) / 593)
if rule_prevalence < 0:
raise ValueError("Match probability cannot be negative")

Expand Down

0 comments on commit d3972f0

Please sign in to comment.