summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/JarIndex.java
diff options
context:
space:
mode:
authorGravatar jeff2015-02-09 22:23:45 -0500
committerGravatar jeff2015-02-09 22:23:45 -0500
commitaf1041731c8c0ce1846ff7e7b6052ed7327a5dbc (patch)
treee781b93f526a6c1ba7b6f5e14c319450199aa1df /src/cuchaz/enigma/analysis/JarIndex.java
parentDon't automatically move mappings around. We're more interested in stability ... (diff)
downloadenigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.gz
enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.xz
enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.zip
fix translation issues, particularly with fields
Diffstat (limited to 'src/cuchaz/enigma/analysis/JarIndex.java')
-rw-r--r--src/cuchaz/enigma/analysis/JarIndex.java57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java
index f54beda..24d110e 100644
--- a/src/cuchaz/enigma/analysis/JarIndex.java
+++ b/src/cuchaz/enigma/analysis/JarIndex.java
@@ -42,12 +42,11 @@ import cuchaz.enigma.Constants;
42import cuchaz.enigma.bytecode.ClassRenamer; 42import cuchaz.enigma.bytecode.ClassRenamer;
43import cuchaz.enigma.mapping.ArgumentEntry; 43import cuchaz.enigma.mapping.ArgumentEntry;
44import cuchaz.enigma.mapping.BehaviorEntry; 44import cuchaz.enigma.mapping.BehaviorEntry;
45import cuchaz.enigma.mapping.BehaviorEntryFactory;
46import cuchaz.enigma.mapping.ClassEntry; 45import cuchaz.enigma.mapping.ClassEntry;
47import cuchaz.enigma.mapping.ConstructorEntry; 46import cuchaz.enigma.mapping.ConstructorEntry;
48import cuchaz.enigma.mapping.Entry; 47import cuchaz.enigma.mapping.Entry;
48import cuchaz.enigma.mapping.EntryFactory;
49import cuchaz.enigma.mapping.FieldEntry; 49import cuchaz.enigma.mapping.FieldEntry;
50import cuchaz.enigma.mapping.JavassistUtil;
51import cuchaz.enigma.mapping.MethodEntry; 50import cuchaz.enigma.mapping.MethodEntry;
52import cuchaz.enigma.mapping.Translator; 51import cuchaz.enigma.mapping.Translator;
53 52
@@ -92,10 +91,10 @@ public class JarIndex {
92 for (CtClass c : JarClassIterator.classes(jar)) { 91 for (CtClass c : JarClassIterator.classes(jar)) {
93 ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); 92 ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage);
94 for (CtField field : c.getDeclaredFields()) { 93 for (CtField field : c.getDeclaredFields()) {
95 m_access.put(JavassistUtil.getFieldEntry(field), Access.get(field)); 94 m_access.put(EntryFactory.getFieldEntry(field), Access.get(field));
96 } 95 }
97 for (CtBehavior behavior : c.getDeclaredBehaviors()) { 96 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
98 m_access.put(JavassistUtil.getBehaviorEntry(behavior), Access.get(behavior)); 97 m_access.put(EntryFactory.getBehaviorEntry(behavior), Access.get(behavior));
99 } 98 }
100 } 99 }
101 100
@@ -166,7 +165,7 @@ public class JarIndex {
166 165
167 private void indexBehavior(CtBehavior behavior) { 166 private void indexBehavior(CtBehavior behavior) {
168 // get the behavior entry 167 // get the behavior entry
169 final BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(behavior); 168 final BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior);
170 if (behaviorEntry instanceof MethodEntry) { 169 if (behaviorEntry instanceof MethodEntry) {
171 MethodEntry methodEntry = (MethodEntry)behaviorEntry; 170 MethodEntry methodEntry = (MethodEntry)behaviorEntry;
172 171
@@ -178,12 +177,12 @@ public class JarIndex {
178 177
179 private void indexBehaviorReferences(CtBehavior behavior) { 178 private void indexBehaviorReferences(CtBehavior behavior) {
180 // index method calls 179 // index method calls
181 final BehaviorEntry behaviorEntry = BehaviorEntryFactory.create(behavior); 180 final BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior);
182 try { 181 try {
183 behavior.instrument(new ExprEditor() { 182 behavior.instrument(new ExprEditor() {
184 @Override 183 @Override
185 public void edit(MethodCall call) { 184 public void edit(MethodCall call) {
186 MethodEntry calledMethodEntry = JavassistUtil.getMethodEntry(call); 185 MethodEntry calledMethodEntry = EntryFactory.getMethodEntry(call);
187 ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledMethodEntry); 186 ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledMethodEntry);
188 if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledMethodEntry.getClassEntry())) { 187 if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledMethodEntry.getClassEntry())) {
189 calledMethodEntry = new MethodEntry( 188 calledMethodEntry = new MethodEntry(
@@ -202,7 +201,7 @@ public class JarIndex {
202 201
203 @Override 202 @Override
204 public void edit(FieldAccess call) { 203 public void edit(FieldAccess call) {
205 FieldEntry calledFieldEntry = JavassistUtil.getFieldEntry(call); 204 FieldEntry calledFieldEntry = EntryFactory.getFieldEntry(call);
206 ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledFieldEntry); 205 ClassEntry resolvedClassEntry = m_translationIndex.resolveEntryClass(calledFieldEntry);
207 if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { 206 if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) {
208 calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry); 207 calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry);
@@ -217,7 +216,7 @@ public class JarIndex {
217 216
218 @Override 217 @Override
219 public void edit(ConstructorCall call) { 218 public void edit(ConstructorCall call) {
220 ConstructorEntry calledConstructorEntry = JavassistUtil.getConstructorEntry(call); 219 ConstructorEntry calledConstructorEntry = EntryFactory.getConstructorEntry(call);
221 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>( 220 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>(
222 calledConstructorEntry, 221 calledConstructorEntry,
223 call.getMethodName(), 222 call.getMethodName(),
@@ -228,7 +227,7 @@ public class JarIndex {
228 227
229 @Override 228 @Override
230 public void edit(NewExpr call) { 229 public void edit(NewExpr call) {
231 ConstructorEntry calledConstructorEntry = JavassistUtil.getConstructorEntry(call); 230 ConstructorEntry calledConstructorEntry = EntryFactory.getConstructorEntry(call);
232 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>( 231 EntryReference<BehaviorEntry,BehaviorEntry> reference = new EntryReference<BehaviorEntry,BehaviorEntry>(
233 calledConstructorEntry, 232 calledConstructorEntry,
234 call.getClassName(), 233 call.getClassName(),
@@ -256,7 +255,7 @@ public class JarIndex {
256 } 255 }
257 256
258 ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); 257 ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName()));
259 ConstructorEntry constructorEntry = JavassistUtil.getConstructorEntry(constructor); 258 ConstructorEntry constructorEntry = EntryFactory.getConstructorEntry(constructor);
260 259
261 // gather the classes from the illegally-set synthetic fields 260 // gather the classes from the illegally-set synthetic fields
262 Set<ClassEntry> illegallySetClasses = Sets.newHashSet(); 261 Set<ClassEntry> illegallySetClasses = Sets.newHashSet();
@@ -422,7 +421,7 @@ public class JarIndex {
422 CtConstructor constructor = c.getDeclaredConstructors()[0]; 421 CtConstructor constructor = c.getDeclaredConstructors()[0];
423 422
424 // is this constructor called exactly once? 423 // is this constructor called exactly once?
425 ConstructorEntry constructorEntry = JavassistUtil.getConstructorEntry(constructor); 424 ConstructorEntry constructorEntry = EntryFactory.getConstructorEntry(constructor);
426 Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = getBehaviorReferences(constructorEntry); 425 Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = getBehaviorReferences(constructorEntry);
427 if (references.size() != 1) { 426 if (references.size() != 1) {
428 return null; 427 return null;
@@ -520,17 +519,17 @@ public class JarIndex {
520 return rootNode; 519 return rootNode;
521 } 520 }
522 521
523 public MethodImplementationsTreeNode getMethodImplementations(Translator deobfuscatingTranslator, MethodEntry obfMethodEntry) { 522 public List<MethodImplementationsTreeNode> getMethodImplementations(Translator deobfuscatingTranslator, MethodEntry obfMethodEntry) {
524 523
525 MethodEntry interfaceMethodEntry; 524 List<MethodEntry> interfaceMethodEntries = Lists.newArrayList();
526 525
527 // is this method on an interface? 526 // is this method on an interface?
528 if (isInterface(obfMethodEntry.getClassName())) { 527 if (isInterface(obfMethodEntry.getClassName())) {
529 interfaceMethodEntry = obfMethodEntry; 528 interfaceMethodEntries.add(obfMethodEntry);
530 } else { 529 } else {
531 // get the interface class 530 // get the interface class
532 List<MethodEntry> methodInterfaces = Lists.newArrayList();
533 for (String interfaceName : getInterfaces(obfMethodEntry.getClassName())) { 531 for (String interfaceName : getInterfaces(obfMethodEntry.getClassName())) {
532
534 // is this method defined in this interface? 533 // is this method defined in this interface?
535 MethodEntry methodInterface = new MethodEntry( 534 MethodEntry methodInterface = new MethodEntry(
536 new ClassEntry(interfaceName), 535 new ClassEntry(interfaceName),
@@ -538,21 +537,20 @@ public class JarIndex {
538 obfMethodEntry.getSignature() 537 obfMethodEntry.getSignature()
539 ); 538 );
540 if (containsObfBehavior(methodInterface)) { 539 if (containsObfBehavior(methodInterface)) {
541 methodInterfaces.add(methodInterface); 540 interfaceMethodEntries.add(methodInterface);
542 } 541 }
543 } 542 }
544 if (methodInterfaces.isEmpty()) {
545 return null;
546 }
547 if (methodInterfaces.size() > 1) {
548 throw new Error("Too many interfaces define this method! This is not yet supported by Enigma!");
549 }
550 interfaceMethodEntry = methodInterfaces.get(0);
551 } 543 }
552 544
553 MethodImplementationsTreeNode rootNode = new MethodImplementationsTreeNode(deobfuscatingTranslator, interfaceMethodEntry); 545 List<MethodImplementationsTreeNode> nodes = Lists.newArrayList();
554 rootNode.load(this); 546 if (!interfaceMethodEntries.isEmpty()) {
555 return rootNode; 547 for (MethodEntry interfaceMethodEntry : interfaceMethodEntries) {
548 MethodImplementationsTreeNode node = new MethodImplementationsTreeNode(deobfuscatingTranslator, interfaceMethodEntry);
549 node.load(this);
550 nodes.add(node);
551 }
552 }
553 return nodes;
556 } 554 }
557 555
558 public Set<MethodEntry> getRelatedMethodImplementations(MethodEntry obfMethodEntry) { 556 public Set<MethodEntry> getRelatedMethodImplementations(MethodEntry obfMethodEntry) {
@@ -569,9 +567,8 @@ public class JarIndex {
569 } 567 }
570 568
571 // look at interface methods too 569 // look at interface methods too
572 MethodImplementationsTreeNode implementations = getMethodImplementations(null, methodEntry); 570 for (MethodImplementationsTreeNode implementationsNode : getMethodImplementations(null, methodEntry)) {
573 if (implementations != null) { 571 getRelatedMethodImplementations(methodEntries, implementationsNode);
574 getRelatedMethodImplementations(methodEntries, implementations);
575 } 572 }
576 573
577 // recurse 574 // recurse