Skip to content

Commit 242b62e

Browse files
committed
batch shell files + comments
1 parent 55d4714 commit 242b62e

File tree

6 files changed

+6
-87
lines changed

6 files changed

+6
-87
lines changed

ScanResult.java

-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ private static void colorPrintEngine(ScanResult scanResult) {
8282
String engine = "";
8383

8484
// Truncate engine name
85-
// https://docs.oracle.com/javase/7/docs/api/java/lang/String.html
8685
try {
8786
engine = scanResult.getEngine().substring(0, MAX_ENGINE_LEN);
8887
}
@@ -136,8 +135,6 @@ public static void multiPrint(ScanResult[] scanResults, int column) {
136135
// Print color coded
137136
colorPrintEngine(scanResult);
138137

139-
// https://introcs.cs.princeton.edu/java/15inout/
140-
// https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html
141138
StdOut.printf("%-11.10s", scanResult.getResult());
142139

143140
// If time to print to next line or if user selected engine was found or

StdOut.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,4 @@ public static void main(String[] args) {
310310
StdOut.printf("%.6f\n", 1.0/7.0);
311311
}
312312

313-
}
313+
}

VT.java

-83
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ public static void colorPrint(boolean erase, Ansi.Color highlight,
7575

7676
// Clear terminal + print or don't clear terminal + print
7777
if (erase)
78-
79-
// http://fusesource.github.io/jansi/
8078
StdOut.print(ansi().eraseScreen().bg(highlight).fg(text).a(str)
8179
.reset());
8280
else
@@ -88,11 +86,6 @@ public static void colorPrint(boolean erase, Ansi.Color highlight,
8886
public static void printLogo(Ansi.Color text) {
8987

9088
// VirusTotal ascii art logo
91-
// https://www.virustotal.com/gui/home/upload
92-
// https://cloudconvert.com/svg-to-jpg
93-
// https://pypi.org/project/ascii-art-cli/
94-
// Python library for image -> ascii art
95-
// cmd: ascii-art "logo - Copy.jpg" --width 90 --height 9 --chars @.
9689
String logo =
9790
"\n.@@@@@@@@@@@@@@@@......................................"
9891
+ "...................................\n"
@@ -152,8 +145,6 @@ private static void help(String[] args, Ansi.Color text) {
152145
StdOut.println();
153146

154147
// End program
155-
// https://stackoverflow.com/questions/2434592/difference-in-syst
156-
// em-exit0-system-exit-1-system-exit1-in-java
157148
System.exit(0);
158149
}
159150
}
@@ -205,13 +196,9 @@ private static String cmdLineArg(String[] args, String flag,
205196
private static String fileExists(String filePath) {
206197

207198
// Absolute path of 'filePath'
208-
// https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html
209-
// https://docs.oracle.com/javase/tutorial/essential/io/pathOps.html
210-
// https://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html
211199
Path absFilePath = Paths.get(filePath).toAbsolutePath();
212200

213201
// Is the file valid, existing, accessible file
214-
// https://docs.oracle.com/javase/tutorial/essential/io/check.html
215202
boolean realFile = Files.isRegularFile(absFilePath)
216203
&& Files.isReadable(absFilePath)
217204
&& Files.isExecutable(absFilePath) && Files.exists(absFilePath);
@@ -243,11 +230,6 @@ public static WebElement findElement(WebDriver driver, String script,
243230
WebElement element = null;
244231

245232
// JavaScript 'script' returns something
246-
// https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/J
247-
// avascriptExecutor.html
248-
// https://www.browserstack.com/guide/javascriptexecutor-in-selenium
249-
// https://www.lambdatest.com/blog/how-to-use-javascriptexecutor-in-sele
250-
// nium-webdriver/
251233
try {
252234
JavascriptExecutor js = (JavascriptExecutor) driver;
253235
element = (WebElement) js.executeScript(script);
@@ -256,8 +238,6 @@ public static WebElement findElement(WebDriver driver, String script,
256238

257239
// If you want to return the HTML element, but JavaScript 'script'
258240
// doesn't return anything
259-
// https://www.oracle.com/technical-resources/articles/java/java8-op
260-
// tional.html
261241
if (element == null && !noReturn) {
262242

263243
// Color print error message
@@ -294,8 +274,6 @@ public static boolean foundString(WebDriver driver, String script) {
294274
}
295275

296276
// Execute 'script' again
297-
// https://stackoverflow.com/questions/40392594/java-try-and-catch-u
298-
// ntil-no-exception-is-thrown
299277
catch (JavascriptException e) {
300278
continue;
301279
}
@@ -355,46 +333,6 @@ public static void removeEngines(String selectEngine,
355333
// Runs everything
356334
public static void main(String[] args) {
357335

358-
//--------------------------------------------------------------
359-
// TESTING: runs if '--test' or '-t' flag is present
360-
// 2 methods to test: cmdLineArg and fileExists
361-
// Iterate through command line arguments
362-
for (int i = 0; i < args.length; i++) {
363-
if (args[i].equals("--test")) {
364-
// cmdLineArg test 1:
365-
String[] args0 = new String[] { "a", "-b", "follows b" };
366-
String afterB = cmdLineArg(args0, "--b", "-b");
367-
assert afterB.equals("follows b");
368-
369-
// cmdLineArg test 2:
370-
String[] args1 = new String[] { "vt", "--file", "file", "-e", "engine" };
371-
String file0 = cmdLineArg(args1, "--file", "-f");
372-
assert file0.equals("file");
373-
String engineName = cmdLineArg(args1, "--engine", "-e");
374-
assert engineName.equals("engine");
375-
376-
// cmdLineArg test 3:
377-
StdOut.println("\nThe following output is from a test case:");
378-
String[] args2 = new String[] { "vt", "--file" };
379-
String file1 = cmdLineArg(args2, "--file", "-f");
380-
assert file1 == null;
381-
382-
}
383-
384-
if (args[i].equals("-t")) {
385-
386-
// fileExists test 1:
387-
// https://www.delftstack.com/howto/java/java-get-type-of-object/
388-
StdOut.println(fileExists("ScanResult.java").getClass() ==
389-
String.class);
390-
391-
// filesExists test 2:
392-
StdOut.println("\nThe following output is from a test case:");
393-
StdOut.println(fileExists("asdfasdf").equals("sdf"));
394-
}
395-
}
396-
//--------------------------------------------------------------
397-
398336
// Color print logo
399337
printLogo(BLUE);
400338

@@ -419,10 +357,6 @@ public static void main(String[] args) {
419357
".\\chromedriver_win32\\chromedriver.exe");
420358

421359
// Browsing options
422-
// https://stackoverflow.com/questions/52975287/selenium-chromedrive
423-
// r-disable-logging-or-redirect-it-java
424-
// https://www.selenium.dev/selenium/docs/api/java/org/openqa/seleni
425-
// um/chrome/ChromeOptions.html
426360
ChromeOptions options = new ChromeOptions();
427361
options.setHeadless(true);
428362
// Logging suppression
@@ -440,13 +374,6 @@ public static void main(String[] args) {
440374

441375
// Find 'Choose file' button
442376
// Long messy JavaScript code to find the button
443-
// https://stackoverflow.com/questions/62799036/unable-to-locate-the
444-
// -sign-in-element-within-shadow-root-open-using-selenium-a/6280367
445-
// 1#62803671
446-
// https://stackoverflow.com/questions/59345959/how-to-pass-the-valu
447-
// e-in-search-on-url-https-www-virustotal-com-gui-home-searc
448-
// https://developer.mozilla.org/en-US/docs/Web/API/Document/querySe
449-
// lector
450377
String script = "return document.querySelector('vt-ui-shell"
451378
+ " div#view-container home-view')"
452379
+ ".shadowRoot.querySelector('div.wrapper"
@@ -457,7 +384,6 @@ public static void main(String[] args) {
457384
WebElement fileUpload = findElement(driver, script, false);
458385

459386
// Upload file
460-
// https://www.guru99.com/upload-download-file-selenium-webdriver.html
461387
fileUpload.sendKeys(absFilePath);
462388

463389
// Check if the file has been uploaded to VirusTotal before
@@ -486,10 +412,6 @@ public static void main(String[] args) {
486412
if (foundString(driver, scanCompleteScript)) {
487413
// Long messy JavaScript code to find + form Array of
488414
// each individual engine scan HTML element
489-
// https://www.geeksforgeeks.org/jquery-queryselector-vs-queryse
490-
// lectorall-methods/
491-
// https://www.techiediaries.com/javascript-queryselectorall-nod
492-
// elist-foreach/
493415
String resultScript
494416
= "return Array.from(document.querySelector("
495417
+ "'vt-ui-shell div#view-container file-view')"
@@ -517,12 +439,7 @@ public static void main(String[] args) {
517439
// Following try-catch needed because of
518440
// org.openqa.selenium.StaleElementReferenceException
519441
// Get engine name from engine scan element
520-
// https://stackoverflow.com/questions/19149327/selenium-exc
521-
// eption-in-thread-main-org-openqa-selenium-staleelementref
522-
// erenceex
523442
try {
524-
// https://docs.oracle.com/javase/7/docs/api/java/util/regex
525-
// /Pattern.html#sum
526443
engine = detectionElements.get(i).getText().split("\n")[0];
527444
}
528445

vt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib=".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar"
2+
javac -cp $lib StdOut.java && javac -cp $lib ScanResult.java && javac -cp $lib VT.java && java -cp $lib VT $@

vt.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
javac -cp ".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar" StdOut.java && javac -cp ".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar" ScanResult.java && javac -cp ".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar" VT.java && java -cp ".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar" VT %*

vt.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib=".;.\lib\introcs.jar;.\lib\stdlib.jar;.\lib\jansi-2.1.0.jar;.\lib\selenium-server-4.1.0.jar"
2+
javac -cp $lib StdOut.java && javac -cp $lib ScanResult.java && javac -cp $lib VT.java && java -cp $lib VT $@

0 commit comments

Comments
 (0)