20#include <Library/BaseLib.h>
21#include <Library/BaseMemoryLib.h>
22#include <Library/BaseOverflowLib.h>
23#include <Library/DebugLib.h>
31#define TEXT_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_EXECUTE)
32#define DATA_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_WRITE)
48 IN CONST CHAR8 *LookupValue,
49 IN UINT32 LookupValueLength,
62 Kext->Processed = TRUE;
64 if (Kext->LinkedSymbolTable != NULL) {
65 NumSymbols = Kext->NumberOfSymbols;
66 Symbols = Kext->LinkedSymbolTable;
69 NumSymbols = Kext->NumberOfCxxSymbols;
70 Symbols = &Kext->LinkedSymbolTable[Kext->NumberOfSymbols - Kext->NumberOfCxxSymbols];
73 SymbolsEnd = &Symbols[NumSymbols];
74 while (Symbols < SymbolsEnd) {
80 if (Symbols->Length == LookupValueLength) {
81 if ( (Symbols->Name[LookupValueLength / 2] == LookupValue[LookupValueLength / 2])
82 && (Symbols->Name[(LookupValueLength / 2) + 1] == LookupValue[(LookupValueLength / 2) + 1]))
84 for (Index = 0; Index < LookupValueLength; ++Index) {
85 if (Symbols->Name[Index] != LookupValue[Index]) {
90 if (Index == LookupValueLength) {
101 for (Index = 0; Index <
ARRAY_SIZE (Kext->Dependencies); ++Index) {
103 if (Dependency == NULL) {
117 if (Symbols != NULL) {
130 IN UINT64 LookupValue,
143 Kext->Processed = TRUE;
145 if (Kext->LinkedSymbolTable != NULL) {
146 NumSymbols = Kext->NumberOfSymbols;
147 Symbols = Kext->LinkedSymbolTable;
150 NumSymbols = Kext->NumberOfCxxSymbols;
151 Symbols = &Kext->LinkedSymbolTable[(Kext->NumberOfSymbols - Kext->NumberOfCxxSymbols) & ~15ULL];
161 SymbolsEnd = &Symbols[NumSymbols & ~15ULL];
162 while (Symbols < SymbolsEnd) {
163 #define MATCH(X) if (Symbols[X].Value == LookupValue) { return &Symbols[X]; }
172 for (Index = 0; Index <
ARRAY_SIZE (Kext->Dependencies); ++Index) {
174 if (Dependency == NULL) {
187 if (Symbols != NULL) {
200 IN CONST CHAR8 *LookupValue,
208 UINT32 LookupValueLength;
211 LookupValueLength = (UINT32)AsciiStrLen (LookupValue);
216 if (LookupValueLength == 0) {
228 for (Index = 0; Index <
ARRAY_SIZE (Kext->Dependencies); ++Index) {
230 if (Dependency == NULL) {
240 if (Symbol != NULL) {
255 IN UINT64 LookupValue,
269 for (Index = 0; Index <
ARRAY_SIZE (Kext->Dependencies); ++Index) {
271 if (Dependency == NULL) {
280 if (Symbol != NULL) {
307 Symbol->Symbol32.Value = (UINT32)Value;
309 Symbol->Symbol32.Section =
NO_SECT;
311 Symbol->Symbol64.Value = Value;
313 Symbol->Symbol64.Section =
NO_SECT;
334 IN CONST CHAR8 *Name,
342 SymbolType = Context->Is32Bit ? Symbol->Symbol32.Type : Symbol->Symbol64.Type;
352 Result = AsciiStrCmp (
371 }
else if ((Context->Is32Bit ? Symbol->Symbol32.Value : Symbol->Symbol64.Value) != 0) {
388 if (ResolveSymbol != NULL) {
418 IN CONST CHAR8 *Name,
420 IN OUT UINT64 *WeakTestValue,
422 IN UINT32 NumUndefinedSymbols
432 ASSERT (UndefinedSymbols != NULL || NumUndefinedSymbols == 0);
436 if (((Context->Is32Bit ? Symbol->Symbol32.Type : Symbol->Symbol64.Type) &
MACH_N_TYPE_STAB) != 0) {
450 if (((Context->Is32Bit ? Symbol->Symbol32.Descriptor : Symbol->Symbol64.Descriptor) &
MACH_N_WEAK_DEF) != 0) {
456 Value = *WeakTestValue;
462 if (NumUndefinedSymbols > 0) {
463 for (Index = 0; Index < NumUndefinedSymbols; ++Index) {
464 if (Context->Is32Bit) {
465 WeakTestSymbol = (
MACH_NLIST_ANY *)&(&UndefinedSymbols->Symbol32)[Index];
467 WeakTestSymbol = (
MACH_NLIST_ANY *)&(&UndefinedSymbols->Symbol64)[Index];
470 Result = AsciiStrCmp (
472 &Kext->Context.MachContext,
478 if (((Context->Is32Bit ?
492 Value = Context->Is32Bit ? WeakTestSymbol->Symbol32.Value : WeakTestSymbol->Symbol64.Value;
493 *WeakTestValue = Value;
497 }
else if (Context->Is32Bit) {
501 if (WeakTestSymbol == NULL) {
505 Result = AsciiStrCmp (
507 &Kext->Context.MachContext,
513 if (((Context->Is32Bit ?
527 Value = Context->Is32Bit ? WeakTestSymbol->Symbol32.Value : WeakTestSymbol->Symbol64.Value;
528 *WeakTestValue = Value;
567 IN UINT64 Adjustment,
568 IN OUT INT32 *Instruction
574 ASSERT (Instruction != NULL);
576 Displacement = ((*Instruction + Target) - Adjustment);
577 Difference = ABS (Displacement);
583 *Instruction = (INT32)Displacement;
610 IN UINT64 LoadAddress,
614 OUT UINT64 *PairTarget,
622 UINT64 TargetAddress;
630 ASSERT (PairTarget != NULL);
632 MachoContext = &Kext->Context.MachContext;
647 if (Relocation->Extern != 0) {
650 Relocation->SymbolNumber
652 if (Symbol == NULL) {
674 if (TargetAddress == 0) {
675 DEBUG ((DEBUG_INFO,
"OCAK: Symbol %a has 0-value\n", Name));
678 if ( (Relocation->SymbolNumber ==
NO_SECT)
679 || (Relocation->SymbolNumber >
MAX_SECT))
686 (Relocation->SymbolNumber - 1)
688 if (Section == NULL) {
692 if (Context->Is32Bit) {
693 TargetAddress = ALIGN_VALUE (
699 TargetAddress = ALIGN_VALUE (
707 if (Context->Is32Bit ?
712 if (NextRelocation == NULL) {
736 *Target = TargetAddress;
737 *PairTarget = PairAddress;
768 if (Index >= Vtable->NumEntries) {
772 Entry = &Vtable->Entries[Index];
773 if (Entry->Name == NULL) {
807 IN UINT64 LoadAddress,
808 IN UINT64 RelocationBase,
817 UINT64 Instruction64;
826 UINT8 *InstructionPtr;
829 BOOLEAN IsNormalLocal;
831 BOOLEAN InvalidPcRel;
835 ASSERT (Relocation != NULL);
839 IsNormalLocal = FALSE;
841 Address = Relocation->Address;
842 Length = Relocation->Size;
843 Type = (UINT8)Relocation->Type;
844 PcRelative = (Relocation->PcRelative != 0);
847 InvalidPcRel = FALSE;
848 ScatteredRelocation = NULL;
853 if (Context->Is32Bit) {
857 Address = ScatteredRelocation->Address;
858 Length = ScatteredRelocation->Size;
859 Type = (UINT8)ScatteredRelocation->Type;
860 PcRelative = (ScatteredRelocation->PcRelative != 0);
861 Target = LoadAddress;
870 &Kext->Context.MachContext,
871 (RelocationBase + Address),
874 if ((InstructionPtr == NULL) || (MaxSize < ((
Length != 3) ? 4U : 8U))) {
878 if (Relocation->Extern == 0) {
879 IsNormalLocal = TRUE;
882 LinkPc = (Address + LoadAddress);
885 if (ScatteredRelocation == NULL) {
905 CopyMem (&Instruction32, InstructionPtr,
sizeof (Instruction32));
907 if ( (Vtable != NULL)
913 if (Context->Is32Bit) {
915 Target = Target + Address - (LinkPc + RelocationBase);
920 Instruction32 += (UINT32)Target;
924 DEBUG ((DEBUG_ERROR,
"OCAK: Non-vanilla 32-bit relocations are unsupported\n"));
994 InvalidPcRel = !PcRelative;
995 Adjustment += LinkPc;
1004 InvalidPcRel = !PcRelative;
1005 Adjustment += (IsNormalLocal ? LoadAddress : LinkPc);
1012 InvalidPcRel = !PcRelative;
1013 Adjustment += LinkPc;
1014 Target = PairTarget;
1021 InvalidPcRel = PcRelative;
1022 Instruction32 = (INT32)(Target - PairTarget);
1045 CopyMem (InstructionPtr, &Instruction32,
sizeof (Instruction32));
1047 CopyMem (&Instruction64, InstructionPtr,
sizeof (Instruction64));
1049 if ( (Vtable != NULL)
1058 InvalidPcRel = PcRelative;
1059 Instruction64 += Target;
1065 InvalidPcRel = PcRelative;
1066 Instruction64 = (Target - PairTarget);
1077 CopyMem (InstructionPtr, &Instruction64,
sizeof (Instruction64));
1081 DEBUG ((DEBUG_WARN,
"OCAK: Relocation has invalid PC relative flag\n"));
1084 if (Context->Is32Bit) {
1091 ReturnValue |= BIT31;
1120 IN UINT64 LoadAddress,
1121 IN UINT64 RelocationBase,
1123 IN OUT UINT32 *NumRelocations,
1127 UINT32 PreservedRelocations;
1130 UINT32 SectionIndex;
1137 ASSERT (NumRelocations != NULL);
1138 ASSERT (SourceRelocations != NULL || *NumRelocations == 0);
1143 if (Context->Is32Bit && (*NumRelocations == 0)) {
1147 if (Section32 == NULL) {
1154 NextRelocation = &Relocation[Index + 1];
1159 NextRelocation = NULL;
1169 RelocationBase + Section32->
Address,
1173 if (Result == MAX_UINTN) {
1188 ASSERT (TargetRelocations != NULL);
1190 PreservedRelocations = 0;
1192 for (Index = 0; Index < *NumRelocations; ++Index) {
1197 if ( (SourceRelocations[Index].Extern == 0)
1207 NextRelocation = &SourceRelocations[Index + 1];
1211 if (Index == (*NumRelocations - 1)) {
1212 NextRelocation = NULL;
1223 &SourceRelocations[Index],
1226 if (Result == MAX_UINTN) {
1233 if ((Result & ~(UINTN)BIT31) != 0) {
1234 Relocation = &TargetRelocations[PreservedRelocations];
1236 CopyMem (Relocation, &SourceRelocations[Index],
sizeof (*Relocation));
1238 if (Relocation->
Extern != 0) {
1252 ++PreservedRelocations;
1259 if ((Result & BIT31) != 0) {
1264 *NumRelocations = PreservedRelocations;
1277 IN UINT64 LoadAddress,
1279 IN OUT UINT32 *KmodInfoOffset
1283 CONST CHAR8 *SymbolName;
1287 KmodOffset = *KmodInfoOffset;
1289 if ((KmodOffset == 0) && (((MachoContext->Is32Bit ? Symbol->Symbol32.Type : Symbol->Symbol64.Type) &
MACH_N_TYPE_STAB) == 0)) {
1291 ASSERT (SymbolName != NULL);
1293 if (AsciiStrCmp (SymbolName,
"_kmod_info") == 0) {
1302 || ((KmodOffset % 4) != 0)))
1307 *KmodInfoOffset = KmodOffset;
1322 IN UINT64 LoadAddress,
1323 IN UINT32 NumSymbols,
1325 OUT UINT32 *KmodInfoOffset
1333 ASSERT (MachoContext != NULL);
1334 ASSERT (Symbols != NULL || NumSymbols == 0);
1335 ASSERT (KmodInfoOffset != NULL);
1340 if (MachoContext->Is32Bit && (NumSymbols == 0)) {
1344 if (Symbol == NULL) {
1368 for (Index = 0; Index < NumSymbols; ++Index) {
1369 if (MachoContext->Is32Bit) {
1398 IN UINT64 LoadAddress
1401 CONST VOID *FileData;
1408 CONST UINT32 *SymIndices;
1409 VOID *IndirectSymPtr;
1420 if (Section == NULL) {
1424 if (MachoContext->Is32Bit) {
1425 NumSymbols = Section->Section32.Size /
sizeof (UINT32);
1426 FirstSym = Section->Section32.Reserved1;
1428 NumSymbols = (UINT32)(Section->Section64.Size / sizeof (UINT64));
1429 FirstSym = Section->Section64.Reserved1;
1432 Result = BaseOverflowAddU32 (FirstSym, NumSymbols, &OffsetTop);
1433 if (Result || (OffsetTop > DySymtab->NumIndirectSymbols)) {
1438 Result = BaseOverflowMulAddU32 (
1439 DySymtab->NumIndirectSymbols,
1441 DySymtab->IndirectSymbolsOffset,
1444 if (Result || (OffsetTop > MachSize)) {
1449 ASSERT (FileData != NULL);
1460 Tmp = (VOID *)((UINTN)FileData + DySymtab->IndirectSymbolsOffset);
1461 if (!BASE_TYPE_ALIGNED (UINT32, Tmp)) {
1465 SymIndices = (UINT32 *)Tmp + FirstSym;
1467 IndirectSymPtr = (VOID *)((UINTN)FileData + (MachoContext->Is32Bit ? Section->Section32.Offset : Section->Section64.Offset));
1468 if (MachoContext->Is32Bit ? !BASE_TYPE_ALIGNED (UINT32, IndirectSymPtr) : !BASE_TYPE_ALIGNED (UINT64, IndirectSymPtr)) {
1472 for (Index = 0; Index < NumSymbols; ++Index) {
1478 if (MachoContext->Is32Bit) {
1479 ((UINT32 *)IndirectSymPtr)[Index] += (UINT32)LoadAddress;
1481 ((UINT64 *)IndirectSymPtr)[Index] += LoadAddress;
1485 if (Symbol == NULL) {
1489 if (MachoContext->Is32Bit) {
1490 ((UINT32 *)IndirectSymPtr)[Index] += Symbol->Symbol32.Value;
1492 ((UINT64 *)IndirectSymPtr)[Index] += Symbol->Symbol64.Value;
1517 IN UINT64 LoadAddress,
1518 IN UINT64 FileOffset
1523 UINT64 LinkEditFileOffset;
1524 UINT64 LinkEditFileSize;
1542 CONST CHAR8 *SymbolName;
1544 CONST CHAR8 *StringTable;
1547 UINT32 NumLocalSymbols;
1549 UINT32 NumExternalSymbols;
1551 UINT32 NumUndefinedSymbols;
1552 UINT64 WeakTestValue;
1554 UINT32 NumRelocations;
1555 UINT32 NumRelocations2;
1561 UINT32 LinkEditSize;
1562 UINT32 SymbolTableOffset;
1563 UINT32 SymbolTableSize;
1564 UINT32 RelocationsOffset;
1565 UINT32 RelocationsSize;
1566 UINT32 StringTableOffset;
1567 UINT32 StringTableSize;
1569 UINT32 NumSymtabLinkEdit32Symbols;
1571 UINT32 SegmentOffset;
1573 UINT64 LoadAddressOffset;
1575 UINT64 SegmentVmSizes;
1576 UINT32 KmodInfoOffset;
1579 ASSERT (Context != NULL);
1581 ASSERT (LoadAddress != 0);
1589 MachoContext = &Kext->Context.MachContext;
1590 LinkEditSegment = Kext->LinkEditSegment;
1601 FileData = (VOID *)MachHeader;
1614 if ((!IsObject32 && (LinkEditSegment == NULL)) || (Kext->Context.VirtualKmod == 0)) {
1615 return EFI_UNSUPPORTED;
1618 if (BaseOverflowAddU64 (LoadAddress, FileOffset, &LoadAddressOffset)) {
1619 return EFI_INVALID_PARAMETER;
1622 if (Context->Is32Bit) {
1623 ASSERT (LoadAddressOffset < MAX_UINT32);
1636 &NumExternalSymbols,
1638 &NumUndefinedSymbols
1640 if (NumSymbols == 0) {
1641 return EFI_UNSUPPORTED;
1644 Symtab = MachoContext->
Symtab;
1649 ASSERT (DySymtab != NULL);
1684 LinkEdit = Context->LinkBuffer;
1685 LinkEditSize = (SymbolTableSize + RelocationsSize + StringTableSize);
1690 return EFI_UNSUPPORTED;
1695 SymbolTableOffset = 0;
1696 RelocationsOffset = (SymbolTableOffset + SymbolTableSize);
1705 for (Index = 0; Index < NumSymbols; ++Index) {
1709 if (SymbolName == NULL) {
1710 return EFI_LOAD_ERROR;
1723 return EFI_LOAD_ERROR;
1735 NumSymtabLinkEdit32Symbols = 0;
1737 NumUndefinedSymbols = NumSymbols;
1740 for (Index = 0; Index < NumUndefinedSymbols; ++Index) {
1741 if (Context->Is32Bit) {
1742 Symbol = (
MACH_NLIST_ANY *)(!IsObject32 ? &(&UndefinedSymtab->Symbol32)[Index] : &(&SymbolTable->Symbol32)[Index]);
1770 !IsObject32 ? UndefinedSymtab : NULL,
1771 !IsObject32 ? NumUndefinedSymbols : 0
1776 "OCAK: Symbol %a was unresolved for kext %a\n",
1780 return EFI_LOAD_ERROR;
1784 "OCAK: Symbol %a was resolved for kext %a to %Lx\n",
1797 DEBUG ((DEBUG_INFO,
"OCAK: Vtable patching failed for kext %a\n", Kext->Identifier));
1798 return EFI_LOAD_ERROR;
1815 return EFI_LOAD_ERROR;
1826 if (!Result || (KmodInfoOffset == 0)) {
1827 return EFI_LOAD_ERROR;
1830 KmodInfo = (
KMOD_INFO_ANY *)((UINTN)FileData + (UINTN)KmodInfoOffset);
1833 if (FirstSegment == NULL) {
1834 return EFI_UNSUPPORTED;
1839 return EFI_LOAD_ERROR;
1847 (UINTN)LinkEdit + RelocationsOffset
1862 &TargetRelocation[0]
1865 return EFI_LOAD_ERROR;
1883 &TargetRelocation[NumRelocations]
1886 return EFI_LOAD_ERROR;
1889 NumRelocations += NumRelocations2;
1897 SymtabSize = SymbolTableSize;
1898 if (NumUndefinedSymbols > 0) {
1899 SymtabSize = (UINT32)((UndefinedSymtab - SymbolTable) * (Context->Is32Bit ? sizeof (
MACH_NLIST) :
sizeof (
MACH_NLIST_64)));
1903 (VOID *)((UINTN)LinkEdit + SymbolTableOffset),
1908 if (NumUndefinedSymbols > 0) {
1909 if (Context->Is32Bit) {
1910 SymtabSize2 = (UINT32)(&(&SymbolTable->Symbol32)[NumSymbols] - &(&UndefinedSymtab->Symbol32)[NumUndefinedSymbols]);
1914 (VOID *)((UINTN)LinkEdit + SymbolTableOffset + SymtabSize),
1915 (VOID *)&(&UndefinedSymtab->Symbol32)[NumUndefinedSymbols],
1919 SymtabSize2 = (UINT32)(&(&SymbolTable->Symbol64)[NumSymbols] - &(&UndefinedSymtab->Symbol64)[NumUndefinedSymbols]);
1923 (VOID *)((UINTN)LinkEdit + SymbolTableOffset + SymtabSize),
1924 (VOID *)&(&UndefinedSymtab->Symbol64)[NumUndefinedSymbols],
1929 NumSymbols -= NumUndefinedSymbols;
1936 StringTableOffset = (RelocationsOffset + RelocationsSize);
1938 (VOID *)((UINTN)LinkEdit + StringTableOffset),
1945 if (Context->Is32Bit) {
1953 Symtab->
SymbolsOffset = (UINT32)(LinkEditFileOffset + SymbolTableOffset);
1955 Symtab->
StringsOffset = (UINT32)(LinkEditFileOffset + StringTableOffset);
1960 LinkEditSize = (SymbolTableSize + RelocationsSize + StringTableSize);
1963 (VOID *)((UINTN)FileData + (UINTN)LinkEditFileOffset),
1968 (VOID *)((UINTN)FileData + (UINTN)LinkEditFileOffset + LinkEditSize),
1969 (UINTN)(LinkEditFileSize - LinkEditSize)
1973 if (Context->Is32Bit) {
1998 if (NumUndefinedSymbols > 0) {
2005 NumSymtabLinkEdit32Symbols = 0;
2006 for (Index = 0; Index < NumSymbols; ++Index) {
2016 &SymtabLinkEdit32[NumSymtabLinkEdit32Symbols++],
2022 SymtabSize = (UINT32)(NumSymbols *
sizeof (
MACH_NLIST));
2023 SymtabSize2 = (UINT32)(NumSymtabLinkEdit32Symbols *
sizeof (
MACH_NLIST));
2038 Symtab->
NumSymbols = NumSymtabLinkEdit32Symbols;
2053 if (Context->Is32Bit) {
2066 if (Context->Is32Bit) {
2116 if (Context->Is32Bit) {
2129 KmodInfo->
Kmod32.
HdrSize = IsObject32 ? (UINT32)FileOffset : 0;
2137 MachSize = SegmentOffset + SegmentSize;
2159 MachSize = SegmentOffset + SegmentSize;
2171 return EFI_INVALID_PARAMETER;
#define ARRAY_SIZE(Array)
#define MACH_HEADER_FLAG_DYNAMIC_LINKER_LINK
#define NO_SECT
symbol is not in any section
#define MACH_RELOC_ABSOLUTE
absolute relocation type for Mach-O files
@ MachGenericRelocVanilla
#define MACH_N_TYPE_TYPE
mask for the type bit
#define MACH_HEADER_FLAG_NO_UNDEFINED_REFERENCES
#define MACH_N_TYPE_UNDF
undefined, n_sect == NO_SECT
#define MACH_N_TYPE_INDR
indirect
@ MachX8664RelocUnsigned
for absolute addresses
@ MachX8664RelocGotLoad
a MOVQ load of a GOT entry
@ MachX8664RelocSigned
for signed 32-bit displacement
@ MachX8664RelocSubtractor
@ MachX8664RelocGot
other GOT references
#define MACH_N_TYPE_SECT
defined in section number n_sect
@ MachHeaderFileTypeObject
#define MACH_N_TYPE_ABS
absolute, n_sect == NO_SECT
#define MACH_INDIRECT_SYMBOL_LOCAL
#define MAX_SECT
1 thru 255 inclusive
#define MACH_INDIRECT_SYMBOL_ABS
STATIC BOOLEAN InternalRelocateAndCopyRelocations(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 RelocationBase, IN CONST MACH_RELOCATION_INFO *SourceRelocations, IN OUT UINT32 *NumRelocations, OUT MACH_RELOCATION_INFO *TargetRelocations)
EFI_STATUS InternalPrelinkKext(IN OUT PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 FileOffset)
STATIC BOOLEAN InternalCalculateTargets(IN PRELINKED_CONTEXT *Context, IN OUT PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN CONST MACH_RELOCATION_INFO *Relocation, IN CONST MACH_RELOCATION_INFO *NextRelocation OPTIONAL, OUT UINT64 *Target, OUT UINT64 *PairTarget, OUT CONST PRELINKED_VTABLE **Vtable OPTIONAL)
CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolName(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel)
STATIC BOOLEAN InternalRelocateSymbols(IN OC_MACHO_CONTEXT *MachoContext, IN UINT64 LoadAddress, IN UINT32 NumSymbols, IN OUT MACH_NLIST_ANY *Symbols, OUT UINT32 *KmodInfoOffset)
STATIC BOOLEAN InternalSolveSymbol(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *Name, IN OUT MACH_NLIST_ANY *Symbol, IN OUT UINT64 *WeakTestValue, IN CONST MACH_NLIST_ANY *UndefinedSymbols, IN UINT32 NumUndefinedSymbols)
STATIC BOOLEAN InternalRelocateSymbol(IN OC_MACHO_CONTEXT *MachoContext, IN UINT64 LoadAddress, IN OUT MACH_NLIST_ANY *Symbol, IN OUT UINT32 *KmodInfoOffset)
STATIC CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolWorkerValue(IN PRELINKED_KEXT *Kext, IN UINT64 LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel)
CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolValue(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel)
STATIC UINTN InternalRelocateRelocation(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 RelocationBase, IN CONST MACH_RELOCATION_INFO *Relocation, IN CONST MACH_RELOCATION_INFO *NextRelocation OPTIONAL)
STATIC BOOLEAN InternalProcessSymbolPointers(IN OC_MACHO_CONTEXT *MachoContext, IN CONST MACH_DYSYMTAB_COMMAND *DySymtab, IN UINT64 LoadAddress)
STATIC BOOLEAN InternalIsDirectPureVirtualCall(IN BOOLEAN Is32Bit, IN CONST PRELINKED_VTABLE *Vtable, IN UINT64 Offset)
STATIC CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolWorkerName(IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *LookupValue, IN UINT32 LookupValueLength, IN OC_GET_SYMBOL_LEVEL SymbolLevel)
STATIC BOOLEAN InternalCalculateDisplacementIntel64(IN UINT64 Target, IN UINT64 Adjustment, IN OUT INT32 *Instruction)
VOID InternalSolveSymbolValue(IN BOOLEAN Is32Bit, IN UINT64 Value, OUT MACH_NLIST_ANY *Symbol)
STATIC BOOLEAN InternalSolveSymbolNonWeak(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *Name, IN OUT MACH_NLIST_ANY *Symbol)
UINT32 MachoGetInnerSize(IN OUT OC_MACHO_CONTEXT *Context)
BOOLEAN MachoRelocateSymbol(IN OUT OC_MACHO_CONTEXT *Context, IN UINT64 LinkAddress, IN OUT MACH_NLIST_ANY *Symbol)
UINT32 MachoGetFileSize(IN OUT OC_MACHO_CONTEXT *Context)
CONST CHAR8 * MachoGetIndirectSymbolName(IN OUT OC_MACHO_CONTEXT *Context, IN CONST MACH_NLIST_ANY *Symbol)
VOID * MachoGetFileData(IN OUT OC_MACHO_CONTEXT *Context)
VOID * MachoGetFilePointerByAddress(IN OUT OC_MACHO_CONTEXT *Context, IN UINT64 Address, OUT UINT32 *MaxSize OPTIONAL)
MACH_SEGMENT_COMMAND_ANY * MachoGetNextSegment(IN OUT OC_MACHO_CONTEXT *Context, IN CONST MACH_SEGMENT_COMMAND_ANY *Segment OPTIONAL)
MACH_HEADER_ANY * MachoGetMachHeader(IN OUT OC_MACHO_CONTEXT *Context)
BOOLEAN MachoInitializeContext(OUT OC_MACHO_CONTEXT *Context, IN VOID *FileData, IN UINT32 FileSize, IN UINT32 HeaderOffset, IN UINT32 InnerSize, IN BOOLEAN Is32Bit)
UINT32 MachoGetSymbolTable(IN OUT OC_MACHO_CONTEXT *Context, OUT CONST MACH_NLIST_ANY **SymbolTable, OUT CONST CHAR8 **StringTable OPTIONAL, OUT CONST MACH_NLIST_ANY **LocalSymbols OPTIONAL, OUT UINT32 *NumLocalSymbols OPTIONAL, OUT CONST MACH_NLIST_ANY **ExternalSymbols OPTIONAL, OUT UINT32 *NumExternalSymbols OPTIONAL, OUT CONST MACH_NLIST_ANY **UndefinedSymbols OPTIONAL, OUT UINT32 *NumUndefinedSymbols OPTIONAL)
BOOLEAN MachoRelocationIsPairIntel64(IN UINT8 Type)
MACH_NLIST_ANY * MachoGetSymbolByIndex(IN OUT OC_MACHO_CONTEXT *Context, IN UINT32 Index)
BOOLEAN MachoPreserveRelocationIntel64(IN UINT8 Type)
BOOLEAN MachoRelocationIsPairIntel32(IN UINT8 Type)
CONST CHAR8 * MachoGetSymbolName(IN OUT OC_MACHO_CONTEXT *Context, IN CONST MACH_NLIST_ANY *Symbol)
MACH_SECTION_ANY * MachoGetNextSection(IN OUT OC_MACHO_CONTEXT *Context, IN MACH_SEGMENT_COMMAND_ANY *Segment, IN MACH_SECTION_ANY *Section OPTIONAL)
BOOLEAN MachoSymbolNameIsVtable(IN CONST CHAR8 *SymbolName)
MACH_SECTION * MachoGetSectionByIndex32(IN OUT OC_MACHO_CONTEXT *Context, IN UINT32 Index)
BOOLEAN MachoSymbolNameIsPureVirtual(IN CONST CHAR8 *Name)
MACH_SECTION_ANY * MachoGetSectionByIndex(IN OUT OC_MACHO_CONTEXT *Context, IN UINT32 Index)
MACH_SECTION_ANY * MachoGetSegmentSectionByName(IN OUT OC_MACHO_CONTEXT *Context, IN CONST CHAR8 *SegmentName, IN CONST CHAR8 *SectionName)
BOOLEAN MachoSymbolGetFileOffset(IN OUT OC_MACHO_CONTEXT *Context, IN CONST MACH_NLIST_ANY *Symbol, OUT UINT32 *FileOffset, OUT UINT32 *MaxSize OPTIONAL)
CONST PRELINKED_VTABLE * InternalGetOcVtableByName(IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *Name)
#define X86_64_RIP_RELATIVE_LIMIT
#define VTABLE_ENTRY_SIZE_X(a)
BOOLEAN InternalPatchByVtables(IN PRELINKED_CONTEXT *Context, IN OUT PRELINKED_KEXT *Kext)
#define KXLD_WEAK_TEST_SYMBOL
VOID InternalUnlockContextKexts(IN PRELINKED_CONTEXT *Context)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT64 EFIAPI DivU64x32Remainder(IN UINT64 Dividend, IN UINT32 Divisor, OUT UINT32 *Remainder OPTIONAL)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
#define DivU64x32(x, y, z)
UINT32 NumExternalRelocations
UINT32 NumExternalSymbols
number of externally defined symbols
UINT32 NumIndirectSymbols
UINT32 UndefinedSymbolsIndex
index to undefined symbols
UINT32 NumLocalSymbols
number of local symbols
UINT32 NumOfLocalRelocations
number of local relocation entries
UINT32 IndirectSymbolsOffset
MACH_LOAD_COMMAND_HDR_ UINT32 LocalSymbolsIndex
index to local symbols
UINT32 ExternalRelocationsOffset
UINT32 NumUndefinedSymbols
number of undefined symbols
UINT32 LocalRelocationsOffset
offset to local relocation entries
UINT32 ExternalSymbolsIndex
index to externally defined symbols
MACH_HEADER_FLAGS Flags
flags
MACH_HEADER_FLAGS Flags
flags
MACH_HEADER_FILE_TYPE FileType
type of file
UINT64 Value
value of this symbol (or stab offset)
UINT8 Type
type flag, see below
UINT8 Section
section number or NO_SECT
UINT8 Type
type flag, see below
UINT32 Value
value of this symbol (or stab offset)
UINT32 Extern
does not include value of sym referenced
UINT32 Alignment
section alignment (power of 2)
UINT64 Address
memory address of this section
UINT32 Alignment
section alignment (power of 2)
UINT32 Address
memory address of this section
UINT32 NumRelocations
number of relocation entries
UINT32 RelocationsOffset
file offset of relocation entries
MACH_VM_PROTECTION InitialProtection
initial VM protection
UINT64 FileOffset
file offset of this segment
MACH_LOAD_COMMAND_HDR_ CHAR8 SegmentName[16]
segment Name
UINT64 Size
memory size of this segment
UINT64 FileSize
amount to map from the file
UINT64 VirtualAddress
memory address of this segment
MACH_VM_PROTECTION MaximumProtection
maximum VM protection
UINT32 FileOffset
file offset of this segment
UINT32 Size
memory size of this segment
MACH_VM_PROTECTION InitialProtection
initial VM protection
UINT32 VirtualAddress
memory address of this segment
MACH_VM_PROTECTION MaximumProtection
maximum VM protection
UINT32 FileSize
amount to map from the file
MACH_LOAD_COMMAND_HDR_ CHAR8 SegmentName[16]
segment Name
UINT32 StringsSize
string table size in bytes
MACH_LOAD_COMMAND_HDR_ UINT32 SymbolsOffset
symbol table offset
UINT32 NumSymbols
number of symbol table entries
UINT32 StringsOffset
string table offset
MACH_RELOCATION_INFO * ExternRelocations
MACH_DYSYMTAB_COMMAND * DySymtab
MACH_RELOCATION_INFO * LocalRelocations
MACH_SYMTAB_COMMAND * Symtab
PRELINKED_KEXT * Dependencies[MAX_KEXT_DEPEDENCIES]
MACH_SECTION_64 Section64
MACH_SEGMENT_COMMAND_64 Segment64
MACH_SEGMENT_COMMAND Segment32