diff options
| author | 2018-07-17 19:14:08 +0200 | |
|---|---|---|
| committer | 2018-07-17 19:14:08 +0200 | |
| commit | a88175ffc95792b88a8724f66db6dda2b8cc32ee (patch) | |
| tree | 65895bbc6cf1766f4ca01e1257619ab1993e71dc /src/main/java/cuchaz/enigma/gui/Gui.java | |
| parent | Merge pull request #3 from thiakil/src-jar (diff) | |
| download | enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.gz enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.tar.xz enigma-fork-a88175ffc95792b88a8724f66db6dda2b8cc32ee.zip | |
ASM Based Class Translator (#1)
* Initial port to ASM
* Package updates
* Annotation + inner class translation
* Fix inner class mapping
* More bytecode translation
* Signature refactoring
* Fix highlighting of mapped names
* Fix parameter name offset
* Fix anonymous class generation
* Fix issues with inner class signature transformation
* Fix bridged method detection
* Fix compile issues
* Resolve all failed tests
* Apply deobfuscated name to transformed classes
* Fix class signatures not being translated
* Fix frame array type translation
* Fix frame array type translation
* Fix array translation in method calls
* Fix method reference and bridge detection
* Fix handling of null deobf mappings
* Parameter translation in interfaces
* Fix enum parameter index offset
* Fix parsed local variable indexing
* Fix stackoverflow on rebuilding method names
* Ignore invalid decompiled variable indices
* basic source jar
* Output directly to file on source export
* Make decompile parallel
* fix incorrect super calls
* Use previous save state to delete old mapping files
* Fix old mappings not properly being removed
* Fix old mappings not properly being removed
* make isMethodProvider public
(cherry picked from commit ebad6a9)
* speed up Deobfuscator's getSources by using a single TranslatingTypeloader and caching the ClassLoaderTypeloader
* ignore .idea project folders
* move SynchronizedTypeLoader to a non-inner
* fix signature remap of inners for now
* index & resolve method/field references for usages view
* Allow reader/writer subclasses to provide the underlying file operations
* fix giving obf classes a name not removing them from the panel
* buffer the ParsedJar class entry inputstream, allow use with a jarinputstream
* make CachingClasspathTypeLoader public
* make CachingClasspathTypeLoader public
* support enum switches with obfuscated SwitchMaps
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/Gui.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/Gui.java | 67 |
1 files changed, 24 insertions, 43 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 4a891cf..cfac8ad 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -32,10 +32,10 @@ import cuchaz.enigma.gui.panels.PanelEditor; | |||
| 32 | import cuchaz.enigma.gui.panels.PanelIdentifier; | 32 | import cuchaz.enigma.gui.panels.PanelIdentifier; |
| 33 | import cuchaz.enigma.gui.panels.PanelObf; | 33 | import cuchaz.enigma.gui.panels.PanelObf; |
| 34 | import cuchaz.enigma.mapping.*; | 34 | import cuchaz.enigma.mapping.*; |
| 35 | import cuchaz.enigma.mapping.entry.*; | ||
| 35 | import cuchaz.enigma.throwables.IllegalNameException; | 36 | import cuchaz.enigma.throwables.IllegalNameException; |
| 36 | import cuchaz.enigma.utils.Utils; | 37 | import cuchaz.enigma.utils.Utils; |
| 37 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 38 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 38 | import javassist.bytecode.Descriptor; | ||
| 39 | 39 | ||
| 40 | import javax.swing.*; | 40 | import javax.swing.*; |
| 41 | import javax.swing.text.BadLocationException; | 41 | import javax.swing.text.BadLocationException; |
| @@ -48,8 +48,10 @@ import java.awt.*; | |||
| 48 | import java.awt.event.*; | 48 | import java.awt.event.*; |
| 49 | import java.io.File; | 49 | import java.io.File; |
| 50 | import java.io.IOException; | 50 | import java.io.IOException; |
| 51 | import java.util.*; | 51 | import java.util.Collection; |
| 52 | import java.util.Collections; | ||
| 52 | import java.util.List; | 53 | import java.util.List; |
| 54 | import java.util.Vector; | ||
| 53 | import java.util.function.Function; | 55 | import java.util.function.Function; |
| 54 | 56 | ||
| 55 | public class Gui { | 57 | public class Gui { |
| @@ -438,14 +440,10 @@ public class Gui { | |||
| 438 | showFieldEntry((FieldEntry) this.reference.entry); | 440 | showFieldEntry((FieldEntry) this.reference.entry); |
| 439 | } else if (this.reference.entry instanceof MethodEntry) { | 441 | } else if (this.reference.entry instanceof MethodEntry) { |
| 440 | showMethodEntry((MethodEntry) this.reference.entry); | 442 | showMethodEntry((MethodEntry) this.reference.entry); |
| 441 | } else if (this.reference.entry instanceof ConstructorEntry) { | ||
| 442 | showConstructorEntry((ConstructorEntry) this.reference.entry); | ||
| 443 | } else if (this.reference.entry instanceof ArgumentEntry) { | ||
| 444 | showArgumentEntry((ArgumentEntry) this.reference.entry); | ||
| 445 | } else if (this.reference.entry instanceof LocalVariableEntry) { | 443 | } else if (this.reference.entry instanceof LocalVariableEntry) { |
| 446 | showLocalVariableEntry((LocalVariableEntry) this.reference.entry); | 444 | showLocalVariableEntry((LocalVariableEntry) this.reference.entry); |
| 447 | } else { | 445 | } else { |
| 448 | throw new Error("Unknown entry type: " + this.reference.entry.getClass().getName()); | 446 | throw new Error("Unknown entry desc: " + this.reference.entry.getClass().getName()); |
| 449 | } | 447 | } |
| 450 | 448 | ||
| 451 | redraw(); | 449 | redraw(); |
| @@ -453,10 +451,9 @@ public class Gui { | |||
| 453 | 451 | ||
| 454 | private void showLocalVariableEntry(LocalVariableEntry entry) { | 452 | private void showLocalVariableEntry(LocalVariableEntry entry) { |
| 455 | addNameValue(infoPanel, "Variable", entry.getName()); | 453 | addNameValue(infoPanel, "Variable", entry.getName()); |
| 456 | addNameValue(infoPanel, "Class", entry.getClassEntry().getName()); | 454 | addNameValue(infoPanel, "Class", entry.getOwnerClassEntry().getName()); |
| 457 | addNameValue(infoPanel, "Method", entry.getBehaviorEntry().getName()); | 455 | addNameValue(infoPanel, "Method", entry.getOwnerEntry().getName()); |
| 458 | addNameValue(infoPanel, "Index", Integer.toString(entry.getIndex())); | 456 | addNameValue(infoPanel, "Index", Integer.toString(entry.getIndex())); |
| 459 | addNameValue(infoPanel, "Type", entry.getType().toString()); | ||
| 460 | } | 457 | } |
| 461 | 458 | ||
| 462 | private void showClassEntry(ClassEntry entry) { | 459 | private void showClassEntry(ClassEntry entry) { |
| @@ -466,32 +463,20 @@ public class Gui { | |||
| 466 | 463 | ||
| 467 | private void showFieldEntry(FieldEntry entry) { | 464 | private void showFieldEntry(FieldEntry entry) { |
| 468 | addNameValue(infoPanel, "Field", entry.getName()); | 465 | addNameValue(infoPanel, "Field", entry.getName()); |
| 469 | addNameValue(infoPanel, "Class", entry.getClassEntry().getName()); | 466 | addNameValue(infoPanel, "Class", entry.getOwnerClassEntry().getName()); |
| 470 | addNameValue(infoPanel, "Type", entry.getType().toString()); | 467 | addNameValue(infoPanel, "TypeDescriptor", entry.getDesc().toString()); |
| 471 | addModifierComboBox(infoPanel, "Modifier", entry); | 468 | addModifierComboBox(infoPanel, "Modifier", entry); |
| 472 | } | 469 | } |
| 473 | 470 | ||
| 474 | private void showMethodEntry(MethodEntry entry) { | 471 | private void showMethodEntry(MethodEntry entry) { |
| 475 | addNameValue(infoPanel, "Method", entry.getName()); | 472 | if (entry.isConstructor()) { |
| 476 | addNameValue(infoPanel, "Class", entry.getClassEntry().getName()); | 473 | addNameValue(infoPanel, "Constructor", entry.getOwnerClassEntry().getName()); |
| 477 | addNameValue(infoPanel, "Signature", entry.getSignature().toString()); | 474 | } else { |
| 478 | addModifierComboBox(infoPanel, "Modifier", entry); | 475 | addNameValue(infoPanel, "Method", entry.getName()); |
| 479 | 476 | addNameValue(infoPanel, "Class", entry.getOwnerClassEntry().getName()); | |
| 480 | } | ||
| 481 | |||
| 482 | private void showConstructorEntry(ConstructorEntry entry) { | ||
| 483 | addNameValue(infoPanel, "Constructor", entry.getClassEntry().getName()); | ||
| 484 | if (!entry.isStatic()) { | ||
| 485 | addNameValue(infoPanel, "Signature", entry.getSignature().toString()); | ||
| 486 | addModifierComboBox(infoPanel, "Modifier", entry); | ||
| 487 | } | 477 | } |
| 488 | } | 478 | addNameValue(infoPanel, "MethodDescriptor", entry.getDesc().toString()); |
| 489 | 479 | addModifierComboBox(infoPanel, "Modifier", entry); | |
| 490 | private void showArgumentEntry(ArgumentEntry entry) { | ||
| 491 | addNameValue(infoPanel, "Argument", entry.getName()); | ||
| 492 | addNameValue(infoPanel, "Class", entry.getClassEntry().getName()); | ||
| 493 | addNameValue(infoPanel, "Method", entry.getBehaviorEntry().getName()); | ||
| 494 | addNameValue(infoPanel, "Index", Integer.toString(entry.getIndex())); | ||
| 495 | } | 480 | } |
| 496 | 481 | ||
| 497 | private void addNameValue(JPanel container, String name, String value) { | 482 | private void addNameValue(JPanel container, String name, String value) { |
| @@ -532,8 +517,8 @@ public class Gui { | |||
| 532 | reference = this.controller.getDeobfReference(token); | 517 | reference = this.controller.getDeobfReference(token); |
| 533 | boolean isClassEntry = isToken && reference.entry instanceof ClassEntry; | 518 | boolean isClassEntry = isToken && reference.entry instanceof ClassEntry; |
| 534 | boolean isFieldEntry = isToken && reference.entry instanceof FieldEntry; | 519 | boolean isFieldEntry = isToken && reference.entry instanceof FieldEntry; |
| 535 | boolean isMethodEntry = isToken && reference.entry instanceof MethodEntry; | 520 | boolean isMethodEntry = isToken && reference.entry instanceof MethodEntry && !((MethodEntry) reference.entry).isConstructor(); |
| 536 | boolean isConstructorEntry = isToken && reference.entry instanceof ConstructorEntry; | 521 | boolean isConstructorEntry = isToken && reference.entry instanceof MethodEntry && ((MethodEntry) reference.entry).isConstructor(); |
| 537 | boolean isInJar = isToken && this.controller.entryIsInJar(reference.entry); | 522 | boolean isInJar = isToken && this.controller.entryIsInJar(reference.entry); |
| 538 | boolean isRenameable = isToken && this.controller.referenceIsRenameable(reference); | 523 | boolean isRenameable = isToken && this.controller.referenceIsRenameable(reference); |
| 539 | 524 | ||
| @@ -710,16 +695,13 @@ public class Gui { | |||
| 710 | if (reference.entry instanceof ClassEntry) { | 695 | if (reference.entry instanceof ClassEntry) { |
| 711 | // look for calls to the default constructor | 696 | // look for calls to the default constructor |
| 712 | // TODO: get a list of all the constructors and find calls to all of them | 697 | // TODO: get a list of all the constructors and find calls to all of them |
| 713 | BehaviorReferenceTreeNode node = this.controller.getMethodReferences(new ConstructorEntry((ClassEntry) reference.entry, new Signature("()V"))); | 698 | MethodReferenceTreeNode node = this.controller.getMethodReferences(new MethodEntry((ClassEntry) reference.entry, "<init>", new MethodDescriptor("()V"))); |
| 714 | callsTree.setModel(new DefaultTreeModel(node)); | 699 | callsTree.setModel(new DefaultTreeModel(node)); |
| 715 | } else if (reference.entry instanceof FieldEntry) { | 700 | } else if (reference.entry instanceof FieldEntry) { |
| 716 | FieldReferenceTreeNode node = this.controller.getFieldReferences((FieldEntry) reference.entry); | 701 | FieldReferenceTreeNode node = this.controller.getFieldReferences((FieldEntry) reference.entry); |
| 717 | callsTree.setModel(new DefaultTreeModel(node)); | 702 | callsTree.setModel(new DefaultTreeModel(node)); |
| 718 | } else if (reference.entry instanceof MethodEntry) { | 703 | } else if (reference.entry instanceof MethodEntry) { |
| 719 | BehaviorReferenceTreeNode node = this.controller.getMethodReferences((MethodEntry) reference.entry); | 704 | MethodReferenceTreeNode node = this.controller.getMethodReferences((MethodEntry) reference.entry); |
| 720 | callsTree.setModel(new DefaultTreeModel(node)); | ||
| 721 | } else if (reference.entry instanceof ConstructorEntry) { | ||
| 722 | BehaviorReferenceTreeNode node = this.controller.getMethodReferences((ConstructorEntry) reference.entry); | ||
| 723 | callsTree.setModel(new DefaultTreeModel(node)); | 705 | callsTree.setModel(new DefaultTreeModel(node)); |
| 724 | } | 706 | } |
| 725 | 707 | ||
| @@ -790,7 +772,6 @@ public class Gui { | |||
| 790 | // package rename | 772 | // package rename |
| 791 | if (data instanceof String) { | 773 | if (data instanceof String) { |
| 792 | for (int i = 0; i < node.getChildCount(); i++) { | 774 | for (int i = 0; i < node.getChildCount(); i++) { |
| 793 | data = Descriptor.toJvmName((String) data); | ||
| 794 | DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i); | 775 | DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i); |
| 795 | ClassEntry prevDataChild = (ClassEntry) childNode.getUserObject(); | 776 | ClassEntry prevDataChild = (ClassEntry) childNode.getUserObject(); |
| 796 | ClassEntry dataChild = new ClassEntry(data + "/" + prevDataChild.getSimpleName()); | 777 | ClassEntry dataChild = new ClassEntry(data + "/" + prevDataChild.getSimpleName()); |
| @@ -807,15 +788,15 @@ public class Gui { | |||
| 807 | } | 788 | } |
| 808 | 789 | ||
| 809 | public void moveClassTree(EntryReference<Entry, Entry> deobfReference, String newName) { | 790 | public void moveClassTree(EntryReference<Entry, Entry> deobfReference, String newName) { |
| 810 | String oldEntry = deobfReference.entry.getClassEntry().getPackageName(); | 791 | String oldEntry = deobfReference.entry.getOwnerClassEntry().getPackageName(); |
| 811 | String newEntry = new ClassEntry(Descriptor.toJvmName(newName)).getPackageName(); | 792 | String newEntry = new ClassEntry(newName).getPackageName(); |
| 812 | moveClassTree(deobfReference, newName, oldEntry == null, | 793 | moveClassTree(deobfReference, newName, oldEntry == null, |
| 813 | newEntry == null); | 794 | newEntry == null); |
| 814 | } | 795 | } |
| 815 | 796 | ||
| 816 | public void moveClassTree(EntryReference<Entry, Entry> deobfReference, String newName, boolean isOldOb, boolean isNewOb) { | 797 | public void moveClassTree(EntryReference<Entry, Entry> deobfReference, String newName, boolean isOldOb, boolean isNewOb) { |
| 817 | ClassEntry oldEntry = deobfReference.entry.getClassEntry(); | 798 | ClassEntry oldEntry = deobfReference.entry.getOwnerClassEntry(); |
| 818 | ClassEntry newEntry = new ClassEntry(Descriptor.toJvmName(newName)); | 799 | ClassEntry newEntry = new ClassEntry(newName); |
| 819 | 800 | ||
| 820 | // Ob -> deob | 801 | // Ob -> deob |
| 821 | if (isOldOb && !isNewOb) { | 802 | if (isOldOb && !isNewOb) { |