diff options
| author | 2018-05-19 17:02:46 +0200 | |
|---|---|---|
| committer | 2018-05-19 17:02:46 +0200 | |
| commit | 2b2249e873c4adfd2dd6e8f1f2489ccd9f6aa021 (patch) | |
| tree | 14c8b1e806449ace1641a1dbafae162855f79670 /src/main/java/cuchaz/enigma/mapping/Mappings.java | |
| parent | Fix build (diff) | |
| download | enigma-fork-2b2249e873c4adfd2dd6e8f1f2489ccd9f6aa021.tar.gz enigma-fork-2b2249e873c4adfd2dd6e8f1f2489ccd9f6aa021.tar.xz enigma-fork-2b2249e873c4adfd2dd6e8f1f2489ccd9f6aa021.zip | |
Initial port to ASM
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/Mappings.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/Mappings.java | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index cf78ca3..cc1ec9c 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -15,6 +15,7 @@ import com.google.common.collect.Lists; | |||
| 15 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 16 | import com.google.common.collect.Sets; | 16 | import com.google.common.collect.Sets; |
| 17 | import cuchaz.enigma.analysis.TranslationIndex; | 17 | import cuchaz.enigma.analysis.TranslationIndex; |
| 18 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 18 | import cuchaz.enigma.throwables.MappingConflict; | 19 | import cuchaz.enigma.throwables.MappingConflict; |
| 19 | 20 | ||
| 20 | import java.io.File; | 21 | import java.io.File; |
| @@ -96,11 +97,11 @@ public class Mappings { | |||
| 96 | 97 | ||
| 97 | public Translator getTranslator(TranslationDirection direction, TranslationIndex index) { | 98 | public Translator getTranslator(TranslationDirection direction, TranslationIndex index) { |
| 98 | switch (direction) { | 99 | switch (direction) { |
| 99 | case Deobfuscating: | 100 | case DEOBFUSCATING: |
| 100 | 101 | ||
| 101 | return new Translator(direction, this.classesByObf, index); | 102 | return new DirectionalTranslator(direction, this.classesByObf, index); |
| 102 | 103 | ||
| 103 | case Obfuscating: | 104 | case OBFUSCATING: |
| 104 | 105 | ||
| 105 | // fill in the missing deobf class entries with obf entries | 106 | // fill in the missing deobf class entries with obf entries |
| 106 | Map<String, ClassMapping> classes = Maps.newHashMap(); | 107 | Map<String, ClassMapping> classes = Maps.newHashMap(); |
| @@ -114,9 +115,9 @@ public class Mappings { | |||
| 114 | 115 | ||
| 115 | // translate the translation index | 116 | // translate the translation index |
| 116 | // NOTE: this isn't actually recursive | 117 | // NOTE: this isn't actually recursive |
| 117 | TranslationIndex deobfIndex = new TranslationIndex(index, getTranslator(TranslationDirection.Deobfuscating, index)); | 118 | TranslationIndex deobfIndex = new TranslationIndex(index, getTranslator(TranslationDirection.DEOBFUSCATING, index)); |
| 118 | 119 | ||
| 119 | return new Translator(direction, classes, deobfIndex); | 120 | return new DirectionalTranslator(direction, classes, deobfIndex); |
| 120 | 121 | ||
| 121 | default: | 122 | default: |
| 122 | throw new Error("Invalid translation direction!"); | 123 | throw new Error("Invalid translation direction!"); |
| @@ -151,9 +152,9 @@ public class Mappings { | |||
| 151 | 152 | ||
| 152 | // add classes from method signatures | 153 | // add classes from method signatures |
| 153 | for (MethodMapping methodMapping : classMapping.methods()) { | 154 | for (MethodMapping methodMapping : classMapping.methods()) { |
| 154 | for (Type type : methodMapping.getObfSignature().types()) { | 155 | for (TypeDescriptor desc : methodMapping.getObfDesc().types()) { |
| 155 | if (type.hasClass()) { | 156 | if (desc.containsType()) { |
| 156 | classNames.add(type.getClassEntry().getClassName()); | 157 | classNames.add(desc.getOwnerEntry().getClassName()); |
| 157 | } | 158 | } |
| 158 | } | 159 | } |
| 159 | } | 160 | } |
| @@ -165,9 +166,9 @@ public class Mappings { | |||
| 165 | return this.classesByDeobf.containsKey(deobfName); | 166 | return this.classesByDeobf.containsKey(deobfName); |
| 166 | } | 167 | } |
| 167 | 168 | ||
| 168 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, Type obfType) { | 169 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, TypeDescriptor obfDesc) { |
| 169 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); | 170 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); |
| 170 | return classMapping != null && classMapping.containsDeobfField(deobfName, obfType); | 171 | return classMapping != null && classMapping.containsDeobfField(deobfName, obfDesc); |
| 171 | } | 172 | } |
| 172 | 173 | ||
| 173 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName) { | 174 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName) { |
| @@ -180,14 +181,14 @@ public class Mappings { | |||
| 180 | return false; | 181 | return false; |
| 181 | } | 182 | } |
| 182 | 183 | ||
| 183 | public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, Signature obfSignature) { | 184 | public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, MethodDescriptor obfDescriptor) { |
| 184 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); | 185 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); |
| 185 | return classMapping != null && classMapping.containsDeobfMethod(deobfName, obfSignature); | 186 | return classMapping != null && classMapping.containsDeobfMethod(deobfName, obfDescriptor); |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { | 189 | public boolean containsArgument(MethodEntry obfMethodEntry, String name) { |
| 189 | ClassMapping classMapping = this.classesByObf.get(obfBehaviorEntry.getClassName()); | 190 | ClassMapping classMapping = this.classesByObf.get(obfMethodEntry.getClassName()); |
| 190 | return classMapping != null && classMapping.containsArgument(obfBehaviorEntry, name); | 191 | return classMapping != null && classMapping.containsArgument(obfMethodEntry, name); |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | public List<ClassMapping> getClassMappingChain(ClassEntry obfClass) { | 194 | public List<ClassMapping> getClassMappingChain(ClassEntry obfClass) { |
| @@ -239,5 +240,19 @@ public class Mappings { | |||
| 239 | public String getFormattedName() { | 240 | public String getFormattedName() { |
| 240 | return " ACC:" + super.toString(); | 241 | return " ACC:" + super.toString(); |
| 241 | } | 242 | } |
| 243 | |||
| 244 | public AccessFlags transform(AccessFlags access) { | ||
| 245 | switch (this) { | ||
| 246 | case PUBLIC: | ||
| 247 | return access.setPublic(); | ||
| 248 | case PROTECTED: | ||
| 249 | return access.setProtected(); | ||
| 250 | case PRIVATE: | ||
| 251 | return access.setPrivate(); | ||
| 252 | case UNCHANGED: | ||
| 253 | default: | ||
| 254 | return access; | ||
| 255 | } | ||
| 256 | } | ||
| 242 | } | 257 | } |
| 243 | } | 258 | } |