diff --git a/grouping/pe_parse.py b/grouping/pe_parse.py index 4d6a20b..1b752e3 100755 --- a/grouping/pe_parse.py +++ b/grouping/pe_parse.py @@ -6,6 +6,7 @@ import math import argparse import redis +from collections import Counter try: from configparser import SafeConfigParser except ImportError: @@ -108,9 +109,10 @@ def H(data): if not data: return 0 + occurrences = Counter(bytearray(data)) entropy = 0 for x in range(256): - p_x = float(data.count(bytes(x))) / len(data) + p_x = float(occurrences[x]) / len(data) if p_x > 0: entropy += - p_x * math.log(p_x, 2) return entropy