Skip to content

Commit

Permalink
Working on the visitor classes and CDSearchPathState.
Browse files Browse the repository at this point in the history
- use properties
- rearranged some methods in implementations
- made some methods and properties private to particular classes
- renamed parameters to get rid of a/an/some prefixes
- renamed findString to searchString
  • Loading branch information
nygard committed Feb 24, 2012
1 parent 2d196e6 commit 801207f
Show file tree
Hide file tree
Showing 19 changed files with 355 additions and 371 deletions.
47 changes: 23 additions & 24 deletions Source/CDClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (void)willBeginVisiting;
[self.classDump appendHeaderToString:self.resultString];

if (self.classDump.hasObjectiveCRuntimeInfo) {
[[self.classDump typeController] appendStructuresToString:self.resultString symbolReferences:nil];
[self.classDump.typeController appendStructuresToString:self.resultString symbolReferences:nil];
}
}

Expand All @@ -45,27 +45,26 @@ - (void)didEndVisiting;
[self writeResultToStandardOutput];
}

- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;
{
CDMachOFile *machOFile = [aProcessor machOFile];
CDMachOFile *machOFile = processor.machOFile;

[self.resultString appendString:@"#pragma mark -\n\n"];
[self.resultString appendString:@"/*\n"];
[self.resultString appendFormat:@" * File: %@\n", [machOFile filename]];
[self.resultString appendFormat:@" * UUID: %@\n", [machOFile uuidString]];
[self.resultString appendFormat:@" * File: %@\n", machOFile.filename];
[self.resultString appendFormat:@" * UUID: %@\n", machOFile.uuidString];

const NXArchInfo *archInfo = NXGetArchInfoFromCpuType([machOFile cputypePlusArchBits], [machOFile cpusubtype]);
//archInfo = [machOFile archInfo];
const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(machOFile.cputypePlusArchBits, machOFile.cpusubtype);
if (archInfo == NULL)
[self.resultString appendFormat:@" * Arch: cputype: 0x%x, cpusubtype: 0x%x\n", [machOFile cputype], [machOFile cpusubtype]];
[self.resultString appendFormat:@" * Arch: cputype: 0x%x, cpusubtype: 0x%x\n", machOFile.cputype, machOFile.cpusubtype];
else
[self.resultString appendFormat:@" * Arch: %s (%s)\n", archInfo->description, archInfo->name];

if ([machOFile filetype] == MH_DYLIB) {
CDLCDylib *identifier = [machOFile dylibIdentifier];
if (machOFile.filetype == MH_DYLIB) {
CDLCDylib *identifier = machOFile.dylibIdentifier;
if (identifier != nil)
[self.resultString appendFormat:@" * Current version: %@, Compatibility version: %@\n",
[identifier formattedCurrentVersion], [identifier formattedCompatibilityVersion]];
identifier.formattedCurrentVersion, identifier.formattedCompatibilityVersion];
}

if (machOFile.minVersionMacOSX != nil)
Expand All @@ -74,8 +73,8 @@ - (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
[self.resultString appendFormat:@" * Minimum iOS version: %@\n", machOFile.minVersionIOS.minimumVersionString];

[self.resultString appendFormat:@" *\n"];
if (aProcessor.garbageCollectionStatus != nil)
[self.resultString appendFormat:@" * Objective-C Garbage Collection: %@\n", aProcessor.garbageCollectionStatus];
if (processor.garbageCollectionStatus != nil)
[self.resultString appendFormat:@" * Objective-C Garbage Collection: %@\n", processor.garbageCollectionStatus];

if ([machOFile.dyldEnvironment count] > 0) {
BOOL first = YES;
Expand All @@ -89,39 +88,39 @@ - (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
}
}

for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
for (CDLoadCommand *loadCommand in machOFile.loadCommands) {
if ([loadCommand isKindOfClass:[CDLCRunPath class]]) {
CDLCRunPath *runPath = (CDLCRunPath *)loadCommand;

[self.resultString appendFormat:@" * Run path: %@\n", [runPath path]];
[self.resultString appendFormat:@" * = %@\n", [runPath resolvedRunPath]];
[self.resultString appendFormat:@" * Run path: %@\n", runPath.path];
[self.resultString appendFormat:@" * = %@\n", runPath.resolvedRunPath];
}
}

if ([machOFile isEncrypted]) {
if (machOFile.isEncrypted) {
[self.resultString appendString:@" * This file is encrypted:\n"];
for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
for (CDLoadCommand *loadCommand in machOFile.loadCommands) {
if ([loadCommand isKindOfClass:[CDLCEncryptionInfo class]]) {
CDLCEncryptionInfo *encryptionInfo = (CDLCEncryptionInfo *)loadCommand;

[self.resultString appendFormat:@" * cryptid: 0x%08x, cryptoff: 0x%08x, cryptsize: 0x%08x\n",
[encryptionInfo cryptid], [encryptionInfo cryptoff], [encryptionInfo cryptsize]];
encryptionInfo.cryptid, encryptionInfo.cryptoff, encryptionInfo.cryptsize];
}
}
} else if ([machOFile hasProtectedSegments]) {
if ([machOFile canDecryptAllSegments]) {
} else if (machOFile.hasProtectedSegments) {
if (machOFile.canDecryptAllSegments) {
[self.resultString appendString:@" * This file has protected segments, decrypting.\n"];
} else {
NSUInteger index = 0;

[self.resultString appendString:@" * This file has protected segments that can't be decrypted:\n"];
for (CDLoadCommand *loadCommand in [machOFile loadCommands]) {
for (CDLoadCommand *loadCommand in machOFile.loadCommands) {
if ([loadCommand isKindOfClass:[CDLCSegment class]]) {
CDLCSegment *segment = (CDLCSegment *)loadCommand;

if ([segment canDecrypt] == NO) {
if (segment.canDecrypt == NO) {
[self.resultString appendFormat:@" * Load command %u, segment encryption: %@\n",
index, CDSegmentEncryptionTypeName([segment encryptionType])];
index, CDSegmentEncryptionTypeName(segment.encryptionType)];
}
}

Expand Down
6 changes: 2 additions & 4 deletions Source/CDClassFrameworkVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

@interface CDClassFrameworkVisitor : CDVisitor

- (NSDictionary *)frameworkNamesByClassName;
- (NSDictionary *)frameworkNamesByProtocolName;

@property (retain) NSString *frameworkName;
@property (readonly) NSDictionary *frameworkNamesByClassName;
@property (readonly) NSDictionary *frameworkNamesByProtocolName;

@end
42 changes: 21 additions & 21 deletions Source/CDClassFrameworkVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@

// This builds up a dictionary mapping class names to a framework name. It is used to generate individual imports when creating separate header files.

@interface CDClassFrameworkVisitor ()
@property (retain) NSString *frameworkName;
@end

#pragma mark -

@implementation CDClassFrameworkVisitor
{
NSMutableDictionary *frameworkNamesByClassName;
NSMutableDictionary *frameworkNamesByProtocolName;
NSMutableDictionary *frameworkNamesByClassName; // NSString (class name) -> NSString (framework name)
NSMutableDictionary *frameworkNamesByProtocolName; // NSString (protocol name) -> NSString (framework name)
NSString *frameworkName;
}

Expand All @@ -40,35 +46,29 @@ - (void)dealloc;

#pragma mark -

- (NSDictionary *)frameworkNamesByClassName;
{
return frameworkNamesByClassName;
}

- (NSDictionary *)frameworkNamesByProtocolName;
{
return frameworkNamesByProtocolName;
}

@synthesize frameworkName;

- (void)willVisitObjectiveCProcessor:(CDObjectiveCProcessor *)anObjCSegment;
- (void)willVisitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;
{
[self setFrameworkName:[[anObjCSegment machOFile] importBaseName]];
self.frameworkName = [processor.machOFile importBaseName];
}

- (void)willVisitClass:(CDOCClass *)aClass;
{
if (frameworkName != nil) {
[frameworkNamesByClassName setObject:frameworkName forKey:[aClass name]];
if (self.frameworkName != nil) {
[frameworkNamesByClassName setObject:self.frameworkName forKey:aClass.name];
}
}

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)willVisitProtocol:(CDOCProtocol *)protocol;
{
if (frameworkName != nil) {
[frameworkNamesByProtocolName setObject:frameworkName forKey:[aProtocol name]];
if (self.frameworkName != nil) {
[frameworkNamesByProtocolName setObject:self.frameworkName forKey:protocol.name];
}
}

#pragma mark -

@synthesize frameworkNamesByClassName;
@synthesize frameworkNamesByProtocolName;
@synthesize frameworkName;

@end
7 changes: 1 addition & 6 deletions Source/CDFindMethodVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

@interface CDFindMethodVisitor : CDVisitor

@property (retain) NSString *findString;

- (void)setContext:(CDOCProtocol *)newContext;
- (void)showContextIfNecessary;

- (void)writeResultToStandardOutput;
@property (retain) NSString *searchString;

@end
88 changes: 49 additions & 39 deletions Source/CDFindMethodVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
#import "CDOCMethod.h"
#import "CDTypeController.h"

@interface CDFindMethodVisitor ()
@property (nonatomic, retain) CDOCProtocol *context;
- (void)showContextIfNecessary;
- (void)writeResultToStandardOutput;
@end

#pragma mark -

@implementation CDFindMethodVisitor
{
NSString *findString;
NSString *searchString;
NSMutableString *resultString;
CDOCProtocol *context;
BOOL hasShownContext;
Expand All @@ -27,7 +35,7 @@ @implementation CDFindMethodVisitor
- (id)init;
{
if ((self = [super init])) {
findString = nil;
searchString = nil;
resultString = [[NSMutableString alloc] init];
context = nil;
hasShownContext = NO;
Expand All @@ -38,7 +46,7 @@ - (id)init;

- (void)dealloc;
{
[findString release];
[searchString release];
[resultString release];
[context release];

Expand All @@ -47,28 +55,6 @@ - (void)dealloc;

#pragma mark -

@synthesize findString;

- (void)setContext:(CDOCProtocol *)newContext;
{
if (newContext == context)
return;

[context release];
context = [newContext retain];

hasShownContext = NO;
}

- (void)showContextIfNecessary;
{
if (hasShownContext == NO) {
[resultString appendString:[context findTag:nil]];
[resultString appendString:@"\n"];
hasShownContext = YES;
}
}

- (void)willBeginVisiting;
{
[self.classDump appendHeaderToString:resultString];
Expand All @@ -79,7 +65,7 @@ - (void)willBeginVisiting;
}
}

- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)aProcessor;
- (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;
{
if (!self.classDump.hasObjectiveCRuntimeInfo) {
[resultString appendString:@"//\n"];
Expand All @@ -99,12 +85,12 @@ - (void)writeResultToStandardOutput;
[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data];
}

- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)willVisitProtocol:(CDOCProtocol *)protocol;
{
[self setContext:aProtocol];
[self setContext:protocol];
}

- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;
- (void)didVisitProtocol:(CDOCProtocol *)protocol;
{
if (hasShownContext)
[resultString appendString:@"\n"];
Expand All @@ -129,43 +115,67 @@ - (void)didVisitIvarsOfClass:(CDOCClass *)aClass;
{
}

- (void)willVisitCategory:(CDOCCategory *)aCategory;
- (void)willVisitCategory:(CDOCCategory *)category;
{
[self setContext:aCategory];
[self setContext:category];
}

- (void)didVisitCategory:(CDOCCategory *)aCategory;
- (void)didVisitCategory:(CDOCCategory *)category;
{
if (hasShownContext)
[resultString appendString:@"\n"];
}

- (void)visitClassMethod:(CDOCMethod *)aMethod;
- (void)visitClassMethod:(CDOCMethod *)method;
{
NSRange range = [[aMethod name] rangeOfString:findString];
NSRange range = [[method name] rangeOfString:searchString];
if (range.length > 0) {
[self showContextIfNecessary];

[resultString appendString:@"+ "];
[aMethod appendToString:resultString typeController:[self.classDump typeController] symbolReferences:nil];
[method appendToString:resultString typeController:[self.classDump typeController] symbolReferences:nil];
[resultString appendString:@"\n"];
}
}

- (void)visitInstanceMethod:(CDOCMethod *)aMethod propertyState:(CDVisitorPropertyState *)propertyState;
- (void)visitInstanceMethod:(CDOCMethod *)method propertyState:(CDVisitorPropertyState *)propertyState;
{
NSRange range = [[aMethod name] rangeOfString:findString];
NSRange range = [[method name] rangeOfString:searchString];
if (range.length > 0) {
[self showContextIfNecessary];

[resultString appendString:@"- "];
[aMethod appendToString:resultString typeController:[self.classDump typeController] symbolReferences:nil];
[method appendToString:resultString typeController:[self.classDump typeController] symbolReferences:nil];
[resultString appendString:@"\n"];
}
}

- (void)visitIvar:(CDOCIvar *)anIvar;
- (void)visitIvar:(CDOCIvar *)ivar;
{
}

#pragma mark -

@synthesize searchString;
@synthesize context;

- (void)setContext:(CDOCProtocol *)newContext;
{
if (newContext != context) {
[context release];
context = [newContext retain];

hasShownContext = NO;
}
}

- (void)showContextIfNecessary;
{
if (hasShownContext == NO) {
[resultString appendString:[self.context findTag:nil]];
[resultString appendString:@"\n"];
hasShownContext = YES;
}
}

@end
6 changes: 3 additions & 3 deletions Source/CDMachOFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef NSUInteger CDByteOrder;
- (NSString *)filetypeDescription;
- (NSString *)flagDescription;

- (CDLCDylib *)dylibIdentifier;
@property (nonatomic, readonly) CDLCDylib *dylibIdentifier;

- (CDLCSegment *)segmentWithName:(NSString *)segmentName;
- (CDLCSegment *)segmentContainingAddress:(NSUInteger)address;
Expand All @@ -80,8 +80,8 @@ typedef NSUInteger CDByteOrder;
- (NSString *)loadCommandString:(BOOL)isVerbose;
- (NSString *)headerString:(BOOL)isVerbose;

- (NSString *)uuidString;
- (NSString *)archName;
@property (nonatomic, readonly) NSString *uuidString;
@property (nonatomic, readonly) NSString *archName;

- (Class)processorClass;
- (void)logInfoForAddress:(NSUInteger)address;
Expand Down
Loading

0 comments on commit 801207f

Please sign in to comment.