diff options
| author | 2019-06-16 23:49:25 +0200 | |
|---|---|---|
| committer | 2019-06-16 23:49:25 +0200 | |
| commit | e27d5967029f4f3da8889dd673ba516dcd9f3ac8 (patch) | |
| tree | 71c98afad01cafdb2884da288e494e8761c2a8ff /src/main/java/cuchaz/enigma/gui | |
| parent | Merge remote-tracking branch 'origin/master' into proposal-tweak (diff) | |
| download | enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.tar.gz enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.tar.xz enigma-fork-e27d5967029f4f3da8889dd673ba516dcd9f3ac8.zip | |
Plugin rework along with API rework: Enigma split from EnigmaProject; plugins now provide services configurable via a profile
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
8 files changed, 283 insertions, 191 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/src/main/java/cuchaz/enigma/gui/ClassSelector.java index 39d0333..5051032 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelector.java | |||
| @@ -155,7 +155,7 @@ public class ClassSelector extends JTree { | |||
| 155 | return; | 155 | return; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | Translator translator = controller.getDeobfuscator().getMapper().getDeobfuscator(); | 158 | Translator translator = controller.project.getMapper().getDeobfuscator(); |
| 159 | 159 | ||
| 160 | // build the package names | 160 | // build the package names |
| 161 | Map<String, ClassSelectorPackageNode> packages = Maps.newHashMap(); | 161 | Map<String, ClassSelectorPackageNode> packages = Maps.newHashMap(); |
| @@ -478,7 +478,7 @@ public class ClassSelector extends JTree { | |||
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | public void insertNode(ClassEntry obfEntry) { | 480 | public void insertNode(ClassEntry obfEntry) { |
| 481 | ClassEntry deobfEntry = controller.getDeobfuscator().deobfuscate(obfEntry); | 481 | ClassEntry deobfEntry = controller.project.getMapper().deobfuscate(obfEntry); |
| 482 | ClassSelectorPackageNode packageNode = getOrCreatePackage(deobfEntry); | 482 | ClassSelectorPackageNode packageNode = getOrCreatePackage(deobfEntry); |
| 483 | 483 | ||
| 484 | DefaultTreeModel model = (DefaultTreeModel) getModel(); | 484 | DefaultTreeModel model = (DefaultTreeModel) getModel(); |
diff --git a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java index d7c981a..44f70f8 100644 --- a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java +++ b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | |||
| @@ -1,12 +1,17 @@ | |||
| 1 | package cuchaz.enigma.gui; | 1 | package cuchaz.enigma.gui; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.Deobfuscator; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.EnigmaServices; | ||
| 4 | import cuchaz.enigma.analysis.EntryReference; | 5 | import cuchaz.enigma.analysis.EntryReference; |
| 5 | import cuchaz.enigma.analysis.SourceIndex; | 6 | import cuchaz.enigma.analysis.SourceIndex; |
| 6 | import cuchaz.enigma.analysis.Token; | 7 | import cuchaz.enigma.analysis.Token; |
| 8 | import cuchaz.enigma.api.service.NameProposalService; | ||
| 7 | import cuchaz.enigma.gui.highlight.TokenHighlightType; | 9 | import cuchaz.enigma.gui.highlight.TokenHighlightType; |
| 8 | import cuchaz.enigma.translation.LocalNameGenerator; | 10 | import cuchaz.enigma.translation.LocalNameGenerator; |
| 9 | import cuchaz.enigma.translation.Translator; | 11 | import cuchaz.enigma.translation.Translator; |
| 12 | import cuchaz.enigma.translation.mapping.EntryRemapper; | ||
| 13 | import cuchaz.enigma.translation.mapping.EntryResolver; | ||
| 14 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | ||
| 10 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 15 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 11 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 12 | import cuchaz.enigma.translation.representation.entry.Entry; | 17 | import cuchaz.enigma.translation.representation.entry.Entry; |
| @@ -34,27 +39,27 @@ public class DecompiledClassSource { | |||
| 34 | return new DecompiledClassSource(classEntry, new SourceIndex(text)); | 39 | return new DecompiledClassSource(classEntry, new SourceIndex(text)); |
| 35 | } | 40 | } |
| 36 | 41 | ||
| 37 | public void remapSource(Deobfuscator deobfuscator, Translator translator) { | 42 | public void remapSource(EnigmaProject project, Translator translator) { |
| 38 | highlightedTokens.clear(); | 43 | highlightedTokens.clear(); |
| 39 | 44 | ||
| 40 | SourceRemapper remapper = new SourceRemapper(obfuscatedIndex.getSource(), obfuscatedIndex.referenceTokens()); | 45 | SourceRemapper remapper = new SourceRemapper(obfuscatedIndex.getSource(), obfuscatedIndex.referenceTokens()); |
| 41 | 46 | ||
| 42 | SourceRemapper.Result remapResult = remapper.remap((token, movedToken) -> remapToken(deobfuscator, token, movedToken, translator)); | 47 | SourceRemapper.Result remapResult = remapper.remap((token, movedToken) -> remapToken(project, token, movedToken, translator)); |
| 43 | remappedIndex = obfuscatedIndex.remapTo(remapResult); | 48 | remappedIndex = obfuscatedIndex.remapTo(remapResult); |
| 44 | } | 49 | } |
| 45 | 50 | ||
| 46 | private String remapToken(Deobfuscator deobfuscator, Token token, Token movedToken, Translator translator) { | 51 | private String remapToken(EnigmaProject project, Token token, Token movedToken, Translator translator) { |
| 47 | EntryReference<Entry<?>, Entry<?>> reference = obfuscatedIndex.getReference(token); | 52 | EntryReference<Entry<?>, Entry<?>> reference = obfuscatedIndex.getReference(token); |
| 48 | 53 | ||
| 49 | Entry<?> entry = reference.getNameableEntry(); | 54 | Entry<?> entry = reference.getNameableEntry(); |
| 50 | Entry<?> translatedEntry = translator.translate(entry); | 55 | Entry<?> translatedEntry = translator.translate(entry); |
| 51 | 56 | ||
| 52 | if (deobfuscator.isRenamable(reference)) { | 57 | if (project.isRenamable(reference)) { |
| 53 | if (isDeobfuscated(entry, translatedEntry)) { | 58 | if (isDeobfuscated(entry, translatedEntry)) { |
| 54 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); | 59 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); |
| 55 | return translatedEntry.getSourceRemapName(); | 60 | return translatedEntry.getSourceRemapName(); |
| 56 | } else { | 61 | } else { |
| 57 | Optional<String> proposedName = proposeName(deobfuscator, entry); | 62 | Optional<String> proposedName = proposeName(project, entry); |
| 58 | if (proposedName.isPresent()) { | 63 | if (proposedName.isPresent()) { |
| 59 | highlightToken(movedToken, TokenHighlightType.PROPOSED); | 64 | highlightToken(movedToken, TokenHighlightType.PROPOSED); |
| 60 | return proposedName.get(); | 65 | return proposedName.get(); |
| @@ -72,13 +77,22 @@ public class DecompiledClassSource { | |||
| 72 | return null; | 77 | return null; |
| 73 | } | 78 | } |
| 74 | 79 | ||
| 75 | private Optional<String> proposeName(Deobfuscator deobfuscator, Entry<?> entry) { | 80 | private Optional<String> proposeName(EnigmaProject project, Entry<?> entry) { |
| 76 | Stream<String> proposals = deobfuscator.getNameProposers() | 81 | EnigmaServices services = project.getEnigma().getServices(); |
| 77 | .map(plugin -> plugin.proposeName(entry, deobfuscator.getMapper())) | ||
| 78 | .filter(Optional::isPresent) | ||
| 79 | .map(Optional::get); | ||
| 80 | 82 | ||
| 81 | return proposals.findFirst(); | 83 | return services.get(NameProposalService.TYPE).flatMap(nameProposalService -> { |
| 84 | EntryResolver resolver = project.getMapper().getObfResolver(); | ||
| 85 | |||
| 86 | Collection<Entry<?>> resolved = resolver.resolveEntry(entry, ResolutionStrategy.RESOLVE_ROOT); | ||
| 87 | EntryRemapper mapper = project.getMapper(); | ||
| 88 | |||
| 89 | Stream<String> proposals = resolved.stream() | ||
| 90 | .map(e -> nameProposalService.proposeName(e, mapper)) | ||
| 91 | .filter(Optional::isPresent) | ||
| 92 | .map(Optional::get); | ||
| 93 | |||
| 94 | return proposals.findFirst(); | ||
| 95 | }); | ||
| 82 | } | 96 | } |
| 83 | 97 | ||
| 84 | @Nullable | 98 | @Nullable |
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index a61f4dd..f5dd8a0 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -31,9 +31,7 @@ import cuchaz.enigma.gui.panels.PanelIdentifier; | |||
| 31 | import cuchaz.enigma.gui.panels.PanelObf; | 31 | import cuchaz.enigma.gui.panels.PanelObf; |
| 32 | import cuchaz.enigma.gui.util.History; | 32 | import cuchaz.enigma.gui.util.History; |
| 33 | import cuchaz.enigma.throwables.IllegalNameException; | 33 | import cuchaz.enigma.throwables.IllegalNameException; |
| 34 | import cuchaz.enigma.translation.mapping.AccessModifier; | 34 | import cuchaz.enigma.translation.mapping.*; |
| 35 | import cuchaz.enigma.translation.mapping.EntryResolver; | ||
| 36 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | ||
| 37 | import cuchaz.enigma.translation.representation.entry.*; | 35 | import cuchaz.enigma.translation.representation.entry.*; |
| 38 | import cuchaz.enigma.utils.Utils; | 36 | import cuchaz.enigma.utils.Utils; |
| 39 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 37 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| @@ -312,13 +310,8 @@ public class Gui { | |||
| 312 | return this.controller; | 310 | return this.controller; |
| 313 | } | 311 | } |
| 314 | 312 | ||
| 315 | public void onStartOpenJar(String message) { | 313 | public void onStartOpenJar() { |
| 316 | this.classesPanel.removeAll(); | 314 | this.classesPanel.removeAll(); |
| 317 | JPanel panel = new JPanel(); | ||
| 318 | panel.setLayout(new FlowLayout()); | ||
| 319 | panel.add(new JLabel(message)); | ||
| 320 | this.classesPanel.add(panel); | ||
| 321 | |||
| 322 | redraw(); | 315 | redraw(); |
| 323 | } | 316 | } |
| 324 | 317 | ||
| @@ -447,7 +440,7 @@ public class Gui { | |||
| 447 | 440 | ||
| 448 | this.cursorReference = reference; | 441 | this.cursorReference = reference; |
| 449 | 442 | ||
| 450 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(reference); | 443 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.project.getMapper().deobfuscate(reference); |
| 451 | 444 | ||
| 452 | infoPanel.removeAll(); | 445 | infoPanel.removeAll(); |
| 453 | if (translatedReference.entry instanceof ClassEntry) { | 446 | if (translatedReference.entry instanceof ClassEntry) { |
| @@ -509,7 +502,7 @@ public class Gui { | |||
| 509 | } | 502 | } |
| 510 | 503 | ||
| 511 | private JComboBox<AccessModifier> addModifierComboBox(JPanel container, String name, Entry entry) { | 504 | private JComboBox<AccessModifier> addModifierComboBox(JPanel container, String name, Entry entry) { |
| 512 | if (!getController().entryIsInJar(entry)) | 505 | if (!getController().project.isRenamable(entry)) |
| 513 | return null; | 506 | return null; |
| 514 | JPanel panel = new JPanel(); | 507 | JPanel panel = new JPanel(); |
| 515 | panel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0)); | 508 | panel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0)); |
| @@ -519,8 +512,16 @@ public class Gui { | |||
| 519 | JComboBox<AccessModifier> combo = new JComboBox<>(AccessModifier.values()); | 512 | JComboBox<AccessModifier> combo = new JComboBox<>(AccessModifier.values()); |
| 520 | ((JLabel) combo.getRenderer()).setHorizontalAlignment(JLabel.LEFT); | 513 | ((JLabel) combo.getRenderer()).setHorizontalAlignment(JLabel.LEFT); |
| 521 | combo.setPreferredSize(new Dimension(100, label.getPreferredSize().height)); | 514 | combo.setPreferredSize(new Dimension(100, label.getPreferredSize().height)); |
| 522 | combo.setSelectedIndex(getController().getDeobfuscator().getModifier(entry).ordinal()); | 515 | |
| 523 | combo.addItemListener(getController()::modifierChange); | 516 | EntryMapping mapping = controller.project.getMapper().getDeobfMapping(entry); |
| 517 | if (mapping != null) { | ||
| 518 | combo.setSelectedIndex(mapping.getAccessModifier().ordinal()); | ||
| 519 | } else { | ||
| 520 | combo.setSelectedIndex(AccessModifier.UNCHANGED.ordinal()); | ||
| 521 | } | ||
| 522 | |||
| 523 | combo.addItemListener(controller::modifierChange); | ||
| 524 | |||
| 524 | panel.add(combo); | 525 | panel.add(combo); |
| 525 | 526 | ||
| 526 | container.add(panel); | 527 | container.add(panel); |
| @@ -529,6 +530,8 @@ public class Gui { | |||
| 529 | } | 530 | } |
| 530 | 531 | ||
| 531 | public void onCaretMove(int pos) { | 532 | public void onCaretMove(int pos) { |
| 533 | EntryRemapper mapper = controller.project.getMapper(); | ||
| 534 | |||
| 532 | Token token = this.controller.getToken(pos); | 535 | Token token = this.controller.getToken(pos); |
| 533 | boolean isToken = token != null; | 536 | boolean isToken = token != null; |
| 534 | 537 | ||
| @@ -539,7 +542,7 @@ public class Gui { | |||
| 539 | shouldNavigateOnClick = false; | 542 | shouldNavigateOnClick = false; |
| 540 | Entry<?> navigationEntry = referenceEntry; | 543 | Entry<?> navigationEntry = referenceEntry; |
| 541 | if (cursorReference.context == null) { | 544 | if (cursorReference.context == null) { |
| 542 | EntryResolver resolver = controller.getDeobfuscator().getMapper().getObfResolver(); | 545 | EntryResolver resolver = mapper.getObfResolver(); |
| 543 | navigationEntry = resolver.resolveFirstEntry(referenceEntry, ResolutionStrategy.RESOLVE_ROOT); | 546 | navigationEntry = resolver.resolveFirstEntry(referenceEntry, ResolutionStrategy.RESOLVE_ROOT); |
| 544 | } | 547 | } |
| 545 | controller.navigateTo(navigationEntry); | 548 | controller.navigateTo(navigationEntry); |
| @@ -550,8 +553,7 @@ public class Gui { | |||
| 550 | boolean isFieldEntry = isToken && referenceEntry instanceof FieldEntry; | 553 | boolean isFieldEntry = isToken && referenceEntry instanceof FieldEntry; |
| 551 | boolean isMethodEntry = isToken && referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor(); | 554 | boolean isMethodEntry = isToken && referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor(); |
| 552 | boolean isConstructorEntry = isToken && referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor(); | 555 | boolean isConstructorEntry = isToken && referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor(); |
| 553 | boolean isInJar = isToken && this.controller.entryIsInJar(referenceEntry); | 556 | boolean isRenamable = isToken && this.controller.project.isRenamable(cursorReference); |
| 554 | boolean isRenamable = isToken && this.controller.getDeobfuscator().isRenamable(cursorReference); | ||
| 555 | 557 | ||
| 556 | if (isToken) { | 558 | if (isToken) { |
| 557 | showCursorReference(cursorReference); | 559 | showCursorReference(cursorReference); |
| @@ -564,12 +566,12 @@ public class Gui { | |||
| 564 | this.popupMenu.showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); | 566 | this.popupMenu.showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); |
| 565 | this.popupMenu.showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); | 567 | this.popupMenu.showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); |
| 566 | this.popupMenu.showCallsSpecificMenu.setEnabled(isMethodEntry); | 568 | this.popupMenu.showCallsSpecificMenu.setEnabled(isMethodEntry); |
| 567 | this.popupMenu.openEntryMenu.setEnabled(isInJar && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry)); | 569 | this.popupMenu.openEntryMenu.setEnabled(isRenamable && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry)); |
| 568 | this.popupMenu.openPreviousMenu.setEnabled(this.controller.hasPreviousReference()); | 570 | this.popupMenu.openPreviousMenu.setEnabled(this.controller.hasPreviousReference()); |
| 569 | this.popupMenu.openNextMenu.setEnabled(this.controller.hasNextReference()); | 571 | this.popupMenu.openNextMenu.setEnabled(this.controller.hasNextReference()); |
| 570 | this.popupMenu.toggleMappingMenu.setEnabled(isRenamable); | 572 | this.popupMenu.toggleMappingMenu.setEnabled(isRenamable); |
| 571 | 573 | ||
| 572 | if (isToken && this.controller.getDeobfuscator().isRemapped(referenceEntry)) { | 574 | if (isToken && !Objects.equals(referenceEntry, mapper.deobfuscate(referenceEntry))) { |
| 573 | this.popupMenu.toggleMappingMenu.setText("Reset to obfuscated"); | 575 | this.popupMenu.toggleMappingMenu.setText("Reset to obfuscated"); |
| 574 | } else { | 576 | } else { |
| 575 | this.popupMenu.toggleMappingMenu.setText("Mark as deobfuscated"); | 577 | this.popupMenu.toggleMappingMenu.setText("Mark as deobfuscated"); |
| @@ -581,7 +583,7 @@ public class Gui { | |||
| 581 | // init the text box | 583 | // init the text box |
| 582 | renameTextField = new JTextField(); | 584 | renameTextField = new JTextField(); |
| 583 | 585 | ||
| 584 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(cursorReference); | 586 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.project.getMapper().deobfuscate(cursorReference); |
| 585 | renameTextField.setText(translatedReference.getNameableName()); | 587 | renameTextField.setText(translatedReference.getNameableName()); |
| 586 | 588 | ||
| 587 | renameTextField.setPreferredSize(new Dimension(360, renameTextField.getPreferredSize().height)); | 589 | renameTextField.setPreferredSize(new Dimension(360, renameTextField.getPreferredSize().height)); |
| @@ -728,7 +730,10 @@ public class Gui { | |||
| 728 | } | 730 | } |
| 729 | 731 | ||
| 730 | public void toggleMapping() { | 732 | public void toggleMapping() { |
| 731 | if (this.controller.getDeobfuscator().isRemapped(cursorReference.entry)) { | 733 | Entry<?> obfEntry = cursorReference.entry; |
| 734 | Entry<?> deobfEntry = controller.project.getMapper().deobfuscate(obfEntry); | ||
| 735 | |||
| 736 | if (!Objects.equals(obfEntry, deobfEntry)) { | ||
| 732 | this.controller.removeMapping(cursorReference); | 737 | this.controller.removeMapping(cursorReference); |
| 733 | } else { | 738 | } else { |
| 734 | this.controller.markAsDeobfuscated(cursorReference); | 739 | this.controller.markAsDeobfuscated(cursorReference); |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 1683333..a55d2cd 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -14,9 +14,13 @@ package cuchaz.enigma.gui; | |||
| 14 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| 15 | import com.google.common.util.concurrent.ThreadFactoryBuilder; | 15 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 16 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | 16 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; |
| 17 | import cuchaz.enigma.Deobfuscator; | 17 | import cuchaz.enigma.CompiledSourceTypeLoader; |
| 18 | import cuchaz.enigma.Enigma; | ||
| 19 | import cuchaz.enigma.EnigmaProject; | ||
| 18 | import cuchaz.enigma.SourceProvider; | 20 | import cuchaz.enigma.SourceProvider; |
| 19 | import cuchaz.enigma.analysis.*; | 21 | import cuchaz.enigma.analysis.*; |
| 22 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 23 | import cuchaz.enigma.bytecode.translators.SourceFixVisitor; | ||
| 20 | import cuchaz.enigma.config.Config; | 24 | import cuchaz.enigma.config.Config; |
| 21 | import cuchaz.enigma.gui.dialog.ProgressDialog; | 25 | import cuchaz.enigma.gui.dialog.ProgressDialog; |
| 22 | import cuchaz.enigma.gui.util.History; | 26 | import cuchaz.enigma.gui.util.History; |
| @@ -30,114 +34,150 @@ import cuchaz.enigma.translation.representation.entry.Entry; | |||
| 30 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | 34 | import cuchaz.enigma.translation.representation.entry.FieldEntry; |
| 31 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 35 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 32 | import cuchaz.enigma.utils.ReadableToken; | 36 | import cuchaz.enigma.utils.ReadableToken; |
| 37 | import org.objectweb.asm.Opcodes; | ||
| 33 | 38 | ||
| 34 | import javax.annotation.Nullable; | 39 | import javax.annotation.Nullable; |
| 35 | import javax.swing.*; | 40 | import javax.swing.*; |
| 36 | import java.awt.event.ItemEvent; | 41 | import java.awt.event.ItemEvent; |
| 37 | import java.io.File; | ||
| 38 | import java.io.IOException; | ||
| 39 | import java.io.PrintWriter; | 42 | import java.io.PrintWriter; |
| 40 | import java.io.StringWriter; | 43 | import java.io.StringWriter; |
| 41 | import java.nio.file.Path; | 44 | import java.nio.file.Path; |
| 42 | import java.util.Collection; | 45 | import java.util.Collection; |
| 43 | import java.util.List; | 46 | import java.util.List; |
| 47 | import java.util.Optional; | ||
| 44 | import java.util.concurrent.ExecutorService; | 48 | import java.util.concurrent.ExecutorService; |
| 45 | import java.util.concurrent.Executors; | 49 | import java.util.concurrent.Executors; |
| 46 | import java.util.jar.JarFile; | ||
| 47 | import java.util.stream.Collectors; | 50 | import java.util.stream.Collectors; |
| 51 | import java.util.stream.Stream; | ||
| 48 | 52 | ||
| 49 | public class GuiController { | 53 | public class GuiController { |
| 50 | private static final ExecutorService DECOMPILER_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("decompiler-thread").build()); | 54 | private static final ExecutorService DECOMPILER_SERVICE = Executors.newSingleThreadExecutor( |
| 55 | new ThreadFactoryBuilder() | ||
| 56 | .setDaemon(true) | ||
| 57 | .setNameFormat("decompiler-thread") | ||
| 58 | .build() | ||
| 59 | ); | ||
| 51 | 60 | ||
| 52 | private final Gui gui; | 61 | private final Gui gui; |
| 53 | private Deobfuscator deobfuscator; | 62 | public final Enigma enigma; |
| 54 | private DecompiledClassSource currentSource; | ||
| 55 | 63 | ||
| 64 | public EnigmaProject project; | ||
| 65 | private SourceProvider sourceProvider; | ||
| 66 | private IndexTreeBuilder indexTreeBuilder; | ||
| 56 | 67 | ||
| 57 | private Path loadedMappingPath; | 68 | private Path loadedMappingPath; |
| 58 | private MappingFormat loadedMappingFormat; | 69 | private MappingFormat loadedMappingFormat; |
| 59 | 70 | ||
| 71 | private DecompiledClassSource currentSource; | ||
| 72 | |||
| 60 | public GuiController(Gui gui) { | 73 | public GuiController(Gui gui) { |
| 61 | this.gui = gui; | 74 | this.gui = gui; |
| 75 | // TODO: load and set profile | ||
| 76 | this.enigma = Enigma.create(); | ||
| 62 | } | 77 | } |
| 63 | 78 | ||
| 64 | public boolean isDirty() { | 79 | public boolean isDirty() { |
| 65 | if (deobfuscator == null) { | 80 | return project != null && project.getMapper().isDirty(); |
| 66 | return false; | ||
| 67 | } | ||
| 68 | return deobfuscator.getMapper().isDirty(); | ||
| 69 | } | 81 | } |
| 70 | 82 | ||
| 71 | public void openJar(final JarFile jar) throws IOException { | 83 | public void openJar(final Path jarPath) { |
| 72 | this.gui.onStartOpenJar("Loading JAR..."); | 84 | this.gui.onStartOpenJar(); |
| 73 | this.deobfuscator = new Deobfuscator(jar, this.gui::onStartOpenJar); | 85 | |
| 74 | this.gui.onFinishOpenJar(jar.getName()); | 86 | ProgressDialog.runOffThread(gui.getFrame(), progress -> { |
| 75 | refreshClasses(); | 87 | project = enigma.openJar(jarPath, progress); |
| 88 | |||
| 89 | indexTreeBuilder = new IndexTreeBuilder(project.getJarIndex()); | ||
| 90 | |||
| 91 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache()); | ||
| 92 | typeLoader.addVisitor(visitor -> new SourceFixVisitor(Opcodes.ASM5, visitor, project.getJarIndex())); | ||
| 93 | sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 94 | |||
| 95 | gui.onFinishOpenJar(jarPath.getFileName().toString()); | ||
| 96 | |||
| 97 | refreshClasses(); | ||
| 98 | }); | ||
| 76 | } | 99 | } |
| 77 | 100 | ||
| 78 | public void closeJar() { | 101 | public void closeJar() { |
| 79 | this.deobfuscator = null; | 102 | this.project = null; |
| 80 | this.gui.onCloseJar(); | 103 | this.gui.onCloseJar(); |
| 81 | } | 104 | } |
| 82 | 105 | ||
| 83 | public void openMappings(MappingFormat format, Path path) { | 106 | public void openMappings(MappingFormat format, Path path) { |
| 84 | if (deobfuscator == null) return; | 107 | if (project == null) return; |
| 85 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> { | 108 | |
| 109 | gui.setMappingsFile(path); | ||
| 110 | |||
| 111 | ProgressDialog.runOffThread(gui.getFrame(), progress -> { | ||
| 86 | try { | 112 | try { |
| 87 | EntryTree<EntryMapping> mappings = format.read(path, progress); | 113 | EntryTree<EntryMapping> mappings = format.read(path, progress); |
| 88 | deobfuscator.setMappings(mappings, progress); | 114 | project.setMappings(mappings); |
| 89 | 115 | ||
| 90 | gui.setMappingsFile(path); | ||
| 91 | loadedMappingFormat = format; | 116 | loadedMappingFormat = format; |
| 92 | loadedMappingPath = path; | 117 | loadedMappingPath = path; |
| 93 | 118 | ||
| 94 | refreshClasses(); | 119 | refreshClasses(); |
| 95 | refreshCurrentClass(); | 120 | refreshCurrentClass(); |
| 96 | } catch (MappingParseException e) { | 121 | } catch (MappingParseException e) { |
| 97 | JOptionPane.showMessageDialog(this.gui.getFrame(), e.getMessage()); | 122 | JOptionPane.showMessageDialog(gui.getFrame(), e.getMessage()); |
| 98 | } | 123 | } |
| 99 | }); | 124 | }); |
| 100 | } | 125 | } |
| 101 | 126 | ||
| 102 | public void saveMappings(Path path) { | 127 | public void saveMappings(Path path) { |
| 103 | saveMappings(loadedMappingFormat, path); | 128 | if (project == null) return; |
| 129 | |||
| 130 | saveMappings(path, loadedMappingFormat); | ||
| 104 | } | 131 | } |
| 105 | 132 | ||
| 106 | public void saveMappings(MappingFormat format, Path path) { | 133 | public void saveMappings(Path path, MappingFormat format) { |
| 107 | if (deobfuscator == null) return; | 134 | if (project == null) return; |
| 108 | EntryRemapper mapper = deobfuscator.getMapper(); | 135 | |
| 136 | ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { | ||
| 137 | EntryRemapper mapper = project.getMapper(); | ||
| 109 | 138 | ||
| 110 | MappingDelta<EntryMapping> delta = mapper.takeMappingDelta(); | 139 | MappingDelta<EntryMapping> delta = mapper.takeMappingDelta(); |
| 111 | boolean saveAll = !path.equals(loadedMappingPath); | 140 | boolean saveAll = !path.equals(loadedMappingPath); |
| 141 | |||
| 142 | loadedMappingFormat = format; | ||
| 143 | loadedMappingPath = path; | ||
| 112 | 144 | ||
| 113 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> { | ||
| 114 | if (saveAll) { | 145 | if (saveAll) { |
| 115 | format.write(mapper.getObfToDeobf(), path, progress); | 146 | format.write(mapper.getObfToDeobf(), path, progress); |
| 116 | } else { | 147 | } else { |
| 117 | format.write(mapper.getObfToDeobf(), delta, path, progress); | 148 | format.write(mapper.getObfToDeobf(), delta, path, progress); |
| 118 | } | 149 | } |
| 119 | }); | 150 | }); |
| 120 | |||
| 121 | loadedMappingFormat = format; | ||
| 122 | loadedMappingPath = path; | ||
| 123 | } | 151 | } |
| 124 | 152 | ||
| 125 | public void closeMappings() { | 153 | public void closeMappings() { |
| 126 | if (deobfuscator == null) return; | 154 | if (project == null) return; |
| 127 | this.deobfuscator.setMappings(null); | 155 | |
| 156 | project.setMappings(null); | ||
| 157 | |||
| 128 | this.gui.setMappingsFile(null); | 158 | this.gui.setMappingsFile(null); |
| 129 | refreshClasses(); | 159 | refreshClasses(); |
| 130 | refreshCurrentClass(); | 160 | refreshCurrentClass(); |
| 131 | } | 161 | } |
| 132 | 162 | ||
| 133 | public void exportSource(final File dirOut) { | 163 | public void exportSource(final Path path) { |
| 134 | if (deobfuscator == null) return; | 164 | if (project == null) return; |
| 135 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut.toPath(), progress)); | 165 | |
| 166 | ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { | ||
| 167 | EnigmaProject.JarExport jar = project.exportRemappedJar(progress); | ||
| 168 | EnigmaProject.SourceExport source = jar.decompile(progress); | ||
| 169 | |||
| 170 | source.write(path, progress); | ||
| 171 | }); | ||
| 136 | } | 172 | } |
| 137 | 173 | ||
| 138 | public void exportJar(final File fileOut) { | 174 | public void exportJar(final Path path) { |
| 139 | if (deobfuscator == null) return; | 175 | if (project == null) return; |
| 140 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeTransformedJar(fileOut, progress)); | 176 | |
| 177 | ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { | ||
| 178 | EnigmaProject.JarExport jar = project.exportRemappedJar(progress); | ||
| 179 | jar.write(path, progress); | ||
| 180 | }); | ||
| 141 | } | 181 | } |
| 142 | 182 | ||
| 143 | public Token getToken(int pos) { | 183 | public Token getToken(int pos) { |
| @@ -167,85 +207,9 @@ public class GuiController { | |||
| 167 | ); | 207 | ); |
| 168 | } | 208 | } |
| 169 | 209 | ||
| 170 | public boolean entryIsInJar(Entry<?> entry) { | ||
| 171 | if (entry == null || deobfuscator == null) return false; | ||
| 172 | return this.deobfuscator.isRenamable(entry); | ||
| 173 | } | ||
| 174 | |||
| 175 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry entry) { | ||
| 176 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 177 | ClassInheritanceTreeNode rootNode = this.deobfuscator.getIndexTreeBuilder().buildClassInheritance(translator, entry); | ||
| 178 | return ClassInheritanceTreeNode.findNode(rootNode, entry); | ||
| 179 | } | ||
| 180 | |||
| 181 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry entry) { | ||
| 182 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 183 | return this.deobfuscator.getIndexTreeBuilder().buildClassImplementations(translator, entry); | ||
| 184 | } | ||
| 185 | |||
| 186 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry entry) { | ||
| 187 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 188 | MethodInheritanceTreeNode rootNode = this.deobfuscator.getIndexTreeBuilder().buildMethodInheritance(translator, entry); | ||
| 189 | return MethodInheritanceTreeNode.findNode(rootNode, entry); | ||
| 190 | } | ||
| 191 | |||
| 192 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry entry) { | ||
| 193 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 194 | List<MethodImplementationsTreeNode> rootNodes = this.deobfuscator.getIndexTreeBuilder().buildMethodImplementations(translator, entry); | ||
| 195 | if (rootNodes.isEmpty()) { | ||
| 196 | return null; | ||
| 197 | } | ||
| 198 | if (rootNodes.size() > 1) { | ||
| 199 | System.err.println("WARNING: Method " + entry + " implements multiple interfaces. Only showing first one."); | ||
| 200 | } | ||
| 201 | return MethodImplementationsTreeNode.findNode(rootNodes.get(0), entry); | ||
| 202 | } | ||
| 203 | |||
| 204 | public ClassReferenceTreeNode getClassReferences(ClassEntry entry) { | ||
| 205 | Translator deobfuscator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 206 | ClassReferenceTreeNode rootNode = new ClassReferenceTreeNode(deobfuscator, entry); | ||
| 207 | rootNode.load(this.deobfuscator.getJarIndex(), true); | ||
| 208 | return rootNode; | ||
| 209 | } | ||
| 210 | |||
| 211 | public FieldReferenceTreeNode getFieldReferences(FieldEntry entry) { | ||
| 212 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 213 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(translator, entry); | ||
| 214 | rootNode.load(this.deobfuscator.getJarIndex(), true); | ||
| 215 | return rootNode; | ||
| 216 | } | ||
| 217 | |||
| 218 | public MethodReferenceTreeNode getMethodReferences(MethodEntry entry, boolean recursive) { | ||
| 219 | Translator translator = this.deobfuscator.getMapper().getDeobfuscator(); | ||
| 220 | MethodReferenceTreeNode rootNode = new MethodReferenceTreeNode(translator, entry); | ||
| 221 | rootNode.load(this.deobfuscator.getJarIndex(), true, recursive); | ||
| 222 | return rootNode; | ||
| 223 | } | ||
| 224 | |||
| 225 | public void rename(EntryReference<Entry<?>, Entry<?>> reference, String newName, boolean refreshClassTree) { | ||
| 226 | this.deobfuscator.rename(reference.getNameableEntry(), newName); | ||
| 227 | |||
| 228 | if (refreshClassTree && reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | ||
| 229 | this.gui.moveClassTree(reference, newName); | ||
| 230 | refreshCurrentClass(reference); | ||
| 231 | } | ||
| 232 | |||
| 233 | public void removeMapping(EntryReference<Entry<?>, Entry<?>> reference) { | ||
| 234 | this.deobfuscator.removeMapping(reference.getNameableEntry()); | ||
| 235 | if (reference.entry instanceof ClassEntry) | ||
| 236 | this.gui.moveClassTree(reference, false, true); | ||
| 237 | refreshCurrentClass(reference); | ||
| 238 | } | ||
| 239 | |||
| 240 | public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) { | ||
| 241 | this.deobfuscator.markAsDeobfuscated(reference.getNameableEntry()); | ||
| 242 | if (reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | ||
| 243 | this.gui.moveClassTree(reference, true, false); | ||
| 244 | refreshCurrentClass(reference); | ||
| 245 | } | ||
| 246 | |||
| 247 | /** | 210 | /** |
| 248 | * Navigates to the declaration with respect to navigation history | 211 | * Navigates to the declaration with respect to navigation history |
| 212 | * | ||
| 249 | * @param entry the entry whose declaration will be navigated to | 213 | * @param entry the entry whose declaration will be navigated to |
| 250 | */ | 214 | */ |
| 251 | public void openDeclaration(Entry<?> entry) { | 215 | public void openDeclaration(Entry<?> entry) { |
| @@ -257,6 +221,7 @@ public class GuiController { | |||
| 257 | 221 | ||
| 258 | /** | 222 | /** |
| 259 | * Navigates to the reference with respect to navigation history | 223 | * Navigates to the reference with respect to navigation history |
| 224 | * | ||
| 260 | * @param reference the reference | 225 | * @param reference the reference |
| 261 | */ | 226 | */ |
| 262 | public void openReference(EntryReference<Entry<?>, Entry<?>> reference) { | 227 | public void openReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| @@ -275,12 +240,13 @@ public class GuiController { | |||
| 275 | 240 | ||
| 276 | /** | 241 | /** |
| 277 | * Navigates to the reference without modifying history. If the class is not currently loaded, it will be loaded. | 242 | * Navigates to the reference without modifying history. If the class is not currently loaded, it will be loaded. |
| 243 | * | ||
| 278 | * @param reference the reference | 244 | * @param reference the reference |
| 279 | */ | 245 | */ |
| 280 | private void setReference(EntryReference<Entry<?>, Entry<?>> reference) { | 246 | private void setReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| 281 | // get the reference target class | 247 | // get the reference target class |
| 282 | ClassEntry classEntry = reference.getLocationClassEntry(); | 248 | ClassEntry classEntry = reference.getLocationClassEntry(); |
| 283 | if (!this.deobfuscator.isRenamable(classEntry)) { | 249 | if (!project.isRenamable(classEntry)) { |
| 284 | throw new IllegalArgumentException("Obfuscated class " + classEntry + " was not found in the jar!"); | 250 | throw new IllegalArgumentException("Obfuscated class " + classEntry + " was not found in the jar!"); |
| 285 | } | 251 | } |
| 286 | 252 | ||
| @@ -294,6 +260,7 @@ public class GuiController { | |||
| 294 | 260 | ||
| 295 | /** | 261 | /** |
| 296 | * Navigates to the reference without modifying history. Assumes the class is loaded. | 262 | * Navigates to the reference without modifying history. Assumes the class is loaded. |
| 263 | * | ||
| 297 | * @param reference | 264 | * @param reference |
| 298 | */ | 265 | */ |
| 299 | private void showReference(EntryReference<Entry<?>, Entry<?>> reference) { | 266 | private void showReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| @@ -307,7 +274,7 @@ public class GuiController { | |||
| 307 | } | 274 | } |
| 308 | 275 | ||
| 309 | public Collection<Token> getTokensForReference(EntryReference<Entry<?>, Entry<?>> reference) { | 276 | public Collection<Token> getTokensForReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| 310 | EntryRemapper mapper = this.deobfuscator.getMapper(); | 277 | EntryRemapper mapper = this.project.getMapper(); |
| 311 | 278 | ||
| 312 | SourceIndex index = this.currentSource.getIndex(); | 279 | SourceIndex index = this.currentSource.getIndex(); |
| 313 | return mapper.getObfResolver().resolveReference(reference, ResolutionStrategy.RESOLVE_CLOSEST) | 280 | return mapper.getObfResolver().resolveReference(reference, ResolutionStrategy.RESOLVE_CLOSEST) |
| @@ -337,7 +304,7 @@ public class GuiController { | |||
| 337 | } | 304 | } |
| 338 | 305 | ||
| 339 | public void navigateTo(Entry<?> entry) { | 306 | public void navigateTo(Entry<?> entry) { |
| 340 | if (!entryIsInJar(entry)) { | 307 | if (!project.isRenamable(entry)) { |
| 341 | // entry is not in the jar. Ignore it | 308 | // entry is not in the jar. Ignore it |
| 342 | return; | 309 | return; |
| 343 | } | 310 | } |
| @@ -345,7 +312,7 @@ public class GuiController { | |||
| 345 | } | 312 | } |
| 346 | 313 | ||
| 347 | public void navigateTo(EntryReference<Entry<?>, Entry<?>> reference) { | 314 | public void navigateTo(EntryReference<Entry<?>, Entry<?>> reference) { |
| 348 | if (!entryIsInJar(reference.getLocationClassEntry())) { | 315 | if (!project.isRenamable(reference.getLocationClassEntry())) { |
| 349 | return; | 316 | return; |
| 350 | } | 317 | } |
| 351 | openReference(reference); | 318 | openReference(reference); |
| @@ -354,11 +321,38 @@ public class GuiController { | |||
| 354 | private void refreshClasses() { | 321 | private void refreshClasses() { |
| 355 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 322 | List<ClassEntry> obfClasses = Lists.newArrayList(); |
| 356 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 323 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| 357 | this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | 324 | this.addSeparatedClasses(obfClasses, deobfClasses); |
| 358 | this.gui.setObfClasses(obfClasses); | 325 | this.gui.setObfClasses(obfClasses); |
| 359 | this.gui.setDeobfClasses(deobfClasses); | 326 | this.gui.setDeobfClasses(deobfClasses); |
| 360 | } | 327 | } |
| 361 | 328 | ||
| 329 | public void addSeparatedClasses(List<ClassEntry> obfClasses, List<ClassEntry> deobfClasses) { | ||
| 330 | EntryRemapper mapper = project.getMapper(); | ||
| 331 | |||
| 332 | Collection<ClassEntry> classes = project.getJarIndex().getEntryIndex().getClasses(); | ||
| 333 | Stream<ClassEntry> visibleClasses = classes.stream() | ||
| 334 | .filter(entry -> !entry.isInnerClass()); | ||
| 335 | |||
| 336 | visibleClasses.forEach(entry -> { | ||
| 337 | ClassEntry deobfEntry = mapper.deobfuscate(entry); | ||
| 338 | |||
| 339 | Optional<ObfuscationTestService> obfService = enigma.getServices().get(ObfuscationTestService.TYPE); | ||
| 340 | boolean obfuscated = deobfEntry.equals(entry); | ||
| 341 | |||
| 342 | if (obfuscated && obfService.isPresent()) { | ||
| 343 | if (obfService.get().testDeobfuscated(entry)) { | ||
| 344 | obfuscated = false; | ||
| 345 | } | ||
| 346 | } | ||
| 347 | |||
| 348 | if (obfuscated) { | ||
| 349 | obfClasses.add(entry); | ||
| 350 | } else { | ||
| 351 | deobfClasses.add(entry); | ||
| 352 | } | ||
| 353 | }); | ||
| 354 | } | ||
| 355 | |||
| 362 | public void refreshCurrentClass() { | 356 | public void refreshCurrentClass() { |
| 363 | refreshCurrentClass(null); | 357 | refreshCurrentClass(null); |
| 364 | } | 358 | } |
| @@ -384,10 +378,10 @@ public class GuiController { | |||
| 384 | DECOMPILER_SERVICE.submit(() -> { | 378 | DECOMPILER_SERVICE.submit(() -> { |
| 385 | try { | 379 | try { |
| 386 | if (requiresDecompile) { | 380 | if (requiresDecompile) { |
| 387 | currentSource = decompileSource(targetClass, deobfuscator.getObfSourceProvider()); | 381 | currentSource = decompileSource(targetClass); |
| 388 | } | 382 | } |
| 389 | 383 | ||
| 390 | remapSource(deobfuscator.getMapper().getDeobfuscator()); | 384 | remapSource(project.getMapper().getDeobfuscator()); |
| 391 | callback.run(); | 385 | callback.run(); |
| 392 | } catch (Throwable t) { | 386 | } catch (Throwable t) { |
| 393 | System.err.println("An exception was thrown while decompiling class " + classEntry.getFullName()); | 387 | System.err.println("An exception was thrown while decompiling class " + classEntry.getFullName()); |
| @@ -396,7 +390,7 @@ public class GuiController { | |||
| 396 | }); | 390 | }); |
| 397 | } | 391 | } |
| 398 | 392 | ||
| 399 | private DecompiledClassSource decompileSource(ClassEntry targetClass, SourceProvider sourceProvider) { | 393 | private DecompiledClassSource decompileSource(ClassEntry targetClass) { |
| 400 | try { | 394 | try { |
| 401 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); | 395 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); |
| 402 | if (sourceTree == null) { | 396 | if (sourceTree == null) { |
| @@ -410,7 +404,7 @@ public class GuiController { | |||
| 410 | String sourceString = sourceProvider.writeSourceToString(sourceTree); | 404 | String sourceString = sourceProvider.writeSourceToString(sourceTree); |
| 411 | 405 | ||
| 412 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); | 406 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); |
| 413 | index.resolveReferences(deobfuscator.getMapper().getObfResolver()); | 407 | index.resolveReferences(project.getMapper().getObfResolver()); |
| 414 | 408 | ||
| 415 | return new DecompiledClassSource(targetClass, index); | 409 | return new DecompiledClassSource(targetClass, index); |
| 416 | } catch (Throwable t) { | 410 | } catch (Throwable t) { |
| @@ -426,20 +420,105 @@ public class GuiController { | |||
| 426 | return; | 420 | return; |
| 427 | } | 421 | } |
| 428 | 422 | ||
| 429 | currentSource.remapSource(deobfuscator, translator); | 423 | currentSource.remapSource(project, translator); |
| 430 | 424 | ||
| 431 | gui.setEditorTheme(Config.getInstance().lookAndFeel); | 425 | gui.setEditorTheme(Config.getInstance().lookAndFeel); |
| 432 | gui.setSource(currentSource); | 426 | gui.setSource(currentSource); |
| 433 | } | 427 | } |
| 434 | 428 | ||
| 435 | public Deobfuscator getDeobfuscator() { | ||
| 436 | return deobfuscator; | ||
| 437 | } | ||
| 438 | |||
| 439 | public void modifierChange(ItemEvent event) { | 429 | public void modifierChange(ItemEvent event) { |
| 440 | if (event.getStateChange() == ItemEvent.SELECTED) { | 430 | if (event.getStateChange() == ItemEvent.SELECTED) { |
| 441 | deobfuscator.changeModifier(gui.cursorReference.entry, (AccessModifier) event.getItem()); | 431 | EntryRemapper mapper = project.getMapper(); |
| 432 | Entry<?> entry = gui.cursorReference.entry; | ||
| 433 | AccessModifier modifier = (AccessModifier) event.getItem(); | ||
| 434 | |||
| 435 | EntryMapping mapping = mapper.getDeobfMapping(entry); | ||
| 436 | if (mapping != null) { | ||
| 437 | mapper.mapFromObf(entry, new EntryMapping(mapping.getTargetName(), modifier)); | ||
| 438 | } else { | ||
| 439 | mapper.mapFromObf(entry, new EntryMapping(entry.getName(), modifier)); | ||
| 440 | } | ||
| 441 | |||
| 442 | refreshCurrentClass(); | 442 | refreshCurrentClass(); |
| 443 | } | 443 | } |
| 444 | } | 444 | } |
| 445 | |||
| 446 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry entry) { | ||
| 447 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 448 | ClassInheritanceTreeNode rootNode = indexTreeBuilder.buildClassInheritance(translator, entry); | ||
| 449 | return ClassInheritanceTreeNode.findNode(rootNode, entry); | ||
| 450 | } | ||
| 451 | |||
| 452 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry entry) { | ||
| 453 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 454 | return this.indexTreeBuilder.buildClassImplementations(translator, entry); | ||
| 455 | } | ||
| 456 | |||
| 457 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry entry) { | ||
| 458 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 459 | MethodInheritanceTreeNode rootNode = indexTreeBuilder.buildMethodInheritance(translator, entry); | ||
| 460 | return MethodInheritanceTreeNode.findNode(rootNode, entry); | ||
| 461 | } | ||
| 462 | |||
| 463 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry entry) { | ||
| 464 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 465 | List<MethodImplementationsTreeNode> rootNodes = indexTreeBuilder.buildMethodImplementations(translator, entry); | ||
| 466 | if (rootNodes.isEmpty()) { | ||
| 467 | return null; | ||
| 468 | } | ||
| 469 | if (rootNodes.size() > 1) { | ||
| 470 | System.err.println("WARNING: Method " + entry + " implements multiple interfaces. Only showing first one."); | ||
| 471 | } | ||
| 472 | return MethodImplementationsTreeNode.findNode(rootNodes.get(0), entry); | ||
| 473 | } | ||
| 474 | |||
| 475 | public ClassReferenceTreeNode getClassReferences(ClassEntry entry) { | ||
| 476 | Translator deobfuscator = project.getMapper().getDeobfuscator(); | ||
| 477 | ClassReferenceTreeNode rootNode = new ClassReferenceTreeNode(deobfuscator, entry); | ||
| 478 | rootNode.load(project.getJarIndex(), true); | ||
| 479 | return rootNode; | ||
| 480 | } | ||
| 481 | |||
| 482 | public FieldReferenceTreeNode getFieldReferences(FieldEntry entry) { | ||
| 483 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 484 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(translator, entry); | ||
| 485 | rootNode.load(project.getJarIndex(), true); | ||
| 486 | return rootNode; | ||
| 487 | } | ||
| 488 | |||
| 489 | public MethodReferenceTreeNode getMethodReferences(MethodEntry entry, boolean recursive) { | ||
| 490 | Translator translator = project.getMapper().getDeobfuscator(); | ||
| 491 | MethodReferenceTreeNode rootNode = new MethodReferenceTreeNode(translator, entry); | ||
| 492 | rootNode.load(project.getJarIndex(), true, recursive); | ||
| 493 | return rootNode; | ||
| 494 | } | ||
| 495 | |||
| 496 | public void rename(EntryReference<Entry<?>, Entry<?>> reference, String newName, boolean refreshClassTree) { | ||
| 497 | Entry<?> entry = reference.getNameableEntry(); | ||
| 498 | project.getMapper().mapFromObf(entry, new EntryMapping(newName)); | ||
| 499 | |||
| 500 | if (refreshClassTree && reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | ||
| 501 | this.gui.moveClassTree(reference, newName); | ||
| 502 | |||
| 503 | refreshCurrentClass(reference); | ||
| 504 | } | ||
| 505 | |||
| 506 | public void removeMapping(EntryReference<Entry<?>, Entry<?>> reference) { | ||
| 507 | project.getMapper().removeByObf(reference.getNameableEntry()); | ||
| 508 | |||
| 509 | if (reference.entry instanceof ClassEntry) | ||
| 510 | this.gui.moveClassTree(reference, false, true); | ||
| 511 | refreshCurrentClass(reference); | ||
| 512 | } | ||
| 513 | |||
| 514 | public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) { | ||
| 515 | EntryRemapper mapper = project.getMapper(); | ||
| 516 | Entry<?> entry = reference.getNameableEntry(); | ||
| 517 | mapper.mapFromObf(entry, new EntryMapping(mapper.deobfuscate(entry).getName())); | ||
| 518 | |||
| 519 | if (reference.entry instanceof ClassEntry && !((ClassEntry) reference.entry).isInnerClass()) | ||
| 520 | this.gui.moveClassTree(reference, true, false); | ||
| 521 | |||
| 522 | refreshCurrentClass(reference); | ||
| 523 | } | ||
| 445 | } | 524 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java index 84fe7c8..c135d03 100644 --- a/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java +++ b/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java | |||
| @@ -57,7 +57,7 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 57 | this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | 57 | this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public static void runInThread(final JFrame parent, final ProgressRunnable runnable) { | 60 | public static void runOffThread(final JFrame parent, final ProgressRunnable runnable) { |
| 61 | new Thread(() -> | 61 | new Thread(() -> |
| 62 | { | 62 | { |
| 63 | try (ProgressDialog progress = new ProgressDialog(parent)) { | 63 | try (ProgressDialog progress = new ProgressDialog(parent)) { |
| @@ -68,6 +68,7 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 68 | }).start(); | 68 | }).start(); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @Override | ||
| 71 | public void close() { | 72 | public void close() { |
| 72 | this.frame.dispose(); | 73 | this.frame.dispose(); |
| 73 | } | 74 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java index a122bd8..1657d7b 100644 --- a/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java +++ b/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java | |||
| @@ -40,7 +40,7 @@ public class SearchDialog { | |||
| 40 | this.parent = parent; | 40 | this.parent = parent; |
| 41 | 41 | ||
| 42 | deobfClasses = Lists.newArrayList(); | 42 | deobfClasses = Lists.newArrayList(); |
| 43 | this.parent.getController().getDeobfuscator().getSeparatedClasses(Lists.newArrayList(), deobfClasses); | 43 | this.parent.getController().addSeparatedClasses(Lists.newArrayList(), deobfClasses); |
| 44 | deobfClasses.removeIf(ClassEntry::isInnerClass); | 44 | deobfClasses.removeIf(ClassEntry::isInnerClass); |
| 45 | } | 45 | } |
| 46 | 46 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 98275b4..5578325 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -13,10 +13,11 @@ import java.awt.event.InputEvent; | |||
| 13 | import java.awt.event.KeyEvent; | 13 | import java.awt.event.KeyEvent; |
| 14 | import java.io.File; | 14 | import java.io.File; |
| 15 | import java.io.IOException; | 15 | import java.io.IOException; |
| 16 | import java.net.MalformedURLException; | ||
| 17 | import java.net.URISyntaxException; | 16 | import java.net.URISyntaxException; |
| 18 | import java.net.URL; | 17 | import java.net.URL; |
| 19 | import java.util.jar.JarFile; | 18 | import java.nio.file.Files; |
| 19 | import java.nio.file.Path; | ||
| 20 | import java.nio.file.Paths; | ||
| 20 | 21 | ||
| 21 | public class MenuBar extends JMenuBar { | 22 | public class MenuBar extends JMenuBar { |
| 22 | 23 | ||
| @@ -43,17 +44,9 @@ public class MenuBar extends JMenuBar { | |||
| 43 | menu.add(item); | 44 | menu.add(item); |
| 44 | item.addActionListener(event -> { | 45 | item.addActionListener(event -> { |
| 45 | this.gui.jarFileChooser.setVisible(true); | 46 | this.gui.jarFileChooser.setVisible(true); |
| 46 | File file = new File(this.gui.jarFileChooser.getDirectory() + File.separator + this.gui.jarFileChooser.getFile()); | 47 | Path path = Paths.get(this.gui.jarFileChooser.getDirectory()).resolve(this.gui.jarFileChooser.getFile()); |
| 47 | if (file.exists()) { | 48 | if (Files.exists(path)) { |
| 48 | // load the jar in a separate thread | 49 | gui.getController().openJar(path); |
| 49 | new Thread(() -> | ||
| 50 | { | ||
| 51 | try { | ||
| 52 | gui.getController().openJar(new JarFile(file)); | ||
| 53 | } catch (IOException ex) { | ||
| 54 | throw new Error(ex); | ||
| 55 | } | ||
| 56 | }).start(); | ||
| 57 | } | 50 | } |
| 58 | }); | 51 | }); |
| 59 | } | 52 | } |
| @@ -106,7 +99,7 @@ public class MenuBar extends JMenuBar { | |||
| 106 | item.addActionListener(event -> { | 99 | item.addActionListener(event -> { |
| 107 | // TODO: Use a specific file chooser for it | 100 | // TODO: Use a specific file chooser for it |
| 108 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 101 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 109 | this.gui.getController().saveMappings(MappingFormat.ENIGMA_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); | 102 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_FILE); |
| 110 | this.saveMappingsMenu.setEnabled(true); | 103 | this.saveMappingsMenu.setEnabled(true); |
| 111 | } | 104 | } |
| 112 | }); | 105 | }); |
| @@ -118,7 +111,7 @@ public class MenuBar extends JMenuBar { | |||
| 118 | item.addActionListener(event -> { | 111 | item.addActionListener(event -> { |
| 119 | // TODO: Use a specific file chooser for it | 112 | // TODO: Use a specific file chooser for it |
| 120 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 113 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 121 | this.gui.getController().saveMappings(MappingFormat.ENIGMA_DIRECTORY, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); | 114 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.ENIGMA_DIRECTORY); |
| 122 | this.saveMappingsMenu.setEnabled(true); | 115 | this.saveMappingsMenu.setEnabled(true); |
| 123 | } | 116 | } |
| 124 | }); | 117 | }); |
| @@ -131,7 +124,7 @@ public class MenuBar extends JMenuBar { | |||
| 131 | item.addActionListener(event -> { | 124 | item.addActionListener(event -> { |
| 132 | // TODO: Use a specific file chooser for it | 125 | // TODO: Use a specific file chooser for it |
| 133 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 126 | if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 134 | this.gui.getController().saveMappings(MappingFormat.SRG_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); | 127 | this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), MappingFormat.SRG_FILE); |
| 135 | this.saveMappingsMenu.setEnabled(true); | 128 | this.saveMappingsMenu.setEnabled(true); |
| 136 | } | 129 | } |
| 137 | }); | 130 | }); |
| @@ -162,7 +155,7 @@ public class MenuBar extends JMenuBar { | |||
| 162 | menu.add(item); | 155 | menu.add(item); |
| 163 | item.addActionListener(event -> { | 156 | item.addActionListener(event -> { |
| 164 | if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 157 | if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 165 | this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile()); | 158 | this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); |
| 166 | } | 159 | } |
| 167 | }); | 160 | }); |
| 168 | this.exportSourceMenu = item; | 161 | this.exportSourceMenu = item; |
| @@ -173,8 +166,8 @@ public class MenuBar extends JMenuBar { | |||
| 173 | item.addActionListener(event -> { | 166 | item.addActionListener(event -> { |
| 174 | this.gui.exportJarFileChooser.setVisible(true); | 167 | this.gui.exportJarFileChooser.setVisible(true); |
| 175 | if (this.gui.exportJarFileChooser.getFile() != null) { | 168 | if (this.gui.exportJarFileChooser.getFile() != null) { |
| 176 | File file = new File(this.gui.exportJarFileChooser.getDirectory() + File.separator + this.gui.exportJarFileChooser.getFile()); | 169 | Path path = Paths.get(this.gui.exportJarFileChooser.getDirectory(), this.gui.exportJarFileChooser.getFile()); |
| 177 | this.gui.getController().exportJar(file); | 170 | this.gui.getController().exportJar(path); |
| 178 | } | 171 | } |
| 179 | }); | 172 | }); |
| 180 | this.exportJarMenu = item; | 173 | this.exportJarMenu = item; |
| @@ -202,7 +195,7 @@ public class MenuBar extends JMenuBar { | |||
| 202 | search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK)); | 195 | search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK)); |
| 203 | menu.add(search); | 196 | menu.add(search); |
| 204 | search.addActionListener(event -> { | 197 | search.addActionListener(event -> { |
| 205 | if (this.gui.getController().getDeobfuscator() != null) { | 198 | if (this.gui.getController().project != null) { |
| 206 | new SearchDialog(this.gui).show(); | 199 | new SearchDialog(this.gui).show(); |
| 207 | } | 200 | } |
| 208 | }); | 201 | }); |
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java index ff84648..e8a9cad 100644 --- a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java +++ b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | package cuchaz.enigma.gui.panels; | 1 | package cuchaz.enigma.gui.panels; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.Deobfuscator; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.analysis.EntryReference; | 4 | import cuchaz.enigma.analysis.EntryReference; |
| 5 | import cuchaz.enigma.config.Config; | 5 | import cuchaz.enigma.config.Config; |
| 6 | import cuchaz.enigma.gui.BrowserCaret; | 6 | import cuchaz.enigma.gui.BrowserCaret; |
| @@ -94,8 +94,8 @@ public class PanelEditor extends JEditorPane { | |||
| 94 | if (!gui.popupMenu.renameMenu.isEnabled()) return; | 94 | if (!gui.popupMenu.renameMenu.isEnabled()) return; |
| 95 | 95 | ||
| 96 | if (!event.isControlDown() && !event.isAltDown()) { | 96 | if (!event.isControlDown() && !event.isAltDown()) { |
| 97 | Deobfuscator deobfuscator = gui.getController().getDeobfuscator(); | 97 | EnigmaProject project = gui.getController().project; |
| 98 | EntryReference<Entry<?>, Entry<?>> reference = deobfuscator.deobfuscate(gui.cursorReference); | 98 | EntryReference<Entry<?>, Entry<?>> reference = project.getMapper().deobfuscate(gui.cursorReference); |
| 99 | Entry<?> entry = reference.getNameableEntry(); | 99 | Entry<?> entry = reference.getNameableEntry(); |
| 100 | 100 | ||
| 101 | String name = String.valueOf(event.getKeyChar()); | 101 | String name = String.valueOf(event.getKeyChar()); |