cube doesn't like calling it malware

This commit is contained in:
PiggyPiglet
2025-11-21 20:01:53 +08:00
parent a81ed63c0f
commit 403adeb217
2 changed files with 15 additions and 11 deletions

View File

@@ -92,7 +92,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
private final TaskScheduler scheduler = UniversalScheduler.getScheduler(this); private final TaskScheduler scheduler = UniversalScheduler.getScheduler(this);
private BukkitAudiences adventure; private BukkitAudiences adventure;
private boolean malwareDetected = false; private boolean maliciousExpansions = false;
/** /**
@@ -153,9 +153,9 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
public void onLoad() { public void onLoad() {
saveDefaultConfig(); saveDefaultConfig();
malwareDetected = new MaliciousExpansionCheck(this).runChecks(); maliciousExpansions = new MaliciousExpansionCheck(this).runChecks();
if (malwareDetected) { if (maliciousExpansions) {
return; return;
} }
@@ -164,7 +164,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
if (malwareDetected) { if (maliciousExpansions) {
return; return;
} }
@@ -185,6 +185,10 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
if (maliciousExpansions) {
return;
}
getCloudExpansionManager().kill(); getCloudExpansionManager().kill();
getLocalExpansionManager().kill(); getLocalExpansionManager().kill();

View File

@@ -46,35 +46,35 @@ public final class MaliciousExpansionCheck {
return false; return false;
} }
final Set<String> knownMalware; final Set<String> knownMaliciousExpansions;
try { try {
final String malware = Resources.toString(new URL("https://check.placeholderapi.com"), StandardCharsets.UTF_8); final String malware = Resources.toString(new URL("https://check.placeholderapi.com"), StandardCharsets.UTF_8);
knownMalware = Arrays.stream(malware.split("\n")).collect(Collectors.toSet()); knownMaliciousExpansions = Arrays.stream(malware.split("\n")).collect(Collectors.toSet());
} catch (Exception e) { } catch (Exception e) {
main.getLogger().log(Level.SEVERE, "Failed to download anti malware hash check list from https://check.placeholderapi.com", e); main.getLogger().log(Level.SEVERE, "Failed to download anti malware hash check list from https://check.placeholderapi.com", e);
return false; return false;
} }
final Set<String> malwarePaths = new HashSet<>(); final Set<String> maliciousPaths = new HashSet<>();
for (File file : expansionsFolder.listFiles()) { for (File file : expansionsFolder.listFiles()) {
try { try {
final String hash = Hashing.sha256().hashBytes(Files.asByteSource(file).read()).toString(); final String hash = Hashing.sha256().hashBytes(Files.asByteSource(file).read()).toString();
if (knownMalware.contains(hash)) { if (knownMaliciousExpansions.contains(hash)) {
malwarePaths.add(file.getAbsolutePath()); maliciousPaths.add(file.getAbsolutePath());
} }
} catch (Exception e) { } catch (Exception e) {
main.getLogger().log(Level.SEVERE, "Error occurred while trying to read " + file.getAbsolutePath(), e); main.getLogger().log(Level.SEVERE, "Error occurred while trying to read " + file.getAbsolutePath(), e);
} }
} }
if (malwarePaths.isEmpty()) { if (maliciousPaths.isEmpty()) {
return false; return false;
} }
main.getLogger().severe(String.format(MESSAGE, malwarePaths.stream().map(p -> "HASH OF " + p + " MATCHES KNOWN MALICIOUS EXPANSION DELETE IMMEDIATELY\n").collect(Collectors.joining()))); main.getLogger().severe(String.format(MESSAGE, maliciousPaths.stream().map(p -> "HASH OF " + p + " MATCHES KNOWN MALICIOUS EXPANSION DELETE IMMEDIATELY\n").collect(Collectors.joining())));
main.getServer().shutdown(); main.getServer().shutdown();
return true; return true;