Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13657
6f19259b-4bc3-4df7-8a09-
765794883524
IA-32, x86, IPF, and EBC processor types. The library functions are memory-based \r
and can be ported easily to any environment.\r
\r
IA-32, x86, IPF, and EBC processor types. The library functions are memory-based \r
and can be ported easily to any environment.\r
\r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available under \r
the terms and conditions of the BSD License that accompanies this distribution. \r
The full text of the license may be found at\r
This program and the accompanying materials are licensed and made available under \r
the terms and conditions of the BSD License that accompanies this distribution. \r
The full text of the license may be found at\r
@param Buffer Output buffer that contains the data read from the PE/COFF image.\r
\r
@retval RETURN_SUCCESS The specified portion of the PE/COFF image was \r
@param Buffer Output buffer that contains the data read from the PE/COFF image.\r
\r
@retval RETURN_SUCCESS The specified portion of the PE/COFF image was \r
+ read and the size return in ReadSize.\r
@retval RETURN_DEVICE_ERROR The specified portion of the PE/COFF image \r
could not be read due to a device error.\r
\r
@retval RETURN_DEVICE_ERROR The specified portion of the PE/COFF image \r
could not be read due to a device error.\r
\r
RETURN_STATUS Status;\r
EFI_IMAGE_DOS_HEADER DosHdr;\r
UINTN Size;\r
RETURN_STATUS Status;\r
EFI_IMAGE_DOS_HEADER DosHdr;\r
UINTN Size;\r
UINT16 Magic;\r
UINT32 SectionHeaderOffset;\r
UINT32 Index;\r
UINT16 Magic;\r
UINT32 SectionHeaderOffset;\r
UINT32 Index;\r
// Read the DOS image header to check for its existence\r
//\r
Size = sizeof (EFI_IMAGE_DOS_HEADER);\r
// Read the DOS image header to check for its existence\r
//\r
Size = sizeof (EFI_IMAGE_DOS_HEADER);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
0,\r
&Size,\r
&DosHdr\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
0,\r
&Size,\r
&DosHdr\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
// location in both images.\r
//\r
Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
// location in both images.\r
//\r
Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
ImageContext->PeCoffHeaderOffset,\r
&Size,\r
Hdr.Pe32\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
ImageContext->PeCoffHeaderOffset,\r
&Size,\r
Hdr.Pe32\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
- // Read Hdr.Pe32.OptionalHeader.SizeOfHeaders data from file\r
+ // 2.2 Read last byte of Hdr.Pe32.OptionalHeader.SizeOfHeaders from the file.\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32->OptionalHeader.SizeOfHeaders - 1,\r
&Size,\r
&BufferData\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32->OptionalHeader.SizeOfHeaders - 1,\r
&Size,\r
&BufferData\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
- // Read section header from file\r
+ // Read last byte of section header from file\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress +\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress +\r
&Size,\r
&BufferData\r
);\r
&Size,\r
&BufferData\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
- // Read Hdr.Pe32.OptionalHeader.SizeOfHeaders data from file\r
+ // 2.2 Read last byte of Hdr.Pe32Plus.OptionalHeader.SizeOfHeaders from the file.\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - 1,\r
&Size,\r
&BufferData\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders - 1,\r
&Size,\r
&BufferData\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
- // Read section header from file\r
+ // Read last byte of section header from file\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress +\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress +\r
&Size,\r
&BufferData\r
);\r
&Size,\r
&BufferData\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
// Read the last byte to make sure the data is in the image region.\r
//\r
Size = 1;\r
// Read the last byte to make sure the data is in the image region.\r
//\r
Size = 1;\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeader.PointerToRawData + SectionHeader.SizeOfRawData - 1,\r
&Size,\r
&BufferData\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeader.PointerToRawData + SectionHeader.SizeOfRawData - 1,\r
&Size,\r
&BufferData\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
EFI_IMAGE_DATA_DIRECTORY *DebugDirectoryEntry;\r
UINTN Size;\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
EFI_IMAGE_DATA_DIRECTORY *DebugDirectoryEntry;\r
UINTN Size;\r
UINTN Index;\r
UINTN DebugDirectoryEntryRva;\r
UINTN DebugDirectoryEntryFileOffset;\r
UINTN Index;\r
UINTN DebugDirectoryEntryRva;\r
UINTN DebugDirectoryEntryFileOffset;\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
// Read next debug directory entry\r
//\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
// Read next debug directory entry\r
//\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
// Read section header from file\r
//\r
Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
SectionHeaderOffset,\r
&Size,\r
&SectionHeader\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
// Read next debug directory entry\r
//\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
// Read next debug directory entry\r
//\r
Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
Status = ImageContext->ImageRead (\r
ImageContext->Handle,\r
DebugDirectoryEntryFileOffset + Index,\r
&Size,\r
&DebugEntry\r
);\r
- if (RETURN_ERROR (Status)) {\r
+ if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r
ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
return Status;\r
}\r