MCPcopy Index your code
hub / github.com/ELMERIKH/PyinMemoryPE / parse_resources_directory

Method parse_resources_directory

pythonmemorymodule/pefile.py:4131–4440  ·  view source on GitHub ↗

Parse the resources directory. Given the RVA of the resources directory, it will process all its entries. The root will have the corresponding member of its structure, IMAGE_RESOURCE_DIRECTORY plus 'entries', a list of all the entries in the directory.

(self, rva, size=0, base_rva=None, level=0, dirs=None)

Source from the content-addressed store, hash-verified

4129 return debug
4130
4131 def parse_resources_directory(self, rva, size=0, base_rva=None, level=0, dirs=None):
4132 """Parse the resources directory.
4133
4134 Given the RVA of the resources directory, it will process all
4135 its entries.
4136
4137 The root will have the corresponding member of its structure,
4138 IMAGE_RESOURCE_DIRECTORY plus 'entries', a list of all the
4139 entries in the directory.
4140
4141 Those entries will have, correspondingly, all the structure's
4142 members (IMAGE_RESOURCE_DIRECTORY_ENTRY) and an additional one,
4143 "directory", pointing to the IMAGE_RESOURCE_DIRECTORY structure
4144 representing upper layers of the tree. This one will also have
4145 an 'entries' attribute, pointing to the 3rd, and last, level.
4146 Another directory with more entries. Those last entries will
4147 have a new attribute (both 'leaf' or 'data_entry' can be used to
4148 access it). This structure finally points to the resource data.
4149 All the members of this structure, IMAGE_RESOURCE_DATA_ENTRY,
4150 are available as its attributes.
4151 """
4152
4153 # OC Patch:
4154 if dirs is None:
4155 dirs = [rva]
4156
4157 if base_rva is None:
4158 base_rva = rva
4159
4160 if level > MAX_RESOURCE_DEPTH:
4161 self.__warnings.append(
4162 "Error parsing the resources directory. "
4163 "Excessively nested table depth %d (>%s)" % (level, MAX_RESOURCE_DEPTH)
4164 )
4165 return None
4166
4167 try:
4168 # If the RVA is invalid all would blow up. Some EXEs seem to be
4169 # specially nasty and have an invalid RVA.
4170 data = self.get_data(
4171 rva, Structure(self.__IMAGE_RESOURCE_DIRECTORY_format__).sizeof()
4172 )
4173 except PEFormatError:
4174 self.__warnings.append(
4175 "Invalid resources directory. Can't read "
4176 "directory data at RVA: 0x%x" % rva
4177 )
4178 return None
4179
4180 # Get the resource directory structure, that is, the header
4181 # of the table preceding the actual entries
4182 #
4183 resource_dir = self.__unpack_data__(
4184 self.__IMAGE_RESOURCE_DIRECTORY_format__,
4185 data,
4186 file_offset=self.get_offset_from_rva(rva),
4187 )
4188 if resource_dir is None:

Callers

nothing calls this directly

Calls 15

get_dataMethod · 0.95
__unpack_data__Method · 0.95
get_offset_from_rvaMethod · 0.95
parse_resource_entryMethod · 0.95
get_pascal_16_lengthMethod · 0.95
StructureClass · 0.85
parse_stringsFunction · 0.85

Tested by

no test coverage detected