1 | /* $Id: mach-o.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Mach-O Structures and Constants.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef IPRT_INCLUDED_formats_mach_o_h
|
---|
28 | #define IPRT_INCLUDED_formats_mach_o_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/types.h>
|
---|
34 | #include <iprt/assertcompile.h>
|
---|
35 |
|
---|
36 | #ifndef CPU_ARCH_MASK
|
---|
37 |
|
---|
38 | /* cputype */
|
---|
39 | #define CPU_ARCH_MASK INT32_C(0xff000000)
|
---|
40 | #define CPU_ARCH_ABI64 INT32_C(0x01000000)
|
---|
41 | #define CPU_ARCH_ABI64_32 INT32_C(0x02000000) /**< LP32 on 64-bit hardware */
|
---|
42 |
|
---|
43 | #define CPU_TYPE_ANY INT32_C(-1)
|
---|
44 | #define CPU_TYPE_VAX INT32_C(1)
|
---|
45 | #define CPU_TYPE_MC680x0 INT32_C(6)
|
---|
46 | #define CPU_TYPE_X86 INT32_C(7)
|
---|
47 | #define CPU_TYPE_I386 CPU_TYPE_X86
|
---|
48 | #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
|
---|
49 | #define CPU_TYPE_MC98000 INT32_C(10)
|
---|
50 | #define CPU_TYPE_HPPA INT32_C(11)
|
---|
51 | #define CPU_TYPE_ARM INT32_C(12)
|
---|
52 | #define CPU_TYPE_ARM32 CPU_TYPE_ARM
|
---|
53 | #define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
|
---|
54 | #define CPU_TYPE_ARM64_32 (CPU_TYPE_ARM | CPU_ARCH_ABI64_32)
|
---|
55 | #define CPU_TYPE_MC88000 INT32_C(13)
|
---|
56 | #define CPU_TYPE_SPARC INT32_C(14)
|
---|
57 | #define CPU_TYPE_I860 INT32_C(15)
|
---|
58 | #define CPU_TYPE_POWERPC INT32_C(18)
|
---|
59 | #define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
|
---|
60 |
|
---|
61 | /* cpusubtype */
|
---|
62 | #define CPU_SUBTYPE_MULTIPLE INT32_C(-1)
|
---|
63 | #define CPU_SUBTYPE_LITTLE_ENDIAN INT32_C(0)
|
---|
64 | #define CPU_SUBTYPE_BIG_ENDIAN INT32_C(1)
|
---|
65 |
|
---|
66 | #define CPU_SUBTYPE_VAX_ALL INT32_C(0)
|
---|
67 | #define CPU_SUBTYPE_VAX780 INT32_C(1)
|
---|
68 | #define CPU_SUBTYPE_VAX785 INT32_C(2)
|
---|
69 | #define CPU_SUBTYPE_VAX750 INT32_C(3)
|
---|
70 | #define CPU_SUBTYPE_VAX730 INT32_C(4)
|
---|
71 | #define CPU_SUBTYPE_UVAXI INT32_C(5)
|
---|
72 | #define CPU_SUBTYPE_UVAXII INT32_C(6)
|
---|
73 | #define CPU_SUBTYPE_VAX8200 INT32_C(7)
|
---|
74 | #define CPU_SUBTYPE_VAX8500 INT32_C(8)
|
---|
75 | #define CPU_SUBTYPE_VAX8600 INT32_C(9)
|
---|
76 | #define CPU_SUBTYPE_VAX8650 INT32_C(10)
|
---|
77 | #define CPU_SUBTYPE_VAX8800 INT32_C(11)
|
---|
78 | #define CPU_SUBTYPE_UVAXIII INT32_C(12)
|
---|
79 |
|
---|
80 | #define CPU_SUBTYPE_MC680x0_ALL INT32_C(1)
|
---|
81 | #define CPU_SUBTYPE_MC68030 INT32_C(1)
|
---|
82 | #define CPU_SUBTYPE_MC68040 INT32_C(2)
|
---|
83 | #define CPU_SUBTYPE_MC68030_ONLY INT32_C(3)
|
---|
84 |
|
---|
85 | #define CPU_SUBTYPE_INTEL(fam, model) ( (int32_t )(((model) << 4) | (fam)) )
|
---|
86 | #define CPU_SUBTYPE_INTEL_FAMILY(subtype) ( (subtype) & 0xf )
|
---|
87 | #define CPU_SUBTYPE_INTEL_MODEL(subtype) ( (subtype) >> 4 )
|
---|
88 | #define CPU_SUBTYPE_INTEL_FAMILY_MAX 0xf
|
---|
89 | #define CPU_SUBTYPE_INTEL_MODEL_ALL 0
|
---|
90 |
|
---|
91 | #define CPU_SUBTYPE_I386_ALL CPU_SUBTYPE_INTEL(3, 0)
|
---|
92 | #define CPU_SUBTYPE_386 CPU_SUBTYPE_INTEL(3, 0)
|
---|
93 | #define CPU_SUBTYPE_486 CPU_SUBTYPE_INTEL(4, 0)
|
---|
94 | #define CPU_SUBTYPE_486SX CPU_SUBTYPE_INTEL(4, 8)
|
---|
95 | #define CPU_SUBTYPE_586 CPU_SUBTYPE_INTEL(5, 0)
|
---|
96 | #define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
|
---|
97 | #define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
|
---|
98 | #define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
|
---|
99 | #define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
|
---|
100 | #define CPU_SUBTYPE_CELERON CPU_SUBTYPE_INTEL(7, 6)
|
---|
101 | #define CPU_SUBTYPE_CELERON_MOBILE CPU_SUBTYPE_INTEL(7, 7)
|
---|
102 | #define CPU_SUBTYPE_PENTIUM_3 CPU_SUBTYPE_INTEL(8, 0)
|
---|
103 | #define CPU_SUBTYPE_PENTIUM_3_M CPU_SUBTYPE_INTEL(8, 1)
|
---|
104 | #define CPU_SUBTYPE_PENTIUM_3_XEON CPU_SUBTYPE_INTEL(8, 2)
|
---|
105 | #define CPU_SUBTYPE_PENTIUM_M CPU_SUBTYPE_INTEL(9, 0)
|
---|
106 | #define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
|
---|
107 | #define CPU_SUBTYPE_PENTIUM_4_M CPU_SUBTYPE_INTEL(10, 1)
|
---|
108 | #define CPU_SUBTYPE_ITANIUM CPU_SUBTYPE_INTEL(11, 0)
|
---|
109 | #define CPU_SUBTYPE_ITANIUM_2 CPU_SUBTYPE_INTEL(11, 1)
|
---|
110 | #define CPU_SUBTYPE_XEON CPU_SUBTYPE_INTEL(12, 0)
|
---|
111 | #define CPU_SUBTYPE_XEON_MP CPU_SUBTYPE_INTEL(12, 1)
|
---|
112 |
|
---|
113 | #define CPU_SUBTYPE_X86_ALL INT32_C(3)
|
---|
114 | #define CPU_SUBTYPE_X86_64_ALL INT32_C(3)
|
---|
115 | #define CPU_SUBTYPE_X86_ARCH1 INT32_C(4)
|
---|
116 |
|
---|
117 | #define CPU_SUBTYPE_MIPS_ALL INT32_C(0)
|
---|
118 | #define CPU_SUBTYPE_MIPS_R2300 INT32_C(1)
|
---|
119 | #define CPU_SUBTYPE_MIPS_R2600 INT32_C(2)
|
---|
120 | #define CPU_SUBTYPE_MIPS_R2800 INT32_C(3)
|
---|
121 | #define CPU_SUBTYPE_MIPS_R2000a INT32_C(4)
|
---|
122 | #define CPU_SUBTYPE_MIPS_R2000 INT32_C(5)
|
---|
123 | #define CPU_SUBTYPE_MIPS_R3000a INT32_C(6)
|
---|
124 | #define CPU_SUBTYPE_MIPS_R3000 INT32_C(7)
|
---|
125 |
|
---|
126 | #define CPU_SUBTYPE_MC98000_ALL INT32_C(0)
|
---|
127 | #define CPU_SUBTYPE_MC98601 INT32_C(1)
|
---|
128 |
|
---|
129 | #define CPU_SUBTYPE_HPPA_ALL INT32_C(0)
|
---|
130 | #define CPU_SUBTYPE_HPPA_7100 INT32_C(0)
|
---|
131 | #define CPU_SUBTYPE_HPPA_7100LC INT32_C(1)
|
---|
132 |
|
---|
133 | #define CPU_SUBTYPE_ARM_ALL INT32_C(0)
|
---|
134 | #define CPU_SUBTYPE_ARM_V4T INT32_C(5)
|
---|
135 | #define CPU_SUBTYPE_ARM_V6 INT32_C(6)
|
---|
136 | #define CPU_SUBTYPE_ARM_V5TEJ INT32_C(7)
|
---|
137 | #define CPU_SUBTYPE_ARM_XSCALE INT32_C(8)
|
---|
138 | #define CPU_SUBTYPE_ARM_V7 INT32_C(9)
|
---|
139 | #define CPU_SUBTYPE_ARM_V7F INT32_C(10)
|
---|
140 | #define CPU_SUBTYPE_ARM_V7S INT32_C(11)
|
---|
141 | #define CPU_SUBTYPE_ARM_V7K INT32_C(12)
|
---|
142 | #define CPU_SUBTYPE_ARM_V8 INT32_C(13)
|
---|
143 | #define CPU_SUBTYPE_ARM_V6M INT32_C(14)
|
---|
144 | #define CPU_SUBTYPE_ARM_V7M INT32_C(15)
|
---|
145 | #define CPU_SUBTYPE_ARM_V7EM INT32_C(16)
|
---|
146 | #define CPU_SUBTYPE_ARM_V8M INT32_C(17)
|
---|
147 |
|
---|
148 | #define CPU_SUBTYPE_ARM64_ALL INT32_C(0)
|
---|
149 | #define CPU_SUBTYPE_ARM64_V8 INT32_C(1)
|
---|
150 | #define CPU_SUBTYPE_ARM64E INT32_C(2)
|
---|
151 | #define CPU_SUBTYPE_ARM64_PTR_AUTH_MASK UINT32_C(0x0f000000)
|
---|
152 | #define CPU_SUBTYPE_ARM64_PTR_AUTH_VERSION(a) ( ((a) & CPU_SUBTYPE_ARM64_PTR_AUTH_MASK) >> 24 )
|
---|
153 |
|
---|
154 | #define CPU_SUBTYPE_ARM64_32_ALL INT32_C(0)
|
---|
155 | #define CPU_SUBTYPE_ARM64_32_V8 INT32_C(1)
|
---|
156 |
|
---|
157 | #define CPU_SUBTYPE_MC88000_ALL INT32_C(0)
|
---|
158 | #define CPU_SUBTYPE_MC88100 INT32_C(1)
|
---|
159 | #define CPU_SUBTYPE_MC88110 INT32_C(2)
|
---|
160 |
|
---|
161 | #define CPU_SUBTYPE_SPARC_ALL INT32_C(0)
|
---|
162 |
|
---|
163 | #define CPU_SUBTYPE_I860_ALL INT32_C(0)
|
---|
164 | #define CPU_SUBTYPE_I860_860 INT32_C(1)
|
---|
165 |
|
---|
166 | #define CPU_SUBTYPE_POWERPC_ALL INT32_C(0)
|
---|
167 | #define CPU_SUBTYPE_POWERPC_601 INT32_C(1)
|
---|
168 | #define CPU_SUBTYPE_POWERPC_602 INT32_C(2)
|
---|
169 | #define CPU_SUBTYPE_POWERPC_603 INT32_C(3)
|
---|
170 | #define CPU_SUBTYPE_POWERPC_603e INT32_C(4)
|
---|
171 | #define CPU_SUBTYPE_POWERPC_603ev INT32_C(5)
|
---|
172 | #define CPU_SUBTYPE_POWERPC_604 INT32_C(6)
|
---|
173 | #define CPU_SUBTYPE_POWERPC_604e INT32_C(7)
|
---|
174 | #define CPU_SUBTYPE_POWERPC_620 INT32_C(8)
|
---|
175 | #define CPU_SUBTYPE_POWERPC_750 INT32_C(9)
|
---|
176 | #define CPU_SUBTYPE_POWERPC_7400 INT32_C(10)
|
---|
177 | #define CPU_SUBTYPE_POWERPC_7450 INT32_C(11)
|
---|
178 | #define CPU_SUBTYPE_POWERPC_Max INT32_C(10)
|
---|
179 | #define CPU_SUBTYPE_POWERPC_SCVger INT32_C(11)
|
---|
180 | #define CPU_SUBTYPE_POWERPC_970 INT32_C(100)
|
---|
181 |
|
---|
182 | #define CPU_SUBTYPE_MASK UINT32_C(0xff000000)
|
---|
183 | #define CPU_SUBTYPE_LIB64 UINT32_C(0x80000000)
|
---|
184 |
|
---|
185 | #endif /* !CPU_ARCH_MASK */
|
---|
186 |
|
---|
187 |
|
---|
188 | typedef struct fat_header
|
---|
189 | {
|
---|
190 | uint32_t magic;
|
---|
191 | uint32_t nfat_arch;
|
---|
192 | } fat_header_t;
|
---|
193 |
|
---|
194 | #ifndef IMAGE_FAT_SIGNATURE
|
---|
195 | # define IMAGE_FAT_SIGNATURE UINT32_C(0xcafebabe)
|
---|
196 | #endif
|
---|
197 | #ifndef IMAGE_FAT_SIGNATURE_OE
|
---|
198 | # define IMAGE_FAT_SIGNATURE_OE UINT32_C(0xbebafeca)
|
---|
199 | #endif
|
---|
200 |
|
---|
201 | typedef struct fat_arch
|
---|
202 | {
|
---|
203 | int32_t cputype;
|
---|
204 | int32_t cpusubtype;
|
---|
205 | uint32_t offset;
|
---|
206 | uint32_t size;
|
---|
207 | uint32_t align;
|
---|
208 | } fat_arch_t;
|
---|
209 |
|
---|
210 | typedef struct mach_header_32
|
---|
211 | {
|
---|
212 | uint32_t magic;
|
---|
213 | int32_t cputype;
|
---|
214 | int32_t cpusubtype;
|
---|
215 | uint32_t filetype;
|
---|
216 | uint32_t ncmds;
|
---|
217 | uint32_t sizeofcmds;
|
---|
218 | uint32_t flags;
|
---|
219 | } mach_header_32_t;
|
---|
220 |
|
---|
221 | /* magic */
|
---|
222 | #ifndef IMAGE_MACHO32_SIGNATURE
|
---|
223 | # define IMAGE_MACHO32_SIGNATURE UINT32_C(0xfeedface)
|
---|
224 | #endif
|
---|
225 | #ifndef IMAGE_MACHO32_SIGNATURE_OE
|
---|
226 | # define IMAGE_MACHO32_SIGNATURE_OE UINT32_C(0xcefaedfe)
|
---|
227 | #endif
|
---|
228 | #define MH_MAGIC IMAGE_MACHO32_SIGNATURE
|
---|
229 | #define MH_CIGAM IMAGE_MACHO32_SIGNATURE_OE
|
---|
230 |
|
---|
231 | typedef struct mach_header_64
|
---|
232 | {
|
---|
233 | uint32_t magic; /**< 0x00 */
|
---|
234 | int32_t cputype; /**< 0x04 */
|
---|
235 | int32_t cpusubtype; /**< 0x08 */
|
---|
236 | uint32_t filetype; /**< 0x0c */
|
---|
237 | uint32_t ncmds; /**< 0x10 */
|
---|
238 | uint32_t sizeofcmds; /**< 0x14 */
|
---|
239 | uint32_t flags; /**< 0x18 */
|
---|
240 | uint32_t reserved; /**< 0x1c */
|
---|
241 | } mach_header_64_t;
|
---|
242 | AssertCompileSize(mach_header_64_t, 0x20);
|
---|
243 |
|
---|
244 | /* magic */
|
---|
245 | #ifndef IMAGE_MACHO64_SIGNATURE
|
---|
246 | # define IMAGE_MACHO64_SIGNATURE UINT32_C(0xfeedfacf)
|
---|
247 | #endif
|
---|
248 | #ifndef IMAGE_MACHO64_SIGNATURE_OE
|
---|
249 | # define IMAGE_MACHO64_SIGNATURE_OE UINT32_C(0xfefaedfe)
|
---|
250 | #endif
|
---|
251 | #define MH_MAGIC_64 IMAGE_MACHO64_SIGNATURE
|
---|
252 | #define MH_CIGAM_64 IMAGE_MACHO64_SIGNATURE_OE
|
---|
253 |
|
---|
254 | /* mach_header_* filetype */
|
---|
255 | #define MH_OBJECT UINT32_C(1)
|
---|
256 | #define MH_EXECUTE UINT32_C(2)
|
---|
257 | #define MH_FVMLIB UINT32_C(3)
|
---|
258 | #define MH_CORE UINT32_C(4)
|
---|
259 | #define MH_PRELOAD UINT32_C(5)
|
---|
260 | #define MH_DYLIB UINT32_C(6)
|
---|
261 | #define MH_DYLINKER UINT32_C(7)
|
---|
262 | #define MH_BUNDLE UINT32_C(8)
|
---|
263 | #define MH_DYLIB_STUB UINT32_C(9)
|
---|
264 | #define MH_DSYM UINT32_C(10)
|
---|
265 | #define MH_KEXT_BUNDLE UINT32_C(11)
|
---|
266 |
|
---|
267 | /* mach_header_* flags */
|
---|
268 | #define MH_NOUNDEFS UINT32_C(0x00000001)
|
---|
269 | #define MH_INCRLINK UINT32_C(0x00000002)
|
---|
270 | #define MH_DYLDLINK UINT32_C(0x00000004)
|
---|
271 | #define MH_BINDATLOAD UINT32_C(0x00000008)
|
---|
272 | #define MH_PREBOUND UINT32_C(0x00000010)
|
---|
273 | #define MH_SPLIT_SEGS UINT32_C(0x00000020)
|
---|
274 | #define MH_LAZY_INIT UINT32_C(0x00000040)
|
---|
275 | #define MH_TWOLEVEL UINT32_C(0x00000080)
|
---|
276 | #define MH_FORCE_FLAT UINT32_C(0x00000100)
|
---|
277 | #define MH_NOMULTIDEFS UINT32_C(0x00000200)
|
---|
278 | #define MH_NOFIXPREBINDING UINT32_C(0x00000400)
|
---|
279 | #define MH_PREBINDABLE UINT32_C(0x00000800)
|
---|
280 | #define MH_ALLMODSBOUND UINT32_C(0x00001000)
|
---|
281 | #define MH_SUBSECTIONS_VIA_SYMBOLS UINT32_C(0x00002000)
|
---|
282 | #define MH_CANONICAL UINT32_C(0x00004000)
|
---|
283 | #define MH_WEAK_DEFINES UINT32_C(0x00008000)
|
---|
284 | #define MH_BINDS_TO_WEAK UINT32_C(0x00010000)
|
---|
285 | #define MH_ALLOW_STACK_EXECUTION UINT32_C(0x00020000)
|
---|
286 | #define MH_ROOT_SAFE UINT32_C(0x00040000)
|
---|
287 | #define MH_SETUID_SAFE UINT32_C(0x00080000)
|
---|
288 | #define MH_NO_REEXPORTED_DYLIBS UINT32_C(0x00100000)
|
---|
289 | #define MH_PIE UINT32_C(0x00200000)
|
---|
290 | #define MH_DEAD_STRIPPABLE_DYLIB UINT32_C(0x00400000)
|
---|
291 | #define MH_HAS_TLV_DESCRIPTORS UINT32_C(0x00800000)
|
---|
292 | #define MH_NO_HEAP_EXECUTION UINT32_C(0x01000000)
|
---|
293 | #define MH_UNKNOWN UINT32_C(0x80000000)
|
---|
294 | #define MH_VALID_FLAGS UINT32_C(0x81ffffff)
|
---|
295 |
|
---|
296 |
|
---|
297 | typedef struct load_command
|
---|
298 | {
|
---|
299 | uint32_t cmd;
|
---|
300 | uint32_t cmdsize;
|
---|
301 | } load_command_t;
|
---|
302 |
|
---|
303 | /* load cmd */
|
---|
304 | #define LC_REQ_DYLD UINT32_C(0x80000000)
|
---|
305 | #define LC_SEGMENT_32 UINT32_C(0x01)
|
---|
306 | #define LC_SYMTAB UINT32_C(0x02)
|
---|
307 | #define LC_SYMSEG UINT32_C(0x03)
|
---|
308 | #define LC_THREAD UINT32_C(0x04)
|
---|
309 | #define LC_UNIXTHREAD UINT32_C(0x05)
|
---|
310 | #define LC_LOADFVMLIB UINT32_C(0x06)
|
---|
311 | #define LC_IDFVMLIB UINT32_C(0x07)
|
---|
312 | #define LC_IDENT UINT32_C(0x08)
|
---|
313 | #define LC_FVMFILE UINT32_C(0x09)
|
---|
314 | #define LC_PREPAGE UINT32_C(0x0a)
|
---|
315 | #define LC_DYSYMTAB UINT32_C(0x0b)
|
---|
316 | #define LC_LOAD_DYLIB UINT32_C(0x0c)
|
---|
317 | #define LC_ID_DYLIB UINT32_C(0x0d)
|
---|
318 | #define LC_LOAD_DYLINKER UINT32_C(0x0e)
|
---|
319 | #define LC_ID_DYLINKER UINT32_C(0x0f)
|
---|
320 | #define LC_PREBOUND_DYLIB UINT32_C(0x10)
|
---|
321 | #define LC_ROUTINES UINT32_C(0x11)
|
---|
322 | #define LC_SUB_FRAMEWORK UINT32_C(0x12)
|
---|
323 | #define LC_SUB_UMBRELLA UINT32_C(0x13)
|
---|
324 | #define LC_SUB_CLIENT UINT32_C(0x14)
|
---|
325 | #define LC_SUB_LIBRARY UINT32_C(0x15)
|
---|
326 | #define LC_TWOLEVEL_HINTS UINT32_C(0x16)
|
---|
327 | #define LC_PREBIND_CKSUM UINT32_C(0x17)
|
---|
328 | #define LC_LOAD_WEAK_DYLIB (UINT32_C(0x18) | LC_REQ_DYLD)
|
---|
329 | #define LC_SEGMENT_64 UINT32_C(0x19)
|
---|
330 | #define LC_ROUTINES_64 UINT32_C(0x1a)
|
---|
331 | #define LC_UUID UINT32_C(0x1b)
|
---|
332 | #define LC_RPATH (UINT32_C(0x1c) | LC_REQ_DYLD)
|
---|
333 | #define LC_CODE_SIGNATURE UINT32_C(0x1d)
|
---|
334 | #define LC_SEGMENT_SPLIT_INFO UINT32_C(0x1e)
|
---|
335 | #define LC_REEXPORT_DYLIB (UINT32_C(0x1f) | LC_REQ_DYLD)
|
---|
336 | #define LC_LAZY_LOAD_DYLIB UINT32_C(0x20)
|
---|
337 | #define LC_ENCRYPTION_INFO UINT32_C(0x21)
|
---|
338 | #define LC_DYLD_INFO UINT32_C(0x22)
|
---|
339 | #define LC_DYLD_INFO_ONLY (UINT32_C(0x22) | LC_REQ_DYLD)
|
---|
340 | #define LC_LOAD_UPWARD_DYLIB (UINT32_C(0x23) | LC_REQ_DYLD)
|
---|
341 | #define LC_VERSION_MIN_MACOSX UINT32_C(0x24)
|
---|
342 | #define LC_VERSION_MIN_IPHONEOS UINT32_C(0x25)
|
---|
343 | #define LC_FUNCTION_STARTS UINT32_C(0x26)
|
---|
344 | #define LC_DYLD_ENVIRONMENT UINT32_C(0x27)
|
---|
345 | #define LC_MAIN (UINT32_C(0x28) | LC_REQ_DYLD)
|
---|
346 | #define LC_DATA_IN_CODE UINT32_C(0x29)
|
---|
347 | #define LC_SOURCE_VERSION UINT32_C(0x2a) /**< source_version_command */
|
---|
348 | #define LC_DYLIB_CODE_SIGN_DRS UINT32_C(0x2b)
|
---|
349 | #define LC_ENCRYPTION_INFO_64 UINT32_C(0x2c)
|
---|
350 | #define LC_LINKER_OPTION UINT32_C(0x2d)
|
---|
351 | #define LC_LINKER_OPTIMIZATION_HINT UINT32_C(0x2e)
|
---|
352 | #define LC_VERSION_MIN_TVOS UINT32_C(0x2f)
|
---|
353 | #define LC_VERSION_MIN_WATCHOS UINT32_C(0x30)
|
---|
354 | #define LC_NOTE UINT32_C(0x31)
|
---|
355 | #define LC_BUILD_VERSION UINT32_C(0x32)
|
---|
356 |
|
---|
357 |
|
---|
358 | typedef struct lc_str
|
---|
359 | {
|
---|
360 | uint32_t offset;
|
---|
361 | } lc_str_t;
|
---|
362 |
|
---|
363 | typedef struct segment_command_32
|
---|
364 | {
|
---|
365 | uint32_t cmd;
|
---|
366 | uint32_t cmdsize;
|
---|
367 | char segname[16];
|
---|
368 | uint32_t vmaddr;
|
---|
369 | uint32_t vmsize;
|
---|
370 | uint32_t fileoff;
|
---|
371 | uint32_t filesize;
|
---|
372 | uint32_t maxprot;
|
---|
373 | uint32_t initprot;
|
---|
374 | uint32_t nsects;
|
---|
375 | uint32_t flags;
|
---|
376 | } segment_command_32_t;
|
---|
377 |
|
---|
378 | typedef struct segment_command_64
|
---|
379 | {
|
---|
380 | uint32_t cmd;
|
---|
381 | uint32_t cmdsize;
|
---|
382 | char segname[16];
|
---|
383 | uint64_t vmaddr;
|
---|
384 | uint64_t vmsize;
|
---|
385 | uint64_t fileoff;
|
---|
386 | uint64_t filesize;
|
---|
387 | uint32_t maxprot;
|
---|
388 | uint32_t initprot;
|
---|
389 | uint32_t nsects;
|
---|
390 | uint32_t flags;
|
---|
391 | } segment_command_64_t;
|
---|
392 |
|
---|
393 | /* segment flags */
|
---|
394 | #define SG_HIGHVM UINT32_C(0x00000001)
|
---|
395 | #define SG_FVMLIB UINT32_C(0x00000002)
|
---|
396 | #define SG_NORELOC UINT32_C(0x00000004)
|
---|
397 | #define SG_PROTECTED_VERSION_1 UINT32_C(0x00000008)
|
---|
398 | #define SG_READ_ONLY UINT32_C(0x00000010) /**< Make it read-only after applying fixups. @since 10.14 */
|
---|
399 |
|
---|
400 | /* maxprot/initprot */
|
---|
401 | #ifndef VM_PROT_NONE
|
---|
402 | # define VM_PROT_NONE UINT32_C(0x00000000)
|
---|
403 | # define VM_PROT_READ UINT32_C(0x00000001)
|
---|
404 | # define VM_PROT_WRITE UINT32_C(0x00000002)
|
---|
405 | # define VM_PROT_EXECUTE UINT32_C(0x00000004)
|
---|
406 | # define VM_PROT_ALL UINT32_C(0x00000007)
|
---|
407 | #endif
|
---|
408 |
|
---|
409 | typedef struct section_32
|
---|
410 | {
|
---|
411 | char sectname[16];
|
---|
412 | char segname[16];
|
---|
413 | uint32_t addr;
|
---|
414 | uint32_t size;
|
---|
415 | uint32_t offset;
|
---|
416 | uint32_t align;
|
---|
417 | uint32_t reloff;
|
---|
418 | uint32_t nreloc;
|
---|
419 | uint32_t flags;
|
---|
420 | /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
|
---|
421 | * this is the index into the indirect symbol table. */
|
---|
422 | uint32_t reserved1;
|
---|
423 | /** For S_SYMBOL_STUBS this is the entry size. */
|
---|
424 | uint32_t reserved2;
|
---|
425 | } section_32_t;
|
---|
426 |
|
---|
427 | typedef struct section_64
|
---|
428 | {
|
---|
429 | char sectname[16];
|
---|
430 | char segname[16];
|
---|
431 | uint64_t addr;
|
---|
432 | uint64_t size;
|
---|
433 | uint32_t offset;
|
---|
434 | uint32_t align;
|
---|
435 | uint32_t reloff;
|
---|
436 | uint32_t nreloc;
|
---|
437 | uint32_t flags;
|
---|
438 | /** For S_LAZY_SYMBOL_POINTERS, S_NON_LAZY_SYMBOL_POINTERS and S_SYMBOL_STUBS
|
---|
439 | * this is the index into the indirect symbol table. */
|
---|
440 | uint32_t reserved1;
|
---|
441 | uint32_t reserved2;
|
---|
442 | uint32_t reserved3;
|
---|
443 | } section_64_t;
|
---|
444 |
|
---|
445 | /* section flags */
|
---|
446 | #define SECTION_TYPE UINT32_C(0xff)
|
---|
447 | #define S_REGULAR UINT32_C(0x00)
|
---|
448 | #define S_ZEROFILL UINT32_C(0x01)
|
---|
449 | #define S_CSTRING_LITERALS UINT32_C(0x02)
|
---|
450 | #define S_4BYTE_LITERALS UINT32_C(0x03)
|
---|
451 | #define S_8BYTE_LITERALS UINT32_C(0x04)
|
---|
452 | #define S_LITERAL_POINTERS UINT32_C(0x05)
|
---|
453 | #define S_NON_LAZY_SYMBOL_POINTERS UINT32_C(0x06)
|
---|
454 | #define S_LAZY_SYMBOL_POINTERS UINT32_C(0x07)
|
---|
455 | #define S_SYMBOL_STUBS UINT32_C(0x08)
|
---|
456 | #define S_MOD_INIT_FUNC_POINTERS UINT32_C(0x09)
|
---|
457 | #define S_MOD_TERM_FUNC_POINTERS UINT32_C(0x0a)
|
---|
458 | #define S_COALESCED UINT32_C(0x0b)
|
---|
459 | #define S_GB_ZEROFILL UINT32_C(0x0c)
|
---|
460 | #define S_INTERPOSING UINT32_C(0x0d)
|
---|
461 | #define S_16BYTE_LITERALS UINT32_C(0x0e)
|
---|
462 | #define S_DTRACE_DOF UINT32_C(0x0f)
|
---|
463 | #define S_LAZY_DYLIB_SYMBOL_POINTERS UINT32_C(0x10)
|
---|
464 | #define S_THREAD_LOCAL_REGULAR UINT32_C(0x11)
|
---|
465 | #define S_THREAD_LOCAL_ZEROFILL UINT32_C(0x12)
|
---|
466 | #define S_THREAD_LOCAL_VARIABLES UINT32_C(0x13)
|
---|
467 | #define S_THREAD_LOCAL_VARIABLE_POINTERS UINT32_C(0x14)
|
---|
468 | #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS UINT32_C(0x15)
|
---|
469 |
|
---|
470 |
|
---|
471 |
|
---|
472 |
|
---|
473 | #define SECTION_ATTRIBUTES UINT32_C(0xffffff00)
|
---|
474 | #define SECTION_ATTRIBUTES_USR UINT32_C(0xff000000)
|
---|
475 | #define S_ATTR_PURE_INSTRUCTIONS UINT32_C(0x80000000)
|
---|
476 | #define S_ATTR_NO_TOC UINT32_C(0x40000000)
|
---|
477 | #define S_ATTR_STRIP_STATIC_SYMS UINT32_C(0x20000000)
|
---|
478 | #define S_ATTR_NO_DEAD_STRIP UINT32_C(0x10000000)
|
---|
479 | #define S_ATTR_LIVE_SUPPORT UINT32_C(0x08000000)
|
---|
480 | #define S_ATTR_SELF_MODIFYING_CODE UINT32_C(0x04000000)
|
---|
481 | #define S_ATTR_DEBUG UINT32_C(0x02000000)
|
---|
482 | #define SECTION_ATTRIBUTES_SYS UINT32_C(0x00ffff00)
|
---|
483 | #define S_ATTR_SOME_INSTRUCTIONS UINT32_C(0x00000400)
|
---|
484 | #define S_ATTR_EXT_RELOC UINT32_C(0x00000200)
|
---|
485 | #define S_ATTR_LOC_RELOC UINT32_C(0x00000100)
|
---|
486 |
|
---|
487 | /* standard section names */
|
---|
488 | #define SEG_PAGEZERO "__PAGEZERO"
|
---|
489 | #define SEG_TEXT "__TEXT"
|
---|
490 | #define SECT_TEXT "__text"
|
---|
491 | #define SECT_FVMLIB_INIT0 "__fvmlib_init0"
|
---|
492 | #define SECT_FVMLIB_INIT1 "__fvmlib_init1"
|
---|
493 | #define SEG_DATA "__DATA"
|
---|
494 | #define SECT_DATA "__data"
|
---|
495 | #define SECT_BSS "__bss"
|
---|
496 | #define SECT_COMMON "__common"
|
---|
497 | #define SEG_OBJC "__OBJC"
|
---|
498 | #define SECT_OBJC_SYMBOLS "__symbol_table"
|
---|
499 | #define SECT_OBJC_MODULES "__module_info"
|
---|
500 | #define SECT_OBJC_STRINGS "__selector_strs"
|
---|
501 | #define SECT_OBJC_REFS "__selector_refs"
|
---|
502 | #define SEG_ICON "__ICON"
|
---|
503 | #define SECT_ICON_HEADER "__header"
|
---|
504 | #define SECT_ICON_TIFF "__tiff"
|
---|
505 | #define SEG_LINKEDIT "__LINKEDIT"
|
---|
506 | #define SEG_UNIXSTACK "__UNIXSTACK"
|
---|
507 | #define SEG_IMPORT "__IMPORT"
|
---|
508 |
|
---|
509 | typedef struct thread_command
|
---|
510 | {
|
---|
511 | uint32_t cmd;
|
---|
512 | uint32_t cmdsize;
|
---|
513 | } thread_command_t;
|
---|
514 |
|
---|
515 | typedef struct symtab_command
|
---|
516 | {
|
---|
517 | uint32_t cmd;
|
---|
518 | uint32_t cmdsize;
|
---|
519 | uint32_t symoff;
|
---|
520 | uint32_t nsyms;
|
---|
521 | uint32_t stroff;
|
---|
522 | uint32_t strsize;
|
---|
523 | } symtab_command_t;
|
---|
524 |
|
---|
525 | typedef struct dysymtab_command
|
---|
526 | {
|
---|
527 | uint32_t cmd;
|
---|
528 | uint32_t cmdsize;
|
---|
529 | /** @name Symbol groupings.
|
---|
530 | * @{ */
|
---|
531 | uint32_t ilocalsym; /**< Index into the symbol table of the first local symbol. */
|
---|
532 | uint32_t nlocalsym; /**< Number of local symbols. */
|
---|
533 | uint32_t iextdefsym; /**< Index into the symbol table of the first externally defined symbol. */
|
---|
534 | uint32_t nextdefsym; /**< Number of externally defined symbols. */
|
---|
535 | uint32_t iundefsym; /**< Index into the symbol table of the first undefined symbol. */
|
---|
536 | uint32_t nundefsym; /**< Number of undefined symbols. */
|
---|
537 | /** @} */
|
---|
538 | uint32_t tocoff; /**< Table of content file offset. (usually empty) */
|
---|
539 | uint32_t ntoc; /**< Number of entries in TOC. */
|
---|
540 | uint32_t modtaboff; /** The module table file offset. (usually empty) */
|
---|
541 | uint32_t nmodtab; /**< Number of entries in the module table. */
|
---|
542 | /** @name Dynamic symbol tables.
|
---|
543 | * @{ */
|
---|
544 | uint32_t extrefsymoff; /**< Externally referenceable symbol table file offset. @sa dylib_reference_t */
|
---|
545 | uint32_t nextrefsym; /**< Number externally referenceable symbols. */
|
---|
546 | uint32_t indirectsymboff; /**< Indirect symbol table (32-bit symtab indexes) for thunks and offset tables. */
|
---|
547 | uint32_t nindirectsymb; /**< Number of indirect symbol table entries. */
|
---|
548 | /** @} */
|
---|
549 | /** @name Relocations.
|
---|
550 | * @{ */
|
---|
551 | uint32_t extreloff; /**< External relocations (r_address is relative to first segment (i.e. RVA)). */
|
---|
552 | uint32_t nextrel; /**< Number of external relocations. */
|
---|
553 | uint32_t locreloff; /**< Local relocations (r_address is relative to first segment (i.e. RVA)). */
|
---|
554 | uint32_t nlocrel; /**< Number of local relocations. */
|
---|
555 | /** @} */
|
---|
556 | } dysymtab_command_t;
|
---|
557 | AssertCompileSize(dysymtab_command_t, 80);
|
---|
558 |
|
---|
559 | /** Special indirect symbol table entry value, stripped local symbol. */
|
---|
560 | #define INDIRECT_SYMBOL_LOCAL UINT32_C(0x80000000)
|
---|
561 | /** Special indirect symbol table entry value, stripped absolute symbol. */
|
---|
562 | #define INDIRECT_SYMBOL_ABS UINT32_C(0x40000000)
|
---|
563 |
|
---|
564 | typedef struct dylib_reference
|
---|
565 | {
|
---|
566 | uint32_t isym : 24; /**< Symbol table index. */
|
---|
567 | uint32_t flags : 8; /**< REFERENCE_FLAG_XXX? */
|
---|
568 | } dylib_reference_t;
|
---|
569 | AssertCompileSize(dylib_reference_t, 4);
|
---|
570 |
|
---|
571 |
|
---|
572 | typedef struct dylib_table_of_contents
|
---|
573 | {
|
---|
574 | uint32_t symbol_index; /**< External symbol table entry. */
|
---|
575 | uint32_t module_index; /**< The module table index of the module defining it. */
|
---|
576 | } dylib_table_of_contents_t;
|
---|
577 | AssertCompileSize(dylib_table_of_contents_t, 8);
|
---|
578 |
|
---|
579 |
|
---|
580 | /** 32-bit module table entry. */
|
---|
581 | typedef struct dylib_module
|
---|
582 | {
|
---|
583 | uint32_t module_name;
|
---|
584 | uint32_t iextdefsym;
|
---|
585 | uint32_t nextdefsym;
|
---|
586 | uint32_t irefsym;
|
---|
587 | uint32_t nrefsym;
|
---|
588 | uint32_t ilocalsym;
|
---|
589 | uint32_t nlocalsym;
|
---|
590 | uint32_t iextrel;
|
---|
591 | uint32_t nextrel;
|
---|
592 | uint32_t iinit_iterm;
|
---|
593 | uint32_t ninit_nterm;
|
---|
594 | uint32_t objc_module_info_addr;
|
---|
595 | uint32_t objc_module_info_size;
|
---|
596 | } dylib_module_32_t;
|
---|
597 | AssertCompileSize(dylib_module_32_t, 13*4);
|
---|
598 |
|
---|
599 | /* a 64-bit module table entry */
|
---|
600 | typedef struct dylib_module_64
|
---|
601 | {
|
---|
602 | uint32_t module_name;
|
---|
603 | uint32_t iextdefsym;
|
---|
604 | uint32_t nextdefsym;
|
---|
605 | uint32_t irefsym;
|
---|
606 | uint32_t nrefsym;
|
---|
607 | uint32_t ilocalsym;
|
---|
608 | uint32_t nlocalsym;
|
---|
609 | uint32_t iextrel;
|
---|
610 | uint32_t nextrel;
|
---|
611 | uint32_t iinit_iterm;
|
---|
612 | uint32_t ninit_nterm;
|
---|
613 | uint32_t objc_module_info_size;
|
---|
614 | uint64_t objc_module_info_addr;
|
---|
615 | } dylib_module_64_t;
|
---|
616 | AssertCompileSize(dylib_module_64_t, 12*4+8);
|
---|
617 |
|
---|
618 | typedef struct uuid_command
|
---|
619 | {
|
---|
620 | uint32_t cmd;
|
---|
621 | uint32_t cmdsize;
|
---|
622 | uint8_t uuid[16];
|
---|
623 | } uuid_command_t;
|
---|
624 | AssertCompileSize(uuid_command_t, 24);
|
---|
625 |
|
---|
626 | typedef struct linkedit_data_command
|
---|
627 | {
|
---|
628 | uint32_t cmd; /**< LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS */
|
---|
629 | uint32_t cmdsize; /**< Size of this structure (16). */
|
---|
630 | uint32_t dataoff; /**< Offset into the file of the data. */
|
---|
631 | uint32_t datasize; /**< The size of the data. */
|
---|
632 | } linkedit_data_command_t;
|
---|
633 | AssertCompileSize(linkedit_data_command_t, 16);
|
---|
634 |
|
---|
635 | typedef struct version_min_command
|
---|
636 | {
|
---|
637 | uint32_t cmd; /**< LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_TVOS, LC_VERSION_MIN_WATCHOS */
|
---|
638 | uint32_t cmdsize; /**< Size of this structure (16). */
|
---|
639 | uint32_t version; /**< 31..16=major, 15..8=minor, 7..0=patch. */
|
---|
640 | uint32_t reserved; /**< MBZ. */
|
---|
641 | } version_min_command_t;
|
---|
642 | AssertCompileSize(version_min_command_t, 16);
|
---|
643 |
|
---|
644 | typedef struct build_tool_version
|
---|
645 | {
|
---|
646 | uint32_t tool; /**< TOOL_XXX */
|
---|
647 | uint32_t version; /**< 31..16=major, 15..8=minor, 7..0=patch. */
|
---|
648 | } build_tool_version_t;
|
---|
649 | AssertCompileSize(build_tool_version_t, 8);
|
---|
650 |
|
---|
651 | /** @name TOOL_XXX - Values for build_tool_version::tool
|
---|
652 | * @{ */
|
---|
653 | #define TOOL_CLANG 1
|
---|
654 | #define TOOL_SWIFT 2
|
---|
655 | #define TOOL_LD 3
|
---|
656 | /** @} */
|
---|
657 |
|
---|
658 | typedef struct build_version_command
|
---|
659 | {
|
---|
660 | uint32_t cmd; /**< LC_BUILD_VERSION */
|
---|
661 | uint32_t cmdsize; /**< Size of this structure (at least 24). */
|
---|
662 | uint32_t platform; /**< PLATFORM_XXX */
|
---|
663 | uint32_t minos; /**< Minimum OS version: 31..16=major, 15..8=minor, 7..0=patch */
|
---|
664 | uint32_t sdk; /**< SDK version: 31..16=major, 15..8=minor, 7..0=patch */
|
---|
665 | uint32_t ntools; /**< Number of build_tool_version entries following in aTools. */
|
---|
666 | RT_FLEXIBLE_ARRAY_EXTENSION
|
---|
667 | build_tool_version_t aTools[RT_FLEXIBLE_ARRAY];
|
---|
668 | } build_version_command_t;
|
---|
669 | AssertCompileMemberOffset(build_version_command_t, aTools, 24);
|
---|
670 |
|
---|
671 | /** @name PLATFORM_XXX - Values for build_version_command::platform
|
---|
672 | * @{ */
|
---|
673 | #define PLATFORM_MACOS 1
|
---|
674 | #define PLATFORM_IOS 2
|
---|
675 | #define PLATFORM_TVOS 3
|
---|
676 | #define PLATFORM_WATCHOS 4
|
---|
677 | /** @} */
|
---|
678 |
|
---|
679 | typedef struct source_version_command
|
---|
680 | {
|
---|
681 | uint32_t cmd; /**< LC_SOURCE_VERSION */
|
---|
682 | uint32_t cmdsize; /**< Size of this structure (16). */
|
---|
683 | uint64_t version; /**< A.B.C.D.E, where A is 24 bits wide and the rest 10 bits each. */
|
---|
684 | } source_version_command_t;
|
---|
685 | AssertCompileSize(source_version_command_t, 16);
|
---|
686 |
|
---|
687 |
|
---|
688 | typedef struct macho_nlist_32
|
---|
689 | {
|
---|
690 | union
|
---|
691 | {
|
---|
692 | int32_t n_strx;
|
---|
693 | } n_un;
|
---|
694 | uint8_t n_type;
|
---|
695 | uint8_t n_sect;
|
---|
696 | int16_t n_desc;
|
---|
697 | uint32_t n_value;
|
---|
698 | } macho_nlist_32_t;
|
---|
699 |
|
---|
700 |
|
---|
701 | typedef struct macho_nlist_64
|
---|
702 | {
|
---|
703 | union
|
---|
704 | {
|
---|
705 | uint32_t n_strx;
|
---|
706 | } n_un;
|
---|
707 | uint8_t n_type;
|
---|
708 | uint8_t n_sect;
|
---|
709 | int16_t n_desc;
|
---|
710 | uint64_t n_value;
|
---|
711 | } macho_nlist_64_t;
|
---|
712 |
|
---|
713 | #define MACHO_N_EXT UINT8_C(0x01)
|
---|
714 | #define MACHO_N_PEXT UINT8_C(0x10)
|
---|
715 |
|
---|
716 | #define MACHO_N_TYPE UINT8_C(0x0e)
|
---|
717 | #define MACHO_N_UNDF UINT8_C(0x00)
|
---|
718 | #define MACHO_N_ABS UINT8_C(0x02)
|
---|
719 | #define MACHO_N_INDR UINT8_C(0x0a)
|
---|
720 | #define MACHO_N_PBUD UINT8_C(0x0c)
|
---|
721 | #define MACHO_N_SECT UINT8_C(0x0e)
|
---|
722 |
|
---|
723 | #define MACHO_N_STAB UINT8_C(0xe0)
|
---|
724 | #define MACHO_N_GSYM UINT8_C(0x20)
|
---|
725 | #define MACHO_N_FNAME UINT8_C(0x22)
|
---|
726 | #define MACHO_N_FUN UINT8_C(0x24)
|
---|
727 | #define MACHO_N_STSYM UINT8_C(0x26)
|
---|
728 | #define MACHO_N_LCSYM UINT8_C(0x28)
|
---|
729 | #define MACHO_N_BNSYM UINT8_C(0x2e)
|
---|
730 | #define MACHO_N_PC UINT8_C(0x30)
|
---|
731 | #define MACHO_N_OPT UINT8_C(0x3c)
|
---|
732 | #define MACHO_N_RSYM UINT8_C(0x40)
|
---|
733 | #define MACHO_N_SLINE UINT8_C(0x44)
|
---|
734 | #define MACHO_N_ENSYM UINT8_C(0x4e)
|
---|
735 | #define MACHO_N_SSYM UINT8_C(0x60)
|
---|
736 | #define MACHO_N_SO UINT8_C(0x64)
|
---|
737 | #define MACHO_N_OSO UINT8_C(0x66)
|
---|
738 | #define MACHO_N_LSYM UINT8_C(0x80)
|
---|
739 | #define MACHO_N_BINCL UINT8_C(0x82)
|
---|
740 | #define MACHO_N_SOL UINT8_C(0x84)
|
---|
741 | #define MACHO_N_PARAMS UINT8_C(0x86)
|
---|
742 | #define MACHO_N_VERSION UINT8_C(0x88)
|
---|
743 | #define MACHO_N_OLEVEL UINT8_C(0x8A)
|
---|
744 | #define MACHO_N_PSYM UINT8_C(0xa0)
|
---|
745 | #define MACHO_N_EINCL UINT8_C(0xa2)
|
---|
746 | #define MACHO_N_ENTRY UINT8_C(0xa4)
|
---|
747 | #define MACHO_N_LBRAC UINT8_C(0xc0)
|
---|
748 | #define MACHO_N_EXCL UINT8_C(0xc2)
|
---|
749 | #define MACHO_N_RBRAC UINT8_C(0xe0)
|
---|
750 | #define MACHO_N_BCOMM UINT8_C(0xe2)
|
---|
751 | #define MACHO_N_ECOMM UINT8_C(0xe4)
|
---|
752 | #define MACHO_N_ECOML UINT8_C(0xe8)
|
---|
753 | #define MACHO_N_LENG UINT8_C(0xfe)
|
---|
754 |
|
---|
755 | #define MACHO_NO_SECT UINT8_C(0x00)
|
---|
756 | #define MACHO_MAX_SECT UINT8_C(0xff)
|
---|
757 |
|
---|
758 | #define REFERENCE_TYPE UINT16_C(0x000f)
|
---|
759 | #define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
|
---|
760 | #define REFERENCE_FLAG_UNDEFINED_LAZY 1
|
---|
761 | #define REFERENCE_FLAG_DEFINED 2
|
---|
762 | #define REFERENCE_FLAG_PRIVATE_DEFINED 3
|
---|
763 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
|
---|
764 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
|
---|
765 | #define REFERENCED_DYNAMICALLY UINT16_C(0x0010)
|
---|
766 |
|
---|
767 | #define GET_LIBRARY_ORDINAL(a_n_desc) \
|
---|
768 | RT_BYTE2(a_n_desc)
|
---|
769 | #define SET_LIBRARY_ORDINAL(a_n_desc, a_ordinal) \
|
---|
770 | do { (a_n_desc) = RT_MAKE_U16(RT_BYTE1(a_n_desc), a_ordinal); } while (0)
|
---|
771 |
|
---|
772 | #define SELF_LIBRARY_ORDINAL 0x00
|
---|
773 | #define MAX_LIBRARY_ORDINAL 0xfd
|
---|
774 | #define DYNAMIC_LOOKUP_ORDINAL 0xfe
|
---|
775 | #define EXECUTABLE_ORDINAL 0xff
|
---|
776 |
|
---|
777 | #define N_NO_DEAD_STRIP UINT16_C(0x0020)
|
---|
778 | #define N_DESC_DISCARDED UINT16_C(0x0020)
|
---|
779 | #define N_WEAK_REF UINT16_C(0x0040)
|
---|
780 | #define N_WEAK_DEF UINT16_C(0x0080)
|
---|
781 | #define N_REF_TO_WEAK UINT16_C(0x0080)
|
---|
782 | #define N_SYMBOL_RESOLVER UINT16_C(0x0100)
|
---|
783 | #define N_ALT_ENTRY UINT16_C(0x0200)
|
---|
784 |
|
---|
785 | typedef struct macho_relocation_info
|
---|
786 | {
|
---|
787 | int32_t r_address;
|
---|
788 | uint32_t r_symbolnum : 24;
|
---|
789 | uint32_t r_pcrel : 1;
|
---|
790 | uint32_t r_length : 2;
|
---|
791 | uint32_t r_extern : 1;
|
---|
792 | uint32_t r_type : 4;
|
---|
793 | } macho_relocation_info_t;
|
---|
794 | AssertCompileSize(macho_relocation_info_t, 8);
|
---|
795 |
|
---|
796 | #define R_ABS 0
|
---|
797 | #define R_SCATTERED UINT32_C(0x80000000)
|
---|
798 |
|
---|
799 | typedef struct scattered_relocation_info
|
---|
800 | {
|
---|
801 | #ifdef RT_LITTLE_ENDIAN
|
---|
802 | uint32_t r_address : 24;
|
---|
803 | uint32_t r_type : 4;
|
---|
804 | uint32_t r_length : 2;
|
---|
805 | uint32_t r_pcrel : 1;
|
---|
806 | uint32_t r_scattered : 1;
|
---|
807 | #elif defined(RT_BIG_ENDIAN)
|
---|
808 | uint32_t r_scattered : 1;
|
---|
809 | uint32_t r_pcrel : 1;
|
---|
810 | uint32_t r_length : 2;
|
---|
811 | uint32_t r_type : 4;
|
---|
812 | uint32_t r_address : 24;
|
---|
813 | #else
|
---|
814 | # error "Neither K_ENDIAN isn't LITTLE or BIG!"
|
---|
815 | #endif
|
---|
816 | int32_t r_value;
|
---|
817 | } scattered_relocation_info_t;
|
---|
818 | AssertCompileSize(scattered_relocation_info_t, 8);
|
---|
819 |
|
---|
820 | typedef union
|
---|
821 | {
|
---|
822 | macho_relocation_info_t r;
|
---|
823 | scattered_relocation_info_t s;
|
---|
824 | } macho_relocation_union_t;
|
---|
825 | AssertCompileSize(macho_relocation_union_t, 8);
|
---|
826 |
|
---|
827 | typedef enum reloc_type_generic
|
---|
828 | {
|
---|
829 | GENERIC_RELOC_VANILLA = 0,
|
---|
830 | GENERIC_RELOC_PAIR,
|
---|
831 | GENERIC_RELOC_SECTDIFF,
|
---|
832 | GENERIC_RELOC_PB_LA_PTR,
|
---|
833 | GENERIC_RELOC_LOCAL_SECTDIFF
|
---|
834 | } reloc_type_generic_t;
|
---|
835 |
|
---|
836 | typedef enum reloc_type_x86_64
|
---|
837 | {
|
---|
838 | X86_64_RELOC_UNSIGNED = 0,
|
---|
839 | X86_64_RELOC_SIGNED,
|
---|
840 | X86_64_RELOC_BRANCH,
|
---|
841 | X86_64_RELOC_GOT_LOAD,
|
---|
842 | X86_64_RELOC_GOT,
|
---|
843 | X86_64_RELOC_SUBTRACTOR,
|
---|
844 | X86_64_RELOC_SIGNED_1,
|
---|
845 | X86_64_RELOC_SIGNED_2,
|
---|
846 | X86_64_RELOC_SIGNED_4
|
---|
847 | } reloc_type_x86_64_t;
|
---|
848 |
|
---|
849 | #endif /* !IPRT_INCLUDED_formats_mach_o_h */
|
---|
850 |
|
---|