Skip to content

Commit

Permalink
Write decompiler filters for dropping illegal annotations and local v…
Browse files Browse the repository at this point in the history
…ariable tables
  • Loading branch information
rcx committed Jul 17, 2019
1 parent bc99312 commit ea0276a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/club/bytecode/the/jda/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +76,7 @@ public static void main(String[] args) {
System.out.println("JDA v" + version);
getJDADirectory();

registerModules();
loadPlugins();

Settings.loadGUI();
Expand Down Expand Up @@ -102,7 +106,12 @@ public static void unloadPlugin(JDAPlugin plugin) {
public static List<JDAPlugin> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecompileFilter> getAllFilters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit ea0276a

Please sign in to comment.