Skip to content

Commit

Permalink
Back to work on this!
Browse files Browse the repository at this point in the history
CDDataCursor gets updated to be more like STDataCursor (raising exception, returning actual values), but retaining the explicit width types.
keys.txt updated for current newclass script.
CDFile as superclass of CDFatFile and CDMachOFile (and eventually CDMachO64File).
Simplified where and how I select the target architecture.
  • Loading branch information
nygard committed Jun 17, 2009
1 parent 14504a8 commit c562fce
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 260 deletions.
6 changes: 3 additions & 3 deletions CDClassDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
CDTypeFormatter *methodTypeFormatter;
CDTypeFormatter *structDeclarationTypeFormatter;

NSString *preferredArchName;
NSString *targetArchName;
}

- (id)init;
Expand Down Expand Up @@ -84,8 +84,8 @@
- (NSArray *)machOFiles;
- (NSArray *)objCSegmentProcessors;

- (NSString *)preferredArchName;
- (void)setPreferredArchName:(NSString *)newArchName;
- (NSString *)targetArchName;
- (void)setTargetArchName:(NSString *)newArchName;

- (BOOL)containsObjectiveCSegments;
- (CDStructureTable *)structureTable;
Expand Down
81 changes: 11 additions & 70 deletions CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (id)init;
[structDeclarationTypeFormatter setDelegate:self]; // But need to ignore some things?

// These can be ppc, ppc7400, ppc64, i386, x86_64
preferredArchName = nil; // Any cpu type is fine.
targetArchName = nil;

flags.shouldShowHeader = YES;

Expand All @@ -83,7 +83,7 @@ - (void)dealloc;
if (flags.shouldMatchRegex == YES)
regfree(&compiledRegex);

[preferredArchName release];
[targetArchName release];

[super dealloc];
}
Expand Down Expand Up @@ -242,18 +242,19 @@ - (NSArray *)objCSegmentProcessors;
return objCSegmentProcessors;
}

- (NSString *)preferredArchName;
- (NSString *)targetArchName;
{
return preferredArchName;
return targetArchName;
}

- (void)setPreferredArchName:(NSString *)newArchName;
- (void)setTargetArchName:(NSString *)newArchName;
{
if (newArchName == preferredArchName)
NSLog(@"new: %@, old: %@", newArchName, targetArchName);
if (newArchName == targetArchName)
return;

[preferredArchName release];
preferredArchName = [newArchName retain];
[targetArchName release];
targetArchName = [newArchName retain];
}

- (BOOL)containsObjectiveCSegments;
Expand Down Expand Up @@ -334,7 +335,6 @@ - (BOOL)processFilename:(NSString *)aFilename;
- (BOOL)_processFilename:(NSString *)aFilename;
{
NSData *data;
CDFatFile *aFatFile;
CDMachOFile *aMachOFile;

data = [[NSData alloc] initWithContentsOfMappedFile:aFilename];
Expand All @@ -352,67 +352,8 @@ - (BOOL)_processFilename:(NSString *)aFilename;
}
[data release];

// TODO (2005-07-08): This isn't good enough. You only have your
// choice on the main file. Link frameworks MUST be the same
// architecture, either as a stand-alone Mach-O file or within a fat file.

// Initial combinations:
// 1. macho file, no cpu preference
// 2. macho file, cpu preference same as macho file
// 3. macho file, cpu preference different from macho file
// 4. fat file, no cpu preference
// 5. fat file, cpu preference contained in fat file
// 6. fat file, cpu preference not contained in fat file
//
// Actions:
// 1, 2, 4, 5: All subsequent files must be same cpu
// 3. Print message saying that arch isn't available in this macho file
// 6. Print message saying that arch isn't available in this fat file
//
// For linked frameworks/libraries, if the arch isn't available silently skip?

aFatFile = [[CDFatFile alloc] initWithFilename:aFilename];
if (aFatFile == nil) {
aMachOFile = [[CDMachOFile alloc] initWithFilename:aFilename];
if (aMachOFile == nil) {
fprintf(stderr, "class-dump: Input file (%s) is neither a Mach-O file nor a fat archive.\n", [aFilename fileSystemRepresentation]);
return NO;
}

if (preferredArchName == nil) {
[self setPreferredArchName:[aMachOFile archName]];
} else if ([[aMachOFile archName] isEqual:preferredArchName] == NO) {
fprintf(stderr, "class-dump: Mach-O file (%s) does not contain required cpu type: %@.\n",
[aFilename fileSystemRepresentation], [preferredArchName UTF8String]);
[aMachOFile release];
return NO;
}
} else {
CDFatArch *fatArch;

NSLog(@"aFatFile: %@", aFatFile);

fatArch = [aFatFile fatArchWithName:preferredArchName];
if (fatArch == nil) {
if (preferredArchName == nil)
fprintf(stderr, "class-dump: Fat archive (%s) did not contain any cpu types!\n", [aFilename fileSystemRepresentation]);
else
fprintf(stderr, "class-dump: Fat archive (%s) does not contain required cpu type: %s.\n",
[aFilename fileSystemRepresentation], [preferredArchName UTF8String]);
[aFatFile release];
return NO;
}

if (preferredArchName == nil) {
[self setPreferredArchName:[fatArch archName]];
}

aMachOFile = [[CDMachOFile alloc] initWithFilename:aFilename archiveOffset:[fatArch offset]];
[aFatFile release];

if (aMachOFile == nil)
return NO;
}
// We need to find the macho file with the target arch name, set it to aMachOFile
aMachOFile = nil;

[aMachOFile setDelegate:self];

Expand Down
34 changes: 24 additions & 10 deletions CDDataCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,35 @@ typedef NSUInteger CDByteOrder;
- (const void *)bytes;

- (NSUInteger)offset;
- (BOOL)seekToPosition:(NSUInteger)newOffset;
- (void)seekToPosition:(NSUInteger)newOffset;
- (void)advanceByLength:(NSUInteger)length;
- (NSUInteger)remaining;

- (BOOL)readLittleInt16:(uint16_t *)value;
- (BOOL)readLittleInt32:(uint32_t *)value;
- (uint8_t)readByte;

- (BOOL)readBigInt16:(uint16_t *)value;
- (BOOL)readBigInt32:(uint32_t *)value;
- (uint16_t)readLittleInt16;
- (uint32_t)readLittleInt32;
- (uint64_t)readLittleInt64;

- (uint16_t)readBigInt16;
- (uint32_t)readBigInt32;
- (uint64_t)readBigInt64;

- (float)readLittleFloat32;
- (float)readBigFloat32;

- (double)readLittleFloat64;
//- (double)readBigFloat64;

- (void)appendBytesOfLength:(NSUInteger)length intoData:(NSMutableData *)targetData;
- (BOOL)isAtEnd;

- (CDByteOrder)byteOrder;
- (void)setByteOrder:(CDByteOrder)newByteOrder;

- (BOOL)readInt16:(uint16_t *)value;
- (BOOL)readInt32:(uint32_t *)value;

- (BOOL)appendBytesOfLength:(NSUInteger)length intoData:(NSMutableData *)targetData;
- (NSData *)readDataWithLength:(NSUInteger)length;
// Read using the current byteOrder
- (uint16_t)readInt16;
- (uint32_t)readInt32;
- (uint64_t)readInt64;

@end
Loading

0 comments on commit c562fce

Please sign in to comment.