macho.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_MACHO_H
  19. #define GRUB_MACHO_H 1
  20. #include <grub/types.h>
  21. /* Multi-architecture header. Always in big-endian. */
  22. struct grub_macho_fat_header
  23. {
  24. grub_uint32_t magic;
  25. grub_uint32_t nfat_arch;
  26. } GRUB_PACKED;
  27. enum
  28. {
  29. GRUB_MACHO_CPUTYPE_IA32 = 0x00000007,
  30. GRUB_MACHO_CPUTYPE_AMD64 = 0x01000007
  31. };
  32. #define GRUB_MACHO_FAT_MAGIC 0xcafebabe
  33. #define GRUB_MACHO_FAT_EFI_MAGIC 0x0ef1fab9U
  34. typedef grub_uint32_t grub_macho_cpu_type_t;
  35. typedef grub_uint32_t grub_macho_cpu_subtype_t;
  36. /* Architecture descriptor. Always in big-endian. */
  37. struct grub_macho_fat_arch
  38. {
  39. grub_macho_cpu_type_t cputype;
  40. grub_macho_cpu_subtype_t cpusubtype;
  41. grub_uint32_t offset;
  42. grub_uint32_t size;
  43. grub_uint32_t align;
  44. } GRUB_PACKED;
  45. /* File header for 32-bit. Always in native-endian. */
  46. struct grub_macho_header32
  47. {
  48. #define GRUB_MACHO_MAGIC32 0xfeedface
  49. grub_uint32_t magic;
  50. grub_macho_cpu_type_t cputype;
  51. grub_macho_cpu_subtype_t cpusubtype;
  52. grub_uint32_t filetype;
  53. grub_uint32_t ncmds;
  54. grub_uint32_t sizeofcmds;
  55. grub_uint32_t flags;
  56. } GRUB_PACKED;
  57. /* File header for 64-bit. Always in native-endian. */
  58. struct grub_macho_header64
  59. {
  60. #define GRUB_MACHO_MAGIC64 0xfeedfacf
  61. grub_uint32_t magic;
  62. grub_macho_cpu_type_t cputype;
  63. grub_macho_cpu_subtype_t cpusubtype;
  64. grub_uint32_t filetype;
  65. grub_uint32_t ncmds;
  66. grub_uint32_t sizeofcmds;
  67. grub_uint32_t flags;
  68. grub_uint32_t reserved;
  69. } GRUB_PACKED;
  70. /* Common header of Mach-O commands. */
  71. struct grub_macho_cmd
  72. {
  73. grub_uint32_t cmd;
  74. grub_uint32_t cmdsize;
  75. } GRUB_PACKED;
  76. typedef grub_uint32_t grub_macho_vmprot_t;
  77. /* 32-bit segment command. */
  78. struct grub_macho_segment32
  79. {
  80. #define GRUB_MACHO_CMD_SEGMENT32 1
  81. grub_uint32_t cmd;
  82. grub_uint32_t cmdsize;
  83. grub_uint8_t segname[16];
  84. grub_uint32_t vmaddr;
  85. grub_uint32_t vmsize;
  86. grub_uint32_t fileoff;
  87. grub_uint32_t filesize;
  88. grub_macho_vmprot_t maxprot;
  89. grub_macho_vmprot_t initprot;
  90. grub_uint32_t nsects;
  91. grub_uint32_t flags;
  92. } GRUB_PACKED;
  93. /* 64-bit segment command. */
  94. struct grub_macho_segment64
  95. {
  96. #define GRUB_MACHO_CMD_SEGMENT64 0x19
  97. grub_uint32_t cmd;
  98. grub_uint32_t cmdsize;
  99. grub_uint8_t segname[16];
  100. grub_uint64_t vmaddr;
  101. grub_uint64_t vmsize;
  102. grub_uint64_t fileoff;
  103. grub_uint64_t filesize;
  104. grub_macho_vmprot_t maxprot;
  105. grub_macho_vmprot_t initprot;
  106. grub_uint32_t nsects;
  107. grub_uint32_t flags;
  108. } GRUB_PACKED;
  109. #define GRUB_MACHO_CMD_THREAD 5
  110. struct grub_macho_lzss_header
  111. {
  112. char magic[8];
  113. #define GRUB_MACHO_LZSS_MAGIC "complzss"
  114. grub_uint32_t unused;
  115. grub_uint32_t uncompressed_size;
  116. grub_uint32_t compressed_size;
  117. };
  118. /* Convenience union. What do we need to load to identify the file type. */
  119. union grub_macho_filestart
  120. {
  121. struct grub_macho_fat_header fat;
  122. struct grub_macho_header32 thin32;
  123. struct grub_macho_header64 thin64;
  124. struct grub_macho_lzss_header lzss;
  125. } GRUB_PACKED;
  126. struct grub_macho_thread32
  127. {
  128. grub_uint32_t cmd;
  129. grub_uint32_t cmdsize;
  130. grub_uint8_t unknown1[48];
  131. grub_uint32_t entry_point;
  132. grub_uint8_t unknown2[20];
  133. } GRUB_PACKED;
  134. struct grub_macho_thread64
  135. {
  136. grub_uint32_t cmd;
  137. grub_uint32_t cmdsize;
  138. grub_uint8_t unknown1[0x88];
  139. grub_uint64_t entry_point;
  140. grub_uint8_t unknown2[0x20];
  141. } GRUB_PACKED;
  142. #define GRUB_MACHO_LZSS_OFFSET 0x180
  143. grub_size_t
  144. grub_decompress_lzss (grub_uint8_t *dst, grub_uint8_t *dstend,
  145. grub_uint8_t *src, grub_uint8_t *srcend);
  146. #endif