forked from AndrewSchenk/App-Scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainVC.m
706 lines (579 loc) · 21.4 KB
/
MainVC.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
//
// MainVC.m
// APIScanner
//
// Created by Andrew Schenk on 9/2/10.
// Copyright 2010 Chimp Studios. All rights reserved.
//
#import "MainVC.h"
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <AppKit/AppKit.h>
#import "Constants.h"
#import "Helpers.h"
#import "APIScannerAppDelegate.h"
#import "Pweep.h"
#define kMinorIncrement 3.3
#define kMajorIncrement 45
#define kTimerInterval 8
@implementation MainVC
//@synthesize window;
-(void)awakeFromNib
{
[box setDelegate:self];
NSString *path = [[NSBundle mainBundle] pathForResource:@"appstore_review_guidelines" ofType:@"txt"];
NSString *guides = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
guidelines = [guides componentsSeparatedByString:@"\n"];
[guidelines retain];
guidelinesTimer = [NSTimer scheduledTimerWithTimeInterval:kTimerInterval
target:self
selector:@selector(loadNewMessage)
userInfo:nil
repeats:YES];
[guidelinesTimer retain];
[guidelinesTimer fire];
[guidelinesDisplay setFont:[NSFont systemFontOfSize:12]];
//[guidelinesDisplay setAlignment:NSCenterTextAlignment];
[guidelinesDisplay setAlignment:NSCenterTextAlignment];
//[self loadNewMessage];
}
-(void)windowDidLoad
{
[box registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
}
-(IBAction)reportMissingSig:(id)sender
{
// Attach/detach window
if (!misWindow) {
NSPoint buttonPoint = NSMakePoint(NSMidX([misSigBtn frame]),
NSMidY([misSigBtn frame]));
misWindow = [[MAAttachedWindow alloc] initWithView:missingSigVw
attachedToPoint:buttonPoint
inWindow:[misSigBtn window]
onSide:MAPositionAutomatic
atDistance:[misSigBtn frame].size.height/2];
[misWindow setBorderColor:[NSColor grayColor]];
[misWindow setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.99]];
[misWindow setViewMargin:10];
[misWindow setBorderWidth:2];
[misWindow setCornerRadius:5];
[misWindow setHasArrow:YES];
[misWindow setDrawsRoundCornerBesideArrow:NO];
[misWindow setArrowBaseWidth:25];
[misWindow setArrowHeight:20];
[[misSigBtn window] addChildWindow:misWindow ordered:NSWindowAbove];
} else {
[[misSigBtn window] removeChildWindow:misWindow];
[misWindow orderOut:self];
[misWindow release];
misWindow = nil;
}
}
-(IBAction)submitMissingSig:(id)sender
{
// open source version does not include any community feedback features.
}
#pragma mark -
#pragma mark NSURLConnection
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSAlert *err = [NSAlert alertWithError:error];
[err runModal];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (!connData) {
connData = [[NSMutableData alloc] initWithCapacity:0];
[connData retain];
}
[connData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *response = [[NSString alloc] initWithData:connData encoding:NSUTF8StringEncoding];
NSAlert *rsp = [NSAlert alertWithMessageText:response
defaultButton:@"Okay"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@""];
[rsp runModal];
[response release];
[connData release];
}
#pragma mark -
#pragma mark Guidelines
-(void)loadNewMessage
{
if (!hasStarted) {
hasStarted = YES;
startingIndex = arc4random()%[guidelines count];
}
NSString *newStr = [NSString stringWithFormat:@"\"%@\"", [guidelines objectAtIndex:startingIndex]];
//[guidelinesDisplay setString:newStr];
//[guidelinesDisplay setAlignment:NSCenterTextAlignment range:NSMakeRange(0,[newStr length])];
NSData *data = [newStr dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://developer.apple.com/appstore/guidelines.html"];
NSAttributedString *attrString = [[NSAttributedString alloc]
initWithHTML: data baseURL: url documentAttributes: (NSDictionary **) NULL];
[[guidelinesDisplay textStorage] setAttributedString: attrString];
[attrString release];
[guidelinesDisplay setAlignment:NSCenterTextAlignment];
startingIndex++;
if (startingIndex > [guidelines count] - 1) {
startingIndex = 0;
}
}
#pragma mark -
#pragma mark Dragging
-(void)didReceiveDraggedFiles:(NSArray*)files
{
[self readInBinaryFromFiles:files];
}
#pragma mark -
#pragma mark Search
-(IBAction)toggleDrawer:(id)sender
{
if([drawer state] == NSDrawerOpenState && [[searchField stringValue] length] <= 0) {
[drawer close];
} else {
[drawer open];
}
}
-(IBAction)search:(id)sender
{
[self toggleDrawer:nil];
APIScannerAppDelegate *delegate = (APIScannerAppDelegate*)[[NSApplication sharedApplication] delegate];
NSString *searchString = [sender stringValue];
NSArray *results = [ModelDataHelpers searchForPweepsLikeSig:searchString context:delegate.managedObjectContext];
if (searchResults) {
[searchResults release];
searchResults = nil;
}
searchResults = [NSMutableArray arrayWithArray:results];
[searchResults retain];
[table reloadData];
}
#pragma mark NSTableView Data Source
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [searchResults count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
Pweep* pweep = [searchResults objectAtIndex:rowIndex];
if ([aTableColumn.identifier isEqualToString:@"Signature"]) {
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:pweep.Signature] autorelease];
return cell;
}
if ([aTableColumn.identifier isEqualToString:@"Likelihood"]) {
int percentage = [pweep.Level intValue];
NSTextFieldCell *cell = [[[NSTextFieldCell alloc] initTextCell:[NSString stringWithFormat:@"%i%@", percentage, @"%"]] autorelease];
if (percentage > 70) {
[cell setTextColor:[NSColor greenColor]];
} else if (percentage >= 50 && percentage <= 70) {
[cell setTextColor:[NSColor brownColor]];
} else if (percentage >= 25 && percentage < 50) {
[cell setTextColor:[NSColor orangeColor]];
} else {
[cell setTextColor:[NSColor redColor]];
}
[cell setAlignment:NSCenterTextAlignment];
return cell;
}
return nil;
}
#pragma mark -
#pragma mark Binary Scan
-(IBAction)openFile:(id)sender
{
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
[self readInBinaryFromFiles:files];
}
}
// Open either a binary or a .app file
-(void)readInBinaryFromFiles:(NSArray*)files
{
NSString * file = [files objectAtIndex:0];
if (!([[file pathExtension] isEqualToString:@"app"] ||
[[file pathExtension] isEqualToString:@""]) ) {
NSAlert *err = [NSAlert alertWithMessageText:@"Invalid file. Only .app files or Unix Executable Files (binaries) may be scanned."
defaultButton:@"Okay"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@""];
[err runModal];
return;
}
[appIcon setImage:[self getImageForFile:file]];
[self startIconAnimation];
NSString *binaryPath = [NSString stringWithString:file];
if ([[file pathExtension] isEqualToString:@"app"]) {
NSBundle *appBundle = [NSBundle bundleWithPath:file];
NSString *binaryPath = [appBundle pathForResource:[[[file lastPathComponent] componentsSeparatedByString:@"."] objectAtIndex:0]
ofType:@""];
NSURL *filePath = [NSURL fileURLWithPath:binaryPath];
[self startScannerWithURL:filePath];
return;
}
[self startScannerWithURL:[NSURL fileURLWithPath:binaryPath]];
}
#pragma mark -
#pragma mark Icon Drop Animation
-(void)startIconAnimation
{
hasPrematurelyFinished = NO;
systemSound = [NSSound soundNamed:@"zap"];
[systemSound setLoops:YES];
[systemSound setVolume:0.2];
[systemSound retain];
NSRect finalRect = appIcon.frame;
[appIcon setFrame:NSMakeRect(appIcon.frame.origin.x,
self.window.frame.size.height + appIcon.frame.size.height,
appIcon.frame.size.width,
appIcon.frame.size.height)];
NSViewAnimation *theAnim;
NSMutableDictionary* firstViewDict;
{
// Create the attributes dictionary for the first view.
firstViewDict = [NSMutableDictionary dictionaryWithCapacity:3];
// Specify which view to modify.
[firstViewDict setObject:appIcon forKey:NSViewAnimationTargetKey];
// Specify the starting position of the view.
[firstViewDict setObject:[NSValue valueWithRect:[appIcon frame]]
forKey:NSViewAnimationStartFrameKey];
// Change the ending position of the view.
[firstViewDict setObject:[NSValue valueWithRect:finalRect]
forKey:NSViewAnimationEndFrameKey];
}
[systemSound play];
theAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
arrayWithObjects:firstViewDict, nil]];
double duration = 0.9;
[theAnim setDuration:duration];
[theAnim setAnimationCurve:NSAnimationEaseIn];
// Run the animation.
[theAnim startAnimation];
// The animation has finished, so go ahead and release it.
[theAnim release];
NSTimer *waitTimer = [NSTimer scheduledTimerWithTimeInterval:duration
target:self
selector:@selector(renderInverseIcon)
userInfo:nil
repeats:NO];
waitTimer = nil;
}
-(void)renderInverseIcon
{
if (!hasPrematurelyFinished) {
//NSLog(@"renderInverseIcon...");
CIImage* ciImage = [[CIImage alloc] initWithData:[[appIcon image] TIFFRepresentation]];
if ([[appIcon image] isFlipped])
{
CGRect cgRect = [ciImage extent];
CGAffineTransform transform;
transform = CGAffineTransformMakeTranslation(0.0,cgRect.size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
ciImage = [ciImage imageByApplyingTransform:transform];
}
CIFilter* filter = [CIFilter filterWithName:@"CIColorInvert"];
[filter setDefaults];
[filter setValue:ciImage forKey:@"inputImage"];
CIImage* output = [filter valueForKey:@"outputImage"];
NSBitmapImageRep* rep =
[[[NSBitmapImageRep alloc] initWithCIImage:output] autorelease];
CGImageRef outputCG = rep.CGImage;
NSImage* inverted = [[NSImage alloc] initWithCGImage:outputCG size:NSZeroSize];
appIcon.image = inverted;
[appIcon retain];
[appIcon removeFromSuperview];
[self.window.contentView addSubview:appIcon positioned:NSWindowAbove relativeTo:nil];
[appIcon release];
// start zapping timer
animationTimer = [NSTimer scheduledTimerWithTimeInterval:2
target:self
selector:@selector(zap)
userInfo:nil
repeats:YES];
[animationTimer retain];
[animationTimer fire];
}
}
-(void)zap
{
NSViewAnimation *theAnimfirst;
NSMutableDictionary* firstanimViewDict;
{
// Create the attributes dictionary for the first view.
firstanimViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
// Specify which view to modify.
[firstanimViewDict setObject:appIcon forKey:NSViewAnimationTargetKey];
// Specify the starting position of the view.
[firstanimViewDict setObject:NSViewAnimationFadeInEffect
forKey:NSViewAnimationEffectKey];
}
theAnimfirst = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
arrayWithObjects:firstanimViewDict, nil]];
double duration = 0.01;
[theAnimfirst setDuration:duration];
[theAnimfirst setAnimationCurve:NSAnimationEaseIn];
// Run the animation.
[theAnimfirst startAnimation];
// The animation has finished, so go ahead and release it.
[theAnimfirst release];
//
NSViewAnimation *theAnim;
NSMutableDictionary* firstViewDict;
{
// Create the attributes dictionary for the first view.
firstViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
// Specify which view to modify.
[firstViewDict setObject:appIcon forKey:NSViewAnimationTargetKey];
// Specify the starting position of the view.
[firstViewDict setObject:NSViewAnimationFadeOutEffect
forKey:NSViewAnimationEffectKey];
}
theAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
arrayWithObjects:firstViewDict, nil]];
duration = 0.9;
[theAnim setDuration:duration];
[theAnim setAnimationCurve:NSAnimationEaseIn];
// Run the animation.
[theAnim startAnimation];
// The animation has finished, so go ahead and release it.
[theAnim release];
}
// return the app icon or a default image
-(NSImage*)getImageForFile:(NSString*)filepath
{
NSWorkspace *workSpace = [[[NSWorkspace alloc] init] autorelease];
if ([[filepath pathExtension] isEqualToString:@"app"]) {
NSBundle *appBundle = [NSBundle bundleWithPath:filepath];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[appBundle pathForResource:@"Info" ofType:@"plist"]];
if (info) {
//NSLog(@"info -> %@", [info description]);
NSString *iconName = [info objectForKey:@"CFBundleIconFile"];
if (iconName) {
return [[[NSImage alloc] initByReferencingFile:[filepath stringByAppendingPathComponent:iconName]] autorelease];
}
}
}
return [workSpace iconForFile:filepath];
}
#pragma mark -
#pragma mark Main Thread Scanning
-(void)startScannerWithURL:(NSURL*)url
{
//NSLog(@"url -> %@", [url description]);
NSString *progressText = [NSString stringWithFormat:@"Scanning \"%@\"", [url lastPathComponent]];
[headerLabel setStringValue:progressText];
[progressLabel setStringValue:@"Analyzing Binary File..."];
[progressIndicator incrementBy:10];
[NSThread detachNewThreadSelector:@selector(readHexCStringDataInFromURL:)
toTarget:self
withObject:url];
//NSString *contents = [self readHexCStringDataInFromURL:url];
//NSLog(@"%@", contents);
//[scanResultsWC release];
}
-(void)continueScannerWithContents:(NSString*)contents
{
[progressLabel setStringValue:@"Pulling Method Signatures Out Of Binary..."];
[progressIndicator incrementBy:kMinorIncrement];
NSArray *hexMethods = [contents componentsSeparatedByString:@"00"];
[NSThread detachNewThreadSelector:@selector(processHexMethods:)
toTarget:self
withObject:hexMethods];
}
-(void)continueScannerWithNormalStrings:(NSArray*)normalStrings
{
[progressLabel setStringValue:@"Cleaning up method signatures..."];
[progressIndicator incrementBy:kMinorIncrement];
[NSThread detachNewThreadSelector:@selector(stripIVarsAndPathsFromStrings:)
toTarget:self
withObject:normalStrings];
}
-(void)continueScanningWithCleanedMethods:(NSArray*)methods
{
[progressLabel setStringValue:@"Searching for private method signature matches..."];
//[progressIndicator incrementBy:10];
// check everything in methods array versus private API database!
[NSThread detachNewThreadSelector:@selector(checkMethodsAgainstDatabase:)
toTarget:self
withObject:methods];
}
-(void)continueScanningWithFlagged:(NSArray*)flagged
{
[progressLabel setStringValue:@"Retrieving Details for Matches..."];
//[progressIndicator incrementBy:10];
[NSThread detachNewThreadSelector:@selector(loadPweepsForSigs:)
toTarget:self
withObject:flagged];
}
NSInteger likelihoodSort(id g1, id g2, void *context)
{
Pweep *first = ((Pweep*)[g1 objectForKey:@"Pweep"]);
Pweep *second = ((Pweep*)[g2 objectForKey:@"Pweep"]);
float v1 = [first.Level floatValue];
float v2 = [second.Level floatValue];
if (v1 > v2)
return NSOrderedAscending;
else if (v1 < v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
-(void)finishScanByShowingResults:(NSArray*)flaggedPweeps
{
[headerLabel setStringValue:@"Scan Complete..."];
[progressLabel setStringValue:@""];
[progressIndicator incrementBy:kMinorIncrement];
[progressIndicator incrementBy:-100];
hasPrematurelyFinished = YES;
if (animationTimer) {
[animationTimer invalidate];
[animationTimer release];
animationTimer = nil;
}
if (systemSound) {
[systemSound stop];
[systemSound release];
systemSound = nil;
}
scanResultsWC = [[ScanResultsWC alloc] initWithWindowNibName:@"ScanResultsWC"];
scanResultsWC.flagged = [flaggedPweeps sortedArrayUsingFunction:likelihoodSort context:NULL];
[scanResultsWC showWindow:scanResultsWC.window];
}
#pragma mark -
#pragma mark Secondary Thread Scanning
-(void)readHexCStringDataInFromURL:(NSURL*)url
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *programData = [NSData dataWithContentsOfURL:url];
//NSLog(@"programData.length -> %i", [programData length]);
int c_string_size = [BinaryDataHelper sizeOfSectionForKeyword:@"__LINKEDIT" inData:programData];
int c_string_offset = [BinaryDataHelper offsetOfSectionForKeyword:@"__LINKEDIT" inData:programData];
//NSLog(@"offset => %i; size => %i", c_string_offset, c_string_size);
NSData *stringsData = [programData subdataWithRange:NSMakeRange(c_string_offset, c_string_size)];
[self performSelectorOnMainThread:@selector(continueScannerWithContents:)
withObject:[BinaryDataHelper stringWithHexBytesFromData:stringsData]
waitUntilDone:NO];
[pool release];
}
-(void)processHexMethods:(NSArray*)hmethds
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *normalMethods = [[[NSMutableArray alloc] initWithCapacity:[hmethds count]] autorelease];
for(NSString *hexStr in hmethds) {
NSString *mthd = [BinaryDataHelper hexToAscii:hexStr];
if (mthd) {
if ([mthd length] > 1) {
[normalMethods addObject:mthd];
}
}
}
[self performSelectorOnMainThread:@selector(continueScannerWithNormalStrings:)
withObject:normalMethods
waitUntilDone:NO];
[pool release];
}
-(void)stripIVarsAndPathsFromStrings:(NSArray*)strings
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *methods = [[[NSMutableArray alloc] initWithCapacity:[strings count]] autorelease];
for(NSString *str in strings) {
//NSString *mthd = [BinaryDataHelper hexToAscii:hexStr];
if ([[str substringToIndex:1] isEqualToString:@"-"] || [[str substringToIndex:1] isEqualToString:@"+"]) {
[methods addObject:str];
}
}
//return methods;
[self performSelectorOnMainThread:@selector(continueScanningWithCleanedMethods:)
withObject:methods
waitUntilDone:NO];
[pool release];
}
-(void)checkMethodsAgainstDatabase:(NSArray*)methods
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray* flagged = [[[NSMutableArray alloc] initWithCapacity:0] autorelease];
APIScannerAppDelegate *delegate = (APIScannerAppDelegate*)[[NSApplication sharedApplication] delegate];
double methodsCount = (double)[methods count];
double incrementBy = kMajorIncrement/methodsCount;
for(NSString* mthd in methods) {
NSString *stripped = [mthd stringByReplacingOccurrencesOfString:@"[" withString:@""];
stripped = [stripped stringByReplacingOccurrencesOfString:@"]" withString:@""];
stripped = [stripped stringByReplacingOccurrencesOfString:@"+" withString:@""];
stripped = [stripped stringByReplacingOccurrencesOfString:@"-" withString:@""];
NSArray *parts = [stripped componentsSeparatedByString:@" "];
NSDictionary *mthSigDict = nil;
if ([parts count] > 1) {
mthSigDict = [NSDictionary dictionaryWithObjectsAndKeys:[parts objectAtIndex:0], @"Class", [parts objectAtIndex:1], @"Sig", nil];
} else {
break;
}
if ([ModelDataHelpers stringIsInDatabase:[mthSigDict objectForKey:@"Sig"] context:delegate.threadedContext]) {
[flagged addObject:mthSigDict];
}
// Update the progress Bar
[self performSelectorOnMainThread:@selector(updateProgressBarBy:)
withObject:[NSNumber numberWithDouble:incrementBy]
waitUntilDone:NO];
}
[self performSelectorOnMainThread:@selector(continueScanningWithFlagged:)
withObject:flagged
waitUntilDone:NO];
[pool release];
}
-(void)loadPweepsForSigs:(NSArray*)flagged
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
APIScannerAppDelegate *delegate = (APIScannerAppDelegate*)[[NSApplication sharedApplication] delegate];
NSMutableArray *flaggedPweeps = [[[NSMutableArray alloc] initWithCapacity:[flagged count]] autorelease];
double methodsCount = (double)[flagged count];
double incrementBy = kMajorIncrement/methodsCount;
for(NSDictionary * dict in flagged) {
[flaggedPweeps addObject:[ModelDataHelpers getPweepObjectForSig:dict context:delegate.threadedContext]];
[self performSelectorOnMainThread:@selector(updateProgressBarBy:)
withObject:[NSNumber numberWithDouble:incrementBy]
waitUntilDone:NO];
}
[self performSelectorOnMainThread:@selector(finishScanByShowingResults:)
withObject:flaggedPweeps
waitUntilDone:NO];
[pool release];
}
-(void)updateProgressBarBy:(NSNumber*)increment
{
[progressIndicator incrementBy:[increment doubleValue]];
}
#pragma mark -
#pragma mark Memory Management
-(void)dealloc
{
if (systemSound) {
[systemSound stop];
[systemSound release];
systemSound = nil;
}
if (animationTimer) {
[animationTimer invalidate];
[animationTimer release];
animationTimer = nil;
}
[guidelinesTimer invalidate];
[guidelinesTimer release];
[guidelines release];
[super dealloc];
}
@end