Skip to content

Commit

Permalink
Improved VT submissions and localizatations
Browse files Browse the repository at this point in the history
  • Loading branch information
objective-see committed Dec 1, 2024
1 parent 7660bc4 commit fae893f
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 143 deletions.
10 changes: 10 additions & 0 deletions AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,13 @@ -(void)startScanUI
//reset item table
[self.itemTableController.itemTableView reloadData];

//close results window
if(YES == [self.resultsWindowController.window isVisible])
{
//close
[self.resultsWindowController.window close];
}

//show progress indicator
self.progressIndicator.hidden = NO;

Expand Down Expand Up @@ -1042,6 +1049,9 @@ -(void)displayScanStats
//show it
[self.resultsWindowController showWindow:self];

//make front/visible
[self.resultsWindowController.window setLevel:NSPopUpMenuWindowLevel];

return;
}

Expand Down
45 changes: 17 additions & 28 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@
}
}
},
"Awaiting results..." : {
"comment" : "Awaiting results...",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Esperando resultados…"
}
}
}
},
"Awaiting VirusTotal results" : {
"comment" : "Awaiting VirusTotal results",
"localizations" : {
Expand Down Expand Up @@ -199,13 +188,13 @@
}
}
},
"ERROR:\nFailed to submit '%@' to VirusTotal" : {
"comment" : "ERROR:\nFailed to submit '%@' to VirusTotal",
"ERROR:\nVirusTotal query for '%@' failed" : {
"comment" : "ERROR:\nVirusTotal query for '%@' failed",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "ERROR:\nNo se pudo enviar '%@' a VirusTotal"
"value" : "ERROR:\nLa consulta de VirusTotal para '%@' falló"
}
}
}
Expand Down Expand Up @@ -254,17 +243,6 @@
}
}
},
"Failed to submit '%@'" : {
"comment" : "Failed to submit '%@'",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "No se pudo enviar '%@'"
}
}
}
},
"failed to submit '%@' to VirusTotal (HTTP response %ld)." : {
"comment" : "failed to submit '%@' to VirusTotal (HTTP response %ld).",
"localizations" : {
Expand Down Expand Up @@ -546,13 +524,13 @@
}
}
},
"Submissions complete, though errors were encountered (HTTP response: %@)." : {
"comment" : "Submissions complete, though errors were encountered (HTTP responses: %@).",
"Submissions complete, though errors were encountered (HTTP response(s): %@)." : {
"comment" : "Submissions complete, though errors were encountered (HTTP response(s): %@).",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Envíos completados, aunque se encontraron errores (respuesta HTTP: %@)."
"value" : "Envíos completados, aunque se encontraron errores (respuesta(s) HTTP: %@)."
}
}
}
Expand Down Expand Up @@ -590,6 +568,17 @@
}
}
},
"Submitting '%@'" : {
"comment" : "Submitting '%@'",
"localizations" : {
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Enviando '%@'"
}
}
}
},
"Submitting %lu item(s) to VirusTotal..." : {
"comment" : "Submitting %lu item(s) to VirusTotal...",
"localizations" : {
Expand Down
92 changes: 28 additions & 64 deletions ResultsWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ -(void)submissionComplete:(NSUInteger)successes httpResponses:(NSMutableArray*)h
else
{
//update message
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Submissions complete, though errors were encountered (HTTP response: %@).", @"Submissions complete, though errors were encountered (HTTP responses: %@)."), httpResponses];
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Submissions complete, though errors were encountered (HTTP response(s): %@).", @"Submissions complete, though errors were encountered (HTTP response(s): %@)."), [httpResponses componentsJoinedByString:@","]];
}

return;
Expand All @@ -121,27 +121,21 @@ -(void)submit
//error code(s)
NSMutableArray* httpResponses = nil;

//scan ids
NSMutableDictionary* scanIDs = nil;
//report
__block NSURL* newReport = nil;

//successful scans
NSUInteger successes = 0;

//alloc/init VT obj
vtObj = [[VirusTotal alloc] init];

//alloc
scanIDs = [NSMutableDictionary dictionary];

//alloc
httpResponses = [NSMutableArray array];

//submit all unknown items
for(ItemBase* item in self.unknownItems)
{
//scan id from VT
NSString* scanID = nil;

//skip non-file items
if(YES != [item isKindOfClass:[File class]])
{
Expand All @@ -157,6 +151,16 @@ -(void)submit
continue;
}

//update UI
dispatch_async(dispatch_get_main_queue(), ^{

//update
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Submitting '%@'", @"Submitting '%@'"), ((File*)item).name];
});

//nap (for UI)
sleep(1);

//submit file to VT
result = [vtObj submit:(File*)item];

Expand All @@ -165,28 +169,14 @@ -(void)submit
{
//add
[httpResponses addObject:[NSNumber numberWithUnsignedLong:[(NSHTTPURLResponse *)result[VT_HTTP_RESPONSE] statusCode]]];
}

//extract scan id
scanID = result[VT_RESULTS_SCANID];
if(nil == scanID)
{
//err msg
NSLog(@"KNOCKKNOCK ERROR: failed to submit %@", item.path);

//update UI
dispatch_async(dispatch_get_main_queue(), ^{

//update
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Failed to submit '%@'", @"Failed to submit '%@'"), ((File*)item).name];
});

//nap (for UI)
sleep(1);

//next
continue;
}

//happy
successes++;

//reset file's VT info
// as we've just submittted
((File*)item).vtInfo = nil;
Expand All @@ -199,50 +189,24 @@ -(void)submit

});

//save
scanIDs[scanID] = item;
}

//only continue if there were submissions
if(0 != scanIDs.count)
{
//nap for VT to process
sleep(5);
//nap
// allows msg to show up, and give VT some time
[NSThread sleepForTimeInterval:2.0];

//update UI
//launch browser to show new report
dispatch_async(dispatch_get_main_queue(), ^{

//update
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Awaiting results...", @"Awaiting results...")];
});

//nap more VT to process
sleep(5);

//get VT results
for(NSString* scanID in scanIDs.allKeys)
{
//get results for item
// waits until recieved (and updates UI on success)
if(YES != [vtObj getInfoForItem:(File*)scanIDs[scanID] scanID:scanID])
//launch browser with scan
if(nil != result[@"sha256"])
{
//update UI
dispatch_async(dispatch_get_main_queue(), ^{

//update
self.submissionStatus.stringValue = [NSString stringWithFormat:@"Failed to get results for '%@'", ((File*)scanIDs[scanID]).name];
});
//build url to scan
newReport = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.virustotal.com/gui/file/%@", result[@"sha256"]]];

//nap for UI
sleep(1);

continue;
//launch browser
[[NSWorkspace sharedWorkspace] openURL:newReport];
}

//happy
// results will show up in UI
successes++;
}
});
}

//tell UI all is done
Expand Down
42 changes: 21 additions & 21 deletions UI/Base.lproj/ResultsWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
<rect key="contentRect" x="196" y="240" width="588" height="284"/>
<rect key="screenRect" x="0.0" y="0.0" width="1512" height="944"/>
<rect key="contentRect" x="196" y="240" width="588" height="295"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="588" height="284"/>
<rect key="frame" x="0.0" y="0.0" width="588" height="295"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lEv-Wj-6S5">
<rect key="frame" x="11" y="108" width="121" height="133"/>
<rect key="frame" x="11" y="119" width="121" height="133"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="kkIcon" id="xKf-GK-m0k"/>
</imageView>
<textField hidden="YES" focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OSm-xS-Dmd">
<rect key="frame" x="63" y="48" width="507" height="45"/>
<rect key="frame" x="58" y="49" width="512" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="Submission Results..." id="bBK-v0-ypq">
<font key="font" size="14" name="Menlo-Regular"/>
Expand All @@ -42,7 +42,7 @@
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JfW-zc-kbJ">
<rect key="frame" x="133" y="180" width="405" height="46"/>
<rect key="frame" x="133" y="191" width="405" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Results..." id="c7T-S9-D47">
<font key="font" size="16" name="Menlo-Regular"/>
Expand All @@ -51,7 +51,7 @@
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kMk-T5-yaD">
<rect key="frame" x="133" y="122" width="241" height="57"/>
<rect key="frame" x="133" y="133" width="241" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="VirusTotal:" id="ivf-fv-SFp">
<font key="font" size="16" name="Menlo-Regular"/>
Expand All @@ -60,38 +60,38 @@
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="h9d-xm-5lM">
<rect key="frame" x="18" y="236" width="350" height="36"/>
<rect key="frame" x="18" y="247" width="350" height="36"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Scan Complete" id="viG-9e-1Nj">
<font key="font" size="30" name="Menlo-Bold"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HZZ-Es-mpy">
<rect key="frame" x="231" y="13" width="94" height="32"/>
<progressIndicator fixedFrame="YES" maxValue="100" displayedWhenStopped="NO" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="YES-az-MHy">
<rect key="frame" x="20" y="89" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="J9x-sM-h9S">
</progressIndicator>
<button hidden="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Czs-Di-8Qw">
<rect key="frame" x="368" y="124" width="207" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Submit (Unknown) Items" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="71T-dO-S3a">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="13" name="Menlo-Regular"/>
</buttonCell>
<connections>
<action selector="close:" target="-2" id="uMS-EM-Wl2"/>
<action selector="submitToVT:" target="-2" id="8u9-zJ-CMA"/>
</connections>
</button>
<progressIndicator fixedFrame="YES" maxValue="100" displayedWhenStopped="NO" indeterminate="YES" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="YES-az-MHy">
<rect key="frame" x="20" y="68" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
<button hidden="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Czs-Di-8Qw">
<rect key="frame" x="368" y="113" width="207" height="32"/>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HZZ-Es-mpy">
<rect key="frame" x="247" y="12" width="94" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Submit (Unknown) Items" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="71T-dO-S3a">
<buttonCell key="cell" type="push" title="Close" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="J9x-sM-h9S">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="13" name="Menlo-Regular"/>
</buttonCell>
<connections>
<action selector="submitToVT:" target="-2" id="8u9-zJ-CMA"/>
<action selector="close:" target="-2" id="uMS-EM-Wl2"/>
</connections>
</button>
</subviews>
Expand All @@ -100,7 +100,7 @@
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
<outlet property="initialFirstResponder" destination="HZZ-Es-mpy" id="dm3-Gf-qfl"/>
</connections>
<point key="canvasLocation" x="401" y="326"/>
<point key="canvasLocation" x="401" y="331.5"/>
</window>
</objects>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion UI/Base.lproj/UpdateWindow.xib
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
<rect key="contentRect" x="196" y="240" width="422" height="123"/>
<rect key="screenRect" x="0.0" y="0.0" width="1512" height="944"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="422" height="123"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down
Loading

0 comments on commit fae893f

Please sign in to comment.