diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java index cda5f778..abfd16e4 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm13.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.utilities.reflection.asm; import com.google.gson.Gson; +import lombok.Getter; import org.objectweb.asm.*; import java.io.IOException; @@ -14,9 +15,16 @@ import java.util.Map; * Created by libraryaddict on 17/02/2020. */ public class Asm13 implements IAsm { + @Getter + private Method defineMethod; + + public Asm13() throws NoSuchMethodException { + defineMethod = getDefineClassMethod(); + } + public Class createClassWithoutMethods(String className, ArrayList> illegalMethods) throws IOException, InvocationTargetException, - IllegalAccessException, NoSuchMethodException, NoSuchFieldException { + IllegalAccessException, NoSuchFieldException { ClassReader cr = new ClassReader( getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class")); ClassWriter writer = new ClassWriter(cr, 0); @@ -42,14 +50,13 @@ public class Asm13 implements IAsm { Field field = loader.getClass().getDeclaredField("classes"); field.setAccessible(true); Map> map = (Map>) field.get(loader); - Class newClass = (Class) getDefineClassMethod() - .invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length); + Class newClass = (Class) defineMethod.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length); map.put(className, newClass); return newClass; } - private static Method getDefineClassMethod() throws NoSuchMethodException { + private Method getDefineClassMethod() throws NoSuchMethodException { Method defineClass = ClassLoader.class .getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); defineClass.setAccessible(true); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java index 639b8238..ede3695c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm; +import lombok.Getter; import org.bukkit.craftbukkit.libs.org.objectweb.asm.*; import java.io.IOException; @@ -13,9 +14,16 @@ import java.util.Map; * Created by libraryaddict on 17/02/2020. */ public class Asm14 implements IAsm { + @Getter + private Method defineMethod; + + public Asm14() throws NoSuchMethodException { + defineMethod = getDefineClassMethod(); + } + public Class createClassWithoutMethods(String className, ArrayList> illegalMethods) throws IOException, InvocationTargetException, - IllegalAccessException, NoSuchMethodException, NoSuchFieldException { + IllegalAccessException, NoSuchFieldException { ClassReader cr = new ClassReader( getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class")); ClassWriter writer = new ClassWriter(cr, 0); @@ -41,16 +49,13 @@ public class Asm14 implements IAsm { Field field = loader.getClass().getDeclaredField("classes"); field.setAccessible(true); Map> map = (Map>) field.get(loader); - Class newClass = - - (Class) getDefineClassMethod() - .invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length); + Class newClass = (Class) defineMethod.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length); map.put(className, newClass); return newClass; } - private static Method getDefineClassMethod() throws NoSuchMethodException { + private Method getDefineClassMethod() throws NoSuchMethodException { Method defineClass = ClassLoader.class .getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); defineClass.setAccessible(true); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java index b754b2c5..c238a0e7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java @@ -1,5 +1,6 @@ package me.libraryaddict.disguise.utilities.reflection.asm; +import com.google.gson.Gson; import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; @@ -78,19 +79,21 @@ public class WatcherSanitizer { e.printStackTrace(); } - IAsm asm; - - if (NmsVersion.v1_14.isSupported()) { - asm = new Asm14(); - } else { - if (!NmsVersion.v1_13.isSupported()) { - new AsmDownloader(); - } - - asm = new Asm13(); - } + ArrayList mapped = new ArrayList<>(); try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) { + IAsm asm; + + if (NmsVersion.v1_14.isSupported()) { + asm = new Asm14(); + } else { + if (!NmsVersion.v1_13.isSupported()) { + new AsmDownloader(); + } + + asm = new Asm13(); + } + List lines = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() .collect(Collectors.toList()); @@ -115,10 +118,12 @@ public class WatcherSanitizer { for (Map.Entry>> entry : toRemove.entrySet()) { Class result = asm.createClassWithoutMethods(entry.getKey(), entry.getValue()); + mapped.add(entry.getKey()); } } - catch (IOException | NoClassDefFoundError | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException e) { + catch (IOException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | LinkageError e) { e.printStackTrace(); + LibsDisguises.getInstance().getLogger().severe("Registered: " + new Gson().toJson(mapped)); } } }