added reachability checks

->VT now only queried if computer is connected to network
This commit is contained in:
Patrick Wardle
2015-08-02 16:19:47 -07:00
parent 365e078bce
commit 06ec61e631
8 changed files with 103 additions and 96 deletions
+2 -5
View File
@@ -31,14 +31,13 @@
}
//Filter obj
//@property (nonatomic, retain) Filter* filter;
//connection flag
@property BOOL isConnected;
//'filter task' search box
// ->top pane
@property (weak) IBOutlet NSSearchField *filterTasksBox;
//(current) bottom view controller
@property(nonatomic, retain)TaskTableController *bottomViewController;
@@ -52,7 +51,6 @@
//task table controller object
@property (nonatomic, retain)TaskTableController *taskTableController;
//current task view format
// ->flat or tree
@property NSUInteger taskViewFormat;
@@ -161,7 +159,6 @@
// ->query OS to refresh/reload all tasks
-(IBAction)refreshTasks:(id)sender;
//callback when user has updated prefs
// ->reload table, etc
//-(void)applyPreferences;
+1 -27
View File
@@ -28,6 +28,7 @@
@synthesize filterObj;
@synthesize vtThreads;
@synthesize isConnected;
@synthesize virusTotalObj;
@synthesize taskTableController;
@synthesize aboutWindowController;
@@ -152,7 +153,6 @@
//init XPC
if(YES != [self initXPC])
{
//bail
goto bail;
}
@@ -771,32 +771,6 @@ bail:
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
+8 -3
View File
@@ -85,10 +85,15 @@
//process
//->for now, just hash, etc
[binary generateDetailedInfo];
//add item for VT processing
[vtObject addItem:binary];
//when connected
// ->add item for VT processing
if(YES == ((AppDelegate*)[[NSApplication sharedApplication] delegate]).isConnected)
{
//add
[vtObject addItem:binary];
}
//unlock
[self.queueCondition unlock];
+4 -3
View File
@@ -20,8 +20,6 @@
#import <unistd.h>
@implementation TaskEnumerator
@@ -32,7 +30,6 @@
@synthesize executables;
//init
-(id)init
{
@@ -61,6 +58,7 @@
//enumerate all tasks
// ->calls back into app delegate to update task (top) table when pau
// TODO: call every x # of seconds?
// TODO: existsing tasks w/ nil vtInfo, call [vtObject addItem:binary] ?
-(void)enumerateTasks
{
//(new) task item
@@ -72,6 +70,9 @@
//new tasks
OrderedDictionary* newTasks = nil;
//set connected flag
((AppDelegate*)[[NSApplication sharedApplication] delegate]).isConnected = isNetworkConnected();
//get all tasks
// ->pids and binary obj with just path/name
newTasks = [self getAllTasks];
+4
View File
@@ -49,6 +49,7 @@
CD7B9FA71ACCAE5E00DF3C71 /* startScanOver.png in Resources */ = {isa = PBXBuildFile; fileRef = CD7B9FA51ACCAE5E00DF3C71 /* startScanOver.png */; };
CD7B9FA81ACCAE5E00DF3C71 /* stopScanOver.png in Resources */ = {isa = PBXBuildFile; fileRef = CD7B9FA61ACCAE5E00DF3C71 /* stopScanOver.png */; };
CD7B9FAB1AD08FA100DF3C71 /* KKRow.m in Sources */ = {isa = PBXBuildFile; fileRef = CD7B9FAA1AD08FA100DF3C71 /* KKRow.m */; };
CD7FBF251B6EDAC000578C5D /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD7FBF241B6EDAC000578C5D /* SystemConfiguration.framework */; };
CD83887F1AACCEDF000EB098 /* VirusTotal.m in Sources */ = {isa = PBXBuildFile; fileRef = CD83887E1AACCEDF000EB098 /* VirusTotal.m */; };
CDA5F6B41B16D805003CE340 /* remoteTaskService.m in Sources */ = {isa = PBXBuildFile; fileRef = CDA5F6B31B16D805003CE340 /* remoteTaskService.m */; };
CDA5F6B61B16D805003CE340 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CDA5F6B51B16D805003CE340 /* main.m */; };
@@ -199,6 +200,7 @@
CD7B9FA61ACCAE5E00DF3C71 /* stopScanOver.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = stopScanOver.png; path = images/stopScanOver.png; sourceTree = SOURCE_ROOT; };
CD7B9FA91AD08FA100DF3C71 /* KKRow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KKRow.h; sourceTree = "<group>"; };
CD7B9FAA1AD08FA100DF3C71 /* KKRow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KKRow.m; sourceTree = "<group>"; };
CD7FBF241B6EDAC000578C5D /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
CD83887D1AACCEDF000EB098 /* VirusTotal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VirusTotal.h; sourceTree = "<group>"; };
CD83887E1AACCEDF000EB098 /* VirusTotal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VirusTotal.m; sourceTree = "<group>"; };
CDA5F6AD1B16D805003CE340 /* remoteTaskService.xpc */ = {isa = PBXFileReference; explicitFileType = "wrapper.xpc-service"; includeInIndex = 0; path = remoteTaskService.xpc; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -290,6 +292,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CD7FBF251B6EDAC000578C5D /* SystemConfiguration.framework in Frameworks */,
CDF08CEA1AC8D97B009B3423 /* Quartz.framework in Frameworks */,
CD6095731A87067D00E091CD /* Security.framework in Frameworks */,
1D21BC4F172AF43D009D1CFD /* Cocoa.framework in Frameworks */,
@@ -347,6 +350,7 @@
1D21BC4D172AF43D009D1CFD /* Frameworks */ = {
isa = PBXGroup;
children = (
CD7FBF241B6EDAC000578C5D /* SystemConfiguration.framework */,
CDF08CE91AC8D97B009B3423 /* Quartz.framework */,
CD6095721A87067D00E091CD /* Security.framework */,
1D21BC4E172AF43D009D1CFD /* Cocoa.framework */,
@@ -39,22 +39,6 @@
moduleName = "">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "VirusTotal.m"
timestampString = "459880884.303039"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "123"
endingLineNumber = "123"
landmarkName = "-addItem:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
@@ -135,22 +119,6 @@
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "VirusTotal.m"
timestampString = "459880884.303039"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "-addItem:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
@@ -222,27 +190,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TaskEnumerator.m"
timestampString = "459880884.303039"
timestampString = "460249948.079536"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "169"
endingLineNumber = "169"
landmarkName = "-enumerateTasks"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "TaskEnumerator.m"
timestampString = "459880884.303039"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "123"
endingLineNumber = "123"
startingLineNumber = "170"
endingLineNumber = "170"
landmarkName = "-enumerateTasks"
landmarkType = "5">
</BreakpointContent>
@@ -254,11 +206,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "AppDelegate.m"
timestampString = "460247716.301871"
timestampString = "460249848.18895"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "1619"
endingLineNumber = "1619"
startingLineNumber = "1593"
endingLineNumber = "1593"
landmarkName = "-constrainView:subView:"
landmarkType = "5">
</BreakpointContent>
@@ -318,11 +270,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "AppDelegate.m"
timestampString = "460246314.23885"
timestampString = "460249848.18895"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "828"
endingLineNumber = "828"
startingLineNumber = "802"
endingLineNumber = "802"
landmarkName = "-reloadTaskTable"
landmarkType = "5">
</BreakpointContent>
+3
View File
@@ -68,4 +68,7 @@ NSString* path2Kernel();
//determine if process is (still) alive
BOOL isAlive(pid_t targetPID);
//check if computer has network connection
BOOL isNetworkConnected();
#endif
+72 -1
View File
@@ -17,6 +17,7 @@
#import <Security/Security.h>
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>
#import <SystemConfiguration/SystemConfiguration.h>
//check if OS is supported
// ->Lion and newer
@@ -694,10 +695,80 @@ BOOL isAlive(pid_t targetPID)
if( (0 != kill(targetPID, 0)) &&
(ESRCH == errno) )
{
//alive
isAlive = NO;
}
return isAlive;
}
//check if computer has network connection
BOOL isNetworkConnected()
{
//flag
BOOL isConnected = NO;
//sock addr stuct
struct sockaddr zeroAddress = {0};
//reachability ref
SCNetworkReachabilityRef reachabilityRef = NULL;
//reachability flags
SCNetworkReachabilityFlags flags = 0;
//reachable flag
BOOL isReachable = NO;
//connection required flag
BOOL connectionRequired = NO;
//ensure its cleared out
bzero(&zeroAddress, sizeof(zeroAddress));
//set size
zeroAddress.sa_len = sizeof(zeroAddress);
//set family
zeroAddress.sa_family = AF_INET;
//create reachability ref
reachabilityRef = SCNetworkReachabilityCreateWithAddress(NULL, (const struct sockaddr*)&zeroAddress);
//sanity check
if(NULL == reachabilityRef)
{
//bail
goto bail;
}
//get flags
if(TRUE != SCNetworkReachabilityGetFlags(reachabilityRef, &flags))
{
//bail
goto bail;
}
//set reachable flag
isReachable = ((flags & kSCNetworkFlagsReachable) != 0);
//set connection required flag
connectionRequired = ((flags & kSCNetworkFlagsConnectionRequired) != 0);
//finally
// ->determine if network is available
isConnected = (isReachable && !connectionRequired) ? YES : NO;
//bail
bail:
//cleanup
if(NULL != reachabilityRef)
{
//release
CFRelease(reachabilityRef);
}
return isConnected;
}