OpenCore
1.0.4
OpenCore Bootloader
|
#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_KEXT * | InsertCachedMkextKext (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_KEXT * | InternalCachedMkextKext (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) |
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.
#define MKEXT_ALIGN | ( | a | ) |
Definition at line 33 of file MkextContext.c.
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.
MKEXT_KEXT * InternalCachedMkextKext | ( | IN OUT MKEXT_CONTEXT * | Context, |
IN CONST CHAR8 * | Identifier ) |
Definition at line 422 of file MkextContext.c.
VOID InternalDropCachedMkextKext | ( | IN OUT MKEXT_CONTEXT * | Context, |
IN CONST CHAR8 * | Identifier ) |
Definition at line 263 of file MkextContext.c.
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.
BOOLEAN InternalParseKextBinary | ( | IN OUT UINT8 ** | Buffer, |
IN OUT UINT32 * | BufferSize, | ||
IN BOOLEAN | Is32Bit ) |
Definition at line 36 of file MkextContext.c.
BOOLEAN MkextCheckCpuType | ( | IN UINT8 * | Mkext, |
IN UINT32 | MkextSize, | ||
IN MACH_CPU_TYPE | CpuType ) |
Check if passed mkext is of desired CPU arch.
[in] | Mkext | Mkext buffer. |
[in] | MkextSize | Mkext buffer size. |
[in] | CpuType | Desired CPU arch. |
Definition at line 1008 of file MkextContext.c.
EFI_STATUS MkextContextApplyPatch | ( | IN OUT MKEXT_CONTEXT * | Context, |
IN CONST CHAR8 * | Identifier, | ||
IN PATCHER_GENERIC_PATCH * | Patch ) |
Apply kext patch to mkext.
[in,out] | Context | Mkext context. |
[in] | Identifier | Kext bundle identifier. |
[in] | Patch | Patch to apply. |
Definition at line 1574 of file MkextContext.c.
EFI_STATUS MkextContextApplyQuirk | ( | IN OUT MKEXT_CONTEXT * | Context, |
IN KERNEL_QUIRK_NAME | Quirk, | ||
IN UINT32 | KernelVersion ) |
Apply kext quirk to mkext.
[in,out] | Context | Mkext context. |
[in] | Quirk | Kext quirk to apply. |
[in] | KernelVersion | Current kernel version. |
Definition at line 1597 of file MkextContext.c.
EFI_STATUS MkextContextBlock | ( | IN OUT MKEXT_CONTEXT * | Context, |
IN CONST CHAR8 * | Identifier, | ||
IN BOOLEAN | Exclude ) |
Block kext in mkext.
[in,out] | Context | Mkext context. |
[in] | Identifier | Kext bundle identifier. |
[in] | Exclude | TRUE to exclude kext from mkext. |
Definition at line 1625 of file MkextContext.c.
VOID MkextContextFree | ( | IN OUT MKEXT_CONTEXT * | Context | ) |
Free resources consumed by mkext context.
[in,out] | Context | Mkext context. |
Definition at line 1203 of file MkextContext.c.
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.
[in,out] | Context | Mkext context. |
[in,out] | Mkext | Decompressed Mkext buffer. |
[in] | MkextSize | Decompressed Mkext buffer size. |
[in] | MkextAllocSize | Decompressed Mkext buffer allocated size. |
Definition at line 1040 of file MkextContext.c.
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.
[in] | Buffer | Mkext buffer. |
[in] | BufferSize | Mkext buffer size. |
[in] | NumReservedKexts | Number of kext slots to reserve for injection. |
[in,out] | OutBuffer | Output buffer. Optional if OutBufferSize is zero. |
[in] | OutBufferSize | Total output buffer size. Specify zero to calculate output buffer size. |
[in,out] | OutMkextSize | Decompressed Mkext size. |
Definition at line 568 of file MkextContext.c.
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.
[in,out] | Context | Mkext context. |
[in] | Identifier | Kext bundle identifier. If a kext with this identifier already exists, the kext will not be injected. Optional. |
[in] | BundlePath | Kext bundle path (e.g. /L/E/mykext.kext). |
[in,out] | InfoPlist | Kext Info.plist. |
[in] | InfoPlistSize | Kext Info.plist size. |
[in,out] | Executable | Kext executable, optional. |
[in] | ExecutableSize | Kext executable size, optional. |
[out] | BundleVersion | Kext bundle version, optionally set on request. |
Definition at line 1274 of file MkextContext.c.
EFI_STATUS MkextInjectPatchComplete | ( | IN OUT MKEXT_CONTEXT * | Context | ) |
Refresh plist and checksum after kext injection and/or patching.
[in,out] | Context | Mkext context. |
Definition at line 1653 of file MkextContext.c.
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.
[in,out] | ReservedInfoSize | Current reserved PLIST size, updated. |
[in,out] | ReservedExeSize | Current reserved KEXT size, updated. |
[in] | InfoPlistSize | Kext Info.plist size. |
[in] | Executable | Kext executable, optional. |
[in] | ExecutableSize | Kext executable size, optional. |
[in] | Is32Bit | TRUE to process 32-bit kext. |
Definition at line 1233 of file MkextContext.c.
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.
STATIC VOID UpdateMkextLengthChecksum | ( | IN MKEXT_HEADER_ANY * | Mkext, |
IN UINT32 | Length ) |
Definition at line 66 of file MkextContext.c.
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.