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

Method parse_export_directory

pythonmemorymodule/pefile.py:4934–5197  ·  view source on GitHub ↗

Parse the export directory. Given the RVA of the export directory, it will process all its entries. The exports will be made available as a list of ExportData instances in the 'IMAGE_DIRECTORY_ENTRY_EXPORT' PE attribute.

(self, rva, size, forwarded_only=False)

Source from the content-addressed store, hash-verified

4932 self.FileInfo.append(finfo)
4933
4934 def parse_export_directory(self, rva, size, forwarded_only=False):
4935 """Parse the export directory.
4936
4937 Given the RVA of the export directory, it will process all
4938 its entries.
4939
4940 The exports will be made available as a list of ExportData
4941 instances in the 'IMAGE_DIRECTORY_ENTRY_EXPORT' PE attribute.
4942 """
4943
4944 try:
4945 export_dir = self.__unpack_data__(
4946 self.__IMAGE_EXPORT_DIRECTORY_format__,
4947 self.get_data(
4948 rva, Structure(self.__IMAGE_EXPORT_DIRECTORY_format__).sizeof()
4949 ),
4950 file_offset=self.get_offset_from_rva(rva),
4951 )
4952 except PEFormatError:
4953 self.__warnings.append(
4954 "Error parsing export directory at RVA: 0x%x" % (rva)
4955 )
4956 return
4957
4958 if not export_dir:
4959 return
4960
4961 # We keep track of the bytes left in the file and use it to set a upper
4962 # bound in the number of items that can be read from the different
4963 # arrays.
4964 def length_until_eof(rva):
4965 return len(self.__data__) - self.get_offset_from_rva(rva)
4966
4967 try:
4968 address_of_names = self.get_data(
4969 export_dir.AddressOfNames,
4970 min(
4971 length_until_eof(export_dir.AddressOfNames),
4972 export_dir.NumberOfNames * 4,
4973 ),
4974 )
4975 address_of_name_ordinals = self.get_data(
4976 export_dir.AddressOfNameOrdinals,
4977 min(
4978 length_until_eof(export_dir.AddressOfNameOrdinals),
4979 export_dir.NumberOfNames * 4,
4980 ),
4981 )
4982 address_of_functions = self.get_data(
4983 export_dir.AddressOfFunctions,
4984 min(
4985 length_until_eof(export_dir.AddressOfFunctions),
4986 export_dir.NumberOfFunctions * 4,
4987 ),
4988 )
4989 except PEFormatError:
4990 self.__warnings.append(
4991 "Error parsing export directory at RVA: 0x%x" % (rva)

Callers

nothing calls this directly

Calls 13

__unpack_data__Method · 0.95
get_dataMethod · 0.95
get_offset_from_rvaMethod · 0.95
get_section_by_rvaMethod · 0.95
get_word_from_dataMethod · 0.95
get_dword_from_dataMethod · 0.95
get_string_at_rvaMethod · 0.95
StructureClass · 0.85
is_valid_function_nameFunction · 0.85
ExportDataClass · 0.85
ExportDirDataClass · 0.85
all_zeroesMethod · 0.80

Tested by

no test coverage detected