forked from Polidea/ios-class-guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDSection64.m
100 lines (79 loc) · 2.59 KB
/
CDSection64.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
// -*- 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-2009 Steve Nygard.
#import "CDSection64.h"
#import "CDDataCursor.h"
#import "CDMachOFile.h"
@implementation CDSection64
- (id)initWithDataCursor:(CDDataCursor *)cursor segment:(CDLCSegment64 *)aSegment;
{
char buf[17];
NSString *str;
if ([super init] == nil)
return nil;
nonretainedSegment = aSegment;
[cursor readBytesOfLength:16 intoBuffer:section.sectname];
[cursor readBytesOfLength:16 intoBuffer:section.segname];
section.addr = [cursor readInt64];
section.size = [cursor readInt64];
section.offset = [cursor readInt32];
section.align = [cursor readInt32];
section.reloff = [cursor readInt32];
section.nreloc = [cursor readInt32];
section.flags = [cursor readInt32];
section.reserved1 = [cursor readInt32];
section.reserved2 = [cursor readInt32];
section.reserved3 = [cursor readInt32];
// These aren't guaranteed to be null terminated. Witness __cstring_object in __OBJC segment
memcpy(buf, section.segname, 16);
buf[16] = 0;
str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
[self setSegmentName:str];
[str release];
memcpy(buf, section.sectname, 16);
buf[16] = 0;
str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
[self setSectionName:str];
[str release];
return self;
}
- (CDLCSegment64 *)segment;
{
return nonretainedSegment;
}
- (CDMachOFile *)machOFile;
{
return [[self segment] machOFile];
}
- (NSUInteger)addr;
{
return section.addr;
}
- (NSUInteger)size;
{
return section.size;
}
- (void)loadData;
{
if (_flags.hasLoadedData == NO) {
data = [[NSData alloc] initWithBytes:[[nonretainedSegment machOFile] machODataBytes] + section.offset length:section.size];
_flags.hasLoadedData = YES;
}
}
- (NSString *)description;
{
return [NSString stringWithFormat:@"<%@:%p> segment; '%@', section: '%-16s', addr: %016lx, size: %016lx",
NSStringFromClass([self class]), self,
segmentName, [sectionName UTF8String],
section.addr, section.size];
}
- (BOOL)containsAddress:(NSUInteger)address;
{
return (address >= section.addr) && (address < section.addr + section.size);
}
- (NSUInteger)fileOffsetForAddress:(NSUInteger)address;
{
NSParameterAssert([self containsAddress:address]);
return section.offset + address - section.addr;
}
@end