forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDSection.m
More file actions
108 lines (83 loc) · 2.45 KB
/
CDSection.m
File metadata and controls
108 lines (83 loc) · 2.45 KB
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
// 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-2006 Steve Nygard
#import "CDSection.h"
#include <mach-o/swap.h>
#import <Foundation/Foundation.h>
#import "CDFatFile.h"
#import "CDMachOFile.h"
#import "CDSegmentCommand.h"
@implementation CDSection
// Just to resolve multiple different definitions...
- (id)initWithPointer:(const void *)ptr segment:(CDSegmentCommand *)aSegment;
{
char buf[17];
if ([super init] == nil)
return nil;
nonretainedSegment = aSegment;
// TODO (2005-07-28): Check for null pointer...
section = *(struct section *)ptr;
if ([[[self segment] machOFile] hasDifferentByteOrder] == YES)
swap_section(§ion, 1, CD_THIS_BYTE_ORDER);
// These aren't guaranteed to be null terminated. Witness __cstring_object in __OBJC segment
memcpy(buf, section.segname, 16);
buf[16] = 0;
segmentName = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
memcpy(buf, section.sectname, 16);
buf[16] = 0;
sectionName = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
//NSLog(@"segmentName: '%@', sectionName: '%@'", segmentName, sectionName);
return self;
}
- (void)dealloc;
{
[segmentName release];
[sectionName release];
[super dealloc];
}
- (CDSegmentCommand *)segment;
{
return nonretainedSegment;
}
- (CDMachOFile *)machOFile;
{
return [[self segment] machOFile];
}
- (NSString *)segmentName;
{
return segmentName;
}
- (NSString *)sectionName;
{
return sectionName;
}
- (unsigned long)addr;
{
return section.addr;
}
- (unsigned long)size;
{
return section.size;
}
- (unsigned long)offset;
{
return section.offset;
}
- (const void *)dataPointer;
{
return [[self machOFile] bytes] + [self offset];
}
- (NSString *)description;
{
return [NSString stringWithFormat:@"addr: 0x%08x, offset: %8d, size: %8d [0x%8x], segment; '%@', section: '%@'",
[self addr], [self offset], [self size], [self size], segmentName, sectionName];
}
- (BOOL)containsAddress:(unsigned long)vmaddr;
{
// TODO (2003-12-06): And what happens when the filesize of the segment is less than the vmsize?
return (vmaddr >= [self addr]) && (vmaddr < [self addr] + [self size]);
}
- (unsigned long)segmentOffsetForVMAddr:(unsigned long)vmaddr;
{
return vmaddr - [self addr];
}
@end