Skip to content

Commit 87b9aeb

Browse files
feat: restrict hardcoded patches to specific iOS ver
1 parent 808dc60 commit 87b9aeb

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

hw/arm/apple-silicon/boot.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,10 +938,7 @@ uint32_t macho_build_version(MachoHeader64 *mh)
938938
for (index = 0; index < mh->n_cmds; index++) {
939939
switch (cmd->cmd) {
940940
case LC_BUILD_VERSION: {
941-
MachoBuildVersionCommand *buildVerCmd =
942-
(MachoBuildVersionCommand *)cmd;
943-
return buildVerCmd->sdk;
944-
break;
941+
return ((MachoBuildVersionCommand *)cmd)->sdk;
945942
}
946943

947944
default:
@@ -961,6 +958,7 @@ uint32_t macho_platform(MachoHeader64 *mh)
961958
if (mh->file_type == MH_FILESET) {
962959
mh = macho_get_fileset_header(mh, "com.apple.kernel");
963960
}
961+
964962
cmd = (MachoLoadCommand *)((char *)mh + sizeof(MachoHeader64));
965963

966964
for (index = 0; index < mh->n_cmds; index++) {

hw/arm/apple-silicon/s8000.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,10 @@ static void s8000_machine_init(MachineState *machine)
12431243
s8000_machine->kernel = hdr;
12441244
s8000_machine->secure_monitor = secure_monitor;
12451245
build_version = macho_build_version(hdr);
1246-
info_report("Loading %s %u.%u...", macho_platform_string(hdr),
1246+
info_report("Loading %s %u.%u.%u...", macho_platform_string(hdr),
12471247
BUILD_VERSION_MAJOR(build_version),
1248-
BUILD_VERSION_MINOR(build_version));
1248+
BUILD_VERSION_MINOR(build_version),
1249+
BUILD_VERSION_PATCH(build_version));
12491250
s8000_machine->build_version = build_version;
12501251

12511252
macho_highest_lowest(hdr, &kernel_low, &kernel_high);

hw/arm/apple-silicon/t8030.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "exec/memattrs.h"
2424
#include "exec/memory.h"
2525
#include "hw/arm/apple-silicon/a13.h"
26+
#include "hw/arm/apple-silicon/boot.h"
2627
#include "hw/arm/apple-silicon/dart.h"
2728
#include "hw/arm/apple-silicon/dtb.h"
2829
#include "hw/arm/apple-silicon/lm-backlight.h"
@@ -151,8 +152,16 @@ static void t8030_create_s3c_uart(const T8030MachineState *t8030_machine,
151152
dev->id = g_strdup(name);
152153
}
153154

154-
static void t8030_patch_kernel(MachoHeader64 *hdr)
155+
static void t8030_patch_kernel(MachoHeader64 *hdr, uint32_t build_version)
155156
{
157+
xnu_kpf(hdr);
158+
159+
if (BUILD_VERSION_MAJOR(build_version) != 14 ||
160+
BUILD_VERSION_MINOR(build_version) != 0 ||
161+
BUILD_VERSION_PATCH(build_version) != 0) {
162+
return;
163+
}
164+
156165
const uint32_t nop = cpu_to_le32(0xD503201F);
157166

158167
// disable_kprintf_output = 0;
@@ -217,8 +226,6 @@ static void t8030_patch_kernel(MachoHeader64 *hdr)
217226
// AND SHOULD BE PROSECUTED TO THE FULL EXTENT OF THE LAW.
218227
// We do NOT endorse nor approve the theft of property.
219228
memcpy((char *)vtop_slid(0xFFFFFFF00703884E), "profile", 8);
220-
221-
xnu_kpf(hdr);
222229
}
223230

224231
static bool t8030_check_panic(T8030MachineState *t8030_machine)
@@ -2385,9 +2392,10 @@ static void t8030_machine_init(MachineState *machine)
23852392
g_assert_nonnull(hdr);
23862393
t8030_machine->kernel = hdr;
23872394
build_version = macho_build_version(hdr);
2388-
info_report("Loading %s %u.%u...", macho_platform_string(hdr),
2395+
info_report("Loading %s %u.%u.%u...", macho_platform_string(hdr),
23892396
BUILD_VERSION_MAJOR(build_version),
2390-
BUILD_VERSION_MINOR(build_version));
2397+
BUILD_VERSION_MINOR(build_version),
2398+
BUILD_VERSION_PATCH(build_version));
23912399
t8030_machine->build_version = build_version;
23922400

23932401
switch (BUILD_VERSION_MAJOR(build_version)) {
@@ -2429,7 +2437,7 @@ static void t8030_machine_init(MachineState *machine)
24292437
g_virt_base = kernel_low;
24302438
g_phys_base = (hwaddr)macho_get_buffer(hdr);
24312439

2432-
t8030_patch_kernel(hdr);
2440+
t8030_patch_kernel(hdr, build_version);
24332441

24342442
t8030_machine->device_tree = load_dtb_from_file(machine->dtb);
24352443
t8030_machine->trustcache =

include/hw/arm/apple-silicon/boot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ typedef struct {
130130
#define PLATFORM_BRIDGEOS (5)
131131

132132
#define BUILD_VERSION_MAJOR(_v) (((_v) & 0xFFFF0000) >> 16)
133-
#define BUILD_VERSION_MINOR(_v) (((_v) & 0x0000FF00) >> 8)
133+
#define BUILD_VERSION_MINOR(_v) (((_v) & 0xFF00) >> 8)
134+
#define BUILD_VERSION_PATCH(_v) ((_v) & 0xFF)
134135

135136
typedef struct {
136137
uint32_t cmd;

0 commit comments

Comments
 (0)