Skip to content

Commit

Permalink
Need to set up the byte ordering for all these data cursors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nygard committed Jun 30, 2009
1 parent ebae7f3 commit df60c66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CDMachOFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ - (NSUInteger)dataOffsetForAddress:(NSUInteger)address segmentName:(NSString *)a

segment = [self segmentContainingAddress:address];
if (segment == nil) {
NSLog(@"Error: Cannot find offset for address 0x%08x in dataOffsetForAddress:", address);
NSLog(@"Error: Cannot find offset for address 0x%08lx in dataOffsetForAddress:", address);
exit(5);
return 0;
}

if (aSegmentName != nil && [[segment name] isEqual:aSegmentName] == NO) {
// This can happen with the symtab in a module. In one case, the symtab is in __DATA, __bss, in the zero filled area.
// i.e. section offset is 0.
if (debug) NSLog(@"Note: Couldn't find address in specified segment (%08x, %@)", address, aSegmentName);
if (debug) NSLog(@"Note: Couldn't find address in specified segment (%08lx, %@)", address, aSegmentName);
//NSLog(@"\tsegment was: %@", segment);
//exit(5);
return 0;
Expand Down
12 changes: 6 additions & 6 deletions CDObjectiveC2Processor32.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (void)loadProtocols;
sectionData = [section data];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO)
[self protocolAtAddress:[cursor readInt32]];
[cursor release];
Expand All @@ -54,22 +55,21 @@ - (void)loadClasses;
segment = [machOFile segmentWithName:@"__DATA"];
section = [segment sectionWithName:@"__objc_classlist"];
sectionData = [section data];
[sectionData writeToFile:@"/tmp/classes.dat" atomically:NO];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO) {
uint32_t val;
CDOCClass *aClass;

//NSLog(@"----------------------------------------------------------------------");
val = [cursor readInt32];
//NSLog(@"class @ %08x", val);
aClass = [self loadClassAtAddress:val];
if (aClass != nil) {
[classes addObject:aClass];
[classesByAddress setObject:aClass forKey:[NSNumber numberWithUnsignedInteger:val]];
}
}

[cursor release];
}

Expand All @@ -85,13 +85,16 @@ - (void)loadCategories;
sectionData = [section data];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO) {
CDOCCategory *category;

category = [self loadCategoryAtAddress:[cursor readInt32]];
if (category != nil)
[categories addObject:category];
}

[cursor release];
}

- (CDOCProtocol *)protocolAtAddress:(uint32_t)address;
Expand Down Expand Up @@ -248,7 +251,6 @@ - (CDOCClass *)loadClassAtAddress:(uint32_t)address;
objc2Class.reserved1 = [cursor readInt32];
objc2Class.reserved2 = [cursor readInt32];
objc2Class.reserved3 = [cursor readInt32];
//NSLog(@"objc2Class 32");
//NSLog(@"%08lx %08lx %08lx %08lx", objc2Class.isa, objc2Class.superclass, objc2Class.cache, objc2Class.vtable);
//NSLog(@"%08lx %08lx %08lx %08lx", objc2Class.data, objc2Class.reserved1, objc2Class.reserved2, objc2Class.reserved3);

Expand All @@ -268,7 +270,6 @@ - (CDOCClass *)loadClassAtAddress:(uint32_t)address;
objc2ClassData.weakIvarLayout = [cursor readInt32];
objc2ClassData.baseProperties = [cursor readInt32];

//NSLog(@"objc2ClassData 32");
//NSLog(@"%08x %08x %08x %08x", objc2ClassData.flags, objc2ClassData.instanceStart, objc2ClassData.instanceSize, objc2ClassData.reserved);

//NSLog(@"%08lx %08lx %08lx %08lx", objc2ClassData.ivarLayout, objc2ClassData.name, objc2ClassData.baseMethods, objc2ClassData.baseProtocols);
Expand Down Expand Up @@ -416,7 +417,6 @@ - (NSArray *)loadMethodsAtAddress:(uint32_t)address;

listHeader.entsize = [cursor readInt32];
listHeader.count = [cursor readInt32];
//NSLog(@"entsize: %u", listHeader.entsize);
NSParameterAssert(listHeader.entsize == 12);

for (index = 0; index < listHeader.count; index++) {
Expand Down
6 changes: 6 additions & 0 deletions CDObjectiveC2Processor64.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (void)loadProtocols;
sectionData = [section data];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO)
[self protocolAtAddress:[cursor readInt64]];
[cursor release];
Expand All @@ -56,6 +57,7 @@ - (void)loadClasses;
sectionData = [section data];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO) {
uint64_t val;
CDOCClass *aClass;
Expand All @@ -67,6 +69,7 @@ - (void)loadClasses;
[classesByAddress setObject:aClass forKey:[NSNumber numberWithUnsignedInteger:val]];
}
}

[cursor release];
}

Expand All @@ -82,13 +85,16 @@ - (void)loadCategories;
sectionData = [section data];

cursor = [[CDDataCursor alloc] initWithData:sectionData];
[cursor setByteOrder:[machOFile byteOrder]];
while ([cursor isAtEnd] == NO) {
CDOCCategory *category;

category = [self loadCategoryAtAddress:[cursor readInt64]];
if (category != nil)
[categories addObject:category];
}

[cursor release];
}

- (CDOCProtocol *)protocolAtAddress:(uint64_t)address;
Expand Down
2 changes: 1 addition & 1 deletion Tests/doTests
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ echo "Starting tests at `date`"

ls -ld /System/Library/Frameworks/*.framework /System/Library/PrivateFrameworks/*.framework /Applications/*.app /Applications/*/*.app /Applications/Utilities/*.app /Developer/Applications/*.app /Developer/Applications/*/*.app ~/Applications/*.app ~/Applications/*.app /Volumes/BigData/TestApplications/*.app | wc

mkdir $TESTDIR $TESTDIR_OLD $TESTDIR_NEW $TESTDIR_NEW_32 $TESTDIR_NEW_64
mkdir $TESTDIR $TESTDIR_OLD $TESTDIR_NEW

# arch = none check for FWAVCPrivate.framework, KAdminClient, Kernel, SyndicationUI

Expand Down

0 comments on commit df60c66

Please sign in to comment.