summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java5
-rw-r--r--enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java63
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 @@
1package cuchaz.enigma.analysis; 1package cuchaz.enigma.analysis;
2 2
3import cuchaz.enigma.analysis.index.JarIndex; 3import cuchaz.enigma.EnigmaProject;
4import cuchaz.enigma.translation.Translator; 4import cuchaz.enigma.api.service.NameProposalService;
5import cuchaz.enigma.api.service.ObfuscationTestService;
6import cuchaz.enigma.translation.mapping.EntryRemapper;
5import cuchaz.enigma.translation.representation.TypeDescriptor; 7import cuchaz.enigma.translation.representation.TypeDescriptor;
6import cuchaz.enigma.translation.representation.entry.*; 8import cuchaz.enigma.translation.representation.entry.*;
7 9
@@ -9,12 +11,14 @@ import javax.swing.tree.DefaultMutableTreeNode;
9import java.util.List; 11import java.util.List;
10 12
11public class StructureTreeNode extends DefaultMutableTreeNode { 13public 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());