/** @file
loaded into memory or is executing at it's linked address.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Base.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/DebugLib.h>
#include <IndustryStandard/PeImage.h>
/**
return RETURN_INVALID_PARAMETER. Otherwise return RETURN_SUCCESS.
If Pe32Data is NULL, then ASSERT().
If EntryPoint is NULL, then ASSERT().
@retval RETURN_SUCCESS EntryPoint was returned.
**/
)
{
//
// DOS image header is present, so read the PE header after the DOS image header.
//
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
}
//
// Calculate the entry point relative to the start of the image.
// AddressOfEntryPoint is common for PE32 & PE32+
//
*EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
return RETURN_SUCCESS;
*EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
return RETURN_SUCCESS;
}
return RETURN_UNSUPPORTED;
}
/**
If Pe32Data is NULL, then ASSERT().
memory.
@return Machine type or zero if not a valid image.
**/
)
{
//
// DOS image header is present, so read the PE header after the DOS image header.
//
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
}
}
return 0x0000;
}
/**
debug directory entry, then NULL is returned. If the debug directory entry
then NULL is returned.
If Pe32Data is NULL, then ASSERT().
memory.
if it cannot be retrieved.
**/
VOID *
)
{
TEImageAdjust = 0;
DebugEntry = NULL;
NumberOfRvaAndSizes = 0;
//
// DOS image header is present, so read the PE header after the DOS image header.
//
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
}
}
//
// It is due to backward-compatibility, for some system might
// generate PE32+ image with PE32 Magic.
//
case IMAGE_FILE_MACHINE_I386:
//
// Assume PE32 image with IA32 Machine field.
//
break;
case IMAGE_FILE_MACHINE_X64:
case IMAGE_FILE_MACHINE_IA64:
//
// Assume PE32+ image with x64 or IA64 Machine field
//
break;
default:
//
// For unknow Machine field, use Magic in optional Header
//
}
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset get Debug Directory Entry
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
//
// Use PE32+ offset get Debug Directory Entry
//
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
}
DebugEntry = NULL;
}
} else {
return NULL;
}
return NULL;
}
//
// Scan the directory to find the debug entry.
//
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {
if (DebugEntry->SizeOfData > 0) {
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
switch (* (UINT32 *) CodeViewEntryPointer) {
case CODEVIEW_SIGNATURE_NB10:
case CODEVIEW_SIGNATURE_RSDS:
case CODEVIEW_SIGNATURE_MTOC:
default:
break;
}
}
}
}
return NULL;
}
/**
If Pe32Data is NULL, then ASSERT().
memory.
**/
)
{
//
// DOS image header is present, so read the PE header after the DOS image header.
//
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
}
SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
} else {
SizeOfHeaders = 0;
}
return (UINT32) SizeOfHeaders;
}