Skip to content

Commit 805810f

Browse files
authored
Merge pull request #456 from j-t-1/peutils
Tweak peutils.py
2 parents 9c84475 + 2924448 commit 805810f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

peutils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def __init__(self, filename=None, data=None):
5757
# - A dictionary with a string as a key (packer name)
5858
# and None as value to indicate a full signature
5959
#
60-
self.signature_tree_eponly_true = dict()
60+
self.signature_tree_eponly_true = {}
6161
self.signature_count_eponly_true = 0
62-
self.signature_tree_eponly_false = dict()
62+
self.signature_tree_eponly_false = {}
6363
self.signature_count_eponly_false = 0
64-
self.signature_tree_section_start = dict()
64+
self.signature_tree_section_start = {}
6565
self.signature_count_section_start = 0
6666

6767
# The depth (length) of the longest signature
@@ -92,7 +92,7 @@ def generate_section_signatures(self, pe, name, sig_length=512):
9292
name,
9393
idx + 1,
9494
len(pe.sections),
95-
"".join([c for c in section.Name if c in string.printable]),
95+
"".join(c for c in section.Name if c in string.printable),
9696
)
9797

9898
section_signatures.append(
@@ -127,7 +127,7 @@ def __generate_signature(
127127

128128
data = pe.__data__[offset : offset + sig_length]
129129

130-
signature_bytes = " ".join(["%02x" % ord(c) for c in data])
130+
signature_bytes = " ".join(f"{ord(c):02x}" for c in data)
131131

132132
if ep_only == True:
133133
ep_only = "true"
@@ -340,7 +340,7 @@ def __match_signature_tree(self, signature_tree, data, depth=0):
340340
if None in list(match.values()):
341341
# idx represent how deep we are in the tree
342342
#
343-
# names = [idx+depth]
343+
# names = [idx + depth]
344344
names = list()
345345

346346
# For each of the item pairs we check
@@ -498,9 +498,9 @@ def is_valid(pe):
498498

499499
def is_suspicious(pe):
500500
"""
501-
unusual locations of import tables
502-
non recognized section names
503-
presence of long ASCII strings
501+
Unusual locations of import tables
502+
Non-recognized section names
503+
Presence of long ASCII strings
504504
"""
505505

506506
relocations_overlap_entry_point = False
@@ -542,7 +542,7 @@ def is_suspicious(pe):
542542
warnings_while_parsing
543543

544544
# If there are few or none (should come with a standard "density" of strings/kilobytes of data) longer (>8)
545-
# ascii sequences that might indicate packed data, (this is similar to the entropy test in some ways but
545+
# ASCII sequences that might indicate packed data, (this is similar to the entropy test in some ways but
546546
# might help to discard cases of legitimate installer or compressed data)
547547

548548
# If compressed data (high entropy) and is_driver => uuuuhhh, nasty
@@ -580,7 +580,6 @@ def is_probably_packed(pe, section_entropy=7.4, packed_threshold=0.2):
580580
# Assume that the file is packed when no data is available
581581
if not total_pe_data_length:
582582
return True
583-
has_significant_amount_of_compressed_data = False
584583

585584
# If some of the sections have high entropy and they make for more than 20% of the file's size
586585
# it's assumed that it could be an installer or a packed file
@@ -591,6 +590,7 @@ def is_probably_packed(pe, section_entropy=7.4, packed_threshold=0.2):
591590
if s_entropy > section_entropy:
592591
total_compressed_data += len(section.get_data())
593592

593+
has_significant_amount_of_compressed_data = False
594594
if (total_compressed_data / total_pe_data_length) > packed_threshold:
595595
has_significant_amount_of_compressed_data = True
596596

0 commit comments

Comments
 (0)