19 #define CPROVER_FAT_MAGIC 0xcafebabe
20 #define CPROVER_FAT_CIGAM 0xbebafeca
21 #define CPROVER_MH_MAGIC 0xfeedface
22 #define CPROVER_MH_CIGAM 0xcefaedfe
23 #define CPROVER_MH_MAGIC_64 0xfeedfacf
24 #define CPROVER_MH_CIGAM_64 0xcffaedfe
27 # include <architecture/byte_order.h>
28 # include <mach-o/fat.h>
29 # include <mach-o/loader.h>
30 # include <mach-o/swap.h>
32 # if(CPROVER_FAT_MAGIC != FAT_MAGIC) || (CPROVER_FAT_CIGAM != FAT_CIGAM) || \
33 (CPROVER_MH_MAGIC != MH_MAGIC) || (CPROVER_MH_CIGAM != MH_CIGAM) || \
34 (CPROVER_MH_MAGIC_64 != MH_MAGIC_64) || \
35 (CPROVER_MH_CIGAM_64 != MH_CIGAM_64)
36 # error "Mach-O magic has inconsistent value"
50 const uint8_t *input_as_bytes =
reinterpret_cast<uint8_t *
>(&input);
51 return (((uint32_t)input_as_bytes[0]) << 24) |
52 (((uint32_t)input_as_bytes[1]) << 16) |
53 (((uint32_t)input_as_bytes[2]) << 8) |
54 (((uint32_t)input_as_bytes[3]) << 0);
68 uint32_t n_architectures_native =
71 n_architectures_native >= 1 && n_architectures_native < 20;
77 : log(message_handler), has_gb_arch(false)
83 in.read(
reinterpret_cast<char*
>(&fh),
sizeof(
struct fat_header));
92 sizeof(fh.nfat_arch) == 4,
"fat_header::nfat_arch is of type uint32_t");
100 in.read(
reinterpret_cast<char*
>(&fa),
sizeof(
struct fat_arch));
103 sizeof(fa.cputype) == 4 &&
sizeof(fa.cpusubtype) == 4 &&
104 sizeof(fa.size) == 4,
105 "This requires a specific fat architecture");
111 cpusubtype==CPU_SUBTYPE_HPPA_7100LC &&
117 log.
warning() <<
"Cannot read OSX fat archive on this platform"
123 const std::string &source,
124 const std::string &dest)
const
129 "lipo", {
"lipo",
"-thin",
"hppa7100LC",
"-output", dest, source}) !=
136 uint32_t *magic =
reinterpret_cast<uint32_t *
>(hdr);
153 for(uint32_t i = 0; i < nsects; ++i)
157 in.read(
reinterpret_cast<char *
>(&s),
sizeof(s));
163 swap_section(&s, 1, NXHostByteOrder());
177 for(uint32_t i = 0; i < nsects; ++i)
181 in.read(
reinterpret_cast<char *
>(&s),
sizeof(s));
187 swap_section_64(&s, 1, NXHostByteOrder());
204 for(uint32_t i = 0; i < ncmds; ++i)
209 struct load_command lc;
210 in.read(
reinterpret_cast<char *
>(&lc),
sizeof(lc));
216 swap_load_command(&lc, NXHostByteOrder());
228 struct segment_command seg;
229 in.read(
reinterpret_cast<char *
>(&seg),
sizeof(seg));
235 swap_segment_command(&seg, NXHostByteOrder());
243 struct segment_command_64 seg;
244 in.read(
reinterpret_cast<char *
>(&seg),
sizeof(seg));
250 swap_segment_command_64(&seg, NXHostByteOrder());
259 offset += lc.cmdsize;
272 : log(message_handler), in(_in)
276 in.read(
reinterpret_cast<char *
>(&magic),
sizeof(magic));
282 bool is_64 =
false, need_swap =
false;
302 std::size_t offset = 0;
310 struct mach_header mh;
311 in.read(
reinterpret_cast<char *
>(&mh),
sizeof(mh));
317 swap_mach_header(&mh, NXHostByteOrder());
325 struct mach_header_64 mh;
326 in.read(
reinterpret_cast<char *
>(&mh),
sizeof(mh));
332 swap_mach_header_64(&mh, NXHostByteOrder());