OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
PrelinkedContext.c File Reference
#include <Uefi.h>
#include <IndustryStandard/AppleKmodInfo.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcAppleKernelLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcStringLib.h>
#include "PrelinkedInternal.h"

Go to the source code of this file.

Functions

STATIC UINT64 PrelinkedFindLastLoadAddress (IN XML_NODE *KextList)
 
STATIC EFI_STATUS PrelinkedGetSegmentsFromMacho (IN OC_MACHO_CONTEXT *MachoContext, OUT MACH_SEGMENT_COMMAND_ANY **PrelinkedInfoSegment, OUT MACH_SECTION_ANY **PrelinkedInfoSection)
 
EFI_STATUS InternalConnectExternalSymtab (IN OUT OC_MACHO_CONTEXT *Context, OUT OC_MACHO_CONTEXT *InnerContext, IN UINT8 *Buffer, IN UINT32 BufferSize, OUT BOOLEAN *KernelCollection OPTIONAL)
 
EFI_STATUS PrelinkedContextInit (IN OUT PRELINKED_CONTEXT *Context, IN OUT UINT8 *Prelinked, IN UINT32 PrelinkedSize, IN UINT32 PrelinkedAllocSize, IN BOOLEAN Is32Bit)
 
VOID PrelinkedContextFree (IN OUT PRELINKED_CONTEXT *Context)
 
EFI_STATUS PrelinkedDependencyInsert (IN OUT PRELINKED_CONTEXT *Context, IN VOID *Buffer)
 
EFI_STATUS PrelinkedInjectPrepare (IN OUT PRELINKED_CONTEXT *Context, IN UINT32 LinkedExpansion, IN UINT32 ReservedExeSize)
 
EFI_STATUS PrelinkedInjectComplete (IN OUT PRELINKED_CONTEXT *Context)
 
EFI_STATUS PrelinkedReserveKextSize (IN OUT UINT32 *ReservedInfoSize, IN OUT UINT32 *ReservedExeSize, IN UINT32 InfoPlistSize, IN UINT8 *Executable OPTIONAL, IN UINT32 ExecutableSize OPTIONAL, IN BOOLEAN Is32Bit)
 
EFI_STATUS PrelinkedInjectKext (IN OUT PRELINKED_CONTEXT *Context, IN CONST CHAR8 *Identifier OPTIONAL, IN CONST CHAR8 *BundlePath, IN CONST CHAR8 *InfoPlist, IN UINT32 InfoPlistSize, IN CONST CHAR8 *ExecutablePath OPTIONAL, IN CONST UINT8 *Executable OPTIONAL, IN UINT32 ExecutableSize OPTIONAL, OUT CHAR8 BundleVersion[MAX_INFO_BUNDLE_VERSION_KEY_SIZE] OPTIONAL)
 
EFI_STATUS PrelinkedContextApplyPatch (IN OUT PRELINKED_CONTEXT *Context, IN CONST CHAR8 *Identifier, IN PATCHER_GENERIC_PATCH *Patch)
 
EFI_STATUS PrelinkedContextApplyQuirk (IN OUT PRELINKED_CONTEXT *Context, IN KERNEL_QUIRK_NAME Quirk, IN UINT32 KernelVersion)
 
EFI_STATUS PrelinkedContextBlock (IN OUT PRELINKED_CONTEXT *Context, IN CONST CHAR8 *Identifier, IN BOOLEAN Exclude)
 

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

Function Documentation

◆ InternalConnectExternalSymtab()

EFI_STATUS InternalConnectExternalSymtab ( IN OUT OC_MACHO_CONTEXT * Context,
OUT OC_MACHO_CONTEXT * InnerContext,
IN UINT8 * Buffer,
IN UINT32 BufferSize,
OUT BOOLEAN *KernelCollection OPTIONAL )

Definition at line 134 of file PrelinkedContext.c.

◆ PrelinkedContextApplyPatch()

EFI_STATUS PrelinkedContextApplyPatch ( IN OUT PRELINKED_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
IN PATCHER_GENERIC_PATCH * Patch )

Apply kext patch to prelinked.

Parameters
[in,out]ContextPrelinked context.
[in]IdentifierKext bundle identifier.
[in]PatchPatch to apply.
Returns
EFI_SUCCESS on success.

Definition at line 1260 of file PrelinkedContext.c.

◆ PrelinkedContextApplyQuirk()

EFI_STATUS PrelinkedContextApplyQuirk ( IN OUT PRELINKED_CONTEXT * Context,
IN KERNEL_QUIRK_NAME Quirk,
IN UINT32 KernelVersion )

Apply kext quirk to prelinked.

Parameters
[in,out]ContextPrelinked context.
[in]QuirkKext quirk to apply.
[in]KernelVersionCurrent kernel version.
Return values
EFI_SUCCESSon success.

Definition at line 1283 of file PrelinkedContext.c.

◆ PrelinkedContextBlock()

EFI_STATUS PrelinkedContextBlock ( IN OUT PRELINKED_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
IN BOOLEAN Exclude )

Block kext in prelinked.

Parameters
[in,out]ContextPrelinked context.
[in]IdentifierKext bundle identifier.
[in]ExcludeTRUE to exclude kext from prelinked.
Returns
EFI_SUCCESS on success.

Definition at line 1311 of file PrelinkedContext.c.

◆ PrelinkedContextFree()

VOID PrelinkedContextFree ( IN OUT PRELINKED_CONTEXT * Context)

Free resources consumed by prelinked context.

Parameters
[in,out]ContextPrelinked context.

Definition at line 427 of file PrelinkedContext.c.

◆ PrelinkedContextInit()

EFI_STATUS PrelinkedContextInit ( IN OUT PRELINKED_CONTEXT * Context,
IN OUT UINT8 * Prelinked,
IN UINT32 PrelinkedSize,
IN UINT32 PrelinkedAllocSize,
IN BOOLEAN Is32Bit )

Construct prelinked context for later modification. Must be freed with PrelinkedContextFree on success. Note, that PrelinkedAllocSize never changes, and is to be estimated.

Parameters
[in,out]ContextPrelinked context.
[in,out]PrelinkedUnpacked prelinked buffer (Mach-O image).
[in]PrelinkedSizeUnpacked prelinked buffer size.
[in]PrelinkedAllocSizeUnpacked prelinked buffer allocated size.
[in]Is32BitTRUE if prelinked is 32-bit.
Returns
EFI_SUCCESS on success.

Definition at line 208 of file PrelinkedContext.c.

◆ PrelinkedDependencyInsert()

EFI_STATUS PrelinkedDependencyInsert ( IN OUT PRELINKED_CONTEXT * Context,
IN VOID * Buffer )

Insert pool-allocated buffer dependency with the same lifetime as prelinked context, so it gets freed with PrelinkedContextFree.

Parameters
[in,out]ContextPrelinked context.
[in]BufferPool allocated buffer.
Returns
EFI_SUCCESS on success.

Definition at line 491 of file PrelinkedContext.c.

◆ PrelinkedFindLastLoadAddress()

STATIC UINT64 PrelinkedFindLastLoadAddress ( IN XML_NODE * KextList)

Definition at line 31 of file PrelinkedContext.c.

◆ PrelinkedGetSegmentsFromMacho()

STATIC EFI_STATUS PrelinkedGetSegmentsFromMacho ( IN OC_MACHO_CONTEXT * MachoContext,
OUT MACH_SEGMENT_COMMAND_ANY ** PrelinkedInfoSegment,
OUT MACH_SECTION_ANY ** PrelinkedInfoSection )

Definition at line 99 of file PrelinkedContext.c.

◆ PrelinkedInjectComplete()

EFI_STATUS PrelinkedInjectComplete ( IN OUT PRELINKED_CONTEXT * Context)

Insert current plist entry after kext injection.

Parameters
[in,out]ContextPrelinked context.
Returns
EFI_SUCCESS on success.

Definition at line 757 of file PrelinkedContext.c.

◆ PrelinkedInjectKext()

EFI_STATUS PrelinkedInjectKext ( IN OUT PRELINKED_CONTEXT * Context,
IN CONST CHAR8 *Identifier OPTIONAL,
IN CONST CHAR8 * BundlePath,
IN CONST CHAR8 * InfoPlist,
IN UINT32 InfoPlistSize,
IN CONST CHAR8 *ExecutablePath OPTIONAL,
IN CONST UINT8 *Executable OPTIONAL,
IN UINT32 ExecutableSize OPTIONAL,
OUT CHAR8 BundleVersion OPTIONAL[MAX_INFO_BUNDLE_VERSION_KEY_SIZE] )

Definition at line 948 of file PrelinkedContext.c.

◆ PrelinkedInjectPrepare()

EFI_STATUS PrelinkedInjectPrepare ( IN OUT PRELINKED_CONTEXT * Context,
IN UINT32 LinkedExpansion,
IN UINT32 ReservedExeSize )

Drop current plist entry, required for kext injection. Ensure that prelinked text can grow with new kexts.

Parameters
[in,out]ContextPrelinked context.
[in]LinkedExpansionExtra LINKEDIT size for KC required to hold DYLD chained fixups.
Return values
EFI_SUCCESSon success.

Definition at line 526 of file PrelinkedContext.c.

◆ PrelinkedReserveKextSize()

EFI_STATUS PrelinkedReserveKextSize ( IN OUT UINT32 * ReservedInfoSize,
IN OUT UINT32 * ReservedExeSize,
IN UINT32 InfoPlistSize,
IN UINT8 *Executable OPTIONAL,
IN UINT32 ExecutableSize OPTIONAL,
IN BOOLEAN Is32Bit )

Updated required reserve size to inject this kext.

Parameters
[in,out]ReservedInfoSizeCurrent reserved PLIST size, updated.
[in,out]ReservedExeSizeCurrent reserved KEXT size, updated.
[in]InfoPlistSizeKext Info.plist size.
[in]ExecutableKext executable, optional.
[in]ExecutableSizeKext executable size, optional.
[in]Is32BitTRUE to process 32-bit kext.
Returns
EFI_SUCCESS on success.

Definition at line 903 of file PrelinkedContext.c.