summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/Mappings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/Mappings.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/Mappings.java58
1 files changed, 41 insertions, 17 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java
index cf78ca3..3ef1be5 100644
--- a/src/main/java/cuchaz/enigma/mapping/Mappings.java
+++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java
@@ -15,11 +15,15 @@ import com.google.common.collect.Lists;
15import com.google.common.collect.Maps; 15import com.google.common.collect.Maps;
16import com.google.common.collect.Sets; 16import com.google.common.collect.Sets;
17import cuchaz.enigma.analysis.TranslationIndex; 17import cuchaz.enigma.analysis.TranslationIndex;
18import cuchaz.enigma.bytecode.AccessFlags;
19import cuchaz.enigma.mapping.entry.ClassEntry;
20import cuchaz.enigma.mapping.entry.MethodEntry;
18import cuchaz.enigma.throwables.MappingConflict; 21import cuchaz.enigma.throwables.MappingConflict;
19 22
20import java.io.File; 23import java.io.File;
21import java.io.IOException; 24import java.io.IOException;
22import java.util.*; 25import java.util.*;
26import java.util.stream.Collectors;
23 27
24public class Mappings { 28public class Mappings {
25 29
@@ -96,11 +100,11 @@ public class Mappings {
96 100
97 public Translator getTranslator(TranslationDirection direction, TranslationIndex index) { 101 public Translator getTranslator(TranslationDirection direction, TranslationIndex index) {
98 switch (direction) { 102 switch (direction) {
99 case Deobfuscating: 103 case DEOBFUSCATING:
100 104
101 return new Translator(direction, this.classesByObf, index); 105 return new DirectionalTranslator(direction, this.classesByObf, index);
102 106
103 case Obfuscating: 107 case OBFUSCATING:
104 108
105 // fill in the missing deobf class entries with obf entries 109 // fill in the missing deobf class entries with obf entries
106 Map<String, ClassMapping> classes = Maps.newHashMap(); 110 Map<String, ClassMapping> classes = Maps.newHashMap();
@@ -114,9 +118,9 @@ public class Mappings {
114 118
115 // translate the translation index 119 // translate the translation index
116 // NOTE: this isn't actually recursive 120 // NOTE: this isn't actually recursive
117 TranslationIndex deobfIndex = new TranslationIndex(index, getTranslator(TranslationDirection.Deobfuscating, index)); 121 TranslationIndex deobfIndex = new TranslationIndex(index, getTranslator(TranslationDirection.DEOBFUSCATING, index));
118 122
119 return new Translator(direction, classes, deobfIndex); 123 return new DirectionalTranslator(direction, classes, deobfIndex);
120 124
121 default: 125 default:
122 throw new Error("Invalid translation direction!"); 126 throw new Error("Invalid translation direction!");
@@ -151,9 +155,9 @@ public class Mappings {
151 155
152 // add classes from method signatures 156 // add classes from method signatures
153 for (MethodMapping methodMapping : classMapping.methods()) { 157 for (MethodMapping methodMapping : classMapping.methods()) {
154 for (Type type : methodMapping.getObfSignature().types()) { 158 for (TypeDescriptor desc : methodMapping.getObfDesc().types()) {
155 if (type.hasClass()) { 159 if (desc.containsType()) {
156 classNames.add(type.getClassEntry().getClassName()); 160 classNames.add(desc.getTypeEntry().getClassName());
157 } 161 }
158 } 162 }
159 } 163 }
@@ -165,9 +169,9 @@ public class Mappings {
165 return this.classesByDeobf.containsKey(deobfName); 169 return this.classesByDeobf.containsKey(deobfName);
166 } 170 }
167 171
168 public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, Type obfType) { 172 public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, TypeDescriptor obfDesc) {
169 ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); 173 ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName());
170 return classMapping != null && classMapping.containsDeobfField(deobfName, obfType); 174 return classMapping != null && classMapping.containsDeobfField(deobfName, obfDesc);
171 } 175 }
172 176
173 public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName) { 177 public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName) {
@@ -180,14 +184,14 @@ public class Mappings {
180 return false; 184 return false;
181 } 185 }
182 186
183 public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, Signature obfSignature) { 187 public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, MethodDescriptor obfDescriptor) {
184 ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); 188 ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName());
185 return classMapping != null && classMapping.containsDeobfMethod(deobfName, obfSignature); 189 return classMapping != null && classMapping.containsDeobfMethod(deobfName, obfDescriptor);
186 } 190 }
187 191
188 public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { 192 public boolean containsArgument(MethodEntry obfMethodEntry, String name) {
189 ClassMapping classMapping = this.classesByObf.get(obfBehaviorEntry.getClassName()); 193 ClassMapping classMapping = this.classesByObf.get(obfMethodEntry.getClassName());
190 return classMapping != null && classMapping.containsArgument(obfBehaviorEntry, name); 194 return classMapping != null && classMapping.containsArgument(obfMethodEntry, name);
191 } 195 }
192 196
193 public List<ClassMapping> getClassMappingChain(ClassEntry obfClass) { 197 public List<ClassMapping> getClassMappingChain(ClassEntry obfClass) {
@@ -210,8 +214,14 @@ public class Mappings {
210 214
211 public void savePreviousState() { 215 public void savePreviousState() {
212 this.previousState = new Mappings(this.originMapping); 216 this.previousState = new Mappings(this.originMapping);
213 this.previousState.classesByDeobf = Maps.newHashMap(this.classesByDeobf); 217 this.previousState.classesByDeobf = new HashMap<>();
214 this.previousState.classesByObf = Maps.newHashMap(this.classesByObf); 218 for (Map.Entry<String, ClassMapping> entry : this.classesByDeobf.entrySet()) {
219 this.previousState.classesByDeobf.put(entry.getKey(), entry.getValue().copy());
220 }
221 this.previousState.classesByObf = new HashMap<>();
222 for (Map.Entry<String, ClassMapping> entry : this.classesByObf.entrySet()) {
223 this.previousState.classesByObf.put(entry.getKey(), entry.getValue().copy());
224 }
215 classesByDeobf.values().forEach(ClassMapping::resetDirty); 225 classesByDeobf.values().forEach(ClassMapping::resetDirty);
216 classesByObf.values().forEach(ClassMapping::resetDirty); 226 classesByObf.values().forEach(ClassMapping::resetDirty);
217 } 227 }
@@ -239,5 +249,19 @@ public class Mappings {
239 public String getFormattedName() { 249 public String getFormattedName() {
240 return " ACC:" + super.toString(); 250 return " ACC:" + super.toString();
241 } 251 }
252
253 public AccessFlags transform(AccessFlags access) {
254 switch (this) {
255 case PUBLIC:
256 return access.setPublic();
257 case PROTECTED:
258 return access.setProtected();
259 case PRIVATE:
260 return access.setPrivate();
261 case UNCHANGED:
262 default:
263 return access;
264 }
265 }
242 } 266 }
243} 267}