diff options
| author | 2015-02-08 23:10:26 -0500 | |
|---|---|---|
| committer | 2015-02-08 23:10:26 -0500 | |
| commit | 31a1a418b04cd3e7b06cb50cb8674a2c25079f6c (patch) | |
| tree | 5914fd0c3557250dc61382a571ea3a3cdb9d941d /src/cuchaz/enigma/analysis | |
| parent | Merge with 09538fb039f2e4e5e240cfb331be512ae8740fda (diff) | |
| download | enigma-fork-31a1a418b04cd3e7b06cb50cb8674a2c25079f6c.tar.gz enigma-fork-31a1a418b04cd3e7b06cb50cb8674a2c25079f6c.tar.xz enigma-fork-31a1a418b04cd3e7b06cb50cb8674a2c25079f6c.zip | |
added types to fields
Diffstat (limited to 'src/cuchaz/enigma/analysis')
4 files changed, 33 insertions, 32 deletions
diff --git a/src/cuchaz/enigma/analysis/EntryRenamer.java b/src/cuchaz/enigma/analysis/EntryRenamer.java index b54489c..2f27049 100644 --- a/src/cuchaz/enigma/analysis/EntryRenamer.java +++ b/src/cuchaz/enigma/analysis/EntryRenamer.java | |||
| @@ -21,10 +21,13 @@ import com.google.common.collect.Sets; | |||
| 21 | 21 | ||
| 22 | import cuchaz.enigma.mapping.ArgumentEntry; | 22 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 23 | import cuchaz.enigma.mapping.ClassEntry; | 23 | import cuchaz.enigma.mapping.ClassEntry; |
| 24 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 24 | import cuchaz.enigma.mapping.ConstructorEntry; | 25 | import cuchaz.enigma.mapping.ConstructorEntry; |
| 25 | import cuchaz.enigma.mapping.Entry; | 26 | import cuchaz.enigma.mapping.Entry; |
| 26 | import cuchaz.enigma.mapping.FieldEntry; | 27 | import cuchaz.enigma.mapping.FieldEntry; |
| 27 | import cuchaz.enigma.mapping.MethodEntry; | 28 | import cuchaz.enigma.mapping.MethodEntry; |
| 29 | import cuchaz.enigma.mapping.Signature; | ||
| 30 | import cuchaz.enigma.mapping.Type; | ||
| 28 | 31 | ||
| 29 | public class EntryRenamer { | 32 | public class EntryRenamer { |
| 30 | 33 | ||
| @@ -127,7 +130,7 @@ public class EntryRenamer { | |||
| 127 | } | 130 | } |
| 128 | 131 | ||
| 129 | @SuppressWarnings("unchecked") | 132 | @SuppressWarnings("unchecked") |
| 130 | public static <T> T renameClassesInThing(Map<String,String> renames, T thing) { | 133 | public static <T> T renameClassesInThing(final Map<String,String> renames, T thing) { |
| 131 | if (thing instanceof String) { | 134 | if (thing instanceof String) { |
| 132 | String stringEntry = (String)thing; | 135 | String stringEntry = (String)thing; |
| 133 | if (renames.containsKey(stringEntry)) { | 136 | if (renames.containsKey(stringEntry)) { |
| @@ -138,19 +141,23 @@ public class EntryRenamer { | |||
| 138 | return (T)new ClassEntry(renameClassesInThing(renames, classEntry.getClassName())); | 141 | return (T)new ClassEntry(renameClassesInThing(renames, classEntry.getClassName())); |
| 139 | } else if (thing instanceof FieldEntry) { | 142 | } else if (thing instanceof FieldEntry) { |
| 140 | FieldEntry fieldEntry = (FieldEntry)thing; | 143 | FieldEntry fieldEntry = (FieldEntry)thing; |
| 141 | return (T)new FieldEntry(renameClassesInThing(renames, fieldEntry.getClassEntry()), fieldEntry.getName()); | 144 | return (T)new FieldEntry( |
| 145 | renameClassesInThing(renames, fieldEntry.getClassEntry()), | ||
| 146 | fieldEntry.getName(), | ||
| 147 | renameClassesInThing(renames, fieldEntry.getType()) | ||
| 148 | ); | ||
| 142 | } else if (thing instanceof ConstructorEntry) { | 149 | } else if (thing instanceof ConstructorEntry) { |
| 143 | ConstructorEntry constructorEntry = (ConstructorEntry)thing; | 150 | ConstructorEntry constructorEntry = (ConstructorEntry)thing; |
| 144 | return (T)new ConstructorEntry( | 151 | return (T)new ConstructorEntry( |
| 145 | renameClassesInThing(renames, constructorEntry.getClassEntry()), | 152 | renameClassesInThing(renames, constructorEntry.getClassEntry()), |
| 146 | constructorEntry.getSignature() | 153 | renameClassesInThing(renames, constructorEntry.getSignature()) |
| 147 | ); | 154 | ); |
| 148 | } else if (thing instanceof MethodEntry) { | 155 | } else if (thing instanceof MethodEntry) { |
| 149 | MethodEntry methodEntry = (MethodEntry)thing; | 156 | MethodEntry methodEntry = (MethodEntry)thing; |
| 150 | return (T)new MethodEntry( | 157 | return (T)new MethodEntry( |
| 151 | renameClassesInThing(renames, methodEntry.getClassEntry()), | 158 | renameClassesInThing(renames, methodEntry.getClassEntry()), |
| 152 | methodEntry.getName(), | 159 | methodEntry.getName(), |
| 153 | methodEntry.getSignature() | 160 | renameClassesInThing(renames, methodEntry.getSignature()) |
| 154 | ); | 161 | ); |
| 155 | } else if (thing instanceof ArgumentEntry) { | 162 | } else if (thing instanceof ArgumentEntry) { |
| 156 | ArgumentEntry argumentEntry = (ArgumentEntry)thing; | 163 | ArgumentEntry argumentEntry = (ArgumentEntry)thing; |
| @@ -164,6 +171,20 @@ public class EntryRenamer { | |||
| 164 | reference.entry = renameClassesInThing(renames, reference.entry); | 171 | reference.entry = renameClassesInThing(renames, reference.entry); |
| 165 | reference.context = renameClassesInThing(renames, reference.context); | 172 | reference.context = renameClassesInThing(renames, reference.context); |
| 166 | return thing; | 173 | return thing; |
| 174 | } else if (thing instanceof Signature) { | ||
| 175 | return (T)new Signature((Signature)thing, new ClassNameReplacer() { | ||
| 176 | @Override | ||
| 177 | public String replace(String className) { | ||
| 178 | return renameClassesInThing(renames, className); | ||
| 179 | } | ||
| 180 | }); | ||
| 181 | } else if (thing instanceof Type) { | ||
| 182 | return (T)new Type((Type)thing, new ClassNameReplacer() { | ||
| 183 | @Override | ||
| 184 | public String replace(String className) { | ||
| 185 | return renameClassesInThing(renames, className); | ||
| 186 | } | ||
| 187 | }); | ||
| 167 | } | 188 | } |
| 168 | 189 | ||
| 169 | return thing; | 190 | return thing; |
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java index 3aac8bd..f54beda 100644 --- a/src/cuchaz/enigma/analysis/JarIndex.java +++ b/src/cuchaz/enigma/analysis/JarIndex.java | |||
| @@ -57,7 +57,6 @@ public class JarIndex { | |||
| 57 | private TranslationIndex m_translationIndex; | 57 | private TranslationIndex m_translationIndex; |
| 58 | private Multimap<String,String> m_interfaces; | 58 | private Multimap<String,String> m_interfaces; |
| 59 | private Map<Entry,Access> m_access; | 59 | private Map<Entry,Access> m_access; |
| 60 | private Map<FieldEntry,ClassEntry> m_fieldClasses; // TODO: this will become obsolete! | ||
| 61 | private Multimap<String,MethodEntry> m_methodImplementations; | 60 | private Multimap<String,MethodEntry> m_methodImplementations; |
| 62 | private Multimap<BehaviorEntry,EntryReference<BehaviorEntry,BehaviorEntry>> m_behaviorReferences; | 61 | private Multimap<BehaviorEntry,EntryReference<BehaviorEntry,BehaviorEntry>> m_behaviorReferences; |
| 63 | private Multimap<FieldEntry,EntryReference<FieldEntry,BehaviorEntry>> m_fieldReferences; | 62 | private Multimap<FieldEntry,EntryReference<FieldEntry,BehaviorEntry>> m_fieldReferences; |
| @@ -70,7 +69,6 @@ public class JarIndex { | |||
| 70 | m_translationIndex = new TranslationIndex(); | 69 | m_translationIndex = new TranslationIndex(); |
| 71 | m_interfaces = HashMultimap.create(); | 70 | m_interfaces = HashMultimap.create(); |
| 72 | m_access = Maps.newHashMap(); | 71 | m_access = Maps.newHashMap(); |
| 73 | m_fieldClasses = Maps.newHashMap(); | ||
| 74 | m_methodImplementations = HashMultimap.create(); | 72 | m_methodImplementations = HashMultimap.create(); |
| 75 | m_behaviorReferences = HashMultimap.create(); | 73 | m_behaviorReferences = HashMultimap.create(); |
| 76 | m_fieldReferences = HashMultimap.create(); | 74 | m_fieldReferences = HashMultimap.create(); |
| @@ -114,9 +112,6 @@ public class JarIndex { | |||
| 114 | } | 112 | } |
| 115 | m_interfaces.put(className, interfaceName); | 113 | m_interfaces.put(className, interfaceName); |
| 116 | } | 114 | } |
| 117 | for (CtField field : c.getDeclaredFields()) { | ||
| 118 | indexField(field); | ||
| 119 | } | ||
| 120 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 115 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 121 | indexBehavior(behavior); | 116 | indexBehavior(behavior); |
| 122 | } | 117 | } |
| @@ -169,18 +164,6 @@ public class JarIndex { | |||
| 169 | } | 164 | } |
| 170 | } | 165 | } |
| 171 | 166 | ||
| 172 | private void indexField(CtField field) { | ||
| 173 | // get the field entry | ||
| 174 | String className = Descriptor.toJvmName(field.getDeclaringClass().getName()); | ||
| 175 | FieldEntry fieldEntry = new FieldEntry(new ClassEntry(className), field.getName()); | ||
| 176 | |||
| 177 | // is the field a class type? | ||
| 178 | if (field.getSignature().startsWith("L")) { | ||
| 179 | ClassEntry fieldTypeEntry = new ClassEntry(field.getSignature().substring(1, field.getSignature().length() - 1)); | ||
| 180 | m_fieldClasses.put(fieldEntry, fieldTypeEntry); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | private void indexBehavior(CtBehavior behavior) { | 167 | private void indexBehavior(CtBehavior behavior) { |
| 185 | // get the behavior entry | 168 | // get the behavior entry |
| 186 | final BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(behavior); | 169 | final BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(behavior); |
| @@ -222,7 +205,7 @@ public class JarIndex { | |||
| 222 | FieldEntry calledFieldEntry = JavassistUtil.getFieldEntry(call); | 205 | FieldEntry calledFieldEntry = JavassistUtil.getFieldEntry(call); |
| 223 | ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledFieldEntry); | 206 | ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledFieldEntry); |
| 224 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { | 207 | if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { |
| 225 | calledFieldEntry = new FieldEntry(resolvedClassEntry, call.getFieldName()); | 208 | calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry); |
| 226 | } | 209 | } |
| 227 | EntryReference<FieldEntry,BehaviorEntry> reference = new EntryReference<FieldEntry,BehaviorEntry>( | 210 | EntryReference<FieldEntry,BehaviorEntry> reference = new EntryReference<FieldEntry,BehaviorEntry>( |
| 228 | calledFieldEntry, | 211 | calledFieldEntry, |
| @@ -448,8 +431,7 @@ public class JarIndex { | |||
| 448 | // does the caller use this type? | 431 | // does the caller use this type? |
| 449 | BehaviorEntry caller = references.iterator().next().context; | 432 | BehaviorEntry caller = references.iterator().next().context; |
| 450 | for (FieldEntry fieldEntry : getReferencedFields(caller)) { | 433 | for (FieldEntry fieldEntry : getReferencedFields(caller)) { |
| 451 | ClassEntry fieldClass = getFieldClass(fieldEntry); | 434 | if (fieldEntry.getType().hasClass() && fieldEntry.getType().getClassEntry().equals(innerClassEntry)) { |
| 452 | if (fieldClass != null && fieldClass.equals(innerClassEntry)) { | ||
| 453 | // caller references this type, so it can't be anonymous | 435 | // caller references this type, so it can't be anonymous |
| 454 | return null; | 436 | return null; |
| 455 | } | 437 | } |
| @@ -475,10 +457,6 @@ public class JarIndex { | |||
| 475 | return m_access.get(entry); | 457 | return m_access.get(entry); |
| 476 | } | 458 | } |
| 477 | 459 | ||
| 478 | public ClassEntry getFieldClass(FieldEntry fieldEntry) { | ||
| 479 | return m_fieldClasses.get(fieldEntry); | ||
| 480 | } | ||
| 481 | |||
| 482 | public ClassInheritanceTreeNode getClassInheritance(Translator deobfuscatingTranslator, ClassEntry obfClassEntry) { | 460 | public ClassInheritanceTreeNode getClassInheritance(Translator deobfuscatingTranslator, ClassEntry obfClassEntry) { |
| 483 | 461 | ||
| 484 | // get the root node | 462 | // get the root node |
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java index 4155128..f15a724 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |||
| @@ -36,6 +36,7 @@ import cuchaz.enigma.mapping.ConstructorEntry; | |||
| 36 | import cuchaz.enigma.mapping.FieldEntry; | 36 | import cuchaz.enigma.mapping.FieldEntry; |
| 37 | import cuchaz.enigma.mapping.MethodEntry; | 37 | import cuchaz.enigma.mapping.MethodEntry; |
| 38 | import cuchaz.enigma.mapping.Signature; | 38 | import cuchaz.enigma.mapping.Signature; |
| 39 | import cuchaz.enigma.mapping.Type; | ||
| 39 | 40 | ||
| 40 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | 41 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { |
| 41 | 42 | ||
| @@ -100,7 +101,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | 103 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); |
| 103 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName()); | 104 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getSignature())); |
| 104 | index.addReference(node.getMemberNameToken(), fieldEntry, m_behaviorEntry); | 105 | index.addReference(node.getMemberNameToken(), fieldEntry, m_behaviorEntry); |
| 105 | } | 106 | } |
| 106 | 107 | ||
| @@ -140,7 +141,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 140 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); | 141 | MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE); |
| 141 | if (ref != null) { | 142 | if (ref != null) { |
| 142 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); | 143 | ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName()); |
| 143 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName()); | 144 | FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName(), new Type(ref.getSignature())); |
| 144 | index.addReference(node.getIdentifierToken(), fieldEntry, m_behaviorEntry); | 145 | index.addReference(node.getIdentifierToken(), fieldEntry, m_behaviorEntry); |
| 145 | } | 146 | } |
| 146 | 147 | ||
diff --git a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index 7222035..e2ff300 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -31,6 +31,7 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 31 | import cuchaz.enigma.mapping.ConstructorEntry; | 31 | import cuchaz.enigma.mapping.ConstructorEntry; |
| 32 | import cuchaz.enigma.mapping.FieldEntry; | 32 | import cuchaz.enigma.mapping.FieldEntry; |
| 33 | import cuchaz.enigma.mapping.Signature; | 33 | import cuchaz.enigma.mapping.Signature; |
| 34 | import cuchaz.enigma.mapping.Type; | ||
| 34 | 35 | ||
| 35 | public class SourceIndexClassVisitor extends SourceIndexVisitor { | 36 | public class SourceIndexClassVisitor extends SourceIndexVisitor { |
| 36 | 37 | ||
| @@ -94,7 +95,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 94 | public Void visitFieldDeclaration(FieldDeclaration node, SourceIndex index) { | 95 | public Void visitFieldDeclaration(FieldDeclaration node, SourceIndex index) { |
| 95 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | 96 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); |
| 96 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | 97 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); |
| 97 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName()); | 98 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName(), new Type(def.getSignature())); |
| 98 | assert (node.getVariables().size() == 1); | 99 | assert (node.getVariables().size() == 1); |
| 99 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | 100 | VariableInitializer variable = node.getVariables().firstOrNullObject(); |
| 100 | index.addDeclaration(variable.getNameToken(), fieldEntry); | 101 | index.addDeclaration(variable.getNameToken(), fieldEntry); |
| @@ -107,7 +108,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 107 | // treat enum declarations as field declarations | 108 | // treat enum declarations as field declarations |
| 108 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | 109 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); |
| 109 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); | 110 | ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); |
| 110 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName()); | 111 | FieldEntry fieldEntry = new FieldEntry(classEntry, def.getName(), new Type(def.getSignature())); |
| 111 | index.addDeclaration(node.getNameToken(), fieldEntry); | 112 | index.addDeclaration(node.getNameToken(), fieldEntry); |
| 112 | 113 | ||
| 113 | return recurse(node, index); | 114 | return recurse(node, index); |