├── iboot ├── sym_order.txt ├── ibootpatch2 │ ├── sym_order.txt │ ├── asm │ │ ├── Makefile │ │ └── shellcode.s │ ├── entry.S │ ├── include │ │ ├── common.h │ │ └── offsetfinder.h │ ├── lib │ │ ├── memmem.c │ │ ├── memset.c │ │ ├── memcmp.c │ │ └── memcpy.c │ ├── Makefile │ ├── generate.c │ └── ibootpatch2.c ├── include │ └── common.h ├── Makefile ├── generate.c ├── entry.S └── tramhook.c ├── magic ├── sym_order.txt ├── README.md ├── include │ ├── offsetfinder.h │ ├── drivers │ │ └── fb │ │ │ └── fb.h │ ├── common.h │ └── printf.h ├── lib │ ├── memmem.c │ ├── strlen.c │ ├── strcpy.c │ ├── memset.c │ ├── strcat.c │ ├── strtoull.c │ ├── strcmp.c │ ├── memcmp.c │ ├── strstr.c │ ├── memcpy.c │ ├── strncmp.c │ └── strchr.c ├── Makefile ├── apple-include │ ├── sys │ │ ├── _types │ │ │ ├── _os_inline.h │ │ │ └── _mach_port_t.h │ │ ├── appleapiopts.h │ │ ├── _posix_availability.h │ │ ├── _types.h │ │ └── _pthread │ │ │ └── _pthread_types.h │ ├── mach │ │ ├── machine │ │ │ ├── thread_state.h │ │ │ ├── _structs.h │ │ │ ├── boolean.h │ │ │ ├── vm_types.h │ │ │ ├── kern_return.h │ │ │ └── thread_status.h │ │ ├── i386 │ │ │ ├── thread_state.h │ │ │ ├── boolean.h │ │ │ ├── kern_return.h │ │ │ ├── vm_types.h │ │ │ └── fp_reg.h │ │ ├── arm │ │ │ ├── thread_state.h │ │ │ ├── boolean.h │ │ │ ├── kern_return.h │ │ │ └── vm_types.h │ │ ├── boolean.h │ │ ├── vm_types.h │ │ └── vm_prot.h │ ├── machine │ │ └── _types.h │ ├── arm │ │ ├── arch.h │ │ └── _types.h │ ├── libkern │ │ ├── _OSByteOrder.h │ │ ├── machine │ │ │ └── OSByteOrder.h │ │ └── arm │ │ │ └── OSByteOrder.h │ ├── i386 │ │ ├── eflags.h │ │ └── _types.h │ └── AvailabilityVersions.h ├── entry.S ├── drivers │ ├── dt │ │ ├── dtree_getprop.c │ │ └── dtree.c │ └── xnu │ │ └── xnu.s └── payload.c ├── .gitattributes ├── README.txt └── .gitignore /iboot/sym_order.txt: -------------------------------------------------------------------------------- 1 | start 2 | -------------------------------------------------------------------------------- /magic/sym_order.txt: -------------------------------------------------------------------------------- 1 | start 2 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/sym_order.txt: -------------------------------------------------------------------------------- 1 | start 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /magic/README.md: -------------------------------------------------------------------------------- 1 | # nya~ 2 | unfinished, incomplete iboot payload 3 | many codes are missing :p 4 | 5 |     ∧_∧__ 6 |   /(´・ω・`) /\ 7 |  /| ̄ ̄ ̄ ̄|\/ 8 |   |    |/ 9 |     ̄ ̄ ̄ ̄ 10 | 11 | credit: 12 | pongoOS ... checkra1n 13 | patchfinder ... in7egral 14 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 魔法の猫ちゃん 2 | 3 | 4 | 未完成の、checkm8(約3年前に発見されたデバイス自体のバグ)を持つデバイス向けjailbreak用toolkitのベースシステムの一部 5 | 悪用厳禁ですが、まずこのソースだけではjailbreakすることはできません。あくまでパッチを適用するパートのみです。 6 | 7 | - iboot 8 | checkm8 exploitを使用してデバイスをカスタムリカバリーモードで起動するまでのパート 9 | 10 | - magic 11 | iBootがカーネルをロードする際にパッチを適用するパート。pongoOSのkpfを少々改変して貼り付けで実行することができます。 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | .irecovery 4 | irecovery 5 | vmacho 6 | iboot/generate 7 | iboot/ibootpatch2/asm/shellcode.bin 8 | iboot/ibootpatch2/asm/shellcode.h 9 | iboot/ibootpatch2/generate 10 | iboot/ibootpatch2/ibootpatch2.bin 11 | iboot/ibootpatch2/ibootpatch2.h 12 | iboot/tramhook.bin 13 | iboot/tramhook.h 14 | magic/magic.h 15 | magic/payload.bin 16 | magic/payload.o 17 | iboot/ibootpatch2/test.c 18 | magic/kpf.c 19 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/asm/Makefile: -------------------------------------------------------------------------------- 1 | CC = xcrun -sdk iphoneos clang 2 | OBJCOPY = /opt/homebrew/opt/binutils/bin/gobjcopy 3 | CFLAGS = -target arm64-apple-darwin -Wall 4 | 5 | .PHONY: all 6 | 7 | all: 8 | -$(RM) shellcode.h 9 | $(CC) $(CFLAGS) shellcode.s -o shellcode.o 10 | $(OBJCOPY) -O binary -j .text shellcode.o shellcode.bin 11 | xxd -i shellcode.bin > shellcode.h 12 | -$(RM) shellcode.o 13 | 14 | clean: 15 | -$(RM) shellcode.h 16 | -$(RM) shellcode.o 17 | -$(RM) shellcode.bin 18 | -------------------------------------------------------------------------------- /magic/include/offsetfinder.h: -------------------------------------------------------------------------------- 1 | #ifndef OFFSETFINDER_H 2 | #define OFFSETFINDER_H 3 | 4 | #include 5 | #include 6 | 7 | uint64_t find_printf(uint64_t region, uint8_t* data, size_t size); 8 | uint64_t find_jumpto_func(uint64_t region, uint8_t* data, size_t size); 9 | uint64_t find_malloc(uint64_t region, uint8_t* data, size_t size); 10 | uint64_t find_panic(uint64_t region, uint8_t* data, size_t size); 11 | uint64_t find_free(uint64_t region, uint8_t* data, size_t size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /iboot/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | 7 | typedef uint64_t size_t; 8 | 9 | #ifndef NULL 10 | #define NULL ((void*)0) 11 | #endif 12 | 13 | // iboot 14 | typedef int (*write_t)(uint64_t arg0); 15 | write_t heapWriteHash; 16 | typedef int (*check_t)(uint64_t arg0); 17 | check_t heapCheckAll; 18 | 19 | typedef void (*memcpy_t)(void *__restrict dst0, const void *__restrict src0, size_t len0); 20 | memcpy_t my_memcpy; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/entry.S: -------------------------------------------------------------------------------- 1 | 2 | .globl _ORIGINAL 3 | .globl _IBOOT_BASE_ADDRESS 4 | .globl _SDRAM_PAGE_ADDRESS 5 | .globl _LOAD_ADDRESS 6 | 7 | .text 8 | .align 4 9 | .org 0x400 10 | .globl start 11 | start: 12 | 13 | msr daifset, #0xf 14 | b _patch 15 | nop 16 | nop 17 | 18 | _MAGIC: 19 | .quad 0xdeadbeefdeadbeef 20 | 21 | _ORIGINAL: 22 | .quad 0x6161616161616161 23 | 24 | _IBOOT_BASE_ADDRESS: 25 | .quad 0x6262626262626262 26 | 27 | _SDRAM_PAGE_ADDRESS: 28 | .quad 0x6363636363636363 29 | 30 | _LOAD_ADDRESS: 31 | .quad 0x6464646464646464 32 | 33 | nop 34 | nop 35 | nop 36 | nop 37 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | 7 | #ifndef TESTBUILD 8 | typedef uint64_t size_t; 9 | 10 | #ifndef NULL 11 | #define NULL ((void*)0) 12 | #endif 13 | 14 | 15 | // libc 16 | void *memmem(const void *haystack, size_t hs_len, const void *needle, size_t ne_len); 17 | void *memcpy(void *__restrict dst0, const void *__restrict src0, size_t len0); 18 | void *memset(void *m, int c, size_t n); 19 | int memcmp(const void *m1, const void *m2, size_t n); 20 | #else 21 | #include 22 | #include 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /magic/lib/memmem.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void * 6 | memmem (const void *haystack, size_t hs_len, const void *needle, size_t ne_len) 7 | { 8 | const char *hs = haystack; 9 | const char *ne = needle; 10 | 11 | if (ne_len == 0) 12 | return (void *)hs; 13 | int i; 14 | int c = ne[0]; 15 | const char *end = hs + hs_len - ne_len; 16 | 17 | for ( ; hs <= end; hs++) 18 | { 19 | if (hs[0] != c) 20 | continue; 21 | for (i = ne_len - 1; i != 0; i--) 22 | if (hs[i] != ne[i]) 23 | break; 24 | if (i == 0) 25 | return (void *)hs; 26 | } 27 | 28 | return NULL; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/lib/memmem.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void * 6 | memmem (const void *haystack, size_t hs_len, const void *needle, size_t ne_len) 7 | { 8 | const char *hs = haystack; 9 | const char *ne = needle; 10 | 11 | if (ne_len == 0) 12 | return (void *)hs; 13 | int i; 14 | int c = ne[0]; 15 | const char *end = hs + hs_len - ne_len; 16 | 17 | for ( ; hs <= end; hs++) 18 | { 19 | if (hs[0] != c) 20 | continue; 21 | for (i = ne_len - 1; i != 0; i--) 22 | if (hs[i] != ne[i]) 23 | break; 24 | if (i == 0) 25 | return (void *)hs; 26 | } 27 | 28 | return NULL; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/include/offsetfinder.h: -------------------------------------------------------------------------------- 1 | #ifndef OFFSETFINDER_H 2 | #define OFFSETFINDER_H 3 | 4 | #include 5 | #include 6 | 7 | uint64_t find_check_bootmode(uint64_t region, uint8_t* data, size_t size); 8 | uint64_t find_sigcheck(uint64_t region, uint8_t* data, size_t size); 9 | uint64_t find_boot_manifest_validation(uint64_t region, uint8_t* data, size_t size); 10 | uint64_t find_zero(uint64_t region, uint8_t* data, size_t size); 11 | uint64_t find_go_cmd_handler(uint64_t region, uint8_t* data, size_t size); 12 | uint64_t find_jumpto_bl(uint64_t region, uint8_t* data, size_t size); 13 | uint64_t find_bootx_cmd_handler(uint64_t region, uint8_t* data, size_t size); 14 | uint64_t find_mount_and_boot_system(uint64_t region, uint8_t* data, size_t size); 15 | uint64_t find_reset_cmd_handler(uint64_t region, uint8_t* data, size_t size); 16 | uint64_t find_ptr_obfuscation(uint64_t region, uint8_t* data, size_t size); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /iboot/Makefile: -------------------------------------------------------------------------------- 1 | CC = xcrun -sdk iphoneos gcc 2 | 3 | OBJCOPY = /opt/homebrew/opt/binutils/bin/gobjcopy 4 | 5 | CFLAGS = -Iinclude/ -Iinclude/drivers/ -Iapple-include/ -DDER_TAG_SIZE=8 -target arm64-apple-ios12.0 6 | CFLAGS += -Wall -Wno-incompatible-library-redeclaration -fno-stack-protector -nostdlib -static -nostdlibinc -Wl,-preload -Wl,-no_uuid 7 | CFLAGS += -Wl,-e,start -Wl,-order_file,sym_order.txt -Wl,-image_base,0x18001C000 -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x8 -O0 8 | 9 | OBJ = tramhook 10 | 11 | SOURCE = \ 12 | tramhook.c \ 13 | 14 | .PHONY: all 15 | 16 | all: 17 | cd ibootpatch2 && make 18 | gcc generate.c -o generate 19 | $(CC) entry.S $(SOURCE) $(CFLAGS) -o $(OBJ).o 20 | ../../bin/vmacho -fM 0x80000 $(OBJ).o $(OBJ).prebin 21 | ./generate $(OBJ).prebin $(OBJ).bin 22 | xxd -i $(OBJ).bin > $(OBJ).h 23 | -$(RM) $(OBJ).o 24 | -$(RM) $(OBJ).prebin 25 | 26 | clean: 27 | cd ibootpatch2 && make clean 28 | -$(RM) $(OBJ).o 29 | -$(RM) $(OBJ).prebin 30 | -$(RM) $(OBJ).bin 31 | -$(RM) $(OBJ).h 32 | -$(RM) generate 33 | 34 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/Makefile: -------------------------------------------------------------------------------- 1 | CC = xcrun -sdk iphoneos gcc 2 | 3 | OBJCOPY = /opt/homebrew/opt/binutils/bin/gobjcopy 4 | 5 | CFLAGS = -Iinclude/ -Iinclude/drivers/ -DDER_TAG_SIZE=8 -target arm64-apple-ios12.0 6 | CFLAGS += -Wall -Wno-incompatible-library-redeclaration -fno-stack-protector -nostdlib -static -nostdlibinc -Wl,-preload -Wl,-no_uuid -O0 7 | CFLAGS += -Wl,-e,start -Wl,-order_file,sym_order.txt -Wl,-image_base,0x180018000 -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x8 8 | 9 | OBJ = ibootpatch2 10 | 11 | SOURCE = \ 12 | ibootpatch2.c \ 13 | offsetfinder.c \ 14 | lib/memset.c \ 15 | lib/memmem.c \ 16 | lib/memcmp.c \ 17 | lib/memcpy.c \ 18 | 19 | .PHONY: all 20 | 21 | all: 22 | cd asm && make 23 | gcc generate.c -o generate 24 | $(CC) entry.S $(SOURCE) $(CFLAGS) -o $(OBJ).o 25 | ../../../bin/vmacho -fM 0x80000 $(OBJ).o $(OBJ).prebin 26 | ./generate $(OBJ).prebin $(OBJ).bin 27 | xxd -i $(OBJ).bin > $(OBJ).h 28 | -$(RM) $(OBJ).o 29 | -$(RM) $(OBJ).prebin 30 | 31 | clean: 32 | cd asm && make clean 33 | -$(RM) generate 34 | -$(RM) $(OBJ).o 35 | -$(RM) $(OBJ).h 36 | -$(RM) $(OBJ).bin 37 | -$(RM) $(OBJ).prebin 38 | 39 | -------------------------------------------------------------------------------- /magic/Makefile: -------------------------------------------------------------------------------- 1 | CC = xcrun -sdk iphoneos gcc 2 | 3 | OBJCOPY = /opt/homebrew/opt/binutils/bin/gobjcopy 4 | 5 | CFLAGS = -Iinclude/ -Iinclude/drivers/ -Iapple-include/ -DDER_TAG_SIZE=8 -target arm64-apple-ios12.0 6 | CFLAGS += -Wall -Wno-incompatible-library-redeclaration -fno-stack-protector -nostdlib -static -nostdlibinc -Wl,-preload -Wl,-no_uuid 7 | CFLAGS += -Wl,-e,start -Wl,-order_file,sym_order.txt -Wl,-image_base,0x100000000 -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x4000 8 | 9 | PKOKESHI_VERSION ?= 1.0.1-$(shell git rev-parse HEAD | cut -c1-8) 10 | 11 | VERSIONFLAGS = -DKOKESHI_VERSION='"$(PKOKESHI_VERSION)"' 12 | 13 | 14 | OBJ = payload 15 | 16 | SOURCE = \ 17 | payload.c \ 18 | offsetfinder.c \ 19 | lib/memmem.c \ 20 | lib/memcpy.c \ 21 | lib/memset.c \ 22 | lib/memcmp.c \ 23 | lib/strcmp.c \ 24 | lib/strchr.c \ 25 | lib/strncmp.c \ 26 | lib/strlen.c \ 27 | lib/strcat.c \ 28 | lib/strcpy.c \ 29 | lib/strstr.c \ 30 | lib/strtoull.c \ 31 | drivers/dt/dtree.c \ 32 | drivers/dt/dtree_getprop.c \ 33 | drivers/fb/fb.c \ 34 | kpf.c \ 35 | shellcode.S \ 36 | drivers/xnu/xnu.s \ 37 | printf.c \ 38 | 39 | .PHONY: all 40 | 41 | all: 42 | $(CC) entry.S $(SOURCE) $(CFLAGS) $(VERSIONFLAGS) -o $(OBJ).o 43 | ../../bin/vmacho -fM 0x80000 $(OBJ).o $(OBJ).bin 44 | mv -v $(OBJ).bin magic 45 | xxd -i magic > magic.h 46 | mv -v magic $(OBJ).bin 47 | 48 | clean: 49 | -$(RM) $(ASMSOURCE) 50 | -$(RM) $(OBJ).o 51 | -$(RM) $(OBJ).bin 52 | -$(RM) magic 53 | -$(RM) magic.h 54 | -------------------------------------------------------------------------------- /magic/apple-include/sys/_types/_os_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #if !defined(OS_INLINE) 29 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 30 | # define OS_INLINE static inline 31 | # else 32 | # define OS_INLINE static __inline__ 33 | # endif 34 | #endif /* OS_INLINE */ 35 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATE_H_ 30 | #define _MACH_MACHINE_THREAD_STATE_H_ 31 | 32 | #if defined (__arm__) || defined (__arm64__) 33 | #include "mach/arm/thread_state.h" 34 | #else 35 | #error architecture not supported 36 | #endif 37 | 38 | #endif /* _MACH_MACHINE_THREAD_STATE_H_ */ 39 | -------------------------------------------------------------------------------- /magic/apple-include/machine/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _BSD_MACHINE__TYPES_H_ 29 | #define _BSD_MACHINE__TYPES_H_ 30 | 31 | #if defined (__i386__) || defined(__x86_64__) 32 | #include "i386/_types.h" 33 | #elif defined (__arm__) || defined (__arm64__) 34 | #include "arm/_types.h" 35 | #else 36 | #error architecture not supported 37 | #endif 38 | 39 | #endif /* _BSD_MACHINE__TYPES_H_ */ 40 | -------------------------------------------------------------------------------- /iboot/generate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int openFile(char *file, size_t *sz, unsigned char **buf) { 8 | FILE *fd = fopen(file, "r"); 9 | if (!fd) { 10 | printf("error opening %s\n", file); 11 | return -1; 12 | } 13 | 14 | fseek(fd, 0, SEEK_END); 15 | *sz = ftell(fd); 16 | fseek(fd, 0, SEEK_SET); 17 | 18 | *buf = malloc(*sz); 19 | if (!*buf) { 20 | printf("error allocating file buffer\n"); 21 | fclose(fd); 22 | return -1; 23 | } 24 | 25 | fread(*buf, *sz, 1, fd); 26 | fclose(fd); 27 | 28 | return 0; 29 | } 30 | 31 | int main(int argc, char **argv) { 32 | 33 | if(argc != 3) { 34 | printf("%s \n", argv[0]); 35 | return 0; 36 | } 37 | 38 | char *inFilePath = argv[1]; 39 | char *outFilePath = argv[2]; 40 | 41 | unsigned char *fileBuf = NULL; 42 | size_t fileSize = 0; 43 | 44 | openFile(inFilePath, &fileSize, &fileBuf); 45 | assert((fileSize > 0x800) && fileBuf && (fileSize < 0x8000)); 46 | 47 | size_t outSize = fileSize - 0x800; 48 | 49 | unsigned char* outBuf = malloc(outSize); 50 | if (!outBuf) { 51 | printf("error allocating file buffer\n"); 52 | return -1; 53 | } 54 | 55 | assert(outBuf); 56 | 57 | memcpy(outBuf, fileBuf + 0x800, outSize); 58 | 59 | FILE *out = fopen(outFilePath, "w"); 60 | if (!out) { 61 | printf("error opening %s\n", outFilePath); 62 | return -1; 63 | } 64 | 65 | fwrite(outBuf, outSize, 1, out); 66 | fflush(out); 67 | fclose(out); 68 | 69 | free(fileBuf); 70 | free(outBuf); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/_structs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE__STRUCTS_H_ 30 | #define _MACH_MACHINE__STRUCTS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/_structs.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/_structs.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE__STRUCTS_H_ */ 41 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_BOOLEAN_H_ 30 | #define _MACH_MACHINE_BOOLEAN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/boolean.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/boolean.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_BOOLEAN_H_ */ 41 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_VM_TYPES_H_ 30 | #define _MACH_MACHINE_VM_TYPES_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/vm_types.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/vm_types.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_VM_TYPES_H_ */ 41 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/generate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int openFile(char *file, size_t *sz, unsigned char **buf) { 8 | FILE *fd = fopen(file, "r"); 9 | if (!fd) { 10 | printf("error opening %s\n", file); 11 | return -1; 12 | } 13 | 14 | fseek(fd, 0, SEEK_END); 15 | *sz = ftell(fd); 16 | fseek(fd, 0, SEEK_SET); 17 | 18 | *buf = malloc(*sz); 19 | if (!*buf) { 20 | printf("error allocating file buffer\n"); 21 | fclose(fd); 22 | return -1; 23 | } 24 | 25 | fread(*buf, *sz, 1, fd); 26 | fclose(fd); 27 | 28 | return 0; 29 | } 30 | 31 | int main(int argc, char **argv) { 32 | 33 | if(argc != 3) { 34 | printf("%s \n", argv[0]); 35 | return 0; 36 | } 37 | 38 | char *inFilePath = argv[1]; 39 | char *outFilePath = argv[2]; 40 | 41 | unsigned char *fileBuf = NULL; 42 | size_t fileSize = 0; 43 | 44 | openFile(inFilePath, &fileSize, &fileBuf); 45 | assert((fileSize > 0x400) && fileBuf && (fileSize < 0x4000)); 46 | 47 | size_t outSize = fileSize - 0x400; 48 | 49 | unsigned char* outBuf = malloc(outSize); 50 | if (!outBuf) { 51 | printf("error allocating file buffer\n"); 52 | return -1; 53 | } 54 | 55 | assert(outBuf); 56 | 57 | memcpy(outBuf, fileBuf + 0x400, outSize); 58 | 59 | FILE *out = fopen(outFilePath, "w"); 60 | if (!out) { 61 | printf("error opening %s\n", outFilePath); 62 | return -1; 63 | } 64 | 65 | fwrite(outBuf, outSize, 1, out); 66 | fflush(out); 67 | fclose(out); 68 | 69 | free(fileBuf); 70 | free(outBuf); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_KERN_RETURN_H_ 30 | #define _MACH_MACHINE_KERN_RETURN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/kern_return.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/kern_return.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_KERN_RETURN_H_ */ 41 | -------------------------------------------------------------------------------- /magic/apple-include/mach/machine/thread_status.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATUS_H_ 30 | #define _MACH_MACHINE_THREAD_STATUS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/thread_status.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/thread_status.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_THREAD_STATUS_H_ */ 41 | -------------------------------------------------------------------------------- /magic/entry.S: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | .globl _CHIP 29 | .globl _OVERLAY_DATA 30 | .globl _OVERLAY_SIZE 31 | 32 | .globl _enable_interrupts 33 | .globl _disable_interrupts 34 | 35 | .globl start 36 | .align 4 37 | start: 38 | 39 | // 0x0000 40 | b _payload 41 | b _jump_hook 42 | nop 43 | nop 44 | 45 | _CHIP: 46 | .quad 0x7171717171717171 47 | 48 | _OVERLAY_DATA: 49 | .quad 0x7272727272727272 50 | 51 | _OVERLAY_SIZE: 52 | .quad 0x7373737373737373 53 | 54 | nop 55 | nop 56 | nop 57 | nop 58 | 59 | _enable_interrupts: 60 | msr daifclr,#0xf 61 | isb 62 | ret 63 | _disable_interrupts: 64 | msr daifset,#0xf 65 | isb 66 | ret 67 | -------------------------------------------------------------------------------- /magic/apple-include/mach/i386/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_I386_THREAD_STATE_H_ 33 | #define _MACH_I386_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in 32-bit words */ 36 | #define I386_THREAD_STATE_MAX (614) /* Size of biggest state possible */ 37 | 38 | #if defined (__i386__) || defined(__x86_64__) 39 | #define THREAD_STATE_MAX I386_THREAD_STATE_MAX 40 | #endif 41 | 42 | #endif /* _MACH_I386_THREAD_STATE_H_ */ 43 | -------------------------------------------------------------------------------- /magic/apple-include/mach/arm/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_ARM_THREAD_STATE_H_ 33 | #define _MACH_ARM_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in words */ 36 | #define ARM_THREAD_STATE_MAX (1296) /* Size of biggest state possible */ 37 | 38 | #if defined (__arm__) || defined(__arm64__) 39 | #define THREAD_STATE_MAX ARM_THREAD_STATE_MAX 40 | #else 41 | #error Unsupported arch 42 | #endif 43 | 44 | #endif /* _MACH_ARM_THREAD_STATE_H_ */ 45 | -------------------------------------------------------------------------------- /magic/include/drivers/fb/fb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef FB_H 28 | #define FB_H 29 | 30 | #include 31 | #include 32 | 33 | #define SCALE_FACTOR scale_factor 34 | #define LEFT_MARGIN 4 * scale_factor 35 | 36 | extern char overflow_mode; 37 | extern uint32_t* gFramebuffer; 38 | extern uint32_t gWidth; 39 | extern uint32_t gHeight; 40 | extern uint32_t gRowPixels; 41 | extern uint32_t y_cursor; 42 | extern uint32_t x_cursor; 43 | extern uint8_t scale_factor; 44 | 45 | void screen_init(); 46 | void screen_puts(const char* str); 47 | void screen_write(const char* str); 48 | void screen_putc(uint8_t c); 49 | void screen_clear_row(); 50 | void screen_mark_banner(); 51 | void screen_fill_basecolor(); 52 | void screen_fill(uint32_t color); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /magic/lib/strlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---character string length 4 | INDEX 5 | strlen 6 | SYNOPSIS 7 | #include 8 | size_t strlen(const char *<[str]>); 9 | DESCRIPTION 10 | The <> function works out the length of the string 11 | starting at <<*<[str]>>> by counting chararacters until it 12 | reaches a <> character. 13 | RETURNS 14 | <> returns the character count. 15 | PORTABILITY 16 | <> is ANSI C. 17 | <> requires no supporting OS subroutines. 18 | QUICKREF 19 | strlen ansi pure 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #define LBLOCKSIZE (sizeof (long)) 26 | #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) 27 | 28 | #if LONG_MAX == 2147483647L 29 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 30 | #else 31 | #if LONG_MAX == 9223372036854775807L 32 | /* Nonzero if X (a long int) contains a NULL byte. */ 33 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 34 | #else 35 | #error long int is not a 32bit or 64bit type. 36 | #endif 37 | #endif 38 | 39 | #ifndef DETECTNULL 40 | #error long int is not a 32bit or 64bit byte 41 | #endif 42 | 43 | size_t 44 | strlen (const char *str) 45 | { 46 | const char *start = str; 47 | 48 | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) 49 | unsigned long *aligned_addr; 50 | 51 | /* Align the pointer, so we can search a word at a time. */ 52 | while (UNALIGNED (str)) 53 | { 54 | if (!*str) 55 | return str - start; 56 | str++; 57 | } 58 | 59 | /* If the string is word-aligned, we can check for the presence of 60 | a null in each word-sized block. */ 61 | aligned_addr = (unsigned long *)str; 62 | while (!DETECTNULL (*aligned_addr)) 63 | aligned_addr++; 64 | 65 | /* Once a null is detected, we check each byte in that block for a 66 | precise position of the null. */ 67 | str = (char *) aligned_addr; 68 | 69 | #endif /* not PREFER_SIZE_OVER_SPEED */ 70 | 71 | while (*str) 72 | str++; 73 | return str - start; 74 | } 75 | -------------------------------------------------------------------------------- /iboot/entry.S: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | .globl _MEMCPY_OFFSET 29 | .globl _TRAMPOLINE 30 | 31 | .globl _HEAP_BASE 32 | .globl _HEAP_WRITE_OFFSET 33 | .globl _HEAP_STATE 34 | .globl _HEAP_WRITE_HASH 35 | .globl _HEAP_CHECK_ALL 36 | .globl _DFU_BOOL 37 | .globl _BOOTSTRAP_TASK_LR 38 | .globl _NAND_BOOT_JUMP 39 | 40 | .globl start 41 | .align 4 42 | start: 43 | 44 | // 0x0000 45 | b start 46 | 47 | .org 0x800 48 | b _payload 49 | nop 50 | nop 51 | nop 52 | 53 | _MEMCPY_OFFSET: 54 | .quad 0x5151515151515151 55 | 56 | _TRAMPOLINE: 57 | .quad 0x5252525252525252 58 | 59 | _HEAP_BASE: 60 | .quad 0x5353535353535353 61 | 62 | _HEAP_WRITE_OFFSET: 63 | .quad 0x5454545454545454 64 | 65 | _HEAP_STATE: 66 | .quad 0x5555555555555555 67 | 68 | _HEAP_WRITE_HASH: 69 | .quad 0x5656565656565656 70 | 71 | _HEAP_CHECK_ALL: 72 | .quad 0x5757575757575757 73 | 74 | _DFU_BOOL: 75 | .quad 0x5858585858585858 76 | 77 | _BOOTSTRAP_TASK_LR: 78 | .quad 0x5959595959595959 79 | 80 | _NAND_BOOT_JUMP: 81 | .quad 0x5a5a5a5a5a5a5a5a 82 | 83 | nop 84 | nop 85 | nop 86 | nop 87 | -------------------------------------------------------------------------------- /magic/apple-include/sys/_types/_mach_port_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | /* 30 | * mach_port_t - a named port right 31 | * 32 | * In user-space, "rights" are represented by the name of the 33 | * right in the Mach port namespace. Even so, this type is 34 | * presented as a unique one to more clearly denote the presence 35 | * of a right coming along with the name. 36 | * 37 | * Often, various rights for a port held in a single name space 38 | * will coalesce and are, therefore, be identified by a single name 39 | * [this is the case for send and receive rights]. But not 40 | * always [send-once rights currently get a unique name for 41 | * each right]. 42 | * 43 | * This definition of mach_port_t is only for user-space. 44 | * 45 | */ 46 | 47 | #ifndef _MACH_PORT_T 48 | #define _MACH_PORT_T 49 | #include "../_types.h" /* __darwin_mach_port_t */ 50 | typedef __darwin_mach_port_t mach_port_t; 51 | #endif /* _MACH_PORT_T */ 52 | -------------------------------------------------------------------------------- /magic/apple-include/sys/appleapiopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef __SYS_APPLEAPIOPTS_H__ 30 | #define __SYS_APPLEAPIOPTS_H__ 31 | 32 | 33 | #ifndef __APPLE_API_STANDARD 34 | #define __APPLE_API_STANDARD 35 | #endif /* __APPLE_API_STANDARD */ 36 | 37 | #ifndef __APPLE_API_STABLE 38 | #define __APPLE_API_STABLE 39 | #endif /* __APPLE_API_STABLE */ 40 | 41 | #ifndef __APPLE_API_STRICT_CONFORMANCE 42 | 43 | #ifndef __APPLE_API_EVOLVING 44 | #define __APPLE_API_EVOLVING 45 | #endif /* __APPLE_API_EVOLVING */ 46 | 47 | #ifndef __APPLE_API_UNSTABLE 48 | #define __APPLE_API_UNSTABLE 49 | #endif /* __APPLE_API_UNSTABLE */ 50 | 51 | #ifndef __APPLE_API_PRIVATE 52 | #define __APPLE_API_PRIVATE 53 | #endif /* __APPLE_API_PRIVATE */ 54 | 55 | #ifndef __APPLE_API_OBSOLETE 56 | #define __APPLE_API_OBSOLETE 57 | #endif /* __APPLE_API_OBSOLETE */ 58 | 59 | #endif /* __APPLE_API_STRICT_CONFORMANCE */ 60 | 61 | #endif /* __SYS_APPLEAPIOPTS_H__ */ 62 | -------------------------------------------------------------------------------- /magic/lib/strcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---copy string 4 | INDEX 5 | strcpy 6 | SYNOPSIS 7 | #include 8 | char *strcpy(char *<[dst]>, const char *<[src]>); 9 | DESCRIPTION 10 | <> copies the string pointed to by <[src]> 11 | (including the terminating null character) to the array 12 | pointed to by <[dst]>. 13 | RETURNS 14 | This function returns the initial value of <[dst]>. 15 | PORTABILITY 16 | <> is ANSI C. 17 | <> requires no supporting OS subroutines. 18 | QUICKREF 19 | strcpy ansi pure 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | /*SUPPRESS 560*/ 26 | /*SUPPRESS 530*/ 27 | 28 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 29 | #define UNALIGNED(X, Y) \ 30 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 31 | 32 | #if LONG_MAX == 2147483647L 33 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 34 | #else 35 | #if LONG_MAX == 9223372036854775807L 36 | /* Nonzero if X (a long int) contains a NULL byte. */ 37 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 38 | #else 39 | #error long int is not a 32bit or 64bit type. 40 | #endif 41 | #endif 42 | 43 | #ifndef DETECTNULL 44 | #error long int is not a 32bit or 64bit byte 45 | #endif 46 | 47 | char* 48 | strcpy (char *dst0, 49 | const char *src0) 50 | { 51 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 52 | char *s = dst0; 53 | 54 | while (*dst0++ = *src0++) 55 | ; 56 | 57 | return s; 58 | #else 59 | char *dst = dst0; 60 | const char *src = src0; 61 | long *aligned_dst; 62 | const long *aligned_src; 63 | 64 | /* If SRC or DEST is unaligned, then copy bytes. */ 65 | if (!UNALIGNED (src, dst)) 66 | { 67 | aligned_dst = (long*)dst; 68 | aligned_src = (long*)src; 69 | 70 | /* SRC and DEST are both "long int" aligned, try to do "long int" 71 | sized copies. */ 72 | while (!DETECTNULL(*aligned_src)) 73 | { 74 | *aligned_dst++ = *aligned_src++; 75 | } 76 | 77 | dst = (char*)aligned_dst; 78 | src = (char*)aligned_src; 79 | } 80 | 81 | while ((*dst++ = *src++)) 82 | ; 83 | return dst0; 84 | #endif /* not PREFER_SIZE_OVER_SPEED */ 85 | } 86 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/asm/shellcode.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .pool 4 | 5 | .set RELOCATED, 0xdeafbeefdeaf0001 // 0x800E00000 6 | .set LOAD_ADDRESS, 0xdeafbeefdeaf0002 // 0x801000000 7 | .set SDRAM_PAGE, 0xdeafbeefdeaf0003 // 0x180002000 8 | .set OVERLAY, 0xdeafbeefdeaf0004 // 0x800F00000 9 | 10 | .set ARM_TTE_BLOCK_PNX, 0x0020000000000000 11 | .set ARM_TTE_BLOCK_NX, 0x0040000000000000 12 | 13 | .global _main 14 | _main: 15 | B _real_main 16 | B _tram 17 | B _relocate_overlay 18 | NOP 19 | 20 | _real_main: 21 | LDR X1, =RELOCATED 22 | LDR X0, =LOAD_ADDRESS 23 | MOV X2, #0 24 | MOV X3, #0x80000 25 | 26 | loop: 27 | LDP X4, X5, [X0] 28 | STP X4, X5, [X1] 29 | ADD X0, X0, #0x10 30 | ADD X1, X1, #0x10 31 | ADD X2, X2, #0x10 32 | CMP X2, X3 33 | B.CC loop 34 | B _dorwx 35 | RET 36 | 37 | _dorwx: 38 | MOV X5, X30 39 | LDR X0, =0x800000000 40 | BL _cache_clean_and_invalidate_page 41 | MOV X0, #0 42 | SVC #0 43 | IC IALLU 44 | 45 | MRS X4, SCTLR_EL1 46 | MOV X0, #0 47 | MSR SCTLR_EL1, x0 48 | 49 | LDR X0, =SDRAM_PAGE 50 | LDR X0, [X0] 51 | BIC X0, X0, (ARM_TTE_BLOCK_PNX | ARM_TTE_BLOCK_NX) 52 | LDR X1, =SDRAM_PAGE 53 | STR X0, [X1] 54 | 55 | MOV X0, X4 56 | BIC X0, X0, #0x80000 57 | MSR SCTLR_EL1, X0 58 | 59 | DSB SY 60 | TLBI VMALLE1 61 | DSB SY 62 | ISB 63 | 64 | MRS X0, SPSR_EL1 65 | AND X0, X0, #0xFFFFFFFFFFFFFFF3 66 | MSR SPSR_EL1, X0 67 | MOV X0, X5 68 | MSR ELR_EL1, X0 69 | ERET 70 | 71 | _cache_clean_and_invalidate_page: 72 | MOV X1, #0x80000 73 | MOV X2, #0 74 | 75 | _one: 76 | CMP X1, X2 77 | B.EQ _two 78 | DC CIVAC, X0 79 | ADD X0, X0, #0x40 80 | ADD X2, X2, #0x40 81 | B _one 82 | 83 | _two: 84 | RET 85 | 86 | _relocate_overlay: 87 | LDR X1, =OVERLAY 88 | LDR X0, =LOAD_ADDRESS 89 | MOV X2, #0 90 | MOV X3, #0x80000 91 | copy_loop: 92 | LDP X4, X5, [X0] 93 | STP X4, X5, [X1] 94 | ADD X0, X0, #0x10 95 | ADD X1, X1, #0x10 96 | ADD X2, X2, #0x10 97 | CMP X2, X3 98 | B.CC copy_loop 99 | MOV X0, #0 100 | RET 101 | 102 | _tram: 103 | LDR X16, =RELOCATED 104 | ADD X16, X16, #4 105 | BR X16 106 | -------------------------------------------------------------------------------- /magic/lib/memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---set an area of memory 4 | INDEX 5 | memset 6 | SYNOPSIS 7 | #include 8 | void *memset(void *<[dst]>, int <[c]>, size_t <[length]>); 9 | DESCRIPTION 10 | This function converts the argument <[c]> into an unsigned 11 | char and fills the first <[length]> characters of the array 12 | pointed to by <[dst]> to the value. 13 | RETURNS 14 | <> returns the value of <[dst]>. 15 | PORTABILITY 16 | <> is ANSI C. 17 | <> requires no supporting OS subroutines. 18 | QUICKREF 19 | memset ansi pure 20 | */ 21 | 22 | #include 23 | 24 | #define LBLOCKSIZE (sizeof(long)) 25 | #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) 26 | #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) 27 | 28 | void * 29 | memset (void *m, 30 | int c, 31 | size_t n) 32 | { 33 | char *s = (char *) m; 34 | 35 | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) 36 | unsigned int i; 37 | unsigned long buffer; 38 | unsigned long *aligned_addr; 39 | unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an 40 | unsigned variable. */ 41 | 42 | while (UNALIGNED (s)) 43 | { 44 | if (n--) 45 | *s++ = (char) c; 46 | else 47 | return m; 48 | } 49 | 50 | if (!TOO_SMALL (n)) 51 | { 52 | /* If we get this far, we know that n is large and s is word-aligned. */ 53 | aligned_addr = (unsigned long *) s; 54 | 55 | /* Store D into each char sized location in BUFFER so that 56 | we can set large blocks quickly. */ 57 | buffer = (d << 8) | d; 58 | buffer |= (buffer << 16); 59 | for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) 60 | buffer = (buffer << i) | buffer; 61 | 62 | /* Unroll the loop. */ 63 | while (n >= LBLOCKSIZE*4) 64 | { 65 | *aligned_addr++ = buffer; 66 | *aligned_addr++ = buffer; 67 | *aligned_addr++ = buffer; 68 | *aligned_addr++ = buffer; 69 | n -= 4*LBLOCKSIZE; 70 | } 71 | 72 | while (n >= LBLOCKSIZE) 73 | { 74 | *aligned_addr++ = buffer; 75 | n -= LBLOCKSIZE; 76 | } 77 | /* Pick up the remainder with a bytewise loop. */ 78 | s = (char*)aligned_addr; 79 | } 80 | 81 | #endif /* not PREFER_SIZE_OVER_SPEED */ 82 | 83 | while (n--) 84 | *s++ = (char) c; 85 | 86 | return m; 87 | } 88 | -------------------------------------------------------------------------------- /magic/lib/strcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---concatenate strings 4 | INDEX 5 | strcat 6 | SYNOPSIS 7 | #include 8 | char *strcat(char *restrict <[dst]>, const char *restrict <[src]>); 9 | DESCRIPTION 10 | <> appends a copy of the string pointed to by <[src]> 11 | (including the terminating null character) to the end of the 12 | string pointed to by <[dst]>. The initial character of 13 | <[src]> overwrites the null character at the end of <[dst]>. 14 | RETURNS 15 | This function returns the initial value of <[dst]> 16 | PORTABILITY 17 | <> is ANSI C. 18 | <> requires no supporting OS subroutines. 19 | QUICKREF 20 | strcat ansi pure 21 | */ 22 | 23 | #include 24 | 25 | /* Nonzero if X is aligned on a "long" boundary. */ 26 | #define ALIGNED(X) \ 27 | (((long)X & (sizeof (long) - 1)) == 0) 28 | 29 | #if LONG_MAX == 2147483647L 30 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 31 | #else 32 | #if 1 //LONG_MAX == 9223372036854775807L 33 | /* Nonzero if X (a long int) contains a NULL byte. */ 34 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 35 | #else 36 | #error long int is not a 32bit or 64bit type. 37 | #endif 38 | #endif 39 | 40 | #ifndef DETECTNULL 41 | #error long int is not a 32bit or 64bit byte 42 | #endif 43 | 44 | 45 | /*SUPPRESS 560*/ 46 | /*SUPPRESS 530*/ 47 | 48 | char * 49 | strcat (char *__restrict s1, 50 | const char *__restrict s2) 51 | { 52 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 53 | char *s = s1; 54 | 55 | while (*s1) 56 | s1++; 57 | 58 | while (*s1++ = *s2++) 59 | ; 60 | return s; 61 | #else 62 | char *s = s1; 63 | 64 | 65 | /* Skip over the data in s1 as quickly as possible. */ 66 | if (ALIGNED (s1)) 67 | { 68 | unsigned long *aligned_s1 = (unsigned long *)s1; 69 | while (!DETECTNULL (*aligned_s1)) 70 | aligned_s1++; 71 | 72 | s1 = (char *)aligned_s1; 73 | } 74 | 75 | while (*s1) 76 | s1++; 77 | 78 | /* s1 now points to the its trailing null character, we can 79 | just use strcpy to do the work for us now. 80 | ?!? We might want to just include strcpy here. 81 | Also, this will cause many more unaligned string copies because 82 | s1 is much less likely to be aligned. I don't know if its worth 83 | tweaking strcpy to handle this better. */ 84 | strcpy (s1, s2); 85 | 86 | return s; 87 | #endif /* not PREFER_SIZE_OVER_SPEED */ 88 | } 89 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/lib/memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---set an area of memory 4 | INDEX 5 | memset 6 | SYNOPSIS 7 | #include 8 | void *memset(void *<[dst]>, int <[c]>, size_t <[length]>); 9 | DESCRIPTION 10 | This function converts the argument <[c]> into an unsigned 11 | char and fills the first <[length]> characters of the array 12 | pointed to by <[dst]> to the value. 13 | RETURNS 14 | <> returns the value of <[dst]>. 15 | PORTABILITY 16 | <> is ANSI C. 17 | <> requires no supporting OS subroutines. 18 | QUICKREF 19 | memset ansi pure 20 | */ 21 | 22 | #include 23 | 24 | #define LBLOCKSIZE (sizeof(long)) 25 | #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) 26 | #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) 27 | 28 | void * 29 | memset (void *m, 30 | int c, 31 | size_t n) 32 | { 33 | char *s = (char *) m; 34 | 35 | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) 36 | unsigned int i; 37 | unsigned long buffer; 38 | unsigned long *aligned_addr; 39 | unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an 40 | unsigned variable. */ 41 | 42 | while (UNALIGNED (s)) 43 | { 44 | if (n--) 45 | *s++ = (char) c; 46 | else 47 | return m; 48 | } 49 | 50 | if (!TOO_SMALL (n)) 51 | { 52 | /* If we get this far, we know that n is large and s is word-aligned. */ 53 | aligned_addr = (unsigned long *) s; 54 | 55 | /* Store D into each char sized location in BUFFER so that 56 | we can set large blocks quickly. */ 57 | buffer = (d << 8) | d; 58 | buffer |= (buffer << 16); 59 | for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) 60 | buffer = (buffer << i) | buffer; 61 | 62 | /* Unroll the loop. */ 63 | while (n >= LBLOCKSIZE*4) 64 | { 65 | *aligned_addr++ = buffer; 66 | *aligned_addr++ = buffer; 67 | *aligned_addr++ = buffer; 68 | *aligned_addr++ = buffer; 69 | n -= 4*LBLOCKSIZE; 70 | } 71 | 72 | while (n >= LBLOCKSIZE) 73 | { 74 | *aligned_addr++ = buffer; 75 | n -= LBLOCKSIZE; 76 | } 77 | /* Pick up the remainder with a bytewise loop. */ 78 | s = (char*)aligned_addr; 79 | } 80 | 81 | #endif /* not PREFER_SIZE_OVER_SPEED */ 82 | 83 | while (n--) 84 | *s++ = (char) c; 85 | 86 | return m; 87 | } 88 | -------------------------------------------------------------------------------- /magic/lib/strtoull.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #ifndef ULLONG_MAX 5 | #define ULLONG_MAX (~(unsigned long long)0) /* 0xFFFFFFFFFFFFFFFF */ 6 | #endif 7 | 8 | #ifndef LLONG_MAX 9 | #define LLONG_MAX ((unsigned long long)(ULLONG_MAX >> 1)) /* 0x7FFFFFFFFFFFFFFF */ 10 | #endif 11 | 12 | #ifndef LLONG_MIN 13 | #define LLONG_MIN (~LLONG_MAX) /* 0x8000000000000000 */ 14 | #endif 15 | 16 | int 17 | isspace(c) 18 | int c; 19 | { 20 | return (c == '\t' || c == '\n' || 21 | c == '\v' || c == '\f' || c == '\r' || c == ' ' ? 1 : 0); 22 | } 23 | 24 | static void fake(void) 25 | { 26 | 27 | } 28 | 29 | unsigned long long 30 | strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) 31 | { 32 | const char *s; 33 | unsigned long long acc; 34 | char c; 35 | unsigned long long cutoff; 36 | int neg, any, cutlim; 37 | 38 | /* 39 | * See strtoq for comments as to the logic used. 40 | */ 41 | s = nptr; 42 | do { 43 | c = *s++; 44 | } while (isspace((unsigned char)c)); 45 | if (c == '-') { 46 | neg = 1; 47 | c = *s++; 48 | } else { 49 | neg = 0; 50 | if (c == '+') 51 | c = *s++; 52 | } 53 | if ((base == 0 || base == 16) && 54 | c == '0' && (*s == 'x' || *s == 'X')) { 55 | c = s[1]; 56 | s += 2; 57 | base = 16; 58 | } 59 | if (base == 0) 60 | base = c == '0' ? 8 : 10; 61 | acc = any = 0; 62 | if (base < 2 || base > 36) 63 | goto noconv; 64 | 65 | cutoff = ULLONG_MAX / base; 66 | cutlim = ULLONG_MAX % base; 67 | for ( ; ; c = *s++) { 68 | if (c >= '0' && c <= '9') 69 | c -= '0'; 70 | else if (c >= 'A' && c <= 'Z') 71 | c -= 'A' - 10; 72 | else if (c >= 'a' && c <= 'z') 73 | c -= 'a' - 10; 74 | else 75 | break; 76 | if (c >= base) 77 | break; 78 | if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 79 | any = -1; 80 | else { 81 | any = 1; 82 | acc *= base; 83 | acc += c; 84 | } 85 | } 86 | if (any < 0) { 87 | acc = ULLONG_MAX; 88 | //errno = ERANGE; 89 | } else if (!any) { 90 | noconv: 91 | fake(); 92 | //errno = EINVAL; 93 | } else if (neg) 94 | acc = -acc; 95 | 96 | if (endptr != NULL) 97 | *endptr = (char *)(any ? s - 1 : nptr); 98 | 99 | return (acc); 100 | } 101 | -------------------------------------------------------------------------------- /magic/apple-include/arm/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _ARM_ARCH_H 29 | #define _ARM_ARCH_H 30 | 31 | /* Collect the __ARM_ARCH_*__ compiler flags into something easier to use. */ 32 | #if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) 33 | #define _ARM_ARCH_7 34 | #endif 35 | 36 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__) 37 | #define _ARM_ARCH_6K 38 | #endif 39 | 40 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__) 41 | #define _ARM_ARCH_6Z 42 | #endif 43 | 44 | #if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__) || \ 45 | defined (_ARM_ARCH_6Z) || defined (_ARM_ARCH_6K) 46 | #define _ARM_ARCH_6 47 | #endif 48 | 49 | #if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5E__) || \ 50 | defined (__ARM_ARCH_5TE__) || defined (__ARM_ARCH_5TEJ__) 51 | #define _ARM_ARCH_5E 52 | #endif 53 | 54 | #if defined (_ARM_ARCH_5E) || defined (__ARM_ARCH_5__) || \ 55 | defined (__ARM_ARCH_5T__) 56 | #define _ARM_ARCH_5 57 | #endif 58 | 59 | #if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__) 60 | #define _ARM_ARCH_4T 61 | #endif 62 | 63 | #if defined (_ARM_ARCH_4T) || defined (__ARM_ARCH_4__) 64 | #define _ARM_ARCH_4 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /iboot/tramhook.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "ibootpatch2/ibootpatch2.h" 6 | 7 | extern uint64_t MEMCPY_OFFSET; 8 | extern uint64_t TRAMPOLINE; 9 | 10 | extern uint64_t HEAP_BASE; 11 | extern uint64_t HEAP_WRITE_OFFSET; 12 | extern uint64_t HEAP_STATE; 13 | extern uint64_t HEAP_WRITE_HASH; 14 | extern uint64_t HEAP_CHECK_ALL; 15 | extern uint64_t DFU_BOOL; 16 | extern uint64_t BOOTSTRAP_TASK_LR; 17 | extern uint64_t NAND_BOOT_JUMP; 18 | 19 | int payload(uint64_t arg0) 20 | { 21 | 22 | my_memcpy = (memcpy_t)MEMCPY_OFFSET; 23 | 24 | heapWriteHash = (write_t)HEAP_WRITE_HASH; 25 | heapCheckAll = (check_t)HEAP_CHECK_ALL; 26 | 27 | uint64_t block1[8]; 28 | uint64_t block2[8]; 29 | 30 | block1[0] = 0; 31 | block1[1] = 0; 32 | block1[2] = 0; 33 | block1[3] = HEAP_STATE; 34 | block1[4] = 2; 35 | block1[5] = 132; 36 | block1[6] = 128; 37 | block1[7] = 0; 38 | 39 | block2[0] = 0; 40 | block2[1] = 0; 41 | block2[2] = 0; 42 | block2[3] = HEAP_STATE; 43 | block2[4] = 2; 44 | block2[5] = 8; 45 | block2[6] = 128; 46 | block2[7] = 0; 47 | 48 | if(HEAP_WRITE_HASH != 0) 49 | { 50 | my_memcpy((void*)(HEAP_BASE + HEAP_WRITE_OFFSET ), (void*)block1, sizeof(block1)); 51 | my_memcpy((void*)(HEAP_BASE + HEAP_WRITE_OFFSET + 0x80), (void*)block2, sizeof(block2)); 52 | my_memcpy((void*)(HEAP_BASE + HEAP_WRITE_OFFSET + 0x100), (void*)block2, sizeof(block2)); 53 | my_memcpy((void*)(HEAP_BASE + HEAP_WRITE_OFFSET + 0x180), (void*)block2, sizeof(block2)); 54 | heapWriteHash(HEAP_BASE + HEAP_WRITE_OFFSET ); 55 | heapWriteHash(HEAP_BASE + HEAP_WRITE_OFFSET + 0x80); 56 | heapWriteHash(HEAP_BASE + HEAP_WRITE_OFFSET + 0x100); 57 | heapWriteHash(HEAP_BASE + HEAP_WRITE_OFFSET + 0x180); 58 | heapCheckAll(0); 59 | // Heap repaired 60 | } 61 | 62 | if(TRAMPOLINE != 0) 63 | { 64 | uint32_t* insn = (uint32_t*)TRAMPOLINE; 65 | insn[0] = 0x14000100; 66 | } 67 | 68 | if(BOOTSTRAP_TASK_LR != 0) 69 | { 70 | uint64_t* boottask_lr = (uint64_t*)BOOTSTRAP_TASK_LR; 71 | boottask_lr[0] = NAND_BOOT_JUMP; 72 | } 73 | 74 | if(TRAMPOLINE != 0) 75 | { 76 | my_memcpy((void*)(TRAMPOLINE + 0x400), ibootpatch2_bin, ibootpatch2_bin_len); 77 | } 78 | 79 | if(DFU_BOOL != 0) 80 | { 81 | uint8_t* dfuboot = (uint8_t*)DFU_BOOL; 82 | dfuboot[0] = 1; 83 | } 84 | 85 | return 0; 86 | } 87 | 88 | int main(void) 89 | { 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /magic/lib/strcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---character string compare 4 | 5 | INDEX 6 | strcmp 7 | SYNOPSIS 8 | #include 9 | int strcmp(const char *<[a]>, const char *<[b]>); 10 | DESCRIPTION 11 | <> compares the string at <[a]> to 12 | the string at <[b]>. 13 | RETURNS 14 | If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, 15 | <> returns a number greater than zero. If the two 16 | strings match, <> returns zero. If <<*<[a]>>> 17 | sorts lexicographically before <<*<[b]>>>, <> returns a 18 | number less than zero. 19 | PORTABILITY 20 | <> is ANSI C. 21 | <> requires no supporting OS subroutines. 22 | QUICKREF 23 | strcmp ansi pure 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 30 | #define UNALIGNED(X, Y) \ 31 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 32 | 33 | /* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ 34 | #if LONG_MAX == 2147483647L 35 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 36 | #else 37 | #if LONG_MAX == 9223372036854775807L 38 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 39 | #else 40 | #error long int is not a 32bit or 64bit type. 41 | #endif 42 | #endif 43 | 44 | #ifndef DETECTNULL 45 | #error long int is not a 32bit or 64bit byte 46 | #endif 47 | 48 | int 49 | strcmp (const char *s1, 50 | const char *s2) 51 | { 52 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 53 | while (*s1 != '\0' && *s1 == *s2) 54 | { 55 | s1++; 56 | s2++; 57 | } 58 | 59 | return (*(unsigned char *) s1) - (*(unsigned char *) s2); 60 | #else 61 | unsigned long *a1; 62 | unsigned long *a2; 63 | 64 | /* If s1 or s2 are unaligned, then compare bytes. */ 65 | if (!UNALIGNED (s1, s2)) 66 | { 67 | /* If s1 and s2 are word-aligned, compare them a word at a time. */ 68 | a1 = (unsigned long*)s1; 69 | a2 = (unsigned long*)s2; 70 | while (*a1 == *a2) 71 | { 72 | /* To get here, *a1 == *a2, thus if we find a null in *a1, 73 | then the strings must be equal, so return zero. */ 74 | if (DETECTNULL (*a1)) 75 | return 0; 76 | 77 | a1++; 78 | a2++; 79 | } 80 | 81 | /* A difference was detected in last few bytes of s1, so search bytewise */ 82 | s1 = (char*)a1; 83 | s2 = (char*)a2; 84 | } 85 | 86 | while (*s1 != '\0' && *s1 == *s2) 87 | { 88 | s1++; 89 | s2++; 90 | } 91 | return (*(unsigned char *) s1) - (*(unsigned char *) s2); 92 | #endif /* not PREFER_SIZE_OVER_SPEED */ 93 | } 94 | -------------------------------------------------------------------------------- /magic/lib/memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---compare two memory areas 4 | INDEX 5 | memcmp 6 | SYNOPSIS 7 | #include 8 | int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); 9 | DESCRIPTION 10 | This function compares not more than <[n]> characters of the 11 | object pointed to by <[s1]> with the object pointed to by <[s2]>. 12 | RETURNS 13 | The function returns an integer greater than, equal to or 14 | less than zero according to whether the object pointed to by 15 | <[s1]> is greater than, equal to or less than the object 16 | pointed to by <[s2]>. 17 | PORTABILITY 18 | <> is ANSI C. 19 | <> requires no supporting OS subroutines. 20 | QUICKREF 21 | memcmp ansi pure 22 | */ 23 | 24 | #include 25 | 26 | 27 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 28 | #define UNALIGNED(X, Y) \ 29 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 30 | 31 | /* How many bytes are copied each iteration of the word copy loop. */ 32 | #define LBLOCKSIZE (sizeof (long)) 33 | 34 | /* Threshhold for punting to the byte copier. */ 35 | #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) 36 | 37 | int 38 | memcmp (const void *m1, 39 | const void *m2, 40 | size_t n) 41 | { 42 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 43 | unsigned char *s1 = (unsigned char *) m1; 44 | unsigned char *s2 = (unsigned char *) m2; 45 | 46 | while (n--) 47 | { 48 | if (*s1 != *s2) 49 | { 50 | return *s1 - *s2; 51 | } 52 | s1++; 53 | s2++; 54 | } 55 | return 0; 56 | #else 57 | unsigned char *s1 = (unsigned char *) m1; 58 | unsigned char *s2 = (unsigned char *) m2; 59 | unsigned long *a1; 60 | unsigned long *a2; 61 | 62 | /* If the size is too small, or either pointer is unaligned, 63 | then we punt to the byte compare loop. Hopefully this will 64 | not turn up in inner loops. */ 65 | if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) 66 | { 67 | /* Otherwise, load and compare the blocks of memory one 68 | word at a time. */ 69 | a1 = (unsigned long*) s1; 70 | a2 = (unsigned long*) s2; 71 | while (n >= LBLOCKSIZE) 72 | { 73 | if (*a1 != *a2) 74 | break; 75 | a1++; 76 | a2++; 77 | n -= LBLOCKSIZE; 78 | } 79 | 80 | /* check m mod LBLOCKSIZE remaining characters */ 81 | 82 | s1 = (unsigned char*)a1; 83 | s2 = (unsigned char*)a2; 84 | } 85 | 86 | while (n--) 87 | { 88 | if (*s1 != *s2) 89 | return *s1 - *s2; 90 | s1++; 91 | s2++; 92 | } 93 | 94 | return 0; 95 | #endif /* not PREFER_SIZE_OVER_SPEED */ 96 | } 97 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/lib/memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---compare two memory areas 4 | INDEX 5 | memcmp 6 | SYNOPSIS 7 | #include 8 | int memcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>); 9 | DESCRIPTION 10 | This function compares not more than <[n]> characters of the 11 | object pointed to by <[s1]> with the object pointed to by <[s2]>. 12 | RETURNS 13 | The function returns an integer greater than, equal to or 14 | less than zero according to whether the object pointed to by 15 | <[s1]> is greater than, equal to or less than the object 16 | pointed to by <[s2]>. 17 | PORTABILITY 18 | <> is ANSI C. 19 | <> requires no supporting OS subroutines. 20 | QUICKREF 21 | memcmp ansi pure 22 | */ 23 | 24 | #include 25 | 26 | 27 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 28 | #define UNALIGNED(X, Y) \ 29 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 30 | 31 | /* How many bytes are copied each iteration of the word copy loop. */ 32 | #define LBLOCKSIZE (sizeof (long)) 33 | 34 | /* Threshhold for punting to the byte copier. */ 35 | #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) 36 | 37 | int 38 | memcmp (const void *m1, 39 | const void *m2, 40 | size_t n) 41 | { 42 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 43 | unsigned char *s1 = (unsigned char *) m1; 44 | unsigned char *s2 = (unsigned char *) m2; 45 | 46 | while (n--) 47 | { 48 | if (*s1 != *s2) 49 | { 50 | return *s1 - *s2; 51 | } 52 | s1++; 53 | s2++; 54 | } 55 | return 0; 56 | #else 57 | unsigned char *s1 = (unsigned char *) m1; 58 | unsigned char *s2 = (unsigned char *) m2; 59 | unsigned long *a1; 60 | unsigned long *a2; 61 | 62 | /* If the size is too small, or either pointer is unaligned, 63 | then we punt to the byte compare loop. Hopefully this will 64 | not turn up in inner loops. */ 65 | if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) 66 | { 67 | /* Otherwise, load and compare the blocks of memory one 68 | word at a time. */ 69 | a1 = (unsigned long*) s1; 70 | a2 = (unsigned long*) s2; 71 | while (n >= LBLOCKSIZE) 72 | { 73 | if (*a1 != *a2) 74 | break; 75 | a1++; 76 | a2++; 77 | n -= LBLOCKSIZE; 78 | } 79 | 80 | /* check m mod LBLOCKSIZE remaining characters */ 81 | 82 | s1 = (unsigned char*)a1; 83 | s2 = (unsigned char*)a2; 84 | } 85 | 86 | while (n--) 87 | { 88 | if (*s1 != *s2) 89 | return *s1 - *s2; 90 | s1++; 91 | s2++; 92 | } 93 | 94 | return 0; 95 | #endif /* not PREFER_SIZE_OVER_SPEED */ 96 | } 97 | -------------------------------------------------------------------------------- /magic/apple-include/mach/arm/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for ARM. 63 | */ 64 | 65 | #ifndef _MACH_ARM_BOOLEAN_H_ 66 | #define _MACH_ARM_BOOLEAN_H_ 67 | 68 | typedef int boolean_t; 69 | 70 | #endif /* _MACH_ARM_BOOLEAN_H_ */ 71 | -------------------------------------------------------------------------------- /magic/lib/strstr.c: -------------------------------------------------------------------------------- 1 | /* Optimized strstr function. 2 | Copyright (c) 2018 Arm Ltd. All rights reserved. 3 | SPDX-License-Identifier: BSD-3-Clause 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. The name of the company may not be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 20 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 25 | 26 | /* 27 | FUNCTION 28 | <>---find string segment 29 | INDEX 30 | strstr 31 | SYNOPSIS 32 | #include 33 | char *strstr(const char *<[s1]>, const char *<[s2]>); 34 | DESCRIPTION 35 | Locates the first occurrence in the string pointed to by <[s1]> of 36 | the sequence of characters in the string pointed to by <[s2]> 37 | (excluding the terminating null character). 38 | RETURNS 39 | Returns a pointer to the located string segment, or a null 40 | pointer if the string <[s2]> is not found. If <[s2]> points to 41 | a string with zero length, <[s1]> is returned. 42 | PORTABILITY 43 | <> is ANSI C. 44 | <> requires no supporting OS subroutines. 45 | QUICKREF 46 | strstr ansi pure 47 | */ 48 | 49 | #include 50 | #include 51 | 52 | /* Small and efficient strstr implementation. */ 53 | char * 54 | strstr (const char *hs, const char *ne) 55 | { 56 | size_t i; 57 | int c = ne[0]; 58 | 59 | if (c == 0) 60 | return (char*)hs; 61 | 62 | for ( ; hs[0] != '\0'; hs++) 63 | { 64 | if (hs[0] != c) 65 | continue; 66 | for (i = 1; ne[i] != 0; i++) 67 | if (hs[i] != ne[i]) 68 | break; 69 | if (ne[i] == '\0') 70 | return (char*)hs; 71 | } 72 | 73 | return NULL; 74 | } 75 | -------------------------------------------------------------------------------- /magic/drivers/dt/dtree_getprop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | uint32_t dt_get_u32_prop(const char* device, const char* prop) { 30 | uint32_t rval = 0; 31 | uint32_t len = 0; 32 | dt_node_t* dev = dt_find(gDeviceTree, device); 33 | if (!dev) panic("invalid devicetree: no device!"); 34 | uint32_t* val = dt_prop(dev, prop, &len); 35 | if (!val) panic("invalid devicetree: no prop!"); 36 | memcpy(&rval, &val[0], 4); 37 | return rval; 38 | } 39 | uint64_t dt_get_u64_prop(const char* device, const char* prop) { 40 | uint64_t rval = 0; 41 | uint32_t len = 0; 42 | dt_node_t* dev = dt_find(gDeviceTree, device); 43 | if (!dev) panic("invalid devicetree: no device!"); 44 | uint64_t* val = dt_prop(dev, prop, &len); 45 | if (!val) panic("invalid devicetree: no prop!"); 46 | memcpy(&rval, &val[0], 8); 47 | return rval; 48 | } 49 | uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx) { 50 | uint64_t rval = 0; 51 | uint32_t len = 0; 52 | dt_node_t* dev = dt_find(gDeviceTree, device); 53 | if (!dev) panic("invalid devicetree: no device!"); 54 | uint64_t* val = dt_prop(dev, prop, &len); 55 | if (!val) panic("invalid devicetree: no prop!"); 56 | memcpy(&rval, &val[idx], 8); 57 | return rval; 58 | } 59 | void* dt_get_prop(const char* device, const char* prop, uint32_t* size) { 60 | uint32_t len = 0; 61 | dt_node_t* dev = dt_find(gDeviceTree, device); 62 | if (!dev) panic("invalid devicetree: no device!"); 63 | void* val = dt_prop(dev, prop, &len); 64 | if (!val) panic("invalid devicetree: no prop!"); 65 | if (size) *size = len; 66 | return val; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /magic/lib/memcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---copy memory regions 4 | SYNOPSIS 5 | #include 6 | void* memcpy(void *restrict <[out]>, const void *restrict <[in]>, 7 | size_t <[n]>); 8 | DESCRIPTION 9 | This function copies <[n]> bytes from the memory region 10 | pointed to by <[in]> to the memory region pointed to by 11 | <[out]>. 12 | If the regions overlap, the behavior is undefined. 13 | RETURNS 14 | <> returns a pointer to the first byte of the <[out]> 15 | region. 16 | PORTABILITY 17 | <> is ANSI C. 18 | <> requires no supporting OS subroutines. 19 | QUICKREF 20 | memcpy ansi pure 21 | */ 22 | 23 | #include 24 | 25 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 26 | #define UNALIGNED(X, Y) \ 27 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 28 | 29 | /* How many bytes are copied each iteration of the 4X unrolled loop. */ 30 | #define BIGBLOCKSIZE (sizeof (long) << 2) 31 | 32 | /* How many bytes are copied each iteration of the word copy loop. */ 33 | #define LITTLEBLOCKSIZE (sizeof (long)) 34 | 35 | /* Threshhold for punting to the byte copier. */ 36 | #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) 37 | 38 | void * 39 | memcpy (void *__restrict dst0, 40 | const void *__restrict src0, 41 | size_t len0) 42 | { 43 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 44 | char *dst = (char *) dst0; 45 | char *src = (char *) src0; 46 | 47 | void *save = dst0; 48 | 49 | while (len0--) 50 | { 51 | *dst++ = *src++; 52 | } 53 | 54 | return save; 55 | #else 56 | char *dst = dst0; 57 | const char *src = src0; 58 | long *aligned_dst; 59 | const long *aligned_src; 60 | 61 | /* If the size is small, or either SRC or DST is unaligned, 62 | then punt into the byte copy loop. This should be rare. */ 63 | if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) 64 | { 65 | aligned_dst = (long*)dst; 66 | aligned_src = (long*)src; 67 | 68 | /* Copy 4X long words at a time if possible. */ 69 | while (len0 >= BIGBLOCKSIZE) 70 | { 71 | *aligned_dst++ = *aligned_src++; 72 | *aligned_dst++ = *aligned_src++; 73 | *aligned_dst++ = *aligned_src++; 74 | *aligned_dst++ = *aligned_src++; 75 | len0 -= BIGBLOCKSIZE; 76 | } 77 | 78 | /* Copy one long word at a time if possible. */ 79 | while (len0 >= LITTLEBLOCKSIZE) 80 | { 81 | *aligned_dst++ = *aligned_src++; 82 | len0 -= LITTLEBLOCKSIZE; 83 | } 84 | 85 | /* Pick up any residual with a byte copier. */ 86 | dst = (char*)aligned_dst; 87 | src = (char*)aligned_src; 88 | } 89 | 90 | while (len0--) 91 | *dst++ = *src++; 92 | 93 | return dst0; 94 | #endif /* not PREFER_SIZE_OVER_SPEED */ 95 | } 96 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/lib/memcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---copy memory regions 4 | SYNOPSIS 5 | #include 6 | void* memcpy(void *restrict <[out]>, const void *restrict <[in]>, 7 | size_t <[n]>); 8 | DESCRIPTION 9 | This function copies <[n]> bytes from the memory region 10 | pointed to by <[in]> to the memory region pointed to by 11 | <[out]>. 12 | If the regions overlap, the behavior is undefined. 13 | RETURNS 14 | <> returns a pointer to the first byte of the <[out]> 15 | region. 16 | PORTABILITY 17 | <> is ANSI C. 18 | <> requires no supporting OS subroutines. 19 | QUICKREF 20 | memcpy ansi pure 21 | */ 22 | 23 | #include 24 | 25 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 26 | #define UNALIGNED(X, Y) \ 27 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 28 | 29 | /* How many bytes are copied each iteration of the 4X unrolled loop. */ 30 | #define BIGBLOCKSIZE (sizeof (long) << 2) 31 | 32 | /* How many bytes are copied each iteration of the word copy loop. */ 33 | #define LITTLEBLOCKSIZE (sizeof (long)) 34 | 35 | /* Threshhold for punting to the byte copier. */ 36 | #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) 37 | 38 | void * 39 | memcpy (void *__restrict dst0, 40 | const void *__restrict src0, 41 | size_t len0) 42 | { 43 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 44 | char *dst = (char *) dst0; 45 | char *src = (char *) src0; 46 | 47 | void *save = dst0; 48 | 49 | while (len0--) 50 | { 51 | *dst++ = *src++; 52 | } 53 | 54 | return save; 55 | #else 56 | char *dst = dst0; 57 | const char *src = src0; 58 | long *aligned_dst; 59 | const long *aligned_src; 60 | 61 | /* If the size is small, or either SRC or DST is unaligned, 62 | then punt into the byte copy loop. This should be rare. */ 63 | if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) 64 | { 65 | aligned_dst = (long*)dst; 66 | aligned_src = (long*)src; 67 | 68 | /* Copy 4X long words at a time if possible. */ 69 | while (len0 >= BIGBLOCKSIZE) 70 | { 71 | *aligned_dst++ = *aligned_src++; 72 | *aligned_dst++ = *aligned_src++; 73 | *aligned_dst++ = *aligned_src++; 74 | *aligned_dst++ = *aligned_src++; 75 | len0 -= BIGBLOCKSIZE; 76 | } 77 | 78 | /* Copy one long word at a time if possible. */ 79 | while (len0 >= LITTLEBLOCKSIZE) 80 | { 81 | *aligned_dst++ = *aligned_src++; 82 | len0 -= LITTLEBLOCKSIZE; 83 | } 84 | 85 | /* Pick up any residual with a byte copier. */ 86 | dst = (char*)aligned_dst; 87 | src = (char*)aligned_src; 88 | } 89 | 90 | while (len0--) 91 | *dst++ = *src++; 92 | 93 | return dst0; 94 | #endif /* not PREFER_SIZE_OVER_SPEED */ 95 | } 96 | -------------------------------------------------------------------------------- /magic/apple-include/mach/i386/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for I386. 63 | */ 64 | 65 | #ifndef _MACH_I386_BOOLEAN_H_ 66 | #define _MACH_I386_BOOLEAN_H_ 67 | 68 | #if defined(__x86_64__) && !defined(KERNEL) 69 | typedef unsigned int boolean_t; 70 | #else 71 | typedef int boolean_t; 72 | #endif 73 | 74 | #endif /* _MACH_I386_BOOLEAN_H_ */ 75 | -------------------------------------------------------------------------------- /magic/apple-include/mach/arm/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_ARM_KERN_RETURN_H_ 68 | #define _MACH_ARM_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_ARM_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /magic/apple-include/mach/i386/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_I386_KERN_RETURN_H_ 68 | #define _MACH_I386_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_I386_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /magic/apple-include/mach/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | /* 59 | * File: mach/boolean.h 60 | * 61 | * Boolean data type. 62 | * 63 | */ 64 | 65 | #ifndef _MACH_BOOLEAN_H_ 66 | #define _MACH_BOOLEAN_H_ 67 | 68 | /* 69 | * Pick up "boolean_t" type definition 70 | */ 71 | 72 | #ifndef ASSEMBLER 73 | #include 74 | #endif /* ASSEMBLER */ 75 | 76 | /* 77 | * Define TRUE and FALSE if not defined. 78 | */ 79 | 80 | #ifndef TRUE 81 | #define TRUE 1 82 | #endif /* TRUE */ 83 | 84 | #ifndef FALSE 85 | #define FALSE 0 86 | #endif /* FALSE */ 87 | 88 | #endif /* _MACH_BOOLEAN_H_ */ 89 | -------------------------------------------------------------------------------- /magic/apple-include/sys/_posix_availability.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Apple Inc. All rights reserved. 2 | * 3 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 4 | * 5 | * This file contains Original Code and/or Modifications of Original Code 6 | * as defined in and that are subject to the Apple Public Source License 7 | * Version 2.0 (the 'License'). You may not use this file except in 8 | * compliance with the License. The rights granted to you under the License 9 | * may not be used to create, or enable the creation or redistribution of, 10 | * unlawful or unlicensed copies of an Apple operating system, or to 11 | * circumvent, violate, or enable the circumvention or violation of, any 12 | * terms of an Apple operating system software license agreement. 13 | * 14 | * Please obtain a copy of the License at 15 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 16 | * 17 | * The Original Code and all software distributed under the License are 18 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 19 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 20 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 22 | * Please see the License for the specific language governing rights and 23 | * limitations under the License. 24 | * 25 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 26 | */ 27 | 28 | #ifndef _CDEFS_H_ 29 | # error "Never use directly. Use instead." 30 | #endif 31 | 32 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 198808L 33 | #define ___POSIX_C_DEPRECATED_STARTING_198808L __deprecated 34 | #else 35 | #define ___POSIX_C_DEPRECATED_STARTING_198808L 36 | #endif 37 | 38 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199009L 39 | #define ___POSIX_C_DEPRECATED_STARTING_199009L __deprecated 40 | #else 41 | #define ___POSIX_C_DEPRECATED_STARTING_199009L 42 | #endif 43 | 44 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199209L 45 | #define ___POSIX_C_DEPRECATED_STARTING_199209L __deprecated 46 | #else 47 | #define ___POSIX_C_DEPRECATED_STARTING_199209L 48 | #endif 49 | 50 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L 51 | #define ___POSIX_C_DEPRECATED_STARTING_199309L __deprecated 52 | #else 53 | #define ___POSIX_C_DEPRECATED_STARTING_199309L 54 | #endif 55 | 56 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199506L 57 | #define ___POSIX_C_DEPRECATED_STARTING_199506L __deprecated 58 | #else 59 | #define ___POSIX_C_DEPRECATED_STARTING_199506L 60 | #endif 61 | 62 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L 63 | #define ___POSIX_C_DEPRECATED_STARTING_200112L __deprecated 64 | #else 65 | #define ___POSIX_C_DEPRECATED_STARTING_200112L 66 | #endif 67 | 68 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L 69 | #define ___POSIX_C_DEPRECATED_STARTING_200809L __deprecated 70 | #else 71 | #define ___POSIX_C_DEPRECATED_STARTING_200809L 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /magic/lib/strncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---character string compare 4 | 5 | INDEX 6 | strncmp 7 | SYNOPSIS 8 | #include 9 | int strncmp(const char *<[a]>, const char * <[b]>, size_t <[length]>); 10 | DESCRIPTION 11 | <> compares up to <[length]> characters 12 | from the string at <[a]> to the string at <[b]>. 13 | RETURNS 14 | If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>, 15 | <> returns a number greater than zero. If the two 16 | strings are equivalent, <> returns zero. If <<*<[a]>>> 17 | sorts lexicographically before <<*<[b]>>>, <> returns a 18 | number less than zero. 19 | PORTABILITY 20 | <> is ANSI C. 21 | <> requires no supporting OS subroutines. 22 | QUICKREF 23 | strncmp ansi pure 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | /* Nonzero if either X or Y is not aligned on a "long" boundary. */ 30 | #define UNALIGNED(X, Y) \ 31 | (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) 32 | 33 | /* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ 34 | #if LONG_MAX == 2147483647L 35 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 36 | #else 37 | #if LONG_MAX == 9223372036854775807L 38 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 39 | #else 40 | #error long int is not a 32bit or 64bit type. 41 | #endif 42 | #endif 43 | 44 | #ifndef DETECTNULL 45 | #error long int is not a 32bit or 64bit byte 46 | #endif 47 | 48 | int 49 | strncmp (const char *s1, 50 | const char *s2, 51 | size_t n) 52 | { 53 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) 54 | if (n == 0) 55 | return 0; 56 | 57 | while (n-- != 0 && *s1 == *s2) 58 | { 59 | if (n == 0 || *s1 == '\0') 60 | break; 61 | s1++; 62 | s2++; 63 | } 64 | 65 | return (*(unsigned char *) s1) - (*(unsigned char *) s2); 66 | #else 67 | unsigned long *a1; 68 | unsigned long *a2; 69 | 70 | if (n == 0) 71 | return 0; 72 | 73 | /* If s1 or s2 are unaligned, then compare bytes. */ 74 | if (!UNALIGNED (s1, s2)) 75 | { 76 | /* If s1 and s2 are word-aligned, compare them a word at a time. */ 77 | a1 = (unsigned long*)s1; 78 | a2 = (unsigned long*)s2; 79 | while (n >= sizeof (long) && *a1 == *a2) 80 | { 81 | n -= sizeof (long); 82 | 83 | /* If we've run out of bytes or hit a null, return zero 84 | since we already know *a1 == *a2. */ 85 | if (n == 0 || DETECTNULL (*a1)) 86 | return 0; 87 | 88 | a1++; 89 | a2++; 90 | } 91 | 92 | /* A difference was detected in last few bytes of s1, so search bytewise */ 93 | s1 = (char*)a1; 94 | s2 = (char*)a2; 95 | } 96 | 97 | while (n-- > 0 && *s1 == *s2) 98 | { 99 | /* If we've run out of bytes or hit a null, return zero 100 | since we already know *s1 == *s2. */ 101 | if (n == 0 || *s1 == '\0') 102 | return 0; 103 | s1++; 104 | s2++; 105 | } 106 | return (*(unsigned char *) s1) - (*(unsigned char *) s2); 107 | #endif /* not PREFER_SIZE_OVER_SPEED */ 108 | } 109 | -------------------------------------------------------------------------------- /magic/lib/strchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---search for character in string 4 | INDEX 5 | strchr 6 | SYNOPSIS 7 | #include 8 | char * strchr(const char *<[string]>, int <[c]>); 9 | DESCRIPTION 10 | This function finds the first occurence of <[c]> (converted to 11 | a char) in the string pointed to by <[string]> (including the 12 | terminating null character). 13 | RETURNS 14 | Returns a pointer to the located character, or a null pointer 15 | if <[c]> does not occur in <[string]>. 16 | PORTABILITY 17 | <> is ANSI C. 18 | <> requires no supporting OS subroutines. 19 | QUICKREF 20 | strchr ansi pure 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | /* Nonzero if X is not aligned on a "long" boundary. */ 27 | #define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) 28 | 29 | /* How many bytes are loaded each iteration of the word copy loop. */ 30 | #define LBLOCKSIZE (sizeof (long)) 31 | 32 | #if LONG_MAX == 2147483647L 33 | #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) 34 | #else 35 | #if LONG_MAX == 9223372036854775807L 36 | /* Nonzero if X (a long int) contains a NULL byte. */ 37 | #define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) 38 | #else 39 | #error long int is not a 32bit or 64bit type. 40 | #endif 41 | #endif 42 | 43 | /* DETECTCHAR returns nonzero if (long)X contains the byte used 44 | to fill (long)MASK. */ 45 | #define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) 46 | 47 | char * 48 | strchr (const char *s1, 49 | int i) 50 | { 51 | const unsigned char *s = (const unsigned char *)s1; 52 | unsigned char c = i; 53 | 54 | #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) 55 | unsigned long mask,j; 56 | unsigned long *aligned_addr; 57 | 58 | /* Special case for finding 0. */ 59 | if (!c) 60 | { 61 | while (UNALIGNED (s)) 62 | { 63 | if (!*s) 64 | return (char *) s; 65 | s++; 66 | } 67 | /* Operate a word at a time. */ 68 | aligned_addr = (unsigned long *) s; 69 | while (!DETECTNULL (*aligned_addr)) 70 | aligned_addr++; 71 | /* Found the end of string. */ 72 | s = (const unsigned char *) aligned_addr; 73 | while (*s) 74 | s++; 75 | return (char *) s; 76 | } 77 | 78 | /* All other bytes. Align the pointer, then search a long at a time. */ 79 | while (UNALIGNED (s)) 80 | { 81 | if (!*s) 82 | return NULL; 83 | if (*s == c) 84 | return (char *) s; 85 | s++; 86 | } 87 | 88 | mask = c; 89 | for (j = 8; j < LBLOCKSIZE * 8; j <<= 1) 90 | mask = (mask << j) | mask; 91 | 92 | aligned_addr = (unsigned long *) s; 93 | while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) 94 | aligned_addr++; 95 | 96 | /* The block of bytes currently pointed to by aligned_addr 97 | contains either a null or the target char, or both. We 98 | catch it using the bytewise search. */ 99 | 100 | s = (unsigned char *) aligned_addr; 101 | 102 | #endif /* not PREFER_SIZE_OVER_SPEED */ 103 | 104 | while (*s && *s != c) 105 | s++; 106 | if (*s == c) 107 | return (char *)s; 108 | return NULL; 109 | } 110 | -------------------------------------------------------------------------------- /magic/apple-include/mach/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | * 31 | */ 32 | #ifndef _MACH_VM_TYPES_H_ 33 | #define _MACH_VM_TYPES_H_ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | typedef vm_offset_t pointer_t; 41 | typedef vm_offset_t vm_address_t; 42 | 43 | /* 44 | * We use addr64_t for 64-bit addresses that are used on both 45 | * 32 and 64-bit machines. On PPC, they are passed and returned as 46 | * two adjacent 32-bit GPRs. We use addr64_t in places where 47 | * common code must be useable both on 32 and 64-bit machines. 48 | */ 49 | typedef uint64_t addr64_t; /* Basic effective address */ 50 | 51 | /* 52 | * We use reg64_t for addresses that are 32 bits on a 32-bit 53 | * machine, and 64 bits on a 64-bit machine, but are always 54 | * passed and returned in a single GPR on PPC. This type 55 | * cannot be used in generic 32-bit c, since on a 64-bit 56 | * machine the upper half of the register will be ignored 57 | * by the c compiler in 32-bit mode. In c, we can only use the 58 | * type in prototypes of functions that are written in and called 59 | * from assembly language. This type is basically a comment. 60 | */ 61 | typedef uint32_t reg64_t; 62 | 63 | /* 64 | * To minimize the use of 64-bit fields, we keep some physical 65 | * addresses (that are page aligned) as 32-bit page numbers. 66 | * This limits the physical address space to 16TB of RAM. 67 | */ 68 | typedef uint32_t ppnum_t; /* Physical page number */ 69 | #define PPNUM_MAX UINT32_MAX 70 | 71 | 72 | 73 | typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 74 | 75 | 76 | #define VM_MAP_NULL ((vm_map_t) 0) 77 | #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 78 | #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 79 | 80 | /* 81 | * Evolving definitions, likely to change. 82 | */ 83 | 84 | typedef uint64_t vm_object_offset_t; 85 | typedef uint64_t vm_object_size_t; 86 | 87 | 88 | 89 | 90 | typedef mach_port_t upl_t; 91 | typedef mach_port_t vm_named_entry_t; 92 | 93 | 94 | #define UPL_NULL ((upl_t) 0) 95 | #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 96 | 97 | #endif /* _MACH_VM_TYPES_H_ */ 98 | -------------------------------------------------------------------------------- /magic/apple-include/sys/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _SYS__TYPES_H_ 30 | #define _SYS__TYPES_H_ 31 | 32 | #include 33 | #include 34 | 35 | /* 36 | * Type definitions; takes common type definitions that must be used 37 | * in multiple header files due to [XSI], removes them from the system 38 | * space, and puts them in the implementation space. 39 | */ 40 | 41 | #ifdef __cplusplus 42 | #ifdef __GNUG__ 43 | #define __DARWIN_NULL __null 44 | #else /* ! __GNUG__ */ 45 | #ifdef __LP64__ 46 | #define __DARWIN_NULL (0L) 47 | #else /* !__LP64__ */ 48 | #define __DARWIN_NULL 0 49 | #endif /* __LP64__ */ 50 | #endif /* __GNUG__ */ 51 | #else /* ! __cplusplus */ 52 | #define __DARWIN_NULL ((void *)0) 53 | #endif /* __cplusplus */ 54 | 55 | typedef __int64_t __darwin_blkcnt_t; /* total blocks */ 56 | typedef __int32_t __darwin_blksize_t; /* preferred block size */ 57 | typedef __int32_t __darwin_dev_t; /* dev_t */ 58 | typedef unsigned int __darwin_fsblkcnt_t; /* Used by statvfs and fstatvfs */ 59 | typedef unsigned int __darwin_fsfilcnt_t; /* Used by statvfs and fstatvfs */ 60 | typedef __uint32_t __darwin_gid_t; /* [???] process and group IDs */ 61 | typedef __uint32_t __darwin_id_t; /* [XSI] pid_t, uid_t, or gid_t*/ 62 | typedef __uint64_t __darwin_ino64_t; /* [???] Used for 64 bit inodes */ 63 | #if __DARWIN_64_BIT_INO_T 64 | typedef __darwin_ino64_t __darwin_ino_t; /* [???] Used for inodes */ 65 | #else /* !__DARWIN_64_BIT_INO_T */ 66 | typedef __uint32_t __darwin_ino_t; /* [???] Used for inodes */ 67 | #endif /* __DARWIN_64_BIT_INO_T */ 68 | typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */ 69 | typedef __darwin_mach_port_name_t __darwin_mach_port_t; /* Used by mach */ 70 | typedef __uint16_t __darwin_mode_t; /* [???] Some file attributes */ 71 | typedef __int64_t __darwin_off_t; /* [???] Used for file sizes */ 72 | typedef __int32_t __darwin_pid_t; /* [???] process and group IDs */ 73 | typedef __uint32_t __darwin_sigset_t; /* [???] signal set */ 74 | typedef __int32_t __darwin_suseconds_t; /* [???] microseconds */ 75 | typedef __uint32_t __darwin_uid_t; /* [???] user IDs */ 76 | typedef __uint32_t __darwin_useconds_t; /* [???] microseconds */ 77 | typedef unsigned char __darwin_uuid_t[16]; 78 | typedef char __darwin_uuid_string_t[37]; 79 | 80 | #include 81 | 82 | #endif /* _SYS__TYPES_H_ */ 83 | -------------------------------------------------------------------------------- /magic/apple-include/arm/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | */ 4 | #ifndef _BSD_ARM__TYPES_H_ 5 | #define _BSD_ARM__TYPES_H_ 6 | 7 | /* 8 | * This header file contains integer types. It's intended to also contain 9 | * flotaing point and other arithmetic types, as needed, later. 10 | */ 11 | 12 | #ifdef __GNUC__ 13 | typedef __signed char __int8_t; 14 | #else /* !__GNUC__ */ 15 | typedef char __int8_t; 16 | #endif /* !__GNUC__ */ 17 | typedef unsigned char __uint8_t; 18 | typedef short __int16_t; 19 | typedef unsigned short __uint16_t; 20 | typedef int __int32_t; 21 | typedef unsigned int __uint32_t; 22 | typedef long long __int64_t; 23 | typedef unsigned long long __uint64_t; 24 | 25 | typedef long __darwin_intptr_t; 26 | typedef unsigned int __darwin_natural_t; 27 | 28 | /* 29 | * The rune type below is declared to be an ``int'' instead of the more natural 30 | * ``unsigned long'' or ``long''. Two things are happening here. It is not 31 | * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, 32 | * it looks like 10646 will be a 31 bit standard. This means that if your 33 | * ints cannot hold 32 bits, you will be in trouble. The reason an int was 34 | * chosen over a long is that the is*() and to*() routines take ints (says 35 | * ANSI C), but they use __darwin_ct_rune_t instead of int. By changing it 36 | * here, you lose a bit of ANSI conformance, but your programs will still 37 | * work. 38 | * 39 | * NOTE: rune_t is not covered by ANSI nor other standards, and should not 40 | * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and 41 | * rune_t must be the same type. Also wint_t must be no narrower than 42 | * wchar_t, and should also be able to hold all members of the largest 43 | * character set plus one extra value (WEOF). wint_t must be at least 16 bits. 44 | */ 45 | 46 | typedef int __darwin_ct_rune_t; /* ct_rune_t */ 47 | 48 | /* 49 | * mbstate_t is an opaque object to keep conversion state, during multibyte 50 | * stream conversions. The content must not be referenced by user programs. 51 | */ 52 | typedef union { 53 | char __mbstate8[128]; 54 | long long _mbstateL; /* for alignment */ 55 | } __mbstate_t; 56 | 57 | typedef __mbstate_t __darwin_mbstate_t; /* mbstate_t */ 58 | 59 | #if defined(__PTRDIFF_TYPE__) 60 | typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 61 | #elif defined(__LP64__) 62 | typedef long __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 63 | #else 64 | typedef int __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 65 | #endif /* __GNUC__ */ 66 | 67 | #if defined(__SIZE_TYPE__) 68 | typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ 69 | #else 70 | typedef unsigned long __darwin_size_t; /* sizeof() */ 71 | #endif 72 | 73 | #if (__GNUC__ > 2) 74 | typedef __builtin_va_list __darwin_va_list; /* va_list */ 75 | #else 76 | typedef void * __darwin_va_list; /* va_list */ 77 | #endif 78 | 79 | #if defined(__WCHAR_TYPE__) 80 | typedef __WCHAR_TYPE__ __darwin_wchar_t; /* wchar_t */ 81 | #else 82 | typedef __darwin_ct_rune_t __darwin_wchar_t; /* wchar_t */ 83 | #endif 84 | 85 | typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 86 | 87 | #if defined(__WINT_TYPE__) 88 | typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 89 | #else 90 | typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */ 91 | #endif 92 | 93 | typedef unsigned long __darwin_clock_t; /* clock() */ 94 | typedef __uint32_t __darwin_socklen_t; /* socklen_t (duh) */ 95 | typedef long __darwin_ssize_t; /* byte count or error */ 96 | typedef long __darwin_time_t; /* time() */ 97 | 98 | #endif /* _BSD_ARM__TYPES_H_ */ 99 | -------------------------------------------------------------------------------- /magic/apple-include/libkern/_OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _OS__OSBYTEORDER_H 30 | #define _OS__OSBYTEORDER_H 31 | 32 | /* 33 | * This header is normally included from . However, 34 | * also includes this in the case of little-endian 35 | * architectures, so that we can map OSByteOrder routines to the hton* and ntoh* 36 | * macros. This results in the asymmetry below; we only include 37 | * for little-endian architectures. 38 | */ 39 | 40 | #include 41 | 42 | /* Macros for swapping constant values in the preprocessing stage. */ 43 | #define __DARWIN_OSSwapConstInt16(x) \ 44 | ((__uint16_t)((((__uint16_t)(x) & 0xff00U) >> 8) | \ 45 | (((__uint16_t)(x) & 0x00ffU) << 8))) 46 | 47 | #define __DARWIN_OSSwapConstInt32(x) \ 48 | ((__uint32_t)((((__uint32_t)(x) & 0xff000000U) >> 24) | \ 49 | (((__uint32_t)(x) & 0x00ff0000U) >> 8) | \ 50 | (((__uint32_t)(x) & 0x0000ff00U) << 8) | \ 51 | (((__uint32_t)(x) & 0x000000ffU) << 24))) 52 | 53 | #define __DARWIN_OSSwapConstInt64(x) \ 54 | ((__uint64_t)((((__uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \ 55 | (((__uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \ 56 | (((__uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \ 57 | (((__uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \ 58 | (((__uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \ 59 | (((__uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \ 60 | (((__uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \ 61 | (((__uint64_t)(x) & 0x00000000000000ffULL) << 56))) 62 | 63 | #if defined(__GNUC__) 64 | 65 | #if !defined(__DARWIN_OS_INLINE) 66 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 67 | # define __DARWIN_OS_INLINE static inline 68 | # elif defined(__MWERKS__) || defined(__cplusplus) 69 | # define __DARWIN_OS_INLINE static inline 70 | # else 71 | # define __DARWIN_OS_INLINE static __inline__ 72 | # endif 73 | #endif 74 | 75 | 76 | #if defined (__arm__) || defined(__arm64__) 77 | #include 78 | #endif 79 | 80 | 81 | #define __DARWIN_OSSwapInt16(x) \ 82 | ((__uint16_t)(__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt16(x) : _OSSwapInt16(x))) 83 | 84 | #define __DARWIN_OSSwapInt32(x) \ 85 | (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt32(x) : _OSSwapInt32(x)) 86 | 87 | #define __DARWIN_OSSwapInt64(x) \ 88 | (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt64(x) : _OSSwapInt64(x)) 89 | 90 | #else /* ! __GNUC__ */ 91 | 92 | 93 | #define __DARWIN_OSSwapInt16(x) _OSSwapInt16(x) 94 | 95 | #define __DARWIN_OSSwapInt32(x) _OSSwapInt32(x) 96 | 97 | #define __DARWIN_OSSwapInt64(x) _OSSwapInt64(x) 98 | 99 | #endif /* __GNUC__ */ 100 | 101 | #endif /* ! _OS__OSBYTEORDER_H */ 102 | -------------------------------------------------------------------------------- /magic/apple-include/libkern/machine/OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _OS_OSBYTEORDERMACHINE_H 30 | #define _OS_OSBYTEORDERMACHINE_H 31 | 32 | #include 33 | 34 | #if !defined(OS_INLINE) 35 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 36 | # define OS_INLINE static inline 37 | # elif defined(__MWERKS__) || defined(__cplusplus) 38 | # define OS_INLINE static inline 39 | # else 40 | # define OS_INLINE static __inline__ 41 | # endif 42 | #endif 43 | 44 | /* Generic byte swapping functions. */ 45 | 46 | OS_INLINE 47 | uint16_t 48 | _OSSwapInt16( 49 | uint16_t data 50 | ) 51 | { 52 | return OSSwapConstInt16(data); 53 | } 54 | 55 | OS_INLINE 56 | uint32_t 57 | _OSSwapInt32( 58 | uint32_t data 59 | ) 60 | { 61 | return OSSwapConstInt32(data); 62 | } 63 | 64 | OS_INLINE 65 | uint64_t 66 | _OSSwapInt64( 67 | uint64_t data 68 | ) 69 | { 70 | return OSSwapConstInt64(data); 71 | } 72 | 73 | /* Functions for byte reversed loads. */ 74 | 75 | OS_INLINE 76 | uint16_t 77 | OSReadSwapInt16( 78 | const volatile void * base, 79 | uintptr_t byteOffset 80 | ) 81 | { 82 | uint16_t data = *(volatile uint16_t *)((uintptr_t)base + byteOffset); 83 | return _OSSwapInt16(data); 84 | } 85 | 86 | OS_INLINE 87 | uint32_t 88 | OSReadSwapInt32( 89 | const volatile void * base, 90 | uintptr_t byteOffset 91 | ) 92 | { 93 | uint32_t data = *(volatile uint32_t *)((uintptr_t)base + byteOffset); 94 | return _OSSwapInt32(data); 95 | } 96 | 97 | OS_INLINE 98 | uint64_t 99 | OSReadSwapInt64( 100 | const volatile void * base, 101 | uintptr_t byteOffset 102 | ) 103 | { 104 | uint64_t data = *(volatile uint64_t *)((uintptr_t)base + byteOffset); 105 | return _OSSwapInt64(data); 106 | } 107 | 108 | /* Functions for byte reversed stores. */ 109 | 110 | OS_INLINE 111 | void 112 | OSWriteSwapInt16( 113 | volatile void * base, 114 | uintptr_t byteOffset, 115 | uint16_t data 116 | ) 117 | { 118 | *(volatile uint16_t *)((uintptr_t)base + byteOffset) = _OSSwapInt16(data); 119 | } 120 | 121 | OS_INLINE 122 | void 123 | OSWriteSwapInt32( 124 | volatile void * base, 125 | uintptr_t byteOffset, 126 | uint32_t data 127 | ) 128 | { 129 | *(volatile uint32_t *)((uintptr_t)base + byteOffset) = _OSSwapInt32(data); 130 | } 131 | 132 | OS_INLINE 133 | void 134 | OSWriteSwapInt64( 135 | volatile void * base, 136 | uintptr_t byteOffset, 137 | uint64_t data 138 | ) 139 | { 140 | *(volatile uint64_t *)((uintptr_t)base + byteOffset) = _OSSwapInt64(data); 141 | } 142 | 143 | #endif /* ! _OS_OSBYTEORDERMACHINE_H */ 144 | -------------------------------------------------------------------------------- /magic/apple-include/i386/eflags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | #ifndef _I386_EFLAGS_H_ 60 | #define _I386_EFLAGS_H_ 61 | 62 | /* 63 | * i386 flags register 64 | */ 65 | 66 | #ifndef EFL_CF 67 | #define EFL_CF 0x00000001 /* carry */ 68 | #define EFL_PF 0x00000004 /* parity of low 8 bits */ 69 | #define EFL_AF 0x00000010 /* carry out of bit 3 */ 70 | #define EFL_ZF 0x00000040 /* zero */ 71 | #define EFL_SF 0x00000080 /* sign */ 72 | #define EFL_TF 0x00000100 /* trace trap */ 73 | #define EFL_IF 0x00000200 /* interrupt enable */ 74 | #define EFL_DF 0x00000400 /* direction */ 75 | #define EFL_OF 0x00000800 /* overflow */ 76 | #define EFL_IOPL 0x00003000 /* IO privilege level: */ 77 | #define EFL_IOPL_KERNEL 0x00000000 /* kernel */ 78 | #define EFL_IOPL_USER 0x00003000 /* user */ 79 | #define EFL_NT 0x00004000 /* nested task */ 80 | #define EFL_RF 0x00010000 /* resume without tracing */ 81 | #define EFL_VM 0x00020000 /* virtual 8086 mode */ 82 | #define EFL_AC 0x00040000 /* alignment check */ 83 | #define EFL_VIF 0x00080000 /* virtual interrupt flag */ 84 | #define EFL_VIP 0x00100000 /* virtual interrupt pending */ 85 | #define EFL_ID 0x00200000 /* cpuID instruction */ 86 | #endif 87 | 88 | #define EFL_CLR 0xfff88028 89 | #define EFL_SET 0x00000002 90 | 91 | #define EFL_USER_SET (EFL_IF) 92 | #define EFL_USER_CLEAR (EFL_IOPL|EFL_NT|EFL_RF) 93 | 94 | #endif /* _I386_EFLAGS_H_ */ 95 | -------------------------------------------------------------------------------- /magic/apple-include/sys/_pthread/_pthread_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2013 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _SYS__PTHREAD_TYPES_H_ 30 | #define _SYS__PTHREAD_TYPES_H_ 31 | 32 | #include 33 | 34 | // pthread opaque structures 35 | #if defined(__LP64__) 36 | #define __PTHREAD_SIZE__ 8176 37 | #define __PTHREAD_ATTR_SIZE__ 56 38 | #define __PTHREAD_MUTEXATTR_SIZE__ 8 39 | #define __PTHREAD_MUTEX_SIZE__ 56 40 | #define __PTHREAD_CONDATTR_SIZE__ 8 41 | #define __PTHREAD_COND_SIZE__ 40 42 | #define __PTHREAD_ONCE_SIZE__ 8 43 | #define __PTHREAD_RWLOCK_SIZE__ 192 44 | #define __PTHREAD_RWLOCKATTR_SIZE__ 16 45 | #else // !__LP64__ 46 | #define __PTHREAD_SIZE__ 4088 47 | #define __PTHREAD_ATTR_SIZE__ 36 48 | #define __PTHREAD_MUTEXATTR_SIZE__ 8 49 | #define __PTHREAD_MUTEX_SIZE__ 40 50 | #define __PTHREAD_CONDATTR_SIZE__ 4 51 | #define __PTHREAD_COND_SIZE__ 24 52 | #define __PTHREAD_ONCE_SIZE__ 4 53 | #define __PTHREAD_RWLOCK_SIZE__ 124 54 | #define __PTHREAD_RWLOCKATTR_SIZE__ 12 55 | #endif // !__LP64__ 56 | 57 | struct __darwin_pthread_handler_rec { 58 | void (*__routine)(void *); // Routine to call 59 | void *__arg; // Argument to pass 60 | struct __darwin_pthread_handler_rec *__next; 61 | }; 62 | 63 | struct _opaque_pthread_attr_t { 64 | long __sig; 65 | char __opaque[__PTHREAD_ATTR_SIZE__]; 66 | }; 67 | 68 | struct _opaque_pthread_cond_t { 69 | long __sig; 70 | char __opaque[__PTHREAD_COND_SIZE__]; 71 | }; 72 | 73 | struct _opaque_pthread_condattr_t { 74 | long __sig; 75 | char __opaque[__PTHREAD_CONDATTR_SIZE__]; 76 | }; 77 | 78 | struct _opaque_pthread_mutex_t { 79 | long __sig; 80 | char __opaque[__PTHREAD_MUTEX_SIZE__]; 81 | }; 82 | 83 | struct _opaque_pthread_mutexattr_t { 84 | long __sig; 85 | char __opaque[__PTHREAD_MUTEXATTR_SIZE__]; 86 | }; 87 | 88 | struct _opaque_pthread_once_t { 89 | long __sig; 90 | char __opaque[__PTHREAD_ONCE_SIZE__]; 91 | }; 92 | 93 | struct _opaque_pthread_rwlock_t { 94 | long __sig; 95 | char __opaque[__PTHREAD_RWLOCK_SIZE__]; 96 | }; 97 | 98 | struct _opaque_pthread_rwlockattr_t { 99 | long __sig; 100 | char __opaque[__PTHREAD_RWLOCKATTR_SIZE__]; 101 | }; 102 | 103 | struct _opaque_pthread_t { 104 | long __sig; 105 | struct __darwin_pthread_handler_rec *__cleanup_stack; 106 | char __opaque[__PTHREAD_SIZE__]; 107 | }; 108 | 109 | typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t; 110 | typedef struct _opaque_pthread_cond_t __darwin_pthread_cond_t; 111 | typedef struct _opaque_pthread_condattr_t __darwin_pthread_condattr_t; 112 | typedef unsigned long __darwin_pthread_key_t; 113 | typedef struct _opaque_pthread_mutex_t __darwin_pthread_mutex_t; 114 | typedef struct _opaque_pthread_mutexattr_t __darwin_pthread_mutexattr_t; 115 | typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; 116 | typedef struct _opaque_pthread_rwlock_t __darwin_pthread_rwlock_t; 117 | typedef struct _opaque_pthread_rwlockattr_t __darwin_pthread_rwlockattr_t; 118 | typedef struct _opaque_pthread_t *__darwin_pthread_t; 119 | 120 | #endif // _SYS__PTHREAD_TYPES_H_ 121 | -------------------------------------------------------------------------------- /magic/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //typedef uint64_t size_t; 10 | 11 | #ifndef NULL 12 | #define NULL ((void*)0) 13 | #endif 14 | 15 | struct cmd_arg { 16 | bool b; 17 | size_t u; 18 | size_t h; 19 | char *str; 20 | }; 21 | 22 | #define DT_KEY_LEN 0x20 23 | #define BOOT_LINE_LENGTH_iOS12 0x100 24 | #define BOOT_LINE_LENGTH_iOS13 0x260 25 | 26 | struct Boot_Video { 27 | unsigned long v_baseAddr; /* Base address of video memory */ 28 | unsigned long v_display; /* Display Code (if Applicable */ 29 | unsigned long v_rowBytes; /* Number of bytes per pixel row */ 30 | unsigned long v_width; /* Width */ 31 | unsigned long v_height; /* Height */ 32 | unsigned long v_depth; /* Pixel Depth and other parameters */ 33 | }; 34 | typedef struct boot_args { 35 | uint16_t Revision; /* Revision of boot_args structure */ 36 | uint16_t Version; /* Version of boot_args structure */ 37 | uint32_t __pad0; 38 | uint64_t virtBase; /* Virtual base of memory */ 39 | uint64_t physBase; /* Physical base of memory */ 40 | uint64_t memSize; /* Size of memory */ 41 | uint64_t topOfKernelData; /* Highest physical address used in kernel data area */ 42 | struct Boot_Video Video; /* Video Information */ 43 | uint32_t machineType; /* Machine Type */ 44 | uint32_t __pad1; 45 | void *deviceTreeP; /* Base of flattened device tree */ 46 | uint32_t deviceTreeLength; /* Length of flattened tree */ 47 | 48 | char CommandLine[BOOT_LINE_LENGTH_iOS13]; /* Passed in command line */ 49 | uint32_t __pad; 50 | uint64_t bootFlags; /* Additional flags specified by the bootloader */ 51 | uint64_t memSizeActual; /* Actual size of memory */ 52 | 53 | } __attribute__((packed)) boot_args; 54 | 55 | typedef struct 56 | { 57 | uint32_t nprop; 58 | uint32_t nchld; 59 | char prop[]; 60 | } dt_node_t; 61 | 62 | typedef struct 63 | { 64 | char key[DT_KEY_LEN]; 65 | uint32_t len; 66 | char val[]; 67 | } dt_prop_t; 68 | 69 | struct memmap { 70 | uint64_t addr; 71 | uint64_t size; 72 | }; 73 | 74 | extern void* gEntryPoint; 75 | extern boot_args *gBootArgs; 76 | extern dt_node_t *gDeviceTree; 77 | 78 | extern int dt_check(void* mem, uint32_t size, uint32_t* offp); 79 | extern int dt_parse(dt_node_t* node, int depth, uint32_t* offp, int (*cb_node)(void*, dt_node_t*), void* cbn_arg, int (*cb_prop)(void*, dt_node_t*, int, const char*, void*, uint32_t), void* cbp_arg); 80 | extern dt_node_t* dt_find(dt_node_t* node, const char* name); 81 | extern void* dt_prop(dt_node_t* node, const char* key, uint32_t* lenp); 82 | extern void* dt_get_prop(const char* device, const char* prop, uint32_t* size); 83 | extern struct memmap* dt_alloc_memmap(dt_node_t* node, const char* name); 84 | extern uint64_t dt_get_u64_prop(const char* device, const char* prop); 85 | extern uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx); 86 | 87 | // iboot 88 | typedef int (*printf_t)(const char *format, ...); 89 | printf_t iprintf; 90 | typedef int (*jumpto_t)(void* arg0, void* arg1); 91 | jumpto_t jumpto; 92 | typedef void* (*malloc_t)(size_t size); 93 | malloc_t imalloc; 94 | typedef int (*panic_t)(const char *format, ...); 95 | panic_t panic; 96 | typedef void (*free_t)(void *ptr); 97 | free_t ifree; 98 | 99 | 100 | // libc 101 | void *memmem(const void *haystack, size_t hs_len, const void *needle, size_t ne_len); 102 | void *memcpy(void *__restrict dst0, const void *__restrict src0, size_t len0); 103 | void *memset(void *m, int c, size_t n); 104 | char *strchr (const char *s1, int i); 105 | int strcmp (const char *s1, const char *s2); 106 | int strncmp(const char *s1, const char *s2, size_t n); 107 | size_t strlen (const char *str); 108 | char *strcpy(char *dst0, const char *src0); 109 | char *strstr (const char *haystack, const char *needle); 110 | int memcmp(const void *m1, const void *m2, size_t n); 111 | unsigned long long strtoull(const char * __restrict nptr, char ** __restrict endptr, int base); 112 | char *strcat (char *__restrict s1, const char *__restrict s2); 113 | 114 | #define DEV_BUILD 1 115 | 116 | #ifdef DEV_BUILD 117 | #define DEVLOG(x, ...) do { \ 118 | printf(x "\n", ##__VA_ARGS__); \ 119 | } while (0) 120 | #define panic_at(addr, str, ...) do { \ 121 | panic(str " (0x%llx)", ##__VA_ARGS__, xnu_ptr_to_va(addr)); \ 122 | } while (0) 123 | #else 124 | #define DEVLOG(x, ...) do {} while (0) 125 | #define panic_at(addr, str, ...) do { \ 126 | (void)(addr); \ 127 | panic(str, ##__VA_ARGS__); \ 128 | } while (0) 129 | #endif 130 | 131 | #define puts(x, ...) do { \ 132 | printf(x "\n", ##__VA_ARGS__); \ 133 | } while (0) 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /magic/include/printf.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // \author (c) Marco Paland (info@paland.com) 3 | // 2014-2019, PALANDesign Hannover, Germany 4 | // 5 | // \license The MIT License (MIT) 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on 26 | // embedded systems with a very limited resources. 27 | // Use this instead of bloated standard/newlib printf. 28 | // These routines are thread safe and reentrant. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _PRINTF_H_ 33 | #define _PRINTF_H_ 34 | 35 | #include 36 | #include 37 | 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | /** 45 | * Output a character to a custom device like UART, used by the printf() function 46 | * This function is declared here only. You have to write your custom implementation somewhere 47 | * \param character Character to output 48 | */ 49 | void _putchar(char character); 50 | 51 | 52 | /** 53 | * Tiny printf implementation 54 | * You have to implement _putchar if you use printf() 55 | * To avoid conflicts with the regular printf() API it is overridden by macro defines 56 | * and internal underscore-appended functions like printf_() are used 57 | * \param format A string that specifies the format of the output 58 | * \return The number of characters that are written into the array, not counting the terminating null character 59 | */ 60 | #define printf printf_ 61 | int printf_(const char* format, ...); 62 | 63 | 64 | /** 65 | * Tiny sprintf implementation 66 | * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! 67 | * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! 68 | * \param format A string that specifies the format of the output 69 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 70 | */ 71 | #define sprintf sprintf_ 72 | int sprintf_(char* buffer, const char* format, ...); 73 | 74 | 75 | /** 76 | * Tiny snprintf/vsnprintf implementation 77 | * \param buffer A pointer to the buffer where to store the formatted string 78 | * \param count The maximum number of characters to store in the buffer, including a terminating null character 79 | * \param format A string that specifies the format of the output 80 | * \param va A value identifying a variable arguments list 81 | * \return The number of characters that COULD have been written into the buffer, not counting the terminating 82 | * null character. A value equal or larger than count indicates truncation. Only when the returned value 83 | * is non-negative and less than count, the string has been completely written. 84 | */ 85 | #define snprintf snprintf_ 86 | #define vsnprintf vsnprintf_ 87 | int snprintf_(char* buffer, size_t count, const char* format, ...); 88 | int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); 89 | 90 | 91 | /** 92 | * Tiny vprintf implementation 93 | * \param format A string that specifies the format of the output 94 | * \param va A value identifying a variable arguments list 95 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 96 | */ 97 | #define vprintf vprintf_ 98 | int vprintf_(const char* format, va_list va); 99 | 100 | 101 | /** 102 | * printf with output function 103 | * You may use this as dynamic alternative to printf() with its fixed _putchar() output 104 | * \param out An output function which takes one character and an argument pointer 105 | * \param arg An argument pointer for user data passed to output function 106 | * \param format A string that specifies the format of the output 107 | * \return The number of characters that are sent to the output function, not counting the terminating null character 108 | */ 109 | int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); 110 | 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | 117 | #endif // _PRINTF_H_ 118 | -------------------------------------------------------------------------------- /magic/apple-include/libkern/arm/OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2007 Apple Inc. All rights reserved. 3 | */ 4 | 5 | #ifndef _OS_OSBYTEORDERARM_H 6 | #define _OS_OSBYTEORDERARM_H 7 | 8 | #include 9 | #include /* for _ARM_ARCH_6 */ 10 | 11 | /* Generic byte swapping functions. */ 12 | 13 | __DARWIN_OS_INLINE 14 | uint16_t 15 | _OSSwapInt16( 16 | uint16_t _data 17 | ) 18 | { 19 | /* Reduces to 'rev16' with clang */ 20 | return (uint16_t)(_data << 8 | _data >> 8); 21 | } 22 | 23 | __DARWIN_OS_INLINE 24 | uint32_t 25 | _OSSwapInt32( 26 | uint32_t _data 27 | ) 28 | { 29 | #if defined(__llvm__) 30 | _data = __builtin_bswap32(_data); 31 | #else 32 | /* This actually generates the best code */ 33 | _data = (((_data ^ (_data >> 16 | (_data << 16))) & 0xFF00FFFF) >> 8) ^ (_data >> 8 | _data << 24); 34 | #endif 35 | 36 | return _data; 37 | } 38 | 39 | __DARWIN_OS_INLINE 40 | uint64_t 41 | _OSSwapInt64( 42 | uint64_t _data 43 | ) 44 | { 45 | #if defined(__llvm__) 46 | return __builtin_bswap64(_data); 47 | #else 48 | union { 49 | uint64_t _ull; 50 | uint32_t _ul[2]; 51 | } _u; 52 | 53 | /* This actually generates the best code */ 54 | _u._ul[0] = (uint32_t)(_data >> 32); 55 | _u._ul[1] = (uint32_t)(_data & 0xffffffff); 56 | _u._ul[0] = _OSSwapInt32(_u._ul[0]); 57 | _u._ul[1] = _OSSwapInt32(_u._ul[1]); 58 | return _u._ull; 59 | #endif 60 | } 61 | 62 | /* Functions for byte reversed loads. */ 63 | 64 | struct _OSUnalignedU16 { 65 | volatile uint16_t __val; 66 | } __attribute__((__packed__)); 67 | 68 | struct _OSUnalignedU32 { 69 | volatile uint32_t __val; 70 | } __attribute__((__packed__)); 71 | 72 | struct _OSUnalignedU64 { 73 | volatile uint64_t __val; 74 | } __attribute__((__packed__)); 75 | 76 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 77 | __DARWIN_OS_INLINE 78 | uint16_t 79 | _OSReadSwapInt16( 80 | const volatile void * _base, 81 | uintptr_t _offset 82 | ) 83 | { 84 | return _OSSwapInt16(((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val); 85 | } 86 | #else 87 | __DARWIN_OS_INLINE 88 | uint16_t 89 | OSReadSwapInt16( 90 | const volatile void * _base, 91 | uintptr_t _offset 92 | ) 93 | { 94 | return _OSSwapInt16(((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val); 95 | } 96 | #endif 97 | 98 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 99 | __DARWIN_OS_INLINE 100 | uint32_t 101 | _OSReadSwapInt32( 102 | const volatile void * _base, 103 | uintptr_t _offset 104 | ) 105 | { 106 | return _OSSwapInt32(((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val); 107 | } 108 | #else 109 | __DARWIN_OS_INLINE 110 | uint32_t 111 | OSReadSwapInt32( 112 | const volatile void * _base, 113 | uintptr_t _offset 114 | ) 115 | { 116 | return _OSSwapInt32(((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val); 117 | } 118 | #endif 119 | 120 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 121 | __DARWIN_OS_INLINE 122 | uint64_t 123 | _OSReadSwapInt64( 124 | const volatile void * _base, 125 | uintptr_t _offset 126 | ) 127 | { 128 | return _OSSwapInt64(((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val); 129 | } 130 | #else 131 | __DARWIN_OS_INLINE 132 | uint64_t 133 | OSReadSwapInt64( 134 | const volatile void * _base, 135 | uintptr_t _offset 136 | ) 137 | { 138 | return _OSSwapInt64(((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val); 139 | } 140 | #endif 141 | 142 | /* Functions for byte reversed stores. */ 143 | 144 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 145 | __DARWIN_OS_INLINE 146 | void 147 | _OSWriteSwapInt16( 148 | volatile void * _base, 149 | uintptr_t _offset, 150 | uint16_t _data 151 | ) 152 | { 153 | ((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt16(_data); 154 | } 155 | #else 156 | __DARWIN_OS_INLINE 157 | void 158 | OSWriteSwapInt16( 159 | volatile void * _base, 160 | uintptr_t _offset, 161 | uint16_t _data 162 | ) 163 | { 164 | ((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt16(_data); 165 | } 166 | #endif 167 | 168 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 169 | __DARWIN_OS_INLINE 170 | void 171 | _OSWriteSwapInt32( 172 | volatile void * _base, 173 | uintptr_t _offset, 174 | uint32_t _data 175 | ) 176 | { 177 | ((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt32(_data); 178 | } 179 | #else 180 | __DARWIN_OS_INLINE 181 | void 182 | OSWriteSwapInt32( 183 | volatile void * _base, 184 | uintptr_t _offset, 185 | uint32_t _data 186 | ) 187 | { 188 | ((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt32(_data); 189 | } 190 | #endif 191 | 192 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 193 | __DARWIN_OS_INLINE 194 | void 195 | _OSWriteSwapInt64( 196 | volatile void * _base, 197 | uintptr_t _offset, 198 | uint64_t _data 199 | ) 200 | { 201 | ((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt64(_data); 202 | } 203 | #else 204 | __DARWIN_OS_INLINE 205 | void 206 | OSWriteSwapInt64( 207 | volatile void * _base, 208 | uintptr_t _offset, 209 | uint64_t _data 210 | ) 211 | { 212 | ((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt64(_data); 213 | } 214 | #endif 215 | 216 | #endif /* ! _OS_OSBYTEORDERARM_H */ 217 | -------------------------------------------------------------------------------- /magic/apple-include/mach/i386/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2016 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: vm_types.h 61 | * Author: Avadis Tevanian, Jr. 62 | * Date: 1985 63 | * 64 | * Header file for VM data types. I386 version. 65 | */ 66 | 67 | #ifndef _MACH_I386_VM_TYPES_H_ 68 | #define _MACH_I386_VM_TYPES_H_ 69 | 70 | #ifndef ASSEMBLER 71 | 72 | #include 73 | #include 74 | 75 | /* 76 | * natural_t and integer_t are Mach's legacy types for machine- 77 | * independent integer types (unsigned, and signed, respectively). 78 | * Their original purpose was to define other types in a machine/ 79 | * compiler independent way. 80 | * 81 | * They also had an implicit "same size as pointer" characteristic 82 | * to them (i.e. Mach's traditional types are very ILP32 or ILP64 83 | * centric). We support x86 ABIs that do not follow either of 84 | * these models (specifically LP64). Therefore, we had to make a 85 | * choice between making these types scale with pointers or stay 86 | * tied to integers. Because their use is predominantly tied to 87 | * to the size of an integer, we are keeping that association and 88 | * breaking free from pointer size guarantees. 89 | * 90 | * New use of these types is discouraged. 91 | */ 92 | typedef __darwin_natural_t natural_t; 93 | typedef int integer_t; 94 | 95 | /* 96 | * A vm_offset_t is a type-neutral pointer, 97 | * e.g. an offset into a virtual memory space. 98 | */ 99 | #ifdef __LP64__ 100 | typedef uintptr_t vm_offset_t; 101 | #else /* __LP64__ */ 102 | typedef natural_t vm_offset_t; 103 | #endif /* __LP64__ */ 104 | 105 | /* 106 | * A vm_size_t is the proper type for e.g. 107 | * expressing the difference between two 108 | * vm_offset_t entities. 109 | */ 110 | #ifdef __LP64__ 111 | typedef uintptr_t vm_size_t; 112 | #else /* __LP64__ */ 113 | typedef natural_t vm_size_t; 114 | #endif /* __LP64__ */ 115 | 116 | /* 117 | * This new type is independent of a particular vm map's 118 | * implementation size - and represents appropriate types 119 | * for all possible maps. This is used for interfaces 120 | * where the size of the map is not known - or we don't 121 | * want to have to distinguish. 122 | */ 123 | typedef uint64_t mach_vm_address_t; 124 | typedef uint64_t mach_vm_offset_t; 125 | typedef uint64_t mach_vm_size_t; 126 | 127 | typedef uint64_t vm_map_offset_t; 128 | typedef uint64_t vm_map_address_t; 129 | typedef uint64_t vm_map_size_t; 130 | 131 | typedef mach_vm_address_t mach_port_context_t; 132 | 133 | 134 | #endif /* ASSEMBLER */ 135 | 136 | /* 137 | * If composing messages by hand (please do not) 138 | */ 139 | #define MACH_MSG_TYPE_INTEGER_T MACH_MSG_TYPE_INTEGER_32 140 | 141 | #endif /* _MACH_I386_VM_TYPES_H_ */ 142 | -------------------------------------------------------------------------------- /magic/apple-include/i386/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _BSD_I386__TYPES_H_ 29 | #define _BSD_I386__TYPES_H_ 30 | 31 | /* 32 | * This header file contains integer types. It's intended to also contain 33 | * flotaing point and other arithmetic types, as needed, later. 34 | */ 35 | 36 | #ifdef __GNUC__ 37 | typedef __signed char __int8_t; 38 | #else /* !__GNUC__ */ 39 | typedef char __int8_t; 40 | #endif /* !__GNUC__ */ 41 | typedef unsigned char __uint8_t; 42 | typedef short __int16_t; 43 | typedef unsigned short __uint16_t; 44 | typedef int __int32_t; 45 | typedef unsigned int __uint32_t; 46 | #if !defined(__GNU_LIBRARY__) 47 | typedef long long __int64_t; 48 | typedef unsigned long long __uint64_t; 49 | #endif 50 | 51 | typedef long __darwin_intptr_t; 52 | typedef unsigned int __darwin_natural_t; 53 | 54 | /* 55 | * The rune type below is declared to be an ``int'' instead of the more natural 56 | * ``unsigned long'' or ``long''. Two things are happening here. It is not 57 | * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, 58 | * it looks like 10646 will be a 31 bit standard. This means that if your 59 | * ints cannot hold 32 bits, you will be in trouble. The reason an int was 60 | * chosen over a long is that the is*() and to*() routines take ints (says 61 | * ANSI C), but they use __darwin_ct_rune_t instead of int. By changing it 62 | * here, you lose a bit of ANSI conformance, but your programs will still 63 | * work. 64 | * 65 | * NOTE: rune_t is not covered by ANSI nor other standards, and should not 66 | * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and 67 | * rune_t must be the same type. Also wint_t must be no narrower than 68 | * wchar_t, and should also be able to hold all members of the largest 69 | * character set plus one extra value (WEOF). wint_t must be at least 16 bits. 70 | */ 71 | 72 | typedef int __darwin_ct_rune_t; /* ct_rune_t */ 73 | 74 | /* 75 | * mbstate_t is an opaque object to keep conversion state, during multibyte 76 | * stream conversions. The content must not be referenced by user programs. 77 | */ 78 | typedef union { 79 | char __mbstate8[128]; 80 | long long _mbstateL; /* for alignment */ 81 | } ___mbstate_t; 82 | 83 | typedef ___mbstate_t __darwin_mbstate_t; /* mbstate_t */ 84 | 85 | #if defined(__PTRDIFF_TYPE__) 86 | typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 87 | #elif defined(__LP64__) 88 | typedef long __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 89 | #else 90 | typedef int __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 91 | #endif /* __GNUC__ */ 92 | 93 | #if defined(__SIZE_TYPE__) 94 | typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ 95 | #else 96 | typedef unsigned long __darwin_size_t; /* sizeof() */ 97 | #endif 98 | 99 | #if (__GNUC__ > 2) 100 | typedef __builtin_va_list __darwin_va_list; /* va_list */ 101 | #else 102 | typedef void * __darwin_va_list; /* va_list */ 103 | #endif 104 | 105 | #if defined(__WCHAR_TYPE__) 106 | typedef __WCHAR_TYPE__ __darwin_wchar_t; /* wchar_t */ 107 | #else 108 | typedef __darwin_ct_rune_t __darwin_wchar_t; /* wchar_t */ 109 | #endif 110 | 111 | typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 112 | 113 | #if defined(__WINT_TYPE__) 114 | typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 115 | #else 116 | typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */ 117 | #endif 118 | 119 | typedef unsigned long __darwin_clock_t; /* clock() */ 120 | typedef __uint32_t __darwin_socklen_t; /* socklen_t (duh) */ 121 | typedef long __darwin_ssize_t; /* byte count or error */ 122 | typedef long __darwin_time_t; /* time() */ 123 | 124 | #endif /* _BSD_I386__TYPES_H_ */ 125 | -------------------------------------------------------------------------------- /magic/apple-include/mach/i386/fp_reg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1992-1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | #ifndef _I386_FP_SAVE_H_ 60 | #define _I386_FP_SAVE_H_ 61 | 62 | /* 63 | * Control register 64 | */ 65 | #define FPC_IE 0x0001 /* enable invalid operation 66 | * exception */ 67 | #define FPC_IM FPC_IE 68 | #define FPC_DE 0x0002 /* enable denormalized operation 69 | * exception */ 70 | #define FPC_DM FPC_DE 71 | #define FPC_ZE 0x0004 /* enable zero-divide exception */ 72 | #define FPC_ZM FPC_ZE 73 | #define FPC_OE 0x0008 /* enable overflow exception */ 74 | #define FPC_OM FPC_OE 75 | #define FPC_UE 0x0010 /* enable underflow exception */ 76 | #define FPC_PE 0x0020 /* enable precision exception */ 77 | #define FPC_PC 0x0300 /* precision control: */ 78 | #define FPC_PC_24 0x0000 /* 24 bits */ 79 | #define FPC_PC_53 0x0200 /* 53 bits */ 80 | #define FPC_PC_64 0x0300 /* 64 bits */ 81 | #define FPC_RC 0x0c00 /* rounding control: */ 82 | #define FPC_RC_RN 0x0000 /* round to nearest or even */ 83 | #define FPC_RC_RD 0x0400 /* round down */ 84 | #define FPC_RC_RU 0x0800 /* round up */ 85 | #define FPC_RC_CHOP 0x0c00 /* chop */ 86 | #define FPC_IC 0x1000 /* infinity control (obsolete) */ 87 | #define FPC_IC_PROJ 0x0000 /* projective infinity */ 88 | #define FPC_IC_AFF 0x1000 /* affine infinity (std) */ 89 | 90 | /* 91 | * Status register 92 | */ 93 | #define FPS_IE 0x0001 /* invalid operation */ 94 | #define FPS_DE 0x0002 /* denormalized operand */ 95 | #define FPS_ZE 0x0004 /* divide by zero */ 96 | #define FPS_OE 0x0008 /* overflow */ 97 | #define FPS_UE 0x0010 /* underflow */ 98 | #define FPS_PE 0x0020 /* precision */ 99 | #define FPS_SF 0x0040 /* stack flag */ 100 | #define FPS_ES 0x0080 /* error summary */ 101 | #define FPS_C0 0x0100 /* condition code bit 0 */ 102 | #define FPS_C1 0x0200 /* condition code bit 1 */ 103 | #define FPS_C2 0x0400 /* condition code bit 2 */ 104 | #define FPS_TOS 0x3800 /* top-of-stack pointer */ 105 | #define FPS_TOS_SHIFT 11 106 | #define FPS_C3 0x4000 /* condition code bit 3 */ 107 | #define FPS_BUSY 0x8000 /* FPU busy */ 108 | 109 | /* 110 | * Kind of floating-point support provided by kernel. 111 | */ 112 | #define FP_NO 0 /* no floating point */ 113 | #define FP_SOFT 1 /* software FP emulator */ 114 | #define FP_287 2 /* 80287 */ 115 | #define FP_387 3 /* 80387 or 80486 */ 116 | #define FP_FXSR 4 /* Fast save/restore SIMD Extension */ 117 | 118 | #endif /* _I386_FP_SAVE_H_ */ 119 | -------------------------------------------------------------------------------- /magic/apple-include/mach/vm_prot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | /* 59 | * File: mach/vm_prot.h 60 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 61 | * 62 | * Virtual memory protection definitions. 63 | * 64 | */ 65 | 66 | #ifndef _MACH_VM_PROT_H_ 67 | #define _MACH_VM_PROT_H_ 68 | 69 | /* 70 | * Types defined: 71 | * 72 | * vm_prot_t VM protection values. 73 | */ 74 | 75 | typedef int vm_prot_t; 76 | 77 | /* 78 | * Protection values, defined as bits within the vm_prot_t type 79 | */ 80 | 81 | #define VM_PROT_NONE ((vm_prot_t) 0x00) 82 | 83 | #define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */ 84 | #define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */ 85 | #define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */ 86 | 87 | /* 88 | * The default protection for newly-created virtual memory 89 | */ 90 | 91 | #define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE) 92 | 93 | /* 94 | * The maximum privileges possible, for parameter checking. 95 | */ 96 | 97 | #define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) 98 | 99 | /* 100 | * An invalid protection value. 101 | * Used only by memory_object_lock_request to indicate no change 102 | * to page locks. Using -1 here is a bad idea because it 103 | * looks like VM_PROT_ALL and then some. 104 | */ 105 | 106 | #define VM_PROT_NO_CHANGE ((vm_prot_t) 0x08) 107 | 108 | /* 109 | * When a caller finds that he cannot obtain write permission on a 110 | * mapped entry, the following flag can be used. The entry will 111 | * be made "needs copy" effectively copying the object (using COW), 112 | * and write permission will be added to the maximum protections 113 | * for the associated entry. 114 | */ 115 | 116 | #define VM_PROT_COPY ((vm_prot_t) 0x10) 117 | 118 | 119 | /* 120 | * Another invalid protection value. 121 | * Used only by memory_object_data_request upon an object 122 | * which has specified a copy_call copy strategy. It is used 123 | * when the kernel wants a page belonging to a copy of the 124 | * object, and is only asking the object as a result of 125 | * following a shadow chain. This solves the race between pages 126 | * being pushed up by the memory manager and the kernel 127 | * walking down the shadow chain. 128 | */ 129 | 130 | #define VM_PROT_WANTS_COPY ((vm_prot_t) 0x10) 131 | 132 | 133 | /* 134 | * Another invalid protection value. 135 | * Indicates that the other protection bits are to be applied as a mask 136 | * against the actual protection bits of the map entry. 137 | */ 138 | #define VM_PROT_IS_MASK ((vm_prot_t) 0x40) 139 | 140 | /* 141 | * Another invalid protection value to support execute-only protection. 142 | * VM_PROT_STRIP_READ is a special marker that tells mprotect to not 143 | * set VM_PROT_READ. We have to do it this way because existing code 144 | * expects the system to set VM_PROT_READ if VM_PROT_EXECUTE is set. 145 | * VM_PROT_EXECUTE_ONLY is just a convenience value to indicate that 146 | * the memory should be executable and explicitly not readable. It will 147 | * be ignored on platforms that do not support this type of protection. 148 | */ 149 | #define VM_PROT_STRIP_READ ((vm_prot_t) 0x80) 150 | #define VM_PROT_EXECUTE_ONLY (VM_PROT_EXECUTE|VM_PROT_STRIP_READ) 151 | 152 | 153 | #endif /* _MACH_VM_PROT_H_ */ 154 | -------------------------------------------------------------------------------- /magic/apple-include/mach/arm/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: vm_types.h 61 | * Author: Avadis Tevanian, Jr. 62 | * Date: 1985 63 | * 64 | * Header file for VM data types. ARM version. 65 | */ 66 | 67 | #ifndef _MACH_ARM_VM_TYPES_H_ 68 | #define _MACH_ARM_VM_TYPES_H_ 69 | 70 | #ifndef ASSEMBLER 71 | 72 | #include 73 | #include 74 | #include 75 | 76 | /* 77 | * natural_t and integer_t are Mach's legacy types for machine- 78 | * independent integer types (unsigned, and signed, respectively). 79 | * Their original purpose was to define other types in a machine/ 80 | * compiler independent way. 81 | * 82 | * They also had an implicit "same size as pointer" characteristic 83 | * to them (i.e. Mach's traditional types are very ILP32 or ILP64 84 | * centric). We will likely support x86 ABIs that do not follow 85 | * either ofthese models (specifically LP64). Therefore, we had to 86 | * make a choice between making these types scale with pointers or stay 87 | * tied to integers. Because their use is predominantly tied to 88 | * to the size of an integer, we are keeping that association and 89 | * breaking free from pointer size guarantees. 90 | * 91 | * New use of these types is discouraged. 92 | */ 93 | typedef __darwin_natural_t natural_t; 94 | typedef int integer_t; 95 | 96 | /* 97 | * A vm_offset_t is a type-neutral pointer, 98 | * e.g. an offset into a virtual memory space. 99 | */ 100 | #ifdef __LP64__ 101 | typedef uintptr_t vm_offset_t; 102 | typedef uintptr_t vm_size_t; 103 | 104 | typedef uint64_t mach_vm_address_t; 105 | typedef uint64_t mach_vm_offset_t; 106 | typedef uint64_t mach_vm_size_t; 107 | 108 | typedef uint64_t vm_map_offset_t; 109 | typedef uint64_t vm_map_address_t; 110 | typedef uint64_t vm_map_size_t; 111 | #else 112 | typedef natural_t vm_offset_t; 113 | /* 114 | * A vm_size_t is the proper type for e.g. 115 | * expressing the difference between two 116 | * vm_offset_t entities. 117 | */ 118 | typedef natural_t vm_size_t; 119 | 120 | /* 121 | * This new type is independent of a particular vm map's 122 | * implementation size - and represents appropriate types 123 | * for all possible maps. This is used for interfaces 124 | * where the size of the map is not known - or we don't 125 | * want to have to distinguish. 126 | */ 127 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0) 128 | typedef uint32_t mach_vm_address_t; 129 | typedef uint32_t mach_vm_offset_t; 130 | typedef uint32_t mach_vm_size_t; 131 | #else 132 | typedef uint64_t mach_vm_address_t; 133 | typedef uint64_t mach_vm_offset_t; 134 | typedef uint64_t mach_vm_size_t; 135 | #endif 136 | 137 | typedef uint32_t vm_map_offset_t; 138 | typedef uint32_t vm_map_address_t; 139 | typedef uint32_t vm_map_size_t; 140 | #endif /* __LP64__ */ 141 | 142 | 143 | typedef uint32_t vm32_offset_t; 144 | typedef uint32_t vm32_address_t; 145 | typedef uint32_t vm32_size_t; 146 | 147 | typedef vm_offset_t mach_port_context_t; 148 | 149 | 150 | #endif /* ASSEMBLER */ 151 | 152 | /* 153 | * If composing messages by hand (please do not) 154 | */ 155 | #define MACH_MSG_TYPE_INTEGER_T MACH_MSG_TYPE_INTEGER_32 156 | 157 | #endif /* _MACH_ARM_VM_TYPES_H_ */ 158 | -------------------------------------------------------------------------------- /magic/drivers/dt/dtree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | int dt_check(void* mem, uint32_t size, uint32_t* offp) 30 | { 31 | if (size < sizeof(dt_node_t)) 32 | return -1; 33 | dt_node_t* node = mem; 34 | uint32_t off = sizeof(dt_node_t); 35 | for (uint32_t i = 0, max = node->nprop; i < max; ++i) { 36 | if (size < off + sizeof(dt_prop_t)) 37 | return -1; 38 | dt_prop_t* prop = (dt_prop_t*)((uintptr_t)mem + off); 39 | uint32_t l = prop->len & 0xffffff; 40 | off += sizeof(dt_prop_t) + ((l + 0x3) & ~0x3); 41 | if (size < off) 42 | return -1; 43 | } 44 | for (uint32_t i = 0, max = node->nchld; i < max; ++i) { 45 | uint32_t add = 0; 46 | int r = dt_check((void*)((uintptr_t)mem + off), size - off, &add); 47 | if (r != 0) 48 | return r; 49 | off += add; 50 | } 51 | if (offp) 52 | *offp = off; 53 | return 0; 54 | } 55 | 56 | int dt_parse(dt_node_t* node, int depth, uint32_t* offp, int (*cb_node)(void*, dt_node_t*), void* cbn_arg, int (*cb_prop)(void*, dt_node_t*, int, const char*, void*, uint32_t), void* cbp_arg) 57 | { 58 | if (cb_node) { 59 | int r = cb_node(cbn_arg, node); 60 | if (r != 0) 61 | return r; 62 | } 63 | if (depth >= 0 || cb_prop) { 64 | uint32_t off = sizeof(dt_node_t); 65 | for (uint32_t i = 0, max = node->nprop; i < max; ++i) { 66 | dt_prop_t* prop = (dt_prop_t*)((uintptr_t)node + off); 67 | uint32_t l = prop->len & 0xffffff; 68 | off += sizeof(dt_prop_t) + ((l + 0x3) & ~0x3); 69 | if (cb_prop) { 70 | int r = cb_prop(cbp_arg, node, depth, prop->key, prop->val, l); 71 | if (r != 0) 72 | return r; 73 | } 74 | } 75 | if (depth >= 0) { 76 | for (uint32_t i = 0, max = node->nchld; i < max; ++i) { 77 | uint32_t add = 0; 78 | int r = dt_parse((dt_node_t*)((uintptr_t)node + off), depth + 1, &add, cb_node, cbn_arg, cb_prop, cbp_arg); 79 | if (r != 0) 80 | return r; 81 | off += add; 82 | } 83 | if (offp) 84 | *offp = off; 85 | } 86 | } 87 | return 0; 88 | } 89 | 90 | typedef struct 91 | { 92 | const char *name; 93 | dt_node_t *node; 94 | int matchdepth; 95 | } dt_find_cb_t; 96 | 97 | static int dt_find_cb(void *a, dt_node_t *node, int depth, const char *key, void *val, uint32_t len) 98 | { 99 | dt_find_cb_t *arg = a; 100 | if(strcmp(key, "name") != 0) 101 | { 102 | return 0; 103 | } 104 | const char *name = arg->name; 105 | if(name[0] == '/') // Absolute path 106 | { 107 | // If we ever get here, we traversed back out of an entry that 108 | // we matched against, without finding a matching child node. 109 | if(depth < arg->matchdepth) 110 | { 111 | return -1; 112 | } 113 | ++name; 114 | const char *end = strchr(name, '/'); 115 | if(end) // Handle non-leaf segment 116 | { 117 | size_t size = end - name; 118 | if(strncmp(name, val, size) == 0 && size + 1 == len && ((const char*)val)[size] == '\0') 119 | { 120 | arg->name = end; 121 | ++arg->matchdepth; 122 | } 123 | return 0; 124 | } 125 | // Leaf segment can fall through 126 | } 127 | // Simple name 128 | if(strncmp(name, val, len) == 0 && strlen(name) + 1 == len) 129 | { 130 | arg->node = node; 131 | return 1; 132 | } 133 | return 0; 134 | } 135 | 136 | dt_node_t* dt_find(dt_node_t *node, const char *name) 137 | { 138 | dt_find_cb_t arg = { name, NULL, 0 }; 139 | dt_parse(node, 0, NULL, NULL, NULL, &dt_find_cb, &arg); 140 | return arg.node; 141 | } 142 | 143 | typedef struct 144 | { 145 | const char *key; 146 | void *val; 147 | size_t len; 148 | } dt_prop_cb_t; 149 | 150 | static int dt_prop_cb(void *a, dt_node_t *node, int depth, const char *key, void *val, uint32_t len) 151 | { 152 | dt_prop_cb_t *arg = a; 153 | if(strcmp(arg->key, key) == 0) 154 | { 155 | arg->val = val; 156 | arg->len = len; 157 | return 1; 158 | } 159 | return 0; 160 | } 161 | 162 | void* dt_prop(dt_node_t *node, const char *key, uint32_t *lenp) 163 | { 164 | dt_prop_cb_t arg = { key, NULL, 0 }; 165 | dt_parse(node, -1, NULL, NULL, NULL, &dt_prop_cb, &arg); 166 | if(arg.val && lenp) *lenp = arg.len; 167 | return arg.val; 168 | } 169 | 170 | static int dt_find_memmap_cb(void* a, dt_node_t* node, int depth, const char* key, void* val, uint32_t len) 171 | { 172 | if ((key[0] == 'M' && key[1] == 'e' && key[9] == 'R' && key[10] == 'e') || (strcmp(*(void**)a, "RAMDisk") == 0)) { 173 | strcpy((char*)key, *(void**)a); 174 | *(void**)a = val; 175 | return 1; 176 | } 177 | return 0; 178 | } 179 | 180 | struct memmap* dt_alloc_memmap(dt_node_t* node, const char* name) 181 | { 182 | void* val = (void*)name; 183 | dt_parse(node, -1, NULL, NULL, NULL, &dt_find_memmap_cb, &val); 184 | if (val == name) 185 | return NULL; 186 | return val; 187 | } 188 | -------------------------------------------------------------------------------- /magic/drivers/xnu/xnu.s: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | .text 28 | .globl _pf_jit_iter_loop_head_start 29 | .globl _pf_jit_iter_loop_head_end 30 | .globl _pf_jit_iter_loop_head_load32_start 31 | .globl _pf_jit_iter_loop_head_load32_end 32 | .globl _pf_jit_iter_loop_iter_load32_start 33 | .globl _pf_jit_iter_loop_iter_load32_end 34 | .globl _pf_jit_iter_loop_head_load64_start 35 | .globl _pf_jit_iter_loop_head_load64_end 36 | .globl _pf_jit_iter_loop_iter_load64_start 37 | .globl _pf_jit_iter_loop_iter_load64_end 38 | .globl _pf_jit_iter_loop_end_start 39 | .globl _pf_jit_iter_loop_end_end 40 | 41 | .globl _pf_jit_absolute_branch_start 42 | .globl _pf_jit_absolute_branch_end 43 | 44 | .align 3 45 | _pf_jit_iter_loop_head_start: 46 | sub sp, sp, #0x60 47 | stp x20, x21, [sp] 48 | stp x22, x23, [sp,#0x10] 49 | stp x24, x25, [sp,#0x20] 50 | stp x26, x27, [sp,#0x30] 51 | stp x28, x29, [sp,#0x40] 52 | stp x30, x19, [sp,#0x50] 53 | mov x19, x0 54 | mov x28, x1 55 | .align 3 56 | _pf_jit_iter_loop_head_end: 57 | 58 | .align 3 59 | _pf_jit_absolute_branch_start: 60 | adr x1, _pf_jit_absolute_branch_end 61 | ldr x1, [x1] 62 | br x1 63 | .align 3 64 | _pf_jit_absolute_branch_end: 65 | 66 | .globl _pf_jit_iter_loop_iter_load8_start 67 | .globl _pf_jit_iter_loop_iter_load8_end 68 | .globl _pf_jit_iter_loop_head_load8_start 69 | .globl _pf_jit_iter_loop_head_load8_end 70 | 71 | .align 3 72 | _pf_jit_iter_loop_head_load8_start: 73 | mov x29, #0x8 // 8 bit 74 | ldrb w20, [x19], #1 75 | ldrb w21, [x19], #1 76 | ldrb w22, [x19], #1 77 | ldrb w23, [x19], #1 78 | ldrb w24, [x19], #1 79 | ldrb w25, [x19], #1 80 | ldrb w26, [x19], #1 81 | ldrb w27, [x19], #1 82 | cmp x19, x28 83 | b.lo Lnext81 84 | _pf_jit_iter_loop_head_load8_end: 85 | nop 86 | Lnext81: 87 | 88 | .align 3 89 | _pf_jit_iter_loop_iter_load8_start: 90 | mov w20, w21 91 | mov w21, w22 92 | mov w22, w23 93 | mov w23, w24 94 | mov w24, w25 95 | mov w25, w26 96 | mov w26, w27 97 | ldrb w27, [x19], #1 98 | cmp x19, x28 99 | b.hi Lnext82 100 | _pf_jit_iter_loop_iter_load8_end: 101 | nop 102 | Lnext82: 103 | 104 | .globl _pf_jit_iter_loop_iter_load16_start 105 | .globl _pf_jit_iter_loop_iter_load16_end 106 | .globl _pf_jit_iter_loop_head_load16_start 107 | .globl _pf_jit_iter_loop_head_load16_end 108 | 109 | .align 3 110 | _pf_jit_iter_loop_head_load16_start: 111 | mov x29, #0x10 // 16 bit 112 | ldrh w20, [x19], #2 113 | ldrh w21, [x19], #2 114 | ldrh w22, [x19], #2 115 | ldrh w23, [x19], #2 116 | ldrh w24, [x19], #2 117 | ldrh w25, [x19], #2 118 | ldrh w26, [x19], #2 119 | ldrh w27, [x19], #2 120 | cmp x19, x28 121 | b.lo Lnext161 122 | _pf_jit_iter_loop_head_load16_end: 123 | nop 124 | Lnext161: 125 | 126 | .align 3 127 | _pf_jit_iter_loop_iter_load16_start: 128 | mov w20, w21 129 | mov w21, w22 130 | mov w22, w23 131 | mov w23, w24 132 | mov w24, w25 133 | mov w25, w26 134 | mov w26, w27 135 | ldrh w27, [x19], #2 136 | cmp x19, x28 137 | b.hi Lnext162 138 | _pf_jit_iter_loop_iter_load16_end: 139 | nop 140 | Lnext162: 141 | 142 | .align 3 143 | _pf_jit_iter_loop_head_load32_start: 144 | mov x29, #0x20 // 32 bit 145 | ldr w20, [x19], #4 146 | ldr w21, [x19], #4 147 | ldr w22, [x19], #4 148 | ldr w23, [x19], #4 149 | ldr w24, [x19], #4 150 | ldr w25, [x19], #4 151 | ldr w26, [x19], #4 152 | ldr w27, [x19], #4 153 | cmp x19, x28 154 | b.lo Lnext1 155 | _pf_jit_iter_loop_head_load32_end: 156 | nop 157 | Lnext1: 158 | 159 | .align 3 160 | _pf_jit_iter_loop_iter_load32_start: 161 | mov w20, w21 162 | mov w21, w22 163 | mov w22, w23 164 | mov w23, w24 165 | mov w24, w25 166 | mov w25, w26 167 | mov w26, w27 168 | ldr w27, [x19], #4 169 | cmp x19, x28 170 | b.hi Lnext2 171 | _pf_jit_iter_loop_iter_load32_end: 172 | nop 173 | Lnext2: 174 | 175 | .align 3 176 | _pf_jit_iter_loop_head_load64_start: 177 | mov x29, #0x40 // 64 bit 178 | ldr x20, [x19], #8 179 | ldr x21, [x19], #8 180 | ldr x22, [x19], #8 181 | ldr x23, [x19], #8 182 | ldr x24, [x19], #8 183 | ldr x25, [x19], #8 184 | ldr x26, [x19], #8 185 | ldr x27, [x19], #8 186 | cmp x19, x28 187 | b.lo Lnext3 188 | _pf_jit_iter_loop_head_load64_end: 189 | nop 190 | Lnext3: 191 | 192 | .align 3 193 | _pf_jit_iter_loop_iter_load64_start: 194 | mov x20, x21 195 | mov x21, x22 196 | mov x22, x23 197 | mov x23, x24 198 | mov x24, x25 199 | mov x25, x26 200 | mov x26, x27 201 | ldr x27, [x19], #8 202 | cmp x19, x28 203 | b.hi Lnext4 204 | _pf_jit_iter_loop_iter_load64_end: 205 | nop 206 | Lnext4: 207 | 208 | .align 3 209 | _pf_jit_iter_loop_end_start: 210 | ldp x20, x21, [sp] 211 | ldp x22, x23, [sp,#0x10] 212 | ldp x24, x25, [sp,#0x20] 213 | ldp x26, x27, [sp,#0x30] 214 | ldp x28, x29, [sp,#0x40] 215 | ldp x30, x19, [sp,#0x50] 216 | add sp, sp, #0x60 217 | ret 218 | .align 3 219 | _pf_jit_iter_loop_end_end: 220 | 221 | 222 | .globl _pf_jit_ptr_comparison_start 223 | .globl _pf_jit_ptr_comparison_end 224 | 225 | .align 3 226 | _pf_jit_ptr_comparison_start: 227 | orr x8, x20, x2 228 | add x8, x8, x3 229 | cmp x8, x0 230 | b.lo _pf_jit_ptr_comparison_next 231 | cmp x8, x1 232 | b.hi _pf_jit_ptr_comparison_next 233 | ldr x0, _pf_jit_ptr_comparison_patch 234 | mov w1, w29 235 | sub x2, x19, #0x40 236 | mov x3, x2 237 | ldr x4, _pf_jit_ptr_comparison_slowpath 238 | blr x4 239 | b _pf_jit_ptr_comparison_next 240 | .align 3 241 | _pf_jit_ptr_comparison_end: 242 | 243 | _pf_jit_ptr_comparison_patch: 244 | .quad 0x4141414142424200 245 | _pf_jit_ptr_comparison_slowpath: 246 | .quad 0x4141414142424201 247 | _pf_jit_ptr_comparison_next: 248 | 249 | 250 | .globl _pf_jit_slowpath_start 251 | .globl _pf_jit_slowpath_end 252 | .globl _pf_jit_slowpath_next 253 | 254 | .align 3 255 | _pf_jit_slowpath_start: 256 | ldr x0, _pf_jit_slowpath_patch 257 | mov w1, w29 258 | sub x2, x19, x29 259 | mov x3, x2 260 | ldr x4, _pf_jit_slowpath_slowpath 261 | blr x4 262 | nop 263 | nop 264 | nop 265 | nop 266 | b _pf_jit_slowpath_next 267 | .align 3 268 | _pf_jit_slowpath_end: 269 | 270 | _pf_jit_slowpath_patch: 271 | .quad 0x4141414142424200 272 | _pf_jit_slowpath_slowpath: 273 | .quad 0x4141414142424201 274 | _pf_jit_slowpath_next: 275 | 276 | 277 | .globl _pf_jit_ptr_comparison_next 278 | -------------------------------------------------------------------------------- /magic/apple-include/AvailabilityVersions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 by Apple Inc.. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef __AVAILABILITY_VERSIONS__ 25 | #define __AVAILABILITY_VERSIONS__ 26 | 27 | #define __MAC_10_0 1000 28 | #define __MAC_10_1 1010 29 | #define __MAC_10_2 1020 30 | #define __MAC_10_3 1030 31 | #define __MAC_10_4 1040 32 | #define __MAC_10_5 1050 33 | #define __MAC_10_6 1060 34 | #define __MAC_10_7 1070 35 | #define __MAC_10_8 1080 36 | #define __MAC_10_9 1090 37 | #define __MAC_10_10 101000 38 | #define __MAC_10_10_2 101002 39 | #define __MAC_10_10_3 101003 40 | #define __MAC_10_11 101100 41 | #define __MAC_10_11_2 101102 42 | #define __MAC_10_11_3 101103 43 | #define __MAC_10_11_4 101104 44 | #define __MAC_10_12 101200 45 | #define __MAC_10_12_1 101201 46 | #define __MAC_10_12_2 101202 47 | #define __MAC_10_12_4 101204 48 | #define __MAC_10_13 101300 49 | #define __MAC_10_13_1 101301 50 | #define __MAC_10_13_2 101302 51 | #define __MAC_10_13_4 101304 52 | #define __MAC_10_14 101400 53 | #define __MAC_10_14_1 101401 54 | #define __MAC_10_14_4 101404 55 | #define __MAC_10_14_6 101406 56 | #define __MAC_10_15 101500 57 | #define __MAC_10_15_1 101501 58 | #define __MAC_10_15_4 101504 59 | #define __MAC_10_16 101600 60 | #define __MAC_11_0 110000 61 | #define __MAC_11_1 110100 62 | /* __MAC_NA is not defined to a value but is used as a token by macros to indicate that the API is unavailable */ 63 | 64 | #define __IPHONE_2_0 20000 65 | #define __IPHONE_2_1 20100 66 | #define __IPHONE_2_2 20200 67 | #define __IPHONE_3_0 30000 68 | #define __IPHONE_3_1 30100 69 | #define __IPHONE_3_2 30200 70 | #define __IPHONE_4_0 40000 71 | #define __IPHONE_4_1 40100 72 | #define __IPHONE_4_2 40200 73 | #define __IPHONE_4_3 40300 74 | #define __IPHONE_5_0 50000 75 | #define __IPHONE_5_1 50100 76 | #define __IPHONE_6_0 60000 77 | #define __IPHONE_6_1 60100 78 | #define __IPHONE_7_0 70000 79 | #define __IPHONE_7_1 70100 80 | #define __IPHONE_8_0 80000 81 | #define __IPHONE_8_1 80100 82 | #define __IPHONE_8_2 80200 83 | #define __IPHONE_8_3 80300 84 | #define __IPHONE_8_4 80400 85 | #define __IPHONE_9_0 90000 86 | #define __IPHONE_9_1 90100 87 | #define __IPHONE_9_2 90200 88 | #define __IPHONE_9_3 90300 89 | #define __IPHONE_10_0 100000 90 | #define __IPHONE_10_1 100100 91 | #define __IPHONE_10_2 100200 92 | #define __IPHONE_10_3 100300 93 | #define __IPHONE_11_0 110000 94 | #define __IPHONE_11_1 110100 95 | #define __IPHONE_11_2 110200 96 | #define __IPHONE_11_3 110300 97 | #define __IPHONE_11_4 110400 98 | #define __IPHONE_12_0 120000 99 | #define __IPHONE_12_1 120100 100 | #define __IPHONE_12_2 120200 101 | #define __IPHONE_12_3 120300 102 | #define __IPHONE_12_4 120400 103 | #define __IPHONE_13_0 130000 104 | #define __IPHONE_13_1 130100 105 | #define __IPHONE_13_2 130200 106 | #define __IPHONE_13_3 130300 107 | #define __IPHONE_13_4 130400 108 | #define __IPHONE_13_5 130500 109 | #define __IPHONE_13_6 130600 110 | #define __IPHONE_13_7 130700 111 | #define __IPHONE_14_0 140000 112 | #define __IPHONE_14_1 140100 113 | #define __IPHONE_14_2 140200 114 | #define __IPHONE_14_3 140300 115 | /* __IPHONE_NA is not defined to a value but is used as a token by macros to indicate that the API is unavailable */ 116 | 117 | #define __TVOS_9_0 90000 118 | #define __TVOS_9_1 90100 119 | #define __TVOS_9_2 90200 120 | #define __TVOS_10_0 100000 121 | #define __TVOS_10_0_1 100001 122 | #define __TVOS_10_1 100100 123 | #define __TVOS_10_2 100200 124 | #define __TVOS_11_0 110000 125 | #define __TVOS_11_1 110100 126 | #define __TVOS_11_2 110200 127 | #define __TVOS_11_3 110300 128 | #define __TVOS_11_4 110400 129 | #define __TVOS_12_0 120000 130 | #define __TVOS_12_1 120100 131 | #define __TVOS_12_2 120200 132 | #define __TVOS_12_3 120300 133 | #define __TVOS_12_4 120400 134 | #define __TVOS_13_0 130000 135 | #define __TVOS_13_2 130200 136 | #define __TVOS_13_3 130300 137 | #define __TVOS_13_4 130400 138 | #define __TVOS_14_0 140000 139 | #define __TVOS_14_1 140100 140 | #define __TVOS_14_2 140200 141 | #define __TVOS_14_3 140300 142 | 143 | #define __WATCHOS_1_0 10000 144 | #define __WATCHOS_2_0 20000 145 | #define __WATCHOS_2_1 20100 146 | #define __WATCHOS_2_2 20200 147 | #define __WATCHOS_3_0 30000 148 | #define __WATCHOS_3_1 30100 149 | #define __WATCHOS_3_1_1 30101 150 | #define __WATCHOS_3_2 30200 151 | #define __WATCHOS_4_0 40000 152 | #define __WATCHOS_4_1 40100 153 | #define __WATCHOS_4_2 40200 154 | #define __WATCHOS_4_3 40300 155 | #define __WATCHOS_5_0 50000 156 | #define __WATCHOS_5_1 50100 157 | #define __WATCHOS_5_2 50200 158 | #define __WATCHOS_5_3 50300 159 | #define __WATCHOS_6_0 60000 160 | #define __WATCHOS_6_1 60100 161 | #define __WATCHOS_6_2 60200 162 | #define __WATCHOS_7_0 70000 163 | #define __WATCHOS_7_1 70100 164 | #define __WATCHOS_7_2 70200 165 | 166 | /* 167 | * Set up standard Mac OS X versions 168 | */ 169 | 170 | #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) 171 | 172 | #define MAC_OS_X_VERSION_10_0 1000 173 | #define MAC_OS_X_VERSION_10_1 1010 174 | #define MAC_OS_X_VERSION_10_2 1020 175 | #define MAC_OS_X_VERSION_10_3 1030 176 | #define MAC_OS_X_VERSION_10_4 1040 177 | #define MAC_OS_X_VERSION_10_5 1050 178 | #define MAC_OS_X_VERSION_10_6 1060 179 | #define MAC_OS_X_VERSION_10_7 1070 180 | #define MAC_OS_X_VERSION_10_8 1080 181 | #define MAC_OS_X_VERSION_10_9 1090 182 | #define MAC_OS_X_VERSION_10_10 101000 183 | #define MAC_OS_X_VERSION_10_10_2 101002 184 | #define MAC_OS_X_VERSION_10_10_3 101003 185 | #define MAC_OS_X_VERSION_10_11 101100 186 | #define MAC_OS_X_VERSION_10_11_2 101102 187 | #define MAC_OS_X_VERSION_10_11_3 101103 188 | #define MAC_OS_X_VERSION_10_11_4 101104 189 | #define MAC_OS_X_VERSION_10_12 101200 190 | #define MAC_OS_X_VERSION_10_12_1 101201 191 | #define MAC_OS_X_VERSION_10_12_2 101202 192 | #define MAC_OS_X_VERSION_10_12_4 101204 193 | #define MAC_OS_X_VERSION_10_13 101300 194 | #define MAC_OS_X_VERSION_10_13_1 101301 195 | #define MAC_OS_X_VERSION_10_13_2 101302 196 | #define MAC_OS_X_VERSION_10_13_4 101304 197 | #define MAC_OS_X_VERSION_10_14 101400 198 | #define MAC_OS_X_VERSION_10_14_1 101401 199 | #define MAC_OS_X_VERSION_10_14_4 101404 200 | #define MAC_OS_X_VERSION_10_14_6 101406 201 | #define MAC_OS_X_VERSION_10_15 101500 202 | #define MAC_OS_X_VERSION_10_15_1 101501 203 | #define MAC_OS_X_VERSION_10_16 101600 204 | #define MAC_OS_VERSION_11_0 110000 205 | 206 | #endif /* #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) */ 207 | 208 | #define __DRIVERKIT_19_0 190000 209 | #define __DRIVERKIT_20_0 200000 210 | 211 | #endif /* __AVAILABILITY_VERSIONS__ */ 212 | 213 | -------------------------------------------------------------------------------- /magic/payload.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void kpf(void); 9 | 10 | int payload(int argc, struct cmd_arg *args) 11 | { 12 | 13 | return 0; 14 | } 15 | 16 | 17 | boot_args *gBootArgs; 18 | void *gEntryPoint; 19 | dt_node_t *gDeviceTree; 20 | uint64_t gIOBase; 21 | uint64_t gWDTBase; 22 | 23 | #define WDT_CHIP_TMR (*(volatile uint32_t*)(gWDTBase + 0x0)) 24 | #define WDT_CHIP_RST (*(volatile uint32_t*)(gWDTBase + 0x4)) 25 | #define WDT_CHIP_INT (*(volatile uint32_t*)(gWDTBase + 0x8)) 26 | #define WDT_CHIP_CTL (*(volatile uint32_t*)(gWDTBase + 0xc)) 27 | 28 | #define WDT_SYS_TMR (*(volatile uint32_t*)(gWDTBase + 0x10)) 29 | #define WDT_SYS_RST (*(volatile uint32_t*)(gWDTBase + 0x14)) 30 | #define WDT_SYS_CTL (*(volatile uint32_t*)(gWDTBase + 0x1c)) 31 | 32 | uint64_t ttb_alloc_base; 33 | uint32_t* ppage_list; 34 | uint64_t ppages = 0; 35 | uint64_t free_pages = 0; 36 | uint64_t wired_pages = 0; 37 | 38 | #define PAGE_FREE 0 39 | #define PAGE_WIRED 0xffffff 40 | #define PAGE_REFBITS 0xffffff 41 | 42 | static uint64_t iboot_base; 43 | 44 | static int iboot_init(uint16_t cpid) 45 | { 46 | if(cpid == 0x8015) 47 | iboot_base = 0x18001c000; 48 | else if(cpid == 0x8011) 49 | iboot_base = 0x1800b0000; 50 | else if(cpid == 0x8010) 51 | iboot_base = 0x1800b0000; 52 | else 53 | return -1; 54 | 55 | uint8_t* idata = (uint8_t*)(iboot_base); 56 | size_t isize = *(uint64_t *)(idata + 0x308) - iboot_base; 57 | 58 | /*-- offsetfinder --*/ 59 | uint64_t func_printf = find_printf(iboot_base, idata, isize); 60 | if(!func_printf) 61 | return -1; 62 | func_printf += iboot_base; 63 | 64 | uint64_t func_jumpto = find_jumpto_func(iboot_base, idata, isize); 65 | if(!func_jumpto) 66 | return -1; 67 | func_jumpto += iboot_base; 68 | 69 | uint64_t func_malloc = find_malloc(iboot_base, idata, isize); 70 | if(!func_malloc) 71 | return -1; 72 | func_malloc += iboot_base; 73 | 74 | uint64_t func_panic = find_panic(iboot_base, idata, isize); 75 | if(!func_panic) 76 | return -1; 77 | func_panic += iboot_base; 78 | 79 | uint64_t func_free = find_free(iboot_base, idata, isize); 80 | if(!func_free) 81 | return -1; 82 | func_free += iboot_base; 83 | 84 | iprintf = (printf_t)func_printf; 85 | jumpto = (jumpto_t)func_jumpto; 86 | imalloc = (malloc_t)func_malloc; 87 | panic = (panic_t)func_panic; 88 | ifree = (free_t)func_free; 89 | 90 | return 0; 91 | } 92 | 93 | 94 | extern void enable_interrupts(); 95 | extern void disable_interrupts(); 96 | uint64_t pa_head; 97 | // hacky haxx 98 | uint64_t vatophys_static(void* kva) { 99 | return (((uint64_t)kva)); 100 | } 101 | 102 | void* phystokv(uint64_t paddr) { 103 | return (void*)(paddr); 104 | } 105 | 106 | void phys_page_was_freed(uint64_t pa) { 107 | disable_interrupts(); 108 | uint64_t* pa_v = phystokv(pa); 109 | if (pa_head) { 110 | uint64_t* pa_head_v = phystokv(pa_head); 111 | pa_head_v[1] = pa; // head->prev = new 112 | } 113 | pa_v[0] = pa_head; // new->next = head 114 | pa_v[1] = 0; // new->prev == null 115 | pa_head = pa; // head = new 116 | free_pages ++; 117 | enable_interrupts(); 118 | } 119 | 120 | void phys_force_free(uint64_t pa, uint64_t size) { 121 | pa -= gBootArgs->physBase; 122 | 123 | uint64_t fpages = size >> 14; 124 | if (pa & 0x3fff) panic("phys_force_free only works with aligned PAs"); 125 | pa >>= 14; 126 | 127 | disable_interrupts(); 128 | for (uint64_t i=pa; i < pa+fpages; i++) { 129 | if (i > ppages) panic("OOB phys_force_free: 0x%llx", i << 14ULL); 130 | if ((ppage_list[i] & PAGE_REFBITS) == PAGE_WIRED) { 131 | wired_pages--; 132 | } 133 | if ((ppage_list[i] & PAGE_REFBITS) != PAGE_FREE) { 134 | phys_page_was_freed((i << 14ULL) + gBootArgs->physBase); 135 | } 136 | ppage_list[i] = PAGE_FREE; 137 | } 138 | enable_interrupts(); 139 | } 140 | 141 | uint64_t overlay_base_address; 142 | extern uint64_t OVERLAY_DATA; 143 | extern uint64_t OVERLAY_SIZE; 144 | 145 | void payload_entry(uint64_t *kernel_args, void *entryp) 146 | { 147 | 148 | gBootArgs = (boot_args*)kernel_args; 149 | gEntryPoint = entryp; 150 | 151 | gDeviceTree = (void*)((uint64_t)gBootArgs->deviceTreeP - gBootArgs->virtBase + gBootArgs->physBase); 152 | 153 | printf("entryp: %016llx: %08x\n", (uint64_t)entryp, *(uint32_t*)entryp); 154 | printf("virtBase: %016llx\n", gBootArgs->virtBase); 155 | printf("physBase: %016llx\n", gBootArgs->physBase); 156 | 157 | screen_init(); 158 | 159 | puts(""); 160 | puts("#=================="); 161 | puts("#"); 162 | printf("# kok3shiOS %s\n", KOKESHI_VERSION); 163 | puts("#"); 164 | puts("# https://dora2ios.web.app/kokeshi16"); 165 | puts("#"); 166 | puts("#==== Made by ==="); 167 | puts("# dora2ios"); 168 | puts("#==== Thanks to ==="); 169 | puts("# checkra1n team"); 170 | puts("#=================="); 171 | screen_mark_banner(); 172 | 173 | printf("Booted by: %s\n", (const char*)dt_get_prop("chosen", "firmware-version", NULL)); 174 | //strcpy(dt_get_prop("chosen", "firmware-version", NULL), "kok3shiOS-"); 175 | //strcat(dt_get_prop("chosen", "firmware-version", NULL), KOKESHI_VERSION); 176 | 177 | #ifdef __clang__ 178 | printf("Built with: Clang %s\n", __clang_version__); 179 | #else 180 | printf("Built with: GCC %s\n", __VERSION__); 181 | #endif 182 | 183 | gIOBase = dt_get_u64_prop_i("arm-io", "ranges", 1); 184 | gWDTBase = gIOBase + dt_get_u64_prop("wdt", "reg"); 185 | WDT_CHIP_CTL = 0x0; // Disable WDT 186 | WDT_SYS_CTL = 0x0; // Disable WDT 187 | 188 | // // alloc_init 189 | // int tt_bits = 11; // 16k 190 | // uint64_t pgsz = 1ULL << (tt_bits + 3); 191 | // ttb_alloc_base = (gBootArgs->physBase + gBootArgs->memSize) & ~(pgsz-1); 192 | // printf("ttb_alloc_base: %016llx\n", ttb_alloc_base); 193 | // 194 | // uint64_t memory_size = gBootArgs->memSize; 195 | // ppages = memory_size >> 14; 196 | // uint64_t early_heap = ttb_alloc_base; 197 | // 198 | // early_heap = (early_heap - 4 * ppages) & ~0x3fffULL; 199 | // ppage_list = (uint32_t*)early_heap; 200 | // for (uint64_t i = 0; i < ppages; i++) { 201 | // wired_pages++; 202 | // ppage_list[i] = PAGE_WIRED; // wire all pages, carve out later. 203 | // } 204 | // uint64_t alloc_heap_base = ((gBootArgs->topOfKernelData) + 0x3fffULL) & ~0x3fffULL; 205 | // uint64_t alloc_heap_end = early_heap; 206 | // phys_force_free(vatophys_static((void*)alloc_heap_base), alloc_heap_end - alloc_heap_base); 207 | // 208 | // // alloc static 209 | // size_t size = (OVERLAY_SIZE + 0x3fffULL) & ~0x3fffULL; 210 | // disable_interrupts(); 211 | // uint64_t base = (gBootArgs->topOfKernelData + 0x3fffULL) & ~0x3fffULL; 212 | // uint32_t idx = (base - gBootArgs->physBase) >> 14; 213 | // for (uint32_t i = 0; i < (size >> 14); ++i) { 214 | // if (ppage_list[idx + i] != PAGE_FREE) { 215 | // panic("alloc_static: ran out of static region"); 216 | // } 217 | // ppage_list[idx + i] = PAGE_WIRED; 218 | // wired_pages++; 219 | // } 220 | // gBootArgs->topOfKernelData = base + size; 221 | // overlay_base_address = base; 222 | // enable_interrupts(); 223 | // 224 | // memcpy((void*)overlay_base_address, (void*)OVERLAY_DATA, OVERLAY_SIZE); 225 | 226 | kpf(); 227 | 228 | printf("old bootArgs: %s\n", gBootArgs->CommandLine); 229 | memcpy((void*)gBootArgs->CommandLine, "rootdev=md0 serial=3 wdt=-1\x00", sizeof("rootdev=md0 serial=3 wdt=-1\x00")); 230 | printf("new bootArgs: %s\n", gBootArgs->CommandLine); 231 | 232 | } 233 | 234 | extern uint64_t CHIP; 235 | int jump_hook(void* boot_image, void* boot_args) 236 | { 237 | uint16_t cpid = (uint16_t)CHIP; 238 | if(iboot_init(cpid)) 239 | return -1; 240 | 241 | if (*(uint8_t*)(boot_args + 8 + 7)) { 242 | // kernel 243 | payload_entry((uint64_t*)boot_args, boot_image); 244 | } else { 245 | // hypv 246 | payload_entry(*(uint64_t**)(boot_args + 0x20), (void*)*(uint64_t*)(boot_args + 0x28)); 247 | } 248 | 249 | puts("Booting..."); 250 | 251 | return jumpto(boot_image, boot_args); 252 | } 253 | 254 | int main(void) 255 | { 256 | return 0; 257 | } 258 | -------------------------------------------------------------------------------- /iboot/ibootpatch2/ibootpatch2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "asm/shellcode.h" 8 | 9 | #define INSN_MOV_X0_0 0xd2800000 10 | #define INSN_MOV_X0_1 0xd2800020 11 | #define INSN_RET 0xd65f03c0 12 | #define INSN_NOP 0xd503201f 13 | 14 | #ifndef TESTBUILD 15 | #define LOG(x, ...) 16 | #define ERR(x, ...) 17 | #define DEVLOG(x, ...) 18 | #else 19 | #define LOG(x, ...) \ 20 | do { \ 21 | printf("[LOG] "x"\n", ##__VA_ARGS__); \ 22 | } while(0) 23 | 24 | #define ERR(x, ...) \ 25 | do { \ 26 | printf("[ERR] "x"\n", ##__VA_ARGS__); \ 27 | } while(0) 28 | #ifdef DEVBUILD 29 | #define DEVLOG(x, ...) \ 30 | do { \ 31 | printf("[DEV] "x"\n", ##__VA_ARGS__); \ 32 | } while(0) 33 | #else 34 | #define DEVLOG(x, ...) 35 | #endif 36 | #endif 37 | 38 | #define sub (0x000200000) 39 | #define overlay (0x000100000) 40 | typedef int (*jump_t)(void* arg0, void* arg1); 41 | 42 | void patch_iboot(uint64_t iboot_base, void* idata, size_t isize, 43 | uint64_t sdram_page, uint64_t load_address) 44 | 45 | { 46 | // find iboot 47 | LOG("---- offsetfinder: start ----"); 48 | 49 | 50 | uint64_t sigcheck = find_sigcheck(iboot_base, idata, isize); 51 | if(!sigcheck) { 52 | ERR("Failed to find sigcheck"); 53 | goto end; 54 | } 55 | DEVLOG("%016llx[%016llx]: sigcheck", sigcheck + iboot_base, sigcheck); 56 | 57 | 58 | uint64_t boot_manifest_validation = find_boot_manifest_validation(iboot_base, idata, isize); 59 | if(!boot_manifest_validation) { 60 | ERR("Failed to find boot_manifest_validation"); 61 | goto end; 62 | } 63 | DEVLOG("%016llx[%016llx]: boot_manifest_validation", boot_manifest_validation + iboot_base, boot_manifest_validation); 64 | 65 | 66 | uint64_t check_bootmode = find_check_bootmode(iboot_base, idata, isize); 67 | if(!check_bootmode) { 68 | ERR("Failed to find check_bootmode"); 69 | goto end; 70 | } 71 | DEVLOG("%016llx[%016llx]: check_bootmode", check_bootmode + iboot_base, check_bootmode); 72 | 73 | 74 | uint64_t zero_region = find_zero(iboot_base, idata, isize); 75 | if(!zero_region) { 76 | ERR("Failed to find zero_region"); 77 | goto end; 78 | } 79 | DEVLOG("%016llx[%016llx]: zero_region", zero_region + iboot_base, zero_region); 80 | 81 | 82 | uint64_t go_cmd_handler = find_go_cmd_handler(iboot_base, idata, isize); 83 | if(!go_cmd_handler) { 84 | ERR("Failed to find go_cmd_handler"); 85 | goto end; 86 | } 87 | DEVLOG("%016llx[%016llx]: go_cmd_handler", go_cmd_handler + iboot_base, go_cmd_handler); 88 | 89 | 90 | uint64_t bootx_cmd_handler = find_bootx_cmd_handler(iboot_base, idata, isize); 91 | if(!bootx_cmd_handler) { 92 | ERR("Failed to find bootx_cmd_handler"); 93 | goto end; 94 | } 95 | DEVLOG("%016llx[%016llx]: bootx_cmd_handler", bootx_cmd_handler + iboot_base, bootx_cmd_handler); 96 | 97 | 98 | uint64_t reset_cmd_handler = find_reset_cmd_handler(iboot_base, idata, isize); 99 | if(!reset_cmd_handler) { 100 | ERR("Failed to find reset_cmd_handler"); 101 | goto end; 102 | } 103 | DEVLOG("%016llx[%016llx]: reset_cmd_handler", reset_cmd_handler + iboot_base, reset_cmd_handler); 104 | 105 | 106 | uint64_t _mount_and_boot_system = find_mount_and_boot_system(iboot_base, idata, isize); 107 | if(!_mount_and_boot_system) { 108 | ERR("Failed to find _mount_and_boot_system"); 109 | goto end; 110 | } 111 | DEVLOG("%016llx[%016llx]: _mount_and_boot_system", _mount_and_boot_system + iboot_base, _mount_and_boot_system); 112 | 113 | 114 | uint64_t jumpto_bl = find_jumpto_bl(iboot_base, idata, isize); 115 | if(!jumpto_bl) 116 | goto end; 117 | DEVLOG("%016llx[%016llx]: jumpto_bl", jumpto_bl + iboot_base, jumpto_bl); 118 | 119 | // 120 | // uint64_t ptr_obfuscation = find_ptr_obfuscation(iboot_base, idata, isize); 121 | // if(!ptr_obfuscation) 122 | // goto end; 123 | // DEVLOG("%016llx[%016llx]: ptr_obfuscation", ptr_obfuscation + iboot_base, ptr_obfuscation); 124 | 125 | LOG("---- offsetfinder: done ----"); 126 | 127 | /*---- patch part ----*/ 128 | 129 | /* 130 | REMOTE_BOOT 131 | $ ./irecovery -s 132 | > saveenv 133 | > /upload ramdisk.img4 134 | > ramdisk 135 | > /upload payload.bin 136 | > go 137 | > bootx 138 | 139 | */ 140 | 141 | LOG("---- patch: start ----"); 142 | { 143 | { 144 | uint32_t* patch_check_bootmode = (uint32_t*)(idata + check_bootmode); 145 | uint32_t opcode = INSN_MOV_X0_1; // 0: LOCAL_BOOT, 1: REMOTE_BOOT 146 | if((opcode & 0xffffffdf) != 0xd2800000) 147 | { 148 | ERR("Detected weird opcode"); 149 | goto end; 150 | } 151 | patch_check_bootmode[0] = opcode; 152 | patch_check_bootmode[1] = INSN_RET; 153 | LOG("bootmode=%d (%s)", ((opcode & 0xf0) >> 5), ((opcode & 0xf0) >> 5) == 0 ? "LOCAL_BOOT" : "REMOTE_BOOT"); 154 | } 155 | 156 | // shellcode injection 157 | { 158 | // 1, set offsets 159 | LOG("setting offsets..."); 160 | size_t point = shellcode_bin_len - (sizeof(uint64_t) * 4); 161 | // 1: RELOCATED 162 | // 2: LOAD_ADDRESS 163 | // 3: SDRAM_PAGE 164 | uint64_t* offset = (uint64_t*)(shellcode_bin + point); 165 | offset[0] = load_address - sub; 166 | offset[1] = load_address; 167 | offset[2] = sdram_page; 168 | offset[3] = load_address - overlay; 169 | 170 | } 171 | 172 | { 173 | // 2, copy payload.bin 174 | LOG("copying payload..."); 175 | memcpy((void*)(idata + zero_region), shellcode_bin, shellcode_bin_len); 176 | LOG("done"); 177 | } 178 | 179 | { 180 | // 3, relocate go cmd 181 | uint64_t cmd_hander = 0; 182 | 183 | cmd_hander = go_cmd_handler; 184 | 185 | uint64_t* patch_go_cmd_handler = (uint64_t*)(idata + cmd_hander); 186 | patch_go_cmd_handler[0] = iboot_base + zero_region; 187 | DEVLOG("new go cmd handler: %016llx", iboot_base + zero_region); 188 | LOG("relocated go cmd handler"); 189 | } 190 | 191 | { 192 | // 4, relocate bootx cmd (set fsboot) 193 | uint64_t cmd_hander = 0; 194 | 195 | cmd_hander = bootx_cmd_handler; 196 | 197 | uint64_t* patch_bootx_cmd_handler = (uint64_t*)(idata + cmd_hander); 198 | patch_bootx_cmd_handler[0] = _mount_and_boot_system + iboot_base; 199 | DEVLOG("new bootx cmd handler: %016llx", _mount_and_boot_system + iboot_base); 200 | LOG("relocated bootx cmd handler"); 201 | } 202 | 203 | { 204 | // 5, relocate reset cmd (set rwx) 205 | uint64_t* patch_reset_cmd_handler = (uint64_t*)(idata + reset_cmd_handler); 206 | patch_reset_cmd_handler[0] = iboot_base + zero_region + 8; 207 | DEVLOG("new reset cmd handler: %016llx", iboot_base + zero_region + 8); 208 | LOG("relocated reset cmd handler"); 209 | } 210 | 211 | 212 | { 213 | // 6, hook jumpto xnu 214 | uint32_t* patch_jumpto = (uint32_t*)(idata + jumpto_bl); 215 | 216 | uint64_t new_jumpto_addr = zero_region + 4; 217 | DEVLOG("%016llx: BL %016llx", jumpto_bl + iboot_base, new_jumpto_addr + iboot_base); 218 | int64_t delta = new_jumpto_addr - jumpto_bl; 219 | uint32_t opcode = 0x94000000 | (((uint64_t)delta >> 2) & 0x3ffffff); 220 | DEVLOG("opcode: %08x", opcode); 221 | patch_jumpto[0] = opcode; 222 | LOG("jumpto"); 223 | } 224 | 225 | } 226 | 227 | { 228 | uint32_t* patch_sigcheck = (uint32_t*)(idata + sigcheck); 229 | patch_sigcheck[0] = INSN_MOV_X0_0; 230 | LOG("signature check"); 231 | } 232 | 233 | { 234 | uint32_t* patch_boot_manifest_validation = (uint32_t*)(idata + boot_manifest_validation); 235 | patch_boot_manifest_validation[0] = INSN_MOV_X0_0; 236 | LOG("boot_manifest hash validation"); 237 | } 238 | 239 | LOG("---- patch: done ----"); 240 | 241 | end: 242 | return; 243 | } 244 | 245 | #ifndef TESTBUILD 246 | extern uint64_t ORIGINAL; 247 | extern uint64_t IBOOT_BASE_ADDRESS; 248 | extern uint64_t SDRAM_PAGE_ADDRESS; 249 | extern uint64_t LOAD_ADDRESS; 250 | 251 | int patch(void* arg0, void* arg1) 252 | { 253 | 254 | // t8015, TODO: offsetfinder 255 | jump_t ret = (jump_t)ORIGINAL;// (jump_t)0x180018004; 256 | uint64_t iboot_base = IBOOT_BASE_ADDRESS; // 0x18001c000; 257 | 258 | void* idata = (void*)(iboot_base); 259 | uint64_t isize = *(uint64_t*)(iboot_base + 0x308) - iboot_base; // ... why 0x308?? 260 | 261 | uint64_t sdram_page = SDRAM_PAGE_ADDRESS; // 0x180002000; 262 | uint64_t loadaddr = LOAD_ADDRESS; // 0x801000000; 263 | 264 | patch_iboot(iboot_base, idata, isize, sdram_page, loadaddr); 265 | 266 | return ret(arg0, arg1); 267 | } 268 | 269 | #endif 270 | --------------------------------------------------------------------------------