OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
MkextContext.c File Reference
#include <Uefi.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/OcStringLib.h>
#include "MkextInternal.h"
#include "PrelinkedInternal.h"

Go to the source code of this file.

Macros

#define MKEXT_ALIGN(a)
 

Functions

BOOLEAN InternalParseKextBinary (IN OUT UINT8 **Buffer, IN OUT UINT32 *BufferSize, IN BOOLEAN Is32Bit)
 
STATIC VOID UpdateMkextLengthChecksum (IN MKEXT_HEADER_ANY *Mkext, IN UINT32 Length)
 
STATIC BOOLEAN ParseMkextV2Plist (IN MKEXT_V2_HEADER *Mkext, OUT UINT8 **Plist, OUT UINT32 *PlistSize, OUT XML_DOCUMENT **PlistDoc, OUT XML_NODE **PlistBundles)
 
STATIC UINT32 UpdateMkextV2Plist (IN OUT MKEXT_V2_HEADER *Mkext, IN UINT32 AllocatedSize, IN XML_DOCUMENT *PlistDoc, IN UINT32 Offset)
 
STATIC MKEXT_KEXTInsertCachedMkextKext (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier, IN UINT32 BinOffset, IN UINT32 BinSize)
 
VOID InternalDropCachedMkextKext (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier)
 
EFI_STATUS InternalGetMkextV1KextOffsets (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier, OUT UINT32 *KextIndex, OUT UINT32 *KextPlistOffset, OUT UINT32 *KextPlistSize, OUT UINT32 *KextBinOffset, OUT UINT32 *KextBinSize)
 
MKEXT_KEXTInternalCachedMkextKext (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier)
 
EFI_STATUS MkextDecompress (IN CONST UINT8 *Buffer, IN UINT32 BufferSize, IN UINT32 NumReservedKexts, IN OUT UINT8 *OutBuffer OPTIONAL, IN UINT32 OutBufferSize OPTIONAL, IN OUT UINT32 *OutMkextSize)
 
BOOLEAN MkextCheckCpuType (IN UINT8 *Mkext, IN UINT32 MkextSize, IN MACH_CPU_TYPE CpuType)
 
EFI_STATUS MkextContextInit (IN OUT MKEXT_CONTEXT *Context, IN OUT UINT8 *Mkext, IN UINT32 MkextSize, IN UINT32 MkextAllocSize)
 
VOID MkextContextFree (IN OUT MKEXT_CONTEXT *Context)
 
EFI_STATUS MkextReserveKextSize (IN OUT UINT32 *ReservedInfoSize, IN OUT UINT32 *ReservedExeSize, IN UINT32 InfoPlistSize, IN UINT8 *Executable OPTIONAL, IN UINT32 ExecutableSize OPTIONAL, IN BOOLEAN Is32Bit)
 
EFI_STATUS MkextInjectKext (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier OPTIONAL, IN CONST CHAR8 *BundlePath, IN CONST CHAR8 *InfoPlist, IN UINT32 InfoPlistSize, IN UINT8 *Executable OPTIONAL, IN UINT32 ExecutableSize OPTIONAL, OUT CHAR8 BundleVersion[MAX_INFO_BUNDLE_VERSION_KEY_SIZE] OPTIONAL)
 
EFI_STATUS MkextContextApplyPatch (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier, IN PATCHER_GENERIC_PATCH *Patch)
 
EFI_STATUS MkextContextApplyQuirk (IN OUT MKEXT_CONTEXT *Context, IN KERNEL_QUIRK_NAME Quirk, IN UINT32 KernelVersion)
 
EFI_STATUS MkextContextBlock (IN OUT MKEXT_CONTEXT *Context, IN CONST CHAR8 *Identifier, IN BOOLEAN Exclude)
 
EFI_STATUS MkextInjectPatchComplete (IN OUT MKEXT_CONTEXT *Context)
 

Detailed Description

Mkext support.

Copyright (c) 2020, Goldfish64. 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 MkextContext.c.

Macro Definition Documentation

◆ MKEXT_ALIGN

#define MKEXT_ALIGN ( a)
Value:
(ALIGN_VALUE (a, sizeof (UINT64)))

Definition at line 33 of file MkextContext.c.

Function Documentation

◆ InsertCachedMkextKext()

STATIC MKEXT_KEXT * InsertCachedMkextKext ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
IN UINT32 BinOffset,
IN UINT32 BinSize )

Definition at line 232 of file MkextContext.c.

◆ InternalCachedMkextKext()

MKEXT_KEXT * InternalCachedMkextKext ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier )

Definition at line 422 of file MkextContext.c.

◆ InternalDropCachedMkextKext()

VOID InternalDropCachedMkextKext ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier )

Definition at line 263 of file MkextContext.c.

◆ InternalGetMkextV1KextOffsets()

EFI_STATUS InternalGetMkextV1KextOffsets ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
OUT UINT32 * KextIndex,
OUT UINT32 * KextPlistOffset,
OUT UINT32 * KextPlistSize,
OUT UINT32 * KextBinOffset,
OUT UINT32 * KextBinSize )

Definition at line 296 of file MkextContext.c.

◆ InternalParseKextBinary()

BOOLEAN InternalParseKextBinary ( IN OUT UINT8 ** Buffer,
IN OUT UINT32 * BufferSize,
IN BOOLEAN Is32Bit )

Definition at line 36 of file MkextContext.c.

◆ MkextCheckCpuType()

BOOLEAN MkextCheckCpuType ( IN UINT8 * Mkext,
IN UINT32 MkextSize,
IN MACH_CPU_TYPE CpuType )

Check if passed mkext is of desired CPU arch.

Parameters
[in]MkextMkext buffer.
[in]MkextSizeMkext buffer size.
[in]CpuTypeDesired CPU arch.
Returns
FALSE if mismatched arch or invalid mkext.

Definition at line 1008 of file MkextContext.c.

◆ MkextContextApplyPatch()

EFI_STATUS MkextContextApplyPatch ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
IN PATCHER_GENERIC_PATCH * Patch )

Apply kext patch to mkext.

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

Definition at line 1574 of file MkextContext.c.

◆ MkextContextApplyQuirk()

EFI_STATUS MkextContextApplyQuirk ( IN OUT MKEXT_CONTEXT * Context,
IN KERNEL_QUIRK_NAME Quirk,
IN UINT32 KernelVersion )

Apply kext quirk to mkext.

Parameters
[in,out]ContextMkext context.
[in]QuirkKext quirk to apply.
[in]KernelVersionCurrent kernel version.
Returns
EFI_SUCCESS on success.

Definition at line 1597 of file MkextContext.c.

◆ MkextContextBlock()

EFI_STATUS MkextContextBlock ( IN OUT MKEXT_CONTEXT * Context,
IN CONST CHAR8 * Identifier,
IN BOOLEAN Exclude )

Block kext in mkext.

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

Definition at line 1625 of file MkextContext.c.

◆ MkextContextFree()

VOID MkextContextFree ( IN OUT MKEXT_CONTEXT * Context)

Free resources consumed by mkext context.

Parameters
[in,out]ContextMkext context.

Definition at line 1203 of file MkextContext.c.

◆ MkextContextInit()

EFI_STATUS MkextContextInit ( IN OUT MKEXT_CONTEXT * Context,
IN OUT UINT8 * Mkext,
IN UINT32 MkextSize,
IN UINT32 MkextAllocSize )

Construct mkext context for later modification. Must be freed with MkextContextFree on success. Note that MkextAllocSize never changes, and is to be estimated.

Mkext buffers cannot contain any compression, and should be run through MkextDecompress first.

Parameters
[in,out]ContextMkext context.
[in,out]MkextDecompressed Mkext buffer.
[in]MkextSizeDecompressed Mkext buffer size.
[in]MkextAllocSizeDecompressed Mkext buffer allocated size.
Returns
EFI_SUCCESS on success.

Definition at line 1040 of file MkextContext.c.

◆ MkextDecompress()

EFI_STATUS MkextDecompress ( IN CONST UINT8 * Buffer,
IN UINT32 BufferSize,
IN UINT32 NumReservedKexts,
IN OUT UINT8 *OutBuffer OPTIONAL,
IN UINT32 OutBufferSize OPTIONAL,
IN OUT UINT32 * OutMkextSize )

Decompress mkext buffer while reserving space for injected kexts later on. Specifying zero for OutBufferSize will calculate the size of the buffer required for the decompressed mkext in OutMkextSize.

Parameters
[in]BufferMkext buffer.
[in]BufferSizeMkext buffer size.
[in]NumReservedKextsNumber of kext slots to reserve for injection.
[in,out]OutBufferOutput buffer. Optional if OutBufferSize is zero.
[in]OutBufferSizeTotal output buffer size. Specify zero to calculate output buffer size.
[in,out]OutMkextSizeDecompressed Mkext size.
Returns
EFI_SUCCESS on success.

Definition at line 568 of file MkextContext.c.

◆ MkextInjectKext()

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

Perform mkext kext injection.

Parameters
[in,out]ContextMkext context.
[in]IdentifierKext bundle identifier. If a kext with this identifier already exists, the kext will not be injected. Optional.
[in]BundlePathKext bundle path (e.g. /L/E/mykext.kext).
[in,out]InfoPlistKext Info.plist.
[in]InfoPlistSizeKext Info.plist size.
[in,out]ExecutableKext executable, optional.
[in]ExecutableSizeKext executable size, optional.
[out]BundleVersionKext bundle version, optionally set on request.
Returns
EFI_SUCCESS on success.

Definition at line 1274 of file MkextContext.c.

◆ MkextInjectPatchComplete()

EFI_STATUS MkextInjectPatchComplete ( IN OUT MKEXT_CONTEXT * Context)

Refresh plist and checksum after kext injection and/or patching.

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

Definition at line 1653 of file MkextContext.c.

◆ MkextReserveKextSize()

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

Updated required mkext 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 1233 of file MkextContext.c.

◆ ParseMkextV2Plist()

STATIC BOOLEAN ParseMkextV2Plist ( IN MKEXT_V2_HEADER * Mkext,
OUT UINT8 ** Plist,
OUT UINT32 * PlistSize,
OUT XML_DOCUMENT ** PlistDoc,
OUT XML_NODE ** PlistBundles )

Definition at line 82 of file MkextContext.c.

◆ UpdateMkextLengthChecksum()

STATIC VOID UpdateMkextLengthChecksum ( IN MKEXT_HEADER_ANY * Mkext,
IN UINT32 Length )

Definition at line 66 of file MkextContext.c.

◆ UpdateMkextV2Plist()

STATIC UINT32 UpdateMkextV2Plist ( IN OUT MKEXT_V2_HEADER * Mkext,
IN UINT32 AllocatedSize,
IN XML_DOCUMENT * PlistDoc,
IN UINT32 Offset )

Definition at line 191 of file MkextContext.c.