diff options
| author | 2020-12-15 09:17:08 +0100 | |
|---|---|---|
| committer | 2020-12-15 09:17:08 +0100 | |
| commit | 68dd12b0efd2632e292e32827f1870310a003634 (patch) | |
| tree | 88efca8730486440751a1dba1ec111af32786846 | |
| parent | Use class icon in class tree (ClassSelector) (#2) (diff) | |
| download | enigma-68dd12b0efd2632e292e32827f1870310a003634.tar.gz enigma-68dd12b0efd2632e292e32827f1870310a003634.tar.xz enigma-68dd12b0efd2632e292e32827f1870310a003634.zip | |
Fix automapped entries
Automatically deobfuscated names (like in enums) were displayed with their obfuscated name, and were not considered as deobf when selecting "hide deobf members"
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | 5 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | 63 |
2 files changed, 53 insertions, 15 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index 4e964dae..656f5a43 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -393,9 +393,8 @@ public class GuiController implements ClientPacketHandler { | |||
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | public StructureTreeNode getClassStructure(ClassEntry entry, boolean hideDeobfuscated) { | 395 | public StructureTreeNode getClassStructure(ClassEntry entry, boolean hideDeobfuscated) { |
| 396 | Translator translator = this.project.getMapper().getDeobfuscator(); | 396 | StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); |
| 397 | StructureTreeNode rootNode = new StructureTreeNode(translator, entry, entry); | 397 | rootNode.load(this.project, hideDeobfuscated); |
| 398 | rootNode.load(this.project.getJarIndex(), hideDeobfuscated); | ||
| 399 | return rootNode; | 398 | return rootNode; |
| 400 | } | 399 | } |
| 401 | 400 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java index 13f277c7..312c2fec 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | package cuchaz.enigma.analysis; | 1 | package cuchaz.enigma.analysis; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.analysis.index.JarIndex; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.translation.Translator; | 4 | import cuchaz.enigma.api.service.NameProposalService; |
| 5 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; | ||
| 5 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 7 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 6 | import cuchaz.enigma.translation.representation.entry.*; | 8 | import cuchaz.enigma.translation.representation.entry.*; |
| 7 | 9 | ||
| @@ -9,12 +11,14 @@ import javax.swing.tree.DefaultMutableTreeNode; | |||
| 9 | import java.util.List; | 11 | import java.util.List; |
| 10 | 12 | ||
| 11 | public class StructureTreeNode extends DefaultMutableTreeNode { | 13 | public class StructureTreeNode extends DefaultMutableTreeNode { |
| 12 | private final Translator translator; | 14 | private final List<NameProposalService> nameProposalServices; |
| 15 | private final EntryRemapper mapper; | ||
| 13 | private final ClassEntry parentEntry; | 16 | private final ClassEntry parentEntry; |
| 14 | private final ParentedEntry entry; | 17 | private final ParentedEntry entry; |
| 15 | 18 | ||
| 16 | public StructureTreeNode(Translator translator, ClassEntry parentEntry, ParentedEntry entry) { | 19 | public StructureTreeNode(EnigmaProject project, ClassEntry parentEntry, ParentedEntry entry) { |
| 17 | this.translator = translator; | 20 | this.nameProposalServices = project.getEnigma().getServices().get(NameProposalService.TYPE); |
| 21 | this.mapper = project.getMapper(); | ||
| 18 | this.parentEntry = parentEntry; | 22 | this.parentEntry = parentEntry; |
| 19 | this.entry = entry; | 23 | this.entry = entry; |
| 20 | } | 24 | } |
| @@ -26,19 +30,19 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 26 | return this.entry; | 30 | return this.entry; |
| 27 | } | 31 | } |
| 28 | 32 | ||
| 29 | public void load(JarIndex jarIndex, boolean hideDeobfuscated) { | 33 | public void load(EnigmaProject project, boolean hideDeobfuscated) { |
| 30 | List<ParentedEntry> children = jarIndex.getChildrenByClass().get(this.parentEntry); | 34 | List<ParentedEntry> children = project.getJarIndex().getChildrenByClass().get(this.parentEntry); |
| 31 | 35 | ||
| 32 | for (ParentedEntry child : children) { | 36 | for (ParentedEntry child : children) { |
| 33 | StructureTreeNode childNode = new StructureTreeNode(this.translator, this.parentEntry, child); | 37 | StructureTreeNode childNode = new StructureTreeNode(project, this.parentEntry, child); |
| 34 | 38 | ||
| 35 | if (child instanceof ClassEntry) { | 39 | if (child instanceof ClassEntry) { |
| 36 | childNode = new StructureTreeNode(this.translator, (ClassEntry) child, child); | 40 | childNode = new StructureTreeNode(project, (ClassEntry) child, child); |
| 37 | childNode.load(jarIndex, hideDeobfuscated); | 41 | childNode.load(project, hideDeobfuscated); |
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | // don't add deobfuscated members if hideDeobfuscated is true, unless it's an inner class | 44 | // don't add deobfuscated members if hideDeobfuscated is true, unless it's an inner class |
| 41 | if (hideDeobfuscated && this.translator.extendedTranslate(child).isDeobfuscated() && !(child instanceof ClassEntry)) { | 45 | if (hideDeobfuscated && this.isDeobfuscated(project, child) && !(child instanceof ClassEntry)) { |
| 42 | continue; | 46 | continue; |
| 43 | } | 47 | } |
| 44 | 48 | ||
| @@ -51,11 +55,46 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 51 | } | 55 | } |
| 52 | } | 56 | } |
| 53 | 57 | ||
| 58 | private boolean isDeobfuscated(EnigmaProject project, ParentedEntry child) { | ||
| 59 | List<ObfuscationTestService> obfuscationTestServices = project.getEnigma().getServices().get(ObfuscationTestService.TYPE); | ||
| 60 | |||
| 61 | if (!obfuscationTestServices.isEmpty()) { | ||
| 62 | for (ObfuscationTestService service : obfuscationTestServices) { | ||
| 63 | if (service.testDeobfuscated(child)) { | ||
| 64 | return true; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | if (!this.nameProposalServices.isEmpty()) { | ||
| 70 | for (NameProposalService service : this.nameProposalServices) { | ||
| 71 | if (service.proposeName(child, this.mapper).isPresent()) { | ||
| 72 | return true; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | String mappedName = project.getMapper().deobfuscate(child).getName(); | ||
| 78 | if (mappedName != null && !mappedName.isEmpty() && !mappedName.equals(child.getName())) { | ||
| 79 | return true; | ||
| 80 | } | ||
| 81 | |||
| 82 | return false; | ||
| 83 | } | ||
| 84 | |||
| 54 | @Override | 85 | @Override |
| 55 | public String toString() { | 86 | public String toString() { |
| 56 | ParentedEntry translatedEntry = this.translator.extendedTranslate(this.entry).getValue(); | 87 | ParentedEntry translatedEntry = this.mapper.deobfuscate(this.entry); |
| 57 | String result = translatedEntry.getName(); | 88 | String result = translatedEntry.getName(); |
| 58 | 89 | ||
| 90 | if (!this.nameProposalServices.isEmpty()) { | ||
| 91 | for (NameProposalService service : this.nameProposalServices) { | ||
| 92 | if (service.proposeName(this.entry, this.mapper).isPresent()) { | ||
| 93 | result = service.proposeName(this.entry, this.mapper).get(); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 59 | if (this.entry instanceof FieldDefEntry) { | 98 | if (this.entry instanceof FieldDefEntry) { |
| 60 | FieldDefEntry field = (FieldDefEntry) translatedEntry; | 99 | FieldDefEntry field = (FieldDefEntry) translatedEntry; |
| 61 | String returnType = this.parseDesc(field.getDesc()); | 100 | String returnType = this.parseDesc(field.getDesc()); |