Skip to content

Commit

Permalink
Merge pull request #344 from elicn/faster-reloc
Browse files Browse the repository at this point in the history
Speed up relocation process
  • Loading branch information
erocarrera authored Apr 10, 2022
2 parents 4911c83 + fe3b98a commit e999b6d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6962,14 +6962,18 @@ def set_bytes_at_offset(self, offset, data):
raise TypeError("data should be of type: bytes")

if 0 <= offset < len(self.__data__):
self.__data__ = (
self.__data__[:offset] + data + self.__data__[offset + len(data) :]
)
self.set_data_bytes(offset, data)
else:
return False

return True

def set_data_bytes(self, offset: int, data: bytes):
if not isinstance(self.__data__, bytearray):
self.__data__ = bytearray(self.__data__)

self.__data__[offset:offset + len(data)] = data

def merge_modified_section_data(self):
"""Update the PE image content with any individual section data that has been
modified.
Expand All @@ -6983,11 +6987,7 @@ def merge_modified_section_data(self):
if section_data_start < len(self.__data__) and section_data_end < len(
self.__data__
):
self.__data__ = (
self.__data__[:section_data_start]
+ section.get_data()
+ self.__data__[section_data_end:]
)
self.set_data_bytes(section_data_start, section.get_data())

def relocate_image(self, new_ImageBase):
"""Apply the relocation information to the image using the provided image base.
Expand Down

0 comments on commit e999b6d

Please sign in to comment.