Skip to content

Commit

Permalink
The --list-arches option now lists unknown architectures as two hex n…
Browse files Browse the repository at this point in the history
…umbers separated by a colon, instead of "unknown", so this

can be used by the --arch command.  i.e. 0xc:0x6.  Can also use c:6.  This lets the testing script go through the iPhone
frameworks.
  • Loading branch information
nygard committed Jun 30, 2009
1 parent 16906dc commit c60e3d7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ - (BOOL)loadFile:(CDFile *)aFile;
//NSLog(@"targetArch: (%08x, %08x)", targetArch.cputype, targetArch.cpusubtype);
aMachOFile = [aFile machOFileWithArch:targetArch];
//NSLog(@"aMachOFile: %@", aMachOFile);
if (aMachOFile == nil) {
fprintf(stderr, "Error: file doesn't contain the specified arch.\n\n");
return NO;
}

if ([self shouldProcessRecursively]) {
@try {
Expand Down
1 change: 1 addition & 0 deletions CDFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef struct {
@class CDMachOFile;

extern NSString *CDNameForCPUType(cpu_type_t cputype, cpu_subtype_t cpusubtype);
extern CDArch CDArchFromName(NSString *name);

@interface CDFile : NSObject
{
Expand Down
38 changes: 37 additions & 1 deletion CDFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,47 @@

archInfo = NXGetArchInfoFromCpuType(cputype, cpusubtype);
if (archInfo == NULL)
return @"unknown";
return [NSString stringWithFormat:@"0x%x:0x%x", cputype, cpusubtype];

return [NSString stringWithUTF8String:archInfo->name];
}

CDArch CDArchFromName(NSString *name)
{
const NXArchInfo *archInfo;
CDArch arch;

arch.cputype = CPU_TYPE_ANY;
arch.cpusubtype = 0;

if (name == nil)
return arch;

archInfo = NXGetArchInfoFromName([name UTF8String]);
if (archInfo == NULL) {
NSScanner *scanner;
NSString *ignore;

scanner = [[NSScanner alloc] initWithString:name];
if ([scanner scanHexInt:(uint32_t *)&arch.cputype]
&& [scanner scanString:@":" intoString:&ignore]
&& [scanner scanHexInt:(uint32_t *)&arch.cpusubtype]) {
// Great!
//NSLog(@"scanned 0x%08x : 0x%08x from '%@'", arch.cputype, arch.cpusubtype, name);
} else {
arch.cputype = CPU_TYPE_ANY;
arch.cpusubtype = 0;
}

[scanner release];
} else {
arch.cputype = archInfo->cputype;
arch.cpusubtype = archInfo->cpusubtype;
}

return arch;
}

@implementation CDFile

+ (id)fileWithData:(NSData *)someData;
Expand Down
6 changes: 5 additions & 1 deletion Tests/doTests
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ OLD_CD=~/Unix/bin/class-dump-3.1.2
NEW_CD=/Local/nygard/Products/Debug/class-dump

# Must be a version that supports --list-arches
ARCH_CD=~/Unix/bin/class-dump-3.1.2
ARCH_CD=/Local/nygard/Products/Debug/class-dump

FRAMEWORKS=(/System/Library/Frameworks/*.framework /System/Library/PrivateFrameworks/*.framework /Developer/Library/Frameworks/*.framework /Developer/Library/PrivateFrameworks/*.framework)
APPS=(/Applications/*.app /Applications/*/*.app /Applications/Utilities/*.app /Developer/Applications/*.app /Developer/Applications/*/*.app ~/Applications/*.app ~/Applications/*.app)
#/Volumes/BigData/TestApplications/*.app

# Uncomment these to just do iPhone frameowoks
FRAMEWORKS=(/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/*.framework /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/*.framework)
APPS=()

echo "Starting tests at `date`"

echo " Framework count: " `ls -ld $FRAMEWORKS | wc -l`
Expand Down
13 changes: 6 additions & 7 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ int main(int argc, char *argv[])
while ( (ch = getopt_long(argc, argv, "aAC:f:HIo:rRsSt", longopts, NULL)) != -1) {
switch (ch) {
case CD_OPT_ARCH: {
const NXArchInfo *archInfo;
NSString *name;

archInfo = NXGetArchInfoFromName(optarg);
if (archInfo == NULL) {
name = [NSString stringWithUTF8String:optarg];
targetArch = CDArchFromName(name);
if (targetArch.cputype != CPU_TYPE_ANY)
hasSpecifiedArch = YES;
else {
fprintf(stderr, "Error: Unknown arch %s\n\n", optarg);
errorFlag = YES;
} else {
targetArch.cputype = archInfo->cputype;
targetArch.cpusubtype = archInfo->cpusubtype;
hasSpecifiedArch = YES;
}
break;
}
Expand Down

0 comments on commit c60e3d7

Please sign in to comment.