ruby-macho 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/macho/headers.rb CHANGED
@@ -1,64 +1,82 @@
1
1
  module MachO
2
2
  # big-endian fat magic
3
+ # @api private
3
4
  FAT_MAGIC = 0xcafebabe
4
5
 
5
6
  # little-endian fat magic
6
7
  # this is defined, but should never appear in ruby-macho code because
7
8
  # fat headers are always big-endian and therefore always unpacked as such.
9
+ # @api private
8
10
  FAT_CIGAM = 0xbebafeca
9
11
 
10
12
  # 32-bit big-endian magic
13
+ # @api private
11
14
  MH_MAGIC = 0xfeedface
12
15
 
13
16
  # 32-bit little-endian magic
17
+ # @api private
14
18
  MH_CIGAM = 0xcefaedfe
15
19
 
16
20
  # 64-bit big-endian magic
21
+ # @api private
17
22
  MH_MAGIC_64 = 0xfeedfacf
18
23
 
19
24
  # 64-bit little-endian magic
25
+ # @api private
20
26
  MH_CIGAM_64 = 0xcffaedfe
21
27
 
22
28
  # association of magic numbers to string representations
29
+ # @api private
23
30
  MH_MAGICS = {
24
31
  FAT_MAGIC => "FAT_MAGIC",
25
32
  MH_MAGIC => "MH_MAGIC",
26
33
  MH_CIGAM => "MH_CIGAM",
27
34
  MH_MAGIC_64 => "MH_MAGIC_64",
28
- MH_CIGAM_64 => "MH_CIGAM_64"
29
- }
35
+ MH_CIGAM_64 => "MH_CIGAM_64",
36
+ }.freeze
30
37
 
31
38
  # mask for CPUs with 64-bit architectures (when running a 64-bit ABI?)
39
+ # @api private
32
40
  CPU_ARCH_ABI64 = 0x01000000
33
41
 
34
42
  # any CPU (unused?)
43
+ # @api private
35
44
  CPU_TYPE_ANY = -1
36
45
 
37
46
  # m68k compatible CPUs
47
+ # @api private
38
48
  CPU_TYPE_MC680X0 = 0x06
39
49
 
40
50
  # i386 and later compatible CPUs
51
+ # @api private
41
52
  CPU_TYPE_I386 = 0x07
42
53
 
43
54
  # x86_64 (AMD64) compatible CPUs
55
+ # @api private
44
56
  CPU_TYPE_X86_64 = (CPU_TYPE_I386 | CPU_ARCH_ABI64)
45
57
 
46
58
  # 32-bit ARM compatible CPUs
59
+ # @api private
47
60
  CPU_TYPE_ARM = 0x0c
48
61
 
49
62
  # m88k compatible CPUs
63
+ # @api private
50
64
  CPU_TYPE_MC88000 = 0xd
51
65
 
52
66
  # 64-bit ARM compatible CPUs
67
+ # @api private
53
68
  CPU_TYPE_ARM64 = (CPU_TYPE_ARM | CPU_ARCH_ABI64)
54
69
 
55
70
  # PowerPC compatible CPUs
71
+ # @api private
56
72
  CPU_TYPE_POWERPC = 0x12
57
73
 
58
74
  # PowerPC64 compatible CPUs
75
+ # @api private
59
76
  CPU_TYPE_POWERPC64 = (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
60
77
 
61
78
  # association of cpu types to symbol representations
79
+ # @api private
62
80
  CPU_TYPES = {
63
81
  CPU_TYPE_ANY => :any,
64
82
  CPU_TYPE_I386 => :i386,
@@ -67,156 +85,213 @@ module MachO
67
85
  CPU_TYPE_ARM64 => :arm64,
68
86
  CPU_TYPE_POWERPC => :ppc,
69
87
  CPU_TYPE_POWERPC64 => :ppc64,
70
- }
88
+ }.freeze
71
89
 
72
90
  # mask for CPU subtype capabilities
91
+ # @api private
73
92
  CPU_SUBTYPE_MASK = 0xff000000
74
93
 
75
94
  # 64-bit libraries (undocumented!)
76
95
  # @see http://llvm.org/docs/doxygen/html/Support_2MachO_8h_source.html
96
+ # @api private
77
97
  CPU_SUBTYPE_LIB64 = 0x80000000
78
98
 
79
99
  # the lowest common sub-type for `CPU_TYPE_I386`
100
+ # @api private
80
101
  CPU_SUBTYPE_I386 = 3
81
102
 
82
103
  # the i486 sub-type for `CPU_TYPE_I386`
104
+ # @api private
83
105
  CPU_SUBTYPE_486 = 4
84
106
 
85
107
  # the i486SX sub-type for `CPU_TYPE_I386`
108
+ # @api private
86
109
  CPU_SUBTYPE_486SX = 132
87
110
 
88
111
  # the i586 (P5, Pentium) sub-type for `CPU_TYPE_I386`
112
+ # @api private
89
113
  CPU_SUBTYPE_586 = 5
90
- CPU_SUBTYPE_PENT = CPU_SUBTYPE_586
114
+
115
+ # @see CPU_SUBTYPE_586
116
+ # @api private
117
+ CPU_SUBTYPE_PENT = CPU_SUBTYPE_586
91
118
 
92
119
  # the Pentium Pro (P6) sub-type for `CPU_TYPE_I386`
120
+ # @api private
93
121
  CPU_SUBTYPE_PENTPRO = 22
94
122
 
95
123
  # the Pentium II (P6, M3?) sub-type for `CPU_TYPE_I386`
124
+ # @api private
96
125
  CPU_SUBTYPE_PENTII_M3 = 54
97
126
 
98
127
  # the Pentium II (P6, M5?) sub-type for `CPU_TYPE_I386`
128
+ # @api private
99
129
  CPU_SUBTYPE_PENTII_M5 = 86
100
130
 
101
131
  # the Pentium 4 (Netburst) sub-type for `CPU_TYPE_I386`
132
+ # @api private
102
133
  CPU_SUBTYPE_PENTIUM_4 = 10
103
134
 
104
135
  # the lowest common sub-type for `CPU_TYPE_MC680X0`
136
+ # @api private
105
137
  CPU_SUBTYPE_MC680X0_ALL = 1
138
+
139
+ # @see CPU_SUBTYPE_MC680X0_ALL
140
+ # @api private
106
141
  CPU_SUBTYPE_MC68030 = CPU_SUBTYPE_MC680X0_ALL
107
142
 
108
143
  # the 040 subtype for `CPU_TYPE_MC680X0`
144
+ # @api private
109
145
  CPU_SUBTYPE_MC68040 = 2
110
146
 
111
147
  # the 030 subtype for `CPU_TYPE_MC680X0`
148
+ # @api private
112
149
  CPU_SUBTYPE_MC68030_ONLY = 3
113
150
 
114
151
  # the lowest common sub-type for `CPU_TYPE_X86_64`
152
+ # @api private
115
153
  CPU_SUBTYPE_X86_64_ALL = CPU_SUBTYPE_I386
116
154
 
117
155
  # the Haskell sub-type for `CPU_TYPE_X86_64`
156
+ # @api private
118
157
  CPU_SUBTYPE_X86_64_H = 8
119
158
 
120
159
  # the lowest common sub-type for `CPU_TYPE_ARM`
160
+ # @api private
121
161
  CPU_SUBTYPE_ARM_ALL = 0
122
162
 
123
163
  # the v4t sub-type for `CPU_TYPE_ARM`
164
+ # @api private
124
165
  CPU_SUBTYPE_ARM_V4T = 5
125
166
 
126
167
  # the v6 sub-type for `CPU_TYPE_ARM`
168
+ # @api private
127
169
  CPU_SUBTYPE_ARM_V6 = 6
128
170
 
129
171
  # the v5 sub-type for `CPU_TYPE_ARM`
172
+ # @api private
130
173
  CPU_SUBTYPE_ARM_V5TEJ = 7
131
174
 
132
175
  # the xscale (v5 family) sub-type for `CPU_TYPE_ARM`
176
+ # @api private
133
177
  CPU_SUBTYPE_ARM_XSCALE = 8
134
178
 
135
179
  # the v7 sub-type for `CPU_TYPE_ARM`
180
+ # @api private
136
181
  CPU_SUBTYPE_ARM_V7 = 9
137
182
 
138
183
  # the v7f (Cortex A9) sub-type for `CPU_TYPE_ARM`
184
+ # @api private
139
185
  CPU_SUBTYPE_ARM_V7F = 10
140
186
 
141
187
  # the v7s ("Swift") sub-type for `CPU_TYPE_ARM`
188
+ # @api private
142
189
  CPU_SUBTYPE_ARM_V7S = 11
143
190
 
144
191
  # the v7k ("Kirkwood40") sub-type for `CPU_TYPE_ARM`
192
+ # @api private
145
193
  CPU_SUBTYPE_ARM_V7K = 12
146
194
 
147
195
  # the v6m sub-type for `CPU_TYPE_ARM`
196
+ # @api private
148
197
  CPU_SUBTYPE_ARM_V6M = 14
149
198
 
150
199
  # the v7m sub-type for `CPU_TYPE_ARM`
200
+ # @api private
151
201
  CPU_SUBTYPE_ARM_V7M = 15
152
202
 
153
203
  # the v7em sub-type for `CPU_TYPE_ARM`
204
+ # @api private
154
205
  CPU_SUBTYPE_ARM_V7EM = 16
155
206
 
156
207
  # the v8 sub-type for `CPU_TYPE_ARM`
208
+ # @api private
157
209
  CPU_SUBTYPE_ARM_V8 = 13
158
210
 
159
211
  # the lowest common sub-type for `CPU_TYPE_ARM64`
212
+ # @api private
160
213
  CPU_SUBTYPE_ARM64_ALL = 0
161
214
 
162
215
  # the v8 sub-type for `CPU_TYPE_ARM64`
216
+ # @api private
163
217
  CPU_SUBTYPE_ARM64_V8 = 1
164
218
 
165
219
  # the lowest common sub-type for `CPU_TYPE_MC88000`
220
+ # @api private
166
221
  CPU_SUBTYPE_MC88000_ALL = 0
222
+
223
+ # @see CPU_SUBTYPE_MC88000_ALL
224
+ # @api private
167
225
  CPU_SUBTYPE_MMAX_JPC = CPU_SUBTYPE_MC88000_ALL
168
226
 
169
227
  # the 100 sub-type for `CPU_TYPE_MC88000`
228
+ # @api private
170
229
  CPU_SUBTYPE_MC88100 = 1
171
230
 
172
231
  # the 110 sub-type for `CPU_TYPE_MC88000`
232
+ # @api private
173
233
  CPU_SUBTYPE_MC88110 = 2
174
234
 
175
235
  # the lowest common sub-type for `CPU_TYPE_POWERPC`
236
+ # @api private
176
237
  CPU_SUBTYPE_POWERPC_ALL = 0
177
238
 
178
239
  # the 601 sub-type for `CPU_TYPE_POWERPC`
240
+ # @api private
179
241
  CPU_SUBTYPE_POWERPC_601 = 1
180
242
 
181
243
  # the 602 sub-type for `CPU_TYPE_POWERPC`
244
+ # @api private
182
245
  CPU_SUBTYPE_POWERPC_602 = 2
183
246
 
184
247
  # the 603 sub-type for `CPU_TYPE_POWERPC`
248
+ # @api private
185
249
  CPU_SUBTYPE_POWERPC_603 = 3
186
250
 
187
251
  # the 603e (G2) sub-type for `CPU_TYPE_POWERPC`
252
+ # @api private
188
253
  CPU_SUBTYPE_POWERPC_603E = 4
189
254
 
190
255
  # the 603ev sub-type for `CPU_TYPE_POWERPC`
256
+ # @api private
191
257
  CPU_SUBTYPE_POWERPC_603EV = 5
192
258
 
193
259
  # the 604 sub-type for `CPU_TYPE_POWERPC`
260
+ # @api private
194
261
  CPU_SUBTYPE_POWERPC_604 = 6
195
262
 
196
263
  # the 604e sub-type for `CPU_TYPE_POWERPC`
264
+ # @api private
197
265
  CPU_SUBTYPE_POWERPC_604E = 7
198
266
 
199
267
  # the 620 sub-type for `CPU_TYPE_POWERPC`
268
+ # @api private
200
269
  CPU_SUBTYPE_POWERPC_620 = 8
201
270
 
202
271
  # the 750 (G3) sub-type for `CPU_TYPE_POWERPC`
272
+ # @api private
203
273
  CPU_SUBTYPE_POWERPC_750 = 9
204
274
 
205
275
  # the 7400 (G4) sub-type for `CPU_TYPE_POWERPC`
276
+ # @api private
206
277
  CPU_SUBTYPE_POWERPC_7400 = 10
207
278
 
208
279
  # the 7450 (G4 "Voyager") sub-type for `CPU_TYPE_POWERPC`
280
+ # @api private
209
281
  CPU_SUBTYPE_POWERPC_7450 = 11
210
282
 
211
283
  # the 970 (G5) sub-type for `CPU_TYPE_POWERPC`
284
+ # @api private
212
285
  CPU_SUBTYPE_POWERPC_970 = 100
213
286
 
214
287
  # any CPU sub-type for CPU type `CPU_TYPE_POWERPC64`
288
+ # @api private
215
289
  CPU_SUBTYPE_POWERPC64_ALL = CPU_SUBTYPE_POWERPC_ALL
216
290
 
217
291
  # association of CPU types/subtype pairs to symbol representations in
218
292
  # (very) roughly descending order of commonness
219
293
  # @see https://opensource.apple.com/source/cctools/cctools-877.8/libstuff/arch.c
294
+ # @api private
220
295
  CPU_SUBTYPES = {
221
296
  CPU_TYPE_I386 => {
222
297
  CPU_SUBTYPE_I386 => :i386,
@@ -280,53 +355,64 @@ module MachO
280
355
  }.freeze
281
356
 
282
357
  # relocatable object file
358
+ # @api private
283
359
  MH_OBJECT = 0x1
284
360
 
285
361
  # demand paged executable file
362
+ # @api private
286
363
  MH_EXECUTE = 0x2
287
364
 
288
365
  # fixed VM shared library file
366
+ # @api private
289
367
  MH_FVMLIB = 0x3
290
368
 
291
369
  # core dump file
370
+ # @api private
292
371
  MH_CORE = 0x4
293
372
 
294
373
  # preloaded executable file
374
+ # @api private
295
375
  MH_PRELOAD = 0x5
296
376
 
297
377
  # dynamically bound shared library
378
+ # @api private
298
379
  MH_DYLIB = 0x6
299
380
 
300
381
  # dynamic link editor
382
+ # @api private
301
383
  MH_DYLINKER = 0x7
302
384
 
303
385
  # dynamically bound bundle file
386
+ # @api private
304
387
  MH_BUNDLE = 0x8
305
388
 
306
389
  # shared library stub for static linking only, no section contents
390
+ # @api private
307
391
  MH_DYLIB_STUB = 0x9
308
392
 
309
393
  # companion file with only debug sections
394
+ # @api private
310
395
  MH_DSYM = 0xa
311
396
 
312
397
  # x86_64 kexts
398
+ # @api private
313
399
  MH_KEXT_BUNDLE = 0xb
314
400
 
315
- # association of filetypes to string representations
401
+ # association of filetypes to Symbol representations
316
402
  # @api private
317
403
  MH_FILETYPES = {
318
- MH_OBJECT => "MH_OBJECT",
319
- MH_EXECUTE => "MH_EXECUTE",
320
- MH_FVMLIB => "MH_FVMLIB",
321
- MH_CORE => "MH_CORE",
322
- MH_PRELOAD => "MH_PRELOAD",
323
- MH_DYLIB => "MH_DYLIB",
324
- MH_DYLINKER => "MH_DYLINKER",
325
- MH_BUNDLE => "MH_BUNDLE",
326
- MH_DYLIB_STUB => "MH_DYLIB_STUB",
327
- MH_DSYM => "MH_DSYM",
328
- MH_KEXT_BUNDLE => "MH_KEXT_BUNDLE"
329
- }
404
+ MH_OBJECT => :object,
405
+ MH_EXECUTE => :execute,
406
+ MH_FVMLIB => :fvmlib,
407
+ MH_CORE => :core,
408
+ MH_PRELOAD => :preload,
409
+ MH_DYLIB => :dylib,
410
+ MH_DYLINKER => :dylinker,
411
+ MH_BUNDLE => :bundle,
412
+ MH_DYLIB_STUB => :dylib_stub,
413
+ MH_DSYM => :dsym,
414
+ MH_KEXT_BUNDLE => :kext_bundle,
415
+ }.freeze
330
416
 
331
417
  # association of mach header flag symbols to values
332
418
  # @api private
@@ -356,8 +442,8 @@ module MachO
356
442
  :MH_DEAD_STRIPPABLE_DYLIB => 0x400000,
357
443
  :MH_HAS_TLV_DESCRIPTORS => 0x800000,
358
444
  :MH_NO_HEAP_EXECUTION => 0x1000000,
359
- :MH_APP_EXTENSION_SAFE => 0x02000000
360
- }
445
+ :MH_APP_EXTENSION_SAFE => 0x02000000,
446
+ }.freeze
361
447
 
362
448
  # Fat binary header structure
363
449
  # @see MachO::FatArch
@@ -369,7 +455,12 @@ module MachO
369
455
  attr_reader :nfat_arch
370
456
 
371
457
  # always big-endian
372
- FORMAT = "N2"
458
+ # @see MachOStructure::FORMAT
459
+ # @api private
460
+ FORMAT = "N2".freeze
461
+
462
+ # @see MachOStructure::SIZEOF
463
+ # @api private
373
464
  SIZEOF = 8
374
465
 
375
466
  # @api private
@@ -399,7 +490,12 @@ module MachO
399
490
  attr_reader :align
400
491
 
401
492
  # always big-endian
402
- FORMAT = "N5"
493
+ # @see MachOStructure::FORMAT
494
+ # @api private
495
+ FORMAT = "N5".freeze
496
+
497
+ # @see MachOStructure::SIZEOF
498
+ # @api private
403
499
  SIZEOF = 20
404
500
 
405
501
  # @api private
@@ -435,12 +531,17 @@ module MachO
435
531
  # @return [Fixnum] the header flags associated with the Mach-O
436
532
  attr_reader :flags
437
533
 
438
- FORMAT = "L=7"
534
+ # @see MachOStructure::FORMAT
535
+ # @api private
536
+ FORMAT = "L=7".freeze
537
+
538
+ # @see MachOStructure::SIZEOF
539
+ # @api private
439
540
  SIZEOF = 28
440
541
 
441
542
  # @api private
442
543
  def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds,
443
- flags)
544
+ flags)
444
545
  @magic = magic
445
546
  @cputype = cputype
446
547
  # For now we're not interested in additional capability bits also to be
@@ -468,12 +569,17 @@ module MachO
468
569
  # @return [void]
469
570
  attr_reader :reserved
470
571
 
471
- FORMAT = "L=8"
572
+ # @see MachOStructure::FORMAT
573
+ # @api private
574
+ FORMAT = "L=8".freeze
575
+
576
+ # @see MachOStructure::SIZEOF
577
+ # @api private
472
578
  SIZEOF = 32
473
579
 
474
580
  # @api private
475
581
  def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds,
476
- flags, reserved)
582
+ flags, reserved)
477
583
  super(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags)
478
584
  @reserved = reserved
479
585
  end