mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-14 10:05:43 +01:00
symbolic kexts and kernel patcher
Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
parent
f78d6dbb7c
commit
a621438d7c
@ -453,7 +453,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
<dict>
|
<dict>
|
||||||
<key>Comment</key>
|
<key>Comment</key>
|
||||||
<string>Lapci panic patch example</string>
|
<string>Lapic panic patch example</string>
|
||||||
<key>MatchOS</key>
|
<key>MatchOS</key>
|
||||||
<string>All</string>
|
<string>All</string>
|
||||||
<key>Disabled</key>
|
<key>Disabled</key>
|
||||||
@ -473,6 +473,26 @@
|
|||||||
<key>RangeFind</key>
|
<key>RangeFind</key>
|
||||||
<integer>200</integer>
|
<integer>200</integer>
|
||||||
</dict>
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>Comment</key>
|
||||||
|
<string>Symbolic patch example got lapic panic</string>
|
||||||
|
<key>MatchOS</key>
|
||||||
|
<string>All</string>
|
||||||
|
<key>Disabled</key>
|
||||||
|
<true/>
|
||||||
|
<key>Procedure</key>
|
||||||
|
<string>_lapic_interrupt</string>
|
||||||
|
<key>Find</key>
|
||||||
|
<data>6AAA//+DAAAAAAAA</data>
|
||||||
|
<key>MaskFind</key>
|
||||||
|
<data>/wAA////AAAAAP//</data>
|
||||||
|
<key>Replace</key>
|
||||||
|
<data>6AAA//8xwJCQkJCQ</data>
|
||||||
|
<key>MaskReplace</key>
|
||||||
|
<data>/wAA////////////</data>
|
||||||
|
<key>RangeFind</key>
|
||||||
|
<integer>200</integer>
|
||||||
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>#ForceKextsToLoad</key>
|
<key>#ForceKextsToLoad</key>
|
||||||
<array>
|
<array>
|
||||||
|
@ -2521,12 +2521,7 @@
|
|||||||
A5717012235A187C000CEC60 /* DataHubStdErrDxe.uni */ = {isa = PBXFileReference; lastKnownFileType = text; path = DataHubStdErrDxe.uni; sourceTree = "<group>"; };
|
A5717012235A187C000CEC60 /* DataHubStdErrDxe.uni */ = {isa = PBXFileReference; lastKnownFileType = text; path = DataHubStdErrDxe.uni; sourceTree = "<group>"; };
|
||||||
A5717014235A188B000CEC60 /* DriverOverride.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = DriverOverride.c; sourceTree = "<group>"; };
|
A5717014235A188B000CEC60 /* DriverOverride.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = DriverOverride.c; sourceTree = "<group>"; };
|
||||||
A5717015235A188B000CEC60 /* DriverOverride.inf */ = {isa = PBXFileReference; lastKnownFileType = text; path = DriverOverride.inf; sourceTree = "<group>"; };
|
A5717015235A188B000CEC60 /* DriverOverride.inf */ = {isa = PBXFileReference; lastKnownFileType = text; path = DriverOverride.inf; sourceTree = "<group>"; };
|
||||||
A571C26F2405749900B6A2C5 /* XStringWArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray.h; sourceTree = "<group>"; };
|
|
||||||
A571C2702405749900B6A2C5 /* XToolsCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = "<group>"; };
|
A571C2702405749900B6A2C5 /* XToolsCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = "<group>"; };
|
||||||
A571C2712405749900B6A2C5 /* XStringW.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringW.h; sourceTree = "<group>"; };
|
|
||||||
A571C2722405749900B6A2C5 /* XStringWArray.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XStringWArray.cpp; sourceTree = "<group>"; };
|
|
||||||
A571C2732405749900B6A2C5 /* XStringW.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XStringW.cpp; sourceTree = "<group>"; };
|
|
||||||
A571C2772405749900B6A2C5 /* XToolsCommon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon.cpp; sourceTree = "<group>"; };
|
|
||||||
A571C2792405749900B6A2C5 /* XArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = "<group>"; };
|
A571C2792405749900B6A2C5 /* XArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = "<group>"; };
|
||||||
A571C27A2405749900B6A2C5 /* XObjArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = "<group>"; };
|
A571C27A2405749900B6A2C5 /* XObjArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = "<group>"; };
|
||||||
A571C27D240574A100B6A2C5 /* XStringWArray_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray_test.h; sourceTree = "<group>"; };
|
A571C27D240574A100B6A2C5 /* XStringWArray_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray_test.h; sourceTree = "<group>"; };
|
||||||
@ -8355,11 +8350,6 @@
|
|||||||
A57CF7CA241BE0D6006DE51E /* XString.h */,
|
A57CF7CA241BE0D6006DE51E /* XString.h */,
|
||||||
A5D12C33243A0BD900DFA98A /* XStringArray.cpp */,
|
A5D12C33243A0BD900DFA98A /* XStringArray.cpp */,
|
||||||
A5D12C32243A0BD900DFA98A /* XStringArray.h */,
|
A5D12C32243A0BD900DFA98A /* XStringArray.h */,
|
||||||
A571C2732405749900B6A2C5 /* XStringW.cpp */,
|
|
||||||
A571C2712405749900B6A2C5 /* XStringW.h */,
|
|
||||||
A571C2722405749900B6A2C5 /* XStringWArray.cpp */,
|
|
||||||
A571C26F2405749900B6A2C5 /* XStringWArray.h */,
|
|
||||||
A571C2772405749900B6A2C5 /* XToolsCommon.cpp */,
|
|
||||||
A571C2702405749900B6A2C5 /* XToolsCommon.h */,
|
A571C2702405749900B6A2C5 /* XToolsCommon.h */,
|
||||||
);
|
);
|
||||||
path = cpp_foundation;
|
path = cpp_foundation;
|
||||||
|
@ -457,8 +457,8 @@ VOID PatchAllTables()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Len = FixAny((UINT8*)NewTable, Len,
|
Len = FixAny((UINT8*)NewTable, Len,
|
||||||
gSettings.PatchDsdtFind[i], gSettings.LenToFind[i],
|
(const UINT8*)gSettings.PatchDsdtFind[i], gSettings.LenToFind[i],
|
||||||
gSettings.PatchDsdtReplace[i], gSettings.LenToReplace[i]);
|
(const UINT8*)gSettings.PatchDsdtReplace[i], gSettings.LenToReplace[i]);
|
||||||
//DBG(" OK\n");
|
//DBG(" OK\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ void aml_destroy_node(AML_CHUNK* node)
|
|||||||
FreePool(node);
|
FreePool(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, /* CONST*/ UINT8* buffer, UINT32 size)
|
AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, CONST UINT8* buffer, UINT32 size)
|
||||||
{
|
{
|
||||||
AML_CHUNK* node = aml_create_node(parent);
|
AML_CHUNK* node = aml_create_node(parent);
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ typedef struct aml_chunk AML_CHUNK;
|
|||||||
BOOLEAN aml_add_to_parent(AML_CHUNK* parent, AML_CHUNK* node);
|
BOOLEAN aml_add_to_parent(AML_CHUNK* parent, AML_CHUNK* node);
|
||||||
AML_CHUNK* aml_create_node(AML_CHUNK* parent);
|
AML_CHUNK* aml_create_node(AML_CHUNK* parent);
|
||||||
VOID aml_destroy_node(AML_CHUNK* node);
|
VOID aml_destroy_node(AML_CHUNK* node);
|
||||||
AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, /* CONST*/ UINT8* buffer, UINT32 size);
|
AML_CHUNK* aml_add_buffer(AML_CHUNK* parent, CONST UINT8* buffer, UINT32 size);
|
||||||
AML_CHUNK* aml_add_byte(AML_CHUNK* parent, UINT8 value);
|
AML_CHUNK* aml_add_byte(AML_CHUNK* parent, UINT8 value);
|
||||||
AML_CHUNK* aml_add_word(AML_CHUNK* parent, UINT16 value);
|
AML_CHUNK* aml_add_word(AML_CHUNK* parent, UINT16 value);
|
||||||
AML_CHUNK* aml_add_dword(AML_CHUNK* parent, UINT32 value);
|
AML_CHUNK* aml_add_dword(AML_CHUNK* parent, UINT32 value);
|
||||||
|
@ -393,57 +393,57 @@ UINT8 hpet1[] = // Name (_CID, EisaId ("PNP0C01"))
|
|||||||
0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x01
|
0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x01
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
UINT8 wakret[] = { 0xA4, 0x12, 0x04, 0x02, 0x00, 0x00 };
|
const UINT8 wakret[] = { 0xA4, 0x12, 0x04, 0x02, 0x00, 0x00 };
|
||||||
UINT8 wakslp1[] = { 0x5B, 0x80, 0x50, 0x4D, 0x33, 0x30, 0x01 };
|
const UINT8 wakslp1[] = { 0x5B, 0x80, 0x50, 0x4D, 0x33, 0x30, 0x01 };
|
||||||
UINT8 wakslp2[] = { 0x0A, 0x08, 0x5B, 0x81, 0x0D, 0x50, 0x4D, 0x33, 0x30, 0x01,
|
const UINT8 wakslp2[] = { 0x0A, 0x08, 0x5B, 0x81, 0x0D, 0x50, 0x4D, 0x33, 0x30, 0x01,
|
||||||
0x00, 0x04, 0x53, 0x4C, 0x4D, 0x45, 0x01, 0x70, 0x00, 0x53, 0x4C, 0x4D, 0x45 };
|
0x00, 0x04, 0x53, 0x4C, 0x4D, 0x45, 0x01, 0x70, 0x00, 0x53, 0x4C, 0x4D, 0x45 };
|
||||||
|
|
||||||
UINT8 waksecur[] = {0xA0, 0x0D, 0x91, 0x95, 0x68, 0x01, 0x94, 0x68, 0x0A, 0x05,
|
const UINT8 waksecur[] = {0xA0, 0x0D, 0x91, 0x95, 0x68, 0x01, 0x94, 0x68, 0x0A, 0x05,
|
||||||
0x70, 0x0A, 0x03, 0x68};
|
0x70, 0x0A, 0x03, 0x68};
|
||||||
|
|
||||||
UINT8 pwrb[] = { //? \_SB_PWRB, 0x02
|
const UINT8 pwrb[] = { //? \_SB_PWRB, 0x02
|
||||||
0x86, 0x5C, 0x2E, 0x5F, 0x53, 0x42, 0x5F, 0x50, 0x57, 0x52, 0x42, 0x0A, 0x02
|
0x86, 0x5C, 0x2E, 0x5F, 0x53, 0x42, 0x5F, 0x50, 0x57, 0x52, 0x42, 0x0A, 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UINT8 acpi3[] = { //Name(_HID, "ACPI003")
|
const UINT8 acpi3[] = { //Name(_HID, "ACPI003")
|
||||||
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0D,
|
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0D,
|
||||||
0x41, 0x43, 0x50, 0x49, 0x30, 0x30, 0x30, 0x33, 0x00
|
0x41, 0x43, 0x50, 0x49, 0x30, 0x30, 0x30, 0x33, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
//Name (_PRW, Package (0x02){0x1C, 0x03}
|
//Name (_PRW, Package (0x02){0x1C, 0x03}
|
||||||
UINT8 prw1c[] = {
|
const UINT8 prw1c[] = {
|
||||||
0x08, 0x5F, 0x50, 0x52, 0x57, 0x12, 0x06, 0x02, 0x0A, 0x1C, 0x0A, 0x03
|
0x08, 0x5F, 0x50, 0x52, 0x57, 0x12, 0x06, 0x02, 0x0A, 0x1C, 0x0A, 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UINT8 dtgp_1[] = { // DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
|
const UINT8 dtgp_1[] = { // DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0))
|
||||||
// Return (Local0)
|
// Return (Local0)
|
||||||
0x44, 0x54, 0x47, 0x50, 0x68, 0x69, 0x6A, 0x6B,
|
0x44, 0x54, 0x47, 0x50, 0x68, 0x69, 0x6A, 0x6B,
|
||||||
0x71, 0x60, 0xA4, 0x60
|
0x71, 0x60, 0xA4, 0x60
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT8 pwrbcid[] = {
|
const UINT8 pwrbcid[] = {
|
||||||
0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x0E, 0x14,
|
0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x0E, 0x14,
|
||||||
0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, 0x0A,
|
0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, 0x0A,
|
||||||
0x0B, 0x0A, 0x04
|
0x0B, 0x0A, 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT8 pwrbprw[] = {
|
const UINT8 pwrbprw[] = {
|
||||||
0x14, 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02,
|
0x14, 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02,
|
||||||
0x0A, 0x0B, 0x0A, 0x04
|
0x0A, 0x0B, 0x0A, 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT8 shutdown0[] = {
|
const UINT8 shutdown0[] = {
|
||||||
0xA0, 0x05, 0x93, 0x68, 0x0A, 0x05, 0xA1, 0x01
|
0xA0, 0x05, 0x93, 0x68, 0x0A, 0x05, 0xA1, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT8 shutdown1[] = {
|
const UINT8 shutdown1[] = {
|
||||||
0xA0, 0x0F, 0x91, 0x91, 0x93, 0x68, 0x0A, 0x03, 0x93, 0x68, 0x0A, 0x04, 0x93, 0x68, 0x0A, 0x05, 0xA1, 0x01
|
0xA0, 0x0F, 0x91, 0x91, 0x93, 0x68, 0x0A, 0x03, 0x93, 0x68, 0x0A, 0x04, 0x93, 0x68, 0x0A, 0x05, 0xA1, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UINT8 pnlf[] = {
|
const UINT8 pnlf[] = {
|
||||||
0x5B, 0x82, 0x2D, 0x50, 0x4E, 0x4C, 0x46, //Device (PNLF)
|
0x5B, 0x82, 0x2D, 0x50, 0x4E, 0x4C, 0x46, //Device (PNLF)
|
||||||
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0C, 0x06, 0x10, 0x00, 0x02, // Name (_HID, EisaId ("APP0002"))
|
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0C, 0x06, 0x10, 0x00, 0x02, // Name (_HID, EisaId ("APP0002"))
|
||||||
0x08, 0x5F, 0x43, 0x49, 0x44, // Name (_CID,
|
0x08, 0x5F, 0x43, 0x49, 0x44, // Name (_CID,
|
||||||
@ -452,7 +452,7 @@ UINT8 pnlf[] = {
|
|||||||
0x08, 0x5F, 0x53, 0x54, 0x41, 0x0A, 0x0B // Name (_STA, 0x0B)
|
0x08, 0x5F, 0x53, 0x54, 0x41, 0x0A, 0x0B // Name (_STA, 0x0B)
|
||||||
};
|
};
|
||||||
//Scope (_SB.PCI0.LPCB)
|
//Scope (_SB.PCI0.LPCB)
|
||||||
UINT8 pnlfLPC[] = {
|
const UINT8 pnlfLPC[] = {
|
||||||
0x10, 0x3e, 0x2f, 0x03, 0x5f, 0x53, 0x42, 0x5f, 0x50, 0x43, 0x49, 0x30, 0x4c, 0x50, 0x43, 0x42,
|
0x10, 0x3e, 0x2f, 0x03, 0x5f, 0x53, 0x42, 0x5f, 0x50, 0x43, 0x49, 0x30, 0x4c, 0x50, 0x43, 0x42,
|
||||||
0x5b, 0x82, 0x2d, 0x50, 0x4e, 0x4c, 0x46, 0x08, 0x5f, 0x48, 0x49,
|
0x5b, 0x82, 0x2d, 0x50, 0x4e, 0x4c, 0x46, 0x08, 0x5f, 0x48, 0x49,
|
||||||
0x44, 0x0c, 0x06, 0x10, 0x00, 0x02, 0x08, 0x5f, 0x43, 0x49, 0x44, 0x0d,
|
0x44, 0x0c, 0x06, 0x10, 0x00, 0x02, 0x08, 0x5f, 0x43, 0x49, 0x44, 0x0d,
|
||||||
@ -461,11 +461,11 @@ UINT8 pnlfLPC[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UINT8 app2[] = { //Name (_HID, EisaId("APP0002"))
|
const UINT8 app2[] = { //Name (_HID, EisaId("APP0002"))
|
||||||
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0C, 0x06, 0x10, 0x00, 0x02
|
0x08, 0x5F, 0x48, 0x49, 0x44, 0x0C, 0x06, 0x10, 0x00, 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT8 darwin[] =
|
UINT8 darwin[] = //it is not const
|
||||||
{ //addresses shifted by 0x24
|
{ //addresses shifted by 0x24
|
||||||
0x08, 0x56, 0x45, 0x52, // 00000020 " .. .VER"
|
0x08, 0x56, 0x45, 0x52, // 00000020 " .. .VER"
|
||||||
0x30, 0x0D, 0x43, 0x6C, 0x6F, 0x76, 0x65, 0x72, // 00000028 "0.Clover"
|
0x30, 0x0D, 0x43, 0x6C, 0x6F, 0x76, 0x65, 0x72, // 00000028 "0.Clover"
|
||||||
@ -1312,7 +1312,7 @@ INT32 CmpDev(UINT8 *dsdt, UINT32 i, UINT8 *Name)
|
|||||||
|
|
||||||
//the procedure can find BIN array UNSIGNED CHAR8 sizeof N inside part of large array "dsdt" size of len
|
//the procedure can find BIN array UNSIGNED CHAR8 sizeof N inside part of large array "dsdt" size of len
|
||||||
// return position or -1 if not found
|
// return position or -1 if not found
|
||||||
INT32 FindBin (UINT8 *dsdt, UINT32 len, UINT8* bin, UINT32 N)
|
INT32 FindBin (UINT8 *dsdt, UINT32 len, const UINT8* bin, UINT32 N)
|
||||||
{
|
{
|
||||||
UINT32 i, j;
|
UINT32 i, j;
|
||||||
BOOLEAN eq;
|
BOOLEAN eq;
|
||||||
@ -1707,7 +1707,7 @@ UINT32 FixADP1 (UINT8* dsdt, UINT32 len)
|
|||||||
INT32 sizeoffset, shift;
|
INT32 sizeoffset, shift;
|
||||||
CHAR8 Name[4];
|
CHAR8 Name[4];
|
||||||
DBG("Start ADP1 fix\n");
|
DBG("Start ADP1 fix\n");
|
||||||
shift = FindBin(dsdt, len, (UINT8*)acpi3, sizeof(acpi3));
|
shift = FindBin(dsdt, len, (const UINT8*)acpi3, sizeof(acpi3));
|
||||||
if (shift < 0) {
|
if (shift < 0) {
|
||||||
// not found - create new one or do nothing
|
// not found - create new one or do nothing
|
||||||
MsgLog("no device(AC) exists\n");
|
MsgLog("no device(AC) exists\n");
|
||||||
@ -1729,7 +1729,7 @@ UINT32 FixADP1 (UINT8* dsdt, UINT32 len)
|
|||||||
}
|
}
|
||||||
ReplaceName(dsdt, len, Name, "ADP1");
|
ReplaceName(dsdt, len, Name, "ADP1");
|
||||||
//find PRW
|
//find PRW
|
||||||
if(FindBin(dsdt+adr, size, (UINT8*)prw1c, 8) >= 0){
|
if(FindBin(dsdt+adr, size, (const UINT8*)prw1c, 8) >= 0){
|
||||||
DBG("_prw is present\n");
|
DBG("_prw is present\n");
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
@ -1744,7 +1744,7 @@ UINT32 FixADP1 (UINT8* dsdt, UINT32 len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 FixAny (UINT8* dsdt, UINT32 len, UINT8* ToFind, UINT32 LenTF, UINT8* ToReplace, UINT32 LenTR)
|
UINT32 FixAny (UINT8* dsdt, UINT32 len, const UINT8* ToFind, UINT32 LenTF, const UINT8* ToReplace, UINT32 LenTR)
|
||||||
{
|
{
|
||||||
INT32 sizeoffset, adr;
|
INT32 sizeoffset, adr;
|
||||||
UINT32 i;
|
UINT32 i;
|
||||||
@ -1790,7 +1790,7 @@ UINT32 FixAny (UINT8* dsdt, UINT32 len, UINT8* ToFind, UINT32 LenTF, UINT8* ToRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
//new method. by goodwin_c
|
//new method. by goodwin_c
|
||||||
UINT32 FixRenameByBridge2 (UINT8* dsdt, UINT32 len, CHAR8* TgtBrgName, UINT8* ToFind, UINT32 LenTF, UINT8* ToReplace, UINT32 LenTR)
|
UINT32 FixRenameByBridge2 (UINT8* dsdt, UINT32 len, CHAR8* TgtBrgName, const UINT8* ToFind, UINT32 LenTF, UINT8* ToReplace, UINT32 LenTR)
|
||||||
{
|
{
|
||||||
INT32 adr;
|
INT32 adr;
|
||||||
BOOLEAN found = FALSE;
|
BOOLEAN found = FALSE;
|
||||||
@ -1910,7 +1910,7 @@ UINT32 AddPNLF (UINT8 *dsdt, UINT32 len)
|
|||||||
UINT32 adr = 0;
|
UINT32 adr = 0;
|
||||||
DBG("Start PNLF Fix\n");
|
DBG("Start PNLF Fix\n");
|
||||||
|
|
||||||
if (FindBin(dsdt, len, (UINT8*)app2, 10) >= 0) {
|
if (FindBin(dsdt, len, app2, 10) >= 0) {
|
||||||
return len; //the device already exists
|
return len; //the device already exists
|
||||||
}
|
}
|
||||||
//search PWRB PNP0C0C
|
//search PWRB PNP0C0C
|
||||||
@ -4899,7 +4899,7 @@ UINT32 FIXSHUTDOWN_ASUS (UINT8 *dsdt, UINT32 len)
|
|||||||
{
|
{
|
||||||
UINT32 i, j, sizeoffset = 0;
|
UINT32 i, j, sizeoffset = 0;
|
||||||
UINT32 adr, adr1 = 0, adr2, size, shift = 0;
|
UINT32 adr, adr1 = 0, adr2, size, shift = 0;
|
||||||
UINT8 *shutdown = NULL;
|
const UINT8 *shutdown;
|
||||||
|
|
||||||
DBG("Start SHUTDOWN Fix len=%X\n", len);
|
DBG("Start SHUTDOWN Fix len=%X\n", len);
|
||||||
adr = FindMethod(dsdt, len, "_PTS");
|
adr = FindMethod(dsdt, len, "_PTS");
|
||||||
@ -5306,13 +5306,13 @@ VOID RenameDevices(UINT8* table)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
shift = FindBin(table + adr, (UINT32)(len - adr), (UINT8*)Find, 4); //next occurence
|
shift = FindBin(table + adr, (UINT32)(len - adr), (const UINT8*)Find, 4); //next occurence
|
||||||
if (shift < 0) {
|
if (shift < 0) {
|
||||||
break; //not found
|
break; //not found
|
||||||
}
|
}
|
||||||
adr += shift;
|
adr += shift;
|
||||||
// DBG("found Name @ 0x%X\n", adr);
|
// DBG("found Name @ 0x%X\n", adr);
|
||||||
if (!Bridge || (FindBin(table + adr - 4, 5, (UINT8*)(Bridge->Name), 4) == 0)) { // long name like "RP02.PXSX"
|
if (!Bridge || (FindBin(table + adr - 4, 5, (const UINT8*)(Bridge->Name), 4) == 0)) { // long name like "RP02.PXSX"
|
||||||
CopyMem(table + adr, Replace, 4);
|
CopyMem(table + adr, Replace, 4);
|
||||||
adr += 5; //at least, it is impossible to see PXSXPXSX
|
adr += 5; //at least, it is impossible to see PXSXPXSX
|
||||||
// DBG("replaced\n");
|
// DBG("replaced\n");
|
||||||
@ -5409,14 +5409,14 @@ VOID FixBiosDsdt (UINT8* temp, EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE* fadt,
|
|||||||
if (gSettings.PatchDsdtMenuItem[i].BValue) {
|
if (gSettings.PatchDsdtMenuItem[i].BValue) {
|
||||||
if (!gSettings.PatchDsdtTgt[i]) {
|
if (!gSettings.PatchDsdtTgt[i]) {
|
||||||
DsdtLen = FixAny(temp, DsdtLen,
|
DsdtLen = FixAny(temp, DsdtLen,
|
||||||
gSettings.PatchDsdtFind[i], gSettings.LenToFind[i],
|
(const UINT8*)gSettings.PatchDsdtFind[i], gSettings.LenToFind[i],
|
||||||
gSettings.PatchDsdtReplace[i], gSettings.LenToReplace[i]);
|
(const UINT8*)gSettings.PatchDsdtReplace[i], gSettings.LenToReplace[i]);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
// DBG("Patching: renaming in bridge\n");
|
// DBG("Patching: renaming in bridge\n");
|
||||||
DsdtLen = FixRenameByBridge2(temp, DsdtLen,
|
DsdtLen = FixRenameByBridge2(temp, DsdtLen,
|
||||||
gSettings.PatchDsdtTgt[i],
|
gSettings.PatchDsdtTgt[i],
|
||||||
gSettings.PatchDsdtFind[i],
|
(const UINT8*)gSettings.PatchDsdtFind[i],
|
||||||
gSettings.LenToFind[i],
|
gSettings.LenToFind[i],
|
||||||
gSettings.PatchDsdtReplace[i],
|
gSettings.PatchDsdtReplace[i],
|
||||||
gSettings.LenToReplace[i]);
|
gSettings.LenToReplace[i]);
|
||||||
|
@ -76,7 +76,7 @@ INT32
|
|||||||
FindBin (
|
FindBin (
|
||||||
UINT8 *Array,
|
UINT8 *Array,
|
||||||
UINT32 ArrayLen,
|
UINT32 ArrayLen,
|
||||||
UINT8 *Pattern,
|
const UINT8 *Pattern,
|
||||||
UINT32 PatternLen
|
UINT32 PatternLen
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -85,9 +85,9 @@ UINT32
|
|||||||
FixAny (
|
FixAny (
|
||||||
UINT8* dsdt,
|
UINT8* dsdt,
|
||||||
UINT32 len,
|
UINT32 len,
|
||||||
UINT8* ToFind,
|
const UINT8* ToFind,
|
||||||
UINT32 LenTF,
|
UINT32 LenTF,
|
||||||
UINT8* ToReplace,
|
const UINT8* ToReplace,
|
||||||
UINT32 LenTR
|
UINT32 LenTR
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -69,15 +69,20 @@ struct mach_header {
|
|||||||
* The 64-bit mach header appears at the very beginning of object files for
|
* The 64-bit mach header appears at the very beginning of object files for
|
||||||
* 64-bit architectures.
|
* 64-bit architectures.
|
||||||
*/
|
*/
|
||||||
|
//CFFAEDFE 07000001 03000000 02000000 12000000 D00F0000 01002000 00000000
|
||||||
|
//19000000 88010000
|
||||||
|
//5F5F5445 58540000 00000000 00000000
|
||||||
|
//00002000 80FFFFFF
|
||||||
|
|
||||||
struct mach_header_64 {
|
struct mach_header_64 {
|
||||||
uint32_t magic; /* mach magic number identifier */
|
uint32_t magic; // mach magic number identifier = 0xFEEDFACF
|
||||||
cpu_type_t cputype; /* cpu specifier */
|
cpu_type_t cputype; // cpu specifier UINT32 = 0x01000007
|
||||||
cpu_subtype_t cpusubtype; /* machine specifier */
|
cpu_subtype_t cpusubtype; // machine specifier = 0x03
|
||||||
uint32_t filetype; /* type of file */
|
uint32_t filetype; // type of file = 0x02 MH_EXECUTE
|
||||||
uint32_t ncmds; /* number of load commands */
|
uint32_t ncmds; // number of load commands = 0x12
|
||||||
uint32_t sizeofcmds; /* the size of all the load commands */
|
uint32_t sizeofcmds; // the size of all the load commands = 0x0FD0
|
||||||
uint32_t flags; /* flags */
|
uint32_t flags; // flags = 0x 0020 0001 (MH_NOUNDEFS | MH_PIE)
|
||||||
uint32_t reserved; /* reserved */
|
uint32_t reserved; // reserved
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Constant for the magic field of the mach_header_64 (64-bit architectures) */
|
/* Constant for the magic field of the mach_header_64 (64-bit architectures) */
|
||||||
|
@ -777,6 +777,13 @@ CopyKernelAndKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Dst,
|
|||||||
Dst->KextPatches[Dst->NrKexts].StartPattern = NULL;
|
Dst->KextPatches[Dst->NrKexts].StartPattern = NULL;
|
||||||
Dst->KextPatches[Dst->NrKexts].StartMask = NULL;
|
Dst->KextPatches[Dst->NrKexts].StartMask = NULL;
|
||||||
}
|
}
|
||||||
|
//ProcedureName
|
||||||
|
if (Src->KextPatches[i].ProcedureName != NULL) {
|
||||||
|
INTN len = strlen(Src->KextPatches[i].ProcedureName);
|
||||||
|
Dst->KextPatches[Dst->NrKexts].ProcedureName = (__typeof__(Dst->KextPatches[Dst->NrKexts].ProcedureName))AllocateCopyPool(len+1, Src->KextPatches[i].ProcedureName);
|
||||||
|
} else {
|
||||||
|
Dst->KextPatches[Dst->NrKexts].ProcedureName = NULL;
|
||||||
|
}
|
||||||
Dst->KextPatches[Dst->NrKexts].StartPatternLen = Src->KextPatches[i].StartPatternLen;
|
Dst->KextPatches[Dst->NrKexts].StartPatternLen = Src->KextPatches[i].StartPatternLen;
|
||||||
Dst->KextPatches[Dst->NrKexts].SearchLen = Src->KextPatches[i].SearchLen;
|
Dst->KextPatches[Dst->NrKexts].SearchLen = Src->KextPatches[i].SearchLen;
|
||||||
++(Dst->NrKexts);
|
++(Dst->NrKexts);
|
||||||
@ -825,6 +832,12 @@ CopyKernelAndKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Dst,
|
|||||||
}
|
}
|
||||||
Dst->KernelPatches[Dst->NrKernels].StartPatternLen = Src->KernelPatches[Dst->NrKernels].StartPatternLen;
|
Dst->KernelPatches[Dst->NrKernels].StartPatternLen = Src->KernelPatches[Dst->NrKernels].StartPatternLen;
|
||||||
Dst->KernelPatches[Dst->NrKernels].SearchLen = Src->KernelPatches[Dst->NrKernels].SearchLen;
|
Dst->KernelPatches[Dst->NrKernels].SearchLen = Src->KernelPatches[Dst->NrKernels].SearchLen;
|
||||||
|
if (Src->KernelPatches[i].ProcedureName != NULL) {
|
||||||
|
INTN len = strlen(Src->KernelPatches[i].ProcedureName);
|
||||||
|
Dst->KernelPatches[Dst->NrKernels].ProcedureName = (__typeof__(Dst->KernelPatches[Dst->NrKernels].ProcedureName))AllocateCopyPool(len, Src->KernelPatches[i].ProcedureName);
|
||||||
|
} else {
|
||||||
|
Dst->KernelPatches[Dst->NrKernels].ProcedureName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
++(Dst->NrKernels);
|
++(Dst->NrKernels);
|
||||||
}
|
}
|
||||||
@ -1164,6 +1177,13 @@ FillinKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Patches,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dict = GetProperty(Prop2, "Procedure");
|
||||||
|
if (Dict != NULL) {
|
||||||
|
INTN len = strlen(Dict->string);
|
||||||
|
Patches->KextPatches[Patches->NrKexts].ProcedureName = (__typeof__(Patches->KextPatches[Patches->NrKexts].ProcedureName))AllocateCopyPool(len, Dict->string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Patches->KextPatches[Patches->NrKexts].Data = (__typeof__(Patches->KextPatches[Patches->NrKexts].Data))AllocateCopyPool(FindLen, TmpData);
|
Patches->KextPatches[Patches->NrKexts].Data = (__typeof__(Patches->KextPatches[Patches->NrKexts].Data))AllocateCopyPool(FindLen, TmpData);
|
||||||
Patches->KextPatches[Patches->NrKexts].DataLen = FindLen;
|
Patches->KextPatches[Patches->NrKexts].DataLen = FindLen;
|
||||||
FreePool(TmpData);
|
FreePool(TmpData);
|
||||||
@ -1336,6 +1356,13 @@ FillinKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Patches,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dict = GetProperty(Prop2, "Procedure");
|
||||||
|
if (Dict != NULL) {
|
||||||
|
INTN len = strlen(Dict->string);
|
||||||
|
Patches->KernelPatches[Patches->NrKernels].ProcedureName = (__typeof__(Patches->KernelPatches[Patches->NrKernels].ProcedureName))AllocateCopyPool(len, Dict->string);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Patches->KernelPatches[Patches->NrKernels].Data = (__typeof__(Patches->KernelPatches[Patches->NrKernels].Data))AllocateCopyPool(FindLen, TmpData);
|
Patches->KernelPatches[Patches->NrKernels].Data = (__typeof__(Patches->KernelPatches[Patches->NrKernels].Data))AllocateCopyPool(FindLen, TmpData);
|
||||||
Patches->KernelPatches[Patches->NrKernels].DataLen = FindLen;
|
Patches->KernelPatches[Patches->NrKernels].DataLen = FindLen;
|
||||||
FreePool(TmpData);
|
FreePool(TmpData);
|
||||||
|
@ -79,6 +79,54 @@ VOID SetKernelRelocBase()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//search a procedure by Name and return its offset in the kernel
|
||||||
|
UINTN searchProc(unsigned char * kernel, UINTN kernelSize, const char *procedure, UINTN *procLen)
|
||||||
|
{
|
||||||
|
if (!procedure) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
INT32 TextAdr = FindBin(kernel, 0x60, (const UINT8 *)kTextSegment, (UINT32)strlen(kTextSegment));
|
||||||
|
if (TextAdr == -1) {
|
||||||
|
TextAdr = 0x28; //ugly hack, not really needed
|
||||||
|
}
|
||||||
|
SEGMENT *TextSeg = (SEGMENT*)&kernel[TextAdr];
|
||||||
|
UINT64 Absolut = TextSeg->SegAddress;
|
||||||
|
|
||||||
|
INT32 LinkAdr = FindBin(kernel, 0x1000, (const UINT8 *)kLinkEditSegment, (UINT32)strlen(kLinkEditSegment));
|
||||||
|
if (LinkAdr == -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
SEGMENT *LinkSeg = (SEGMENT*)&kernel[LinkAdr];
|
||||||
|
UINT32 AddrVtable = LinkSeg->AddrVtable;
|
||||||
|
UINT32 SizeVtable = LinkSeg->SizeVtable;
|
||||||
|
const char* Names = (const char*)(&kernel[LinkSeg->AddrNames]);
|
||||||
|
VTABLE * vArray = (VTABLE*)(&kernel[AddrVtable]);
|
||||||
|
//search for the name
|
||||||
|
UINTN nameLen = strlen(procedure);
|
||||||
|
size_t i;
|
||||||
|
bool found = false;
|
||||||
|
for (i=0; i<SizeVtable; ++i) {
|
||||||
|
size_t Offset = vArray[i].NameOffset;
|
||||||
|
if (CompareMem(&Names[Offset], procedure, nameLen) == 0) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
UINT64 procAddr = vArray[i].ProcAddr - Absolut;
|
||||||
|
UINT64 prevAddr;
|
||||||
|
if (i == 0) {
|
||||||
|
prevAddr = Absolut;
|
||||||
|
} else {
|
||||||
|
prevAddr = vArray[i-1].ProcAddr;
|
||||||
|
}
|
||||||
|
*procLen = vArray[i].ProcAddr - prevAddr;
|
||||||
|
return procAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//TimeWalker - extended and corrected for systems up to Yosemite
|
//TimeWalker - extended and corrected for systems up to Yosemite
|
||||||
VOID KernelPatcher_64(VOID* kernelData, LOADER_ENTRY *Entry)
|
VOID KernelPatcher_64(VOID* kernelData, LOADER_ENTRY *Entry)
|
||||||
{
|
{
|
||||||
@ -512,18 +560,18 @@ BOOLEAN PatchCPUID(UINT8* bytes, UINT8* Location, INT32 LenLoc,
|
|||||||
UINT8 FakeModel = (Entry->KernelAndKextPatches->FakeCPUID >> 4) & 0x0f;
|
UINT8 FakeModel = (Entry->KernelAndKextPatches->FakeCPUID >> 4) & 0x0f;
|
||||||
UINT8 FakeExt = (Entry->KernelAndKextPatches->FakeCPUID >> 0x10) & 0x0f;
|
UINT8 FakeExt = (Entry->KernelAndKextPatches->FakeCPUID >> 0x10) & 0x0f;
|
||||||
for (Num = 0; Num < 2; Num++) {
|
for (Num = 0; Num < 2; Num++) {
|
||||||
Adr = FindBin(&bytes[Adr], 0x800000 - Adr, Location, LenLoc);
|
Adr = FindBin(&bytes[Adr], 0x800000 - Adr, (const UINT8*)Location, (UINT32)LenLoc);
|
||||||
if (Adr < 0) {
|
if (Adr < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DBG_RT(Entry, "found location at %x\n", Adr);
|
DBG_RT(Entry, "found location at %x\n", Adr);
|
||||||
patchLocation = FindBin(&bytes[Adr], 0x100, Search4, Len);
|
patchLocation = FindBin(&bytes[Adr], 0x100, (const UINT8*)Search4, (UINT32)Len);
|
||||||
if (patchLocation > 0 && patchLocation < 70) {
|
if (patchLocation > 0 && patchLocation < 70) {
|
||||||
//found
|
//found
|
||||||
DBG_RT(Entry, "found Model location at %x\n", Adr + patchLocation);
|
DBG_RT(Entry, "found Model location at %x\n", Adr + patchLocation);
|
||||||
CopyMem(&bytes[Adr + patchLocation], ReplaceModel, Len);
|
CopyMem(&bytes[Adr + patchLocation], ReplaceModel, Len);
|
||||||
bytes[Adr + patchLocation + 1] = FakeModel;
|
bytes[Adr + patchLocation + 1] = FakeModel;
|
||||||
patchLocation1 = FindBin(&bytes[Adr], 0x100, Search10, Len);
|
patchLocation1 = FindBin(&bytes[Adr], 0x100, (const UINT8*)Search10, (UINT32)Len);
|
||||||
if (patchLocation1 > 0 && patchLocation1 < 100) {
|
if (patchLocation1 > 0 && patchLocation1 < 100) {
|
||||||
DBG_RT(Entry, "found ExtModel location at %x\n", Adr + patchLocation1);
|
DBG_RT(Entry, "found ExtModel location at %x\n", Adr + patchLocation1);
|
||||||
CopyMem(&bytes[Adr + patchLocation1], ReplaceExt, Len);
|
CopyMem(&bytes[Adr + patchLocation1], ReplaceExt, Len);
|
||||||
@ -655,7 +703,7 @@ BOOLEAN KernelPatchPm(VOID *kernelData, LOADER_ENTRY *Entry)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC UINT8 PanicNoKextDumpFind[6] = {0x00, 0x25, 0x2E, 0x2A, 0x73, 0x00};
|
const UINT8 PanicNoKextDumpFind[] = {0x00, 0x25, 0x2E, 0x2A, 0x73, 0x00};
|
||||||
//STATIC UINT8 PanicNoKextDumpReplace[6] = {0x00, 0x00, 0x2E, 0x2A, 0x73, 0x00};
|
//STATIC UINT8 PanicNoKextDumpReplace[6] = {0x00, 0x00, 0x2E, 0x2A, 0x73, 0x00};
|
||||||
|
|
||||||
BOOLEAN KernelPanicNoKextDump(VOID *kernelData)
|
BOOLEAN KernelPanicNoKextDump(VOID *kernelData)
|
||||||
@ -1795,10 +1843,21 @@ KernelUserPatch(IN UINT8 *UKernelData, LOADER_ENTRY *Entry)
|
|||||||
DBG_RT(Entry, "==> disabled\n");
|
DBG_RT(Entry, "==> disabled\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!Entry->KernelAndKextPatches->KernelPatches[i].SearchLen) {
|
bool once = false;
|
||||||
|
UINTN procLen = 0;
|
||||||
|
UINTN procAddr = searchProc(UKernelData, KERNEL_MAX_SIZE,
|
||||||
|
Entry->KernelAndKextPatches->KernelPatches[i].ProcedureName, &procLen);
|
||||||
|
|
||||||
|
if (Entry->KernelAndKextPatches->KernelPatches[i].SearchLen == 0) {
|
||||||
Entry->KernelAndKextPatches->KernelPatches[i].SearchLen = KERNEL_MAX_SIZE;
|
Entry->KernelAndKextPatches->KernelPatches[i].SearchLen = KERNEL_MAX_SIZE;
|
||||||
|
if (procLen > KERNEL_MAX_SIZE) {
|
||||||
|
procLen = KERNEL_MAX_SIZE - procAddr;
|
||||||
|
once = true;
|
||||||
}
|
}
|
||||||
UINT8 * curs = UKernelData;
|
} else {
|
||||||
|
procLen = Entry->KernelAndKextPatches->KernelPatches[i].SearchLen;
|
||||||
|
}
|
||||||
|
UINT8 * curs = &UKernelData[procAddr];
|
||||||
UINTN j = 0;
|
UINTN j = 0;
|
||||||
while (j < KERNEL_MAX_SIZE) {
|
while (j < KERNEL_MAX_SIZE) {
|
||||||
if (!Entry->KernelAndKextPatches->KernelPatches[i].StartPattern || //old behavior
|
if (!Entry->KernelAndKextPatches->KernelPatches[i].StartPattern || //old behavior
|
||||||
@ -1808,7 +1867,7 @@ KernelUserPatch(IN UINT8 *UKernelData, LOADER_ENTRY *Entry)
|
|||||||
Entry->KernelAndKextPatches->KernelPatches[i].StartPatternLen)) {
|
Entry->KernelAndKextPatches->KernelPatches[i].StartPatternLen)) {
|
||||||
DBG_RT(Entry, " StartPattern found\n");
|
DBG_RT(Entry, " StartPattern found\n");
|
||||||
Num = SearchAndReplaceMask(curs,
|
Num = SearchAndReplaceMask(curs,
|
||||||
Entry->KernelAndKextPatches->KernelPatches[i].SearchLen,
|
procLen,
|
||||||
Entry->KernelAndKextPatches->KernelPatches[i].Data,
|
Entry->KernelAndKextPatches->KernelPatches[i].Data,
|
||||||
Entry->KernelAndKextPatches->KernelPatches[i].MaskFind,
|
Entry->KernelAndKextPatches->KernelPatches[i].MaskFind,
|
||||||
Entry->KernelAndKextPatches->KernelPatches[i].DataLen,
|
Entry->KernelAndKextPatches->KernelPatches[i].DataLen,
|
||||||
@ -1823,7 +1882,8 @@ KernelUserPatch(IN UINT8 *UKernelData, LOADER_ENTRY *Entry)
|
|||||||
j += Entry->KernelAndKextPatches->KernelPatches[i].SearchLen - 1;
|
j += Entry->KernelAndKextPatches->KernelPatches[i].SearchLen - 1;
|
||||||
}
|
}
|
||||||
DBG_RT(Entry, "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
|
DBG_RT(Entry, "==> %s : %lld replaces done\n", Num ? "Success" : "Error", Num);
|
||||||
if (!Entry->KernelAndKextPatches->KernelPatches[i].StartPattern ||
|
if (once ||
|
||||||
|
!Entry->KernelAndKextPatches->KernelPatches[i].StartPattern ||
|
||||||
!Entry->KernelAndKextPatches->KernelPatches[i].StartPatternLen) {
|
!Entry->KernelAndKextPatches->KernelPatches[i].StartPatternLen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
#define kPrelinkInfoSegment "__PRELINK_INFO"
|
#define kPrelinkInfoSegment "__PRELINK_INFO"
|
||||||
#define kPrelinkInfoSection "__info"
|
#define kPrelinkInfoSection "__info"
|
||||||
|
|
||||||
|
#define kTextSegment "__TEXT"
|
||||||
|
#define kLinkEditSegment "__LINKEDIT"
|
||||||
|
|
||||||
#define kPrelinkBundlePathKey "_PrelinkBundlePath"
|
#define kPrelinkBundlePathKey "_PrelinkBundlePath"
|
||||||
#define kPrelinkExecutableRelativePathKey "_PrelinkExecutableRelativePath"
|
#define kPrelinkExecutableRelativePathKey "_PrelinkExecutableRelativePath"
|
||||||
#define kPrelinkExecutableLoadKey "_PrelinkExecutableLoadAddr"
|
#define kPrelinkExecutableLoadKey "_PrelinkExecutableLoadAddr"
|
||||||
@ -71,6 +74,20 @@ typedef struct _DeviceTreeBuffer {
|
|||||||
uint32_t length;
|
uint32_t length;
|
||||||
} _DeviceTreeBuffer;
|
} _DeviceTreeBuffer;
|
||||||
|
|
||||||
|
typedef struct VTABLE {
|
||||||
|
UINT32 NameOffset;
|
||||||
|
UINT32 Attr;
|
||||||
|
UINT64 ProcAddr;
|
||||||
|
} VTABLE;
|
||||||
|
|
||||||
|
typedef struct SEGMENT {
|
||||||
|
CHAR8 Name[16]; //0
|
||||||
|
UINT64 SegAddress; //16
|
||||||
|
UINT32 Cmd[12]; //24
|
||||||
|
UINT32 AddrVtable; //72
|
||||||
|
UINT32 SizeVtable; //76
|
||||||
|
UINT32 AddrNames; //80
|
||||||
|
} SEGMENT;
|
||||||
|
|
||||||
|
|
||||||
extern EFI_PHYSICAL_ADDRESS KernelRelocBase;
|
extern EFI_PHYSICAL_ADDRESS KernelRelocBase;
|
||||||
@ -159,4 +176,6 @@ UINTN SearchAndReplace(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINTN Se
|
|||||||
|
|
||||||
UINTN SearchAndReplaceMask(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINT8 *MaskSearch, UINTN SearchSize, UINT8 *Replace, UINT8 *MaskReplace, INTN MaxReplaces);
|
UINTN SearchAndReplaceMask(UINT8 *Source, UINT64 SourceSize, UINT8 *Search, UINT8 *MaskSearch, UINTN SearchSize, UINT8 *Replace, UINT8 *MaskReplace, INTN MaxReplaces);
|
||||||
|
|
||||||
|
UINTN searchProc(unsigned char * kernel, UINTN kernelSize, const char *procedure, UINTN *procLen);
|
||||||
|
|
||||||
#endif /* !__LIBSAIO_KERNEL_PATCHER_H */
|
#endif /* !__LIBSAIO_KERNEL_PATCHER_H */
|
||||||
|
@ -987,7 +987,21 @@ VOID AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 Inf
|
|||||||
if (!Entry->KernelAndKextPatches->KextPatches[N].IsPlistPatch) {
|
if (!Entry->KernelAndKextPatches->KextPatches[N].IsPlistPatch) {
|
||||||
// kext binary patch
|
// kext binary patch
|
||||||
DBG_RT(Entry, "Binary patch\n");
|
DBG_RT(Entry, "Binary patch\n");
|
||||||
UINT8 * curs = Driver;
|
bool once = false;
|
||||||
|
UINTN procLen = 0;
|
||||||
|
UINTN procAddr = searchProc(Driver, DriverSize,
|
||||||
|
Entry->KernelAndKextPatches->KextPatches[N].ProcedureName, &procLen);
|
||||||
|
|
||||||
|
if (Entry->KernelAndKextPatches->KextPatches[N].SearchLen == 0) {
|
||||||
|
Entry->KernelAndKextPatches->KextPatches[N].SearchLen = DriverSize;
|
||||||
|
if (procLen > DriverSize) {
|
||||||
|
procLen = DriverSize - procAddr;
|
||||||
|
once = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
procLen = Entry->KernelAndKextPatches->KextPatches[N].SearchLen;
|
||||||
|
}
|
||||||
|
UINT8 * curs = &Driver[procAddr];
|
||||||
UINTN j = 0;
|
UINTN j = 0;
|
||||||
while (j < DriverSize) {
|
while (j < DriverSize) {
|
||||||
if (!Entry->KernelAndKextPatches->KextPatches[N].StartPattern || //old behavior
|
if (!Entry->KernelAndKextPatches->KextPatches[N].StartPattern || //old behavior
|
||||||
@ -998,7 +1012,7 @@ VOID AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 Inf
|
|||||||
DBG_RT(Entry, " StartPattern found\n");
|
DBG_RT(Entry, " StartPattern found\n");
|
||||||
|
|
||||||
Num = SearchAndReplaceMask(Driver,
|
Num = SearchAndReplaceMask(Driver,
|
||||||
Entry->KernelAndKextPatches->KextPatches[N].SearchLen,
|
procLen,
|
||||||
Entry->KernelAndKextPatches->KextPatches[N].Data,
|
Entry->KernelAndKextPatches->KextPatches[N].Data,
|
||||||
Entry->KernelAndKextPatches->KextPatches[N].MaskFind,
|
Entry->KernelAndKextPatches->KextPatches[N].MaskFind,
|
||||||
Entry->KernelAndKextPatches->KextPatches[N].DataLen,
|
Entry->KernelAndKextPatches->KextPatches[N].DataLen,
|
||||||
@ -1010,7 +1024,8 @@ VOID AnyKextPatch(UINT8 *Driver, UINT32 DriverSize, CHAR8 *InfoPlist, UINT32 Inf
|
|||||||
j += Entry->KernelAndKextPatches->KextPatches[N].SearchLen - 1;
|
j += Entry->KernelAndKextPatches->KextPatches[N].SearchLen - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Entry->KernelAndKextPatches->KextPatches[N].StartPattern ||
|
if (once ||
|
||||||
|
!Entry->KernelAndKextPatches->KextPatches[N].StartPattern ||
|
||||||
!Entry->KernelAndKextPatches->KextPatches[N].StartPatternLen) {
|
!Entry->KernelAndKextPatches->KextPatches[N].StartPatternLen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -281,6 +281,7 @@ struct KEXT_PATCH
|
|||||||
UINT8 *StartMask;
|
UINT8 *StartMask;
|
||||||
INTN StartPatternLen;
|
INTN StartPatternLen;
|
||||||
INTN SearchLen;
|
INTN SearchLen;
|
||||||
|
CHAR8 *ProcedureName; //procedure len will be StartPatternLen
|
||||||
CHAR8 *MatchOS;
|
CHAR8 *MatchOS;
|
||||||
CHAR8 *MatchBuild;
|
CHAR8 *MatchBuild;
|
||||||
INPUT_ITEM MenuItem;
|
INPUT_ITEM MenuItem;
|
||||||
@ -297,6 +298,7 @@ typedef struct {
|
|||||||
UINT8 *StartMask;
|
UINT8 *StartMask;
|
||||||
INTN StartPatternLen;
|
INTN StartPatternLen;
|
||||||
INTN SearchLen;
|
INTN SearchLen;
|
||||||
|
CHAR8 *ProcedureName;
|
||||||
INTN Count;
|
INTN Count;
|
||||||
CHAR8 *MatchOS;
|
CHAR8 *MatchOS;
|
||||||
CHAR8 *MatchBuild;
|
CHAR8 *MatchBuild;
|
||||||
|
Loading…
Reference in New Issue
Block a user