From 1856b519e5f1fda3ca2d1a018a19119e50dd5ff0 Mon Sep 17 00:00:00 2001 From: SergeySlice Date: Wed, 24 Jun 2020 07:20:45 +0300 Subject: [PATCH] position in installer bigsur Signed-off-by: SergeySlice --- Protocols/DumpUefiCalls/AppleProtocols.c | 3 +- Protocols/DumpUefiCalls/BootServices.c | 11 ++++- Protocols/DumpUefiCalls/Common.h | 4 ++ rEFIt_UEFI/Platform/Events.cpp | 1 + rEFIt_UEFI/Platform/guid.cpp | 31 ++++++++++++++ rEFIt_UEFI/Platform/kernel_patcher.cpp | 52 +++++++++++++++++++++--- rEFIt_UEFI/Platform/kext_inject.cpp | 16 ++++++-- rEFIt_UEFI/entry_scan/loader.cpp | 4 +- rEFIt_UEFI/refit/main.cpp | 2 +- 9 files changed, 110 insertions(+), 14 deletions(-) diff --git a/Protocols/DumpUefiCalls/AppleProtocols.c b/Protocols/DumpUefiCalls/AppleProtocols.c index c83738c89..39df34f27 100644 --- a/Protocols/DumpUefiCalls/AppleProtocols.c +++ b/Protocols/DumpUefiCalls/AppleProtocols.c @@ -738,9 +738,10 @@ OvrSetKeyStrokeBufferKeys ( { EFI_STATUS Status; Status = gOrgAppleKeyMapDb.SetKeyStrokeBufferKeys(This, Index, Modifiers, NumberOfKeys, Keys); +#if SET_KEY_STROKE PRINT("->SetKeyStrokeBufferKeys => Index=%d, Modifiers=%x, NoKeys=%d, Keys={%x, %x}, Status=%r\n", Index, Modifiers, NumberOfKeys, Keys?*Keys:0, (Keys && NumberOfKeys>1)?Keys[1]:0, Status); - +#endif return Status; } diff --git a/Protocols/DumpUefiCalls/BootServices.c b/Protocols/DumpUefiCalls/BootServices.c index 323acd3e8..46bdb875e 100644 --- a/Protocols/DumpUefiCalls/BootServices.c +++ b/Protocols/DumpUefiCalls/BootServices.c @@ -180,7 +180,7 @@ OvrSetTimer( EFI_STATUS Status; Status = gOrgBS.SetTimer(Event, Type, TriggerTime); - PRINT("->SetTimer(%p, %d, 0x%x) = %r\n", Event, Type, TriggerTime, Status); +// PRINT("->SetTimer(%p, %d, 0x%x) = %r\n", Event, Type, TriggerTime, Status); return Status; } @@ -288,7 +288,9 @@ OvrHandleProtocol( EFI_STATUS Status; Status = gOrgBS.HandleProtocol(Handle, Protocol, Interface); +#if HANDLE_PROTOCOL PRINT("->HandleProtocol(%p, %s, %p) = %r\n", Handle, GuidStr(Protocol), *Interface, Status); +#endif return Status; } @@ -563,10 +565,13 @@ OvrOpenProtocol( ) { EFI_STATUS Status; +#if OPEN_PROTOCOL VOID *InterfaceIn = *Interface; - +#endif Status = gOrgBS.OpenProtocol(Handle, Protocol, Interface, AgentHandle, ControllerHandle, Attributes); +#if OPEN_PROTOCOL PRINT("->OpenProtocol(%p, %s, %p/%p, %p, %p, %x) = %r\n", Handle, GuidStr(Protocol), InterfaceIn, *Interface, AgentHandle, ControllerHandle, Attributes, Status); +#endif return Status; } @@ -581,7 +586,9 @@ OvrCloseProtocol( EFI_STATUS Status; Status = gOrgBS.CloseProtocol(Handle, Protocol, AgentHandle, ControllerHandle); +#if OPEN_PROTOCOL PRINT("->CloseProtocol(%p, %s, %p, %p) = %r\n", Handle, GuidStr(Protocol), AgentHandle, ControllerHandle, Status); +#endif return Status; } diff --git a/Protocols/DumpUefiCalls/Common.h b/Protocols/DumpUefiCalls/Common.h index f38f911df..c828a96a1 100644 --- a/Protocols/DumpUefiCalls/Common.h +++ b/Protocols/DumpUefiCalls/Common.h @@ -144,6 +144,10 @@ // #define BOOT_LOADERS { L"boot.efi", L"bootmgfw.efi", L"grub.efi", L"grubx64.efi", L"bootx64.efi", NULL } +#define HANDLE_PROTOCOL 0 +#define LOCATE_PROTOCOL 0 +#define OPEN_PROTOCOL 0 +#define SET_KEY_STROKE 0 #include "Lib.h" #include "Log.h" diff --git a/rEFIt_UEFI/Platform/Events.cpp b/rEFIt_UEFI/Platform/Events.cpp index ff9f2ab48..a07b3f62e 100644 --- a/rEFIt_UEFI/Platform/Events.cpp +++ b/rEFIt_UEFI/Platform/Events.cpp @@ -354,6 +354,7 @@ OnReadyToBoot ( } // printf("MSR 0xE2 on ReadyToBoot %08x\n", msr); */ + gST->ConOut->OutputString (gST->ConOut, L"-- ReadyToBoot --\n"); } VOID diff --git a/rEFIt_UEFI/Platform/guid.cpp b/rEFIt_UEFI/Platform/guid.cpp index 4952e1294..3ea537196 100644 --- a/rEFIt_UEFI/Platform/guid.cpp +++ b/rEFIt_UEFI/Platform/guid.cpp @@ -79,6 +79,37 @@ EFI_GUID GPT_EMPTY_PARTITION = \ // 24B73556-2197-4702-82A8-3E1337DAFBF3 // 1BAD711C-D451-4241-B1F3-8537812E0C70 GUID for MeBiosExtensionSetup variable // 36C28AB5-6566-4C50-9EBD-CBB920F83843:preferred-networks gAppleWirelessNetworkVariableGuid +// ->SetVariable(boot-feature-usage, 62BF9B1C-8568-48EE-85DC-DD3057660863, 7, 8, 4C4ABBE8) = Success +// 00 00 08 00 00 00 00 00 | ........ + +/* +->SetVariable(ApECID, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 8, 4C4ABC90) = Success +1C 02 1B 03 0D 04 66 05 | ......f. +->SetVariable(ApChipID, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 4, 4C4ABCB4) = Success +12 80 00 00 | .... +->SetVariable(ApBoardID, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 4, 4C4ABCB0) = Success +F0 00 00 00 | .... +->SetVariable(ApSecurityDomain, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 4, 4C4ABCB8) = Success +01 00 00 00 | .... +->SetVariable(ApProductionStatus, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBD) = Success +01 | . +->SetVariable(ApSecurityMode, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBD) = Success +01 | . +->SetVariable(EffectiveProductionStatus, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBD) = Success +01 | . +->SetVariable(EffectiveSecurityMode, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBD) = Success +01 | . +->SetVariable(CertificateEpoch, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBF) = Success +02 | . +->SetVariable(MixNMatchPreventionStatus, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBE) = Success +00 | . +->SetVariable(CryptoDigestMethod, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 10, 4C4ABC70) = Success +73 68 61 32 2D 33 38 34 00 00 00 00 00 00 00 00 | sha2-384........ +->SetVariable(HardwareModel, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 10, 4C4ABC60) = Success +78 38 36 6C 65 67 61 63 79 61 70 00 00 00 00 00 | x86legacyap..... +->SetVariable(InternalUseOnlyUnit, 94B73556-2197-4702-82A8-3E1337DAFBFB, 6, 1, 4C4ABCBD) = Success +01 | . +*/ /* * Copyright (c) 2007 Apple Inc. All rights reserved. diff --git a/rEFIt_UEFI/Platform/kernel_patcher.cpp b/rEFIt_UEFI/Platform/kernel_patcher.cpp index bbb0f2068..6e7d709fb 100644 --- a/rEFIt_UEFI/Platform/kernel_patcher.cpp +++ b/rEFIt_UEFI/Platform/kernel_patcher.cpp @@ -190,6 +190,8 @@ UINTN LOADER_ENTRY::searchProc(const char *procedure) bool found = false; for (i=0; iVersion==2 && bootArgs2->Revision==0 + if (bootArgs2->Version==2 && (bootArgs2->Revision==0 || bootArgs2->Revision==1) // plus additional checks - some values are not inited by boot.efi yet && bootArgs2->efiMode == archMode && bootArgs2->kaddr == 0 && bootArgs2->ksize == 0 @@ -2072,7 +2074,7 @@ LOADER_ENTRY::FindBootArgs() DBG_RT( "bootArgs2->kslide = 0x%x\n", bootArgs2->kslide); DBG_RT( "bootArgs2->bootMemStart = 0x%llx\n", bootArgs2->bootMemStart); if (KernelAndKextPatches && KernelAndKextPatches->KPDebug) - gBS->Stall(2000000); + gBS->Stall(5000000); // disable other pointer bootArgs1 = NULL; @@ -2080,6 +2082,7 @@ LOADER_ENTRY::FindBootArgs() } // check bootargs for 10.4 - 10.6.x + /* bootArgs1 = (BootArgs1*)ptr; if (bootArgs1->Version==1 @@ -2101,8 +2104,43 @@ LOADER_ENTRY::FindBootArgs() bootArgs2 = NULL; break; } - +*/ ptr += 0x1000; + if ((UINTN)ptr > 0x10000000ull) { + DBG_RT("bootArgs not found\n"); + bootArgs2 = 0; + break; + } + } + if (bootArgs2 == 0) { + ptr = (UINT8*)0x200000ull; + while(TRUE) { + + // check bootargs for 10.16 + bootArgs2 = (BootArgs2*)ptr; + if (strstr(&bootArgs2->CommandLine[0], "big=sur") + && bootArgs2->efiMode == archMode) { + dtRoot = (CHAR8*)(UINTN)bootArgs2->deviceTreeP; + dtLength = &bootArgs2->deviceTreeLength; + KernelSlide = bootArgs2->kslide; + + DBG_RT( "Found bootArgs at 0x%llX, DevTree at 0x%llX\n", (UINTN)ptr, (UINTN)bootArgs2->deviceTreeP); + DBG_RT( "bootArgs2->CommandLine = %s\n", bootArgs2->CommandLine); + DBG_RT( "bootArgs2->Version = 0x%x\n", bootArgs2->Version); + DBG_RT( "bootArgs2->Revision = 0x%x\n", bootArgs2->Revision); + DBG_RT( "bootArgs2->flags = 0x%hx\n", bootArgs2->flags); + if (KernelAndKextPatches && KernelAndKextPatches->KPDebug) + gBS->Stall(20000000); + break; + } + + ptr += 0x1000; + if ((UINTN)ptr > 0x10000000ull) { + DBG_RT("bootArgs 2 not found\n"); + bootArgs2 = 0; + break; + } + } } } @@ -2250,13 +2288,13 @@ LOADER_ENTRY::KernelAndKextPatcherInit() // KernelRelocBase will normally be 0 // but if OsxAptioFixDrv is used, then it will be > 0 SetKernelRelocBase(); - DBG("KernelRelocBase = %llx\n", KernelRelocBase); + DBG_RT("KernelRelocBase = %llx\n", KernelRelocBase); // Find bootArgs - we need then for proper detection // of kernel Mach-O header FindBootArgs(); if (bootArgs1 == NULL && bootArgs2 == NULL) { - DBG("BootArgs not found - skipping patches!\n"); + DBG_RT("BootArgs not found - skipping patches!\n"); return; } @@ -2267,6 +2305,7 @@ LOADER_ENTRY::KernelAndKextPatcherInit() // for AptioFix booting - it's always at KernelRelocBase + 0x00200000 UINT64 os_version = AsciiOSVersionToUint64(OSVersion); + DBG_RT("os_version=%s\n", OSVersion); if (os_version < AsciiOSVersionToUint64("10.6")) { KernelData = (UINT8*)(UINTN)(KernelSlide + KernelRelocBase + 0x00111000); } else { @@ -2275,7 +2314,7 @@ LOADER_ENTRY::KernelAndKextPatcherInit() // check that it is Mach-O header and detect architecture if(MACH_GET_MAGIC(KernelData) == MH_MAGIC || MACH_GET_MAGIC(KernelData) == MH_CIGAM) { - DBG("Found 32 bit kernel at 0x%llx\n", (UINTN)KernelData); + DBG_RT("Found 32 bit kernel at 0x%llx\n", (UINTN)KernelData); is64BitKernel = FALSE; } else if (MACH_GET_MAGIC(KernelData) == MH_MAGIC_64 || MACH_GET_MAGIC(KernelData) == MH_CIGAM_64) { DBG_RT( "Found 64 bit kernel at 0x%llx\n", (UINTN)KernelData); @@ -2490,6 +2529,7 @@ LOADER_ENTRY::KernelAndKextsPatcherStart() ); if (KextPatchesNeeded && gSettings.KextPatchesAllowed) { + DBG_RT( "\nKext patching INIT\n"); KernelAndKextPatcherInit(); if (KernelData == NULL) goto NoKernelData; DBG_RT( "\nKext patching STARTED\n"); diff --git a/rEFIt_UEFI/Platform/kext_inject.cpp b/rEFIt_UEFI/Platform/kext_inject.cpp index 0dc3db698..331f2aac9 100644 --- a/rEFIt_UEFI/Platform/kext_inject.cpp +++ b/rEFIt_UEFI/Platform/kext_inject.cpp @@ -1000,6 +1000,14 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch() // } // DBG_RT("\n"); // Stall(10000000); + //second attempt brute force for 10.16 + const UINT8 findJmp2[] = {0xEB, 0x05, 0xE8, 0x7D, 0x03}; + const UINT8 patchJmp2[] = {0x90, 0x90, 0xE8, 0x7D, 0x03}; + if (!SearchAndReplace(&KernelData[0], KERNEL_MAX_SIZE, findJmp2, 5, patchJmp2, 1)) { + DBG_RT("load kexts 2 not patched\n"); + } else { + DBG_RT("load kexts 2 patched !!!\n"); + } } else { DBG_RT("load kexts patched\n"); // for (UINTN j=procLocation+0x3b; j patch SIP applied\n"); patchLocation2 += procLocation; @@ -1090,11 +1098,13 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch() KernelData[patchLocation2 + 4] = 0x12; } } else { - patchLocation2 = FindRelative32(KernelData, procLocation, 0x500, taskLocation); + patchLocation2 = FindRelative32(KernelData, procLocation, 0x1000, taskLocation); if (patchLocation2 != 0) { DBG_RT("=> patch2 SIP applied\n"); KernelData[patchLocation2] = 0xEB; KernelData[patchLocation2 + 1] = 0x06; + } else { + DBG_RT("=> patch2 SIP not applied\n"); } } Stall(10000000); @@ -1173,7 +1183,7 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch() } */ if (patchLocation3 == KERNEL_MAX_SIZE) { - DBG_RT("==> can't find KxldUnmap (10.14 - recent macOS), kernel patch aborted.\n"); + DBG_RT("==> can't find KxldUnmap (10.14 - recent macOS)\n"); Stall(3000000); } else { DBG_RT("==> patched KxldUnmap (10.14 - recent macOS)\n"); diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 814393fc0..8cdf91552 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -206,7 +206,8 @@ CONST XStringW OSXInstallerPaths[] = { L"\\Mac OS X Install Data\\boot.efi"_XSW, // 10.7 L"\\OS X Install Data\\boot.efi"_XSW, // 10.8 - 10.11 L"\\macOS Install Data\\boot.efi"_XSW, // 10.12 - 10.12.3 - L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW // 10.12.4+ + L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW, // 10.12.4-10.15 + L"\\macOS Install Data\\Locked Files\\boot.efi"_XSW // 10.16+ }; STATIC CONST UINTN OSXInstallerPathsCount = (sizeof(OSXInstallerPaths) / sizeof(OSXInstallerPaths[0])); @@ -1362,6 +1363,7 @@ VOID ScanLoader(VOID) AddLoaderEntry(L"\\OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.8 - 10.11 AddLoaderEntry(L"\\macOS Install Data\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.12.3 AddLoaderEntry(L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12.4+ + AddLoaderEntry(L"\\macOS Install Data\\Locked Files\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.16+ AddPRSEntry(Volume); // 10.12+ // Netinstall diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 24047a806..1b90e7d82 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -718,7 +718,7 @@ VOID LOADER_ENTRY::StartLoader() } OSVersion = (__typeof__(OSVersion))AllocateCopyPool(AsciiStrLen(InstallerVersion)+1, InstallerVersion); OSVersion[AsciiStrLen(InstallerVersion)] = '\0'; -// DBG("Corrected OSVersion: %s\n", OSVersion); + DBG("Corrected OSVersion: %s\n", OSVersion); } } }