MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / get_memory_mapped_image

Method get_memory_mapped_image

pythonmemorymodule/pefile.py:5773–5844  ·  view source on GitHub ↗

Returns the data corresponding to the memory layout of the PE file. The data includes the PE header and the sections loaded at offsets corresponding to their relative virtual addresses. (the VirtualAddress section header member). Any offset in this data corresponds t

(self, max_virtual_address=0x10000000, ImageBase=None)

Source from the content-addressed store, hash-verified

5771 return table
5772
5773 def get_memory_mapped_image(self, max_virtual_address=0x10000000, ImageBase=None):
5774 """Returns the data corresponding to the memory layout of the PE file.
5775
5776 The data includes the PE header and the sections loaded at offsets
5777 corresponding to their relative virtual addresses. (the VirtualAddress
5778 section header member).
5779 Any offset in this data corresponds to the absolute memory address
5780 ImageBase+offset.
5781
5782 The optional argument 'max_virtual_address' provides with means of limiting
5783 which sections are processed.
5784 Any section with their VirtualAddress beyond this value will be skipped.
5785 Normally, sections with values beyond this range are just there to confuse
5786 tools. It's a common trick to see in packed executables.
5787
5788 If the 'ImageBase' optional argument is supplied, the file's relocations
5789 will be applied to the image by calling the 'relocate_image()' method. Beware
5790 that the relocation information is applied permanently.
5791 """
5792
5793 # Rebase if requested
5794 #
5795 if ImageBase is not None:
5796
5797 # Keep a copy of the image's data before modifying it by rebasing it
5798 #
5799 original_data = self.__data__
5800
5801 self.relocate_image(ImageBase)
5802
5803 # Collect all sections in one code block
5804 mapped_data = self.__data__[:]
5805 for section in self.sections:
5806
5807 # Miscellaneous integrity tests.
5808 # Some packer will set these to bogus values to make tools go nuts.
5809 if section.Misc_VirtualSize == 0 and section.SizeOfRawData == 0:
5810 continue
5811
5812 srd = section.SizeOfRawData
5813 prd = self.adjust_FileAlignment(
5814 section.PointerToRawData, self.OPTIONAL_HEADER.FileAlignment
5815 )
5816 VirtualAddress_adj = self.adjust_SectionAlignment(
5817 section.VirtualAddress,
5818 self.OPTIONAL_HEADER.SectionAlignment,
5819 self.OPTIONAL_HEADER.FileAlignment,
5820 )
5821
5822 if (
5823 srd > len(self.__data__)
5824 or prd > len(self.__data__)
5825 or srd + prd > len(self.__data__)
5826 or VirtualAddress_adj >= max_virtual_address
5827 ):
5828 continue
5829
5830 padding_length = VirtualAddress_adj - len(mapped_data)

Callers

nothing calls this directly

Calls 4

relocate_imageMethod · 0.95
adjust_FileAlignmentMethod · 0.95
get_dataMethod · 0.45

Tested by

no test coverage detected