OcAppleKernelLib: Only apply KC address fixup during block if KC

This commit is contained in:
Goldfish64 2020-09-13 10:57:53 -05:00
parent 8c66f78a3d
commit d583e2031a
3 changed files with 26 additions and 17 deletions

View File

@ -326,6 +326,10 @@ typedef struct {
// Pointer to KXLD state (read only, it is allocated in PrelinkedStateKexts).
//
UINT32 KxldStateSize;
//
// Patcher context is contained within a kernel collection.
//
BOOLEAN IsKernelCollection;
} PATCHER_CONTEXT;
//

View File

@ -97,10 +97,11 @@ PatcherInitContextFromBuffer (
return EFI_NOT_FOUND;
}
Context->VirtualBase = Segment->VirtualAddress - Segment->FileOffset;
Context->VirtualKmod = 0;
Context->KxldState = NULL;
Context->KxldStateSize = 0;
Context->VirtualBase = Segment->VirtualAddress - Segment->FileOffset;
Context->VirtualKmod = 0;
Context->KxldState = NULL;
Context->KxldStateSize = 0;
Context->IsKernelCollection = FALSE;
Status = InternalConnectExternalSymtab (
&Context->MachContext,
@ -284,7 +285,9 @@ PatcherBlockKext (
KmodOffset = Context->VirtualKmod - Context->VirtualBase;
KmodInfo = (KMOD_INFO_64_V1 *)((UINT8 *) MachoGetMachHeader64 (&Context->MachContext) + KmodOffset);
StartAddr = KcFixupValue (KmodInfo->StartAddr, NULL);;
if (Context->IsKernelCollection) {
StartAddr = KcFixupValue (KmodInfo->StartAddr, NULL);
}
if (OcOverflowAddU64 (KmodOffset, sizeof (KMOD_INFO_64_V1), &TmpOffset)
|| TmpOffset > MachoGetFileSize (&Context->MachContext)

View File

@ -221,12 +221,13 @@ InternalCreatePrelinkedKext (
return NULL;
}
NewKext->Signature = PRELINKED_KEXT_SIGNATURE;
NewKext->Identifier = KextIdentifier;
NewKext->BundleLibraries = BundleLibraries;
NewKext->CompatibleVersion = CompatibleVersion;
NewKext->Context.VirtualBase = VirtualBase;
NewKext->Context.VirtualKmod = VirtualKmod;
NewKext->Signature = PRELINKED_KEXT_SIGNATURE;
NewKext->Identifier = KextIdentifier;
NewKext->BundleLibraries = BundleLibraries;
NewKext->CompatibleVersion = CompatibleVersion;
NewKext->Context.VirtualBase = VirtualBase;
NewKext->Context.VirtualKmod = VirtualKmod;
NewKext->Context.IsKernelCollection = Prelinked->IsKernelCollection;
//
// Provide pointer to 10.6.8 KXLD state.
@ -738,12 +739,13 @@ InternalCachedPrelinkedKernel (
return NULL;
}
NewKext->Signature = PRELINKED_KEXT_SIGNATURE;
NewKext->Identifier = PRELINK_KERNEL_IDENTIFIER;
NewKext->BundleLibraries = NULL;
NewKext->CompatibleVersion = "0";
NewKext->Context.VirtualBase = Segment->VirtualAddress - Segment->FileOffset;
NewKext->Context.VirtualKmod = 0;
NewKext->Signature = PRELINKED_KEXT_SIGNATURE;
NewKext->Identifier = PRELINK_KERNEL_IDENTIFIER;
NewKext->BundleLibraries = NULL;
NewKext->CompatibleVersion = "0";
NewKext->Context.VirtualBase = Segment->VirtualAddress - Segment->FileOffset;
NewKext->Context.VirtualKmod = 0;
NewKext->Context.IsKernelCollection = Prelinked->IsKernelCollection;
if (!Prelinked->IsKernelCollection) {
//