Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small simplifications #434

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,12 @@ def get_entropy(self):

return self.entropy_H(self.get_data())

def get_hash_md5(self):
"""Get the MD5 hex-digest of the section's data."""

if md5 is not None:
return md5(self.get_data()).hexdigest()

def get_hash_sha1(self):
"""Get the SHA-1 hex-digest of the section's data."""

Expand All @@ -1318,12 +1324,6 @@ def get_hash_sha512(self):
if sha512 is not None:
return sha512(self.get_data()).hexdigest()

def get_hash_md5(self):
"""Get the MD5 hex-digest of the section's data."""

if md5 is not None:
return md5(self.get_data()).hexdigest()

def entropy_H(self, data):
"""Calculate the entropy of a chunk of data."""

Expand All @@ -1334,7 +1334,7 @@ def entropy_H(self, data):

entropy = 0
for x in occurences.values():
p_x = float(x) / len(data)
p_x = x / len(data)
entropy -= p_x * math.log(p_x, 2)

return entropy
Expand Down Expand Up @@ -6002,13 +6002,12 @@ def parse_imports(
# bound.
iat = self.get_import_table(first_thunk, max_length, contains_addresses)

# Would crash if IAT or ILT had None type
if (not iat or len(iat) == 0) and (not ilt or len(ilt) == 0):
if (not iat) and (not ilt):
self.__warnings.append(
"Damaged Import Table information. "
"ILT and/or IAT appear to be broken. "
f"OriginalFirstThunk: 0x{original_first_thunk:x} "
f"FirstThunk: 0x{first_thunk:x}"
f"OriginalFirstThunk: {original_first_thunk:#x} "
f"FirstThunk: {first_thunk:#x}"
)
return []

Expand Down
Loading