From c559acd81c5575b57ee20a60e7e89802569504ba Mon Sep 17 00:00:00 2001 From: Goldfish64 Date: Sat, 12 Sep 2020 18:52:22 -0500 Subject: [PATCH] OcAppleKernelLib: Do not abort if Info.plist is missing Some versions of 10.4 may have kexts that do not have an Info.plist, but have plugins. We still want to scan any plugins in this case. --- Library/OcAppleKernelLib/CachelessContext.c | 86 ++++++++++++--------- Platform/OpenCore/OpenCoreKernel.c | 4 + 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/Library/OcAppleKernelLib/CachelessContext.c b/Library/OcAppleKernelLib/CachelessContext.c index 0adb1019..f80c4aa5 100644 --- a/Library/OcAppleKernelLib/CachelessContext.c +++ b/Library/OcAppleKernelLib/CachelessContext.c @@ -186,19 +186,29 @@ ScanExtensions ( if (FileInfoSize > 0) { if (OcUnicodeEndsWith (FileInfo->FileName, L".kext")) { Status = File->Open (File, &FileKext, FileInfo->FileName, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY); - if (!EFI_ERROR (Status)) { - Status = FileKext->Open (FileKext, &FilePlist, L"Contents\\Info.plist", EFI_FILE_MODE_READ, 0); - UseContents = !EFI_ERROR (Status); - if (Status == EFI_NOT_FOUND) { - Status = FileKext->Open (FileKext, &FilePlist, L"Info.plist", EFI_FILE_MODE_READ, 0); - } - if (EFI_ERROR (Status)) { - FileKext->Close (FileKext); - File->SetPosition (File, 0); - FreePool (FileInfo); - return Status; - } + if (EFI_ERROR (Status)) { + continue; + } + // + // Determine if Contents directory exists. + // If not, we'll use the root of the kext. + // + Status = FileKext->Open (FileKext, &FilePlist, L"Contents", EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY); + UseContents = !EFI_ERROR (Status); + + // + // There are some kexts that do not have an Info.plist, but do have PlugIns. + // This was observed in some versions of 10.4. + // + Status = FileKext->Open ( + FileKext, + &FilePlist, + UseContents ? L"Contents\\Info.plist" : L"Info.plist", + EFI_FILE_MODE_READ, + 0 + ); + if (!EFI_ERROR (Status)) { // // Parse Info.plist. // @@ -393,40 +403,40 @@ ScanExtensions ( BuiltinKext->BinaryPath, BuiltinKext->OSBundleRequiredValue )); + } - // - // Scan PlugIns directory. - // - if (ReadPlugins) { - Status = FileKext->Open (FileKext, &FilePlugins, UseContents ? L"Contents\\PlugIns" : L"PlugIns", EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY); - if (Status == EFI_SUCCESS) { - Status = OcUnicodeSafeSPrint ( - TmpPath, - sizeof (TmpPath), - L"%s\\%s\\%s", - FilePath, - FileInfo->FileName, - UseContents ? L"Contents\\PlugIns" : L"PlugIns" - ); - - Status = ScanExtensions (Context, FilePlugins, TmpPath, FALSE); - FilePlugins->Close (FilePlugins); - if (EFI_ERROR (Status)) { - FileKext->Close (FileKext); - File->SetPosition (File, 0); - FreePool (FileInfo); - return Status; - } - } else if (Status != EFI_NOT_FOUND) { + // + // Scan PlugIns directory. + // + if (ReadPlugins) { + Status = FileKext->Open (FileKext, &FilePlugins, UseContents ? L"Contents\\PlugIns" : L"PlugIns", EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY); + if (Status == EFI_SUCCESS) { + Status = OcUnicodeSafeSPrint ( + TmpPath, + sizeof (TmpPath), + L"%s\\%s\\%s", + FilePath, + FileInfo->FileName, + UseContents ? L"Contents\\PlugIns" : L"PlugIns" + ); + + Status = ScanExtensions (Context, FilePlugins, TmpPath, FALSE); + FilePlugins->Close (FilePlugins); + if (EFI_ERROR (Status)) { FileKext->Close (FileKext); File->SetPosition (File, 0); FreePool (FileInfo); return Status; } + } else if (Status != EFI_NOT_FOUND) { + FileKext->Close (FileKext); + File->SetPosition (File, 0); + FreePool (FileInfo); + return Status; } - - FileKext->Close (FileKext); } + + FileKext->Close (FileKext); } } } while (FileInfoSize > 0); diff --git a/Platform/OpenCore/OpenCoreKernel.c b/Platform/OpenCore/OpenCoreKernel.c index aa4e2ea4..6e2fabd9 100644 --- a/Platform/OpenCore/OpenCoreKernel.c +++ b/Platform/OpenCore/OpenCoreKernel.c @@ -1419,6 +1419,10 @@ OcKernelFileOpen ( &VirtualFileHandle ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "OC: Error SLE hooking %s - %r\n", FileName, Status)); + } + if (!EFI_ERROR (Status) && VirtualFileHandle != NULL) { *NewHandle = VirtualFileHandle; return EFI_SUCCESS; -- GitLab