Skip to content

Commit

Permalink
Fix 17.6b3+ mac_mount top
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Jul 20, 2024
1 parent 374872e commit 3477f15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions checkra1n/kpf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,16 @@ bool kpf_mac_mount_callback(struct xnu_pf_patch* patch, uint32_t* opcode_stream)
// Most reliable marker of a stack frame seems to be "add x29, sp, 0x...".
// And this function is HUGE, hence up to 2k insn.
uint32_t *frame = find_prev_insn(mac_mount_1, 2000, 0x910003fd, 0xff8003ff);
if(!frame) return false;

if(!frame) {
DEVLOG("kpf_mac_mount_callback: failed to find stack frame");
return false;
}
// Now find the insn that decrements sp. This can be either
// "stp ..., ..., [sp, -0x...]!" or "sub sp, sp, 0x...".
// Match top bit of imm on purpose, since we only want negative offsets.
uint32_t *start = find_prev_insn(frame, 10, 0xa9a003e0, 0xffe003e0);
if(!start) start = find_prev_insn(frame, 10, 0xd10003ff, 0xff8003ff);
uint32_t *start = find_prev_insn(frame, 10, 0xa9a003e0, 0xffe003e0); // stp xN, xM, [sp, #-0x...]!
if(!start) start = find_prev_insn(frame, 10, 0xd10003ff, 0xff8003ff); // sub sp, sp, ...
if(!start) start = find_prev_insn(frame, 10, 0x6da003e0, 0xffe083e0); // stp dN, dM, [sp, #-0x...]!
if(!start) return false;

_mac_mount = start;
Expand Down
2 changes: 2 additions & 0 deletions checkra1n/kpf/ramdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static void kpf_ramdisk_init(struct mach_header_64 *hdr, xnu_pf_range_t *cstring
#endif
}

#if !defined(KPF_TEST)
static const char* disk_prefix(void) {
if (gKernelVersion.darwinMajor >= 19) {
if (xnu_platform() == PLATFORM_TVOS) {
Expand All @@ -151,6 +152,7 @@ static const char* disk_prefix(void) {
return "disk0s1s";
}
}
#endif

static void kpf_ramdisk_bootprep(struct mach_header_64 *hdr, palerain_option_t palera1n_flags)
{
Expand Down

0 comments on commit 3477f15

Please sign in to comment.