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 "CDMachO32File.h" |
| 7 |
| 8 #import "CDObjectiveC1Processor.h" |
| 9 #import "CDObjectiveC2Processor32.h" |
| 10 |
| 11 @implementation CDMachO32File |
| 12 |
| 13 - (id)initWithData:(NSData *)someData offset:(NSUInteger)anOffset filename:(NSSt
ring *)aFilename searchPathState:(CDSearchPathState *)aSearchPathState; |
| 14 { |
| 15 CDDataCursor *cursor; |
| 16 |
| 17 if ([super initWithData:someData offset:anOffset filename:aFilename searchPa
thState:aSearchPathState] == nil) |
| 18 return nil; |
| 19 |
| 20 cursor = [[CDDataCursor alloc] initWithData:someData]; |
| 21 //NSLog(@"CDMachO32File - setting offset to %08x", offset); |
| 22 [cursor setOffset:offset]; |
| 23 header.magic = [cursor readLittleInt32]; |
| 24 |
| 25 //NSLog(@"(testing macho 32) magic: 0x%x", header.magic); |
| 26 if (header.magic == MH_MAGIC) { |
| 27 byteOrder = CDByteOrderLittleEndian; |
| 28 } else if (header.magic == MH_CIGAM) { |
| 29 byteOrder = CDByteOrderBigEndian; |
| 30 } else { |
| 31 [cursor release]; |
| 32 [self release]; |
| 33 return nil; |
| 34 } |
| 35 |
| 36 //NSLog(@"byte order: %d", byteOrder); |
| 37 [cursor setByteOrder:byteOrder]; |
| 38 |
| 39 header.cputype = [cursor readInt32]; |
| 40 //NSLog(@"cputype: 0x%08x", header.cputype); |
| 41 |
| 42 header.cpusubtype = [cursor readInt32]; |
| 43 header.filetype = [cursor readInt32]; |
| 44 header.ncmds = [cursor readInt32]; |
| 45 header.sizeofcmds = [cursor readInt32]; |
| 46 header.flags = [cursor readInt32]; |
| 47 |
| 48 //NSLog(@"cpusubtype: 0x%08x", header.cpusubtype); |
| 49 //NSLog(@"filetype: 0x%08x", header.filetype); |
| 50 //NSLog(@"ncmds: %u", header.ncmds); |
| 51 //NSLog(@"sizeofcmds: %u", header.sizeofcmds); |
| 52 //NSLog(@"flags: 0x%08x", header.flags); |
| 53 |
| 54 _flags.uses64BitABI = CDArchUses64BitABI((CDArch){ .cputype = header.cputype
, .cpusubtype = header.cpusubtype }); |
| 55 header.cputype &= ~CPU_ARCH_MASK; |
| 56 |
| 57 [self _readLoadCommands:cursor count:header.ncmds]; |
| 58 |
| 59 return self; |
| 60 } |
| 61 |
| 62 - (uint32_t)magic; |
| 63 { |
| 64 return header.magic; |
| 65 } |
| 66 |
| 67 - (cpu_type_t)cputype; |
| 68 { |
| 69 return header.cputype; |
| 70 } |
| 71 |
| 72 - (cpu_subtype_t)cpusubtype; |
| 73 { |
| 74 return header.cpusubtype; |
| 75 } |
| 76 |
| 77 - (uint32_t)filetype; |
| 78 { |
| 79 return header.filetype; |
| 80 } |
| 81 |
| 82 - (uint32_t)flags; |
| 83 { |
| 84 return header.flags; |
| 85 } |
| 86 |
| 87 - (BOOL)bestMatchForLocalArch:(CDArch *)archPtr; |
| 88 { |
| 89 if (archPtr != NULL) { |
| 90 archPtr->cputype = header.cputype; |
| 91 archPtr->cpusubtype = header.cpusubtype; |
| 92 } |
| 93 |
| 94 return YES; |
| 95 } |
| 96 |
| 97 - (Class)processorClass; |
| 98 { |
| 99 if ([self hasObjectiveC2Data]) |
| 100 return [CDObjectiveC2Processor32 class]; |
| 101 |
| 102 return [CDObjectiveC1Processor class]; |
| 103 } |
| 104 |
| 105 @end |
OLD | NEW |