Handle Skip in patches.
This commit is contained in:
parent
fc3fa0de26
commit
d540f76b54
|
@ -1 +1 @@
|
|||
Subproject commit 39fb43413e5d3377de65bd0355a11b790edada4f
|
||||
Subproject commit 70c07161095c63031461308d60a43c8189795c10
|
|
@ -4,9 +4,22 @@
|
|||
*/
|
||||
|
||||
#include "MemoryOperation.h"
|
||||
#include <BootLog.h>
|
||||
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
||||
#ifndef DEBUG_MEMORYOPERATION
|
||||
#define DEBUG_MEMORYOPERATION 1
|
||||
#else
|
||||
#define DEBUG_MAIN DEBUG_ALL
|
||||
#endif
|
||||
|
||||
#if DEBUG_MEMORYOPERATION == 0
|
||||
#define DBG(...)
|
||||
#else
|
||||
#define DBG(...) DebugLog(DEBUG_MEMORYOPERATION, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Searches Source for Search pattern of size SearchSize
|
||||
|
@ -111,19 +124,59 @@ UINTN FindMemMask(const UINT8 *Source, UINTN SourceSize, const UINT8 *Search, UI
|
|||
}
|
||||
|
||||
UINTN SearchAndReplaceMask(UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, const UINT8 *MaskSearch, UINTN SearchSize,
|
||||
const UINT8 *Replace, const UINT8 *MaskReplace, INTN MaxReplaces)
|
||||
const UINT8 *Replace, const UINT8 *MaskReplace, INTN MaxReplaces, INTN Skip)
|
||||
{
|
||||
UINTN NumReplaces = 0;
|
||||
BOOLEAN NoReplacesRestriction = MaxReplaces <= 0;
|
||||
UINT8* SourceBak = Source;
|
||||
UINT8 *End = Source + SourceSize;
|
||||
if (!Source || !Search || !Replace || !SearchSize) {
|
||||
return 0;
|
||||
}
|
||||
while ((Source < End) && (NoReplacesRestriction || (MaxReplaces > 0))) {
|
||||
if (CompareMemMask((const UINT8 *)Source, Search, SearchSize, MaskSearch, SearchSize)) {
|
||||
CopyMemMask(Source, Replace, MaskReplace, SearchSize);
|
||||
NumReplaces++;
|
||||
MaxReplaces--;
|
||||
if ( Skip == 0 ) {
|
||||
DBG("Replace " );
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", Search[Index]);
|
||||
}
|
||||
if ( MaskSearch ) {
|
||||
DBG("/" );
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", MaskSearch[Index]);
|
||||
}
|
||||
DBG("(" );
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", Source[Index]);
|
||||
}
|
||||
DBG(")" );
|
||||
}
|
||||
DBG(" by " );
|
||||
|
||||
CopyMemMask(Source, Replace, MaskReplace, SearchSize);
|
||||
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", Replace[Index]);
|
||||
}
|
||||
if ( MaskReplace ) {
|
||||
DBG("/");
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", MaskReplace[Index]);
|
||||
}
|
||||
DBG("(");
|
||||
for (UINTN Index = 0; Index < SearchSize; ++Index) {
|
||||
DBG("%02X", Source[Index]);
|
||||
}
|
||||
DBG(")");
|
||||
}
|
||||
|
||||
DBG(" at ofs:%lX\n", Source-SourceBak);
|
||||
|
||||
NumReplaces++;
|
||||
MaxReplaces--;
|
||||
}else{
|
||||
--Skip;
|
||||
}
|
||||
Source += SearchSize;
|
||||
} else {
|
||||
Source++;
|
||||
|
|
|
@ -45,7 +45,7 @@ void CopyMemMask(UINT8 *Dest, const UINT8 *Replace, const UINT8 *Mask, UINTN Sea
|
|||
UINTN FindMemMask(const UINT8 *Source, UINTN SourceSize, const UINT8 *Search, UINTN SearchSize, const UINT8 *MaskSearch, UINTN MaskSize);
|
||||
|
||||
UINTN SearchAndReplaceMask(UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, const UINT8 *MaskSearch, UINTN SearchSize,
|
||||
const UINT8 *Replace, const UINT8 *MaskReplace, INTN MaxReplaces);
|
||||
const UINT8 *Replace, const UINT8 *MaskReplace, INTN MaxReplaces, INTN Skip);
|
||||
|
||||
|
||||
UINTN SearchAndReplaceTxt(UINT8 *Source, UINT64 SourceSize, const UINT8 *Search, UINTN SearchSize, const UINT8 *Replace, INTN MaxReplaces);
|
||||
|
|
|
@ -2399,8 +2399,8 @@ LOADER_ENTRY::KernelUserPatch()
|
|||
KernelAndKextPatches.KernelPatches[i].Data.size(),
|
||||
(const UINT8*)KernelAndKextPatches.KernelPatches[i].Patch.data(),
|
||||
(const UINT8*)KernelAndKextPatches.KernelPatches[i].MaskReplace.data(),
|
||||
KernelAndKextPatches.KernelPatches[i].Count
|
||||
);
|
||||
KernelAndKextPatches.KernelPatches[i].Count,
|
||||
KernelAndKextPatches.KernelPatches[i].Skip);
|
||||
|
||||
if (Num) {
|
||||
y++;
|
||||
|
@ -2459,8 +2459,8 @@ LOADER_ENTRY::BooterPatch(IN UINT8 *BooterData, IN UINT64 BooterSize)
|
|||
KernelAndKextPatches.BootPatches[i].Data.size(),
|
||||
(const UINT8*)KernelAndKextPatches.BootPatches[i].Patch.data(),
|
||||
(const UINT8*)KernelAndKextPatches.BootPatches[i].MaskReplace.data(),
|
||||
KernelAndKextPatches.BootPatches[i].Count
|
||||
);
|
||||
KernelAndKextPatches.BootPatches[i].Count,
|
||||
KernelAndKextPatches.BootPatches[i].Skip);
|
||||
if (Num) {
|
||||
y++;
|
||||
curs += SearchLen - 1;
|
||||
|
|
|
@ -982,7 +982,8 @@ void LOADER_ENTRY::AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPli
|
|||
kextpatch.Data.size(),
|
||||
kextpatch.Patch.data(),
|
||||
kextpatch.MaskReplace.data(),
|
||||
kextpatch.Count);
|
||||
kextpatch.Count,
|
||||
kextpatch.Skip);
|
||||
if (Num) {
|
||||
curs += SearchLen - 1;
|
||||
j += SearchLen - 1;
|
||||
|
|
|
@ -46,7 +46,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 10,
|
||||
(UINT8*)"\x13\x14\x15", NULL, 3,
|
||||
(UINT8*)"\x23\x24\x25", NULL,
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 10) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 10,
|
||||
(UINT8*)"\x13\x00\x15", (UINT8*)"\xFF\x00\xFF", 3,
|
||||
(UINT8*)"\x23\x24\x25", NULL,
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 10) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 10,
|
||||
(UINT8*)"\x13\x00\x15", (UINT8*)"\xFF\x00\xFF", 3,
|
||||
(UINT8*)"\x23\x24\x25", (UINT8*)"\xFF\x00\xFF",
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 10) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 10,
|
||||
(UINT8*)"\x13\x00\x15", (UINT8*)"\xFF\x00\xFF", 3,
|
||||
(UINT8*)"\x23\x24\x25", (UINT8*)"\xFF\xFF\x00",
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 10) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 3,
|
||||
(UINT8*)"\xC0", (UINT8*)"\xF0", 1,
|
||||
(UINT8*)"\x22", (UINT8*)"\x0F",
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 3) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 8,
|
||||
(UINT8*)"\x43\x6c\x65\x76\x65\x72", (UINT8*)"\xDF\xFF\xFF\xFF\xFF\xFF", 6,
|
||||
(UINT8*)"\x43\x6c\x6f\x76\x65\x72", (UINT8*)"\x00\x00\xFF\x00\x00\x00",
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 3) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ int find_replace_mask_Clover_tests()
|
|||
uintn = SearchAndReplaceMask(buf, 8,
|
||||
(UINT8*)"\x43\x6c\x65\x76\x65\x72", (UINT8*)"\xDF\xFF\xFF\xFF\xFF\xFF", 6,
|
||||
(UINT8*)"\x43\x6c\x6f\x76\x65\x72", (UINT8*)"\x00\x00\xFF\x00\x00\x00",
|
||||
0);
|
||||
0, 0);
|
||||
if ( uintn != 1 ) breakpoint(1);
|
||||
if ( memcmp(buf, expectedBuf, 3) != 0 ) breakpoint(1);
|
||||
}
|
||||
|
|
|
@ -717,6 +717,11 @@ void LOADER_ENTRY::DelegateKernelPatches()
|
|||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Replace, kextPatch.Patch.vdata(), kextPatch.Patch.size());
|
||||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->ReplaceMask, kextPatch.MaskReplace.vdata(), kextPatch.MaskReplace.size());
|
||||
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Skip = (UINT32)kextPatch.Skip;
|
||||
#ifdef JIEF_DEBUG
|
||||
if ( kextPatch.Label == "algrey - cpuid_set_info - ryzen cores and logicals count - part 3 - 10.14"_XS8 ) {
|
||||
DEBUG (( DEBUG_INFO, "" ));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue