Skip to content

Commit 3f774b5

Browse files
committed
Gui and setting boilerplate code for filters
1 parent a0cad77 commit 3f774b5

File tree

13 files changed

+122
-27
lines changed

13 files changed

+122
-27
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.decompilers.filter.DecompileFilter;
4+
import org.objectweb.asm.tree.ClassNode;
5+
6+
public class DeobfuscateFilter implements DecompileFilter, MapleComponent {
7+
@Override
8+
public void process(ClassNode cn) {
9+
10+
}
11+
12+
@Override
13+
public String getName() {
14+
return "Deobfuscator";
15+
}
16+
}

mapleir/src/main/java/org/mapleir/jdaplugin/ILDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.objectweb.asm.tree.ClassNode;
1616
import org.objectweb.asm.tree.MethodNode;
1717

18-
public class ILDecompiler extends JDADecompiler {
18+
public class ILDecompiler extends JDADecompiler implements MapleComponent {
1919
@Override
2020
public String decompileClassNode(FileContainer container, ClassNode cn) {
2121
TabbedStringWriter sw = new TabbedStringWriter();

mapleir/src/main/java/org/mapleir/jdaplugin/IRDecompiler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.mapleir.jdaplugin;
22

3-
import club.bytecode.the.jda.api.JDANamespace;
43
import club.bytecode.the.jda.decompilers.bytecode.*;
54
import org.mapleir.ir.algorithms.BoissinotDestructor;
65
import org.mapleir.ir.cfg.ControlFlowGraph;
@@ -12,7 +11,7 @@
1211
import java.util.Arrays;
1312
import java.util.Iterator;
1413

15-
public class IRDecompiler extends BytecodeDecompiler {
14+
public class IRDecompiler extends BytecodeDecompiler implements MapleComponent {
1615
@Override
1716
protected MethodNodeDecompiler getMethodNodeDecompiler(PrefixedStringBuilder sb, ClassNode cn, Iterator<MethodNode> it) {
1817
return new IRMethodDecompiler(this, sb, it.next(), cn);
@@ -22,11 +21,6 @@ protected MethodNodeDecompiler getMethodNodeDecompiler(PrefixedStringBuilder sb,
2221
public String getName() {
2322
return "MapleIR";
2423
}
25-
26-
@Override
27-
public JDANamespace getNamespace() {
28-
return MaplePlugin.getInstance().getNamespace();
29-
}
3024
}
3125

3226
class IRMethodDecompiler extends MethodNodeDecompiler {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.api.JDANamespace;
4+
import club.bytecode.the.jda.api.JDANamespacedComponent;
5+
6+
// Is this bad design...?
7+
public interface MapleComponent extends JDANamespacedComponent {
8+
@Override
9+
default JDANamespace getNamespace() {
10+
return MaplePlugin.getInstance().getNamespace();
11+
}
12+
}

mapleir/src/main/java/org/mapleir/jdaplugin/MaplePlugin.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import club.bytecode.the.jda.api.JDAPlugin;
55
import club.bytecode.the.jda.api.JDAPluginNamespace;
66
import club.bytecode.the.jda.decompilers.Decompilers;
7-
import club.bytecode.the.jda.decompilers.JDADecompiler;
7+
import club.bytecode.the.jda.decompilers.filter.DecompileFilters;
88
import org.mapleir.DefaultInvocationResolver;
99
import org.mapleir.app.client.SimpleApplicationContext;
1010
import org.mapleir.app.service.ApplicationClassSource;
@@ -22,8 +22,6 @@ public class MaplePlugin implements JDAPlugin {
2222
private static MaplePlugin instance;
2323

2424
public final Map<FileContainer, AnalysisContext> cxts = new HashMap<>();
25-
private final JDADecompiler MAPLEIR = new IRDecompiler();
26-
private final JDADecompiler MAPLEIL = new ILDecompiler();
2725
public final JDAPluginNamespace namespace = new JDAPluginNamespace(this);
2826

2927
public MaplePlugin() {
@@ -50,8 +48,9 @@ public JDAPluginNamespace getNamespace() {
5048

5149
@Override
5250
public void onLoad() {
53-
Decompilers.BY_NAME.put("MapleIR", MAPLEIR);
54-
Decompilers.BY_NAME.put("MapleIL", MAPLEIL);
51+
Decompilers.registerDecompiler(new IRDecompiler());
52+
Decompilers.registerDecompiler(new ILDecompiler());
53+
DecompileFilters.registerFilter(new DeobfuscateFilter());
5554
System.out.println("MapleIR plugin loaded");
5655
}
5756

src/main/java/club/bytecode/the/jda/api/JDANamespacedComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface JDANamespacedComponent {
66
JDANamespace getNamespace();
77

88
default String getFullName() {
9-
return getName() + ":" + getNamespace();
9+
return getNamespace() + ":" + getName();
1010
}
1111
}

src/main/java/club/bytecode/the/jda/decompilers/Decompilers.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,34 @@
88
import java.util.Map;
99

1010
public class Decompilers {
11-
public static final Map<String, JDADecompiler> BY_NAME = new LinkedHashMap<>();
11+
private static final Map<String, JDADecompiler> BY_NAME = new LinkedHashMap<>();
1212

1313
public final static JDADecompiler PROCYON = new ProcyonDecompiler();
1414
public final static JDADecompiler CFR = new CFRDecompiler();
1515
public final static JDADecompiler FERNFLOWER = new FernflowerDecompiler();
1616
public final static JDADecompiler BYTECODE = new BytecodeDecompiler();
1717

18+
public static void registerDecompiler(JDADecompiler decompiler) {
19+
BY_NAME.put(decompiler.getFullName(), decompiler);
20+
}
1821

1922
public static Collection<JDADecompiler> getAllDecompilers() {
2023
return Collections.unmodifiableCollection(BY_NAME.values());
2124
}
2225

26+
/**
27+
* @param name the FULL name of the decompiler
28+
* @return the decompiler, if found
29+
*/
2330
public static JDADecompiler getByName(String name) {
2431
return BY_NAME.get(name);
2532
}
2633

2734
static
2835
{
29-
Decompilers.BY_NAME.put(PROCYON.getName(), PROCYON);
30-
Decompilers.BY_NAME.put(CFR.getName(), CFR);
31-
Decompilers.BY_NAME.put(FERNFLOWER.getName(), FERNFLOWER);
32-
Decompilers.BY_NAME.put(BYTECODE.getName(), BYTECODE);
36+
registerDecompiler(PROCYON);
37+
registerDecompiler(CFR);
38+
registerDecompiler(FERNFLOWER);
39+
registerDecompiler(BYTECODE);
3340
}
3441
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
public class DecompileFilters {
99
public static final Map<String, DecompileFilter> BY_NAME = new LinkedHashMap<>();
1010

11+
public static void registerFilter(DecompileFilter filter) {
12+
BY_NAME.put(filter.getFullName(), filter);
13+
}
14+
1115
public static Collection<DecompileFilter> getAllFilters() {
1216
return Collections.unmodifiableCollection(BY_NAME.values());
1317
}
14-
18+
19+
/**
20+
* @param name the FULL name of the decompile filter
21+
* @return the filter, if found
22+
*/
1523
public static DecompileFilter getByName(String name) {
1624
return BY_NAME.get(name);
1725
}

src/main/java/club/bytecode/the/jda/gui/MainViewerGUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import club.bytecode.the.jda.api.JDAPlugin;
88
import club.bytecode.the.jda.decompilers.Decompilers;
99
import club.bytecode.the.jda.decompilers.JDADecompiler;
10+
import club.bytecode.the.jda.gui.components.TabbedPane;
1011
import club.bytecode.the.jda.gui.dialogs.AboutWindow;
1112
import club.bytecode.the.jda.gui.dialogs.FontOptionsDialog;
1213
import club.bytecode.the.jda.gui.dialogs.IntroWindow;
13-
import club.bytecode.the.jda.gui.dialogs.TabbedPane;
1414
import club.bytecode.the.jda.gui.fileviewer.FileViewerPane;
1515
import club.bytecode.the.jda.gui.fileviewer.Viewer;
1616
import club.bytecode.the.jda.gui.fileviewer.ViewerFile;
@@ -400,7 +400,7 @@ private JMenu generatePane(int id) {
400400

401401
for (JDADecompiler decompiler : Decompilers.getAllDecompilers()) {
402402
JRadioButtonMenuItem button = new JRadioButtonMenuItem(decompiler.getName());
403-
button.addActionListener((e) -> Settings.PANE_DECOMPILERS[id].set(decompiler.getName()));
403+
button.addActionListener((e) -> Settings.PANE_DECOMPILERS[id].set(decompiler.getFullName()));
404404
allDecompilers.get(group).put(button, decompiler);
405405
allDecompilersRev.get(group).put(decompiler, button);
406406
group.add(button);

src/main/java/club/bytecode/the/jda/gui/dialogs/TabbedPane.java renamed to src/main/java/club/bytecode/the/jda/gui/components/TabbedPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package club.bytecode.the.jda.gui.dialogs;
1+
package club.bytecode.the.jda.gui.components;
22

33
import javax.swing.*;
44
import javax.swing.plaf.basic.BasicButtonUI;
@@ -196,4 +196,4 @@ public void mouseExited(final MouseEvent e) {
196196
}
197197
};
198198

199-
}
199+
}

0 commit comments

Comments
 (0)