diff options
3 files changed, 37 insertions, 66 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java index b898eac3..20d6a0eb 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java | |||
| @@ -3,8 +3,6 @@ package cuchaz.enigma.gui.stats; | |||
| 3 | import cuchaz.enigma.EnigmaProject; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.ProgressListener; | 4 | import cuchaz.enigma.ProgressListener; |
| 5 | import cuchaz.enigma.analysis.index.EntryIndex; | 5 | import cuchaz.enigma.analysis.index.EntryIndex; |
| 6 | import cuchaz.enigma.api.service.NameProposalService; | ||
| 7 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 8 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 9 | import cuchaz.enigma.translation.mapping.EntryResolver; | 7 | import cuchaz.enigma.translation.mapping.EntryResolver; |
| 10 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | 8 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; |
| @@ -15,18 +13,16 @@ import cuchaz.enigma.utils.I18n; | |||
| 15 | import java.util.*; | 13 | import java.util.*; |
| 16 | 14 | ||
| 17 | public class StatsGenerator { | 15 | public class StatsGenerator { |
| 16 | private final EnigmaProject project; | ||
| 18 | private final EntryIndex entryIndex; | 17 | private final EntryIndex entryIndex; |
| 19 | private final EntryRemapper mapper; | 18 | private final EntryRemapper mapper; |
| 20 | private final EntryResolver entryResolver; | 19 | private final EntryResolver entryResolver; |
| 21 | private final List<ObfuscationTestService> obfuscationTestServices; | ||
| 22 | private final List<NameProposalService> nameProposalServices; | ||
| 23 | 20 | ||
| 24 | public StatsGenerator(EnigmaProject project) { | 21 | public StatsGenerator(EnigmaProject project) { |
| 25 | entryIndex = project.getJarIndex().getEntryIndex(); | 22 | this.project = project; |
| 26 | mapper = project.getMapper(); | 23 | this.entryIndex = project.getJarIndex().getEntryIndex(); |
| 27 | entryResolver = project.getJarIndex().getEntryResolver(); | 24 | this.mapper = project.getMapper(); |
| 28 | obfuscationTestServices = project.getEnigma().getServices().get(ObfuscationTestService.TYPE); | 25 | this.entryResolver = project.getJarIndex().getEntryResolver(); |
| 29 | nameProposalServices = project.getEnigma().getServices().get(NameProposalService.TYPE); | ||
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | public StatsResult generate(ProgressListener progress, Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { | 28 | public StatsResult generate(ProgressListener progress, Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { |
| @@ -111,36 +107,9 @@ public class StatsGenerator { | |||
| 111 | } | 107 | } |
| 112 | 108 | ||
| 113 | private void update(Map<String, Integer> counts, Entry<?> entry) { | 109 | private void update(Map<String, Integer> counts, Entry<?> entry) { |
| 114 | if (isObfuscated(entry)) { | 110 | if (project.isObfuscated(entry)) { |
| 115 | String parent = mapper.deobfuscate(entry.getAncestry().get(0)).getName().replace('/', '.'); | 111 | String parent = mapper.deobfuscate(entry.getAncestry().get(0)).getName().replace('/', '.'); |
| 116 | counts.put(parent, counts.getOrDefault(parent, 0) + 1); | 112 | counts.put(parent, counts.getOrDefault(parent, 0) + 1); |
| 117 | } | 113 | } |
| 118 | } | 114 | } |
| 119 | |||
| 120 | private boolean isObfuscated(Entry<?> entry) { | ||
| 121 | String name = entry.getName(); | ||
| 122 | |||
| 123 | if (!obfuscationTestServices.isEmpty()) { | ||
| 124 | for (ObfuscationTestService service : obfuscationTestServices) { | ||
| 125 | if (service.testDeobfuscated(entry)) { | ||
| 126 | return false; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!nameProposalServices.isEmpty()) { | ||
| 132 | for (NameProposalService service : nameProposalServices) { | ||
| 133 | if (service.proposeName(entry, mapper).isPresent()) { | ||
| 134 | return false; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | String mappedName = mapper.deobfuscate(entry).getName(); | ||
| 140 | if (mappedName != null && !mappedName.isEmpty() && !mappedName.equals(name)) { | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | |||
| 144 | return true; | ||
| 145 | } | ||
| 146 | } | 115 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index fcd2c96a..a01eca19 100644 --- a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java +++ b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java | |||
| @@ -18,6 +18,7 @@ import java.util.stream.Stream; | |||
| 18 | 18 | ||
| 19 | import com.google.common.base.Functions; | 19 | import com.google.common.base.Functions; |
| 20 | import com.google.common.base.Preconditions; | 20 | import com.google.common.base.Preconditions; |
| 21 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 21 | import cuchaz.enigma.classprovider.ObfuscationFixClassProvider; | 22 | import cuchaz.enigma.classprovider.ObfuscationFixClassProvider; |
| 22 | import org.objectweb.asm.ClassWriter; | 23 | import org.objectweb.asm.ClassWriter; |
| 23 | import org.objectweb.asm.tree.ClassNode; | 24 | import org.objectweb.asm.tree.ClassNode; |
| @@ -158,6 +159,35 @@ public class EnigmaProject { | |||
| 158 | return obfReference.isNamed() && isRenamable(obfReference.getNameableEntry()); | 159 | return obfReference.isNamed() && isRenamable(obfReference.getNameableEntry()); |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 162 | public boolean isObfuscated(Entry<?> entry) { | ||
| 163 | String name = entry.getName(); | ||
| 164 | |||
| 165 | List<ObfuscationTestService> obfuscationTestServices = this.getEnigma().getServices().get(ObfuscationTestService.TYPE); | ||
| 166 | if (!obfuscationTestServices.isEmpty()) { | ||
| 167 | for (ObfuscationTestService service : obfuscationTestServices) { | ||
| 168 | if (service.testDeobfuscated(entry)) { | ||
| 169 | return false; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | List<NameProposalService> nameProposalServices = this.getEnigma().getServices().get(NameProposalService.TYPE); | ||
| 175 | if (!nameProposalServices.isEmpty()) { | ||
| 176 | for (NameProposalService service : nameProposalServices) { | ||
| 177 | if (service.proposeName(entry, mapper).isPresent()) { | ||
| 178 | return false; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | String mappedName = mapper.deobfuscate(entry).getName(); | ||
| 184 | if (mappedName != null && !mappedName.isEmpty() && !mappedName.equals(name)) { | ||
| 185 | return false; | ||
| 186 | } | ||
| 187 | |||
| 188 | return true; | ||
| 189 | } | ||
| 190 | |||
| 161 | public JarExport exportRemappedJar(ProgressListener progress) { | 191 | public JarExport exportRemappedJar(ProgressListener progress) { |
| 162 | Collection<ClassEntry> classEntries = jarIndex.getEntryIndex().getClasses(); | 192 | Collection<ClassEntry> classEntries = jarIndex.getEntryIndex().getClasses(); |
| 163 | ClassProvider fixingClassProvider = new ObfuscationFixClassProvider(classProvider, jarIndex); | 193 | ClassProvider fixingClassProvider = new ObfuscationFixClassProvider(classProvider, jarIndex); |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java index 876b5ca9..f310aa75 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | |||
| @@ -2,7 +2,6 @@ package cuchaz.enigma.analysis; | |||
| 2 | 2 | ||
| 3 | import cuchaz.enigma.EnigmaProject; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.api.service.NameProposalService; | 4 | import cuchaz.enigma.api.service.NameProposalService; |
| 5 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 6 | import cuchaz.enigma.translation.TranslateResult; | 5 | import cuchaz.enigma.translation.TranslateResult; |
| 7 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 8 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 7 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| @@ -43,7 +42,7 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 43 | } | 42 | } |
| 44 | 43 | ||
| 45 | // 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 |
| 46 | if (hideDeobfuscated && this.isDeobfuscated(project, child) && !(child instanceof ClassEntry)) { | 45 | if (hideDeobfuscated && !project.isObfuscated(child) && !(child instanceof ClassEntry)) { |
| 47 | continue; | 46 | continue; |
| 48 | } | 47 | } |
| 49 | 48 | ||
| @@ -56,33 +55,6 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 56 | } | 55 | } |
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | private boolean isDeobfuscated(EnigmaProject project, ParentedEntry child) { | ||
| 60 | List<ObfuscationTestService> obfuscationTestServices = project.getEnigma().getServices().get(ObfuscationTestService.TYPE); | ||
| 61 | |||
| 62 | if (!obfuscationTestServices.isEmpty()) { | ||
| 63 | for (ObfuscationTestService service : obfuscationTestServices) { | ||
| 64 | if (service.testDeobfuscated(child)) { | ||
| 65 | return true; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | if (!this.nameProposalServices.isEmpty()) { | ||
| 71 | for (NameProposalService service : this.nameProposalServices) { | ||
| 72 | if (service.proposeName(child, this.mapper).isPresent()) { | ||
| 73 | return true; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | String mappedName = project.getMapper().deobfuscate(child).getName(); | ||
| 79 | if (mappedName != null && !mappedName.isEmpty() && !mappedName.equals(child.getName())) { | ||
| 80 | return true; | ||
| 81 | } | ||
| 82 | |||
| 83 | return false; | ||
| 84 | } | ||
| 85 | |||
| 86 | @Override | 58 | @Override |
| 87 | public String toString() { | 59 | public String toString() { |
| 88 | TranslateResult<ParentedEntry> translateResult = this.mapper.extendedDeobfuscate(this.entry); | 60 | TranslateResult<ParentedEntry> translateResult = this.mapper.extendedDeobfuscate(this.entry); |