1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __MACH_O_FILE_ABSTRACTION__
25 #define __MACH_O_FILE_ABSTRACTION__
27 #include <mach-o/loader.h>
28 #include <mach-o/nlist.h>
29 #include <mach-o/reloc.h>
30 #include <mach/machine.h>
32 // suport older versions of mach-o/loader.h
36 uint32_t cmd; /* LC_UUID */
37 uint32_t cmdsize; /* sizeof(struct uuid_command) */
38 uint8_t uuid[16]; /* the 128-bit uuid */
42 #ifndef S_16BYTE_LITERALS
43 #define S_16BYTE_LITERALS 0xE
46 #include "FileAbstraction.hpp"
47 #include "Architectures.hpp"
52 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
60 template <typename P> struct macho_header_content {};
61 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
62 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
63 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
64 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
69 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
70 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
72 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
73 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
75 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
76 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
78 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
79 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
81 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
82 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
84 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
85 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
87 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
88 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
90 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
91 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
93 typedef typename P::E E;
95 macho_header_content<P> header;
100 // mach-o load command
102 template <typename P>
103 class macho_load_command {
105 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
106 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
108 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
109 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
111 typedef typename P::E E;
113 load_command command;
118 // mach-o segment load command
120 template <typename P> struct macho_segment_content {};
121 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
122 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
123 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
124 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
126 template <typename P>
127 class macho_segment_command {
129 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
130 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
132 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
133 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
135 const char* segname() const INLINE { return segment.fields.segname; }
136 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
138 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
139 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
141 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
142 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
144 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
145 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
147 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
148 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
150 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
151 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
153 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
154 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
156 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
157 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
159 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
160 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
163 CMD = macho_segment_content<P>::CMD
166 typedef typename P::E E;
168 macho_segment_content<P> segment;
175 template <typename P> struct macho_section_content {};
176 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
177 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
178 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
179 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
181 template <typename P>
182 class macho_section {
184 const char* sectname() const INLINE { return section.fields.sectname; }
185 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
187 const char* segname() const INLINE { return section.fields.segname; }
188 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
190 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
191 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
193 uint64_t size() const INLINE { return P::getP(section.fields.size); }
194 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
196 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
197 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
199 uint32_t align() const INLINE { return E::get32(section.fields.align); }
200 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
202 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
203 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
205 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
206 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
208 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
209 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
211 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
212 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
214 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
215 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
217 typedef typename P::E E;
219 macho_section_content<P> section;
224 // mach-o dylib load command
226 template <typename P>
227 class macho_dylib_command {
229 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
230 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
232 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
233 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
235 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
236 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
238 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
239 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
241 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
242 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
244 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
245 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
247 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
248 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
250 typedef typename P::E E;
252 dylib_command fields;
257 // mach-o dylinker load command
259 template <typename P>
260 class macho_dylinker_command {
262 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
263 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
265 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
266 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
268 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
269 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
271 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
272 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
274 typedef typename P::E E;
276 dylinker_command fields;
281 // mach-o sub_framework load command
283 template <typename P>
284 class macho_sub_framework_command {
286 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
287 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
289 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
290 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
292 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
293 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
295 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
296 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
298 typedef typename P::E E;
300 sub_framework_command fields;
305 // mach-o sub_client load command
307 template <typename P>
308 class macho_sub_client_command {
310 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
311 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
313 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
314 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
316 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
317 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
319 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
320 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
322 typedef typename P::E E;
324 sub_client_command fields;
329 // mach-o sub_umbrella load command
331 template <typename P>
332 class macho_sub_umbrella_command {
334 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
335 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
337 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
338 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
340 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
341 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
343 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
344 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
346 typedef typename P::E E;
348 sub_umbrella_command fields;
353 // mach-o sub_library load command
355 template <typename P>
356 class macho_sub_library_command {
358 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
359 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
361 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
362 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
364 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
365 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
367 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
368 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
370 typedef typename P::E E;
372 sub_library_command fields;
377 // mach-o uuid load command
379 template <typename P>
380 class macho_uuid_command {
382 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
383 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
385 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
386 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
388 const uint8_t* uuid() const INLINE { return fields.uuid; }
389 void set_uuid(uint8_t uuid[16]) INLINE { memcpy(&fields.uuid, uuid, 16); }
391 typedef typename P::E E;
398 // mach-o routines load command
400 template <typename P> struct macho_routines_content {};
401 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
402 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
403 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
404 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
406 template <typename P>
407 class macho_routines_command {
409 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
410 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
412 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
413 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
415 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
416 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
418 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
419 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
421 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
422 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
424 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
425 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
427 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
428 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
430 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
431 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
433 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
434 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
436 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
437 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
439 typedef typename P::E E;
441 CMD = macho_routines_content<P>::CMD
444 macho_routines_content<P> routines;
449 // mach-o symbol table load command
451 template <typename P>
452 class macho_symtab_command {
454 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
455 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
457 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
458 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
460 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
461 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
463 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
464 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
466 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
467 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
469 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
470 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
473 typedef typename P::E E;
475 symtab_command fields;
480 // mach-o dynamic symbol table load command
482 template <typename P>
483 class macho_dysymtab_command {
485 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
486 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
488 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
489 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
491 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
492 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
494 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
495 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
497 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
498 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
500 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
501 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
503 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
504 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
506 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
507 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
509 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
510 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
512 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
513 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
515 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
516 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
518 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
519 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
521 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
522 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
524 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
525 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
527 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
528 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
530 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
531 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
533 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
534 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
536 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
537 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
539 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
540 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
542 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
543 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
545 typedef typename P::E E;
547 dysymtab_command fields;
552 // mach-o two-level hints load command
554 template <typename P>
555 class macho_twolevel_hints_command {
557 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
558 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
560 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
561 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
563 uint32_t offset() const INLINE { return E::get32(fields.offset); }
564 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
566 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
567 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
569 typedef typename P::E E;
571 twolevel_hints_command fields;
576 // mach-o threads load command
578 template <typename P>
579 class macho_thread_command {
581 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
582 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
584 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
585 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
587 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
588 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
590 uint32_t count() const INLINE { return E::get32(fields_count); }
591 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
593 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
594 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
596 typedef typename P::E E;
597 typedef typename P::uint_t pint_t;
599 struct thread_command fields;
600 uint32_t fields_flavor;
601 uint32_t fields_count;
602 pint_t thread_registers[1];
609 // mach-o symbol table entry
611 template <typename P> struct macho_nlist_content {};
612 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
613 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
614 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
615 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
617 template <typename P>
620 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
621 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
623 uint8_t n_type() const INLINE { return entry.fields.n_type; }
624 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
626 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
627 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
629 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
630 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
632 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
633 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
635 typedef typename P::E E;
637 macho_nlist_content<P> entry;
643 // mach-o relocation info
645 template <typename P>
646 class macho_relocation_info {
648 uint32_t r_address() const INLINE { return E::get32(address); }
649 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
651 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
652 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
654 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
655 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
657 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
658 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
660 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
661 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
663 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
664 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
666 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
668 typedef typename P::E E;
676 // mach-o scattered relocation info
677 // The bit fields are always in big-endian order (see mach-o/reloc.h)
679 template <typename P>
680 class macho_scattered_relocation_info {
682 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
683 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
685 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
686 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
688 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
689 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
691 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
692 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
694 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
695 void set_r_address(uint32_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
697 uint32_t r_value() const INLINE { return E::get32(value); }
698 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
700 uint32_t r_other() const INLINE { return other; }
702 typedef typename P::E E;
713 #endif // __MACH_O_FILE_ABSTRACTION__