diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping')
25 files changed, 335 insertions, 701 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java index 83033bc..1409fc4 100644 --- a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java | |||
| @@ -10,17 +10,13 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | import cuchaz.enigma.utils.Utils; |
| 14 | 14 | ||
| 15 | import cuchaz.enigma.Util; | 15 | public class ArgumentEntry implements Entry { |
| 16 | 16 | ||
| 17 | public class ArgumentEntry implements Entry, Serializable { | 17 | private BehaviorEntry behaviorEntry; |
| 18 | 18 | private int index; | |
| 19 | private static final long serialVersionUID = 4472172468162696006L; | 19 | private String name; |
| 20 | |||
| 21 | private BehaviorEntry m_behaviorEntry; | ||
| 22 | private int m_index; | ||
| 23 | private String m_name; | ||
| 24 | 20 | ||
| 25 | public ArgumentEntry(BehaviorEntry behaviorEntry, int index, String name) { | 21 | public ArgumentEntry(BehaviorEntry behaviorEntry, int index, String name) { |
| 26 | if (behaviorEntry == null) { | 22 | if (behaviorEntry == null) { |
| @@ -33,44 +29,38 @@ public class ArgumentEntry implements Entry, Serializable { | |||
| 33 | throw new IllegalArgumentException("Argument name cannot be null!"); | 29 | throw new IllegalArgumentException("Argument name cannot be null!"); |
| 34 | } | 30 | } |
| 35 | 31 | ||
| 36 | m_behaviorEntry = behaviorEntry; | 32 | this.behaviorEntry = behaviorEntry; |
| 37 | m_index = index; | 33 | this.index = index; |
| 38 | m_name = name; | 34 | this.name = name; |
| 39 | } | ||
| 40 | |||
| 41 | public ArgumentEntry(ArgumentEntry other) { | ||
| 42 | m_behaviorEntry = (BehaviorEntry) m_behaviorEntry.cloneToNewClass(getClassEntry()); | ||
| 43 | m_index = other.m_index; | ||
| 44 | m_name = other.m_name; | ||
| 45 | } | 35 | } |
| 46 | 36 | ||
| 47 | public ArgumentEntry(ArgumentEntry other, String newClassName) { | 37 | public ArgumentEntry(ArgumentEntry other, String newClassName) { |
| 48 | m_behaviorEntry = (BehaviorEntry) other.m_behaviorEntry.cloneToNewClass(new ClassEntry(newClassName)); | 38 | this.behaviorEntry = (BehaviorEntry) other.behaviorEntry.cloneToNewClass(new ClassEntry(newClassName)); |
| 49 | m_index = other.m_index; | 39 | this.index = other.index; |
| 50 | m_name = other.m_name; | 40 | this.name = other.name; |
| 51 | } | 41 | } |
| 52 | 42 | ||
| 53 | public BehaviorEntry getBehaviorEntry() { | 43 | public BehaviorEntry getBehaviorEntry() { |
| 54 | return m_behaviorEntry; | 44 | return this.behaviorEntry; |
| 55 | } | 45 | } |
| 56 | 46 | ||
| 57 | public int getIndex() { | 47 | public int getIndex() { |
| 58 | return m_index; | 48 | return this.index; |
| 59 | } | 49 | } |
| 60 | 50 | ||
| 61 | @Override | 51 | @Override |
| 62 | public String getName() { | 52 | public String getName() { |
| 63 | return m_name; | 53 | return this.name; |
| 64 | } | 54 | } |
| 65 | 55 | ||
| 66 | @Override | 56 | @Override |
| 67 | public ClassEntry getClassEntry() { | 57 | public ClassEntry getClassEntry() { |
| 68 | return m_behaviorEntry.getClassEntry(); | 58 | return this.behaviorEntry.getClassEntry(); |
| 69 | } | 59 | } |
| 70 | 60 | ||
| 71 | @Override | 61 | @Override |
| 72 | public String getClassName() { | 62 | public String getClassName() { |
| 73 | return m_behaviorEntry.getClassName(); | 63 | return this.behaviorEntry.getClassName(); |
| 74 | } | 64 | } |
| 75 | 65 | ||
| 76 | @Override | 66 | @Override |
| @@ -79,20 +69,16 @@ public class ArgumentEntry implements Entry, Serializable { | |||
| 79 | } | 69 | } |
| 80 | 70 | ||
| 81 | public String getMethodName() { | 71 | public String getMethodName() { |
| 82 | return m_behaviorEntry.getName(); | 72 | return this.behaviorEntry.getName(); |
| 83 | } | 73 | } |
| 84 | 74 | ||
| 85 | public Signature getMethodSignature() { | 75 | public Signature getMethodSignature() { |
| 86 | return m_behaviorEntry.getSignature(); | 76 | return this.behaviorEntry.getSignature(); |
| 87 | } | 77 | } |
| 88 | 78 | ||
| 89 | @Override | 79 | @Override |
| 90 | public int hashCode() { | 80 | public int hashCode() { |
| 91 | return Util.combineHashesOrdered( | 81 | return Utils.combineHashesOrdered(this.behaviorEntry, Integer.valueOf(this.index).hashCode(), this.name.hashCode()); |
| 92 | m_behaviorEntry, | ||
| 93 | Integer.valueOf(m_index).hashCode(), | ||
| 94 | m_name.hashCode() | ||
| 95 | ); | ||
| 96 | } | 82 | } |
| 97 | 83 | ||
| 98 | @Override | 84 | @Override |
| @@ -101,11 +87,11 @@ public class ArgumentEntry implements Entry, Serializable { | |||
| 101 | } | 87 | } |
| 102 | 88 | ||
| 103 | public boolean equals(ArgumentEntry other) { | 89 | public boolean equals(ArgumentEntry other) { |
| 104 | return m_behaviorEntry.equals(other.m_behaviorEntry) && m_index == other.m_index && m_name.equals(other.m_name); | 90 | return this.behaviorEntry.equals(other.behaviorEntry) && this.index == other.index && this.name.equals(other.name); |
| 105 | } | 91 | } |
| 106 | 92 | ||
| 107 | @Override | 93 | @Override |
| 108 | public String toString() { | 94 | public String toString() { |
| 109 | return m_behaviorEntry.toString() + "(" + m_index + ":" + m_name + ")"; | 95 | return this.behaviorEntry.toString() + "(" + this.index + ":" + this.name + ")"; |
| 110 | } | 96 | } |
| 111 | } | 97 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/ArgumentMapping.java b/src/main/java/cuchaz/enigma/mapping/ArgumentMapping.java index 2b77d6e..918395f 100644 --- a/src/main/java/cuchaz/enigma/mapping/ArgumentMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ArgumentMapping.java | |||
| @@ -10,40 +10,31 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | public class ArgumentMapping implements Comparable<ArgumentMapping> { |
| 14 | 14 | ||
| 15 | public class ArgumentMapping implements Serializable, Comparable<ArgumentMapping> { | 15 | private int index; |
| 16 | 16 | private String name; | |
| 17 | private static final long serialVersionUID = 8610742471440861315L; | ||
| 18 | |||
| 19 | private int m_index; | ||
| 20 | private String m_name; | ||
| 21 | 17 | ||
| 22 | // NOTE: this argument order is important for the MethodReader/MethodWriter | 18 | // NOTE: this argument order is important for the MethodReader/MethodWriter |
| 23 | public ArgumentMapping(int index, String name) { | 19 | public ArgumentMapping(int index, String name) { |
| 24 | m_index = index; | 20 | this.index = index; |
| 25 | m_name = NameValidator.validateArgumentName(name); | 21 | this.name = NameValidator.validateArgumentName(name); |
| 26 | } | ||
| 27 | |||
| 28 | public ArgumentMapping(ArgumentMapping other) { | ||
| 29 | m_index = other.m_index; | ||
| 30 | m_name = other.m_name; | ||
| 31 | } | 22 | } |
| 32 | 23 | ||
| 33 | public int getIndex() { | 24 | public int getIndex() { |
| 34 | return m_index; | 25 | return this.index; |
| 35 | } | 26 | } |
| 36 | 27 | ||
| 37 | public String getName() { | 28 | public String getName() { |
| 38 | return m_name; | 29 | return this.name; |
| 39 | } | 30 | } |
| 40 | 31 | ||
| 41 | public void setName(String val) { | 32 | public void setName(String val) { |
| 42 | m_name = NameValidator.validateArgumentName(val); | 33 | this.name = NameValidator.validateArgumentName(val); |
| 43 | } | 34 | } |
| 44 | 35 | ||
| 45 | @Override | 36 | @Override |
| 46 | public int compareTo(ArgumentMapping other) { | 37 | public int compareTo(ArgumentMapping other) { |
| 47 | return Integer.compare(m_index, other.m_index); | 38 | return Integer.compare(this.index, other.index); |
| 48 | } | 39 | } |
| 49 | } | 40 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java index c9304d4..a58d054 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java | |||
| @@ -12,14 +12,11 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Lists; | 13 | import com.google.common.collect.Lists; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.List; | 15 | import java.util.List; |
| 17 | 16 | ||
| 18 | public class ClassEntry implements Entry, Serializable { | 17 | public class ClassEntry implements Entry { |
| 19 | 18 | ||
| 20 | private static final long serialVersionUID = 4235460580973955811L; | 19 | private String name; |
| 21 | |||
| 22 | private String m_name; | ||
| 23 | 20 | ||
| 24 | public ClassEntry(String className) { | 21 | public ClassEntry(String className) { |
| 25 | if (className == null) { | 22 | if (className == null) { |
| @@ -29,7 +26,7 @@ public class ClassEntry implements Entry, Serializable { | |||
| 29 | throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); | 26 | throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); |
| 30 | } | 27 | } |
| 31 | 28 | ||
| 32 | m_name = className; | 29 | this.name = className; |
| 33 | 30 | ||
| 34 | if (isInnerClass() && getInnermostClassName().indexOf('/') >= 0) { | 31 | if (isInnerClass() && getInnermostClassName().indexOf('/') >= 0) { |
| 35 | throw new IllegalArgumentException("Inner class must not have a package: " + className); | 32 | throw new IllegalArgumentException("Inner class must not have a package: " + className); |
| @@ -37,17 +34,17 @@ public class ClassEntry implements Entry, Serializable { | |||
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | public ClassEntry(ClassEntry other) { | 36 | public ClassEntry(ClassEntry other) { |
| 40 | m_name = other.m_name; | 37 | this.name = other.name; |
| 41 | } | 38 | } |
| 42 | 39 | ||
| 43 | @Override | 40 | @Override |
| 44 | public String getName() { | 41 | public String getName() { |
| 45 | return m_name; | 42 | return this.name; |
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | @Override | 45 | @Override |
| 49 | public String getClassName() { | 46 | public String getClassName() { |
| 50 | return m_name; | 47 | return this.name; |
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | @Override | 50 | @Override |
| @@ -62,7 +59,7 @@ public class ClassEntry implements Entry, Serializable { | |||
| 62 | 59 | ||
| 63 | @Override | 60 | @Override |
| 64 | public int hashCode() { | 61 | public int hashCode() { |
| 65 | return m_name.hashCode(); | 62 | return this.name.hashCode(); |
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | @Override | 65 | @Override |
| @@ -71,20 +68,20 @@ public class ClassEntry implements Entry, Serializable { | |||
| 71 | } | 68 | } |
| 72 | 69 | ||
| 73 | public boolean equals(ClassEntry other) { | 70 | public boolean equals(ClassEntry other) { |
| 74 | return m_name.equals(other.m_name); | 71 | return this.name.equals(other.name); |
| 75 | } | 72 | } |
| 76 | 73 | ||
| 77 | @Override | 74 | @Override |
| 78 | public String toString() { | 75 | public String toString() { |
| 79 | return m_name; | 76 | return this.name; |
| 80 | } | 77 | } |
| 81 | 78 | ||
| 82 | public boolean isInnerClass() { | 79 | public boolean isInnerClass() { |
| 83 | return m_name.lastIndexOf('$') >= 0; | 80 | return this.name.lastIndexOf('$') >= 0; |
| 84 | } | 81 | } |
| 85 | 82 | ||
| 86 | public List<String> getClassChainNames() { | 83 | public List<String> getClassChainNames() { |
| 87 | return Lists.newArrayList(m_name.split("\\$")); | 84 | return Lists.newArrayList(this.name.split("\\$")); |
| 88 | } | 85 | } |
| 89 | 86 | ||
| 90 | public List<ClassEntry> getClassChain() { | 87 | public List<ClassEntry> getClassChain() { |
| @@ -102,9 +99,9 @@ public class ClassEntry implements Entry, Serializable { | |||
| 102 | 99 | ||
| 103 | public String getOutermostClassName() { | 100 | public String getOutermostClassName() { |
| 104 | if (isInnerClass()) { | 101 | if (isInnerClass()) { |
| 105 | return m_name.substring(0, m_name.indexOf('$')); | 102 | return this.name.substring(0, this.name.indexOf('$')); |
| 106 | } | 103 | } |
| 107 | return m_name; | 104 | return this.name; |
| 108 | } | 105 | } |
| 109 | 106 | ||
| 110 | public ClassEntry getOutermostClassEntry() { | 107 | public ClassEntry getOutermostClassEntry() { |
| @@ -115,7 +112,7 @@ public class ClassEntry implements Entry, Serializable { | |||
| 115 | if (!isInnerClass()) { | 112 | if (!isInnerClass()) { |
| 116 | throw new Error("This is not an inner class!"); | 113 | throw new Error("This is not an inner class!"); |
| 117 | } | 114 | } |
| 118 | return m_name.substring(0, m_name.lastIndexOf('$')); | 115 | return this.name.substring(0, this.name.lastIndexOf('$')); |
| 119 | } | 116 | } |
| 120 | 117 | ||
| 121 | public ClassEntry getOuterClassEntry() { | 118 | public ClassEntry getOuterClassEntry() { |
| @@ -126,27 +123,27 @@ public class ClassEntry implements Entry, Serializable { | |||
| 126 | if (!isInnerClass()) { | 123 | if (!isInnerClass()) { |
| 127 | throw new Error("This is not an inner class!"); | 124 | throw new Error("This is not an inner class!"); |
| 128 | } | 125 | } |
| 129 | return m_name.substring(m_name.lastIndexOf('$') + 1); | 126 | return this.name.substring(this.name.lastIndexOf('$') + 1); |
| 130 | } | 127 | } |
| 131 | 128 | ||
| 132 | public boolean isInDefaultPackage() { | 129 | public boolean isInDefaultPackage() { |
| 133 | return m_name.indexOf('/') < 0; | 130 | return this.name.indexOf('/') < 0; |
| 134 | } | 131 | } |
| 135 | 132 | ||
| 136 | public String getPackageName() { | 133 | public String getPackageName() { |
| 137 | int pos = m_name.lastIndexOf('/'); | 134 | int pos = this.name.lastIndexOf('/'); |
| 138 | if (pos > 0) { | 135 | if (pos > 0) { |
| 139 | return m_name.substring(0, pos); | 136 | return this.name.substring(0, pos); |
| 140 | } | 137 | } |
| 141 | return null; | 138 | return null; |
| 142 | } | 139 | } |
| 143 | 140 | ||
| 144 | public String getSimpleName() { | 141 | public String getSimpleName() { |
| 145 | int pos = m_name.lastIndexOf('/'); | 142 | int pos = this.name.lastIndexOf('/'); |
| 146 | if (pos > 0) { | 143 | if (pos > 0) { |
| 147 | return m_name.substring(pos + 1); | 144 | return this.name.substring(pos + 1); |
| 148 | } | 145 | } |
| 149 | return m_name; | 146 | return this.name; |
| 150 | } | 147 | } |
| 151 | 148 | ||
| 152 | public ClassEntry buildClassEntry(List<ClassEntry> classChain) { | 149 | public ClassEntry buildClassEntry(List<ClassEntry> classChain) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index f831a3b..b2c076a 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -12,13 +12,11 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.ArrayList; | ||
| 17 | import java.util.Map; | 15 | import java.util.Map; |
| 18 | 16 | ||
| 19 | public class ClassMapping implements Serializable, Comparable<ClassMapping> { | 17 | import cuchaz.enigma.throwables.MappingConflict; |
| 20 | 18 | ||
| 21 | private static final long serialVersionUID = -5148491146902340107L; | 19 | public class ClassMapping implements Comparable<ClassMapping> { |
| 22 | 20 | ||
| 23 | private String m_obfFullName; | 21 | private String m_obfFullName; |
| 24 | private String m_obfSimpleName; | 22 | private String m_obfSimpleName; |
| @@ -70,13 +68,17 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 70 | return m_innerClassesByObfSimple.values(); | 68 | return m_innerClassesByObfSimple.values(); |
| 71 | } | 69 | } |
| 72 | 70 | ||
| 73 | public void addInnerClassMapping(ClassMapping classMapping) { | 71 | public void addInnerClassMapping(ClassMapping classMapping) throws MappingConflict { |
| 74 | boolean obfWasAdded = m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping) == null; | 72 | if (this.m_innerClassesByObfSimple.containsKey(classMapping.getObfSimpleName())) { |
| 75 | assert (obfWasAdded); | 73 | throw new MappingConflict("classes", classMapping.getObfSimpleName(), this.m_innerClassesByObfSimple.get(classMapping.getObfSimpleName()).getObfSimpleName()); |
| 74 | } | ||
| 75 | m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping); | ||
| 76 | |||
| 76 | if (classMapping.getDeobfName() != null) { | 77 | if (classMapping.getDeobfName() != null) { |
| 77 | assert (isSimpleClassName(classMapping.getDeobfName())); | 78 | if (this.m_innerClassesByDeobf.containsKey(classMapping.getDeobfName())) { |
| 78 | boolean deobfWasAdded = m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping) == null; | 79 | throw new MappingConflict("classes", classMapping.getDeobfName(), this.m_innerClassesByDeobf.get(classMapping.getDeobfName()).getDeobfName()); |
| 79 | assert (deobfWasAdded); | 80 | } |
| 81 | m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping); | ||
| 80 | } | 82 | } |
| 81 | } | 83 | } |
| 82 | 84 | ||
| @@ -225,17 +227,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 225 | } | 227 | } |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 228 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { | ||
| 229 | assert (newObfName != null); | ||
| 230 | FieldMapping fieldMapping = m_fieldsByObf.remove(getFieldKey(oldObfName, obfType)); | ||
| 231 | assert (fieldMapping != null); | ||
| 232 | fieldMapping.setObfName(newObfName); | ||
| 233 | fieldMapping.setObfType(newObfType); | ||
| 234 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; | ||
| 235 | assert (obfWasAdded); | ||
| 236 | } | ||
| 237 | |||
| 238 | |||
| 239 | //// METHODS //////// | 230 | //// METHODS //////// |
| 240 | 231 | ||
| 241 | public Iterable<MethodMapping> methods() { | 232 | public Iterable<MethodMapping> methods() { |
| @@ -307,16 +298,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 307 | } | 298 | } |
| 308 | } | 299 | } |
| 309 | 300 | ||
| 310 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { | ||
| 311 | assert (newObfName != null); | ||
| 312 | MethodMapping methodMapping = m_methodsByObf.remove(getMethodKey(oldObfName, obfSignature)); | ||
| 313 | assert (methodMapping != null); | ||
| 314 | methodMapping.setObfName(newObfName); | ||
| 315 | methodMapping.setObfSignature(newObfSignature); | ||
| 316 | boolean obfWasAdded = m_methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; | ||
| 317 | assert (obfWasAdded); | ||
| 318 | } | ||
| 319 | |||
| 320 | //// ARGUMENTS //////// | 301 | //// ARGUMENTS //////// |
| 321 | 302 | ||
| 322 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { | 303 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { |
| @@ -388,7 +369,4 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 388 | return name.indexOf('/') < 0 && name.indexOf('$') < 0; | 369 | return name.indexOf('/') < 0 && name.indexOf('$') < 0; |
| 389 | } | 370 | } |
| 390 | 371 | ||
| 391 | public ClassEntry getObfEntry() { | ||
| 392 | return new ClassEntry(m_obfFullName); | ||
| 393 | } | ||
| 394 | } | 372 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java b/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java index ac1a7f2..4c79820 100644 --- a/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java | |||
| @@ -10,16 +10,12 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | import cuchaz.enigma.utils.Utils; |
| 14 | 14 | ||
| 15 | import cuchaz.enigma.Util; | 15 | public class ConstructorEntry implements BehaviorEntry { |
| 16 | 16 | ||
| 17 | public class ConstructorEntry implements BehaviorEntry, Serializable { | 17 | private ClassEntry classEntry; |
| 18 | 18 | private Signature signature; | |
| 19 | private static final long serialVersionUID = -868346075317366758L; | ||
| 20 | |||
| 21 | private ClassEntry m_classEntry; | ||
| 22 | private Signature m_signature; | ||
| 23 | 19 | ||
| 24 | public ConstructorEntry(ClassEntry classEntry) { | 20 | public ConstructorEntry(ClassEntry classEntry) { |
| 25 | this(classEntry, null); | 21 | this(classEntry, null); |
| @@ -30,23 +26,18 @@ public class ConstructorEntry implements BehaviorEntry, Serializable { | |||
| 30 | throw new IllegalArgumentException("Class cannot be null!"); | 26 | throw new IllegalArgumentException("Class cannot be null!"); |
| 31 | } | 27 | } |
| 32 | 28 | ||
| 33 | m_classEntry = classEntry; | 29 | this.classEntry = classEntry; |
| 34 | m_signature = signature; | 30 | this.signature = signature; |
| 35 | } | ||
| 36 | |||
| 37 | public ConstructorEntry(ConstructorEntry other) { | ||
| 38 | m_classEntry = new ClassEntry(other.m_classEntry); | ||
| 39 | m_signature = other.m_signature; | ||
| 40 | } | 31 | } |
| 41 | 32 | ||
| 42 | public ConstructorEntry(ConstructorEntry other, String newClassName) { | 33 | public ConstructorEntry(ConstructorEntry other, String newClassName) { |
| 43 | m_classEntry = new ClassEntry(newClassName); | 34 | this.classEntry = new ClassEntry(newClassName); |
| 44 | m_signature = other.m_signature; | 35 | this.signature = other.signature; |
| 45 | } | 36 | } |
| 46 | 37 | ||
| 47 | @Override | 38 | @Override |
| 48 | public ClassEntry getClassEntry() { | 39 | public ClassEntry getClassEntry() { |
| 49 | return m_classEntry; | 40 | return this.classEntry; |
| 50 | } | 41 | } |
| 51 | 42 | ||
| 52 | @Override | 43 | @Override |
| @@ -58,17 +49,17 @@ public class ConstructorEntry implements BehaviorEntry, Serializable { | |||
| 58 | } | 49 | } |
| 59 | 50 | ||
| 60 | public boolean isStatic() { | 51 | public boolean isStatic() { |
| 61 | return m_signature == null; | 52 | return this.signature == null; |
| 62 | } | 53 | } |
| 63 | 54 | ||
| 64 | @Override | 55 | @Override |
| 65 | public Signature getSignature() { | 56 | public Signature getSignature() { |
| 66 | return m_signature; | 57 | return this.signature; |
| 67 | } | 58 | } |
| 68 | 59 | ||
| 69 | @Override | 60 | @Override |
| 70 | public String getClassName() { | 61 | public String getClassName() { |
| 71 | return m_classEntry.getName(); | 62 | return this.classEntry.getName(); |
| 72 | } | 63 | } |
| 73 | 64 | ||
| 74 | @Override | 65 | @Override |
| @@ -79,9 +70,9 @@ public class ConstructorEntry implements BehaviorEntry, Serializable { | |||
| 79 | @Override | 70 | @Override |
| 80 | public int hashCode() { | 71 | public int hashCode() { |
| 81 | if (isStatic()) { | 72 | if (isStatic()) { |
| 82 | return Util.combineHashesOrdered(m_classEntry); | 73 | return Utils.combineHashesOrdered(this.classEntry); |
| 83 | } else { | 74 | } else { |
| 84 | return Util.combineHashesOrdered(m_classEntry, m_signature); | 75 | return Utils.combineHashesOrdered(this.classEntry, this.signature); |
| 85 | } | 76 | } |
| 86 | } | 77 | } |
| 87 | 78 | ||
| @@ -96,18 +87,18 @@ public class ConstructorEntry implements BehaviorEntry, Serializable { | |||
| 96 | } | 87 | } |
| 97 | 88 | ||
| 98 | if (isStatic()) { | 89 | if (isStatic()) { |
| 99 | return m_classEntry.equals(other.m_classEntry); | 90 | return this.classEntry.equals(other.classEntry); |
| 100 | } else { | 91 | } else { |
| 101 | return m_classEntry.equals(other.m_classEntry) && m_signature.equals(other.m_signature); | 92 | return this.classEntry.equals(other.classEntry) && this.signature.equals(other.signature); |
| 102 | } | 93 | } |
| 103 | } | 94 | } |
| 104 | 95 | ||
| 105 | @Override | 96 | @Override |
| 106 | public String toString() { | 97 | public String toString() { |
| 107 | if (isStatic()) { | 98 | if (isStatic()) { |
| 108 | return m_classEntry.getName() + "." + getName(); | 99 | return this.classEntry.getName() + "." + getName(); |
| 109 | } else { | 100 | } else { |
| 110 | return m_classEntry.getName() + "." + getName() + m_signature; | 101 | return this.classEntry.getName() + "." + getName() + this.signature; |
| 111 | } | 102 | } |
| 112 | } | 103 | } |
| 113 | } | 104 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java index 3584ebb..2351dcf 100644 --- a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java +++ b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java | |||
| @@ -38,19 +38,11 @@ public class EntryFactory { | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | public static FieldEntry getFieldEntry(CtField field) { | 40 | public static FieldEntry getFieldEntry(CtField field) { |
| 41 | return new FieldEntry( | 41 | return new FieldEntry(getClassEntry(field.getDeclaringClass()), field.getName(), new Type(field.getFieldInfo().getDescriptor())); |
| 42 | getClassEntry(field.getDeclaringClass()), | ||
| 43 | field.getName(), | ||
| 44 | new Type(field.getFieldInfo().getDescriptor()) | ||
| 45 | ); | ||
| 46 | } | 42 | } |
| 47 | 43 | ||
| 48 | public static FieldEntry getFieldEntry(FieldAccess call) { | 44 | public static FieldEntry getFieldEntry(FieldAccess call) { |
| 49 | return new FieldEntry( | 45 | return new FieldEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), call.getFieldName(), new Type(call.getSignature())); |
| 50 | new ClassEntry(Descriptor.toJvmName(call.getClassName())), | ||
| 51 | call.getFieldName(), | ||
| 52 | new Type(call.getSignature()) | ||
| 53 | ); | ||
| 54 | } | 46 | } |
| 55 | 47 | ||
| 56 | public static FieldEntry getFieldEntry(String className, String name, String type) { | 48 | public static FieldEntry getFieldEntry(String className, String name, String type) { |
| @@ -58,19 +50,11 @@ public class EntryFactory { | |||
| 58 | } | 50 | } |
| 59 | 51 | ||
| 60 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { | 52 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { |
| 61 | return new FieldEntry( | 53 | return new FieldEntry(getObfClassEntry(classMapping), fieldMapping.getObfName(), fieldMapping.getObfType()); |
| 62 | getObfClassEntry(classMapping), | ||
| 63 | fieldMapping.getObfName(), | ||
| 64 | fieldMapping.getObfType() | ||
| 65 | ); | ||
| 66 | } | 54 | } |
| 67 | 55 | ||
| 68 | public static MethodEntry getMethodEntry(CtMethod method) { | 56 | public static MethodEntry getMethodEntry(CtMethod method) { |
| 69 | return new MethodEntry( | 57 | return new MethodEntry(getClassEntry(method.getDeclaringClass()), method.getName(), new Signature(method.getMethodInfo().getDescriptor())); |
| 70 | getClassEntry(method.getDeclaringClass()), | ||
| 71 | method.getName(), | ||
| 72 | new Signature(method.getMethodInfo().getDescriptor()) | ||
| 73 | ); | ||
| 74 | } | 58 | } |
| 75 | 59 | ||
| 76 | public static MethodEntry getMethodEntry(MethodCall call) { | 60 | public static MethodEntry getMethodEntry(MethodCall call) { |
| @@ -106,10 +90,6 @@ public class EntryFactory { | |||
| 106 | return getBehaviorEntry(new ClassEntry(className), behaviorName, new Signature(behaviorSignature)); | 90 | return getBehaviorEntry(new ClassEntry(className), behaviorName, new Signature(behaviorSignature)); |
| 107 | } | 91 | } |
| 108 | 92 | ||
| 109 | public static BehaviorEntry getBehaviorEntry(String className, String behaviorName) { | ||
| 110 | return getBehaviorEntry(new ClassEntry(className), behaviorName); | ||
| 111 | } | ||
| 112 | |||
| 113 | public static BehaviorEntry getBehaviorEntry(String className) { | 93 | public static BehaviorEntry getBehaviorEntry(String className) { |
| 114 | return new ConstructorEntry(new ClassEntry(className)); | 94 | return new ConstructorEntry(new ClassEntry(className)); |
| 115 | } | 95 | } |
| @@ -125,14 +105,6 @@ public class EntryFactory { | |||
| 125 | } | 105 | } |
| 126 | } | 106 | } |
| 127 | 107 | ||
| 128 | public static BehaviorEntry getBehaviorEntry(ClassEntry classEntry, String behaviorName) { | ||
| 129 | if (behaviorName.equals("<clinit>")) { | ||
| 130 | return new ConstructorEntry(classEntry); | ||
| 131 | } else { | ||
| 132 | throw new IllegalArgumentException("Only class initializers don't have signatures"); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) { | 108 | public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) { |
| 137 | return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature()); | 109 | return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 138 | } | 110 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java index bebc504..9980e8e 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java | |||
| @@ -10,17 +10,13 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | import cuchaz.enigma.utils.Utils; |
| 14 | 14 | ||
| 15 | import cuchaz.enigma.Util; | 15 | public class FieldEntry implements Entry { |
| 16 | 16 | ||
| 17 | public class FieldEntry implements Entry, Serializable { | 17 | private ClassEntry classEntry; |
| 18 | 18 | private String name; | |
| 19 | private static final long serialVersionUID = 3004663582802885451L; | 19 | private Type type; |
| 20 | |||
| 21 | private ClassEntry m_classEntry; | ||
| 22 | private String m_name; | ||
| 23 | private Type m_type; | ||
| 24 | 20 | ||
| 25 | // NOTE: this argument order is important for the MethodReader/MethodWriter | 21 | // NOTE: this argument order is important for the MethodReader/MethodWriter |
| 26 | public FieldEntry(ClassEntry classEntry, String name, Type type) { | 22 | public FieldEntry(ClassEntry classEntry, String name, Type type) { |
| @@ -34,38 +30,34 @@ public class FieldEntry implements Entry, Serializable { | |||
| 34 | throw new IllegalArgumentException("Field type cannot be null!"); | 30 | throw new IllegalArgumentException("Field type cannot be null!"); |
| 35 | } | 31 | } |
| 36 | 32 | ||
| 37 | m_classEntry = classEntry; | 33 | this.classEntry = classEntry; |
| 38 | m_name = name; | 34 | this.name = name; |
| 39 | m_type = type; | 35 | this.type = type; |
| 40 | } | ||
| 41 | |||
| 42 | public FieldEntry(FieldEntry other) { | ||
| 43 | this(other, new ClassEntry(other.m_classEntry)); | ||
| 44 | } | 36 | } |
| 45 | 37 | ||
| 46 | public FieldEntry(FieldEntry other, ClassEntry newClassEntry) { | 38 | public FieldEntry(FieldEntry other, ClassEntry newClassEntry) { |
| 47 | m_classEntry = newClassEntry; | 39 | this.classEntry = newClassEntry; |
| 48 | m_name = other.m_name; | 40 | this.name = other.name; |
| 49 | m_type = other.m_type; | 41 | this.type = other.type; |
| 50 | } | 42 | } |
| 51 | 43 | ||
| 52 | @Override | 44 | @Override |
| 53 | public ClassEntry getClassEntry() { | 45 | public ClassEntry getClassEntry() { |
| 54 | return m_classEntry; | 46 | return this.classEntry; |
| 55 | } | 47 | } |
| 56 | 48 | ||
| 57 | @Override | 49 | @Override |
| 58 | public String getName() { | 50 | public String getName() { |
| 59 | return m_name; | 51 | return this.name; |
| 60 | } | 52 | } |
| 61 | 53 | ||
| 62 | @Override | 54 | @Override |
| 63 | public String getClassName() { | 55 | public String getClassName() { |
| 64 | return m_classEntry.getName(); | 56 | return this.classEntry.getName(); |
| 65 | } | 57 | } |
| 66 | 58 | ||
| 67 | public Type getType() { | 59 | public Type getType() { |
| 68 | return m_type; | 60 | return this.type; |
| 69 | } | 61 | } |
| 70 | 62 | ||
| 71 | @Override | 63 | @Override |
| @@ -75,7 +67,7 @@ public class FieldEntry implements Entry, Serializable { | |||
| 75 | 67 | ||
| 76 | @Override | 68 | @Override |
| 77 | public int hashCode() { | 69 | public int hashCode() { |
| 78 | return Util.combineHashesOrdered(m_classEntry, m_name, m_type); | 70 | return Utils.combineHashesOrdered(this.classEntry, this.name, this.type); |
| 79 | } | 71 | } |
| 80 | 72 | ||
| 81 | @Override | 73 | @Override |
| @@ -84,13 +76,11 @@ public class FieldEntry implements Entry, Serializable { | |||
| 84 | } | 76 | } |
| 85 | 77 | ||
| 86 | public boolean equals(FieldEntry other) { | 78 | public boolean equals(FieldEntry other) { |
| 87 | return m_classEntry.equals(other.m_classEntry) | 79 | return this.classEntry.equals(other.classEntry) && this.name.equals(other.name) && this.type.equals(other.type); |
| 88 | && m_name.equals(other.m_name) | ||
| 89 | && m_type.equals(other.m_type); | ||
| 90 | } | 80 | } |
| 91 | 81 | ||
| 92 | @Override | 82 | @Override |
| 93 | public String toString() { | 83 | public String toString() { |
| 94 | return m_classEntry.getName() + "." + m_name + ":" + m_type; | 84 | return this.classEntry.getName() + "." + this.name + ":" + this.type; |
| 95 | } | 85 | } |
| 96 | } | 86 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java index 19d68a9..3ec1af0 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java | |||
| @@ -10,11 +10,7 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | public class FieldMapping implements Comparable<FieldMapping>, MemberMapping<FieldEntry> { |
| 14 | |||
| 15 | public class FieldMapping implements Serializable, Comparable<FieldMapping>, MemberMapping<FieldEntry> { | ||
| 16 | |||
| 17 | private static final long serialVersionUID = 8610742471440861315L; | ||
| 18 | 14 | ||
| 19 | private String obfName; | 15 | private String obfName; |
| 20 | private String deobfName; | 16 | private String deobfName; |
| @@ -26,21 +22,11 @@ public class FieldMapping implements Serializable, Comparable<FieldMapping>, Mem | |||
| 26 | this.obfType = obfType; | 22 | this.obfType = obfType; |
| 27 | } | 23 | } |
| 28 | 24 | ||
| 29 | public FieldMapping(FieldMapping other, ClassNameReplacer obfClassNameReplacer) { | ||
| 30 | this.obfName = other.obfName; | ||
| 31 | this.deobfName = other.deobfName; | ||
| 32 | this.obfType = new Type(other.obfType, obfClassNameReplacer); | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | 25 | @Override |
| 36 | public String getObfName() { | 26 | public String getObfName() { |
| 37 | return this.obfName; | 27 | return this.obfName; |
| 38 | } | 28 | } |
| 39 | 29 | ||
| 40 | public void setObfName(String val) { | ||
| 41 | this.obfName = NameValidator.validateFieldName(val); | ||
| 42 | } | ||
| 43 | |||
| 44 | public String getDeobfName() { | 30 | public String getDeobfName() { |
| 45 | return this.deobfName; | 31 | return this.deobfName; |
| 46 | } | 32 | } |
| @@ -53,34 +39,8 @@ public class FieldMapping implements Serializable, Comparable<FieldMapping>, Mem | |||
| 53 | return this.obfType; | 39 | return this.obfType; |
| 54 | } | 40 | } |
| 55 | 41 | ||
| 56 | public void setObfType(Type val) { | ||
| 57 | this.obfType = val; | ||
| 58 | } | ||
| 59 | |||
| 60 | @Override | 42 | @Override |
| 61 | public int compareTo(FieldMapping other) { | 43 | public int compareTo(FieldMapping other) { |
| 62 | return (this.obfName + this.obfType).compareTo(other.obfName + other.obfType); | 44 | return (this.obfName + this.obfType).compareTo(other.obfName + other.obfType); |
| 63 | } | 45 | } |
| 64 | |||
| 65 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { | ||
| 66 | |||
| 67 | // rename obf classes in the type | ||
| 68 | Type newType = new Type(this.obfType, className -> { | ||
| 69 | if (className.equals(oldObfClassName)) { | ||
| 70 | return newObfClassName; | ||
| 71 | } | ||
| 72 | return null; | ||
| 73 | }); | ||
| 74 | |||
| 75 | if (!newType.equals(this.obfType)) { | ||
| 76 | this.obfType = newType; | ||
| 77 | return true; | ||
| 78 | } | ||
| 79 | return false; | ||
| 80 | } | ||
| 81 | |||
| 82 | @Override | ||
| 83 | public FieldEntry getObfEntry(ClassEntry classEntry) { | ||
| 84 | return new FieldEntry(classEntry, this.obfName, new Type(this.obfType)); | ||
| 85 | } | ||
| 86 | } | 46 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/IllegalNameException.java b/src/main/java/cuchaz/enigma/mapping/IllegalNameException.java deleted file mode 100644 index f2119d8..0000000 --- a/src/main/java/cuchaz/enigma/mapping/IllegalNameException.java +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | public class IllegalNameException extends RuntimeException { | ||
| 14 | |||
| 15 | private static final long serialVersionUID = -2279910052561114323L; | ||
| 16 | |||
| 17 | private String m_name; | ||
| 18 | private String m_reason; | ||
| 19 | |||
| 20 | public IllegalNameException(String name) { | ||
| 21 | this(name, null); | ||
| 22 | } | ||
| 23 | |||
| 24 | public IllegalNameException(String name, String reason) { | ||
| 25 | m_name = name; | ||
| 26 | m_reason = reason; | ||
| 27 | } | ||
| 28 | |||
| 29 | public String getReason() { | ||
| 30 | return m_reason; | ||
| 31 | } | ||
| 32 | |||
| 33 | @Override | ||
| 34 | public String getMessage() { | ||
| 35 | StringBuilder buf = new StringBuilder(); | ||
| 36 | buf.append("Illegal name: "); | ||
| 37 | buf.append(m_name); | ||
| 38 | if (m_reason != null) { | ||
| 39 | buf.append(" because "); | ||
| 40 | buf.append(m_reason); | ||
| 41 | } | ||
| 42 | return buf.toString(); | ||
| 43 | } | ||
| 44 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingParseException.java b/src/main/java/cuchaz/enigma/mapping/MappingParseException.java deleted file mode 100644 index 3c25ea5..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingParseException.java +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | public class MappingParseException extends Exception { | ||
| 14 | |||
| 15 | private static final long serialVersionUID = -5487280332892507236L; | ||
| 16 | |||
| 17 | private int m_line; | ||
| 18 | private String m_message; | ||
| 19 | |||
| 20 | public MappingParseException(int line, String message) { | ||
| 21 | m_line = line; | ||
| 22 | m_message = message; | ||
| 23 | } | ||
| 24 | |||
| 25 | @Override | ||
| 26 | public String getMessage() { | ||
| 27 | return "Line " + m_line + ": " + m_message; | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index ee4c302..b51e1a4 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -12,85 +12,64 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Lists; | 13 | import com.google.common.collect.Lists; |
| 14 | import com.google.common.collect.Maps; | 14 | import com.google.common.collect.Maps; |
| 15 | import com.google.common.collect.Sets; | ||
| 16 | 15 | ||
| 17 | import java.io.Serializable; | 16 | import java.util.Collection; |
| 18 | import java.util.*; | 17 | import java.util.List; |
| 18 | import java.util.Map; | ||
| 19 | 19 | ||
| 20 | import cuchaz.enigma.analysis.TranslationIndex; | 20 | import cuchaz.enigma.analysis.TranslationIndex; |
| 21 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 21 | 22 | ||
| 22 | public class Mappings implements Serializable { | 23 | public class Mappings { |
| 23 | 24 | ||
| 24 | private static final long serialVersionUID = 4649790259460259026L; | 25 | protected Map<String, ClassMapping> classesByObf; |
| 25 | 26 | protected Map<String, ClassMapping> classesByDeobf; | |
| 26 | protected Map<String, ClassMapping> m_classesByObf; | ||
| 27 | protected Map<String, ClassMapping> m_classesByDeobf; | ||
| 28 | 27 | ||
| 29 | public Mappings() { | 28 | public Mappings() { |
| 30 | m_classesByObf = Maps.newHashMap(); | 29 | this.classesByObf = Maps.newHashMap(); |
| 31 | m_classesByDeobf = Maps.newHashMap(); | 30 | this.classesByDeobf = Maps.newHashMap(); |
| 32 | } | ||
| 33 | |||
| 34 | public Mappings(Iterable<ClassMapping> classes) { | ||
| 35 | this(); | ||
| 36 | |||
| 37 | for (ClassMapping classMapping : classes) { | ||
| 38 | m_classesByObf.put(classMapping.getObfFullName(), classMapping); | ||
| 39 | if (classMapping.getDeobfName() != null) { | ||
| 40 | m_classesByDeobf.put(classMapping.getDeobfName(), classMapping); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | 31 | } |
| 44 | 32 | ||
| 45 | public Collection<ClassMapping> classes() { | 33 | public Collection<ClassMapping> classes() { |
| 46 | assert (m_classesByObf.size() >= m_classesByDeobf.size()); | 34 | assert (this.classesByObf.size() >= this.classesByDeobf.size()); |
| 47 | return m_classesByObf.values(); | 35 | return this.classesByObf.values(); |
| 48 | } | 36 | } |
| 49 | 37 | ||
| 50 | public void addClassMapping(ClassMapping classMapping) { | 38 | public void addClassMapping(ClassMapping classMapping) throws MappingConflict { |
| 51 | if (m_classesByObf.containsKey(classMapping.getObfFullName())) { | 39 | if (this.classesByObf.containsKey(classMapping.getObfFullName())) { |
| 52 | throw new Error("Already have mapping for " + classMapping.getObfFullName()); | 40 | throw new MappingConflict("class", classMapping.getObfFullName(), this.classesByObf.get(classMapping.getObfFullName()).getObfFullName()); |
| 53 | } | 41 | } |
| 54 | boolean obfWasAdded = m_classesByObf.put(classMapping.getObfFullName(), classMapping) == null; | 42 | this.classesByObf.put(classMapping.getObfFullName(), classMapping); |
| 55 | assert (obfWasAdded); | 43 | |
| 56 | if (classMapping.getDeobfName() != null) { | 44 | if (classMapping.getDeobfName() != null) { |
| 57 | if (m_classesByDeobf.containsKey(classMapping.getDeobfName())) { | 45 | if (this.classesByDeobf.containsKey(classMapping.getDeobfName())) { |
| 58 | throw new Error("Already have mapping for " + classMapping.getDeobfName()); | 46 | throw new MappingConflict("class", classMapping.getDeobfName(), this.classesByDeobf.get(classMapping.getDeobfName()).getDeobfName()); |
| 59 | } | 47 | } |
| 60 | boolean deobfWasAdded = m_classesByDeobf.put(classMapping.getDeobfName(), classMapping) == null; | 48 | this.classesByDeobf.put(classMapping.getDeobfName(), classMapping); |
| 61 | assert (deobfWasAdded); | ||
| 62 | } | 49 | } |
| 63 | } | 50 | } |
| 64 | 51 | ||
| 65 | public void removeClassMapping(ClassMapping classMapping) { | 52 | public void removeClassMapping(ClassMapping classMapping) { |
| 66 | boolean obfWasRemoved = m_classesByObf.remove(classMapping.getObfFullName()) != null; | 53 | boolean obfWasRemoved = this.classesByObf.remove(classMapping.getObfFullName()) != null; |
| 67 | assert (obfWasRemoved); | 54 | assert (obfWasRemoved); |
| 68 | if (classMapping.getDeobfName() != null) { | 55 | if (classMapping.getDeobfName() != null) { |
| 69 | boolean deobfWasRemoved = m_classesByDeobf.remove(classMapping.getDeobfName()) != null; | 56 | boolean deobfWasRemoved = this.classesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 70 | assert (deobfWasRemoved); | 57 | assert (deobfWasRemoved); |
| 71 | } | 58 | } |
| 72 | } | 59 | } |
| 73 | 60 | ||
| 74 | public ClassMapping getClassByObf(ClassEntry entry) { | ||
| 75 | return getClassByObf(entry.getName()); | ||
| 76 | } | ||
| 77 | |||
| 78 | public ClassMapping getClassByObf(String obfName) { | 61 | public ClassMapping getClassByObf(String obfName) { |
| 79 | return m_classesByObf.get(obfName); | 62 | return this.classesByObf.get(obfName); |
| 80 | } | ||
| 81 | |||
| 82 | public ClassMapping getClassByDeobf(String deobfName) { | ||
| 83 | return m_classesByDeobf.get(deobfName); | ||
| 84 | } | 63 | } |
| 85 | 64 | ||
| 86 | public void setClassDeobfName(ClassMapping classMapping, String deobfName) { | 65 | public void setClassDeobfName(ClassMapping classMapping, String deobfName) { |
| 87 | if (classMapping.getDeobfName() != null) { | 66 | if (classMapping.getDeobfName() != null) { |
| 88 | boolean wasRemoved = m_classesByDeobf.remove(classMapping.getDeobfName()) != null; | 67 | boolean wasRemoved = this.classesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 89 | assert (wasRemoved); | 68 | assert (wasRemoved); |
| 90 | } | 69 | } |
| 91 | classMapping.setDeobfName(deobfName); | 70 | classMapping.setDeobfName(deobfName); |
| 92 | if (deobfName != null) { | 71 | if (deobfName != null) { |
| 93 | boolean wasAdded = m_classesByDeobf.put(deobfName, classMapping) == null; | 72 | boolean wasAdded = this.classesByDeobf.put(deobfName, classMapping) == null; |
| 94 | assert (wasAdded); | 73 | assert (wasAdded); |
| 95 | } | 74 | } |
| 96 | } | 75 | } |
| @@ -99,7 +78,7 @@ public class Mappings implements Serializable { | |||
| 99 | switch (direction) { | 78 | switch (direction) { |
| 100 | case Deobfuscating: | 79 | case Deobfuscating: |
| 101 | 80 | ||
| 102 | return new Translator(direction, m_classesByObf, index); | 81 | return new Translator(direction, this.classesByObf, index); |
| 103 | 82 | ||
| 104 | case Obfuscating: | 83 | case Obfuscating: |
| 105 | 84 | ||
| @@ -127,7 +106,7 @@ public class Mappings implements Serializable { | |||
| 127 | @Override | 106 | @Override |
| 128 | public String toString() { | 107 | public String toString() { |
| 129 | StringBuilder buf = new StringBuilder(); | 108 | StringBuilder buf = new StringBuilder(); |
| 130 | for (ClassMapping classMapping : m_classesByObf.values()) { | 109 | for (ClassMapping classMapping : this.classesByObf.values()) { |
| 131 | buf.append(classMapping.toString()); | 110 | buf.append(classMapping.toString()); |
| 132 | buf.append("\n"); | 111 | buf.append("\n"); |
| 133 | } | 112 | } |
| @@ -135,21 +114,21 @@ public class Mappings implements Serializable { | |||
| 135 | } | 114 | } |
| 136 | 115 | ||
| 137 | public boolean containsDeobfClass(String deobfName) { | 116 | public boolean containsDeobfClass(String deobfName) { |
| 138 | return m_classesByDeobf.containsKey(deobfName); | 117 | return this.classesByDeobf.containsKey(deobfName); |
| 139 | } | 118 | } |
| 140 | 119 | ||
| 141 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, Type obfType) { | 120 | public boolean containsDeobfField(ClassEntry obfClassEntry, String deobfName, Type obfType) { |
| 142 | ClassMapping classMapping = m_classesByObf.get(obfClassEntry.getName()); | 121 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); |
| 143 | return classMapping != null && classMapping.containsDeobfField(deobfName, obfType); | 122 | return classMapping != null && classMapping.containsDeobfField(deobfName, obfType); |
| 144 | } | 123 | } |
| 145 | 124 | ||
| 146 | public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, Signature deobfSignature) { | 125 | public boolean containsDeobfMethod(ClassEntry obfClassEntry, String deobfName, Signature deobfSignature) { |
| 147 | ClassMapping classMapping = m_classesByObf.get(obfClassEntry.getName()); | 126 | ClassMapping classMapping = this.classesByObf.get(obfClassEntry.getName()); |
| 148 | return classMapping != null && classMapping.containsDeobfMethod(deobfName, deobfSignature); | 127 | return classMapping != null && classMapping.containsDeobfMethod(deobfName, deobfSignature); |
| 149 | } | 128 | } |
| 150 | 129 | ||
| 151 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { | 130 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { |
| 152 | ClassMapping classMapping = m_classesByObf.get(obfBehaviorEntry.getClassName()); | 131 | ClassMapping classMapping = this.classesByObf.get(obfBehaviorEntry.getClassName()); |
| 153 | return classMapping != null && classMapping.containsArgument(obfBehaviorEntry, name); | 132 | return classMapping != null && classMapping.containsArgument(obfBehaviorEntry, name); |
| 154 | } | 133 | } |
| 155 | 134 | ||
| @@ -158,7 +137,7 @@ public class Mappings implements Serializable { | |||
| 158 | ClassMapping classMapping = null; | 137 | ClassMapping classMapping = null; |
| 159 | for (ClassEntry obfClassEntry : obfClass.getClassChain()) { | 138 | for (ClassEntry obfClassEntry : obfClass.getClassChain()) { |
| 160 | if (mappingChain.isEmpty()) { | 139 | if (mappingChain.isEmpty()) { |
| 161 | classMapping = m_classesByObf.get(obfClassEntry.getName()); | 140 | classMapping = this.classesByObf.get(obfClassEntry.getName()); |
| 162 | } else if (classMapping != null) { | 141 | } else if (classMapping != null) { |
| 163 | classMapping = classMapping.getInnerClassByObfSimple(obfClassEntry.getInnermostClassName()); | 142 | classMapping = classMapping.getInnerClassByObfSimple(obfClassEntry.getInnermostClassName()); |
| 164 | } | 143 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java index d850787..6cf279d 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -20,41 +20,41 @@ import cuchaz.enigma.analysis.JarIndex; | |||
| 20 | 20 | ||
| 21 | public class MappingsChecker { | 21 | public class MappingsChecker { |
| 22 | 22 | ||
| 23 | private JarIndex m_index; | 23 | private JarIndex index; |
| 24 | private Map<ClassEntry, ClassMapping> m_droppedClassMappings; | 24 | private Map<ClassEntry, ClassMapping> droppedClassMappings; |
| 25 | private Map<ClassEntry, ClassMapping> m_droppedInnerClassMappings; | 25 | private Map<ClassEntry, ClassMapping> droppedInnerClassMappings; |
| 26 | private Map<FieldEntry, FieldMapping> m_droppedFieldMappings; | 26 | private Map<FieldEntry, FieldMapping> droppedFieldMappings; |
| 27 | private Map<BehaviorEntry, MethodMapping> m_droppedMethodMappings; | 27 | private Map<BehaviorEntry, MethodMapping> droppedMethodMappings; |
| 28 | 28 | ||
| 29 | public MappingsChecker(JarIndex index) { | 29 | public MappingsChecker(JarIndex index) { |
| 30 | m_index = index; | 30 | this.index = index; |
| 31 | m_droppedClassMappings = Maps.newHashMap(); | 31 | this.droppedClassMappings = Maps.newHashMap(); |
| 32 | m_droppedInnerClassMappings = Maps.newHashMap(); | 32 | this.droppedInnerClassMappings = Maps.newHashMap(); |
| 33 | m_droppedFieldMappings = Maps.newHashMap(); | 33 | this.droppedFieldMappings = Maps.newHashMap(); |
| 34 | m_droppedMethodMappings = Maps.newHashMap(); | 34 | this.droppedMethodMappings = Maps.newHashMap(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | public Map<ClassEntry, ClassMapping> getDroppedClassMappings() { | 37 | public Map<ClassEntry, ClassMapping> getDroppedClassMappings() { |
| 38 | return m_droppedClassMappings; | 38 | return this.droppedClassMappings; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public Map<ClassEntry, ClassMapping> getDroppedInnerClassMappings() { | 41 | public Map<ClassEntry, ClassMapping> getDroppedInnerClassMappings() { |
| 42 | return m_droppedInnerClassMappings; | 42 | return this.droppedInnerClassMappings; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public Map<FieldEntry, FieldMapping> getDroppedFieldMappings() { | 45 | public Map<FieldEntry, FieldMapping> getDroppedFieldMappings() { |
| 46 | return m_droppedFieldMappings; | 46 | return this.droppedFieldMappings; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | public Map<BehaviorEntry, MethodMapping> getDroppedMethodMappings() { | 49 | public Map<BehaviorEntry, MethodMapping> getDroppedMethodMappings() { |
| 50 | return m_droppedMethodMappings; | 50 | return this.droppedMethodMappings; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | public void dropBrokenMappings(Mappings mappings) { | 53 | public void dropBrokenMappings(Mappings mappings) { |
| 54 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { | 54 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { |
| 55 | if (!checkClassMapping(classMapping)) { | 55 | if (!checkClassMapping(classMapping)) { |
| 56 | mappings.removeClassMapping(classMapping); | 56 | mappings.removeClassMapping(classMapping); |
| 57 | m_droppedClassMappings.put(EntryFactory.getObfClassEntry(m_index, classMapping), classMapping); | 57 | this.droppedClassMappings.put(EntryFactory.getObfClassEntry(this.index, classMapping), classMapping); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| @@ -62,26 +62,26 @@ public class MappingsChecker { | |||
| 62 | private boolean checkClassMapping(ClassMapping classMapping) { | 62 | private boolean checkClassMapping(ClassMapping classMapping) { |
| 63 | 63 | ||
| 64 | // check the class | 64 | // check the class |
| 65 | ClassEntry classEntry = EntryFactory.getObfClassEntry(m_index, classMapping); | 65 | ClassEntry classEntry = EntryFactory.getObfClassEntry(this.index, classMapping); |
| 66 | if (!m_index.getObfClassEntries().contains(classEntry)) { | 66 | if (!this.index.getObfClassEntries().contains(classEntry)) { |
| 67 | return false; | 67 | return false; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | // check the fields | 70 | // check the fields |
| 71 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | 71 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { |
| 72 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); | 72 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); |
| 73 | if (!m_index.containsObfField(obfFieldEntry)) { | 73 | if (!this.index.containsObfField(obfFieldEntry)) { |
| 74 | classMapping.removeFieldMapping(fieldMapping); | 74 | classMapping.removeFieldMapping(fieldMapping); |
| 75 | m_droppedFieldMappings.put(obfFieldEntry, fieldMapping); | 75 | this.droppedFieldMappings.put(obfFieldEntry, fieldMapping); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // check methods | 79 | // check methods |
| 80 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | 80 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { |
| 81 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | 81 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); |
| 82 | if (!m_index.containsObfBehavior(obfBehaviorEntry)) { | 82 | if (!this.index.containsObfBehavior(obfBehaviorEntry)) { |
| 83 | classMapping.removeMethodMapping(methodMapping); | 83 | classMapping.removeMethodMapping(methodMapping); |
| 84 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | 84 | this.droppedMethodMappings.put(obfBehaviorEntry, methodMapping); |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| @@ -89,7 +89,7 @@ public class MappingsChecker { | |||
| 89 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | 89 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { |
| 90 | if (!checkClassMapping(innerClassMapping)) { | 90 | if (!checkClassMapping(innerClassMapping)) { |
| 91 | classMapping.removeInnerClassMapping(innerClassMapping); | 91 | classMapping.removeInnerClassMapping(innerClassMapping); |
| 92 | m_droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(m_index, innerClassMapping), innerClassMapping); | 92 | this.droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(this.index, innerClassMapping), innerClassMapping); |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index 7aedc5b..b2b6d09 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -20,17 +20,17 @@ import java.io.FileReader; | |||
| 20 | import java.io.IOException; | 20 | import java.io.IOException; |
| 21 | 21 | ||
| 22 | import cuchaz.enigma.json.JsonClass; | 22 | import cuchaz.enigma.json.JsonClass; |
| 23 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 23 | 24 | ||
| 24 | public class MappingsReader { | 25 | public class MappingsReader { |
| 25 | 26 | ||
| 26 | public Mappings read(File in) throws IOException, MappingParseException { | 27 | public Mappings read(File in) throws IOException { |
| 27 | Mappings mappings = new Mappings(); | 28 | Mappings mappings = new Mappings(); |
| 28 | readDirectory(mappings, in); | 29 | readDirectory(mappings, in); |
| 29 | return mappings; | 30 | return mappings; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | public void readDirectory(Mappings mappings, File in) throws IOException, MappingParseException { | 33 | public void readDirectory(Mappings mappings, File in) throws IOException { |
| 33 | |||
| 34 | File[] fList = in.listFiles(); | 34 | File[] fList = in.listFiles(); |
| 35 | if (fList != null) { | 35 | if (fList != null) { |
| 36 | for (File file : fList) { | 36 | for (File file : fList) { |
| @@ -43,8 +43,7 @@ public class MappingsReader { | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { | 46 | public void readFile(Mappings mappings, BufferedReader in) throws IOException { |
| 47 | |||
| 48 | StringBuilder buf = new StringBuilder(); | 47 | StringBuilder buf = new StringBuilder(); |
| 49 | String line; | 48 | String line; |
| 50 | while ((line = in.readLine()) != null) { | 49 | while ((line = in.readLine()) != null) { |
| @@ -53,11 +52,15 @@ public class MappingsReader { | |||
| 53 | 52 | ||
| 54 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 53 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
| 55 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); | 54 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); |
| 56 | load(null, jsonClass, mappings); | 55 | try { |
| 56 | load(null, jsonClass, mappings); | ||
| 57 | } catch (MappingConflict e) { | ||
| 58 | e.printStackTrace(); | ||
| 59 | } | ||
| 57 | in.close(); | 60 | in.close(); |
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | public void load(ClassMapping parent, JsonClass jsonClass, Mappings mappings) { | 63 | public void load(ClassMapping parent, JsonClass jsonClass, Mappings mappings) throws MappingConflict { |
| 61 | ClassMapping classMapping = readClass(jsonClass.getObf(), jsonClass.getName()); | 64 | ClassMapping classMapping = readClass(jsonClass.getObf(), jsonClass.getName()); |
| 62 | if (parent != null) { | 65 | if (parent != null) { |
| 63 | parent.addInnerClassMapping(classMapping); | 66 | parent.addInnerClassMapping(classMapping); |
| @@ -68,17 +71,35 @@ public class MappingsReader { | |||
| 68 | 71 | ||
| 69 | jsonClass.getConstructors().forEach(jsonConstructor -> { | 72 | jsonClass.getConstructors().forEach(jsonConstructor -> { |
| 70 | MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "<clinit>" : "<init>", null, jsonConstructor.getSignature()); | 73 | MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "<clinit>" : "<init>", null, jsonConstructor.getSignature()); |
| 71 | jsonConstructor.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); | 74 | jsonConstructor.getArgs().forEach(jsonArgument -> { |
| 75 | try { | ||
| 76 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 77 | } catch (MappingConflict e) { | ||
| 78 | e.printStackTrace(); | ||
| 79 | } | ||
| 80 | }); | ||
| 72 | classMapping.addMethodMapping(methodMapping); | 81 | classMapping.addMethodMapping(methodMapping); |
| 73 | }); | 82 | }); |
| 74 | 83 | ||
| 75 | jsonClass.getMethod().forEach(jsonMethod -> { | 84 | jsonClass.getMethod().forEach(jsonMethod -> { |
| 76 | MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); | 85 | MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); |
| 77 | jsonMethod.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); | 86 | jsonMethod.getArgs().forEach(jsonArgument -> { |
| 87 | try { | ||
| 88 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 89 | } catch (MappingConflict e) { | ||
| 90 | e.printStackTrace(); | ||
| 91 | } | ||
| 92 | }); | ||
| 78 | classMapping.addMethodMapping(methodMapping); | 93 | classMapping.addMethodMapping(methodMapping); |
| 79 | }); | 94 | }); |
| 80 | 95 | ||
| 81 | jsonClass.getInnerClass().forEach(jsonInnerClasses -> load(classMapping, jsonInnerClasses, mappings)); | 96 | jsonClass.getInnerClass().forEach(jsonInnerClasses -> { |
| 97 | try { | ||
| 98 | load(classMapping, jsonInnerClasses, mappings); | ||
| 99 | } catch (MappingConflict e) { | ||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | }); | ||
| 82 | } | 103 | } |
| 83 | 104 | ||
| 84 | private ArgumentMapping readArgument(int index, String name) { | 105 | private ArgumentMapping readArgument(int index, String name) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java index ed36d42..776d908 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java | |||
| @@ -7,6 +7,9 @@ import java.io.IOException; | |||
| 7 | import java.io.Reader; | 7 | import java.io.Reader; |
| 8 | import java.util.Deque; | 8 | import java.util.Deque; |
| 9 | 9 | ||
| 10 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 11 | import cuchaz.enigma.throwables.MappingParseException; | ||
| 12 | |||
| 10 | public class MappingsReaderOld { | 13 | public class MappingsReaderOld { |
| 11 | 14 | ||
| 12 | public Mappings read(Reader in) throws IOException, MappingParseException { | 15 | public Mappings read(Reader in) throws IOException, MappingParseException { |
| @@ -89,6 +92,8 @@ public class MappingsReaderOld { | |||
| 89 | } | 92 | } |
| 90 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { | 93 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { |
| 91 | throw new MappingParseException(lineNumber, "Malformed line:\n" + line); | 94 | throw new MappingParseException(lineNumber, "Malformed line:\n" + line); |
| 95 | } catch (MappingConflict e) { | ||
| 96 | e.printStackTrace(); | ||
| 92 | } | 97 | } |
| 93 | } | 98 | } |
| 94 | 99 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index 3050da6..afb8c97 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -10,14 +10,12 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.IOException; | ||
| 14 | import java.io.ObjectOutputStream; | ||
| 15 | import java.io.OutputStream; | ||
| 16 | import java.util.List; | 13 | import java.util.List; |
| 17 | import java.util.Set; | 14 | import java.util.Set; |
| 18 | import java.util.zip.GZIPOutputStream; | ||
| 19 | 15 | ||
| 20 | import cuchaz.enigma.analysis.JarIndex; | 16 | import cuchaz.enigma.analysis.JarIndex; |
| 17 | import cuchaz.enigma.throwables.IllegalNameException; | ||
| 18 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 21 | 19 | ||
| 22 | public class MappingsRenamer { | 20 | public class MappingsRenamer { |
| 23 | 21 | ||
| @@ -167,14 +165,6 @@ public class MappingsRenamer { | |||
| 167 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); | 165 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); |
| 168 | } | 166 | } |
| 169 | 167 | ||
| 170 | public void write(OutputStream out) throws IOException { | ||
| 171 | // TEMP: just use the object output for now. We can find a more efficient storage format later | ||
| 172 | GZIPOutputStream gzipout = new GZIPOutputStream(out); | ||
| 173 | ObjectOutputStream oout = new ObjectOutputStream(gzipout); | ||
| 174 | oout.writeObject(this); | ||
| 175 | gzipout.finish(); | ||
| 176 | } | ||
| 177 | |||
| 178 | private ClassMapping getOrCreateClassMapping(ClassEntry obfClassEntry) { | 168 | private ClassMapping getOrCreateClassMapping(ClassEntry obfClassEntry) { |
| 179 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obfClassEntry); | 169 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obfClassEntry); |
| 180 | return mappingChain.get(mappingChain.size() - 1); | 170 | return mappingChain.get(mappingChain.size() - 1); |
| @@ -193,10 +183,14 @@ public class MappingsRenamer { | |||
| 193 | mappingChain.set(i, classMapping); | 183 | mappingChain.set(i, classMapping); |
| 194 | 184 | ||
| 195 | // add it to the right parent | 185 | // add it to the right parent |
| 196 | if (i == 0) { | 186 | try { |
| 197 | m_mappings.addClassMapping(classMapping); | 187 | if (i == 0) { |
| 198 | } else { | 188 | m_mappings.addClassMapping(classMapping); |
| 199 | mappingChain.get(i - 1).addInnerClassMapping(classMapping); | 189 | } else { |
| 190 | mappingChain.get(i - 1).addInnerClassMapping(classMapping); | ||
| 191 | } | ||
| 192 | } catch (MappingConflict mappingConflict) { | ||
| 193 | mappingConflict.printStackTrace(); | ||
| 200 | } | 194 | } |
| 201 | } | 195 | } |
| 202 | } | 196 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java index 4b2db9d..4793166 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java | |||
| @@ -51,7 +51,7 @@ public class MappingsWriter { | |||
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | private void write(JsonClass jsonClass, ClassMapping classMapping) throws IOException { | 54 | private void write(JsonClass jsonClass, ClassMapping classMapping) { |
| 55 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | 55 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { |
| 56 | JsonClass innerClass = new JsonClass(classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName().replace("nome/", ""), innerClassMapping.getDeobfName()); | 56 | JsonClass innerClass = new JsonClass(classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName().replace("nome/", ""), innerClassMapping.getDeobfName()); |
| 57 | write(innerClass, innerClassMapping); | 57 | write(innerClass, innerClassMapping); |
| @@ -85,19 +85,18 @@ public class MappingsWriter { | |||
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | public static boolean deleteDirectory(File directory) { | 87 | public static boolean deleteDirectory(File directory) { |
| 88 | if(directory.exists()){ | 88 | if (directory.exists()) { |
| 89 | File[] files = directory.listFiles(); | 89 | File[] files = directory.listFiles(); |
| 90 | if(null!=files){ | 90 | if (null != files) { |
| 91 | for(int i=0; i<files.length; i++) { | 91 | for (int i = 0; i < files.length; i++) { |
| 92 | if(files[i].isDirectory()) { | 92 | if (files[i].isDirectory()) { |
| 93 | deleteDirectory(files[i]); | 93 | deleteDirectory(files[i]); |
| 94 | } | 94 | } else { |
| 95 | else { | ||
| 96 | files[i].delete(); | 95 | files[i].delete(); |
| 97 | } | 96 | } |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | } | 99 | } |
| 101 | return(directory.delete()); | 100 | return (directory.delete()); |
| 102 | } | 101 | } |
| 103 | } | 102 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MemberMapping.java b/src/main/java/cuchaz/enigma/mapping/MemberMapping.java index 90c096f..590c830 100644 --- a/src/main/java/cuchaz/enigma/mapping/MemberMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MemberMapping.java | |||
| @@ -12,7 +12,5 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | public interface MemberMapping<T extends Entry> { | 14 | public interface MemberMapping<T extends Entry> { |
| 15 | T getObfEntry(ClassEntry classEntry); | ||
| 16 | |||
| 17 | String getObfName(); | 15 | String getObfName(); |
| 18 | } | 16 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java index 7df4dd8..4d7ed8f 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java | |||
| @@ -10,17 +10,13 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.Serializable; | 13 | import cuchaz.enigma.utils.Utils; |
| 14 | 14 | ||
| 15 | import cuchaz.enigma.Util; | 15 | public class MethodEntry implements BehaviorEntry { |
| 16 | 16 | ||
| 17 | public class MethodEntry implements BehaviorEntry, Serializable { | 17 | private ClassEntry classEntry; |
| 18 | 18 | private String name; | |
| 19 | private static final long serialVersionUID = 4770915224467247458L; | 19 | private Signature signature; |
| 20 | |||
| 21 | private ClassEntry m_classEntry; | ||
| 22 | private String m_name; | ||
| 23 | private Signature m_signature; | ||
| 24 | 20 | ||
| 25 | public MethodEntry(ClassEntry classEntry, String name, Signature signature) { | 21 | public MethodEntry(ClassEntry classEntry, String name, Signature signature) { |
| 26 | if (classEntry == null) { | 22 | if (classEntry == null) { |
| @@ -36,41 +32,35 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 36 | throw new IllegalArgumentException("Don't use MethodEntry for a constructor!"); | 32 | throw new IllegalArgumentException("Don't use MethodEntry for a constructor!"); |
| 37 | } | 33 | } |
| 38 | 34 | ||
| 39 | m_classEntry = classEntry; | 35 | this.classEntry = classEntry; |
| 40 | m_name = name; | 36 | this.name = name; |
| 41 | m_signature = signature; | 37 | this.signature = signature; |
| 42 | } | ||
| 43 | |||
| 44 | public MethodEntry(MethodEntry other) { | ||
| 45 | m_classEntry = new ClassEntry(other.m_classEntry); | ||
| 46 | m_name = other.m_name; | ||
| 47 | m_signature = other.m_signature; | ||
| 48 | } | 38 | } |
| 49 | 39 | ||
| 50 | public MethodEntry(MethodEntry other, String newClassName) { | 40 | public MethodEntry(MethodEntry other, String newClassName) { |
| 51 | m_classEntry = new ClassEntry(newClassName); | 41 | this.classEntry = new ClassEntry(newClassName); |
| 52 | m_name = other.m_name; | 42 | this.name = other.name; |
| 53 | m_signature = other.m_signature; | 43 | this.signature = other.signature; |
| 54 | } | 44 | } |
| 55 | 45 | ||
| 56 | @Override | 46 | @Override |
| 57 | public ClassEntry getClassEntry() { | 47 | public ClassEntry getClassEntry() { |
| 58 | return m_classEntry; | 48 | return this.classEntry; |
| 59 | } | 49 | } |
| 60 | 50 | ||
| 61 | @Override | 51 | @Override |
| 62 | public String getName() { | 52 | public String getName() { |
| 63 | return m_name; | 53 | return this.name; |
| 64 | } | 54 | } |
| 65 | 55 | ||
| 66 | @Override | 56 | @Override |
| 67 | public Signature getSignature() { | 57 | public Signature getSignature() { |
| 68 | return m_signature; | 58 | return this.signature; |
| 69 | } | 59 | } |
| 70 | 60 | ||
| 71 | @Override | 61 | @Override |
| 72 | public String getClassName() { | 62 | public String getClassName() { |
| 73 | return m_classEntry.getName(); | 63 | return this.classEntry.getName(); |
| 74 | } | 64 | } |
| 75 | 65 | ||
| 76 | @Override | 66 | @Override |
| @@ -80,7 +70,7 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 80 | 70 | ||
| 81 | @Override | 71 | @Override |
| 82 | public int hashCode() { | 72 | public int hashCode() { |
| 83 | return Util.combineHashesOrdered(m_classEntry, m_name, m_signature); | 73 | return Utils.combineHashesOrdered(this.classEntry, this.name, this.signature); |
| 84 | } | 74 | } |
| 85 | 75 | ||
| 86 | @Override | 76 | @Override |
| @@ -89,11 +79,11 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 89 | } | 79 | } |
| 90 | 80 | ||
| 91 | public boolean equals(MethodEntry other) { | 81 | public boolean equals(MethodEntry other) { |
| 92 | return m_classEntry.equals(other.m_classEntry) && m_name.equals(other.m_name) && m_signature.equals(other.m_signature); | 82 | return this.classEntry.equals(other.classEntry) && this.name.equals(other.name) && this.signature.equals(other.signature); |
| 93 | } | 83 | } |
| 94 | 84 | ||
| 95 | @Override | 85 | @Override |
| 96 | public String toString() { | 86 | public String toString() { |
| 97 | return m_classEntry.getName() + "." + m_name + m_signature; | 87 | return this.classEntry.getName() + "." + this.name + this.signature; |
| 98 | } | 88 | } |
| 99 | } | 89 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index fbd97bd..6e7c1ef 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -12,18 +12,16 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.Map; | 15 | import java.util.Map; |
| 17 | import java.util.Map.Entry; | ||
| 18 | 16 | ||
| 19 | public class MethodMapping implements Serializable, Comparable<MethodMapping>, MemberMapping<BehaviorEntry> { | 17 | import cuchaz.enigma.throwables.MappingConflict; |
| 20 | 18 | ||
| 21 | private static final long serialVersionUID = -4409570216084263978L; | 19 | public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<BehaviorEntry> { |
| 22 | 20 | ||
| 23 | private String m_obfName; | 21 | private String obfName; |
| 24 | private String m_deobfName; | 22 | private String deobfName; |
| 25 | private Signature m_obfSignature; | 23 | private Signature obfSignature; |
| 26 | private Map<Integer, ArgumentMapping> m_arguments; | 24 | private Map<Integer, ArgumentMapping> arguments; |
| 27 | 25 | ||
| 28 | public MethodMapping(String obfName, Signature obfSignature) { | 26 | public MethodMapping(String obfName, Signature obfSignature) { |
| 29 | this(obfName, obfSignature, null); | 27 | this(obfName, obfSignature, null); |
| @@ -36,62 +34,42 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 36 | if (obfSignature == null) { | 34 | if (obfSignature == null) { |
| 37 | throw new IllegalArgumentException("obf signature cannot be null!"); | 35 | throw new IllegalArgumentException("obf signature cannot be null!"); |
| 38 | } | 36 | } |
| 39 | this.m_obfName = obfName; | 37 | this.obfName = obfName; |
| 40 | this.m_deobfName = NameValidator.validateMethodName(deobfName); | 38 | this.deobfName = NameValidator.validateMethodName(deobfName); |
| 41 | this.m_obfSignature = obfSignature; | 39 | this.obfSignature = obfSignature; |
| 42 | this.m_arguments = Maps.newTreeMap(); | 40 | this.arguments = Maps.newTreeMap(); |
| 43 | } | ||
| 44 | |||
| 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { | ||
| 46 | this.m_obfName = other.m_obfName; | ||
| 47 | this.m_deobfName = other.m_deobfName; | ||
| 48 | this.m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); | ||
| 49 | this.m_arguments = Maps.newTreeMap(); | ||
| 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { | ||
| 51 | this.m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); | ||
| 52 | } | ||
| 53 | } | 41 | } |
| 54 | 42 | ||
| 55 | @Override | 43 | @Override |
| 56 | public String getObfName() { | 44 | public String getObfName() { |
| 57 | return this.m_obfName; | 45 | return this.obfName; |
| 58 | } | ||
| 59 | |||
| 60 | public void setObfName(String val) { | ||
| 61 | this.m_obfName = NameValidator.validateMethodName(val); | ||
| 62 | } | 46 | } |
| 63 | 47 | ||
| 64 | public String getDeobfName() { | 48 | public String getDeobfName() { |
| 65 | return this.m_deobfName; | 49 | return this.deobfName; |
| 66 | } | 50 | } |
| 67 | 51 | ||
| 68 | public void setDeobfName(String val) { | 52 | public void setDeobfName(String val) { |
| 69 | this.m_deobfName = NameValidator.validateMethodName(val); | 53 | this.deobfName = NameValidator.validateMethodName(val); |
| 70 | } | 54 | } |
| 71 | 55 | ||
| 72 | public Signature getObfSignature() { | 56 | public Signature getObfSignature() { |
| 73 | return this.m_obfSignature; | 57 | return this.obfSignature; |
| 74 | } | ||
| 75 | |||
| 76 | public void setObfSignature(Signature val) { | ||
| 77 | this.m_obfSignature = val; | ||
| 78 | } | 58 | } |
| 79 | 59 | ||
| 80 | public Iterable<ArgumentMapping> arguments() { | 60 | public Iterable<ArgumentMapping> arguments() { |
| 81 | return this.m_arguments.values(); | 61 | return this.arguments.values(); |
| 82 | } | 62 | } |
| 83 | 63 | ||
| 84 | public boolean isConstructor() { | 64 | public void addArgumentMapping(ArgumentMapping argumentMapping) throws MappingConflict { |
| 85 | return this.m_obfName.startsWith("<"); | 65 | if (this.arguments.containsKey(argumentMapping.getIndex())) { |
| 86 | } | 66 | throw new MappingConflict("argument", argumentMapping.getName(), this.arguments.get(argumentMapping.getIndex()).getName()); |
| 87 | 67 | } | |
| 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { | 68 | this.arguments.put(argumentMapping.getIndex(), argumentMapping); |
| 89 | boolean wasAdded = this.m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; | ||
| 90 | assert (wasAdded); | ||
| 91 | } | 69 | } |
| 92 | 70 | ||
| 93 | public String getObfArgumentName(int index) { | 71 | public String getObfArgumentName(int index) { |
| 94 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 72 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 95 | if (argumentMapping != null) { | 73 | if (argumentMapping != null) { |
| 96 | return argumentMapping.getName(); | 74 | return argumentMapping.getName(); |
| 97 | } | 75 | } |
| @@ -100,7 +78,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 100 | } | 78 | } |
| 101 | 79 | ||
| 102 | public String getDeobfArgumentName(int index) { | 80 | public String getDeobfArgumentName(int index) { |
| 103 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 81 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 104 | if (argumentMapping != null) { | 82 | if (argumentMapping != null) { |
| 105 | return argumentMapping.getName(); | 83 | return argumentMapping.getName(); |
| 106 | } | 84 | } |
| @@ -109,10 +87,10 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 109 | } | 87 | } |
| 110 | 88 | ||
| 111 | public void setArgumentName(int index, String name) { | 89 | public void setArgumentName(int index, String name) { |
| 112 | ArgumentMapping argumentMapping = this.m_arguments.get(index); | 90 | ArgumentMapping argumentMapping = this.arguments.get(index); |
| 113 | if (argumentMapping == null) { | 91 | if (argumentMapping == null) { |
| 114 | argumentMapping = new ArgumentMapping(index, name); | 92 | argumentMapping = new ArgumentMapping(index, name); |
| 115 | boolean wasAdded = this.m_arguments.put(index, argumentMapping) == null; | 93 | boolean wasAdded = this.arguments.put(index, argumentMapping) == null; |
| 116 | assert (wasAdded); | 94 | assert (wasAdded); |
| 117 | } else { | 95 | } else { |
| 118 | argumentMapping.setName(name); | 96 | argumentMapping.setName(name); |
| @@ -120,7 +98,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 120 | } | 98 | } |
| 121 | 99 | ||
| 122 | public void removeArgumentName(int index) { | 100 | public void removeArgumentName(int index) { |
| 123 | boolean wasRemoved = this.m_arguments.remove(index) != null; | 101 | boolean wasRemoved = this.arguments.remove(index) != null; |
| 124 | assert (wasRemoved); | 102 | assert (wasRemoved); |
| 125 | } | 103 | } |
| 126 | 104 | ||
| @@ -128,15 +106,15 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 128 | public String toString() { | 106 | public String toString() { |
| 129 | StringBuilder buf = new StringBuilder(); | 107 | StringBuilder buf = new StringBuilder(); |
| 130 | buf.append("\t"); | 108 | buf.append("\t"); |
| 131 | buf.append(m_obfName); | 109 | buf.append(this.obfName); |
| 132 | buf.append(" <-> "); | 110 | buf.append(" <-> "); |
| 133 | buf.append(m_deobfName); | 111 | buf.append(this.deobfName); |
| 134 | buf.append("\n"); | 112 | buf.append("\n"); |
| 135 | buf.append("\t"); | 113 | buf.append("\t"); |
| 136 | buf.append(m_obfSignature); | 114 | buf.append(this.obfSignature); |
| 137 | buf.append("\n"); | 115 | buf.append("\n"); |
| 138 | buf.append("\tArguments:\n"); | 116 | buf.append("\tArguments:\n"); |
| 139 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { | 117 | for (ArgumentMapping argumentMapping : this.arguments.values()) { |
| 140 | buf.append("\t\t"); | 118 | buf.append("\t\t"); |
| 141 | buf.append(argumentMapping.getIndex()); | 119 | buf.append(argumentMapping.getIndex()); |
| 142 | buf.append(" -> "); | 120 | buf.append(" -> "); |
| @@ -148,24 +126,15 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 148 | 126 | ||
| 149 | @Override | 127 | @Override |
| 150 | public int compareTo(MethodMapping other) { | 128 | public int compareTo(MethodMapping other) { |
| 151 | return (this.m_obfName + this.m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); | 129 | return (this.obfName + this.obfSignature).compareTo(other.obfName + other.obfSignature); |
| 152 | } | 130 | } |
| 153 | 131 | ||
| 154 | public boolean containsArgument(String name) { | 132 | public boolean containsArgument(String name) { |
| 155 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { | 133 | for (ArgumentMapping argumentMapping : this.arguments.values()) { |
| 156 | if (argumentMapping.getName().equals(name)) { | 134 | if (argumentMapping.getName().equals(name)) { |
| 157 | return true; | 135 | return true; |
| 158 | } | 136 | } |
| 159 | } | 137 | } |
| 160 | return false; | 138 | return false; |
| 161 | } | 139 | } |
| 162 | |||
| 163 | @Override | ||
| 164 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { | ||
| 165 | if (isConstructor()) { | ||
| 166 | return new ConstructorEntry(classEntry, this.m_obfSignature); | ||
| 167 | } else { | ||
| 168 | return new MethodEntry(classEntry, this.m_obfName, this.m_obfSignature); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | 140 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/NameValidator.java b/src/main/java/cuchaz/enigma/mapping/NameValidator.java index f416322..15b0314 100644 --- a/src/main/java/cuchaz/enigma/mapping/NameValidator.java +++ b/src/main/java/cuchaz/enigma/mapping/NameValidator.java | |||
| @@ -14,6 +14,7 @@ import java.util.Arrays; | |||
| 14 | import java.util.List; | 14 | import java.util.List; |
| 15 | import java.util.regex.Pattern; | 15 | import java.util.regex.Pattern; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.throwables.IllegalNameException; | ||
| 17 | import javassist.bytecode.Descriptor; | 18 | import javassist.bytecode.Descriptor; |
| 18 | 19 | ||
| 19 | public class NameValidator { | 20 | public class NameValidator { |
diff --git a/src/main/java/cuchaz/enigma/mapping/ProcyonEntryFactory.java b/src/main/java/cuchaz/enigma/mapping/ProcyonEntryFactory.java index ac42499..26e554b 100644 --- a/src/main/java/cuchaz/enigma/mapping/ProcyonEntryFactory.java +++ b/src/main/java/cuchaz/enigma/mapping/ProcyonEntryFactory.java | |||
| @@ -13,35 +13,21 @@ package cuchaz.enigma.mapping; | |||
| 13 | import com.strobel.assembler.metadata.FieldDefinition; | 13 | import com.strobel.assembler.metadata.FieldDefinition; |
| 14 | import com.strobel.assembler.metadata.MethodDefinition; | 14 | import com.strobel.assembler.metadata.MethodDefinition; |
| 15 | 15 | ||
| 16 | |||
| 17 | public class ProcyonEntryFactory { | 16 | public class ProcyonEntryFactory { |
| 18 | 17 | ||
| 19 | public static FieldEntry getFieldEntry(FieldDefinition def) { | 18 | public static FieldEntry getFieldEntry(FieldDefinition def) { |
| 20 | return new FieldEntry( | 19 | return new FieldEntry(new ClassEntry(def.getDeclaringType().getInternalName()), def.getName(), new Type(def.getErasedSignature())); |
| 21 | new ClassEntry(def.getDeclaringType().getInternalName()), | ||
| 22 | def.getName(), | ||
| 23 | new Type(def.getErasedSignature()) | ||
| 24 | ); | ||
| 25 | } | 20 | } |
| 26 | 21 | ||
| 27 | public static MethodEntry getMethodEntry(MethodDefinition def) { | 22 | public static MethodEntry getMethodEntry(MethodDefinition def) { |
| 28 | return new MethodEntry( | 23 | return new MethodEntry(new ClassEntry(def.getDeclaringType().getInternalName()), def.getName(), new Signature(def.getErasedSignature())); |
| 29 | new ClassEntry(def.getDeclaringType().getInternalName()), | ||
| 30 | def.getName(), | ||
| 31 | new Signature(def.getErasedSignature()) | ||
| 32 | ); | ||
| 33 | } | 24 | } |
| 34 | 25 | ||
| 35 | public static ConstructorEntry getConstructorEntry(MethodDefinition def) { | 26 | public static ConstructorEntry getConstructorEntry(MethodDefinition def) { |
| 36 | if (def.isTypeInitializer()) { | 27 | if (def.isTypeInitializer()) { |
| 37 | return new ConstructorEntry( | 28 | return new ConstructorEntry(new ClassEntry(def.getDeclaringType().getInternalName())); |
| 38 | new ClassEntry(def.getDeclaringType().getInternalName()) | ||
| 39 | ); | ||
| 40 | } else { | 29 | } else { |
| 41 | return new ConstructorEntry( | 30 | return new ConstructorEntry(new ClassEntry(def.getDeclaringType().getInternalName()), new Signature(def.getErasedSignature())); |
| 42 | new ClassEntry(def.getDeclaringType().getInternalName()), | ||
| 43 | new Signature(def.getErasedSignature()) | ||
| 44 | ); | ||
| 45 | } | 31 | } |
| 46 | } | 32 | } |
| 47 | 33 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java index e2f9f09..f30b606 100644 --- a/src/main/java/cuchaz/enigma/mapping/Signature.java +++ b/src/main/java/cuchaz/enigma/mapping/Signature.java | |||
| @@ -12,80 +12,72 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Lists; | 13 | import com.google.common.collect.Lists; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.List; | 15 | import java.util.List; |
| 17 | 16 | ||
| 18 | import cuchaz.enigma.Util; | 17 | import cuchaz.enigma.utils.Utils; |
| 19 | 18 | ||
| 20 | public class Signature implements Serializable { | 19 | public class Signature { |
| 21 | 20 | ||
| 22 | private static final long serialVersionUID = -5843719505729497539L; | 21 | private List<Type> argumentTypes; |
| 23 | 22 | private Type returnType; | |
| 24 | private List<Type> m_argumentTypes; | ||
| 25 | private Type m_returnType; | ||
| 26 | 23 | ||
| 27 | public Signature(String signature) { | 24 | public Signature(String signature) { |
| 28 | try { | 25 | try { |
| 29 | m_argumentTypes = Lists.newArrayList(); | 26 | this.argumentTypes = Lists.newArrayList(); |
| 30 | int i = 0; | 27 | int i = 0; |
| 31 | while (i < signature.length()) { | 28 | while (i < signature.length()) { |
| 32 | char c = signature.charAt(i); | 29 | char c = signature.charAt(i); |
| 33 | if (c == '(') { | 30 | if (c == '(') { |
| 34 | assert (m_argumentTypes.isEmpty()); | 31 | assert (this.argumentTypes.isEmpty()); |
| 35 | assert (m_returnType == null); | 32 | assert (this.returnType == null); |
| 36 | i++; | 33 | i++; |
| 37 | } else if (c == ')') { | 34 | } else if (c == ')') { |
| 38 | i++; | 35 | i++; |
| 39 | break; | 36 | break; |
| 40 | } else { | 37 | } else { |
| 41 | String type = Type.parseFirst(signature.substring(i)); | 38 | String type = Type.parseFirst(signature.substring(i)); |
| 42 | m_argumentTypes.add(new Type(type)); | 39 | this.argumentTypes.add(new Type(type)); |
| 43 | i += type.length(); | 40 | i += type.length(); |
| 44 | } | 41 | } |
| 45 | } | 42 | } |
| 46 | m_returnType = new Type(Type.parseFirst(signature.substring(i))); | 43 | this.returnType = new Type(Type.parseFirst(signature.substring(i))); |
| 47 | } catch (Exception ex) { | 44 | } catch (Exception ex) { |
| 48 | throw new IllegalArgumentException("Unable to parse signature: " + signature, ex); | 45 | throw new IllegalArgumentException("Unable to parse signature: " + signature, ex); |
| 49 | } | 46 | } |
| 50 | } | 47 | } |
| 51 | 48 | ||
| 52 | public Signature(Signature other) { | ||
| 53 | m_argumentTypes = Lists.newArrayList(other.m_argumentTypes); | ||
| 54 | m_returnType = new Type(other.m_returnType); | ||
| 55 | } | ||
| 56 | |||
| 57 | public Signature(Signature other, ClassNameReplacer replacer) { | 49 | public Signature(Signature other, ClassNameReplacer replacer) { |
| 58 | m_argumentTypes = Lists.newArrayList(other.m_argumentTypes); | 50 | this.argumentTypes = Lists.newArrayList(other.argumentTypes); |
| 59 | for (int i = 0; i < m_argumentTypes.size(); i++) { | 51 | for (int i = 0; i < this.argumentTypes.size(); i++) { |
| 60 | m_argumentTypes.set(i, new Type(m_argumentTypes.get(i), replacer)); | 52 | this.argumentTypes.set(i, new Type(this.argumentTypes.get(i), replacer)); |
| 61 | } | 53 | } |
| 62 | m_returnType = new Type(other.m_returnType, replacer); | 54 | this.returnType = new Type(other.returnType, replacer); |
| 63 | } | 55 | } |
| 64 | 56 | ||
| 65 | public List<Type> getArgumentTypes() { | 57 | public List<Type> getArgumentTypes() { |
| 66 | return m_argumentTypes; | 58 | return this.argumentTypes; |
| 67 | } | 59 | } |
| 68 | 60 | ||
| 69 | public Type getReturnType() { | 61 | public Type getReturnType() { |
| 70 | return m_returnType; | 62 | return this.returnType; |
| 71 | } | 63 | } |
| 72 | 64 | ||
| 73 | @Override | 65 | @Override |
| 74 | public String toString() { | 66 | public String toString() { |
| 75 | StringBuilder buf = new StringBuilder(); | 67 | StringBuilder buf = new StringBuilder(); |
| 76 | buf.append("("); | 68 | buf.append("("); |
| 77 | for (Type type : m_argumentTypes) { | 69 | for (Type type : this.argumentTypes) { |
| 78 | buf.append(type.toString()); | 70 | buf.append(type.toString()); |
| 79 | } | 71 | } |
| 80 | buf.append(")"); | 72 | buf.append(")"); |
| 81 | buf.append(m_returnType.toString()); | 73 | buf.append(this.returnType.toString()); |
| 82 | return buf.toString(); | 74 | return buf.toString(); |
| 83 | } | 75 | } |
| 84 | 76 | ||
| 85 | public Iterable<Type> types() { | 77 | public Iterable<Type> types() { |
| 86 | List<Type> types = Lists.newArrayList(); | 78 | List<Type> types = Lists.newArrayList(); |
| 87 | types.addAll(m_argumentTypes); | 79 | types.addAll(this.argumentTypes); |
| 88 | types.add(m_returnType); | 80 | types.add(this.returnType); |
| 89 | return types; | 81 | return types; |
| 90 | } | 82 | } |
| 91 | 83 | ||
| @@ -95,12 +87,12 @@ public class Signature implements Serializable { | |||
| 95 | } | 87 | } |
| 96 | 88 | ||
| 97 | public boolean equals(Signature other) { | 89 | public boolean equals(Signature other) { |
| 98 | return m_argumentTypes.equals(other.m_argumentTypes) && m_returnType.equals(other.m_returnType); | 90 | return this.argumentTypes.equals(other.argumentTypes) && this.returnType.equals(other.returnType); |
| 99 | } | 91 | } |
| 100 | 92 | ||
| 101 | @Override | 93 | @Override |
| 102 | public int hashCode() { | 94 | public int hashCode() { |
| 103 | return Util.combineHashesOrdered(m_argumentTypes.hashCode(), m_returnType.hashCode()); | 95 | return Utils.combineHashesOrdered(this.argumentTypes.hashCode(), this.returnType.hashCode()); |
| 104 | } | 96 | } |
| 105 | 97 | ||
| 106 | public boolean hasClass(ClassEntry classEntry) { | 98 | public boolean hasClass(ClassEntry classEntry) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java deleted file mode 100644 index ec300fe..0000000 --- a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java +++ /dev/null | |||
| @@ -1,82 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import com.google.common.collect.Lists; | ||
| 14 | |||
| 15 | import java.io.IOException; | ||
| 16 | import java.io.StringReader; | ||
| 17 | import java.util.List; | ||
| 18 | |||
| 19 | public class SignatureUpdater { | ||
| 20 | |||
| 21 | public interface ClassNameUpdater { | ||
| 22 | String update(String className); | ||
| 23 | } | ||
| 24 | |||
| 25 | public static String update(String signature, ClassNameUpdater updater) { | ||
| 26 | try { | ||
| 27 | StringBuilder buf = new StringBuilder(); | ||
| 28 | |||
| 29 | // read the signature character-by-character | ||
| 30 | StringReader reader = new StringReader(signature); | ||
| 31 | int i; | ||
| 32 | while ((i = reader.read()) != -1) { | ||
| 33 | char c = (char) i; | ||
| 34 | |||
| 35 | // does this character start a class name? | ||
| 36 | if (c == 'L') { | ||
| 37 | // update the class name and add it to the buffer | ||
| 38 | buf.append('L'); | ||
| 39 | String className = readClass(reader); | ||
| 40 | if (className == null) { | ||
| 41 | throw new IllegalArgumentException("Malformed signature: " + signature); | ||
| 42 | } | ||
| 43 | buf.append(updater.update(className)); | ||
| 44 | buf.append(';'); | ||
| 45 | } else { | ||
| 46 | // copy the character into the buffer | ||
| 47 | buf.append(c); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | return buf.toString(); | ||
| 52 | } catch (IOException ex) { | ||
| 53 | // I'm pretty sure a StringReader will never throw one of these | ||
| 54 | throw new Error(ex); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | private static String readClass(StringReader reader) throws IOException { | ||
| 59 | // read all the characters in the buffer until we hit a ';' | ||
| 60 | // remember to treat generics correctly | ||
| 61 | StringBuilder buf = new StringBuilder(); | ||
| 62 | int depth = 0; | ||
| 63 | int i; | ||
| 64 | while ((i = reader.read()) != -1) { | ||
| 65 | char c = (char) i; | ||
| 66 | |||
| 67 | if (c == '<') { | ||
| 68 | depth++; | ||
| 69 | } else if (c == '>') { | ||
| 70 | depth--; | ||
| 71 | } else if (depth == 0) { | ||
| 72 | if (c == ';') { | ||
| 73 | return buf.toString(); | ||
| 74 | } else { | ||
| 75 | buf.append(c); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | return null; | ||
| 81 | } | ||
| 82 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index b0107ce..eb6a189 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java | |||
| @@ -20,22 +20,22 @@ import cuchaz.enigma.analysis.TranslationIndex; | |||
| 20 | 20 | ||
| 21 | public class Translator { | 21 | public class Translator { |
| 22 | 22 | ||
| 23 | private TranslationDirection m_direction; | 23 | private TranslationDirection direction; |
| 24 | private Map<String, ClassMapping> m_classes; | 24 | private Map<String, ClassMapping> classes; |
| 25 | private TranslationIndex m_index; | 25 | private TranslationIndex index; |
| 26 | 26 | ||
| 27 | private ClassNameReplacer m_classNameReplacer = className -> translateEntry(new ClassEntry(className)).getName(); | 27 | private ClassNameReplacer classNameReplacer = className -> translateEntry(new ClassEntry(className)).getName(); |
| 28 | 28 | ||
| 29 | public Translator() { | 29 | public Translator() { |
| 30 | m_direction = null; | 30 | this.direction = null; |
| 31 | m_classes = Maps.newHashMap(); | 31 | this.classes = Maps.newHashMap(); |
| 32 | m_index = new TranslationIndex(); | 32 | this.index = new TranslationIndex(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | public Translator(TranslationDirection direction, Map<String, ClassMapping> classes, TranslationIndex index) { | 35 | public Translator(TranslationDirection direction, Map<String, ClassMapping> classes, TranslationIndex index) { |
| 36 | m_direction = direction; | 36 | this.direction = direction; |
| 37 | m_classes = classes; | 37 | this.classes = classes; |
| 38 | m_index = index; | 38 | this.index = index; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | @SuppressWarnings("unchecked") | 41 | @SuppressWarnings("unchecked") |
| @@ -96,7 +96,7 @@ public class Translator { | |||
| 96 | String className = null; | 96 | String className = null; |
| 97 | ClassMapping classMapping = mappingsChain.get(i); | 97 | ClassMapping classMapping = mappingsChain.get(i); |
| 98 | if (classMapping != null) { | 98 | if (classMapping != null) { |
| 99 | className = m_direction.choose( | 99 | className = this.direction.choose( |
| 100 | classMapping.getDeobfName(), | 100 | classMapping.getDeobfName(), |
| 101 | isFirstClass ? classMapping.getObfFullName() : classMapping.getObfSimpleName() | 101 | isFirstClass ? classMapping.getObfFullName() : classMapping.getObfSimpleName() |
| 102 | ); | 102 | ); |
| @@ -114,11 +114,11 @@ public class Translator { | |||
| 114 | } else { | 114 | } else { |
| 115 | 115 | ||
| 116 | // normal classes are easy | 116 | // normal classes are easy |
| 117 | ClassMapping classMapping = m_classes.get(in.getName()); | 117 | ClassMapping classMapping = this.classes.get(in.getName()); |
| 118 | if (classMapping == null) { | 118 | if (classMapping == null) { |
| 119 | return in; | 119 | return in; |
| 120 | } | 120 | } |
| 121 | return m_direction.choose( | 121 | return this.direction.choose( |
| 122 | classMapping.getDeobfName() != null ? new ClassEntry(classMapping.getDeobfName()) : in, | 122 | classMapping.getDeobfName() != null ? new ClassEntry(classMapping.getDeobfName()) : in, |
| 123 | new ClassEntry(classMapping.getObfFullName()) | 123 | new ClassEntry(classMapping.getObfFullName()) |
| 124 | ); | 124 | ); |
| @@ -128,7 +128,7 @@ public class Translator { | |||
| 128 | public String translate(FieldEntry in) { | 128 | public String translate(FieldEntry in) { |
| 129 | 129 | ||
| 130 | // resolve the class entry | 130 | // resolve the class entry |
| 131 | ClassEntry resolvedClassEntry = m_index.resolveEntryClass(in); | 131 | ClassEntry resolvedClassEntry = this.index.resolveEntryClass(in); |
| 132 | if (resolvedClassEntry != null) { | 132 | if (resolvedClassEntry != null) { |
| 133 | 133 | ||
| 134 | // look for the class | 134 | // look for the class |
| @@ -136,7 +136,7 @@ public class Translator { | |||
| 136 | if (classMapping != null) { | 136 | if (classMapping != null) { |
| 137 | 137 | ||
| 138 | // look for the field | 138 | // look for the field |
| 139 | String translatedName = m_direction.choose( | 139 | String translatedName = this.direction.choose( |
| 140 | classMapping.getDeobfFieldName(in.getName(), in.getType()), | 140 | classMapping.getDeobfFieldName(in.getName(), in.getType()), |
| 141 | classMapping.getObfFieldName(in.getName(), translateType(in.getType())) | 141 | classMapping.getObfFieldName(in.getName(), translateType(in.getType())) |
| 142 | ); | 142 | ); |
| @@ -159,7 +159,7 @@ public class Translator { | |||
| 159 | public String translate(MethodEntry in) { | 159 | public String translate(MethodEntry in) { |
| 160 | 160 | ||
| 161 | // resolve the class entry | 161 | // resolve the class entry |
| 162 | ClassEntry resolvedClassEntry = m_index.resolveEntryClass(in); | 162 | ClassEntry resolvedClassEntry = this.index.resolveEntryClass(in); |
| 163 | if (resolvedClassEntry != null) { | 163 | if (resolvedClassEntry != null) { |
| 164 | 164 | ||
| 165 | // look for class | 165 | // look for class |
| @@ -167,12 +167,12 @@ public class Translator { | |||
| 167 | if (classMapping != null) { | 167 | if (classMapping != null) { |
| 168 | 168 | ||
| 169 | // look for the method | 169 | // look for the method |
| 170 | MethodMapping methodMapping = m_direction.choose( | 170 | MethodMapping methodMapping = this.direction.choose( |
| 171 | classMapping.getMethodByObf(in.getName(), in.getSignature()), | 171 | classMapping.getMethodByObf(in.getName(), in.getSignature()), |
| 172 | classMapping.getMethodByDeobf(in.getName(), translateSignature(in.getSignature())) | 172 | classMapping.getMethodByDeobf(in.getName(), translateSignature(in.getSignature())) |
| 173 | ); | 173 | ); |
| 174 | if (methodMapping != null) { | 174 | if (methodMapping != null) { |
| 175 | return m_direction.choose(methodMapping.getDeobfName(), methodMapping.getObfName()); | 175 | return this.direction.choose(methodMapping.getDeobfName(), methodMapping.getObfName()); |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
| 178 | } | 178 | } |
| @@ -211,12 +211,12 @@ public class Translator { | |||
| 211 | if (classMapping != null) { | 211 | if (classMapping != null) { |
| 212 | 212 | ||
| 213 | // look for the method | 213 | // look for the method |
| 214 | MethodMapping methodMapping = m_direction.choose( | 214 | MethodMapping methodMapping = this.direction.choose( |
| 215 | classMapping.getMethodByObf(in.getMethodName(), in.getMethodSignature()), | 215 | classMapping.getMethodByObf(in.getMethodName(), in.getMethodSignature()), |
| 216 | classMapping.getMethodByDeobf(in.getMethodName(), translateSignature(in.getMethodSignature())) | 216 | classMapping.getMethodByDeobf(in.getMethodName(), translateSignature(in.getMethodSignature())) |
| 217 | ); | 217 | ); |
| 218 | if (methodMapping != null) { | 218 | if (methodMapping != null) { |
| 219 | return m_direction.choose( | 219 | return this.direction.choose( |
| 220 | methodMapping.getDeobfArgumentName(in.getIndex()), | 220 | methodMapping.getDeobfArgumentName(in.getIndex()), |
| 221 | methodMapping.getObfArgumentName(in.getIndex()) | 221 | methodMapping.getObfArgumentName(in.getIndex()) |
| 222 | ); | 222 | ); |
| @@ -234,11 +234,11 @@ public class Translator { | |||
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | public Type translateType(Type type) { | 236 | public Type translateType(Type type) { |
| 237 | return new Type(type, m_classNameReplacer); | 237 | return new Type(type, this.classNameReplacer); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | public Signature translateSignature(Signature signature) { | 240 | public Signature translateSignature(Signature signature) { |
| 241 | return new Signature(signature, m_classNameReplacer); | 241 | return new Signature(signature, this.classNameReplacer); |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | private ClassMapping findClassMapping(ClassEntry in) { | 244 | private ClassMapping findClassMapping(ClassEntry in) { |
| @@ -253,7 +253,7 @@ public class Translator { | |||
| 253 | List<ClassMapping> mappingsChain = Lists.newArrayList(); | 253 | List<ClassMapping> mappingsChain = Lists.newArrayList(); |
| 254 | 254 | ||
| 255 | // get mappings for the outer class | 255 | // get mappings for the outer class |
| 256 | ClassMapping outerClassMapping = m_classes.get(parts[0]); | 256 | ClassMapping outerClassMapping = this.classes.get(parts[0]); |
| 257 | mappingsChain.add(outerClassMapping); | 257 | mappingsChain.add(outerClassMapping); |
| 258 | 258 | ||
| 259 | for (int i = 1; i < parts.length; i++) { | 259 | for (int i = 1; i < parts.length; i++) { |
| @@ -261,7 +261,7 @@ public class Translator { | |||
| 261 | // get mappings for the inner class | 261 | // get mappings for the inner class |
| 262 | ClassMapping innerClassMapping = null; | 262 | ClassMapping innerClassMapping = null; |
| 263 | if (outerClassMapping != null) { | 263 | if (outerClassMapping != null) { |
| 264 | innerClassMapping = m_direction.choose( | 264 | innerClassMapping = this.direction.choose( |
| 265 | outerClassMapping.getInnerClassByObfSimple(parts[i]), | 265 | outerClassMapping.getInnerClassByObfSimple(parts[i]), |
| 266 | outerClassMapping.getInnerClassByDeobfThenObfSimple(parts[i]) | 266 | outerClassMapping.getInnerClassByDeobfThenObfSimple(parts[i]) |
| 267 | ); | 267 | ); |
diff --git a/src/main/java/cuchaz/enigma/mapping/Type.java b/src/main/java/cuchaz/enigma/mapping/Type.java index ec15941..34ddc05 100644 --- a/src/main/java/cuchaz/enigma/mapping/Type.java +++ b/src/main/java/cuchaz/enigma/mapping/Type.java | |||
| @@ -12,12 +12,9 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.io.Serializable; | ||
| 16 | import java.util.Map; | 15 | import java.util.Map; |
| 17 | 16 | ||
| 18 | public class Type implements Serializable { | 17 | public class Type { |
| 19 | |||
| 20 | private static final long serialVersionUID = 7862257669347104063L; | ||
| 21 | 18 | ||
| 22 | public enum Primitive { | 19 | public enum Primitive { |
| 23 | Byte('B'), | 20 | Byte('B'), |
| @@ -29,27 +26,27 @@ public class Type implements Serializable { | |||
| 29 | Double('D'), | 26 | Double('D'), |
| 30 | Boolean('Z'); | 27 | Boolean('Z'); |
| 31 | 28 | ||
| 32 | private static final Map<Character, Primitive> m_lookup; | 29 | private static final Map<Character, Primitive> lookup; |
| 33 | 30 | ||
| 34 | static { | 31 | static { |
| 35 | m_lookup = Maps.newTreeMap(); | 32 | lookup = Maps.newTreeMap(); |
| 36 | for (Primitive val : values()) { | 33 | for (Primitive val : values()) { |
| 37 | m_lookup.put(val.getCode(), val); | 34 | lookup.put(val.getCode(), val); |
| 38 | } | 35 | } |
| 39 | } | 36 | } |
| 40 | 37 | ||
| 41 | public static Primitive get(char code) { | 38 | public static Primitive get(char code) { |
| 42 | return m_lookup.get(code); | 39 | return lookup.get(code); |
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | private char m_code; | 42 | private char code; |
| 46 | 43 | ||
| 47 | Primitive(char code) { | 44 | Primitive(char code) { |
| 48 | m_code = code; | 45 | this.code = code; |
| 49 | } | 46 | } |
| 50 | 47 | ||
| 51 | public char getCode() { | 48 | public char getCode() { |
| 52 | return m_code; | 49 | return this.code; |
| 53 | } | 50 | } |
| 54 | } | 51 | } |
| 55 | 52 | ||
| @@ -94,7 +91,7 @@ public class Type implements Serializable { | |||
| 94 | throw new IllegalArgumentException("don't know how to parse: " + in); | 91 | throw new IllegalArgumentException("don't know how to parse: " + in); |
| 95 | } | 92 | } |
| 96 | 93 | ||
| 97 | protected String m_name; | 94 | protected String name; |
| 98 | 95 | ||
| 99 | public Type(String name) { | 96 | public Type(String name) { |
| 100 | 97 | ||
| @@ -104,59 +101,51 @@ public class Type implements Serializable { | |||
| 104 | throw new IllegalArgumentException("don't use with generic types or templates: " + name); | 101 | throw new IllegalArgumentException("don't use with generic types or templates: " + name); |
| 105 | } | 102 | } |
| 106 | 103 | ||
| 107 | m_name = name; | 104 | this.name = name; |
| 108 | } | ||
| 109 | |||
| 110 | public Type(Type other) { | ||
| 111 | m_name = other.m_name; | ||
| 112 | } | ||
| 113 | |||
| 114 | public Type(ClassEntry classEntry) { | ||
| 115 | m_name = "L" + classEntry.getClassName() + ";"; | ||
| 116 | } | 105 | } |
| 117 | 106 | ||
| 118 | public Type(Type other, ClassNameReplacer replacer) { | 107 | public Type(Type other, ClassNameReplacer replacer) { |
| 119 | m_name = other.m_name; | 108 | this.name = other.name; |
| 120 | if (other.isClass()) { | 109 | if (other.isClass()) { |
| 121 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); | 110 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); |
| 122 | if (replacedName != null) { | 111 | if (replacedName != null) { |
| 123 | m_name = "L" + replacedName + ";"; | 112 | this.name = "L" + replacedName + ";"; |
| 124 | } | 113 | } |
| 125 | } else if (other.isArray() && other.hasClass()) { | 114 | } else if (other.isArray() && other.hasClass()) { |
| 126 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); | 115 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); |
| 127 | if (replacedName != null) { | 116 | if (replacedName != null) { |
| 128 | m_name = Type.getArrayPrefix(other.getArrayDimension()) + "L" + replacedName + ";"; | 117 | this.name = Type.getArrayPrefix(other.getArrayDimension()) + "L" + replacedName + ";"; |
| 129 | } | 118 | } |
| 130 | } | 119 | } |
| 131 | } | 120 | } |
| 132 | 121 | ||
| 133 | @Override | 122 | @Override |
| 134 | public String toString() { | 123 | public String toString() { |
| 135 | return m_name; | 124 | return this.name; |
| 136 | } | 125 | } |
| 137 | 126 | ||
| 138 | public boolean isVoid() { | 127 | public boolean isVoid() { |
| 139 | return m_name.length() == 1 && m_name.charAt(0) == 'V'; | 128 | return this.name.length() == 1 && this.name.charAt(0) == 'V'; |
| 140 | } | 129 | } |
| 141 | 130 | ||
| 142 | public boolean isPrimitive() { | 131 | public boolean isPrimitive() { |
| 143 | return m_name.length() == 1 && Primitive.get(m_name.charAt(0)) != null; | 132 | return this.name.length() == 1 && Primitive.get(this.name.charAt(0)) != null; |
| 144 | } | 133 | } |
| 145 | 134 | ||
| 146 | public Primitive getPrimitive() { | 135 | public Primitive getPrimitive() { |
| 147 | if (!isPrimitive()) { | 136 | if (!isPrimitive()) { |
| 148 | throw new IllegalStateException("not a primitive"); | 137 | throw new IllegalStateException("not a primitive"); |
| 149 | } | 138 | } |
| 150 | return Primitive.get(m_name.charAt(0)); | 139 | return Primitive.get(this.name.charAt(0)); |
| 151 | } | 140 | } |
| 152 | 141 | ||
| 153 | public boolean isClass() { | 142 | public boolean isClass() { |
| 154 | return m_name.charAt(0) == 'L' && m_name.charAt(m_name.length() - 1) == ';'; | 143 | return this.name.charAt(0) == 'L' && this.name.charAt(this.name.length() - 1) == ';'; |
| 155 | } | 144 | } |
| 156 | 145 | ||
| 157 | public ClassEntry getClassEntry() { | 146 | public ClassEntry getClassEntry() { |
| 158 | if (isClass()) { | 147 | if (isClass()) { |
| 159 | String name = m_name.substring(1, m_name.length() - 1); | 148 | String name = this.name.substring(1, this.name.length() - 1); |
| 160 | 149 | ||
| 161 | int pos = name.indexOf('<'); | 150 | int pos = name.indexOf('<'); |
| 162 | if (pos >= 0) { | 151 | if (pos >= 0) { |
| @@ -174,21 +163,21 @@ public class Type implements Serializable { | |||
| 174 | } | 163 | } |
| 175 | 164 | ||
| 176 | public boolean isArray() { | 165 | public boolean isArray() { |
| 177 | return m_name.charAt(0) == '['; | 166 | return this.name.charAt(0) == '['; |
| 178 | } | 167 | } |
| 179 | 168 | ||
| 180 | public int getArrayDimension() { | 169 | public int getArrayDimension() { |
| 181 | if (!isArray()) { | 170 | if (!isArray()) { |
| 182 | throw new IllegalStateException("not an array"); | 171 | throw new IllegalStateException("not an array"); |
| 183 | } | 172 | } |
| 184 | return countArrayDimension(m_name); | 173 | return countArrayDimension(this.name); |
| 185 | } | 174 | } |
| 186 | 175 | ||
| 187 | public Type getArrayType() { | 176 | public Type getArrayType() { |
| 188 | if (!isArray()) { | 177 | if (!isArray()) { |
| 189 | throw new IllegalStateException("not an array"); | 178 | throw new IllegalStateException("not an array"); |
| 190 | } | 179 | } |
| 191 | return new Type(m_name.substring(getArrayDimension(), m_name.length())); | 180 | return new Type(this.name.substring(getArrayDimension(), this.name.length())); |
| 192 | } | 181 | } |
| 193 | 182 | ||
| 194 | private static String getArrayPrefix(int dimension) { | 183 | private static String getArrayPrefix(int dimension) { |
| @@ -209,16 +198,17 @@ public class Type implements Serializable { | |||
| 209 | } | 198 | } |
| 210 | 199 | ||
| 211 | public boolean equals(Type other) { | 200 | public boolean equals(Type other) { |
| 212 | return m_name.equals(other.m_name); | 201 | return this.name.equals(other.name); |
| 213 | } | 202 | } |
| 214 | 203 | ||
| 215 | public int hashCode() { | 204 | public int hashCode() { |
| 216 | return m_name.hashCode(); | 205 | return this.name.hashCode(); |
| 217 | } | 206 | } |
| 218 | 207 | ||
| 219 | private static int countArrayDimension(String in) { | 208 | private static int countArrayDimension(String in) { |
| 220 | int i = 0; | 209 | int i = 0; |
| 221 | for (; i < in.length() && in.charAt(i) == '['; i++) {} | 210 | for (; i < in.length() && in.charAt(i) == '['; i++) { |
| 211 | } | ||
| 222 | return i; | 212 | return i; |
| 223 | } | 213 | } |
| 224 | 214 | ||