OLD | NEW |
(Empty) | |
| 1 // -*- mode: ObjC -*- |
| 2 |
| 3 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 5 |
| 6 #import "CDSection64.h" |
| 7 |
| 8 #import "CDDataCursor.h" |
| 9 #import "CDMachOFile.h" |
| 10 |
| 11 @implementation CDSection64 |
| 12 |
| 13 - (id)initWithDataCursor:(CDDataCursor *)cursor segment:(CDLCSegment64 *)aSegmen
t; |
| 14 { |
| 15 char buf[17]; |
| 16 NSString *str; |
| 17 |
| 18 if ([super init] == nil) |
| 19 return nil; |
| 20 |
| 21 nonretained_segment = aSegment; |
| 22 |
| 23 [cursor readBytesOfLength:16 intoBuffer:section.sectname]; |
| 24 [cursor readBytesOfLength:16 intoBuffer:section.segname]; |
| 25 section.addr = [cursor readInt64]; |
| 26 section.size = [cursor readInt64]; |
| 27 section.offset = [cursor readInt32]; |
| 28 section.align = [cursor readInt32]; |
| 29 section.reloff = [cursor readInt32]; |
| 30 section.nreloc = [cursor readInt32]; |
| 31 section.flags = [cursor readInt32]; |
| 32 section.reserved1 = [cursor readInt32]; |
| 33 section.reserved2 = [cursor readInt32]; |
| 34 section.reserved3 = [cursor readInt32]; |
| 35 |
| 36 // These aren't guaranteed to be null terminated. Witness __cstring_object
in __OBJC segment |
| 37 |
| 38 memcpy(buf, section.segname, 16); |
| 39 buf[16] = 0; |
| 40 str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCI
IStringEncoding]; |
| 41 [self setSegmentName:str]; |
| 42 [str release]; |
| 43 |
| 44 memcpy(buf, section.sectname, 16); |
| 45 buf[16] = 0; |
| 46 str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCI
IStringEncoding]; |
| 47 [self setSectionName:str]; |
| 48 [str release]; |
| 49 |
| 50 return self; |
| 51 } |
| 52 |
| 53 - (CDLCSegment64 *)segment; |
| 54 { |
| 55 return nonretained_segment; |
| 56 } |
| 57 |
| 58 - (CDMachOFile *)machOFile; |
| 59 { |
| 60 return [[self segment] machOFile]; |
| 61 } |
| 62 |
| 63 - (NSUInteger)addr; |
| 64 { |
| 65 return section.addr; |
| 66 } |
| 67 |
| 68 - (NSUInteger)size; |
| 69 { |
| 70 return section.size; |
| 71 } |
| 72 |
| 73 - (void)loadData; |
| 74 { |
| 75 if (_flags.hasLoadedData == NO) { |
| 76 data = [[NSData alloc] initWithBytes:[[nonretained_segment machOFile] ma
chODataBytes] + section.offset length:section.size]; |
| 77 _flags.hasLoadedData = YES; |
| 78 } |
| 79 } |
| 80 |
| 81 - (NSString *)description; |
| 82 { |
| 83 return [NSString stringWithFormat:@"<%@:%p> segment; '%@', section: '%-16s',
addr: %016lx, size: %016lx", |
| 84 NSStringFromClass([self class]), self, |
| 85 segmentName, [sectionName UTF8String], |
| 86 section.addr, section.size]; |
| 87 } |
| 88 |
| 89 - (BOOL)containsAddress:(NSUInteger)address; |
| 90 { |
| 91 return (address >= section.addr) && (address < section.addr + section.size); |
| 92 } |
| 93 |
| 94 - (NSUInteger)fileOffsetForAddress:(NSUInteger)address; |
| 95 { |
| 96 NSParameterAssert([self containsAddress:address]); |
| 97 return section.offset + address - section.addr; |
| 98 } |
| 99 |
| 100 @end |
OLD | NEW |