4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: PeCoffGetEntryPoint.c
20 Loads a PE/COFF image into memory.
22 @param Pe32Data Pointer to a PE/COFF Image
24 @param EntryPoint Pointer to the entry point of the PE/COFF image
26 @retval EFI_SUCCESS if the EntryPoint was returned
27 @retval EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data
32 PeCoffLoaderGetEntryPoint (
34 IN OUT VOID
**EntryPoint
37 EFI_IMAGE_DOS_HEADER
*DosHeader
;
38 EFI_IMAGE_NT_HEADERS
*PeHeader
;
40 DosHeader
= (EFI_IMAGE_DOS_HEADER
*)Pe32Data
;
41 if (DosHeader
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
43 // DOS image header is present, so read the PE header after the DOS image header
45 PeHeader
= (EFI_IMAGE_NT_HEADERS
*) ((UINTN
) Pe32Data
+ (UINTN
) ((DosHeader
->e_lfanew
) & 0x0ffff));
48 // DOS image header is not present, so PE header is at the image base
50 PeHeader
= (EFI_IMAGE_NT_HEADERS
*) Pe32Data
;
52 *EntryPoint
= (VOID
*) ((UINTN
) Pe32Data
+ (UINTN
) (PeHeader
->OptionalHeader
.AddressOfEntryPoint
& 0x0ffffffff));
53 return RETURN_SUCCESS
;