From 00b7e3e3a2ecead3fae83791a25c06a57f65de68 Mon Sep 17 00:00:00 2001 From: ydong10 Date: Fri, 4 May 2012 05:11:07 +0000 Subject: Update the logic related to get section header offset for TE image. Signed-off-by: Eric Dong Reviewed-by: Liming Gao git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13273 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'MdePkg') diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 69c649a32a..e44f04c799 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -71,6 +71,7 @@ PeCoffLoaderGetPeHeader ( UINT32 SectionHeaderOffset; UINT32 Index; CHAR8 BufferData; + UINTN NumberOfSections; EFI_IMAGE_SECTION_HEADER SectionHeader; // @@ -303,8 +304,15 @@ PeCoffLoaderGetPeHeader ( // // Check each section field. // - SectionHeaderOffset = ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + Hdr.Pe32->FileHeader.SizeOfOptionalHeader; - for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) { + if (ImageContext->IsTeImage) { + SectionHeaderOffset = sizeof(EFI_TE_IMAGE_HEADER); + NumberOfSections = (UINTN) (Hdr.Te->NumberOfSections); + } else { + SectionHeaderOffset = ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + Hdr.Pe32->FileHeader.SizeOfOptionalHeader; + NumberOfSections = (UINTN) (Hdr.Pe32->FileHeader.NumberOfSections); + } + + for (Index = 0; Index < NumberOfSections; Index++) { // // Read section header from file // -- cgit v1.2.3