Chameleon

Chameleon Commit Details

Date:2017-03-25 19:29:41 (7 years 24 days ago)
Author:ErmaC
Commit:2871
Parents: 2870
Message:Add embedded KernelPatcher (Micky1979)
Changes:
A/branches/ErmaC/Enoch/i386/boot2/sse3_5_patcher.h
A/branches/ErmaC/Enoch/i386/boot2/kernel_patcher_internal.c
A/branches/ErmaC/Enoch/i386/boot2/kernel_patcher_internal.h
A/branches/ErmaC/Enoch/i386/boot2/sse3_patcher.h
M/branches/ErmaC/Enoch/i386/boot2/config.h
M/branches/ErmaC/Enoch/i386/boot2/Makefile
M/branches/ErmaC/Enoch/i386/libsaio/load.c
M/branches/ErmaC/Enoch/i386/boot2/drivers.c
M/branches/ErmaC/Enoch/i386/boot2/boot.c
M/branches/ErmaC/Enoch/i386/boot2/boot.h

File differences

branches/ErmaC/Enoch/i386/libsaio/load.c
3030
3131
3232
33
34
3335
3436
3537
......
4749
4850
4951
52
5053
5154
5255
......
171174
172175
173176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
174216
175217
176218
#include <mach/machine/thread_status.h>
#include <sl.h>
#include "boot.h"
#include "kernel_patcher_internal.h"
#if DEBUG
#define DBG(x...)printf(x)
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType = CPU_TYPE_I386;
bool incompatibleModuleLoaded = false;
//==============================================================================
// Public function.
return -1;
}
if (skipKernelPatcher)
{
verbose("\nInternal kernel patcher skipped as requested\n\n");
}
else
{
if( is_module_loaded("KernelPatcher.dylib"))
{
verbose("\nKernelPatcher.dylib prevent the internal kernel/kexts Patcher, skipped!\n\n");
incompatibleModuleLoaded = true;
}
else
{
// call the kernel patcher main function
/*
if (( KernelBooter_kexts ||
KernelPm ||
KernelLapicError ||
KernelLapicVersion ||
KernelHaswell ||
KernelcpuFamily ||
KernelSSE3 ) &&
(MacOSVerCurrent >= MacOSVer2Int("10.6"))
)
{
patch_kernel_internal(binary, uncompressed_size);
}
*/
// since users can done their own patches, just ensure for the minimum OS version
// w/o dependencies from other patches (e.g KernelBooter_kexts)
if (MacOSVerCurrent >= MacOSVer2Int("10.6"))
{
patch_kernel_internal(binary, uncompressed_size);
}
}
}
cmdBase = cmdstart;
ncmds = mH->ncmds;
branches/ErmaC/Enoch/i386/boot2/config.h
1515
1616
1717
18
18
19
20
1921
2022
2123
////////////////////////////////// drivers.c
//////////////////////////////////
////////////////////////////////// kernel_patcher.c
#define DEBUG_KERNEL 0// 0 mean NO show verbose message, 1 mean YES show verbose message
#define KEXTPATCH_SUPPORT 0// 1 enabled by default
////////////////////////////////// hpet.c
#define DEBUG_HPET 0
branches/ErmaC/Enoch/i386/boot2/sse3_5_patcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const uint8_t sse3_5_patcher[] = {
0x55, 0x48, 0x89, 0xe5, 0x48, 0x89, 0xf0, 0x48,
0x89, 0xfe, 0x48, 0x89, 0xc7, 0x48, 0x29, 0xf0, 0x48, 0x39, 0xd0, 0x72,
0x52, 0x48, 0x83, 0xfa, 0x50, 0x76, 0x1d, 0xeb, 0x4f, 0x90, 0x90, 0x90,
0x55, 0x48, 0x89, 0xe5, 0x49, 0x89, 0xfb, 0x48, 0x89, 0xf8, 0x48, 0x29,
0xf0, 0x48, 0x39, 0xd0, 0x72, 0x35, 0x48, 0x83, 0xfa, 0x50, 0x77, 0x34,
0x89, 0xd1, 0xc1, 0xe9, 0x02, 0x74, 0x10, 0x8b, 0x06, 0x48, 0x83, 0xc6,
0x04, 0x89, 0x07, 0x48, 0x83, 0xc7, 0x04, 0xff, 0xc9, 0x75, 0xf0, 0x83,
0xe2, 0x03, 0x74, 0x0e, 0x8a, 0x06, 0x48, 0xff, 0xc6, 0x88, 0x07, 0x48,
0xff, 0xc7, 0xff, 0xca, 0x75, 0xf2, 0x4c, 0x89, 0xd8, 0x5d, 0xc3, 0xe9,
0xbd, 0x04, 0x00, 0x00, 0x48, 0x81, 0xfa, 0x00, 0xd0, 0x07, 0x00, 0x0f,
0x83, 0x7f, 0x00, 0x00, 0x00, 0x89, 0xf9, 0xf7, 0xd9, 0x83, 0xe1, 0x0f,
0x74, 0x04, 0x29, 0xca, 0xf3, 0xa4, 0x48, 0x89, 0xd1, 0x89, 0xf0, 0x83,
0xe2, 0x3f, 0x83, 0xe0, 0x0f, 0x48, 0x83, 0xe1, 0xc0, 0x49, 0xb8, 0x80,
0x07, 0xe0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x49, 0x81, 0xc0, 0xb8, 0x00,
0x00, 0x00, 0x48, 0x01, 0xce, 0x48, 0x01, 0xcf, 0x41, 0x8b, 0x04, 0x80,
0x48, 0xf7, 0xd9, 0x4c, 0x01, 0xc0, 0xff, 0xe0, 0x66, 0x00, 0x00, 0x00,
0xb1, 0x00, 0x00, 0x00, 0xf1, 0x00, 0x00, 0x00, 0x31, 0x01, 0x00, 0x00,
0x71, 0x01, 0x00, 0x00, 0xb1, 0x01, 0x00, 0x00, 0xf1, 0x01, 0x00, 0x00,
0x31, 0x02, 0x00, 0x00, 0x71, 0x02, 0x00, 0x00, 0xb1, 0x02, 0x00, 0x00,
0xf1, 0x02, 0x00, 0x00, 0x31, 0x03, 0x00, 0x00, 0x71, 0x03, 0x00, 0x00,
0xb1, 0x03, 0x00, 0x00, 0xf1, 0x03, 0x00, 0x00, 0x31, 0x04, 0x00, 0x00,
0x41, 0x53, 0x48, 0xb8, 0x00, 0x12, 0xe0, 0xff, 0xff, 0x7f, 0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
};
branches/ErmaC/Enoch/i386/boot2/drivers.c
3333
3434
3535
36
3637
3738
3839
3940
4041
42
4143
4244
4345
......
102104
103105
104106
107
105108
106109
107110
......
215218
216219
217220
218
219
220221
221222
222223
......
691692
692693
693694
695
694696
695697
696698
......
767769
768770
769771
772
773
774
775
770776
771777
772778
#include <libkern/OSByteOrder.h>
#include <mach/machine.h>
#include "config.h"
#include "sl.h"
#include "boot.h"
#include "bootstruct.h"
#include "xml.h"
#include "ramdisk.h"
#include "kernel_patcher_internal.h"
#include "modules.h"
#if DEBUG
static long MatchPersonalities(void);
static long MatchLibraries(void);
#ifdef NOTDEF
static ModulePtr FindModule(char *name);
static void ThinFatFile(void **loadAddrP, unsigned long *lengthP);
strcpy(dirSpecExtra, "rd(0,0)/Extra/");
FileLoadDrivers(dirSpecExtra, 0);
}
// verbose("Attempting to loading drivers from \"Extra\" repository:\n");
// =====================================================================
// Secondly try to load drivers from Common folder if in use
if (gUseCommonAndOSdir)
DriverInfoPtrdriver;
longlength, driverAddr, driverLength;
void*executableAddr = 0;
void*embedded = 0;
module = gModuleHead;
module = module->nextModule;
}
if(embedded)
{
free(embedded);
}
return 0;
}
branches/ErmaC/Enoch/i386/boot2/sse3_patcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const uint8_t sse3_patcher[] = {
0x55, 0x48, 0x89, 0xe5,
0x48, 0x89, 0xf0, 0x48, 0x89, 0xfe, 0x48, 0x89, 0xc7, 0x48, 0x29, 0xf0,
0x48, 0x39, 0xd0, 0x72, 0x52, 0x48, 0x83, 0xfa, 0x50, 0x76, 0x1d, 0xeb,
0x4f, 0x0f, 0x1f, 0x00, 0x55, 0x48, 0x89, 0xe5, 0x49, 0x89, 0xfb, 0x48,
0x89, 0xf8, 0x48, 0x29, 0xf0, 0x48, 0x39, 0xd0, 0x72, 0x35, 0x48, 0x83,
0xfa, 0x50, 0x77, 0x34, 0x89, 0xd1, 0xc1, 0xe9, 0x02, 0x74, 0x10, 0x8b,
0x06, 0x48, 0x83, 0xc6, 0x04, 0x89, 0x07, 0x48, 0x83, 0xc7, 0x04, 0xff,
0xc9, 0x75, 0xf0, 0x83, 0xe2, 0x03, 0x74, 0x0e, 0x8a, 0x06, 0x48, 0xff,
0xc6, 0x88, 0x07, 0x48, 0xff, 0xc7, 0xff, 0xca, 0x75, 0xf2, 0x4c, 0x89,
0xd8, 0x5d, 0xc3, 0xe9, 0xad, 0x04, 0x00, 0x00, 0x48, 0x81, 0xfa, 0x00,
0xd0, 0x07, 0x00, 0x73, 0x77, 0x89, 0xf9, 0xf7, 0xd9, 0x83, 0xe1, 0x0f,
0x74, 0x04, 0x29, 0xca, 0xf3, 0xa4, 0x48, 0x89, 0xd1, 0x89, 0xf0, 0x83,
0xe2, 0x3f, 0x83, 0xe0, 0x0f, 0x48, 0x83, 0xe1, 0xc0, 0x4c, 0x8d, 0x05,
0x14, 0x00, 0x00, 0x00, 0x48, 0x01, 0xce, 0x48, 0x01, 0xcf, 0x41, 0x8b,
0x04, 0x80, 0x48, 0xf7, 0xd9, 0x4c, 0x01, 0xc0, 0xff, 0xe0, 0x66, 0x90,
0x66, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, 0xed, 0x00, 0x00, 0x00,
0x2d, 0x01, 0x00, 0x00, 0x6d, 0x01, 0x00, 0x00, 0xad, 0x01, 0x00, 0x00,
0xed, 0x01, 0x00, 0x00, 0x2d, 0x02, 0x00, 0x00, 0x6d, 0x02, 0x00, 0x00,
0xad, 0x02, 0x00, 0x00, 0xed, 0x02, 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7f, 0x44, 0x0f, 0xf0, 0x66,
0x0f, 0x7f, 0x4c, 0x0f, 0xe0, 0x66, 0x0f, 0x7f, 0x54, 0x0f, 0xd0, 0x66,
0x0f, 0x7f, 0x5c, 0x0f, 0xc0, 0x48, 0x83, 0xe9, 0x40, 0x75, 0xca, 0xe9,
0x29, 0xff, 0xff, 0xff
};
branches/ErmaC/Enoch/i386/boot2/Makefile
4545
4646
4747
48
48
4949
5050
5151
OBJS = boot2.o boot.o graphics.o \
drivers.o prompt.o options.o \
lzss.o lzvn.o mboot.o \
ramdisk.o \
ramdisk.o kernel_patcher_internal.o \
picopng.o resume.o \
bmdecompress.o graphic_utils.o gui.o \
modules.o \
branches/ErmaC/Enoch/i386/boot2/boot.c
141141
142142
143143
144
145
146
147
148
149
144150
151
152
153
154
155
156
157
158
159
160
161
162
163
145164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
146180
181
147182
148183
149184
......
821856
822857
823858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
824912
825913
826914
}
// =========================================================================
// Load the Kernel.plist override config file if any
static void setupKernelConfigFile(const char *filename)
{
chardirSpec[128];
const char*override_pathname = NULL;
intlen = 0, err = 0;
// Take in account user overriding
if (getValueForKey(kKERNELKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)
{
// Specify a path to a file, e.g. KERNELPlist=/Extra/Kernel2.plist
strcpy(dirSpec, override_pathname);
err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);
}
else
{
// Check selected volume's Extra.
sprintf(dirSpec, "/Extra/%s", filename);
err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);
}
if (!err)
{
getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, KERNELPlist);
getBoolForKey(kKernelPm, &KernelPm, KERNELPlist);
getBoolForKey(kKernelLapicError, &KernelLapicError, KERNELPlist);
getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, KERNELPlist);
getBoolForKey(kKernelHaswell, &KernelHaswell, KERNELPlist);
getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, KERNELPlist);
getBoolForKey(kKernelSSE3, &KernelSSE3, KERNELPlist);
}
else
{
verbose("No %s replacement found.\n", filename);
}
}
//==========================================================================
// ExecKernel - Load the kernel image (mach-o) and jump to its entry point.
// Notify modules that we are attempting to boot
execute_hook("PreBoot", NULL, NULL, NULL, NULL);
//--------------------------------------
getBoolForKey(kSkipKernelPatcher, &skipKernelPatcher, &bootInfo->chameleonConfig);
// kernel patcher
if (!skipKernelPatcher)
{
const char*key = NULL;
int len = 0;
setupKernelConfigFile("kernel.plist");
// looking at command line for kernel patcher setting and override where needed
if (getValueForKey(kKernelBooter_kexts, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelPm, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelPm, &KernelPm, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelLapicError, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelLapicError, &KernelLapicError, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelLapicVersion, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelHaswell, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelHaswell, &KernelHaswell, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelcpuFamily, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, &bootInfo->chameleonConfig);
}
key = NULL; len = 0;
if (getValueForKey(kKernelSSE3, &key, &len, &bootInfo->chameleonConfig) && len > 0)
{
getBoolForKey(kKernelSSE3, &KernelSSE3, &bootInfo->chameleonConfig);
}
}
if (gBootVolume->OSisInstaller)
{
isInstaller = true;
branches/ErmaC/Enoch/i386/boot2/boot.h
212212
213213
214214
215
216
215217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
216233
217234
235
236
237
238
239
240
218241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
219266
220267
221268
......
319366
320367
321368
322
369
323370
324371
325372
#define kDropAPIC"DropAPIC"/* acpi_patcher.c */
#define kCsrActiveConfig"CsrActiveConfig"/* boot.c */
#define kProductBuildVersion"ProductBuildVersion"/* boot.c */
#define kKERNELKey"KERNELPlist"/* kernel_patcher.c */
#define kKEXTKey"KEXTPlist"/* kext_patcher.c */
/*
* Kernel Patcher (internal)
*/
#define kSkipKernelPatcher "SkipKP"/* drivers.c */
#define kKernelPm "KernelPm"/* kernel_patcher.c */
#define kKernelLapicError "KernelLapicError"/* kernel_patcher.c */
#define kKernelLapicVersion "KernelLapicVersion"/* kernel_patcher.c */
#define kKernelHaswell "KernelHaswell"/* kernel_patcher.c */
#define kKernelcpuFamily "KernelcpuFamily"/* kernel_patcher.c */
#define kKernelSSE3 "KernelSSE3"/* kernel_patcher.c */
#define kKernelBooter_kexts "KernelBooter_kexts"/* kernel_patcher.c */
// Here we define our Kernel.plist
#define KERNELPlist &bootInfo->kernelConfig
uint32_t kernelOSVer; /* boot.c */
bool skipKernelPatcher;
bool KernelPm; // disable by default
bool KernelLapicError; // disable by default
bool KernelLapicVersion; // disable by default
bool KernelHaswell; // disable by default
bool KernelcpuFamily; // disable by default
bool KernelSSE3; // disable by default
bool KernelBooter_kexts; // disable by default
/*
* Kext Patcher (internal)
*/
#define kSkipKextsPatcher"SkipKextsPatcher"/* drivers.c */
#define kAICPMPatch"AICPMPatch"/* kernel_patcher.c */
#define kAppleRTCPatch"AppleRTCPatch"/* kernel_patcher.c */
#define kOrangeIconFixSata"OrangeIconFixSata"/* kernel_patcher.c */
#define kTrimEnablerSata"TrimEnablerSata"/* kernel_patcher.c */
#define kNVIDIAWebDrv"NVIDIAWebDrv"/* kernel_patcher.c */
#define kAppleHDABinPatch"AppleHDABinPatch"/* kernel_patcher.c */ /* autopatcher to be implemented */
// Here we define our kext.plist
#define KEXTPlist &bootInfo->kextConfig
bool skipKextsPatcher;
bool AICPMPatch; // disable by default
bool OrangeIconFixSata; // disable by default
bool TrimEnablerSata; // disable by default
bool NVIDIAWebDrv; // disable by default
bool AppleRTCPatch; // disable by default
/* Pike R. Alpha: added this key */
#define kBlackMode"BlackMode"
int gDarwinMinor;
int gDarwinRev;
bool useDarwinVersion;
bool FakeSMCLoaded;
/*!
Hookable function pointer called during the driver loading phase that
allows other code to cause additional drivers to be loaded.
branches/ErmaC/Enoch/i386/boot2/kernel_patcher_internal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
/*
* Original idea of patching kernel by Evan Lojewsky, 2009
*
* Copyright (c) 2011-2012 Frank Peng. All rights reserved.
*
* Correction and improvements by Clover team
*
* Ported and adapted to Chameleon by Micky1979 and ErmaC
*
* kexts patcher by Micky1979, 2017
*/
// TODO:
// replace for loops with FindAndReplace
#include "config.h"
#include "boot.h"
#include "libsaio.h"
#include "bootstruct.h"
#include "kernel_patcher_internal.h"
#include "sse3_patcher.h"
#include "sse3_5_patcher.h"
#include "platform.h"
#include "xml.h"
#include "sl.h"
#if DEBUG_KERNEL
#define DBG(x...)verbose(x)
#else
#define DBG(x...)
#endif
#define NVDAVALUE "1" // unused (old method to activate NVidia Web Drivers)
// ===================================
/*
* Entrypoint from load.c
*/
void patch_kernel_internal(void *kernelData, u_int32_t uncompressed_size)
{
// ================================
if (!useDarwinVersion)
{
kernelOSVer = MacOSVerCurrent;
}
// ================================
verbose("[ KERNEL PATCHER START ]\n");
/* to debug kernelOSVer and see if match the OS version: */
DBG("\n\tMacOSVerCurrent = %08x version.\n\n", MacOSVerCurrent);
DBG("\n\tkernelOSVer = %08x version.\n\n", kernelOSVer);
verbose("\n\tWill patch for %d.%d.%d kernel version compatible.\n\n", gDarwinMajor, gDarwinMinor, gDarwinRev);
verbose("\tKernelBooter_kexts state: %s!\n", KernelBooter_kexts ? " enabled" : "disabled");
verbose("\tKernelPm state: %s!\n", KernelPm ? " enabled" : "disabled");
verbose("\tKernelLapicError state: %s!\n", KernelLapicError ? " enabled" : "disabled");
verbose("\tKernelLapicVersion state: %s!\n", KernelLapicVersion ? " enabled" : "disabled");
verbose("\tKernelHaswell state: %s!\n", KernelHaswell ? " enabled" : "disabled");
verbose("\tKernelcpuFamily state: %s!\n", KernelcpuFamily ? " enabled" : "disabled");
verbose("\tKernelSSE3 state: %s!\n", KernelSSE3 ? " enabled" : "disabled");
u_int32_t sizeToScan = uncompressed_size; // for further expansion
// Select machine arch
if (archCpuType == CPU_TYPE_I386)
{
patch_kernel_32((void *)kernelData, sizeToScan);
}
else
{
patch_kernel_64((void *)kernelData, sizeToScan);
}
/* VMware issue
if (patch_string_XNU_init(kernelData))
{
DBG("\tKernel string replaced.\n");
}
*/
// do user's defined patches
if (bootInfo->kernelConfig.dictionary) {
pach_binaryUsingDictionary(kernelData,
(UInt32)uncompressed_size,
0,
"KernelPatches",
bootInfo->kernelConfig.dictionary);
}
verbose("Kernel patcher: end!\n\n");
}
// ===================================
// patches for a 64-bit kernel.
void patch_kernel_64(void *kernelData, u_int32_t uncompressed_size) // KernelPatcher_64
{
DBG("[ 64-bit ]\n");
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation = 0, patchLocation1 = 0;
UInt32 i;
UInt32 switchaddr = 0;
UInt32 mask_family = 0, mask_model = 0;
UInt32 cpuid_family_addr = 0, cpuid_model_addr = 0;
// Prelinked Extensions Patcher
if (KernelBooter_kexts)
{
patch_BooterExtensions_64(kernelData);
}
// Lapic Error
if (KernelLapicError && patch_lapic_init_64(kernelData))
{
verbose("\tLapic Error call removed.\n");
}
// Lapic Version
if (KernelLapicVersion && patch_lapic_version_init_64(kernelData))
{
verbose("\tLapic Version call removed.\n");
}
// Power Managment
if (KernelPm && patch_pm_init(kernelData))
{
verbose("\tPower Managment patch applied.\n");
}
// Haswell Kernel Patcher
if ( KernelHaswell && (kernelOSVer >= MacOSVer2Int("10.8")) ) // Haswell "E" and "ULT" support
{
switch (Platform.CPU.Family)
{
case 0x06:
{
switch (Platform.CPU.Model)
{
case CPUID_MODEL_HASWELL_SVR: // Haswell-E Kernel Patcher
if (patch_haswell_E_init(kernelData))
{
verbose("\tHaswell-E Kernel patch applied.\n");
}
break;
case CPUID_MODEL_HASWELL_ULT: // Haswell-ULT Kernel Patcher
if (patch_haswell_ULT_init(kernelData))
{
verbose("\tHaswell-ULT Kernel patch applied.\n");
}
break;
default:
verbose("\tNo Haswell-ULT/-E Kernel patch applied for this CPU.\n");
break;
}
}
}
}
if (KernelcpuFamily)
{
verbose("\t- Looking for _cpuid_set_info _panic ...\n");
// Determine location of _cpuid_set_info _panic call for reference
// basically looking for info_p->cpuid_model = bitfield32(reg[eax], 7, 4);
for (i=0; i<0x1000000; i++)
{
if (bytes[i + 0] == 0xC7
&& bytes[i + 1] == 0x05
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x07
&& bytes[i + 7] == 0x00
&& bytes[i + 8] == 0x00
&& bytes[i + 9] == 0x00
&& bytes[i - 5] == 0xE8)
{
// matching 0xE8 for _panic call start
patchLocation = i-5;
break;
}
}
if (!patchLocation)
{
verbose("\t_cpuid_set_info Unsupported CPU _panic not found \n");
return;
}
// make sure only kernels for OSX 10.6.0 to 10.7.3 are being patched by this approach
if (kernelOSVer >= MacOSVer2Int("10.6") && kernelOSVer <= MacOSVer2Int("10.7.3"))
{
verbose("\t- will patch kernel for OSX 10.6.0 to 10.7.3\n");
// remove tsc_init: unknown CPU family panic for kernels prior to 10.6.2 which still had Atom support
if (kernelOSVer < MacOSVer2Int("10.6.2"))
{
for (i=0; i<0x1000000; i++)
{
// find _tsc_init panic address by byte sequence 488d3df4632a00
if (bytes[i] == 0x48
&& bytes[i + 1] == 0x8D
&& bytes[i + 2] == 0x3D
&& bytes[i + 3] == 0xF4
&& bytes[i + 4] == 0x63
&& bytes[i + 5] == 0x2A
&& bytes[i + 6] == 0x00)
{
patchLocation1 = i+9;
verbose("\tFound _tsc_init _panic address at 0x%08x\n", (unsigned int)patchLocation1);
break;
}
}
// NOP _panic call
if (patchLocation1)
{
bytes[patchLocation1 + 0] = 0x90;
bytes[patchLocation1 + 1] = 0x90;
bytes[patchLocation1 + 2] = 0x90;
bytes[patchLocation1 + 3] = 0x90;
bytes[patchLocation1 + 4] = 0x90;
}
}
else
{
// assume patching logic for OSX 10.6.2 to 10.7.3
/*
* Here is our case from CPUID switch statement, it sets CPUFAMILY_UNKNOWN
* C7051C2C5F0000000000 mov dword [ds:0xffffff80008a22c0], 0x0 (example from 10.7)
*/
switchaddr = patchLocation - 19;
verbose("\tswitch statement patch location is 0x%08lx\n", (switchaddr+6));
if (bytes[switchaddr + 0] == 0xC7
&& bytes[switchaddr + 1] == 0x05
&& bytes[switchaddr + 5] == 0x00
&& bytes[switchaddr + 6] == 0x00
&& bytes[switchaddr + 7] == 0x00
&& bytes[switchaddr + 8] == 0x00)
{
// Determine cpuid_family address from above mov operation
cpuid_family_addr =
bytes[switchaddr + 2] << 0 |
bytes[switchaddr + 3] << 8 |
bytes[switchaddr + 4] << 16 |
bytes[switchaddr + 5] << 24;
cpuid_family_addr = cpuid_family_addr + (switchaddr + 10);
if (cpuid_family_addr)
{
// Determine cpuid_model address
// for 10.6.2 kernels it's offset by 299 bytes from cpuid_family address
if (kernelOSVer == MacOSVer2Int("10.6.2"))
{
cpuid_model_addr = cpuid_family_addr - 0X12B;
}
// for 10.6.3 to 10.6.7 it's offset by 303 bytes
else if (kernelOSVer <= MacOSVer2Int("10.6.7"))
{
cpuid_model_addr = cpuid_family_addr - 0X12F;
}
// for 10.6.8 to 10.7.3 kernels - by 339 bytes
else
{
cpuid_model_addr = cpuid_family_addr - 0X153;
}
verbose("\tcpuid_family address: 0x%08X\n", (unsigned int)cpuid_family_addr);
verbose("\tcpuid_model address: 0x%08X\n", (unsigned int)cpuid_model_addr);
switchaddr += 6; // offset 6 bytes in mov operation to write a dword instead of zero
// calculate mask for patching, cpuid_family mask not needed as we offset on a valid mask
mask_model = cpuid_model_addr - (switchaddr+14);
//verbose("\tmodel mask 0x%08x\n", (unsigned int)mask_model);
//verbose("\toverriding cpuid_family and cpuid_model as CPUID_INTEL_PENRYN\n");
bytes[switchaddr+0] = (CPUFAMILY_INTEL_PENRYN & 0x000000FF) >> 0;
bytes[switchaddr+1] = (CPUFAMILY_INTEL_PENRYN & 0x0000FF00) >> 8;
bytes[switchaddr+2] = (CPUFAMILY_INTEL_PENRYN & 0x00FF0000) >> 16;
bytes[switchaddr+3] = (CPUFAMILY_INTEL_PENRYN & 0xFF000000) >> 24;
// mov dword [ds:0xffffff80008a216d], 0x2000117
bytes[switchaddr+4] = 0xC7;
bytes[switchaddr+5] = 0x05;
bytes[switchaddr+6] = (UInt8)((mask_model & 0x000000FF) >> 0);
bytes[switchaddr+7] = (UInt8)((mask_model & 0x0000FF00) >> 8);
bytes[switchaddr+8] = (UInt8)((mask_model & 0x00FF0000) >> 16);
bytes[switchaddr+9] = (UInt8)((mask_model & 0xFF000000) >> 24);
bytes[switchaddr+10] = 0x17; // cpuid_model (Penryn)
bytes[switchaddr+11] = 0x01; // cpuid_extmodel
bytes[switchaddr+12] = 0x00; // cpuid_extfamily
bytes[switchaddr+13] = 0x02; // cpuid_stepping
// fill remainder with 4 NOPs
for (i = 14; i < 18; i++)
{
bytes[switchaddr+i] = 0x90;
}
}
}
else
{
verbose("\tUnable to determine cpuid_family address, patching aborted\n");
return;
}
}
// patch sse3
if (KernelSSE3 && (SNOW_LEOPARD))
{
patch_SSE3_6((void *)bytes);
}
if (KernelSSE3 && (LION))
{
patch_SSE3_7((void *)bytes);
}
}
// all 10.7.4+ kernels share common CPUID switch statement logic,
// it needs to be exploited in diff manner due to the lack of space
else if (kernelOSVer >= MacOSVer2Int("10.7.4"))
{
verbose("\t- will patch kernel for OSX %s (from 10.7.4 and newer)\n", gBootVolume->OSFullVer);
/*
* Here is our switchaddress location ... it should be case 20 from CPUID switch statement
* 833D78945F0000 cmp dword [ds:0xffffff80008a21d0], 0x0;
* 7417 je 0xffffff80002a8d71
*/
switchaddr = patchLocation-45;
verbose("\tswitch statement patch location is 0x%08X\n", (unsigned int)switchaddr);
if(bytes[switchaddr + 0] == 0x83
&& bytes[switchaddr + 1] == 0x3D
&& bytes[switchaddr + 5] == 0x00
&& bytes[switchaddr + 6] == 0x00
&& bytes[switchaddr + 7] == 0x74)
{
// Determine cpuid_family address
// 891D4F945F00 mov dword [ds:0xffffff80008a21a0], ebx
cpuid_family_addr =
bytes[switchaddr - 4] << 0 |
bytes[switchaddr - 3] << 8 |
bytes[switchaddr - 2] << 16 |
bytes[switchaddr - 1] << 24;
cpuid_family_addr = cpuid_family_addr + switchaddr;
if (cpuid_family_addr)
{
// Determine cpuid_model address
// for 10.6.8+ kernels it's 339 bytes apart from cpuid_family address
cpuid_model_addr = cpuid_family_addr - 0X153;
verbose("\tcpuid_family address: 0x%08X\n", (unsigned int)cpuid_family_addr);
verbose("\tcpuid_model address: 0x%08X\n", (unsigned int)cpuid_model_addr);
// Calculate masks for patching
mask_family = cpuid_family_addr - (switchaddr +15);
mask_model = cpuid_model_addr - (switchaddr +25);
verbose("\tfamily mask: 0x%08X \n\tmodel mask: 0x%08X\n", (unsigned int)mask_family, (unsigned int)mask_model);
// retain original
// test ebx, ebx
bytes[switchaddr+0] = bytes[patchLocation-13];
bytes[switchaddr+1] = bytes[patchLocation-12];
// retain original, but move jump offset by 20 bytes forward
// jne for above test
bytes[switchaddr+2] = bytes[patchLocation-11];
bytes[switchaddr+3] = bytes[patchLocation-10]+0x20;
// mov ebx, 0x78ea4fbc
bytes[switchaddr+4] = 0xBB;
bytes[switchaddr+5] = (CPUFAMILY_INTEL_PENRYN & 0x000000FF) >> 0;
bytes[switchaddr+6] = (CPUFAMILY_INTEL_PENRYN & 0x0000FF00) >> 8;
bytes[switchaddr+7] = (CPUFAMILY_INTEL_PENRYN & 0x00FF0000) >> 16;
bytes[switchaddr+8] = (CPUFAMILY_INTEL_PENRYN & 0xFF000000) >> 24;
// mov dword, ebx
bytes[switchaddr+9] = 0x89;
bytes[switchaddr+10] = 0x1D;
// cpuid_cpufamily address 0xffffff80008a21a0
bytes[switchaddr+11] = (UInt8)((mask_family & 0x000000FF) >> 0);
bytes[switchaddr+12] = (UInt8)((mask_family & 0x0000FF00) >> 8);
bytes[switchaddr+13] = (UInt8)((mask_family & 0x00FF0000) >> 16);
bytes[switchaddr+14] = (UInt8)((mask_family & 0xFF000000) >> 24);
// mov dword
bytes[switchaddr+15] = 0xC7;
bytes[switchaddr+16] = 0x05;
// cpuid_model address 0xffffff80008b204d
bytes[switchaddr+17] = (UInt8)((mask_model & 0x000000FF) >> 0);
bytes[switchaddr+18] = (UInt8)((mask_model & 0x0000FF00) >> 8);
bytes[switchaddr+19] = (UInt8)((mask_model & 0x00FF0000) >> 16);
bytes[switchaddr+20] = (UInt8)((mask_model & 0xFF000000) >> 24);
bytes[switchaddr+21] = 0x17; // cpuid_model
bytes[switchaddr+22] = 0x01; // cpuid_extmodel
bytes[switchaddr+23] = 0x00; // cpuid_extfamily
bytes[switchaddr+24] = 0x02; // cpuid_stepping
// fill remainder with 25 NOPs
for (i=25; i<25+25; i++)
{
bytes[switchaddr+i] = 0x90;
}
}
}
else
{
verbose("\tUnable to determine cpuid_family address, patching aborted\n");
return;
}
}
verbose("\n");
}
}
// ===================================
// patches for a 32-bit kernel.
void patch_kernel_32(void *kernelData, u_int32_t uncompressed_size) // KernelPatcher_32
{
DBG("[ 32-bit ]\n");
UInt8 *bytes = ( UInt8 *)kernelData;
UInt32 patchLocation = 0, patchLocation1 = 0;
UInt32 i;
UInt32 jumpaddr;
// Prelinked Extensions Patcher
if (KernelBooter_kexts)
{
patch_BooterExtensions_32(kernelData);
}
// Lapic Error
if (KernelLapicError && patch_lapic_init_32(kernelData))
{
verbose("\tLapic Error call removed.\n");
}
// Lapic Version
if (KernelLapicVersion && patch_lapic_version_init_32(kernelData))
{
verbose("\tLapic Version call removed.\n");
}
if (KernelcpuFamily)
{
verbose("\t- Looking for _cpuid_set_info _panic ...\n");
// _cpuid_set_info _panic address
for (i = 0; i < 0x1000000; i++)
{
if (bytes[i] == 0xC7
&& bytes[i + 1] == 0x05
&& bytes[i + 6] == 0x07
&& bytes[i + 7] == 0x00
&& bytes[i + 8] == 0x00
&& bytes[i + 9] == 0x00
&& bytes[i + 10] == 0xC7
&& bytes[i + 11] == 0x05
&& bytes[i - 5] == 0xE8)
{
patchLocation = i-5;
verbose("\tFound _cpuid_set_info _panic address at 0x%08X\n", (unsigned int)patchLocation);
break;
}
}
if (!patchLocation)
{
verbose("\tCan't find _cpuid_set_info _panic address, patch kernel abort.\n");
return;
}
// this for 10.6.0 and 10.6.1 kernel and remove tsc.c unknow cpufamily panic
// c70424540e5900
// find _tsc_init panic address
for (i = 0; i < 0x1000000; i++)
{
// _cpuid_set_info _panic address
if (bytes[i] == 0xC7
&& bytes[i + 1] == 0x04
&& bytes[i + 2] == 0x24
&& bytes[i + 3] == 0x54
&& bytes[i + 4] == 0x0E
&& bytes[i + 5] == 0x59
&& bytes[i + 6] == 0x00)
{
patchLocation1 = i+7;
verbose("\tFound _tsc_init _panic address at 0x%08X\n", (unsigned int)patchLocation1);
break;
}
}
// found _tsc_init panic addres and patch it
if (patchLocation1)
{
bytes[patchLocation1 + 0] = 0x90;
bytes[patchLocation1 + 1] = 0x90;
bytes[patchLocation1 + 2] = 0x90;
bytes[patchLocation1 + 3] = 0x90;
bytes[patchLocation1 + 4] = 0x90;
}
// end tsc.c panic
//first move panic code total 5 bytes, if patch cpuid fail still can boot with kernel
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
jumpaddr = patchLocation;
for (i = 0 ;i < 500; i++)
{
if (bytes[jumpaddr-i-3] == 0x85
&& bytes[jumpaddr-i-2] == 0xC0
&& bytes[jumpaddr-i-1] == 0x75 )
{
jumpaddr -= i;
bytes[jumpaddr-1] = 0x77;
if(bytes[patchLocation - 17] == 0xC7)
{
bytes[jumpaddr] -=10;
}
break;
}
}
if (jumpaddr == patchLocation)
{
verbose("\tCan't Found jumpaddr address.\n");
return; //can't find jump location
}
// patch info_p->cpufamily to CPUFAMILY_INTEL_MEROM
if (bytes[patchLocation - 17] == 0xC7)
{
bytes[patchLocation - 11] = (CPUFAMILY_INTEL_MEROM & 0x000000FF) >> 0;
bytes[patchLocation - 10] = (CPUFAMILY_INTEL_MEROM & 0x0000FF00) >> 8;
bytes[patchLocation - 9] = (CPUFAMILY_INTEL_MEROM & 0x00FF0000) >> 16;
bytes[patchLocation - 8] = (CPUFAMILY_INTEL_MEROM & 0xFF000000) >> 24;
}
//patch info->cpuid_cpufamily
bytes[patchLocation - 7] = 0xC7;
bytes[patchLocation - 6] = 0x05;
bytes[patchLocation - 5] = bytes[jumpaddr + 3];
bytes[patchLocation - 4] = bytes[jumpaddr + 4];
bytes[patchLocation - 3] = bytes[jumpaddr + 5];
bytes[patchLocation - 2] = bytes[jumpaddr + 6];
bytes[patchLocation - 1] = CPUIDFAMILY_DEFAULT; //cpuid_family need alway set 0x06
bytes[patchLocation + 0] = CPUID_MODEL_MEROM; //cpuid_model set CPUID_MODEL_MEROM
bytes[patchLocation + 1] = 0x01; //cpuid_extmodel alway set 0x01
bytes[patchLocation + 2] = 0x00; //cpuid_extfamily alway set 0x00
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
if (KernelSSE3 && ( LION ))
{
patch_SSE3_6((void *)bytes);
}
if (KernelSSE3 && ( LEOPARD ))
{
patch_SSE3_5((void *)bytes);
}
}
}
// ===================================
// Power Managment
bool patch_pm_init(void *kernelData) // KernelPatchPm
{
UInt8 *Ptr = (UInt8 *)kernelData;
UInt8 *End = Ptr + 0x1000000;
if (Ptr == NULL)
{
return false;
}
// Credits to RehabMan for the kernel patch information
// XCPM (Xnu CPU Power Management)
verbose("\t- Patching kernel power management...\n");
while (Ptr < End)
{
if (KERNEL_PATCH_SIGNATURE == (*((UInt64 *)Ptr)))
{
// Bytes 19,20 of KernelPm patch for kernel 13.x change between kernel versions, so we skip them in search&replace
if ((memcmp(Ptr + sizeof(UInt64), KernelPatchPmSrc + sizeof(UInt64), 18 * sizeof(UInt8) - sizeof(UInt64)) == 0) &&
(memcmp(Ptr + 20 * sizeof(UInt8), KernelPatchPmSrc + 20 * sizeof(UInt8), sizeof(KernelPatchPmSrc) - 20 * sizeof(UInt8)) == 0))
{
// Don't copy more than the source here!
memcpy(Ptr, KernelPatchPmRepl, 18 * sizeof(UInt8)); // Copy block of memory
memcpy(Ptr + 20 * sizeof(UInt8), KernelPatchPmRepl + 20 * sizeof(UInt8), sizeof(KernelPatchPmSrc) - 20 * sizeof(UInt8)); // Copy block of memory
verbose("\tKernel power management patch region 1 found and patched\n");
return true;
}
else if (memcmp(Ptr + sizeof(UInt64), KernelPatchPmSrc2 + sizeof(UInt64), sizeof(KernelPatchPmSrc2) - sizeof(UInt64)) == 0)
{
// Don't copy more than the source here!
memcpy(Ptr, KernelPatchPmRepl2, sizeof(KernelPatchPmSrc2)); // Copy block of memory
verbose("\tKernel power management patch region 2 found and patched\n");
return true;
}
}
// RehabMan: for 10.10 (data portion)
else if (0x00000002000000E2ULL == (*((UInt64 *)Ptr)))
{
(*((UInt64 *)Ptr)) = 0x0000000000000000ULL;
verbose("\tKernel power management patch 10.1x(data1) found and patched\n");
}
else if (0x0000004C000000E2ULL == (*((UInt64 *)Ptr)))
{
(*((UInt64 *)Ptr)) = 0x0000000000000000ULL;
verbose("\tKernel power management patch 10.1x(data2) found and patched\n");
}
else if (0x00000190000000E2ULL == (*((UInt64 *)Ptr)))
{
(*((UInt64 *)Ptr)) = 0x0000000000000000ULL;
verbose("\tKernel power management patch 10.10(data3) found and patched\n");
return true;
}
// rehabman: change for 10.11.1 beta 15B38b
else if (0x00001390000000E2ULL == (*((UInt64 *)Ptr)))
{
(*((UInt64 *)Ptr)) = 0x0000000000000000ULL;
verbose("\tKernel power management patch 10.11(data3) found and patched\n");
return true;
}
// sherlocks: change for 10.12 DP1
else if (0x00003390000000E2ULL == (*((UInt64 *)Ptr)))
{
(*((UInt64 *)Ptr)) = 0x0000000000000000ULL;
verbose("\tKernel power management patch 10.12 DP1 found and patched\n");
return TRUE;
}
Ptr += 16;
}
verbose("\tKernel power management patch region not found!\n");
return false;
}
// ===================================
// Bronya: Lapic Panic Version 64
bool patch_lapic_version_init_64(void *kernelData) // KernelLapicVersionPatch_64
{
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation = 0;
UInt32 i;
verbose("\t- Looking for Lapic Version panic call Start\n");
for (i = 0; i < 0x1000000; i++)
{
// Bronya: Snow Leopard 10.6 Lapic Version
if (bytes[i + 0] == 0x48
&& bytes[i + 1] == 0x0f
&& bytes[i + 2] == 0x44
&& bytes[i + 3] == 0xc2
&& bytes[i + 57] == 0x31
&& bytes[i + 58] == 0xc0)
{
patchLocation = i + 59;
verbose("\tFound Snow Leopard Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// Bronya: Lion 10.7 Lapic Version
else if (bytes[i + 0] == 0x48
&& bytes[i + 1] == 0x0f
&& bytes[i + 2] == 0x44
&& bytes[i + 3] == 0xc8
&& bytes[i + 61] == 0x30
&& bytes[i + 62] == 0xc0
&& bytes[i + 63] == 0xe8)
{
patchLocation = i + 63;
verbose("\tFound Lion, Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// Bronya: Mountain Lion 10.8 Lapic Version
else if (bytes[i + 0] == 0x45
&& bytes[i + 1] == 0x85
&& bytes[i + 2] == 0xf6
&& bytes[i + 3] == 0x48
&& bytes[i + 4] == 0x0f
&& bytes[i + 5] == 0x45
&& bytes[i + 6] == 0xc1
&& bytes[i + 68] == 0xe8
&& bytes[i + 69] == 0x3d
&& bytes[i + 70] == 0x15
&& bytes[i + 71] == 0xf6
&& bytes[i + 72] == 0xff)
{
patchLocation = i + 68;
verbose("\tFound Mountain Lion, Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// Bronya: Mavericks 10.9 Lapic Version
else if (bytes[i + 0] == 0xff
&& bytes[i + 1] == 0x50
&& bytes[i + 2] == 0x08
&& bytes[i + 3] == 0x89
&& bytes[i + 4] == 0xc3
&& bytes[i + 90] == 0xe8
&& bytes[i + 91] == 0x02
&& bytes[i + 92] == 0x17
&& bytes[i + 93] == 0xf4
&& bytes[i + 94] == 0xff)
{
patchLocation = i + 90;
verbose("\tFound Mavericks Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// Bronya: Yosemite 10.10 lapic version
else if (bytes[i + 0] == 0xff
&& bytes[i + 1] == 0x50
&& bytes[i + 2] == 0x08
&& bytes[i + 38] == 0x31
&& bytes[i + 39] == 0xdb
&& bytes[i + 40] == 0x31
&& bytes[i + 41] == 0xc0)
{
patchLocation = i + 42;
verbose("\tFound Yosemite Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// Bronya: El Capitan 10.11 Lapic Version
else if (bytes[i + 0] == 0xff
&& bytes[i + 1] == 0x50
&& bytes[i + 2] == 0x08
&& bytes[i + 38] == 0x31
&& bytes[i + 39] == 0xc0)
{
patchLocation = i + 40;
verbose("\tFound El Capitan Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
}
if (!patchLocation)
{
verbose("\tCan't find Lapic Version panic, kernel patch aborted.\n");
return false;
}
// Already patched? May be running a non-vanilla kernel already?
if (bytes[patchLocation + 0] == 0x90
&& bytes[patchLocation + 1] == 0x90
&& bytes[patchLocation + 2] == 0x90
&& bytes[patchLocation + 3] == 0x90
&& bytes[patchLocation + 4] == 0x90)
{
verbose("\tLapic Version panic already patched, kernel file manually patched?\n");
return false;
}
else
{
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
}
return true;
}
// ===================================
// Lapic Error Panic 64
bool patch_lapic_init_64(void *kernelData) // KernelLapicPatch_64
{
// Credits to donovan6000 and sherlocks for providing the lapic kernel patch source used to build this function
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation = 0;
UInt32 i;
verbose("\t- Looking for Lapic panic call Start\n");
for (i = 0; i < 0x1000000; i++)
{
if (KernelLapicError
&& (bytes[i + 0] == 0x65
&& bytes[i + 1] == 0x8B
&& bytes[i + 2] == 0x04
&& bytes[i + 3] == 0x25
&& bytes[i + 4] == 0x3C
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x00
&& bytes[i + 7] == 0x00
&& bytes[i + 45] == 0x65
&& bytes[i + 46] == 0x8B
&& bytes[i + 47] == 0x04
&& bytes[i + 48] == 0x25
&& bytes[i + 49] == 0x3C
&& bytes[i + 50] == 0x00
&& bytes[i + 51] == 0x00
&& bytes[i + 52] == 0x00))
{
patchLocation = i + 40;
verbose("\tFound Snow Leopard Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
else if (KernelLapicError
&& (bytes[i + 0] == 0x65
&& bytes[i + 1] == 0x8B
&& bytes[i + 2] == 0x04
&& bytes[i + 3] == 0x25
&& bytes[i + 4] == 0x14
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x00
&& bytes[i + 7] == 0x00
&& bytes[i + 35] == 0x65
&& bytes[i + 36] == 0x8B
&& bytes[i + 37] == 0x04
&& bytes[i + 38] == 0x25
&& bytes[i + 39] == 0x14
&& bytes[i + 40] == 0x00
&& bytes[i + 41] == 0x00
&& bytes[i + 42] == 0x00))
{
patchLocation = i + 30;
verbose("\tFound %sLion Lapic panic at 0x%08X\n", checkOSVersion("10.7") ? "" : "Mountain ", (unsigned int)patchLocation);
break;
}
else if (KernelLapicError
&& (bytes[i + 0] == 0x65
&& bytes[i + 1] == 0x8B
&& bytes[i + 2] == 0x04
&& bytes[i + 3] == 0x25
&& bytes[i + 4] == 0x1C
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x00
&& bytes[i + 7] == 0x00
&& bytes[i + 36] == 0x65
&& bytes[i + 37] == 0x8B
&& bytes[i + 38] == 0x04
&& bytes[i + 39] == 0x25
&& bytes[i + 40] == 0x1C
&& bytes[i + 41] == 0x00
&& bytes[i + 42] == 0x00
&& bytes[i + 43] == 0x00))
{
patchLocation = i + 31;
verbose("\tFound Mavericks Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// RehabMan: 10.10.DP1 lapic
else if (KernelLapicError
&& (bytes[i + 0] == 0x65
&& bytes[i + 1] == 0x8B
&& bytes[i + 2] == 0x04
&& bytes[i + 3] == 0x25
&& bytes[i + 4] == 0x1C
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x00
&& bytes[i + 7] == 0x00
&& bytes[i + 33] == 0x65
&& bytes[i + 34] == 0x8B
&& bytes[i + 35] == 0x04
&& bytes[i + 36] == 0x25
&& bytes[i + 37] == 0x1C
&& bytes[i + 38] == 0x00
&& bytes[i + 39] == 0x00
&& bytes[i + 40] == 0x00))
{
patchLocation = i + 28;
verbose("\tFound Yosemite Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// sherlocks: 10.11.DB1
else if (KernelLapicError
&& (bytes[i + 0] == 0x65
&& bytes[i + 1] == 0x8B
&& bytes[i + 2] == 0x0C
&& bytes[i + 3] == 0x25
&& bytes[i + 4] == 0x1C
&& bytes[i + 5] == 0x00
&& bytes[i + 6] == 0x00
&& bytes[i + 7] == 0x00
&& bytes[i + 1411] == 0x65
&& bytes[i + 1412] == 0x8B
&& bytes[i + 1413] == 0x0C
&& bytes[i + 1414] == 0x25
&& bytes[i + 1415] == 0x1C
&& bytes[i + 1416] == 0x00
&& bytes[i + 1417] == 0x00
&& bytes[i + 1418] == 0x00))
{
patchLocation = i + 1400;
verbose("\tFound El Capitan Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
// sherlocks: 10.12.DP1
else if (KernelLapicError
&& (bytes[i+0] == 0x65
&& bytes[i+1] == 0x8B
&& bytes[i+2] == 0x0C
&& bytes[i+3] == 0x25
&& bytes[i+4] == 0x1C
&& bytes[i+5] == 0x00
&& bytes[i+6] == 0x00
&& bytes[i+7] == 0x00
&& bytes[i+1409] == 0x65
&& bytes[i+1410] == 0x8B
&& bytes[i+1411] == 0x0C
&& bytes[i+1412] == 0x25
&& bytes[i+1413] == 0x1C
&& bytes[i+1414] == 0x00
&& bytes[i+1415] == 0x00
&& bytes[i+1416] == 0x00))
{
patchLocation = i+1398;
DBG("\tFound Sierra Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
}
if (!patchLocation)
{
verbose("\tCan't find Lapic panic, kernel patch aborted.\n");
return false;
}
// Already patched? May be running a non-vanilla kernel already?
if (bytes[patchLocation + 0] == 0x90
&& bytes[patchLocation + 1] == 0x90
&& bytes[patchLocation + 2] == 0x90
&& bytes[patchLocation + 3] == 0x90
&& bytes[patchLocation + 4] == 0x90)
{
verbose("\tLapic panic already patched, kernel file manually patched?\n");
return false;
}
else
{
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
}
return true;
}
// ===================================
// Bronya: Lapic Panic Version 32 bit
bool patch_lapic_version_init_32(void *kernelData)
{
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation = 0;
UInt32 i;
verbose("\t- Looking for Lapic Version panic call Start\n");
for (i = 0; i < 0x1000000; i++)
{
// Bronya: Snow Leopard 10.6 Lapic Version
if (bytes[i + 0] == 0x0f
&& bytes[i + 1] == 0x44
&& bytes[i + 2] == 0xc2
&& bytes[i + 49] == 0x89
&& bytes[i + 50] == 0x44
&& bytes[i + 51] == 0x24
&& bytes[i + 52] == 0x04)
{
patchLocation = i+60;
verbose("\tFound Snow Leopard Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
else
{
// Bronya: Lion 10.7 Lapic Version
if (bytes[i + 0] == 0x0f
&& bytes[i + 1] == 0x44
&& bytes[i + 2] == 0xc8
&& bytes[i + 52] == 0x89
&& bytes[i + 53] == 0x44
&& bytes[i + 54] == 0x24
&& bytes[i + 55] == 0x04)
{
patchLocation = i+63;
verbose("\tFound Lion, Lion Lapic Version panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
}
}
if (!patchLocation)
{
verbose("\tCan't find Lapic Version panic, kernel patch aborted.\n");
return false;
}
// Already patched? May be running a non-vanilla kernel already?
if (bytes[patchLocation + 0] == 0x90
&& bytes[patchLocation + 1] == 0x90
&& bytes[patchLocation + 2] == 0x90
&& bytes[patchLocation + 3] == 0x90
&& bytes[patchLocation + 4] == 0x90)
{
verbose("\tLapic Version panic already patched, kernel file manually patched?\n");
return false;
}
else
{
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
}
return true;
}
// ===================================
// Lapic Error Panic 32
bool patch_lapic_init_32(void *kernelData) // KernelLapicPatch_32
{
// Credits to donovan6000 and sherlocks for providing the lapic kernel patch source used to build this function
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation=0;
UInt32 i;
verbose("\t- Looking for Lapic panic call Start\n");
for (i = 0; i < 0x1000000; i++)
{
if (bytes[i+0] == 0x65
&& bytes[i+1] == 0xA1
&& bytes[i+2] == 0x0C
&& bytes[i+3] == 0x00
&& bytes[i+4] == 0x00
&& bytes[i+5] == 0x00
&& bytes[i+30] == 0x65
&& bytes[i+31] == 0xA1
&& bytes[i+32] == 0x0C
&& bytes[i+33] == 0x00
&& bytes[i+34] == 0x00
&& bytes[i+35] == 0x00)
{
patchLocation = i + 25;
verbose("\tFound Lapic panic at 0x%08X\n", (unsigned int)patchLocation);
break;
}
}
if (!patchLocation)
{
verbose("\tCan't find Lapic panic, kernel patch aborted.\n");
return false;
}
// Already patched? May be running a non-vanilla kernel already?
if (bytes[patchLocation + 0] == 0x90
&& bytes[patchLocation + 1] == 0x90
&& bytes[patchLocation + 2] == 0x90
&& bytes[patchLocation + 3] == 0x90
&& bytes[patchLocation + 4] == 0x90)
{
verbose("\tLapic panic already patched, kernel file manually patched?\n");
return false;
}
else
{
bytes[patchLocation + 0] = 0x90;
bytes[patchLocation + 1] = 0x90;
bytes[patchLocation + 2] = 0x90;
bytes[patchLocation + 3] = 0x90;
bytes[patchLocation + 4] = 0x90;
}
return true;
}
// ===================================
// Haswell-E Patch
bool patch_haswell_E_init(void *kernelData) // KernelHaswellEPatch
{
// Credit to stinga11 for the patches used below
// Based on Pike R. Alpha's Haswell patch for Mavericks
UInt8*Bytes;
UInt32Index;
boolPatchApplied;
verbose("\t- Searching for Haswell-E patch pattern\n");
Bytes = (UInt8 *)kernelData;
PatchApplied = false;
for (Index = 0; Index < 0x1000000; ++Index)
{
// sudo perl -pi -e 's|\x74\x11\x83\xF8\x3C|\x74\x11\x83\xF8\x3F|g' /System/Library/Kernels/kernel
if (Bytes[Index] == 0x74
&& Bytes[Index + 1] == 0x11
&& Bytes[Index + 2] == 0x83
&& Bytes[Index + 3] == 0xF8
&& Bytes[Index + 4] == 0x3C)
{
Bytes[Index + 4] = 0x3F;
verbose("\tFound Haswell-E pattern #1; patched.\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
// sudo perl -pi -e 's|\xEB\x0A\x83\xF8\x3A|\xEB\x0A\x83\xF8\x3F|g' /System/Library/Kernels/kernel
if (Bytes[Index] == 0xEB
&& Bytes[Index + 1] == 0x0A
&& Bytes[Index + 2] == 0x83
&& Bytes[Index + 3] == 0xF8
&& Bytes[Index + 4] == 0x3A)
{
Bytes[Index + 4] = 0x3F;
verbose("\tFound Haswell-E pattern #2; patched.\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
if (!PatchApplied)
{
verbose("\tCan't find Haswell-E patch pattern, patch not applied.\n");
}
return PatchApplied;
}
// ===================================
// Haswell-ULT Patch
bool patch_haswell_ULT_init(void *kernelData) // Fake CPUFAMILY To IVYBRIDGE Patch
{
// Credit to Tora Chi Yo for the patches used below
// http://www.insanelymac.com/forum/topic/307721-haswell-ult-kernel-patch-for-yosemite-mavericks
UInt8*Bytes;
UInt32Index;
boolPatchApplied;
verbose("\t- Searching for Haswell-ULT patch pattern\n");
Bytes = (UInt8 *)kernelData;
PatchApplied = false;
for (Index = 0; Index < 0x1000000; ++Index)
{
// sudo perl -pi -e 's|\xbb\xdc\x82\xb2\xdc|\xbb\x35\xe8\x65\x1f|g' /System/Library/Kernels/kernel
if (Bytes[Index] == 0xBB
&& Bytes[Index + 1] == 0xDC
&& Bytes[Index + 2] == 0x82
&& Bytes[Index + 3] == 0xB2
&& Bytes[Index + 4] == 0xdc)
{
Bytes[Index + 1] = 0x35;
Bytes[Index + 2] = 0xE8;
Bytes[Index + 3] = 0x65;
Bytes[Index + 4] = 0x1F;
verbose("\tFound Haswell-ULT pattern #1; patched.\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
if (!PatchApplied)
{
verbose("\tCan't find Haswell-ULT patch pattern, patch not applied.\n");
}
return PatchApplied;
}
// ===================================
// Custom Kext injection from Extra/Extensions folder
void patch_BooterExtensions_32(void *kernelData)
{
// KernelBooterExtensionsPatch to load extra kexts besides kernelcache
UInt8 *Bytes;
UInt32 Index;
bool PatchApplied;
int count = 0;
verbose("\t- Searching for booter extensions pattern:\n");
Bytes = (UInt8 *)kernelData;
PatchApplied = false;
if (kernelOSVer >= MacOSVer2Int("10.7") && kernelOSVer < MacOSVer2Int("10.8"))
{
//UInt8 KBELionSearch_i386[] = { 0xE8, 0xAA, 0xFB, 0xFF, 0xFF, 0xEB, 0x08, 0x89, 0x34, 0x24 };
//UInt8 KBELionReplace_i386[] = { 0xE8, 0xAA, 0xFB, 0xFF, 0xFF, 0x90, 0x90, 0x89, 0x34, 0x24 };
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0xAA
&& Bytes[Index + 2] == 0xFB
&& Bytes[Index + 3] == 0xFF
&& Bytes[Index + 4] == 0xFF
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x08
&& Bytes[Index + 7] == 0x89
&& Bytes[Index + 8] == 0x34
&& Bytes[Index + 9] == 0x24)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count ++;
verbose("\tFound Lion pattern: patched!\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
/* UNDER REVIEW, crazybirdy test this patch on Snow leopard:
1) He has reported has not working, but he runs the /S/L/E/Extensions.mkext: this patch allow booter extensions, so no reason to use that!
2) He try to load /Extra/Extensions, but the bootloader have a bug (after the RecoveryHD code inserted) and does not load the kernelcache and scan SLE
need to re-try later.
*/
if (kernelOSVer >= MacOSVer2Int("10.6") && kernelOSVer < MacOSVer2Int("10.7"))
{
//UInt8 KBESnowSearch_i386[] = { 0xE8, 0xED, 0xF9, 0xFF, 0xFF, 0xEB, 0x08, 0x89, 0x1C, 0x24 };
//UInt8 KBESnowReplace_i386[] = { 0xE8, 0xED, 0xF9, 0xFF, 0xFF, 0x90, 0x90, 0x89, 0x1C, 0x24 };
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0xED
&& Bytes[Index + 2] == 0xF9
&& Bytes[Index + 3] == 0xFF
&& Bytes[Index + 4] == 0xFF
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x08
&& Bytes[Index + 7] == 0x89
&& Bytes[Index + 8] == 0x1C
&& Bytes[Index + 9] == 0x24)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count ++;
verbose("\tFound Snow Leopard pattern: patched!\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
if (!PatchApplied)
{
verbose("\tCan't find Booter Extensions patch location.\n");
}
else
{
verbose("\t%d substitution(s) made.\n", count);
}
}
void patch_BooterExtensions_64(void *kernelData)
{
// KernelBooterExtensionsPatch to load extra kexts besides kernelcache
UInt8 *Bytes;
UInt32 Index;
bool PatchApplied; // does nothing
int count = 0;
verbose("\t- Searching for booter extensions pattern:\n");
Bytes = (UInt8 *)kernelData;
PatchApplied = false;
// Sierra onward
if (kernelOSVer >= MacOSVer2Int("10.12"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if ((kernelOSVer >= MacOSVer2Int("10.12"))
&& (Bytes[Index] == 0xC3
&& Bytes[Index + 1] == 0x48
&& Bytes[Index + 2] == 0x85
&& Bytes[Index + 3] == 0xDB
&& Bytes[Index + 4] == 0x74
&& Bytes[Index + 5] == 0x71
&& Bytes[Index + 6] == 0x48
&& Bytes[Index + 7] == 0x8B
&& Bytes[Index + 8] == 0x03
&& Bytes[Index + 9] == 0x48
&& Bytes[Index + 10] == 0x89
&& Bytes[Index + 11] == 0xDF
&& Bytes[Index + 12] == 0xFF
&& Bytes[Index + 13] == 0x50
&& Bytes[Index + 14] == 0x28
&& Bytes[Index + 15] == 0x48))
{
Bytes[Index + 4] = 0xEB;
Bytes[Index + 5] = 0x12;
count++;
verbose("\tFound Sierra SIP pattern: patched!\n");
PatchApplied = true;
break;
}
}
}
if (kernelOSVer >= MacOSVer2Int("10.12"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x25
&& Bytes[Index + 2] == 0x00
&& Bytes[Index + 3] == 0x00
&& Bytes[Index + 4] == 0x00
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x05
&& Bytes[Index + 7] == 0xE8
&& Bytes[Index + 8] == 0xCE
&& Bytes[Index + 9] == 0x02
&& Bytes[Index + 10] == 0x00
&& Bytes[Index + 11] == 0x00)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count++;
verbose("\tFound Sierra EXT (Yosemite) pattern: patched!\n");
PatchApplied = true;
break;
}
}
}
if (kernelOSVer <= MacOSVer2Int("10.12.3"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x25
&& Bytes[Index + 2] == 0x00
&& Bytes[Index + 3] == 0x00
&& Bytes[Index + 4] == 0x00
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x05
&& Bytes[Index + 7] == 0xE8
&& Bytes[Index + 8] == 0x7E
&& Bytes[Index + 9] == 0x05
&& Bytes[Index + 10] == 0x00
&& Bytes[Index + 11] == 0x00)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count++;
verbose("\tFound Sierra EXT (<= 10.12.4) pattern: patched!\n");
PatchApplied = true;
break;
}
}
}
if (kernelOSVer >= MacOSVer2Int("10.12.4"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x25
&& Bytes[Index + 2] == 0x00
&& Bytes[Index + 3] == 0x00
&& Bytes[Index + 4] == 0x00
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x05
&& Bytes[Index + 7] == 0xE8
&& Bytes[Index + 8] == 0x9E
&& Bytes[Index + 9] == 0x05
&& Bytes[Index + 10] == 0x00
&& Bytes[Index + 11] == 0x00)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count++;
verbose("\tFound Sierra (> = 10.12.4) EXT pattern: patched!\n");
PatchApplied = true;
break;
}
}
}
// El Capitan/Yosemite
if (kernelOSVer >= MacOSVer2Int("10.10") && kernelOSVer < MacOSVer2Int("10.12"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
// El Capitan
if (Bytes[Index] == 0xC3
&& Bytes[Index + 1] == 0x48
&& Bytes[Index + 2] == 0x85
&& Bytes[Index + 3] == 0xDB
&& Bytes[Index + 4] == 0x74
&& Bytes[Index + 5] == 0x70
&& Bytes[Index + 6] == 0x48
&& Bytes[Index + 7] == 0x8B
&& Bytes[Index + 8] == 0x03
&& Bytes[Index + 9] == 0x48
&& Bytes[Index + 10] == 0x89
&& Bytes[Index + 11] == 0xDF
&& Bytes[Index + 12] == 0xFF
&& Bytes[Index + 13] == 0x50
&& Bytes[Index + 14] == 0x28
&& Bytes[Index + 15] == 0x48)
{
Bytes[Index + 4] = 0xEB;
Bytes[Index + 5] = 0x12;
count++;
if (kernelOSVer >= MacOSVer2Int("10.11"))
{
verbose("\tFound El Capitan SIP pattern: patched!\n");
}
else
{
verbose("\tFound Yosemite SIP pattern: patched!\n");
}
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
// Yosemite and El Capitan
if ((kernelOSVer >= MacOSVer2Int("10.10") && kernelOSVer < MacOSVer2Int("10.12"))
&& (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x25
&& Bytes[Index + 2] == 0x00
&& Bytes[Index + 3] == 0x00
&& Bytes[Index + 4] == 0x00
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x05
&& Bytes[Index + 7] == 0xE8
&& Bytes[Index + 8] == 0xCE
&& Bytes[Index + 9] == 0x02
&& Bytes[Index + 10] == 0x00
&& Bytes[Index + 11] == 0x00))
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count++;
if (kernelOSVer < MacOSVer2Int("10.11"))
{
verbose("\tFound Yosemite EXT pattern: patched!\n");
}
else
{
verbose("\tFound EL Capitan EXT pattern: patched!\n");
}
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
// Mountain Lion/Mavericks
if (kernelOSVer >= MacOSVer2Int("10.8") && kernelOSVer < MacOSVer2Int("10.10"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xC6
&& Bytes[Index + 1] == 0xE8
&& Bytes[Index + 2] == 0x30
&& Bytes[Index + 3] == 0x00
&& Bytes[Index + 4] == 0x00
&& Bytes[Index + 5] == 0x00
&& Bytes[Index + 6] == 0xEB
&& Bytes[Index + 7] == 0x08
&& Bytes[Index + 8] == 0x48
&& Bytes[Index + 9] == 0x89
&& Bytes[Index + 10] == 0xDF)
{
Bytes[Index + 6] = 0x90;
Bytes[Index + 7] = 0x90;
count++;
verbose("\tFound M%s EXT pattern: patched!\n", checkOSVersion("10.8") ? "ountain Lion" : "avericks");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
// Lion 64
if (kernelOSVer >= MacOSVer2Int("10.7") && kernelOSVer < MacOSVer2Int("10.8"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x0C
&& Bytes[Index + 2] == 0xFD
&& Bytes[Index + 3] == 0xFF
&& Bytes[Index + 4] == 0xFF
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x08
&& Bytes[Index + 7] == 0x48
&& Bytes[Index + 8] == 0x89
&& Bytes[Index + 9] == 0xDF)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
count++;
verbose("\tFound Lion EXT pattern: patched!\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
// Snow Leopard 64
if (kernelOSVer >= MacOSVer2Int("10.6") && kernelOSVer < MacOSVer2Int("10.7"))
{
for (Index = 0; Index < 0x1000000; ++Index)
{
if (Bytes[Index] == 0xE8
&& Bytes[Index + 1] == 0x5A
&& Bytes[Index + 2] == 0xFB
&& Bytes[Index + 3] == 0xFF
&& Bytes[Index + 4] == 0xFF
&& Bytes[Index + 5] == 0xEB
&& Bytes[Index + 6] == 0x08
&& Bytes[Index + 7] == 0x48
&& Bytes[Index + 8] == 0x89
&& Bytes[Index + 9] == 0xDF)
{
Bytes[Index + 5] = 0x90;
Bytes[Index + 6] = 0x90;
verbose("\tFound Snow Leopard EXT pattern: patched!\n");
count++;
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
}
if (!PatchApplied)
{
verbose("\tCan't find Booter Extensions patch location.\n");
}
else
{
verbose("\t%d substitution(s) made.\n", count);
}
}
// ===================================
// Patch ssse3
void patch_SSE3_6(void *kernelData)
{
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation1 = 0;
UInt32 patchLocation2 = 0;
UInt32 patchlast = 0;
UInt32 i;
//UInt32 Length = sizeof(kernelData);
verbose("\t- Start find SSE3 address\n");
i = 0;
//for (i = 0; i < Length; i++)
while(true)
{
if (bytes[i] == 0x66
&& bytes[i + 1] == 0x0F
&& bytes[i + 2] == 0x6F
&& bytes[i + 3] == 0x44
&& bytes[i + 4] == 0x0E
&& bytes[i + 5] == 0xF1
&& bytes[i - 1664 - 32] == 0x55)
{
patchLocation1 = i-1664-32;
verbose("\tFound SSE3 data address at 0x%08X\n", (unsigned int)patchLocation1);
}
// hasSSE2+..... title
if (bytes[i] == 0xE3
&& bytes[i + 1] == 0x07
&& bytes[i + 2] == 0x00
&& bytes[i + 3] == 0x00
&& bytes[i + 4] == 0x80
&& bytes[i + 5] == 0x07
&& bytes[i + 6] == 0xFF
&& bytes[i + 7] == 0xFF
&& bytes[i + 8] == 0x24
&& bytes[i + 9] == 0x01)
{
patchLocation2 = i;
verbose("\tFound SSE3 Title address at 0x%08X\n", (unsigned int)patchLocation2);
break;
}
i++;
}
if (!patchLocation1 || !patchLocation2)
{
verbose("\tCan't found SSE3 data addres or Title address at 0x%08X 0x%08X\n", (unsigned int)patchLocation1, (unsigned int)patchLocation2);
return;
}
verbose("\tFound SSE3 last data addres Start\n");
i = patchLocation1 + 1500;
//for (i=(patchLocation1+1500); i<(patchLocation1+3000); i++)
while(true)
{
if (bytes[i] == 0x90
&& bytes[i + 1] == 0x90
&& bytes[i + 2] == 0x55 )
{
patchlast = (i+1) - patchLocation1;
verbose("\tFound SSE3 last data addres at 0x%08X\n", (unsigned int)patchlast);
break;
}
i++;
}
if (!patchlast)
{
verbose("\tCan't found SSE3 data last addres at 0x%08X\n", (unsigned int)patchlast);
return;
}
// patch sse3_64 data
for (i = 0; i < patchlast; i++)
{
if (i < sizeof(sse3_patcher))
{
bytes[patchLocation1 + i] = sse3_patcher[i];
}
else
{
bytes[patchLocation1 + i] = 0x90;
}
}
// patch kHasSSE3 title
bytes[patchLocation2 + 0] = 0xFC;
bytes[patchLocation2 + 1] = 0x05;
bytes[patchLocation2 + 8] = 0x2C;
bytes[patchLocation2 + 9] = 0x00;
}
// ===================================
//
void patch_SSE3_5(void *kernelData)
{
UInt8 *bytes = (UInt8 *)kernelData;
UInt32 patchLocation1 = 0;
UInt32 patchLocation2 = 0;
UInt32 patchlast=0;
UInt32 Length = sizeof(kernelData);
UInt32 i;
verbose("\t- Start find SSE3 address\n");
for (i = 256; i < (Length-256); i++)
{
if (bytes[i] == 0x66
&& bytes[i + 1] == 0x0F
&& bytes[i + 2] == 0x6F
&& bytes[i + 3] == 0x44
&& bytes[i + 4] == 0x0E
&& bytes[i + 5] == 0xF1
&& bytes[i - 1680 - 32] == 0x55)
{
patchLocation1 = i-1680-32;
verbose("\tFound SSE3 data address at 0x%08X\n", (unsigned int)patchLocation1);
}
// khasSSE2+..... title
if (bytes[i] == 0xF3
&& bytes[i + 1] == 0x07
&& bytes[i + 2] == 0x00
&& bytes[i + 3] == 0x00
&& bytes[i + 4] == 0x80
&& bytes[i + 5] == 0x07
&& bytes[i + 6] == 0xFF
&& bytes[i + 7] == 0xFF
&& bytes[i + 8] == 0x24
&& bytes[i + 9] == 0x01)
{
patchLocation2 = i;
verbose("\tFound SSE3 Title address at 0x%08X\n", (unsigned int)patchLocation2);
break;
}
}
if (!patchLocation1 || !patchLocation2)
{
verbose("\tCan't found SSE3 data addres or Title address at 0x%08X 0x%08X\n", (unsigned int)patchLocation1, (unsigned int)patchLocation2);
return;
}
verbose("\tFound SSE3 last data addres Start\n");
for (i = (patchLocation1+1500);i < Length;i++)
{
if (bytes[i] == 0x90
&& bytes[i + 1] == 0x90
&& bytes[i + 2] == 0x55)
{
patchlast = (i+1) - patchLocation1;
verbose("\tFound SSE3 last data addres at 0x%08X\n", (unsigned int)patchlast);
break;
}
}
if (!patchlast)
{
verbose("\tCan't found SSE3 data last addres at 0x%08X\n", (unsigned int)patchlast);
return;
}
// patech sse3_64 data
for (i = 0; i < patchlast; i++)
{
if (i < sizeof(sse3_5_patcher))
{
bytes[patchLocation1 + i] = sse3_5_patcher[i];
}
else
{
bytes[patchLocation1 + i] = 0x90;
}
}
// patch kHasSSE3 title
bytes[patchLocation2 + 0] = 0x0C;
bytes[patchLocation2 + 1] = 0x06;
bytes[patchLocation2 + 8] = 0x2C;
bytes[patchLocation2 + 9] = 0x00;
}
// ===================================
//
void patch_SSE3_7(void *kernelData)
{
// not support yet
return;
}
// ===================================
// root:xnu text replacement Patch
bool patch_string_XNU_init(void *kernelData) //
{
UInt8*Bytes;
UInt32Index;
boolPatchApplied;
DBG("\t- Searching for \"root:xnu-\" string pattern\n");
Bytes = (UInt8 *)kernelData;
PatchApplied = false;
for (Index = 0; Index < 0x1000000; ++Index)
{
// search for root:xnu- and replace it with ***Enoch-
if (Bytes[Index] == ' '
&& Bytes[Index + 1] == 'r'
&& Bytes[Index + 2] == 'o'
&& Bytes[Index + 3] == 'o'
&& Bytes[Index + 4] == 't'
&& Bytes[Index + 5] == ':'
&& Bytes[Index + 6] == 'x'
&& Bytes[Index + 7] == 'n'
&& Bytes[Index + 8] == 'u'
&& Bytes[Index + 9] == '-' )
{
Bytes[Index + 1] = '*';
Bytes[Index + 2] = '*';
Bytes[Index + 3] = '*';
Bytes[Index + 4] = 'E';
Bytes[Index + 5] = 'n';
Bytes[Index + 6] = 'o';
Bytes[Index + 7] = 'c';
Bytes[Index + 8] = 'h';
DBG("\tFound \"root:xnu-\" pattern; patched.\n");
if (PatchApplied)
{
break;
}
PatchApplied = true;
}
}
if (!PatchApplied)
{
DBG("\tCan't find \"root:xnu-\" string pattern: patch not applied.\n");
}
return PatchApplied;
}
// ===================================
// (Clover)
// Patching AppleRTC to prevent CMOS reset
unsigned int AppleRTC_Patch(void *data, UInt32 DriverSize, UInt32 StartLocation)
{
unsigned int count = 0;
// as far as I know this works from Lion to Sierra
UInt8 LionSearch_X64[] = { 0x75, 0x30, 0x44, 0x89, 0xf8 };
UInt8 LionReplace_X64[] = { 0xeb, 0x30, 0x44, 0x89, 0xf8 };
UInt8 LionSearch_i386[] = { 0x75, 0x3d, 0x8b, 0x75, 0x08 };
UInt8 LionReplace_i386[] = { 0xeb, 0x3d, 0x8b, 0x75, 0x08 };
UInt8 MLSearch[] = { 0x75, 0x30, 0x89, 0xd8 };
UInt8 MLReplace[] = { 0xeb, 0x30, 0x89, 0xd8 };
//SunKi
//752e0fb6 -> eb2e0fb6
UInt8 MavSearch[] = { 0x75, 0x2e, 0x0f, 0xb6 };
UInt8 MavReplace[] = { 0xeb, 0x2e, 0x0f, 0xb6};
if (kernelOSVer >= MacOSVer2Int("10.7") && kernelOSVer < MacOSVer2Int("10.8"))
{
count = FindAndReplace(data,
DriverSize,
StartLocation,
LionSearch_i386,
sizeof(LionSearch_i386),
LionReplace_i386,
0);
count = count + FindAndReplace(data,
DriverSize,
StartLocation,
LionSearch_X64,
sizeof(LionSearch_X64),
LionReplace_X64,
0);
}
else
if (kernelOSVer >= MacOSVer2Int("10.8") && kernelOSVer < MacOSVer2Int("10.9"))
{
count = FindAndReplace(data,
DriverSize,
StartLocation,
MLSearch,
sizeof(MLSearch),
MLReplace,
0);
}
else
if (kernelOSVer >= MacOSVer2Int("10.9"))
{
count = FindAndReplace(data,
DriverSize,
StartLocation,
MavSearch,
sizeof(MavSearch),
MavReplace,
0);
}
return count;
}
// ===================================
// (Clover)
// Patching AppleIntelCPUPowerManagement
unsigned int AsusAICPUPMPatch(void *data, UInt32 DriverSize, UInt32 StartLocation)
{
unsigned int Index1;
unsigned int Index2;
unsigned int Count = 0;
UInt8 MovlE2ToEcx[] = { 0xB9, 0xE2, 0x00, 0x00, 0x00 };
UInt8 MovE2ToCx[] = { 0x66, 0xB9, 0xE2, 0x00 };
UInt8 Wrmsr[] = { 0x0F, 0x30 };
UInt8*Driver = (UInt8 *)data;
//TODO: we should scan only __text __TEXT
for (Index1 = StartLocation; Index1 < (StartLocation+DriverSize); Index1++)
{
// search for MovlE2ToEcx
if (memcmp(Driver + Index1, MovlE2ToEcx, sizeof(MovlE2ToEcx)) == 0)
{
// search for wrmsr in next few bytes
for (Index2 = Index1 + sizeof(MovlE2ToEcx); Index2 < Index1 + sizeof(MovlE2ToEcx) + 32; Index2++)
{
if (Driver[Index2] == Wrmsr[0] && Driver[Index2 + 1] == Wrmsr[1])
{
// found it - patch it with nops
Count++;
Driver[Index2] = 0x90;
Driver[Index2 + 1] = 0x90;
verbose("\t%d wrmsr patched at 0x%X\n", Count, Index2);
break;
} else if ((Driver[Index2] == 0xC9 && Driver[Index2 + 1] == 0xC3) ||
(Driver[Index2] == 0x5D && Driver[Index2 + 1] == 0xC3) ||
(Driver[Index2] == 0xB9 && Driver[Index2 + 3] == 0 && Driver[Index2 + 4] == 0) ||
(Driver[Index2] == 0x66 && Driver[Index2 + 1] == 0xB9 && Driver[Index2 + 3] == 0))
{
// a leave/ret will cancel the search
// so will an intervening "mov[l] $xx, [e]cx"
break;
}
}
} else if (memcmp(Driver + Index1, MovE2ToCx, sizeof(MovE2ToCx)) == 0)
{
// search for wrmsr in next few bytes
for (Index2 = Index1 + sizeof(MovE2ToCx); Index2 < Index1 + sizeof(MovE2ToCx) + 32; Index2++)
{
if (Driver[Index2] == Wrmsr[0] && Driver[Index2 + 1] == Wrmsr[1])
{
// found it - patch it with nops
Count++;
Driver[Index2] = 0x90;
Driver[Index2 + 1] = 0x90;
verbose("\t%d wrmsr patched at 0x%X\n", Count, Index2);
break;
} else if ((Driver[Index2] == 0xC9 && Driver[Index2 + 1] == 0xC3) ||
(Driver[Index2] == 0x5D && Driver[Index2 + 1] == 0xC3) ||
(Driver[Index2] == 0xB9 && Driver[Index2 + 3] == 0 && Driver[Index2 + 4] == 0) ||
(Driver[Index2] == 0x66 && Driver[Index2 + 1] == 0xB9 && Driver[Index2 + 3] == 0))
{
// a leave/ret will cancel the search
// so will an intervening "mov[l] $xx, [e]cx"
break;
}
}
}
}
return Count;
}
// ===================================
// Patching IOAHCIBlockStorage to enable the trim support
unsigned int trimEnablerSata(void *data, UInt32 DriverSize, UInt32 StartLocation)
{
// as far as I know this works from Lion to Sierra
UInt8 Find[] = { 0x00, 0x41, 0x50, 0x50, 0x4C, 0x45, 0x20, 0x53, 0x53, 0x44, 0x00 };
UInt8 Replace[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
unsigned int count = FindAndReplace(data,
DriverSize,
StartLocation,
Find,
sizeof(Find),
Replace,
0);
return count;
}
// ===================================
// Patching AppleAHCIPort to fix orange icon (Sata only)
unsigned int patch_AppleAHCIPort_OrangeFix(void *data, UInt32 DriverSize, UInt32 StartLocation)
{
// as far as I know this works from lion onward
UInt8 Find[] = { 0x45, 0x78, 0x74, 0x65, 0x72, 0x6E, 0x61, 0x6C };
UInt8 Replace[] = { 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x61, 0x6C };
unsigned int count = FindAndReplace(data,
DriverSize,
StartLocation,
Find,
sizeof(Find),
Replace,
0);
return count;
}
// ===================================
// (Micky1979)
// Patching NVDAStartupWeb
unsigned int patch_NVDAStartupWeb(void *data, UInt32 DriverSize, UInt32 StartLocation)
{
unsigned int count = 0;
// this patch is needed only in Sierra onward
if (MacOSVerCurrent >= MacOSVer2Int("10.12"))
{
Node *nvdadrvNode = DT__FindNode("/nvdadrv", true);
if (nvdadrvNode != 0)
{
DT__AddProperty(nvdadrvNode, "nvda_drv", strlen(NVDAVALUE), (void*)NVDAVALUE);
UInt8 Find[] = { 0x49, 0x4F, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x72, 0x65, 0x65,
0x3A, 0x2F, 0x6F, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x00, 0x4E, 0x56,
0x44, 0x41, 0x53, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x57, 0x65, 0x62,
0x3A };
UInt8 Replace[] = { 0x49, 0x4F, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x72, 0x65, 0x65,
0x3A, 0x2F, 0x6E, 0x76, 0x64, 0x61, 0x64, 0x72, 0x76, 0x00, 0x4E, 0x56,
0x44, 0x41, 0x53, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x57, 0x65, 0x62,
0x3A };
count = FindAndReplace(data,
DriverSize,
StartLocation,
Find,
sizeof(Find),
Replace,
0);
}
else
{
verbose("Error: Unable to add nvdadrv node\n");
}
}
return count;
}
// ===================================
// Micky1979, 2017
// patch_prelinked_kexts
void patch_prelinked_kexts(void *kernelData,
u_int32_t uncompressed_size,
unsigned prelinkTextVmaddr,
unsigned prelinkTextFileOff)
{
TagPtr KextsPatches;
bool canPatchKexts = false;
unsigned long prelinkDictSize;
unsigned int Index;
unsigned int Count = 0;
UInt8 *Bytes = (UInt8 *)kernelData;
UInt8 *prelinkDic = NULL;
UInt32 prelinkDictStartLocation = 0;
UInt32 prelinkDictEndLocation = 0;
if (bootInfo->kextConfig.dictionary)
{
KextsPatches = XMLGetProperty(bootInfo->kextConfig.dictionary, (const char*)"KextsPatches");
}
verbose("[ KEXTS PATCHER START ]\n");
//int lessBytes = (int)((uncompressed_size/3)*2); // speedup, the _PrelinkInfoDictionary should not be 1/3 of entire cache!
for (Index = 0/*lessBytes*/; Index < uncompressed_size; ++Index)
{
//scan for _PrelinkInfoDictionary
if (Bytes[Index] == 0x3C
&& Bytes[Index + 1] == 0x64
&& Bytes[Index + 2] == 0x69
&& Bytes[Index + 3] == 0x63
&& Bytes[Index + 4] == 0x74
&& Bytes[Index + 5] == 0x3E
&& Bytes[Index + 6] == 0x3C
&& Bytes[Index + 7] == 0x6B
&& Bytes[Index + 8] == 0x65
&& Bytes[Index + 9] == 0x79
&& Bytes[Index + 10] == 0x3E
&& Bytes[Index + 11] == 0x5F
&& Bytes[Index + 12] == 0x50
&& Bytes[Index + 13] == 0x72
&& Bytes[Index + 14] == 0x65
&& Bytes[Index + 15] == 0x6C
&& Bytes[Index + 16] == 0x69
&& Bytes[Index + 17] == 0x6E
&& Bytes[Index + 18] == 0x6B
&& Bytes[Index + 19] == 0x49
&& Bytes[Index + 20] == 0x6E
&& Bytes[Index + 21] == 0x66
&& Bytes[Index + 22] == 0x6F
&& Bytes[Index + 23] == 0x44
&& Bytes[Index + 24] == 0x69
&& Bytes[Index + 25] == 0x63
&& Bytes[Index + 26] == 0x74
&& Bytes[Index + 27] == 0x69
&& Bytes[Index + 28] == 0x6F
&& Bytes[Index + 29] == 0x6E
&& Bytes[Index + 30] == 0x61
&& Bytes[Index + 31] == 0x72
&& Bytes[Index + 32] == 0x79
&& Bytes[Index + 33] == 0x3C
&& Bytes[Index + 34] == 0x2F
&& Bytes[Index + 35] == 0x6B
&& Bytes[Index + 36] == 0x65
&& Bytes[Index + 37] == 0x79
&& Bytes[Index + 38] == 0x3E)
{
Count++;
prelinkDictStartLocation = Index;
DBG("\tFound _PrelinkInfoDictionary at 0x%08X index = %d\n", (unsigned int)prelinkDictStartLocation, Index);
canPatchKexts = true;
break;
}
}
if (prelinkDictStartLocation)
{
for (Index = prelinkDictStartLocation; Index < uncompressed_size; ++Index)
{
// end of prelink ( <> plus some zeros)
if (Bytes[Index] == 0x3C
&& Bytes[Index + 1] == 0x2F
&& Bytes[Index + 2] == 0x64
&& Bytes[Index + 3] == 0x69
&& Bytes[Index + 4] == 0x63
&& Bytes[Index + 5] == 0x74
&& Bytes[Index + 6] == 0x3E
&& Bytes[Index + 7] == 0x00
&& Bytes[Index + 8] == 0x00
&& Bytes[Index + 9] == 0x00
&& Bytes[Index + 10] == 0x00
&& Bytes[Index + 11] == 0x00
&& Bytes[Index + 12] == 0x00
&& Bytes[Index + 13] == 0x00)
{
Count++;
if ((Count = 2))
{
canPatchKexts = true;
prelinkDictEndLocation = Index + 7 ;
DBG("\tFound _PrelinkInfoDictionary end location at 0x%08X index = %d\n", (unsigned int)prelinkDictEndLocation, Index);
}
break;
}
}
}
if (canPatchKexts)
{
prelinkDictSize = uncompressed_size - prelinkDictStartLocation;
prelinkDic = malloc(prelinkDictSize);
memcpy(prelinkDic, Bytes+prelinkDictStartLocation, prelinkDictSize);
TagPtr prelinkInfoPtr = NULL;
XMLParseFile( (char *)prelinkDic, &prelinkInfoPtr );
if (prelinkInfoPtr)
{
TagPtr prelinkInfoDictionary = XMLGetProperty(prelinkInfoPtr, "_PrelinkInfoDictionary");
if (!prelinkInfoDictionary)
{
verbose("Unable to allocate the _PrelinkInfoDictionary, kexts patcher skipped.");
return;
}
int count = XMLTagCount(prelinkInfoDictionary);
while(count)
{
TagPtr sub = XMLGetElement( prelinkInfoDictionary, count-1);
if (sub && XMLIsDict(sub))
{
char* execPath = XMLCastString(XMLGetProperty(sub, (const char*)"CFBundleExecutable"));
if (execPath != NULL)
{
UInt32 kextSize = XMLCastInteger(XMLGetProperty(sub, (const char*)"_PrelinkExecutableSize"));
UInt32 kextAddr = XMLCastInteger(XMLGetProperty(sub, (const char*)"_PrelinkExecutableSourceAddr"));
if (kextAddr && kextSize)
{
// adjust binary address location
kextAddr -= prelinkTextVmaddr;
kextAddr += prelinkTextFileOff;
DBG("\t[%d] found exec:%s (size = %u, kextAddr = 0x%X [vmaddr = 0x%X fileoff = 0x%X])\n", count, execPath,
(unsigned int)kextSize, (unsigned int)kextAddr, (unsigned int)prelinkTextVmaddr, (unsigned int)prelinkTextFileOff);
if (!strcmp(execPath, "FakeSMC"))
{
FakeSMCLoaded = true;
}
// chameleon patches
patchBooterDefinedKext(execPath, kernelData, kextSize, kextAddr);
// user's defined
if (KextsPatches && XMLIsDict(KextsPatches))
{
pach_binaryUsingDictionary(kernelData,
kextSize,
kextAddr,
execPath,
KextsPatches);
}
#if DEBUG_KERNEL
getchar();
#endif
}
}
}
count --;
}
}
}
else
{
verbose("Unable to find the _PrelinkInfoDictionary, kexts patcher skipped.");
}
if (prelinkDic) free(prelinkDic);
verbose("Kexts patcher: end!\n\n");
}
void patchBooterDefinedKext(const char *kext, void *driverAddr, UInt32 DriverSize, UInt32 StartLocation)
{
if ((!strcmp(kext, "AppleRTC")) && AppleRTCPatch)
{
verbose("\tPatching %s:", kext);
unsigned int numPatches = AppleRTC_Patch(driverAddr, DriverSize, StartLocation);
verbose(" %d substitutions made!\n", numPatches);
}
if ((!strcmp(kext, "AppleIntelCPUPowerManagement")) && AICPMPatch)
{
verbose("\tPatching %s (locked msr):\n", kext);
unsigned int numPatches = AsusAICPUPMPatch(driverAddr, DriverSize, StartLocation);
verbose("\t %d substitutions made!\n", numPatches);
}
if ((!strcmp(kext, "NVDAStartupWeb")) && NVIDIAWebDrv)
{
verbose("\tPatching %s (force load w/o nvram):\n", kext);
unsigned int numPatches = patch_NVDAStartupWeb(driverAddr, DriverSize, StartLocation);
verbose("\t %d substitutions made!\n", numPatches);
}
if ((!strcmp(kext, "IOAHCIBlockStorage")) && TrimEnablerSata)
{
verbose("\tPatching %s (trim enabler SATA):", kext);
unsigned int numPatches = trimEnablerSata(driverAddr, DriverSize, StartLocation);
verbose(" %d substitutions made!\n", numPatches);
}
if ((!strcmp(kext, "AppleAHCIPort")) && OrangeIconFixSata)
{
verbose("\tPatching %s (orange icon fix):", kext);
unsigned int numPatches = patch_AppleAHCIPort_OrangeFix(driverAddr, DriverSize, StartLocation);
verbose(" %d substitutions made!\n", numPatches);
}
}
// ===================================
// Boolean function to check the full OSX match version
bool checkFullOSVer(const char *version)
{
// We are in a version with 7 char ?
if ( (sizeof(version) == 7) && ('.' == version[5]) && ('\0' != version[6]) ) // 10.xx.x
{
return ( (gBootVolume->OSFullVer[0] == version[0]) // 1
&& (gBootVolume->OSFullVer[1] == version[1]) // 0
&& (gBootVolume->OSFullVer[2] == version[2]) // .
&& (gBootVolume->OSFullVer[3] == version[3]) // x
&& (gBootVolume->OSFullVer[4] == version[4]) // x
&& (gBootVolume->OSFullVer[5] == version[5]) // .
&& (gBootVolume->OSFullVer[6] == version[6]) // x
);
}
// We are in a version with 7 char ?
if ( (sizeof(version) == 7) && ('.' == version[4]) && ('\0' != version[6]) ) // 10.4.11
{
return ( (gBootVolume->OSFullVer[0] == version[0]) // 1
&& (gBootVolume->OSFullVer[1] == version[1]) // 0
&& (gBootVolume->OSFullVer[2] == version[2]) // .
&& (gBootVolume->OSFullVer[3] == version[3]) // 4
&& (gBootVolume->OSFullVer[4] == version[4]) // .
&& (gBootVolume->OSFullVer[5] == version[5]) // x
&& (gBootVolume->OSFullVer[6] == version[6]) // x
);
}
// We are in a version with 6 char ?
if ( (sizeof(version) == 6) && ('.' == version[4]) && ('\0' != version[5]) ) // 10.x.x
{
return ( (gBootVolume->OSFullVer[0] == version[0]) // 1
&& (gBootVolume->OSFullVer[1] == version[1]) // 0
&& (gBootVolume->OSFullVer[2] == version[2]) // .
&& (gBootVolume->OSFullVer[3] == version[3]) // x
&& (gBootVolume->OSFullVer[4] == version[4]) // .
&& (gBootVolume->OSFullVer[5] == version[5]) // x
);
}
// We are in a version with 5 char ?
if ( (sizeof(version) == 5) && ('.' != version[4]) && ('\0' != version[4]) ) // 10.xx
{
return ( (gBootVolume->OSFullVer[0] == version[0]) // 1
&& (gBootVolume->OSFullVer[1] == version[1]) // 0
&& (gBootVolume->OSFullVer[2] == version[2]) // .
&& (gBootVolume->OSFullVer[3] == version[3]) // x
&& (gBootVolume->OSFullVer[4] == version[4]) // x
);
}
// We are in a version with 4 char ?
if ( (sizeof(version) == 4) && ('\0' != version[3]) ) // 10.x
{
return ( (gBootVolume->OSFullVer[0] == version[0]) // 1
&& (gBootVolume->OSFullVer[1] == version[1]) // 0
&& (gBootVolume->OSFullVer[2] == version[2]) // .
&& (gBootVolume->OSFullVer[3] == version[3]) // x
);
}
// no match found
return false;
}
branches/ErmaC/Enoch/i386/boot2/kernel_patcher_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (c) 2009-2012 Evan Lojewski. All rights reserved.
* Copyright (c) 2013-2015 xZenue LLC. All rights reserved.
*
*
* This work is licensed under the
* Creative Commons Attribution-NonCommercial 3.0 Unported License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/.
*/
#ifndef __BOOT2_KERNEL_PATCHER_H
#define __BOOT2_KERNEL_PATCHER_H
#include <libkern/OSTypes.h>
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <mach-o/reloc.h>
#include "modules.h"
#include "cpu.h"
#include "binaryPatcher.h"
#define CPU_MODEL_ANY 0x00
#define CPU_MODEL_UNKNOWN 0x01
#define KERNEL_ANY 0x00
#define KERNEL_64 0x01
#define KERNEL_32 0x02
#define KERNEL_ERR 0xFF
#define CPUIDFAMILY_DEFAULT 6
// kernel patches
void patch_kernel_internal(void *kernelData, u_int32_t uncompressed_size);
// Power management patch for kernel 13.0
static UInt8 KernelPatchPmSrc[] = {
0x55, 0x48, 0x89, 0xe5, 0x41, 0x89, 0xd0, 0x85,
0xf6, 0x74, 0x6c, 0x48, 0x83, 0xc7, 0x28, 0x90,
0x8b, 0x05, 0x5e, 0x30, 0x5e, 0x00, 0x85, 0x47,
0xdc, 0x74, 0x54, 0x8b, 0x4f, 0xd8, 0x45, 0x85,
0xc0, 0x74, 0x08, 0x44, 0x39, 0xc1, 0x44, 0x89,
0xc1, 0x75, 0x44, 0x0f, 0x32, 0x89, 0xc0, 0x48,
0xc1, 0xe2, 0x20, 0x48, 0x09, 0xc2, 0x48, 0x89,
0x57, 0xf8, 0x48, 0x8b, 0x47, 0xe8, 0x48, 0x85,
0xc0, 0x74, 0x06, 0x48, 0xf7, 0xd0, 0x48, 0x21,
0xc2, 0x48, 0x0b, 0x57, 0xf0, 0x49, 0x89, 0xd1,
0x49, 0xc1, 0xe9, 0x20, 0x89, 0xd0, 0x8b, 0x4f,
0xd8, 0x4c, 0x89, 0xca, 0x0f, 0x30, 0x8b, 0x4f,
0xd8, 0x0f, 0x32, 0x89, 0xc0, 0x48, 0xc1, 0xe2,
0x20, 0x48, 0x09, 0xc2, 0x48, 0x89, 0x17, 0x48,
0x83, 0xc7, 0x30, 0xff, 0xce, 0x75, 0x99, 0x5d,
0xc3, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
};
static UInt8 KernelPatchPmRepl[] = {
0x55, 0x48, 0x89, 0xe5, 0x41, 0x89, 0xd0, 0x85,
0xf6, 0x74, 0x73, 0x48, 0x83, 0xc7, 0x28, 0x90,
0x8b, 0x05, 0x5e, 0x30, 0x5e, 0x00, 0x85, 0x47,
0xdc, 0x74, 0x5b, 0x8b, 0x4f, 0xd8, 0x45, 0x85,
0xc0, 0x74, 0x08, 0x44, 0x39, 0xc1, 0x44, 0x89,
0xc1, 0x75, 0x4b, 0x0f, 0x32, 0x89, 0xc0, 0x48,
0xc1, 0xe2, 0x20, 0x48, 0x09, 0xc2, 0x48, 0x89,
0x57, 0xf8, 0x48, 0x8b, 0x47, 0xe8, 0x48, 0x85,
0xc0, 0x74, 0x06, 0x48, 0xf7, 0xd0, 0x48, 0x21,
0xc2, 0x48, 0x0b, 0x57, 0xf0, 0x49, 0x89, 0xd1,
0x49, 0xc1, 0xe9, 0x20, 0x89, 0xd0, 0x8b, 0x4f,
0xd8, 0x4c, 0x89, 0xca, 0x66, 0x81, 0xf9, 0xe2,
0x00, 0x74, 0x02, 0x0f, 0x30, 0x8b, 0x4f, 0xd8,
0x0f, 0x32, 0x89, 0xc0, 0x48, 0xc1, 0xe2, 0x20,
0x48, 0x09, 0xc2, 0x48, 0x89, 0x17, 0x48, 0x83,
0xc7, 0x30, 0xff, 0xce, 0x75, 0x92, 0x5d, 0xc3
};
// Power management patch for kernel 12.5
static UInt8 KernelPatchPmSrc2[] = {
0x55, 0x48, 0x89, 0xe5, 0x41, 0x89, 0xd0, 0x85,
0xf6, 0x74, 0x69, 0x48, 0x83, 0xc7, 0x28, 0x90,
0x8b, 0x05, 0xfe, 0xce, 0x5f, 0x00, 0x85, 0x47,
0xdc, 0x74, 0x51, 0x8b, 0x4f, 0xd8, 0x45, 0x85,
0xc0, 0x74, 0x05, 0x44, 0x39, 0xc1, 0x75, 0x44,
0x0f, 0x32, 0x89, 0xc0, 0x48, 0xc1, 0xe2, 0x20,
0x48, 0x09, 0xc2, 0x48, 0x89, 0x57, 0xf8, 0x48,
0x8b, 0x47, 0xe8, 0x48, 0x85, 0xc0, 0x74, 0x06,
0x48, 0xf7, 0xd0, 0x48, 0x21, 0xc2, 0x48, 0x0b,
0x57, 0xf0, 0x49, 0x89, 0xd1, 0x49, 0xc1, 0xe9,
0x20, 0x89, 0xd0, 0x8b, 0x4f, 0xd8, 0x4c, 0x89,
0xca, 0x0f, 0x30, 0x8b, 0x4f, 0xd8, 0x0f, 0x32,
0x89, 0xc0, 0x48, 0xc1, 0xe2, 0x20, 0x48, 0x09,
0xc2, 0x48, 0x89, 0x17, 0x48, 0x83, 0xc7, 0x30,
0xff, 0xce, 0x75, 0x9c, 0x5d, 0xc3, 0x90, 0x90,
0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90
};
static UInt8 KernelPatchPmRepl2[] = {
0x55, 0x48, 0x89, 0xe5, 0x41, 0x89, 0xd0, 0x85,
0xf6, 0x74, 0x70, 0x48, 0x83, 0xc7, 0x28, 0x90,
0x8b, 0x05, 0xfe, 0xce, 0x5f, 0x00, 0x85, 0x47,
0xdc, 0x74, 0x58, 0x8b, 0x4f, 0xd8, 0x45, 0x85,
0xc0, 0x74, 0x05, 0x44, 0x39, 0xc1, 0x75, 0x4b,
0x0f, 0x32, 0x89, 0xc0, 0x48, 0xc1, 0xe2, 0x20,
0x48, 0x09, 0xc2, 0x48, 0x89, 0x57, 0xf8, 0x48,
0x8b, 0x47, 0xe8, 0x48, 0x85, 0xc0, 0x74, 0x06,
0x48, 0xf7, 0xd0, 0x48, 0x21, 0xc2, 0x48, 0x0b,
0x57, 0xf0, 0x49, 0x89, 0xd1, 0x49, 0xc1, 0xe9,
0x20, 0x89, 0xd0, 0x8b, 0x4f, 0xd8, 0x4c, 0x89,
0xca, 0x66, 0x81, 0xf9, 0xe2, 0x00, 0x74, 0x02,
0x0f, 0x30, 0x8b, 0x4f, 0xd8, 0x0f, 0x32, 0x89,
0xc0, 0x48, 0xc1, 0xe2, 0x20, 0x48, 0x09, 0xc2,
0x48, 0x89, 0x17, 0x48, 0x83, 0xc7, 0x30, 0xff,
0xce, 0x75, 0x95, 0x5d, 0xc3, 0x90, 0x90, 0x90
};
#define KERNEL_PATCH_SIGNATURE 0x85d08941e5894855ULL
void patch_kernel_32(void *kernelData, u_int32_t uncompressed_size);
void patch_kernel_64(void *kernelData, u_int32_t uncompressed_size);
void patch_BooterExtensions_32(void *kernelData);
void patch_BooterExtensions_64(void *kernelData);
bool patch_pm_init(void *kernelData);
bool patch_lapic_version_init_32(void *kernelData);
bool patch_lapic_version_init_64(void *kernelData);
bool patch_lapic_init_32(void *kernelData);
bool patch_lapic_init_64(void *kernelData);
bool patch_haswell_E_init(void *kernelData);
bool patch_haswell_ULT_init(void *kernelData);
void patch_SSE3_6(void *kernelData);
void patch_SSE3_5(void *kernelData);
void patch_SSE3_7(void *kernelData);
bool patch_string_XNU_init(void *kernelData);
// kexts pathes
unsigned int AppleRTC_Patch(void *data, UInt32 DriverSize, UInt32 StartLocation);
unsigned int AsusAICPUPMPatch(void *data, UInt32 DriverSize, UInt32 StartLocation);
unsigned int patch_NVDAStartupWeb(void *kernelData, UInt32 DriverSize, UInt32 StartLocation);
unsigned int trimEnablerSata(void *data, UInt32 DriverSize, UInt32 StartLocation);
unsigned int patch_AppleAHCIPort_OrangeFix(void *data, UInt32 DriverSize, UInt32 StartLocation);
void patch_prelinked_kexts(void *kernelData,
u_int32_t uncompressed_size,
unsigned prelinkTextVmaddr,
unsigned prelinkTextFileOff);
void patchBooterDefinedKext(const char *kext, void *driverAddr, UInt32 DriverSize, UInt32 StartLocation);
// os version
bool checkFullOSVer(const char *version);
#endif /* !__BOOT2_KERNEL_PATCHER_H */

Archive Download the corresponding diff file

Revision: 2871