diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode')
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/translators/ClassTranslator.java (renamed from src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java) | 38 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/translators/InnerClassWriter.java (renamed from src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java) | 27 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/translators/LocalVariableTranslator.java (renamed from src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java) | 30 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/bytecode/translators/MethodParameterTranslator.java (renamed from src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java) | 15 |
4 files changed, 43 insertions, 67 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java b/src/main/java/cuchaz/enigma/bytecode/translators/ClassTranslator.java index 1ebf656..4ac5a8b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassTranslator.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/ClassTranslator.java | |||
| @@ -9,8 +9,10 @@ | |||
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | 11 | ||
| 12 | package cuchaz.enigma.bytecode; | 12 | package cuchaz.enigma.bytecode.translators; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.bytecode.ClassRenamer; | ||
| 15 | import cuchaz.enigma.bytecode.ConstPoolEditor; | ||
| 14 | import cuchaz.enigma.mapping.*; | 16 | import cuchaz.enigma.mapping.*; |
| 15 | import javassist.CtBehavior; | 17 | import javassist.CtBehavior; |
| 16 | import javassist.CtClass; | 18 | import javassist.CtClass; |
| @@ -20,13 +22,7 @@ import javassist.bytecode.*; | |||
| 20 | 22 | ||
| 21 | public class ClassTranslator { | 23 | public class ClassTranslator { |
| 22 | 24 | ||
| 23 | private Translator translator; | 25 | public static void translate(Translator translator, CtClass c) { |
| 24 | |||
| 25 | public ClassTranslator(Translator translator) { | ||
| 26 | this.translator = translator; | ||
| 27 | } | ||
| 28 | |||
| 29 | public void translate(CtClass c) { | ||
| 30 | 26 | ||
| 31 | // NOTE: the order of these translations is very important | 27 | // NOTE: the order of these translations is very important |
| 32 | 28 | ||
| @@ -44,7 +40,7 @@ public class ClassTranslator { | |||
| 44 | constants.getFieldrefName(i), | 40 | constants.getFieldrefName(i), |
| 45 | constants.getFieldrefType(i) | 41 | constants.getFieldrefType(i) |
| 46 | ); | 42 | ); |
| 47 | FieldEntry translatedEntry = this.translator.translateEntry(entry); | 43 | FieldEntry translatedEntry = translator.translateEntry(entry); |
| 48 | if (!entry.equals(translatedEntry)) { | 44 | if (!entry.equals(translatedEntry)) { |
| 49 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); | 45 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getType().toString()); |
| 50 | } | 46 | } |
| @@ -60,7 +56,7 @@ public class ClassTranslator { | |||
| 60 | editor.getMemberrefName(i), | 56 | editor.getMemberrefName(i), |
| 61 | editor.getMemberrefType(i) | 57 | editor.getMemberrefType(i) |
| 62 | ); | 58 | ); |
| 63 | BehaviorEntry translatedEntry = this.translator.translateEntry(entry); | 59 | BehaviorEntry translatedEntry = translator.translateEntry(entry); |
| 64 | if (!entry.equals(translatedEntry)) { | 60 | if (!entry.equals(translatedEntry)) { |
| 65 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); | 61 | editor.changeMemberrefNameAndType(i, translatedEntry.getName(), translatedEntry.getSignature().toString()); |
| 66 | } | 62 | } |
| @@ -72,7 +68,7 @@ public class ClassTranslator { | |||
| 72 | } | 68 | } |
| 73 | 69 | ||
| 74 | ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); | 70 | ClassEntry classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); |
| 75 | Mappings.EntryModifier modifier = this.translator.getModifier(classEntry); | 71 | Mappings.EntryModifier modifier = translator.getModifier(classEntry); |
| 76 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) | 72 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) |
| 77 | ClassRenamer.applyModifier(c, modifier); | 73 | ClassRenamer.applyModifier(c, modifier); |
| 78 | 74 | ||
| @@ -81,8 +77,8 @@ public class ClassTranslator { | |||
| 81 | 77 | ||
| 82 | // translate the name | 78 | // translate the name |
| 83 | FieldEntry entry = EntryFactory.getFieldEntry(field); | 79 | FieldEntry entry = EntryFactory.getFieldEntry(field); |
| 84 | String translatedName = this.translator.translate(entry); | 80 | String translatedName = translator.translate(entry); |
| 85 | modifier = this.translator.getModifier(entry); | 81 | modifier = translator.getModifier(entry); |
| 86 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) | 82 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) |
| 87 | ClassRenamer.applyModifier(field, modifier); | 83 | ClassRenamer.applyModifier(field, modifier); |
| 88 | 84 | ||
| @@ -91,7 +87,7 @@ public class ClassTranslator { | |||
| 91 | } | 87 | } |
| 92 | 88 | ||
| 93 | // translate the type | 89 | // translate the type |
| 94 | Type translatedType = this.translator.translateType(entry.getType()); | 90 | Type translatedType = translator.translateType(entry.getType()); |
| 95 | field.getFieldInfo().setDescriptor(translatedType.toString()); | 91 | field.getFieldInfo().setDescriptor(translatedType.toString()); |
| 96 | } | 92 | } |
| 97 | 93 | ||
| @@ -100,7 +96,7 @@ public class ClassTranslator { | |||
| 100 | 96 | ||
| 101 | BehaviorEntry entry = EntryFactory.getBehaviorEntry(behavior); | 97 | BehaviorEntry entry = EntryFactory.getBehaviorEntry(behavior); |
| 102 | 98 | ||
| 103 | modifier = this.translator.getModifier(entry); | 99 | modifier = translator.getModifier(entry); |
| 104 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) | 100 | if (modifier != null && modifier != Mappings.EntryModifier.UNCHANGED) |
| 105 | ClassRenamer.applyModifier(behavior, modifier); | 101 | ClassRenamer.applyModifier(behavior, modifier); |
| 106 | 102 | ||
| @@ -108,7 +104,7 @@ public class ClassTranslator { | |||
| 108 | CtMethod method = (CtMethod) behavior; | 104 | CtMethod method = (CtMethod) behavior; |
| 109 | 105 | ||
| 110 | // translate the name | 106 | // translate the name |
| 111 | String translatedName = this.translator.translate(entry); | 107 | String translatedName = translator.translate(entry); |
| 112 | if (translatedName != null) { | 108 | if (translatedName != null) { |
| 113 | method.setName(translatedName); | 109 | method.setName(translatedName); |
| 114 | } | 110 | } |
| @@ -116,7 +112,7 @@ public class ClassTranslator { | |||
| 116 | 112 | ||
| 117 | if (entry.getSignature() != null) { | 113 | if (entry.getSignature() != null) { |
| 118 | // translate the signature | 114 | // translate the signature |
| 119 | Signature translatedSignature = this.translator.translateSignature(entry.getSignature()); | 115 | Signature translatedSignature = translator.translateSignature(entry.getSignature()); |
| 120 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); | 116 | behavior.getMethodInfo().setDescriptor(translatedSignature.toString()); |
| 121 | } | 117 | } |
| 122 | } | 118 | } |
| @@ -127,7 +123,7 @@ public class ClassTranslator { | |||
| 127 | 123 | ||
| 128 | if (enclosingMethodAttr.methodIndex() == 0) { | 124 | if (enclosingMethodAttr.methodIndex() == 0) { |
| 129 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); | 125 | BehaviorEntry obfBehaviorEntry = EntryFactory.getBehaviorEntry(Descriptor.toJvmName(enclosingMethodAttr.className())); |
| 130 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); | 126 | BehaviorEntry deobfBehaviorEntry = translator.translateEntry(obfBehaviorEntry); |
| 131 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 127 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 132 | constants, | 128 | constants, |
| 133 | deobfBehaviorEntry.getClassName() | 129 | deobfBehaviorEntry.getClassName() |
| @@ -138,7 +134,7 @@ public class ClassTranslator { | |||
| 138 | enclosingMethodAttr.methodName(), | 134 | enclosingMethodAttr.methodName(), |
| 139 | enclosingMethodAttr.methodDescriptor() | 135 | enclosingMethodAttr.methodDescriptor() |
| 140 | ); | 136 | ); |
| 141 | BehaviorEntry deobfBehaviorEntry = this.translator.translateEntry(obfBehaviorEntry); | 137 | BehaviorEntry deobfBehaviorEntry = translator.translateEntry(obfBehaviorEntry); |
| 142 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( | 138 | c.getClassFile().addAttribute(new EnclosingMethodAttribute( |
| 143 | constants, | 139 | constants, |
| 144 | deobfBehaviorEntry.getClassName(), | 140 | deobfBehaviorEntry.getClassName(), |
| @@ -150,10 +146,10 @@ public class ClassTranslator { | |||
| 150 | 146 | ||
| 151 | // translate all the class names referenced in the code | 147 | // translate all the class names referenced in the code |
| 152 | // the above code only changed method/field/reference names and types, but not the rest of the class references | 148 | // the above code only changed method/field/reference names and types, but not the rest of the class references |
| 153 | ClassRenamer.renameClasses(c, this.translator); | 149 | ClassRenamer.renameClasses(c, translator); |
| 154 | 150 | ||
| 155 | // translate the source file attribute too | 151 | // translate the source file attribute too |
| 156 | ClassEntry deobfClassEntry = this.translator.translateEntry(classEntry); | 152 | ClassEntry deobfClassEntry = translator.translateEntry(classEntry); |
| 157 | if (deobfClassEntry != null) { | 153 | if (deobfClassEntry != null) { |
| 158 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; | 154 | String sourceFile = Descriptor.toJvmName(deobfClassEntry.getOutermostClassEntry().getSimpleName()) + ".java"; |
| 159 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); | 155 | c.getClassFile().addAttribute(new SourceFileAttribute(constants, sourceFile)); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java b/src/main/java/cuchaz/enigma/bytecode/translators/InnerClassWriter.java index f1c3dd7..0e35938 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InnerClassWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/InnerClassWriter.java | |||
| @@ -9,10 +9,11 @@ | |||
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | 11 | ||
| 12 | package cuchaz.enigma.bytecode; | 12 | package cuchaz.enigma.bytecode.translators; |
| 13 | 13 | ||
| 14 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| 15 | import cuchaz.enigma.analysis.JarIndex; | 15 | import cuchaz.enigma.analysis.JarIndex; |
| 16 | import cuchaz.enigma.bytecode.ClassRenamer; | ||
| 16 | import cuchaz.enigma.mapping.*; | 17 | import cuchaz.enigma.mapping.*; |
| 17 | import javassist.ClassPool; | 18 | import javassist.ClassPool; |
| 18 | import javassist.CtClass; | 19 | import javassist.CtClass; |
| @@ -24,14 +25,6 @@ import java.util.List; | |||
| 24 | 25 | ||
| 25 | public class InnerClassWriter { | 26 | public class InnerClassWriter { |
| 26 | 27 | ||
| 27 | private JarIndex index; | ||
| 28 | private Translator deobfuscatorTranslator; | ||
| 29 | |||
| 30 | public InnerClassWriter(JarIndex index, Translator deobfuscatorTranslator) { | ||
| 31 | this.index = index; | ||
| 32 | this.deobfuscatorTranslator = deobfuscatorTranslator; | ||
| 33 | } | ||
| 34 | |||
| 35 | // FIXME: modifier is not applied to inner class | 28 | // FIXME: modifier is not applied to inner class |
| 36 | public static void changeModifier(CtClass c, InnerClassesAttribute attr, Translator translator) { | 29 | public static void changeModifier(CtClass c, InnerClassesAttribute attr, Translator translator) { |
| 37 | ClassPool pool = c.getClassPool(); | 30 | ClassPool pool = c.getClassPool(); |
| @@ -52,7 +45,7 @@ public class InnerClassWriter { | |||
| 52 | } | 45 | } |
| 53 | } | 46 | } |
| 54 | 47 | ||
| 55 | public void write(CtClass c) { | 48 | public static void write(JarIndex index, CtClass c) { |
| 56 | 49 | ||
| 57 | // don't change anything if there's already an attribute there | 50 | // don't change anything if there's already an attribute there |
| 58 | InnerClassesAttribute oldAttr = (InnerClassesAttribute) c.getClassFile().getAttribute(InnerClassesAttribute.tag); | 51 | InnerClassesAttribute oldAttr = (InnerClassesAttribute) c.getClassFile().getAttribute(InnerClassesAttribute.tag); |
| @@ -62,7 +55,7 @@ public class InnerClassWriter { | |||
| 62 | } | 55 | } |
| 63 | 56 | ||
| 64 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); | 57 | ClassEntry obfClassEntry = EntryFactory.getClassEntry(c); |
| 65 | List<ClassEntry> obfClassChain = this.index.getObfClassChain(obfClassEntry); | 58 | List<ClassEntry> obfClassChain = index.getObfClassChain(obfClassEntry); |
| 66 | 59 | ||
| 67 | boolean isInnerClass = obfClassChain.size() > 1; | 60 | boolean isInnerClass = obfClassChain.size() > 1; |
| 68 | if (isInnerClass) { | 61 | if (isInnerClass) { |
| @@ -70,7 +63,7 @@ public class InnerClassWriter { | |||
| 70 | // it's an inner class, rename it to the fully qualified name | 63 | // it's an inner class, rename it to the fully qualified name |
| 71 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); | 64 | c.setName(obfClassEntry.buildClassEntry(obfClassChain).getName()); |
| 72 | 65 | ||
| 73 | BehaviorEntry caller = this.index.getAnonymousClassCaller(obfClassEntry); | 66 | BehaviorEntry caller = index.getAnonymousClassCaller(obfClassEntry); |
| 74 | if (caller != null) { | 67 | if (caller != null) { |
| 75 | 68 | ||
| 76 | // write the enclosing method attribute | 69 | // write the enclosing method attribute |
| @@ -83,7 +76,7 @@ public class InnerClassWriter { | |||
| 83 | } | 76 | } |
| 84 | 77 | ||
| 85 | // does this class have any inner classes? | 78 | // does this class have any inner classes? |
| 86 | Collection<ClassEntry> obfInnerClassEntries = this.index.getInnerClasses(obfClassEntry); | 79 | Collection<ClassEntry> obfInnerClassEntries = index.getInnerClasses(obfClassEntry); |
| 87 | 80 | ||
| 88 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { | 81 | if (isInnerClass || !obfInnerClassEntries.isEmpty()) { |
| 89 | 82 | ||
| @@ -94,7 +87,7 @@ public class InnerClassWriter { | |||
| 94 | // write the ancestry, but not the outermost class | 87 | // write the ancestry, but not the outermost class |
| 95 | for (int i = 1; i < obfClassChain.size(); i++) { | 88 | for (int i = 1; i < obfClassChain.size(); i++) { |
| 96 | ClassEntry obfInnerClassEntry = obfClassChain.get(i); | 89 | ClassEntry obfInnerClassEntry = obfClassChain.get(i); |
| 97 | writeInnerClass(attr, obfClassChain, obfInnerClassEntry); | 90 | writeInnerClass(index, attr, obfClassChain, obfInnerClassEntry); |
| 98 | 91 | ||
| 99 | // update references to use the fully qualified inner class name | 92 | // update references to use the fully qualified inner class name |
| 100 | c.replaceClassName(obfInnerClassEntry.getName(), obfInnerClassEntry.buildClassEntry(obfClassChain).getName()); | 93 | c.replaceClassName(obfInnerClassEntry.getName(), obfInnerClassEntry.buildClassEntry(obfClassChain).getName()); |
| @@ -107,7 +100,7 @@ public class InnerClassWriter { | |||
| 107 | List<ClassEntry> extendedObfClassChain = Lists.newArrayList(obfClassChain); | 100 | List<ClassEntry> extendedObfClassChain = Lists.newArrayList(obfClassChain); |
| 108 | extendedObfClassChain.add(obfInnerClassEntry); | 101 | extendedObfClassChain.add(obfInnerClassEntry); |
| 109 | 102 | ||
| 110 | writeInnerClass(attr, extendedObfClassChain, obfInnerClassEntry); | 103 | writeInnerClass(index, attr, extendedObfClassChain, obfInnerClassEntry); |
| 111 | 104 | ||
| 112 | // update references to use the fully qualified inner class name | 105 | // update references to use the fully qualified inner class name |
| 113 | c.replaceClassName(obfInnerClassEntry.getName(), obfInnerClassEntry.buildClassEntry(extendedObfClassChain).getName()); | 106 | c.replaceClassName(obfInnerClassEntry.getName(), obfInnerClassEntry.buildClassEntry(extendedObfClassChain).getName()); |
| @@ -115,7 +108,7 @@ public class InnerClassWriter { | |||
| 115 | } | 108 | } |
| 116 | } | 109 | } |
| 117 | 110 | ||
| 118 | private void writeInnerClass(InnerClassesAttribute attr, List<ClassEntry> obfClassChain, ClassEntry obfClassEntry) { | 111 | private static void writeInnerClass(JarIndex index, InnerClassesAttribute attr, List<ClassEntry> obfClassChain, ClassEntry obfClassEntry) { |
| 119 | 112 | ||
| 120 | // get the new inner class name | 113 | // get the new inner class name |
| 121 | ClassEntry obfInnerClassEntry = obfClassEntry.buildClassEntry(obfClassChain); | 114 | ClassEntry obfInnerClassEntry = obfClassEntry.buildClassEntry(obfClassChain); |
| @@ -131,7 +124,7 @@ public class InnerClassWriter { | |||
| 131 | int innerClassNameIndex = 0; | 124 | int innerClassNameIndex = 0; |
| 132 | int accessFlags = AccessFlag.PUBLIC; | 125 | int accessFlags = AccessFlag.PUBLIC; |
| 133 | // TODO: need to figure out if we can put static or not | 126 | // TODO: need to figure out if we can put static or not |
| 134 | if (!this.index.isAnonymousClass(obfClassEntry)) { | 127 | if (!index.isAnonymousClass(obfClassEntry)) { |
| 135 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); | 128 | innerClassNameIndex = constPool.addUtf8Info(obfInnerClassEntry.getInnermostClassName()); |
| 136 | } | 129 | } |
| 137 | 130 | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/translators/LocalVariableTranslator.java index 878e30a..51b3d2d 100644 --- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/LocalVariableTranslator.java | |||
| @@ -9,22 +9,16 @@ | |||
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | 11 | ||
| 12 | package cuchaz.enigma.bytecode; | 12 | package cuchaz.enigma.bytecode.translators; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.mapping.*; | 14 | import cuchaz.enigma.mapping.*; |
| 15 | import javassist.CtBehavior; | 15 | import javassist.CtBehavior; |
| 16 | import javassist.CtClass; | 16 | import javassist.CtClass; |
| 17 | import javassist.bytecode.*; | 17 | import javassist.bytecode.*; |
| 18 | 18 | ||
| 19 | public class LocalVariableRenamer { | 19 | public class LocalVariableTranslator { |
| 20 | 20 | ||
| 21 | private Translator translator; | 21 | public static void translate(Translator translator, CtClass c) { |
| 22 | |||
| 23 | public LocalVariableRenamer(Translator translator) { | ||
| 24 | this.translator = translator; | ||
| 25 | } | ||
| 26 | |||
| 27 | public void rename(CtClass c) { | ||
| 28 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 22 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| 29 | 23 | ||
| 30 | // if there's a local variable table, just rename everything to v1, v2, v3, ... for now | 24 | // if there's a local variable table, just rename everything to v1, v2, v3, ... for now |
| @@ -38,7 +32,7 @@ public class LocalVariableRenamer { | |||
| 38 | 32 | ||
| 39 | LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); | 33 | LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); |
| 40 | if (table != null) { | 34 | if (table != null) { |
| 41 | renameLVT(behaviorEntry, constants, table, c); | 35 | renameLVT(translator, behaviorEntry, constants, table, c); |
| 42 | } | 36 | } |
| 43 | 37 | ||
| 44 | LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); | 38 | LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); |
| @@ -50,7 +44,7 @@ public class LocalVariableRenamer { | |||
| 50 | 44 | ||
| 51 | // DEBUG | 45 | // DEBUG |
| 52 | @SuppressWarnings("unused") | 46 | @SuppressWarnings("unused") |
| 53 | private void dumpTable(LocalVariableAttribute table) { | 47 | private static void dumpTable(LocalVariableAttribute table) { |
| 54 | for (int i = 0; i < table.tableLength(); i++) { | 48 | for (int i = 0; i < table.tableLength(); i++) { |
| 55 | System.out.println(String.format("\t%d (%d): %s %s", | 49 | System.out.println(String.format("\t%d (%d): %s %s", |
| 56 | i, table.index(i), table.variableName(i), table.descriptor(i) | 50 | i, table.index(i), table.variableName(i), table.descriptor(i) |
| @@ -58,7 +52,7 @@ public class LocalVariableRenamer { | |||
| 58 | } | 52 | } |
| 59 | } | 53 | } |
| 60 | 54 | ||
| 61 | private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table, CtClass ctClass) { | 55 | private static void renameLVT(Translator translator, BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table, CtClass ctClass) { |
| 62 | 56 | ||
| 63 | // skip empty tables | 57 | // skip empty tables |
| 64 | if (table.tableLength() <= 0) { | 58 | if (table.tableLength() <= 0) { |
| @@ -94,9 +88,7 @@ public class LocalVariableRenamer { | |||
| 94 | int argi = i - starti; | 88 | int argi = i - starti; |
| 95 | if (ctClass.isEnum()) | 89 | if (ctClass.isEnum()) |
| 96 | argi += 2; | 90 | argi += 2; |
| 97 | if (behaviorEntry.getClassEntry().getName().contains("ahd") && behaviorEntry instanceof ConstructorEntry) | 91 | String argName = translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); |
| 98 | System.out.println(behaviorEntry.getClassEntry() + " " + i); | ||
| 99 | String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); | ||
| 100 | if (argName == null) { | 92 | if (argName == null) { |
| 101 | int argIndex = isNestedClassConstructor ? argi + 1 : argi; | 93 | int argIndex = isNestedClassConstructor ? argi + 1 : argi; |
| 102 | if (ctClass.isEnum()) | 94 | if (ctClass.isEnum()) |
| @@ -110,7 +102,7 @@ public class LocalVariableRenamer { | |||
| 110 | // List types would require this whole block again, so just go with aListx | 102 | // List types would require this whole block again, so just go with aListx |
| 111 | argName = "aList" + (argIndex + 1); | 103 | argName = "aList" + (argIndex + 1); |
| 112 | } else if (argType.isClass()) { | 104 | } else if (argType.isClass()) { |
| 113 | ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry()); | 105 | ClassEntry argClsTrans = translator.translateEntry(argType.getClassEntry()); |
| 114 | argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argIndex + 1); | 106 | argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argIndex + 1); |
| 115 | } else { | 107 | } else { |
| 116 | argName = "a" + (argIndex + 1); | 108 | argName = "a" + (argIndex + 1); |
| @@ -127,19 +119,19 @@ public class LocalVariableRenamer { | |||
| 127 | } | 119 | } |
| 128 | } | 120 | } |
| 129 | 121 | ||
| 130 | private void renameLVTT(LocalVariableTypeAttribute typeTable, LocalVariableAttribute table) { | 122 | private static void renameLVTT(LocalVariableTypeAttribute typeTable, LocalVariableAttribute table) { |
| 131 | // rename args to the same names as in the LVT | 123 | // rename args to the same names as in the LVT |
| 132 | for (int i = 0; i < typeTable.tableLength(); i++) { | 124 | for (int i = 0; i < typeTable.tableLength(); i++) { |
| 133 | renameVariable(typeTable, i, getNameIndex(table, typeTable.index(i))); | 125 | renameVariable(typeTable, i, getNameIndex(table, typeTable.index(i))); |
| 134 | } | 126 | } |
| 135 | } | 127 | } |
| 136 | 128 | ||
| 137 | private void renameVariable(LocalVariableAttribute table, int i, int stringId) { | 129 | private static void renameVariable(LocalVariableAttribute table, int i, int stringId) { |
| 138 | // based off of LocalVariableAttribute.nameIndex() | 130 | // based off of LocalVariableAttribute.nameIndex() |
| 139 | ByteArray.write16bit(stringId, table.get(), i * 10 + 6); | 131 | ByteArray.write16bit(stringId, table.get(), i * 10 + 6); |
| 140 | } | 132 | } |
| 141 | 133 | ||
| 142 | private int getNameIndex(LocalVariableAttribute table, int index) { | 134 | private static int getNameIndex(LocalVariableAttribute table, int index) { |
| 143 | for (int i = 0; i < table.tableLength(); i++) { | 135 | for (int i = 0; i < table.tableLength(); i++) { |
| 144 | if (table.index(i) == index) { | 136 | if (table.index(i) == index) { |
| 145 | return table.nameIndex(i); | 137 | return table.nameIndex(i); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/translators/MethodParameterTranslator.java index d63572e..4e632b9 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/MethodParameterTranslator.java | |||
| @@ -9,8 +9,9 @@ | |||
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | 11 | ||
| 12 | package cuchaz.enigma.bytecode; | 12 | package cuchaz.enigma.bytecode.translators; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.bytecode.MethodParametersAttribute; | ||
| 14 | import cuchaz.enigma.mapping.*; | 15 | import cuchaz.enigma.mapping.*; |
| 15 | import javassist.CtBehavior; | 16 | import javassist.CtBehavior; |
| 16 | import javassist.CtClass; | 17 | import javassist.CtClass; |
| @@ -20,15 +21,9 @@ import javassist.bytecode.LocalVariableAttribute; | |||
| 20 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
| 21 | import java.util.List; | 22 | import java.util.List; |
| 22 | 23 | ||
| 23 | public class MethodParameterWriter { | 24 | public class MethodParameterTranslator { |
| 24 | 25 | ||
| 25 | private Translator translator; | 26 | public static void translate(Translator translator, CtClass c) { |
| 26 | |||
| 27 | public MethodParameterWriter(Translator translator) { | ||
| 28 | this.translator = translator; | ||
| 29 | } | ||
| 30 | |||
| 31 | public void writeMethodArguments(CtClass c) { | ||
| 32 | 27 | ||
| 33 | // Procyon will read method arguments from the "MethodParameters" attribute, so write those | 28 | // Procyon will read method arguments from the "MethodParameters" attribute, so write those |
| 34 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | 29 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { |
| @@ -57,7 +52,7 @@ public class MethodParameterWriter { | |||
| 57 | // get the list of argument names | 52 | // get the list of argument names |
| 58 | List<String> names = new ArrayList<>(numParams); | 53 | List<String> names = new ArrayList<>(numParams); |
| 59 | for (int i = 0; i < numParams; i++) { | 54 | for (int i = 0; i < numParams; i++) { |
| 60 | names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); | 55 | names.add(translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); |
| 61 | } | 56 | } |
| 62 | 57 | ||
| 63 | // save the mappings to the class | 58 | // save the mappings to the class |