Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but\r
only supports relocating IA32, x64, IPF, and EBC images.\r
\r
- Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
// Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.\r
//\r
// Look at the file header to determine if relocations have been stripped, and\r
- // save this info in the image context for later use.\r
+ // save this information in the image context for later use.\r
//\r
if ((!(ImageContext->IsTeImage)) && ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) {\r
ImageContext->RelocationsStripped = TRUE;\r
} else {\r
ImageContext->RelocationsStripped = FALSE;\r
}\r
+ \r
+ //\r
+ // TE Image Relocation Data Directory Entry size is non-zero, but the Relocation Data Directory Virtual Address is zero.\r
+ // This case is not a valid TE image. \r
+ //\r
+ if ((ImageContext->IsTeImage) && (Hdr.Te->DataDirectory[0].Size != 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {\r
+ return RETURN_INVALID_PARAMETER;\r
+ }\r
\r
if (!(ImageContext->IsTeImage)) {\r
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
- DebugDirectoryEntryFileOffset,\r
+ DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
- DebugDirectoryEntryFileOffset,\r
+ DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *ResourceDirectoryEntry;\r
EFI_IMAGE_RESOURCE_DIRECTORY_STRING *ResourceDirectoryString;\r
EFI_IMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry;\r
+ CHAR16 *String;\r
\r
\r
ASSERT (ImageContext != NULL);\r
ImageContext->ImageError = IMAGE_ERROR_SUCCESS;\r
\r
//\r
- // Copy the provided context info into our local version, get what we\r
+ // Copy the provided context information into our local version, get what we\r
// can from the original image, and then use that to make sure everything\r
// is legit.\r
//\r
ImageContext->FixupData = NULL;\r
\r
//\r
- // Load the Codeview info if present\r
+ // Load the Codeview information if present\r
//\r
if (ImageContext->DebugDirectoryEntryRva != 0) {\r
if (!(ImageContext->IsTeImage)) {\r
for (Index = 0; Index < ResourceDirectory->NumberOfNamedEntries; Index++) {\r
if (ResourceDirectoryEntry->u1.s.NameIsString) {\r
ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);\r
+ String = &ResourceDirectoryString->String[0];\r
\r
if (ResourceDirectoryString->Length == 3 &&\r
- ResourceDirectoryString->String[0] == L'H' &&\r
- ResourceDirectoryString->String[1] == L'I' &&\r
- ResourceDirectoryString->String[2] == L'I') {\r
+ String[0] == L'H' &&\r
+ String[1] == L'I' &&\r
+ String[2] == L'I') {\r
//\r
// Resource Type "HII" found\r
//\r