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 "CDLCDynamicSymbolTable.h" |
| 7 |
| 8 #import "CDFatFile.h" |
| 9 #import "CDMachOFile.h" |
| 10 #import "CDDataCursor.h" |
| 11 #import "CDRelocationInfo.h" |
| 12 |
| 13 @implementation CDLCDynamicSymbolTable |
| 14 |
| 15 - (id)initWithDataCursor:(CDDataCursor *)cursor machOFile:(CDMachOFile *)aMachOF
ile; |
| 16 { |
| 17 if ([super initWithDataCursor:cursor machOFile:aMachOFile] == nil) |
| 18 return nil; |
| 19 |
| 20 dysymtab.cmd = [cursor readInt32]; |
| 21 dysymtab.cmdsize = [cursor readInt32]; |
| 22 |
| 23 dysymtab.ilocalsym = [cursor readInt32]; |
| 24 dysymtab.nlocalsym = [cursor readInt32]; |
| 25 dysymtab.iextdefsym = [cursor readInt32]; |
| 26 dysymtab.nextdefsym = [cursor readInt32]; |
| 27 dysymtab.iundefsym = [cursor readInt32]; |
| 28 dysymtab.nundefsym = [cursor readInt32]; |
| 29 dysymtab.tocoff = [cursor readInt32]; |
| 30 dysymtab.ntoc = [cursor readInt32]; |
| 31 dysymtab.modtaboff = [cursor readInt32]; |
| 32 dysymtab.nmodtab = [cursor readInt32]; |
| 33 dysymtab.extrefsymoff = [cursor readInt32]; |
| 34 dysymtab.nextrefsyms = [cursor readInt32]; |
| 35 dysymtab.indirectsymoff = [cursor readInt32]; |
| 36 dysymtab.nindirectsyms = [cursor readInt32]; |
| 37 dysymtab.extreloff = [cursor readInt32]; |
| 38 dysymtab.nextrel = [cursor readInt32]; |
| 39 dysymtab.locreloff = [cursor readInt32]; |
| 40 dysymtab.nlocrel = [cursor readInt32]; |
| 41 #if 0 |
| 42 NSLog(@"ilocalsym: 0x%08x %d", dysymtab.ilocalsym, dysymtab.ilocalsym)
; |
| 43 NSLog(@"nlocalsym: 0x%08x %d", dysymtab.nlocalsym, dysymtab.nlocalsym)
; |
| 44 NSLog(@"iextdefsym: 0x%08x %d", dysymtab.iextdefsym, dysymtab.iextdefsy
m); |
| 45 NSLog(@"nextdefsym: 0x%08x %d", dysymtab.nextdefsym, dysymtab.nextdefsy
m); |
| 46 NSLog(@"iundefsym: 0x%08x %d", dysymtab.iundefsym, dysymtab.iundefsym)
; |
| 47 NSLog(@"nundefsym: 0x%08x %d", dysymtab.nundefsym, dysymtab.nundefsym)
; |
| 48 |
| 49 NSLog(@"tocoff: 0x%08x %d", dysymtab.tocoff, dysymtab.tocoff); |
| 50 NSLog(@"ntoc: 0x%08x %d", dysymtab.ntoc, dysymtab.ntoc); |
| 51 NSLog(@"modtaboff: 0x%08x %d", dysymtab.modtaboff, dysymtab.modtaboff)
; |
| 52 NSLog(@"nmodtab: 0x%08x %d", dysymtab.nmodtab, dysymtab.nmodtab); |
| 53 |
| 54 NSLog(@"extrefsymoff: 0x%08x %d", dysymtab.extrefsymoff, dysymtab.extrefs
ymoff); |
| 55 NSLog(@"nextrefsyms: 0x%08x %d", dysymtab.nextrefsyms, dysymtab.nextrefs
yms); |
| 56 NSLog(@"indirectsymoff: 0x%08x %d", dysymtab.indirectsymoff, dysymtab.indir
ectsymoff); |
| 57 NSLog(@"nindirectsyms: 0x%08x %d", dysymtab.nindirectsyms, dysymtab.nindir
ectsyms); |
| 58 |
| 59 NSLog(@"extreloff: 0x%08x %d", dysymtab.extreloff, dysymtab.extreloff)
; |
| 60 NSLog(@"nextrel: 0x%08x %d", dysymtab.nextrel, dysymtab.nextrel); |
| 61 NSLog(@"locreloff: 0x%08x %d", dysymtab.locreloff, dysymtab.locreloff)
; |
| 62 NSLog(@"nlocrel: 0x%08x %d", dysymtab.nlocrel, dysymtab.nlocrel); |
| 63 #endif |
| 64 |
| 65 externalRelocationEntries = [[NSMutableArray alloc] init]; |
| 66 |
| 67 return self; |
| 68 } |
| 69 |
| 70 - (void)dealloc; |
| 71 { |
| 72 [externalRelocationEntries release]; |
| 73 |
| 74 [super dealloc]; |
| 75 } |
| 76 |
| 77 - (uint32_t)cmd; |
| 78 { |
| 79 return dysymtab.cmd; |
| 80 } |
| 81 |
| 82 - (uint32_t)cmdsize; |
| 83 { |
| 84 return dysymtab.cmdsize; |
| 85 } |
| 86 |
| 87 - (void)loadSymbols; |
| 88 { |
| 89 CDDataCursor *cursor; |
| 90 uint32_t index; |
| 91 |
| 92 cursor = [[CDDataCursor alloc] initWithData:[nonretained_machOFile data]]; |
| 93 [cursor setByteOrder:[nonretained_machOFile byteOrder]]; |
| 94 |
| 95 //NSLog(@"indirectsymoff: %lu", dysymtab.indirectsymoff); |
| 96 //NSLog(@"nindirectsyms: %lu", dysymtab.nindirectsyms); |
| 97 #if 0 |
| 98 [cursor setOffset:[nonretained_machOFile offset] + dysymtab.indirectsymoff]; |
| 99 for (index = 0; index < dysymtab.nindirectsyms; index++) { |
| 100 uint32_t val; |
| 101 |
| 102 // From loader.h: An indirect symbol table entry is simply a 32bit index
into the symbol table to the symbol that the pointer or stub is referring to. |
| 103 val = [cursor readInt32]; |
| 104 NSLog(@"%3u: %08x (%u)", index, val, val); |
| 105 } |
| 106 #endif |
| 107 |
| 108 //NSLog(@"extreloff: %lu", dysymtab.extreloff); |
| 109 //NSLog(@"nextrel: %lu", dysymtab.nextrel); |
| 110 |
| 111 [cursor setOffset:[nonretained_machOFile offset] + dysymtab.extreloff]; |
| 112 //NSLog(@" address val symbolnum pcrel len ext type"); |
| 113 //NSLog(@"--- -------- -------- --------- ----- --- --- ----"); |
| 114 for (index = 0; index < dysymtab.nextrel; index++) { |
| 115 struct relocation_info rinfo; |
| 116 uint32_t val; |
| 117 CDRelocationInfo *ri; |
| 118 |
| 119 rinfo.r_address = [cursor readInt32]; |
| 120 val = [cursor readInt32]; |
| 121 // TODO (2009-06-25): Make sure this works on PPC. |
| 122 rinfo.r_symbolnum = val & 0x00ffffff; |
| 123 rinfo.r_pcrel = (val & 0x01000000) >> 24; |
| 124 rinfo.r_length = (val & 0x06000000) >> 25; |
| 125 rinfo.r_extern = (val & 0x08000000) >> 27; |
| 126 rinfo.r_type = (val & 0xf0000000) >> 28; |
| 127 #if 0 |
| 128 NSLog(@"%3d: %08x %08x %08x %01x %01x %01x %01x", inde
x, rinfo.r_address, val, |
| 129 rinfo.r_symbolnum, rinfo.r_pcrel, rinfo.r_length, rinfo.r_extern,
rinfo.r_type); |
| 130 #endif |
| 131 |
| 132 ri = [[CDRelocationInfo alloc] initWithInfo:rinfo]; |
| 133 [externalRelocationEntries addObject:ri]; |
| 134 [ri release]; |
| 135 } |
| 136 |
| 137 //NSLog(@"externalRelocationEntries: %@", externalRelocationEntries); |
| 138 |
| 139 // r_address is purported to be the offset from the vmaddr of the first segm
ent, but... |
| 140 // It seems to be from the first segment with r/w initprot. |
| 141 |
| 142 // it appears to be the offset from the vmaddr of the 3rd segment in t1s. |
| 143 // Actually, it really seems to be the offset from the vmaddr of the section
indicated in the n_desc part of the nlist. |
| 144 // 0000000000000000 01 00 0500 0000000000000038 _OBJC_CLASS_$_NSObject |
| 145 // GET_LIBRARY_ORDINAL() from nlist.h for library. |
| 146 |
| 147 [cursor release]; |
| 148 } |
| 149 |
| 150 // Just search for externals. |
| 151 - (CDRelocationInfo *)relocationEntryWithOffset:(NSUInteger)offset; |
| 152 { |
| 153 for (CDRelocationInfo *info in externalRelocationEntries) { |
| 154 if ([info isExtern] && [info offset] == offset) { |
| 155 return info; |
| 156 } |
| 157 } |
| 158 |
| 159 return nil; |
| 160 } |
| 161 |
| 162 @end |
OLD | NEW |