From b19f9e0fd1a5c50dd1ed13dbcb057839c8296f77 Mon Sep 17 00:00:00 2001 From: Thog Date: Mon, 15 May 2017 00:02:18 +0200 Subject: Add offset for Enum constructor arguments (Fix #58) --- .../analysis/SourceIndexBehaviorVisitor.java | 5 ++--- .../enigma/analysis/SourceIndexClassVisitor.java | 7 ++++--- .../cuchaz/enigma/bytecode/InnerClassWriter.java | 2 +- .../enigma/bytecode/LocalVariableRenamer.java | 24 ++++++++++++++-------- .../java/cuchaz/enigma/convert/ClassMatching.java | 3 +-- .../java/cuchaz/enigma/gui/ClassMatchingGui.java | 1 - src/main/java/cuchaz/enigma/gui/ClassSelector.java | 10 ++++++--- 7 files changed, 30 insertions(+), 22 deletions(-) (limited to 'src/main/java/cuchaz') 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; import java.util.Map; public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { - private BehaviorEntry behaviorEntry; // TODO: Really fix Procyon index problem with inner classes @@ -35,9 +34,9 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { private Multimap unmatchedIdentifier = HashMultimap.create(); private Map identifierEntryCache = new HashMap<>(); - public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) { + public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry, boolean isEnum) { this.behaviorEntry = behaviorEntry; - this.argumentPosition = 0; + this.argumentPosition = isEnum ? 2 : 0; this.localsPosition = 0; } 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.*; public class SourceIndexClassVisitor extends SourceIndexVisitor { private ClassEntry classEntry; + private boolean isEnum; public SourceIndexClassVisitor(ClassEntry classEntry) { this.classEntry = classEntry; @@ -65,7 +66,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { } } index.addDeclaration(tokenNode, behaviorEntry); - return node.acceptVisitor(new SourceIndexBehaviorVisitor(behaviorEntry), index); + return node.acceptVisitor(new SourceIndexBehaviorVisitor(behaviorEntry, false), index); } @Override @@ -73,7 +74,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { MethodDefinition def = node.getUserData(Keys.METHOD_DEFINITION); ConstructorEntry constructorEntry = ProcyonEntryFactory.getConstructorEntry(def); index.addDeclaration(node.getNameToken(), constructorEntry); - return node.acceptVisitor(new SourceIndexBehaviorVisitor(constructorEntry), index); + return node.acceptVisitor(new SourceIndexBehaviorVisitor(constructorEntry, isEnum), index); } @Override @@ -93,7 +94,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor { FieldDefinition def = node.getUserData(Keys.FIELD_DEFINITION); FieldEntry fieldEntry = ProcyonEntryFactory.getFieldEntry(def); index.addDeclaration(node.getNameToken(), fieldEntry); - + this.isEnum = true; return recurse(node, index); } } 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 { this.deobfuscatorTranslator = deobfuscatorTranslator; } - // FIXME: modiffier is not applied to inner class + // FIXME: modifier is not applied to inner class public static void changeModifier(CtClass c, InnerClassesAttribute attr, Translator translator) { ClassPool pool = c.getClassPool(); 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 { LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); if (table != null) { - renameLVT(behaviorEntry, constants, table); + renameLVT(behaviorEntry, constants, table, c); } LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); @@ -58,7 +58,7 @@ public class LocalVariableRenamer { } } - private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table) { + private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table, CtClass ctClass) { // skip empty tables if (table.tableLength() <= 0) { @@ -69,14 +69,13 @@ public class LocalVariableRenamer { int starti = 0; if (table.variableName(0).equals("this")) { // skip the "this" variable - starti = 1; + starti++; } // rename method arguments first int numArgs = 0; if (behaviorEntry.getSignature() != null) { numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); - boolean isNestedClassConstructor = false; // 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 { for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { int argi = i - starti; + if (ctClass.isEnum()) + argi += 2; + if (behaviorEntry.getClassEntry().getName().contains("ahd") && behaviorEntry instanceof ConstructorEntry) + System.out.println(behaviorEntry.getClassEntry() + " " + i); String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); if (argName == null) { - Type argType = behaviorEntry.getSignature().getArgumentTypes().get(isNestedClassConstructor ? argi + 1 : argi); + int argIndex = isNestedClassConstructor ? argi + 1 : argi; + if (ctClass.isEnum()) + argIndex -= 2; + Type argType = behaviorEntry.getSignature().getArgumentTypes().get(argIndex); // Unfortunately each of these have different name getters, so they have different code paths if (argType.isPrimitive()) { Type.Primitive argCls = argType.getPrimitive(); - argName = "a" + argCls.name() + (argi + 1); + argName = "a" + argCls.name() + (argIndex + 1); } else if (argType.isArray()) { // List types would require this whole block again, so just go with aListx - argName = "aList" + (argi + 1); + argName = "aList" + (argIndex + 1); } else if (argType.isClass()) { ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry()); - argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argi + 1); + argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argIndex + 1); } else { - argName = "a" + (argi + 1); + argName = "a" + (argIndex + 1); } } 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 { numAmbiguousDest += match.destClasses.size(); } - String buf = String.format("%20s%8s%8s\n", "", "Source", "Dest") + String + return String.format("%20s%8s%8s\n", "", "Source", "Dest") + String .format("%20s%8d%8d\n", "Classes", sourceClasses().size(), destClasses().size()) + String .format("%20s%8d%8d\n", "Uniquely matched", uniqueMatches().size(), uniqueMatches().size()) + String .format("%20s%8d%8d\n", "Ambiguously matched", numAmbiguousSource, numAmbiguousDest) + String .format("%20s%8d%8d\n", "Unmatched", unmatchedSourceClasses().size(), unmatchedDestClasses().size()); - return buf; } } 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 { } catch (MappingConflict ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); - return; } } 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 { } public ClassEntry getFirstClass() { - for (ClassSelectorPackageNode packageNode : packageNodes()) { - for (ClassSelectorClassNode classNode : classNodes(packageNode)) { + ClassSelectorPackageNode packageNode = packageNodes().get(0); + if (packageNode != null) + { + ClassSelectorClassNode classNode = classNodes(packageNode).get(0); + if (classNode != null) { return classNode.getClassEntry(); } } @@ -360,7 +363,8 @@ public class ClassSelector extends JTree { } } else { // return the next class - for (ClassSelectorClassNode classNode : classNodes(packageNode)) { + ClassSelectorClassNode classNode = classNodes(packageNode).get(0); + if (classNode != null) { return classNode.getClassEntry(); } } -- cgit v1.2.3