OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcPeCoffExtLib.c File Reference
#include <Base.h>
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/PeCoffLib2.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/OcCryptoLib.h>
#include <Library/OcAppleKeysLib.h>
#include <Library/OcStringLib.h>
#include <Guid/AppleCertificate.h>
#include "OcPeCoffExtInternal.h"

Go to the source code of this file.

Functions

STATIC RETURN_STATUS PeCoffGetSecurityDirectoryEntry (IN PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 FileSize, OUT CONST EFI_IMAGE_DATA_DIRECTORY **DirectoryEntry)
 
STATIC EFI_STATUS PeCoffGetAppleCertificateInfo (IN PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 FileSize, OUT APPLE_EFI_CERTIFICATE_INFO **CertInfo, OUT UINT32 *SecDirOffset, OUT UINT32 *SignedFileSize)
 
STATIC EFI_STATUS PeCoffGetAppleSignature (IN PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN APPLE_EFI_CERTIFICATE_INFO *CertInfo, OUT APPLE_SIGNATURE_CONTEXT *SignatureContext)
 
STATIC EFI_STATUS PeCoffSanitiseAppleImage (IN PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 SecDirOffset, IN UINT32 SignedFileSize, IN UINT32 FileSize)
 
STATIC VOID PeCoffHashAppleImage (IN PE_COFF_LOADER_IMAGE_CONTEXT *Context, IN UINT32 SecDirOffset, IN UINT32 SignedFileSize, OUT UINT8 *Hash)
 
STATIC EFI_STATUS InternalPeCoffVerifyAppleSignatureFromContext (IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN OUT UINT32 *ImageSize)
 
EFI_STATUS PeCoffVerifyAppleSignature (IN OUT VOID *PeImage, IN OUT UINT32 *ImageSize)
 
STATIC EFI_STATUS InternalPeCoffGetApfsDriverVersionFromContext (IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN UINT32 DriverSize, OUT APFS_DRIVER_VERSION **DriverVersionPtr)
 
EFI_STATUS PeCoffGetApfsDriverVersion (IN VOID *DriverBuffer, IN UINT32 DriverSize, OUT APFS_DRIVER_VERSION **DriverVersionPtr)
 
EFI_STATUS OcPatchLegacyEfi (IN VOID *DriverBuffer, IN UINT32 DriverSize)
 

Detailed Description

AppleDxeImageVerificationLib

  • Apple key-storage
  • Apple PE-256 hash calculation
  • Verifying Rsa2048Sha256 signature

Copyright (c) 2018, savvas

All rights reserved.

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 http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file OcPeCoffExtLib.c.

Function Documentation

◆ InternalPeCoffGetApfsDriverVersionFromContext()

STATIC EFI_STATUS InternalPeCoffGetApfsDriverVersionFromContext ( IN PE_COFF_LOADER_IMAGE_CONTEXT * ImageContext,
IN UINT32 DriverSize,
OUT APFS_DRIVER_VERSION ** DriverVersionPtr )

Definition at line 484 of file OcPeCoffExtLib.c.

◆ InternalPeCoffVerifyAppleSignatureFromContext()

STATIC EFI_STATUS InternalPeCoffVerifyAppleSignatureFromContext ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT * ImageContext,
IN OUT UINT32 * ImageSize )

Definition at line 383 of file OcPeCoffExtLib.c.

◆ OcPatchLegacyEfi()

EFI_STATUS OcPatchLegacyEfi ( IN VOID * DriverBuffer,
IN UINT32 DriverSize )

Detect and patch W^X and overlapping section errors in legacy boot.efi. Expected to fix overlapping sections in 10.4 and 10.5 32-bit only, and W^X errors in most macOS binaries.

Parameters
[in]DriverBufferImage buffer.
[in]DriverSizeSize of the image.
Return values
EFI_SUCCESSon success.

Definition at line 577 of file OcPeCoffExtLib.c.

◆ PeCoffGetApfsDriverVersion()

EFI_STATUS PeCoffGetApfsDriverVersion ( IN VOID * DriverBuffer,
IN UINT32 DriverSize,
OUT APFS_DRIVER_VERSION ** DriverVersionPtr )

Obtain APFS driver version.

Parameters
[in]DriverBufferImage buffer.
[in]DriverSizeSize of the image.
[out]DriverVersionPtrDriver version within image buffer.
Return values
EFI_SUCCESSon success.

Definition at line 553 of file OcPeCoffExtLib.c.

◆ PeCoffGetAppleCertificateInfo()

STATIC EFI_STATUS PeCoffGetAppleCertificateInfo ( IN PE_COFF_LOADER_IMAGE_CONTEXT * Context,
IN UINT32 FileSize,
OUT APPLE_EFI_CERTIFICATE_INFO ** CertInfo,
OUT UINT32 * SecDirOffset,
OUT UINT32 * SignedFileSize )

Definition at line 110 of file OcPeCoffExtLib.c.

◆ PeCoffGetAppleSignature()

STATIC EFI_STATUS PeCoffGetAppleSignature ( IN PE_COFF_LOADER_IMAGE_CONTEXT * Context,
IN APPLE_EFI_CERTIFICATE_INFO * CertInfo,
OUT APPLE_SIGNATURE_CONTEXT * SignatureContext )

Definition at line 167 of file OcPeCoffExtLib.c.

◆ PeCoffGetSecurityDirectoryEntry()

STATIC RETURN_STATUS PeCoffGetSecurityDirectoryEntry ( IN PE_COFF_LOADER_IMAGE_CONTEXT * Context,
IN UINT32 FileSize,
OUT CONST EFI_IMAGE_DATA_DIRECTORY ** DirectoryEntry )

Definition at line 43 of file OcPeCoffExtLib.c.

◆ PeCoffHashAppleImage()

STATIC VOID PeCoffHashAppleImage ( IN PE_COFF_LOADER_IMAGE_CONTEXT * Context,
IN UINT32 SecDirOffset,
IN UINT32 SignedFileSize,
OUT UINT8 * Hash )

Definition at line 332 of file OcPeCoffExtLib.c.

◆ PeCoffSanitiseAppleImage()

STATIC EFI_STATUS PeCoffSanitiseAppleImage ( IN PE_COFF_LOADER_IMAGE_CONTEXT * Context,
IN UINT32 SecDirOffset,
IN UINT32 SignedFileSize,
IN UINT32 FileSize )

Definition at line 266 of file OcPeCoffExtLib.c.

◆ PeCoffVerifyAppleSignature()

EFI_STATUS PeCoffVerifyAppleSignature ( IN OUT VOID * PeImage,
IN OUT UINT32 * ImageSize )

Verify Apple COFF legacy signature. Image buffer is sanitized where necessary (zeroed), and an updated length is returned through size parameter.

Parameters
[in,out]PeImageImage buffer.
[in,out]ImageSizeSize of the image.
Return values
EFI_SUCCESSon success.

Definition at line 458 of file OcPeCoffExtLib.c.