OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
KextPatcher.c File Reference
#include <Base.h>
#include <IndustryStandard/AppleKmodInfo.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/OcAppleKernelLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcXmlLib.h>
#include "MkextInternal.h"
#include "PrelinkedInternal.h"

Go to the source code of this file.

Functions

STATIC BOOLEAN GetTextBaseOffset (IN OC_MACHO_CONTEXT *ExecutableContext, OUT UINT64 *Address, OUT UINT64 *Offset)
 
EFI_STATUS PatcherInitContextFromPrelinked (IN OUT PATCHER_CONTEXT *Context, IN OUT PRELINKED_CONTEXT *Prelinked, IN CONST CHAR8 *Name)
 
EFI_STATUS PatcherInitContextFromMkext (IN OUT PATCHER_CONTEXT *Context, IN OUT MKEXT_CONTEXT *Mkext, IN CONST CHAR8 *Name)
 
EFI_STATUS PatcherInitContextFromBuffer (IN OUT PATCHER_CONTEXT *Context, IN OUT UINT8 *Buffer, IN UINT32 BufferSize, IN BOOLEAN Is32Bit)
 
EFI_STATUS PatcherGetSymbolAddress (IN OUT PATCHER_CONTEXT *Context, IN CONST CHAR8 *Name, IN OUT UINT8 **Address)
 
EFI_STATUS PatcherGetSymbolValue (IN OUT PATCHER_CONTEXT *Context, IN CONST CHAR8 *Name, IN OUT UINT64 *Value)
 
EFI_STATUS PatcherGetSymbolAddressValue (IN OUT PATCHER_CONTEXT *Context, IN CONST CHAR8 *Name, IN OUT UINT8 **Address, IN OUT UINT64 *Value)
 
EFI_STATUS PatcherApplyGenericPatch (IN OUT PATCHER_CONTEXT *Context, IN PATCHER_GENERIC_PATCH *Patch)
 
EFI_STATUS PatcherExcludePrelinkedKext (IN CONST CHAR8 *Identifier, IN OUT PATCHER_CONTEXT *PatcherContext, IN OUT PRELINKED_CONTEXT *PrelinkedContext)
 
EFI_STATUS PatcherExcludeMkextKext (IN OUT MKEXT_CONTEXT *MkextContext, IN CONST CHAR8 *Identifier)
 
EFI_STATUS PatcherBlockKext (IN OUT PATCHER_CONTEXT *Context)
 
BOOLEAN KextFindKmodAddress (IN OC_MACHO_CONTEXT *ExecutableContext, IN UINT64 LoadAddress, IN UINT32 Size, OUT UINT64 *Kmod)
 

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

Function Documentation

◆ GetTextBaseOffset()

STATIC BOOLEAN GetTextBaseOffset ( IN OC_MACHO_CONTEXT * ExecutableContext,
OUT UINT64 * Address,
OUT UINT64 * Offset )

Definition at line 32 of file KextPatcher.c.

◆ KextFindKmodAddress()

BOOLEAN KextFindKmodAddress ( IN OC_MACHO_CONTEXT * ExecutableContext,
IN UINT64 LoadAddress,
IN UINT32 Size,
OUT UINT64 * Kmod )

Find kmod address.

Parameters
[in]ExecutableContextMach-O context.
[in]LoadAddressLoad address.
[in]SizeExecutable size.
[out]KmodPointer to kmod.
Returns
TRUE on success.

Definition at line 790 of file KextPatcher.c.

◆ PatcherApplyGenericPatch()

EFI_STATUS PatcherApplyGenericPatch ( IN OUT PATCHER_CONTEXT * Context,
IN PATCHER_GENERIC_PATCH * Patch )

Apply generic patch.

Parameters
[in,out]ContextPatcher context.
[in]PatchPatch description.
Returns
EFI_SUCCESS on success.

Definition at line 310 of file KextPatcher.c.

◆ PatcherBlockKext()

EFI_STATUS PatcherBlockKext ( IN OUT PATCHER_CONTEXT * Context)

Block kext from loading.

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

Definition at line 712 of file KextPatcher.c.

◆ PatcherExcludeMkextKext()

EFI_STATUS PatcherExcludeMkextKext ( IN OUT MKEXT_CONTEXT * MkextContext,
IN CONST CHAR8 * Identifier )

Exclude kext from mkext.

Parameters
[in,out]MkextContextMkext context.
[in]IdentifierKext identifier to be excluded.
Returns
EFI_SUCCESS on success.

Definition at line 546 of file KextPatcher.c.

◆ PatcherExcludePrelinkedKext()

EFI_STATUS PatcherExcludePrelinkedKext ( IN CONST CHAR8 * Identifier,
IN OUT PATCHER_CONTEXT * PatcherContext,
IN OUT PRELINKED_CONTEXT * PrelinkedContext )

Exclude kext from prelinked.

Parameters
[in]IdentifierKext identifier to be excluded.
[in,out]PatcherContextPatcher context.
[in,out]PrelinkedContextPrelinked context.
Returns
EFI_SUCCESS on success.

Definition at line 396 of file KextPatcher.c.

◆ PatcherGetSymbolAddress()

EFI_STATUS PatcherGetSymbolAddress ( IN OUT PATCHER_CONTEXT * Context,
IN CONST CHAR8 * Name,
IN OUT UINT8 ** Address )

Get local symbol address.

Parameters
[in,out]ContextPatcher context.
[in]NameSymbol name.
[in,out]AddressReturned symbol address in file.
Returns
EFI_SUCCESS on success.

Definition at line 214 of file KextPatcher.c.

◆ PatcherGetSymbolAddressValue()

EFI_STATUS PatcherGetSymbolAddressValue ( IN OUT PATCHER_CONTEXT * Context,
IN CONST CHAR8 * Name,
IN OUT UINT8 ** Address,
IN OUT UINT64 * Value )

Get local symbol address and symbol value.

Parameters
[in,out]ContextPatcher context.
[in]NameSymbol name.
[in,out]AddressReturned symbol address in file.
[in,out]ValueReturned original symbol value.
Returns
EFI_SUCCESS on success.

Definition at line 234 of file KextPatcher.c.

◆ PatcherGetSymbolValue()

EFI_STATUS PatcherGetSymbolValue ( IN OUT PATCHER_CONTEXT * Context,
IN CONST CHAR8 * Name,
IN OUT UINT64 * Value )

Get local symbol value.

Parameters
[in,out]ContextPatcher context.
[in]NameSymbol name.
[in,out]ValueReturned original symbol value.
Returns
EFI_SUCCESS on success.

Definition at line 224 of file KextPatcher.c.

◆ PatcherInitContextFromBuffer()

EFI_STATUS PatcherInitContextFromBuffer ( IN OUT PATCHER_CONTEXT * Context,
IN OUT UINT8 * Buffer,
IN UINT32 BufferSize,
IN BOOLEAN Use32Bit )

Initialize patcher from buffer for e.g. kernel patching.

Parameters
[in,out]ContextPatcher context.
[in,out]BufferKernel buffer (could be prelinked).
[in]BufferSizeKernel buffer size.
[in]Is32BitTRUE to use 32-bit.
Returns
EFI_SUCCESS on success.

Definition at line 134 of file KextPatcher.c.

◆ PatcherInitContextFromMkext()

EFI_STATUS PatcherInitContextFromMkext ( IN OUT PATCHER_CONTEXT * Context,
IN OUT MKEXT_CONTEXT * Mkext,
IN CONST CHAR8 * Name )

Initialize patcher from mkext context for kext patching.

Parameters
[in,out]ContextPatcher context.
[in,out]MkextMkext context.
[in]NameKext bundle identifier.
Returns
EFI_SUCCESS on success.

Definition at line 117 of file KextPatcher.c.

◆ PatcherInitContextFromPrelinked()

EFI_STATUS PatcherInitContextFromPrelinked ( IN OUT PATCHER_CONTEXT * Context,
IN OUT PRELINKED_CONTEXT * Prelinked,
IN CONST CHAR8 * Name )

Initialize patcher from prelinked context for kext patching.

Parameters
[in,out]ContextPatcher context.
[in,out]PrelinkedPrelinked context.
[in]NameKext bundle identifier.
Returns
EFI_SUCCESS on success.

Definition at line 99 of file KextPatcher.c.