summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui
diff options
context:
space:
mode:
authorGravatar asie2018-12-08 11:21:18 +0100
committerGravatar asie2018-12-08 11:21:18 +0100
commit4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5 (patch)
tree99e43aa385d7fa1248c7fe474c022db55c364592 /src/main/java/cuchaz/enigma/gui
parentwork around Procyon weirdness (diff)
downloadenigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.tar.gz
enigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.tar.xz
enigma-fork-4bc3afe4ff08b9f0c08952ec7f6e0ac930280cc5.zip
add barebones plugin framework, cleanup
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
-rw-r--r--src/main/java/cuchaz/enigma/gui/CodeReader.java1
-rw-r--r--src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java (renamed from src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java)2
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java41
-rw-r--r--src/main/java/cuchaz/enigma/gui/GuiController.java81
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java13
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java21
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java21
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java21
8 files changed, 88 insertions, 113 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/CodeReader.java b/src/main/java/cuchaz/enigma/gui/CodeReader.java
index ac45b4a..137c730 100644
--- a/src/main/java/cuchaz/enigma/gui/CodeReader.java
+++ b/src/main/java/cuchaz/enigma/gui/CodeReader.java
@@ -143,6 +143,7 @@ public class CodeReader extends JEditorPane {
143 { 143 {
144 144
145 // decompile it 145 // decompile it
146
146 CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName()); 147 CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName());
147 String source = deobfuscator.getSource(sourceTree); 148 String source = deobfuscator.getSource(sourceTree);
148 setCode(source); 149 setCode(source);
diff --git a/src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java b/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java
index d9fcee5..5ea0bc2 100644
--- a/src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java
+++ b/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java
@@ -5,7 +5,7 @@ import de.sciss.syntaxpane.components.LineNumbersRuler;
5import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; 5import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit;
6import de.sciss.syntaxpane.util.Configuration; 6import de.sciss.syntaxpane.util.Configuration;
7 7
8public class MinecraftSyntaxKit extends JavaSyntaxKit { 8public class EnigmaSyntaxKit extends JavaSyntaxKit {
9 private static Configuration configuration = null; 9 private static Configuration configuration = null;
10 10
11 @Override 11 @Override
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index 06e7842..8ec58f9 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -22,9 +22,7 @@ import cuchaz.enigma.gui.elements.MenuBar;
22import cuchaz.enigma.gui.elements.PopupMenuBar; 22import cuchaz.enigma.gui.elements.PopupMenuBar;
23import cuchaz.enigma.gui.filechooser.FileChooserAny; 23import cuchaz.enigma.gui.filechooser.FileChooserAny;
24import cuchaz.enigma.gui.filechooser.FileChooserFolder; 24import cuchaz.enigma.gui.filechooser.FileChooserFolder;
25import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter; 25import cuchaz.enigma.gui.highlight.BoxHighlightPainter;
26import cuchaz.enigma.gui.highlight.ObfuscatedHighlightPainter;
27import cuchaz.enigma.gui.highlight.OtherHighlightPainter;
28import cuchaz.enigma.gui.highlight.SelectionHighlightPainter; 26import cuchaz.enigma.gui.highlight.SelectionHighlightPainter;
29import cuchaz.enigma.gui.node.ClassSelectorPackageNode; 27import cuchaz.enigma.gui.node.ClassSelectorPackageNode;
30import cuchaz.enigma.gui.panels.PanelDeobf; 28import cuchaz.enigma.gui.panels.PanelDeobf;
@@ -48,10 +46,8 @@ import java.awt.*;
48import java.awt.event.*; 46import java.awt.event.*;
49import java.io.File; 47import java.io.File;
50import java.io.IOException; 48import java.io.IOException;
51import java.util.Collection; 49import java.util.*;
52import java.util.Collections;
53import java.util.List; 50import java.util.List;
54import java.util.Vector;
55import java.util.function.Function; 51import java.util.function.Function;
56 52
57public class Gui { 53public class Gui {
@@ -75,9 +71,7 @@ public class Gui {
75 private JPanel classesPanel; 71 private JPanel classesPanel;
76 private JSplitPane splitClasses; 72 private JSplitPane splitClasses;
77 private PanelIdentifier infoPanel; 73 private PanelIdentifier infoPanel;
78 public ObfuscatedHighlightPainter obfuscatedHighlightPainter; 74 public Map<String, BoxHighlightPainter> boxHighlightPainters;
79 public DeobfuscatedHighlightPainter deobfuscatedHighlightPainter;
80 public OtherHighlightPainter otherHighlightPainter;
81 private SelectionHighlightPainter selectionHighlightPainter; 75 private SelectionHighlightPainter selectionHighlightPainter;
82 private JTree inheritanceTree; 76 private JTree inheritanceTree;
83 private JTree implementationsTree; 77 private JTree implementationsTree;
@@ -145,7 +139,7 @@ public class Gui {
145 selectionHighlightPainter = new SelectionHighlightPainter(); 139 selectionHighlightPainter = new SelectionHighlightPainter();
146 this.editor = new PanelEditor(this); 140 this.editor = new PanelEditor(this);
147 JScrollPane sourceScroller = new JScrollPane(this.editor); 141 JScrollPane sourceScroller = new JScrollPane(this.editor);
148 this.editor.setContentType("text/minecraft"); 142 this.editor.setContentType("text/enigma-sources");
149 this.editor.setBackground(new Color(Config.getInstance().editorBackground)); 143 this.editor.setBackground(new Color(Config.getInstance().editorBackground));
150 DefaultSyntaxKit kit = (DefaultSyntaxKit) this.editor.getEditorKit(); 144 DefaultSyntaxKit kit = (DefaultSyntaxKit) this.editor.getEditorKit();
151 kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker"); 145 kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker");
@@ -311,11 +305,11 @@ public class Gui {
311 return this.controller; 305 return this.controller;
312 } 306 }
313 307
314 public void onStartOpenJar() { 308 public void onStartOpenJar(String message) {
315 this.classesPanel.removeAll(); 309 this.classesPanel.removeAll();
316 JPanel panel = new JPanel(); 310 JPanel panel = new JPanel();
317 panel.setLayout(new FlowLayout()); 311 panel.setLayout(new FlowLayout());
318 panel.add(new JLabel("Loading...")); 312 panel.add(new JLabel(message));
319 this.classesPanel.add(panel); 313 this.classesPanel.add(panel);
320 314
321 redraw(); 315 redraw();
@@ -407,20 +401,17 @@ public class Gui {
407 showToken(sortedTokens.get(0)); 401 showToken(sortedTokens.get(0));
408 } 402 }
409 403
410 public void setHighlightedTokens(Iterable<Token> obfuscatedTokens, Iterable<Token> deobfuscatedTokens, Iterable<Token> otherTokens) { 404 public void setHighlightedTokens(Map<String, Iterable<Token>> tokens) {
411
412 // remove any old highlighters 405 // remove any old highlighters
413 this.editor.getHighlighter().removeAllHighlights(); 406 this.editor.getHighlighter().removeAllHighlights();
414 407
415 // color things based on the index 408 if (boxHighlightPainters != null) {
416 if (obfuscatedTokens != null) { 409 for (String s : tokens.keySet()) {
417 setHighlightedTokens(obfuscatedTokens, obfuscatedHighlightPainter); 410 BoxHighlightPainter painter = boxHighlightPainters.get(s);
418 } 411 if (painter != null) {
419 if (deobfuscatedTokens != null) { 412 setHighlightedTokens(tokens.get(s), painter);
420 setHighlightedTokens(deobfuscatedTokens, deobfuscatedHighlightPainter); 413 }
421 } 414 }
422 if (otherTokens != null) {
423 setHighlightedTokens(otherTokens, otherHighlightPainter);
424 } 415 }
425 416
426 redraw(); 417 redraw();
@@ -582,7 +573,7 @@ public class Gui {
582 573
583 // init the text box 574 // init the text box
584 final JTextField text = new JTextField(); 575 final JTextField text = new JTextField();
585 text.setText(reference.getNamableName()); 576 text.setText(reference.getNameableName());
586 text.setPreferredSize(new Dimension(360, text.getPreferredSize().height)); 577 text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
587 text.addKeyListener(new KeyAdapter() { 578 text.addKeyListener(new KeyAdapter() {
588 @Override 579 @Override
@@ -633,7 +624,7 @@ public class Gui {
633 // abort the rename 624 // abort the rename
634 JPanel panel = (JPanel) infoPanel.getComponent(0); 625 JPanel panel = (JPanel) infoPanel.getComponent(0);
635 panel.remove(panel.getComponentCount() - 1); 626 panel.remove(panel.getComponentCount() - 1);
636 panel.add(Utils.unboldLabel(new JLabel(reference.getNamableName(), JLabel.LEFT))); 627 panel.add(Utils.unboldLabel(new JLabel(reference.getNameableName(), JLabel.LEFT)));
637 628
638 this.editor.grabFocus(); 629 this.editor.grabFocus();
639 630
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java
index 6e15bb0..e2f332d 100644
--- a/src/main/java/cuchaz/enigma/gui/GuiController.java
+++ b/src/main/java/cuchaz/enigma/gui/GuiController.java
@@ -11,13 +11,14 @@
11 11
12package cuchaz.enigma.gui; 12package cuchaz.enigma.gui;
13 13
14import com.google.common.collect.ImmutableMap;
14import com.google.common.collect.Lists; 15import com.google.common.collect.Lists;
15import com.google.common.collect.Queues; 16import com.google.common.collect.Queues;
16import com.strobel.decompiler.languages.java.ast.CompilationUnit; 17import com.strobel.decompiler.languages.java.ast.CompilationUnit;
17import cuchaz.enigma.Deobfuscator; 18import cuchaz.enigma.Deobfuscator;
18import cuchaz.enigma.analysis.*; 19import cuchaz.enigma.analysis.*;
20import cuchaz.enigma.api.EnigmaPlugin;
19import cuchaz.enigma.config.Config; 21import cuchaz.enigma.config.Config;
20import cuchaz.enigma.config.Themes;
21import cuchaz.enigma.gui.dialog.ProgressDialog; 22import cuchaz.enigma.gui.dialog.ProgressDialog;
22import cuchaz.enigma.mapping.*; 23import cuchaz.enigma.mapping.*;
23import cuchaz.enigma.mapping.entry.ClassEntry; 24import cuchaz.enigma.mapping.entry.ClassEntry;
@@ -30,9 +31,7 @@ import cuchaz.enigma.utils.ReadableToken;
30import java.awt.event.ItemEvent; 31import java.awt.event.ItemEvent;
31import java.io.File; 32import java.io.File;
32import java.io.IOException; 33import java.io.IOException;
33import java.util.Collection; 34import java.util.*;
34import java.util.Deque;
35import java.util.List;
36import java.util.jar.JarFile; 35import java.util.jar.JarFile;
37 36
38public class GuiController { 37public class GuiController {
@@ -58,8 +57,10 @@ public class GuiController {
58 } 57 }
59 58
60 public void openJar(final JarFile jar) throws IOException { 59 public void openJar(final JarFile jar) throws IOException {
61 this.gui.onStartOpenJar(); 60 this.gui.onStartOpenJar("Loading JAR...");
62 this.deobfuscator = new Deobfuscator(jar); 61 this.deobfuscator = new Deobfuscator(jar, (msg) -> {
62 this.gui.onStartOpenJar(msg);
63 });
63 this.gui.onFinishOpenJar(jar.getName()); 64 this.gui.onFinishOpenJar(jar.getName());
64 refreshClasses(); 65 refreshClasses();
65 } 66 }
@@ -162,7 +163,7 @@ public class GuiController {
162 } 163 }
163 164
164 public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) { 165 public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) {
165 return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference), true); 166 return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference));
166 } 167 }
167 168
168 public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { 169 public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) {
@@ -334,29 +335,73 @@ public class GuiController {
334 } 335 }
335 String source = deobfuscator.getSource(sourceTree); 336 String source = deobfuscator.getSource(sourceTree);
336 index = deobfuscator.getSourceIndex(sourceTree, source); 337 index = deobfuscator.getSourceIndex(sourceTree, source);
337 gui.setSource(index.getSource()); 338
338 if (obfReference != null) { 339 String sourceString = index.getSource();
339 showReference(obfReference);
340 }
341 340
342 // set the highlighted tokens 341 // set the highlighted tokens
343 List<Token> obfuscatedTokens = Lists.newArrayList(); 342 List<Token> obfuscatedTokens = Lists.newArrayList();
343 List<Token> proposedTokens = Lists.newArrayList();
344 List<Token> deobfuscatedTokens = Lists.newArrayList(); 344 List<Token> deobfuscatedTokens = Lists.newArrayList();
345 List<Token> otherTokens = Lists.newArrayList(); 345 List<Token> otherTokens = Lists.newArrayList();
346 for (Token token : index.referenceTokens()) { 346
347 EntryReference<Entry, Entry> reference = index.getDeobfReference(token); 347 int offset = 0;
348 Map<Token, Token> tokenRemap = new IdentityHashMap<>();
349 boolean remapped = false;
350
351 for (Token inToken : index.referenceTokens()) {
352 EntryReference<Entry, Entry> reference = index.getDeobfReference(inToken);
353 Token token = inToken.move(offset);
354
348 if (referenceIsRenameable(reference)) { 355 if (referenceIsRenameable(reference)) {
349 if (entryHasDeobfuscatedName(reference.getNameableEntry())) { 356 boolean renamed = false;
350 deobfuscatedTokens.add(token); 357
351 } else { 358 if (!entryHasDeobfuscatedName(reference.getNameableEntry())) {
352 obfuscatedTokens.add(token); 359 Entry obfEntry = deobfuscator.obfuscateEntry(reference.getNameableEntry());
360 if (obfEntry instanceof FieldEntry) {
361 for (EnigmaPlugin plugin : deobfuscator.getPlugins()) {
362 String proposal = plugin.proposeFieldName(obfEntry.getClassName(), obfEntry.getName(), ((FieldEntry) obfEntry).getDesc().toString());
363 if (proposal != null) {
364 proposedTokens.add(token);
365 offset += token.getRenameOffset(proposal);
366 sourceString = token.rename(sourceString, proposal);
367 renamed = true;
368 remapped = true;
369 break;
370 }
371 }
372 }
373 }
374
375 if (!renamed) {
376 if (entryHasDeobfuscatedName(reference.getNameableEntry())) {
377 deobfuscatedTokens.add(token);
378 } else {
379 obfuscatedTokens.add(token);
380 }
353 } 381 }
354 } else { 382 } else {
355 otherTokens.add(token); 383 otherTokens.add(token);
356 } 384 }
385
386 tokenRemap.put(inToken, token);
387 }
388
389 if (remapped) {
390 index.remap(sourceString, tokenRemap);
391 }
392
393 gui.setSource(sourceString);
394 if (obfReference != null) {
395 showReference(obfReference);
357 } 396 }
397
358 gui.setEditorTheme(Config.getInstance().lookAndFeel); 398 gui.setEditorTheme(Config.getInstance().lookAndFeel);
359 gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); 399 gui.setHighlightedTokens(ImmutableMap.of(
400 "obfuscated", obfuscatedTokens,
401 "proposed", proposedTokens,
402 "deobfuscated", deobfuscatedTokens,
403 "other", otherTokens
404 ));
360 }).start(); 405 }).start();
361 } 406 }
362 407
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
index 976c215..10366ce 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
@@ -11,13 +11,14 @@
11 11
12package cuchaz.enigma.gui.highlight; 12package cuchaz.enigma.gui.highlight;
13 13
14import cuchaz.enigma.config.Config;
15
14import javax.swing.text.BadLocationException; 16import javax.swing.text.BadLocationException;
15import javax.swing.text.Highlighter; 17import javax.swing.text.Highlighter;
16import javax.swing.text.JTextComponent; 18import javax.swing.text.JTextComponent;
17import java.awt.*; 19import java.awt.*;
18 20
19public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { 21public class BoxHighlightPainter implements Highlighter.HighlightPainter {
20
21 private Color fillColor; 22 private Color fillColor;
22 private Color borderColor; 23 private Color borderColor;
23 24
@@ -26,6 +27,10 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte
26 this.borderColor = borderColor; 27 this.borderColor = borderColor;
27 } 28 }
28 29
30 public static BoxHighlightPainter create(Config.AlphaColorEntry entry, Config.AlphaColorEntry entryOutline) {
31 return new BoxHighlightPainter(entry != null ? entry.get() : null, entryOutline != null ? entryOutline.get() : null);
32 }
33
29 public static Rectangle getBounds(JTextComponent text, int start, int end) { 34 public static Rectangle getBounds(JTextComponent text, int start, int end) {
30 try { 35 try {
31 // determine the bounds of the text 36 // determine the bounds of the text
@@ -59,8 +64,4 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte
59 g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); 64 g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
60 } 65 }
61 66
62 protected static Color getColor(int rgb, float alpha){
63 Color baseColor = new Color(rgb);
64 return new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), (int)(255 * alpha));
65 }
66} 67}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java
deleted file mode 100644
index 41aa97f..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java
+++ /dev/null
@@ -1,21 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui.highlight;
13
14import cuchaz.enigma.config.Config;
15
16public class DeobfuscatedHighlightPainter extends BoxHighlightPainter {
17
18 public DeobfuscatedHighlightPainter() {
19 super(getColor(Config.getInstance().deobfuscatedColor, Config.getInstance().deobfuscatedHiglightAlpha), getColor(Config.getInstance().deobfuscatedColorOutline, Config.getInstance().deobfuscatedOutlineAlpha));
20 }
21}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java
deleted file mode 100644
index d735874..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java
+++ /dev/null
@@ -1,21 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui.highlight;
13
14import cuchaz.enigma.config.Config;
15
16public class ObfuscatedHighlightPainter extends BoxHighlightPainter {
17
18 public ObfuscatedHighlightPainter() {
19 super(getColor(Config.getInstance().obfuscatedColor, Config.getInstance().obfuscatedHiglightAlpha), getColor(Config.getInstance().obfuscatedColorOutline, Config.getInstance().obfuscatedOutlineAlpha));
20 }
21}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java
deleted file mode 100644
index f4ae235..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java
+++ /dev/null
@@ -1,21 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui.highlight;
13
14import cuchaz.enigma.config.Config;
15
16public class OtherHighlightPainter extends BoxHighlightPainter {
17
18 public OtherHighlightPainter() {
19 super(null, getColor(Config.getInstance().otherColorOutline, Config.getInstance().otherOutlineAlpha));
20 }
21}