correct root pointer

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-03-08 19:48:52 +03:00
parent ede47c040b
commit 5f9f7072a3
4 changed files with 41 additions and 52 deletions

View File

@ -136,7 +136,7 @@ XBool LOADER_ENTRY::checkOSBundleRequired(const TagDict* dict)
//extern void AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N, LOADER_ENTRY *Entry); //extern void AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N, LOADER_ENTRY *Entry);
//XStringW infoPlistPath = getKextPlist(&self.getCloverDir(), dir, KextEntry, &NoContents); //XStringW infoPlistPath = getKextPlist(&self.getCloverDir(), dir, KextEntry, &NoContents);
XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents) XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE* Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents)
{ {
XStringW TempName; XStringW TempName;
XStringW FullName; XStringW FullName;
@ -150,10 +150,10 @@ XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE& Root, const XStringW& dirPat
#ifndef LESS_DEBUG #ifndef LESS_DEBUG
MsgLog("info plist path: %ls\n", TempName.wc_str()); MsgLog("info plist path: %ls\n", TempName.wc_str());
#endif #endif
if (!FileExists(&Root, TempName)) { if (!FileExists(Root, TempName)) {
//try to find a planar kext, without Contents //try to find a planar kext, without Contents
TempName = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Info.plist"); TempName = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Info.plist");
if (!FileExists(&Root, TempName)) { if (!FileExists(Root, TempName)) {
MsgLog("Failed to load extra kext : %ls \n", TempName.wc_str()); MsgLog("Failed to load extra kext : %ls \n", TempName.wc_str());
return L""_XSW; return L""_XSW;
} }
@ -164,15 +164,15 @@ XStringW LOADER_ENTRY::getKextPlist(const EFI_FILE& Root, const XStringW& dirPat
return TempName; return TempName;
} }
//TagDict* dict = getInfoPlist(infoPlistPath); //TagDict* dict = getInfoPlist(Root, infoPlistPath);
TagDict* LOADER_ENTRY::getInfoPlist(const EFI_FILE& Root, const XStringW& infoPlistPath) TagDict* LOADER_ENTRY::getInfoPlist(const EFI_FILE* Root, const XStringW& infoPlistPath)
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT8* infoDictBuffer = NULL; UINT8* infoDictBuffer = NULL;
UINTN infoDictBufferLength = 0; UINTN infoDictBufferLength = 0;
TagDict* dict = NULL; TagDict* dict = NULL;
Status = egLoadFile(&Root, infoPlistPath.wc_str(), &infoDictBuffer, &infoDictBufferLength); Status = egLoadFile(Root, infoPlistPath.wc_str(), &infoDictBuffer, &infoDictBufferLength);
if (!EFI_ERROR(Status)) { //double check if (!EFI_ERROR(Status)) { //double check
if( ParseXML((CHAR8*)infoDictBuffer, &dict, infoDictBufferLength)!=0 ) { if( ParseXML((CHAR8*)infoDictBuffer, &dict, infoDictBufferLength)!=0 ) {
MsgLog("Failed to parse Info.plist: %ls\n", infoPlistPath.wc_str()); MsgLog("Failed to parse Info.plist: %ls\n", infoPlistPath.wc_str());
@ -185,7 +185,7 @@ TagDict* LOADER_ENTRY::getInfoPlist(const EFI_FILE& Root, const XStringW& infoPl
} }
//XString8 execpath = getKextExecPath(dir, KextEntry.FileName, dict, NoContents); //XString8 execpath = getKextExecPath(dir, KextEntry.FileName, dict, NoContents);
XString8 LOADER_ENTRY::getKextExecPath(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents) XString8 LOADER_ENTRY::getKextExecPath(const EFI_FILE* Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents)
{ {
const TagStruct* prop = NULL; const TagStruct* prop = NULL;
XString8 TempName; XString8 TempName;
@ -199,7 +199,7 @@ XString8 LOADER_ENTRY::getKextExecPath(const EFI_FILE& Root, const XStringW& di
TempName = S8Printf("Contents\\MacOS\\%s", Executable.c_str()); TempName = S8Printf("Contents\\MacOS\\%s", Executable.c_str());
} }
const XStringW& fullPath = SWPrintf("%ls\\%ls\\%s", dirPath.wc_str(), FileName.wc_str(), TempName.c_str()); const XStringW& fullPath = SWPrintf("%ls\\%ls\\%s", dirPath.wc_str(), FileName.wc_str(), TempName.c_str());
if (!FileExists(&Root, fullPath)) { if (!FileExists(Root, fullPath)) {
MsgLog("Failed to load kext executable: %ls\n", FileName.wc_str()); MsgLog("Failed to load kext executable: %ls\n", FileName.wc_str());
return ""_XS8; //no executable return ""_XS8; //no executable
} }

View File

@ -489,9 +489,9 @@ class REFIT_ABSTRACT_MENU_ENTRY
void DelegateKernelPatches(); void DelegateKernelPatches();
XBool checkOSBundleRequired(const TagDict* dict); XBool checkOSBundleRequired(const TagDict* dict);
XStringW getKextPlist(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents); XStringW getKextPlist(const EFI_FILE* Root, const XStringW& dirPath, const XStringW& FileName, XBool* NoContents);
TagDict* getInfoPlist(const EFI_FILE& Root, const XStringW& infoPlistPath); TagDict* getInfoPlist(const EFI_FILE* Root, const XStringW& infoPlistPath);
XString8 getKextExecPath(const EFI_FILE& Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents); XString8 getKextExecPath(const EFI_FILE* Root, const XStringW& dirPath, const XStringW& FileName, TagDict* dict, XBool NoContents);
} ; } ;

View File

@ -983,7 +983,7 @@ void ScanVolumes(void)
return; return;
DBG("Found %llu volumes with blockIO\n", HandleCount); DBG("Found %llu volumes with blockIO\n", HandleCount);
// first pass: collect information about all handles // first pass: collect information about all handles
for (UINT32 HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { for (UINTN HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
REFIT_VOLUME* Volume = new REFIT_VOLUME; REFIT_VOLUME* Volume = new REFIT_VOLUME;
Volume->LegacyOS = new LEGACY_OS; Volume->LegacyOS = new LEGACY_OS;

View File

@ -817,20 +817,6 @@ void LOADER_ENTRY::StartLoader()
if ( OSTYPE_IS_OSX(LoaderType) || OSTYPE_IS_OSX_RECOVERY(LoaderType) || OSTYPE_IS_OSX_INSTALLER(LoaderType) ) { if ( OSTYPE_IS_OSX(LoaderType) || OSTYPE_IS_OSX_RECOVERY(LoaderType) || OSTYPE_IS_OSX_INSTALLER(LoaderType) ) {
// These 2 drivers are now filtered and won't load. This check is currentmy useless.
// {
// EFI_HANDLE Interface = NULL;
// Status = gBS->LocateProtocol(&gAptioMemoryFixProtocolGuid, NULL, &Interface );
// if ( !EFI_ERROR(Status) ) {
//#ifdef JIEF_DEBUG
// panic("Remove AptioMemoryFix.efi and OcQuirks.efi from your driver folder\n");
//#else
// DBG("Remove AptioMemoryFix.efi and OcQuirks.efi from your driver folder\n");
//#endif
// }
// }
// if OC is NOT initialized with OcMain, we need the following // if OC is NOT initialized with OcMain, we need the following
// OcConfigureLogProtocol ( // OcConfigureLogProtocol (
// 9, // 9,
@ -1042,8 +1028,6 @@ void LOADER_ENTRY::StartLoader()
AddKextsInArray(&kextArray); AddKextsInArray(&kextArray);
} }
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelArch, "x86_64"); OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelArch, "x86_64");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelCache, gSettings.Quirks.OcKernelCache.c_str()); OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelCache, gSettings.Quirks.OcKernelCache.c_str());
mOpenCoreConfiguration.Kernel.Scheme.FuzzyMatch = gSettings.Quirks.FuzzyMatch; mOpenCoreConfiguration.Kernel.Scheme.FuzzyMatch = gSettings.Quirks.FuzzyMatch;
@ -1080,8 +1064,8 @@ void LOADER_ENTRY::StartLoader()
size_t pos = setKextAtPos(&kextArray, "Lilu.kext"_XS8, 0); size_t pos = setKextAtPos(&kextArray, "Lilu.kext"_XS8, 0);
pos = setKextAtPos(&kextArray, "VirtualSMC.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "VirtualSMC.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "FakeSMC.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "FakeSMC.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "vecLib.kext"_XS8, pos); // pos = setKextAtPos(&kextArray, "vecLib.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "IOAudioFamily.kext"_XS8, pos); // pos = setKextAtPos(&kextArray, "IOAudioFamily.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "FakePCIID.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "FakePCIID.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "FakePCIID_XHCIMux.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "FakePCIID_XHCIMux.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "AMDRyzenCPUPowerManagement.kext"_XS8, pos); pos = setKextAtPos(&kextArray, "AMDRyzenCPUPowerManagement.kext"_XS8, pos);
@ -1129,8 +1113,8 @@ void LOADER_ENTRY::StartLoader()
#if 1 #if 1
//CFBundleExecutable //CFBundleExecutable
XBool NoContents = false; XBool NoContents = false;
XStringW infoPlistPath = getKextPlist(self.getCloverDir(), dirPath, KextEntry.FileName, &NoContents); //it will be fullPath, including dir XStringW infoPlistPath = getKextPlist(&self.getCloverDir(), dirPath, KextEntry.FileName, &NoContents); //it will be fullPath, including dir
TagDict* dict = getInfoPlist(self.getCloverDir(), infoPlistPath); TagDict* dict = getInfoPlist(&self.getCloverDir(), infoPlistPath);
// XBool inject = checkOSBundleRequired(dict); // XBool inject = checkOSBundleRequired(dict);
XBool inject = true; XBool inject = true;
if (inject) { if (inject) {
@ -1143,7 +1127,7 @@ void LOADER_ENTRY::StartLoader()
}else{ }else{
DBG("Cannot find kext info.plist at '%ls'\n", KextEntry.FileName.wc_str()); DBG("Cannot find kext info.plist at '%ls'\n", KextEntry.FileName.wc_str());
} }
XString8 execpath = getKextExecPath(self.getCloverDir(), dirPath, KextEntry.FileName, dict, NoContents); XString8 execpath = getKextExecPath(&self.getCloverDir(), dirPath, KextEntry.FileName, dict, NoContents);
if (execpath.notEmpty()) { if (execpath.notEmpty()) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, execpath.c_str()); OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, execpath.c_str());
DBG("assign executable as '%s'\n", execpath.c_str()); DBG("assign executable as '%s'\n", execpath.c_str());
@ -1170,20 +1154,20 @@ void LOADER_ENTRY::StartLoader()
} }
//DelegateKernelPatches();
//Force kexts is not ready
/*
mOpenCoreConfiguration.Kernel.Force.Count = (UINT32)KernelAndKextPatches.ForceKextsToLoad.size(); mOpenCoreConfiguration.Kernel.Force.Count = (UINT32)KernelAndKextPatches.ForceKextsToLoad.size();
mOpenCoreConfiguration.Kernel.Force.AllocCount = mOpenCoreConfiguration.Kernel.Force.Count; mOpenCoreConfiguration.Kernel.Force.AllocCount = mOpenCoreConfiguration.Kernel.Force.Count;
mOpenCoreConfiguration.Kernel.Force.ValueSize = sizeof(__typeof_am__(**mOpenCoreConfiguration.Kernel.Force.Values)); // sizeof(OC_KERNEL_FORCE_ENTRY) mOpenCoreConfiguration.Kernel.Force.ValueSize = sizeof(__typeof_am__(**mOpenCoreConfiguration.Kernel.Force.Values)); // sizeof(OC_KERNEL_FORCE_ENTRY)
mOpenCoreConfiguration.Kernel.Force.Values = (OC_KERNEL_ADD_ENTRY**)malloc(mOpenCoreConfiguration.Kernel.Force.AllocCount*sizeof(*mOpenCoreConfiguration.Kernel.Force.Values)); // sizeof(OC_KERNEL_FORCE_ENTRY*) == sizeof(ptr) int valuesSize = mOpenCoreConfiguration.Kernel.Force.AllocCount*sizeof(*mOpenCoreConfiguration.Kernel.Force.Values);
memset(mOpenCoreConfiguration.Kernel.Force.Values, 0, mOpenCoreConfiguration.Kernel.Force.AllocCount*sizeof(*mOpenCoreConfiguration.Kernel.Force.Values)); mOpenCoreConfiguration.Kernel.Force.Values = (OC_KERNEL_ADD_ENTRY**)malloc(valuesSize); // sizeof(OC_KERNEL_FORCE_ENTRY*) == sizeof(ptr)
memset(mOpenCoreConfiguration.Kernel.Force.Values, 0, valuesSize);
const XStringW& empty = ""_XSW; const XStringW empty;
// empty.setEmpty();
for (size_t kextIdx = 0 ; kextIdx < KernelAndKextPatches.ForceKextsToLoad.size() ; kextIdx++ ) for (size_t kextIdx = 0 ; kextIdx < KernelAndKextPatches.ForceKextsToLoad.size() ; kextIdx++ )
{ {
const XStringW& forceKext = KernelAndKextPatches.ForceKextsToLoad[kextIdx]; const XStringW& forceKext = KernelAndKextPatches.ForceKextsToLoad[kextIdx];
//("TODO !!!!!!!! Bridge force kext to OC : %ls\n", forceKext.wc_str());
DBG("Bridge force kext to OC : Path=%ls\n", forceKext.wc_str()); DBG("Bridge force kext to OC : Path=%ls\n", forceKext.wc_str());
mOpenCoreConfiguration.Kernel.Force.Values[kextIdx] = (__typeof_am__(*mOpenCoreConfiguration.Kernel.Force.Values))malloc(mOpenCoreConfiguration.Kernel.Force.ValueSize); mOpenCoreConfiguration.Kernel.Force.Values[kextIdx] = (__typeof_am__(*mOpenCoreConfiguration.Kernel.Force.Values))malloc(mOpenCoreConfiguration.Kernel.Force.ValueSize);
memset(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx], 0, mOpenCoreConfiguration.Kernel.Force.ValueSize); memset(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx], 0, mOpenCoreConfiguration.Kernel.Force.ValueSize);
@ -1199,32 +1183,37 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistData = NULL; mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistData = NULL;
mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistDataSize = 0; mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->PlistDataSize = 0;
XBool NoContents = false;
REFIT_VOLUME * SystemVolume = Volume;
if (Volume->ApfsRole == APPLE_APFS_VOLUME_ROLE_PREBOOT) {
DBG("boot from Preboot, index=%llu\n", Volume->Index);
SystemVolume = &Volumes[Volume->Index+1];
DBG("next volume has role=%d\n", SystemVolume->ApfsRole);
}
XStringW infoPlistPath = getKextPlist(Volume->RootDir, dirPath, forceKext, &NoContents); //it will be fullPath, including dir XStringW infoPlistPath = getKextPlist(SystemVolume->RootDir, empty, forceKext, &NoContents); //it will be fullPath, including dir
// XString8 execpath = getKextExecPath(Volume->RootDir, dirPath, forceKext, dict, NoContents); TagDict* dictInfo = getInfoPlist(SystemVolume->RootDir, infoPlistPath);
if (dictInfo) {
DBG("Info.plist at %ls\n", infoPlistPath.wc_str());
}
XString8 execpath = getKextExecPath(SystemVolume->RootDir, empty, forceKext, dictInfo, NoContents);
// for kext IOAudioFamily BundlePath = System\Library\Extensions\IOAudioFamily.kext // for kext IOAudioFamily BundlePath = System\Library\Extensions\IOAudioFamily.kext
// ExecutablePath = Contents/MacOS/IOAudioFamily // ExecutablePath = Contents/MacOS/IOAudioFamily
// XStringW plist = SWPrintf("%s\\System\\Library\\CoreServices\\SystemVersion.plist", uuidPrefix.c_str());
// if ( !FileExists(Volume->RootDir, plist) ) {
// plist = SWPrintf("%s\\System\\Library\\CoreServices\\ServerVersion.plist", uuidPrefix.c_str());
// if ( !FileExists(Volume->RootDir, plist) ) {
// plist.setEmpty();
// }
// }
if ( FileExists(Volume->RootDir, forceKext.wc_str()) ) { if ( FileExists(Volume->RootDir, forceKext.wc_str()) ) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, S8Printf("%ls",forceKext.wc_str()).c_str()); OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->BundlePath, S8Printf("%ls",forceKext.wc_str()).c_str());
}else{ }else{
DBG("Cannot find kext bundlePath at '%s'\n", S8Printf("%ls",forceKext.wc_str()).c_str()); DBG("Cannot find kext bundlePath at '%s'\n", S8Printf("%ls",forceKext.wc_str()).c_str());
} }
//then we have to find executablePath and plistPath //then we have to find executablePath and plistPath
if (forceKext.notEmpty()) { if (forceKext.notEmpty()) {
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath, executablePath.c_str()); OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath, execpath.c_str());
DBG("assign executable as '%s'\n", mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath.Value); DBG("assign executable as '%s'\n", mOpenCoreConfiguration.Kernel.Force.Values[kextIdx]->ExecutablePath.Value);
} }
} }
*/
#endif #endif
mOpenCoreConfiguration.Uefi.Output.ProvideConsoleGop = gSettings.GUI.ProvideConsoleGop; mOpenCoreConfiguration.Uefi.Output.ProvideConsoleGop = gSettings.GUI.ProvideConsoleGop;