This commit is contained in:
OpticFusion1
2024-01-20 13:44:40 -05:00
parent 1d9523c4ee
commit 082e0e735f
2 changed files with 20 additions and 7 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>MCAntiMalware</artifactId>
<version>15.10</version>
<version>15.11</version>
<packaging>jar</packaging>
<parent>
@@ -21,9 +21,12 @@ import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
@@ -59,6 +62,7 @@ public class FileScanner {
private final CommandLineParser commandLineParser;
private final CheckManager checkManager;
private final BiConsumer<Path, CheckResult> notifications;
private List<Path> alreadyScanned = new ArrayList<>();
public FileScanner(CacheContainer cache, Database database, CommandLineParser commandLineParser, CheckManager checkManager, BiConsumer<Path, CheckResult> notifications) {
this.cache = cache;
@@ -69,12 +73,15 @@ public class FileScanner {
}
public void scanFile(Path file) {
if (alreadyScanned.contains(file)) {
return;
}
alreadyScanned.add(file);
// Not needed because this method shouldn't be called with a directory like tf it's FileScanner.scanFile like bruh
// if (Files.isDirectory(file)) {
// scanDirectory(file);
// return;
// }
if (ScanHelper.isFileEmpty(file)) {
return;
}
@@ -181,32 +188,38 @@ public class FileScanner {
AtomicBoolean possiblyMalicious = new AtomicBoolean(false);
walkThroughFiles(rootFolder, classPath -> {
if (!validClassPath(classPath)) {
// Walks through every file within the .jar, .zip, or .rar file
walkThroughFiles(rootFolder, zipEntryPath -> {
// Checks if the zipEntryPath is a valid .class file
if (!validClassPath(zipEntryPath)) {
return;
}
ClassNode classNode = cache.fetchClass(file, classPath);
// Gets an instance of the .class. Returns null if not possible
ClassNode classNode = cache.fetchClass(file, zipEntryPath);
if (classNode == null) {
return;
}
// Loops through every Anti-Malware check
for (BaseCheck check : checkManager.getChecks()) {
// Processes the classNode, rootFolder, and the file itself
List<CheckResult> results = check.process(classNode, rootFolder, file, cache);
if (results == null || results.isEmpty()) {
continue;
}
// Used to determine if the "probably_safe" notification should be used
possiblyMalicious.set(true);
// Loops through the Check results and sends a notification
for (CheckResult checkResult : results) {
if (commandLineParser.dontLogINFOCR() && checkResult.getType().equals("INFO")) {
continue;
}
submitNotification(file, checkResult);
}
// Resets the check to its default state
check.reset();
}
});