20 #define CPROVER_FAT_MAGIC 0xcafebabe
21 #define CPROVER_FAT_CIGAM 0xbebafeca
22 #define CPROVER_MH_MAGIC 0xfeedface
23 #define CPROVER_MH_CIGAM 0xcefaedfe
24 #define CPROVER_MH_MAGIC_64 0xfeedfacf
25 #define CPROVER_MH_CIGAM_64 0xcffaedfe
28 # include <architecture/byte_order.h>
29 # include <mach-o/fat.h>
30 # include <mach-o/loader.h>
31 # include <mach-o/swap.h>
33 # if(CPROVER_FAT_MAGIC != FAT_MAGIC) || (CPROVER_FAT_CIGAM != FAT_CIGAM) || \
34 (CPROVER_MH_MAGIC != MH_MAGIC) || (CPROVER_MH_CIGAM != MH_CIGAM) || \
35 (CPROVER_MH_MAGIC_64 != MH_MAGIC_64) || \
36 (CPROVER_MH_CIGAM_64 != MH_CIGAM_64)
37 # error "Mach-O magic has inconsistent value"
51 const uint8_t *input_as_bytes =
reinterpret_cast<uint8_t *
>(&input);
52 return (((uint32_t)input_as_bytes[0]) << 24) |
53 (((uint32_t)input_as_bytes[1]) << 16) |
54 (((uint32_t)input_as_bytes[2]) << 8) |
55 (((uint32_t)input_as_bytes[3]) << 0);
69 uint32_t n_architectures_native =
72 n_architectures_native >= 1 && n_architectures_native < 20;
78 : log(message_handler), has_gb_arch(false)
84 in.read(
reinterpret_cast<char*
>(&fh),
sizeof(
struct fat_header));
93 sizeof(fh.nfat_arch) == 4,
"fat_header::nfat_arch is of type uint32_t");
101 in.read(
reinterpret_cast<char*
>(&fa),
sizeof(
struct fat_arch));
104 sizeof(fa.cputype) == 4 &&
sizeof(fa.cpusubtype) == 4 &&
105 sizeof(fa.size) == 4,
106 "This requires a specific fat architecture");
112 cpusubtype==CPU_SUBTYPE_HPPA_7100LC &&
118 log.
warning() <<
"Cannot read OSX fat archive on this platform"
124 const std::string &source,
125 const std::string &dest)
const
130 "lipo", {
"lipo",
"-thin",
"hppa7100LC",
"-output", dest, source}) !=
137 uint32_t *magic =
reinterpret_cast<uint32_t *
>(hdr);
154 for(uint32_t i = 0; i < nsects; ++i)
158 in.read(
reinterpret_cast<char *
>(&s),
sizeof(s));
164 swap_section(&s, 1, NXHostByteOrder());
178 for(uint32_t i = 0; i < nsects; ++i)
182 in.read(
reinterpret_cast<char *
>(&s),
sizeof(s));
188 swap_section_64(&s, 1, NXHostByteOrder());
205 for(uint32_t i = 0; i < ncmds; ++i)
210 struct load_command lc;
211 in.read(
reinterpret_cast<char *
>(&lc),
sizeof(lc));
217 swap_load_command(&lc, NXHostByteOrder());
229 struct segment_command seg;
230 in.read(
reinterpret_cast<char *
>(&seg),
sizeof(seg));
236 swap_segment_command(&seg, NXHostByteOrder());
244 struct segment_command_64 seg;
245 in.read(
reinterpret_cast<char *
>(&seg),
sizeof(seg));
251 swap_segment_command_64(&seg, NXHostByteOrder());
260 offset += lc.cmdsize;
273 : log(message_handler), in(_in)
277 in.read(
reinterpret_cast<char *
>(&magic),
sizeof(magic));
283 bool is_64 =
false, need_swap =
false;
303 std::size_t offset = 0;
311 struct mach_header mh;
312 in.read(
reinterpret_cast<char *
>(&mh),
sizeof(mh));
318 swap_mach_header(&mh, NXHostByteOrder());
326 struct mach_header_64 mh;
327 in.read(
reinterpret_cast<char *
>(&mh),
sizeof(mh));
333 swap_mach_header_64(&mh, NXHostByteOrder());