2021-02-06 18:16:46 +01:00
|
|
|
/*
|
|
|
|
* KERNEL_AND_KEXT_PATCHES.h
|
|
|
|
*
|
|
|
|
* Created on: 4 Feb 2021
|
|
|
|
* Author: jief
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __KERNEL_AND_KEXT_PATCHES_H__
|
|
|
|
#define __KERNEL_AND_KEXT_PATCHES_H__
|
|
|
|
|
|
|
|
#include "../cpp_foundation/XBuffer.h"
|
|
|
|
#include "../libeg/libeg.h"
|
|
|
|
#include "MacOsVersion.h"
|
2021-04-28 20:30:34 +02:00
|
|
|
#include "../Settings/ConfigPlist/ConfigPlistClass.h"
|
|
|
|
#include "../Platform/SettingsUtils.h"
|
2021-02-06 18:16:46 +01:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
# include <Library/OcConfigurationLib.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-25 15:32:56 +01:00
|
|
|
class ABSTRACT_PATCH
|
2021-02-06 18:16:46 +01:00
|
|
|
{
|
|
|
|
public:
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool Disabled = XBool();
|
2021-04-06 15:39:55 +02:00
|
|
|
XBuffer<UINT8> Find = XBuffer<UINT8> ();
|
|
|
|
XBuffer<UINT8> Replace = XBuffer<UINT8> ();
|
2021-03-25 15:32:56 +01:00
|
|
|
XBuffer<UINT8> MaskFind = XBuffer<UINT8> ();
|
|
|
|
XBuffer<UINT8> MaskReplace = XBuffer<UINT8> ();
|
|
|
|
XBuffer<UINT8> StartPattern = XBuffer<UINT8> ();
|
|
|
|
XBuffer<UINT8> StartMask = XBuffer<UINT8> ();
|
|
|
|
INTN SearchLen = INTN();
|
|
|
|
INTN Count = INTN();
|
|
|
|
INTN Skip = INTN();
|
|
|
|
XString8 MatchOS = XString8();
|
|
|
|
XString8 MatchBuild = XString8();
|
2021-04-11 07:18:52 +02:00
|
|
|
INPUT_ITEM MenuItem = INPUT_ITEM();
|
2021-03-25 15:32:56 +01:00
|
|
|
|
|
|
|
// Computed
|
2021-04-11 07:18:52 +02:00
|
|
|
virtual XString8 getName() const = 0;
|
2021-03-25 15:32:56 +01:00
|
|
|
XString8 Label = XString8(); // TODO : it's a calculated value from comment field.
|
2021-02-06 18:16:46 +01:00
|
|
|
|
2021-04-11 07:18:52 +02:00
|
|
|
virtual ~ABSTRACT_PATCH() {}
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const ABSTRACT_PATCH&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const ABSTRACT_PATCH& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
|
|
|
if ( !(Disabled == other.Disabled ) ) return false;
|
|
|
|
if ( !(Find == other.Find ) ) return false;
|
|
|
|
if ( !(Replace == other.Replace ) ) return false;
|
|
|
|
if ( !(MaskFind == other.MaskFind ) ) return false;
|
|
|
|
if ( !(MaskReplace == other.MaskReplace ) ) return false;
|
|
|
|
if ( !(StartPattern == other.StartPattern ) ) return false;
|
|
|
|
if ( !(StartMask == other.StartMask ) ) return false;
|
|
|
|
if ( !(SearchLen == other.SearchLen ) ) return false;
|
|
|
|
if ( !(Count == other.Count ) ) return false;
|
|
|
|
if ( !(Skip == other.Skip ) ) return false;
|
|
|
|
if ( !(MatchOS == other.MatchOS ) ) return false;
|
|
|
|
if ( !(MatchBuild == other.MatchBuild ) ) return false;
|
|
|
|
if ( MenuItem != other.MenuItem ) return false;
|
|
|
|
if ( !(Label == other.Label ) ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-28 20:30:34 +02:00
|
|
|
void takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_AbstractPatch_Class& other)
|
|
|
|
{
|
|
|
|
Disabled = other.dgetDisabled();
|
|
|
|
Find = other.dgetFind();
|
|
|
|
Replace = other.dgetReplace();
|
|
|
|
MaskFind = other.dgetMaskFind();
|
|
|
|
MaskReplace = other.dgetMaskReplace();
|
|
|
|
StartPattern = other.dgetStartPattern();
|
|
|
|
StartMask = other.dgetStartMask();
|
|
|
|
SearchLen = other.dgetSearchLen();
|
|
|
|
Count = other.dgetCount();
|
|
|
|
Skip = other.dgetSkip();
|
|
|
|
MatchOS = other.dgetMatchOS();
|
|
|
|
MatchBuild = other.dgetMatchBuild();
|
|
|
|
MenuItem.BValue = !other.dgetDisabled();
|
|
|
|
Label = other.dgetLabel();
|
|
|
|
}
|
2021-04-11 07:18:52 +02:00
|
|
|
|
2021-02-06 18:16:46 +01:00
|
|
|
/** Returns a boolean and then enable disable the patch if MachOSEntry have a match for the booted OS. */
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool IsPatchEnabledByBuildNumber(const XString8& Build);
|
|
|
|
XBool IsPatchEnabled(const MacOsVersion& CurrOS);
|
2021-02-06 18:16:46 +01:00
|
|
|
|
2021-04-11 07:18:52 +02:00
|
|
|
|
2021-02-06 18:16:46 +01:00
|
|
|
};
|
|
|
|
|
2021-03-25 15:32:56 +01:00
|
|
|
class ABSTRACT_KEXT_OR_KERNEL_PATCH : public ABSTRACT_PATCH
|
2021-02-06 18:16:46 +01:00
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
using super = ABSTRACT_PATCH;
|
2021-02-06 18:16:46 +01:00
|
|
|
public:
|
2021-03-25 15:32:56 +01:00
|
|
|
XString8 ProcedureName = XString8(); //procedure len will be StartPatternLen
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const ABSTRACT_KEXT_OR_KERNEL_PATCH&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const ABSTRACT_KEXT_OR_KERNEL_PATCH& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
if ( !super::isEqual (other) ) return false;
|
2021-04-11 07:18:52 +02:00
|
|
|
if ( !(ProcedureName == other.ProcedureName ) ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class::ABSTRACT_KEXT_OR_KERNEL_PATCH& other)
|
2021-04-28 20:30:34 +02:00
|
|
|
{
|
|
|
|
super::takeValueFrom(other);
|
|
|
|
ProcedureName = other.dgetProcedureName();
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-25 15:32:56 +01:00
|
|
|
};
|
2021-02-06 18:16:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-25 15:32:56 +01:00
|
|
|
class KEXT_PATCH : public ABSTRACT_KEXT_OR_KERNEL_PATCH
|
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
using super = ABSTRACT_KEXT_OR_KERNEL_PATCH;
|
2021-03-25 15:32:56 +01:00
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
XString8 Name = XString8();
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool IsPlistPatch = XBool();
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
virtual XString8 getName() const { return Name; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const KEXT_PATCH&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const KEXT_PATCH& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
if ( !super::isEqual (other) ) return false;
|
|
|
|
if ( !(Name == other.Name ) ) return false;
|
2021-04-11 07:18:52 +02:00
|
|
|
if ( !(IsPlistPatch == other.IsPlistPatch ) ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-28 20:30:34 +02:00
|
|
|
void takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_KextsToPatch_Class& other)
|
|
|
|
{
|
|
|
|
super::takeValueFrom(other);
|
|
|
|
Name = other.dgetName();
|
|
|
|
IsPlistPatch = other.dgetIsPlistPatch();
|
|
|
|
}
|
2021-03-25 15:32:56 +01:00
|
|
|
};
|
2021-02-06 18:16:46 +01:00
|
|
|
|
2021-03-25 15:32:56 +01:00
|
|
|
class KERNEL_PATCH : public ABSTRACT_KEXT_OR_KERNEL_PATCH
|
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
using super = ABSTRACT_KEXT_OR_KERNEL_PATCH;
|
2021-03-25 15:32:56 +01:00
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
virtual XString8 getName() const { return "kernel"_XS8; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const KERNEL_PATCH&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const KERNEL_PATCH& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
if ( !super::isEqual (other) ) return false;
|
2021-04-11 07:18:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-04-28 20:30:34 +02:00
|
|
|
void takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_KernelToPatch_Class& other)
|
|
|
|
{
|
|
|
|
super::takeValueFrom(other);
|
|
|
|
}
|
2021-03-25 15:32:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class BOOT_PATCH : public ABSTRACT_PATCH
|
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
using super = ABSTRACT_PATCH;
|
2021-03-25 15:32:56 +01:00
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
virtual XString8 getName() const { return "boot.efi"_XS8; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const BOOT_PATCH&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const BOOT_PATCH& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
2021-04-28 20:30:34 +02:00
|
|
|
if ( !super::isEqual (other) ) return false;
|
2021-04-11 07:18:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-04-28 20:30:34 +02:00
|
|
|
void takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_BootPatch_Class& other)
|
|
|
|
{
|
|
|
|
super::takeValueFrom(other);
|
|
|
|
}
|
2021-03-25 15:32:56 +01:00
|
|
|
};
|
2021-02-06 18:16:46 +01:00
|
|
|
|
2021-03-25 15:32:56 +01:00
|
|
|
class KERNEL_AND_KEXT_PATCHES
|
|
|
|
{
|
|
|
|
public:
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool KPDebug = XBool();
|
|
|
|
XBool KPKernelLapic = XBool();
|
|
|
|
XBool KPKernelXCPM = XBool();
|
|
|
|
XBool _KPKernelPm = XBool();
|
|
|
|
XBool KPPanicNoKextDump = XBool();
|
|
|
|
XBool _KPAppleIntelCPUPM = XBool();
|
|
|
|
XBool KPAppleRTC = XBool();
|
2023-08-27 21:14:02 +02:00
|
|
|
XBool BlockSkywalk = XBool();
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool EightApple = XBool();
|
|
|
|
XBool KPDELLSMBIOS = XBool(); // Dell SMBIOS patch
|
2021-03-25 15:32:56 +01:00
|
|
|
UINT32 FakeCPUID = UINT32();
|
|
|
|
XString8 KPATIConnectorsController = XString8();
|
|
|
|
XBuffer<UINT8> KPATIConnectorsData = XBuffer<UINT8>();
|
|
|
|
XBuffer<UINT8> KPATIConnectorsPatch = XBuffer<UINT8>();
|
2021-04-11 07:18:52 +02:00
|
|
|
XStringWArray ForceKextsToLoad/* = XStringWArray()*/;
|
2021-04-28 20:30:34 +02:00
|
|
|
XObjArrayWithTakeValueFromXmlArray<KEXT_PATCH, ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_KextsToPatch_Class> KextPatches/* = XObjArrayWithTakeValueFromXmlArray<KEXT_PATCH>()*/;
|
|
|
|
XObjArrayWithTakeValueFromXmlArray<KERNEL_PATCH, ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_KernelToPatch_Class> KernelPatches/* = XObjArrayWithTakeValueFromXmlArray<KERNEL_PATCH>()*/;
|
|
|
|
XObjArrayWithTakeValueFromXmlArray<BOOT_PATCH, ConfigPlistClass::KernelAndKextPatches_Class::KernelAndKextPatches_BootPatch_Class> BootPatches/* = XObjArrayWithTakeValueFromXmlArray<BOOT_PATCH>()*/;
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
KERNEL_AND_KEXT_PATCHES() : ForceKextsToLoad(), KextPatches(), KernelPatches(), BootPatches() {}
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool operator == (const KERNEL_AND_KEXT_PATCHES&) const = default;
|
2021-04-11 07:18:52 +02:00
|
|
|
#endif
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool isEqual(const KERNEL_AND_KEXT_PATCHES& other) const
|
2021-04-11 07:18:52 +02:00
|
|
|
{
|
|
|
|
if ( !(KPDebug == other.KPDebug ) ) return false;
|
|
|
|
if ( !(KPKernelLapic == other.KPKernelLapic ) ) return false;
|
|
|
|
if ( !(KPKernelXCPM == other.KPKernelXCPM ) ) return false;
|
|
|
|
if ( !(_KPKernelPm == other._KPKernelPm ) ) return false;
|
|
|
|
if ( !(KPPanicNoKextDump == other.KPPanicNoKextDump ) ) return false;
|
|
|
|
if ( !(_KPAppleIntelCPUPM == other._KPAppleIntelCPUPM ) ) return false;
|
|
|
|
if ( !(KPAppleRTC == other.KPAppleRTC ) ) return false;
|
|
|
|
if ( !(EightApple == other.EightApple ) ) return false;
|
2023-08-27 21:14:02 +02:00
|
|
|
if ( !(BlockSkywalk == other.BlockSkywalk ) ) return false;
|
2021-04-11 07:18:52 +02:00
|
|
|
if ( !(KPDELLSMBIOS == other.KPDELLSMBIOS ) ) return false;
|
|
|
|
if ( !(FakeCPUID == other.FakeCPUID ) ) return false;
|
|
|
|
if ( !(KPATIConnectorsController == other.KPATIConnectorsController ) ) return false;
|
|
|
|
if ( !(KPATIConnectorsData == other.KPATIConnectorsData ) ) return false;
|
|
|
|
if ( !(KPATIConnectorsPatch == other.KPATIConnectorsPatch ) ) return false;
|
|
|
|
if ( !(ForceKextsToLoad == other.ForceKextsToLoad ) ) return false;
|
|
|
|
if ( !KextPatches.isEqual(other.KextPatches) ) return false;
|
|
|
|
if ( !KernelPatches.isEqual(other.KernelPatches) ) return false;
|
|
|
|
if ( !BootPatches.isEqual(other.BootPatches) ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-28 20:30:34 +02:00
|
|
|
void takeValueFrom(const ConfigPlistClass::KernelAndKextPatches_Class& other)
|
|
|
|
{
|
|
|
|
KPDebug = other.dgetKPDebug();
|
|
|
|
KPKernelLapic = other.dgetKPKernelLapic();
|
|
|
|
KPKernelXCPM = other.dgetKPKernelXCPM();
|
|
|
|
_KPKernelPm = other.dget_KPKernelPm();
|
|
|
|
KPPanicNoKextDump = other.dgetKPPanicNoKextDump();
|
|
|
|
_KPAppleIntelCPUPM = other.dget_KPAppleIntelCPUPM();
|
|
|
|
KPAppleRTC = other.dgetKPAppleRTC();
|
2023-08-27 21:14:02 +02:00
|
|
|
BlockSkywalk = other.dgetBlockSkywalk();
|
2021-04-28 20:30:34 +02:00
|
|
|
EightApple = other.dgetEightApple();
|
|
|
|
KPDELLSMBIOS = other.dgetKPDELLSMBIOS();
|
|
|
|
FakeCPUID = other.dgetFakeCPUID();
|
|
|
|
KPATIConnectorsController = other.dgetKPATIConnectorsController();
|
|
|
|
KPATIConnectorsData = other.dgetKPATIConnectorsData();
|
|
|
|
KPATIConnectorsPatch = other.dgetKPATIConnectorsPatch();
|
|
|
|
ForceKextsToLoad = other.dgetForceKextsToLoad();
|
|
|
|
KextPatches.takeValueFrom(other.KextsToPatch);
|
|
|
|
KernelPatches.takeValueFrom(other.KernelToPatch);
|
|
|
|
BootPatches.takeValueFrom(other.BootPatches);
|
|
|
|
}
|
2021-02-06 18:16:46 +01:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|