vaseboot/include/VasEBoot/macho.h

167 lines
4.5 KiB
C

/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VasEBoot 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.
*
* VasEBoot 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 VasEBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VasEBoot_MACHO_H
#define VasEBoot_MACHO_H 1
#include <VasEBoot/types.h>
/* Multi-architecture header. Always in big-endian. */
struct VasEBoot_macho_fat_header
{
VasEBoot_uint32_t magic;
VasEBoot_uint32_t nfat_arch;
} VasEBoot_PACKED;
enum
{
VasEBoot_MACHO_CPUTYPE_IA32 = 0x00000007,
VasEBoot_MACHO_CPUTYPE_AMD64 = 0x01000007
};
#define VasEBoot_MACHO_FAT_MAGIC 0xcafebabe
#define VasEBoot_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;
} VasEBoot_PACKED;
/* File header for 32-bit. Always in native-endian. */
struct VasEBoot_macho_header32
{
#define VasEBoot_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;
} VasEBoot_PACKED;
/* File header for 64-bit. Always in native-endian. */
struct VasEBoot_macho_header64
{
#define VasEBoot_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;
} VasEBoot_PACKED;
/* Common header of Mach-O commands. */
struct VasEBoot_macho_cmd
{
VasEBoot_uint32_t cmd;
VasEBoot_uint32_t cmdsize;
} VasEBoot_PACKED;
typedef VasEBoot_uint32_t VasEBoot_macho_vmprot_t;
/* 32-bit segment command. */
struct VasEBoot_macho_segment32
{
#define VasEBoot_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;
} VasEBoot_PACKED;
/* 64-bit segment command. */
struct VasEBoot_macho_segment64
{
#define VasEBoot_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;
} VasEBoot_PACKED;
#define VasEBoot_MACHO_CMD_THREAD 5
struct VasEBoot_macho_lzss_header
{
char magic[8];
#define VasEBoot_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;
} VasEBoot_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];
} VasEBoot_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];
} VasEBoot_PACKED;
#define VasEBoot_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