forked from Bluelich/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDLCSegment32.m
120 lines (96 loc) · 3.59 KB
/
CDLCSegment32.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
113
114
115
116
117
118
119
120
// -*- 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-2011 Steve Nygard.
#import "CDLCSegment32.h"
#import "CDSection32.h"
@implementation CDLCSegment32
- (id)initWithDataCursor:(CDMachOFileDataCursor *)cursor;
{
if ((self = [super initWithDataCursor:cursor])) {
segmentCommand.cmd = [cursor readInt32];
segmentCommand.cmdsize = [cursor readInt32];
[cursor readBytesOfLength:16 intoBuffer:segmentCommand.segname];
segmentCommand.vmaddr = [cursor readInt32];
segmentCommand.vmsize = [cursor readInt32];
segmentCommand.fileoff = [cursor readInt32];
segmentCommand.filesize = [cursor readInt32];
segmentCommand.maxprot = [cursor readInt32];
segmentCommand.initprot = [cursor readInt32];
segmentCommand.nsects = [cursor readInt32];
segmentCommand.flags = [cursor readInt32];
{
char buf[17];
memcpy(buf, segmentCommand.segname, 16);
buf[16] = 0;
NSString *str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
[self setName:str];
[str release];
}
NSMutableArray *_sections = [[NSMutableArray alloc] init];
for (NSUInteger index = 0; index < segmentCommand.nsects; index++) {
CDSection32 *section = [[CDSection32 alloc] initWithDataCursor:cursor segment:self];
[_sections addObject:section];
[section release];
}
sections = [_sections copy]; [_sections release];
}
return self;
}
#pragma mark -
- (uint32_t)cmd;
{
return segmentCommand.cmd;
}
- (uint32_t)cmdsize;
{
return segmentCommand.cmdsize;
}
- (NSUInteger)vmaddr;
{
return segmentCommand.vmaddr;
}
- (NSUInteger)fileoff;
{
return segmentCommand.fileoff;
}
- (NSUInteger)filesize;
{
return segmentCommand.filesize;
}
- (vm_prot_t)initprot;
{
return segmentCommand.initprot;
}
- (uint32_t)flags;
{
return segmentCommand.flags;
}
- (NSString *)extraDescription;
{
return [NSString stringWithFormat:@"vmaddr: 0x%08x - 0x%08x [0x%08x], offset: %d, flags: 0x%x (%@), nsects: %d, sections: %@",
segmentCommand.vmaddr, segmentCommand.vmaddr + segmentCommand.vmsize - 1, segmentCommand.vmsize, segmentCommand.fileoff,
self.flags, [self flagDescription], segmentCommand.nsects, sections];
}
- (BOOL)containsAddress:(NSUInteger)address;
{
return (address >= segmentCommand.vmaddr) && (address < segmentCommand.vmaddr + segmentCommand.vmsize);
}
- (void)appendToString:(NSMutableString *)resultString verbose:(BOOL)isVerbose;
{
[super appendToString:resultString verbose:isVerbose];
#if 0
[resultString appendFormat:@" segname %@\n", [self name]];
[resultString appendFormat:@" vmaddr 0x%08x\n", segmentCommand.vmaddr];
[resultString appendFormat:@" vmsize 0x%08x\n", segmentCommand.vmsize];
[resultString appendFormat:@" fileoff %d\n", segmentCommand.fileoff];
[resultString appendFormat:@" filesize %d\n", segmentCommand.filesize];
[resultString appendFormat:@" maxprot 0x%08x\n", segmentCommand.maxprot];
[resultString appendFormat:@" initprot 0x%08x\n", segmentCommand.initprot];
[resultString appendFormat:@" nsects %d\n", segmentCommand.nsects];
if (isVerbose)
[resultString appendFormat:@" flags %@\n", [self flagDescription]];
else
[resultString appendFormat:@" flags 0x%x\n", segmentCommand.flags];
#endif
}
@end