diff options
| author | 2017-03-07 21:24:39 +0100 | |
|---|---|---|
| committer | 2017-03-07 21:30:02 +0100 | |
| commit | b4aaff683d78ab92b83f3a7257c33b8e27d1affa (patch) | |
| tree | f23c9bb0927d83cc7302881266b7df8fd37959c7 /src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |
| parent | Avoid crash of the matcher when the obf name is invalid (set a deob it using ... (diff) | |
| download | enigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.gz enigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.xz enigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.zip | |
Drop unix case style and implement hashCode when equals is overrided
Also update Guava to version 21
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index bac6250..e1428ea 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -13,30 +13,28 @@ package cuchaz.enigma.mapping; | |||
| 13 | import java.io.IOException; | 13 | import java.io.IOException; |
| 14 | import java.io.ObjectOutputStream; | 14 | import java.io.ObjectOutputStream; |
| 15 | import java.io.OutputStream; | 15 | import java.io.OutputStream; |
| 16 | import java.io.Serializable; | ||
| 17 | import java.util.List; | 16 | import java.util.List; |
| 18 | import java.util.Set; | 17 | import java.util.Set; |
| 19 | import java.util.zip.GZIPOutputStream; | 18 | import java.util.zip.GZIPOutputStream; |
| 20 | 19 | ||
| 21 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 22 | import cuchaz.enigma.analysis.JarIndex; | 21 | import cuchaz.enigma.analysis.JarIndex; |
| 23 | import cuchaz.enigma.analysis.MethodImplementationsTreeNode; | ||
| 24 | import cuchaz.enigma.throwables.IllegalNameException; | 22 | import cuchaz.enigma.throwables.IllegalNameException; |
| 25 | import cuchaz.enigma.throwables.MappingConflict; | 23 | import cuchaz.enigma.throwables.MappingConflict; |
| 26 | 24 | ||
| 27 | public class MappingsRenamer { | 25 | public class MappingsRenamer { |
| 28 | 26 | ||
| 29 | private JarIndex m_index; | 27 | private JarIndex index; |
| 30 | private Mappings m_mappings; | 28 | private Mappings mappings; |
| 31 | 29 | ||
| 32 | public MappingsRenamer(JarIndex index, Mappings mappings) { | 30 | public MappingsRenamer(JarIndex index, Mappings mappings) { |
| 33 | m_index = index; | 31 | this.index = index; |
| 34 | m_mappings = mappings; | 32 | this.mappings = mappings; |
| 35 | } | 33 | } |
| 36 | 34 | ||
| 37 | public void setMappings(Mappings mappings) | 35 | public void setMappings(Mappings mappings) |
| 38 | { | 36 | { |
| 39 | this.m_mappings = mappings; | 37 | this.mappings = mappings; |
| 40 | } | 38 | } |
| 41 | 39 | ||
| 42 | public void setClassName(ClassEntry obf, String deobfName) { | 40 | public void setClassName(ClassEntry obf, String deobfName) { |
| @@ -48,13 +46,13 @@ public class MappingsRenamer { | |||
| 48 | 46 | ||
| 49 | if (deobfName != null) { | 47 | if (deobfName != null) { |
| 50 | // make sure we don't rename to an existing obf or deobf class | 48 | // make sure we don't rename to an existing obf or deobf class |
| 51 | if (m_mappings.containsDeobfClass(deobfName) || m_index.containsObfClass(new ClassEntry(deobfName))) { | 49 | if (mappings.containsDeobfClass(deobfName) || index.containsObfClass(new ClassEntry(deobfName))) { |
| 52 | throw new IllegalNameException(deobfName, "There is already a class with that name"); | 50 | throw new IllegalNameException(deobfName, "There is already a class with that name"); |
| 53 | } | 51 | } |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | ClassMapping classMapping = mappingChain.get(0); | 54 | ClassMapping classMapping = mappingChain.get(0); |
| 57 | m_mappings.setClassDeobfName(classMapping, deobfName); | 55 | mappings.setClassDeobfName(classMapping, deobfName); |
| 58 | 56 | ||
| 59 | } else { | 57 | } else { |
| 60 | 58 | ||
| @@ -80,7 +78,7 @@ public class MappingsRenamer { | |||
| 80 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obf); | 78 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obf); |
| 81 | if (mappingChain.size() == 1) { | 79 | if (mappingChain.size() == 1) { |
| 82 | ClassMapping classMapping = mappingChain.get(0); | 80 | ClassMapping classMapping = mappingChain.get(0); |
| 83 | m_mappings.setClassDeobfName(classMapping, deobfName); | 81 | mappings.setClassDeobfName(classMapping, deobfName); |
| 84 | } else { | 82 | } else { |
| 85 | ClassMapping outerClassMapping = mappingChain.get(mappingChain.size() - 2); | 83 | ClassMapping outerClassMapping = mappingChain.get(mappingChain.size() - 2); |
| 86 | outerClassMapping.setInnerClassName(obf, deobfName); | 84 | outerClassMapping.setInnerClassName(obf, deobfName); |
| @@ -91,11 +89,11 @@ public class MappingsRenamer { | |||
| 91 | deobfName = NameValidator.validateFieldName(deobfName); | 89 | deobfName = NameValidator.validateFieldName(deobfName); |
| 92 | FieldEntry targetEntry = new FieldEntry(obf.getClassEntry(), deobfName, obf.getType()); | 90 | FieldEntry targetEntry = new FieldEntry(obf.getClassEntry(), deobfName, obf.getType()); |
| 93 | ClassEntry definedClass = null; | 91 | ClassEntry definedClass = null; |
| 94 | if (m_mappings.containsDeobfField(obf.getClassEntry(), deobfName) || m_index.containsEntryWithSameName(targetEntry)) | 92 | if (mappings.containsDeobfField(obf.getClassEntry(), deobfName) || index.containsEntryWithSameName(targetEntry)) |
| 95 | definedClass = obf.getClassEntry(); | 93 | definedClass = obf.getClassEntry(); |
| 96 | else { | 94 | else { |
| 97 | for (ClassEntry ancestorEntry : this.m_index.getTranslationIndex().getAncestry(obf.getClassEntry())) { | 95 | for (ClassEntry ancestorEntry : this.index.getTranslationIndex().getAncestry(obf.getClassEntry())) { |
| 98 | if (m_mappings.containsDeobfField(ancestorEntry, deobfName) || m_index.containsEntryWithSameName(targetEntry.cloneToNewClass(ancestorEntry))) { | 96 | if (mappings.containsDeobfField(ancestorEntry, deobfName) || index.containsEntryWithSameName(targetEntry.cloneToNewClass(ancestorEntry))) { |
| 99 | definedClass = ancestorEntry; | 97 | definedClass = ancestorEntry; |
| 100 | break; | 98 | break; |
| 101 | } | 99 | } |
| @@ -103,7 +101,7 @@ public class MappingsRenamer { | |||
| 103 | } | 101 | } |
| 104 | 102 | ||
| 105 | if (definedClass != null) { | 103 | if (definedClass != null) { |
| 106 | String className = m_mappings.getTranslator(TranslationDirection.Deobfuscating, m_index.getTranslationIndex()).translateClass(definedClass.getClassName()); | 104 | String className = mappings.getTranslator(TranslationDirection.Deobfuscating, index.getTranslationIndex()).translateClass(definedClass.getClassName()); |
| 107 | if (className == null) | 105 | if (className == null) |
| 108 | className = definedClass.getClassName(); | 106 | className = definedClass.getClassName(); |
| 109 | throw new IllegalNameException(deobfName, "There is already a field with that name in " + className); | 107 | throw new IllegalNameException(deobfName, "There is already a field with that name in " + className); |
| @@ -127,23 +125,23 @@ public class MappingsRenamer { | |||
| 127 | MethodEntry targetEntry = new MethodEntry(entry.getClassEntry(), deobfName, entry.getSignature()); | 125 | MethodEntry targetEntry = new MethodEntry(entry.getClassEntry(), deobfName, entry.getSignature()); |
| 128 | 126 | ||
| 129 | // TODO: Verify if I don't break things | 127 | // TODO: Verify if I don't break things |
| 130 | ClassMapping classMapping = m_mappings.getClassByObf(entry.getClassEntry()); | 128 | ClassMapping classMapping = mappings.getClassByObf(entry.getClassEntry()); |
| 131 | if ((classMapping != null && classMapping.containsDeobfMethod(deobfName, entry.getSignature()) && classMapping.getMethodByObf(entry.getName(), entry.getSignature()) != classMapping.getMethodByDeobf(deobfName, entry.getSignature())) | 129 | if ((classMapping != null && classMapping.containsDeobfMethod(deobfName, entry.getSignature()) && classMapping.getMethodByObf(entry.getName(), entry.getSignature()) != classMapping.getMethodByDeobf(deobfName, entry.getSignature())) |
| 132 | || m_index.containsObfBehavior(targetEntry)) { | 130 | || index.containsObfBehavior(targetEntry)) { |
| 133 | String deobfClassName = m_mappings.getTranslator(TranslationDirection.Deobfuscating, m_index.getTranslationIndex()).translateClass(entry.getClassName()); | 131 | String deobfClassName = mappings.getTranslator(TranslationDirection.Deobfuscating, index.getTranslationIndex()).translateClass(entry.getClassName()); |
| 134 | if (deobfClassName == null) { | 132 | if (deobfClassName == null) { |
| 135 | deobfClassName = entry.getClassName(); | 133 | deobfClassName = entry.getClassName(); |
| 136 | } | 134 | } |
| 137 | throw new IllegalNameException(deobfName, "There is already a method with that name and signature in class " + deobfClassName); | 135 | throw new IllegalNameException(deobfName, "There is already a method with that name and signature in class " + deobfClassName); |
| 138 | } | 136 | } |
| 139 | 137 | ||
| 140 | for (ClassEntry child : m_index.getTranslationIndex().getSubclass(entry.getClassEntry())) { | 138 | for (ClassEntry child : index.getTranslationIndex().getSubclass(entry.getClassEntry())) { |
| 141 | validateMethodTreeName(entry.cloneToNewClass(child), deobfName); | 139 | validateMethodTreeName(entry.cloneToNewClass(child), deobfName); |
| 142 | } | 140 | } |
| 143 | } | 141 | } |
| 144 | 142 | ||
| 145 | public void setMethodTreeName(MethodEntry obf, String deobfName) { | 143 | public void setMethodTreeName(MethodEntry obf, String deobfName) { |
| 146 | Set<MethodEntry> implementations = m_index.getRelatedMethodImplementations(obf); | 144 | Set<MethodEntry> implementations = index.getRelatedMethodImplementations(obf); |
| 147 | 145 | ||
| 148 | deobfName = NameValidator.validateMethodName(deobfName); | 146 | deobfName = NameValidator.validateMethodName(deobfName); |
| 149 | for (MethodEntry entry : implementations) { | 147 | for (MethodEntry entry : implementations) { |
| @@ -161,9 +159,9 @@ public class MappingsRenamer { | |||
| 161 | ClassMapping classMapping = getOrCreateClassMapping(obf.getClassEntry()); | 159 | ClassMapping classMapping = getOrCreateClassMapping(obf.getClassEntry()); |
| 162 | 160 | ||
| 163 | // TODO: Verify if I don't break things | 161 | // TODO: Verify if I don't break things |
| 164 | if ((m_mappings.containsDeobfMethod(obf.getClassEntry(), deobfName, obf.getSignature()) && classMapping.getMethodByObf(obf.getName(), obf.getSignature()) != classMapping.getMethodByDeobf(deobfName, obf.getSignature())) | 162 | if ((mappings.containsDeobfMethod(obf.getClassEntry(), deobfName, obf.getSignature()) && classMapping.getMethodByObf(obf.getName(), obf.getSignature()) != classMapping.getMethodByDeobf(deobfName, obf.getSignature())) |
| 165 | || m_index.containsObfBehavior(targetEntry)) { | 163 | || index.containsObfBehavior(targetEntry)) { |
| 166 | String deobfClassName = m_mappings.getTranslator(TranslationDirection.Deobfuscating, m_index.getTranslationIndex()).translateClass(obf.getClassName()); | 164 | String deobfClassName = mappings.getTranslator(TranslationDirection.Deobfuscating, index.getTranslationIndex()).translateClass(obf.getClassName()); |
| 167 | if (deobfClassName == null) { | 165 | if (deobfClassName == null) { |
| 168 | deobfClassName = obf.getClassName(); | 166 | deobfClassName = obf.getClassName(); |
| 169 | } | 167 | } |
| @@ -174,7 +172,7 @@ public class MappingsRenamer { | |||
| 174 | } | 172 | } |
| 175 | 173 | ||
| 176 | public void removeMethodTreeMapping(MethodEntry obf) { | 174 | public void removeMethodTreeMapping(MethodEntry obf) { |
| 177 | m_index.getRelatedMethodImplementations(obf).forEach(this::removeMethodMapping); | 175 | index.getRelatedMethodImplementations(obf).forEach(this::removeMethodMapping); |
| 178 | } | 176 | } |
| 179 | 177 | ||
| 180 | public void removeMethodMapping(MethodEntry obf) { | 178 | public void removeMethodMapping(MethodEntry obf) { |
| @@ -183,7 +181,7 @@ public class MappingsRenamer { | |||
| 183 | } | 181 | } |
| 184 | 182 | ||
| 185 | public void markMethodTreeAsDeobfuscated(MethodEntry obf) { | 183 | public void markMethodTreeAsDeobfuscated(MethodEntry obf) { |
| 186 | m_index.getRelatedMethodImplementations(obf).forEach(this::markMethodAsDeobfuscated); | 184 | index.getRelatedMethodImplementations(obf).forEach(this::markMethodAsDeobfuscated); |
| 187 | } | 185 | } |
| 188 | 186 | ||
| 189 | public void markMethodAsDeobfuscated(MethodEntry obf) { | 187 | public void markMethodAsDeobfuscated(MethodEntry obf) { |
| @@ -199,9 +197,9 @@ public class MappingsRenamer { | |||
| 199 | 197 | ||
| 200 | MethodEntry obfMethod = (MethodEntry) obf.getBehaviorEntry(); | 198 | MethodEntry obfMethod = (MethodEntry) obf.getBehaviorEntry(); |
| 201 | 199 | ||
| 202 | Set<MethodEntry> implementations = m_index.getRelatedMethodImplementations(obfMethod); | 200 | Set<MethodEntry> implementations = index.getRelatedMethodImplementations(obfMethod); |
| 203 | for (MethodEntry entry : implementations) { | 201 | for (MethodEntry entry : implementations) { |
| 204 | ClassMapping classMapping = m_mappings.getClassByObf(entry.getClassEntry()); | 202 | ClassMapping classMapping = mappings.getClassByObf(entry.getClassEntry()); |
| 205 | if (classMapping != null) { | 203 | if (classMapping != null) { |
| 206 | MethodMapping mapping = classMapping.getMethodByObf(entry.getName(), entry.getSignature()); | 204 | MethodMapping mapping = classMapping.getMethodByObf(entry.getName(), entry.getSignature()); |
| 207 | // NOTE: don't need to check arguments for name collisions with names determined by Procyon | 205 | // NOTE: don't need to check arguments for name collisions with names determined by Procyon |
| @@ -297,7 +295,7 @@ public class MappingsRenamer { | |||
| 297 | 295 | ||
| 298 | private List<ClassMapping> getOrCreateClassMappingChain(ClassEntry obfClassEntry) { | 296 | private List<ClassMapping> getOrCreateClassMappingChain(ClassEntry obfClassEntry) { |
| 299 | List<ClassEntry> classChain = obfClassEntry.getClassChain(); | 297 | List<ClassEntry> classChain = obfClassEntry.getClassChain(); |
| 300 | List<ClassMapping> mappingChain = m_mappings.getClassMappingChain(obfClassEntry); | 298 | List<ClassMapping> mappingChain = mappings.getClassMappingChain(obfClassEntry); |
| 301 | for (int i = 0; i < classChain.size(); i++) { | 299 | for (int i = 0; i < classChain.size(); i++) { |
| 302 | ClassEntry classEntry = classChain.get(i); | 300 | ClassEntry classEntry = classChain.get(i); |
| 303 | ClassMapping classMapping = mappingChain.get(i); | 301 | ClassMapping classMapping = mappingChain.get(i); |
| @@ -310,7 +308,7 @@ public class MappingsRenamer { | |||
| 310 | // add it to the right parent | 308 | // add it to the right parent |
| 311 | try { | 309 | try { |
| 312 | if (i == 0) { | 310 | if (i == 0) { |
| 313 | m_mappings.addClassMapping(classMapping); | 311 | mappings.addClassMapping(classMapping); |
| 314 | } else { | 312 | } else { |
| 315 | mappingChain.get(i - 1).addInnerClassMapping(classMapping); | 313 | mappingChain.get(i - 1).addInnerClassMapping(classMapping); |
| 316 | } | 314 | } |