diff options
| author | 2017-05-15 00:02:18 +0200 | |
|---|---|---|
| committer | 2017-05-15 00:02:18 +0200 | |
| commit | b19f9e0fd1a5c50dd1ed13dbcb057839c8296f77 (patch) | |
| tree | a750f346e543320668afb5eb0ba3075a3f09e71a | |
| parent | Rebuild innerclass method names. (diff) | |
| download | enigma-b19f9e0fd1a5c50dd1ed13dbcb057839c8296f77.tar.gz enigma-b19f9e0fd1a5c50dd1ed13dbcb057839c8296f77.tar.xz enigma-b19f9e0fd1a5c50dd1ed13dbcb057839c8296f77.zip | |
Add offset for Enum constructor arguments (Fix #58)
7 files changed, 30 insertions, 22 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java index 68ca87e3..1b619164 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java | |||
| @@ -26,7 +26,6 @@ import java.util.HashMap; | |||
| 26 | import java.util.Map; | 26 | import java.util.Map; |
| 27 | 27 | ||
| 28 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | 28 | public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { |
| 29 | |||
| 30 | private BehaviorEntry behaviorEntry; | 29 | private BehaviorEntry behaviorEntry; |
| 31 | 30 | ||
| 32 | // TODO: Really fix Procyon index problem with inner classes | 31 | // TODO: Really fix Procyon index problem with inner classes |
| @@ -35,9 +34,9 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { | |||
| 35 | private Multimap<String, Identifier> unmatchedIdentifier = HashMultimap.create(); | 34 | private Multimap<String, Identifier> unmatchedIdentifier = HashMultimap.create(); |
| 36 | private Map<String, Entry> identifierEntryCache = new HashMap<>(); | 35 | private Map<String, Entry> identifierEntryCache = new HashMap<>(); |
| 37 | 36 | ||
| 38 | public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) { | 37 | public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry, boolean isEnum) { |
| 39 | this.behaviorEntry = behaviorEntry; | 38 | this.behaviorEntry = behaviorEntry; |
| 40 | this.argumentPosition = 0; | 39 | this.argumentPosition = isEnum ? 2 : 0; |
| 41 | this.localsPosition = 0; | 40 | this.localsPosition = 0; |
| 42 | } | 41 | } |
| 43 | 42 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index 11482163..b13415da 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndexClassVisitor.java | |||
| @@ -22,6 +22,7 @@ import cuchaz.enigma.mapping.*; | |||
| 22 | public class SourceIndexClassVisitor extends SourceIndexVisitor { | 22 | public class SourceIndexClassVisitor extends SourceIndexVisitor { |
| 23 | 23 | ||
| 24 | private ClassEntry classEntry; | 24 | private ClassEntry classEntry; |
| 25 | private boolean isEnum; | ||
| 25 | 26 | ||
| 26 | public SourceIndexClassVisitor(ClassEntry classEntry) { | 27 | public SourceIndexClassVisitor(ClassEntry classEntry) { |
| 27 | this.classEntry = classEntry; | 28 | this.classEntry = classEntry; |
| @@ -65,7 +66,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 65 | } | 66 | } |
| 66 | } | 67 | } |
| 67 | index.addDeclaration(tokenNode, behaviorEntry); | 68 | index.addDeclaration(tokenNode, behaviorEntry); |
| 68 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(behaviorEntry), index); | 69 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(behaviorEntry, false), index); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | @Override | 72 | @Override |
| @@ -73,7 +74,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 73 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); | 74 | MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); |
| 74 | ConstructorEntry constructorEntry = ProcyonEntryFactory.getConstructorEntry(def); | 75 | ConstructorEntry constructorEntry = ProcyonEntryFactory.getConstructorEntry(def); |
| 75 | index.addDeclaration(node.getNameToken(), constructorEntry); | 76 | index.addDeclaration(node.getNameToken(), constructorEntry); |
| 76 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(constructorEntry), index); | 77 | return node.acceptVisitor(new SourceIndexBehaviorVisitor(constructorEntry, isEnum), index); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | @Override | 80 | @Override |
| @@ -93,7 +94,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { | |||
| 93 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); | 94 | FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); |
| 94 | FieldEntry fieldEntry = ProcyonEntryFactory.getFieldEntry(def); | 95 | FieldEntry fieldEntry = ProcyonEntryFactory.getFieldEntry(def); |
| 95 | index.addDeclaration(node.getNameToken(), fieldEntry); | 96 | index.addDeclaration(node.getNameToken(), fieldEntry); |
| 96 | 97 | this.isEnum = true; | |
| 97 | return recurse(node, index); | 98 | return recurse(node, index); |
| 98 | } | 99 | } |
| 99 | } | 100 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java index 1fb95935..f1c3dd77 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java | |||
| @@ -32,7 +32,7 @@ public class InnerClassWriter { | |||
| 32 | this.deobfuscatorTranslator = deobfuscatorTranslator; | 32 | this.deobfuscatorTranslator = deobfuscatorTranslator; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | // FIXME: modiffier is not applied to inner class | 35 | // FIXME: modifier is not applied to inner class |
| 36 | public static void changeModifier(CtClass c, InnerClassesAttribute attr, Translator translator) { | 36 | public static void changeModifier(CtClass c, InnerClassesAttribute attr, Translator translator) { |
| 37 | ClassPool pool = c.getClassPool(); | 37 | ClassPool pool = c.getClassPool(); |
| 38 | for (int i = 0; i < attr.tableLength(); i++) { | 38 | for (int i = 0; i < attr.tableLength(); i++) { |
diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java index 8b4ef9c2..878e30a7 100644 --- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java | |||
| @@ -38,7 +38,7 @@ public class LocalVariableRenamer { | |||
| 38 | 38 | ||
| 39 | LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); | 39 | LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); |
| 40 | if (table != null) { | 40 | if (table != null) { |
| 41 | renameLVT(behaviorEntry, constants, table); | 41 | renameLVT(behaviorEntry, constants, table, c); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); | 44 | LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); |
| @@ -58,7 +58,7 @@ public class LocalVariableRenamer { | |||
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table) { | 61 | private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table, CtClass ctClass) { |
| 62 | 62 | ||
| 63 | // skip empty tables | 63 | // skip empty tables |
| 64 | if (table.tableLength() <= 0) { | 64 | if (table.tableLength() <= 0) { |
| @@ -69,14 +69,13 @@ public class LocalVariableRenamer { | |||
| 69 | int starti = 0; | 69 | int starti = 0; |
| 70 | if (table.variableName(0).equals("this")) { | 70 | if (table.variableName(0).equals("this")) { |
| 71 | // skip the "this" variable | 71 | // skip the "this" variable |
| 72 | starti = 1; | 72 | starti++; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | // rename method arguments first | 75 | // rename method arguments first |
| 76 | int numArgs = 0; | 76 | int numArgs = 0; |
| 77 | if (behaviorEntry.getSignature() != null) { | 77 | if (behaviorEntry.getSignature() != null) { |
| 78 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); | 78 | numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); |
| 79 | |||
| 80 | boolean isNestedClassConstructor = false; | 79 | boolean isNestedClassConstructor = false; |
| 81 | 80 | ||
| 82 | // If the behavior is a constructor and if it have more than one arg, it's probably from a nested! | 81 | // If the behavior is a constructor and if it have more than one arg, it's probably from a nested! |
| @@ -93,21 +92,28 @@ public class LocalVariableRenamer { | |||
| 93 | 92 | ||
| 94 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { | 93 | for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { |
| 95 | int argi = i - starti; | 94 | int argi = i - starti; |
| 95 | if (ctClass.isEnum()) | ||
| 96 | argi += 2; | ||
| 97 | if (behaviorEntry.getClassEntry().getName().contains("ahd") && behaviorEntry instanceof ConstructorEntry) | ||
| 98 | System.out.println(behaviorEntry.getClassEntry() + " " + i); | ||
| 96 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); | 99 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); |
| 97 | if (argName == null) { | 100 | if (argName == null) { |
| 98 | Type argType = behaviorEntry.getSignature().getArgumentTypes().get(isNestedClassConstructor ? argi + 1 : argi); | 101 | int argIndex = isNestedClassConstructor ? argi + 1 : argi; |
| 102 | if (ctClass.isEnum()) | ||
| 103 | argIndex -= 2; | ||
| 104 | Type argType = behaviorEntry.getSignature().getArgumentTypes().get(argIndex); | ||
| 99 | // Unfortunately each of these have different name getters, so they have different code paths | 105 | // Unfortunately each of these have different name getters, so they have different code paths |
| 100 | if (argType.isPrimitive()) { | 106 | if (argType.isPrimitive()) { |
| 101 | Type.Primitive argCls = argType.getPrimitive(); | 107 | Type.Primitive argCls = argType.getPrimitive(); |
| 102 | argName = "a" + argCls.name() + (argi + 1); | 108 | argName = "a" + argCls.name() + (argIndex + 1); |
| 103 | } else if (argType.isArray()) { | 109 | } else if (argType.isArray()) { |
| 104 | // List types would require this whole block again, so just go with aListx | 110 | // List types would require this whole block again, so just go with aListx |
| 105 | argName = "aList" + (argi + 1); | 111 | argName = "aList" + (argIndex + 1); |
| 106 | } else if (argType.isClass()) { | 112 | } else if (argType.isClass()) { |
| 107 | ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry()); | 113 | ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry()); |
| 108 | argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argi + 1); | 114 | argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argIndex + 1); |
| 109 | } else { | 115 | } else { |
| 110 | argName = "a" + (argi + 1); | 116 | argName = "a" + (argIndex + 1); |
| 111 | } | 117 | } |
| 112 | } | 118 | } |
| 113 | renameVariable(table, i, constants.addUtf8Info(argName)); | 119 | renameVariable(table, i, constants.addUtf8Info(argName)); |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java index f302f130..f0f27cf5 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java | |||
| @@ -144,11 +144,10 @@ public class ClassMatching { | |||
| 144 | numAmbiguousDest += match.destClasses.size(); | 144 | numAmbiguousDest += match.destClasses.size(); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | String buf = String.format("%20s%8s%8s\n", "", "Source", "Dest") + String | 147 | return String.format("%20s%8s%8s\n", "", "Source", "Dest") + String |
| 148 | .format("%20s%8d%8d\n", "Classes", sourceClasses().size(), destClasses().size()) + String | 148 | .format("%20s%8d%8d\n", "Classes", sourceClasses().size(), destClasses().size()) + String |
| 149 | .format("%20s%8d%8d\n", "Uniquely matched", uniqueMatches().size(), uniqueMatches().size()) + String | 149 | .format("%20s%8d%8d\n", "Uniquely matched", uniqueMatches().size(), uniqueMatches().size()) + String |
| 150 | .format("%20s%8d%8d\n", "Ambiguously matched", numAmbiguousSource, numAmbiguousDest) + String | 150 | .format("%20s%8d%8d\n", "Ambiguously matched", numAmbiguousSource, numAmbiguousDest) + String |
| 151 | .format("%20s%8d%8d\n", "Unmatched", unmatchedSourceClasses().size(), unmatchedDestClasses().size()); | 151 | .format("%20s%8d%8d\n", "Unmatched", unmatchedSourceClasses().size(), unmatchedDestClasses().size()); |
| 152 | return buf; | ||
| 153 | } | 152 | } |
| 154 | } | 153 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java index ce1c1ceb..833a5340 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java | |||
| @@ -192,7 +192,6 @@ public class ClassMatchingGui { | |||
| 192 | } catch (MappingConflict ex) { | 192 | } catch (MappingConflict ex) { |
| 193 | System.out.println(ex.getMessage()); | 193 | System.out.println(ex.getMessage()); |
| 194 | ex.printStackTrace(); | 194 | ex.printStackTrace(); |
| 195 | return; | ||
| 196 | } | 195 | } |
| 197 | } | 196 | } |
| 198 | 197 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/src/main/java/cuchaz/enigma/gui/ClassSelector.java index 8df21947..ed84ef24 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelector.java | |||
| @@ -316,8 +316,11 @@ public class ClassSelector extends JTree { | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | public ClassEntry getFirstClass() { | 318 | public ClassEntry getFirstClass() { |
| 319 | for (ClassSelectorPackageNode packageNode : packageNodes()) { | 319 | ClassSelectorPackageNode packageNode = packageNodes().get(0); |
| 320 | for (ClassSelectorClassNode classNode : classNodes(packageNode)) { | 320 | if (packageNode != null) |
| 321 | { | ||
| 322 | ClassSelectorClassNode classNode = classNodes(packageNode).get(0); | ||
| 323 | if (classNode != null) { | ||
| 321 | return classNode.getClassEntry(); | 324 | return classNode.getClassEntry(); |
| 322 | } | 325 | } |
| 323 | } | 326 | } |
| @@ -360,7 +363,8 @@ public class ClassSelector extends JTree { | |||
| 360 | } | 363 | } |
| 361 | } else { | 364 | } else { |
| 362 | // return the next class | 365 | // return the next class |
| 363 | for (ClassSelectorClassNode classNode : classNodes(packageNode)) { | 366 | ClassSelectorClassNode classNode = classNodes(packageNode).get(0); |
| 367 | if (classNode != null) { | ||
| 364 | return classNode.getClassEntry(); | 368 | return classNode.getClassEntry(); |
| 365 | } | 369 | } |
| 366 | } | 370 | } |