From 3595f859fe1f6b427b0f9bfa6d636ad8e438c3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BCrklin?= Date: Wed, 6 Oct 2021 15:48:22 +0200 Subject: [PATCH] Fix not detecting classes when spigot is launch-wrapped. --- .../utilities/reflection/ClassGetter.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java index 010d0893..f5930aa2 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassGetter.java @@ -51,19 +51,23 @@ public class ClassGetter { // Get a File object for the package CodeSource src = runFrom.getProtectionDomain().getCodeSource(); - if (src != null) { URL resource = src.getLocation(); - - if (resource.getPath().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { + boolean isInsideJar = resource.getPath().toLowerCase(Locale.ENGLISH).contains(".jar!") && resource.getPath().toLowerCase(Locale.ENGLISH).endsWith(".class"); + if (resource.getPath().toLowerCase(Locale.ENGLISH).endsWith(".jar") || isInsideJar) { processJarfile(resource, pkgname, classes); } else { - for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) { - if (f.getName().contains("$")) { - continue; - } + File[] baseFileList = new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles(); + if (baseFileList != null) { + for (File f : baseFileList){ + if (f.getName().contains("$")) { + continue; + } - classes.add(pkgname + "/" + f.getName()); + classes.add(pkgname + "/" + f.getName()); + } + } else { + System.out.println("File not found for: " + resource.getPath() + "/" + pkgname.replace(".", "/")); } } }