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 "CDLCSegment32.h" |
| 7 |
| 8 #import "CDDataCursor.h" |
| 9 #import "CDSection32.h" |
| 10 |
| 11 @implementation CDLCSegment32 |
| 12 |
| 13 - (id)initWithDataCursor:(CDDataCursor *)cursor machOFile:(CDMachOFile *)aMachOF
ile; |
| 14 { |
| 15 if ([super initWithDataCursor:cursor machOFile:aMachOFile] == nil) |
| 16 return nil; |
| 17 |
| 18 segmentCommand.cmd = [cursor readInt32]; |
| 19 segmentCommand.cmdsize = [cursor readInt32]; |
| 20 |
| 21 [cursor readBytesOfLength:16 intoBuffer:segmentCommand.segname]; |
| 22 segmentCommand.vmaddr = [cursor readInt32]; |
| 23 segmentCommand.vmsize = [cursor readInt32]; |
| 24 segmentCommand.fileoff = [cursor readInt32]; |
| 25 segmentCommand.filesize = [cursor readInt32]; |
| 26 segmentCommand.maxprot = [cursor readInt32]; |
| 27 segmentCommand.initprot = [cursor readInt32]; |
| 28 segmentCommand.nsects = [cursor readInt32]; |
| 29 segmentCommand.flags = [cursor readInt32]; |
| 30 |
| 31 { |
| 32 char buf[17]; |
| 33 NSString *str; |
| 34 |
| 35 memcpy(buf, segmentCommand.segname, 16); |
| 36 buf[16] = 0; |
| 37 str = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NS
ASCIIStringEncoding]; |
| 38 if ([str length] >= 16) { |
| 39 NSLog(@"Notice: segment '%@' has length >= 16, which means it's not
always null terminated.", str); |
| 40 } |
| 41 [self setName:str]; |
| 42 [str release]; |
| 43 } |
| 44 |
| 45 { |
| 46 unsigned int index; |
| 47 |
| 48 for (index = 0; index < segmentCommand.nsects; index++) { |
| 49 CDSection32 *section; |
| 50 |
| 51 section = [[CDSection32 alloc] initWithDataCursor:cursor segment:sel
f]; |
| 52 [sections addObject:section]; |
| 53 [section release]; |
| 54 } |
| 55 } |
| 56 |
| 57 return self; |
| 58 } |
| 59 |
| 60 - (uint32_t)cmd; |
| 61 { |
| 62 return segmentCommand.cmd; |
| 63 } |
| 64 |
| 65 - (uint32_t)cmdsize; |
| 66 { |
| 67 return segmentCommand.cmdsize; |
| 68 } |
| 69 |
| 70 - (NSUInteger)vmaddr; |
| 71 { |
| 72 return segmentCommand.vmaddr; |
| 73 } |
| 74 |
| 75 - (NSUInteger)fileoff; |
| 76 { |
| 77 return segmentCommand.fileoff; |
| 78 } |
| 79 |
| 80 - (NSUInteger)filesize; |
| 81 { |
| 82 return segmentCommand.filesize; |
| 83 } |
| 84 |
| 85 - (vm_prot_t)initprot; |
| 86 { |
| 87 return segmentCommand.initprot; |
| 88 } |
| 89 |
| 90 - (uint32_t)flags; |
| 91 { |
| 92 return segmentCommand.flags; |
| 93 } |
| 94 |
| 95 - (NSString *)extraDescription; |
| 96 { |
| 97 #if 1 |
| 98 return [NSString stringWithFormat:@"vmaddr: 0x%08x - 0x%08x [0x%08x], offset
: %d, flags: 0x%x (%@), nsects: %d, sections: %@", |
| 99 segmentCommand.vmaddr, segmentCommand.vmaddr + segmentComma
nd.vmsize - 1, segmentCommand.vmsize, segmentCommand.fileoff, |
| 100 [self flags], [self flagDescription], segmentCommand.nsects
, sections]; |
| 101 #endif |
| 102 return nil; |
| 103 } |
| 104 |
| 105 - (BOOL)containsAddress:(NSUInteger)address; |
| 106 { |
| 107 return (address >= segmentCommand.vmaddr) && (address < segmentCommand.vmadd
r + segmentCommand.vmsize); |
| 108 } |
| 109 |
| 110 - (void)appendToString:(NSMutableString *)resultString verbose:(BOOL)isVerbose; |
| 111 { |
| 112 [super appendToString:resultString verbose:isVerbose]; |
| 113 #if 0 |
| 114 |
| 115 [resultString appendFormat:@" segname %@\n", [self name]]; |
| 116 [resultString appendFormat:@" vmaddr 0x%08x\n", segmentCommand.vmaddr]; |
| 117 [resultString appendFormat:@" vmsize 0x%08x\n", segmentCommand.vmsize]; |
| 118 [resultString appendFormat:@" fileoff %d\n", segmentCommand.fileoff]; |
| 119 [resultString appendFormat:@" filesize %d\n", segmentCommand.filesize]; |
| 120 [resultString appendFormat:@" maxprot 0x%08x\n", segmentCommand.maxprot]; |
| 121 [resultString appendFormat:@" initprot 0x%08x\n", segmentCommand.initprot]; |
| 122 [resultString appendFormat:@" nsects %d\n", segmentCommand.nsects]; |
| 123 |
| 124 if (isVerbose) |
| 125 [resultString appendFormat:@" flags %@\n", [self flagDescription]]; |
| 126 else |
| 127 [resultString appendFormat:@" flags 0x%x\n", segmentCommand.flags]; |
| 128 #endif |
| 129 } |
| 130 |
| 131 @end |
OLD | NEW |