From ea0276a0b318ea516ffffa0d142154433c2656cc Mon Sep 17 00:00:00 2001 From: rcx Date: Wed, 17 Jul 2019 03:42:38 -0400 Subject: [PATCH] Write decompiler filters for dropping illegal annotations and local variable tables --- src/main/java/club/bytecode/the/jda/JDA.java | 11 +++++++- .../decompilers/filter/DecompileFilters.java | 1 + .../filter/DropLocalVariableTableFilter.java | 22 +++++++++++++++ .../filter/IllegalAnnotationFilter.java | 28 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/java/club/bytecode/the/jda/decompilers/filter/DropLocalVariableTableFilter.java create mode 100644 src/main/java/club/bytecode/the/jda/decompilers/filter/IllegalAnnotationFilter.java diff --git a/src/main/java/club/bytecode/the/jda/JDA.java b/src/main/java/club/bytecode/the/jda/JDA.java index d408120..3fa750d 100644 --- a/src/main/java/club/bytecode/the/jda/JDA.java +++ b/src/main/java/club/bytecode/the/jda/JDA.java @@ -4,6 +4,9 @@ import club.bytecode.the.jda.api.JDANamespace; import club.bytecode.the.jda.api.JDAPlugin; import club.bytecode.the.jda.api.PluginLoader; +import club.bytecode.the.jda.decompilers.filter.DecompileFilters; +import club.bytecode.the.jda.decompilers.filter.DropLocalVariableTableFilter; +import club.bytecode.the.jda.decompilers.filter.IllegalAnnotationFilter; import club.bytecode.the.jda.gui.MainViewerGUI; import club.bytecode.the.jda.gui.fileviewer.BytecodeFoldParser; import club.bytecode.the.jda.gui.fileviewer.BytecodeTokenizer; @@ -73,6 +76,7 @@ public static void main(String[] args) { System.out.println("JDA v" + version); getJDADirectory(); + registerModules(); loadPlugins(); Settings.loadGUI(); @@ -102,7 +106,12 @@ public static void unloadPlugin(JDAPlugin plugin) { public static List getLoadedPlugins() { return Collections.unmodifiableList(plugins); } - + + private static void registerModules() { + DecompileFilters.registerFilter(new IllegalAnnotationFilter()); + DecompileFilters.registerFilter(new DropLocalVariableTableFilter()); + } + private static void loadPlugins() throws MalformedURLException { if (autoloadPlugin != null) { JDAPlugin plugin = autoloadPlugin.get(); diff --git a/src/main/java/club/bytecode/the/jda/decompilers/filter/DecompileFilters.java b/src/main/java/club/bytecode/the/jda/decompilers/filter/DecompileFilters.java index 15fcd21..1adbff4 100644 --- a/src/main/java/club/bytecode/the/jda/decompilers/filter/DecompileFilters.java +++ b/src/main/java/club/bytecode/the/jda/decompilers/filter/DecompileFilters.java @@ -10,6 +10,7 @@ public class DecompileFilters { public static void registerFilter(DecompileFilter filter) { BY_NAME.put(filter.getFullName(), filter); + System.out.println("Decompile filter registered: " + filter.getFullName()); } public static Collection getAllFilters() { diff --git a/src/main/java/club/bytecode/the/jda/decompilers/filter/DropLocalVariableTableFilter.java b/src/main/java/club/bytecode/the/jda/decompilers/filter/DropLocalVariableTableFilter.java new file mode 100644 index 0000000..d5dee38 --- /dev/null +++ b/src/main/java/club/bytecode/the/jda/decompilers/filter/DropLocalVariableTableFilter.java @@ -0,0 +1,22 @@ +package club.bytecode.the.jda.decompilers.filter; + +import club.bytecode.the.jda.JDA; +import club.bytecode.the.jda.api.JDANamespace; +import org.objectweb.asm.tree.ClassNode; + +public class DropLocalVariableTableFilter implements DecompileFilter { + @Override + public void process(ClassNode cn) { + cn.methods.forEach(methodNode -> methodNode.localVariables.clear()); + } + + @Override + public String getName() { + return "Drop local variable table"; + } + + @Override + public JDANamespace getNamespace() { + return JDA.namespace; + } +} diff --git a/src/main/java/club/bytecode/the/jda/decompilers/filter/IllegalAnnotationFilter.java b/src/main/java/club/bytecode/the/jda/decompilers/filter/IllegalAnnotationFilter.java new file mode 100644 index 0000000..bc8233d --- /dev/null +++ b/src/main/java/club/bytecode/the/jda/decompilers/filter/IllegalAnnotationFilter.java @@ -0,0 +1,28 @@ +package club.bytecode.the.jda.decompilers.filter; + +import club.bytecode.the.jda.JDA; +import club.bytecode.the.jda.api.JDANamespace; +import org.objectweb.asm.tree.ClassNode; + +public class IllegalAnnotationFilter implements DecompileFilter { + @Override + public void process(ClassNode cn) { + cn.methods.forEach(methodNode -> { + if (methodNode.invisibleAnnotations != null) + methodNode.invisibleAnnotations.removeIf(node -> node.desc.equals("@")); + }); + + if (cn.invisibleAnnotations != null) + cn.invisibleAnnotations.removeIf(node -> node.desc.equals("@")); + } + + @Override + public String getName() { + return "Kill illegal annotations"; + } + + @Override + public JDANamespace getNamespace() { + return JDA.namespace; + } +}