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