From a8c39ba2986c1ffb1dab864cefedc86402a9695c Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Thu, 31 Mar 2016 09:27:38 +0200 Subject: ArmPlatformPkg/DS-5: fix 64-bit PE/COFF header parsing bug The 64-bit version of the DS-5 debug script that retrieves the debug file path from the PE/COFF image in memory assumes that the PE/COFF header is packed, and that the debug directory entry in the optional header appears at a fixed offset into the file. This is no longer true, now that we pad between the file header and the PE header if the section alignment exceeds the size of the header (which may be the case when the module contains a vector table or small model code, which requires 2 KB or 4 KB section alignment, respectively), to allow this padding to be emitted if the image is subsequently converted to TE format. So replace the fixed offset with a dereference of the appropriate header field. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reported-by: Vladimir Olovyannikov --- ArmPlatformPkg/Scripts/Ds5/firmware_volume.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ArmPlatformPkg/Scripts') diff --git a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py index c434e3de19..9a76ae066d 100644 --- a/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py +++ b/ArmPlatformPkg/Scripts/Ds5/firmware_volume.py @@ -138,11 +138,10 @@ class EfiSectionPE64: def get_debug_filepath(self): # Offset from dos hdr to PE file hdr (EFI_IMAGE_NT_HEADERS64) - #file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C) - file_header_offset = 0x0 + file_header_offset = self.ec.getMemoryService().readMemory32(self.base_pe64 + 0x3C) # Offset to debug dir in PE hdrs - debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + file_header_offset + 0x138) + debug_dir_entry_rva = self.ec.getMemoryService().readMemory32(self.base_pe64 + file_header_offset + 0xB8) if debug_dir_entry_rva == 0: raise Exception("EfiFileSectionPE64","No Debug Directory") -- cgit v1.2.3