Refactoring KEXT_PATCH.

Change numerous CHAR8* CHAR16* to XString.
This commit is contained in:
jief666 2020-08-12 18:15:47 +03:00
parent ee80193158
commit 59d8cbad7f
44 changed files with 1573 additions and 1425 deletions

View File

@ -1553,7 +1553,7 @@ VOID SaveOemDsdt(BOOLEAN FullPatch)
CopyMem((VOID*)(UINTN)dsdt, buffer, DsdtLen);
buffer = (UINT8*)(UINTN)dsdt;
if (FullPatch) {
FixBiosDsdt(buffer, FadtPointer, NULL);
FixBiosDsdt(buffer, FadtPointer, NullXString8);
DsdtLen = ((EFI_ACPI_DESCRIPTION_HEADER*)buffer)->Length;
OriginDsdt = OriginDsdtFixed;
}
@ -1672,7 +1672,7 @@ void LoadAllPatchedAML(CONST CHAR16* AcpiOemPath, UINTN Pass)
}
}
EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, CHAR8 *OSVersion)
EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
{
EFI_STATUS Status = EFI_SUCCESS;
UINTN Index;

View File

@ -44,7 +44,7 @@ extern UINT64 machineSignature;
//ACPI
EFI_STATUS
PatchACPI(IN REFIT_VOLUME *Volume, CHAR8 *OSVersion);
PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion);
EFI_STATUS
PatchACPI_OtherOS(CONST CHAR16* OsSubdir, BOOLEAN DropSSDT);

View File

@ -395,7 +395,7 @@ SetVariablesForOSX(LOADER_ENTRY *Entry)
// Sherlocks: to fix "OSInstall.mpkg appears to be missing or damaged" in 10.13+, we should remove this variables.
if (Entry->LoaderType == OSTYPE_OSX_INSTALLER) {
if (os_version > AsciiOSVersionToUint64("10.12")) {
if (os_version > AsciiOSVersionToUint64("10.12"_XS8)) {
DeleteNvramVariable(L"install-product-url", &gEfiAppleBootGuid);
DeleteNvramVariable(L"previous-system-uuid", &gEfiAppleBootGuid);
}

View File

@ -3712,7 +3712,7 @@ UINT32 FIXFirewire (UINT8 *dsdt, UINT32 len)
return len;
}
UINT32 AddHDEF (UINT8 *dsdt, UINT32 len, CHAR8* OSVersion)
UINT32 AddHDEF (UINT8 *dsdt, UINT32 len, const XString8& OSVersion)
{
UINT32 i, k;
UINT32 PCIADR, PCISIZE = 0;
@ -5300,7 +5300,7 @@ VOID RenameDevices(UINT8* table)
MsgLog(" %lld replacements\n", Num);
}
VOID FixBiosDsdt(UINT8* temp, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE* fadt, CHAR8 *OSVersion)
VOID FixBiosDsdt(UINT8* temp, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE* fadt, const XString8& OSVersion)
{
UINT32 DsdtLen;

View File

@ -60,7 +60,7 @@ VOID
FixBiosDsdt (
UINT8 *Dsdt,
EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *fadt,
CHAR8 *OSVersion
const XString8& OSVersion
);

View File

@ -22,7 +22,7 @@
// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
// originally from OpensslLib
#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
//#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
//#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))

View File

@ -45,6 +45,13 @@ inline char* strncpy(char * dst, const char * src, size_t len)
return dst;
}
extern void* memset(void *b, int c, size_t len); // memset is defined in cpp_util/memory.cpp because it is required by c++
//inline void* memset(void *b, int c, size_t len)
//{
// SetMem(b, len, c);
// return b;
//}
//inline char* strncat(char *restrict s1, const char *restrict s2, size_t n)
//{
// return AsciiStrCatS(s1, AsciiStrLen(strDest)+1,strSource)

File diff suppressed because it is too large Load Diff

View File

@ -216,7 +216,7 @@ public:
// SMBIOS TYPE0
CHAR8 VendorName[64];
CHAR8 RomVersion[64];
CHAR8 EfiVersion[64];
XString8 EfiVersion;
CHAR8 ReleaseDate[64];
// SMBIOS TYPE1
CHAR8 ManufactureName[64];
@ -839,8 +839,8 @@ VOID
SetBootCurrent(REFIT_MENU_ITEM_BOOTNUM *LoadedEntry);
CHAR8
*GetOSVersion (
XString8
GetOSVersion (
IN LOADER_ENTRY *Entry
);
@ -865,7 +865,7 @@ GetDevices(VOID);
CONST XStringW
GetOSIconName (
IN CONST CHAR8 *OSVersion
const XString8& OSVersion
);
EFI_STATUS
@ -917,12 +917,12 @@ SaveSettings (VOID);
/** Returns a boolean and then enable disable the patch if MachOSEntry have a match for the booted OS. */
BOOLEAN IsPatchEnabled(CHAR8 *MatchOSEntry, CHAR8 *CurrOS);
BOOLEAN IsPatchEnabled(const XString8& MatchOSEntry, const XString8& CurrOS);
/** return true if a given os contains '.' as separator,
and then match components of the current booted OS. Also allow 10.10.x format meaning all revisions
of the 10.10 OS */
BOOLEAN IsOSValid(CHAR8 *MatchOS, CHAR8 *CurrOS);
BOOLEAN IsOSValid(const CHAR8 *MatchOS, const CHAR8 *CurrOS);
// Micky1979: Next five functions (+ needed struct) are to split a string like "10.10.5,10.7,10.11.6,10.8.x"
// in their components separated by comma (in this case)
@ -934,7 +934,7 @@ struct MatchOSes {
/** return MatchOSes struct (count+array) with the components of str that contains the given char sep as separator. */
struct
MatchOSes *GetStrArraySeparatedByChar(CHAR8 *str, CHAR8 sep);
MatchOSes *GetStrArraySeparatedByChar(const CHAR8 *str, CHAR8 sep);
/** trim spaces in MatchOSes struct array */
VOID
@ -945,7 +945,7 @@ VOID deallocMatchOSes(struct MatchOSes *s);
/** count occurrences of a given char in a char* string. */
INTN
countOccurrences(CHAR8 *s, CHAR8 c);
countOccurrences(const CHAR8 *s, CHAR8 c);
//get default boot
@ -965,9 +965,9 @@ ParseSMBIOSSettings (
TagPtr dictPointer
);
BOOLEAN
CopyKernelAndKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Dst,
IN CONST KERNEL_AND_KEXT_PATCHES *Src);
//BOOLEAN
//CopyKernelAndKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Dst,
// IN CONST KERNEL_AND_KEXT_PATCHES *Src);
#endif

View File

@ -5,7 +5,7 @@
#include "Platform.h"
CHAR8 NonDetected[] = "10.10.10"; //longer string
XString8 NonDetected = "10.10.10"_XS8; //longer string
/**
Convert a Null-terminated ASCII string representing version number (separate by dots)
@ -23,34 +23,36 @@ CHAR8 NonDetected[] = "10.10.10"; //longer string
**/
UINT64 AsciiStrVersionToUint64(const CHAR8 *Version, UINT8 MaxDigitByPart, UINT8 MaxParts)
UINT64 AsciiStrVersionToUint64(const XString8& Version_, UINT8 MaxDigitByPart, UINT8 MaxParts)
{
UINT64 result = 0;
UINT16 part_value = 0;
UINT16 part_mult = 1;
UINT16 max_part_value;
if (!Version) {
Version = NonDetected; //pointer to non-NULL string
const XString8* VersionPtr = &Version_;
if (VersionPtr->isEmpty()) {
VersionPtr = &NonDetected; //pointer to non-NULL string
}
const XString8& Version = *VersionPtr;
while (MaxDigitByPart--) {
part_mult = part_mult * 10;
}
max_part_value = part_mult - 1;
while (*Version && MaxParts > 0) { //Slice - NULL pointer dereferencing
if (*Version >= '0' && *Version <= '9') {
part_value = part_value * 10 + (*Version - '0');
size_t idx = 0;
while (idx < Version.length() && MaxParts > 0) { //Slice - NULL pointer dereferencing
if (Version[idx] >= '0' && Version[idx] <= '9') {
part_value = part_value * 10 + (Version[idx] - '0');
if (part_value > max_part_value)
part_value = max_part_value;
}
else if (*Version == '.') {
else if (Version[idx] == '.') {
result = MultU64x64(result, part_mult) + part_value;
part_value = 0;
MaxParts--;
}
Version++;
idx++;
}
while (MaxParts--) {

View File

@ -2,7 +2,7 @@
#define __REFIT_STRING_H__
extern CHAR8 NonDetected[]; //longer string
extern XString8 NonDetected;
/**
Convert a Null-terminated ASCII string representing version number (separate by dots)
@ -19,7 +19,7 @@ extern CHAR8 NonDetected[]; //longer string
@return Result
**/
UINT64 AsciiStrVersionToUint64(const CHAR8 *Version, UINT8 MaxDigitByPart, UINT8 MaxParts);
UINT64 AsciiStrVersionToUint64(const XString8& Version, UINT8 MaxDigitByPart, UINT8 MaxParts);
/* Macro to use the AsciiStrVersionToUint64 for OSX Version strings */

View File

@ -1392,10 +1392,10 @@ BOOLEAN get_conntype_val(value_t *val, INTN index, BOOLEAN Sier)
//0x400: DisplayPort
//0x02: LVDS
if ((CurrentPatches == NULL) || (CurrentPatches->KPATIConnectorsDataLen == 0)) {
if ((CurrentPatches == NULL) || (CurrentPatches->KPATIConnectorsData.isEmpty())) {
return FALSE;
}
ct = CurrentPatches->KPATIConnectorsPatch;
ct = CurrentPatches->KPATIConnectorsPatch.data();
Len = Sier?24:16;
/* if (gMobile) {
@ -1546,13 +1546,13 @@ VOID free_val(value_t *val )
value_t default_val;
} AtiDevProp;
*/
VOID devprop_add_list(AtiDevProp devprop_list[], CHAR8 *OSVersion)
VOID devprop_add_list(AtiDevProp devprop_list[], const XString8& OSVersion)
{
INTN i, pnum;
BOOLEAN Sier;
value_t *val = (__typeof__(val))BllocateZeroPool(sizeof(value_t));
Sier = (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.12"));
Sier = (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.12"_XS8));
for (i = 0; devprop_list[i].name != NULL; i++) {
if ((devprop_list[i].flags & card->flags) != 0) {

View File

@ -2592,7 +2592,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
// if wakes up with an HDMI connected, somtimes this value causes force reboot in 10.14+
if (os_version < AsciiOSVersionToUint64("10.14")) {
if (os_version < AsciiOSVersionToUint64("10.14"_XS8)) {
devprop_add_value(device, "AAPL,GfxYTile", skylake_hd_vals[1], 4);
}
break;
@ -2644,7 +2644,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
switch (gma_dev->device_id) {
case 0x5902:
case 0x5906:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19028086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2671,7 +2671,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x5912:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19128086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2699,7 +2699,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
break;
case 0x5916:
case 0x5917:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19168086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2728,7 +2728,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
case 0x591A:
case 0x591B:
case 0x591D:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x191B8086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2756,7 +2756,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
break;
case 0x591C:
case 0x591E:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x191E8086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2783,7 +2783,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x5923:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19168086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2810,7 +2810,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x5926:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19268086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2837,7 +2837,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x5927:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x19278086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2865,7 +2865,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
break;
case 0x87C0:
case 0x87CA:
if (os_version < AsciiOSVersionToUint64("10.12.6")) {
if (os_version < AsciiOSVersionToUint64("10.12.6"_XS8)) {
if (!SetFake) {
FakeID = 0x191E8086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2877,7 +2877,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
devprop_add_value(device, "AAPL,ig-platform-id", skylake_ig_vals[8], 4);
DBG(" Found ig-platform-id = 0x191E0000\n");
}
} else if (os_version < AsciiOSVersionToUint64("10.14")) {
} else if (os_version < AsciiOSVersionToUint64("10.14"_XS8)) {
if (!SetFake) {
FakeID = 0x591E8086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -2948,7 +2948,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
// if wakes up with an HDMI connected, somtimes this value causes force reboot in 10.14+
if (os_version < AsciiOSVersionToUint64("10.14")) {
if (os_version < AsciiOSVersionToUint64("10.14"_XS8)) {
devprop_add_value(device, "AAPL,GfxYTile", kabylake_hd_vals[1], 4);
}
break;
@ -3007,8 +3007,8 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
switch (gma_dev->device_id) {
case 0x3E90:
case 0x3E93:
if ((os_version >= AsciiOSVersionToUint64("10.14")) || ((os_version == AsciiOSVersionToUint64("10.13.6")) &&
(AsciiStrStr(Entry->BuildVersion, "17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if ((os_version >= AsciiOSVersionToUint64("10.14"_XS8)) || ((os_version == AsciiOSVersionToUint64("10.13.6"_XS8)) &&
(Entry->BuildVersion.contains("17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if (!SetFake) {
FakeID = 0x3E908086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -3035,8 +3035,8 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x3E91:
if ((os_version >= AsciiOSVersionToUint64("10.14")) || ((os_version == AsciiOSVersionToUint64("10.13.6")) &&
(AsciiStrStr(Entry->BuildVersion, "17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if ((os_version >= AsciiOSVersionToUint64("10.14"_XS8)) || ((os_version == AsciiOSVersionToUint64("10.13.6"_XS8)) &&
(Entry->BuildVersion.contains("17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if (!SetFake) {
FakeID = 0x3E918086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -3064,8 +3064,8 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
break;
case 0x3E92:
case 0x3E98:
if ((os_version >= AsciiOSVersionToUint64("10.14")) || ((os_version == AsciiOSVersionToUint64("10.13.6")) &&
(AsciiStrStr(Entry->BuildVersion, "17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if ((os_version >= AsciiOSVersionToUint64("10.14"_XS8)) || ((os_version == AsciiOSVersionToUint64("10.13.6"_XS8)) &&
(Entry->BuildVersion.contains("17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if (!SetFake) {
FakeID = 0x3E928086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -3095,8 +3095,8 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
case 0x3EA0:
case 0x9B41:
case 0x9BCA:
if ((os_version >= AsciiOSVersionToUint64("10.14")) || ((os_version == AsciiOSVersionToUint64("10.13.6")) &&
(AsciiStrStr(Entry->BuildVersion, "17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if ((os_version >= AsciiOSVersionToUint64("10.14"_XS8)) || ((os_version == AsciiOSVersionToUint64("10.13.6"_XS8)) &&
(Entry->BuildVersion.contains("17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if (!SetFake) {
FakeID = 0x3E9B8086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -3123,8 +3123,8 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
break;
case 0x3EA5:
if ((os_version >= AsciiOSVersionToUint64("10.14")) || ((os_version == AsciiOSVersionToUint64("10.13.6")) &&
(AsciiStrStr(Entry->BuildVersion, "17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if ((os_version >= AsciiOSVersionToUint64("10.14"_XS8)) || ((os_version == AsciiOSVersionToUint64("10.13.6"_XS8)) &&
(Entry->BuildVersion.contains("17G2") || FileExists(Entry->Volume->RootDir, CFLFBPath)))) {
if (!SetFake) {
FakeID = 0x3EA58086 >> 16;
DBG(" Found FakeID Intel GFX = 0x%04x8086\n", FakeID);
@ -3189,7 +3189,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}
// if wakes up with an HDMI connected, somtimes this value causes force reboot in 10.14+
if (os_version < AsciiOSVersionToUint64("10.14")) {
if (os_version < AsciiOSVersionToUint64("10.14"_XS8)) {
devprop_add_value(device, "AAPL,GfxYTile", coffeelake_hd_vals[1], 4);
}
break;
@ -3354,7 +3354,7 @@ BOOLEAN setup_gma_devprop(LOADER_ENTRY *Entry, pci_dt_t *gma_dev)
}*/
// if wakes up with an HDMI connected, somtimes this value causes force reboot in 10.14+
if (os_version < AsciiOSVersionToUint64("10.14")) {
if (os_version < AsciiOSVersionToUint64("10.14"_XS8)) {
devprop_add_value(device, "AAPL,GfxYTile", cannonlake_hd_vals[1], 4);
}
break;

View File

@ -150,7 +150,7 @@ BOOLEAN EFIAPI IsHDMIAudio(EFI_HANDLE PciDevHandle)
return FALSE;
}
BOOLEAN setup_hda_devprop(EFI_PCI_IO_PROTOCOL *PciIo, pci_dt_t *hda_dev, CHAR8 *OSVersion)
BOOLEAN setup_hda_devprop(EFI_PCI_IO_PROTOCOL *PciIo, pci_dt_t *hda_dev, const XString8& OSVersion)
{
DevPropDevice *device = NULL;
UINT32 layoutId = 0;
@ -242,7 +242,7 @@ BOOLEAN setup_hda_devprop(EFI_PCI_IO_PROTOCOL *PciIo, pci_dt_t *hda_dev, CHAR8 *
}
}
if (!Injected) {
if ((OSVersion != NULL && AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.8")) || (gSettings.HDALayoutId > 0)) {
if ((OSVersion.notEmpty() && AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.8"_XS8)) || (gSettings.HDALayoutId > 0)) {
devprop_add_value(device, "layout-id", (UINT8 *)&layoutId, 4);
}
layoutId = 0; // reuse variable

View File

@ -327,7 +327,7 @@ BOOLEAN
setup_hda_devprop (
EFI_PCI_IO_PROTOCOL *PciIo,
pci_dt_t *hda_dev,
CHAR8 *OSVersion
const XString8& OSVersion
);
BOOLEAN EFIAPI IsHDMIAudio(EFI_HANDLE PciDevHandle);

View File

@ -165,9 +165,9 @@ UINT32 LOADER_ENTRY::searchSectionByNum(UINT8 * binary, UINT32 Num)
return 0;
}
UINTN LOADER_ENTRY::searchProcInDriver(UINT8 * driver, UINT32 driverLen, const char *procedure)
UINTN LOADER_ENTRY::searchProcInDriver(UINT8 * driver, UINT32 driverLen, const XString8& procedure)
{
if (!procedure) {
if (procedure.isEmpty()) {
return 0;
}
/*
@ -192,7 +192,7 @@ UINTN LOADER_ENTRY::searchProcInDriver(UINT8 * driver, UINT32 driverLen, const c
};
*/
DBG("search procedure %s\n", procedure);
DBG("search procedure %s\n", procedure.c_str());
struct nlist_64 * vArray = NULL;
INT32 lSizeVtable = 0;
const char* Names = NULL;
@ -224,13 +224,13 @@ UINTN LOADER_ENTRY::searchProcInDriver(UINT8 * driver, UINT32 driverLen, const c
bool found = false;
for (i = 0; i < lSizeVtable; ++i) {
Offset = vArray[i].n_un.n_strx;
if (strstr(&Names[Offset], procedure)) {
if (strstr(&Names[Offset], procedure.c_str())) {
found = true;
break;
}
}
if (!found) {
DBG("%s not found\n", procedure);
DBG("%s not found\n", procedure.c_str());
return 0;
}
DBG("found section %d at pos=%d\n", vArray[i].n_sect, i);
@ -320,12 +320,12 @@ UINTN LOADER_ENTRY::searchProcInDriver(UINT8 * driver, UINT32 driverLen, const c
//static int N = 0;
//search a procedure by Name and return its offset in the kernel
UINTN LOADER_ENTRY::searchProc(const char *procedure)
UINTN LOADER_ENTRY::searchProc(const XString8& procedure)
{
if (!procedure) {
if (procedure.isEmpty()) {
return 0;
}
DBG("search name in kernel: %s\n", procedure);
DBG("search name in kernel: %s\n", procedure.c_str());
const char* Names = (const char*)(&KernelData[NamesTable]);
VTABLE * vArray = (VTABLE*)(&KernelData[AddrVtable]);
//search for the name
@ -343,7 +343,7 @@ UINTN LOADER_ENTRY::searchProc(const char *procedure)
// DBG_RT("Offset %lx Seg=%x\n", Offset, vArray[i].Seg);
// DBG_RT("Name to compare %s\n", &Names[Offset]);
// Stall(3000000);
if (AsciiStrStr(&Names[Offset], procedure) != NULL) {
if (AsciiStrStr(&Names[Offset], procedure.c_str()) != NULL) {
found = true;
break;
}
@ -924,7 +924,7 @@ BOOLEAN LOADER_ENTRY::KernelPatchPm()
// wrmsr 0xe2 twice
// B9E2000000 0F30 replace to eb05
// UINTN procLen = 0;
UINTN procLocation = searchProc("xcpm_idle");
UINTN procLocation = searchProc("xcpm_idle"_XS8);
const UINT8 findJmp[] = {0xB9, 0xE2, 0x00, 0x00, 0x00, 0x0F, 0x30};
const UINT8 patchJmp[] = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
DBG_RT("==> xcpm_idle at %llx\n", procLocation);
@ -938,8 +938,8 @@ BOOLEAN LOADER_ENTRY::KernelPatchPm()
// E87EFCFFFF call sub_ffffff80004fa610 => check e8?
// there are other occurence of _xcpm_core_scope_msrs so check 488D3D or E8 at .+7
// or restrict len = 0x200
procLocation = searchProc("xcpm_init");
UINTN symbol1 = searchProc("xcpm_core_scope_msrs");
procLocation = searchProc("xcpm_init"_XS8);
UINTN symbol1 = searchProc("xcpm_core_scope_msrs"_XS8);
UINTN patchLocation1 = FindRelative32(KernelData, procLocation, 0x200, symbol1);
if (patchLocation1 != 0) {
DBG_RT("=> xcpm_core_scope_msrs found at %llx\n", patchLocation1);
@ -959,7 +959,7 @@ BOOLEAN LOADER_ENTRY::KernelPatchPm()
// DBG_RT("\n");
}
}
UINTN symbol2 = searchProc("xcpm_SMT_scope_msrs");
UINTN symbol2 = searchProc("xcpm_SMT_scope_msrs"_XS8);
patchLocation1 = FindRelative32(KernelData, procLocation, 0x200, symbol2);
if (patchLocation1 != 0) {
DBG_RT("=> xcpm_SMT_scope_msrs found at %llx\n", patchLocation1);
@ -1061,9 +1061,9 @@ BOOLEAN LOADER_ENTRY::KernelLapicPatch_64()
// address: 002e4a2f
// bytes:658b04251c0000003b058bb97b00
// call _panic -> change to nop {90,90,90,90,90}
if (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.10")) {
UINTN procAddr = searchProc("lapic_interrupt");
patchLocation1 = searchProc("_panic");
if (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.10"_XS8)) {
UINTN procAddr = searchProc("lapic_interrupt"_XS8);
patchLocation1 = searchProc("_panic"_XS8);
patchLocation2 = FindRelative32(KernelData, procAddr, 0x140, patchLocation1);
if (patchLocation2 != 0) {
KernelData[patchLocation2 - 5] = 0xEB;
@ -1277,7 +1277,7 @@ VOID LOADER_ENTRY::applyKernPatch(const UINT8 *find, UINTN size, const UINT8 *re
//
static inline BOOLEAN IsXCPMOSVersionCompat(UINT64 os_version)
{
return (os_version >= AsciiOSVersionToUint64("10.8.5")) && (os_version < AsciiOSVersionToUint64("11.1.0"));
return (os_version >= AsciiOSVersionToUint64("10.8.5"_XS8)) && (os_version < AsciiOSVersionToUint64("11.1.0"_XS8));
}
//
@ -1299,7 +1299,7 @@ BOOLEAN LOADER_ENTRY::HaswellEXCPM()
{
DBG("HaswellEXCPM() ===>\n");
UINT8 *kern = KernelData;
CONST CHAR8 *comment;
XString8 comment;
// UINT32 i;
UINTN patchLocation;
UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
@ -1312,59 +1312,59 @@ BOOLEAN LOADER_ENTRY::HaswellEXCPM()
}
// _cpuid_set_info
comment = "_cpuid_set_info";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_cpuid_set_info"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = { 0x83, 0xF8, 0x3C, 0x74, 0x2D };
const UINT8 repl[] = { 0x83, 0xF8, 0x3F, 0x74, 0x2D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version < AsciiOSVersionToUint64("10.10")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[] = { 0x83, 0xF8, 0x3C, 0x75, 0x07 };
const UINT8 repl[] = { 0x83, 0xF8, 0x3F, 0x75, 0x07 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.10.1")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.10.1"_XS8)) {
// 10.10 - 10.10.1
const UINT8 find[] = { 0x74, 0x11, 0x83, 0xF8, 0x3C };
const UINT8 repl[] = { 0x74, 0x11, 0x83, 0xF8, 0x3F };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} // 10.10.2+: native support reached, no need to patch
// _xcpm_bootstrap
comment = "_xcpm_bootstrap";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_xcpm_bootstrap"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x54 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3F, 0x75, 0x54 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version < AsciiOSVersionToUint64("10.10")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x68 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3F, 0x75, 0x68 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.10.2")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.10.2"_XS8)) {
// 10.10 - 10.10.2
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x63 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3F, 0x75, 0x63 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.10.5")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.10.5"_XS8)) {
// 10.10.3 - 10.10.5
const UINT8 find[] = { 0x83, 0xC3, 0xC6, 0x83, 0xFB, 0x0D };
const UINT8 repl[] = { 0x83, 0xC3, 0xC3, 0x83, 0xFB, 0x0D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.11")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.11"_XS8)) {
// 10.11 DB/PB - 10.11.0
const UINT8 find[] = { 0x83, 0xC3, 0xC6, 0x83, 0xFB, 0x0D };
const UINT8 repl[] = { 0x83, 0xC3, 0xC3, 0x83, 0xFB, 0x0D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.11.6")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.11.6"_XS8)) {
// 10.11.1 - 10.11.6
const UINT8 find[] = { 0x83, 0xC3, 0xBB, 0x83, 0xFB, 0x09 };
const UINT8 repl[] = { 0x83, 0xC3, 0xB8, 0x83, 0xFB, 0x09 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else {
UINTN procLocation = searchProc(comment);
UINTN featureCall = searchProc("_cpuid_features");
UINTN featureCall = searchProc("_cpuid_features"_XS8);
UINTN place = FindRelative32(KernelData, procLocation, 0x100, featureCall);
for (UINTN i = 10; i < 20; ++i) {
if (KernelData[place + i] == 0xC4) {
@ -1406,8 +1406,8 @@ BOOLEAN LOADER_ENTRY::HaswellEXCPM()
}
DBG("Searching _xcpm_pkg_scope_msr ...\n");
comment = "_xcpm_pkg_scope_msrs";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_xcpm_pkg_scope_msrs"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = {
0x48, 0x8D, 0x3D, 0x02, 0x71, 0x55, 0x00, 0xBE,
@ -1421,12 +1421,12 @@ BOOLEAN LOADER_ENTRY::HaswellEXCPM()
0x3D, 0xF4, 0x70, 0x55, 0x00, 0xBE, 0x07, 0x00,
0x00, 0x00, 0x31, 0xD2, 0x90, 0x90, 0x90, 0x90, 0x90
};
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version < AsciiOSVersionToUint64("10.10")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[] = { 0xBE, 0x07, 0x00, 0x00, 0x00, 0x74, 0x13, 0x31, 0xD2, 0xE8, 0x5F, 0x02, 0x00, 0x00 };
const UINT8 repl[] = { 0xBE, 0x07, 0x00, 0x00, 0x00, 0x90, 0x90, 0x31, 0xD2, 0x90, 0x90, 0x90, 0x90, 0x90 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else {
// 10.10+
/* patchLocation = 0; // clean out the value just in case
@ -1438,8 +1438,8 @@ BOOLEAN LOADER_ENTRY::HaswellEXCPM()
break;
}
} */
UINTN procLocation = searchProc("xcpm_init");
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs");
UINTN procLocation = searchProc("xcpm_init"_XS8);
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs"_XS8);
patchLocation = FindRelative32(KernelData, procLocation, 0x100, symbol1);
@ -1477,7 +1477,7 @@ BOOLEAN LOADER_ENTRY::BroadwellEPM()
return FALSE;
}
KernelAndKextPatches.FakeCPUID = (UINT32)(os_version < AsciiOSVersionToUint64("10.10.3") ? 0x0306C0 : 0x040674);
KernelAndKextPatches.FakeCPUID = (UINT32)(os_version < AsciiOSVersionToUint64("10.10.3"_XS8) ? 0x0306C0 : 0x040674);
KernelCPUIDPatch();
DBG("Searching _xcpm_pkg_scope_msr ...\n");
@ -1486,7 +1486,7 @@ BOOLEAN LOADER_ENTRY::BroadwellEPM()
// ffffff800046882c BE07000000 mov esi, 0x7
// ffffff8000468831 31D2 xor edx, edx
// ffffff8000468833 E838FDFFFF call sub_ffffff8000468570
if (os_version >= AsciiOSVersionToUint64("10.12")) {
if (os_version >= AsciiOSVersionToUint64("10.12"_XS8)) {
// 10.12+
// patchLocation = 0; // clean out the value just in case
// for (i = 0; i < 0x1000000; i++) {
@ -1496,8 +1496,8 @@ BOOLEAN LOADER_ENTRY::BroadwellEPM()
// DBG("Found _xcpm_pkg_scope_msr\n");
// break;
// }
UINTN procLocation = searchProc("xcpm_init");
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs");
UINTN procLocation = searchProc("xcpm_init"_XS8);
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs"_XS8);
patchLocation = FindRelative32(KernelData, procLocation, 0x100, symbol1);
@ -1525,7 +1525,7 @@ BOOLEAN LOADER_ENTRY::HaswellLowEndXCPM()
{
DBG("HaswellLowEndXCPM() ===>\n");
UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
CONST CHAR8 *comment;
XString8 comment;
// check OS version suit for patches
if (!IsXCPMOSVersionCompat(os_version)) {
@ -1538,7 +1538,7 @@ BOOLEAN LOADER_ENTRY::HaswellLowEndXCPM()
KernelCPUIDPatch();
// 10.8.5 - 10.11.x no need the following kernel patches on Haswell Celeron/Pentium
if (os_version >= AsciiOSVersionToUint64("10.8.5") && os_version < AsciiOSVersionToUint64("10.12")) {
if (os_version >= AsciiOSVersionToUint64("10.8.5"_XS8) && os_version < AsciiOSVersionToUint64("10.12"_XS8)) {
DBG("HaswellLowEndXCPM() <===\n");
return TRUE;
}
@ -1552,9 +1552,9 @@ BOOLEAN LOADER_ENTRY::HaswellLowEndXCPM()
applyKernPatch(find, sizeof(find), repl, comment);
}
*/
comment = "_xcpm_bootstrap";
comment = "_xcpm_bootstrap"_XS8;
UINTN procLocation = searchProc(comment);
UINTN featureCall = searchProc("_cpuid_features");
UINTN featureCall = searchProc("_cpuid_features"_XS8);
UINTN place = FindRelative32(KernelData, procLocation, 0x100, featureCall);
for (UINTN i = 10; i < 20; ++i) {
if (KernelData[place + i] == 0xC4) {
@ -1598,13 +1598,13 @@ BOOLEAN LOADER_ENTRY::HaswellLowEndXCPM()
applyKernPatch(find, sizeof(find), repl, comment);
}
*/
comment = "_cpuid_set_info_rdmsr";
comment = "_cpuid_set_info_rdmsr"_XS8;
// PMheart: bytes seem stable as of 10.12
if (os_version >= AsciiOSVersionToUint64("10.12")) {
if (os_version >= AsciiOSVersionToUint64("10.12"_XS8)) {
// 10.12+
const UINT8 find[] = { 0xB9, 0xA0, 0x01, 0x00, 0x00, 0x0F, 0x32 };
const UINT8 repl[] = { 0xB9, 0xA0, 0x01, 0x00, 0x00, 0x31, 0xC0 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
}
DBG("HaswellLowEndXCPM() <===\n");
@ -1616,7 +1616,7 @@ BOOLEAN LOADER_ENTRY::HaswellLowEndXCPM()
//
BOOLEAN LOADER_ENTRY::KernelIvyBridgeXCPM()
{
CONST CHAR8 *comment;
XString8 comment;
// UINT32 i;
UINTN patchLocation;
UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
@ -1634,14 +1634,14 @@ BOOLEAN LOADER_ENTRY::KernelIvyBridgeXCPM()
DBG("KernelIvyBridgeXCPM():Unsupported macOS.\n");
DBG("KernelIvyBridgeXCPM() <===FALSE\n");
return FALSE;
} else if (os_version >= AsciiOSVersionToUint64("10.8.5") && os_version < AsciiOSVersionToUint64("10.12")) {
} else if (os_version >= AsciiOSVersionToUint64("10.8.5"_XS8) && os_version < AsciiOSVersionToUint64("10.12"_XS8)) {
// 10.8.5 - 10.11.x no need the following kernel patches on Ivy Bridge - we just use -xcpm boot-args
DBG("KernelIvyBridgeXCPM() <===\n");
return TRUE;
}
DBG("Searching _xcpm_pkg_scope_msr ...\n");
if (os_version >= AsciiOSVersionToUint64("10.12")) {
if (os_version >= AsciiOSVersionToUint64("10.12"_XS8)) {
// 10.12+
/* patchLocation = 0; // clean out the value just in case
for (i = 0; i < 0x1000000; i++) {
@ -1652,8 +1652,8 @@ BOOLEAN LOADER_ENTRY::KernelIvyBridgeXCPM()
break;
}
} */
UINTN procLocation = searchProc("xcpm_init");
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs");
UINTN procLocation = searchProc("xcpm_init"_XS8);
UINTN symbol1 = searchProc("_xcpm_pkg_scope_msrs"_XS8);
patchLocation = FindRelative32(KernelData, procLocation, 0x100, symbol1);
@ -1669,9 +1669,9 @@ BOOLEAN LOADER_ENTRY::KernelIvyBridgeXCPM()
}
}
comment = "_xcpm_bootstrap";
comment = "_xcpm_bootstrap"_XS8;
UINTN procLocation = searchProc(comment);
UINTN featureCall = searchProc("_cpuid_features");
UINTN featureCall = searchProc("_cpuid_features"_XS8);
UINTN place = FindRelative32(KernelData, procLocation, 0x100, featureCall);
for (UINTN i = 10; i < 20; ++i) {
if (KernelData[place + i] == 0xC4) {
@ -1722,7 +1722,7 @@ BOOLEAN LOADER_ENTRY::KernelIvyBridgeXCPM()
BOOLEAN LOADER_ENTRY::KernelIvyE5XCPM()
{
UINT8 *kern = (UINT8*)KernelData;
CONST CHAR8 *comment;
XString8 comment;
// UINT32 i;
UINTN patchLocation;
UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
@ -1744,23 +1744,23 @@ BOOLEAN LOADER_ENTRY::KernelIvyE5XCPM()
// _cpuid_set_info
// TODO: should we use FakeCPUID instead?
comment = "_cpuid_set_info";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_cpuid_set_info"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = { 0x83, 0xF8, 0x3C, 0x74, 0x2D };
const UINT8 repl[] = { 0x83, 0xF8, 0x3E, 0x74, 0x2D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version == AsciiOSVersionToUint64("10.9") || os_version == AsciiOSVersionToUint64("10.9.1")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version == AsciiOSVersionToUint64("10.9"_XS8) || os_version == AsciiOSVersionToUint64("10.9.1"_XS8)) {
// 10.9.0 - 10.9.1
const UINT8 find[] = { 0x83, 0xF8, 0x3C, 0x75, 0x07 };
const UINT8 repl[] = { 0x83, 0xF8, 0x3E, 0x75, 0x07 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} // 10.9.2+: native support reached, no need to patch
// _xcpm_pkg_scope_msrs
DBG("Searching _xcpm_pkg_scope_msrs ...\n");
comment = "_xcpm_pkg_scope_msrs";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_xcpm_pkg_scope_msrs"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = {
0x48, 0x8D, 0x3D, 0x02, 0x71, 0x55, 0x00, 0xBE,
@ -1774,16 +1774,16 @@ BOOLEAN LOADER_ENTRY::KernelIvyE5XCPM()
0x3D, 0xF4, 0x70, 0x55, 0x00, 0xBE, 0x07, 0x00,
0x00, 0x00, 0x31, 0xD2, 0x90, 0x90, 0x90, 0x90, 0x90
};
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version < AsciiOSVersionToUint64("10.10")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[] = { 0xBE, 0x07, 0x00, 0x00, 0x00, 0x74, 0x13, 0x31, 0xD2, 0xE8, 0x5F, 0x02, 0x00, 0x00 };
const UINT8 repl[] = { 0xBE, 0x07, 0x00, 0x00, 0x00, 0x90, 0x90, 0x31, 0xD2, 0x90, 0x90, 0x90, 0x90, 0x90 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else {
// 10.10+
// patchLocation = 0; // clean out the value just in case
UINTN procLocation = searchProc("xcpm_init");
UINTN procLocation = searchProc("xcpm_init"_XS8);
UINTN symbol1 = searchProc(comment);
patchLocation = FindRelative32(kern, procLocation, 0x100, symbol1);
@ -1809,41 +1809,41 @@ BOOLEAN LOADER_ENTRY::KernelIvyE5XCPM()
}
// _xcpm_bootstrap
comment = "_xcpm_bootstrap";
if (os_version <= AsciiOSVersionToUint64("10.8.5")) {
comment = "_xcpm_bootstrap"_XS8;
if (os_version <= AsciiOSVersionToUint64("10.8.5"_XS8)) {
// 10.8.5
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x54 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3E, 0x75, 0x54 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version < AsciiOSVersionToUint64("10.10")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x68 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3E, 0x75, 0x68 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.10.2")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.10.2"_XS8)) {
// 10.10 - 10.10.2
const UINT8 find[] = { 0x83, 0xFB, 0x3C, 0x75, 0x63 };
const UINT8 repl[] = { 0x83, 0xFB, 0x3E, 0x75, 0x63 };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.10.5")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.10.5"_XS8)) {
// 10.10.3 - 10.10.5
const UINT8 find[] = { 0x83, 0xC3, 0xC6, 0x83, 0xFB, 0x0D };
const UINT8 repl[] = { 0x83, 0xC3, 0xC4, 0x83, 0xFB, 0x0D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.11")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.11"_XS8)) {
// 10.11 DB/PB - 10.11.0
const UINT8 find[] = { 0x83, 0xC3, 0xC6, 0x83, 0xFB, 0x0D };
const UINT8 repl[] = { 0x83, 0xC3, 0xC4, 0x83, 0xFB, 0x0D };
applyKernPatch(find, sizeof(find), repl, comment);
} else if (os_version <= AsciiOSVersionToUint64("10.11.6")) {
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else if (os_version <= AsciiOSVersionToUint64("10.11.6"_XS8)) {
// 10.11.1 - 10.11.6
const UINT8 find[] = { 0x83, 0xC3, 0xBB, 0x83, 0xFB, 0x09 };
const UINT8 repl[] = { 0x83, 0xC3, 0xB9, 0x83, 0xFB, 0x09 };
applyKernPatch(find, sizeof(find), repl, comment);
applyKernPatch(find, sizeof(find), repl, comment.c_str());
} else {
UINTN procLocation = searchProc(comment);
UINTN featureCall = searchProc("_cpuid_features");
UINTN featureCall = searchProc("_cpuid_features"_XS8);
UINTN place = FindRelative32(KernelData, procLocation, 0x100, featureCall);
for (UINTN i = 10; i < 20; ++i) {
if (KernelData[place + i] == 0xC4) {
@ -2352,27 +2352,27 @@ LOADER_ENTRY::FindBootArgs()
BOOLEAN
LOADER_ENTRY::KernelUserPatch()
{
INTN Num, i = 0, y = 0;
INTN Num, y = 0;
// if we modify directly KernelAndKextPatches.KernelPatches[i].SearchLen, it will wrong for next driver
UINTN SearchLen = KernelAndKextPatches.KernelPatches[i].SearchLen;
// old confuse
// We are using KernelAndKextPatches as set by Custom Entries.
// while config patches go to gSettings.KernelAndKextPatches
// how to resolve it?
for (; i < KernelAndKextPatches.NrKernels; ++i) {
DBG( "Patch[%lld]: %s\n", i, KernelAndKextPatches.KernelPatches[i].Label);
for (size_t i = 0 ; i < KernelAndKextPatches.KernelPatches.size(); ++i) {
DBG( "Patch[%zu]: %s\n", i, KernelAndKextPatches.KernelPatches[i].Label.c_str());
if (!KernelAndKextPatches.KernelPatches[i].MenuItem.BValue) {
//DBG_RT( "Patch[%d]: %a :: is not allowed for booted OS %a\n", i, KernelAndKextPatches.KernelPatches[i].Label, OSVersion);
DBG( "==> disabled\n");
continue;
}
// if we modify directly KernelAndKextPatches.KernelPatches[i].SearchLen, it will wrong for next driver
UINTN SearchLen = KernelAndKextPatches.KernelPatches[i].SearchLen;
bool once = false;
UINTN procLen = 0;
UINTN procAddr = searchProc(KernelAndKextPatches.KernelPatches[i].ProcedureName);
DBG("procedure %s found at 0x%llx\n", KernelAndKextPatches.KernelPatches[i].ProcedureName, procAddr);
DBG("procedure %s found at 0x%llx\n", KernelAndKextPatches.KernelPatches[i].ProcedureName.c_str(), procAddr);
if (SearchLen == 0) {
SearchLen = KERNEL_MAX_SIZE;
procLen = KERNEL_MAX_SIZE - procAddr;
@ -2385,18 +2385,18 @@ LOADER_ENTRY::KernelUserPatch()
while (j < KERNEL_MAX_SIZE) {
if (!KernelAndKextPatches.KernelPatches[i].StartPattern || //old behavior
CompareMemMask((const UINT8*)curs,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].StartPattern,
KernelAndKextPatches.KernelPatches[i].StartPatternLen,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].StartMask,
KernelAndKextPatches.KernelPatches[i].StartPatternLen)) {
KernelAndKextPatches.KernelPatches[i].StartPattern.data(),
KernelAndKextPatches.KernelPatches[i].StartPattern.size(),
KernelAndKextPatches.KernelPatches[i].StartMask.data(),
KernelAndKextPatches.KernelPatches[i].StartPattern.size())) {
DBG( " StartPattern found\n");
Num = SearchAndReplaceMask(curs,
procLen,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].Data,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].MaskFind,
KernelAndKextPatches.KernelPatches[i].DataLen,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].Patch,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].MaskReplace,
(const UINT8*)KernelAndKextPatches.KernelPatches[i].Data.data(),
(const UINT8*)KernelAndKextPatches.KernelPatches[i].MaskFind.data(),
KernelAndKextPatches.KernelPatches[i].Data.size(),
(const UINT8*)KernelAndKextPatches.KernelPatches[i].Patch.data(),
(const UINT8*)KernelAndKextPatches.KernelPatches[i].MaskReplace.data(),
KernelAndKextPatches.KernelPatches[i].Count
);
@ -2408,7 +2408,7 @@ LOADER_ENTRY::KernelUserPatch()
DBG( "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
if (once ||
!KernelAndKextPatches.KernelPatches[i].StartPattern ||
!KernelAndKextPatches.KernelPatches[i].StartPatternLen) {
!KernelAndKextPatches.KernelPatches[i].StartPattern.size()) {
break;
}
}
@ -2425,16 +2425,18 @@ LOADER_ENTRY::KernelUserPatch()
BOOLEAN
LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
{
INTN Num, i = 0, y = 0;
INTN Num, y = 0;
for (size_t i = 0 ; i < KernelAndKextPatches.BootPatches.size(); ++i)
{
// if we modify directly KernelAndKextPatches.BootPatches[i].SearchLen, it will wrong for next driver
UINTN SearchLen = KernelAndKextPatches.BootPatches[i].SearchLen;
if (!SearchLen) {
SearchLen = BooterSize;
}
for (; i < KernelAndKextPatches.NrBoots; ++i) {
DBG( "Patch[%lld]: %s\n", i, KernelAndKextPatches.BootPatches[i].Label);
DBG( "Patch[%zu]: %s\n", i, KernelAndKextPatches.BootPatches[i].Label.c_str());
if (!KernelAndKextPatches.BootPatches[i].MenuItem.BValue) {
DBG( "==> disabled\n");
continue;
@ -2444,19 +2446,19 @@ LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
while (j < BooterSize) {
if (!KernelAndKextPatches.BootPatches[i].StartPattern || //old behavior
CompareMemMask((const UINT8*)curs,
(const UINT8*)KernelAndKextPatches.BootPatches[i].StartPattern,
KernelAndKextPatches.BootPatches[i].StartPatternLen,
(const UINT8*)KernelAndKextPatches.BootPatches[i].StartMask,
KernelAndKextPatches.BootPatches[i].StartPatternLen)) {
(const UINT8*)KernelAndKextPatches.BootPatches[i].StartPattern.data(),
KernelAndKextPatches.BootPatches[i].StartPattern.size(),
(const UINT8*)KernelAndKextPatches.BootPatches[i].StartMask.data(),
KernelAndKextPatches.BootPatches[i].StartPattern.size())) {
DBG( " StartPattern found\n");
Num = SearchAndReplaceMask(curs,
SearchLen,
(const UINT8*)KernelAndKextPatches.BootPatches[i].Data,
(const UINT8*)KernelAndKextPatches.BootPatches[i].MaskFind,
KernelAndKextPatches.BootPatches[i].DataLen,
(const UINT8*)KernelAndKextPatches.BootPatches[i].Patch,
(const UINT8*)KernelAndKextPatches.BootPatches[i].MaskReplace,
(const UINT8*)KernelAndKextPatches.BootPatches[i].Data.data(),
(const UINT8*)KernelAndKextPatches.BootPatches[i].MaskFind.data(),
KernelAndKextPatches.BootPatches[i].Data.size(),
(const UINT8*)KernelAndKextPatches.BootPatches[i].Patch.data(),
(const UINT8*)KernelAndKextPatches.BootPatches[i].MaskReplace.data(),
KernelAndKextPatches.BootPatches[i].Count
);
if (Num) {
@ -2467,7 +2469,7 @@ LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
DBG( "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
if (!KernelAndKextPatches.BootPatches[i].StartPattern ||
!KernelAndKextPatches.BootPatches[i].StartPatternLen) {
!KernelAndKextPatches.BootPatches[i].StartPattern.size()) {
break;
}
}
@ -2511,7 +2513,7 @@ LOADER_ENTRY::KernelAndKextPatcherInit()
// for AptioFix booting - it's always at KernelRelocBase + 0x00200000
// UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
DBG("os_version=%s\n", OSVersion);
DBG("os_version=%s\n", OSVersion.c_str());
// if (os_version < AsciiOSVersionToUint64("10.6")) {
// KernelData = (UINT8*)(UINTN)(KernelSlide + KernelRelocBase + 0x00111000);
@ -2601,7 +2603,8 @@ LOADER_ENTRY::KernelAndKextsPatcherStart()
* so set common until better solution invented
*/
//KernelAndKextPatches = (KERNEL_AND_KEXT_PATCHES *)(((UINTN)&gSettings) + OFFSET_OF(SETTINGS_DATA, KernelAndKextPatches));
CopyKernelAndKextPatches(&KernelAndKextPatches, &gSettings.KernelAndKextPatches);
// CopyKernelAndKextPatches(&KernelAndKextPatches, &gSettings.KernelAndKextPatches);
KernelAndKextPatches = gSettings.KernelAndKextPatches;
PatcherInited = false;
KernelAndKextPatcherInit();
@ -2611,13 +2614,13 @@ LOADER_ENTRY::KernelAndKextsPatcherStart()
KernelAndKextPatches.KPAppleRTC ||
KernelAndKextPatches.EightApple ||
KernelAndKextPatches.KPDELLSMBIOS ||
(KernelAndKextPatches.KPATIConnectorsPatch != NULL) ||
((KernelAndKextPatches.NrKexts > 0) && (KernelAndKextPatches.KextPatches != NULL))
KernelAndKextPatches.KPATIConnectorsPatch != NULL ||
KernelAndKextPatches.KextPatches.size() > 0
);
// DBG_RT("\nKernelToPatch: ");
// DBG_RT("Kernels patches: %d\n", KernelAndKextPatches.NrKernels);
if (gSettings.KernelPatchesAllowed && (KernelAndKextPatches.KernelPatches != NULL) && KernelAndKextPatches.NrKernels) {
// DBG_RT("Kernels patches: %d\n", KernelAndKextPatches.KernelPatches.size());
if (gSettings.KernelPatchesAllowed && KernelAndKextPatches.KernelPatches.notEmpty()) {
// DBG_RT("Enabled: \n");
DBG("Kernels patches: enabled \n");
// KernelAndKextPatcherInit();

View File

@ -285,7 +285,7 @@ VOID LOADER_ENTRY::LoadPlugInKexts(IN EFI_FILE *RootDir, IN CONST CHAR16 *DirNam
DirIterClose(&PlugInIter);
}
VOID LOADER_ENTRY::AddKexts(CONST CHAR16 *SrcDir, CONST CHAR16 *Path, cpu_type_t archCpuType)
VOID LOADER_ENTRY::AddKexts(const XStringW& SrcDir, const XStringW& Path, cpu_type_t archCpuType)
{
XStringW FileName;
XStringW PlugInName;
@ -293,12 +293,12 @@ VOID LOADER_ENTRY::AddKexts(CONST CHAR16 *SrcDir, CONST CHAR16 *Path, cpu_type_t
SIDELOAD_KEXT *CurrentPlugInKext;
EFI_STATUS Status;
MsgLog("Preparing kexts injection from %ls\n", SrcDir);
MsgLog("Preparing kexts injection from %ls\n", SrcDir.wc_str());
CurrentKext = InjectKextList;
while (CurrentKext) {
// DBG(" current kext name=%ls path=%ls, match against=%ls\n", CurrentKext->FileName, CurrentKext->KextDirNameUnderOEMPath, Path);
if (StrCmp(CurrentKext->KextDirNameUnderOEMPath.wc_str(), Path) == 0) {
FileName = SWPrintf("%ls\\%ls", SrcDir, CurrentKext->FileName.wc_str());
if ( CurrentKext->KextDirNameUnderOEMPath == Path ) {
FileName = SWPrintf("%ls\\%ls", SrcDir.wc_str(), CurrentKext->FileName.wc_str());
// snwprintf(FileName, 512, "%s\\%s", SrcDir, CurrentKext->FileName);
if (!(CurrentKext->MenuItem.BValue)) {
// inject require
@ -322,7 +322,7 @@ VOID LOADER_ENTRY::AddKexts(CONST CHAR16 *SrcDir, CONST CHAR16 *Path, cpu_type_t
}
} else {
// disable current kext injection
if (!StriStr(SrcDir, L"Off")) {
if ( SrcDir.containsIC(L"Off") ) {
MsgLog("Disabled kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext->Version.wc_str());
}
}
@ -363,28 +363,27 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
// } else if (Arch != NULL && StrnCmp(Arch,L"i386",StrLen(L"i386")) == 0) {
} else if (LoadOptions.contains("arch=i386")) {
archCpuType = CPU_TYPE_I386;
} else if (OSVersion != NULL) {
} else if (OSVersion.notEmpty()) {
UINT64 os_version = AsciiOSVersionToUint64(OSVersion);
if (os_version >= AsciiOSVersionToUint64("10.8")) {
if (os_version >= AsciiOSVersionToUint64("10.8"_XS8)) {
archCpuType = CPU_TYPE_X86_64; // For OSVersion >= 10.8, only x86_64 exists
} else if (os_version < AsciiOSVersionToUint64("10.7")) {
} else if (os_version < AsciiOSVersionToUint64("10.7"_XS8)) {
archCpuType = CPU_TYPE_I386; // For OSVersion < 10.7, use default of i386
}
}
// Force kexts to load
if ((KernelAndKextPatches.NrForceKexts > 0) &&
(KernelAndKextPatches.ForceKexts != NULL)) {
for (INT32 i = 0; i < KernelAndKextPatches.NrForceKexts; ++i) {
MsgLog(" Force kext: %ls\n", KernelAndKextPatches.ForceKexts[i]);
if ( KernelAndKextPatches.ForceKexts.notEmpty() ) {
for (size_t i = 0; i < KernelAndKextPatches.ForceKexts.size(); ++i) {
MsgLog(" Force kext: %ls\n", KernelAndKextPatches.ForceKexts[i].wc_str());
if (Volume && Volume->RootDir) {
// Check if the entry is a directory
if (StrStr(KernelAndKextPatches.ForceKexts[i], L".kext") == NULL) {
DirIterOpen(Volume->RootDir, KernelAndKextPatches.ForceKexts[i], &PlugInIter);
if (StrStr(KernelAndKextPatches.ForceKexts[i].wc_str(), L".kext") == NULL) {
DirIterOpen(Volume->RootDir, KernelAndKextPatches.ForceKexts[i].wc_str(), &PlugInIter);
while (DirIterNext(&PlugInIter, 1, L"*.kext", &PlugInFile)) {
if (PlugInFile->FileName[0] == '.' || StrStr(PlugInFile->FileName, L".kext") == NULL)
continue; // skip this
FileName = SWPrintf("%ls\\%ls", KernelAndKextPatches.ForceKexts[i], PlugInFile->FileName);
FileName = SWPrintf("%ls\\%ls", KernelAndKextPatches.ForceKexts[i].wc_str(), PlugInFile->FileName);
// snwprintf(FileName, 512, "%s\\%s", KernelAndKextPatches.ForceKexts[i], PlugInFile->FileName);
MsgLog(" Force kext: %ls\n", FileName.wc_str());
AddKext( Volume->RootDir, FileName.wc_str(), archCpuType);
@ -394,8 +393,8 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
}
DirIterClose(&PlugInIter);
} else {
AddKext( Volume->RootDir, KernelAndKextPatches.ForceKexts[i], archCpuType);
PlugIns = SWPrintf("%ls\\Contents\\PlugIns", KernelAndKextPatches.ForceKexts[i]);
AddKext( Volume->RootDir, KernelAndKextPatches.ForceKexts[i].wc_str(), archCpuType);
PlugIns = SWPrintf("%ls\\Contents\\PlugIns", KernelAndKextPatches.ForceKexts[i].wc_str());
// snwprintf(PlugIns, 512, "%s\\Contents\\PlugIns", KernelAndKextPatches.ForceKexts[i]);
LoadPlugInKexts(Volume->RootDir, PlugIns.wc_str(), archCpuType, TRUE);
}
@ -403,35 +402,35 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
}
}
CHAR16 UniOSVersion[16];
AsciiStrToUnicodeStrS(OSVersion, UniOSVersion, 16);
DBG("UniOSVersion == %ls\n", UniOSVersion);
XStringW UniOSVersion;
UniOSVersion = OSVersion;
DBG("UniOSVersion == %ls\n", UniOSVersion.wc_str());
CHAR16 UniShortOSVersion[6];
CHAR8 ShortOSVersion[6];
if (AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.10")) {
XStringW UniShortOSVersion;
// XString8 ShortOSVersion;
if (AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.10"_XS8)) {
// OSVersion that are earlier than 10.10(form: 10.x.y)
AsciiStrnCpyS(ShortOSVersion, 6, OSVersion, 4);
AsciiStrToUnicodeStrS(OSVersion, UniShortOSVersion, 5);
// ShortOSVersion.strncpy(OSVersion.c_str(), 4);
UniShortOSVersion.strncpy(OSVersion.c_str(), 4);
} else {
AsciiStrnCpyS(ShortOSVersion, 6, OSVersion, 5);
AsciiStrToUnicodeStrS(OSVersion, UniShortOSVersion, 6);
// ShortOSVersion.strncpy(OSVersion.c_str(), 5);
UniShortOSVersion.strncpy(OSVersion.c_str(), 5);
}
DBG("ShortOSVersion == %s\n", ShortOSVersion);
DBG("UniShortOSVersion == %ls\n", UniShortOSVersion);
// DBG("ShortOSVersion == %s\n", ShortOSVersion.c_str());
DBG("UniShortOSVersion == %ls\n", UniShortOSVersion.wc_str());
// syscl - allow specific load inject kext
// Clover/Kexts/Other is for general injection thus we need to scan both Other and OSVersion folder
SrcDir = GetOtherKextsDir(TRUE);
if ( SrcDir.notEmpty() ) {
AddKexts(SrcDir.wc_str(), L"Other", archCpuType);
AddKexts(SrcDir, L"Other"_XSW, archCpuType);
} else {
DBG("GetOtherKextsDir(TRUE) return NULL\n");
}
// slice: CLOVER/kexts/Off keep disabled kext which can be allowed
SrcDir = GetOtherKextsDir(FALSE);
if ( SrcDir.notEmpty() ) {
AddKexts(SrcDir.wc_str(), L"Off", archCpuType);
AddKexts(SrcDir, L"Off"_XSW, archCpuType);
} else {
DBG("GetOtherKextsDir(FALSE) return NULL\n");
}
@ -445,7 +444,7 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
XStringW DirPath;
OSAllVersionKextsDir = SWPrintf("%ls\\kexts\\10", OEMPath.wc_str());
// snwprintf(OSAllVersionKextsDir, sizeof(OSAllVersionKextsDir), "%s\\kexts\\10", OEMPath);
AddKexts(OSAllVersionKextsDir.wc_str(), L"10", archCpuType);
AddKexts(OSAllVersionKextsDir, L"10"_XSW, archCpuType);
if (OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
DirName = SWPrintf("10_install");
@ -459,45 +458,45 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
}
DirPath = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), DirName.wc_str());
// snwprintf(DirPath, sizeof(DirPath), "%s\\kexts\\%s", OEMPath, DirName);
AddKexts(DirPath.wc_str(), DirName.wc_str(), archCpuType);
AddKexts(DirPath, DirName, archCpuType);
// Add kext from 10.{version}
OSShortVersionKextsDir = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), UniShortOSVersion);
OSShortVersionKextsDir = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), UniShortOSVersion.wc_str());
// snwprintf(OSShortVersionKextsDir, sizeof(OSShortVersionKextsDir), "%s\\kexts\\%s", OEMPath, UniShortOSVersion);
AddKexts( OSShortVersionKextsDir.wc_str(), UniShortOSVersion, archCpuType);
AddKexts( OSShortVersionKextsDir, UniShortOSVersion, archCpuType);
if (OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
DirName = SWPrintf("%ls_install", UniShortOSVersion);
DirName = SWPrintf("%ls_install", UniShortOSVersion.wc_str());
// snwprintf(DirName, sizeof(DirName), "%s_install", UniShortOSVersion);
} else if (OSTYPE_IS_OSX_RECOVERY(LoaderType)) {
DirName = SWPrintf("%ls_recovery", UniShortOSVersion);
DirName = SWPrintf("%ls_recovery", UniShortOSVersion.wc_str());
// snwprintf(DirName, sizeof(DirName), "%s_recovery", UniShortOSVersion);
} else {
DirName = SWPrintf("%ls_normal", UniShortOSVersion);
DirName = SWPrintf("%ls_normal", UniShortOSVersion.wc_str());
// snwprintf(DirName, sizeof(DirName), "%s_normal", UniShortOSVersion);
}
DirPath = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), DirName.wc_str());
// snwprintf(DirPath, sizeof(DirPath), "%s\\kexts\\%s", OEMPath, DirName);
AddKexts(DirPath.wc_str(), DirName.wc_str(), archCpuType);
AddKexts(DirPath, DirName, archCpuType);
// Add kext from :
// 10.{version}.0 if NO minor version
// 10.{version}.{minor version} if minor version is > 0
if ( AsciiStrCmp(ShortOSVersion, OSVersion) == 0 ) {
OSVersionKextsDirName = SWPrintf("%s.0", OSVersion);
if ( UniShortOSVersion == OSVersion ) {
OSVersionKextsDirName = SWPrintf("%s.0", OSVersion.c_str());
// snwprintf(OSVersionKextsDirName, sizeof(OSVersionKextsDirName), "%a.0", OSVersion);
} else {
OSVersionKextsDirName = SWPrintf("%s", OSVersion);
OSVersionKextsDirName = SWPrintf("%s", OSVersion.c_str());
// snwprintf(OSVersionKextsDirName, sizeof(OSVersionKextsDirName), "%a", OSVersion);
}
DirPath = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), OSVersionKextsDirName.wc_str());
// snwprintf(DirPath, sizeof(DirPath), "%s\\kexts\\%s", OEMPath, OSVersionKextsDirName);
AddKexts(DirPath.wc_str(), OSVersionKextsDirName.wc_str(), archCpuType);
AddKexts(DirPath, OSVersionKextsDirName, archCpuType);
if ( OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
DirName = SWPrintf("%ls_install", OSVersionKextsDirName.wc_str());
@ -511,7 +510,7 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
}
DirPath = SWPrintf("%ls\\kexts\\%ls", OEMPath.wc_str(), DirName.wc_str());
// snwprintf(DirPath, sizeof(DirPath), "%s\\kexts\\%s", OEMPath, DirName);
AddKexts(DirPath.wc_str(), DirName.wc_str(), archCpuType);
AddKexts(DirPath, DirName, archCpuType);
}
@ -825,15 +824,14 @@ EFI_STATUS LOADER_ENTRY::InjectKexts(IN UINT32 deviceTreeP, IN UINT32* deviceTre
DBG_RT(" %llu - %s\n", Index, (CHAR8 *)(UINTN)drvinfo->bundlePathPhysAddr);
DBG(" %llu - %s\n", Index, (CHAR8 *)(UINTN)drvinfo->bundlePathPhysAddr);
if (gSettings.KextPatchesAllowed) {
INT32 i;
CHAR8 SavedValue;
CHAR8 *InfoPlist = (CHAR8*)(UINTN)drvinfo->infoDictPhysAddr;
SavedValue = InfoPlist[drvinfo->infoDictLength];
InfoPlist[drvinfo->infoDictLength] = '\0';
// KernelAndKextPatcherInit();
for (i = 0; i < KernelAndKextPatches.NrKexts; i++) {
if ((KernelAndKextPatches.KextPatches[i].DataLen > 0) &&
(AsciiStrStr(InfoPlist, KernelAndKextPatches.KextPatches[i].Name) != NULL)) {
for (size_t i = 0; i < KernelAndKextPatches.KextPatches.size(); i++) {
if ((KernelAndKextPatches.KextPatches[i].Data.size() > 0) &&
(AsciiStrStr(InfoPlist, KernelAndKextPatches.KextPatches[i].Name.c_str()) != NULL)) {
AnyKextPatch(
(UINT8*)(UINTN)drvinfo->executablePhysAddr,
drvinfo->executableLength,
@ -975,7 +973,7 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch()
// E8 ?? 00 00 00 EB 05 E8 -->
// E8 ?? 00 00 00 90 90 E8.
UINTN procLocation = searchProc("readStartupExtensions");
UINTN procLocation = searchProc("readStartupExtensions"_XS8);
const UINT8 findJmp[] = {0xEB, 0x05};
const UINT8 patchJmp[] = {0x90, 0x90};
DBG("==> readStartupExtensions at %llx\n", procLocation);
@ -1075,8 +1073,8 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch()
//ffffff80009a2273 85C0 test eax, eax =>change to eb06 -> jmp .+6
//ffffff80009a2275 0F843C010000 je 0xffffff80009a23b7
//ffffff80009a227b
UINTN taskLocation = searchProc("IOTaskHasEntitlement");
procLocation = searchProc("loadExecutable");
UINTN taskLocation = searchProc("IOTaskHasEntitlement"_XS8);
procLocation = searchProc("loadExecutable"_XS8);
patchLocation2 = FindMemMask(&KernelData[procLocation], 0x500, find3, sizeof(find3), mask3, sizeof(mask3));
DBG("IOTaskHasEntitlement at 0x%llx, loadExecutable at 0x%llx\n", taskLocation, procLocation);
DBG("find3 at 0x%llx\n", patchLocation2);
@ -1147,7 +1145,7 @@ VOID EFIAPI LOADER_ENTRY::KernelBooterExtensionsPatch()
//Slice - hope this patch useful for some system that I have no.
// KxldUnmap by vit9696
// Avoid race condition in OSKext::removeKextBootstrap when using booter kexts without keepsyms=1.
procLocation = searchProc("removeKextBootstrap");
procLocation = searchProc("removeKextBootstrap"_XS8);
const UINT8 find5[] = {0x00, 0x0F, 0x85, 00, 00, 0x00, 0x00, 0x48 };
const UINT8 mask5[] = {0xFF, 0xFF, 0xFF, 00, 00, 0xFF, 0xFF, 0xFF };
patchLocation3 = FindMemMask(&KernelData[procLocation], 0x300, find5, sizeof(find5), mask5, sizeof(mask5));

View File

@ -208,14 +208,15 @@ UINTN SearchAndReplaceMask(UINT8 *Source, UINT64 SourceSize, const UINT8 *Search
}
UINTN SearchAndReplaceTxt(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINTN SearchSize, UINT8 *Replace, INTN MaxReplaces)
UINTN SearchAndReplaceTxt(UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, UINTN SearchSize, const UINT8 *Replace, INTN MaxReplaces)
{
UINTN NumReplaces = 0;
UINTN Skip = 0;
BOOLEAN NoReplacesRestriction = MaxReplaces <= 0;
UINT8 *End = Source + SourceSize;
UINT8 *SearchEnd = Search + SearchSize;
UINT8 *Pos = NULL;
const UINT8 *SearchEnd = Search + SearchSize;
const UINT8 *Pos = NULL;
UINT8 *SourcePos = NULL;
UINT8 *FirstMatch = Source;
if (!Source || !Search || !Replace || !SearchSize) {
return 0;
@ -242,11 +243,11 @@ UINTN SearchAndReplaceTxt(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINTN
}
if (Pos == SearchEnd) { // pattern found
Pos = FirstMatch;
SourcePos = FirstMatch;
break;
}
else
Pos = NULL;
SourcePos = NULL;
Source = FirstMatch + 1;
/* if (Pos != Search) {
@ -255,11 +256,11 @@ UINTN SearchAndReplaceTxt(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINTN
}
if (!Pos) {
if (!SourcePos) {
break;
}
CopyMem(Pos, Replace, SearchSize);
SetMem(Pos + SearchSize, Skip, 0x20); //fill skip places with spaces
CopyMem(SourcePos, Replace, SearchSize);
SetMem(SourcePos + SearchSize, Skip, 0x20); //fill skip places with spaces
NumReplaces++;
MaxReplaces--;
Source = FirstMatch + SearchSize + Skip;
@ -366,13 +367,13 @@ VOID LOADER_ENTRY::ATIConnectorsPatchInit()
sizeof(ATIKextBundleId[0]),
"com.apple.kext.ATI%sController", // when it was AsciiSPrint, %a was used with KPATIConnectorsController which is CHAR16 ??? Result is printing stop at first char <= 255
//now it is CHAR8*
KernelAndKextPatches.KPATIConnectorsController
KernelAndKextPatches.KPATIConnectorsController.c_str()
);
// ML
snprintf(ATIKextBundleId[1],
sizeof(ATIKextBundleId[1]),
"com.apple.kext.AMD%sController", // when it was AsciiSPrint, %a was used with KPATIConnectorsController which is CHAR16 ??? Result is printing stop at first char <= 255
KernelAndKextPatches.KPATIConnectorsController
KernelAndKextPatches.KPATIConnectorsController.c_str()
);
ATIConnectorsPatchInited = TRUE;
@ -391,11 +392,11 @@ VOID LOADER_ENTRY::ATIConnectorsPatchRegisterKexts(void *FSInject_v, void *Force
FSI_STRING_LIST *ForceLoadKexts = (FSI_STRING_LIST *)ForceLoadKexts_v;
// for future?
FSInject->AddStringToList(ForceLoadKexts,
SWPrintf("\\AMD%sController.kext\\Contents\\Info.plist", KernelAndKextPatches.KPATIConnectorsController).wc_str()
SWPrintf("\\AMD%sController.kext\\Contents\\Info.plist", KernelAndKextPatches.KPATIConnectorsController.c_str()).wc_str()
);
// Lion, ML, SnowLeo 10.6.7 2011 MBP
FSInject->AddStringToList(ForceLoadKexts,
SWPrintf("\\ATI%sController.kext\\Contents\\Info.plist", KernelAndKextPatches.KPATIConnectorsController).wc_str()
SWPrintf("\\ATI%sController.kext\\Contents\\Info.plist", KernelAndKextPatches.KPATIConnectorsController.c_str()).wc_str()
);
// SnowLeo
FSInject->AddStringToList(ForceLoadKexts, L"\\ATIFramebuffer.kext\\Contents\\Info.plist");
@ -419,12 +420,12 @@ VOID LOADER_ENTRY::ATIConnectorsPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *I
UINTN Num = 0;
DBG_RT("\nATIConnectorsPatch: driverAddr = %llx, driverSize = %x\nController = %s\n",
(UINTN)Driver, DriverSize, KernelAndKextPatches.KPATIConnectorsController);
(UINTN)Driver, DriverSize, KernelAndKextPatches.KPATIConnectorsController.c_str());
ExtractKextBundleIdentifier(InfoPlist);
DBG_RT("Kext: %s\n", gKextBundleIdentifier);
// number of occurences od Data should be 1
Num = SearchAndCount(Driver, DriverSize, KernelAndKextPatches.KPATIConnectorsData, KernelAndKextPatches.KPATIConnectorsDataLen);
Num = SearchAndCount(Driver, DriverSize, KernelAndKextPatches.KPATIConnectorsData.data(), KernelAndKextPatches.KPATIConnectorsData.size());
if (Num > 1) {
// error message - shoud always be printed
printf("==> KPATIConnectorsData found %llu times in %s - skipping patching!\n", Num, gKextBundleIdentifier);
@ -435,9 +436,9 @@ VOID LOADER_ENTRY::ATIConnectorsPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *I
// patch
Num = SearchAndReplace(Driver,
DriverSize,
KernelAndKextPatches.KPATIConnectorsData,
KernelAndKextPatches.KPATIConnectorsDataLen,
KernelAndKextPatches.KPATIConnectorsPatch,
KernelAndKextPatches.KPATIConnectorsData.data(),
KernelAndKextPatches.KPATIConnectorsData.size(),
KernelAndKextPatches.KPATIConnectorsPatch.data(),
1);
if (Num > 0) {
DBG_RT("==> patched %llu times!\n", Num);
@ -628,7 +629,7 @@ VOID LOADER_ENTRY::AppleRTCPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPl
#else
//RodionS
UINTN procLocation = searchProcInDriver(Driver, DriverSize, "updateChecksum");
UINTN procLocation = searchProcInDriver(Driver, DriverSize, "updateChecksum"_XS8);
DBG("updateChecksum at 0x%llx\n", procLocation);
if (procLocation != 0) {
if ((((struct mach_header_64*)KernelData)->filetype) == MH_KERNEL_COLLECTION) {
@ -752,13 +753,13 @@ VOID LOADER_ENTRY::SNBE_AICPUPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
DBG_RT("Kext: %s\n", gKextBundleIdentifier);
// now let's patch it
if (os_ver < AsciiOSVersionToUint64("10.9") || os_ver >= AsciiOSVersionToUint64("10.14")) {
if (os_ver < AsciiOSVersionToUint64("10.9"_XS8) || os_ver >= AsciiOSVersionToUint64("10.14"_XS8)) {
DBG("Unsupported macOS.\nSandyBridge-E requires macOS 10.9 - 10.13.x, aborted\n");
DBG("SNBE_AICPUPatch() <===FALSE\n");
return;
}
if (os_ver < AsciiOSVersionToUint64("10.10")) {
if (os_ver < AsciiOSVersionToUint64("10.10"_XS8)) {
// 10.9.x
const UINT8 find[][3] = {
{ 0x84, 0x2F, 0x01 },
@ -786,7 +787,7 @@ VOID LOADER_ENTRY::SNBE_AICPUPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
DBG("SNBE_AICPUPatch (%d/7) not apply\n", i);
}
}
} else if (os_ver < AsciiOSVersionToUint64("10.11")) {
} else if (os_ver < AsciiOSVersionToUint64("10.11"_XS8)) {
// 10.10.x
const UINT8 find[][3] = {
{ 0x3E, 0x75, 0x39 },
@ -838,7 +839,7 @@ VOID LOADER_ENTRY::SNBE_AICPUPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
} else {
DBG("SNBE_AICPUPatch (7/7) not apply\n");
}
} else if (os_ver < AsciiOSVersionToUint64("10.12")) {
} else if (os_ver < AsciiOSVersionToUint64("10.12"_XS8)) {
// 10.11
const UINT8 find[][3] = {
{ 0x3E, 0x75, 0x39 },
@ -889,7 +890,7 @@ VOID LOADER_ENTRY::SNBE_AICPUPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
} else {
DBG("SNBE_AICPUPatch (7/7) not apply\n");
}
} else if (os_ver < AsciiOSVersionToUint64("10.13")) {
} else if (os_ver < AsciiOSVersionToUint64("10.13"_XS8)) {
// 10.12
const UINT8 find[][3] = {
{ 0x01, 0x74, 0x61 },
@ -940,7 +941,7 @@ VOID LOADER_ENTRY::SNBE_AICPUPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
} else {
DBG("SNBE_AICPUPatch (7/7) not apply\n");
}
} else if (os_ver < AsciiOSVersionToUint64("10.15")) {
} else if (os_ver < AsciiOSVersionToUint64("10.15"_XS8)) {
// 10.13/10.14
const UINT8 find[][3] = {
{ 0x01, 0x74, 0x61 },
@ -1030,9 +1031,9 @@ VOID LOADER_ENTRY::BDWE_IOPCIPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *Info
// now, let's patch it!
//
if (os_ver < AsciiOSVersionToUint64("10.12")) {
if (os_ver < AsciiOSVersionToUint64("10.12"_XS8)) {
count = SearchAndReplace(Driver, DriverSize, BroadwellE_IOPCI_Find_El, sizeof(BroadwellE_IOPCI_Find_El), BroadwellE_IOPCI_Repl_El, 0);
} else if (os_ver < AsciiOSVersionToUint64("10.14")) {
} else if (os_ver < AsciiOSVersionToUint64("10.14"_XS8)) {
count = SearchAndReplace(Driver, DriverSize, BroadwellE_IOPCI_Find_SieHS, sizeof(BroadwellE_IOPCI_Find_SieHS), BroadwellE_IOPCI_Repl_SieHS, 0);
} else {
count = SearchAndReplace(Driver, DriverSize, BroadwellE_IOPCI_Find_MojCata, sizeof(BroadwellE_IOPCI_Find_MojCata), BroadwellE_IOPCI_Repl_MojCata, 0);
@ -1051,8 +1052,8 @@ VOID LOADER_ENTRY::EightApplePatch(UINT8 *Driver, UINT32 DriverSize)
{
// UINTN procLen = 0;
DBG("8 apple patch\n");
UINTN procAddr = searchProcInDriver(Driver, DriverSize, "initFB");
UINTN verbose = searchProcInDriver(Driver, DriverSize, "gIOFBVerboseBoot");
UINTN procAddr = searchProcInDriver(Driver, DriverSize, "initFB"_XS8);
UINTN verbose = searchProcInDriver(Driver, DriverSize, "gIOFBVerboseBoot"_XS8);
if (procAddr != 0) {
UINTN patchLoc;
@ -1105,18 +1106,17 @@ VOID LOADER_ENTRY::EightApplePatch(UINT8 *Driver, UINT32 DriverSize)
// Generic kext patch functions
//
//
VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N)
VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, size_t N)
{
UINTN Num = 0;
INTN Ind;
// if we modify value directly at KernelAndKextPatches->KextPatches[N].SearchLen, it will be wrong for next driver
UINTN SearchLen = KernelAndKextPatches.KextPatches[N].SearchLen;
DBG_RT("\nAnyKextPatch %d: driverAddr = %llx, driverSize = %x\nAnyKext = %s\n",
N, (UINTN)Driver, DriverSize, KernelAndKextPatches.KextPatches[N].Label);
DBG("\nAnyKextPatch %d: driverAddr = %llx, driverSize = %x\nLabel = %s\n",
N, (UINTN)Driver, DriverSize, KernelAndKextPatches.KextPatches[N].Label);
DBG_RT("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\nAnyKext = %s\n",
N, (UINTN)Driver, DriverSize, KernelAndKextPatches.KextPatches[N].Label.c_str());
DBG("\nAnyKextPatch %zu: driverAddr = %llx, driverSize = %x\nLabel = %s\n",
N, (UINTN)Driver, DriverSize, KernelAndKextPatches.KextPatches[N].Label.c_str());
if (!KernelAndKextPatches.KextPatches[N].MenuItem.BValue) {
return;
@ -1152,20 +1152,20 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
while (j < DriverSize) {
if (!KernelAndKextPatches.KextPatches[N].StartPattern || //old behavior
CompareMemMask((const UINT8*)curs,
(const UINT8 *)KernelAndKextPatches.KextPatches[N].StartPattern,
KernelAndKextPatches.KextPatches[N].StartPatternLen,
(const UINT8 *)KernelAndKextPatches.KextPatches[N].StartMask,
KernelAndKextPatches.KextPatches[N].StartPatternLen)) {
KernelAndKextPatches.KextPatches[N].StartPattern.data(),
KernelAndKextPatches.KextPatches[N].StartPattern.size(),
KernelAndKextPatches.KextPatches[N].StartMask.data(),
KernelAndKextPatches.KextPatches[N].StartPattern.size())) {
DBG_RT(" StartPattern found\n");
Num = SearchAndReplaceMask(curs,
procLen,
(const UINT8*)KernelAndKextPatches.KextPatches[N].Data,
(const UINT8*)KernelAndKextPatches.KextPatches[N].MaskFind,
KernelAndKextPatches.KextPatches[N].DataLen,
(const UINT8*)KernelAndKextPatches.KextPatches[N].Patch,
(const UINT8*)KernelAndKextPatches.KextPatches[N].MaskReplace,
-1);
KernelAndKextPatches.KextPatches[N].Data.data(),
KernelAndKextPatches.KextPatches[N].MaskFind.data(),
KernelAndKextPatches.KextPatches[N].Data.size(),
KernelAndKextPatches.KextPatches[N].Patch.data(),
KernelAndKextPatches.KextPatches[N].MaskReplace.data(),
KernelAndKextPatches.KextPatches[N].Count);
if (Num) {
curs += SearchLen - 1;
j += SearchLen - 1;
@ -1173,7 +1173,7 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
}
if (once ||
!KernelAndKextPatches.KextPatches[N].StartPattern ||
!KernelAndKextPatches.KextPatches[N].StartPatternLen) {
!KernelAndKextPatches.KextPatches[N].StartPattern.size()) {
break;
}
j++; curs++;
@ -1181,21 +1181,21 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
} else {
// Info plist patch
DBG_RT("Info.plist data : '");
for (Ind = 0; Ind < KernelAndKextPatches.KextPatches[N].DataLen; Ind++) {
for (size_t Ind = 0; Ind < KernelAndKextPatches.KextPatches[N].Data.size(); Ind++) {
DBG_RT("%c", KernelAndKextPatches.KextPatches[N].Data[Ind]);
}
DBG_RT("' ->\n");
DBG_RT("Info.plist patch: '");
for (Ind = 0; Ind < KernelAndKextPatches.KextPatches[N].DataLen; Ind++) {
for (size_t Ind = 0; Ind < KernelAndKextPatches.KextPatches[N].Data.size(); Ind++) {
DBG_RT("%c", KernelAndKextPatches.KextPatches[N].Patch[Ind]);
}
DBG_RT("' \n");
Num = SearchAndReplaceTxt((UINT8*)InfoPlist,
InfoPlistSize,
KernelAndKextPatches.KextPatches[N].Data,
KernelAndKextPatches.KextPatches[N].DataLen,
KernelAndKextPatches.KextPatches[N].Patch,
KernelAndKextPatches.KextPatches[N].Data.data(),
KernelAndKextPatches.KextPatches[N].Data.size(),
KernelAndKextPatches.KextPatches[N].Patch.data(),
-1);
}
@ -1216,13 +1216,13 @@ VOID LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
VOID LOADER_ENTRY::KextPatcherRegisterKexts(void *FSInject_v, void *ForceLoadKexts)
{
FSINJECTION_PROTOCOL *FSInject = (FSINJECTION_PROTOCOL *)FSInject_v;
if (KernelAndKextPatches.KPATIConnectorsController != NULL) {
if (KernelAndKextPatches.KPATIConnectorsController.notEmpty()) {
ATIConnectorsPatchRegisterKexts(FSInject_v, ForceLoadKexts);
}
for (INTN i = 0; i < KernelAndKextPatches.NrKexts; i++) {
for (size_t i = 0; i < KernelAndKextPatches.KextPatches.size(); i++) {
FSInject->AddStringToList((FSI_STRING_LIST*)ForceLoadKexts,
SWPrintf("\\%s.kext\\Contents\\Info.plist", KernelAndKextPatches.KextPatches[i].Name).wc_str() );
SWPrintf("\\%s.kext\\Contents\\Info.plist", KernelAndKextPatches.KextPatches[i].Name.c_str()).wc_str() );
}
}
@ -1232,7 +1232,7 @@ VOID LOADER_ENTRY::KextPatcherRegisterKexts(void *FSInject_v, void *ForceLoadKex
//
VOID LOADER_ENTRY::PatchKext(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize)
{
if (KernelAndKextPatches.KPATIConnectorsController != NULL) {
if (KernelAndKextPatches.KPATIConnectorsController.notEmpty()) {
//
// ATIConnectors
//
@ -1301,13 +1301,13 @@ VOID LOADER_ENTRY::PatchKext(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist,
}
//com.apple.iokit.IOGraphicsFamily
for (INT32 i = 0; i < KernelAndKextPatches.NrKexts; i++) {
CHAR8 *Name = KernelAndKextPatches.KextPatches[i].Name;
BOOLEAN isBundle = (AsciiStrStr(Name, ".") != NULL);
if ((KernelAndKextPatches.KextPatches[i].DataLen > 0) &&
isBundle?(AsciiStrCmp(gKextBundleIdentifier, Name) == 0):(AsciiStrStr(gKextBundleIdentifier, Name) != NULL)) {
for (size_t i = 0; i < KernelAndKextPatches.KextPatches.size(); i++) {
XString8& Name = KernelAndKextPatches.KextPatches[i].Name;
BOOLEAN isBundle = Name.contains(".");
if ((KernelAndKextPatches.KextPatches[i].Data.size() > 0) &&
isBundle?(AsciiStrCmp(gKextBundleIdentifier, Name.c_str()) == 0):(AsciiStrStr(gKextBundleIdentifier, Name.c_str()) != NULL)) {
// (AsciiStrStr(InfoPlist, KernelAndKextPatches.KextPatches[i].Name) != NULL)) {
DBG_RT("\n\nPatch kext: %s\n", KernelAndKextPatches.KextPatches[i].Name);
DBG_RT("\n\nPatch kext: %s\n", KernelAndKextPatches.KextPatches[i].Name.c_str());
AnyKextPatch(Driver, DriverSize, InfoPlist, InfoPlistSize, i);
}
}

View File

@ -641,7 +641,8 @@ VOID SetDMISettingsForModel(MACHINE_TYPES Model, BOOLEAN Redefine)
break;
}
AsciiStrCpyS (gSettings.EfiVersion, 64, ApplePlatformData[Model].efiversion);
gSettings.EfiVersion.takeValueFrom(ApplePlatformData[Model].efiversion);
gSettings.EfiVersion.trim();
AsciiStrCpyS (gSettings.ManufactureName, 64, BiosVendor);
if (Redefine) {
AsciiStrCpyS (gSettings.ProductName, 64, ApplePlatformData[Model].productName);

View File

@ -468,8 +468,8 @@ VOID PatchTableType0()
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->Vendor, gSettings.VendorName);
}
if(iStrLen(gSettings.RomVersion, 64)>0){
if(iStrLen(gSettings.EfiVersion, 64)>0){
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosVersion, gSettings.EfiVersion);
if( gSettings.EfiVersion.notEmpty() ) {
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosVersion, gSettings.EfiVersion.c_str());
} else {
UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type0->BiosVersion, gSettings.RomVersion);
}

View File

@ -203,7 +203,7 @@ void XArray<TYPE>::CheckSize(size_t nNewSize)
template<class TYPE>
void XArray<TYPE>::setSize(size_t l)
{
CheckSize(l, XArrayGrowByDefault); // be sure the size is allocated
CheckSize(l, 0); // be sure the size is allocated
m_len = l;
#ifdef DEBUG
if(m_len > m_allocatedSize) {

View File

@ -1,277 +1,269 @@
//*************************************************************************************************
////*************************************************************************************************
////
//// Buffer
////
////*************************************************************************************************
//
// Buffer
//#if !defined(__XBUFFER_CPP__)
//#define __XBUFFER_CPP__
//
//*************************************************************************************************
#if !defined(__XBUFFER_CPP__)
#define __XBUFFER_CPP__
#include <XToolsConf.h>
#include "XToolsCommon.h"
#include "XBuffer.h"
//#include "../JiefDevTools/XConstString.h"
#include "XString.h"
const XBuffer NullXBuffer;
//*************************************************************************************************
void XBuffer::Initialize(const unsigned char* p, size_t count, size_t index)
{
if ( p!=NULL && count>0 )
{
m_allocatedSize = count;
_WData = (unsigned char*)malloc(m_allocatedSize);
if ( !_WData ) {
panic("XBuffer::Initialize(%zu) : malloc returned NULL. System halted\n", count);
}
memcpy(_WData, p, count);
_RData = _WData;
_Len = count;
_Index = index;
}
else{
m_allocatedSize = 0;
_WData = NULL;
_RData = NULL;
_Len = 0;
_Index = 0;
}
}
//-------------------------------------------------------------------------------------------------
// CheckSize
//-------------------------------------------------------------------------------------------------
void XBuffer::CheckSize(size_t nNewSize, size_t nGrowBy)
{
if ( m_allocatedSize < nNewSize )
{
nNewSize += nGrowBy;
_WData = (unsigned char*)Xrealloc(_WData, nNewSize, m_allocatedSize);
if ( !_WData ) {
panic("XBuffer::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR " %zu, %zu) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(_WData), nNewSize, m_allocatedSize);
}
_RData = _WData;
m_allocatedSize = nNewSize;
}
}
//-------------------------------------------------------------------------------------------------
// ctor
//-------------------------------------------------------------------------------------------------
XBuffer::XBuffer() : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
Initialize(NULL, 0, 0);
}
XBuffer::XBuffer(XRBuffer &aXRBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
if ( pos < aXRBuffer.Length() ) {
Initialize(NULL, 0, 0);
}else{
if ( count > aXRBuffer.Length()-pos ) count = aXRBuffer.Length()-pos;
Initialize(aXRBuffer.UCData(pos), count, aXRBuffer.Index());
}
}
XBuffer::XBuffer(XBuffer &aXBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
if ( pos >= aXBuffer.Length() ) {
Initialize(NULL, 0, 0);
}else{
if ( count > aXBuffer.Length()-pos ) count = aXBuffer.Length()-pos;
Initialize(aXBuffer.UCData(pos), count, aXBuffer.Index());
}
}
XBuffer::XBuffer(void *p, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
Initialize((const unsigned char*)p, count, 0);
}
XBuffer::~XBuffer()
{
free(_WData);
}
//-------------------------------------------------------------------------------------------------
// operator =, +=
//-------------------------------------------------------------------------------------------------
const XBuffer &XBuffer::operator =(const XRBuffer &aBuffer)
{
//TRACE("Operator =const XBuffer&\n");
Cpy(aBuffer.Data(), aBuffer.Length());
SetIndex(aBuffer.Index());
return *this;
}
const XBuffer &XBuffer::operator =(const XBuffer &aBuffer)
{
//TRACE("Operator =const XBuffer&\n");
Cpy(aBuffer.Data(), aBuffer.Length());
SetIndex(aBuffer.Index());
return *this;
}
const XBuffer &XBuffer::operator +=(const XRBuffer &aBuffer)
{
//TRACE("Operator +=const XBuffer&\n");
Cat(aBuffer.Data(), aBuffer.Length());
return *this;
}
//-------------------------------------------------------------------------------------------------
// Cpy, Cat, Delete
//-------------------------------------------------------------------------------------------------
void XBuffer::Cpy(const void *buf, size_t len)
{
if ( buf && len > 0 ) {
CheckSize(len, 0); // GrowBy <20> 0
memcpy(Data(), buf, len);
SetLength(len);
}
}
void XBuffer::Cat(const void *buf, size_t len)
{
if ( buf && len > 0 ) {
CheckSize(Length()+len);
memcpy(Data(Length()), buf, len);
SetLength(Length()+len);
}
}
void XBuffer::Cat(const XString8 &aXString8)
{
Cat(aXString8.sizeInBytes());
Cat(aXString8.data(),aXString8.sizeInBytes());
};
void XBuffer::Delete(unsigned int pos, unsigned int count)
{
if ( pos < Length() ) {
if ( pos + count < Length() ) {
memmove( _WData+pos, _WData+pos+count, Length()-pos-count);
SetLength(Length()-count);
}else{
SetLength(pos);
}
}
}
//-------------------------------------------------------------------------------------------------
// ReadFrom
//-------------------------------------------------------------------------------------------------
//bool XBuffer::ReadFileName(const char* FileName, unsigned int AddZeros)
//#include <XToolsConf.h>
//#include "XToolsCommon.h"
//
//#include "XRBuffer.h"
//#include "XBuffer.h"
//
////#include "../JiefDevTools/XConstString.h"
//#include "XString.h"
//
////const XBuffer NullXBuffer;
//
////*************************************************************************************************
//template <typename T>
//void XBuffer<T>::Initialize(T* p, size_t count, size_t index)
//{
// FILE *fp;
// long int ulen;
// unsigned int len;
//
// fp = fopen(FileName, "rb");
// if ( fp == NULL ) {
// SetLastErrorMsgf("Impossible d'ouvrir le fichier en lecture '%s'", FileName);
// goto finally;
// if ( p!=NULL && count>0 )
// {
// m_allocatedSize = count;
// _WData = (unsigned char*)malloc(m_allocatedSize);
// if ( !_WData ) {
// panic("XBuffer<T>::Initialize(%zu) : malloc returned NULL. System halted\n", count);
// }
//
// fseek(fp, 0, 2); // Seek to end of file
// ulen = ftell(fp);
// if ( ulen <= 0 ) {
// SetLastErrorMsgf("Impossible d'avoir la longueur du fichier '%s'", FileName);
// goto finally;
// memcpy(_WData, p, count);
// XRBuffer<T>::_RData = _WData;
// XRBuffer<T>::_Len = count;
// XRBuffer<T>::_Index = index;
// }
//
// len = (unsigned int)ulen;
// fseek(fp, 0, 0);
//
// if ( fread(CDataWithSizeMin(0, len+AddZeros), 1, len, fp) != len ) {
// SetLastErrorMsgf("Impossible de lire %d octets du fichier '%s'", len, FileName);
// goto finally;
// else{
// m_allocatedSize = 0;
// _WData = NULL;
// XRBuffer<T>::_RData = NULL;
// XRBuffer<T>::_Len = 0;
// XRBuffer<T>::_Index = 0;
// }
// SetLength(len);
// SetIndex(0);
// if ( fclose(fp) != 0 ) {
// SetLastErrorMsgf("Impossible de fermer les fichier '%s'", FileName);
// goto finally;
// }
// {for ( unsigned int ui=len ; ui<len+AddZeros ; ui+=1 ) *CData(ui) = 0;}
// return YES;
// finally:
// if ( fp != NULL ) fclose(fp);
// SetLength(0);
// return false;
//
//}
//bool XBuffer::ReadFromFILE(FILE *fp)
//{
// unsigned int longueur;
//
// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin;
// if ( longueur > 0 && fread(DataWithSizeMin(0, longueur, 0), longueur, 1, fp) != 1 ) goto fin;
////-------------------------------------------------------------------------------------------------
//// CheckSize
////-------------------------------------------------------------------------------------------------
//template <typename T>
//void XBuffer<T>::CheckSize(size_t nNewSize, size_t nGrowBy)
//{
// if ( m_allocatedSize < nNewSize )
// {
// nNewSize += nGrowBy;
// _WData = (unsigned char*)Xrealloc(_WData, nNewSize, m_allocatedSize);
// if ( !_WData ) {
// panic("XBuffer<T>::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR " %zu, %zu) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(_WData), nNewSize, m_allocatedSize);
// }
// XRBuffer<T>::_RData = _WData;
// m_allocatedSize = nNewSize;
// }
//}
//
////-------------------------------------------------------------------------------------------------
//// ctor
////-------------------------------------------------------------------------------------------------
//
//template <typename T>
//XBuffer<T>::XBuffer() : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
//{
// Initialize(NULL, 0, 0);
//}
//
//template <typename T>
//XBuffer<T>::XBuffer(XRBuffer<T> &aXRBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
//{
// if ( pos < aXRBuffer.Length() ) {
// Initialize(NULL, 0, 0);
// }else{
// if ( count > aXRBuffer.Length()-pos ) count = aXRBuffer.Length()-pos;
// Initialize(aXRBuffer.UCData(pos), count, aXRBuffer.Index());
// }
//}
//
//template <typename T>
//XBuffer<T>::XBuffer(XBuffer &aXBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
//{
// if ( pos >= aXBuffer.Length() ) {
// Initialize(NULL, 0, 0);
// }else{
// if ( count > aXBuffer.Length()-pos ) count = aXBuffer.Length()-pos;
// Initialize(aXBuffer.UCData(pos), count, aXBuffer.Index());
// }
//}
//
//template <typename T>
//XBuffer<T>::XBuffer(void *p, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
//{
// Initialize((const unsigned char*)p, count, 0);
//}
//
//template <typename T>
//XBuffer<T>::~XBuffer()
//{
// free(_WData);
//}
//
////-------------------------------------------------------------------------------------------------
//// operator =, +=
////-------------------------------------------------------------------------------------------------
//template <typename T>
//const XBuffer<T>& XBuffer<T>::operator =(const XRBuffer<T> &aBuffer)
//{
////TRACE("Operator =const XBuffer&\n");
// Cpy(aBuffer.Data(), aBuffer.Length());
// SetIndex(aBuffer.Index());
// return *this;
//}
//
//template <typename T>
//const XBuffer<T>& XBuffer<T>::operator =(const XBuffer<T> &aBuffer)
//{
////TRACE("Operator =const XBuffer&\n");
// Cpy(aBuffer.Data(), aBuffer.Length());
// SetIndex(aBuffer.Index());
// return *this;
//}
//
//template <typename T>
//const XBuffer<T> &XBuffer<T>::operator +=(const XRBuffer<T> &aBuffer)
//{
////TRACE("Operator +=const XBuffer&\n");
// Cat(aBuffer.Data(), aBuffer.Length());
// return *this;
//}
//
////-------------------------------------------------------------------------------------------------
//// Cpy, Cat, Delete
////-------------------------------------------------------------------------------------------------
//template <typename T>
//void XBuffer<T>::ncpy(const void *buf, size_t len)
//{
// if ( buf && len > 0 ) {
// CheckSize(len, 0); // GrowBy 0
// memcpy(data(), buf, len);
// SetLength(len);
// }
//}
//
//template <typename T>
//void XBuffer<T>::Cat(const void *buf, size_t len)
//{
// if ( buf && len > 0 ) {
// CheckSize(size()+len);
// memcpy(Data(size()), buf, len);
// SetLength(size()+len);
// }
//}
//
//template <typename T>
//void XBuffer<T>::Cat(const XString8 &aXString8)
//{
// Cat(aXString8.sizeInBytes());
// Cat(aXString8.data(),aXString8.sizeInBytes());
//};
//
//template <typename T>
//void XBuffer<T>::Delete(unsigned int pos, unsigned int count)
//{
// if ( pos < size() ) {
// if ( pos + count < size() ) {
// memmove( _WData+pos, _WData+pos+count, size()-pos-count);
// SetLength(size()-count);
// }else{
// SetLength(pos);
// }
// }
//}
//
////-------------------------------------------------------------------------------------------------
//// ReadFrom
////-------------------------------------------------------------------------------------------------
////bool XBuffer<T>::ReadFileName(const char* FileName, unsigned int AddZeros)
////{
//// FILE *fp;
//// long int ulen;
//// unsigned int len;
////
//// fp = fopen(FileName, "rb");
//// if ( fp == NULL ) {
//// SetLastErrorMsgf("Impossible d'ouvrir le fichier en lecture '%s'", FileName);
//// goto finally;
//// }
////
//// fseek(fp, 0, 2); // Seek to end of file
//// ulen = ftell(fp);
//// if ( ulen <= 0 ) {
//// SetLastErrorMsgf("Impossible d'avoir la longueur du fichier '%s'", FileName);
//// goto finally;
//// }
////
//// len = (unsigned int)ulen;
//// fseek(fp, 0, 0);
////
//// if ( fread(CDataWithSizeMin(0, len+AddZeros), 1, len, fp) != len ) {
//// SetLastErrorMsgf("Impossible de lire %d octets du fichier '%s'", len, FileName);
//// goto finally;
//// }
//// SetLength(len);
//// SetIndex(0);
//// if ( fclose(fp) != 0 ) {
//// SetLastErrorMsgf("Impossible de fermer les fichier '%s'", FileName);
//// goto finally;
//// }
//// {for ( unsigned int ui=len ; ui<len+AddZeros ; ui+=1 ) *CData(ui) = 0;}
//// return YES;
//// finally:
//// if ( fp != NULL ) fclose(fp);
//// SetLength(0);
//// return false;
////
////}
//
////bool XBuffer<T>::ReadFromFILE(FILE *fp)
////{
//// unsigned int longueur;
////
//// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin;
//// if ( longueur > 0 && fread(DataWithSizeMin(0, longueur, 0), longueur, 1, fp) != 1 ) goto fin;
//// SetLength(longueur);
//// SetIndex(0);
//// return OUI;
//// fin:
//// SetNull();
//// return NON;
////}
//
//template <typename T>
//bool XBuffer<T>::ReadFromXRBuffer(XRBuffer<T> &unXBuffer)
//{
// size_t longueur;
//
// if ( !unXBuffer.GetSize_t(&longueur) ) return false;
// if ( !unXBuffer.Get(DataWithSizeMin(0, longueur, 0), longueur) ) return false; // GrowBy (param 3 of DataWithSizeMin is 0 to avoid memory waste
// SetLength(longueur);
// SetIndex(0);
// return OUI;
// fin:
// SetNull();
// return NON;
// return true;
//}
bool XBuffer::ReadFromXBuffer(XRBuffer &unXBuffer)
{
size_t longueur;
if ( !unXBuffer.GetSize_t(&longueur) ) return false;
if ( !unXBuffer.Get(DataWithSizeMin(0, longueur, 0), longueur) ) return false; // GrowBy (param 3 de DataWithSizeMin est <20> 0 pour eviter du gachis m<>moire
SetLength(longueur);
SetIndex(0);
return true;
}
bool XBuffer::ReadFromBuf(const char *buf, size_t *idx, size_t count)
{
size_t longueur;
if ( count-*idx >= sizeof(longueur) ) {
longueur = *((size_t *)(buf+*idx));
*idx += sizeof(longueur);
if ( longueur > 0 && count-*idx>=longueur ) memcpy(DataWithSizeMin(0, longueur, 0), buf+*idx, longueur);
*idx += longueur;
SetLength(longueur);
SetIndex(0);
return true;
}else{
SetNull();
return false;
}
}
#ifdef __DEVTOOLS_SOCKETS__
void XBuffer::ReadFromSOCKETT(SOCKET Sock, unsigned int LenMax, unsigned int TO, unsigned int AddZeros, const char *ErrMsg)
{
unsigned int longueur;
SockReceiveT(Sock, &longueur, sizeof(longueur), TO, ErrMsg);
if ( longueur > LenMax ) Throw("Longueur re<72>ue (%d) sup<75>rieure <20> la longueur max (%d)", longueur, LenMax);
if ( longueur > 0 ) SockReceiveT(Sock, DataWithSizeMin(0, longueur+AddZeros, 0), longueur, TO, ErrMsg);
SetLength(longueur);
{for ( unsigned int ui=longueur ; ui<longueur+AddZeros ; ui+=1 ) *CData(ui) = 0;}
SetIndex(0);
}
bool XBuffer::ReadFromSOCKET(SOCKET Sock, unsigned int LenMax, unsigned int TO, unsigned int AddZeros, const char *ErrMsg)
{
try
{
ReadFromSOCKETT(Sock, LenMax, TO, AddZeros, ErrMsg);
SetLastErrorFlag(NON);
}
StdCatch();
return !LastErrorFlag();
}
#endif
#endif
//
//template <typename T>
//bool XBuffer<T>::ReadFromBuf(const char *buf, size_t *idx, size_t count)
//{
// size_t longueur;
//
// if ( count-*idx >= sizeof(longueur) ) {
// longueur = *((size_t *)(buf+*idx));
// *idx += sizeof(longueur);
// if ( longueur > 0 && count-*idx>=longueur ) memcpy(DataWithSizeMin(0, longueur, 0), buf+*idx, longueur);
// *idx += longueur;
// SetLength(longueur);
// SetIndex(0);
// return true;
// }else{
// SetNull();
// return false;
// }
//}
//
//#endif

View File

@ -15,49 +15,102 @@
#include "XString.h"
#define XBuffer_Super XRBuffer
#define XBuffer_Super XRBuffer<T>
template <typename T>
class XBuffer : public XBuffer_Super
{
protected:
unsigned char*_WData; // same as RData (see XRBuffer)
T*_WData; // same as RData (see XRBuffer)
size_t m_allocatedSize;
void Initialize(const unsigned char* p, size_t count, size_t index);
void Initialize(T* p, size_t count, size_t index);
public:
XBuffer();
XBuffer(XRBuffer &aBuffer, size_t pos = 0, size_t count = MAX_XSIZE);
XBuffer(XBuffer &aBuffer, size_t pos = 0, size_t count = MAX_XSIZE);
XBuffer() : _WData(NULL), m_allocatedSize(0) { Initialize(NULL, 0, 0); } // ": _WData(NULL), m_allocatedSize(0)" to avoid effc++ warning
XBuffer(const XBuffer<T>& aBuffer) : _WData(NULL), m_allocatedSize(0) { Initialize(aBuffer.data(), aBuffer.size(), aBuffer.index()); }
XBuffer(XRBuffer<T> &aBuffer, size_t pos = 0, size_t count = MAX_XSIZE);
// XBuffer(XBuffer &aBuffer, size_t pos = 0, size_t count = MAX_XSIZE);
XBuffer(void *p, size_t count);
const XBuffer &operator =(const XRBuffer &aBuffer);
const XBuffer &operator =(const XRBuffer<T> &aBuffer);
const XBuffer &operator =(const XBuffer &aBuffer);
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void stealValueFrom(T* p, IntegralType count) {
if ( count < 0 ) {
panic("XBuffer::stealValueFrom : count < 0. System halted\n");
}
if( _WData ) free(_WData);
Initialize(p, count, 0);
}
~XBuffer();
public:
void CheckSize(size_t nNewSize, size_t nGrowBy = XBufferGrowByDefault);
// La red<65>finition de la m<>thode suivante ne devrait pas <20>tre n<>cessaire (je crois !). Et pourtant, si on l'enleve, <20>a ne compile pas...
const void *Data(size_t ui=0) const { return XBuffer_Super::Data(ui); }
void *Data(size_t ui=0) { return _WData+ui; }
void *DataWithSizeMin(size_t ui, size_t size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return Data(ui); }
void* vdata() const { return XBuffer_Super::data(); }
T* data() const { return _WData; }
char *CData(size_t ui=0) { return (char *)(_WData+ui); }
char *CDataWithSizeMin(size_t ui, size_t size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return CData(ui); }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
const T* data(IntegralType i) const { return XBuffer_Super::data(i); }
unsigned char *UCData(size_t ui=0) { return _WData+ui; }
void *UCDataWithSizeMin(size_t ui, unsigned int size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return UCData(ui); }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T* dataSized(IntegralType size) {
if ( size < 0 ) {
panic("XBuffer::dataSized : size < 0. System halted\n");
}
CheckSize(size, 0);
return data();
}
size_t Size() const { return m_allocatedSize; }
void SetLength(size_t len) { _Len = len; };
// void *Data(size_t ui=0) { return _WData+ui; }
// void *DataWithSizeMin(size_t ui, size_t size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return Data(ui); }
//
// char *CData(size_t ui=0) { return (char *)(_WData+ui); }
// char *CDataWithSizeMin(size_t ui, size_t size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return CData(ui); }
//
// unsigned char *UCData(size_t ui=0) { return _WData+ui; }
// void *UCDataWithSizeMin(size_t ui, unsigned int size, size_t nGrowBy=XBufferGrowByDefault) { CheckSize(size, nGrowBy); return UCData(ui); }
/* IsNull ? */
void SetNull() { SetLength(0); };
size_t size() const { return XRBuffer<T>::size(); }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void setSize(IntegralType size) { CheckSize(size); XBuffer_Super::m_size = size; };
void setEmpty() { setSize(0); };
/* [] */
unsigned char& operator [](int i) { return UCData()[i]; } // underflow ? overflow ?
unsigned char& operator [](size_t i) { return UCData()[i]; }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
T& operator [](IntegralType i)
{
if (i < 0) panic("XBuffer::[] : i < 0. System halted\n");
if ( (unsigned_type(IntegralType))i >= size() ) panic("XBuffer::[] : i > _Len. System halted\n");
return _WData[(unsigned_type(IntegralType))i];
}
void Cpy(const void *buf, size_t len);
// unsigned char& operator [](int i) { return UCData()[i]; } // underflow ? overflow ?
// unsigned char& operator [](size_t i) { return UCData()[i]; }
void memset(unsigned char c) {
memset(_WData, c, size());
}
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void memset(unsigned char c, IntegralType count) {
if (count < 0) panic("XBuffer::memset : count < 0. System halted\n");
if ( (unsigned_type(IntegralType))count >= size() ) setSize(count);
::memset(_WData, c, count);
}
template<typename IntegralType1, typename IntegralType2, enable_if( is_integral(IntegralType1) && is_integral(IntegralType2) )>
void memsetAtPos(IntegralType1 pos, unsigned char c, IntegralType2 count) {
if (pos < 0) panic("XBuffer::memset : pos < 0. System halted\n");
if (count < 0) panic("XBuffer::memset : count < 0. System halted\n");
if ( (size_t)pos + (unsigned_type(IntegralType2))count >= size() ) setSize((size_t)pos + (unsigned_type(IntegralType2))count);
::memset(_WData, c, count);
}
void ncpy(const void *buf, size_t len);
// Cat
void Cat(const void *buf, size_t len);
@ -80,12 +133,258 @@ class XBuffer : public XBuffer_Super
void Cat(const XBuffer &unXBuffer) { Cat(unXBuffer.Length()); Cat(unXBuffer.Data(), unXBuffer.Length()); }
void Delete(unsigned int pos, unsigned int count=1);
const XBuffer &operator += (const XRBuffer &aBuffer);
const XBuffer &operator += (const XRBuffer<T> &aBuffer);
size_t Sizeof() const;
// bool ReadFileName(const char* FileName, unsigned int AddZeros=0);
bool ReadFromBuf(const char *buf, size_t *idx, size_t count);
bool ReadFromXBuffer(XRBuffer &unXBuffer);
bool ReadFromXRBuffer(XRBuffer<T> &unXBuffer);
};
//*************************************************************************************************
template <typename T>
void XBuffer<T>::Initialize(T* p, size_t count, size_t index)
{
if ( p!=NULL && count>0 )
{
m_allocatedSize = count;
_WData = (unsigned char*)malloc(m_allocatedSize);
if ( !_WData ) {
panic("XBuffer<T>::Initialize(%zu) : malloc returned NULL. System halted\n", count);
}
memcpy(_WData, p, count);
XRBuffer<T>::_RData = _WData;
XRBuffer<T>::m_size = count;
XRBuffer<T>::_Index = index;
}
else{
m_allocatedSize = 0;
_WData = NULL;
XRBuffer<T>::_RData = NULL;
XRBuffer<T>::m_size = 0;
XRBuffer<T>::_Index = 0;
}
}
//-------------------------------------------------------------------------------------------------
// CheckSize
//-------------------------------------------------------------------------------------------------
template <typename T>
void XBuffer<T>::CheckSize(size_t nNewSize, size_t nGrowBy)
{
if ( m_allocatedSize < nNewSize )
{
nNewSize += nGrowBy;
_WData = (unsigned char*)Xrealloc(_WData, nNewSize, m_allocatedSize);
if ( !_WData ) {
panic("XBuffer<T>::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR " %zu, %zu) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(_WData), nNewSize, m_allocatedSize);
}
XRBuffer<T>::_RData = _WData;
m_allocatedSize = nNewSize;
}
}
//-------------------------------------------------------------------------------------------------
// ctor
//-------------------------------------------------------------------------------------------------
template <typename T>
XBuffer<T>::XBuffer(XRBuffer<T> &aXRBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
if ( pos < aXRBuffer.Length() ) {
Initialize(NULL, 0, 0);
}else{
if ( count > aXRBuffer.Length()-pos ) count = aXRBuffer.Length()-pos;
Initialize(aXRBuffer.UCData(pos), count, aXRBuffer.Index());
}
}
//
//template <typename T>
//XBuffer<T>::XBuffer(XBuffer &aXBuffer, size_t pos, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
//{
// if ( pos >= aXBuffer.Length() ) {
// Initialize(NULL, 0, 0);
// }else{
// if ( count > aXBuffer.Length()-pos ) count = aXBuffer.Length()-pos;
// Initialize(aXBuffer.UCData(pos), count, aXBuffer.Index());
// }
//}
template <typename T>
XBuffer<T>::XBuffer(void *p, size_t count) : _WData(NULL), m_allocatedSize(0) // initialisation to avoid effc++ warning
{
Initialize((const unsigned char*)p, count, 0);
}
template <typename T>
XBuffer<T>::~XBuffer()
{
free(_WData);
}
//-------------------------------------------------------------------------------------------------
// operator =, +=
//-------------------------------------------------------------------------------------------------
template <typename T>
const XBuffer<T>& XBuffer<T>::operator =(const XRBuffer<T> &aBuffer)
{
//TRACE("Operator =const XBuffer&\n");
Cpy(aBuffer.Data(), aBuffer.Length());
SetIndex(aBuffer.Index());
return *this;
}
template <typename T>
const XBuffer<T>& XBuffer<T>::operator =(const XBuffer<T> &aBuffer)
{
//TRACE("Operator =const XBuffer&\n");
ncpy(aBuffer.data(), aBuffer.size());
XBuffer_Super::setIndex(aBuffer.index());
return *this;
}
template <typename T>
const XBuffer<T> &XBuffer<T>::operator +=(const XRBuffer<T> &aBuffer)
{
//TRACE("Operator +=const XBuffer&\n");
Cat(aBuffer.Data(), aBuffer.Length());
return *this;
}
//-------------------------------------------------------------------------------------------------
// Cpy, Cat, Delete
//-------------------------------------------------------------------------------------------------
template <typename T>
void XBuffer<T>::ncpy(const void *buf, size_t len)
{
if ( buf && len > 0 ) {
setSize(len);
memcpy(data(), buf, len);
}
}
template <typename T>
void XBuffer<T>::Cat(const void *buf, size_t len)
{
if ( buf && len > 0 ) {
CheckSize(size()+len);
memcpy(Data(size()), buf, len);
SetLength(size()+len);
}
}
template <typename T>
void XBuffer<T>::Cat(const XString8 &aXString8)
{
Cat(aXString8.sizeInBytes());
Cat(aXString8.data(),aXString8.sizeInBytes());
};
template <typename T>
void XBuffer<T>::Delete(unsigned int pos, unsigned int count)
{
if ( pos < size() ) {
if ( pos + count < size() ) {
memmove( _WData+pos, _WData+pos+count, size()-pos-count);
setSize(size()-count);
}else{
setSize(pos);
}
}
}
//-------------------------------------------------------------------------------------------------
// ReadFrom
//-------------------------------------------------------------------------------------------------
//bool XBuffer<T>::ReadFileName(const char* FileName, unsigned int AddZeros)
//{
// FILE *fp;
// long int ulen;
// unsigned int len;
//
// fp = fopen(FileName, "rb");
// if ( fp == NULL ) {
// SetLastErrorMsgf("Impossible d'ouvrir le fichier en lecture '%s'", FileName);
// goto finally;
// }
//
// fseek(fp, 0, 2); // Seek to end of file
// ulen = ftell(fp);
// if ( ulen <= 0 ) {
// SetLastErrorMsgf("Impossible d'avoir la longueur du fichier '%s'", FileName);
// goto finally;
// }
//
// len = (unsigned int)ulen;
// fseek(fp, 0, 0);
//
// if ( fread(CDataWithSizeMin(0, len+AddZeros), 1, len, fp) != len ) {
// SetLastErrorMsgf("Impossible de lire %d octets du fichier '%s'", len, FileName);
// goto finally;
// }
// SetLength(len);
// SetIndex(0);
// if ( fclose(fp) != 0 ) {
// SetLastErrorMsgf("Impossible de fermer les fichier '%s'", FileName);
// goto finally;
// }
// {for ( unsigned int ui=len ; ui<len+AddZeros ; ui+=1 ) *CData(ui) = 0;}
// return YES;
// finally:
// if ( fp != NULL ) fclose(fp);
// SetLength(0);
// return false;
//
//}
//bool XBuffer<T>::ReadFromFILE(FILE *fp)
//{
// unsigned int longueur;
//
// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin;
// if ( longueur > 0 && fread(DataWithSizeMin(0, longueur, 0), longueur, 1, fp) != 1 ) goto fin;
// SetLength(longueur);
// SetIndex(0);
// return OUI;
// fin:
// SetNull();
// return NON;
//}
template <typename T>
bool XBuffer<T>::ReadFromXRBuffer(XRBuffer<T> &unXBuffer)
{
size_t longueur;
if ( !unXBuffer.GetSize_t(&longueur) ) return false;
if ( !unXBuffer.Get(dataSized(longueur), longueur) ) return false; // GrowBy (param 3 of DataWithSizeMin is 0 to avoid memory waste
setSize(longueur);
XBuffer_Super::setIndex(0);
return true;
}
template <typename T>
bool XBuffer<T>::ReadFromBuf(const char *buf, size_t *idx, size_t count)
{
size_t longueur;
if ( count-*idx >= sizeof(longueur) ) {
longueur = *((size_t *)(buf+*idx));
*idx += sizeof(longueur);
if ( longueur > 0 && count-*idx>=longueur ) memcpy(dataSized(longueur), buf+*idx, longueur);
*idx += longueur;
setSize(longueur);
XBuffer_Super::setIndex(0);
return true;
}else{
setEmpty();
return false;
}
}
#endif

View File

@ -56,8 +56,8 @@ class XObjArrayNC
size_t size() const { return _Len; }
size_t length() const { return _Len; }
bool NotNull() const { return size() > 0; }
bool IsNull() const { return size() == 0; }
bool notEmpty() const { return size() > 0; }
bool isEmpty() const { return size() == 0; }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
const TYPE &ElementAt(IntegralType nIndex) const
@ -111,7 +111,7 @@ class XObjArrayNC
//void Remove(int nIndex);
void RemoveAllBut(const TYPE *Element);
void Empty();
void setEmpty();
public:
void CheckSize(size_t nNewSize, size_t nGrowBy = XArrayGrowByDefault);
@ -188,7 +188,7 @@ const XObjArray<TYPE> &XObjArray<TYPE>::operator =(const XObjArray<TYPE> &anObjA
size_t ui;
if ( this == &anObjArray ) return *this; // self assignement
XObjArrayNC<TYPE>::Empty();
XObjArrayNC<TYPE>::setEmpty();
this->CheckSize(anObjArray.length(), 0);
for ( ui=0 ; ui<anObjArray.size() ; ui+=1 ) AddCopy(anObjArray.ElementAt(ui));
return *this;
@ -199,7 +199,7 @@ template<class TYPE>
XObjArrayNC<TYPE>::~XObjArrayNC()
{
//printf("XObjArray Destructor\n");
Empty();
setEmpty();
if ( _Data ) free(_Data);
}
@ -555,7 +555,7 @@ void XObjArrayNC<TYPE>::RemoveAllBut(const TYPE *Element)
/* Empty() */
template<class TYPE>
void XObjArrayNC<TYPE>::Empty()
void XObjArrayNC<TYPE>::setEmpty()
{
size_t i;

View File

@ -1,6 +1,6 @@
//*************************************************************************************************
//
// Buffer
// Read only Buffer
//
//*************************************************************************************************
@ -15,7 +15,7 @@
#include "XString.h"
#include "XStringArray.h"
const XRBuffer NullXRBuffer;
//const XRBuffer NullXRBuffer;
//*************************************************************************************************
@ -23,25 +23,20 @@ const XRBuffer NullXRBuffer;
// RBuffer (ConstBuffer)
//
//*************************************************************************************************
void XRBuffer::Initialize(const void *p, size_t count)
{
_RData = (unsigned char*)p;
_Len = count;
_Index = 0;
}
XRBuffer::XRBuffer(const XRBuffer &aXRBuffer, size_t pos, size_t count) : _RData(0), _Len(0), _Index(0)
template <typename T>
XRBuffer<T>::XRBuffer(const XRBuffer &aXRBuffer, size_t pos, size_t count) : _RData(0), m_size(0), _Index(0)
{
if ( pos < aXRBuffer.Length() ) {
_Len = count;
if ( _Len > aXRBuffer.Length()-pos ) _Len = aXRBuffer.Length()-pos;
if ( pos < aXRBuffer.size() ) {
m_size = count;
if ( m_size > aXRBuffer.size()-pos ) m_size = aXRBuffer.size()-pos;
_RData = (unsigned char*)aXRBuffer.Data(pos);
}
}
/*
XRBuffer::XRBuffer(const XBuffer &aXBuffer, size_t pos, size_t count)
{
if ( count > aXBuffer.Length() ) count = aXBuffer.Length();
if ( count > aXBuffer.size() ) count = aXBuffer.size();
_Data = aXBuffer.UCData();
_Len = count;
_Index = 0;
@ -51,27 +46,30 @@ XRBuffer::XRBuffer(const XBuffer &aXBuffer, size_t pos, size_t count)
//-------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
bool XRBuffer::Get(void *buf, size_t count)
template <typename T>
bool XRBuffer<T>::Get(void *buf, size_t count)
{
if ( Length() - Index() >= count ) {
memcpy(buf, Data(Index()), count);
SetIndex(Index()+count);
if ( size() - index() >= count ) {
memcpy(buf, Data(index()), count);
setIndex(index()+count);
return true;
}
return false;
}
size_t XRBuffer::IdxOf(const XString8& aXString8, size_t Pos) const
template <typename T>
size_t XRBuffer<T>::IdxOf(const XString8& aXString8, size_t Pos) const
{
if ( aXString8.length() > Length()-Pos ) return MAX_XSIZE;
size_t nb = Length()-aXString8.length()+1;
if ( aXString8.length() > size()-Pos ) return MAX_XSIZE;
size_t nb = size()-aXString8.sizeInBytes()+1;
for ( size_t ui=Pos ; ui<nb ; ui+=1 ) {
if ( strncmp(CData(ui), aXString8.c_str(), aXString8.sizeInBytes()) == 0 ) return ui;
}
return MAX_XSIZE;
}
size_t XRBuffer::IdxOf(const XString8Array& aXString8Array, size_t Pos, size_t *n) const
template <typename T>
size_t XRBuffer<T>::IdxOf(const XString8Array& aXString8Array, size_t Pos, size_t *n) const
{
size_t pos;
@ -85,21 +83,22 @@ size_t XRBuffer::IdxOf(const XString8Array& aXString8Array, size_t Pos, size_t *
return MAX_XSIZE;
}
size_t XRBuffer::Sizeof() const
template <typename T>
size_t XRBuffer<T>::Sizeof() const
{
return sizeof(unsigned int)+Length();
return sizeof(unsigned int)+size();
}
/*
bool XRBuffer::WriteToBuf(char *buf, size_t *idx, size_t count) const
{
unsigned int longueur;
if ( count-*idx < sizeof(longueur) + Length() ) return NON;
longueur = Length();
if ( count-*idx < sizeof(longueur) + size() ) return NON;
longueur = size();
memcpy(buf+*idx, &longueur, sizeof(longueur));
*idx += sizeof(longueur);
memcpy(buf+*idx, _Data, Length());
*idx += Length();
memcpy(buf+*idx, _Data, size());
*idx += size();
return OUI;
}
*/
@ -108,7 +107,7 @@ bool XRBuffer::WriteToBuf(char *buf, size_t *idx, size_t count) const
// XFILE f;
//
// f.OpenT(FileName, "wb");
// f.WriteT(Data(), Length());
// f.WriteT(Data(), size());
// f.CloseT();
//}
//
@ -126,7 +125,7 @@ bool XRBuffer::WriteToBuf(char *buf, size_t *idx, size_t count) const
//{
// size_t longueur;
//
// longueur = Length();
// longueur = size();
// if ( fwrite(&longueur, sizeof(longueur), 1, fp) != 1 ) return NON;
// if ( longueur > 0 && fwrite(Data(), longueur, 1, fp) != 1 ) return NON;
// return OUI;
@ -136,7 +135,7 @@ bool XRBuffer::WriteToBuf(char *buf, size_t *idx, size_t count) const
//{
// size_t longueur;
//
// longueur = Length();
// longueur = size();
// f->WriteT(&longueur, sizeof(longueur));
// if ( longueur > 0 ) f->WriteT(Data(), longueur);
//}

View File

@ -16,50 +16,66 @@
class XStringW;
class XString8;
class XString8Array;
class XBuffer;
template <typename T>
class XRBuffer
{
protected:
const unsigned char *_RData;
size_t _Len;
const T* _RData;
size_t m_size;
size_t _Index;
public:
void Initialize(const void *p, size_t count);
XRBuffer() : _RData(0), _Len(0), _Index(0) { }
XRBuffer(const void *p, size_t count) : _RData((const unsigned char *)p), _Len(count), _Index(0) { Initialize(p, count); }
XRBuffer() : _RData(0), m_size(0), _Index(0) { }
XRBuffer(const T* p, size_t count) : _RData(p), m_size(count), _Index(0) { }
XRBuffer(const XRBuffer& aXRBuffer, size_t pos = 0, size_t count = MAX_XSIZE);
// {
// if ( pos < aXRBuffer.Length() ) {
// _Len = count;
// if ( _Len > aXRBuffer.Length()-pos ) _Len = aXRBuffer.Length()-pos;
// _RData = (unsigned char*)aXRBuffer.Data(pos);
// }
// }
// XRBuffer(const XBuffer &aBuffer, unsigned int pos = 0, unsigned int count = MAX_XSIZE);
public:
const void *Data(size_t ui=0) const { return _RData+ui; }
const T* data() const { return _RData; }
const char *CData(size_t ui=0) const { return (char *)(_RData+ui); }
const unsigned char *UCData(size_t ui=0) const { return _RData+ui; }
const unsigned char *UCData(size_t ui=0) const { return (unsigned char*)(_RData+ui); }
size_t Sizeof() const;
size_t Length() const { return _Len; }
size_t Index() const { return _Index; }
void SetIndex(size_t Idx) { _Index = Idx; };
size_t size() const { return m_size; }
size_t index() const { return _Index; }
// IsNull ? //
bool IsNull() const { return Length() == 0 ; }
bool NotNull() const { return Length() > 0 ; }
template<typename IntegralType, enable_if(is_integral(IntegralType))>
void setIndex(IntegralType Idx)
{
if (Idx < 0) {
panic("XBuffer::setIndex : Idx >= m_size. System halted\n");
}
_Index = Idx;
}
bool isEmpty() const { return m_size == 0 ; }
bool notEmpty() const { return m_size > 0 ; }
// Cast //
operator const char *() const { return CData(); }
// [] //
template<typename IntegralType, enable_if(is_integral(IntegralType))>
unsigned char operator [](IntegralType i) const {
T& operator [](IntegralType i)
{
if (i < 0) {
panic("XRBuffer::operator [] : i < 0. System halted\n");
}
if ( (unsigned_type(IntegralType))i >= _Len ) {
if ( (unsigned_type(IntegralType))i >= m_size ) {
panic("XRBuffer::operator [] : index > len. System halted\n");
}
return UCData()[i];

View File

@ -32,6 +32,9 @@ class LString8 : public LString<char, XString8>
// no assignement, no destructor
friend constexpr LString8 operator "" _XS8 ( const char* s, size_t) { return LString8(s); }
const char* c_str() const { return m_data; }
};
class XString8 : public XStringAbstract<char, XString8>
@ -48,6 +51,8 @@ class XString8 : public XStringAbstract<char, XString8>
using XStringAbstract<char, XString8>::operator =;
const char* c_str() const { return m_data; }
protected:
static void transmitS8Printf(const char* buf, unsigned int nbchar, void* context)
{
@ -132,6 +137,8 @@ class LStringW : public LString<wchar_t, XStringW>
constexpr LStringW(const wchar_t* s) : LString<wchar_t, XStringW>(s) {};
friend constexpr LStringW operator "" _XSW ( const wchar_t* s, size_t) { return LStringW(s); }
const wchar_t* wc_str() const { return m_data; }
};
class XStringW : public XStringAbstract<wchar_t, XStringW>
@ -149,6 +156,8 @@ public:
using XStringAbstract<wchar_t, XStringW>::operator =;
const wchar_t* wc_str() const { return m_data; }
protected:
static void transmitSPrintf(const wchar_t* buf, unsigned int nbchar, void* context)
{

View File

@ -243,8 +243,6 @@ public:
size_t sizeInBytesIncludingTerminator() const { return (size_of_utf_string(m_data)+1)*sizeof(T); } // usefull for unit tests
const T* wc_str() const { return m_data; }
const T* c_str() const { return m_data; }
const T* s() const { return m_data; }
const T* data() const { return m_data; } // todo delete

View File

@ -70,7 +70,7 @@ class XStringArray_/* : public XStringArraySuper*/
XStringArray_() : array() {};
size_t size() const { return array.size(); }
void setEmpty() { array.Empty(); }
void setEmpty() { array.setEmpty(); }
bool isEmpty() const { return this->size() == 0 ; }
bool notEmpty() const { return this->size() > 0 ; }

View File

@ -108,7 +108,7 @@ int XStringArray_tests()
XString8Array LoadOptions2;
LoadOptions2 = Split<XString8Array>(array.ConcatAll(" "_XS8).wc_str(), " ");
LoadOptions2 = Split<XString8Array>(array.ConcatAll(" "_XS8).c_str(), " ");
if ( LoadOptions2 != array ) return 22;
LoadOptions2 = Split<XString8Array>(array.ConcatAll(" "_XS8), " ");

View File

@ -1390,7 +1390,7 @@ SimpleString testtrim_(const InitialValue& initialValue, const ExpectedValue& ex
CHECK_RESULT(str.strcmp(expectedValue.cha) == 0,
ssprintf("str.strcmp(expectedValue.cha) == 0 (\"%s\")", SimpleString(expectedValue.cha).c_str()),
ssprintf("str.strcmp(expectedValue.cha) != 0 (\"%s\"!=\"%s\")", SimpleString(str.c_str()).c_str(), SimpleString(expectedValue.cha).c_str())
ssprintf("str.strcmp(expectedValue.cha) != 0 (\"%s\"!=\"%s\")", SimpleString(str.s()).c_str(), SimpleString(expectedValue.cha).c_str())
);
//str.takeValueFrom(initialValue.cha);
//str.trim();

View File

@ -10,15 +10,16 @@ extern "C" {
*/
#if 1 //!defined(_MSC_VER)
#ifdef __GNUC__
void* memset(void* dst, int ch, UINT64 count) __attribute__ ((used));
//void* memcpy(void* dst, const void* src, UINT64 count) __attribute__ ((used));
void* memset(void* dst, int ch, size_t count) __attribute__ ((used));
//void* memcpy(void* dst, const void* src, UINT64 count) __attribute__ ((used));
#else
void* memset(void* dst, int ch, UINT64 count);
// void* memcpy(void* dst, const void* src, UINT64 count);
//void* memcpy(void* dst, const void* src, UINT64 count);
#endif
void* memset(void* dst, int ch, UINT64 count)
void* memset(void* dst, int ch, size_t count)
{
SetMem(dst, count, (UINT8)(ch));
return dst;

View File

@ -452,7 +452,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST XStringW& LoaderPath,
EFI_GRAPHICS_OUTPUT_BLT_PIXEL BootBgColor,
IN UINT8 CustomBoot,
IN XImage *CustomLogo,
IN KERNEL_AND_KEXT_PATCHES *Patches,
IN const KERNEL_AND_KEXT_PATCHES* Patches,
IN BOOLEAN CustomEntry)
{
EFI_DEVICE_PATH *LoaderDevicePath;
@ -604,7 +604,7 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST XStringW& LoaderPath,
}
Entry->LoaderType = OSType;
Entry->BuildVersion = NULL;
Entry->BuildVersion.setEmpty();
Entry->OSVersion = GetOSVersion(Entry);
//DBG("OSVersion=%s \n", Entry->OSVersion);
// detect specific loaders
@ -758,7 +758,9 @@ STATIC LOADER_ENTRY *CreateLoaderEntry(IN CONST XStringW& LoaderPath,
Entry->BootBgColor = BootBgColor;
// Entry->KernelAndKextPatches = ((Patches == NULL) ? (KERNEL_AND_KEXT_PATCHES *)(((UINTN)&gSettings) + OFFSET_OF(SETTINGS_DATA, KernelAndKextPatches)) : Patches);
CopyKernelAndKextPatches(&Entry->KernelAndKextPatches, Patches == NULL ? &gSettings.KernelAndKextPatches : Patches);
// CopyKernelAndKextPatches(&Entry->KernelAndKextPatches, Patches == NULL ? &gSettings.KernelAndKextPatches : Patches);
Entry->KernelAndKextPatches = Patches == NULL ? gSettings.KernelAndKextPatches : *Patches;
#ifdef DUMP_KERNEL_KEXT_PATCHES
DumpKernelAndKextPatches(Entry->KernelAndKextPatches);
#endif
@ -783,11 +785,11 @@ void LOADER_ENTRY::AddDefaultMenu()
constexpr LString8 splashLitteral = "splash";
// Only kernels up to 10.7 have 32-bit mode
KernelIs64BitOnly = (OSVersion == NULL ||
os_version >= AsciiOSVersionToUint64("10.8"));
KernelIs64BitOnly = (OSVersion.isEmpty() ||
os_version >= AsciiOSVersionToUint64("10.8"_XS8));
const char* macOS = (os_version < AsciiOSVersionToUint64("10.8"))? "Mac OS X" :
(os_version < AsciiOSVersionToUint64("10.12"))? "OS X" : "macOS";
const char* macOS = (os_version < AsciiOSVersionToUint64("10.8"_XS8))? "Mac OS X" :
(os_version < AsciiOSVersionToUint64("10.12"_XS8))? "OS X" : "macOS";
FileName = LoaderPath.basename();
@ -820,7 +822,7 @@ void LOADER_ENTRY::AddDefaultMenu()
if (LoaderType == OSTYPE_OSX ||
LoaderType == OSTYPE_OSX_INSTALLER ||
LoaderType == OSTYPE_RECOVERY) { // entries for Mac OS X
SubScreen->AddMenuInfoLine_f("%s: %s", macOS, OSVersion);
SubScreen->AddMenuInfoLine_f("%s: %s", macOS, OSVersion.c_str());
if (OSFLAG_ISSET(Flags, OSFLAG_HIBERNATED)) {
SubEntry = getPartiallyDuplicatedEntry();
@ -856,7 +858,7 @@ void LOADER_ENTRY::AddDefaultMenu()
SubScreen->AddMenuEntry(SubMenuKextInjectMgmt(), true);
SubScreen->AddMenuInfo_f("=== boot-args ===");
if (!KernelIs64BitOnly) {
if (os_version < AsciiOSVersionToUint64("10.8")) {
if (os_version < AsciiOSVersionToUint64("10.8"_XS8)) {
SubScreen->AddMenuCheck("Mac OS X 32bit", OPT_I386, 68);
}
// SubScreen->AddMenuCheck(XString8().SPrintf("%s 64bit", macOS).c_str(), OPT_X64, 68);
@ -864,7 +866,7 @@ void LOADER_ENTRY::AddDefaultMenu()
}
SubScreen->AddMenuCheck("Verbose (-v)", OPT_VERBOSE, 68);
// No Caches option works on 10.6 - 10.9
if (os_version < AsciiOSVersionToUint64("10.10")) {
if (os_version < AsciiOSVersionToUint64("10.10"_XS8)) {
SubScreen->AddMenuCheck("Without caches (-f)", OPT_NOCACHES, 68);
}
SubScreen->AddMenuCheck("Single User (-s)", OPT_SINGLE_USER, 68);

View File

@ -466,7 +466,7 @@ VOID REFIT_MENU_SCREEN::FreeMenu()
Tentry->SubScreen = NULL;
}
}
Entries.Empty();
Entries.setEmpty();
}
InfoLines.setEmpty();
}

View File

@ -75,7 +75,8 @@ LOADER_ENTRY* LOADER_ENTRY::getPartiallyDuplicatedEntry() const
DuplicateEntry->LoaderType = LoaderType;
DuplicateEntry->OSVersion = OSVersion;
DuplicateEntry->BuildVersion = BuildVersion;
CopyKernelAndKextPatches(&DuplicateEntry->KernelAndKextPatches, &KernelAndKextPatches);
// CopyKernelAndKextPatches(&DuplicateEntry->KernelAndKextPatches, &KernelAndKextPatches);
DuplicateEntry->KernelAndKextPatches = KernelAndKextPatches;
return DuplicateEntry;
}

View File

@ -368,8 +368,8 @@ class REFIT_ABSTRACT_MENU_ENTRY
EFI_DEVICE_PATH *DevicePath;
UINT16 Flags;
UINT8 LoaderType;
CHAR8 *OSVersion;
CHAR8 *BuildVersion;
XString8 OSVersion;
XString8 BuildVersion;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL BootBgColor;
UINT8 CustomBoot;
@ -430,8 +430,8 @@ class REFIT_ABSTRACT_MENU_ENTRY
void Get_PreLink();
UINT32 Get_Symtab(UINT8* binary);
UINT32 GetTextExec();
UINTN searchProc(const char *procedure);
UINTN searchProcInDriver(UINT8 * driver, UINT32 driverLen, const char *procedure);
UINTN searchProc(const XString8& procedure);
UINTN searchProcInDriver(UINT8 * driver, UINT32 driverLen, const XString8& procedure);
UINT32 searchSectionByNum(UINT8 * Binary, UINT32 Num);
void KernelAndKextsPatcherStart();
void KernelAndKextPatcherInit();
@ -462,13 +462,13 @@ class REFIT_ABSTRACT_MENU_ENTRY
EFI_STATUS LoadKext(IN EFI_FILE *RootDir, IN CONST CHAR16 *FileName, IN cpu_type_t archCpuType, IN OUT void *kext);
EFI_STATUS AddKext(IN EFI_FILE *RootDir, IN CONST CHAR16 *FileName, IN cpu_type_t archCpuType);
void LoadPlugInKexts(IN EFI_FILE *RootDir, IN CONST CHAR16 *DirName, IN cpu_type_t archCpuType, IN BOOLEAN Force);
void AddKexts(CONST CHAR16 *SrcDir, CONST CHAR16 *Path, cpu_type_t archCpuType);
void AddKexts(const XStringW& SrcDir, const XStringW& Path, cpu_type_t archCpuType);
void KextPatcherRegisterKexts(void *FSInject, void *ForceLoadKexts);
void KextPatcherStart();
void PatchPrelinkedKexts();
void PatchLoadedKexts();
void PatchKext(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize);
void AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, INT32 N);
void AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize, size_t N);
void ATIConnectorsPatchInit();
void ATIConnectorsPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 InfoPlistSize);
void ATIConnectorsPatchRegisterKexts(void *FSInject_v, void *ForceLoadKexts_v);

View File

@ -112,7 +112,7 @@ VOID DecodeOptions(REFIT_MENU_ITEM_BOOTNUM *Entry)
LOADER_ENTRY* loaderEntry = Entry->getLOADER_ENTRY();
// Only for non-legacy entries, as LEGACY_ENTRY doesn't have OSVersion
if (gSettings.OptionsBits & OPT_NVWEBON) {
if (AsciiOSVersionToUint64(loaderEntry->OSVersion) >= AsciiOSVersionToUint64("10.12")) {
if (AsciiOSVersionToUint64(loaderEntry->OSVersion) >= AsciiOSVersionToUint64("10.12"_XS8)) {
gSettings.NvidiaWeb = TRUE;
} else {
//Entry->LoadOptions = loaderEntry->LoadOptions;
@ -121,7 +121,7 @@ VOID DecodeOptions(REFIT_MENU_ITEM_BOOTNUM *Entry)
}
}
if ((gSettings.OptionsBits & OPT_NVWEBON) == 0) {
if (AsciiOSVersionToUint64(loaderEntry->OSVersion) >= AsciiOSVersionToUint64("10.12")) {
if (AsciiOSVersionToUint64(loaderEntry->OSVersion) >= AsciiOSVersionToUint64("10.12"_XS8)) {
gSettings.NvidiaWeb = FALSE;
} else {
//Entry->LoadOptions = loaderEntry->LoadOptions;

View File

@ -233,7 +233,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
{
EFI_STATUS Status;
Icons.Empty();
Icons.setEmpty();
// --- Parse theme.svg --- low case
NSVGparser *mainParser = nsvgParse((CHAR8*)buffer, 72, 1.f); //the buffer will be modified, it is how nanosvg works

View File

@ -101,7 +101,7 @@ class XCinema
FILM* GetFilm(INTN Id);
void AddFilm(FILM* NewFilm);
void setEmpty() { Cinema.Empty(); }
void setEmpty() { Cinema.setEmpty(); }
};
#endif /* XCinema_h */

View File

@ -27,7 +27,7 @@ extern "C" {
//xtheme class
XTheme::XTheme() : Icons(), ThemeDir(0), HideBadges(0), HideUIFlags(0), Font(FONT_ALFA), CharWidth(0), SelectionColor(0), FontFileName(),
XTheme::XTheme() : Icons(), ThemeDir(0), HideBadges(0), HideUIFlags(0), Font(FONT_ALFA), CharWidth(0), SelectionColor(0), FontFileName(), Theme(),
BannerFileName(), SelectionSmallFileName(), SelectionBigFileName(), SelectionIndicatorName(), DefaultSelection(),
BackgroundName(), BackgroundScale(imNone), BackgroundSharp(0), BackgroundDark(0), SelectionOnTop(0), BootCampStyle(0),
BadgeOffsetX(0), BadgeOffsetY(0), BadgeScale(0), ThemeDesignWidth(0), ThemeDesignHeight(0), BannerPosX(0), BannerPosY(0),
@ -294,7 +294,7 @@ void XTheme::FillByEmbedded()
SelectionColor = 0xA0A0A080;
SelectionBackgroundPixel = { 0xa0, 0xa0, 0xa0, 0x80 };
Icons.Empty();
Icons.setEmpty();
for (INTN i = 0; i < BUILTIN_ICON_COUNT; ++i) { //this is embedded icon count
XIcon* NewIcon = new XIcon(i, true);
Icons.AddReference(NewIcon, true);
@ -453,7 +453,7 @@ void XTheme::ClearScreen() //and restore background and banner
void XTheme::FillByDir() //assume ThemeDir is defined by InitTheme() procedure
{
EFI_STATUS Status;
Icons.Empty();
Icons.setEmpty();
for (INTN i = 0; i < IconsNamesSize; ++i) { //scan full table
Status = EFI_NOT_FOUND;
XIcon* NewIcon = new XIcon(i); //initialize without embedded

View File

@ -143,6 +143,7 @@ extern "C" {
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/XStringArray.h"
#include "../cpp_foundation/XBuffer.h"
/* types */
typedef enum {
@ -220,8 +221,8 @@ public:
UINTN LineShift;
INPUT_ITEM() : ItemType(BoolValue), Valid(0), BValue(0), Pad8(0), IValue(0), SValue(0), LineShift(0) {};
INPUT_ITEM(const INPUT_ITEM& other) = delete; // Can be defined if needed
const INPUT_ITEM& operator = ( const INPUT_ITEM & ) = delete; // Can be defined if needed
INPUT_ITEM(const INPUT_ITEM& other) = default; // default is fine if there is only native type and objects that have copy ctor
INPUT_ITEM& operator = ( const INPUT_ITEM & ) = default; // default is fine if there is only native type and objects that have copy ctor
~INPUT_ITEM() { }
};
@ -295,57 +296,75 @@ public:
class KEXT_PATCH
{
public:
CHAR8 *Name;
CHAR8 *Label;
XString8 Name;
XString8 Label;
BOOLEAN IsPlistPatch;
CHAR8 align[7];
INT64 DataLen;
UINT8 *Data;
UINT8 *Patch;
UINT8 *MaskFind;
UINT8 *MaskReplace;
UINT8 *StartPattern;
UINT8 *StartMask;
INTN StartPatternLen;
XBuffer<UINT8> Data;
XBuffer<UINT8> Patch;
XBuffer<UINT8> MaskFind;
XBuffer<UINT8> MaskReplace;
XBuffer<UINT8> StartPattern;
XBuffer<UINT8> StartMask;
INTN SearchLen;
CHAR8 *ProcedureName; //procedure len will be StartPatternLen
CHAR8 *MatchOS;
CHAR8 *MatchBuild;
XString8 ProcedureName; //procedure len will be StartPatternLen
INTN Count;
XString8 MatchOS;
XString8 MatchBuild;
// CHAR8 *Name;
// CHAR8 *Label;
// BOOLEAN IsPlistPatch;
// CHAR8 align[7];
// INT64 DataLen;
// UINT8 *Data; // len = DataLen
// UINT8 *Patch; // len = DataLen
// UINT8 *MaskFind;
// UINT8 *MaskReplace;
// UINT8 *StartPattern; // len = StartPatternLen
// UINT8 *StartMask; // len = StartPatternLen
// INTN StartPatternLen;
// INTN SearchLen;
// CHAR8 *ProcedureName;
// INTN Count;
// CHAR8 *MatchOS;
// CHAR8 *MatchBuild;
INPUT_ITEM MenuItem;
KEXT_PATCH() : Name(0), Label(0), IsPlistPatch(0), align{0}, DataLen(0), Data(0), Patch(0), MaskFind(0), MaskReplace(0),
StartPattern(0), StartMask(0), StartPatternLen(0), SearchLen(0), ProcedureName(0), MatchOS(0), MatchBuild(0), MenuItem()
// KEXT_PATCH() : Name(0), Label(0), IsPlistPatch(0), align{0}, DataLen(0), Data(0), Patch(0), MaskFind(0), MaskReplace(0),
// StartPattern(0), StartMask(0), StartPatternLen(0), SearchLen(0), ProcedureName(0), Count(-1), MatchOS(0), MatchBuild(0), MenuItem()
// { }
KEXT_PATCH() : Name(), Label(), IsPlistPatch(0), Data(), Patch(), MaskFind(), MaskReplace(),
StartPattern(), StartMask(), SearchLen(0), ProcedureName(), Count(-1), MatchOS(), MatchBuild(), MenuItem()
{ }
KEXT_PATCH(const KEXT_PATCH& other) = delete; // Can be defined if needed
const KEXT_PATCH& operator = ( const KEXT_PATCH & ) = delete; // Can be defined if needed
KEXT_PATCH(const KEXT_PATCH& other) = default; // default is fine if there is only native type and objects that have copy ctor
KEXT_PATCH& operator = ( const KEXT_PATCH & ) = default; // default is fine if there is only native type and objects that have copy ctor
~KEXT_PATCH() {}
};
class KERNEL_PATCH {
public:
CHAR8 *Label;
INTN DataLen;
UINT8 *Data;
UINT8 *Patch;
UINT8 *MaskFind;
UINT8 *MaskReplace;
UINT8 *StartPattern;
UINT8 *StartMask;
INTN StartPatternLen;
INTN SearchLen;
CHAR8 *ProcedureName;
INTN Count;
CHAR8 *MatchOS;
CHAR8 *MatchBuild;
INPUT_ITEM MenuItem;
KERNEL_PATCH() : Label(0), DataLen(0), Data(0), Patch(0), MaskFind(0), MaskReplace(0), StartPattern(0), StartMask(0),
StartPatternLen(0), SearchLen(0), ProcedureName(0), Count(0), MatchOS(0), MatchBuild(0), MenuItem()
{ }
KERNEL_PATCH(const KERNEL_PATCH& other) = delete; // Can be defined if needed
const KERNEL_PATCH& operator = ( const KERNEL_PATCH & ) = delete; // Can be defined if needed
~KERNEL_PATCH() {}
} ;
//class KERNEL_PATCH {
//public:
// CHAR8 *Label;
// INTN DataLen;
// UINT8 *Data;
// UINT8 *Patch;
// UINT8 *MaskFind;
// UINT8 *MaskReplace;
// UINT8 *StartPattern;
// UINT8 *StartMask;
// INTN StartPatternLen;
// INTN SearchLen;
// CHAR8 *ProcedureName;
// INTN Count;
// CHAR8 *MatchOS;
// CHAR8 *MatchBuild;
// INPUT_ITEM MenuItem;
//
// KERNEL_PATCH() : Label(0), DataLen(0), Data(0), Patch(0), MaskFind(0), MaskReplace(0), StartPattern(0), StartMask(0),
// StartPatternLen(0), SearchLen(0), ProcedureName(0), Count(0), MatchOS(0), MatchBuild(0), MenuItem()
// { }
// KERNEL_PATCH(const KERNEL_PATCH& other) = delete; // Can be defined if needed
// const KERNEL_PATCH& operator = ( const KERNEL_PATCH & ) = delete; // Can be defined if needed
// ~KERNEL_PATCH() {}
//} ;
class KERNEL_AND_KEXT_PATCHES
{
@ -363,50 +382,50 @@ public:
UINT8 pad[7];
UINT32 FakeCPUID;
// UINT32 align0;
CHAR8 *KPATIConnectorsController;
XString8 KPATIConnectorsController;
#if defined(MDE_CPU_IA32)
UINT32 align1;
#endif
UINT8 *KPATIConnectorsData;
XBuffer<UINT8> KPATIConnectorsData;
#if defined(MDE_CPU_IA32)
UINT32 align2;
#endif
UINTN KPATIConnectorsDataLen;
#if defined(MDE_CPU_IA32)
UINT32 align3;
#endif
UINT8 *KPATIConnectorsPatch;
XBuffer<UINT8> KPATIConnectorsPatch;
#if defined(MDE_CPU_IA32)
UINT32 align4;
#endif
INT32 NrKexts;
// INT32 NrKexts;
UINT32 align40;
KEXT_PATCH *KextPatches; //zzzz
XObjArray<KEXT_PATCH> KextPatches;
#if defined(MDE_CPU_IA32)
UINT32 align5;
#endif
INT32 NrForceKexts;
// INT32 NrForceKexts;
UINT32 align50;
CHAR16 **ForceKexts;
// CHAR16 **ForceKexts;
XStringWArray ForceKexts;
#if defined(MDE_CPU_IA32)
UINT32 align6;
#endif
INT32 NrKernels;
KERNEL_PATCH *KernelPatches;
INT32 NrBoots;
KERNEL_PATCH *BootPatches;
// INT32 NrKernels;
XObjArray<KEXT_PATCH> KernelPatches;
// INT32 NrBoots;
XObjArray<KEXT_PATCH> BootPatches;
KERNEL_AND_KEXT_PATCHES() : KPDebug(0), KPKernelLapic(0), KPKernelXCPM(0), KPKernelPm(0), KPAppleIntelCPUPM(0), KPAppleRTC(0), KPDELLSMBIOS(0), KPPanicNoKextDump(0),
EightApple(0), pad{0}, FakeCPUID(0), KPATIConnectorsController(0), KPATIConnectorsData(0), KPATIConnectorsDataLen(0),
KPATIConnectorsPatch(0), NrKexts(0), align40(0), KextPatches(0), NrForceKexts(0), align50(0), ForceKexts(),
NrKernels(0), KernelPatches(0), NrBoots(0), BootPatches(0)
EightApple(0), pad{0}, FakeCPUID(0), KPATIConnectorsController(0), KPATIConnectorsData(),
KPATIConnectorsPatch(), align40(0), KextPatches(), align50(0), ForceKexts(),
KernelPatches(), BootPatches()
{ }
KERNEL_AND_KEXT_PATCHES(const KERNEL_AND_KEXT_PATCHES& other) = delete; // Can be defined if needed
const KERNEL_AND_KEXT_PATCHES& operator = ( const KERNEL_AND_KEXT_PATCHES & ) = delete; // Can be defined if needed
KERNEL_AND_KEXT_PATCHES(const KERNEL_AND_KEXT_PATCHES& other) = default; // Can be defined if needed
KERNEL_AND_KEXT_PATCHES& operator = ( const KERNEL_AND_KEXT_PATCHES & ) = default; // Can be defined if needed
~KERNEL_AND_KEXT_PATCHES() {}
} ;

View File

@ -1251,7 +1251,7 @@ static VOID UninitVolumes(VOID)
Volume->WholeDiskDeviceHandle = NULL;
FreePool(Volume);
}
Volumes.Empty();
Volumes.setEmpty();
}
VOID ReinitVolumes(VOID)

View File

@ -232,9 +232,9 @@ static EFI_STATUS StartEFILoadedImage(IN EFI_HANDLE ChildImageHandle,
if (LoadOptionsPrefix != NULL) {
// NOTE: That last space is also added by the EFI shell and seems to be significant
// when passing options to Apple's boot.efi...
loadOptionsW = SWPrintf("%ls %s ", LoadOptionsPrefix, LoadOptions.ConcatAll(" "_XS8).wc_str());
loadOptionsW = SWPrintf("%ls %s ", LoadOptionsPrefix, LoadOptions.ConcatAll(" "_XS8).c_str());
}else{
loadOptionsW = SWPrintf("%s ", LoadOptions.ConcatAll(" "_XS8).wc_str()); // Jief : should we add a space ? Wasn't the case before big refactoring. Yes, a space required.
loadOptionsW = SWPrintf("%s ", LoadOptions.ConcatAll(" "_XS8).c_str()); // Jief : should we add a space ? Wasn't the case before big refactoring. Yes, a space required.
}
// NOTE: We also include the terminating null in the length for safety.
ChildLoadedImage->LoadOptionsSize = (UINT32)loadOptionsW.sizeInBytes() + sizeof(wchar_t);
@ -393,17 +393,17 @@ VOID DumpKernelAndKextPatches(KERNEL_AND_KEXT_PATCHES *Patches)
DBG("\tFakeCPUID: 0x%X\n", Patches->FakeCPUID);
DBG("\tATIController: %s\n", (Patches->KPATIConnectorsController == NULL) ? "(null)": Patches->KPATIConnectorsController);
DBG("\tATIDataLength: %d\n", Patches->KPATIConnectorsDataLen);
DBG("\t%d Kexts to load\n", Patches->NrForceKexts);
DBG("\t%d Kexts to load\n", Patches->ForceKexts.size());
if (Patches->ForceKexts) {
INTN i = 0;
for (; i < Patches->NrForceKexts; ++i) {
for (; i < Patches->ForceKexts.size(); ++i) {
DBG("\t KextToLoad[%d]: %ls\n", i, Patches->ForceKexts[i]);
}
}
DBG("\t%d Kexts to patch\n", Patches->NrKexts);
DBG("\t%d Kexts to patch\n", Patches->KextPatches.size());
if (Patches->KextPatches) {
INTN i = 0;
for (; i < Patches->NrKexts; ++i) {
for (; i < Patches->KextPatches.size(); ++i) {
if (Patches->KextPatches[i].IsPlistPatch) {
DBG("\t KextPatchPlist[%d]: %d bytes, %s\n", i, Patches->KextPatches[i].DataLen, Patches->KextPatches[i].Name);
} else {
@ -415,23 +415,23 @@ VOID DumpKernelAndKextPatches(KERNEL_AND_KEXT_PATCHES *Patches)
#endif
VOID LOADER_ENTRY::FilterKextPatches()
{
if (gSettings.KextPatchesAllowed && (KernelAndKextPatches.KextPatches != NULL) && (KernelAndKextPatches.NrKexts != 0)) {
if ( gSettings.KextPatchesAllowed && KernelAndKextPatches.KextPatches.size() > 0 ) {
DBG("Filtering KextPatches:\n");
for (INTN i = 0; i < KernelAndKextPatches.NrKexts; i++) {
DBG(" - [%02lld]: %s :: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
for (size_t i = 0; i < KernelAndKextPatches.KextPatches.size(); i++) {
DBG(" - [%02zu]: %s :: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
i,
KernelAndKextPatches.KextPatches[i].Label,
KernelAndKextPatches.KextPatches[i].Label.c_str(),
KernelAndKextPatches.KextPatches[i].IsPlistPatch ? "PlistPatch" : "BinPatch",
OSVersion,
KernelAndKextPatches.KextPatches[i].MatchOS ? KernelAndKextPatches.KextPatches[i].MatchOS : "All",
KernelAndKextPatches.KextPatches[i].MatchBuild != NULL ? KernelAndKextPatches.KextPatches[i].MatchBuild : "All"
OSVersion.c_str(),
KernelAndKextPatches.KextPatches[i].MatchOS.notEmpty() ? KernelAndKextPatches.KextPatches[i].MatchOS.c_str() : "All",
KernelAndKextPatches.KextPatches[i].MatchBuild.notEmpty() ? KernelAndKextPatches.KextPatches[i].MatchBuild.c_str() : "All"
);
if (!KernelAndKextPatches.KextPatches[i].MenuItem.BValue) {
DBG(" ==> disabled by user\n");
continue;
}
if ((BuildVersion != NULL) && (KernelAndKextPatches.KextPatches[i].MatchBuild != NULL)) {
if ((BuildVersion.notEmpty()) && (KernelAndKextPatches.KextPatches[i].MatchBuild.notEmpty())) {
KernelAndKextPatches.KextPatches[i].MenuItem.BValue = IsPatchEnabled(KernelAndKextPatches.KextPatches[i].MatchBuild, BuildVersion);
DBG(" ==> %s\n", KernelAndKextPatches.KextPatches[i].MenuItem.BValue ? "allowed" : "not allowed");
continue;
@ -445,23 +445,22 @@ VOID LOADER_ENTRY::FilterKextPatches()
VOID LOADER_ENTRY::FilterKernelPatches()
{
if (gSettings.KernelPatchesAllowed && (KernelAndKextPatches.KernelPatches != NULL) && KernelAndKextPatches.NrKernels) {
INTN i = 0;
if ( gSettings.KernelPatchesAllowed && KernelAndKextPatches.KernelPatches.notEmpty() ) {
DBG("Filtering KernelPatches:\n");
for (; i < KernelAndKextPatches.NrKernels; ++i) {
DBG(" - [%02lld]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
for (size_t i = 0; i < KernelAndKextPatches.KernelPatches.size(); ++i) {
DBG(" - [%02zu]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
i,
KernelAndKextPatches.KernelPatches[i].Label,
OSVersion,
KernelAndKextPatches.KernelPatches[i].MatchOS ? KernelAndKextPatches.KernelPatches[i].MatchOS : "All",
KernelAndKextPatches.KernelPatches[i].MatchBuild != NULL ? KernelAndKextPatches.KernelPatches[i].MatchBuild : "no"
KernelAndKextPatches.KernelPatches[i].Label.c_str(),
OSVersion.c_str(),
KernelAndKextPatches.KernelPatches[i].MatchOS.notEmpty() ? KernelAndKextPatches.KernelPatches[i].MatchOS.c_str() : "All",
KernelAndKextPatches.KernelPatches[i].MatchBuild.notEmpty() ? KernelAndKextPatches.KernelPatches[i].MatchBuild.c_str() : "no"
);
if (!KernelAndKextPatches.KernelPatches[i].MenuItem.BValue) {
DBG(" ==> disabled by user\n");
continue;
}
if ((BuildVersion != NULL) && (KernelAndKextPatches.KernelPatches[i].MatchBuild != NULL)) {
if ((BuildVersion.notEmpty()) && (KernelAndKextPatches.KernelPatches[i].MatchBuild.notEmpty())) {
KernelAndKextPatches.KernelPatches[i].MenuItem.BValue = IsPatchEnabled(KernelAndKextPatches.KernelPatches[i].MatchBuild, BuildVersion);
DBG(" ==> %s by build\n", KernelAndKextPatches.KernelPatches[i].MenuItem.BValue ? "allowed" : "not allowed");
continue;
@ -475,22 +474,22 @@ VOID LOADER_ENTRY::FilterKernelPatches()
VOID LOADER_ENTRY::FilterBootPatches()
{
if ((KernelAndKextPatches.BootPatches != NULL) && KernelAndKextPatches.NrBoots) {
if ( KernelAndKextPatches.BootPatches.notEmpty() ) {
DBG("Filtering BootPatches:\n");
for (INTN i = 0; i < KernelAndKextPatches.NrBoots; ++i) {
DBG(" - [%02lld]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
for (size_t i = 0; i < KernelAndKextPatches.BootPatches.size(); ++i) {
DBG(" - [%02zu]: %s :: [OS: %s | MatchOS: %s | MatchBuild: %s]",
i,
KernelAndKextPatches.BootPatches[i].Label,
OSVersion,
KernelAndKextPatches.BootPatches[i].MatchOS ? KernelAndKextPatches.BootPatches[i].MatchOS : "All",
KernelAndKextPatches.BootPatches[i].MatchBuild != NULL ? KernelAndKextPatches.BootPatches[i].MatchBuild : "no"
KernelAndKextPatches.BootPatches[i].Label.c_str(),
OSVersion.c_str(),
KernelAndKextPatches.BootPatches[i].MatchOS.notEmpty() ? KernelAndKextPatches.BootPatches[i].MatchOS.c_str() : "All",
KernelAndKextPatches.BootPatches[i].MatchBuild.notEmpty() ? KernelAndKextPatches.BootPatches[i].MatchBuild.c_str() : "no"
);
if (!KernelAndKextPatches.BootPatches[i].MenuItem.BValue) {
DBG(" ==> disabled by user\n");
continue;
}
if ((BuildVersion != NULL) && (KernelAndKextPatches.BootPatches[i].MatchBuild != NULL)) {
if ((BuildVersion.notEmpty()) && (KernelAndKextPatches.BootPatches[i].MatchBuild.notEmpty())) {
KernelAndKextPatches.BootPatches[i].MenuItem.BValue = IsPatchEnabled(KernelAndKextPatches.BootPatches[i].MatchBuild, BuildVersion);
DBG(" ==> %s by build\n", KernelAndKextPatches.BootPatches[i].MenuItem.BValue ? "allowed" : "not allowed");
continue;
@ -689,7 +688,7 @@ VOID LOADER_ENTRY::StartLoader()
// Correct OSVersion if it was not found
// This should happen only for 10.7-10.9 OSTYPE_OSX_INSTALLER
// For these cases, take OSVersion from loaded boot.efi image in memory
if (/*LoaderType == OSTYPE_OSX_INSTALLER ||*/ !OSVersion) {
if (/*LoaderType == OSTYPE_OSX_INSTALLER ||*/ OSVersion.isEmpty()) {
if (!EFI_ERROR(Status)) {
// version in boot.efi appears as "Mac OS X 10.?"
@ -715,29 +714,22 @@ VOID LOADER_ENTRY::StartLoader()
InstallerVersion = NULL; // flag known version was not found
}
if (InstallerVersion != NULL) { // known version was found in image
if (OSVersion != NULL) {
FreePool(OSVersion);
}
OSVersion = (__typeof__(OSVersion))AllocateCopyPool(AsciiStrLen(InstallerVersion)+1, InstallerVersion);
OSVersion[AsciiStrLen(InstallerVersion)] = '\0';
DBG("Corrected OSVersion: %s\n", OSVersion);
OSVersion.takeValueFrom(InstallerVersion);
DBG("Corrected OSVersion: %s\n", OSVersion.c_str());
}
}
}
if (BuildVersion != NULL) {
FreePool(BuildVersion);
BuildVersion = NULL;
}
BuildVersion.setEmpty();
}
if (BuildVersion != NULL) {
DBG(" %s (%s)\n", OSVersion, BuildVersion);
if (BuildVersion.notEmpty()) {
DBG(" %s (%s)\n", OSVersion.c_str(), BuildVersion.c_str());
} else {
DBG(" %s\n", OSVersion);
DBG(" %s\n", OSVersion.c_str());
}
if (OSVersion && (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.11"))) {
if (OSVersion.notEmpty() && (AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.11"_XS8))) {
if (OSFLAG_ISSET(Flags, OSFLAG_NOSIP)) {
gSettings.CsrActiveConfig = (UINT32)0xB7F;
gSettings.BooterConfig = 0x28;
@ -756,7 +748,7 @@ VOID LOADER_ENTRY::StartLoader()
if ( OSFLAG_ISSET(Flags, OSFLAG_NOCACHES) && !LoadOptions.containsStartWithIC("Kernel=") ) {
XString8 KernelLocation;
if (OSVersion && AsciiOSVersionToUint64(OSVersion) <= AsciiOSVersionToUint64("10.9")) {
if (OSVersion.notEmpty() && AsciiOSVersionToUint64(OSVersion) <= AsciiOSVersionToUint64("10.9"_XS8)) {
KernelLocation.S8Printf("\"Kernel=/mach_kernel\"");
} else {
// used for 10.10, 10.11, and new version.
@ -818,8 +810,8 @@ VOID LOADER_ENTRY::StartLoader()
if (KernelAndKextPatches.KPKernelXCPM &&
gCPUStructure.Vendor == CPU_VENDOR_INTEL && gCPUStructure.Model >= CPU_MODEL_HASWELL &&
(AsciiStrStr(gCPUStructure.BrandString, "Celeron") || AsciiStrStr(gCPUStructure.BrandString, "Pentium")) &&
(AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.8.5")) &&
(AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.12")) &&
(AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.8.5"_XS8)) &&
(AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.12"_XS8)) &&
(!LoadOptions.containsIC("-xcpm"))) {
// add "-xcpm" argv if not present on Haswell+ Celeron/Pentium
LoadOptions.AddID("-xcpm"_XS8);
@ -828,8 +820,8 @@ VOID LOADER_ENTRY::StartLoader()
// add -xcpm on Ivy Bridge if set KernelXCPM and system version is 10.8.5 - 10.11.x
if (KernelAndKextPatches.KPKernelXCPM &&
gCPUStructure.Model == CPU_MODEL_IVY_BRIDGE &&
(AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.8.5")) &&
(AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.12")) &&
(AsciiOSVersionToUint64(OSVersion) >= AsciiOSVersionToUint64("10.8.5"_XS8)) &&
(AsciiOSVersionToUint64(OSVersion) < AsciiOSVersionToUint64("10.12"_XS8)) &&
(!LoadOptions.containsIC("-xcpm"))) {
// add "-xcpm" argv if not present on Ivy Bridge
LoadOptions.AddID("-xcpm"_XS8);
@ -2287,8 +2279,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,
}
gBootChanged = FALSE;
MainMenu.Entries.Empty();
OptionMenu.Entries.Empty();
MainMenu.Entries.setEmpty();
OptionMenu.Entries.setEmpty();
InitKextList();
ScanVolumes();
@ -2317,8 +2309,8 @@ RefitMain (IN EFI_HANDLE ImageHandle,
DBG("change theme\n");
InitTheme(FALSE);
//OptionMenu.FreeMenu(); // it is already freed at loop beginning
AboutMenu.Entries.Empty();
HelpMenu.Entries.Empty();
AboutMenu.Entries.setEmpty();
HelpMenu.Entries.setEmpty();
}
DBG("theme inited\n");
if (ThemeX.embedded) {

View File

@ -259,7 +259,7 @@ VOID FillInputs(BOOLEAN New)
InputItems[InputItemsCount++].SValue.SWPrintf("%06d", gSettings.RefCLK);
InputItems[InputItemsCount].ItemType = ASString; //51 OS version if non-detected
InputItems[InputItemsCount++].SValue.SWPrintf("%s ", NonDetected);
InputItems[InputItemsCount++].SValue.SWPrintf("%s ", NonDetected.c_str());
InputItems[InputItemsCount].ItemType = BoolValue; //52
InputItems[InputItemsCount++].BValue = gSettings.InjectEDID;
@ -427,7 +427,7 @@ VOID FillInputs(BOOLEAN New)
InputItems[InputItemsCount++].IValue = 116;
InputItems[InputItemsCount].ItemType = ASString; //117
InputItems[InputItemsCount++].SValue.SWPrintf("%s", gSettings.EfiVersion);
InputItems[InputItemsCount++].SValue.SWPrintf("%s", gSettings.EfiVersion.c_str());
InputItems[InputItemsCount].ItemType = ASString; //118
InputItems[InputItemsCount++].SValue.SWPrintf("%s", gSettings.BooterCfgStr);
@ -676,7 +676,7 @@ VOID ApplyInputs(VOID)
i++; //51
if (InputItems[i].Valid) {
snprintf(NonDetected, 64, "%ls", InputItems[i].SValue.wc_str());
NonDetected = InputItems[i].SValue;
}
i++; //52
@ -1019,7 +1019,7 @@ VOID ApplyInputs(VOID)
}
i++; //117
if (InputItems[i].Valid) {
snprintf(gSettings.EfiVersion, 64, "%ls", InputItems[i].SValue.wc_str());
gSettings.EfiVersion = InputItems[i].SValue;
}
i++; //118
if (InputItems[i].Valid) {
@ -1537,11 +1537,9 @@ VOID HelpRefit(VOID)
// user-callable dispatcher functions
//
REFIT_ABSTRACT_MENU_ENTRY* NewEntry_(REFIT_ABSTRACT_MENU_ENTRY *Entry, REFIT_MENU_SCREEN **SubScreen, ACTION AtClick, UINTN ID, CONST CHAR8 *CTitle)
REFIT_ABSTRACT_MENU_ENTRY* NewEntry_(REFIT_ABSTRACT_MENU_ENTRY *Entry, REFIT_MENU_SCREEN **SubScreen, ACTION AtClick, UINTN ID, const XString8& Title)
{
if (CTitle) Entry->Title.takeValueFrom(CTitle);
else Entry->Title.setEmpty();
Entry->Title = Title;
Entry->Image = OptionMenu.TitleImage;
Entry->AtClick = AtClick;
// create the submenu
@ -1554,7 +1552,7 @@ REFIT_ABSTRACT_MENU_ENTRY* NewEntry_(REFIT_ABSTRACT_MENU_ENTRY *Entry, REFIT_MEN
return Entry;
}
REFIT_MENU_ITEM_OPTIONS* newREFIT_MENU_ITEM_OPTIONS(REFIT_MENU_SCREEN **SubScreen, ACTION AtClick, UINTN ID, CONST CHAR8 *Title)
REFIT_MENU_ITEM_OPTIONS* newREFIT_MENU_ITEM_OPTIONS(REFIT_MENU_SCREEN **SubScreen, ACTION AtClick, UINTN ID, const XString8& Title)
{
REFIT_MENU_ITEM_OPTIONS* Entry = new REFIT_MENU_ITEM_OPTIONS();
return NewEntry_(Entry, SubScreen, AtClick, ID, Title)->getREFIT_MENU_ITEM_OPTIONS();
@ -1583,7 +1581,7 @@ REFIT_ABSTRACT_MENU_ENTRY *SubMenuGraphics()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_GRAPHICS, "Graphics Injector->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_GRAPHICS, "Graphics Injector->"_XS8);
SubScreen->AddMenuInfoLine_f("Number of VideoCard%s=%llu",((NGFX!=1)?"s":""), NGFX);
SubScreen->AddMenuItemInput(52, "InjectEDID", FALSE);
SubScreen->AddMenuItemInput(53, "Fake Vendor EDID:", TRUE);
@ -1671,7 +1669,7 @@ REFIT_ABSTRACT_MENU_ENTRY *SubMenuAudio()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the main menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_AUDIO, "Audio tuning->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_AUDIO, "Audio tuning->"_XS8);
// submenu description
SubScreen->AddMenuInfoLine_f("Choose options to tune the HDA devices");
@ -1706,7 +1704,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuSpeedStep()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_CPU, "CPU tuning->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_CPU, "CPU tuning->"_XS8);
SubScreen->AddMenuInfoLine_f("%s", gCPUStructure.BrandString);
SubScreen->AddMenuInfoLine_f("Model: %2X/%2X/%2X",
gCPUStructure.Family, gCPUStructure.Model, gCPUStructure.Stepping);
@ -1748,18 +1746,15 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuKextPatches()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
REFIT_INPUT_DIALOG *InputBootArgs;
INTN NrKexts = gSettings.KernelAndKextPatches.NrKexts;
KEXT_PATCH *KextPatchesMenu = gSettings.KernelAndKextPatches.KextPatches; //zzzz
INTN Index;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KEXTS, "Custom kexts patches->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KEXTS, "Custom kexts patches->"_XS8);
for (Index = 0; Index < NrKexts; Index++) {
for ( size_t Index = 0; Index < gSettings.KernelAndKextPatches.KextPatches.size(); Index++) {
InputBootArgs = new REFIT_INPUT_DIALOG;
InputBootArgs->Title.SWPrintf("%90s", KextPatchesMenu[Index].Label);
InputBootArgs->Title.SWPrintf("%90s", gSettings.KernelAndKextPatches.KextPatches[Index].Label.c_str());
// InputBootArgs->Tag = TAG_INPUT;
InputBootArgs->Row = 0xFFFF; //cursor
InputBootArgs->Item = &(KextPatchesMenu[Index].MenuItem);
InputBootArgs->Item = &(gSettings.KernelAndKextPatches.KextPatches[Index].MenuItem);
InputBootArgs->AtClick = ActionEnter;
InputBootArgs->AtRightClick = ActionDetails;
SubScreen->AddMenuEntry(InputBootArgs, true);
@ -1769,28 +1764,17 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuKextPatches()
return Entry;
}
REFIT_ABSTRACT_MENU_ENTRY* SubMenuKextBlockInjection(CONST CHAR16* UniSysVer)
REFIT_ABSTRACT_MENU_ENTRY* SubMenuKextBlockInjection(const XString8& UniSysVer)
{
REFIT_MENU_ITEM_OPTIONS *Entry = NULL;
REFIT_MENU_SCREEN *SubScreen = NULL;
REFIT_INPUT_DIALOG *InputBootArgs;
UINTN i = 0;
SIDELOAD_KEXT *Kext = NULL;
CHAR8 sysVer[256];
UnicodeStrToAsciiStrS(UniSysVer, sysVer, sizeof(sysVer));
for (i = 0; i < sizeof(sysVer)-2; i++) {
if (sysVer[i] == '\0') {
sysVer[i+0] = '-';
sysVer[i+1] = '>';
sysVer[i+2] = '\0';
break;
}
}
XString8 sysVer = S8Printf("%s->", UniSysVer.c_str());
Kext = InjectKextList;
while (Kext) {
if (StrCmp(Kext->KextDirNameUnderOEMPath.wc_str(), UniSysVer) == 0) {
if ( Kext->KextDirNameUnderOEMPath == UniSysVer ) {
if ( SubScreen == NULL ) {
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KEXT_INJECT, sysVer);
SubScreen->AddMenuInfoLine_f("Choose/check kext to disable:");
@ -1830,44 +1814,41 @@ LOADER_ENTRY* LOADER_ENTRY::SubMenuKextInjectMgmt()
REFIT_MENU_SCREEN *SubScreen;
XStringW kextDir;
// UINTN i;
CHAR8 ShortOSVersion[8];
XString8 ShortOSVersion;
// CHAR16 *UniSysVer = NULL;
CHAR8 *ChosenOS = OSVersion;
SubEntry = new LOADER_ENTRY();
NewEntry_(SubEntry, &SubScreen, ActionEnter, SCREEN_SYSTEM, "Block injected kexts->");
NewEntry_(SubEntry, &SubScreen, ActionEnter, SCREEN_SYSTEM, "Block injected kexts->"_XS8);
SubEntry->Flags = Flags;
if (ChosenOS) {
if (OSVersion.notEmpty()) {
// DBG("chosen os %s\n", ChosenOS);
//shorten os version 10.11.6 -> 10.11
for (int i = 0; i < 8; i++) {
ShortOSVersion[i] = ChosenOS[i];
if (ShortOSVersion[i] == '\0') {
if (OSVersion[i] == '\0') {
break;
}
if (((i > 2) && (ShortOSVersion[i] == '.')) || (i == 5)) {
ShortOSVersion[i] = '\0';
if (((i > 2) && (OSVersion[i] == '.')) || (i == 5)) {
break;
}
ShortOSVersion += OSVersion[i];
}
SubScreen->AddMenuInfoLine_f("Block injected kexts for target version of macOS: %s",
ShortOSVersion);
SubScreen->AddMenuInfoLine_f("Block injected kexts for target version of macOS: %s", ShortOSVersion.c_str());
// Add kext from 10
{
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(L"10"), true);
SubScreen->AddMenuEntry(SubMenuKextBlockInjection("10"_XS8), true);
CHAR16 DirName[256];
XString8 DirName;
if (OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "10_install");
DirName = "10_install"_XS8;
}
else {
if (OSTYPE_IS_OSX_RECOVERY(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "10_recovery");
DirName = "10_recovery"_XS8;
}
else {
snwprintf(DirName, sizeof(DirName), "10_normal");
DirName = "10_normal"_XS8;
}
}
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(DirName), true);
@ -1875,19 +1856,19 @@ LOADER_ENTRY* LOADER_ENTRY::SubMenuKextInjectMgmt()
// Add kext from 10.{version}
{
CHAR16 DirName[256];
snwprintf(DirName, sizeof(DirName), "%s", ShortOSVersion);
XString8 DirName;
DirName.takeValueFrom(ShortOSVersion);
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(DirName), true);
if (OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "%s_install", ShortOSVersion);
DirName.S8Printf("%s_install", ShortOSVersion.c_str());
}
else {
if (OSTYPE_IS_OSX_RECOVERY(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "%s_recovery", ShortOSVersion);
DirName.S8Printf("%s_recovery", ShortOSVersion.c_str());
}
else {
snwprintf(DirName, sizeof(DirName), "%s_normal", ShortOSVersion);
DirName.S8Printf("%s_normal", ShortOSVersion.c_str());
}
}
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(DirName), true);
@ -1898,44 +1879,40 @@ LOADER_ENTRY* LOADER_ENTRY::SubMenuKextInjectMgmt()
// 10.{version}.{minor version} if minor version is > 0
{
{
CHAR16 OSVersionKextsDirName[256];
if ( AsciiStrCmp(ShortOSVersion, OSVersion) == 0 ) {
snwprintf(OSVersionKextsDirName, sizeof(OSVersionKextsDirName), "%s.0", OSVersion);
XString8 OSVersionKextsDirName;
if ( ShortOSVersion == OSVersion ) {
OSVersionKextsDirName.S8Printf("%s.0", OSVersion.c_str());
}else{
snwprintf(OSVersionKextsDirName, sizeof(OSVersionKextsDirName), "%s", OSVersion);
OSVersionKextsDirName = OSVersion;
}
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(OSVersionKextsDirName), true);
}
CHAR16 DirName[256];
XString8 DirName;
if (OSTYPE_IS_OSX_INSTALLER(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "%s_install",
OSVersion);
DirName.S8Printf("%s_install", OSVersion.c_str());
}
else {
if (OSTYPE_IS_OSX_RECOVERY(LoaderType)) {
snwprintf(DirName, sizeof(DirName), "%s_recovery",
OSVersion);
DirName.S8Printf("%s_recovery", OSVersion.c_str());
}
else {
snwprintf(DirName, sizeof(DirName), "%s_normal",
OSVersion);
DirName.S8Printf("%s_normal", OSVersion.c_str());
}
}
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(DirName), true);
}
}
else {
SubScreen->AddMenuInfoLine_f("Block injected kexts for target version of macOS: %s",
ChosenOS);
SubScreen->AddMenuInfoLine_f("Block injected kexts for target version of macOS: %s", OSVersion.c_str());
}
kextDir = GetOtherKextsDir(TRUE);
if ( kextDir.notEmpty() ) {
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(L"Other"), true);
SubScreen->AddMenuEntry(SubMenuKextBlockInjection("Other"_XS8), true);
}
kextDir = GetOtherKextsDir(FALSE);
if ( kextDir.notEmpty() ) {
SubScreen->AddMenuEntry(SubMenuKextBlockInjection(L"Off"), true);
SubScreen->AddMenuEntry(SubMenuKextBlockInjection("Off"_XS8), true);
}
SubScreen->AddMenuEntry(&MenuEntryReturn, false);
@ -1949,18 +1926,15 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuKernelPatches()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
REFIT_INPUT_DIALOG *InputBootArgs;
INTN NrKernels = gSettings.KernelAndKextPatches.NrKernels;
KERNEL_PATCH *KernelPatchesMenu = gSettings.KernelAndKextPatches.KernelPatches; //zzzz
INTN Index;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KERNELS, "Custom kernel patches->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KERNELS, "Custom kernel patches->"_XS8);
for (Index = 0; Index < NrKernels; Index++) {
for (size_t Index = 0; Index < gSettings.KernelAndKextPatches.KernelPatches.size(); Index++) {
InputBootArgs = new REFIT_INPUT_DIALOG;
InputBootArgs->Title.SWPrintf("%90s", KernelPatchesMenu[Index].Label);
InputBootArgs->Title.SWPrintf("%90s", gSettings.KernelAndKextPatches.KernelPatches[Index].Label.c_str());
// InputBootArgs->Tag = TAG_INPUT;
InputBootArgs->Row = 0xFFFF; //cursor
InputBootArgs->Item = &(KernelPatchesMenu[Index].MenuItem);
InputBootArgs->Item = &(gSettings.KernelAndKextPatches.KernelPatches[Index].MenuItem);
InputBootArgs->AtClick = ActionEnter;
InputBootArgs->AtRightClick = ActionDetails;
SubScreen->AddMenuEntry(InputBootArgs, true);
@ -1975,18 +1949,15 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuBootPatches()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
REFIT_INPUT_DIALOG *InputBootArgs;
INTN NrBoots = gSettings.KernelAndKextPatches.NrBoots;
KERNEL_PATCH *BootPatchesMenu = gSettings.KernelAndKextPatches.BootPatches; //zzzz
INTN Index;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BOOTER, "Custom booter patches->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BOOTER, "Custom booter patches->"_XS8);
for (Index = 0; Index < NrBoots; Index++) {
for (size_t Index = 0; Index < gSettings.KernelAndKextPatches.BootPatches.size(); Index++) {
InputBootArgs = new REFIT_INPUT_DIALOG;
InputBootArgs->Title.SWPrintf("%90s", BootPatchesMenu[Index].Label);
InputBootArgs->Title.SWPrintf("%90s", gSettings.KernelAndKextPatches.BootPatches[Index].Label.c_str());
// InputBootArgs->Tag = TAG_INPUT;
InputBootArgs->Row = 0xFFFF; //cursor
InputBootArgs->Item = &(BootPatchesMenu[Index].MenuItem);
InputBootArgs->Item = &(gSettings.KernelAndKextPatches.BootPatches[Index].MenuItem);
InputBootArgs->AtClick = ActionEnter;
InputBootArgs->AtRightClick = ActionDetails;
SubScreen->AddMenuEntry(InputBootArgs, true);
@ -2001,7 +1972,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuBinaries()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BINARIES, "Binaries patching->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BINARIES, "Binaries patching->"_XS8);
SubScreen->AddMenuInfoLine_f("%s", gCPUStructure.BrandString);
SubScreen->AddMenuInfoLine_f("Real CPUID: 0x%06X", gCPUStructure.Signature);
@ -2040,7 +2011,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuDropTables()
sign[4] = 0;
OTID[8] = 0;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_TABLES, "Tables dropping->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_TABLES, "Tables dropping->"_XS8);
if (gSettings.ACPIDropTables) {
ACPI_DROP_TABLE *DropTable = gSettings.ACPIDropTables;
@ -2091,7 +2062,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuSmbios()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_SMBIOS, "SMBIOS->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_SMBIOS, "SMBIOS->"_XS8);
SubScreen->AddMenuInfoLine_f("%s", gCPUStructure.BrandString);
SubScreen->AddMenuInfoLine_f("%s", gSettings.OEMProduct);
@ -2122,7 +2093,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuDsdtFix()
REFIT_MENU_SCREEN *SubScreen;
// REFIT_INPUT_DIALOG *InputBootArgs;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DSDT, NULL);
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DSDT, NullXString8);
// Entry->Title.SPrintf("DSDT fix mask [0x%08hhx]->", gSettings.FixDsdt);
SubScreen->AddMenuCheck("Add DTGP", FIX_DTGP, 67);
@ -2174,7 +2145,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuDSDTPatches()
INPUT_ITEM *DSDTPatchesMenu = gSettings.PatchDsdtMenuItem;
INTN Index;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DSDT_PATCHES, "Custom DSDT patches->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DSDT_PATCHES, "Custom DSDT patches->"_XS8);
for (Index = 0; Index < PatchDsdtNum; Index++) {
InputBootArgs = new REFIT_INPUT_DIALOG;
@ -2198,7 +2169,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuDsdts()
REFIT_MENU_SWITCH *InputBootArgs;
UINTN i;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_ACPI, "Dsdt name->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_ACPI, "Dsdt name->"_XS8);
SubScreen->AddMenuInfoLine_f("Select a DSDT file:");
SubScreen->AddMenuItemSwitch(116, "BIOS.aml", FALSE);
@ -2225,7 +2196,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuACPI()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the options menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_ACPI, "ACPI patching->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_ACPI, "ACPI patching->"_XS8);
// submenu description
SubScreen->AddMenuInfoLine_f("Choose options to patch ACPI");
@ -2250,7 +2221,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuAudioPort()
REFIT_MENU_SWITCH *InputBootArgs;
UINTN i;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_AUDIOPORTS, "Startup sound output->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_AUDIOPORTS, "Startup sound output->"_XS8);
SubScreen->AddMenuInfoLine_f("Select an audio output, press F7 to test");
SubScreen->AddMenuItemInput(120, "Volume:", TRUE);
@ -2312,7 +2283,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuCustomDevices()
UINT32 DevAddr, OldDevAddr = 0;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DEVICES, "Custom properties->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_DEVICES, "Custom properties->"_XS8);
if (gSettings.ArbProperties) {
DEV_PROPERTY *Prop = gSettings.ArbProperties;
@ -2352,7 +2323,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuPCI()
REFIT_MENU_ITEM_OPTIONS *Entry;
REFIT_MENU_SCREEN *SubScreen;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_USB, "PCI devices->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_USB, "PCI devices->"_XS8);
SubScreen->AddMenuItemInput(74, "USB Ownership", FALSE);
SubScreen->AddMenuItemInput(92, "USB Injection", FALSE);
@ -2379,7 +2350,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuThemes()
REFIT_MENU_SWITCH *InputBootArgs;
UINTN i;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_THEME, "Themes->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_THEME, "Themes->"_XS8);
SubScreen->AddMenuInfoLine_f("Installed themes:");
//add embedded
@ -2406,7 +2377,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuGUI()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the options menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_GUI, "GUI tuning->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_GUI, "GUI tuning->"_XS8);
// submenu description
SubScreen->AddMenuInfoLine_f("Choose options to tune the Interface");
@ -2434,7 +2405,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuCSR()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the main menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_CSR, NULL);
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_CSR, NullXString8);
// submenu description
SubScreen->AddMenuInfoLine_f("Modify the System Integrity Protection configuration.");
@ -2465,7 +2436,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuBLC()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the main menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BLC, NULL);
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_BLC, NullXString8);
// Entry->Title.SPrintf("boot_args->flags [0x%02hhx]->", gSettings.BooterConfig);
// submenu description
@ -2493,13 +2464,13 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuSystem()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the options menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_SYSTEM, "System Parameters->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_SYSTEM, "System Parameters->"_XS8);
// submenu description
SubScreen->AddMenuInfoLine_f("Choose options for booted OS");
SubScreen->AddMenuItemInput(2, "Block kext:", TRUE);
SubScreen->AddMenuItemInput(51, "Set OS version if not:", TRUE);
SubScreen->AddMenuItemInput(51, "Set OS version if not detected:", TRUE);
SubScreen->AddMenuItemInput(118, "Booter Cfg Command:", TRUE);
SubScreen->AddMenuEntry(SubMenuCSR(), true);
@ -2516,7 +2487,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuConfigs()
REFIT_MENU_SWITCH *InputBootArgs;
UINTN i;
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_THEME, "Configs->");
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_THEME, "Configs->"_XS8);
SubScreen->AddMenuInfoLine_f("Select a config file:");
@ -2541,7 +2512,7 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuQuirks()
REFIT_MENU_SCREEN *SubScreen;
// create the entry in the main menu
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_QUIRKS, NULL);
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_QUIRKS, NullXString8);
Entry->Title.SWPrintf("Quirks mask [0x%04x]->", gSettings.QuirksMask);
// submenu description