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"
|
|
|
|
|
|
|
|
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-03-25 15:32:56 +01:00
|
|
|
bool Disabled = bool();
|
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
|
|
|
|
bool operator == (const ABSTRACT_PATCH&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const ABSTRACT_PATCH& other) const
|
|
|
|
{
|
|
|
|
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-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. */
|
|
|
|
bool IsPatchEnabledByBuildNumber(const XString8& Build);
|
|
|
|
bool IsPatchEnabled(const MacOsVersion& CurrOS);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
bool operator == (const ABSTRACT_KEXT_OR_KERNEL_PATCH&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const ABSTRACT_KEXT_OR_KERNEL_PATCH& other) const
|
|
|
|
{
|
|
|
|
if ( !ABSTRACT_PATCH::isEqual (other) ) return false;
|
|
|
|
if ( !(ProcedureName == other.ProcedureName ) ) return false;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
XString8 Name = XString8();
|
2021-03-25 15:32:56 +01:00
|
|
|
bool IsPlistPatch = BOOLEAN();
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
virtual XString8 getName() const { return Name; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
|
|
|
bool operator == (const KEXT_PATCH&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const KEXT_PATCH& other) const
|
|
|
|
{
|
|
|
|
if ( !ABSTRACT_KEXT_OR_KERNEL_PATCH::isEqual (other) ) return false;
|
|
|
|
if ( !(IsPlistPatch == other.IsPlistPatch ) ) return false;
|
|
|
|
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 KERNEL_PATCH : public ABSTRACT_KEXT_OR_KERNEL_PATCH
|
|
|
|
{
|
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
virtual XString8 getName() const { return "kernel"_XS8; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
|
|
|
bool operator == (const KERNEL_PATCH&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const KERNEL_PATCH& other) const
|
|
|
|
{
|
|
|
|
if ( !ABSTRACT_KEXT_OR_KERNEL_PATCH::isEqual (other) ) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-25 15:32:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class BOOT_PATCH : public ABSTRACT_PATCH
|
|
|
|
{
|
|
|
|
public:
|
2021-04-11 07:18:52 +02:00
|
|
|
|
|
|
|
virtual XString8 getName() const { return "boot.efi"_XS8; }
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
|
|
|
bool operator == (const BOOT_PATCH&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const BOOT_PATCH& other) const
|
|
|
|
{
|
|
|
|
if ( !ABSTRACT_PATCH::isEqual (other) ) return false;
|
|
|
|
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 KERNEL_AND_KEXT_PATCHES
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool KPDebug = bool();
|
|
|
|
bool KPKernelLapic = bool();
|
|
|
|
bool KPKernelXCPM = bool();
|
|
|
|
bool _KPKernelPm = bool();
|
|
|
|
bool KPPanicNoKextDump = bool();
|
|
|
|
bool _KPAppleIntelCPUPM = bool();
|
|
|
|
bool KPAppleRTC = bool();
|
|
|
|
bool EightApple = bool();
|
|
|
|
bool KPDELLSMBIOS = bool(); // Dell SMBIOS patch
|
|
|
|
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()*/;
|
|
|
|
XObjArray<KEXT_PATCH> KextPatches/* = XObjArray<KEXT_PATCH>()*/;
|
|
|
|
XObjArray<KERNEL_PATCH> KernelPatches/* = XObjArray<KERNEL_PATCH>()*/;
|
|
|
|
XObjArray<BOOT_PATCH> BootPatches/* = XObjArray<BOOT_PATCH>()*/;
|
|
|
|
|
|
|
|
KERNEL_AND_KEXT_PATCHES() : ForceKextsToLoad(), KextPatches(), KernelPatches(), BootPatches() {}
|
|
|
|
|
|
|
|
#if __cplusplus > 201703L
|
|
|
|
bool operator == (const KERNEL_AND_KEXT_PATCHES&) const = default;
|
|
|
|
#endif
|
|
|
|
bool isEqual(const KERNEL_AND_KEXT_PATCHES& other) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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-02-06 18:16:46 +01:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|