forked from Bluelich/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDLCSegment64.m
97 lines (76 loc) · 2.38 KB
/
CDLCSegment64.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
// -*- 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 "CDLCSegment64.h"
#import "CDSection64.h"
@implementation CDLCSegment64
- (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 readInt64];
segmentCommand.vmsize = [cursor readInt64];
segmentCommand.fileoff = [cursor readInt64];
segmentCommand.filesize = [cursor readInt64];
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++) {
CDSection64 *section = [[CDSection64 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;
}
- (BOOL)containsAddress:(NSUInteger)address;
{
return (address >= segmentCommand.vmaddr) && (address < segmentCommand.vmaddr + segmentCommand.vmsize);
}
- (NSString *)extraDescription;
{
return [NSString stringWithFormat:@"addr: 0x%016lx", [self vmaddr]];
}
@end