def _fixup_pe_header(self, pe):
"""Fixes the PE header from an in-memory representation to an
on-disk representation."""
for section in pe.sections:
section.PointerToRawData = section.VirtualAddress
section.SizeOfRawData = max(
section.Misc_VirtualSize, section.SizeOfRawData
)
reloc = pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_BASERELOC"]
if len(pe.OPTIONAL_HEADER.DATA_DIRECTORY) < reloc:
return
reloc = pe.OPTIONAL_HEADER.DATA_DIRECTORY[reloc]
if not reloc.VirtualAddress or not reloc.Size:
return
# Disable relocations as those have already been applied.
reloc.VirtualAddress = reloc.Size = 0
pe.FILE_HEADER.Characteristics |= \
pefile.IMAGE_CHARACTERISTICS["IMAGE_FILE_RELOCS_STRIPPED"]
评论列表
文章目录