OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
KernelReader.c File Reference
#include <Uefi.h>
#include <IndustryStandard/AppleCompressedBinaryImage.h>
#include <IndustryStandard/AppleFatBinaryImage.h>
#include <Library/BaseLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcAppleKernelLib.h>
#include <Library/OcCompressionLib.h>
#include <Library/OcCryptoLib.h>
#include <Library/OcFileLib.h>

Go to the source code of this file.

Macros

#define KERNEL_HEADER_SIZE   (EFI_PAGE_SIZE * 2)
 

Enumerations

enum  KERNEL_ARCH { KernelArchUnknown , KernelArch32 , KernelArch64 }
 

Functions

STATIC EFI_STATUS ReplaceBuffer (IN UINT32 TargetSize, IN OUT UINT8 **Buffer, OUT UINT32 *AllocatedSize, IN UINT32 ReservedSize)
 
STATIC EFI_STATUS KernelGetFileData (IN EFI_FILE_PROTOCOL *File, IN UINT32 Position, IN UINT32 Size, OUT UINT8 *Buffer)
 
STATIC EFI_STATUS ParseFatArchitecture (IN EFI_FILE_PROTOCOL *File, IN BOOLEAN Prefer32Bit, IN UINT8 *Buffer, IN UINT32 BufferSize, OUT BOOLEAN *Is32Bit, OUT UINT32 *FatOffset, OUT UINT32 *FatSize)
 
STATIC UINT32 ParseCompressedHeader (IN EFI_FILE_PROTOCOL *File, IN OUT UINT8 **Buffer, IN UINT32 Offset, OUT UINT32 *AllocatedSize, IN UINT32 ReservedSize)
 
STATIC EFI_STATUS ReadAppleKernelImage (IN EFI_FILE_PROTOCOL *File, IN BOOLEAN Prefer32Bit, IN OUT KERNEL_ARCH *Arch, IN OUT UINT8 **Buffer, OUT UINT32 *KernelSize, OUT UINT32 *AllocatedSize, IN UINT32 ReservedSize, IN UINT32 Offset)
 
EFI_STATUS ReadAppleKernel (IN EFI_FILE_PROTOCOL *File, IN BOOLEAN Prefer32Bit, OUT BOOLEAN *Is32Bit, OUT UINT8 **Kernel, OUT UINT32 *KernelSize, OUT UINT32 *AllocatedSize, IN UINT32 ReservedSize, OUT UINT8 *Digest OPTIONAL)
 
EFI_STATUS ReadAppleMkext (IN EFI_FILE_PROTOCOL *File, IN BOOLEAN Prefer32Bit, OUT UINT8 **Mkext, OUT UINT32 *MkextSize, OUT UINT32 *AllocatedSize, IN UINT32 ReservedSize, IN UINT32 NumReservedKexts)
 

Variables

STATIC SHA384_CONTEXT mKernelDigestContext
 
STATIC UINT32 mKernelDigestPosition
 
STATIC BOOLEAN mNeedKernelDigest
 

Detailed Description

Copyright (C) 2019, vit9696. All rights reserved.

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 KernelReader.c.

Macro Definition Documentation

◆ KERNEL_HEADER_SIZE

#define KERNEL_HEADER_SIZE   (EFI_PAGE_SIZE * 2)

Definition at line 32 of file KernelReader.c.

Enumeration Type Documentation

◆ KERNEL_ARCH

Enumerator
KernelArchUnknown 
KernelArch32 
KernelArch64 

Definition at line 38 of file KernelReader.c.

Function Documentation

◆ KernelGetFileData()

STATIC EFI_STATUS KernelGetFileData ( IN EFI_FILE_PROTOCOL * File,
IN UINT32 Position,
IN UINT32 Size,
OUT UINT8 * Buffer )

Definition at line 77 of file KernelReader.c.

◆ ParseCompressedHeader()

STATIC UINT32 ParseCompressedHeader ( IN EFI_FILE_PROTOCOL * File,
IN OUT UINT8 ** Buffer,
IN UINT32 Offset,
OUT UINT32 * AllocatedSize,
IN UINT32 ReservedSize )

Definition at line 193 of file KernelReader.c.

◆ ParseFatArchitecture()

STATIC EFI_STATUS ParseFatArchitecture ( IN EFI_FILE_PROTOCOL * File,
IN BOOLEAN Prefer32Bit,
IN UINT8 * Buffer,
IN UINT32 BufferSize,
OUT BOOLEAN * Is32Bit,
OUT UINT32 * FatOffset,
OUT UINT32 * FatSize )

Definition at line 141 of file KernelReader.c.

◆ ReadAppleKernel()

EFI_STATUS ReadAppleKernel ( IN EFI_FILE_PROTOCOL * File,
IN BOOLEAN Prefer32Bit,
OUT BOOLEAN * Is32Bit,
OUT UINT8 ** Kernel,
OUT UINT32 * KernelSize,
OUT UINT32 * AllocatedSize,
IN UINT32 ReservedSize,
OUT UINT8 *Digest OPTIONAL )

Read Apple kernel for target architecture (possibly decompressing) into pool allocated buffer. If CpuType does not exist in fat mkext, an error is returned.

Parameters
[in]FileFile handle instance.
[in]Prefer32BitPrefer 32-bit in case of fat binary.
[out]Is32BitWhether resulting kernel is 32-bit or not.
[in,out]KernelResulting non-fat kernel buffer from pool.
[out]KernelSizeActual kernel size.
[out]AllocatedSizeAllocated kernel size (AllocatedSize >= KernelSize).
[in]ReservedSizeAllocated extra size for added kernel extensions.
[out]DigestSHA-384 digest for the original kernel, optional.
Returns
EFI_SUCCESS on success.

Definition at line 418 of file KernelReader.c.

◆ ReadAppleKernelImage()

STATIC EFI_STATUS ReadAppleKernelImage ( IN EFI_FILE_PROTOCOL * File,
IN BOOLEAN Prefer32Bit,
IN OUT KERNEL_ARCH * Arch,
IN OUT UINT8 ** Buffer,
OUT UINT32 * KernelSize,
OUT UINT32 * AllocatedSize,
IN UINT32 ReservedSize,
IN UINT32 Offset )

Definition at line 269 of file KernelReader.c.

◆ ReadAppleMkext()

EFI_STATUS ReadAppleMkext ( IN EFI_FILE_PROTOCOL * File,
IN BOOLEAN Prefer32Bit,
OUT UINT8 ** Mkext,
OUT UINT32 * MkextSize,
OUT UINT32 * AllocatedSize,
IN UINT32 ReservedSize,
IN UINT32 NumReservedKexts )

Read mkext for target architecture (possibly decompressing) into pool allocated buffer. If CpuType does not exist in fat mkext, an error is returned.

Parameters
[in]FileFile handle instance.
[in]Prefer32BitPrefer 32-bit in case of fat binary.
[in,out]MkextResulting non-fat mkext buffer from pool.
[out]MkextSizeActual mkext size.
[out]AllocatedSizeAllocated mkext size (AllocatedSize >= MkextSize).
[in]ReservedSizeAllocated extra size for added kernel extensions.
[in]NumReservedKextsNumber of kext slots to reserve in mkext.
Returns
EFI_SUCCESS on success.

Definition at line 514 of file KernelReader.c.

◆ ReplaceBuffer()

STATIC EFI_STATUS ReplaceBuffer ( IN UINT32 TargetSize,
IN OUT UINT8 ** Buffer,
OUT UINT32 * AllocatedSize,
IN UINT32 ReservedSize )

Definition at line 46 of file KernelReader.c.

Variable Documentation

◆ mKernelDigestContext

STATIC SHA384_CONTEXT mKernelDigestContext

Definition at line 34 of file KernelReader.c.

◆ mKernelDigestPosition

STATIC UINT32 mKernelDigestPosition

Definition at line 35 of file KernelReader.c.

◆ mNeedKernelDigest

STATIC BOOLEAN mNeedKernelDigest

Definition at line 36 of file KernelReader.c.