OpenCore
1.0.4
OpenCore Bootloader
|
#include <Base.h>
#include <Uefi/UefiBaseType.h>
#include <IndustryStandard/PeImage2.h>
#include <Guid/WinCertificate.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/PeCoffLib2.h>
#include <Library/OcStringLib.h>
#include "BasePeCoffLib2Internals.h"
Go to the source code of this file.
Functions | |
STATIC RETURN_STATUS | InternalVerifySections (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 FileSize, OUT UINT32 *StartAddress, IN BOOLEAN InMemoryFixup) |
STATIC RETURN_STATUS | InternalValidateRelocInfo (IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 StartAddress) |
STATIC RETURN_STATUS | InternalInitializePe (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 FileSize, IN BOOLEAN InMemoryFixup) |
RETURN_STATUS | OcPeCoffFixupInitializeContext (OUT PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN CONST VOID *FileBuffer, IN UINT32 FileSize, IN BOOLEAN InMemoryFixup) |
Implements APIs to fix certain issues in legacy EFI files in memory before loading.
Very closely based on MdePkg/Library/BasePeCoffLib2/PeCoffInit.c, and intentionally kept more similar to that file than it would otherwise need to be, to easily allow diffing and importing future changes if required.
Copyright (c) 2023, Mike Beaton, Vitaly Cheptsov. All rights reserved.
Copyright (c) 2020 - 2021, Marvin Häuser. All rights reserved.
Copyright (c) 2020, Vitaly Cheptsov. All rights reserved.
Copyright (c) 2020, ISP RAS. All rights reserved.
Portions copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
Portions copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
Definition in file OcPeCoffFixupInit.c.
STATIC RETURN_STATUS InternalInitializePe | ( | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT * | Context, |
IN UINT32 | FileSize, | ||
IN BOOLEAN | InMemoryFixup ) |
Verify the PE32 or PE32+ Image and initialise Context.
Used offsets and ranges must be aligned and in the bounds of the raw file. Image section Headers and basic Relocation information must be Well-formed.
[in,out] | Context | The context describing the Image. Must have been initialised by PeCoffInitializeContext(). |
[in] | FileSize | The size, in Bytes, of Context->FileBuffer. |
[in] | InMemoryFixup | If TRUE, fixes are made to image in memory. If FALSE, Context is initialised as if fixes were made, but no changes are made to loaded image. |
RETURN_SUCCESS | The PE Image is Well-formed. |
other | The PE Image is malformed. |
Definition at line 409 of file OcPeCoffFixupInit.c.
STATIC RETURN_STATUS InternalValidateRelocInfo | ( | IN CONST PE_COFF_LOADER_IMAGE_CONTEXT * | Context, |
IN UINT32 | StartAddress ) |
Verify the basic Image Relocation information.
The preferred Image load address must be aligned by the section alignment. The Relocation Directory must be contained within the Image section memory. The Relocation Directory must be sufficiently aligned in memory.
[in] | Context | The context describing the Image. Must have been initialised by PeCoffInitializeContext(). |
[in] | StartAddress | The RVA of the first Image section. |
RETURN_SUCCESS | The basic Image Relocation information is well-formed. |
other | The basic Image Relocation information is malformed. |
Definition at line 327 of file OcPeCoffFixupInit.c.
STATIC RETURN_STATUS InternalVerifySections | ( | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT * | Context, |
IN UINT32 | FileSize, | ||
OUT UINT32 * | StartAddress, | ||
IN BOOLEAN | InMemoryFixup ) |
Verify the Image section Headers and initialise the Image memory space size.
The first Image section must be the beginning of the memory space, or be contiguous to the aligned Image Headers. Sections must be disjoint and, depending on the policy, contiguous in the memory space space. The section data must be in bounds bounds of the file buffer.
[in,out] | Context | The context describing the Image. Must have been initialised by PeCoffInitializeContext(). |
[in] | FileSize | The size, in Bytes, of Context->FileBuffer. |
[out] | StartAddress | On output, the RVA of the first Image section. |
[in] | InMemoryFixup | If TRUE, fixes are made to image in memory. If FALSE, Context is initialised as if fixes were made, but no changes are made to loaded image. |
RETURN_SUCCESS | The Image section Headers are well-formed. |
other | The Image section Headers are malformed. |
Definition at line 61 of file OcPeCoffFixupInit.c.
RETURN_STATUS OcPeCoffFixupInitializeContext | ( | OUT PE_COFF_LOADER_IMAGE_CONTEXT * | Context, |
IN CONST VOID * | FileBuffer, | ||
IN UINT32 | FileSize, | ||
IN BOOLEAN | InMemoryFixup ) |
Fix W^X and section overlap issues in loaded TE, PE32, or PE32+ Image in memory while initialising Context.
Closely based on PeCoffInitializeContext from PeCoffLib2.
The approach of modifying the image in memory is basically incompatible with secure boot, although: a) Certain firmware may allow optionally registering the hash of any image which does not load, which would still work. b) It is fairly crazy anyway to want to apply secure boot to the old, insecure .efi files which need these fixups.
[out] | Context | The context describing the Image. |
[in] | FileBuffer | The file data to parse as PE Image. |
[in] | FileSize | The size, in Bytes, of FileBuffer. |
[in] | InMemoryFixup | If TRUE, fixes are made to image in memory. If FALSE, Context is initialised as if fixes were made, but no changes are made to loaded image. |
RETURN_SUCCESS | The Image context has been initialised successfully. |
other | The file data is malformed. |
Definition at line 739 of file OcPeCoffFixupInit.c.