Skip to content

Commit ea0276a

Browse files
committed
Write decompiler filters for dropping illegal annotations and local variable tables
1 parent bc99312 commit ea0276a

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/main/java/club/bytecode/the/jda/JDA.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import club.bytecode.the.jda.api.JDANamespace;
55
import club.bytecode.the.jda.api.JDAPlugin;
66
import club.bytecode.the.jda.api.PluginLoader;
7+
import club.bytecode.the.jda.decompilers.filter.DecompileFilters;
8+
import club.bytecode.the.jda.decompilers.filter.DropLocalVariableTableFilter;
9+
import club.bytecode.the.jda.decompilers.filter.IllegalAnnotationFilter;
710
import club.bytecode.the.jda.gui.MainViewerGUI;
811
import club.bytecode.the.jda.gui.fileviewer.BytecodeFoldParser;
912
import club.bytecode.the.jda.gui.fileviewer.BytecodeTokenizer;
@@ -73,6 +76,7 @@ public static void main(String[] args) {
7376
System.out.println("JDA v" + version);
7477
getJDADirectory();
7578

79+
registerModules();
7680
loadPlugins();
7781

7882
Settings.loadGUI();
@@ -102,7 +106,12 @@ public static void unloadPlugin(JDAPlugin plugin) {
102106
public static List<JDAPlugin> getLoadedPlugins() {
103107
return Collections.unmodifiableList(plugins);
104108
}
105-
109+
110+
private static void registerModules() {
111+
DecompileFilters.registerFilter(new IllegalAnnotationFilter());
112+
DecompileFilters.registerFilter(new DropLocalVariableTableFilter());
113+
}
114+
106115
private static void loadPlugins() throws MalformedURLException {
107116
if (autoloadPlugin != null) {
108117
JDAPlugin plugin = autoloadPlugin.get();

src/main/java/club/bytecode/the/jda/decompilers/filter/DecompileFilters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class DecompileFilters {
1010

1111
public static void registerFilter(DecompileFilter filter) {
1212
BY_NAME.put(filter.getFullName(), filter);
13+
System.out.println("Decompile filter registered: " + filter.getFullName());
1314
}
1415

1516
public static Collection<DecompileFilter> getAllFilters() {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package club.bytecode.the.jda.decompilers.filter;
2+
3+
import club.bytecode.the.jda.JDA;
4+
import club.bytecode.the.jda.api.JDANamespace;
5+
import org.objectweb.asm.tree.ClassNode;
6+
7+
public class DropLocalVariableTableFilter implements DecompileFilter {
8+
@Override
9+
public void process(ClassNode cn) {
10+
cn.methods.forEach(methodNode -> methodNode.localVariables.clear());
11+
}
12+
13+
@Override
14+
public String getName() {
15+
return "Drop local variable table";
16+
}
17+
18+
@Override
19+
public JDANamespace getNamespace() {
20+
return JDA.namespace;
21+
}
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package club.bytecode.the.jda.decompilers.filter;
2+
3+
import club.bytecode.the.jda.JDA;
4+
import club.bytecode.the.jda.api.JDANamespace;
5+
import org.objectweb.asm.tree.ClassNode;
6+
7+
public class IllegalAnnotationFilter implements DecompileFilter {
8+
@Override
9+
public void process(ClassNode cn) {
10+
cn.methods.forEach(methodNode -> {
11+
if (methodNode.invisibleAnnotations != null)
12+
methodNode.invisibleAnnotations.removeIf(node -> node.desc.equals("@"));
13+
});
14+
15+
if (cn.invisibleAnnotations != null)
16+
cn.invisibleAnnotations.removeIf(node -> node.desc.equals("@"));
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "Kill illegal annotations";
22+
}
23+
24+
@Override
25+
public JDANamespace getNamespace() {
26+
return JDA.namespace;
27+
}
28+
}

0 commit comments

Comments
 (0)