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

Method get_OptionalHeader

windows/pe_parse.py:341–357  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

339 )
340
341 def get_OptionalHeader(self):
342 # We can have a 32bits PE with a 64 bits OptionalHeader
343 # Ex : PE32 .NET that allow to be loaded in 64b process
344 # See: https://github.com/dotnet/runtime/blob/8bbe33819464216becffb7cf8b7ea8dd3bab5836/src/coreclr/src/vm/peimagelayout.cpp#L599
345 # In this case the OptionalHeader is transformed in 64bits & OptionalHeader.Magic is changed accordingly
346 # So we cannot just rely on get_NT_HEADER() to give us the correct OptionalHeader type. some re-check are required
347 default_opth = self.get_NT_HEADER().OptionalHeader
348 # Cannot juste compare types with type(default_opth) as it may be a remoteType
349 current_opth_infos = (default_opth.Magic, ctypes.sizeof(default_opth))
350 if current_opth_infos in self.STANDARD_OPTIONAL_HEADER_SIZE_PER_MAGIC:
351 # The default OptionalHeader structure match what we expect based on the magic (most of the cases)
352 return default_opth
353 # Mismatch -> PE32 remapped as 64b (with OptionalHeader rewrite)
354 # Remap the correct OptionalHeader
355 opt_header_real_type = self.STANDARD_OPTIONAL_HEADER_TYPE_PER_MAGIC[default_opth.Magic]
356 opt_header_addr = default_opth._base_addr if self.target else ctypes.addressof(default_opth)
357 return self.transformers.create_structure_at(opt_header_real_type, opt_header_addr)
358
359 def get_DataDirectory(self):
360 return self.get_OptionalHeader().DataDirectory

Callers 1

get_DataDirectoryMethod · 0.95

Calls 2

get_NT_HEADERMethod · 0.95
sizeofMethod · 0.45

Tested by

no test coverage detected