From 0b8ec1929bfb66273d3fa1d9100b6a01047bc215 Mon Sep 17 00:00:00 2001 From: Wayne Bonnici <24826299+waynebonc@users.noreply.github.com> Date: Thu, 8 Jul 2021 22:52:01 +0200 Subject: [PATCH] Restore header for fat macho kernels after patching --- Kernel64Patcher.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Kernel64Patcher.c b/Kernel64Patcher.c index 45f3aa9..6750db4 100644 --- a/Kernel64Patcher.c +++ b/Kernel64Patcher.c @@ -99,8 +99,20 @@ int main(int argc, char **argv) { return -1; } + int is_fat = 0; + void* fat_buf; if (*(uint32_t*)kernel_buf == 0xbebafeca) { printf("%s: Detected fat macho kernel\n",__FUNCTION__); + + is_fat = 1; + fat_buf = (void*)malloc(28); + if(!fat_buf) { + printf("%s: Out of memory!\n", __FUNCTION__); + free(kernel_buf); + return -1; + } + memcpy(fat_buf, kernel_buf, 28); + memmove(kernel_buf,kernel_buf+28,kernel_len); } @@ -121,6 +133,12 @@ int main(int argc, char **argv) { return -1; } + if (is_fat == 1) { + memmove(kernel_buf, kernel_buf - 28, kernel_len); + memcpy(kernel_buf, fat_buf, 28); + free(fat_buf); + } + fwrite(kernel_buf, 1, kernel_len, fp); fflush(fp); fclose(fp);