forked from preemptive/PPiOS-Rename
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CDFatArch.m
112 lines (87 loc) · 2.77 KB
/
CDFatArch.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2015 Steve Nygard.
#import "CDFatArch.h"
#include <mach-o/fat.h>
#import "CDDataCursor.h"
#import "CDFatFile.h"
#import "CDMachOFile.h"
@implementation CDFatArch
{
__weak CDFatFile *_fatFile;
// This is essentially struct fat_arch, but this way our property accessors can be synthesized.
cpu_type_t _cputype;
cpu_subtype_t _cpusubtype;
uint32_t _offset;
uint32_t _size;
uint32_t _align;
CDMachOFile *_machOFile; // Lazily create this.
}
- (id)initWithMachOFile:(CDMachOFile *)machOFile;
{
if ((self = [super init])) {
_machOFile = machOFile;
NSParameterAssert([machOFile.data length] < 0x100000000);
_cputype = _machOFile.cputype;
_cpusubtype = _machOFile.cpusubtype;
_offset = 0; // Would be filled in when this is written to disk
_size = (uint32_t)[_machOFile.data length];
_align = 12; // 2**12 = 4096 (0x1000)
}
return self;
}
- (id)initWithDataCursor:(CDDataCursor *)cursor;
{
if ((self = [super init])) {
_cputype = [cursor readBigInt32];
_cpusubtype = [cursor readBigInt32];
_offset = [cursor readBigInt32];
_size = [cursor readBigInt32];
_align = [cursor readBigInt32];
//NSLog(@"self: %@", self);
}
return self;
}
#pragma mark - Debugging
- (NSString *)description;
{
return [NSString stringWithFormat:@"64 bit ABI? %d, cputype: 0x%08x, cpusubtype: 0x%08x, offset: 0x%08x (%8u), size: 0x%08x (%8u), align: 2^%u (%x), arch name: %@",
self.uses64BitABI, self.cputype, self.cpusubtype, self.offset, self.offset, self.size, self.size,
self.align, 1 << self.align, self.archName];
}
#pragma mark -
- (cpu_type_t)maskedCPUType;
{
return self.cputype & ~CPU_ARCH_MASK;
}
- (cpu_subtype_t)maskedCPUSubtype;
{
return self.cpusubtype & ~CPU_SUBTYPE_MASK;
}
- (BOOL)uses64BitABI;
{
return CDArchUses64BitABI(self.arch);
}
- (BOOL)uses64BitLibraries;
{
return CDArchUses64BitLibraries(self.arch);
}
- (CDArch)arch;
{
CDArch arch = { self.cputype, self.cpusubtype };
return arch;
}
// Must not return nil.
- (NSString *)archName;
{
return CDNameForCPUType(self.cputype, self.cpusubtype);
}
- (CDMachOFile *)machOFile;
{
if (_machOFile == nil) {
NSData *data = [NSData dataWithBytesNoCopy:((uint8_t *)[self.fatFile.data bytes] + self.offset) length:self.size freeWhenDone:NO];
_machOFile = [[CDMachOFile alloc] initWithData:data filename:self.fatFile.filename searchPathState:self.fatFile.searchPathState];
}
return _machOFile;
}
@end