diff options
| author | 2015-03-16 19:22:22 -0400 | |
|---|---|---|
| committer | 2015-03-16 19:22:22 -0400 | |
| commit | 5e3743a0aca3529eacf9be400c8b8d7547f66e7f (patch) | |
| tree | ea601747547f78e1b83ab828650932126440e221 /src/cuchaz/enigma/mapping | |
| parent | update to new javassist version to (hopefully) get bug fixes (diff) | |
| download | enigma-fork-5e3743a0aca3529eacf9be400c8b8d7547f66e7f.tar.gz enigma-fork-5e3743a0aca3529eacf9be400c8b8d7547f66e7f.tar.xz enigma-fork-5e3743a0aca3529eacf9be400c8b8d7547f66e7f.zip | |
started adding minimal support for generics
fixed mark-as-deobfuscated issue
Diffstat (limited to 'src/cuchaz/enigma/mapping')
| -rw-r--r-- | src/cuchaz/enigma/mapping/EntryFactory.java | 17 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsChecker.java | 2 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsRenamer.java | 10 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/ParameterizedType.java | 54 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Signature.java | 10 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Type.java | 78 |
6 files changed, 143 insertions, 28 deletions
diff --git a/src/cuchaz/enigma/mapping/EntryFactory.java b/src/cuchaz/enigma/mapping/EntryFactory.java index 7bc6183..4898e6d 100644 --- a/src/cuchaz/enigma/mapping/EntryFactory.java +++ b/src/cuchaz/enigma/mapping/EntryFactory.java | |||
| @@ -11,6 +11,7 @@ import javassist.expr.FieldAccess; | |||
| 11 | import javassist.expr.MethodCall; | 11 | import javassist.expr.MethodCall; |
| 12 | import javassist.expr.NewExpr; | 12 | import javassist.expr.NewExpr; |
| 13 | 13 | ||
| 14 | import com.strobel.assembler.metadata.FieldDefinition; | ||
| 14 | import com.strobel.assembler.metadata.MethodDefinition; | 15 | import com.strobel.assembler.metadata.MethodDefinition; |
| 15 | 16 | ||
| 16 | import cuchaz.enigma.analysis.JarIndex; | 17 | import cuchaz.enigma.analysis.JarIndex; |
| @@ -54,6 +55,18 @@ public class EntryFactory { | |||
| 54 | ); | 55 | ); |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 58 | public static FieldEntry getFieldEntry(FieldDefinition def) { | ||
| 59 | return new FieldEntry( | ||
| 60 | new ClassEntry(def.getDeclaringType().getInternalName()), | ||
| 61 | def.getName(), | ||
| 62 | new Type(def.getErasedSignature()) | ||
| 63 | ); | ||
| 64 | } | ||
| 65 | |||
| 66 | public static FieldEntry getFieldEntry(String className, String name, String type) { | ||
| 67 | return new FieldEntry(new ClassEntry(className), name, new Type(type)); | ||
| 68 | } | ||
| 69 | |||
| 57 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { | 70 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { |
| 58 | return new FieldEntry( | 71 | return new FieldEntry( |
| 59 | getObfClassEntry(classMapping), | 72 | getObfClassEntry(classMapping), |
| @@ -82,7 +95,7 @@ public class EntryFactory { | |||
| 82 | return new MethodEntry( | 95 | return new MethodEntry( |
| 83 | new ClassEntry(def.getDeclaringType().getInternalName()), | 96 | new ClassEntry(def.getDeclaringType().getInternalName()), |
| 84 | def.getName(), | 97 | def.getName(), |
| 85 | new Signature(def.getSignature()) | 98 | new Signature(def.getErasedSignature()) |
| 86 | ); | 99 | ); |
| 87 | } | 100 | } |
| 88 | 101 | ||
| @@ -121,7 +134,7 @@ public class EntryFactory { | |||
| 121 | } else { | 134 | } else { |
| 122 | return new ConstructorEntry( | 135 | return new ConstructorEntry( |
| 123 | new ClassEntry(def.getDeclaringType().getInternalName()), | 136 | new ClassEntry(def.getDeclaringType().getInternalName()), |
| 124 | new Signature(def.getSignature()) | 137 | new Signature(def.getErasedSignature()) |
| 125 | ); | 138 | ); |
| 126 | } | 139 | } |
| 127 | } | 140 | } |
diff --git a/src/cuchaz/enigma/mapping/MappingsChecker.java b/src/cuchaz/enigma/mapping/MappingsChecker.java index c5ff7a7..57ea90c 100644 --- a/src/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -66,7 +66,7 @@ public class MappingsChecker { | |||
| 66 | 66 | ||
| 67 | // check the fields | 67 | // check the fields |
| 68 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | 68 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { |
| 69 | FieldEntry obfFieldEntry = new FieldEntry(classEntry, fieldMapping.getObfName(), fieldMapping.getObfType()); | 69 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); |
| 70 | if (!m_index.containsObfField(obfFieldEntry)) { | 70 | if (!m_index.containsObfField(obfFieldEntry)) { |
| 71 | classMapping.removeFieldMapping(fieldMapping); | 71 | classMapping.removeFieldMapping(fieldMapping); |
| 72 | m_droppedFieldMappings.put(obfFieldEntry, fieldMapping); | 72 | m_droppedFieldMappings.put(obfFieldEntry, fieldMapping); |
diff --git a/src/cuchaz/enigma/mapping/MappingsRenamer.java b/src/cuchaz/enigma/mapping/MappingsRenamer.java index d7766dc..ad6c878 100644 --- a/src/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -66,7 +66,15 @@ public class MappingsRenamer { | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | public void markClassAsDeobfuscated(ClassEntry obf) { | 68 | public void markClassAsDeobfuscated(ClassEntry obf) { |
| 69 | setClassName(obf, obf.isInnerClass() ? obf.getInnermostClassName() : obf.getSimpleName()); | 69 | String deobfName = obf.isInnerClass() ? obf.getInnermostClassName() : obf.getName(); |
| 70 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obf); | ||
| 71 | if (mappingChain.size() == 1) { | ||
| 72 | ClassMapping classMapping = mappingChain.get(0); | ||
| 73 | m_mappings.setClassDeobfName(classMapping, deobfName); | ||
| 74 | } else { | ||
| 75 | ClassMapping outerClassMapping = mappingChain.get(mappingChain.size() - 2); | ||
| 76 | outerClassMapping.setInnerClassName(obf, deobfName); | ||
| 77 | } | ||
| 70 | } | 78 | } |
| 71 | 79 | ||
| 72 | public void setFieldName(FieldEntry obf, String deobfName) { | 80 | public void setFieldName(FieldEntry obf, String deobfName) { |
diff --git a/src/cuchaz/enigma/mapping/ParameterizedType.java b/src/cuchaz/enigma/mapping/ParameterizedType.java new file mode 100644 index 0000000..af24ef4 --- /dev/null +++ b/src/cuchaz/enigma/mapping/ParameterizedType.java | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Util; | ||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | public class ParameterizedType extends Type { | ||
| 8 | |||
| 9 | private static final long serialVersionUID = 1758975507937309011L; | ||
| 10 | |||
| 11 | public ParameterizedType(Type other) { | ||
| 12 | super(other); | ||
| 13 | for (int i=0; i<m_parameters.size(); i++) { | ||
| 14 | m_parameters.set(i, new ParameterizedType(m_parameters.get(i))); | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | public ParameterizedType(ParameterizedType type, ClassNameReplacer replacer) { | ||
| 19 | this(new Type(type, replacer)); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public String toString() { | ||
| 24 | if (hasParameters()) { | ||
| 25 | StringBuilder buf = new StringBuilder(); | ||
| 26 | buf.append(m_name.substring(0, m_name.length() - 1)); | ||
| 27 | buf.append("<"); | ||
| 28 | for (Type parameter : parameters()) { | ||
| 29 | buf.append(parameter.toString()); | ||
| 30 | } | ||
| 31 | buf.append(">;"); | ||
| 32 | return buf.toString(); | ||
| 33 | } else { | ||
| 34 | return m_name; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public boolean equals(Object other) { | ||
| 40 | if (other instanceof ParameterizedType) { | ||
| 41 | return equals((ParameterizedType)other); | ||
| 42 | } | ||
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | public boolean equals(ParameterizedType other) { | ||
| 47 | return m_name.equals(other.m_name) && m_parameters.equals(other.m_parameters); | ||
| 48 | } | ||
| 49 | |||
| 50 | public int hashCode() { | ||
| 51 | return Util.combineHashesOrdered(m_name.hashCode(), m_parameters.hashCode()); | ||
| 52 | } | ||
| 53 | |||
| 54 | } | ||
diff --git a/src/cuchaz/enigma/mapping/Signature.java b/src/cuchaz/enigma/mapping/Signature.java index ea83e40..f4850ac 100644 --- a/src/cuchaz/enigma/mapping/Signature.java +++ b/src/cuchaz/enigma/mapping/Signature.java | |||
| @@ -79,16 +79,6 @@ public class Signature implements Serializable { | |||
| 79 | return types; | 79 | return types; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | public Iterable<ClassEntry> classes() { | ||
| 83 | List<ClassEntry> out = Lists.newArrayList(); | ||
| 84 | for (Type type : types()) { | ||
| 85 | if (type.isClass()) { | ||
| 86 | out.add(type.getClassEntry()); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | return out; | ||
| 90 | } | ||
| 91 | |||
| 92 | @Override | 82 | @Override |
| 93 | public boolean equals(Object other) { | 83 | public boolean equals(Object other) { |
| 94 | if (other instanceof Signature) { | 84 | if (other instanceof Signature) { |
diff --git a/src/cuchaz/enigma/mapping/Type.java b/src/cuchaz/enigma/mapping/Type.java index 72118b0..d530083 100644 --- a/src/cuchaz/enigma/mapping/Type.java +++ b/src/cuchaz/enigma/mapping/Type.java | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | package cuchaz.enigma.mapping; | 1 | package cuchaz.enigma.mapping; |
| 2 | 2 | ||
| 3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
| 4 | import java.util.List; | ||
| 4 | import java.util.Map; | 5 | import java.util.Map; |
| 5 | 6 | ||
| 7 | import com.beust.jcommander.internal.Lists; | ||
| 6 | import com.google.common.collect.Maps; | 8 | import com.google.common.collect.Maps; |
| 7 | 9 | ||
| 8 | public class Type implements Serializable { | 10 | public class Type implements Serializable { |
| @@ -84,33 +86,66 @@ public class Type implements Serializable { | |||
| 84 | throw new IllegalArgumentException("don't know how to parse: " + in); | 86 | throw new IllegalArgumentException("don't know how to parse: " + in); |
| 85 | } | 87 | } |
| 86 | 88 | ||
| 87 | private String m_name; | 89 | protected String m_name; |
| 90 | protected List<Type> m_parameters; | ||
| 88 | 91 | ||
| 89 | public Type(String name) { | 92 | public Type(String name) { |
| 90 | m_name = name; | 93 | m_name = null; |
| 94 | m_parameters = Lists.newArrayList(); | ||
| 95 | |||
| 96 | int start = name.indexOf('<'); | ||
| 97 | int stop = name.lastIndexOf('>'); | ||
| 98 | if (start > 0 && stop > start) { | ||
| 99 | |||
| 100 | // deal with generic parameters | ||
| 101 | m_name = name.substring(0, start) + name.substring(stop + 1); | ||
| 102 | |||
| 103 | String parameters = name.substring(start + 1, stop); | ||
| 104 | int i=0; | ||
| 105 | while (i<parameters.length()) { | ||
| 106 | String typeName = Type.parseFirst(parameters.substring(i)); | ||
| 107 | if (typeName == null) { | ||
| 108 | throw new Error("Don't know how to parse parameters: " + name); | ||
| 109 | } | ||
| 110 | m_parameters.add(new Type(typeName)); | ||
| 111 | i += typeName.length(); | ||
| 112 | } | ||
| 113 | |||
| 114 | } else { | ||
| 115 | m_name = name; | ||
| 116 | } | ||
| 91 | } | 117 | } |
| 92 | 118 | ||
| 93 | public Type(Type other) { | 119 | public Type(Type other) { |
| 94 | m_name = other.m_name; | 120 | m_name = other.m_name; |
| 121 | m_parameters = Lists.newArrayList(); | ||
| 122 | for (Type parameter : other.m_parameters) { | ||
| 123 | m_parameters.add(new Type(parameter)); | ||
| 124 | } | ||
| 95 | } | 125 | } |
| 96 | 126 | ||
| 97 | public Type(ClassEntry classEntry) { | 127 | public Type(ClassEntry classEntry) { |
| 98 | m_name = "L" + classEntry.getClassName() + ";"; | 128 | m_name = "L" + classEntry.getClassName() + ";"; |
| 99 | } | 129 | } |
| 100 | 130 | ||
| 101 | public Type(Type type, ClassNameReplacer replacer) { | 131 | public Type(Type other, ClassNameReplacer replacer) { |
| 102 | m_name = type.m_name; | 132 | m_name = other.m_name; |
| 103 | if (type.isClass()) { | 133 | if (other.isClass()) { |
| 104 | String replacedName = replacer.replace(type.getClassEntry().getClassName()); | 134 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); |
| 105 | if (replacedName != null) { | 135 | if (replacedName != null) { |
| 106 | m_name = "L" + replacedName + ";"; | 136 | m_name = "L" + replacedName + ";"; |
| 107 | } | 137 | } |
| 108 | } else if (type.isArray() && type.hasClass()) { | 138 | } else if (other.isArray() && other.hasClass()) { |
| 109 | String replacedName = replacer.replace(type.getClassEntry().getClassName()); | 139 | String replacedName = replacer.replace(other.getClassEntry().getClassName()); |
| 110 | if (replacedName != null) { | 140 | if (replacedName != null) { |
| 111 | m_name = Type.getArrayPrefix(type.getArrayDimension()) + "L" + replacedName + ";"; | 141 | m_name = Type.getArrayPrefix(other.getArrayDimension()) + "L" + replacedName + ";"; |
| 112 | } | 142 | } |
| 113 | } | 143 | } |
| 144 | |||
| 145 | m_parameters = Lists.newArrayList(); | ||
| 146 | for (Type parameter : other.m_parameters) { | ||
| 147 | m_parameters.add(new Type(parameter, replacer)); | ||
| 148 | } | ||
| 114 | } | 149 | } |
| 115 | 150 | ||
| 116 | @Override | 151 | @Override |
| @@ -137,10 +172,6 @@ public class Type implements Serializable { | |||
| 137 | return m_name.charAt(0) == 'L' && m_name.charAt(m_name.length() - 1) == ';'; | 172 | return m_name.charAt(0) == 'L' && m_name.charAt(m_name.length() - 1) == ';'; |
| 138 | } | 173 | } |
| 139 | 174 | ||
| 140 | public boolean isTemplate() { | ||
| 141 | return m_name.charAt(0) == 'T' && m_name.charAt(m_name.length() - 1) == ';'; | ||
| 142 | } | ||
| 143 | |||
| 144 | public ClassEntry getClassEntry() { | 175 | public ClassEntry getClassEntry() { |
| 145 | if (isClass()) { | 176 | if (isClass()) { |
| 146 | String name = m_name.substring(1, m_name.length() - 1); | 177 | String name = m_name.substring(1, m_name.length() - 1); |
| @@ -160,6 +191,17 @@ public class Type implements Serializable { | |||
| 160 | } | 191 | } |
| 161 | } | 192 | } |
| 162 | 193 | ||
| 194 | public boolean isTemplate() { | ||
| 195 | return m_name.charAt(0) == 'T' && m_name.charAt(m_name.length() - 1) == ';'; | ||
| 196 | } | ||
| 197 | |||
| 198 | public String getTemplate() { | ||
| 199 | if (!isTemplate()) { | ||
| 200 | throw new IllegalStateException("not an template"); | ||
| 201 | } | ||
| 202 | return m_name.substring(1, m_name.length() - 1); | ||
| 203 | } | ||
| 204 | |||
| 163 | public boolean isArray() { | 205 | public boolean isArray() { |
| 164 | return m_name.charAt(0) == '['; | 206 | return m_name.charAt(0) == '['; |
| 165 | } | 207 | } |
| @@ -190,6 +232,14 @@ public class Type implements Serializable { | |||
| 190 | return isClass() || (isArray() && getArrayType().hasClass()); | 232 | return isClass() || (isArray() && getArrayType().hasClass()); |
| 191 | } | 233 | } |
| 192 | 234 | ||
| 235 | public boolean hasParameters() { | ||
| 236 | return !m_parameters.isEmpty(); | ||
| 237 | } | ||
| 238 | |||
| 239 | public Iterable<Type> parameters() { | ||
| 240 | return m_parameters; | ||
| 241 | } | ||
| 242 | |||
| 193 | @Override | 243 | @Override |
| 194 | public boolean equals(Object other) { | 244 | public boolean equals(Object other) { |
| 195 | if (other instanceof Type) { | 245 | if (other instanceof Type) { |
| @@ -214,7 +264,7 @@ public class Type implements Serializable { | |||
| 214 | 264 | ||
| 215 | private static String readClass(String in) { | 265 | private static String readClass(String in) { |
| 216 | // read all the characters in the buffer until we hit a ';' | 266 | // read all the characters in the buffer until we hit a ';' |
| 217 | // remember to treat parameters correctly | 267 | // include the parameters too |
| 218 | StringBuilder buf = new StringBuilder(); | 268 | StringBuilder buf = new StringBuilder(); |
| 219 | int depth = 0; | 269 | int depth = 0; |
| 220 | for (int i=0; i<in.length(); i++) { | 270 | for (int i=0; i<in.length(); i++) { |