forked from Naville/class-dump-utf8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDFindMethodVisitor.m
174 lines (137 loc) · 3.58 KB
/
CDFindMethodVisitor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2009 Steve Nygard.
#import "CDFindMethodVisitor.h"
#import "NSArray-Extensions.h"
#import "CDClassDump.h"
#import "CDObjectiveC1Processor.h"
#import "CDMachOFile.h"
#import "CDOCProtocol.h"
#import "CDLCDylib.h"
#import "CDOCClass.h"
#import "CDOCCategory.h"
#import "CDOCMethod.h"
@implementation CDFindMethodVisitor
- (id)init;
{
if ([super init] == nil)
return nil;
findString = nil;
resultString = [[NSMutableString alloc] init];
context = nil;
hasShownContext = NO;
return self;
}
- (void)dealloc;
{
[findString release];
[resultString release];
[context release];
[super dealloc];
}
- (NSString *)findString;
{
return findString;
}
- (void)setFindString:(NSString *)newFindString;
{
if (newFindString == findString)
return;
[findString release];
findString = [newFindString retain];
}
- (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;
{
[classDump appendHeaderToString:resultString];
if ([classDump containsObjectiveCData]) {
//[classDump appendStructuresToString:resultString symbolReferences:nil];
//[resultString appendString:@"// [structures go here]\n"];
} else {
[resultString appendString:@"This file does not contain any Objective-C runtime information.\n"];
}
}
- (void)didEndVisiting;
{
[self writeResultToStandardOutput];
}
- (void)writeResultToStandardOutput;
{
NSData *data;
data = [resultString dataUsingEncoding:NSUTF8StringEncoding];
[(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data];
}
- (void)willVisitProtocol:(CDOCProtocol *)aProtocol;
{
[self setContext:aProtocol];
}
- (void)didVisitProtocol:(CDOCProtocol *)aProtocol;
{
if (hasShownContext)
[resultString appendString:@"\n"];
}
- (void)willVisitClass:(CDOCClass *)aClass;
{
[self setContext:aClass];
}
- (void)didVisitClass:(CDOCClass *)aClass;
{
if (hasShownContext)
[resultString appendString:@"\n"];
}
- (void)willVisitIvarsOfClass:(CDOCClass *)aClass;
{
}
- (void)didVisitIvarsOfClass:(CDOCClass *)aClass;
{
}
- (void)willVisitCategory:(CDOCCategory *)aCategory;
{
[self setContext:aCategory];
}
- (void)didVisitCategory:(CDOCCategory *)aCategory;
{
if (hasShownContext)
[resultString appendString:@"\n"];
}
- (void)visitClassMethod:(CDOCMethod *)aMethod;
{
NSRange range;
range = [[aMethod name] rangeOfString:findString];
if (range.length > 0) {
[self showContextIfNecessary];
[resultString appendString:@"+ "];
[aMethod appendToString:resultString classDump:classDump symbolReferences:nil];
[resultString appendString:@"\n"];
}
}
- (void)visitInstanceMethod:(CDOCMethod *)aMethod;
{
NSRange range;
range = [[aMethod name] rangeOfString:findString];
if (range.length > 0) {
[self showContextIfNecessary];
[resultString appendString:@"- "];
[aMethod appendToString:resultString classDump:classDump symbolReferences:nil];
[resultString appendString:@"\n"];
}
}
- (void)visitIvar:(CDOCIvar *)anIvar;
{
}
@end