|
OpenCore
1.0.8
OpenCore Bootloader
|
#include <Uefi.h>#include <IndustryStandard/AppleCompressedBinaryImage.h>#include <IndustryStandard/AppleFatBinaryImage.h>#include <Library/BaseLib.h>#include <Library/BaseMemoryLib.h>#include <Library/BaseOverflowLib.h>#include <Library/DebugLib.h>#include <Library/MemoryAllocationLib.h>#include <Library/OcAppleKernelLib.h>#include <Library/OcCompressionLib.h>#include <Library/OcFileLib.h>#include "PrelinkedInternal.h"Go to the source code of this file.
Functions | |
| STATIC UINTN | InternalKcGetKextFilesetSize (IN OUT PRELINKED_CONTEXT *Context) |
| STATIC VOID | InternalKcWriteCommandHeaders (IN OUT PRELINKED_CONTEXT *Context, IN OUT MACH_HEADER_64 *MachHeader) |
| EFI_STATUS | KcRebuildMachHeader (IN OUT PRELINKED_CONTEXT *Context) |
| UINT32 | KcGetSegmentFixupChainsSize (IN UINT32 SegmentSize) |
| EFI_STATUS | KcInitKextFixupChains (IN OUT PRELINKED_CONTEXT *Context, IN UINT32 SegChainSize, IN UINT32 ReservedSize) |
| STATIC VOID | InternalKcConvertRelocToFixup (IN OUT PRELINKED_CONTEXT *Context, IN OC_MACHO_CONTEXT *MachContext, IN CONST MACH_RELOCATION_INFO *RelocInfo, IN UINT64 RelocBase) |
| VOID | KcKextIndexFixups (IN OUT PRELINKED_CONTEXT *Context, IN OC_MACHO_CONTEXT *MachContext) |
| UINT32 | KcGetKextSize (IN PRELINKED_CONTEXT *Context, IN UINT64 SourceAddress) |
| EFI_STATUS | KcKextApplyFileDelta (IN PRELINKED_CONTEXT *PrelinkedContext, IN OUT OC_MACHO_CONTEXT *Context, IN UINT32 Delta) |
| UINT64 | KcFixupValue (IN UINT64 Value, IN CONST CHAR8 *Name OPTIONAL) |
| UINTN | KcWalkChainedFixupsInSegment (IN UINT8 *Buffer, IN UINTN BufferSize, IN MACH_DYLD_CHAINED_STARTS_IN_SEGMENT *StartsSeg, IN UINTN StartsSegSize, IN KC_CHAINED_FIXUP_VISIT Visitor OPTIONAL, IN OUT VOID *VisitorContext OPTIONAL) |
| UINTN | KcWalkChainedFixupsInImage (IN UINT8 *Buffer, IN UINTN BufferSize, IN MACH_DYLD_CHAINED_STARTS_IN_IMAGE *Starts, IN UINTN StartsSize, IN KC_CHAINED_FIXUP_VISIT Visitor OPTIONAL, IN OUT VOID *VisitorContext OPTIONAL) |
Kernel collection support.
Copyright (c) 2020, vit9696. 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 KernelCollection.c.
| STATIC VOID InternalKcConvertRelocToFixup | ( | IN OUT PRELINKED_CONTEXT * | Context, |
| IN OC_MACHO_CONTEXT * | MachContext, | ||
| IN CONST MACH_RELOCATION_INFO * | RelocInfo, | ||
| IN UINT64 | RelocBase ) |
Definition at line 431 of file KernelCollection.c.
| STATIC UINTN InternalKcGetKextFilesetSize | ( | IN OUT PRELINKED_CONTEXT * | Context | ) |
Definition at line 33 of file KernelCollection.c.
| STATIC VOID InternalKcWriteCommandHeaders | ( | IN OUT PRELINKED_CONTEXT * | Context, |
| IN OUT MACH_HEADER_64 * | MachHeader ) |
Definition at line 62 of file KernelCollection.c.
| UINT64 KcFixupValue | ( | IN UINT64 | Value, |
| IN CONST CHAR8 *Name | OPTIONAL ) |
Update address or dyld fixup value to real address.
| [in] | Value | Value or fixup. |
| [in] | Name | Source name, optional. |
Definition at line 800 of file KernelCollection.c.
| UINT32 KcGetKextSize | ( | IN PRELINKED_CONTEXT * | Context, |
| IN UINT64 | SourceAddress ) |
Retrieves a KC KEXT's virtual size.
| [in] | Context | Prelinked context. |
| [in] | SourceAddress | The virtual address within the KC image of the KEXT. |
| 0 | An error has occured. |
| other | The virtual size, in bytes, of the KEXT at SourceAddress. |
Definition at line 643 of file KernelCollection.c.
| UINT32 KcGetSegmentFixupChainsSize | ( | IN UINT32 | SegmentSize | ) |
Returns the size required to store a segment's fixup chains information.
| [in] | SegmentSize | The size, in bytes, of the segment to index. |
| 0 | The segment is too large to index with a single structure. |
| other | The size, in bytes, required to store a segment's fixup chain information. |
Definition at line 270 of file KernelCollection.c.
| EFI_STATUS KcInitKextFixupChains | ( | IN OUT PRELINKED_CONTEXT * | Context, |
| IN UINT32 | SegChainSize, | ||
| IN UINT32 | ReservedSize ) |
Initialises a structure that stores a segments's fixup chains information.
| [out] | SegChain | The information structure to initialise. |
| [in] | SegChainSize | The size, in bytes, available to SegChain. |
| [in] | VmAddress | The virtual address of the segment to index. |
| [in] | VmSize | The virtual size of the segment to index. |
Definition at line 287 of file KernelCollection.c.
| EFI_STATUS KcKextApplyFileDelta | ( | IN PRELINKED_CONTEXT * | PrelinkedContext, |
| IN OUT OC_MACHO_CONTEXT * | Context, | ||
| IN UINT32 | Delta ) |
Apply the delta from KC header to the file's offsets.
| [in] | PrelinkedContext | Prelinked context. |
| [in,out] | Context | The context of the KEXT to rebase. |
| [in] | Delta | The offset from KC header the KEXT starts at. |
| EFI_SUCCESS | The file has beem rebased successfully. |
| other | An error has occured. |
Definition at line 684 of file KernelCollection.c.
| VOID KcKextIndexFixups | ( | IN OUT PRELINKED_CONTEXT * | Context, |
| IN OC_MACHO_CONTEXT * | MachContext ) |
Indexes all relocations of MachContext into the kernel described by Context.
| [in,out] | Context | Prelinked context. |
| [in] | MachContext | The context of the Mach-O to index. It must have been prelinked by OcAppleKernelLib. The image must reside in Segment. |
Definition at line 559 of file KernelCollection.c.
| EFI_STATUS KcRebuildMachHeader | ( | IN OUT PRELINKED_CONTEXT * | Context | ) |
Update Mach-O header with new commands.
@Param[in,out] Context Prelinked context.
| EFI_SUCCESS | on success. |
Definition at line 189 of file KernelCollection.c.
| UINTN KcWalkChainedFixupsInImage | ( | IN UINT8 * | Buffer, |
| IN UINTN | BufferSize, | ||
| IN MACH_DYLD_CHAINED_STARTS_IN_IMAGE * | Starts, | ||
| IN UINTN | StartsSize, | ||
| IN KC_CHAINED_FIXUP_VISIT Visitor | OPTIONAL, | ||
| IN OUT VOID *VisitorContext | OPTIONAL ) |
Walk every chained-fixup slot in every segment of a kernel collection's LC_DYLD_CHAINED_FIXUPS payload by iterating over the STARTS_IN_IMAGE table and calling KcWalkChainedFixupsInSegment for each populated segment.
Both the Starts table and each per-segment record it indexes are treated as untrusted input and bounds-checked against StartsSize. Per-segment validation is performed by KcWalkChainedFixupsInSegment.
| [in] | Buffer | Pointer to the containing kernel collection buffer. |
| [in] | BufferSize | Size of Buffer in bytes. Forwarded to KcWalkChainedFixupsInSegment. |
| [in] | Starts | MACH_DYLD_CHAINED_STARTS_IN_IMAGE for the whole image. |
| [in] | StartsSize | Size of the chained-fixups metadata region pointed to by Starts. Bounds the SegInfoOffset[] array reads and each per-segment dereference. |
| [in] | Visitor | Callback invoked per fixup slot, or NULL to count only. |
| [in,out] | VisitorContext | Opaque context forwarded to Visitor, may be NULL. |
Definition at line 1069 of file KernelCollection.c.
| UINTN KcWalkChainedFixupsInSegment | ( | IN UINT8 * | Buffer, |
| IN UINTN | BufferSize, | ||
| IN MACH_DYLD_CHAINED_STARTS_IN_SEGMENT * | StartsSeg, | ||
| IN UINTN | StartsSegSize, | ||
| IN KC_CHAINED_FIXUP_VISIT Visitor | OPTIONAL, | ||
| IN OUT VOID *VisitorContext | OPTIONAL ) |
Walk every chained-fixup slot in a single segment of a kernel collection's LC_DYLD_CHAINED_FIXUPS payload, invoking Visitor on each slot. Pointer-format-aware: handles both stride-1 (X86_64_KERNEL_CACHE) and stride-4 (64_KERNEL_CACHE / 64_OFFSET / ARM64E_KERNEL) layouts; returns 0 for any other format without walking.
All fields read from StartsSeg are treated as untrusted input. Every computed offset and chain step is bounds-checked against the caller-supplied container sizes. The walker never reads or invokes Visitor on a slot that lies outside [Buffer, Buffer + BufferSize). A self-referencing chain is bounded by the per-page iteration cap PageSize / sizeof (UINT64).
| [in] | Buffer | Pointer to the containing kernel collection buffer (the same base SegmentOffset is relative to). |
| [in] | BufferSize | Size of Buffer in bytes. The walker will not access Buffer past this. |
| [in] | StartsSeg | MACH_DYLD_CHAINED_STARTS_IN_SEGMENT for the segment to walk. |
| [in] | StartsSegSize | Size of the metadata region pointed to by StartsSeg. The walker will not read the StartsSeg struct or its PageStart[] array past this. |
| [in] | Visitor | Callback invoked per fixup slot, or NULL to count only. |
| [in,out] | VisitorContext | Opaque context forwarded to Visitor, may be NULL. |
Definition at line 840 of file KernelCollection.c.