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

Method parse_directory_bound_imports

pythonmemorymodule/pefile.py:3700–3817  ·  view source on GitHub ↗
(self, rva, size)

Source from the content-addressed store, hash-verified

3698 return rt_funcs
3699
3700 def parse_directory_bound_imports(self, rva, size):
3701 """"""
3702
3703 bnd_descr = Structure(self.__IMAGE_BOUND_IMPORT_DESCRIPTOR_format__)
3704 bnd_descr_size = bnd_descr.sizeof()
3705 start = rva
3706
3707 bound_imports = []
3708 while True:
3709 bnd_descr = self.__unpack_data__(
3710 self.__IMAGE_BOUND_IMPORT_DESCRIPTOR_format__,
3711 self.__data__[rva : rva + bnd_descr_size],
3712 file_offset=rva,
3713 )
3714 if bnd_descr is None:
3715 # If can't parse directory then silently return.
3716 # This directory does not necessarily have to be valid to
3717 # still have a valid PE file
3718
3719 self.__warnings.append(
3720 "The Bound Imports directory exists but can't be parsed."
3721 )
3722
3723 return
3724
3725 if bnd_descr.all_zeroes():
3726 break
3727
3728 rva += bnd_descr.sizeof()
3729
3730 section = self.get_section_by_offset(rva)
3731 file_offset = self.get_offset_from_rva(rva)
3732 if section is None:
3733 safety_boundary = len(self.__data__) - file_offset
3734 sections_after_offset = [
3735 s.PointerToRawData
3736 for s in self.sections
3737 if s.PointerToRawData > file_offset
3738 ]
3739 if sections_after_offset:
3740 # Find the first section starting at a later offset than that
3741 # specified by 'rva'
3742 first_section_after_offset = min(sections_after_offset)
3743 section = self.get_section_by_offset(first_section_after_offset)
3744 if section is not None:
3745 safety_boundary = section.PointerToRawData - file_offset
3746 else:
3747 safety_boundary = (
3748 section.PointerToRawData + len(section.get_data()) - file_offset
3749 )
3750 if not section:
3751 self.__warnings.append(
3752 (
3753 "RVA of IMAGE_BOUND_IMPORT_DESCRIPTOR points "
3754 "to an invalid address: {0:x}"
3755 ).format(rva)
3756 )
3757 return

Callers

nothing calls this directly

Calls 11

sizeofMethod · 0.95
__unpack_data__Method · 0.95
all_zeroesMethod · 0.95
get_section_by_offsetMethod · 0.95
get_offset_from_rvaMethod · 0.95
get_string_from_dataMethod · 0.95
StructureClass · 0.85
PEFormatErrorClass · 0.85
BoundImportRefDataClass · 0.85
BoundImportDescDataClass · 0.85
get_dataMethod · 0.45

Tested by

no test coverage detected