Skip to content

Commit

Permalink
Merge pull request #373 from j-t-1/floor_division
Browse files Browse the repository at this point in the history
Floor division (//) does mathematical division with the floor functio…
  • Loading branch information
erocarrera authored Apr 7, 2023
2 parents 0463745 + 0afd75e commit 270b44e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3359,10 +3359,10 @@ def parse_rich_header(self):
rich_data = self.__data__[0x80 : rich_index + 8]
# Make the data have length a multiple of 4, otherwise the
# subsequent parsing will fail. It's not impossible that we retrieve
# truncated data that it's not a multiple.
rich_data = rich_data[: 4 * int(len(rich_data) / 4)]
# truncated data that is not a multiple.
rich_data = rich_data[: 4 * (len(rich_data) // 4)]
data = list(
struct.unpack("<{0}I".format(int(len(rich_data) / 4)), rich_data)
struct.unpack("<{0}I".format(len(rich_data) // 4), rich_data)
)
if RICH not in data:
return None
Expand Down Expand Up @@ -3394,7 +3394,7 @@ def parse_rich_header(self):
result["values"] = headervalues

data = data[4:]
for i in range(int(len(data) / 2)):
for i in range(len(data) // 2):

# Stop until the Rich footer signature is found
#
Expand Down Expand Up @@ -4209,7 +4209,7 @@ def parse_relocations(self, data_rva, rva, size):

entries = []
offsets_and_type = set()
for idx in range(int(len(data) / 2)):
for idx in range(len(data) // 2):

entry = self.__unpack_data__(
self.__IMAGE_BASE_RELOCATION_ENTRY_format__,
Expand Down Expand Up @@ -4254,7 +4254,7 @@ def parse_relocations_with_format(self, data_rva, rva, size, format):
entry_size = StructureWithBitfields(format).sizeof()
entries = []
offsets = set()
for idx in range(int(len(data) / entry_size)):
for idx in range(len(data) // entry_size):

entry = self.__unpack_data_with_bitfields__(
format,
Expand Down Expand Up @@ -7610,11 +7610,11 @@ def generate_checksum(self):
remainder = len(self.__data__) % 4
data_len = len(self.__data__) + ((4 - remainder) * (remainder != 0))

for i in range(int(data_len / 4)):
for i in range(data_len // 4):
# Skip the checksum field
if i == int(checksum_offset / 4):
if i == checksum_offset // 4:
continue
if i + 1 == (int(data_len / 4)) and remainder:
if i + 1 == (data_len // 4) and remainder:
dword = struct.unpack(
"I", self.__data__[i * 4 :] + (b"\0" * (4 - remainder))
)[0]
Expand Down

0 comments on commit 270b44e

Please sign in to comment.