/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_MACHO_H #define VAS_EBOOT_MACHO_H 1 #include /* Multi-architecture header. Always in big-endian. */ struct VasEBoot_macho_fat_header { VasEBoot_uint32_t magic; VasEBoot_uint32_t nfat_arch; } VAS_EBOOT_PACKED; enum { VAS_EBOOT_MACHO_CPUTYPE_IA32 = 0x00000007, VAS_EBOOT_MACHO_CPUTYPE_AMD64 = 0x01000007 }; #define VAS_EBOOT_MACHO_FAT_MAGIC 0xcafebabe #define VAS_EBOOT_MACHO_FAT_EFI_MAGIC 0x0ef1fab9U typedef VasEBoot_uint32_t VasEBoot_macho_cpu_type_t; typedef VasEBoot_uint32_t VasEBoot_macho_cpu_subtype_t; /* Architecture descriptor. Always in big-endian. */ struct VasEBoot_macho_fat_arch { VasEBoot_macho_cpu_type_t cputype; VasEBoot_macho_cpu_subtype_t cpusubtype; VasEBoot_uint32_t offset; VasEBoot_uint32_t size; VasEBoot_uint32_t align; } VAS_EBOOT_PACKED; /* File header for 32-bit. Always in native-endian. */ struct VasEBoot_macho_header32 { #define VAS_EBOOT_MACHO_MAGIC32 0xfeedface VasEBoot_uint32_t magic; VasEBoot_macho_cpu_type_t cputype; VasEBoot_macho_cpu_subtype_t cpusubtype; VasEBoot_uint32_t filetype; VasEBoot_uint32_t ncmds; VasEBoot_uint32_t sizeofcmds; VasEBoot_uint32_t flags; } VAS_EBOOT_PACKED; /* File header for 64-bit. Always in native-endian. */ struct VasEBoot_macho_header64 { #define VAS_EBOOT_MACHO_MAGIC64 0xfeedfacf VasEBoot_uint32_t magic; VasEBoot_macho_cpu_type_t cputype; VasEBoot_macho_cpu_subtype_t cpusubtype; VasEBoot_uint32_t filetype; VasEBoot_uint32_t ncmds; VasEBoot_uint32_t sizeofcmds; VasEBoot_uint32_t flags; VasEBoot_uint32_t reserved; } VAS_EBOOT_PACKED; /* Common header of Mach-O commands. */ struct VasEBoot_macho_cmd { VasEBoot_uint32_t cmd; VasEBoot_uint32_t cmdsize; } VAS_EBOOT_PACKED; typedef VasEBoot_uint32_t VasEBoot_macho_vmprot_t; /* 32-bit segment command. */ struct VasEBoot_macho_segment32 { #define VAS_EBOOT_MACHO_CMD_SEGMENT32 1 VasEBoot_uint32_t cmd; VasEBoot_uint32_t cmdsize; VasEBoot_uint8_t segname[16]; VasEBoot_uint32_t vmaddr; VasEBoot_uint32_t vmsize; VasEBoot_uint32_t fileoff; VasEBoot_uint32_t filesize; VasEBoot_macho_vmprot_t maxprot; VasEBoot_macho_vmprot_t initprot; VasEBoot_uint32_t nsects; VasEBoot_uint32_t flags; } VAS_EBOOT_PACKED; /* 64-bit segment command. */ struct VasEBoot_macho_segment64 { #define VAS_EBOOT_MACHO_CMD_SEGMENT64 0x19 VasEBoot_uint32_t cmd; VasEBoot_uint32_t cmdsize; VasEBoot_uint8_t segname[16]; VasEBoot_uint64_t vmaddr; VasEBoot_uint64_t vmsize; VasEBoot_uint64_t fileoff; VasEBoot_uint64_t filesize; VasEBoot_macho_vmprot_t maxprot; VasEBoot_macho_vmprot_t initprot; VasEBoot_uint32_t nsects; VasEBoot_uint32_t flags; } VAS_EBOOT_PACKED; #define VAS_EBOOT_MACHO_CMD_THREAD 5 struct VasEBoot_macho_lzss_header { char magic[8]; #define VAS_EBOOT_MACHO_LZSS_MAGIC "complzss" VasEBoot_uint32_t unused; VasEBoot_uint32_t uncompressed_size; VasEBoot_uint32_t compressed_size; }; /* Convenience union. What do we need to load to identify the file type. */ union VasEBoot_macho_filestart { struct VasEBoot_macho_fat_header fat; struct VasEBoot_macho_header32 thin32; struct VasEBoot_macho_header64 thin64; struct VasEBoot_macho_lzss_header lzss; } VAS_EBOOT_PACKED; struct VasEBoot_macho_thread32 { VasEBoot_uint32_t cmd; VasEBoot_uint32_t cmdsize; VasEBoot_uint8_t unknown1[48]; VasEBoot_uint32_t entry_point; VasEBoot_uint8_t unknown2[20]; } VAS_EBOOT_PACKED; struct VasEBoot_macho_thread64 { VasEBoot_uint32_t cmd; VasEBoot_uint32_t cmdsize; VasEBoot_uint8_t unknown1[0x88]; VasEBoot_uint64_t entry_point; VasEBoot_uint8_t unknown2[0x20]; } VAS_EBOOT_PACKED; #define VAS_EBOOT_MACHO_LZSS_OFFSET 0x180 VasEBoot_size_t VasEBoot_decompress_lzss (VasEBoot_uint8_t *dst, VasEBoot_uint8_t *dstend, VasEBoot_uint8_t *src, VasEBoot_uint8_t *srcend); #endif