-
Notifications
You must be signed in to change notification settings - Fork 34
/
AppDelegate.m
executable file
·1701 lines (1344 loc) · 47.8 KB
/
AppDelegate.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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// AppDelegate.m
// KnockKnock
//
#import "Consts.h"
#import "Update.h"
#import "Utilities.h"
#import "PluginBase.h"
#import "AppDelegate.h"
//TODO: scan other volumes
//TODO: support delete items
//TODO: search in UI
@implementation AppDelegate
@synthesize friends;
@synthesize plugins;
@synthesize vtThreads;
@synthesize scanButton;
@synthesize isConnected;
@synthesize scannerThread;
@synthesize tableContents;
@synthesize versionString;
@synthesize virusTotalObj;
@synthesize selectedPlugin;
@synthesize scanButtonLabel;
@synthesize progressIndicator;
@synthesize itemTableController;
@synthesize aboutWindowController;
@synthesize prefsWindowController;
@synthesize showSettingsButton;
@synthesize updateWindowController;
@synthesize categoryTableController;
@synthesize resultsWindowController;
//center window
// also make front
-(void)awakeFromNib
{
//center
[self.window center];
//make it key window
[self.window makeKeyAndOrderFront:self];
//make window front
[NSApp activateIgnoringOtherApps:YES];
return;
}
//automatically invoked by OS
-(void)applicationDidFinishLaunching:(NSNotification *)notification
{
//defaults
NSUserDefaults* defaults = nil;
//init filter object
itemFilter = [[Filter alloc] init];
//init virus total object
virusTotalObj = [[VirusTotal alloc] init];
//init array for virus total threads
vtThreads = [NSMutableArray array];
//alloc shared item enumerator
sharedItemEnumerator = [[ItemEnumerator alloc] init];
//toggle away
[[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.loginwindow"] firstObject] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
//toggle back
// work-around for menu not showing since we set Application is agent(UIElement): YES
[[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.objective-see.KnockKnock"] firstObject] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
//load defaults
defaults = [NSUserDefaults standardUserDefaults];
//first time run?
// show thanks to friends window!
if(YES != [defaults boolForKey:NOT_FIRST_TIME])
{
//set key
[defaults setBool:YES forKey:NOT_FIRST_TIME];
//set delegate
self.friends.delegate = self;
//show friends window
[self.friends makeKeyAndOrderFront:self];
//then make action button first responder
[self.friends makeFirstResponder:self.closeButton];
//close after a few seconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
//close to hide
[self.friends close];
});
}
//asked for full disk access yet?
else if(YES != [defaults boolForKey:REQUESTED_FULL_DISK_ACCESS])
{
//set key
[defaults setBool:YES forKey:REQUESTED_FULL_DISK_ACCESS];
//request access
// delay, so UI completes rendering
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
//request access
[self requestFullDiskAcces];
});
}
//check for update
// unless user has turn off via prefs
if(YES != [defaults boolForKey:PREF_DISABLE_UPDATE_CHECK])
{
//check
[self check4Update:nil];
}
//kick off thread to begin enumerating shared objects
// ->this takes awhile, so do it now/first!
[sharedItemEnumerator start];
//instantiate all plugins objects
self.plugins = [self instantiatePlugins];
//set selected plugin to first
self.selectedPlugin = [self.plugins firstObject];
//pre-populate category table w/ each plugin title
[self.categoryTableController initTable:self.plugins];
//make category table active/selected
[[self.categoryTableController.categoryTableView window] makeFirstResponder:self.categoryTableController.categoryTableView];
//hide status msg
// ->when user clicks scan, will show up..
[self.statusText setStringValue:@""];
//hide progress indicator
self.progressIndicator.hidden = YES;
//set label text to 'Start Scan'
self.scanButtonLabel.stringValue = NSLocalizedString(@"Start Scan", @"Start Scan");
//set version info
[self.versionString setStringValue:[NSString stringWithFormat:NSLocalizedString(@"version: %@", @"version: %@"), getAppVersion()]];
//init tracking areas
[self initTrackingAreas];
//set delegate
// ->ensures our 'windowWillClose' method, which has logic to fully exit app
self.window.delegate = self;
//alloc/init prefs
prefsWindowController = [[PrefsWindowController alloc] initWithWindowNibName:@"PrefsWindow"];
//register defaults
[self.prefsWindowController registerDefaults];
//load prefs
[self.prefsWindowController loadPreferences];
return;
}
//close 'friends' window
-(IBAction)closeFriendsWindow:(id)sender
{
//close to hide
[self.friends close];
return;
}
//window close handler
-(void)windowWillClose:(NSNotification *)notification {
//closing friends window?
// request full disk access
if(self.friends == notification.object)
{
//request access
// delay ensures (friends) window will close
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (100 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
//request access
[self requestFullDiskAcces];
});
}
return;
}
//automatically close when user closes last window
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
return YES;
}
//request full disk access
-(void)requestFullDiskAcces
{
//request
__block NSAlert* infoAlert = nil;
//once
static dispatch_once_t once;
//show request once
dispatch_once(&once, ^
{
//on request on 10.14+
if(@available(macOS 10.14, *))
{
//alloc alert
infoAlert = [[NSAlert alloc] init];
//main text
infoAlert.messageText = NSLocalizedString(@"Open 'System Preferences' to give KnockKnock Full Disk Access?", @"Open 'System Preferences' to give KnockKnock Full Disk Access?");
//detailed test
infoAlert.informativeText = NSLocalizedString(@"This allows the app to perform a comprehensive scan.\n\nIn System Preferences:\r ▪ Click the 🔒 to authenticate\r ▪ Click the ➕ to add KnockKnock.app\n", @"This allows the app to perform a comprehensive scan.\n\nIn System Preferences:\r ▪ Click the 🔒 to authenticate\r ▪ Click the ➕ to add KnockKnock.app\n");
//ok button
[infoAlert addButtonWithTitle:NSLocalizedString(@"OK", @"OK")];
//alert button
[infoAlert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Cancel")];
//show 'alert' and capture user response
// user clicked 'OK'? -> open System Preferences
if(NSAlertFirstButtonReturn == [infoAlert runModal])
{
//open System Preferences
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"]];
}
}
});
return;
}
//init tracking areas for buttons
// provides mouse over effects (i.e. image swaps)
-(void)initTrackingAreas
{
//tracking area for buttons
NSTrackingArea* trackingArea = nil;
//init tracking area
// ->for scan button
trackingArea = [[NSTrackingArea alloc] initWithRect:[self.scanButton bounds] options:(NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:@{@"tag":[NSNumber numberWithUnsignedInteger:self.scanButton.tag]}];
//add tracking area to scan button
[self.scanButton addTrackingArea:trackingArea];
//init tracking area
// ->for preference button
trackingArea = [[NSTrackingArea alloc] initWithRect:[self.showSettingsButton bounds] options:(NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:@{@"tag":[NSNumber numberWithUnsignedInteger:self.showSettingsButton.tag]}];
//add tracking area to pref button
[self.showSettingsButton addTrackingArea:trackingArea];
//init tracking area
// ->for save results button
trackingArea = [[NSTrackingArea alloc] initWithRect:[self.saveButton bounds] options:(NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:@{@"tag":[NSNumber numberWithUnsignedInteger:self.saveButton.tag]}];
//add tracking area to save button
[self.saveButton addTrackingArea:trackingArea];
//init tracking area
// ->for save results button
trackingArea = [[NSTrackingArea alloc] initWithRect:[self.compareButton bounds] options:(NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:@{@"tag":[NSNumber numberWithUnsignedInteger:self.compareButton.tag]}];
//add tracking area to save button
[self.compareButton addTrackingArea:trackingArea];
//init tracking area
// ->for logo button
trackingArea = [[NSTrackingArea alloc] initWithRect:[self.logoButton bounds] options:(NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:@{@"tag":[NSNumber numberWithUnsignedInteger:self.logoButton.tag]}];
//add tracking area to logo button
[self.logoButton addTrackingArea:trackingArea];
return;
}
//automatically invoked when window is un-minimized
// since the progress indicator is stopped (bug?), restart it
-(void)windowDidDeminiaturize:(NSNotification *)notification
{
//make sure scan is going on
// ->and then restart spinner
if(YES == [self.scannerThread isExecuting])
{
//show
[self.progressIndicator setHidden:NO];
//start spinner
[self.progressIndicator startAnimation:nil];
}
return;
}
//create instances of all registered plugins
-(NSMutableArray*)instantiatePlugins
{
//plugin objects
NSMutableArray* pluginObjects = nil;
//number of plugins
NSUInteger pluginCount = 0;
//plugin object
PluginBase* pluginObj = nil;
//init array
pluginObjects = [NSMutableArray array];
//get number of plugins
pluginCount = sizeof(SUPPORTED_PLUGINS)/sizeof(SUPPORTED_PLUGINS[0]);
//iterate over all supported plugin names
// ->init and save each
for(NSUInteger i=0; i < pluginCount; i++)
{
//init plugin
pluginObj = [[NSClassFromString(SUPPORTED_PLUGINS[i]) alloc] init];
//save it
[pluginObjects addObject:pluginObj];
}
return pluginObjects;
}
//automatically invoked when the user clicks 'start'/'stop' scan
-(IBAction)scanButtonHandler:(id)sender
{
//check state
// START scan
if(YES == [self.scanButtonLabel.stringValue isEqualToString:NSLocalizedString(@"Start Scan", @"Start Scan")])
{
//clear out all plugin results
for(PluginBase* plugin in self.plugins)
{
//remove all results
[plugin reset];
}
//update the UI
// reset tables/reflect the started state
[self startScanUI];
//start scan
// kicks off background scanner thread
[self startScan];
}
//check state
// ->STOP scan, by cancelling threads, etc.
else
{
//complete scan
[self completeScan];
//update the UI
// ->reflect the stopped state & and display stats
[self stopScanUI:SCAN_MSG_STOPPED];
}
return;
}
//kickoff background thread to scan
// ->also shared enumerator thread (if needed)
-(void)startScan
{
//alloc scanner thread
scannerThread = [[NSThread alloc] initWithTarget:self selector:@selector(scan) object:nil];
//on secondary runs
// ->always restart shared enumerator
if(YES == self.secondaryScan)
{
//start it
[sharedItemEnumerator start];
}
//start scanner thread
[self.scannerThread start];
//set flag
// ->indicates that this isn't first scan
self.secondaryScan = YES;
return;
}
//thread function
// ->runs in the background to execute each plugin
-(void)scan
{
//flag indicating an active VT thread
BOOL activeThread = NO;
//set scan flag
self.isConnected = isNetworkConnected();
//iterate over all plugins
// ->invoke's each scan message
for(PluginBase* plugin in self.plugins)
{
//pool
@autoreleasepool
{
//exit if scanner (self) thread was cancelled
if(YES == [[NSThread currentThread] isCancelled])
{
//exit
[NSThread exit];
}
//update scanner msg
dispatch_async(dispatch_get_main_queue(), ^{
//show
self.statusText.hidden = NO;
//update
[self.statusText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Scanning: %@", @"Scanning: %@"), plugin.name]];
});
//set callback
plugin.callback = ^(ItemBase* item)
{
[self itemFound:item];
};
//scan
// will invoke callback as items are found
[plugin scan];
//when 'disable VT' prefs not selected and network is reachable
// ->kick of thread to perform VT query in background
if( (YES != self.prefsWindowController.disableVTQueries) &&
(YES == self.isConnected) )
{
//do query
[self queryVT:plugin];
}
}//pool
}
//if VT querying is enabled (default) and network is available
// ->wait till all VT threads are done
if( (YES != self.prefsWindowController.disableVTQueries) &&
(YES == self.isConnected) )
{
//update scanner msg
dispatch_async(dispatch_get_main_queue(), ^{
//update
[self.statusText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Awaiting VirusTotal results", @"Awaiting VirusTotal results")]];
});
//nap
// ->VT threads take some time to spawn/process
[NSThread sleepForTimeInterval:3.0f];
//wait for all VT threads to exit
while(YES)
{
//reset flag
activeThread = NO;
//sync
@synchronized(self.vtThreads)
{
//check all threads
for(NSThread* vtThread in self.vtThreads)
{
//check if still running
// ->set flag & break out of loop
if(YES == [vtThread isExecuting])
{
//set flag
activeThread = YES;
//bail
break;
}
}
}//sync
//check flag
if(YES != activeThread)
{
//finally no active threads
// ->bail
break;
}
//exit if scanner (self) thread was cancelled
if(YES == [[NSThread currentThread] isCancelled])
{
//exit
[NSThread exit];
}
//nap
[NSThread sleepForTimeInterval:0.5];
}//active thread
}//VT scanning enabled
//complete scan logic and show result
// ->but *only* if scan wasn't stopped
if(YES != [[NSThread currentThread] isCancelled])
{
//execute final scan logic
[self completeScan];
//stop ui & show informational alert
// ->executed on main thread
dispatch_async(dispatch_get_main_queue(), ^{
//update the UI
// ->reflect the stopped state
[self stopScanUI:SCAN_MSG_COMPLETE];
});
}//scan not stopped by user
return;
}
//kickoff a thread to query VT
-(void)queryVT:(PluginBase*)plugin
{
//virus total thread
NSThread* virusTotalThread = nil;
//alloc thread
// ->will query virus total to get info about all detected items
virusTotalThread = [[NSThread alloc] initWithTarget:virusTotalObj selector:@selector(getInfo:) object:plugin];
//start thread
[virusTotalThread start];
//sync
@synchronized(self.vtThreads)
{
//save it into array
[self.vtThreads addObject:virusTotalThread];
}
return;
}
//automatically invoked when user clicks logo
// ->load objective-see's html page
-(IBAction)logoButtonHandler:(id)sender
{
//open URL
// ->invokes user's default browser
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://objective-see.org"]];
return;
}
//callback method, invoked by plugin(s) when item is found
// ->update the 'total' count and the item table (if it's selected)
-(void)itemFound:(ItemBase*)item
{
//item backing item table
// ->depending on flilter status, either all items, or just known ones
NSArray* tableItems = nil;
//only show refresh table if
// a) filter is not enabled (e.g. show all)
// b) filtering is enable, but item is unknown
if( (YES == self.prefsWindowController.showTrustedItems) ||
((YES != self.prefsWindowController.showTrustedItems) && (YES != item.isTrusted)) )
{
//set table item array
// ->case: all
if(YES == self.prefsWindowController.showTrustedItems)
{
//set to all items
tableItems = item.plugin.allItems;
}
//set table item array
// ->case: unknown items
else
{
//set to unknown items
tableItems = item.plugin.untrustedItems;
}
//reload category table (on main thread)
// ->this will result in the 'total' being updated
dispatch_async(dispatch_get_main_queue(), ^{
//begin updates
[self.itemTableController.itemTableView beginUpdates];
//update category table row
// ->this will result in the 'total' being updated
[self.categoryTableController.categoryTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:[self.plugins indexOfObject:item.plugin]] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
//if this plugin is currently the selected one (in the category table)
// ->update the item row
if(self.selectedPlugin == item.plugin)
{
//first tell item table the # of items have changed
[self.itemTableController.itemTableView noteNumberOfRowsChanged];
//reload just the new row
[self.itemTableController.itemTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:(tableItems.count-1)] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}
//end updates
[self.itemTableController.itemTableView endUpdates];
});
}
return;
}
//callback method, invoked by virus total when plugin's items have been processed
// ->reload table if plugin matches active plugin
-(void)itemsProcessed:(PluginBase*)plugin
{
//if there are any flagged items
// ->reload category table (to trigger title turning red)
if(0 != plugin.flaggedItems.count)
{
//reload category table
[self.categoryTableController customReload];
}
//check if active plugin matches
if(plugin == self.selectedPlugin)
{
//scroll to top of item table
[self.itemTableController scrollToTop];
//reload item table
[self.itemTableController.itemTableView reloadData];
}
return;
}
//update a single row
-(void)itemProcessed:(File*)fileObj
{
//row index
__block NSUInteger rowIndex = NSNotFound;
//current items
__block NSArray* tableItems = nil;
//reload category table
[self.categoryTableController customReload];
//check if active plugin matches
if(fileObj.plugin == self.selectedPlugin)
{
//get current items
tableItems = [self.itemTableController getTableItems];
//find index of item
rowIndex = [tableItems indexOfObject:fileObj];
//reload row
if(NSNotFound != rowIndex)
{
//start table updates
[self.itemTableController.itemTableView beginUpdates];
//update
[self.itemTableController.itemTableView reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
//end table updates
[self.itemTableController.itemTableView endUpdates];
}
}
return;
}
//callback method, invoked by category table controller when OS/user clicks a row
// ->lookup/save the selected plugin & reload the item table
-(void)categorySelected:(NSUInteger)rowIndex
{
//save selected plugin
self.selectedPlugin = self.plugins[rowIndex];
//scroll to top of item table
[self.itemTableController scrollToTop];
//reload item table
[self.itemTableController.itemTableView reloadData];
return;
}
//callback when user has updated prefs
// ->reload table, etc
-(void)applyPreferences
{
//currently selected category
NSUInteger selectedCategory = 0;
//get currently selected category
selectedCategory = self.categoryTableController.categoryTableView.selectedRow;
//reload category table
[self.categoryTableController customReload];
//reloading the category table resets the selected plugin
// ->so manually (re)set it here
self.selectedPlugin = self.plugins[selectedCategory];
//reload item table
[self.itemTableController.itemTableView reloadData];
//(re)check network connectivity
// ->set iVar
self.isConnected = isNetworkConnected();
//if VT query was never done (e.g. scan was started w/ pref disabled) and network is available
// ->kick off VT queries now
if( (0 == self.vtThreads.count) &&
(YES != self.prefsWindowController.disableVTQueries) &&
(YES == self.isConnected) )
{
//iterate over all plugins
// ->do VT query for each
for(PluginBase* plugin in self.plugins)
{
//do query
[self queryVT:plugin];
}
}
return;
}
//update the UI to reflect that the fact the scan was started
// ->disable settings, set text 'stop scan', etc...
-(void)startScanUI
{
//if scan was previous run
// ->will need to shift status msg back over
if(YES != [[self.statusText stringValue] isEqualToString:@""])
{
//reset
self.statusTextConstraint.constant = 56;
}
//reset category table
[self.categoryTableController.categoryTableView reloadData];
//reset item table
[self.itemTableController.itemTableView reloadData];
//show progress indicator
self.progressIndicator.hidden = NO;
//start spinner
[self.progressIndicator startAnimation:nil];
//set status msg
// ->scanning started
[self.statusText setStringValue:SCAN_MSG_STARTED];
//update button's image
self.scanButton.image = [NSImage imageNamed:@"stopScan"];
//update button's backgroud image
self.scanButton.alternateImage = [NSImage imageNamed:@"stopScanBG"];
//set label text to 'Stop Scan'
self.scanButtonLabel.stringValue = NSLocalizedString(@"Stop Scan", @"Stop Scan");
//disable gear (show prefs) button
self.showSettingsButton.enabled = NO;
//disable save button
self.saveButton.enabled = NO;
//disable compare button
self.compareButton.enabled = NO;
return;
}
//execute logic to complete scan
// ->ensures various threads are terminated, etc
-(void)completeScan
{
//tell enumerator to stop
[sharedItemEnumerator stop];
//cancel enumerator thread
if(YES == [sharedItemEnumerator.enumeratorThread isExecuting])
{
//cancel
[sharedItemEnumerator.enumeratorThread cancel];
}
//sync to cancel all VT threads
@synchronized(self.vtThreads)
{
//tell all VT threads to bail
for(NSThread* vtThread in self.vtThreads)
{
//cancel running threads
if(YES == [vtThread isExecuting])
{
//cancel
[vtThread cancel];
}
}
}
//remove all VT threads
[self.vtThreads removeAllObjects];
//when invoked from the UI (e.g. 'Stop Scan' was clicked)
// ->cancel scanner thread
if([NSThread currentThread] != self.scannerThread)
{
//cancel scanner thread
if(YES == [self.scannerThread isExecuting])
{
//cancel
[self.scannerThread cancel];
}
}
return;
}
//update the UI to reflect that the fact the scan was stopped
// ->set text back to 'start scan', etc...
-(void)stopScanUI:(NSString*)statusMsg
{
//stop spinner
[self.progressIndicator stopAnimation:nil];
//hide progress indicator
self.progressIndicator.hidden = YES;
//shift over status msg
self.statusTextConstraint.constant = 10;
//set status msg
[self.statusText setStringValue:statusMsg];
//update button's image
self.scanButton.image = [NSImage imageNamed:@"startScan"];
//update button's backgroud image
self.scanButton.alternateImage = [NSImage imageNamed:@"startScanBG"];
//set label text to 'Start Scan'
self.scanButtonLabel.stringValue = NSLocalizedString(@"Start Scan", @"Start Scan");
//(re)enable gear (show prefs) button
self.showSettingsButton.enabled = YES;
//(re)enable save button
self.saveButton.enabled = YES;
//enable compare button
self.compareButton.enabled = YES;
//only show scan stats for completed scan
if(YES == [statusMsg isEqualToString:SCAN_MSG_COMPLETE])
{
//display scan stats in UI (popup)
[self displayScanStats];
}
return;
}
//shows alert stating that that scan is complete (w/ stats)
-(void)displayScanStats
{
//detailed results msg
NSMutableString* details = nil;
//unknown items message
NSString* vtDetails = nil;
//item count
NSUInteger items = 0;
//flagged item count
NSUInteger flaggedItems = 0;
//unknown items
NSMutableArray* unknownItems = nil;
//init
unknownItems = [NSMutableArray array];
//iterate over all plugins
// sum up their item counts and flag items count
for(PluginBase* plugin in self.plugins)
{
//when showing all (including OS) findings
if(YES == self.prefsWindowController.showTrustedItems)
{
//add up
items += plugin.allItems.count;
//add plugin's flagged items
flaggedItems += plugin.flaggedItems.count;
//add unknown file items
// plugins will only have one type, so can just check first
if(YES == [[plugin.unknownItems firstObject] isKindOfClass:[File class]])
{
//add
[unknownItems addObjectsFromArray:plugin.unknownItems];
}
//init detailed msg
details = [NSMutableString stringWithFormat:NSLocalizedString(@"Found %lu persistent items", @"Found %lu persistent items"), (unsigned long)items];
}
//not showing OS files
else
{
//add up
items += plugin.untrustedItems.count;
//manually check if each untrusted item is flagged/unknown
for(ItemBase* item in plugin.untrustedItems)
{
//check if item is flagged
if(YES == [plugin.flaggedItems containsObject:item])
{
//inc
flaggedItems++;
}
//check if item is unknown
// but has to be a File* object
if(YES == [item isKindOfClass:[File class]])
{
//is unknown?
if(YES == [plugin.unknownItems containsObject:item])
{
//add
[unknownItems addObject:item];
}
}
}
//init detailed msg
details = [NSMutableString stringWithFormat:NSLocalizedString(@"Found %lu persistent (non-OS) items", @"Found %lu persistent (non-OS) items"), (unsigned long)items];
}
}
//when VT integration is enabled
// add flagged and unknown items
if(YES != self.prefsWindowController.disableVTQueries)
{
//when network is down
// ->add msg about not being able to query VT
if(YES != self.isConnected)
{