diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode')
6 files changed, 123 insertions, 187 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java b/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java deleted file mode 100644 index 31c8691..0000000 --- a/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java +++ /dev/null | |||
| @@ -1,105 +0,0 @@ | |||
| 1 | package cuchaz.enigma.bytecode; | ||
| 2 | |||
| 3 | import cuchaz.enigma.analysis.Access; | ||
| 4 | import org.objectweb.asm.Opcodes; | ||
| 5 | |||
| 6 | import java.lang.reflect.Modifier; | ||
| 7 | |||
| 8 | public class AccessFlags { | ||
| 9 | private int flags; | ||
| 10 | |||
| 11 | public AccessFlags(int flags) { | ||
| 12 | this.flags = flags; | ||
| 13 | } | ||
| 14 | |||
| 15 | public boolean isPrivate() { | ||
| 16 | return Modifier.isPrivate(this.flags); | ||
| 17 | } | ||
| 18 | |||
| 19 | public boolean isProtected() { | ||
| 20 | return Modifier.isProtected(this.flags); | ||
| 21 | } | ||
| 22 | |||
| 23 | public boolean isPublic() { | ||
| 24 | return Modifier.isPublic(this.flags); | ||
| 25 | } | ||
| 26 | |||
| 27 | public boolean isSynthetic() { | ||
| 28 | return (this.flags & Opcodes.ACC_SYNTHETIC) != 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | public boolean isStatic() { | ||
| 32 | return Modifier.isStatic(this.flags); | ||
| 33 | } | ||
| 34 | |||
| 35 | public boolean isEnum() { | ||
| 36 | return (flags & Opcodes.ACC_ENUM) != 0; | ||
| 37 | } | ||
| 38 | |||
| 39 | public boolean isBridge() { | ||
| 40 | return (flags & Opcodes.ACC_BRIDGE) != 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | public AccessFlags setPrivate() { | ||
| 44 | this.setVisibility(Opcodes.ACC_PRIVATE); | ||
| 45 | return this; | ||
| 46 | } | ||
| 47 | |||
| 48 | public AccessFlags setProtected() { | ||
| 49 | this.setVisibility(Opcodes.ACC_PROTECTED); | ||
| 50 | return this; | ||
| 51 | } | ||
| 52 | |||
| 53 | public AccessFlags setPublic() { | ||
| 54 | this.setVisibility(Opcodes.ACC_PUBLIC); | ||
| 55 | return this; | ||
| 56 | } | ||
| 57 | |||
| 58 | public AccessFlags setBridge() { | ||
| 59 | flags |= Opcodes.ACC_BRIDGE; | ||
| 60 | return this; | ||
| 61 | } | ||
| 62 | |||
| 63 | @Deprecated | ||
| 64 | public AccessFlags setBridged() { | ||
| 65 | return setBridge(); | ||
| 66 | } | ||
| 67 | |||
| 68 | public void setVisibility(int visibility) { | ||
| 69 | this.resetVisibility(); | ||
| 70 | this.flags |= visibility; | ||
| 71 | } | ||
| 72 | |||
| 73 | private void resetVisibility() { | ||
| 74 | this.flags &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); | ||
| 75 | } | ||
| 76 | |||
| 77 | public int getFlags() { | ||
| 78 | return this.flags; | ||
| 79 | } | ||
| 80 | |||
| 81 | @Override | ||
| 82 | public boolean equals(Object obj) { | ||
| 83 | return obj instanceof AccessFlags && ((AccessFlags) obj).flags == flags; | ||
| 84 | } | ||
| 85 | |||
| 86 | @Override | ||
| 87 | public int hashCode() { | ||
| 88 | return flags; | ||
| 89 | } | ||
| 90 | |||
| 91 | @Override | ||
| 92 | public String toString() { | ||
| 93 | StringBuilder builder = new StringBuilder(Access.get(this).toString().toLowerCase()); | ||
| 94 | if (isStatic()) { | ||
| 95 | builder.append(" static"); | ||
| 96 | } | ||
| 97 | if (isSynthetic()) { | ||
| 98 | builder.append(" synthetic"); | ||
| 99 | } | ||
| 100 | if (isBridge()) { | ||
| 101 | builder.append(" bridge"); | ||
| 102 | } | ||
| 103 | return builder.toString(); | ||
| 104 | } | ||
| 105 | } | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/AsmObjectTranslator.java b/src/main/java/cuchaz/enigma/bytecode/translators/AsmObjectTranslator.java new file mode 100644 index 0000000..1a2b47f --- /dev/null +++ b/src/main/java/cuchaz/enigma/bytecode/translators/AsmObjectTranslator.java | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | ||
| 2 | |||
| 3 | import cuchaz.enigma.translation.Translator; | ||
| 4 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 5 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 6 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 7 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 8 | import org.objectweb.asm.Handle; | ||
| 9 | import org.objectweb.asm.Type; | ||
| 10 | |||
| 11 | public class AsmObjectTranslator { | ||
| 12 | public static Type translateType(Translator translator, Type type) { | ||
| 13 | String descString = type.getDescriptor(); | ||
| 14 | switch (type.getSort()) { | ||
| 15 | case Type.OBJECT: { | ||
| 16 | ClassEntry classEntry = new ClassEntry(type.getInternalName()); | ||
| 17 | return Type.getObjectType(translator.translate(classEntry).getFullName()); | ||
| 18 | } | ||
| 19 | case Type.ARRAY: { | ||
| 20 | TypeDescriptor descriptor = new TypeDescriptor(descString); | ||
| 21 | return Type.getType(translator.translate(descriptor).toString()); | ||
| 22 | } | ||
| 23 | case Type.METHOD: { | ||
| 24 | MethodDescriptor descriptor = new MethodDescriptor(descString); | ||
| 25 | return Type.getMethodType(translator.translate(descriptor).toString()); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | return type; | ||
| 29 | } | ||
| 30 | |||
| 31 | public static Handle translateHandle(Translator translator, Handle handle) { | ||
| 32 | MethodEntry entry = new MethodEntry(new ClassEntry(handle.getOwner()), handle.getName(), new MethodDescriptor(handle.getDesc())); | ||
| 33 | MethodEntry translatedMethod = translator.translate(entry); | ||
| 34 | ClassEntry ownerClass = translatedMethod.getParent(); | ||
| 35 | return new Handle(handle.getTag(), ownerClass.getFullName(), translatedMethod.getName(), translatedMethod.getDesc().toString(), handle.isInterface()); | ||
| 36 | } | ||
| 37 | |||
| 38 | public static Object translateValue(Translator translator, Object value) { | ||
| 39 | if (value instanceof Type) { | ||
| 40 | return translateType(translator, (Type) value); | ||
| 41 | } else if (value instanceof Handle) { | ||
| 42 | return translateHandle(translator, (Handle) value); | ||
| 43 | } | ||
| 44 | return value; | ||
| 45 | } | ||
| 46 | } | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java index 2e5b54d..cb843ad 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.mapping.Translator; | 3 | import cuchaz.enigma.translation.Translator; |
| 4 | import cuchaz.enigma.mapping.TypeDescriptor; | 4 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 5 | import cuchaz.enigma.mapping.entry.ClassEntry; | 5 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 6 | import cuchaz.enigma.mapping.entry.FieldEntry; | 6 | import cuchaz.enigma.translation.representation.entry.FieldEntry; |
| 7 | import org.objectweb.asm.AnnotationVisitor; | 7 | import org.objectweb.asm.AnnotationVisitor; |
| 8 | 8 | ||
| 9 | public class TranslationAnnotationVisitor extends AnnotationVisitor { | 9 | public class TranslationAnnotationVisitor extends AnnotationVisitor { |
| @@ -18,7 +18,7 @@ public class TranslationAnnotationVisitor extends AnnotationVisitor { | |||
| 18 | 18 | ||
| 19 | @Override | 19 | @Override |
| 20 | public void visit(String name, Object value) { | 20 | public void visit(String name, Object value) { |
| 21 | super.visit(name, translator.getTranslatedValue(value)); | 21 | super.visit(name, AsmObjectTranslator.translateValue(translator, value)); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | @Override | 24 | @Override |
| @@ -30,22 +30,22 @@ public class TranslationAnnotationVisitor extends AnnotationVisitor { | |||
| 30 | public AnnotationVisitor visitAnnotation(String name, String desc) { | 30 | public AnnotationVisitor visitAnnotation(String name, String desc) { |
| 31 | TypeDescriptor type = new TypeDescriptor(desc); | 31 | TypeDescriptor type = new TypeDescriptor(desc); |
| 32 | if (name != null) { | 32 | if (name != null) { |
| 33 | FieldEntry annotationField = translator.getTranslatedField(new FieldEntry(annotationEntry, name, type)); | 33 | FieldEntry annotationField = translator.translate(new FieldEntry(annotationEntry, name, type)); |
| 34 | return super.visitAnnotation(annotationField.getName(), annotationField.getDesc().toString()); | 34 | return super.visitAnnotation(annotationField.getName(), annotationField.getDesc().toString()); |
| 35 | } else { | 35 | } else { |
| 36 | return super.visitAnnotation(null, translator.getTranslatedTypeDesc(type).toString()); | 36 | return super.visitAnnotation(null, translator.translate(type).toString()); |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | @Override | 40 | @Override |
| 41 | public void visitEnum(String name, String desc, String value) { | 41 | public void visitEnum(String name, String desc, String value) { |
| 42 | TypeDescriptor type = new TypeDescriptor(desc); | 42 | TypeDescriptor type = new TypeDescriptor(desc); |
| 43 | FieldEntry enumField = translator.getTranslatedField(new FieldEntry(type.getTypeEntry(), value, type)); | 43 | FieldEntry enumField = translator.translate(new FieldEntry(type.getTypeEntry(), value, type)); |
| 44 | if (name != null) { | 44 | if (name != null) { |
| 45 | FieldEntry annotationField = translator.getTranslatedField(new FieldEntry(annotationEntry, name, type)); | 45 | FieldEntry annotationField = translator.translate(new FieldEntry(annotationEntry, name, type)); |
| 46 | super.visitEnum(annotationField.getName(), annotationField.getDesc().toString(), enumField.getName()); | 46 | super.visitEnum(annotationField.getName(), annotationField.getDesc().toString(), enumField.getName()); |
| 47 | } else { | 47 | } else { |
| 48 | super.visitEnum(null, translator.getTranslatedTypeDesc(type).toString(), enumField.getName()); | 48 | super.visitEnum(null, translator.translate(type).toString(), enumField.getName()); |
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java index 5b16138..53d09bb 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java | |||
| @@ -11,61 +11,53 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.bytecode.translators; | 12 | package cuchaz.enigma.bytecode.translators; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.JarIndex; | 14 | import cuchaz.enigma.translation.Translator; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | 16 | import cuchaz.enigma.translation.representation.ReferencedEntryPool; |
| 17 | import cuchaz.enigma.mapping.Signature; | 17 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 18 | import cuchaz.enigma.mapping.Translator; | 18 | import cuchaz.enigma.translation.representation.entry.*; |
| 19 | import cuchaz.enigma.mapping.TypeDescriptor; | ||
| 20 | import cuchaz.enigma.mapping.entry.*; | ||
| 21 | import org.objectweb.asm.*; | 19 | import org.objectweb.asm.*; |
| 22 | 20 | ||
| 21 | import java.util.Arrays; | ||
| 22 | |||
| 23 | public class TranslationClassVisitor extends ClassVisitor { | 23 | public class TranslationClassVisitor extends ClassVisitor { |
| 24 | private final Translator translator; | 24 | private final Translator translator; |
| 25 | private final JarIndex jarIndex; | ||
| 26 | private final ReferencedEntryPool entryPool; | 25 | private final ReferencedEntryPool entryPool; |
| 27 | 26 | ||
| 28 | private ClassDefEntry obfClassEntry; | 27 | private ClassDefEntry obfClassEntry; |
| 29 | private Signature obfSignature; | ||
| 30 | 28 | ||
| 31 | public TranslationClassVisitor(Translator translator, JarIndex jarIndex, ReferencedEntryPool entryPool, int api, ClassVisitor cv) { | 29 | public TranslationClassVisitor(Translator translator, ReferencedEntryPool entryPool, int api, ClassVisitor cv) { |
| 32 | super(api, cv); | 30 | super(api, cv); |
| 33 | this.translator = translator; | 31 | this.translator = translator; |
| 34 | this.jarIndex = jarIndex; | ||
| 35 | this.entryPool = entryPool; | 32 | this.entryPool = entryPool; |
| 36 | } | 33 | } |
| 37 | 34 | ||
| 38 | @Override | 35 | @Override |
| 39 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { | 36 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { |
| 40 | obfSignature = Signature.createSignature(signature); | 37 | obfClassEntry = ClassDefEntry.parse(access, name, signature, superName, interfaces); |
| 41 | obfClassEntry = new ClassDefEntry(name, obfSignature, new AccessFlags(access)); | 38 | |
| 42 | ClassDefEntry translatedEntry = translator.getTranslatedClassDef(obfClassEntry); | 39 | ClassDefEntry translatedEntry = translator.translate(obfClassEntry); |
| 43 | ClassEntry superEntry = translator.getTranslatedClass(entryPool.getClass(superName)); | 40 | String translatedSuper = translatedEntry.getSuperClass() != null ? translatedEntry.getSuperClass().getFullName() : null; |
| 44 | String[] translatedInterfaces = new String[interfaces.length]; | 41 | String[] translatedInterfaces = Arrays.stream(translatedEntry.getInterfaces()).map(ClassEntry::getFullName).toArray(String[]::new); |
| 45 | for (int i = 0; i < interfaces.length; i++) { | 42 | |
| 46 | translatedInterfaces[i] = translator.getTranslatedClass(entryPool.getClass(interfaces[i])).getName(); | 43 | super.visit(version, translatedEntry.getAccess().getFlags(), translatedEntry.getFullName(), translatedEntry.getSignature().toString(), translatedSuper, translatedInterfaces); |
| 47 | } | ||
| 48 | super.visit(version, translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getSignature().toString(), superEntry.getName(), translatedInterfaces); | ||
| 49 | } | 44 | } |
| 50 | 45 | ||
| 51 | @Override | 46 | @Override |
| 52 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { | 47 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { |
| 53 | FieldDefEntry entry = new FieldDefEntry(obfClassEntry, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access)); | 48 | FieldDefEntry entry = FieldDefEntry.parse(obfClassEntry, access, name, desc, signature); |
| 54 | FieldDefEntry translatedEntry = translator.getTranslatedFieldDef(entry); | 49 | FieldDefEntry translatedEntry = translator.translate(entry); |
| 55 | FieldVisitor fv = super.visitField(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), value); | 50 | FieldVisitor fv = super.visitField(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), value); |
| 56 | return new TranslationFieldVisitor(translator, translatedEntry, api, fv); | 51 | return new TranslationFieldVisitor(translator, translatedEntry, api, fv); |
| 57 | } | 52 | } |
| 58 | 53 | ||
| 59 | @Override | 54 | @Override |
| 60 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | 55 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { |
| 61 | MethodDefEntry entry = new MethodDefEntry(obfClassEntry, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); | 56 | MethodDefEntry entry = MethodDefEntry.parse(obfClassEntry, access, name, desc, signature); |
| 62 | MethodDefEntry translatedEntry = translator.getTranslatedMethodDef(entry); | 57 | MethodDefEntry translatedEntry = translator.translate(entry); |
| 63 | if (jarIndex.getBridgedMethod(entry) != null) { | ||
| 64 | translatedEntry.getAccess().setBridge(); | ||
| 65 | } | ||
| 66 | String[] translatedExceptions = new String[exceptions.length]; | 58 | String[] translatedExceptions = new String[exceptions.length]; |
| 67 | for (int i = 0; i < exceptions.length; i++) { | 59 | for (int i = 0; i < exceptions.length; i++) { |
| 68 | translatedExceptions[i] = translator.getTranslatedClass(entryPool.getClass(exceptions[i])).getName(); | 60 | translatedExceptions[i] = translator.translate(entryPool.getClass(exceptions[i])).getFullName(); |
| 69 | } | 61 | } |
| 70 | MethodVisitor mv = super.visitMethod(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), translatedExceptions); | 62 | MethodVisitor mv = super.visitMethod(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), translatedExceptions); |
| 71 | return new TranslationMethodVisitor(translator, obfClassEntry, entry, api, mv); | 63 | return new TranslationMethodVisitor(translator, obfClassEntry, entry, api, mv); |
| @@ -73,25 +65,25 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 73 | 65 | ||
| 74 | @Override | 66 | @Override |
| 75 | public void visitInnerClass(String name, String outerName, String innerName, int access) { | 67 | public void visitInnerClass(String name, String outerName, String innerName, int access) { |
| 76 | ClassDefEntry translatedEntry = translator.getTranslatedClassDef(new ClassDefEntry(name, obfSignature, new AccessFlags(access))); | 68 | ClassDefEntry classEntry = ClassDefEntry.parse(access, name, obfClassEntry.getSignature().toString(), null, new String[0]); |
| 77 | String translatedName = translatedEntry.getName(); | 69 | ClassDefEntry translatedEntry = translator.translate(classEntry); |
| 78 | int separatorIndex = translatedName.lastIndexOf("$"); | 70 | ClassEntry translatedOuterClass = translatedEntry.getOuterClass(); |
| 79 | String parentName = translatedName.substring(0, separatorIndex); | 71 | if (translatedOuterClass == null) { |
| 80 | String childName = translatedName.substring(separatorIndex + 1); | 72 | throw new IllegalStateException("Translated inner class did not have outer class"); |
| 81 | 73 | } | |
| 82 | ClassEntry outerEntry = translator.getTranslatedClass(entryPool.getClass(parentName)); | ||
| 83 | 74 | ||
| 84 | // Anonymous classes do not specify an outer or inner name. As we do not translate from the given parameter, ignore if the input is null | 75 | // Anonymous classes do not specify an outer or inner name. As we do not translate from the given parameter, ignore if the input is null |
| 85 | String translatedOuterName = outerName != null ? outerEntry.getName() : null; | 76 | String translatedName = translatedEntry.getFullName(); |
| 86 | String translatedInnerName = innerName != null ? childName : null; | 77 | String translatedOuterName = outerName != null ? translatedOuterClass.getFullName() : null; |
| 78 | String translatedInnerName = innerName != null ? translatedEntry.getName() : null; | ||
| 87 | super.visitInnerClass(translatedName, translatedOuterName, translatedInnerName, translatedEntry.getAccess().getFlags()); | 79 | super.visitInnerClass(translatedName, translatedOuterName, translatedInnerName, translatedEntry.getAccess().getFlags()); |
| 88 | } | 80 | } |
| 89 | 81 | ||
| 90 | @Override | 82 | @Override |
| 91 | public void visitOuterClass(String owner, String name, String desc) { | 83 | public void visitOuterClass(String owner, String name, String desc) { |
| 92 | if (desc != null) { | 84 | if (desc != null) { |
| 93 | MethodEntry translatedEntry = translator.getTranslatedMethod(new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc))); | 85 | MethodEntry translatedEntry = translator.translate(new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc))); |
| 94 | super.visitOuterClass(translatedEntry.getClassName(), translatedEntry.getName(), translatedEntry.getDesc().toString()); | 86 | super.visitOuterClass(translatedEntry.getParent().getFullName(), translatedEntry.getName(), translatedEntry.getDesc().toString()); |
| 95 | } else { | 87 | } else { |
| 96 | super.visitOuterClass(owner, name, desc); | 88 | super.visitOuterClass(owner, name, desc); |
| 97 | } | 89 | } |
| @@ -99,14 +91,14 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 99 | 91 | ||
| 100 | @Override | 92 | @Override |
| 101 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | 93 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { |
| 102 | TypeDescriptor translatedDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 94 | TypeDescriptor translatedDesc = translator.translate(new TypeDescriptor(desc)); |
| 103 | AnnotationVisitor av = super.visitAnnotation(translatedDesc.toString(), visible); | 95 | AnnotationVisitor av = super.visitAnnotation(translatedDesc.toString(), visible); |
| 104 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); | 96 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); |
| 105 | } | 97 | } |
| 106 | 98 | ||
| 107 | @Override | 99 | @Override |
| 108 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { | 100 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { |
| 109 | TypeDescriptor translatedDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 101 | TypeDescriptor translatedDesc = translator.translate(new TypeDescriptor(desc)); |
| 110 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, translatedDesc.toString(), visible); | 102 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, translatedDesc.toString(), visible); |
| 111 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); | 103 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); |
| 112 | } | 104 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationFieldVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationFieldVisitor.java index e4695fb..28fc199 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationFieldVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationFieldVisitor.java | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.mapping.Translator; | 3 | import cuchaz.enigma.translation.Translator; |
| 4 | import cuchaz.enigma.mapping.TypeDescriptor; | 4 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 5 | import cuchaz.enigma.mapping.entry.FieldDefEntry; | 5 | import cuchaz.enigma.translation.representation.entry.FieldDefEntry; |
| 6 | import org.objectweb.asm.AnnotationVisitor; | 6 | import org.objectweb.asm.AnnotationVisitor; |
| 7 | import org.objectweb.asm.FieldVisitor; | 7 | import org.objectweb.asm.FieldVisitor; |
| 8 | import org.objectweb.asm.TypePath; | 8 | import org.objectweb.asm.TypePath; |
| @@ -19,14 +19,14 @@ public class TranslationFieldVisitor extends FieldVisitor { | |||
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | 21 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { |
| 22 | TypeDescriptor typeDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 22 | TypeDescriptor typeDesc = translator.translate(new TypeDescriptor(desc)); |
| 23 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); | 23 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); |
| 24 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); | 24 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | @Override | 27 | @Override |
| 28 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { | 28 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { |
| 29 | TypeDescriptor typeDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 29 | TypeDescriptor typeDesc = translator.translate(new TypeDescriptor(desc)); |
| 30 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); | 30 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); |
| 31 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); | 31 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); |
| 32 | } | 32 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java index 6d0d550..a5a33e6 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java | |||
| @@ -1,7 +1,11 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.mapping.*; | 3 | import cuchaz.enigma.translation.Translator; |
| 4 | import cuchaz.enigma.mapping.entry.*; | 4 | import cuchaz.enigma.translation.mapping.NameValidator; |
| 5 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 6 | import cuchaz.enigma.translation.representation.Signature; | ||
| 7 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 8 | import cuchaz.enigma.translation.representation.entry.*; | ||
| 5 | import org.objectweb.asm.*; | 9 | import org.objectweb.asm.*; |
| 6 | 10 | ||
| 7 | import java.util.Collection; | 11 | import java.util.Collection; |
| @@ -26,15 +30,15 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 26 | @Override | 30 | @Override |
| 27 | public void visitFieldInsn(int opcode, String owner, String name, String desc) { | 31 | public void visitFieldInsn(int opcode, String owner, String name, String desc) { |
| 28 | FieldEntry entry = new FieldEntry(new ClassEntry(owner), name, new TypeDescriptor(desc)); | 32 | FieldEntry entry = new FieldEntry(new ClassEntry(owner), name, new TypeDescriptor(desc)); |
| 29 | FieldEntry translatedEntry = translator.getTranslatedField(entry); | 33 | FieldEntry translatedEntry = translator.translate(entry); |
| 30 | super.visitFieldInsn(opcode, translatedEntry.getClassName(), translatedEntry.getName(), translatedEntry.getDesc().toString()); | 34 | super.visitFieldInsn(opcode, translatedEntry.getParent().getFullName(), translatedEntry.getName(), translatedEntry.getDesc().toString()); |
| 31 | } | 35 | } |
| 32 | 36 | ||
| 33 | @Override | 37 | @Override |
| 34 | public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { | 38 | public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { |
| 35 | MethodEntry entry = new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc)); | 39 | MethodEntry entry = new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc)); |
| 36 | MethodEntry translatedEntry = translator.getTranslatedMethod(entry); | 40 | MethodEntry translatedEntry = translator.translate(entry); |
| 37 | super.visitMethodInsn(opcode, translatedEntry.getClassName(), translatedEntry.getName(), translatedEntry.getDesc().toString(), itf); | 41 | super.visitMethodInsn(opcode, translatedEntry.getParent().getFullName(), translatedEntry.getName(), translatedEntry.getDesc().toString(), itf); |
| 38 | } | 42 | } |
| 39 | 43 | ||
| 40 | @Override | 44 | @Override |
| @@ -52,7 +56,7 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 52 | Object object = array[i]; | 56 | Object object = array[i]; |
| 53 | if (object instanceof String) { | 57 | if (object instanceof String) { |
| 54 | String type = (String) object; | 58 | String type = (String) object; |
| 55 | array[i] = translator.getTranslatedClass(new ClassEntry(type)).getName(); | 59 | array[i] = translator.translate(new ClassEntry(type)).getFullName(); |
| 56 | } | 60 | } |
| 57 | } | 61 | } |
| 58 | return array; | 62 | return array; |
| @@ -60,21 +64,21 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 60 | 64 | ||
| 61 | @Override | 65 | @Override |
| 62 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | 66 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { |
| 63 | TypeDescriptor typeDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 67 | TypeDescriptor typeDesc = translator.translate(new TypeDescriptor(desc)); |
| 64 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); | 68 | AnnotationVisitor av = super.visitAnnotation(typeDesc.toString(), visible); |
| 65 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); | 69 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); |
| 66 | } | 70 | } |
| 67 | 71 | ||
| 68 | @Override | 72 | @Override |
| 69 | public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { | 73 | public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { |
| 70 | TypeDescriptor typeDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 74 | TypeDescriptor typeDesc = translator.translate(new TypeDescriptor(desc)); |
| 71 | AnnotationVisitor av = super.visitParameterAnnotation(parameter, typeDesc.toString(), visible); | 75 | AnnotationVisitor av = super.visitParameterAnnotation(parameter, typeDesc.toString(), visible); |
| 72 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); | 76 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); |
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | @Override | 79 | @Override |
| 76 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { | 80 | public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { |
| 77 | TypeDescriptor typeDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 81 | TypeDescriptor typeDesc = translator.translate(new TypeDescriptor(desc)); |
| 78 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, typeDesc.toString(), visible); | 82 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, typeDesc.toString(), visible); |
| 79 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); | 83 | return new TranslationAnnotationVisitor(translator, typeDesc.getTypeEntry(), api, av); |
| 80 | } | 84 | } |
| @@ -83,19 +87,18 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 83 | public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { | 87 | public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { |
| 84 | hasParameterMeta = true; | 88 | hasParameterMeta = true; |
| 85 | 89 | ||
| 86 | String translatedSignature = translator.getTranslatedSignature(Signature.createTypedSignature(signature)).toString(); | 90 | String translatedSignature = translator.translate(Signature.createTypedSignature(signature)).toString(); |
| 87 | int argumentIndex = methodEntry.getArgumentIndex(ownerEntry, index); | 91 | int argumentIndex = methodEntry.getArgumentIndex(ownerEntry, index); |
| 88 | 92 | ||
| 89 | if (argumentIndex >= 0) { | 93 | if (argumentIndex >= 0) { |
| 90 | LocalVariableDefEntry entry = new LocalVariableDefEntry(methodEntry, index, name, new TypeDescriptor(desc)); | 94 | LocalVariableDefEntry entry = new LocalVariableDefEntry(methodEntry, index, name, true, new TypeDescriptor(desc)); |
| 91 | LocalVariableDefEntry translatedEntry = translator.getTranslatedVariableDef(entry); | 95 | LocalVariableDefEntry translatedEntry = translator.translate(entry); |
| 92 | String translatedName = translatedEntry.getName(); | 96 | String translatedName = translatedEntry.getName(); |
| 93 | 97 | ||
| 94 | // TODO: Better name inference | ||
| 95 | if (translatedName.equals(entry.getName())) { | 98 | if (translatedName.equals(entry.getName())) { |
| 96 | List<TypeDescriptor> arguments = methodEntry.getDesc().getArgumentDescs(); | 99 | List<TypeDescriptor> arguments = methodEntry.getDesc().getArgumentDescs(); |
| 97 | List<TypeDescriptor> translatedArguments = arguments.stream() | 100 | List<TypeDescriptor> translatedArguments = arguments.stream() |
| 98 | .map(translator::getTranslatedTypeDesc) | 101 | .map(translator::translate) |
| 99 | .collect(Collectors.toList()); | 102 | .collect(Collectors.toList()); |
| 100 | 103 | ||
| 101 | boolean argument = argumentIndex < arguments.size(); | 104 | boolean argument = argumentIndex < arguments.size(); |
| @@ -109,42 +112,42 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 109 | super.visitLocalVariable(translatedName, translatedEntry.getDesc().toString(), translatedSignature, start, end, index); | 112 | super.visitLocalVariable(translatedName, translatedEntry.getDesc().toString(), translatedSignature, start, end, index); |
| 110 | } else { | 113 | } else { |
| 111 | // Handle "this" variable | 114 | // Handle "this" variable |
| 112 | TypeDescriptor translatedDesc = translator.getTranslatedTypeDesc(new TypeDescriptor(desc)); | 115 | TypeDescriptor translatedDesc = translator.translate(new TypeDescriptor(desc)); |
| 113 | super.visitLocalVariable(name, translatedDesc.toString(), translatedSignature, start, end, index); | 116 | super.visitLocalVariable(name, translatedDesc.toString(), translatedSignature, start, end, index); |
| 114 | } | 117 | } |
| 115 | } | 118 | } |
| 116 | 119 | ||
| 117 | @Override | 120 | @Override |
| 118 | public void visitTypeInsn(int opcode, String type) { | 121 | public void visitTypeInsn(int opcode, String type) { |
| 119 | ClassEntry translatedEntry = translator.getTranslatedClass(new ClassEntry(type)); | 122 | ClassEntry translatedEntry = translator.translate(new ClassEntry(type)); |
| 120 | super.visitTypeInsn(opcode, translatedEntry.getName()); | 123 | super.visitTypeInsn(opcode, translatedEntry.getFullName()); |
| 121 | } | 124 | } |
| 122 | 125 | ||
| 123 | @Override | 126 | @Override |
| 124 | public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { | 127 | public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { |
| 125 | MethodDescriptor translatedMethodDesc = translator.getTranslatedMethodDesc(new MethodDescriptor(desc)); | 128 | MethodDescriptor translatedMethodDesc = translator.translate(new MethodDescriptor(desc)); |
| 126 | Object[] translatedBsmArgs = new Object[bsmArgs.length]; | 129 | Object[] translatedBsmArgs = new Object[bsmArgs.length]; |
| 127 | for (int i = 0; i < bsmArgs.length; i++) { | 130 | for (int i = 0; i < bsmArgs.length; i++) { |
| 128 | translatedBsmArgs[i] = translator.getTranslatedValue(bsmArgs[i]); | 131 | translatedBsmArgs[i] = AsmObjectTranslator.translateValue(translator, bsmArgs[i]); |
| 129 | } | 132 | } |
| 130 | super.visitInvokeDynamicInsn(name, translatedMethodDesc.toString(), translator.getTranslatedHandle(bsm), translatedBsmArgs); | 133 | super.visitInvokeDynamicInsn(name, translatedMethodDesc.toString(), AsmObjectTranslator.translateHandle(translator, bsm), translatedBsmArgs); |
| 131 | } | 134 | } |
| 132 | 135 | ||
| 133 | @Override | 136 | @Override |
| 134 | public void visitLdcInsn(Object cst) { | 137 | public void visitLdcInsn(Object cst) { |
| 135 | super.visitLdcInsn(translator.getTranslatedValue(cst)); | 138 | super.visitLdcInsn(AsmObjectTranslator.translateValue(translator, cst)); |
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | @Override | 141 | @Override |
| 139 | public void visitMultiANewArrayInsn(String desc, int dims) { | 142 | public void visitMultiANewArrayInsn(String desc, int dims) { |
| 140 | super.visitMultiANewArrayInsn(translator.getTranslatedTypeDesc(new TypeDescriptor(desc)).toString(), dims); | 143 | super.visitMultiANewArrayInsn(translator.translate(new TypeDescriptor(desc)).toString(), dims); |
| 141 | } | 144 | } |
| 142 | 145 | ||
| 143 | @Override | 146 | @Override |
| 144 | public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { | 147 | public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { |
| 145 | if (type != null) { | 148 | if (type != null) { |
| 146 | ClassEntry translatedEntry = translator.getTranslatedClass(new ClassEntry(type)); | 149 | ClassEntry translatedEntry = translator.translate(new ClassEntry(type)); |
| 147 | super.visitTryCatchBlock(start, end, handler, translatedEntry.getName()); | 150 | super.visitTryCatchBlock(start, end, handler, translatedEntry.getFullName()); |
| 148 | } else { | 151 | } else { |
| 149 | super.visitTryCatchBlock(start, end, handler, type); | 152 | super.visitTryCatchBlock(start, end, handler, type); |
| 150 | } | 153 | } |
| @@ -159,7 +162,7 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 159 | 162 | ||
| 160 | for (int argumentIndex = 0; argumentIndex < arguments.size(); argumentIndex++) { | 163 | for (int argumentIndex = 0; argumentIndex < arguments.size(); argumentIndex++) { |
| 161 | LocalVariableEntry entry = new LocalVariableEntry(methodEntry, offset, "", true); | 164 | LocalVariableEntry entry = new LocalVariableEntry(methodEntry, offset, "", true); |
| 162 | LocalVariableEntry translatedEntry = translator.getTranslatedVariable(entry); | 165 | LocalVariableEntry translatedEntry = translator.translate(entry); |
| 163 | String translatedName = translatedEntry.getName(); | 166 | String translatedName = translatedEntry.getName(); |
| 164 | if (translatedName.equals(entry.getName())) { | 167 | if (translatedName.equals(entry.getName())) { |
| 165 | super.visitParameter(inferArgumentName(argumentIndex, arguments.get(argumentIndex), arguments), 0); | 168 | super.visitParameter(inferArgumentName(argumentIndex, arguments.get(argumentIndex), arguments), 0); |