diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping')
6 files changed, 163 insertions, 173 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 8f89388..a261c91 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -20,19 +20,19 @@ import cuchaz.enigma.throwables.MappingConflict; | |||
| 20 | // FIXME: Enigma doesn't support inner classes of inner class????! | 20 | // FIXME: Enigma doesn't support inner classes of inner class????! |
| 21 | public class ClassMapping implements Comparable<ClassMapping> { | 21 | public class ClassMapping implements Comparable<ClassMapping> { |
| 22 | 22 | ||
| 23 | private String m_obfFullName; | 23 | private String obfFullName; |
| 24 | private String m_obfSimpleName; | 24 | private String obfSimpleName; |
| 25 | private String m_deobfName; | 25 | private String deobfName; |
| 26 | private String m_previousDeobfName; | 26 | private String previousDeobfName; |
| 27 | private Map<String, ClassMapping> m_innerClassesByObfSimple; | 27 | private Map<String, ClassMapping> innerClassesByObfSimple; |
| 28 | private Map<String, ClassMapping> m_innerClassesByObfFull; | 28 | private Map<String, ClassMapping> innerClassesByObfFull; |
| 29 | private Map<String, ClassMapping> m_innerClassesByDeobf; | 29 | private Map<String, ClassMapping> innerClassesByDeobf; |
| 30 | private Map<String, FieldMapping> m_fieldsByObf; | 30 | private Map<String, FieldMapping> fieldsByObf; |
| 31 | private Map<String, FieldMapping> m_fieldsByDeobf; | 31 | private Map<String, FieldMapping> fieldsByDeobf; |
| 32 | private Map<String, MethodMapping> m_methodsByObf; | 32 | private Map<String, MethodMapping> methodsByObf; |
| 33 | private Map<String, MethodMapping> m_methodsByDeobf; | 33 | private Map<String, MethodMapping> methodsByDeobf; |
| 34 | private boolean isDirty; | 34 | private boolean isDirty; |
| 35 | private Mappings.EntryModifier modifier; | 35 | private Mappings.EntryModifier modifier; |
| 36 | 36 | ||
| 37 | public ClassMapping(String obfFullName) | 37 | public ClassMapping(String obfFullName) |
| 38 | { | 38 | { |
| @@ -46,85 +46,85 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 46 | 46 | ||
| 47 | public ClassMapping(String obfFullName, String deobfName, Mappings.EntryModifier modifier) | 47 | public ClassMapping(String obfFullName, String deobfName, Mappings.EntryModifier modifier) |
| 48 | { | 48 | { |
| 49 | m_obfFullName = obfFullName; | 49 | this.obfFullName = obfFullName; |
| 50 | ClassEntry classEntry = new ClassEntry(obfFullName); | 50 | ClassEntry classEntry = new ClassEntry(obfFullName); |
| 51 | m_obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); | 51 | obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); |
| 52 | m_previousDeobfName = null; | 52 | previousDeobfName = null; |
| 53 | m_deobfName = NameValidator.validateClassName(deobfName, false); | 53 | this.deobfName = NameValidator.validateClassName(deobfName, false); |
| 54 | m_innerClassesByObfSimple = Maps.newHashMap(); | 54 | innerClassesByObfSimple = Maps.newHashMap(); |
| 55 | m_innerClassesByObfFull = Maps.newHashMap(); | 55 | innerClassesByObfFull = Maps.newHashMap(); |
| 56 | m_innerClassesByDeobf = Maps.newHashMap(); | 56 | innerClassesByDeobf = Maps.newHashMap(); |
| 57 | m_fieldsByObf = Maps.newHashMap(); | 57 | fieldsByObf = Maps.newHashMap(); |
| 58 | m_fieldsByDeobf = Maps.newHashMap(); | 58 | fieldsByDeobf = Maps.newHashMap(); |
| 59 | m_methodsByObf = Maps.newHashMap(); | 59 | methodsByObf = Maps.newHashMap(); |
| 60 | m_methodsByDeobf = Maps.newHashMap(); | 60 | methodsByDeobf = Maps.newHashMap(); |
| 61 | isDirty = true; | 61 | isDirty = true; |
| 62 | this.modifier = modifier; | 62 | this.modifier = modifier; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | public String getObfFullName() { | 65 | public String getObfFullName() { |
| 66 | return m_obfFullName; | 66 | return obfFullName; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | public String getObfSimpleName() { | 69 | public String getObfSimpleName() { |
| 70 | return m_obfSimpleName; | 70 | return obfSimpleName; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | public String getPreviousDeobfName() { | 73 | public String getPreviousDeobfName() { |
| 74 | return m_previousDeobfName; | 74 | return previousDeobfName; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | public String getDeobfName() { | 77 | public String getDeobfName() { |
| 78 | return m_deobfName; | 78 | return deobfName; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public void setDeobfName(String val) { | 81 | public void setDeobfName(String val) { |
| 82 | m_previousDeobfName = m_deobfName; | 82 | previousDeobfName = deobfName; |
| 83 | m_deobfName = NameValidator.validateClassName(val, false); | 83 | deobfName = NameValidator.validateClassName(val, false); |
| 84 | this.isDirty = true; | 84 | this.isDirty = true; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | //// INNER CLASSES //////// | 87 | //// INNER CLASSES //////// |
| 88 | 88 | ||
| 89 | public Iterable<ClassMapping> innerClasses() { | 89 | public Iterable<ClassMapping> innerClasses() { |
| 90 | assert (m_innerClassesByObfSimple.size() >= m_innerClassesByDeobf.size()); | 90 | assert (innerClassesByObfSimple.size() >= innerClassesByDeobf.size()); |
| 91 | return m_innerClassesByObfSimple.values(); | 91 | return innerClassesByObfSimple.values(); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | public void addInnerClassMapping(ClassMapping classMapping) throws MappingConflict { | 94 | public void addInnerClassMapping(ClassMapping classMapping) throws MappingConflict { |
| 95 | // FIXME: dirty hack, that can get into issues, but it's a temp fix! | 95 | // FIXME: dirty hack, that can get into issues, but it's a temp fix! |
| 96 | if (this.m_innerClassesByObfFull.containsKey(classMapping.getObfSimpleName())) { | 96 | if (this.innerClassesByObfFull.containsKey(classMapping.getObfSimpleName())) { |
| 97 | throw new MappingConflict("classes", classMapping.getObfSimpleName(), this.m_innerClassesByObfSimple.get(classMapping.getObfSimpleName()).getObfSimpleName()); | 97 | throw new MappingConflict("classes", classMapping.getObfSimpleName(), this.innerClassesByObfSimple.get(classMapping.getObfSimpleName()).getObfSimpleName()); |
| 98 | } | 98 | } |
| 99 | m_innerClassesByObfFull.put(classMapping.getObfFullName(), classMapping); | 99 | innerClassesByObfFull.put(classMapping.getObfFullName(), classMapping); |
| 100 | m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping); | 100 | innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping); |
| 101 | 101 | ||
| 102 | if (classMapping.getDeobfName() != null) { | 102 | if (classMapping.getDeobfName() != null) { |
| 103 | if (this.m_innerClassesByDeobf.containsKey(classMapping.getDeobfName())) { | 103 | if (this.innerClassesByDeobf.containsKey(classMapping.getDeobfName())) { |
| 104 | throw new MappingConflict("classes", classMapping.getDeobfName(), this.m_innerClassesByDeobf.get(classMapping.getDeobfName()).getDeobfName()); | 104 | throw new MappingConflict("classes", classMapping.getDeobfName(), this.innerClassesByDeobf.get(classMapping.getDeobfName()).getDeobfName()); |
| 105 | } | 105 | } |
| 106 | m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping); | 106 | innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping); |
| 107 | } | 107 | } |
| 108 | this.isDirty = true; | 108 | this.isDirty = true; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | public void removeInnerClassMapping(ClassMapping classMapping) { | 111 | public void removeInnerClassMapping(ClassMapping classMapping) { |
| 112 | m_innerClassesByObfFull.remove(classMapping.getObfFullName()); | 112 | innerClassesByObfFull.remove(classMapping.getObfFullName()); |
| 113 | boolean obfWasRemoved = m_innerClassesByObfSimple.remove(classMapping.getObfSimpleName()) != null; | 113 | boolean obfWasRemoved = innerClassesByObfSimple.remove(classMapping.getObfSimpleName()) != null; |
| 114 | assert (obfWasRemoved); | 114 | assert (obfWasRemoved); |
| 115 | if (classMapping.getDeobfName() != null) { | 115 | if (classMapping.getDeobfName() != null) { |
| 116 | boolean deobfWasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; | 116 | boolean deobfWasRemoved = innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 117 | assert (deobfWasRemoved); | 117 | assert (deobfWasRemoved); |
| 118 | } | 118 | } |
| 119 | this.isDirty = true; | 119 | this.isDirty = true; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | public ClassMapping getOrCreateInnerClass(ClassEntry obfInnerClass) { | 122 | public ClassMapping getOrCreateInnerClass(ClassEntry obfInnerClass) { |
| 123 | ClassMapping classMapping = m_innerClassesByObfSimple.get(obfInnerClass.getInnermostClassName()); | 123 | ClassMapping classMapping = innerClassesByObfSimple.get(obfInnerClass.getInnermostClassName()); |
| 124 | if (classMapping == null) { | 124 | if (classMapping == null) { |
| 125 | classMapping = new ClassMapping(obfInnerClass.getName()); | 125 | classMapping = new ClassMapping(obfInnerClass.getName()); |
| 126 | m_innerClassesByObfFull.put(classMapping.getObfFullName(), classMapping); | 126 | innerClassesByObfFull.put(classMapping.getObfFullName(), classMapping); |
| 127 | boolean wasAdded = m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping) == null; | 127 | boolean wasAdded = innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping) == null; |
| 128 | assert (wasAdded); | 128 | assert (wasAdded); |
| 129 | this.isDirty = true; | 129 | this.isDirty = true; |
| 130 | } | 130 | } |
| @@ -133,12 +133,12 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 133 | 133 | ||
| 134 | public ClassMapping getInnerClassByObfSimple(String obfSimpleName) { | 134 | public ClassMapping getInnerClassByObfSimple(String obfSimpleName) { |
| 135 | assert (isSimpleClassName(obfSimpleName)); | 135 | assert (isSimpleClassName(obfSimpleName)); |
| 136 | return m_innerClassesByObfSimple.get(obfSimpleName); | 136 | return innerClassesByObfSimple.get(obfSimpleName); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | public ClassMapping getInnerClassByDeobf(String deobfName) { | 139 | public ClassMapping getInnerClassByDeobf(String deobfName) { |
| 140 | assert (isSimpleClassName(deobfName)); | 140 | assert (isSimpleClassName(deobfName)); |
| 141 | return m_innerClassesByDeobf.get(deobfName); | 141 | return innerClassesByDeobf.get(deobfName); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | public ClassMapping getInnerClassByDeobfThenObfSimple(String name) { | 144 | public ClassMapping getInnerClassByDeobfThenObfSimple(String name) { |
| @@ -151,7 +151,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 151 | 151 | ||
| 152 | public String getDeobfInnerClassName(String obfSimpleName) { | 152 | public String getDeobfInnerClassName(String obfSimpleName) { |
| 153 | assert (isSimpleClassName(obfSimpleName)); | 153 | assert (isSimpleClassName(obfSimpleName)); |
| 154 | ClassMapping classMapping = m_innerClassesByObfSimple.get(obfSimpleName); | 154 | ClassMapping classMapping = innerClassesByObfSimple.get(obfSimpleName); |
| 155 | if (classMapping != null) { | 155 | if (classMapping != null) { |
| 156 | return classMapping.getDeobfName(); | 156 | return classMapping.getDeobfName(); |
| 157 | } | 157 | } |
| @@ -161,80 +161,80 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 161 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { | 161 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { |
| 162 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); | 162 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); |
| 163 | if (classMapping.getDeobfName() != null) { | 163 | if (classMapping.getDeobfName() != null) { |
| 164 | boolean wasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; | 164 | boolean wasRemoved = innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 165 | assert (wasRemoved); | 165 | assert (wasRemoved); |
| 166 | } | 166 | } |
| 167 | classMapping.setDeobfName(deobfName); | 167 | classMapping.setDeobfName(deobfName); |
| 168 | if (deobfName != null) { | 168 | if (deobfName != null) { |
| 169 | assert (isSimpleClassName(deobfName)); | 169 | assert (isSimpleClassName(deobfName)); |
| 170 | boolean wasAdded = m_innerClassesByDeobf.put(deobfName, classMapping) == null; | 170 | boolean wasAdded = innerClassesByDeobf.put(deobfName, classMapping) == null; |
| 171 | assert (wasAdded); | 171 | assert (wasAdded); |
| 172 | } | 172 | } |
| 173 | this.isDirty = true; | 173 | this.isDirty = true; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | public boolean hasInnerClassByObfSimple(String obfSimpleName) { | 176 | public boolean hasInnerClassByObfSimple(String obfSimpleName) { |
| 177 | return m_innerClassesByObfSimple.containsKey(obfSimpleName); | 177 | return innerClassesByObfSimple.containsKey(obfSimpleName); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | public boolean hasInnerClassByDeobf(String deobfName) { | 180 | public boolean hasInnerClassByDeobf(String deobfName) { |
| 181 | return m_innerClassesByDeobf.containsKey(deobfName); | 181 | return innerClassesByDeobf.containsKey(deobfName); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | 184 | ||
| 185 | //// FIELDS //////// | 185 | //// FIELDS //////// |
| 186 | 186 | ||
| 187 | public Iterable<FieldMapping> fields() { | 187 | public Iterable<FieldMapping> fields() { |
| 188 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); | 188 | assert (fieldsByObf.size() == fieldsByDeobf.size()); |
| 189 | return m_fieldsByObf.values(); | 189 | return fieldsByObf.values(); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | public boolean containsObfField(String obfName, Type obfType) { | 192 | public boolean containsObfField(String obfName, Type obfType) { |
| 193 | return m_fieldsByObf.containsKey(getFieldKey(obfName, obfType)); | 193 | return fieldsByObf.containsKey(getFieldKey(obfName, obfType)); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | public boolean containsDeobfField(String deobfName, Type deobfType) { | 196 | public boolean containsDeobfField(String deobfName, Type deobfType) { |
| 197 | return m_fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); | 197 | return fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | public void addFieldMapping(FieldMapping fieldMapping) { | 200 | public void addFieldMapping(FieldMapping fieldMapping) { |
| 201 | String obfKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | 201 | String obfKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); |
| 202 | if (m_fieldsByObf.containsKey(obfKey)) { | 202 | if (fieldsByObf.containsKey(obfKey)) { |
| 203 | throw new Error("Already have mapping for " + m_obfFullName + "." + obfKey); | 203 | throw new Error("Already have mapping for " + obfFullName + "." + obfKey); |
| 204 | } | 204 | } |
| 205 | if (fieldMapping.getDeobfName() != null) { | 205 | if (fieldMapping.getDeobfName() != null) { |
| 206 | String deobfKey = getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType()); | 206 | String deobfKey = getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType()); |
| 207 | if (m_fieldsByDeobf.containsKey(deobfKey)) { | 207 | if (fieldsByDeobf.containsKey(deobfKey)) { |
| 208 | throw new Error("Already have mapping for " + m_deobfName + "." + deobfKey); | 208 | throw new Error("Already have mapping for " + deobfName + "." + deobfKey); |
| 209 | } | 209 | } |
| 210 | boolean deobfWasAdded = m_fieldsByDeobf.put(deobfKey, fieldMapping) == null; | 210 | boolean deobfWasAdded = fieldsByDeobf.put(deobfKey, fieldMapping) == null; |
| 211 | assert (deobfWasAdded); | 211 | assert (deobfWasAdded); |
| 212 | } | 212 | } |
| 213 | boolean obfWasAdded = m_fieldsByObf.put(obfKey, fieldMapping) == null; | 213 | boolean obfWasAdded = fieldsByObf.put(obfKey, fieldMapping) == null; |
| 214 | assert (obfWasAdded); | 214 | assert (obfWasAdded); |
| 215 | this.isDirty = true; | 215 | this.isDirty = true; |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | public void removeFieldMapping(FieldMapping fieldMapping) { | 218 | public void removeFieldMapping(FieldMapping fieldMapping) { |
| 219 | boolean obfWasRemoved = m_fieldsByObf.remove(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType())) != null; | 219 | boolean obfWasRemoved = fieldsByObf.remove(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType())) != null; |
| 220 | assert (obfWasRemoved); | 220 | assert (obfWasRemoved); |
| 221 | if (fieldMapping.getDeobfName() != null) { | 221 | if (fieldMapping.getDeobfName() != null) { |
| 222 | boolean deobfWasRemoved = m_fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType())) != null; | 222 | boolean deobfWasRemoved = fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType())) != null; |
| 223 | assert (deobfWasRemoved); | 223 | assert (deobfWasRemoved); |
| 224 | } | 224 | } |
| 225 | this.isDirty = true; | 225 | this.isDirty = true; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | public FieldMapping getFieldByObf(String obfName, Type obfType) { | 228 | public FieldMapping getFieldByObf(String obfName, Type obfType) { |
| 229 | return m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 229 | return fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | public FieldMapping getFieldByDeobf(String deobfName, Type obfType) { | 232 | public FieldMapping getFieldByDeobf(String deobfName, Type obfType) { |
| 233 | return m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | 233 | return fieldsByDeobf.get(getFieldKey(deobfName, obfType)); |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | public String getObfFieldName(String deobfName, Type obfType) { | 236 | public String getObfFieldName(String deobfName, Type obfType) { |
| 237 | FieldMapping fieldMapping = m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | 237 | FieldMapping fieldMapping = fieldsByDeobf.get(getFieldKey(deobfName, obfType)); |
| 238 | if (fieldMapping != null) { | 238 | if (fieldMapping != null) { |
| 239 | return fieldMapping.getObfName(); | 239 | return fieldMapping.getObfName(); |
| 240 | } | 240 | } |
| @@ -242,7 +242,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | public String getDeobfFieldName(String obfName, Type obfType) { | 244 | public String getDeobfFieldName(String obfName, Type obfType) { |
| 245 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 245 | FieldMapping fieldMapping = fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 246 | if (fieldMapping != null) { | 246 | if (fieldMapping != null) { |
| 247 | return fieldMapping.getDeobfName(); | 247 | return fieldMapping.getDeobfName(); |
| 248 | } | 248 | } |
| @@ -261,18 +261,18 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 261 | 261 | ||
| 262 | public void setFieldName(String obfName, Type obfType, String deobfName) { | 262 | public void setFieldName(String obfName, Type obfType, String deobfName) { |
| 263 | assert (deobfName != null); | 263 | assert (deobfName != null); |
| 264 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 264 | FieldMapping fieldMapping = fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 265 | if (fieldMapping == null) { | 265 | if (fieldMapping == null) { |
| 266 | fieldMapping = new FieldMapping(obfName, obfType, deobfName, Mappings.EntryModifier.UNCHANGED); | 266 | fieldMapping = new FieldMapping(obfName, obfType, deobfName, Mappings.EntryModifier.UNCHANGED); |
| 267 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping) == null; | 267 | boolean obfWasAdded = fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping) == null; |
| 268 | assert (obfWasAdded); | 268 | assert (obfWasAdded); |
| 269 | } else { | 269 | } else { |
| 270 | boolean wasRemoved = m_fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), obfType)) != null; | 270 | boolean wasRemoved = fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), obfType)) != null; |
| 271 | assert (wasRemoved); | 271 | assert (wasRemoved); |
| 272 | } | 272 | } |
| 273 | fieldMapping.setDeobfName(deobfName); | 273 | fieldMapping.setDeobfName(deobfName); |
| 274 | if (deobfName != null) { | 274 | if (deobfName != null) { |
| 275 | boolean wasAdded = m_fieldsByDeobf.put(getFieldKey(deobfName, obfType), fieldMapping) == null; | 275 | boolean wasAdded = fieldsByDeobf.put(getFieldKey(deobfName, obfType), fieldMapping) == null; |
| 276 | assert (wasAdded); | 276 | assert (wasAdded); |
| 277 | } | 277 | } |
| 278 | this.isDirty = true; | 278 | this.isDirty = true; |
| @@ -280,11 +280,11 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 280 | 280 | ||
| 281 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { | 281 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { |
| 282 | assert(newObfName != null); | 282 | assert(newObfName != null); |
| 283 | FieldMapping fieldMapping = m_fieldsByObf.remove(getFieldKey(oldObfName, obfType)); | 283 | FieldMapping fieldMapping = fieldsByObf.remove(getFieldKey(oldObfName, obfType)); |
| 284 | assert(fieldMapping != null); | 284 | assert(fieldMapping != null); |
| 285 | fieldMapping.setObfName(newObfName); | 285 | fieldMapping.setObfName(newObfName); |
| 286 | fieldMapping.setObfType(newObfType); | 286 | fieldMapping.setObfType(newObfType); |
| 287 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; | 287 | boolean obfWasAdded = fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; |
| 288 | assert(obfWasAdded); | 288 | assert(obfWasAdded); |
| 289 | this.isDirty = true; | 289 | this.isDirty = true; |
| 290 | } | 290 | } |
| @@ -292,53 +292,53 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 292 | //// METHODS //////// | 292 | //// METHODS //////// |
| 293 | 293 | ||
| 294 | public Iterable<MethodMapping> methods() { | 294 | public Iterable<MethodMapping> methods() { |
| 295 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); | 295 | assert (methodsByObf.size() >= methodsByDeobf.size()); |
| 296 | return m_methodsByObf.values(); | 296 | return methodsByObf.values(); |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | public boolean containsObfMethod(String obfName, Signature obfSignature) { | 299 | public boolean containsObfMethod(String obfName, Signature obfSignature) { |
| 300 | return m_methodsByObf.containsKey(getMethodKey(obfName, obfSignature)); | 300 | return methodsByObf.containsKey(getMethodKey(obfName, obfSignature)); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { | 303 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { |
| 304 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); | 304 | return methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | public void addMethodMapping(MethodMapping methodMapping) { | 307 | public void addMethodMapping(MethodMapping methodMapping) { |
| 308 | String obfKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | 308 | String obfKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 309 | if (m_methodsByObf.containsKey(obfKey)) { | 309 | if (methodsByObf.containsKey(obfKey)) { |
| 310 | throw new Error("Already have mapping for " + m_obfFullName + "." + obfKey); | 310 | throw new Error("Already have mapping for " + obfFullName + "." + obfKey); |
| 311 | } | 311 | } |
| 312 | boolean wasAdded = m_methodsByObf.put(obfKey, methodMapping) == null; | 312 | boolean wasAdded = methodsByObf.put(obfKey, methodMapping) == null; |
| 313 | assert (wasAdded); | 313 | assert (wasAdded); |
| 314 | if (methodMapping.getDeobfName() != null) { | 314 | if (methodMapping.getDeobfName() != null) { |
| 315 | String deobfKey = getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature()); | 315 | String deobfKey = getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature()); |
| 316 | if (m_methodsByDeobf.containsKey(deobfKey)) { | 316 | if (methodsByDeobf.containsKey(deobfKey)) { |
| 317 | throw new Error("Already have mapping for " + m_deobfName + "." + deobfKey); | 317 | throw new Error("Already have mapping for " + deobfName + "." + deobfKey); |
| 318 | } | 318 | } |
| 319 | boolean deobfWasAdded = m_methodsByDeobf.put(deobfKey, methodMapping) == null; | 319 | boolean deobfWasAdded = methodsByDeobf.put(deobfKey, methodMapping) == null; |
| 320 | assert (deobfWasAdded); | 320 | assert (deobfWasAdded); |
| 321 | } | 321 | } |
| 322 | this.isDirty = true; | 322 | this.isDirty = true; |
| 323 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); | 323 | assert (methodsByObf.size() >= methodsByDeobf.size()); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | public void removeMethodMapping(MethodMapping methodMapping) { | 326 | public void removeMethodMapping(MethodMapping methodMapping) { |
| 327 | boolean obfWasRemoved = m_methodsByObf.remove(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature())) != null; | 327 | boolean obfWasRemoved = methodsByObf.remove(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature())) != null; |
| 328 | assert (obfWasRemoved); | 328 | assert (obfWasRemoved); |
| 329 | if (methodMapping.getDeobfName() != null) { | 329 | if (methodMapping.getDeobfName() != null) { |
| 330 | boolean deobfWasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; | 330 | boolean deobfWasRemoved = methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; |
| 331 | assert (deobfWasRemoved); | 331 | assert (deobfWasRemoved); |
| 332 | } | 332 | } |
| 333 | this.isDirty = true; | 333 | this.isDirty = true; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | public MethodMapping getMethodByObf(String obfName, Signature obfSignature) { | 336 | public MethodMapping getMethodByObf(String obfName, Signature obfSignature) { |
| 337 | return m_methodsByObf.get(getMethodKey(obfName, obfSignature)); | 337 | return methodsByObf.get(getMethodKey(obfName, obfSignature)); |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | public MethodMapping getMethodByDeobf(String deobfName, Signature obfSignature) { | 340 | public MethodMapping getMethodByDeobf(String deobfName, Signature obfSignature) { |
| 341 | return m_methodsByDeobf.get(getMethodKey(deobfName, obfSignature)); | 341 | return methodsByDeobf.get(getMethodKey(deobfName, obfSignature)); |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | private String getMethodKey(String name, Signature signature) { | 344 | private String getMethodKey(String name, Signature signature) { |
| @@ -352,16 +352,16 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | public void setMethodName(String obfName, Signature obfSignature, String deobfName) { | 354 | public void setMethodName(String obfName, Signature obfSignature, String deobfName) { |
| 355 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfName, obfSignature)); | 355 | MethodMapping methodMapping = methodsByObf.get(getMethodKey(obfName, obfSignature)); |
| 356 | if (methodMapping == null) { | 356 | if (methodMapping == null) { |
| 357 | methodMapping = createMethodMapping(obfName, obfSignature); | 357 | methodMapping = createMethodMapping(obfName, obfSignature); |
| 358 | } else if (methodMapping.getDeobfName() != null) { | 358 | } else if (methodMapping.getDeobfName() != null) { |
| 359 | boolean wasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; | 359 | boolean wasRemoved = methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; |
| 360 | assert (wasRemoved); | 360 | assert (wasRemoved); |
| 361 | } | 361 | } |
| 362 | methodMapping.setDeobfName(deobfName); | 362 | methodMapping.setDeobfName(deobfName); |
| 363 | if (deobfName != null) { | 363 | if (deobfName != null) { |
| 364 | boolean wasAdded = m_methodsByDeobf.put(getMethodKey(deobfName, obfSignature), methodMapping) == null; | 364 | boolean wasAdded = methodsByDeobf.put(getMethodKey(deobfName, obfSignature), methodMapping) == null; |
| 365 | assert (wasAdded); | 365 | assert (wasAdded); |
| 366 | } | 366 | } |
| 367 | this.isDirty = true; | 367 | this.isDirty = true; |
| @@ -369,11 +369,11 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 369 | 369 | ||
| 370 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { | 370 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { |
| 371 | assert(newObfName != null); | 371 | assert(newObfName != null); |
| 372 | MethodMapping methodMapping = m_methodsByObf.remove(getMethodKey(oldObfName, obfSignature)); | 372 | MethodMapping methodMapping = methodsByObf.remove(getMethodKey(oldObfName, obfSignature)); |
| 373 | assert(methodMapping != null); | 373 | assert(methodMapping != null); |
| 374 | methodMapping.setObfName(newObfName); | 374 | methodMapping.setObfName(newObfName); |
| 375 | methodMapping.setObfSignature(newObfSignature); | 375 | methodMapping.setObfSignature(newObfSignature); |
| 376 | boolean obfWasAdded = m_methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; | 376 | boolean obfWasAdded = methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; |
| 377 | assert(obfWasAdded); | 377 | assert(obfWasAdded); |
| 378 | this.isDirty = true; | 378 | this.isDirty = true; |
| 379 | } | 379 | } |
| @@ -382,7 +382,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 382 | 382 | ||
| 383 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { | 383 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { |
| 384 | assert (argumentName != null); | 384 | assert (argumentName != null); |
| 385 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)); | 385 | MethodMapping methodMapping = methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)); |
| 386 | if (methodMapping == null) { | 386 | if (methodMapping == null) { |
| 387 | methodMapping = createMethodMapping(obfMethodName, obfMethodSignature); | 387 | methodMapping = createMethodMapping(obfMethodName, obfMethodSignature); |
| 388 | } | 388 | } |
| @@ -391,13 +391,13 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | public void removeArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex) { | 393 | public void removeArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex) { |
| 394 | m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)).removeArgumentName(argumentIndex); | 394 | methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)).removeArgumentName(argumentIndex); |
| 395 | this.isDirty = true; | 395 | this.isDirty = true; |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | private MethodMapping createMethodMapping(String obfName, Signature obfSignature) { | 398 | private MethodMapping createMethodMapping(String obfName, Signature obfSignature) { |
| 399 | MethodMapping methodMapping = new MethodMapping(obfName, obfSignature); | 399 | MethodMapping methodMapping = new MethodMapping(obfName, obfSignature); |
| 400 | boolean wasAdded = m_methodsByObf.put(getMethodKey(obfName, obfSignature), methodMapping) == null; | 400 | boolean wasAdded = methodsByObf.put(getMethodKey(obfName, obfSignature), methodMapping) == null; |
| 401 | assert (wasAdded); | 401 | assert (wasAdded); |
| 402 | this.isDirty = true; | 402 | this.isDirty = true; |
| 403 | return methodMapping; | 403 | return methodMapping; |
| @@ -406,9 +406,9 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 406 | @Override | 406 | @Override |
| 407 | public String toString() { | 407 | public String toString() { |
| 408 | StringBuilder buf = new StringBuilder(); | 408 | StringBuilder buf = new StringBuilder(); |
| 409 | buf.append(m_obfFullName); | 409 | buf.append(obfFullName); |
| 410 | buf.append(" <-> "); | 410 | buf.append(" <-> "); |
| 411 | buf.append(m_deobfName); | 411 | buf.append(deobfName); |
| 412 | buf.append("\n"); | 412 | buf.append("\n"); |
| 413 | buf.append("Fields:\n"); | 413 | buf.append("Fields:\n"); |
| 414 | for (FieldMapping fieldMapping : fields()) { | 414 | for (FieldMapping fieldMapping : fields()) { |
| @@ -419,12 +419,12 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 419 | buf.append("\n"); | 419 | buf.append("\n"); |
| 420 | } | 420 | } |
| 421 | buf.append("Methods:\n"); | 421 | buf.append("Methods:\n"); |
| 422 | for (MethodMapping methodMapping : m_methodsByObf.values()) { | 422 | for (MethodMapping methodMapping : methodsByObf.values()) { |
| 423 | buf.append(methodMapping.toString()); | 423 | buf.append(methodMapping.toString()); |
| 424 | buf.append("\n"); | 424 | buf.append("\n"); |
| 425 | } | 425 | } |
| 426 | buf.append("Inner Classes:\n"); | 426 | buf.append("Inner Classes:\n"); |
| 427 | for (ClassMapping classMapping : m_innerClassesByObfSimple.values()) { | 427 | for (ClassMapping classMapping : innerClassesByObfSimple.values()) { |
| 428 | buf.append("\t"); | 428 | buf.append("\t"); |
| 429 | buf.append(classMapping.getObfSimpleName()); | 429 | buf.append(classMapping.getObfSimpleName()); |
| 430 | buf.append(" <-> "); | 430 | buf.append(" <-> "); |
| @@ -437,49 +437,51 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 437 | @Override | 437 | @Override |
| 438 | public int compareTo(ClassMapping other) { | 438 | public int compareTo(ClassMapping other) { |
| 439 | // sort by a, b, c, ... aa, ab, etc | 439 | // sort by a, b, c, ... aa, ab, etc |
| 440 | if (m_obfFullName.length() != other.m_obfFullName.length()) { | 440 | if (obfFullName.length() != other.obfFullName.length()) { |
| 441 | return m_obfFullName.length() - other.m_obfFullName.length(); | 441 | return obfFullName.length() - other.obfFullName.length(); |
| 442 | } | 442 | } |
| 443 | return m_obfFullName.compareTo(other.m_obfFullName); | 443 | return obfFullName.compareTo(other.obfFullName); |
| 444 | } | 444 | } |
| 445 | 445 | ||
| 446 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { | 446 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { |
| 447 | 447 | ||
| 448 | // rename inner classes | 448 | // rename inner classes |
| 449 | for (ClassMapping innerClassMapping : new ArrayList<>(m_innerClassesByObfSimple.values())) { | 449 | for (ClassMapping innerClassMapping : new ArrayList<>(innerClassesByObfSimple.values())) { |
| 450 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 450 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 451 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; | 451 | boolean wasRemoved = innerClassesByObfSimple.remove(oldObfClassName) != null; |
| 452 | assert (wasRemoved); | 452 | assert (wasRemoved); |
| 453 | boolean wasAdded = m_innerClassesByObfSimple.put(newObfClassName, innerClassMapping) == null; | 453 | boolean wasAdded = innerClassesByObfSimple.put(newObfClassName, innerClassMapping) == null; |
| 454 | assert (wasAdded); | 454 | assert (wasAdded); |
| 455 | } | 455 | } |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | // rename field types | 458 | // rename field types |
| 459 | for (FieldMapping fieldMapping : new ArrayList<>(m_fieldsByObf.values())) { | 459 | for (FieldMapping fieldMapping : new ArrayList<>(fieldsByObf.values())) { |
| 460 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | 460 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); |
| 461 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 461 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 462 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; | 462 | boolean wasRemoved = fieldsByObf.remove(oldFieldKey) != null; |
| 463 | assert (wasRemoved); | 463 | assert (wasRemoved); |
| 464 | boolean wasAdded = m_fieldsByObf.put(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()), fieldMapping) == null; | 464 | boolean wasAdded = fieldsByObf |
| 465 | .put(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()), fieldMapping) == null; | ||
| 465 | assert (wasAdded); | 466 | assert (wasAdded); |
| 466 | } | 467 | } |
| 467 | } | 468 | } |
| 468 | 469 | ||
| 469 | // rename method signatures | 470 | // rename method signatures |
| 470 | for (MethodMapping methodMapping : new ArrayList<>(m_methodsByObf.values())) { | 471 | for (MethodMapping methodMapping : new ArrayList<>(methodsByObf.values())) { |
| 471 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | 472 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 472 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 473 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 473 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; | 474 | boolean wasRemoved = methodsByObf.remove(oldMethodKey) != null; |
| 474 | assert (wasRemoved); | 475 | assert (wasRemoved); |
| 475 | boolean wasAdded = m_methodsByObf.put(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()), methodMapping) == null; | 476 | boolean wasAdded = methodsByObf |
| 477 | .put(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()), methodMapping) == null; | ||
| 476 | assert (wasAdded); | 478 | assert (wasAdded); |
| 477 | } | 479 | } |
| 478 | } | 480 | } |
| 479 | 481 | ||
| 480 | if (m_obfFullName.equals(oldObfClassName)) { | 482 | if (obfFullName.equals(oldObfClassName)) { |
| 481 | // rename this class | 483 | // rename this class |
| 482 | m_obfFullName = newObfClassName; | 484 | obfFullName = newObfClassName; |
| 483 | return true; | 485 | return true; |
| 484 | } | 486 | } |
| 485 | this.isDirty = true; | 487 | this.isDirty = true; |
| @@ -487,7 +489,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 487 | } | 489 | } |
| 488 | 490 | ||
| 489 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { | 491 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { |
| 490 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); | 492 | MethodMapping methodMapping = methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); |
| 491 | return methodMapping != null && methodMapping.containsArgument(name); | 493 | return methodMapping != null && methodMapping.containsArgument(name); |
| 492 | } | 494 | } |
| 493 | 495 | ||
| @@ -496,7 +498,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 496 | } | 498 | } |
| 497 | 499 | ||
| 498 | public ClassEntry getObfEntry() { | 500 | public ClassEntry getObfEntry() { |
| 499 | return new ClassEntry(m_obfFullName); | 501 | return new ClassEntry(obfFullName); |
| 500 | } | 502 | } |
| 501 | 503 | ||
| 502 | public boolean isDirty() | 504 | public boolean isDirty() |
| @@ -522,11 +524,8 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 522 | } | 524 | } |
| 523 | 525 | ||
| 524 | public void setFieldModifier(String obfName, Type obfType, Mappings.EntryModifier modifier) { | 526 | public void setFieldModifier(String obfName, Type obfType, Mappings.EntryModifier modifier) { |
| 525 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 527 | FieldMapping fieldMapping = fieldsByObf.computeIfAbsent(getFieldKey(obfName, obfType), |
| 526 | if (fieldMapping == null) { | 528 | k -> new FieldMapping(obfName, obfType, null, Mappings.EntryModifier.UNCHANGED)); |
| 527 | fieldMapping = new FieldMapping(obfName, obfType, null, Mappings.EntryModifier.UNCHANGED); | ||
| 528 | m_fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping); | ||
| 529 | } | ||
| 530 | 529 | ||
| 531 | if (fieldMapping.getModifier() != modifier) | 530 | if (fieldMapping.getModifier() != modifier) |
| 532 | { | 531 | { |
| @@ -536,11 +535,8 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 536 | } | 535 | } |
| 537 | 536 | ||
| 538 | public void setMethodModifier(String obfName, Signature sig, Mappings.EntryModifier modifier) { | 537 | public void setMethodModifier(String obfName, Signature sig, Mappings.EntryModifier modifier) { |
| 539 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfName, sig)); | 538 | MethodMapping methodMapping = methodsByObf.computeIfAbsent(getMethodKey(obfName, sig), |
| 540 | if (methodMapping == null) { | 539 | k -> new MethodMapping(obfName, sig, null, Mappings.EntryModifier.UNCHANGED)); |
| 541 | methodMapping = new MethodMapping(obfName, sig, null, Mappings.EntryModifier.UNCHANGED); | ||
| 542 | m_methodsByObf.put(getMethodKey(obfName, sig), methodMapping); | ||
| 543 | } | ||
| 544 | 540 | ||
| 545 | if (methodMapping.getModifier() != modifier) | 541 | if (methodMapping.getModifier() != modifier) |
| 546 | { | 542 | { |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java index 83e2277..22ba307 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java | |||
| @@ -92,14 +92,12 @@ public class FieldMapping implements Comparable<FieldMapping>, MemberMapping<Fie | |||
| 92 | 92 | ||
| 93 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { | 93 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { |
| 94 | // rename obf classes in the type | 94 | // rename obf classes in the type |
| 95 | Type newType = new Type(this.obfType, new ClassNameReplacer() { | 95 | Type newType = new Type(this.obfType, className -> |
| 96 | @Override | 96 | { |
| 97 | public String replace(String className) { | 97 | if (className.equals(oldObfClassName)) { |
| 98 | if (className.equals(oldObfClassName)) { | 98 | return newObfClassName; |
| 99 | return newObfClassName; | ||
| 100 | } | ||
| 101 | return null; | ||
| 102 | } | 99 | } |
| 100 | return null; | ||
| 103 | }); | 101 | }); |
| 104 | 102 | ||
| 105 | if (!newType.equals(this.obfType)) { | 103 | if (!newType.equals(this.obfType)) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index c09f4a6..6c57200 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -131,7 +131,7 @@ public class MappingsEnigmaWriter { | |||
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException { | 134 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) { |
| 135 | if (fieldMapping.getDeobfName() == null) | 135 | if (fieldMapping.getDeobfName() == null) |
| 136 | out.format("%sFIELD %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getObfType().toString(), fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); | 136 | out.format("%sFIELD %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getObfType().toString(), fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); |
| 137 | else | 137 | else |
| @@ -150,12 +150,12 @@ public class MappingsEnigmaWriter { | |||
| 150 | } | 150 | } |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | private void write(PrintWriter out, ArgumentMapping argumentMapping, int depth) throws IOException { | 153 | private void write(PrintWriter out, ArgumentMapping argumentMapping, int depth) { |
| 154 | out.format("%sARG %d %s\n", getIndent(depth), argumentMapping.getIndex(), argumentMapping.getName()); | 154 | out.format("%sARG %d %s\n", getIndent(depth), argumentMapping.getIndex(), argumentMapping.getName()); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { | 157 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { |
| 158 | List<T> out = new ArrayList<T>(); | 158 | List<T> out = new ArrayList<>(); |
| 159 | for (T t : classes) { | 159 | for (T t : classes) { |
| 160 | out.add(t); | 160 | out.add(t); |
| 161 | } | 161 | } |
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 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java index 4d0c261..a3f0cc8 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | |||
| @@ -71,7 +71,7 @@ public class MappingsSRGWriter { | |||
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { | 73 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { |
| 74 | List<T> out = new ArrayList<T>(); | 74 | List<T> out = new ArrayList<>(); |
| 75 | for (T t : classes) { | 75 | for (T t : classes) { |
| 76 | out.add(t); | 76 | out.add(t); |
| 77 | } | 77 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index f973d6b..e0aeea2 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -178,14 +178,12 @@ public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<B | |||
| 178 | 178 | ||
| 179 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { | 179 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { |
| 180 | // rename obf classes in the signature | 180 | // rename obf classes in the signature |
| 181 | Signature newSignature = new Signature(this.obfSignature, new ClassNameReplacer() { | 181 | Signature newSignature = new Signature(this.obfSignature, className -> |
| 182 | @Override | 182 | { |
| 183 | public String replace(String className) { | 183 | if (className.equals(oldObfClassName)) { |
| 184 | if (className.equals(oldObfClassName)) { | 184 | return newObfClassName; |
| 185 | return newObfClassName; | ||
| 186 | } | ||
| 187 | return null; | ||
| 188 | } | 185 | } |
| 186 | return null; | ||
| 189 | }); | 187 | }); |
| 190 | 188 | ||
| 191 | if (!newSignature.equals(this.obfSignature)) { | 189 | if (!newSignature.equals(this.obfSignature)) { |