object/macho.rs
1//! Mach-O definitions.
2//!
3//! These definitions are independent of read/write support, although we do implement
4//! some traits useful for those.
5//!
6//! This module is based heavily on header files from `MacOSX26.2.sdk`.
7
8#![allow(missing_docs)]
9
10use crate::endian::{BigEndian, Endian, U16, U32, U64};
11use crate::pod::Pod;
12
13// Definitions from "/usr/include/mach/machine.h".
14
15/*
16 * Capability bits used in the definition of cpu_type.
17 */
18
19/// mask for architecture bits
20pub const CPU_ARCH_MASK: u32 = 0xff00_0000;
21/// 64 bit ABI
22pub const CPU_ARCH_ABI64: u32 = 0x0100_0000;
23/// ABI for 64-bit hardware with 32-bit types; LP32
24pub const CPU_ARCH_ABI64_32: u32 = 0x0200_0000;
25
26/*
27 * Machine types known by all.
28 */
29
30pub const CPU_TYPE_ANY: u32 = !0;
31
32pub const CPU_TYPE_VAX: u32 = 1;
33pub const CPU_TYPE_MC680X0: u32 = 6;
34pub const CPU_TYPE_X86: u32 = 7;
35/// Compatibility alias of [`CPU_TYPE_X86`].
36pub const CPU_TYPE_I386: u32 = CPU_TYPE_X86;
37pub const CPU_TYPE_X86_64: u32 = CPU_TYPE_X86 | CPU_ARCH_ABI64;
38pub const CPU_TYPE_MIPS: u32 = 8;
39pub const CPU_TYPE_MC98000: u32 = 10;
40pub const CPU_TYPE_HPPA: u32 = 11;
41pub const CPU_TYPE_ARM: u32 = 12;
42pub const CPU_TYPE_ARM64: u32 = CPU_TYPE_ARM | CPU_ARCH_ABI64;
43pub const CPU_TYPE_ARM64_32: u32 = CPU_TYPE_ARM | CPU_ARCH_ABI64_32;
44pub const CPU_TYPE_MC88000: u32 = 13;
45pub const CPU_TYPE_SPARC: u32 = 14;
46pub const CPU_TYPE_I860: u32 = 15;
47pub const CPU_TYPE_ALPHA: u32 = 16;
48pub const CPU_TYPE_POWERPC: u32 = 18;
49pub const CPU_TYPE_POWERPC64: u32 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64;
50
51/*
52 * Capability bits used in the definition of cpu_subtype.
53 */
54/// mask for feature flags
55pub const CPU_SUBTYPE_MASK: u32 = 0xff00_0000;
56/// 64 bit libraries
57pub const CPU_SUBTYPE_LIB64: u32 = 0x8000_0000;
58/// pointer authentication with versioned ABI
59pub const CPU_SUBTYPE_PTRAUTH_ABI: u32 = 0x8000_0000;
60
61/// When selecting a slice, ANY will pick the slice with the best
62/// grading for the selected cpu_type_t, unlike the "ALL" subtypes,
63/// which are the slices that can run on any hardware for that cpu type.
64pub const CPU_SUBTYPE_ANY: u32 = !0;
65
66/*
67 * Object files that are hand-crafted to run on any
68 * implementation of an architecture are tagged with
69 * CPU_SUBTYPE_MULTIPLE. This functions essentially the same as
70 * the "ALL" subtype of an architecture except that it allows us
71 * to easily find object files that may need to be modified
72 * whenever a new implementation of an architecture comes out.
73 *
74 * It is the responsibility of the implementor to make sure the
75 * software handles unsupported implementations elegantly.
76 */
77pub const CPU_SUBTYPE_MULTIPLE: u32 = !0;
78pub const CPU_SUBTYPE_LITTLE_ENDIAN: u32 = 0;
79pub const CPU_SUBTYPE_BIG_ENDIAN: u32 = 1;
80
81/*
82 * VAX subtypes (these do *not* necessary conform to the actual cpu
83 * ID assigned by DEC available via the SID register).
84 */
85
86pub const CPU_SUBTYPE_VAX_ALL: u32 = 0;
87pub const CPU_SUBTYPE_VAX780: u32 = 1;
88pub const CPU_SUBTYPE_VAX785: u32 = 2;
89pub const CPU_SUBTYPE_VAX750: u32 = 3;
90pub const CPU_SUBTYPE_VAX730: u32 = 4;
91pub const CPU_SUBTYPE_UVAXI: u32 = 5;
92pub const CPU_SUBTYPE_UVAXII: u32 = 6;
93pub const CPU_SUBTYPE_VAX8200: u32 = 7;
94pub const CPU_SUBTYPE_VAX8500: u32 = 8;
95pub const CPU_SUBTYPE_VAX8600: u32 = 9;
96pub const CPU_SUBTYPE_VAX8650: u32 = 10;
97pub const CPU_SUBTYPE_VAX8800: u32 = 11;
98pub const CPU_SUBTYPE_UVAXIII: u32 = 12;
99
100/*
101 * 680x0 subtypes
102 *
103 * The subtype definitions here are unusual for historical reasons.
104 * NeXT used to consider 68030 code as generic 68000 code. For
105 * backwards compatibility:
106 *
107 * CPU_SUBTYPE_MC68030 symbol has been preserved for source code
108 * compatibility.
109 *
110 * CPU_SUBTYPE_MC680x0_ALL has been defined to be the same
111 * subtype as CPU_SUBTYPE_MC68030 for binary comatability.
112 *
113 * CPU_SUBTYPE_MC68030_ONLY has been added to allow new object
114 * files to be tagged as containing 68030-specific instructions.
115 */
116
117pub const CPU_SUBTYPE_MC680X0_ALL: u32 = 1;
118// compat
119pub const CPU_SUBTYPE_MC68030: u32 = 1;
120pub const CPU_SUBTYPE_MC68040: u32 = 2;
121pub const CPU_SUBTYPE_MC68030_ONLY: u32 = 3;
122
123/*
124 * I386 subtypes
125 */
126
127#[inline]
128pub const fn cpu_subtype_intel(f: u32, m: u32) -> u32 {
129 f + (m << 4)
130}
131
132pub const CPU_SUBTYPE_I386_ALL: u32 = cpu_subtype_intel(3, 0);
133pub const CPU_SUBTYPE_386: u32 = cpu_subtype_intel(3, 0);
134pub const CPU_SUBTYPE_486: u32 = cpu_subtype_intel(4, 0);
135pub const CPU_SUBTYPE_486SX: u32 = cpu_subtype_intel(4, 8);
136pub const CPU_SUBTYPE_586: u32 = cpu_subtype_intel(5, 0);
137pub const CPU_SUBTYPE_PENT: u32 = cpu_subtype_intel(5, 0);
138pub const CPU_SUBTYPE_PENTPRO: u32 = cpu_subtype_intel(6, 1);
139pub const CPU_SUBTYPE_PENTII_M3: u32 = cpu_subtype_intel(6, 3);
140pub const CPU_SUBTYPE_PENTII_M5: u32 = cpu_subtype_intel(6, 5);
141pub const CPU_SUBTYPE_CELERON: u32 = cpu_subtype_intel(7, 6);
142pub const CPU_SUBTYPE_CELERON_MOBILE: u32 = cpu_subtype_intel(7, 7);
143pub const CPU_SUBTYPE_PENTIUM_3: u32 = cpu_subtype_intel(8, 0);
144pub const CPU_SUBTYPE_PENTIUM_3_M: u32 = cpu_subtype_intel(8, 1);
145pub const CPU_SUBTYPE_PENTIUM_3_XEON: u32 = cpu_subtype_intel(8, 2);
146pub const CPU_SUBTYPE_PENTIUM_M: u32 = cpu_subtype_intel(9, 0);
147pub const CPU_SUBTYPE_PENTIUM_4: u32 = cpu_subtype_intel(10, 0);
148pub const CPU_SUBTYPE_PENTIUM_4_M: u32 = cpu_subtype_intel(10, 1);
149pub const CPU_SUBTYPE_ITANIUM: u32 = cpu_subtype_intel(11, 0);
150pub const CPU_SUBTYPE_ITANIUM_2: u32 = cpu_subtype_intel(11, 1);
151pub const CPU_SUBTYPE_XEON: u32 = cpu_subtype_intel(12, 0);
152pub const CPU_SUBTYPE_XEON_MP: u32 = cpu_subtype_intel(12, 1);
153
154#[inline]
155pub const fn cpu_subtype_intel_family(x: u32) -> u32 {
156 x & 15
157}
158pub const CPU_SUBTYPE_INTEL_FAMILY_MAX: u32 = 15;
159
160#[inline]
161pub const fn cpu_subtype_intel_model(x: u32) -> u32 {
162 x >> 4
163}
164pub const CPU_SUBTYPE_INTEL_MODEL_ALL: u32 = 0;
165
166/*
167 * X86 subtypes.
168 */
169
170pub const CPU_SUBTYPE_X86_ALL: u32 = 3;
171pub const CPU_SUBTYPE_X86_64_ALL: u32 = 3;
172pub const CPU_SUBTYPE_X86_ARCH1: u32 = 4;
173/// Haswell feature subset
174pub const CPU_SUBTYPE_X86_64_H: u32 = 8;
175
176/*
177 * Mips subtypes.
178 */
179
180pub const CPU_SUBTYPE_MIPS_ALL: u32 = 0;
181pub const CPU_SUBTYPE_MIPS_R2300: u32 = 1;
182pub const CPU_SUBTYPE_MIPS_R2600: u32 = 2;
183pub const CPU_SUBTYPE_MIPS_R2800: u32 = 3;
184/// pmax
185pub const CPU_SUBTYPE_MIPS_R2000A: u32 = 4;
186pub const CPU_SUBTYPE_MIPS_R2000: u32 = 5;
187/// 3max
188pub const CPU_SUBTYPE_MIPS_R3000A: u32 = 6;
189pub const CPU_SUBTYPE_MIPS_R3000: u32 = 7;
190
191/*
192 * MC98000 (PowerPC) subtypes
193 */
194pub const CPU_SUBTYPE_MC98000_ALL: u32 = 0;
195pub const CPU_SUBTYPE_MC98601: u32 = 1;
196
197/*
198 * HPPA subtypes for Hewlett-Packard HP-PA family of
199 * risc processors. Port by NeXT to 700 series.
200 */
201
202pub const CPU_SUBTYPE_HPPA_ALL: u32 = 0;
203/// Compatibility alias of [`CPU_SUBTYPE_HPPA_ALL`].
204pub const CPU_SUBTYPE_HPPA_7100: u32 = 0;
205pub const CPU_SUBTYPE_HPPA_7100LC: u32 = 1;
206
207/*
208 * MC88000 subtypes.
209 */
210pub const CPU_SUBTYPE_MC88000_ALL: u32 = 0;
211pub const CPU_SUBTYPE_MC88100: u32 = 1;
212pub const CPU_SUBTYPE_MC88110: u32 = 2;
213
214/*
215 * SPARC subtypes
216 */
217pub const CPU_SUBTYPE_SPARC_ALL: u32 = 0;
218
219/*
220 * I860 subtypes
221 */
222pub const CPU_SUBTYPE_I860_ALL: u32 = 0;
223pub const CPU_SUBTYPE_I860_860: u32 = 1;
224
225/*
226 * PowerPC subtypes
227 */
228pub const CPU_SUBTYPE_POWERPC_ALL: u32 = 0;
229pub const CPU_SUBTYPE_POWERPC_601: u32 = 1;
230pub const CPU_SUBTYPE_POWERPC_602: u32 = 2;
231pub const CPU_SUBTYPE_POWERPC_603: u32 = 3;
232pub const CPU_SUBTYPE_POWERPC_603E: u32 = 4;
233pub const CPU_SUBTYPE_POWERPC_603EV: u32 = 5;
234pub const CPU_SUBTYPE_POWERPC_604: u32 = 6;
235pub const CPU_SUBTYPE_POWERPC_604E: u32 = 7;
236pub const CPU_SUBTYPE_POWERPC_620: u32 = 8;
237pub const CPU_SUBTYPE_POWERPC_750: u32 = 9;
238pub const CPU_SUBTYPE_POWERPC_7400: u32 = 10;
239pub const CPU_SUBTYPE_POWERPC_7450: u32 = 11;
240pub const CPU_SUBTYPE_POWERPC_970: u32 = 100;
241
242/*
243 * ARM subtypes
244 */
245pub const CPU_SUBTYPE_ARM_ALL: u32 = 0;
246pub const CPU_SUBTYPE_ARM_V4T: u32 = 5;
247pub const CPU_SUBTYPE_ARM_V6: u32 = 6;
248pub const CPU_SUBTYPE_ARM_V5TEJ: u32 = 7;
249pub const CPU_SUBTYPE_ARM_XSCALE: u32 = 8;
250/// ARMv7-A and ARMv7-R
251pub const CPU_SUBTYPE_ARM_V7: u32 = 9;
252/// Cortex A9
253pub const CPU_SUBTYPE_ARM_V7F: u32 = 10;
254/// Swift
255pub const CPU_SUBTYPE_ARM_V7S: u32 = 11;
256pub const CPU_SUBTYPE_ARM_V7K: u32 = 12;
257pub const CPU_SUBTYPE_ARM_V8: u32 = 13;
258/// Not meant to be run under xnu
259pub const CPU_SUBTYPE_ARM_V6M: u32 = 14;
260/// Not meant to be run under xnu
261pub const CPU_SUBTYPE_ARM_V7M: u32 = 15;
262/// Not meant to be run under xnu
263pub const CPU_SUBTYPE_ARM_V7EM: u32 = 16;
264/// Not meant to be run under xnu
265pub const CPU_SUBTYPE_ARM_V8M: u32 = 17;
266/// Not meant to be run under xnu
267pub const CPU_SUBTYPE_ARM_V8M_MAIN: u32 = CPU_SUBTYPE_ARM_V8M;
268/// Not meant to be run under xnu
269pub const CPU_SUBTYPE_ARM_V8M_BASE: u32 = 18;
270/// Not meant to be run under xnu
271pub const CPU_SUBTYPE_ARM_V8_1M_MAIN: u32 = 19;
272
273/*
274 * ARM64 subtypes
275 */
276pub const CPU_SUBTYPE_ARM64_ALL: u32 = 0;
277pub const CPU_SUBTYPE_ARM64_V8: u32 = 1;
278pub const CPU_SUBTYPE_ARM64E: u32 = 2;
279
280/* CPU subtype feature flags for ptrauth on arm64e platforms */
281pub const CPU_SUBTYPE_ARM64_PTR_AUTH_MASK: u32 = 0x0f000000;
282#[inline]
283pub const fn cpu_subtype_arm64_ptr_auth_version(x: u32) -> u32 {
284 (x & CPU_SUBTYPE_ARM64_PTR_AUTH_MASK) >> 24
285}
286
287/*
288 * ARM64_32 subtypes
289 */
290pub const CPU_SUBTYPE_ARM64_32_ALL: u32 = 0;
291pub const CPU_SUBTYPE_ARM64_32_V8: u32 = 1;
292
293// Definitions from "/usr/include/mach/vm_prot.h".
294
295/// read permission
296pub const VM_PROT_READ: u32 = 0x01;
297/// write permission
298pub const VM_PROT_WRITE: u32 = 0x02;
299/// execute permission
300pub const VM_PROT_EXECUTE: u32 = 0x04;
301
302// Definitions from https://github.com/llvm/llvm-project/blob/llvmorg-22.1.3/clang/lib/Headers/ptrauth.h
303
304/// The key used to sign a pointer for authentication.
305///
306/// The variant values correspond to the values used in the
307/// `ptrauth_key` enum in `ptrauth.h`.
308#[repr(u8)]
309#[derive(Debug, Clone, Copy, PartialEq, Eq)]
310pub enum PtrauthKey {
311 /// Instruction key A.
312 IA = 0,
313 /// Instruction key B.
314 IB = 1,
315 /// Data key A.
316 DA = 2,
317 /// Data key B.
318 DB = 3,
319}
320
321// Definitions from https://opensource.apple.com/source/dyld/dyld-210.2.3/launch-cache/dyld_cache_format.h.auto.html
322
323/// The dyld cache header.
324/// Corresponds to struct dyld_cache_header from dyld_cache_format.h.
325/// This header has grown over time. Only the fields up to and including dyld_base_address
326/// are guaranteed to be present. For all other fields, check the header size before
327/// accessing the field. The header size is stored in mapping_offset; the mappings start
328/// right after the theader.
329#[derive(Debug, Clone, Copy)]
330#[repr(C)]
331pub struct DyldCacheHeader<E: Endian> {
332 /// e.g. "dyld_v0 i386"
333 pub magic: [u8; 16],
334 /// file offset to first dyld_cache_mapping_info
335 pub mapping_offset: U32<E>,
336 /// number of dyld_cache_mapping_info entries
337 pub mapping_count: U32<E>,
338 /// UNUSED: moved to imagesOffset to prevent older dsc_extarctors from crashing
339 pub images_offset_old: U32<E>,
340 /// UNUSED: moved to imagesCount to prevent older dsc_extarctors from crashing
341 pub images_count_old: U32<E>,
342 /// base address of dyld when cache was built
343 pub dyld_base_address: U64<E>,
344 /// file offset of code signature blob
345 pub code_signature_offset: U64<E>,
346 /// size of code signature blob (zero means to end of file)
347 pub code_signature_size: U64<E>,
348 /// unused. Used to be file offset of kernel slid info
349 pub slide_info_offset_unused: U64<E>,
350 /// unused. Used to be size of kernel slid info
351 pub slide_info_size_unused: U64<E>,
352 /// file offset of where local symbols are stored
353 pub local_symbols_offset: U64<E>,
354 /// size of local symbols information
355 pub local_symbols_size: U64<E>,
356 /// unique value for each shared cache file
357 pub uuid: [u8; 16],
358 /// 0 for development, 1 for production, 2 for multi-cache
359 pub cache_type: U64<E>,
360 /// file offset to table of uint64_t pool addresses
361 pub branch_pools_offset: U32<E>,
362 /// number of uint64_t entries
363 pub branch_pools_count: U32<E>,
364 /// (unslid) address of mach_header of dyld in cache
365 pub dyld_in_cache_mh: U64<E>,
366 /// (unslid) address of entry point (_dyld_start) of dyld in cache
367 pub dyld_in_cache_entry: U64<E>,
368 /// file offset to first dyld_cache_image_text_info
369 pub images_text_offset: U64<E>,
370 /// number of dyld_cache_image_text_info entries
371 pub images_text_count: U64<E>,
372 /// (unslid) address of dyld_cache_patch_info
373 pub patch_info_addr: U64<E>,
374 /// Size of all of the patch information pointed to via the dyld_cache_patch_info
375 pub patch_info_size: U64<E>,
376 /// unused
377 pub other_image_group_addr_unused: U64<E>,
378 /// unused
379 pub other_image_group_size_unused: U64<E>,
380 /// (unslid) address of list of program launch closures
381 pub prog_closures_addr: U64<E>,
382 /// size of list of program launch closures
383 pub prog_closures_size: U64<E>,
384 /// (unslid) address of trie of indexes into program launch closures
385 pub prog_closures_trie_addr: U64<E>,
386 /// size of trie of indexes into program launch closures
387 pub prog_closures_trie_size: U64<E>,
388 /// platform number (macOS=1, etc)
389 pub platform: U32<E>,
390 // bitfield of values
391 pub flags: U32<E>,
392 /// base load address of cache if not slid
393 pub shared_region_start: U64<E>,
394 /// overall size required to map the cache and all subCaches, if any
395 pub shared_region_size: U64<E>,
396 /// runtime slide of cache can be between zero and this value
397 pub max_slide: U64<E>,
398 /// (unslid) address of ImageArray for dylibs in this cache
399 pub dylibs_image_array_addr: U64<E>,
400 /// size of ImageArray for dylibs in this cache
401 pub dylibs_image_array_size: U64<E>,
402 /// (unslid) address of trie of indexes of all cached dylibs
403 pub dylibs_trie_addr: U64<E>,
404 /// size of trie of cached dylib paths
405 pub dylibs_trie_size: U64<E>,
406 /// (unslid) address of ImageArray for dylibs and bundles with dlopen closures
407 pub other_image_array_addr: U64<E>,
408 /// size of ImageArray for dylibs and bundles with dlopen closures
409 pub other_image_array_size: U64<E>,
410 /// (unslid) address of trie of indexes of all dylibs and bundles with dlopen closures
411 pub other_trie_addr: U64<E>,
412 /// size of trie of dylibs and bundles with dlopen closures
413 pub other_trie_size: U64<E>,
414 /// file offset to first dyld_cache_mapping_and_slide_info
415 pub mapping_with_slide_offset: U32<E>,
416 /// number of dyld_cache_mapping_and_slide_info entries
417 pub mapping_with_slide_count: U32<E>,
418 /// unused
419 pub dylibs_pbl_state_array_addr_unused: U64<E>,
420 /// (unslid) address of PrebuiltLoaderSet of all cached dylibs
421 pub dylibs_pbl_set_addr: U64<E>,
422 /// (unslid) address of pool of PrebuiltLoaderSet for each program
423 pub programs_pbl_set_pool_addr: U64<E>,
424 /// size of pool of PrebuiltLoaderSet for each program
425 pub programs_pbl_set_pool_size: U64<E>,
426 /// (unslid) address of trie mapping program path to PrebuiltLoaderSet
427 pub program_trie_addr: U64<E>,
428 /// OS Version of dylibs in this cache for the main platform
429 pub os_version: U32<E>,
430 /// e.g. iOSMac on macOS
431 pub alt_platform: U32<E>,
432 /// e.g. 14.0 for iOSMac
433 pub alt_os_version: U32<E>,
434 reserved1: [u8; 4],
435 /// VM offset from cache_header* to Swift optimizations header
436 pub swift_opts_offset: U64<E>,
437 /// size of Swift optimizations header
438 pub swift_opts_size: U64<E>,
439 /// file offset to first dyld_subcache_entry
440 pub sub_cache_array_offset: U32<E>,
441 /// number of subCache entries
442 pub sub_cache_array_count: U32<E>,
443 /// unique value for the shared cache file containing unmapped local symbols
444 pub symbol_file_uuid: [u8; 16],
445 /// (unslid) address of the start of where Rosetta can add read-only/executable data
446 pub rosetta_read_only_addr: U64<E>,
447 /// maximum size of the Rosetta read-only/executable region
448 pub rosetta_read_only_size: U64<E>,
449 /// (unslid) address of the start of where Rosetta can add read-write data
450 pub rosetta_read_write_addr: U64<E>,
451 /// maximum size of the Rosetta read-write region
452 pub rosetta_read_write_size: U64<E>,
453 /// file offset to first dyld_cache_image_info
454 pub images_offset: U32<E>,
455 /// number of dyld_cache_image_info entries
456 pub images_count: U32<E>,
457 /// 0 for development, 1 for production, when cacheType is multi-cache(2)
458 pub cache_sub_type: U32<E>,
459 /// VM offset from cache_header* to ObjC optimizations header
460 pub objc_opts_offset: U64<E>,
461 /// size of ObjC optimizations header
462 pub objc_opts_size: U64<E>,
463 /// VM offset from cache_header* to embedded cache atlas for process introspection
464 pub cache_atlas_offset: U64<E>,
465 /// size of embedded cache atlas
466 pub cache_atlas_size: U64<E>,
467 /// VM offset from cache_header* to the location of dyld_cache_dynamic_data_header
468 pub dynamic_data_offset: U64<E>,
469 /// maximum size of space reserved from dynamic data
470 pub dynamic_data_max_size: U64<E>,
471}
472
473/// Corresponds to struct dyld_cache_mapping_info from dyld_cache_format.h.
474#[derive(Debug, Clone, Copy)]
475#[repr(C)]
476pub struct DyldCacheMappingInfo<E: Endian> {
477 pub address: U64<E>,
478 pub size: U64<E>,
479 pub file_offset: U64<E>,
480 pub max_prot: U32<E>,
481 pub init_prot: U32<E>,
482}
483
484// Contains the flags for the dyld_cache_mapping_and_slide_info flags field
485pub const DYLD_CACHE_MAPPING_AUTH_DATA: u64 = 1 << 0;
486pub const DYLD_CACHE_MAPPING_DIRTY_DATA: u64 = 1 << 1;
487pub const DYLD_CACHE_MAPPING_CONST_DATA: u64 = 1 << 2;
488pub const DYLD_CACHE_MAPPING_TEXT_STUBS: u64 = 1 << 3;
489pub const DYLD_CACHE_DYNAMIC_CONFIG_DATA: u64 = 1 << 4;
490
491/// Corresponds to struct dyld_cache_mapping_and_slide_info from dyld_cache_format.h.
492#[derive(Debug, Clone, Copy)]
493#[repr(C)]
494pub struct DyldCacheMappingAndSlideInfo<E: Endian> {
495 pub address: U64<E>,
496 pub size: U64<E>,
497 pub file_offset: U64<E>,
498 pub slide_info_file_offset: U64<E>,
499 pub slide_info_file_size: U64<E>,
500 pub flags: U64<E>,
501 pub max_prot: U32<E>,
502 pub init_prot: U32<E>,
503}
504
505/// Corresponds to struct dyld_cache_image_info from dyld_cache_format.h.
506#[derive(Debug, Clone, Copy)]
507#[repr(C)]
508pub struct DyldCacheImageInfo<E: Endian> {
509 pub address: U64<E>,
510 pub mod_time: U64<E>,
511 pub inode: U64<E>,
512 pub path_file_offset: U32<E>,
513 pub pad: U32<E>,
514}
515
516/// Corresponds to struct dyld_cache_slide_info2 from dyld_cache_format.h.
517#[derive(Debug, Clone, Copy)]
518#[repr(C)]
519pub struct DyldCacheSlideInfo2<E: Endian> {
520 pub version: U32<E>, // currently 2
521 pub page_size: U32<E>, // currently 4096 (may also be 16384)
522 pub page_starts_offset: U32<E>,
523 pub page_starts_count: U32<E>,
524 pub page_extras_offset: U32<E>,
525 pub page_extras_count: U32<E>,
526 pub delta_mask: U64<E>, // which (contiguous) set of bits contains the delta to the next rebase location
527 pub value_add: U64<E>,
528}
529
530pub const DYLD_CACHE_SLIDE_PAGE_ATTRS: u16 = 0xC000;
531// Index is into extras array (not starts array).
532pub const DYLD_CACHE_SLIDE_PAGE_ATTR_EXTRA: u16 = 0x8000;
533// Page has no rebasing.
534pub const DYLD_CACHE_SLIDE_PAGE_ATTR_NO_REBASE: u16 = 0x4000;
535// Last chain entry for page.
536pub const DYLD_CACHE_SLIDE_PAGE_ATTR_END: u16 = 0x8000;
537
538/// Corresponds to struct dyld_cache_slide_info3 from dyld_cache_format.h.
539#[derive(Debug, Clone, Copy)]
540#[repr(C)]
541pub struct DyldCacheSlideInfo3<E: Endian> {
542 pub version: U32<E>, // currently 3
543 pub page_size: U32<E>, // currently 4096 (may also be 16384)
544 pub page_starts_count: U32<E>,
545 reserved1: [u8; 4],
546 pub auth_value_add: U64<E>,
547}
548
549/// Page has no rebasing.
550pub const DYLD_CACHE_SLIDE_V3_PAGE_ATTR_NO_REBASE: u16 = 0xFFFF;
551
552/// Corresponds to union dyld_cache_slide_pointer3 from dyld_cache_format.h.
553#[derive(Debug, Clone, Copy)]
554pub struct DyldCacheSlidePointer3(pub u64);
555
556impl DyldCacheSlidePointer3 {
557 /// Whether the pointer is authenticated.
558 pub fn is_auth(&self) -> bool {
559 ((self.0 >> 63) & 1) != 0
560 }
561
562 /// The target of the pointer.
563 ///
564 /// Only valid if `is_auth` is false.
565 pub fn target(&self) -> u64 {
566 self.0 & ((1 << 43) - 1)
567 }
568
569 /// The high 8 bits of the pointer.
570 ///
571 /// Only valid if `is_auth` is false.
572 pub fn high8(&self) -> u64 {
573 (self.0 >> 43) & 0xff
574 }
575
576 /// The target of the pointer as an offset from the start of the shared cache.
577 ///
578 /// Only valid if `is_auth` is true.
579 pub fn runtime_offset(&self) -> u64 {
580 self.0 & ((1 << 32) - 1)
581 }
582
583 /// The diversity value for authentication.
584 ///
585 /// Only valid if `is_auth` is true.
586 pub fn diversity(&self) -> u16 {
587 ((self.0 >> 32) & 0xffff) as u16
588 }
589
590 /// Whether to use address diversity for authentication.
591 ///
592 /// Only valid if `is_auth` is true.
593 pub fn addr_div(&self) -> bool {
594 ((self.0 >> 48) & 1) != 0
595 }
596
597 /// The key for authentication.
598 ///
599 /// Only valid if `is_auth` is true.
600 pub fn key(&self) -> u8 {
601 ((self.0 >> 49) & 3) as u8
602 }
603
604 /// The offset to the next slide pointer in 8-byte units.
605 ///
606 /// 0 if no next slide pointer.
607 pub fn next(&self) -> u64 {
608 (self.0 >> 51) & ((1 << 11) - 1)
609 }
610}
611
612/// Corresponds to struct dyld_cache_slide_info5 from dyld_cache_format.h.
613#[derive(Debug, Clone, Copy)]
614#[repr(C)]
615pub struct DyldCacheSlideInfo5<E: Endian> {
616 pub version: U32<E>, // currently 5
617 pub page_size: U32<E>, // currently 4096 (may also be 16384)
618 pub page_starts_count: U32<E>,
619 reserved1: [u8; 4],
620 pub value_add: U64<E>,
621}
622
623/// Page has no rebasing.
624pub const DYLD_CACHE_SLIDE_V5_PAGE_ATTR_NO_REBASE: u16 = 0xFFFF;
625
626/// Corresponds to struct dyld_cache_slide_pointer5 from dyld_cache_format.h.
627#[derive(Debug, Clone, Copy)]
628pub struct DyldCacheSlidePointer5(pub u64);
629
630impl DyldCacheSlidePointer5 {
631 /// Whether the pointer is authenticated.
632 pub fn is_auth(&self) -> bool {
633 ((self.0 >> 63) & 1) != 0
634 }
635
636 /// The target of the pointer as an offset from the start of the shared cache.
637 pub fn runtime_offset(&self) -> u64 {
638 self.0 & 0x3_ffff_ffff
639 }
640
641 /// The high 8 bits of the pointer.
642 ///
643 /// Only valid if `is_auth` is false.
644 pub fn high8(&self) -> u64 {
645 (self.0 >> 34) & 0xff
646 }
647
648 /// The diversity value for authentication.
649 ///
650 /// Only valid if `is_auth` is true.
651 pub fn diversity(&self) -> u16 {
652 ((self.0 >> 34) & 0xffff) as u16
653 }
654
655 /// Whether to use address diversity for authentication.
656 ///
657 /// Only valid if `is_auth` is true.
658 pub fn addr_div(&self) -> bool {
659 ((self.0 >> 50) & 1) != 0
660 }
661
662 /// Whether the key is IA or DA.
663 ///
664 /// Only valid if `is_auth` is true.
665 pub fn key_is_data(&self) -> bool {
666 ((self.0 >> 51) & 1) != 0
667 }
668
669 /// The offset to the next slide pointer in 8-byte units.
670 ///
671 /// 0 if no next slide pointer.
672 pub fn next(&self) -> u64 {
673 (self.0 >> 52) & 0x7ff
674 }
675}
676
677/// Added in dyld-940, which shipped with macOS 12 / iOS 15.
678/// Originally called `dyld_subcache_entry`, renamed to `dyld_subcache_entry_v1`
679/// in dyld-1042.1.
680#[derive(Debug, Clone, Copy)]
681#[repr(C)]
682pub struct DyldSubCacheEntryV1<E: Endian> {
683 /// The UUID of this subcache.
684 pub uuid: [u8; 16],
685 /// The offset of this subcache from the main cache base address.
686 pub cache_vm_offset: U64<E>,
687}
688
689/// Added in dyld-1042.1, which shipped with macOS 13 / iOS 16.
690/// Called `dyld_subcache_entry` as of dyld-1042.1.
691#[derive(Debug, Clone, Copy)]
692#[repr(C)]
693pub struct DyldSubCacheEntryV2<E: Endian> {
694 /// The UUID of this subcache.
695 pub uuid: [u8; 16],
696 /// The offset of this subcache from the main cache base address.
697 pub cache_vm_offset: U64<E>,
698 /// The file name suffix of the subCache file, e.g. ".25.data" or ".03.development".
699 pub file_suffix: [u8; 32],
700}
701
702// Definitions from "/usr/include/mach-o/fat.h".
703
704/*
705 * This header file describes the structures of the file format for "fat"
706 * architecture specific file (wrapper design). At the beginning of the file
707 * there is one `FatHeader` structure followed by a number of `FatArch*`
708 * structures. For each architecture in the file, specified by a pair of
709 * cputype and cpusubtype, the `FatHeader` describes the file offset, file
710 * size and alignment in the file of the architecture specific member.
711 * The padded bytes in the file to place each member on it's specific alignment
712 * are defined to be read as zeros and can be left as "holes" if the file system
713 * can support them as long as they read as zeros.
714 *
715 * All structures defined here are always written and read to/from disk
716 * in big-endian order.
717 */
718
719pub const FAT_MAGIC: u32 = 0xcafe_babe;
720/// NXSwapLong(FAT_MAGIC)
721pub const FAT_CIGAM: u32 = 0xbeba_feca;
722
723#[derive(Debug, Clone, Copy)]
724#[repr(C)]
725pub struct FatHeader {
726 /// FAT_MAGIC or FAT_MAGIC_64
727 pub magic: U32<BigEndian>,
728 /// number of structs that follow
729 pub nfat_arch: U32<BigEndian>,
730}
731
732#[derive(Debug, Clone, Copy)]
733#[repr(C)]
734pub struct FatArch32 {
735 /// cpu specifier (int)
736 pub cputype: U32<BigEndian>,
737 /// machine specifier (int)
738 pub cpusubtype: U32<BigEndian>,
739 /// file offset to this object file
740 pub offset: U32<BigEndian>,
741 /// size of this object file
742 pub size: U32<BigEndian>,
743 /// alignment as a power of 2
744 pub align: U32<BigEndian>,
745}
746
747/*
748 * The support for the 64-bit fat file format described here is a work in
749 * progress and not yet fully supported in all the Apple Developer Tools.
750 *
751 * When a slice is greater than 4mb or an offset to a slice is greater than 4mb
752 * then the 64-bit fat file format is used.
753 */
754pub const FAT_MAGIC_64: u32 = 0xcafe_babf;
755/// NXSwapLong(FAT_MAGIC_64)
756pub const FAT_CIGAM_64: u32 = 0xbfba_feca;
757
758#[derive(Debug, Clone, Copy)]
759#[repr(C)]
760pub struct FatArch64 {
761 /// cpu specifier (int)
762 pub cputype: U32<BigEndian>,
763 /// machine specifier (int)
764 pub cpusubtype: U32<BigEndian>,
765 /// file offset to this object file
766 pub offset: U64<BigEndian>,
767 /// size of this object file
768 pub size: U64<BigEndian>,
769 /// alignment as a power of 2
770 pub align: U32<BigEndian>,
771 /// reserved
772 pub reserved: U32<BigEndian>,
773}
774
775// Definitions from "/usr/include/mach-o/loader.h".
776
777/// The 32-bit mach header.
778///
779/// Appears at the very beginning of the object file for 32-bit architectures.
780#[derive(Debug, Clone, Copy)]
781#[repr(C)]
782pub struct MachHeader32<E: Endian> {
783 /// mach magic number identifier
784 pub magic: U32<BigEndian>,
785 /// cpu specifier
786 pub cputype: U32<E>,
787 /// machine specifier
788 pub cpusubtype: U32<E>,
789 /// type of file
790 pub filetype: U32<E>,
791 /// number of load commands
792 pub ncmds: U32<E>,
793 /// the size of all the load commands
794 pub sizeofcmds: U32<E>,
795 /// flags
796 pub flags: U32<E>,
797}
798
799// Values for `MachHeader32::magic`.
800/// the mach magic number
801pub const MH_MAGIC: u32 = 0xfeed_face;
802/// NXSwapInt(MH_MAGIC)
803pub const MH_CIGAM: u32 = 0xcefa_edfe;
804
805/// The 64-bit mach header.
806///
807/// Appears at the very beginning of object files for 64-bit architectures.
808#[derive(Debug, Clone, Copy)]
809#[repr(C)]
810pub struct MachHeader64<E: Endian> {
811 /// mach magic number identifier
812 pub magic: U32<BigEndian>,
813 /// cpu specifier
814 pub cputype: U32<E>,
815 /// machine specifier
816 pub cpusubtype: U32<E>,
817 /// type of file
818 pub filetype: U32<E>,
819 /// number of load commands
820 pub ncmds: U32<E>,
821 /// the size of all the load commands
822 pub sizeofcmds: U32<E>,
823 /// flags
824 pub flags: U32<E>,
825 /// reserved
826 pub reserved: U32<E>,
827}
828
829// Values for `MachHeader64::magic`.
830/// the 64-bit mach magic number
831pub const MH_MAGIC_64: u32 = 0xfeed_facf;
832/// NXSwapInt(MH_MAGIC_64)
833pub const MH_CIGAM_64: u32 = 0xcffa_edfe;
834
835/*
836 * The layout of the file depends on the filetype. For all but the MH_OBJECT
837 * file type the segments are padded out and aligned on a segment alignment
838 * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
839 * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
840 * of their first segment.
841 *
842 * The file type MH_OBJECT is a compact format intended as output of the
843 * assembler and input (and possibly output) of the link editor (the .o
844 * format). All sections are in one unnamed segment with no segment padding.
845 * This format is used as an executable format when the file is so small the
846 * segment padding greatly increases its size.
847 *
848 * The file type MH_PRELOAD is an executable format intended for things that
849 * are not executed under the kernel (proms, stand alones, kernels, etc). The
850 * format can be executed under the kernel but may demand paged it and not
851 * preload it before execution.
852 *
853 * A core file is in MH_CORE format and can be any in an arbritray legal
854 * Mach-O file.
855 */
856
857// Values for `MachHeader*::filetype`.
858/// relocatable object file
859pub const MH_OBJECT: u32 = 0x1;
860/// demand paged executable file
861pub const MH_EXECUTE: u32 = 0x2;
862/// fixed VM shared library file
863pub const MH_FVMLIB: u32 = 0x3;
864/// core file
865pub const MH_CORE: u32 = 0x4;
866/// preloaded executable file
867pub const MH_PRELOAD: u32 = 0x5;
868/// dynamically bound shared library
869pub const MH_DYLIB: u32 = 0x6;
870/// dynamic link editor
871pub const MH_DYLINKER: u32 = 0x7;
872/// dynamically bound bundle file
873pub const MH_BUNDLE: u32 = 0x8;
874/// shared library stub for static linking only, no section contents
875pub const MH_DYLIB_STUB: u32 = 0x9;
876/// companion file with only debug sections
877pub const MH_DSYM: u32 = 0xa;
878/// x86_64 kexts
879pub const MH_KEXT_BUNDLE: u32 = 0xb;
880/// a file composed of other Mach-Os to be run in the same userspace sharing a single linkedit.
881pub const MH_FILESET: u32 = 0xc;
882/// gpu program
883pub const MH_GPU_EXECUTE: u32 = 0xd;
884/// gpu support functions
885pub const MH_GPU_DYLIB: u32 = 0xe;
886
887// Values for `MachHeader*::flags`.
888/// the object file has no undefined references
889pub const MH_NOUNDEFS: u32 = 0x1;
890/// the object file is the output of an incremental link against a base file and can't be link edited again
891pub const MH_INCRLINK: u32 = 0x2;
892/// the object file is input for the dynamic linker and can't be statically link edited again
893pub const MH_DYLDLINK: u32 = 0x4;
894/// the object file's undefined references are bound by the dynamic linker when loaded.
895pub const MH_BINDATLOAD: u32 = 0x8;
896/// the file has its dynamic undefined references prebound.
897pub const MH_PREBOUND: u32 = 0x10;
898/// the file has its read-only and read-write segments split
899pub const MH_SPLIT_SEGS: u32 = 0x20;
900/// the shared library init routine is to be run lazily via catching memory faults to its writeable segments (obsolete)
901pub const MH_LAZY_INIT: u32 = 0x40;
902/// the image is using two-level name space bindings
903pub const MH_TWOLEVEL: u32 = 0x80;
904/// the executable is forcing all images to use flat name space bindings
905pub const MH_FORCE_FLAT: u32 = 0x100;
906/// this umbrella guarantees no multiple definitions of symbols in its sub-images so the two-level namespace hints can always be used.
907pub const MH_NOMULTIDEFS: u32 = 0x200;
908/// do not have dyld notify the prebinding agent about this executable
909pub const MH_NOFIXPREBINDING: u32 = 0x400;
910/// the binary is not prebound but can have its prebinding redone. only used when MH_PREBOUND is not set.
911pub const MH_PREBINDABLE: u32 = 0x800;
912/// indicates that this binary binds to all two-level namespace modules of its dependent libraries. only used when MH_PREBINDABLE and MH_TWOLEVEL are both set.
913pub const MH_ALLMODSBOUND: u32 = 0x1000;
914/// safe to divide up the sections into sub-sections via symbols for dead code stripping
915pub const MH_SUBSECTIONS_VIA_SYMBOLS: u32 = 0x2000;
916/// the binary has been canonicalized via the unprebind operation
917pub const MH_CANONICAL: u32 = 0x4000;
918/// the final linked image contains external weak symbols
919pub const MH_WEAK_DEFINES: u32 = 0x8000;
920/// the final linked image uses weak symbols
921pub const MH_BINDS_TO_WEAK: u32 = 0x10000;
922/// When this bit is set, all stacks in the task will be given stack execution privilege. Only used in MH_EXECUTE filetypes.
923pub const MH_ALLOW_STACK_EXECUTION: u32 = 0x20000;
924/// When this bit is set, the binary declares it is safe for use in processes with uid zero
925pub const MH_ROOT_SAFE: u32 = 0x40000;
926/// When this bit is set, the binary declares it is safe for use in processes when issetugid() is true
927pub const MH_SETUID_SAFE: u32 = 0x80000;
928/// When this bit is set on a dylib, the static linker does not need to examine dependent dylibs to see if any are re-exported
929pub const MH_NO_REEXPORTED_DYLIBS: u32 = 0x10_0000;
930/// When this bit is set, the OS will load the main executable at a random address. Only used in MH_EXECUTE filetypes.
931pub const MH_PIE: u32 = 0x20_0000;
932/// Only for use on dylibs. When linking against a dylib that has this bit set, the static linker will automatically not create a LC_LOAD_DYLIB load command to the dylib if no symbols are being referenced from the dylib.
933pub const MH_DEAD_STRIPPABLE_DYLIB: u32 = 0x40_0000;
934/// Contains a section of type S_THREAD_LOCAL_VARIABLES
935pub const MH_HAS_TLV_DESCRIPTORS: u32 = 0x80_0000;
936/// When this bit is set, the OS will run the main executable with a non-executable heap even on platforms (e.g. i386) that don't require it. Only used in MH_EXECUTE filetypes.
937pub const MH_NO_HEAP_EXECUTION: u32 = 0x100_0000;
938/// The code was linked for use in an application extension.
939pub const MH_APP_EXTENSION_SAFE: u32 = 0x0200_0000;
940/// The external symbols listed in the nlist symbol table do not include all the symbols listed in the dyld info.
941pub const MH_NLIST_OUTOFSYNC_WITH_DYLDINFO: u32 = 0x0400_0000;
942/// Allow LC_MIN_VERSION_MACOS and LC_BUILD_VERSION load commands with
943/// the platforms macOS, iOSMac, iOSSimulator, tvOSSimulator and watchOSSimulator.
944pub const MH_SIM_SUPPORT: u32 = 0x0800_0000;
945/// main executable has no __PAGEZERO segment. Instead, loader (xnu) will load program high and block out all memory below it.
946pub const MH_IMPLICIT_PAGEZERO: u32 = 0x1000_0000;
947/// Only for use on dylibs. When this bit is set, the dylib is part of the dyld
948/// shared cache, rather than loose in the filesystem.
949pub const MH_DYLIB_IN_CACHE: u32 = 0x8000_0000;
950
951/// Common fields at the start of every load command.
952///
953/// The load commands directly follow the mach_header. The total size of all
954/// of the commands is given by the sizeofcmds field in the mach_header. All
955/// load commands must have as their first two fields `cmd` and `cmdsize`. The `cmd`
956/// field is filled in with a constant for that command type. Each command type
957/// has a structure specifically for it. The `cmdsize` field is the size in bytes
958/// of the particular load command structure plus anything that follows it that
959/// is a part of the load command (i.e. section structures, strings, etc.). To
960/// advance to the next load command the `cmdsize` can be added to the offset or
961/// pointer of the current load command. The `cmdsize` for 32-bit architectures
962/// MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple
963/// of 8 bytes (these are forever the maximum alignment of any load commands).
964/// The padded bytes must be zero. All tables in the object file must also
965/// follow these rules so the file can be memory mapped. Otherwise the pointers
966/// to these tables will not work well or at all on some machines. With all
967/// padding zeroed like objects will compare byte for byte.
968#[derive(Debug, Clone, Copy)]
969#[repr(C)]
970pub struct LoadCommand<E: Endian> {
971 /// Type of load command.
972 ///
973 /// One of the `LC_*` constants.
974 pub cmd: U32<E>,
975 /// Total size of command in bytes.
976 pub cmdsize: U32<E>,
977}
978
979/*
980 * After MacOS X 10.1 when a new load command is added that is required to be
981 * understood by the dynamic linker for the image to execute properly the
982 * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic
983 * linker sees such a load command it it does not understand will issue a
984 * "unknown load command required for execution" error and refuse to use the
985 * image. Other load commands without this bit that are not understood will
986 * simply be ignored.
987 */
988pub const LC_REQ_DYLD: u32 = 0x8000_0000;
989
990/* Constants for the cmd field of all load commands, the type */
991/// segment of this file to be mapped
992pub const LC_SEGMENT: u32 = 0x1;
993/// link-edit stab symbol table info
994pub const LC_SYMTAB: u32 = 0x2;
995/// link-edit gdb symbol table info (obsolete)
996pub const LC_SYMSEG: u32 = 0x3;
997/// thread
998pub const LC_THREAD: u32 = 0x4;
999/// unix thread (includes a stack)
1000pub const LC_UNIXTHREAD: u32 = 0x5;
1001/// load a specified fixed VM shared library
1002pub const LC_LOADFVMLIB: u32 = 0x6;
1003/// fixed VM shared library identification
1004pub const LC_IDFVMLIB: u32 = 0x7;
1005/// object identification info (obsolete)
1006pub const LC_IDENT: u32 = 0x8;
1007/// fixed VM file inclusion (internal use)
1008pub const LC_FVMFILE: u32 = 0x9;
1009/// prepage command (internal use)
1010pub const LC_PREPAGE: u32 = 0xa;
1011/// dynamic link-edit symbol table info
1012pub const LC_DYSYMTAB: u32 = 0xb;
1013/// load a dynamically linked shared library
1014pub const LC_LOAD_DYLIB: u32 = 0xc;
1015/// dynamically linked shared lib ident
1016pub const LC_ID_DYLIB: u32 = 0xd;
1017/// load a dynamic linker
1018pub const LC_LOAD_DYLINKER: u32 = 0xe;
1019/// dynamic linker identification
1020pub const LC_ID_DYLINKER: u32 = 0xf;
1021/// modules prebound for a dynamically linked shared library
1022pub const LC_PREBOUND_DYLIB: u32 = 0x10;
1023/// image routines
1024pub const LC_ROUTINES: u32 = 0x11;
1025/// sub framework
1026pub const LC_SUB_FRAMEWORK: u32 = 0x12;
1027/// sub umbrella
1028pub const LC_SUB_UMBRELLA: u32 = 0x13;
1029/// sub client
1030pub const LC_SUB_CLIENT: u32 = 0x14;
1031/// sub library
1032pub const LC_SUB_LIBRARY: u32 = 0x15;
1033/// two-level namespace lookup hints
1034pub const LC_TWOLEVEL_HINTS: u32 = 0x16;
1035/// prebind checksum
1036pub const LC_PREBIND_CKSUM: u32 = 0x17;
1037/// load a dynamically linked shared library that is allowed to be missing
1038/// (all symbols are weak imported).
1039pub const LC_LOAD_WEAK_DYLIB: u32 = 0x18 | LC_REQ_DYLD;
1040/// 64-bit segment of this file to be mapped
1041pub const LC_SEGMENT_64: u32 = 0x19;
1042/// 64-bit image routines
1043pub const LC_ROUTINES_64: u32 = 0x1a;
1044/// the uuid
1045pub const LC_UUID: u32 = 0x1b;
1046/// runpath additions
1047pub const LC_RPATH: u32 = 0x1c | LC_REQ_DYLD;
1048/// local of code signature
1049pub const LC_CODE_SIGNATURE: u32 = 0x1d;
1050/// local of info to split segments
1051pub const LC_SEGMENT_SPLIT_INFO: u32 = 0x1e;
1052/// load and re-export dylib
1053pub const LC_REEXPORT_DYLIB: u32 = 0x1f | LC_REQ_DYLD;
1054/// delay load of dylib until first use
1055pub const LC_LAZY_LOAD_DYLIB: u32 = 0x20;
1056/// encrypted segment information
1057pub const LC_ENCRYPTION_INFO: u32 = 0x21;
1058/// compressed dyld information
1059pub const LC_DYLD_INFO: u32 = 0x22;
1060/// compressed dyld information only
1061pub const LC_DYLD_INFO_ONLY: u32 = 0x22 | LC_REQ_DYLD;
1062/// load upward dylib
1063pub const LC_LOAD_UPWARD_DYLIB: u32 = 0x23 | LC_REQ_DYLD;
1064/// build for MacOSX min OS version
1065pub const LC_VERSION_MIN_MACOSX: u32 = 0x24;
1066/// build for iPhoneOS min OS version
1067pub const LC_VERSION_MIN_IPHONEOS: u32 = 0x25;
1068/// compressed table of function start addresses
1069pub const LC_FUNCTION_STARTS: u32 = 0x26;
1070/// string for dyld to treat like environment variable
1071pub const LC_DYLD_ENVIRONMENT: u32 = 0x27;
1072/// replacement for LC_UNIXTHREAD
1073pub const LC_MAIN: u32 = 0x28 | LC_REQ_DYLD;
1074/// table of non-instructions in __text
1075pub const LC_DATA_IN_CODE: u32 = 0x29;
1076/// source version used to build binary
1077pub const LC_SOURCE_VERSION: u32 = 0x2A;
1078/// Code signing DRs copied from linked dylibs
1079pub const LC_DYLIB_CODE_SIGN_DRS: u32 = 0x2B;
1080/// 64-bit encrypted segment information
1081pub const LC_ENCRYPTION_INFO_64: u32 = 0x2C;
1082/// linker options in MH_OBJECT files
1083pub const LC_LINKER_OPTION: u32 = 0x2D;
1084/// optimization hints in MH_OBJECT files
1085pub const LC_LINKER_OPTIMIZATION_HINT: u32 = 0x2E;
1086/// build for AppleTV min OS version
1087pub const LC_VERSION_MIN_TVOS: u32 = 0x2F;
1088/// build for Watch min OS version
1089pub const LC_VERSION_MIN_WATCHOS: u32 = 0x30;
1090/// arbitrary data included within a Mach-O file
1091pub const LC_NOTE: u32 = 0x31;
1092/// build for platform min OS version
1093pub const LC_BUILD_VERSION: u32 = 0x32;
1094/// used with `LinkeditDataCommand`, payload is trie
1095pub const LC_DYLD_EXPORTS_TRIE: u32 = 0x33 | LC_REQ_DYLD;
1096/// used with `LinkeditDataCommand`
1097pub const LC_DYLD_CHAINED_FIXUPS: u32 = 0x34 | LC_REQ_DYLD;
1098/// used with `FilesetEntryCommand`
1099pub const LC_FILESET_ENTRY: u32 = 0x35 | LC_REQ_DYLD;
1100/// used with linkedit_data_command
1101pub const LC_ATOM_INFO: u32 = 0x36;
1102/// used with linkedit_data_command
1103pub const LC_FUNCTION_VARIANTS: u32 = 0x37;
1104/// used with linkedit_data_command
1105pub const LC_FUNCTION_VARIANT_FIXUPS: u32 = 0x38;
1106/// target triple used to compile
1107pub const LC_TARGET_TRIPLE: u32 = 0x39;
1108
1109/// A variable length string in a load command.
1110///
1111/// The strings are stored just after the load command structure and
1112/// the offset is from the start of the load command structure. The size
1113/// of the string is reflected in the `cmdsize` field of the load command.
1114/// Once again any padded bytes to bring the `cmdsize` field to a multiple
1115/// of 4 bytes must be zero.
1116#[derive(Debug, Clone, Copy)]
1117#[repr(C)]
1118pub struct LcStr<E: Endian> {
1119 /// offset to the string
1120 pub offset: U32<E>,
1121}
1122
1123/// 32-bit segment load command.
1124///
1125/// The segment load command indicates that a part of this file is to be
1126/// mapped into the task's address space. The size of this segment in memory,
1127/// vmsize, maybe equal to or larger than the amount to map from this file,
1128/// filesize. The file is mapped starting at fileoff to the beginning of
1129/// the segment in memory, vmaddr. The rest of the memory of the segment,
1130/// if any, is allocated zero fill on demand. The segment's maximum virtual
1131/// memory protection and initial virtual memory protection are specified
1132/// by the maxprot and initprot fields. If the segment has sections then the
1133/// `Section32` structures directly follow the segment command and their size is
1134/// reflected in `cmdsize`.
1135#[derive(Debug, Clone, Copy)]
1136#[repr(C)]
1137pub struct SegmentCommand32<E: Endian> {
1138 /// LC_SEGMENT
1139 pub cmd: U32<E>,
1140 /// includes sizeof section structs
1141 pub cmdsize: U32<E>,
1142 /// segment name
1143 pub segname: [u8; 16],
1144 /// memory address of this segment
1145 pub vmaddr: U32<E>,
1146 /// memory size of this segment
1147 pub vmsize: U32<E>,
1148 /// file offset of this segment
1149 pub fileoff: U32<E>,
1150 /// amount to map from the file
1151 pub filesize: U32<E>,
1152 /// maximum VM protection
1153 pub maxprot: U32<E>,
1154 /// initial VM protection
1155 pub initprot: U32<E>,
1156 /// number of sections in segment
1157 pub nsects: U32<E>,
1158 /// flags
1159 pub flags: U32<E>,
1160}
1161
1162/// 64-bit segment load command.
1163///
1164/// The 64-bit segment load command indicates that a part of this file is to be
1165/// mapped into a 64-bit task's address space. If the 64-bit segment has
1166/// sections then `Section64` structures directly follow the 64-bit segment
1167/// command and their size is reflected in `cmdsize`.
1168#[derive(Debug, Clone, Copy)]
1169#[repr(C)]
1170pub struct SegmentCommand64<E: Endian> {
1171 /// LC_SEGMENT_64
1172 pub cmd: U32<E>,
1173 /// includes sizeof section_64 structs
1174 pub cmdsize: U32<E>,
1175 /// segment name
1176 pub segname: [u8; 16],
1177 /// memory address of this segment
1178 pub vmaddr: U64<E>,
1179 /// memory size of this segment
1180 pub vmsize: U64<E>,
1181 /// file offset of this segment
1182 pub fileoff: U64<E>,
1183 /// amount to map from the file
1184 pub filesize: U64<E>,
1185 /// maximum VM protection
1186 pub maxprot: U32<E>,
1187 /// initial VM protection
1188 pub initprot: U32<E>,
1189 /// number of sections in segment
1190 pub nsects: U32<E>,
1191 /// flags
1192 pub flags: U32<E>,
1193}
1194
1195// Values for `SegmentCommand*::flags`.
1196/// the file contents for this segment is for the high part of the VM space, the low part is zero filled (for stacks in core files)
1197pub const SG_HIGHVM: u32 = 0x1;
1198/// this segment is the VM that is allocated by a fixed VM library, for overlap checking in the link editor
1199pub const SG_FVMLIB: u32 = 0x2;
1200/// this segment has nothing that was relocated in it and nothing relocated to it, that is it maybe safely replaced without relocation
1201pub const SG_NORELOC: u32 = 0x4;
1202/// This segment is protected. If the segment starts at file offset 0, the first page of the segment is not protected. All other pages of the segment are protected.
1203pub const SG_PROTECTED_VERSION_1: u32 = 0x8;
1204/// This segment is made read-only after fixups
1205pub const SG_READ_ONLY: u32 = 0x10;
1206
1207/*
1208 * A segment is made up of zero or more sections. Non-MH_OBJECT files have
1209 * all of their segments with the proper sections in each, and padded to the
1210 * specified segment alignment when produced by the link editor. The first
1211 * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
1212 * and load commands of the object file before its first section. The zero
1213 * fill sections are always last in their segment (in all formats). This
1214 * allows the zeroed segment padding to be mapped into memory where zero fill
1215 * sections might be. The gigabyte zero fill sections, those with the section
1216 * type S_GB_ZEROFILL, can only be in a segment with sections of this type.
1217 * These segments are then placed after all other segments.
1218 *
1219 * The MH_OBJECT format has all of its sections in one segment for
1220 * compactness. There is no padding to a specified segment boundary and the
1221 * mach_header and load commands are not part of the segment.
1222 *
1223 * Sections with the same section name, sectname, going into the same segment,
1224 * segname, are combined by the link editor. The resulting section is aligned
1225 * to the maximum alignment of the combined sections and is the new section's
1226 * alignment. The combined sections are aligned to their original alignment in
1227 * the combined section. Any padded bytes to get the specified alignment are
1228 * zeroed.
1229 *
1230 * The format of the relocation entries referenced by the reloff and nreloc
1231 * fields of the section structure for mach object files is described in the
1232 * header file <reloc.h>.
1233 */
1234/// 32-bit section.
1235#[derive(Debug, Clone, Copy)]
1236#[repr(C)]
1237pub struct Section32<E: Endian> {
1238 /// name of this section
1239 pub sectname: [u8; 16],
1240 /// segment this section goes in
1241 pub segname: [u8; 16],
1242 /// memory address of this section
1243 pub addr: U32<E>,
1244 /// size in bytes of this section
1245 pub size: U32<E>,
1246 /// file offset of this section
1247 pub offset: U32<E>,
1248 /// section alignment (power of 2)
1249 pub align: U32<E>,
1250 /// file offset of relocation entries
1251 pub reloff: U32<E>,
1252 /// number of relocation entries
1253 pub nreloc: U32<E>,
1254 /// flags (section type and attributes)
1255 pub flags: U32<E>,
1256 /// reserved (for offset or index)
1257 pub reserved1: U32<E>,
1258 /// reserved (for count or sizeof)
1259 pub reserved2: U32<E>,
1260}
1261
1262/// 64-bit section.
1263#[derive(Debug, Clone, Copy)]
1264#[repr(C)]
1265pub struct Section64<E: Endian> {
1266 /// name of this section
1267 pub sectname: [u8; 16],
1268 /// segment this section goes in
1269 pub segname: [u8; 16],
1270 /// memory address of this section
1271 pub addr: U64<E>,
1272 /// size in bytes of this section
1273 pub size: U64<E>,
1274 /// file offset of this section
1275 pub offset: U32<E>,
1276 /// section alignment (power of 2)
1277 pub align: U32<E>,
1278 /// file offset of relocation entries
1279 pub reloff: U32<E>,
1280 /// number of relocation entries
1281 pub nreloc: U32<E>,
1282 /// flags (section type and attributes)
1283 pub flags: U32<E>,
1284 /// reserved (for offset or index)
1285 pub reserved1: U32<E>,
1286 /// reserved (for count or sizeof)
1287 pub reserved2: U32<E>,
1288 /// reserved
1289 pub reserved3: U32<E>,
1290}
1291
1292/*
1293 * The flags field of a section structure is separated into two parts a section
1294 * type and section attributes. The section types are mutually exclusive (it
1295 * can only have one type) but the section attributes are not (it may have more
1296 * than one attribute).
1297 */
1298/// 256 section types
1299pub const SECTION_TYPE: u32 = 0x0000_00ff;
1300/// 24 section attributes
1301pub const SECTION_ATTRIBUTES: u32 = 0xffff_ff00;
1302
1303/* Constants for the type of a section */
1304/// regular section
1305pub const S_REGULAR: u32 = 0x0;
1306/// zero fill on demand section
1307pub const S_ZEROFILL: u32 = 0x1;
1308/// section with only literal C strings
1309pub const S_CSTRING_LITERALS: u32 = 0x2;
1310/// section with only 4 byte literals
1311pub const S_4BYTE_LITERALS: u32 = 0x3;
1312/// section with only 8 byte literals
1313pub const S_8BYTE_LITERALS: u32 = 0x4;
1314/// section with only pointers to literals
1315pub const S_LITERAL_POINTERS: u32 = 0x5;
1316/*
1317 * For the two types of symbol pointers sections and the symbol stubs section
1318 * they have indirect symbol table entries. For each of the entries in the
1319 * section the indirect symbol table entries, in corresponding order in the
1320 * indirect symbol table, start at the index stored in the reserved1 field
1321 * of the section structure. Since the indirect symbol table entries
1322 * correspond to the entries in the section the number of indirect symbol table
1323 * entries is inferred from the size of the section divided by the size of the
1324 * entries in the section. For symbol pointers sections the size of the entries
1325 * in the section is 4 bytes and for symbol stubs sections the byte size of the
1326 * stubs is stored in the reserved2 field of the section structure.
1327 */
1328/// section with only non-lazy symbol pointers
1329pub const S_NON_LAZY_SYMBOL_POINTERS: u32 = 0x6;
1330/// section with only lazy symbol pointers
1331pub const S_LAZY_SYMBOL_POINTERS: u32 = 0x7;
1332/// section with only symbol stubs, byte size of stub in the reserved2 field
1333pub const S_SYMBOL_STUBS: u32 = 0x8;
1334/// section with only function pointers for initialization
1335pub const S_MOD_INIT_FUNC_POINTERS: u32 = 0x9;
1336/// section with only function pointers for termination
1337pub const S_MOD_TERM_FUNC_POINTERS: u32 = 0xa;
1338/// section contains symbols that are to be coalesced
1339pub const S_COALESCED: u32 = 0xb;
1340/// zero fill on demand section (that can be larger than 4 gigabytes)
1341pub const S_GB_ZEROFILL: u32 = 0xc;
1342/// section with only pairs of function pointers for interposing
1343pub const S_INTERPOSING: u32 = 0xd;
1344/// section with only 16 byte literals
1345pub const S_16BYTE_LITERALS: u32 = 0xe;
1346/// section contains DTrace Object Format
1347pub const S_DTRACE_DOF: u32 = 0xf;
1348/// section with only lazy symbol pointers to lazy loaded dylibs
1349pub const S_LAZY_DYLIB_SYMBOL_POINTERS: u32 = 0x10;
1350/*
1351 * Section types to support thread local variables
1352 */
1353/// template of initial values for TLVs
1354pub const S_THREAD_LOCAL_REGULAR: u32 = 0x11;
1355/// template of initial values for TLVs
1356pub const S_THREAD_LOCAL_ZEROFILL: u32 = 0x12;
1357/// TLV descriptors
1358pub const S_THREAD_LOCAL_VARIABLES: u32 = 0x13;
1359/// pointers to TLV descriptors
1360pub const S_THREAD_LOCAL_VARIABLE_POINTERS: u32 = 0x14;
1361/// functions to call to initialize TLV values
1362pub const S_THREAD_LOCAL_INIT_FUNCTION_POINTERS: u32 = 0x15;
1363/// 32-bit offsets to initializers
1364pub const S_INIT_FUNC_OFFSETS: u32 = 0x16;
1365
1366/*
1367 * Constants for the section attributes part of the flags field of a section
1368 * structure.
1369 */
1370/// User setable attributes
1371pub const SECTION_ATTRIBUTES_USR: u32 = 0xff00_0000;
1372/// section contains only true machine instructions
1373pub const S_ATTR_PURE_INSTRUCTIONS: u32 = 0x8000_0000;
1374/// section contains coalesced symbols that are not to be in a ranlib table of contents
1375pub const S_ATTR_NO_TOC: u32 = 0x4000_0000;
1376/// ok to strip static symbols in this section in files with the MH_DYLDLINK flag
1377pub const S_ATTR_STRIP_STATIC_SYMS: u32 = 0x2000_0000;
1378/// no dead stripping
1379pub const S_ATTR_NO_DEAD_STRIP: u32 = 0x1000_0000;
1380/// blocks are live if they reference live blocks
1381pub const S_ATTR_LIVE_SUPPORT: u32 = 0x0800_0000;
1382/// Used with i386 code stubs written on by dyld
1383pub const S_ATTR_SELF_MODIFYING_CODE: u32 = 0x0400_0000;
1384/*
1385 * If a segment contains any sections marked with S_ATTR_DEBUG then all
1386 * sections in that segment must have this attribute. No section other than
1387 * a section marked with this attribute may reference the contents of this
1388 * section. A section with this attribute may contain no symbols and must have
1389 * a section type S_REGULAR. The static linker will not copy section contents
1390 * from sections with this attribute into its output file. These sections
1391 * generally contain DWARF debugging info.
1392 */
1393/// a debug section
1394pub const S_ATTR_DEBUG: u32 = 0x0200_0000;
1395/// system setable attributes
1396pub const SECTION_ATTRIBUTES_SYS: u32 = 0x00ff_ff00;
1397/// section contains some machine instructions
1398pub const S_ATTR_SOME_INSTRUCTIONS: u32 = 0x0000_0400;
1399/// section has external relocation entries
1400pub const S_ATTR_EXT_RELOC: u32 = 0x0000_0200;
1401/// section has local relocation entries
1402pub const S_ATTR_LOC_RELOC: u32 = 0x0000_0100;
1403
1404/*
1405 * The names of segments and sections in them are mostly meaningless to the
1406 * link-editor. But there are few things to support traditional UNIX
1407 * executables that require the link-editor and assembler to use some names
1408 * agreed upon by convention.
1409 *
1410 * The initial protection of the "__TEXT" segment has write protection turned
1411 * off (not writeable).
1412 *
1413 * The link-editor will allocate common symbols at the end of the "__common"
1414 * section in the "__DATA" segment. It will create the section and segment
1415 * if needed.
1416 */
1417
1418/* The currently known segment names and the section names in those segments */
1419
1420/// the pagezero segment which has no protections and catches NULL references for MH_EXECUTE files
1421pub const SEG_PAGEZERO: &str = "__PAGEZERO";
1422
1423/// the tradition UNIX text segment
1424pub const SEG_TEXT: &str = "__TEXT";
1425/// the real text part of the text section no headers, and no padding
1426pub const SECT_TEXT: &str = "__text";
1427/// the fvmlib initialization section
1428pub const SECT_FVMLIB_INIT0: &str = "__fvmlib_init0";
1429/// the section following the fvmlib initialization section
1430pub const SECT_FVMLIB_INIT1: &str = "__fvmlib_init1";
1431
1432/// the tradition UNIX data segment
1433pub const SEG_DATA: &str = "__DATA";
1434/// the real initialized data section no padding, no bss overlap
1435pub const SECT_DATA: &str = "__data";
1436/// the real uninitialized data section no padding
1437pub const SECT_BSS: &str = "__bss";
1438/// the section common symbols are allocated in by the link editor
1439pub const SECT_COMMON: &str = "__common";
1440
1441/// objective-C runtime segment
1442pub const SEG_OBJC: &str = "__OBJC";
1443/// symbol table
1444pub const SECT_OBJC_SYMBOLS: &str = "__symbol_table";
1445/// module information
1446pub const SECT_OBJC_MODULES: &str = "__module_info";
1447/// string table
1448pub const SECT_OBJC_STRINGS: &str = "__selector_strs";
1449/// string table
1450pub const SECT_OBJC_REFS: &str = "__selector_refs";
1451
1452/// the icon segment
1453pub const SEG_ICON: &str = "__ICON";
1454/// the icon headers
1455pub const SECT_ICON_HEADER: &str = "__header";
1456/// the icons in tiff format
1457pub const SECT_ICON_TIFF: &str = "__tiff";
1458
1459/// the segment containing all structs created and maintained by the link editor. Created with -seglinkedit option to ld(1) for MH_EXECUTE and FVMLIB file types only
1460pub const SEG_LINKEDIT: &str = "__LINKEDIT";
1461
1462/// the segment overlapping with linkedit containing linking information
1463pub const SEG_LINKINFO: &str = "__LINKINFO";
1464
1465/// the unix stack segment
1466pub const SEG_UNIXSTACK: &str = "__UNIXSTACK";
1467
1468/// the segment for the self (dyld) modifying code stubs that has read, write and execute permissions
1469pub const SEG_IMPORT: &str = "__IMPORT";
1470
1471/*
1472 * Fixed virtual memory shared libraries are identified by two things. The
1473 * target pathname (the name of the library as found for execution), and the
1474 * minor version number. The address of where the headers are loaded is in
1475 * header_addr. (THIS IS OBSOLETE and no longer supported).
1476 */
1477#[derive(Debug, Clone, Copy)]
1478#[repr(C)]
1479pub struct Fvmlib<E: Endian> {
1480 /// library's target pathname
1481 pub name: LcStr<E>,
1482 /// library's minor version number
1483 pub minor_version: U32<E>,
1484 /// library's header address
1485 pub header_addr: U32<E>,
1486}
1487
1488/*
1489 * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
1490 * contains a `FvmlibCommand` (cmd == LC_IDFVMLIB) to identify the library.
1491 * An object that uses a fixed virtual shared library also contains a
1492 * `FvmlibCommand` (cmd == LC_LOADFVMLIB) for each library it uses.
1493 * (THIS IS OBSOLETE and no longer supported).
1494 */
1495#[derive(Debug, Clone, Copy)]
1496#[repr(C)]
1497pub struct FvmlibCommand<E: Endian> {
1498 /// LC_IDFVMLIB or LC_LOADFVMLIB
1499 pub cmd: U32<E>,
1500 /// includes pathname string
1501 pub cmdsize: U32<E>,
1502 /// the library identification
1503 pub fvmlib: Fvmlib<E>,
1504}
1505
1506/*
1507 * Dynamically linked shared libraries are identified by two things. The
1508 * pathname (the name of the library as found for execution), and the
1509 * compatibility version number. The pathname must match and the compatibility
1510 * number in the user of the library must be greater than or equal to the
1511 * library being used. The time stamp is used to record the time a library was
1512 * built and copied into user so it can be use to determined if the library used
1513 * at runtime is exactly the same as used to built the program.
1514 */
1515#[derive(Debug, Clone, Copy)]
1516#[repr(C)]
1517pub struct Dylib<E: Endian> {
1518 /// library's path name
1519 pub name: LcStr<E>,
1520 /// library's build time stamp
1521 pub timestamp: U32<E>,
1522 /// library's current version number
1523 pub current_version: U32<E>,
1524 /// library's compatibility vers number
1525 pub compatibility_version: U32<E>,
1526}
1527
1528/*
1529 * A dynamically linked shared library (filetype == MH_DYLIB in the mach header)
1530 * contains a `DylibCommand` (cmd == LC_ID_DYLIB) to identify the library.
1531 * An object that uses a dynamically linked shared library also contains a
1532 * `DylibCommand` (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or
1533 * LC_REEXPORT_DYLIB) for each library it uses.
1534 */
1535#[derive(Debug, Clone, Copy)]
1536#[repr(C)]
1537pub struct DylibCommand<E: Endian> {
1538 /// LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB, LC_REEXPORT_DYLIB
1539 pub cmd: U32<E>,
1540 /// includes pathname string
1541 pub cmdsize: U32<E>,
1542 /// the library identification
1543 pub dylib: Dylib<E>,
1544}
1545
1546/*
1547 * An alternate encoding for: LC_LOAD_DYLIB.
1548 * The flags field contains independent flags DYLIB_USE_*
1549 * First supported in macOS 15, iOS 18.
1550 */
1551#[derive(Debug, Clone, Copy)]
1552#[repr(C)]
1553pub struct DylibUseCommand<E: Endian> {
1554 /// LC_LOAD_DYLIB or LC_LOAD_WEAK_DYLIB
1555 pub cmd: U32<E>,
1556 /// overall size, including path
1557 pub cmdsize: U32<E>,
1558 /// == 28, dylibs's path offset
1559 pub nameoff: U32<E>,
1560 /// == DYLIB_USE_MARKER
1561 pub marker: U32<E>,
1562 /// dylib's current version number
1563 pub current_version: U32<E>,
1564 /// dylib's compatibility version number
1565 pub compat_version: U32<E>,
1566 /// DYLIB_USE_... flags
1567 pub flags: U32<E>,
1568}
1569
1570pub const DYLIB_USE_WEAK_LINK: u32 = 0x01;
1571pub const DYLIB_USE_REEXPORT: u32 = 0x02;
1572pub const DYLIB_USE_UPWARD: u32 = 0x04;
1573pub const DYLIB_USE_DELAYED_INIT: u32 = 0x08;
1574
1575pub const DYLIB_USE_MARKER: u32 = 0x1a741800;
1576
1577/*
1578 * A dynamically linked shared library may be a subframework of an umbrella
1579 * framework. If so it will be linked with "-umbrella umbrella_name" where
1580 * Where "umbrella_name" is the name of the umbrella framework. A subframework
1581 * can only be linked against by its umbrella framework or other subframeworks
1582 * that are part of the same umbrella framework. Otherwise the static link
1583 * editor produces an error and states to link against the umbrella framework.
1584 * The name of the umbrella framework for subframeworks is recorded in the
1585 * following structure.
1586 */
1587#[derive(Debug, Clone, Copy)]
1588#[repr(C)]
1589pub struct SubFrameworkCommand<E: Endian> {
1590 /// LC_SUB_FRAMEWORK
1591 pub cmd: U32<E>,
1592 /// includes umbrella string
1593 pub cmdsize: U32<E>,
1594 /// the umbrella framework name
1595 pub umbrella: LcStr<E>,
1596}
1597
1598/*
1599 * For dynamically linked shared libraries that are subframework of an umbrella
1600 * framework they can allow clients other than the umbrella framework or other
1601 * subframeworks in the same umbrella framework. To do this the subframework
1602 * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
1603 * command is created for each -allowable_client flag. The client_name is
1604 * usually a framework name. It can also be a name used for bundles clients
1605 * where the bundle is built with "-client_name client_name".
1606 */
1607#[derive(Debug, Clone, Copy)]
1608#[repr(C)]
1609pub struct SubClientCommand<E: Endian> {
1610 /// LC_SUB_CLIENT
1611 pub cmd: U32<E>,
1612 /// includes client string
1613 pub cmdsize: U32<E>,
1614 /// the client name
1615 pub client: LcStr<E>,
1616}
1617
1618/*
1619 * A dynamically linked shared library may be a sub_umbrella of an umbrella
1620 * framework. If so it will be linked with "-sub_umbrella umbrella_name" where
1621 * Where "umbrella_name" is the name of the sub_umbrella framework. When
1622 * statically linking when -twolevel_namespace is in effect a twolevel namespace
1623 * umbrella framework will only cause its subframeworks and those frameworks
1624 * listed as sub_umbrella frameworks to be implicited linked in. Any other
1625 * dependent dynamic libraries will not be linked it when -twolevel_namespace
1626 * is in effect. The primary library recorded by the static linker when
1627 * resolving a symbol in these libraries will be the umbrella framework.
1628 * Zero or more sub_umbrella frameworks may be use by an umbrella framework.
1629 * The name of a sub_umbrella framework is recorded in the following structure.
1630 */
1631#[derive(Debug, Clone, Copy)]
1632#[repr(C)]
1633pub struct SubUmbrellaCommand<E: Endian> {
1634 /// LC_SUB_UMBRELLA
1635 pub cmd: U32<E>,
1636 /// includes sub_umbrella string
1637 pub cmdsize: U32<E>,
1638 /// the sub_umbrella framework name
1639 pub sub_umbrella: LcStr<E>,
1640}
1641
1642/*
1643 * A dynamically linked shared library may be a sub_library of another shared
1644 * library. If so it will be linked with "-sub_library library_name" where
1645 * Where "library_name" is the name of the sub_library shared library. When
1646 * statically linking when -twolevel_namespace is in effect a twolevel namespace
1647 * shared library will only cause its subframeworks and those frameworks
1648 * listed as sub_umbrella frameworks and libraries listed as sub_libraries to
1649 * be implicited linked in. Any other dependent dynamic libraries will not be
1650 * linked it when -twolevel_namespace is in effect. The primary library
1651 * recorded by the static linker when resolving a symbol in these libraries
1652 * will be the umbrella framework (or dynamic library). Zero or more sub_library
1653 * shared libraries may be use by an umbrella framework or (or dynamic library).
1654 * The name of a sub_library framework is recorded in the following structure.
1655 * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
1656 */
1657#[derive(Debug, Clone, Copy)]
1658#[repr(C)]
1659pub struct SubLibraryCommand<E: Endian> {
1660 /// LC_SUB_LIBRARY
1661 pub cmd: U32<E>,
1662 /// includes sub_library string
1663 pub cmdsize: U32<E>,
1664 /// the sub_library name
1665 pub sub_library: LcStr<E>,
1666}
1667
1668/*
1669 * A program (filetype == MH_EXECUTE) that is
1670 * prebound to its dynamic libraries has one of these for each library that
1671 * the static linker used in prebinding. It contains a bit vector for the
1672 * modules in the library. The bits indicate which modules are bound (1) and
1673 * which are not (0) from the library. The bit for module 0 is the low bit
1674 * of the first byte. So the bit for the Nth module is:
1675 * (linked_modules[N/8] >> N%8) & 1
1676 */
1677#[derive(Debug, Clone, Copy)]
1678#[repr(C)]
1679pub struct PreboundDylibCommand<E: Endian> {
1680 /// LC_PREBOUND_DYLIB
1681 pub cmd: U32<E>,
1682 /// includes strings
1683 pub cmdsize: U32<E>,
1684 /// library's path name
1685 pub name: LcStr<E>,
1686 /// number of modules in library
1687 pub nmodules: U32<E>,
1688 /// bit vector of linked modules
1689 pub linked_modules: LcStr<E>,
1690}
1691
1692/*
1693 * A program that uses a dynamic linker contains a `DylinkerCommand` to identify
1694 * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker
1695 * contains a `DylinkerCommand` to identify the dynamic linker (LC_ID_DYLINKER).
1696 * A file can have at most one of these.
1697 * This struct is also used for the LC_DYLD_ENVIRONMENT load command and
1698 * contains string for dyld to treat like environment variable.
1699 */
1700#[derive(Debug, Clone, Copy)]
1701#[repr(C)]
1702pub struct DylinkerCommand<E: Endian> {
1703 /// LC_ID_DYLINKER, LC_LOAD_DYLINKER or LC_DYLD_ENVIRONMENT
1704 pub cmd: U32<E>,
1705 /// includes pathname string
1706 pub cmdsize: U32<E>,
1707 /// dynamic linker's path name
1708 pub name: LcStr<E>,
1709}
1710
1711/*
1712 * Thread commands contain machine-specific data structures suitable for
1713 * use in the thread state primitives. The machine specific data structures
1714 * follow the struct `ThreadCommand` as follows.
1715 * Each flavor of machine specific data structure is preceded by an uint32_t
1716 * constant for the flavor of that data structure, an uint32_t that is the
1717 * count of uint32_t's of the size of the state data structure and then
1718 * the state data structure follows. This triple may be repeated for many
1719 * flavors. The constants for the flavors, counts and state data structure
1720 * definitions are expected to be in the header file <machine/thread_status.h>.
1721 * These machine specific data structures sizes must be multiples of
1722 * 4 bytes. The `cmdsize` reflects the total size of the `ThreadCommand`
1723 * and all of the sizes of the constants for the flavors, counts and state
1724 * data structures.
1725 *
1726 * For executable objects that are unix processes there will be one
1727 * `ThreadCommand` (cmd == LC_UNIXTHREAD) created for it by the link-editor.
1728 * This is the same as a LC_THREAD, except that a stack is automatically
1729 * created (based on the shell's limit for the stack size). Command arguments
1730 * and environment variables are copied onto that stack.
1731 */
1732#[derive(Debug, Clone, Copy)]
1733#[repr(C)]
1734pub struct ThreadCommand<E: Endian> {
1735 /// LC_THREAD or LC_UNIXTHREAD
1736 pub cmd: U32<E>,
1737 /// total size of this command
1738 pub cmdsize: U32<E>,
1739 /* uint32_t flavor flavor of thread state */
1740 /* uint32_t count count of uint32_t's in thread state */
1741 /* struct XXX_thread_state state thread state for this flavor */
1742 /* ... */
1743}
1744
1745/*
1746 * The routines command contains the address of the dynamic shared library
1747 * initialization routine and an index into the module table for the module
1748 * that defines the routine. Before any modules are used from the library the
1749 * dynamic linker fully binds the module that defines the initialization routine
1750 * and then calls it. This gets called before any module initialization
1751 * routines (used for C++ static constructors) in the library.
1752 */
1753#[derive(Debug, Clone, Copy)]
1754#[repr(C)]
1755pub struct RoutinesCommand32<E: Endian> {
1756 /* for 32-bit architectures */
1757 /// LC_ROUTINES
1758 pub cmd: U32<E>,
1759 /// total size of this command
1760 pub cmdsize: U32<E>,
1761 /// address of initialization routine
1762 pub init_address: U32<E>,
1763 /// index into the module table that the init routine is defined in
1764 pub init_module: U32<E>,
1765 pub reserved1: U32<E>,
1766 pub reserved2: U32<E>,
1767 pub reserved3: U32<E>,
1768 pub reserved4: U32<E>,
1769 pub reserved5: U32<E>,
1770 pub reserved6: U32<E>,
1771}
1772
1773/*
1774 * The 64-bit routines command. Same use as above.
1775 */
1776#[derive(Debug, Clone, Copy)]
1777#[repr(C)]
1778pub struct RoutinesCommand64<E: Endian> {
1779 /* for 64-bit architectures */
1780 /// LC_ROUTINES_64
1781 pub cmd: U32<E>,
1782 /// total size of this command
1783 pub cmdsize: U32<E>,
1784 /// address of initialization routine
1785 pub init_address: U64<E>,
1786 /// index into the module table that the init routine is defined in
1787 pub init_module: U64<E>,
1788 pub reserved1: U64<E>,
1789 pub reserved2: U64<E>,
1790 pub reserved3: U64<E>,
1791 pub reserved4: U64<E>,
1792 pub reserved5: U64<E>,
1793 pub reserved6: U64<E>,
1794}
1795
1796/*
1797 * The `SymtabCommand` contains the offsets and sizes of the link-edit 4.3BSD
1798 * "stab" style symbol table information as described in the header files
1799 * <nlist.h> and <stab.h>.
1800 */
1801#[derive(Debug, Clone, Copy)]
1802#[repr(C)]
1803pub struct SymtabCommand<E: Endian> {
1804 /// LC_SYMTAB
1805 pub cmd: U32<E>,
1806 /// sizeof(struct SymtabCommand)
1807 pub cmdsize: U32<E>,
1808 /// symbol table offset
1809 pub symoff: U32<E>,
1810 /// number of symbol table entries
1811 pub nsyms: U32<E>,
1812 /// string table offset
1813 pub stroff: U32<E>,
1814 /// string table size in bytes
1815 pub strsize: U32<E>,
1816}
1817
1818/*
1819 * This is the second set of the symbolic information which is used to support
1820 * the data structures for the dynamically link editor.
1821 *
1822 * The original set of symbolic information in the `SymtabCommand` which contains
1823 * the symbol and string tables must also be present when this load command is
1824 * present. When this load command is present the symbol table is organized
1825 * into three groups of symbols:
1826 * local symbols (static and debugging symbols) - grouped by module
1827 * defined external symbols - grouped by module (sorted by name if not lib)
1828 * undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
1829 * and in order the were seen by the static
1830 * linker if MH_BINDATLOAD is set)
1831 * In this load command there are offsets and counts to each of the three groups
1832 * of symbols.
1833 *
1834 * This load command contains a the offsets and sizes of the following new
1835 * symbolic information tables:
1836 * table of contents
1837 * module table
1838 * reference symbol table
1839 * indirect symbol table
1840 * The first three tables above (the table of contents, module table and
1841 * reference symbol table) are only present if the file is a dynamically linked
1842 * shared library. For executable and object modules, which are files
1843 * containing only one module, the information that would be in these three
1844 * tables is determined as follows:
1845 * table of contents - the defined external symbols are sorted by name
1846 * module table - the file contains only one module so everything in the
1847 * file is part of the module.
1848 * reference symbol table - is the defined and undefined external symbols
1849 *
1850 * For dynamically linked shared library files this load command also contains
1851 * offsets and sizes to the pool of relocation entries for all sections
1852 * separated into two groups:
1853 * external relocation entries
1854 * local relocation entries
1855 * For executable and object modules the relocation entries continue to hang
1856 * off the section structures.
1857 */
1858#[derive(Debug, Clone, Copy)]
1859#[repr(C)]
1860pub struct DysymtabCommand<E: Endian> {
1861 /// LC_DYSYMTAB
1862 pub cmd: U32<E>,
1863 /// sizeof(struct DysymtabCommand)
1864 pub cmdsize: U32<E>,
1865
1866 /*
1867 * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
1868 * are grouped into the following three groups:
1869 * local symbols (further grouped by the module they are from)
1870 * defined external symbols (further grouped by the module they are from)
1871 * undefined symbols
1872 *
1873 * The local symbols are used only for debugging. The dynamic binding
1874 * process may have to use them to indicate to the debugger the local
1875 * symbols for a module that is being bound.
1876 *
1877 * The last two groups are used by the dynamic binding process to do the
1878 * binding (indirectly through the module table and the reference symbol
1879 * table when this is a dynamically linked shared library file).
1880 */
1881 /// index to local symbols
1882 pub ilocalsym: U32<E>,
1883 /// number of local symbols
1884 pub nlocalsym: U32<E>,
1885
1886 /// index to externally defined symbols
1887 pub iextdefsym: U32<E>,
1888 /// number of externally defined symbols
1889 pub nextdefsym: U32<E>,
1890
1891 /// index to undefined symbols
1892 pub iundefsym: U32<E>,
1893 /// number of undefined symbols
1894 pub nundefsym: U32<E>,
1895
1896 /*
1897 * For the for the dynamic binding process to find which module a symbol
1898 * is defined in the table of contents is used (analogous to the ranlib
1899 * structure in an archive) which maps defined external symbols to modules
1900 * they are defined in. This exists only in a dynamically linked shared
1901 * library file. For executable and object modules the defined external
1902 * symbols are sorted by name and is use as the table of contents.
1903 */
1904 /// file offset to table of contents
1905 pub tocoff: U32<E>,
1906 /// number of entries in table of contents
1907 pub ntoc: U32<E>,
1908
1909 /*
1910 * To support dynamic binding of "modules" (whole object files) the symbol
1911 * table must reflect the modules that the file was created from. This is
1912 * done by having a module table that has indexes and counts into the merged
1913 * tables for each module. The module structure that these two entries
1914 * refer to is described below. This exists only in a dynamically linked
1915 * shared library file. For executable and object modules the file only
1916 * contains one module so everything in the file belongs to the module.
1917 */
1918 /// file offset to module table
1919 pub modtaboff: U32<E>,
1920 /// number of module table entries
1921 pub nmodtab: U32<E>,
1922
1923 /*
1924 * To support dynamic module binding the module structure for each module
1925 * indicates the external references (defined and undefined) each module
1926 * makes. For each module there is an offset and a count into the
1927 * reference symbol table for the symbols that the module references.
1928 * This exists only in a dynamically linked shared library file. For
1929 * executable and object modules the defined external symbols and the
1930 * undefined external symbols indicates the external references.
1931 */
1932 /// offset to referenced symbol table
1933 pub extrefsymoff: U32<E>,
1934 /// number of referenced symbol table entries
1935 pub nextrefsyms: U32<E>,
1936
1937 /*
1938 * The sections that contain "symbol pointers" and "routine stubs" have
1939 * indexes and (implied counts based on the size of the section and fixed
1940 * size of the entry) into the "indirect symbol" table for each pointer
1941 * and stub. For every section of these two types the index into the
1942 * indirect symbol table is stored in the section header in the field
1943 * reserved1. An indirect symbol table entry is simply a 32bit index into
1944 * the symbol table to the symbol that the pointer or stub is referring to.
1945 * The indirect symbol table is ordered to match the entries in the section.
1946 */
1947 /// file offset to the indirect symbol table
1948 pub indirectsymoff: U32<E>,
1949 /// number of indirect symbol table entries
1950 pub nindirectsyms: U32<E>,
1951
1952 /*
1953 * To support relocating an individual module in a library file quickly the
1954 * external relocation entries for each module in the library need to be
1955 * accessed efficiently. Since the relocation entries can't be accessed
1956 * through the section headers for a library file they are separated into
1957 * groups of local and external entries further grouped by module. In this
1958 * case the presents of this load command who's extreloff, nextrel,
1959 * locreloff and nlocrel fields are non-zero indicates that the relocation
1960 * entries of non-merged sections are not referenced through the section
1961 * structures (and the reloff and nreloc fields in the section headers are
1962 * set to zero).
1963 *
1964 * Since the relocation entries are not accessed through the section headers
1965 * this requires the r_address field to be something other than a section
1966 * offset to identify the item to be relocated. In this case r_address is
1967 * set to the offset from the vmaddr of the first LC_SEGMENT command.
1968 * For MH_SPLIT_SEGS images r_address is set to the the offset from the
1969 * vmaddr of the first read-write LC_SEGMENT command.
1970 *
1971 * The relocation entries are grouped by module and the module table
1972 * entries have indexes and counts into them for the group of external
1973 * relocation entries for that the module.
1974 *
1975 * For sections that are merged across modules there must not be any
1976 * remaining external relocation entries for them (for merged sections
1977 * remaining relocation entries must be local).
1978 */
1979 /// offset to external relocation entries
1980 pub extreloff: U32<E>,
1981 /// number of external relocation entries
1982 pub nextrel: U32<E>,
1983
1984 /*
1985 * All the local relocation entries are grouped together (they are not
1986 * grouped by their module since they are only used if the object is moved
1987 * from it statically link edited address).
1988 */
1989 /// offset to local relocation entries
1990 pub locreloff: U32<E>,
1991 /// number of local relocation entries
1992 pub nlocrel: U32<E>,
1993}
1994
1995/*
1996 * An indirect symbol table entry is simply a 32bit index into the symbol table
1997 * to the symbol that the pointer or stub is referring to. Unless it is for a
1998 * non-lazy symbol pointer section for a defined symbol which strip(1) as
1999 * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
2000 * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
2001 */
2002pub const INDIRECT_SYMBOL_LOCAL: u32 = 0x8000_0000;
2003pub const INDIRECT_SYMBOL_ABS: u32 = 0x4000_0000;
2004
2005/* a table of contents entry */
2006#[derive(Debug, Clone, Copy)]
2007#[repr(C)]
2008pub struct DylibTableOfContents<E: Endian> {
2009 /// the defined external symbol (index into the symbol table)
2010 pub symbol_index: U32<E>,
2011 /// index into the module table this symbol is defined in
2012 pub module_index: U32<E>,
2013}
2014
2015/* a module table entry */
2016#[derive(Debug, Clone, Copy)]
2017#[repr(C)]
2018pub struct DylibModule32<E: Endian> {
2019 /// the module name (index into string table)
2020 pub module_name: U32<E>,
2021
2022 /// index into externally defined symbols
2023 pub iextdefsym: U32<E>,
2024 /// number of externally defined symbols
2025 pub nextdefsym: U32<E>,
2026 /// index into reference symbol table
2027 pub irefsym: U32<E>,
2028 /// number of reference symbol table entries
2029 pub nrefsym: U32<E>,
2030 /// index into symbols for local symbols
2031 pub ilocalsym: U32<E>,
2032 /// number of local symbols
2033 pub nlocalsym: U32<E>,
2034
2035 /// index into external relocation entries
2036 pub iextrel: U32<E>,
2037 /// number of external relocation entries
2038 pub nextrel: U32<E>,
2039
2040 /// low 16 bits are the index into the init section, high 16 bits are the index into the term section
2041 pub iinit_iterm: U32<E>,
2042 /// low 16 bits are the number of init section entries, high 16 bits are the number of term section entries
2043 pub ninit_nterm: U32<E>,
2044
2045 /// for this module address of the start of the (__OBJC,__module_info) section
2046 pub objc_module_info_addr: U32<E>,
2047 /// for this module size of the (__OBJC,__module_info) section
2048 pub objc_module_info_size: U32<E>,
2049}
2050
2051/* a 64-bit module table entry */
2052#[derive(Debug, Clone, Copy)]
2053#[repr(C)]
2054pub struct DylibModule64<E: Endian> {
2055 /// the module name (index into string table)
2056 pub module_name: U32<E>,
2057
2058 /// index into externally defined symbols
2059 pub iextdefsym: U32<E>,
2060 /// number of externally defined symbols
2061 pub nextdefsym: U32<E>,
2062 /// index into reference symbol table
2063 pub irefsym: U32<E>,
2064 /// number of reference symbol table entries
2065 pub nrefsym: U32<E>,
2066 /// index into symbols for local symbols
2067 pub ilocalsym: U32<E>,
2068 /// number of local symbols
2069 pub nlocalsym: U32<E>,
2070
2071 /// index into external relocation entries
2072 pub iextrel: U32<E>,
2073 /// number of external relocation entries
2074 pub nextrel: U32<E>,
2075
2076 /// low 16 bits are the index into the init section, high 16 bits are the index into the term section
2077 pub iinit_iterm: U32<E>,
2078 /// low 16 bits are the number of init section entries, high 16 bits are the number of term section entries
2079 pub ninit_nterm: U32<E>,
2080
2081 /// for this module size of the (__OBJC,__module_info) section
2082 pub objc_module_info_size: U32<E>,
2083 /// for this module address of the start of the (__OBJC,__module_info) section
2084 pub objc_module_info_addr: U64<E>,
2085}
2086
2087/*
2088 * The entries in the reference symbol table are used when loading the module
2089 * (both by the static and dynamic link editors) and if the module is unloaded
2090 * or replaced. Therefore all external symbols (defined and undefined) are
2091 * listed in the module's reference table. The flags describe the type of
2092 * reference that is being made. The constants for the flags are defined in
2093 * <mach-o/nlist.h> as they are also used for symbol table entries.
2094 */
2095#[derive(Debug, Clone, Copy)]
2096#[repr(C)]
2097pub struct DylibReference<E: Endian> {
2098 /* TODO:
2099 uint32_t isym:24, /* index into the symbol table */
2100 flags:8; /* flags to indicate the type of reference */
2101 */
2102 pub bitfield: U32<E>,
2103}
2104
2105/*
2106 * The TwolevelHintsCommand contains the offset and number of hints in the
2107 * two-level namespace lookup hints table.
2108 */
2109#[derive(Debug, Clone, Copy)]
2110#[repr(C)]
2111pub struct TwolevelHintsCommand<E: Endian> {
2112 /// LC_TWOLEVEL_HINTS
2113 pub cmd: U32<E>,
2114 /// sizeof(struct TwolevelHintsCommand)
2115 pub cmdsize: U32<E>,
2116 /// offset to the hint table
2117 pub offset: U32<E>,
2118 /// number of hints in the hint table
2119 pub nhints: U32<E>,
2120}
2121
2122/*
2123 * The entries in the two-level namespace lookup hints table are TwolevelHint
2124 * structs. These provide hints to the dynamic link editor where to start
2125 * looking for an undefined symbol in a two-level namespace image. The
2126 * isub_image field is an index into the sub-images (sub-frameworks and
2127 * sub-umbrellas list) that made up the two-level image that the undefined
2128 * symbol was found in when it was built by the static link editor. If
2129 * isub-image is 0 the the symbol is expected to be defined in library and not
2130 * in the sub-images. If isub-image is non-zero it is an index into the array
2131 * of sub-images for the umbrella with the first index in the sub-images being
2132 * 1. The array of sub-images is the ordered list of sub-images of the umbrella
2133 * that would be searched for a symbol that has the umbrella recorded as its
2134 * primary library. The table of contents index is an index into the
2135 * library's table of contents. This is used as the starting point of the
2136 * binary search or a directed linear search.
2137 */
2138#[derive(Debug, Clone, Copy)]
2139#[repr(C)]
2140pub struct TwolevelHint<E: Endian> {
2141 /* TODO:
2142 uint32_t
2143 isub_image:8, /* index into the sub images */
2144 itoc:24; /* index into the table of contents */
2145 */
2146 pub bitfield: U32<E>,
2147}
2148
2149/*
2150 * The PrebindCksumCommand contains the value of the original check sum for
2151 * prebound files or zero. When a prebound file is first created or modified
2152 * for other than updating its prebinding information the value of the check sum
2153 * is set to zero. When the file has it prebinding re-done and if the value of
2154 * the check sum is zero the original check sum is calculated and stored in
2155 * cksum field of this load command in the output file. If when the prebinding
2156 * is re-done and the cksum field is non-zero it is left unchanged from the
2157 * input file.
2158 */
2159#[derive(Debug, Clone, Copy)]
2160#[repr(C)]
2161pub struct PrebindCksumCommand<E: Endian> {
2162 /// LC_PREBIND_CKSUM
2163 pub cmd: U32<E>,
2164 /// sizeof(struct PrebindCksumCommand)
2165 pub cmdsize: U32<E>,
2166 /// the check sum or zero
2167 pub cksum: U32<E>,
2168}
2169
2170/*
2171 * The uuid load command contains a single 128-bit unique random number that
2172 * identifies an object produced by the static link editor.
2173 */
2174#[derive(Debug, Clone, Copy)]
2175#[repr(C)]
2176pub struct UuidCommand<E: Endian> {
2177 /// LC_UUID
2178 pub cmd: U32<E>,
2179 /// sizeof(struct UuidCommand)
2180 pub cmdsize: U32<E>,
2181 /// the 128-bit uuid
2182 pub uuid: [u8; 16],
2183}
2184
2185/*
2186 * The RpathCommand contains a path which at runtime should be added to
2187 * the current run path used to find @rpath prefixed dylibs.
2188 */
2189#[derive(Debug, Clone, Copy)]
2190#[repr(C)]
2191pub struct RpathCommand<E: Endian> {
2192 /// LC_RPATH
2193 pub cmd: U32<E>,
2194 /// includes string
2195 pub cmdsize: U32<E>,
2196 /// path to add to run path
2197 pub path: LcStr<E>,
2198}
2199
2200/*
2201 * The target_triple_command contains a string which specifies the
2202 * target triple (e.g. "arm64e-apple-macosx15.0.0") used to compile the code.
2203 */
2204#[derive(Debug, Clone, Copy)]
2205#[repr(C)]
2206pub struct TargetTripleCommand<E: Endian> {
2207 /// LC_TARGET_TRIPLE
2208 pub cmd: U32<E>,
2209 /// including string
2210 pub cmdsize: U32<E>,
2211 /// target triple string
2212 pub triple: LcStr<E>,
2213}
2214
2215/*
2216 * The LinkeditDataCommand contains the offsets and sizes of a blob
2217 * of data in the __LINKEDIT segment.
2218 */
2219#[derive(Debug, Clone, Copy)]
2220#[repr(C)]
2221pub struct LinkeditDataCommand<E: Endian> {
2222 /// `LC_CODE_SIGNATURE`, `LC_SEGMENT_SPLIT_INFO`, `LC_FUNCTION_STARTS`,
2223 /// `LC_DATA_IN_CODE`, `LC_DYLIB_CODE_SIGN_DRS`, `LC_LINKER_OPTIMIZATION_HINT`,
2224 /// `LC_DYLD_EXPORTS_TRIE`, or `LC_DYLD_CHAINED_FIXUPS`.
2225 pub cmd: U32<E>,
2226 /// sizeof(struct LinkeditDataCommand)
2227 pub cmdsize: U32<E>,
2228 /// file offset of data in __LINKEDIT segment
2229 pub dataoff: U32<E>,
2230 /// file size of data in __LINKEDIT segment
2231 pub datasize: U32<E>,
2232}
2233
2234/*
2235 * The EncryptionInfoCommand32 contains the file offset and size of an
2236 * of an encrypted segment.
2237 */
2238#[derive(Debug, Clone, Copy)]
2239#[repr(C)]
2240pub struct EncryptionInfoCommand32<E: Endian> {
2241 /// LC_ENCRYPTION_INFO
2242 pub cmd: U32<E>,
2243 /// sizeof(struct EncryptionInfoCommand32)
2244 pub cmdsize: U32<E>,
2245 /// file offset of encrypted range
2246 pub cryptoff: U32<E>,
2247 /// file size of encrypted range
2248 pub cryptsize: U32<E>,
2249 /// which enryption system, 0 means not-encrypted yet
2250 pub cryptid: U32<E>,
2251}
2252
2253/*
2254 * The EncryptionInfoCommand64 contains the file offset and size of an
2255 * of an encrypted segment (for use in x86_64 targets).
2256 */
2257#[derive(Debug, Clone, Copy)]
2258#[repr(C)]
2259pub struct EncryptionInfoCommand64<E: Endian> {
2260 /// LC_ENCRYPTION_INFO_64
2261 pub cmd: U32<E>,
2262 /// sizeof(struct EncryptionInfoCommand64)
2263 pub cmdsize: U32<E>,
2264 /// file offset of encrypted range
2265 pub cryptoff: U32<E>,
2266 /// file size of encrypted range
2267 pub cryptsize: U32<E>,
2268 /// which enryption system, 0 means not-encrypted yet
2269 pub cryptid: U32<E>,
2270 /// padding to make this struct's size a multiple of 8 bytes
2271 pub pad: U32<E>,
2272}
2273
2274/*
2275 * The VersionMinCommand contains the min OS version on which this
2276 * binary was built to run.
2277 */
2278#[derive(Debug, Clone, Copy)]
2279#[repr(C)]
2280pub struct VersionMinCommand<E: Endian> {
2281 /// LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS or LC_VERSION_MIN_WATCHOS or LC_VERSION_MIN_TVOS
2282 pub cmd: U32<E>,
2283 /// sizeof(struct VersionMinCommand)
2284 pub cmdsize: U32<E>,
2285 /// X.Y.Z is encoded in nibbles xxxx.yy.zz
2286 pub version: U32<E>,
2287 /// X.Y.Z is encoded in nibbles xxxx.yy.zz
2288 pub sdk: U32<E>,
2289}
2290
2291/*
2292 * The BuildVersionCommand contains the min OS version on which this
2293 * binary was built to run for its platform. The list of known platforms and
2294 * tool values following it.
2295 */
2296#[derive(Debug, Clone, Copy)]
2297#[repr(C)]
2298pub struct BuildVersionCommand<E: Endian> {
2299 /// LC_BUILD_VERSION
2300 pub cmd: U32<E>,
2301 /// sizeof(struct BuildVersionCommand) plus ntools * sizeof(struct BuildToolVersion)
2302 pub cmdsize: U32<E>,
2303 /// platform
2304 pub platform: U32<E>,
2305 /// X.Y.Z is encoded in nibbles xxxx.yy.zz
2306 pub minos: U32<E>,
2307 /// X.Y.Z is encoded in nibbles xxxx.yy.zz
2308 pub sdk: U32<E>,
2309 /// number of tool entries following this
2310 pub ntools: U32<E>,
2311}
2312
2313#[derive(Debug, Clone, Copy)]
2314#[repr(C)]
2315pub struct BuildToolVersion<E: Endian> {
2316 /// enum for the tool
2317 pub tool: U32<E>,
2318 /// version number of the tool
2319 pub version: U32<E>,
2320}
2321
2322/* Known values for the platform field above. */
2323pub const PLATFORM_UNKNOWN: u32 = 0;
2324pub const PLATFORM_ANY: u32 = 0xFFFFFFFF;
2325pub const PLATFORM_MACOS: u32 = 1;
2326pub const PLATFORM_IOS: u32 = 2;
2327pub const PLATFORM_TVOS: u32 = 3;
2328pub const PLATFORM_WATCHOS: u32 = 4;
2329pub const PLATFORM_BRIDGEOS: u32 = 5;
2330pub const PLATFORM_MACCATALYST: u32 = 6;
2331pub const PLATFORM_IOSSIMULATOR: u32 = 7;
2332pub const PLATFORM_TVOSSIMULATOR: u32 = 8;
2333pub const PLATFORM_WATCHOSSIMULATOR: u32 = 9;
2334pub const PLATFORM_DRIVERKIT: u32 = 10;
2335pub const PLATFORM_VISIONOS: u32 = 11;
2336pub const PLATFORM_VISIONOSSIMULATOR: u32 = 12;
2337/// Compatibility alias for [`PLATFORM_VISIONOS`].
2338pub const PLATFORM_XROS: u32 = PLATFORM_VISIONOS;
2339/// Compatibility alias for [`PLATFORM_VISIONOSSIMULATOR`].
2340pub const PLATFORM_XROSSIMULATOR: u32 = PLATFORM_VISIONOSSIMULATOR;
2341
2342pub const PLATFORM_FIRMWARE: u32 = 13;
2343pub const PLATFORM_SEPOS: u32 = 14;
2344
2345pub const PLATFORM_MACOS_EXCLAVECORE: u32 = 15;
2346pub const PLATFORM_MACOS_EXCLAVEKIT: u32 = 16;
2347pub const PLATFORM_IOS_EXCLAVECORE: u32 = 17;
2348pub const PLATFORM_IOS_EXCLAVEKIT: u32 = 18;
2349pub const PLATFORM_TVOS_EXCLAVECORE: u32 = 19;
2350pub const PLATFORM_TVOS_EXCLAVEKIT: u32 = 20;
2351pub const PLATFORM_WATCHOS_EXCLAVECORE: u32 = 21;
2352pub const PLATFORM_WATCHOS_EXCLAVEKIT: u32 = 22;
2353pub const PLATFORM_VISIONOS_EXCLAVECORE: u32 = 23;
2354pub const PLATFORM_VISIONOS_EXCLAVEKIT: u32 = 24;
2355
2356/* Known values for the tool field above. */
2357pub const TOOL_CLANG: u32 = 1;
2358pub const TOOL_SWIFT: u32 = 2;
2359pub const TOOL_LD: u32 = 3;
2360
2361/* values for gpu tools (1024 to 1048) */
2362pub const TOOL_METAL: u32 = 1024;
2363pub const TOOL_AIRLLD: u32 = 1025;
2364pub const TOOL_AIRNT: u32 = 1026;
2365pub const TOOL_AIRNT_PLUGIN: u32 = 1027;
2366pub const TOOL_AIRPACK: u32 = 1028;
2367pub const TOOL_GPUARCHIVER: u32 = 1031;
2368pub const TOOL_METAL_FRAMEWORK: u32 = 1032;
2369
2370/*
2371 * The DyldInfoCommand contains the file offsets and sizes of
2372 * the new compressed form of the information dyld needs to
2373 * load the image. This information is used by dyld on Mac OS X
2374 * 10.6 and later. All information pointed to by this command
2375 * is encoded using byte streams, so no endian swapping is needed
2376 * to interpret it.
2377 */
2378#[derive(Debug, Clone, Copy)]
2379#[repr(C)]
2380pub struct DyldInfoCommand<E: Endian> {
2381 /// LC_DYLD_INFO or LC_DYLD_INFO_ONLY
2382 pub cmd: U32<E>,
2383 /// sizeof(struct DyldInfoCommand)
2384 pub cmdsize: U32<E>,
2385
2386 /*
2387 * Dyld rebases an image whenever dyld loads it at an address different
2388 * from its preferred address. The rebase information is a stream
2389 * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_.
2390 * Conceptually the rebase information is a table of tuples:
2391 * <seg-index, seg-offset, type>
2392 * The opcodes are a compressed way to encode the table by only
2393 * encoding when a column changes. In addition simple patterns
2394 * like "every n'th offset for m times" can be encoded in a few
2395 * bytes.
2396 */
2397 /// file offset to rebase info
2398 pub rebase_off: U32<E>,
2399 /// size of rebase info
2400 pub rebase_size: U32<E>,
2401
2402 /*
2403 * Dyld binds an image during the loading process, if the image
2404 * requires any pointers to be initialized to symbols in other images.
2405 * The bind information is a stream of byte sized
2406 * opcodes whose symbolic names start with BIND_OPCODE_.
2407 * Conceptually the bind information is a table of tuples:
2408 * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
2409 * The opcodes are a compressed way to encode the table by only
2410 * encoding when a column changes. In addition simple patterns
2411 * like for runs of pointers initialized to the same value can be
2412 * encoded in a few bytes.
2413 */
2414 /// file offset to binding info
2415 pub bind_off: U32<E>,
2416 /// size of binding info
2417 pub bind_size: U32<E>,
2418
2419 /*
2420 * Some C++ programs require dyld to unique symbols so that all
2421 * images in the process use the same copy of some code/data.
2422 * This step is done after binding. The content of the weak_bind
2423 * info is an opcode stream like the bind_info. But it is sorted
2424 * alphabetically by symbol name. This enable dyld to walk
2425 * all images with weak binding information in order and look
2426 * for collisions. If there are no collisions, dyld does
2427 * no updating. That means that some fixups are also encoded
2428 * in the bind_info. For instance, all calls to "operator new"
2429 * are first bound to libstdc++.dylib using the information
2430 * in bind_info. Then if some image overrides operator new
2431 * that is detected when the weak_bind information is processed
2432 * and the call to operator new is then rebound.
2433 */
2434 /// file offset to weak binding info
2435 pub weak_bind_off: U32<E>,
2436 /// size of weak binding info
2437 pub weak_bind_size: U32<E>,
2438
2439 /*
2440 * Some uses of external symbols do not need to be bound immediately.
2441 * Instead they can be lazily bound on first use. The lazy_bind
2442 * are contains a stream of BIND opcodes to bind all lazy symbols.
2443 * Normal use is that dyld ignores the lazy_bind section when
2444 * loading an image. Instead the static linker arranged for the
2445 * lazy pointer to initially point to a helper function which
2446 * pushes the offset into the lazy_bind area for the symbol
2447 * needing to be bound, then jumps to dyld which simply adds
2448 * the offset to lazy_bind_off to get the information on what
2449 * to bind.
2450 */
2451 /// file offset to lazy binding info
2452 pub lazy_bind_off: U32<E>,
2453 /// size of lazy binding infs
2454 pub lazy_bind_size: U32<E>,
2455
2456 /*
2457 * The symbols exported by a dylib are encoded in a trie. This
2458 * is a compact representation that factors out common prefixes.
2459 * It also reduces LINKEDIT pages in RAM because it encodes all
2460 * information (name, address, flags) in one small, contiguous range.
2461 * The export area is a stream of nodes. The first node sequentially
2462 * is the start node for the trie.
2463 *
2464 * Nodes for a symbol start with a uleb128 that is the length of
2465 * the exported symbol information for the string so far.
2466 * If there is no exported symbol, the node starts with a zero byte.
2467 * If there is exported info, it follows the length.
2468 *
2469 * First is a uleb128 containing flags. Normally, it is followed by
2470 * a uleb128 encoded offset which is location of the content named
2471 * by the symbol from the mach_header for the image. If the flags
2472 * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is
2473 * a uleb128 encoded library ordinal, then a zero terminated
2474 * UTF8 string. If the string is zero length, then the symbol
2475 * is re-export from the specified dylib with the same name.
2476 * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following
2477 * the flags is two uleb128s: the stub offset and the resolver offset.
2478 * The stub is used by non-lazy pointers. The resolver is used
2479 * by lazy pointers and must be called to get the actual address to use.
2480 *
2481 * After the optional exported symbol information is a byte of
2482 * how many edges (0-255) that this node has leaving it,
2483 * followed by each edge.
2484 * Each edge is a zero terminated UTF8 of the addition chars
2485 * in the symbol, followed by a uleb128 offset for the node that
2486 * edge points to.
2487 *
2488 */
2489 /// file offset to lazy binding info
2490 pub export_off: U32<E>,
2491 /// size of lazy binding infs
2492 pub export_size: U32<E>,
2493}
2494
2495/*
2496 * The following are used to encode rebasing information
2497 */
2498pub const REBASE_TYPE_POINTER: u8 = 1;
2499pub const REBASE_TYPE_TEXT_ABSOLUTE32: u8 = 2;
2500pub const REBASE_TYPE_TEXT_PCREL32: u8 = 3;
2501
2502pub const REBASE_OPCODE_MASK: u8 = 0xF0;
2503pub const REBASE_IMMEDIATE_MASK: u8 = 0x0F;
2504pub const REBASE_OPCODE_DONE: u8 = 0x00;
2505pub const REBASE_OPCODE_SET_TYPE_IMM: u8 = 0x10;
2506pub const REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: u8 = 0x20;
2507pub const REBASE_OPCODE_ADD_ADDR_ULEB: u8 = 0x30;
2508pub const REBASE_OPCODE_ADD_ADDR_IMM_SCALED: u8 = 0x40;
2509pub const REBASE_OPCODE_DO_REBASE_IMM_TIMES: u8 = 0x50;
2510pub const REBASE_OPCODE_DO_REBASE_ULEB_TIMES: u8 = 0x60;
2511pub const REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: u8 = 0x70;
2512pub const REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: u8 = 0x80;
2513
2514/*
2515 * The following are used to encode binding information
2516 */
2517pub const BIND_TYPE_POINTER: u8 = 1;
2518pub const BIND_TYPE_TEXT_ABSOLUTE32: u8 = 2;
2519pub const BIND_TYPE_TEXT_PCREL32: u8 = 3;
2520
2521pub const BIND_SPECIAL_DYLIB_SELF: i8 = 0;
2522pub const BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE: i8 = -1;
2523pub const BIND_SPECIAL_DYLIB_FLAT_LOOKUP: i8 = -2;
2524pub const BIND_SPECIAL_DYLIB_WEAK_LOOKUP: i8 = -3;
2525
2526pub const BIND_SYMBOL_FLAGS_WEAK_IMPORT: u8 = 0x1;
2527pub const BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION: u8 = 0x8;
2528
2529pub const BIND_OPCODE_MASK: u8 = 0xF0;
2530pub const BIND_IMMEDIATE_MASK: u8 = 0x0F;
2531pub const BIND_OPCODE_DONE: u8 = 0x00;
2532pub const BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: u8 = 0x10;
2533pub const BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: u8 = 0x20;
2534pub const BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: u8 = 0x30;
2535pub const BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: u8 = 0x40;
2536pub const BIND_OPCODE_SET_TYPE_IMM: u8 = 0x50;
2537pub const BIND_OPCODE_SET_ADDEND_SLEB: u8 = 0x60;
2538pub const BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: u8 = 0x70;
2539pub const BIND_OPCODE_ADD_ADDR_ULEB: u8 = 0x80;
2540pub const BIND_OPCODE_DO_BIND: u8 = 0x90;
2541pub const BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: u8 = 0xA0;
2542pub const BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: u8 = 0xB0;
2543pub const BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: u8 = 0xC0;
2544pub const BIND_OPCODE_THREADED: u8 = 0xD0;
2545pub const BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB: u8 = 0x00;
2546pub const BIND_SUBOPCODE_THREADED_APPLY: u8 = 0x01;
2547
2548/*
2549 * The following are used on the flags byte of a terminal node
2550 * in the export information.
2551 */
2552pub const EXPORT_SYMBOL_FLAGS_KIND_MASK: u8 = 0x03;
2553pub const EXPORT_SYMBOL_FLAGS_KIND_REGULAR: u8 = 0x00;
2554pub const EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL: u8 = 0x01;
2555pub const EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE: u8 = 0x02;
2556pub const EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION: u8 = 0x04;
2557pub const EXPORT_SYMBOL_FLAGS_REEXPORT: u8 = 0x08;
2558pub const EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER: u8 = 0x10;
2559pub const EXPORT_SYMBOL_FLAGS_STATIC_RESOLVER: u8 = 0x20;
2560
2561/*
2562 * The LinkerOptionCommand contains linker options embedded in object files.
2563 */
2564#[derive(Debug, Clone, Copy)]
2565#[repr(C)]
2566pub struct LinkerOptionCommand<E: Endian> {
2567 /// LC_LINKER_OPTION only used in MH_OBJECT filetypes
2568 pub cmd: U32<E>,
2569 pub cmdsize: U32<E>,
2570 /// number of strings
2571 pub count: U32<E>,
2572 /* concatenation of zero terminated UTF8 strings.
2573 Zero filled at end to align */
2574}
2575
2576/*
2577 * The SymsegCommand contains the offset and size of the GNU style
2578 * symbol table information as described in the header file <symseg.h>.
2579 * The symbol roots of the symbol segments must also be aligned properly
2580 * in the file. So the requirement of keeping the offsets aligned to a
2581 * multiple of a 4 bytes translates to the length field of the symbol
2582 * roots also being a multiple of a long. Also the padding must again be
2583 * zeroed. (THIS IS OBSOLETE and no longer supported).
2584 */
2585#[derive(Debug, Clone, Copy)]
2586#[repr(C)]
2587pub struct SymsegCommand<E: Endian> {
2588 /// LC_SYMSEG
2589 pub cmd: U32<E>,
2590 /// sizeof(struct SymsegCommand)
2591 pub cmdsize: U32<E>,
2592 /// symbol segment offset
2593 pub offset: U32<E>,
2594 /// symbol segment size in bytes
2595 pub size: U32<E>,
2596}
2597
2598/*
2599 * The IdentCommand contains a free format string table following the
2600 * IdentCommand structure. The strings are null terminated and the size of
2601 * the command is padded out with zero bytes to a multiple of 4 bytes/
2602 * (THIS IS OBSOLETE and no longer supported).
2603 */
2604#[derive(Debug, Clone, Copy)]
2605#[repr(C)]
2606pub struct IdentCommand<E: Endian> {
2607 /// LC_IDENT
2608 pub cmd: U32<E>,
2609 /// strings that follow this command
2610 pub cmdsize: U32<E>,
2611}
2612
2613/*
2614 * The FvmfileCommand contains a reference to a file to be loaded at the
2615 * specified virtual address. (Presently, this command is reserved for
2616 * internal use. The kernel ignores this command when loading a program into
2617 * memory).
2618 */
2619#[derive(Debug, Clone, Copy)]
2620#[repr(C)]
2621pub struct FvmfileCommand<E: Endian> {
2622 /// LC_FVMFILE
2623 pub cmd: U32<E>,
2624 /// includes pathname string
2625 pub cmdsize: U32<E>,
2626 /// files pathname
2627 pub name: LcStr<E>,
2628 /// files virtual address
2629 pub header_addr: U32<E>,
2630}
2631
2632/*
2633 * The EntryPointCommand is a replacement for thread_command.
2634 * It is used for main executables to specify the location (file offset)
2635 * of main(). If -stack_size was used at link time, the stacksize
2636 * field will contain the stack size need for the main thread.
2637 */
2638#[derive(Debug, Clone, Copy)]
2639#[repr(C)]
2640pub struct EntryPointCommand<E: Endian> {
2641 /// LC_MAIN only used in MH_EXECUTE filetypes
2642 pub cmd: U32<E>,
2643 /// 24
2644 pub cmdsize: U32<E>,
2645 /// file (__TEXT) offset of main()
2646 pub entryoff: U64<E>,
2647 /// if not zero, initial stack size
2648 pub stacksize: U64<E>,
2649}
2650
2651/*
2652 * The SourceVersionCommand is an optional load command containing
2653 * the version of the sources used to build the binary.
2654 */
2655#[derive(Debug, Clone, Copy)]
2656#[repr(C)]
2657pub struct SourceVersionCommand<E: Endian> {
2658 /// LC_SOURCE_VERSION
2659 pub cmd: U32<E>,
2660 /// 16
2661 pub cmdsize: U32<E>,
2662 /// A.B.C.D.E packed as a24.b10.c10.d10.e10
2663 pub version: U64<E>,
2664}
2665
2666/*
2667 * The LC_DATA_IN_CODE load commands uses a LinkeditDataCommand
2668 * to point to an array of DataInCodeEntry entries. Each entry
2669 * describes a range of data in a code section.
2670 */
2671#[derive(Debug, Clone, Copy)]
2672#[repr(C)]
2673pub struct DataInCodeEntry<E: Endian> {
2674 /// from mach_header to start of data range
2675 pub offset: U32<E>,
2676 /// number of bytes in data range
2677 pub length: U16<E>,
2678 /// a DICE_KIND_* value
2679 pub kind: U16<E>,
2680}
2681pub const DICE_KIND_DATA: u32 = 0x0001;
2682pub const DICE_KIND_JUMP_TABLE8: u32 = 0x0002;
2683pub const DICE_KIND_JUMP_TABLE16: u32 = 0x0003;
2684pub const DICE_KIND_JUMP_TABLE32: u32 = 0x0004;
2685pub const DICE_KIND_ABS_JUMP_TABLE32: u32 = 0x0005;
2686
2687/*
2688 * Sections of type S_THREAD_LOCAL_VARIABLES contain an array
2689 * of TlvDescriptor structures.
2690 */
2691/* TODO:
2692#[derive(Debug, Clone, Copy)]
2693#[repr(C)]
2694pub struct TlvDescriptor<E: Endian>
2695{
2696 void* (*thunk)(struct TlvDescriptor*);
2697 unsigned long key;
2698 unsigned long offset;
2699}
2700*/
2701
2702/*
2703 * LC_NOTE commands describe a region of arbitrary data included in a Mach-O
2704 * file. Its initial use is to record extra data in MH_CORE files.
2705 */
2706#[derive(Debug, Clone, Copy)]
2707#[repr(C)]
2708pub struct NoteCommand<E: Endian> {
2709 /// LC_NOTE
2710 pub cmd: U32<E>,
2711 /// sizeof(struct NoteCommand)
2712 pub cmdsize: U32<E>,
2713 /// owner name for this LC_NOTE
2714 pub data_owner: [u8; 16],
2715 /// file offset of this data
2716 pub offset: U64<E>,
2717 /// length of data region
2718 pub size: U64<E>,
2719}
2720
2721/*
2722 * LC_FILESET_ENTRY commands describe constituent Mach-O files that are part
2723 * of a fileset. In one implementation, entries are dylibs with individual
2724 * mach headers and repositionable text and data segments. Each entry is
2725 * further described by its own mach header.
2726 */
2727#[derive(Debug, Clone, Copy)]
2728#[repr(C)]
2729pub struct FilesetEntryCommand<E: Endian> {
2730 // LC_FILESET_ENTRY
2731 pub cmd: U32<E>,
2732 /// includes id string
2733 pub cmdsize: U32<E>,
2734 /// memory address of the dylib
2735 pub vmaddr: U64<E>,
2736 /// file offset of the dylib
2737 pub fileoff: U64<E>,
2738 /// contained entry id
2739 pub entry_id: LcStr<E>,
2740 /// entry_id is 32-bits long, so this is the reserved padding
2741 pub reserved: U32<E>,
2742}
2743
2744// Definitions from "/usr/include/mach-o/nlist.h".
2745
2746#[derive(Debug, Clone, Copy)]
2747#[repr(C)]
2748pub struct Nlist32<E: Endian> {
2749 /// index into the string table
2750 pub n_strx: U32<E>,
2751 /// type flag, see below
2752 pub n_type: u8,
2753 /// section number or NO_SECT
2754 pub n_sect: u8,
2755 /// see <mach-o/stab.h>
2756 pub n_desc: U16<E>,
2757 /// value of this symbol (or stab offset)
2758 pub n_value: U32<E>,
2759}
2760
2761/*
2762 * This is the symbol table entry structure for 64-bit architectures.
2763 */
2764#[derive(Debug, Clone, Copy)]
2765#[repr(C)]
2766pub struct Nlist64<E: Endian> {
2767 /// index into the string table
2768 pub n_strx: U32<E>,
2769 /// type flag, see below
2770 pub n_type: u8,
2771 /// section number or NO_SECT
2772 pub n_sect: u8,
2773 /// see <mach-o/stab.h>
2774 pub n_desc: U16<E>,
2775 /// value of this symbol (or stab offset)
2776 pub n_value: U64<E>,
2777}
2778
2779/*
2780 * Symbols with a index into the string table of zero (n_un.n_strx == 0) are
2781 * defined to have a null, "", name. Therefore all string indexes to non null
2782 * names must not have a zero string index. This is bit historical information
2783 * that has never been well documented.
2784 */
2785
2786/*
2787 * The n_type field really contains four fields:
2788 * unsigned char N_STAB:3,
2789 * N_PEXT:1,
2790 * N_TYPE:3,
2791 * N_EXT:1;
2792 * which are used via the following masks.
2793 */
2794/// if any of these bits set, a symbolic debugging entry
2795pub const N_STAB: u8 = 0xe0;
2796/// private external symbol bit
2797pub const N_PEXT: u8 = 0x10;
2798/// mask for the type bits
2799pub const N_TYPE: u8 = 0x0e;
2800/// external symbol bit, set for external symbols
2801pub const N_EXT: u8 = 0x01;
2802
2803/*
2804 * Only symbolic debugging entries have some of the N_STAB bits set and if any
2805 * of these bits are set then it is a symbolic debugging entry (a stab). In
2806 * which case then the values of the n_type field (the entire field) are given
2807 * in <mach-o/stab.h>
2808 */
2809
2810/*
2811 * Values for N_TYPE bits of the n_type field.
2812 */
2813/// undefined, n_sect == NO_SECT
2814pub const N_UNDF: u8 = 0x0;
2815/// absolute, n_sect == NO_SECT
2816pub const N_ABS: u8 = 0x2;
2817/// defined in section number n_sect
2818pub const N_SECT: u8 = 0xe;
2819/// prebound undefined (defined in a dylib)
2820pub const N_PBUD: u8 = 0xc;
2821/// indirect
2822pub const N_INDR: u8 = 0xa;
2823
2824/*
2825 * If the type is N_INDR then the symbol is defined to be the same as another
2826 * symbol. In this case the n_value field is an index into the string table
2827 * of the other symbol's name. When the other symbol is defined then they both
2828 * take on the defined type and value.
2829 */
2830
2831/*
2832 * If the type is N_SECT then the n_sect field contains an ordinal of the
2833 * section the symbol is defined in. The sections are numbered from 1 and
2834 * refer to sections in order they appear in the load commands for the file
2835 * they are in. This means the same ordinal may very well refer to different
2836 * sections in different files.
2837 *
2838 * The n_value field for all symbol table entries (including N_STAB's) gets
2839 * updated by the link editor based on the value of it's n_sect field and where
2840 * the section n_sect references gets relocated. If the value of the n_sect
2841 * field is NO_SECT then it's n_value field is not changed by the link editor.
2842 */
2843/// symbol is not in any section
2844pub const NO_SECT: u8 = 0;
2845/// 1 thru 255 inclusive
2846pub const MAX_SECT: u8 = 255;
2847
2848/*
2849 * Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
2850 * who's values (n_value) are non-zero. In which case the value of the n_value
2851 * field is the size (in bytes) of the common symbol. The n_sect field is set
2852 * to NO_SECT. The alignment of a common symbol may be set as a power of 2
2853 * between 2^1 and 2^15 as part of the n_desc field using the macros below. If
2854 * the alignment is not set (a value of zero) then natural alignment based on
2855 * the size is used.
2856 */
2857/* TODO:
2858#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f)
2859#define SET_COMM_ALIGN(n_desc,align) \
2860 (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
2861 */
2862
2863/*
2864 * To support the lazy binding of undefined symbols in the dynamic link-editor,
2865 * the undefined symbols in the symbol table (the nlist structures) are marked
2866 * with the indication if the undefined reference is a lazy reference or
2867 * non-lazy reference. If both a non-lazy reference and a lazy reference is
2868 * made to the same symbol the non-lazy reference takes precedence. A reference
2869 * is lazy only when all references to that symbol are made through a symbol
2870 * pointer in a lazy symbol pointer section.
2871 *
2872 * The implementation of marking nlist structures in the symbol table for
2873 * undefined symbols will be to use some of the bits of the n_desc field as a
2874 * reference type. The mask REFERENCE_TYPE will be applied to the n_desc field
2875 * of an nlist structure for an undefined symbol to determine the type of
2876 * undefined reference (lazy or non-lazy).
2877 *
2878 * The constants for the REFERENCE FLAGS are propagated to the reference table
2879 * in a shared library file. In that case the constant for a defined symbol,
2880 * REFERENCE_FLAG_DEFINED, is also used.
2881 */
2882/* Reference type bits of the n_desc field of undefined symbols */
2883pub const REFERENCE_TYPE: u16 = 0x7;
2884/* types of references */
2885pub const REFERENCE_FLAG_UNDEFINED_NON_LAZY: u16 = 0;
2886pub const REFERENCE_FLAG_UNDEFINED_LAZY: u16 = 1;
2887pub const REFERENCE_FLAG_DEFINED: u16 = 2;
2888pub const REFERENCE_FLAG_PRIVATE_DEFINED: u16 = 3;
2889pub const REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY: u16 = 4;
2890pub const REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY: u16 = 5;
2891
2892/*
2893 * To simplify stripping of objects that use are used with the dynamic link
2894 * editor, the static link editor marks the symbols defined an object that are
2895 * referenced by a dynamically bound object (dynamic shared libraries, bundles).
2896 * With this marking strip knows not to strip these symbols.
2897 */
2898pub const REFERENCED_DYNAMICALLY: u16 = 0x0010;
2899
2900/*
2901 * For images created by the static link editor with the -twolevel_namespace
2902 * option in effect the flags field of the mach header is marked with
2903 * MH_TWOLEVEL. And the binding of the undefined references of the image are
2904 * determined by the static link editor. Which library an undefined symbol is
2905 * bound to is recorded by the static linker in the high 8 bits of the n_desc
2906 * field using the SET_LIBRARY_ORDINAL macro below. The ordinal recorded
2907 * references the libraries listed in the Mach-O's LC_LOAD_DYLIB,
2908 * LC_LOAD_WEAK_DYLIB, LC_REEXPORT_DYLIB, LC_LOAD_UPWARD_DYLIB, and
2909 * LC_LAZY_LOAD_DYLIB, etc. load commands in the order they appear in the
2910 * headers. The library ordinals start from 1.
2911 * For a dynamic library that is built as a two-level namespace image the
2912 * undefined references from module defined in another use the same nlist struct
2913 * an in that case SELF_LIBRARY_ORDINAL is used as the library ordinal. For
2914 * defined symbols in all images they also must have the library ordinal set to
2915 * SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable
2916 * image for references from plugins that refer to the executable that loads
2917 * them.
2918 *
2919 * The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace
2920 * image that are looked up by the dynamic linker with flat namespace semantics.
2921 * This ordinal was added as a feature in Mac OS X 10.3 by reducing the
2922 * value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries
2923 * or binaries built with older tools to have 0xfe (254) dynamic libraries. In
2924 * this case the ordinal value 0xfe (254) must be treated as a library ordinal
2925 * for compatibility.
2926 */
2927/* TODO:
2928#define GET_LIBRARY_ORDINAL(n_desc) (((n_desc) >> 8) & 0xff)
2929#define SET_LIBRARY_ORDINAL(n_desc,ordinal) \
2930 (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
2931 */
2932pub const SELF_LIBRARY_ORDINAL: u8 = 0x0;
2933pub const MAX_LIBRARY_ORDINAL: u8 = 0xfd;
2934pub const DYNAMIC_LOOKUP_ORDINAL: u8 = 0xfe;
2935pub const EXECUTABLE_ORDINAL: u8 = 0xff;
2936
2937/*
2938 * The bit 0x0020 of the n_desc field is used for two non-overlapping purposes
2939 * and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED.
2940 */
2941
2942/*
2943 * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
2944 * relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
2945 * static link editor it is never to dead strip the symbol.
2946 */
2947/// symbol is not to be dead stripped
2948pub const N_NO_DEAD_STRIP: u16 = 0x0020;
2949
2950/*
2951 * The N_DESC_DISCARDED bit of the n_desc field never appears in linked image.
2952 * But is used in very rare cases by the dynamic link editor to mark an in
2953 * memory symbol as discared and longer used for linking.
2954 */
2955/// symbol is discarded
2956pub const N_DESC_DISCARDED: u16 = 0x0020;
2957
2958/*
2959 * The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
2960 * the undefined symbol is allowed to be missing and is to have the address of
2961 * zero when missing.
2962 */
2963/// symbol is weak referenced
2964pub const N_WEAK_REF: u16 = 0x0040;
2965
2966/*
2967 * The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
2968 * linkers that the symbol definition is weak, allowing a non-weak symbol to
2969 * also be used which causes the weak definition to be discared. Currently this
2970 * is only supported for symbols in coalesced sections.
2971 */
2972/// coalesced symbol is a weak definition
2973pub const N_WEAK_DEF: u16 = 0x0080;
2974
2975/*
2976 * The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
2977 * that the undefined symbol should be resolved using flat namespace searching.
2978 */
2979/// reference to a weak symbol
2980pub const N_REF_TO_WEAK: u16 = 0x0080;
2981
2982/*
2983 * The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is
2984 * a definition of a Thumb function.
2985 */
2986/// symbol is a Thumb function (ARM)
2987pub const N_ARM_THUMB_DEF: u16 = 0x0008;
2988
2989/*
2990 * The N_SYMBOL_RESOLVER bit of the n_desc field indicates that the
2991 * that the function is actually a resolver function and should
2992 * be called to get the address of the real function to use.
2993 * This bit is only available in .o files (MH_OBJECT filetype)
2994 */
2995pub const N_SYMBOL_RESOLVER: u16 = 0x0100;
2996
2997/*
2998 * The N_ALT_ENTRY bit of the n_desc field indicates that the
2999 * symbol is pinned to the previous content.
3000 */
3001pub const N_ALT_ENTRY: u16 = 0x0200;
3002
3003/*
3004 * The N_COLD_FUNC bit of the n_desc field indicates that the symbol is used
3005 * infrequently and the linker should order it towards the end of the section.
3006 */
3007pub const N_COLD_FUNC: u16 = 0x0400;
3008
3009// Definitions from "/usr/include/mach-o/stab.h".
3010
3011/*
3012 * This file gives definitions supplementing <nlist.h> for permanent symbol
3013 * table entries of Mach-O files. Modified from the BSD definitions. The
3014 * modifications from the original definitions were changing what the values of
3015 * what was the n_other field (an unused field) which is now the n_sect field.
3016 * These modifications are required to support symbols in an arbitrary number of
3017 * sections not just the three sections (text, data and bss) in a BSD file.
3018 * The values of the defined constants have NOT been changed.
3019 *
3020 * These must have one of the N_STAB bits on. The n_value fields are subject
3021 * to relocation according to the value of their n_sect field. So for types
3022 * that refer to things in sections the n_sect field must be filled in with the
3023 * proper section ordinal. For types that are not to have their n_value field
3024 * relocatated the n_sect field must be NO_SECT.
3025 */
3026
3027/*
3028 * Symbolic debugger symbols. The comments give the conventional use for
3029 *
3030 * .stabs "n_name", n_type, n_sect, n_desc, n_value
3031 *
3032 * where n_type is the defined constant and not listed in the comment. Other
3033 * fields not listed are zero. n_sect is the section ordinal the entry is
3034 * referring to.
3035 */
3036/// global symbol: name,,NO_SECT,type,0
3037pub const N_GSYM: u8 = 0x20;
3038/// procedure name (f77 kludge): name,,NO_SECT,0,0
3039pub const N_FNAME: u8 = 0x22;
3040/// procedure: name,,n_sect,linenumber,address
3041pub const N_FUN: u8 = 0x24;
3042/// static symbol: name,,n_sect,type,address
3043pub const N_STSYM: u8 = 0x26;
3044/// .lcomm symbol: name,,n_sect,type,address
3045pub const N_LCSYM: u8 = 0x28;
3046/// begin nsect sym: 0,,n_sect,0,address
3047pub const N_BNSYM: u8 = 0x2e;
3048/// AST file path: name,,NO_SECT,0,0
3049pub const N_AST: u8 = 0x32;
3050/// emitted with gcc2_compiled and in gcc source
3051pub const N_OPT: u8 = 0x3c;
3052/// register sym: name,,NO_SECT,type,register
3053pub const N_RSYM: u8 = 0x40;
3054/// src line: 0,,n_sect,linenumber,address
3055pub const N_SLINE: u8 = 0x44;
3056/// end nsect sym: 0,,n_sect,0,address
3057pub const N_ENSYM: u8 = 0x4e;
3058/// structure elt: name,,NO_SECT,type,struct_offset
3059pub const N_SSYM: u8 = 0x60;
3060/// source file name: name,,n_sect,0,address
3061pub const N_SO: u8 = 0x64;
3062/// object file name: name,,0,0,st_mtime
3063///
3064/// historically N_OSO set n_sect to 0. The N_OSO
3065/// n_sect may instead hold the low byte of the
3066/// cpusubtype value from the Mach-O header.
3067pub const N_OSO: u8 = 0x66;
3068/// dynamic library file name: name,,NO_SECT,0,0
3069pub const N_LIB: u8 = 0x68;
3070/// local sym: name,,NO_SECT,type,offset
3071pub const N_LSYM: u8 = 0x80;
3072/// include file beginning: name,,NO_SECT,0,sum
3073pub const N_BINCL: u8 = 0x82;
3074/// #included file name: name,,n_sect,0,address
3075pub const N_SOL: u8 = 0x84;
3076/// compiler parameters: name,,NO_SECT,0,0
3077pub const N_PARAMS: u8 = 0x86;
3078/// compiler version: name,,NO_SECT,0,0
3079pub const N_VERSION: u8 = 0x88;
3080/// compiler -O level: name,,NO_SECT,0,0
3081pub const N_OLEVEL: u8 = 0x8A;
3082/// parameter: name,,NO_SECT,type,offset
3083pub const N_PSYM: u8 = 0xa0;
3084/// include file end: name,,NO_SECT,0,0
3085pub const N_EINCL: u8 = 0xa2;
3086/// alternate entry: name,,n_sect,linenumber,address
3087pub const N_ENTRY: u8 = 0xa4;
3088/// left bracket: 0,,NO_SECT,nesting level,address
3089pub const N_LBRAC: u8 = 0xc0;
3090/// deleted include file: name,,NO_SECT,0,sum
3091pub const N_EXCL: u8 = 0xc2;
3092/// right bracket: 0,,NO_SECT,nesting level,address
3093pub const N_RBRAC: u8 = 0xe0;
3094/// begin common: name,,NO_SECT,0,0
3095pub const N_BCOMM: u8 = 0xe2;
3096/// end common: name,,n_sect,0,0
3097pub const N_ECOMM: u8 = 0xe4;
3098/// end common (local name): 0,,n_sect,0,address
3099pub const N_ECOML: u8 = 0xe8;
3100/// second stab entry with length information
3101pub const N_LENG: u8 = 0xfe;
3102
3103/*
3104 * for the berkeley pascal compiler, pc(1):
3105 */
3106/// global pascal symbol: name,,NO_SECT,subtype,line
3107pub const N_PC: u8 = 0x30;
3108
3109// Definitions from "/usr/include/mach-o/reloc.h".
3110
3111/// A relocation entry.
3112///
3113/// Mach-O relocations have plain and scattered variants, with the
3114/// meaning of the fields depending on the variant.
3115///
3116/// This type provides functions for determining whether the relocation
3117/// is scattered, and for accessing the fields of each variant.
3118#[derive(Debug, Clone, Copy)]
3119#[repr(C)]
3120pub struct Relocation<E: Endian> {
3121 pub r_word0: U32<E>,
3122 pub r_word1: U32<E>,
3123}
3124
3125impl<E: Endian> Relocation<E> {
3126 /// Determine whether this is a scattered relocation.
3127 #[inline]
3128 pub fn r_scattered(self, endian: E, cputype: u32) -> bool {
3129 if cputype == CPU_TYPE_X86_64 {
3130 false
3131 } else {
3132 self.r_word0.get(endian) & R_SCATTERED != 0
3133 }
3134 }
3135
3136 /// Return the fields of a plain relocation.
3137 pub fn info(self, endian: E) -> RelocationInfo {
3138 let r_address = self.r_word0.get(endian);
3139 let r_word1 = self.r_word1.get(endian);
3140 if endian.is_little_endian() {
3141 RelocationInfo {
3142 r_address,
3143 r_symbolnum: r_word1 & 0x00ff_ffff,
3144 r_pcrel: ((r_word1 >> 24) & 0x1) != 0,
3145 r_length: ((r_word1 >> 25) & 0x3) as u8,
3146 r_extern: ((r_word1 >> 27) & 0x1) != 0,
3147 r_type: (r_word1 >> 28) as u8,
3148 }
3149 } else {
3150 RelocationInfo {
3151 r_address,
3152 r_symbolnum: r_word1 >> 8,
3153 r_pcrel: ((r_word1 >> 7) & 0x1) != 0,
3154 r_length: ((r_word1 >> 5) & 0x3) as u8,
3155 r_extern: ((r_word1 >> 4) & 0x1) != 0,
3156 r_type: (r_word1 & 0xf) as u8,
3157 }
3158 }
3159 }
3160
3161 /// Return the fields of a scattered relocation.
3162 pub fn scattered_info(self, endian: E) -> ScatteredRelocationInfo {
3163 let r_word0 = self.r_word0.get(endian);
3164 let r_value = self.r_word1.get(endian);
3165 ScatteredRelocationInfo {
3166 r_address: r_word0 & 0x00ff_ffff,
3167 r_type: ((r_word0 >> 24) & 0xf) as u8,
3168 r_length: ((r_word0 >> 28) & 0x3) as u8,
3169 r_pcrel: ((r_word0 >> 30) & 0x1) != 0,
3170 r_value,
3171 }
3172 }
3173}
3174
3175/*
3176 * Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD
3177 * format. The modifications from the original format were changing the value
3178 * of the r_symbolnum field for "local" (r_extern == 0) relocation entries.
3179 * This modification is required to support symbols in an arbitrary number of
3180 * sections not just the three sections (text, data and bss) in a 4.3BSD file.
3181 * Also the last 4 bits have had the r_type tag added to them.
3182 */
3183
3184#[derive(Debug, Clone, Copy)]
3185pub struct RelocationInfo {
3186 /// offset in the section to what is being relocated
3187 pub r_address: u32,
3188 /// symbol index if r_extern == 1 or section ordinal if r_extern == 0
3189 pub r_symbolnum: u32,
3190 /// was relocated pc relative already
3191 pub r_pcrel: bool,
3192 /// 0=byte, 1=word, 2=long, 3=quad
3193 pub r_length: u8,
3194 /// does not include value of sym referenced
3195 pub r_extern: bool,
3196 /// if not 0, machine specific relocation type
3197 pub r_type: u8,
3198}
3199
3200impl RelocationInfo {
3201 /// Combine the fields into a `Relocation`.
3202 pub fn relocation<E: Endian>(self, endian: E) -> Relocation<E> {
3203 let r_word0 = U32::new(endian, self.r_address);
3204 let r_word1 = U32::new(
3205 endian,
3206 if endian.is_little_endian() {
3207 self.r_symbolnum & 0x00ff_ffff
3208 | u32::from(self.r_pcrel) << 24
3209 | u32::from(self.r_length & 0x3) << 25
3210 | u32::from(self.r_extern) << 27
3211 | u32::from(self.r_type) << 28
3212 } else {
3213 self.r_symbolnum >> 8
3214 | u32::from(self.r_pcrel) << 7
3215 | u32::from(self.r_length & 0x3) << 5
3216 | u32::from(self.r_extern) << 4
3217 | u32::from(self.r_type) & 0xf
3218 },
3219 );
3220 Relocation { r_word0, r_word1 }
3221 }
3222}
3223
3224/// absolute relocation type for Mach-O files
3225pub const R_ABS: u8 = 0;
3226
3227/*
3228 * The r_address is not really the address as it's name indicates but an offset.
3229 * In 4.3BSD a.out objects this offset is from the start of the "segment" for
3230 * which relocation entry is for (text or data). For Mach-O object files it is
3231 * also an offset but from the start of the "section" for which the relocation
3232 * entry is for. See comments in <mach-o/loader.h> about the r_address feild
3233 * in images for used with the dynamic linker.
3234 *
3235 * In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal
3236 * for the segment the symbol being relocated is in. These ordinals are the
3237 * symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these
3238 * ordinals refer to the sections in the object file in the order their section
3239 * structures appear in the headers of the object file they are in. The first
3240 * section has the ordinal 1, the second 2, and so on. This means that the
3241 * same ordinal in two different object files could refer to two different
3242 * sections. And further could have still different ordinals when combined
3243 * by the link-editor. The value R_ABS is used for relocation entries for
3244 * absolute symbols which need no further relocation.
3245 */
3246
3247/*
3248 * For RISC machines some of the references are split across two instructions
3249 * and the instruction does not contain the complete value of the reference.
3250 * In these cases a second, or paired relocation entry, follows each of these
3251 * relocation entries, using a PAIR r_type, which contains the other part of the
3252 * reference not contained in the instruction. This other part is stored in the
3253 * pair's r_address field. The exact number of bits of the other part of the
3254 * reference store in the r_address field is dependent on the particular
3255 * relocation type for the particular architecture.
3256 */
3257
3258/*
3259 * To make scattered loading by the link editor work correctly "local"
3260 * relocation entries can't be used when the item to be relocated is the value
3261 * of a symbol plus an offset (where the resulting expression is outside the
3262 * block the link editor is moving, a blocks are divided at symbol addresses).
3263 * In this case. where the item is a symbol value plus offset, the link editor
3264 * needs to know more than just the section the symbol was defined. What is
3265 * needed is the actual value of the symbol without the offset so it can do the
3266 * relocation correctly based on where the value of the symbol got relocated to
3267 * not the value of the expression (with the offset added to the symbol value).
3268 * So for the NeXT 2.0 release no "local" relocation entries are ever used when
3269 * there is a non-zero offset added to a symbol. The "external" and "local"
3270 * relocation entries remain unchanged.
3271 *
3272 * The implementation is quite messy given the compatibility with the existing
3273 * relocation entry format. The ASSUMPTION is that a section will never be
3274 * bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes. This assumption
3275 * allows the r_address (which is really an offset) to fit in 24 bits and high
3276 * bit of the r_address field in the relocation_info structure to indicate
3277 * it is really a scattered_relocation_info structure. Since these are only
3278 * used in places where "local" relocation entries are used and not where
3279 * "external" relocation entries are used the r_extern field has been removed.
3280 *
3281 * For scattered loading to work on a RISC machine where some of the references
3282 * are split across two instructions the link editor needs to be assured that
3283 * each reference has a unique 32 bit reference (that more than one reference is
3284 * NOT sharing the same high 16 bits for example) so it move each referenced
3285 * item independent of each other. Some compilers guarantees this but the
3286 * compilers don't so scattered loading can be done on those that do guarantee
3287 * this.
3288 */
3289
3290/// Bit set in `Relocation::r_word0` for scattered relocations.
3291pub const R_SCATTERED: u32 = 0x8000_0000;
3292
3293#[derive(Debug, Clone, Copy)]
3294pub struct ScatteredRelocationInfo {
3295 /// offset in the section to what is being relocated
3296 pub r_address: u32,
3297 /// if not 0, machine specific relocation type
3298 pub r_type: u8,
3299 /// 0=byte, 1=word, 2=long, 3=quad
3300 pub r_length: u8,
3301 /// was relocated pc relative already
3302 pub r_pcrel: bool,
3303 /// the value the item to be relocated is referring to (without any offset added)
3304 pub r_value: u32,
3305}
3306
3307impl ScatteredRelocationInfo {
3308 /// Combine the fields into a `Relocation`.
3309 pub fn relocation<E: Endian>(self, endian: E) -> Relocation<E> {
3310 let r_word0 = U32::new(
3311 endian,
3312 self.r_address & 0x00ff_ffff
3313 | u32::from(self.r_type & 0xf) << 24
3314 | u32::from(self.r_length & 0x3) << 28
3315 | u32::from(self.r_pcrel) << 30
3316 | R_SCATTERED,
3317 );
3318 let r_word1 = U32::new(endian, self.r_value);
3319 Relocation { r_word0, r_word1 }
3320 }
3321}
3322
3323/*
3324 * Relocation types used in a generic implementation. Relocation entries for
3325 * normal things use the generic relocation as described above and their r_type
3326 * is GENERIC_RELOC_VANILLA (a value of zero).
3327 *
3328 * Another type of generic relocation, GENERIC_RELOC_SECTDIFF, is to support
3329 * the difference of two symbols defined in different sections. That is the
3330 * expression "symbol1 - symbol2 + constant" is a relocatable expression when
3331 * both symbols are defined in some section. For this type of relocation the
3332 * both relocations entries are scattered relocation entries. The value of
3333 * symbol1 is stored in the first relocation entry's r_value field and the
3334 * value of symbol2 is stored in the pair's r_value field.
3335 *
3336 * A special case for a prebound lazy pointer is needed to beable to set the
3337 * value of the lazy pointer back to its non-prebound state. This is done
3338 * using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation
3339 * entry where the r_value feild is the value of the lazy pointer not prebound.
3340 */
3341/// generic relocation as described above
3342pub const GENERIC_RELOC_VANILLA: u8 = 0;
3343/// Only follows a GENERIC_RELOC_SECTDIFF
3344pub const GENERIC_RELOC_PAIR: u8 = 1;
3345pub const GENERIC_RELOC_SECTDIFF: u8 = 2;
3346/// prebound lazy pointer
3347pub const GENERIC_RELOC_PB_LA_PTR: u8 = 3;
3348pub const GENERIC_RELOC_LOCAL_SECTDIFF: u8 = 4;
3349/// thread local variables
3350pub const GENERIC_RELOC_TLV: u8 = 5;
3351
3352// Definitions from "/usr/include/mach-o/arm/reloc.h".
3353
3354/*
3355 * Relocation types used in the arm implementation. Relocation entries for
3356 * things other than instructions use the same generic relocation as described
3357 * in <mach-o/reloc.h> and their r_type is ARM_RELOC_VANILLA, one of the
3358 * *_SECTDIFF or the *_PB_LA_PTR types. The rest of the relocation types are
3359 * for instructions. Since they are for instructions the r_address field
3360 * indicates the 32 bit instruction that the relocation is to be performed on.
3361 */
3362/// generic relocation as described above
3363pub const ARM_RELOC_VANILLA: u8 = 0;
3364/// the second relocation entry of a pair
3365pub const ARM_RELOC_PAIR: u8 = 1;
3366/// a PAIR follows with subtract symbol value
3367pub const ARM_RELOC_SECTDIFF: u8 = 2;
3368/// like ARM_RELOC_SECTDIFF, but the symbol referenced was local.
3369pub const ARM_RELOC_LOCAL_SECTDIFF: u8 = 3;
3370/// prebound lazy pointer
3371pub const ARM_RELOC_PB_LA_PTR: u8 = 4;
3372/// 24 bit branch displacement (to a word address)
3373pub const ARM_RELOC_BR24: u8 = 5;
3374/// 22 bit branch displacement (to a half-word address)
3375pub const ARM_THUMB_RELOC_BR22: u8 = 6;
3376/// obsolete - a thumb 32-bit branch instruction possibly needing page-spanning branch workaround
3377pub const ARM_THUMB_32BIT_BRANCH: u8 = 7;
3378
3379/*
3380 * For these two r_type relocations they always have a pair following them
3381 * and the r_length bits are used differently. The encoding of the
3382 * r_length is as follows:
3383 * low bit of r_length:
3384 * 0 - :lower16: for movw instructions
3385 * 1 - :upper16: for movt instructions
3386 * high bit of r_length:
3387 * 0 - arm instructions
3388 * 1 - thumb instructions
3389 * the other half of the relocated expression is in the following pair
3390 * relocation entry in the the low 16 bits of r_address field.
3391 */
3392pub const ARM_RELOC_HALF: u8 = 8;
3393pub const ARM_RELOC_HALF_SECTDIFF: u8 = 9;
3394
3395// Definitions from "/usr/include/mach-o/arm64/reloc.h".
3396
3397/*
3398 * Relocation types used in the arm64 implementation.
3399 */
3400/// for pointers
3401pub const ARM64_RELOC_UNSIGNED: u8 = 0;
3402/// must be followed by a ARM64_RELOC_UNSIGNED
3403pub const ARM64_RELOC_SUBTRACTOR: u8 = 1;
3404/// a B/BL instruction with 26-bit displacement
3405pub const ARM64_RELOC_BRANCH26: u8 = 2;
3406/// pc-rel distance to page of target
3407pub const ARM64_RELOC_PAGE21: u8 = 3;
3408/// offset within page, scaled by r_length
3409pub const ARM64_RELOC_PAGEOFF12: u8 = 4;
3410/// pc-rel distance to page of GOT slot
3411pub const ARM64_RELOC_GOT_LOAD_PAGE21: u8 = 5;
3412/// offset within page of GOT slot, scaled by r_length
3413pub const ARM64_RELOC_GOT_LOAD_PAGEOFF12: u8 = 6;
3414/// for pointers to GOT slots
3415pub const ARM64_RELOC_POINTER_TO_GOT: u8 = 7;
3416/// pc-rel distance to page of TLVP slot
3417pub const ARM64_RELOC_TLVP_LOAD_PAGE21: u8 = 8;
3418/// offset within page of TLVP slot, scaled by r_length
3419pub const ARM64_RELOC_TLVP_LOAD_PAGEOFF12: u8 = 9;
3420/// must be followed by PAGE21 or PAGEOFF12
3421pub const ARM64_RELOC_ADDEND: u8 = 10;
3422
3423// An arm64e authenticated pointer.
3424//
3425// Represents a pointer to a symbol (like ARM64_RELOC_UNSIGNED).
3426// Additionally, the resulting pointer is signed. The signature is
3427// specified in the target location: the addend is restricted to the lower
3428// 32 bits (instead of the full 64 bits for ARM64_RELOC_UNSIGNED):
3429//
3430// |63|62|61-51|50-49| 48 |47 - 32|31 - 0|
3431// | 1| 0| 0 | key | addr | discriminator | addend |
3432//
3433// The key is one of:
3434// IA: 00 IB: 01
3435// DA: 10 DB: 11
3436//
3437// The discriminator field is used as extra signature diversification.
3438//
3439// The addr field indicates whether the target address should be blended
3440// into the discriminator.
3441//
3442pub const ARM64_RELOC_AUTHENTICATED_POINTER: u8 = 11;
3443
3444// Definitions from "/usr/include/mach-o/ppc/reloc.h".
3445
3446/*
3447 * Relocation types used in the ppc implementation. Relocation entries for
3448 * things other than instructions use the same generic relocation as described
3449 * above and their r_type is RELOC_VANILLA. The rest of the relocation types
3450 * are for instructions. Since they are for instructions the r_address field
3451 * indicates the 32 bit instruction that the relocation is to be performed on.
3452 * The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types
3453 * except for PPC_RELOC_BR14.
3454 *
3455 * For PPC_RELOC_BR14 if the r_length is the unused value 3, then the branch was
3456 * statically predicted setting or clearing the Y-bit based on the sign of the
3457 * displacement or the opcode. If this is the case the static linker must flip
3458 * the value of the Y-bit if the sign of the displacement changes for non-branch
3459 * always conditions.
3460 */
3461/// generic relocation as described above
3462pub const PPC_RELOC_VANILLA: u8 = 0;
3463/// the second relocation entry of a pair
3464pub const PPC_RELOC_PAIR: u8 = 1;
3465/// 14 bit branch displacement (to a word address)
3466pub const PPC_RELOC_BR14: u8 = 2;
3467/// 24 bit branch displacement (to a word address)
3468pub const PPC_RELOC_BR24: u8 = 3;
3469/// a PAIR follows with the low half
3470pub const PPC_RELOC_HI16: u8 = 4;
3471/// a PAIR follows with the high half
3472pub const PPC_RELOC_LO16: u8 = 5;
3473/// Same as the RELOC_HI16 except the low 16 bits and the high 16 bits are added together
3474/// with the low 16 bits sign extended first. This means if bit 15 of the low 16 bits is
3475/// set the high 16 bits stored in the instruction will be adjusted.
3476pub const PPC_RELOC_HA16: u8 = 6;
3477/// Same as the LO16 except that the low 2 bits are not stored in the instruction and are
3478/// always zero. This is used in double word load/store instructions.
3479pub const PPC_RELOC_LO14: u8 = 7;
3480/// a PAIR follows with subtract symbol value
3481pub const PPC_RELOC_SECTDIFF: u8 = 8;
3482/// prebound lazy pointer
3483pub const PPC_RELOC_PB_LA_PTR: u8 = 9;
3484/// section difference forms of above. a PAIR
3485pub const PPC_RELOC_HI16_SECTDIFF: u8 = 10;
3486/// follows these with subtract symbol value
3487pub const PPC_RELOC_LO16_SECTDIFF: u8 = 11;
3488pub const PPC_RELOC_HA16_SECTDIFF: u8 = 12;
3489pub const PPC_RELOC_JBSR: u8 = 13;
3490pub const PPC_RELOC_LO14_SECTDIFF: u8 = 14;
3491/// like PPC_RELOC_SECTDIFF, but the symbol referenced was local.
3492pub const PPC_RELOC_LOCAL_SECTDIFF: u8 = 15;
3493
3494// Definitions from "/usr/include/mach-o/x86_64/reloc.h".
3495
3496/*
3497 * Relocations for x86_64 are a bit different than for other architectures in
3498 * Mach-O: Scattered relocations are not used. Almost all relocations produced
3499 * by the compiler are external relocations. An external relocation has the
3500 * r_extern bit set to 1 and the r_symbolnum field contains the symbol table
3501 * index of the target label.
3502 *
3503 * When the assembler is generating relocations, if the target label is a local
3504 * label (begins with 'L'), then the previous non-local label in the same
3505 * section is used as the target of the external relocation. An addend is used
3506 * with the distance from that non-local label to the target label. Only when
3507 * there is no previous non-local label in the section is an internal
3508 * relocation used.
3509 *
3510 * The addend (i.e. the 4 in _foo+4) is encoded in the instruction (Mach-O does
3511 * not have RELA relocations). For PC-relative relocations, the addend is
3512 * stored directly in the instruction. This is different from other Mach-O
3513 * architectures, which encode the addend minus the current section offset.
3514 *
3515 * The relocation types are:
3516 *
3517 * X86_64_RELOC_UNSIGNED // for absolute addresses
3518 * X86_64_RELOC_SIGNED // for signed 32-bit displacement
3519 * X86_64_RELOC_BRANCH // a CALL/JMP instruction with 32-bit displacement
3520 * X86_64_RELOC_GOT_LOAD // a MOVQ load of a GOT entry
3521 * X86_64_RELOC_GOT // other GOT references
3522 * X86_64_RELOC_SUBTRACTOR // must be followed by a X86_64_RELOC_UNSIGNED
3523 *
3524 * The following are sample assembly instructions, followed by the relocation
3525 * and section content they generate in an object file:
3526 *
3527 * call _foo
3528 * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3529 * E8 00 00 00 00
3530 *
3531 * call _foo+4
3532 * r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3533 * E8 04 00 00 00
3534 *
3535 * movq _foo@GOTPCREL(%rip), %rax
3536 * r_type=X86_64_RELOC_GOT_LOAD, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3537 * 48 8B 05 00 00 00 00
3538 *
3539 * pushq _foo@GOTPCREL(%rip)
3540 * r_type=X86_64_RELOC_GOT, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3541 * FF 35 00 00 00 00
3542 *
3543 * movl _foo(%rip), %eax
3544 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3545 * 8B 05 00 00 00 00
3546 *
3547 * movl _foo+4(%rip), %eax
3548 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3549 * 8B 05 04 00 00 00
3550 *
3551 * movb $0x12, _foo(%rip)
3552 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3553 * C6 05 FF FF FF FF 12
3554 *
3555 * movl $0x12345678, _foo(%rip)
3556 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
3557 * C7 05 FC FF FF FF 78 56 34 12
3558 *
3559 * .quad _foo
3560 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3561 * 00 00 00 00 00 00 00 00
3562 *
3563 * .quad _foo+4
3564 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3565 * 04 00 00 00 00 00 00 00
3566 *
3567 * .quad _foo - _bar
3568 * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
3569 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3570 * 00 00 00 00 00 00 00 00
3571 *
3572 * .quad _foo - _bar + 4
3573 * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
3574 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3575 * 04 00 00 00 00 00 00 00
3576 *
3577 * .long _foo - _bar
3578 * r_type=X86_64_RELOC_SUBTRACTOR, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_bar
3579 * r_type=X86_64_RELOC_UNSIGNED, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3580 * 00 00 00 00
3581 *
3582 * lea L1(%rip), %rax
3583 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_prev
3584 * 48 8d 05 12 00 00 00
3585 * // assumes _prev is the first non-local label 0x12 bytes before L1
3586 *
3587 * lea L0(%rip), %rax
3588 * r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3
3589 * 48 8d 05 56 00 00 00
3590 * // assumes L0 is in third section and there is no previous non-local label.
3591 * // The rip-relative-offset of 0x00000056 is L0-address_of_next_instruction.
3592 * // address_of_next_instruction is the address of the relocation + 4.
3593 *
3594 * add $6,L0(%rip)
3595 * r_type=X86_64_RELOC_SIGNED_1, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3
3596 * 83 05 18 00 00 00 06
3597 * // assumes L0 is in third section and there is no previous non-local label.
3598 * // The rip-relative-offset of 0x00000018 is L0-address_of_next_instruction.
3599 * // address_of_next_instruction is the address of the relocation + 4 + 1.
3600 * // The +1 comes from SIGNED_1. This is used because the relocation is not
3601 * // at the end of the instruction.
3602 *
3603 * .quad L1
3604 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
3605 * 12 00 00 00 00 00 00 00
3606 * // assumes _prev is the first non-local label 0x12 bytes before L1
3607 *
3608 * .quad L0
3609 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=0, r_pcrel=0, r_symbolnum=3
3610 * 56 00 00 00 00 00 00 00
3611 * // assumes L0 is in third section, has an address of 0x00000056 in .o
3612 * // file, and there is no previous non-local label
3613 *
3614 * .quad _foo - .
3615 * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
3616 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3617 * EE FF FF FF FF FF FF FF
3618 * // assumes _prev is the first non-local label 0x12 bytes before this
3619 * // .quad
3620 *
3621 * .quad _foo - L1
3622 * r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
3623 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
3624 * EE FF FF FF FF FF FF FF
3625 * // assumes _prev is the first non-local label 0x12 bytes before L1
3626 *
3627 * .quad L1 - _prev
3628 * // No relocations. This is an assembly time constant.
3629 * 12 00 00 00 00 00 00 00
3630 * // assumes _prev is the first non-local label 0x12 bytes before L1
3631 *
3632 *
3633 *
3634 * In final linked images, there are only two valid relocation kinds:
3635 *
3636 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=1, r_symbolnum=sym_index
3637 * This tells dyld to add the address of a symbol to a pointer sized (8-byte)
3638 * piece of data (i.e on disk the 8-byte piece of data contains the addend). The
3639 * r_symbolnum contains the index into the symbol table of the target symbol.
3640 *
3641 * r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=0, r_symbolnum=0
3642 * This tells dyld to adjust the pointer sized (8-byte) piece of data by the amount
3643 * the containing image was loaded from its base address (e.g. slide).
3644 *
3645 */
3646/// for absolute addresses
3647pub const X86_64_RELOC_UNSIGNED: u8 = 0;
3648/// for signed 32-bit displacement
3649pub const X86_64_RELOC_SIGNED: u8 = 1;
3650/// a CALL/JMP instruction with 32-bit displacement
3651pub const X86_64_RELOC_BRANCH: u8 = 2;
3652/// a MOVQ load of a GOT entry
3653pub const X86_64_RELOC_GOT_LOAD: u8 = 3;
3654/// other GOT references
3655pub const X86_64_RELOC_GOT: u8 = 4;
3656/// must be followed by a X86_64_RELOC_UNSIGNED
3657pub const X86_64_RELOC_SUBTRACTOR: u8 = 5;
3658/// for signed 32-bit displacement with a -1 addend
3659pub const X86_64_RELOC_SIGNED_1: u8 = 6;
3660/// for signed 32-bit displacement with a -2 addend
3661pub const X86_64_RELOC_SIGNED_2: u8 = 7;
3662/// for signed 32-bit displacement with a -4 addend
3663pub const X86_64_RELOC_SIGNED_4: u8 = 8;
3664/// for thread local variables
3665pub const X86_64_RELOC_TLV: u8 = 9;
3666
3667unsafe_impl_pod!(FatHeader, FatArch32, FatArch64,);
3668unsafe_impl_endian_pod!(
3669 DyldCacheHeader,
3670 DyldCacheMappingInfo,
3671 DyldCacheMappingAndSlideInfo,
3672 DyldCacheImageInfo,
3673 DyldCacheSlideInfo2,
3674 DyldCacheSlideInfo3,
3675 DyldCacheSlideInfo5,
3676 DyldSubCacheEntryV1,
3677 DyldSubCacheEntryV2,
3678 MachHeader32,
3679 MachHeader64,
3680 LoadCommand,
3681 LcStr,
3682 SegmentCommand32,
3683 SegmentCommand64,
3684 Section32,
3685 Section64,
3686 Fvmlib,
3687 FvmlibCommand,
3688 Dylib,
3689 DylibCommand,
3690 DylibUseCommand,
3691 SubFrameworkCommand,
3692 SubClientCommand,
3693 SubUmbrellaCommand,
3694 SubLibraryCommand,
3695 PreboundDylibCommand,
3696 DylinkerCommand,
3697 ThreadCommand,
3698 RoutinesCommand32,
3699 RoutinesCommand64,
3700 SymtabCommand,
3701 DysymtabCommand,
3702 DylibTableOfContents,
3703 DylibModule32,
3704 DylibModule64,
3705 DylibReference,
3706 TwolevelHintsCommand,
3707 TwolevelHint,
3708 PrebindCksumCommand,
3709 UuidCommand,
3710 RpathCommand,
3711 TargetTripleCommand,
3712 LinkeditDataCommand,
3713 EncryptionInfoCommand32,
3714 EncryptionInfoCommand64,
3715 VersionMinCommand,
3716 BuildVersionCommand,
3717 BuildToolVersion,
3718 DyldInfoCommand,
3719 LinkerOptionCommand,
3720 SymsegCommand,
3721 IdentCommand,
3722 FvmfileCommand,
3723 EntryPointCommand,
3724 SourceVersionCommand,
3725 DataInCodeEntry,
3726 //TlvDescriptor,
3727 NoteCommand,
3728 FilesetEntryCommand,
3729 Nlist32,
3730 Nlist64,
3731 Relocation,
3732);