Browse files

Changed version to 3.1.3 dev. Added CDDataCursor. Changed project to …

…Xcode 3.1 format, and target to 10.5. Experimenting with different

way for reading files, starting with CDFatFile.
  • Loading branch information...
1 parent e4aaa98 commit 71d728fea9d104561388c4786b7a652ffa60e0d0 @nygard nygard committed May 6, 2008
Showing with 211 additions and 18 deletions.
  1. +1 −1 CDClassDump.h
  2. +12 −0 CDClassDump.m
  3. +32 −0 CDDataCursor.h
  4. +143 −0 CDDataCursor.m
  5. +2 −3 CDFatFile.h
  6. +11 −10 CDFatFile.m
  7. +10 −4 class-dump.xcodeproj/project.pbxproj
View
2 CDClassDump.h
@@ -9,7 +9,7 @@
#include <regex.h>
#import "CDStructureRegistrationProtocol.h"
-#define CLASS_DUMP_VERSION @"3.1.2"
+#define CLASS_DUMP_VERSION @"3.1.3 dev"
@class NSMutableArray, NSMutableDictionary, NSMutableSet, NSMutableString, NSString;
@class CDDylibCommand, CDMachOFile;
View
12 CDClassDump.m
@@ -333,9 +333,19 @@ - (BOOL)processFilename:(NSString *)aFilename;
// Return YES if successful, NO if there was an error.
- (BOOL)_processFilename:(NSString *)aFilename;
{
+ NSData *data;
CDFatFile *aFatFile;
CDMachOFile *aMachOFile;
+ data = [[NSData alloc] initWithContentsOfMappedFile:aFilename];
+ {
+ CDFatFile *f1;
+
+ f1 = [[CDFatFile alloc] initWithData:data];
+ NSLog(@"f1: %@", f1);
+ [f1 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.
@@ -374,6 +384,8 @@ - (BOOL)_processFilename:(NSString *)aFilename;
} else {
CDFatArch *fatArch;
+ NSLog(@"aFatFile: %@", aFatFile);
+
fatArch = [aFatFile fatArchWithName:preferredArchName];
if (fatArch == nil) {
if (preferredArchName == nil)
View
32 CDDataCursor.h
@@ -0,0 +1,32 @@
+// -*- mode: ObjC -*-
+
+// This file is part of __APPNAME__, __SHORT_DESCRIPTION__.
+// Copyright (C) 2008 __OWNER__. All rights reserved.
+
+#import <Foundation/Foundation.h>
+
+@interface CDDataCursor : NSObject
+{
+ NSData *data;
+ NSUInteger offset;
+}
+
+- (id)initWithData:(NSData *)someData;
+- (void)dealloc;
+
+- (NSData *)data;
+- (const void *)bytes;
+
+- (NSUInteger)offset;
+- (BOOL)seekToPosition:(NSUInteger)newOffset;
+
+- (BOOL)readLittleInt16:(unsigned short *)value;
+- (BOOL)readLittleInt32:(unsigned int *)value;
+
+- (BOOL)readBigInt16:(unsigned short *)value;
+- (BOOL)readBigInt32:(unsigned int *)value;
+
+- (BOOL)appendBytesOfLength:(NSUInteger)length intoData:(NSMutableData *)targetData;
+- (NSData *)readDataWithLength:(NSUInteger)length;
+
+@end
View
143 CDDataCursor.m
@@ -0,0 +1,143 @@
+// This file is part of __APPNAME__, __SHORT_DESCRIPTION__.
+// Copyright (C) 2008 __OWNER__. All rights reserved.
+
+#import "CDDataCursor.h"
+
+@implementation CDDataCursor
+
+- (id)initWithData:(NSData *)someData;
+{
+ if ([super init] == nil)
+ return nil;
+
+ data = [someData retain];
+ offset = 0;
+
+ return self;
+}
+
+- (void)dealloc;
+{
+ [data release];
+
+ [super dealloc];
+}
+
+- (NSData *)data;
+{
+ return data;
+}
+
+- (const void *)bytes;
+{
+ return [data bytes];
+}
+
+- (NSUInteger)offset;
+{
+ return offset;
+}
+
+// Return NO on failure.
+- (BOOL)seekToPosition:(NSUInteger)newOffset;
+{
+ if (newOffset <= [data length]) {
+ offset = newOffset;
+ return YES;
+ }
+
+ NSLog(@"Trying to seek past end.");
+ return NO;
+}
+
+// Return NO on failure.
+- (BOOL)readLittleInt16:(unsigned short *)value;
+{
+ if (offset + sizeof(unsigned short) <= [data length]) {
+ if (value != NULL)
+ *value = OSReadLittleInt16([data bytes], offset);
+ offset += sizeof(unsigned short);
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ return NO;
+ }
+
+ return YES;
+}
+
+// Return NO on failure.
+- (BOOL)readLittleInt32:(unsigned int *)value;
+{
+ if (offset + sizeof(unsigned int) <= [data length]) {
+ if (value != NULL)
+ *value = OSReadLittleInt32([data bytes], offset);
+ offset += sizeof(unsigned int);
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ return NO;
+ }
+
+ return YES;
+}
+
+// Return NO on failure.
+- (BOOL)readBigInt16:(unsigned short *)value;
+{
+ if (offset + sizeof(unsigned short) <= [data length]) {
+ if (value != NULL)
+ *value = OSReadBigInt16([data bytes], offset);
+ offset += sizeof(unsigned short);
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ return NO;
+ }
+
+ return YES;
+}
+
+// Return NO on failure.
+- (BOOL)readBigInt32:(unsigned int *)value;
+{
+ if (offset + sizeof(unsigned int) <= [data length]) {
+ if (value != NULL)
+ *value = OSReadBigInt32([data bytes], offset);
+ offset += sizeof(unsigned int);
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ return NO;
+ }
+
+ return YES;
+}
+
+// Return NO on failure.
+- (BOOL)appendBytesOfLength:(NSUInteger)length intoData:(NSMutableData *)targetData;
+{
+ if (offset + length <= [data length]) {
+ [targetData appendBytes:([self bytes] + offset) length:length];
+ offset += length;
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ return NO;
+ }
+
+ return YES;
+}
+
+// Return nil on failure.
+- (NSData *)readDataWithLength:(NSUInteger)length;
+{
+ NSData *result = nil;
+
+ if (offset + length <= [data length]) {
+ // No copy didn't work... alignment problems. Let's not worry about efficiency for now.
+ result = [NSData dataWithBytes:([self bytes] + offset) length:length];
+ offset += length;
+ } else {
+ NSLog(@"%s, Trying to read past end.", _cmd);
+ }
+
+ return result;
+}
+
+@end
View
5 CDFatFile.h
@@ -19,19 +19,18 @@
@interface CDFatFile : NSObject
{
- NSString *filename;
NSData *data;
struct fat_header header;
NSMutableArray *arches;
}
+- (id)initWithData:(NSData *)someData;
+
- (id)initWithFilename:(NSString *)aFilename;
- (void)dealloc;
- (void)_processFatArchesWithPointer:(const void *)ptr swapBytes:(BOOL)shouldSwapBytes;
-- (NSString *)filename;
-
- (unsigned int)fatCount;
- (CDFatArch *)fatArchWithName:(NSString *)archName;
View
21 CDFatFile.m
@@ -14,6 +14,14 @@
@implementation CDFatFile
+- (id)initWithData:(NSData *)someData;
+{
+ if ([super init] == nil)
+ return nil;
+
+ return self;
+}
+
- (id)initWithFilename:(NSString *)aFilename;
{
BOOL shouldSwapBytes;
@@ -22,11 +30,10 @@ - (id)initWithFilename:(NSString *)aFilename;
return nil;
shouldSwapBytes = NO;
- filename = [aFilename retain];
- data = [[NSData alloc] initWithContentsOfMappedFile:filename];
+ data = [[NSData alloc] initWithContentsOfMappedFile:aFilename];
if (data == nil) {
- NSLog(@"Couldn't read file: %@", filename);
+ NSLog(@"Couldn't read file: %@", aFilename);
[self release];
return nil;
}
@@ -50,7 +57,6 @@ - (id)initWithFilename:(NSString *)aFilename;
- (void)dealloc;
{
- [filename release];
[data release];
[arches release];
@@ -72,11 +78,6 @@ - (void)_processFatArchesWithPointer:(const void *)ptr swapBytes:(BOOL)shouldSwa
}
}
-- (NSString *)filename;
-{
- return filename;
-}
-
- (unsigned int)fatCount;
{
return header.nfat_arch;
@@ -131,7 +132,7 @@ - (CDFatArch *)localArchitecture;
- (NSString *)description;
{
- return [NSString stringWithFormat:@"[%p]CDFatFile with %u arches", self, [self fatCount]];
+ return [NSString stringWithFormat:@"[%p] CDFatFile with %u arches", self, [self fatCount]];
#if 0
return [NSString stringWithFormat:@"magic: 0x%08x, cputype: %d, cpusubtype: %d, filetype: %d, ncmds: %d, sizeofcmds: %d, flags: 0x%x",
header.magic, header.cputype, header.cpusubtype, header.filetype, header.ncmds, header.sizeofcmds, header.flags];
View
14 class-dump.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 42;
+ objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
@@ -201,6 +201,7 @@
013182FD0CDF6EE400EC5A2C /* CDTypeFormatterUnitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 012E2B7D08AE9E45003E99F8 /* CDTypeFormatterUnitTest.m */; };
013182FE0CDF6EE400EC5A2C /* CDStructHandlingUnitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 012E2B7B08AE9E45003E99F8 /* CDStructHandlingUnitTest.m */; };
013182FF0CDF6EE400EC5A2C /* NSError-CDExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0114EE6C0CDCC4880061F80F /* NSError-CDExtensions.m */; };
+ 017F9C9A0DD0F66400EC8D0A /* CDDataCursor.m in Sources */ = {isa = PBXBuildFile; fileRef = 017F9C990DD0F66400EC8D0A /* CDDataCursor.m */; };
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
/* End PBXBuildFile section */
@@ -333,6 +334,8 @@
012FF18A0CDB886C00F31E61 /* CDUnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
012FF18B0CDB886C00F31E61 /* CDUnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CDUnitTests-Info.plist"; sourceTree = "<group>"; };
013183060CDF6EE400EC5A2C /* CDUnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDUnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 017F9C980DD0F66400EC8D0A /* CDDataCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDDataCursor.h; sourceTree = "<group>"; };
+ 017F9C990DD0F66400EC8D0A /* CDDataCursor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDDataCursor.m; sourceTree = "<group>"; };
01A905F30ADDF11000DAEDBA /* CDTypeLexerUnitTest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = CDTypeLexerUnitTest.h; path = UnitTests/CDTypeLexerUnitTest.h; sourceTree = "<group>"; };
01A905F40ADDF11000DAEDBA /* CDTypeLexerUnitTest.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = CDTypeLexerUnitTest.m; path = UnitTests/CDTypeLexerUnitTest.m; sourceTree = "<group>"; };
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
@@ -398,6 +401,8 @@
011262420C218CAD00B9C4E0 /* CDMultiFileVisitor.m */,
011262580C21909400B9C4E0 /* CDTextClassDumpVisitor.h */,
011262590C21909400B9C4E0 /* CDTextClassDumpVisitor.m */,
+ 017F9C980DD0F66400EC8D0A /* CDDataCursor.h */,
+ 017F9C990DD0F66400EC8D0A /* CDDataCursor.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -656,7 +661,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 012E2A9408AE9B4F003E99F8 /* Build configuration list for PBXProject "class-dump" */;
- compatibilityVersion = "Xcode 2.4";
+ compatibilityVersion = "Xcode 3.1";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* class-dump */;
projectDirPath = "";
@@ -928,6 +933,7 @@
011262450C218CAD00B9C4E0 /* CDMultiFileVisitor.m in Sources */,
0112625C0C21909400B9C4E0 /* CDTextClassDumpVisitor.m in Sources */,
0114EE6E0CDCC4880061F80F /* NSError-CDExtensions.m in Sources */,
+ 017F9C9A0DD0F66400EC8D0A /* CDDataCursor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -980,15 +986,15 @@
isa = XCBuildConfiguration;
buildSettings = {
MACOSX_DEPLOYMENT_TARGET = 10.4;
- SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
+ SDKROOT = macosx10.5;
};
name = Debug;
};
012E2A9608AE9B4F003E99F8 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
MACOSX_DEPLOYMENT_TARGET = 10.4;
- SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
+ SDKROOT = macosx10.5;
};
name = Release;
};

0 comments on commit 71d728f

Please sign in to comment.