1 | /* $Id: mach-o.h 69105 2017-10-17 10:20:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Mach-O Structures and Constants.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2017 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 ___internal_ldrMach_O_h
|
---|
28 | #define ___internal_ldrMach_O_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 | #ifndef CPU_ARCH_MASK
|
---|
33 |
|
---|
34 | /* cputype */
|
---|
35 | #define CPU_ARCH_MASK INT32_C(0xff000000)
|
---|
36 | #define CPU_ARCH_ABI64 INT32_C(0x01000000)
|
---|
37 | #define CPU_TYPE_ANY INT32_C(-1)
|
---|
38 | #define CPU_TYPE_VAX INT32_C(1)
|
---|
39 | #define CPU_TYPE_MC680x0 INT32_C(6)
|
---|
40 | #define CPU_TYPE_X86 INT32_C(7)
|
---|
41 | #define CPU_TYPE_I386 CPU_TYPE_X86
|
---|
42 | #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
|
---|
43 | #define CPU_TYPE_MC98000 INT32_C(10)
|
---|
44 | #define CPU_TYPE_HPPA INT32_C(11)
|
---|
45 | #define CPU_TYPE_MC88000 INT32_C(13)
|
---|
46 | #define CPU_TYPE_SPARC INT32_C(14)
|
---|
47 | #define CPU_TYPE_I860 INT32_C(15)
|
---|
48 | #define CPU_TYPE_POWERPC INT32_C(18)
|
---|
49 | #define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
|
---|
50 |
|
---|
51 | /* cpusubtype */
|
---|
52 | #define CPU_SUBTYPE_MULTIPLE INT32_C(-1)
|
---|
53 | #define CPU_SUBTYPE_LITTLE_ENDIAN INT32_C(0)
|
---|
54 | #define CPU_SUBTYPE_BIG_ENDIAN INT32_C(1)
|
---|
55 |
|
---|
56 | #define CPU_SUBTYPE_VAX_ALL INT32_C(0)
|
---|
57 | #define CPU_SUBTYPE_VAX780 INT32_C(1)
|
---|
58 | #define CPU_SUBTYPE_VAX785 INT32_C(2)
|
---|
59 | #define CPU_SUBTYPE_VAX750 INT32_C(3)
|
---|
60 | #define CPU_SUBTYPE_VAX730 INT32_C(4)
|
---|
61 | #define CPU_SUBTYPE_UVAXI INT32_C(5)
|
---|
62 | #define CPU_SUBTYPE_UVAXII INT32_C(6)
|
---|
63 | #define CPU_SUBTYPE_VAX8200 INT32_C(7)
|
---|
64 | #define CPU_SUBTYPE_VAX8500 INT32_C(8)
|
---|
65 | #define CPU_SUBTYPE_VAX8600 INT32_C(9)
|
---|
66 | #define CPU_SUBTYPE_VAX8650 INT32_C(10)
|
---|
67 | #define CPU_SUBTYPE_VAX8800 INT32_C(11)
|
---|
68 | #define CPU_SUBTYPE_UVAXIII INT32_C(12)
|
---|
69 |
|
---|
70 | #define CPU_SUBTYPE_MC680x0_ALL INT32_C(1)
|
---|
71 | #define CPU_SUBTYPE_MC68030 INT32_C(1)
|
---|
72 | #define CPU_SUBTYPE_MC68040 INT32_C(2)
|
---|
73 | #define CPU_SUBTYPE_MC68030_ONLY INT32_C(3)
|
---|
74 |
|
---|
75 | #define CPU_SUBTYPE_INTEL(fam, model) ( (int32_t )(((model) << 4) | (fam)) )
|
---|
76 | #define CPU_SUBTYPE_INTEL_FAMILY(subtype) ( (subtype) & 0xf )
|
---|
77 | #define CPU_SUBTYPE_INTEL_MODEL(subtype) ( (subtype) >> 4 )
|
---|
78 | #define CPU_SUBTYPE_INTEL_FAMILY_MAX 0xf
|
---|
79 | #define CPU_SUBTYPE_INTEL_MODEL_ALL 0
|
---|
80 |
|
---|
81 | #define CPU_SUBTYPE_I386_ALL CPU_SUBTYPE_INTEL(3, 0)
|
---|
82 | #define CPU_SUBTYPE_386 CPU_SUBTYPE_INTEL(3, 0)
|
---|
83 | #define CPU_SUBTYPE_486 CPU_SUBTYPE_INTEL(4, 0)
|
---|
84 | #define CPU_SUBTYPE_486SX CPU_SUBTYPE_INTEL(4, 8)
|
---|
85 | #define CPU_SUBTYPE_586 CPU_SUBTYPE_INTEL(5, 0)
|
---|
86 | #define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
|
---|
87 | #define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
|
---|
88 | #define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
|
---|
89 | #define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
|
---|
90 | #define CPU_SUBTYPE_CELERON CPU_SUBTYPE_INTEL(7, 6)
|
---|
91 | #define CPU_SUBTYPE_CELERON_MOBILE CPU_SUBTYPE_INTEL(7, 7)
|
---|
92 | #define CPU_SUBTYPE_PENTIUM_3 CPU_SUBTYPE_INTEL(8, 0)
|
---|
93 | #define CPU_SUBTYPE_PENTIUM_3_M CPU_SUBTYPE_INTEL(8, 1)
|
---|
94 | #define CPU_SUBTYPE_PENTIUM_3_XEON CPU_SUBTYPE_INTEL(8, 2)
|
---|
95 | #define CPU_SUBTYPE_PENTIUM_M CPU_SUBTYPE_INTEL(9, 0)
|
---|
96 | #define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
|
---|
97 | #define CPU_SUBTYPE_PENTIUM_4_M CPU_SUBTYPE_INTEL(10, 1)
|
---|
98 | #define CPU_SUBTYPE_ITANIUM CPU_SUBTYPE_INTEL(11, 0)
|
---|
99 | #define CPU_SUBTYPE_ITANIUM_2 CPU_SUBTYPE_INTEL(11, 1)
|
---|
100 | #define CPU_SUBTYPE_XEON CPU_SUBTYPE_INTEL(12, 0)
|
---|
101 | #define CPU_SUBTYPE_XEON_MP CPU_SUBTYPE_INTEL(12, 1)
|
---|
102 |
|
---|
103 | #define CPU_SUBTYPE_X86_ALL INT32_C(3)
|
---|
104 | #define CPU_SUBTYPE_X86_64_ALL INT32_C(3)
|
---|
105 | #define CPU_SUBTYPE_X86_ARCH1 INT32_C(4)
|
---|
106 |
|
---|
107 | #define CPU_SUBTYPE_MIPS_ALL INT32_C(0)
|
---|
108 | #define CPU_SUBTYPE_MIPS_R2300 INT32_C(1)
|
---|
109 | #define CPU_SUBTYPE_MIPS_R2600 INT32_C(2)
|
---|
110 | #define CPU_SUBTYPE_MIPS_R2800 INT32_C(3)
|
---|
111 | #define CPU_SUBTYPE_MIPS_R2000a INT32_C(4)
|
---|
112 | #define CPU_SUBTYPE_MIPS_R2000 INT32_C(5)
|
---|
113 | #define CPU_SUBTYPE_MIPS_R3000a INT32_C(6)
|
---|
114 | #define CPU_SUBTYPE_MIPS_R3000 INT32_C(7)
|
---|
115 |
|
---|
116 | #define CPU_SUBTYPE_MC98000_ALL INT32_C(0)
|
---|
117 | #define CPU_SUBTYPE_MC98601 INT32_C(1)
|
---|
118 |
|
---|
119 | #define CPU_SUBTYPE_HPPA_ALL INT32_C(0)
|
---|
120 | #define CPU_SUBTYPE_HPPA_7100 INT32_C(0)
|
---|
121 | #define CPU_SUBTYPE_HPPA_7100LC INT32_C(1)
|
---|
122 |
|
---|
123 | #define CPU_SUBTYPE_MC88000_ALL INT32_C(0)
|
---|
124 | #define CPU_SUBTYPE_MC88100 INT32_C(1)
|
---|
125 | #define CPU_SUBTYPE_MC88110 INT32_C(2)
|
---|
126 |
|
---|
127 | #define CPU_SUBTYPE_SPARC_ALL INT32_C(0)
|
---|
128 |
|
---|
129 | #define CPU_SUBTYPE_I860_ALL INT32_C(0)
|
---|
130 | #define CPU_SUBTYPE_I860_860 INT32_C(1)
|
---|
131 |
|
---|
132 | #define CPU_SUBTYPE_POWERPC_ALL INT32_C(0)
|
---|
133 | #define CPU_SUBTYPE_POWERPC_601 INT32_C(1)
|
---|
134 | #define CPU_SUBTYPE_POWERPC_602 INT32_C(2)
|
---|
135 | #define CPU_SUBTYPE_POWERPC_603 INT32_C(3)
|
---|
136 | #define CPU_SUBTYPE_POWERPC_603e INT32_C(4)
|
---|
137 | #define CPU_SUBTYPE_POWERPC_603ev INT32_C(5)
|
---|
138 | #define CPU_SUBTYPE_POWERPC_604 INT32_C(6)
|
---|
139 | #define CPU_SUBTYPE_POWERPC_604e INT32_C(7)
|
---|
140 | #define CPU_SUBTYPE_POWERPC_620 INT32_C(8)
|
---|
141 | #define CPU_SUBTYPE_POWERPC_750 INT32_C(9)
|
---|
142 | #define CPU_SUBTYPE_POWERPC_7400 INT32_C(10)
|
---|
143 | #define CPU_SUBTYPE_POWERPC_7450 INT32_C(11)
|
---|
144 | #define CPU_SUBTYPE_POWERPC_Max INT32_C(10)
|
---|
145 | #define CPU_SUBTYPE_POWERPC_SCVger INT32_C(11)
|
---|
146 | #define CPU_SUBTYPE_POWERPC_970 INT32_C(100)
|
---|
147 |
|
---|
148 | #define CPU_SUBTYPE_MASK UINT32_C(0xff000000)
|
---|
149 | #define CPU_SUBTYPE_LIB64 UINT32_C(0x80000000)
|
---|
150 |
|
---|
151 | #endif /* !CPU_ARCH_MASK */
|
---|
152 |
|
---|
153 |
|
---|
154 | typedef struct fat_header
|
---|
155 | {
|
---|
156 | uint32_t magic;
|
---|
157 | uint32_t nfat_arch;
|
---|
158 | } fat_header_t;
|
---|
159 |
|
---|
160 | #ifndef IMAGE_FAT_SIGNATURE
|
---|
161 | # define IMAGE_FAT_SIGNATURE UINT32_C(0xcafebabe)
|
---|
162 | #endif
|
---|
163 | #ifndef IMAGE_FAT_SIGNATURE_OE
|
---|
164 | # define IMAGE_FAT_SIGNATURE_OE UINT32_C(0xbebafeca)
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | typedef struct fat_arch
|
---|
168 | {
|
---|
169 | int32_t cputype;
|
---|
170 | int32_t cpusubtype;
|
---|
171 | uint32_t offset;
|
---|
172 | uint32_t size;
|
---|
173 | uint32_t align;
|
---|
174 | } fat_arch_t;
|
---|
175 |
|
---|
176 | typedef struct mach_header_32
|
---|
177 | {
|
---|
178 | uint32_t magic;
|
---|
179 | int32_t cputype;
|
---|
180 | int32_t cpusubtype;
|
---|
181 | uint32_t filetype;
|
---|
182 | uint32_t ncmds;
|
---|
183 | uint32_t sizeofcmds;
|
---|
184 | uint32_t flags;
|
---|
185 | } mach_header_32_t;
|
---|
186 |
|
---|
187 | /* magic */
|
---|
188 | #ifndef IMAGE_MACHO32_SIGNATURE
|
---|
189 | # define IMAGE_MACHO32_SIGNATURE UINT32_C(0xfeedface)
|
---|
190 | #endif
|
---|
191 | #ifndef IMAGE_MACHO32_SIGNATURE_OE
|
---|
192 | # define IMAGE_MACHO32_SIGNATURE_OE UINT32_C(0xcefaedfe)
|
---|
193 | #endif
|
---|
194 | #define MH_MAGIC IMAGE_MACHO32_SIGNATURE
|
---|
195 | #define MH_CIGAM IMAGE_MACHO32_SIGNATURE_OE
|
---|
196 |
|
---|
197 | typedef struct mach_header_64
|
---|
198 | {
|
---|
199 | uint32_t magic;
|
---|
200 | int32_t cputype;
|
---|
201 | int32_t cpusubtype;
|
---|
202 | uint32_t filetype;
|
---|
203 | uint32_t ncmds;
|
---|
204 | uint32_t sizeofcmds;
|
---|
205 | uint32_t flags;
|
---|
206 | uint32_t reserved;
|
---|
207 | } mach_header_64_t;
|
---|
208 |
|
---|
209 | /* magic */
|
---|
210 | #ifndef IMAGE_MACHO64_SIGNATURE
|
---|
211 | # define IMAGE_MACHO64_SIGNATURE UINT32_C(0xfeedfacf)
|
---|
212 | #endif
|
---|
213 | #ifndef IMAGE_MACHO64_SIGNATURE_OE
|
---|
214 | # define IMAGE_MACHO64_SIGNATURE_OE UINT32_C(0xfefaedfe)
|
---|
215 | #endif
|
---|
216 | #define MH_MAGIC_64 IMAGE_MACHO64_SIGNATURE
|
---|
217 | #define MH_CIGAM_64 IMAGE_MACHO64_SIGNATURE_OE
|
---|
218 |
|
---|
219 | /* mach_header_* filetype */
|
---|
220 | #define MH_OBJECT UINT32_C(1)
|
---|
221 | #define MH_EXECUTE UINT32_C(2)
|
---|
222 | #define MH_FVMLIB UINT32_C(3)
|
---|
223 | #define MH_CORE UINT32_C(4)
|
---|
224 | #define MH_PRELOAD UINT32_C(5)
|
---|
225 | #define MH_DYLIB UINT32_C(6)
|
---|
226 | #define MH_DYLINKER UINT32_C(7)
|
---|
227 | #define MH_BUNDLE UINT32_C(8)
|
---|
228 | #define MH_DYLIB_STUB UINT32_C(9)
|
---|
229 | #define MH_DSYM UINT32_C(10)
|
---|
230 | #define MH_KEXT_BUNDLE UINT32_C(11)
|
---|
231 |
|
---|
232 | /* mach_header_* flags */
|
---|
233 | #define MH_NOUNDEFS UINT32_C(0x00000001)
|
---|
234 | #define MH_INCRLINK UINT32_C(0x00000002)
|
---|
235 | #define MH_DYLDLINK UINT32_C(0x00000004)
|
---|
236 | #define MH_BINDATLOAD UINT32_C(0x00000008)
|
---|
237 | #define MH_PREBOUND UINT32_C(0x00000010)
|
---|
238 | #define MH_SPLIT_SEGS UINT32_C(0x00000020)
|
---|
239 | #define MH_LAZY_INIT UINT32_C(0x00000040)
|
---|
240 | #define MH_TWOLEVEL UINT32_C(0x00000080)
|
---|
241 | #define MH_FORCE_FLAT UINT32_C(0x00000100)
|
---|
242 | #define MH_NOMULTIDEFS UINT32_C(0x00000200)
|
---|
243 | #define MH_NOFIXPREBINDING UINT32_C(0x00000400)
|
---|
244 | #define MH_PREBINDABLE UINT32_C(0x00000800)
|
---|
245 | #define MH_ALLMODSBOUND UINT32_C(0x00001000)
|
---|
246 | #define MH_SUBSECTIONS_VIA_SYMBOLS UINT32_C(0x00002000)
|
---|
247 | #define MH_CANONICAL UINT32_C(0x00004000)
|
---|
248 | #define MH_WEAK_DEFINES UINT32_C(0x00008000)
|
---|
249 | #define MH_BINDS_TO_WEAK UINT32_C(0x00010000)
|
---|
250 | #define MH_ALLOW_STACK_EXECUTION UINT32_C(0x00020000)
|
---|
251 | #define MH_ROOT_SAFE UINT32_C(0x00040000)
|
---|
252 | #define MH_SETUID_SAFE UINT32_C(0x00080000)
|
---|
253 | #define MH_NO_REEXPORTED_DYLIBS UINT32_C(0x00100000)
|
---|
254 | #define MH_PIE UINT32_C(0x00200000)
|
---|
255 | #define MH_DEAD_STRIPPABLE_DYLIB UINT32_C(0x00400000)
|
---|
256 | #define MH_HAS_TLV_DESCRIPTORS UINT32_C(0x00800000)
|
---|
257 | #define MH_NO_HEAP_EXECUTION UINT32_C(0x01000000)
|
---|
258 | #define MH_VALID_FLAGS UINT32_C(0x01ffffff)
|
---|
259 |
|
---|
260 |
|
---|
261 | typedef struct load_command
|
---|
262 | {
|
---|
263 | uint32_t cmd;
|
---|
264 | uint32_t cmdsize;
|
---|
265 | } load_command_t;
|
---|
266 |
|
---|
267 | /* load cmd */
|
---|
268 | #define LC_REQ_DYLD UINT32_C(0x80000000)
|
---|
269 | #define LC_SEGMENT_32 UINT32_C(0x01)
|
---|
270 | #define LC_SYMTAB UINT32_C(0x02)
|
---|
271 | #define LC_SYMSEG UINT32_C(0x03)
|
---|
272 | #define LC_THREAD UINT32_C(0x04)
|
---|
273 | #define LC_UNIXTHREAD UINT32_C(0x05)
|
---|
274 | #define LC_LOADFVMLIB UINT32_C(0x06)
|
---|
275 | #define LC_IDFVMLIB UINT32_C(0x07)
|
---|
276 | #define LC_IDENT UINT32_C(0x08)
|
---|
277 | #define LC_FVMFILE UINT32_C(0x09)
|
---|
278 | #define LC_PREPAGE UINT32_C(0x0a)
|
---|
279 | #define LC_DYSYMTAB UINT32_C(0x0b)
|
---|
280 | #define LC_LOAD_DYLIB UINT32_C(0x0c)
|
---|
281 | #define LC_ID_DYLIB UINT32_C(0x0d)
|
---|
282 | #define LC_LOAD_DYLINKER UINT32_C(0x0e)
|
---|
283 | #define LC_ID_DYLINKER UINT32_C(0x0f)
|
---|
284 | #define LC_PREBOUND_DYLIB UINT32_C(0x10)
|
---|
285 | #define LC_ROUTINES UINT32_C(0x11)
|
---|
286 | #define LC_SUB_FRAMEWORK UINT32_C(0x12)
|
---|
287 | #define LC_SUB_UMBRELLA UINT32_C(0x13)
|
---|
288 | #define LC_SUB_CLIENT UINT32_C(0x14)
|
---|
289 | #define LC_SUB_LIBRARY UINT32_C(0x15)
|
---|
290 | #define LC_TWOLEVEL_HINTS UINT32_C(0x16)
|
---|
291 | #define LC_PREBIND_CKSUM UINT32_C(0x17)
|
---|
292 | #define LC_LOAD_WEAK_DYLIB (UINT32_C(0x18) | LC_REQ_DYLD)
|
---|
293 | #define LC_SEGMENT_64 UINT32_C(0x19)
|
---|
294 | #define LC_ROUTINES_64 UINT32_C(0x1a)
|
---|
295 | #define LC_UUID UINT32_C(0x1b)
|
---|
296 | #define LC_RPATH (UINT32_C(0x1c) | LC_REQ_DYLD)
|
---|
297 | #define LC_CODE_SIGNATURE UINT32_C(0x1d)
|
---|
298 | #define LC_SEGMENT_SPLIT_INFO UINT32_C(0x1e)
|
---|
299 | #define LC_REEXPORT_DYLIB (UINT32_C(0x1f) | LC_REQ_DYLD)
|
---|
300 | #define LC_LAZY_LOAD_DYLIB UINT32_C(0x20)
|
---|
301 | #define LC_ENCRYPTION_INFO UINT32_C(0x21)
|
---|
302 | #define LC_DYLD_INFO UINT32_C(0x22)
|
---|
303 | #define LC_DYLD_INFO_ONLY (UINT32_C(0x22) | LC_REQ_DYLD)
|
---|
304 | #define LC_LOAD_UPWARD_DYLIB (UINT32_C(0x23) | LC_REQ_DYLD)
|
---|
305 | #define LC_VERSION_MIN_MACOSX UINT32_C(0x24)
|
---|
306 | #define LC_VERSION_MIN_IPHONEOS UINT32_C(0x25)
|
---|
307 | #define LC_FUNCTION_STARTS UINT32_C(0x26)
|
---|
308 | #define LC_DYLD_ENVIRONMENT UINT32_C(0x27)
|
---|
309 | #define LC_MAIN (UINT32_C(0x28) | LC_REQ_DYLD)
|
---|
310 | #define LC_DATA_IN_CODE UINT32_C(0x29)
|
---|
311 | #define LC_SOURCE_VERSION UINT32_C(0x2a)
|
---|
312 | #define LC_DYLIB_CODE_SIGN_DRS UINT32_C(0x2b)
|
---|
313 |
|
---|
314 |
|
---|
315 | typedef struct lc_str
|
---|
316 | {
|
---|
317 | uint32_t offset;
|
---|
318 | } lc_str_t;
|
---|
319 |
|
---|
320 | typedef struct segment_command_32
|
---|
321 | {
|
---|
322 | uint32_t cmd;
|
---|
323 | uint32_t cmdsize;
|
---|
324 | char segname[16];
|
---|
325 | uint32_t vmaddr;
|
---|
326 | uint32_t vmsize;
|
---|
327 | uint32_t fileoff;
|
---|
328 | uint32_t filesize;
|
---|
329 | uint32_t maxprot;
|
---|
330 | uint32_t initprot;
|
---|
331 | uint32_t nsects;
|
---|
332 | uint32_t flags;
|
---|
333 | } segment_command_32_t;
|
---|
334 |
|
---|
335 | typedef struct segment_command_64
|
---|
336 | {
|
---|
337 | uint32_t cmd;
|
---|
338 | uint32_t cmdsize;
|
---|
339 | char segname[16];
|
---|
340 | uint64_t vmaddr;
|
---|
341 | uint64_t vmsize;
|
---|
342 | uint64_t fileoff;
|
---|
343 | uint64_t filesize;
|
---|
344 | uint32_t maxprot;
|
---|
345 | uint32_t initprot;
|
---|
346 | uint32_t nsects;
|
---|
347 | uint32_t flags;
|
---|
348 | } segment_command_64_t;
|
---|
349 |
|
---|
350 | /* segment flags */
|
---|
351 | #define SG_HIGHVM UINT32_C(0x00000001)
|
---|
352 | #define SG_FVMLIB UINT32_C(0x00000002)
|
---|
353 | #define SG_NORELOC UINT32_C(0x00000004)
|
---|
354 | #define SG_PROTECTED_VERSION_1 UINT32_C(0x00000008)
|
---|
355 |
|
---|
356 | /* maxprot/initprot */
|
---|
357 | #ifndef VM_PROT_NONE
|
---|
358 | # define VM_PROT_NONE UINT32_C(0x00000000)
|
---|
359 | # define VM_PROT_READ UINT32_C(0x00000001)
|
---|
360 | # define VM_PROT_WRITE UINT32_C(0x00000002)
|
---|
361 | # define VM_PROT_EXECUTE UINT32_C(0x00000004)
|
---|
362 | # define VM_PROT_ALL UINT32_C(0x00000007)
|
---|
363 | #endif
|
---|
364 |
|
---|
365 | typedef struct section_32
|
---|
366 | {
|
---|
367 | char sectname[16];
|
---|
368 | char segname[16];
|
---|
369 | uint32_t addr;
|
---|
370 | uint32_t size;
|
---|
371 | uint32_t offset;
|
---|
372 | uint32_t align;
|
---|
373 | uint32_t reloff;
|
---|
374 | uint32_t nreloc;
|
---|
375 | uint32_t flags;
|
---|
376 | uint32_t reserved1;
|
---|
377 | uint32_t reserved2;
|
---|
378 | } section_32_t;
|
---|
379 |
|
---|
380 | typedef struct section_64
|
---|
381 | {
|
---|
382 | char sectname[16];
|
---|
383 | char segname[16];
|
---|
384 | uint64_t addr;
|
---|
385 | uint64_t size;
|
---|
386 | uint32_t offset;
|
---|
387 | uint32_t align;
|
---|
388 | uint32_t reloff;
|
---|
389 | uint32_t nreloc;
|
---|
390 | uint32_t flags;
|
---|
391 | uint32_t reserved1;
|
---|
392 | uint32_t reserved2;
|
---|
393 | uint32_t reserved3;
|
---|
394 | } section_64_t;
|
---|
395 |
|
---|
396 | /* section flags */
|
---|
397 | #define SECTION_TYPE UINT32_C(0x000000ff)
|
---|
398 | #define S_REGULAR 0x0
|
---|
399 | #define S_ZEROFILL 0x1
|
---|
400 | #define S_CSTRING_LITERALS 0x2
|
---|
401 | #define S_4BYTE_LITERALS 0x3
|
---|
402 | #define S_8BYTE_LITERALS 0x4
|
---|
403 | #define S_LITERAL_POINTERS 0x5
|
---|
404 | #define S_NON_LAZY_SYMBOL_POINTERS 0x6
|
---|
405 | #define S_LAZY_SYMBOL_POINTERS 0x7
|
---|
406 | #define S_SYMBOL_STUBS 0x8
|
---|
407 | #define S_MOD_INIT_FUNC_POINTERS 0x9
|
---|
408 | #define S_MOD_TERM_FUNC_POINTERS 0xa
|
---|
409 | #define S_COALESCED 0xb
|
---|
410 | #define S_GB_ZEROFILL 0xc
|
---|
411 | #define S_INTERPOSING 0xd
|
---|
412 | #define S_16BYTE_LITERALS 0xe
|
---|
413 | #define S_DTRACE_DOF 0xf
|
---|
414 | #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10
|
---|
415 |
|
---|
416 | #define SECTION_ATTRIBUTES UINT32_C(0xffffff00)
|
---|
417 | #define SECTION_ATTRIBUTES_USR UINT32_C(0xff000000)
|
---|
418 | #define S_ATTR_PURE_INSTRUCTIONS UINT32_C(0x80000000)
|
---|
419 | #define S_ATTR_NO_TOC UINT32_C(0x40000000)
|
---|
420 | #define S_ATTR_STRIP_STATIC_SYMS UINT32_C(0x20000000)
|
---|
421 | #define S_ATTR_NO_DEAD_STRIP UINT32_C(0x10000000)
|
---|
422 | #define S_ATTR_LIVE_SUPPORT UINT32_C(0x08000000)
|
---|
423 | #define S_ATTR_SELF_MODIFYING_CODE UINT32_C(0x04000000)
|
---|
424 | #define S_ATTR_DEBUG UINT32_C(0x02000000)
|
---|
425 | #define SECTION_ATTRIBUTES_SYS UINT32_C(0x00ffff00)
|
---|
426 | #define S_ATTR_SOME_INSTRUCTIONS UINT32_C(0x00000400)
|
---|
427 | #define S_ATTR_EXT_RELOC UINT32_C(0x00000200)
|
---|
428 | #define S_ATTR_LOC_RELOC UINT32_C(0x00000100)
|
---|
429 |
|
---|
430 | /* standard section names */
|
---|
431 | #define SEG_PAGEZERO "__PAGEZERO"
|
---|
432 | #define SEG_TEXT "__TEXT"
|
---|
433 | #define SECT_TEXT "__text"
|
---|
434 | #define SECT_FVMLIB_INIT0 "__fvmlib_init0"
|
---|
435 | #define SECT_FVMLIB_INIT1 "__fvmlib_init1"
|
---|
436 | #define SEG_DATA "__DATA"
|
---|
437 | #define SECT_DATA "__data"
|
---|
438 | #define SECT_BSS "__bss"
|
---|
439 | #define SECT_COMMON "__common"
|
---|
440 | #define SEG_OBJC "__OBJC"
|
---|
441 | #define SECT_OBJC_SYMBOLS "__symbol_table"
|
---|
442 | #define SECT_OBJC_MODULES "__module_info"
|
---|
443 | #define SECT_OBJC_STRINGS "__selector_strs"
|
---|
444 | #define SECT_OBJC_REFS "__selector_refs"
|
---|
445 | #define SEG_ICON "__ICON"
|
---|
446 | #define SECT_ICON_HEADER "__header"
|
---|
447 | #define SECT_ICON_TIFF "__tiff"
|
---|
448 | #define SEG_LINKEDIT "__LINKEDIT"
|
---|
449 | #define SEG_UNIXSTACK "__UNIXSTACK"
|
---|
450 | #define SEG_IMPORT "__IMPORT"
|
---|
451 |
|
---|
452 | typedef struct thread_command
|
---|
453 | {
|
---|
454 | uint32_t cmd;
|
---|
455 | uint32_t cmdsize;
|
---|
456 | } thread_command_t;
|
---|
457 |
|
---|
458 | typedef struct symtab_command
|
---|
459 | {
|
---|
460 | uint32_t cmd;
|
---|
461 | uint32_t cmdsize;
|
---|
462 | uint32_t symoff;
|
---|
463 | uint32_t nsyms;
|
---|
464 | uint32_t stroff;
|
---|
465 | uint32_t strsize;
|
---|
466 | } symtab_command_t;
|
---|
467 |
|
---|
468 | typedef struct uuid_command
|
---|
469 | {
|
---|
470 | uint32_t cmd;
|
---|
471 | uint32_t cmdsize;
|
---|
472 | uint8_t uuid[16];
|
---|
473 | } uuid_command_t;
|
---|
474 |
|
---|
475 | typedef struct macho_nlist_32
|
---|
476 | {
|
---|
477 | union
|
---|
478 | {
|
---|
479 | int32_t n_strx;
|
---|
480 | } n_un;
|
---|
481 | uint8_t n_type;
|
---|
482 | uint8_t n_sect;
|
---|
483 | int16_t n_desc;
|
---|
484 | uint32_t n_value;
|
---|
485 | } macho_nlist_32_t;
|
---|
486 |
|
---|
487 |
|
---|
488 | typedef struct macho_nlist_64
|
---|
489 | {
|
---|
490 | union
|
---|
491 | {
|
---|
492 | uint32_t n_strx;
|
---|
493 | } n_un;
|
---|
494 | uint8_t n_type;
|
---|
495 | uint8_t n_sect;
|
---|
496 | int16_t n_desc;
|
---|
497 | uint64_t n_value;
|
---|
498 | } macho_nlist_64_t;
|
---|
499 |
|
---|
500 | #define MACHO_N_EXT UINT8_C(0x01)
|
---|
501 | #define MACHO_N_PEXT UINT8_C(0x10)
|
---|
502 |
|
---|
503 | #define MACHO_N_TYPE UINT8_C(0x0e)
|
---|
504 | #define MACHO_N_UNDF UINT8_C(0x00)
|
---|
505 | #define MACHO_N_ABS UINT8_C(0x02)
|
---|
506 | #define MACHO_N_INDR UINT8_C(0x0a)
|
---|
507 | #define MACHO_N_PBUD UINT8_C(0x0c)
|
---|
508 | #define MACHO_N_SECT UINT8_C(0x0e)
|
---|
509 |
|
---|
510 | #define MACHO_N_STAB UINT8_C(0xe0)
|
---|
511 | #define MACHO_N_GSYM UINT8_C(0x20)
|
---|
512 | #define MACHO_N_FNAME UINT8_C(0x22)
|
---|
513 | #define MACHO_N_FUN UINT8_C(0x24)
|
---|
514 | #define MACHO_N_STSYM UINT8_C(0x26)
|
---|
515 | #define MACHO_N_LCSYM UINT8_C(0x28)
|
---|
516 | #define MACHO_N_BNSYM UINT8_C(0x2e)
|
---|
517 | #define MACHO_N_PC UINT8_C(0x30)
|
---|
518 | #define MACHO_N_OPT UINT8_C(0x3c)
|
---|
519 | #define MACHO_N_RSYM UINT8_C(0x40)
|
---|
520 | #define MACHO_N_SLINE UINT8_C(0x44)
|
---|
521 | #define MACHO_N_ENSYM UINT8_C(0x4e)
|
---|
522 | #define MACHO_N_SSYM UINT8_C(0x60)
|
---|
523 | #define MACHO_N_SO UINT8_C(0x64)
|
---|
524 | #define MACHO_N_OSO UINT8_C(0x66)
|
---|
525 | #define MACHO_N_LSYM UINT8_C(0x80)
|
---|
526 | #define MACHO_N_BINCL UINT8_C(0x82)
|
---|
527 | #define MACHO_N_SOL UINT8_C(0x84)
|
---|
528 | #define MACHO_N_PARAMS UINT8_C(0x86)
|
---|
529 | #define MACHO_N_VERSION UINT8_C(0x88)
|
---|
530 | #define MACHO_N_OLEVEL UINT8_C(0x8A)
|
---|
531 | #define MACHO_N_PSYM UINT8_C(0xa0)
|
---|
532 | #define MACHO_N_EINCL UINT8_C(0xa2)
|
---|
533 | #define MACHO_N_ENTRY UINT8_C(0xa4)
|
---|
534 | #define MACHO_N_LBRAC UINT8_C(0xc0)
|
---|
535 | #define MACHO_N_EXCL UINT8_C(0xc2)
|
---|
536 | #define MACHO_N_RBRAC UINT8_C(0xe0)
|
---|
537 | #define MACHO_N_BCOMM UINT8_C(0xe2)
|
---|
538 | #define MACHO_N_ECOMM UINT8_C(0xe4)
|
---|
539 | #define MACHO_N_ECOML UINT8_C(0xe8)
|
---|
540 | #define MACHO_N_LENG UINT8_C(0xfe)
|
---|
541 |
|
---|
542 | #define MACHO_NO_SECT UINT8_C(0x00)
|
---|
543 | #define MACHO_MAX_SECT UINT8_C(0xff)
|
---|
544 |
|
---|
545 | #define REFERENCE_TYPE UINT16_C(0x000f)
|
---|
546 | #define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
|
---|
547 | #define REFERENCE_FLAG_UNDEFINED_LAZY 1
|
---|
548 | #define REFERENCE_FLAG_DEFINED 2
|
---|
549 | #define REFERENCE_FLAG_PRIVATE_DEFINED 3
|
---|
550 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
|
---|
551 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
|
---|
552 | #define REFERENCED_DYNAMICALLY UINT16_C(0x0010)
|
---|
553 |
|
---|
554 | #define GET_LIBRARY_ORDINAL(a_n_desc) \
|
---|
555 | RT_BYTE2(a_n_desc)
|
---|
556 | #define SET_LIBRARY_ORDINAL(a_n_desc, a_ordinal) \
|
---|
557 | do { (a_n_desc) = RT_MAKE_U16(RT_BYTE1(a_n_desc), a_ordinal); } while (0)
|
---|
558 |
|
---|
559 | #define SELF_LIBRARY_ORDINAL 0x00
|
---|
560 | #define MAX_LIBRARY_ORDINAL 0xfd
|
---|
561 | #define DYNAMIC_LOOKUP_ORDINAL 0xfe
|
---|
562 | #define EXECUTABLE_ORDINAL 0xff
|
---|
563 |
|
---|
564 | #define N_NO_DEAD_STRIP UINT16_C(0x0020)
|
---|
565 | #define N_DESC_DISCARDED UINT16_C(0x0020)
|
---|
566 | #define N_WEAK_REF UINT16_C(0x0040)
|
---|
567 | #define N_WEAK_DEF UINT16_C(0x0080)
|
---|
568 | #define N_REF_TO_WEAK UINT16_C(0x0080)
|
---|
569 |
|
---|
570 | typedef struct macho_relocation_info
|
---|
571 | {
|
---|
572 | int32_t r_address;
|
---|
573 | uint32_t r_symbolnum : 24;
|
---|
574 | uint32_t r_pcrel : 1;
|
---|
575 | uint32_t r_length : 2;
|
---|
576 | uint32_t r_extern : 1;
|
---|
577 | uint32_t r_type : 4;
|
---|
578 | } macho_relocation_info_t;
|
---|
579 |
|
---|
580 | #define R_ABS 0
|
---|
581 | #define R_SCATTERED UINT32_C(0x80000000)
|
---|
582 |
|
---|
583 | typedef struct scattered_relocation_info
|
---|
584 | {
|
---|
585 | #ifdef RT_LITTLE_ENDIAN
|
---|
586 | uint32_t r_address : 24;
|
---|
587 | uint32_t r_type : 4;
|
---|
588 | uint32_t r_length : 2;
|
---|
589 | uint32_t r_pcrel : 1;
|
---|
590 | uint32_t r_scattered : 1;
|
---|
591 | #elif defined(RT_BIG_ENDIAN)
|
---|
592 | uint32_t r_scattered : 1;
|
---|
593 | uint32_t r_pcrel : 1;
|
---|
594 | uint32_t r_length : 2;
|
---|
595 | uint32_t r_type : 4;
|
---|
596 | uint32_t r_address : 24;
|
---|
597 | #else
|
---|
598 | # error "Neither K_ENDIAN isn't LITTLE or BIG!"
|
---|
599 | #endif
|
---|
600 | int32_t r_value;
|
---|
601 | } scattered_relocation_info_t;
|
---|
602 |
|
---|
603 | typedef enum reloc_type_generic
|
---|
604 | {
|
---|
605 | GENERIC_RELOC_VANILLA = 0,
|
---|
606 | GENERIC_RELOC_PAIR,
|
---|
607 | GENERIC_RELOC_SECTDIFF,
|
---|
608 | GENERIC_RELOC_PB_LA_PTR,
|
---|
609 | GENERIC_RELOC_LOCAL_SECTDIFF
|
---|
610 | } reloc_type_generic_t;
|
---|
611 |
|
---|
612 | typedef enum reloc_type_x86_64
|
---|
613 | {
|
---|
614 | X86_64_RELOC_UNSIGNED = 0,
|
---|
615 | X86_64_RELOC_SIGNED,
|
---|
616 | X86_64_RELOC_BRANCH,
|
---|
617 | X86_64_RELOC_GOT_LOAD,
|
---|
618 | X86_64_RELOC_GOT,
|
---|
619 | X86_64_RELOC_SUBTRACTOR,
|
---|
620 | X86_64_RELOC_SIGNED_1,
|
---|
621 | X86_64_RELOC_SIGNED_2,
|
---|
622 | X86_64_RELOC_SIGNED_4
|
---|
623 | } reloc_type_x86_64_t;
|
---|
624 |
|
---|
625 | #endif
|
---|
626 |
|
---|