diff options
16 files changed, 206 insertions, 96 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java index 656fa320..e37c1d0c 100644 --- a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java +++ b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java | |||
| @@ -122,10 +122,22 @@ public class EntryRenamer { | |||
| 122 | return (T) new ClassEntry(renameClassesInThing(renames, classEntry.getClassName())); | 122 | return (T) new ClassEntry(renameClassesInThing(renames, classEntry.getClassName())); |
| 123 | } else if (thing instanceof FieldDefEntry) { | 123 | } else if (thing instanceof FieldDefEntry) { |
| 124 | FieldDefEntry fieldEntry = (FieldDefEntry) thing; | 124 | FieldDefEntry fieldEntry = (FieldDefEntry) thing; |
| 125 | return (T) new FieldDefEntry(renameClassesInThing(renames, fieldEntry.getOwnerClassEntry()), fieldEntry.getName(), renameClassesInThing(renames, fieldEntry.getDesc()), fieldEntry.getAccess()); | 125 | return (T) new FieldDefEntry( |
| 126 | renameClassesInThing(renames, fieldEntry.getOwnerClassEntry()), | ||
| 127 | fieldEntry.getName(), | ||
| 128 | renameClassesInThing(renames, fieldEntry.getDesc()), | ||
| 129 | renameClassesInThing(renames, fieldEntry.getSignature()), | ||
| 130 | fieldEntry.getAccess() | ||
| 131 | ); | ||
| 126 | } else if (thing instanceof MethodDefEntry) { | 132 | } else if (thing instanceof MethodDefEntry) { |
| 127 | MethodDefEntry methodEntry = (MethodDefEntry) thing; | 133 | MethodDefEntry methodEntry = (MethodDefEntry) thing; |
| 128 | return (T) new MethodDefEntry(renameClassesInThing(renames, methodEntry.getOwnerClassEntry()), methodEntry.getName(), renameClassesInThing(renames, methodEntry.getDesc()), methodEntry.getAccess()); | 134 | return (T) new MethodDefEntry( |
| 135 | renameClassesInThing(renames, methodEntry.getOwnerClassEntry()), | ||
| 136 | methodEntry.getName(), | ||
| 137 | renameClassesInThing(renames, methodEntry.getDesc()), | ||
| 138 | renameClassesInThing(renames, methodEntry.getSignature()), | ||
| 139 | methodEntry.getAccess() | ||
| 140 | ); | ||
| 129 | } else if (thing instanceof LocalVariableEntry) { | 141 | } else if (thing instanceof LocalVariableEntry) { |
| 130 | LocalVariableEntry argumentEntry = (LocalVariableEntry) thing; | 142 | LocalVariableEntry argumentEntry = (LocalVariableEntry) thing; |
| 131 | return (T) new LocalVariableEntry(renameClassesInThing(renames, argumentEntry.getOwnerEntry()), argumentEntry.getIndex(), argumentEntry.getName()); | 143 | return (T) new LocalVariableEntry(renameClassesInThing(renames, argumentEntry.getOwnerEntry()), argumentEntry.getIndex(), argumentEntry.getName()); |
| @@ -138,6 +150,8 @@ public class EntryRenamer { | |||
| 138 | return (T) ((MethodDescriptor) thing).remap(className -> renameClassesInThing(renames, className)); | 150 | return (T) ((MethodDescriptor) thing).remap(className -> renameClassesInThing(renames, className)); |
| 139 | } else if (thing instanceof TypeDescriptor) { | 151 | } else if (thing instanceof TypeDescriptor) { |
| 140 | return (T) ((TypeDescriptor) thing).remap(className -> renameClassesInThing(renames, className)); | 152 | return (T) ((TypeDescriptor) thing).remap(className -> renameClassesInThing(renames, className)); |
| 153 | } else if (thing instanceof Signature) { | ||
| 154 | return (T) ((Signature) thing).remap(className -> renameClassesInThing(renames, className)); | ||
| 141 | } | 155 | } |
| 142 | 156 | ||
| 143 | return thing; | 157 | return thing; |
diff --git a/src/main/java/cuchaz/enigma/analysis/IndexClassVisitor.java b/src/main/java/cuchaz/enigma/analysis/IndexClassVisitor.java index 7828fa94..69fe54fc 100644 --- a/src/main/java/cuchaz/enigma/analysis/IndexClassVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/IndexClassVisitor.java | |||
| @@ -16,14 +16,14 @@ public class IndexClassVisitor extends ClassVisitor { | |||
| 16 | 16 | ||
| 17 | @Override | 17 | @Override |
| 18 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { | 18 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { |
| 19 | this.classEntry = this.index.indexClass(access, name, superName, interfaces); | 19 | this.classEntry = this.index.indexClass(access, name, signature, superName, interfaces); |
| 20 | super.visit(version, access, name, signature, superName, interfaces); | 20 | super.visit(version, access, name, signature, superName, interfaces); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | @Override | 23 | @Override |
| 24 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { | 24 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { |
| 25 | if (this.classEntry != null) { | 25 | if (this.classEntry != null) { |
| 26 | this.index.indexField(this.classEntry, access, name, desc); | 26 | this.index.indexField(this.classEntry, access, name, desc, signature); |
| 27 | } | 27 | } |
| 28 | return super.visitField(access, name, desc, signature, value); | 28 | return super.visitField(access, name, desc, signature, value); |
| 29 | } | 29 | } |
| @@ -31,7 +31,7 @@ public class IndexClassVisitor extends ClassVisitor { | |||
| 31 | @Override | 31 | @Override |
| 32 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | 32 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { |
| 33 | if (this.classEntry != null) { | 33 | if (this.classEntry != null) { |
| 34 | this.index.indexMethod(this.classEntry, access, name, desc); | 34 | this.index.indexMethod(this.classEntry, access, name, desc, signature); |
| 35 | } | 35 | } |
| 36 | return super.visitMethod(access, name, desc, signature, exceptions); | 36 | return super.visitMethod(access, name, desc, signature, exceptions); |
| 37 | } | 37 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/IndexReferenceVisitor.java b/src/main/java/cuchaz/enigma/analysis/IndexReferenceVisitor.java index bd64bfc1..c05281bd 100644 --- a/src/main/java/cuchaz/enigma/analysis/IndexReferenceVisitor.java +++ b/src/main/java/cuchaz/enigma/analysis/IndexReferenceVisitor.java | |||
| @@ -1,22 +1,20 @@ | |||
| 1 | package cuchaz.enigma.analysis; | 1 | package cuchaz.enigma.analysis; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.bytecode.AccessFlags; | 3 | import cuchaz.enigma.bytecode.AccessFlags; |
| 4 | import cuchaz.enigma.mapping.*; | 4 | import cuchaz.enigma.mapping.MethodDescriptor; |
| 5 | import cuchaz.enigma.mapping.Signature; | ||
| 5 | import cuchaz.enigma.mapping.entry.ClassEntry; | 6 | import cuchaz.enigma.mapping.entry.ClassEntry; |
| 6 | import cuchaz.enigma.mapping.entry.MethodDefEntry; | 7 | import cuchaz.enigma.mapping.entry.MethodDefEntry; |
| 7 | import cuchaz.enigma.mapping.entry.ReferencedEntryPool; | ||
| 8 | import org.objectweb.asm.ClassVisitor; | 8 | import org.objectweb.asm.ClassVisitor; |
| 9 | import org.objectweb.asm.MethodVisitor; | 9 | import org.objectweb.asm.MethodVisitor; |
| 10 | 10 | ||
| 11 | public class IndexReferenceVisitor extends ClassVisitor { | 11 | public class IndexReferenceVisitor extends ClassVisitor { |
| 12 | private final JarIndex index; | 12 | private final JarIndex index; |
| 13 | private final ReferencedEntryPool entryPool; | ||
| 14 | private ClassEntry classEntry; | 13 | private ClassEntry classEntry; |
| 15 | 14 | ||
| 16 | public IndexReferenceVisitor(JarIndex index, ReferencedEntryPool entryPool, int api) { | 15 | public IndexReferenceVisitor(JarIndex index, int api) { |
| 17 | super(api); | 16 | super(api); |
| 18 | this.index = index; | 17 | this.index = index; |
| 19 | this.entryPool = entryPool; | ||
| 20 | } | 18 | } |
| 21 | 19 | ||
| 22 | @Override | 20 | @Override |
| @@ -26,7 +24,7 @@ public class IndexReferenceVisitor extends ClassVisitor { | |||
| 26 | 24 | ||
| 27 | @Override | 25 | @Override |
| 28 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | 26 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { |
| 29 | MethodDefEntry entry = new MethodDefEntry(classEntry, name, new MethodDescriptor(desc), new AccessFlags(access)); | 27 | MethodDefEntry entry = new MethodDefEntry(classEntry, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); |
| 30 | return new Method(this.index, entry, this.api); | 28 | return new Method(this.index, entry, this.api); |
| 31 | } | 29 | } |
| 32 | 30 | ||
diff --git a/src/main/java/cuchaz/enigma/analysis/JarIndex.java b/src/main/java/cuchaz/enigma/analysis/JarIndex.java index 54dd5068..3479c5d5 100644 --- a/src/main/java/cuchaz/enigma/analysis/JarIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/JarIndex.java | |||
| @@ -61,7 +61,7 @@ public class JarIndex { | |||
| 61 | jar.visit(node -> node.accept(new IndexClassVisitor(this, Opcodes.ASM5))); | 61 | jar.visit(node -> node.accept(new IndexClassVisitor(this, Opcodes.ASM5))); |
| 62 | 62 | ||
| 63 | // step 3: index field, method, constructor references | 63 | // step 3: index field, method, constructor references |
| 64 | jar.visit(node -> node.accept(new IndexReferenceVisitor(this, entryPool, Opcodes.ASM5))); | 64 | jar.visit(node -> node.accept(new IndexReferenceVisitor(this, Opcodes.ASM5))); |
| 65 | 65 | ||
| 66 | // step 4: index bridged methods | 66 | // step 4: index bridged methods |
| 67 | for (MethodDefEntry methodEntry : methods.values()) { | 67 | for (MethodDefEntry methodEntry : methods.values()) { |
| @@ -95,24 +95,24 @@ public class JarIndex { | |||
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | protected ClassDefEntry indexClass(int access, String name, String superName, String[] interfaces) { | 98 | protected ClassDefEntry indexClass(int access, String name, String signature, String superName, String[] interfaces) { |
| 99 | for (String interfaceName : interfaces) { | 99 | for (String interfaceName : interfaces) { |
| 100 | if (name.equals(interfaceName)) { | 100 | if (name.equals(interfaceName)) { |
| 101 | throw new IllegalArgumentException("Class cannot be its own interface! " + name); | 101 | throw new IllegalArgumentException("Class cannot be its own interface! " + name); |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | return this.translationIndex.indexClass(access, name, superName, interfaces); | 104 | return this.translationIndex.indexClass(access, name, signature, superName, interfaces); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | protected void indexField(ClassDefEntry owner, int access, String name, String desc) { | 107 | protected void indexField(ClassDefEntry owner, int access, String name, String desc, String signature) { |
| 108 | FieldDefEntry fieldEntry = new FieldDefEntry(owner, name, new TypeDescriptor(desc), new AccessFlags(access)); | 108 | FieldDefEntry fieldEntry = new FieldDefEntry(owner, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access)); |
| 109 | this.translationIndex.indexField(fieldEntry); | 109 | this.translationIndex.indexField(fieldEntry); |
| 110 | this.access.put(fieldEntry, Access.get(access)); | 110 | this.access.put(fieldEntry, Access.get(access)); |
| 111 | this.fields.put(fieldEntry.getOwnerClassEntry(), fieldEntry); | 111 | this.fields.put(fieldEntry.getOwnerClassEntry(), fieldEntry); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | protected void indexMethod(ClassDefEntry owner, int access, String name, String desc) { | 114 | protected void indexMethod(ClassDefEntry owner, int access, String name, String desc, String signature) { |
| 115 | MethodDefEntry methodEntry = new MethodDefEntry(owner, name, new MethodDescriptor(desc), new AccessFlags(access)); | 115 | MethodDefEntry methodEntry = new MethodDefEntry(owner, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); |
| 116 | this.translationIndex.indexMethod(methodEntry); | 116 | this.translationIndex.indexMethod(methodEntry); |
| 117 | this.access.put(methodEntry, Access.get(access)); | 117 | this.access.put(methodEntry, Access.get(access)); |
| 118 | this.methods.put(methodEntry.getOwnerClassEntry(), methodEntry); | 118 | this.methods.put(methodEntry.getOwnerClassEntry(), methodEntry); |
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java index 0c8ed9cd..644a3f2b 100644 --- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | |||
| @@ -76,8 +76,8 @@ public class TranslationIndex { | |||
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | protected ClassDefEntry indexClass(int access, String name, String superName, String[] interfaces) { | 79 | protected ClassDefEntry indexClass(int access, String name, String signature, String superName, String[] interfaces) { |
| 80 | ClassDefEntry classEntry = new ClassDefEntry(name, new AccessFlags(access)); | 80 | ClassDefEntry classEntry = new ClassDefEntry(name, Signature.createSignature(signature), new AccessFlags(access)); |
| 81 | if (isJre(classEntry)) { | 81 | if (isJre(classEntry)) { |
| 82 | return null; | 82 | return null; |
| 83 | } | 83 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java index 7cc37719..df5f8f7e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationAnnotationVisitor.java | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.bytecode.AccessFlags; | ||
| 4 | import cuchaz.enigma.mapping.Translator; | 3 | import cuchaz.enigma.mapping.Translator; |
| 5 | import cuchaz.enigma.mapping.TypeDescriptor; | 4 | import cuchaz.enigma.mapping.TypeDescriptor; |
| 6 | import cuchaz.enigma.mapping.entry.ClassEntry; | 5 | import cuchaz.enigma.mapping.entry.ClassEntry; |
| 7 | import cuchaz.enigma.mapping.entry.FieldDefEntry; | 6 | import cuchaz.enigma.mapping.entry.FieldEntry; |
| 8 | import org.objectweb.asm.AnnotationVisitor; | 7 | import org.objectweb.asm.AnnotationVisitor; |
| 9 | 8 | ||
| 10 | public class TranslationAnnotationVisitor extends AnnotationVisitor { | 9 | public class TranslationAnnotationVisitor extends AnnotationVisitor { |
| @@ -30,15 +29,15 @@ public class TranslationAnnotationVisitor extends AnnotationVisitor { | |||
| 30 | @Override | 29 | @Override |
| 31 | public AnnotationVisitor visitAnnotation(String name, String desc) { | 30 | public AnnotationVisitor visitAnnotation(String name, String desc) { |
| 32 | TypeDescriptor type = new TypeDescriptor(desc); | 31 | TypeDescriptor type = new TypeDescriptor(desc); |
| 33 | FieldDefEntry annotationField = translator.getTranslatedFieldDef(new FieldDefEntry(annotationEntry, name, type, AccessFlags.PUBLIC)); | 32 | FieldEntry annotationField = translator.getTranslatedField(new FieldEntry(annotationEntry, name, type)); |
| 34 | return super.visitAnnotation(annotationField.getName(), annotationField.getDesc().toString()); | 33 | return super.visitAnnotation(annotationField.getName(), annotationField.getDesc().toString()); |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | @Override | 36 | @Override |
| 38 | public void visitEnum(String name, String desc, String value) { | 37 | public void visitEnum(String name, String desc, String value) { |
| 39 | TypeDescriptor type = new TypeDescriptor(desc); | 38 | TypeDescriptor type = new TypeDescriptor(desc); |
| 40 | FieldDefEntry annotationField = translator.getTranslatedFieldDef(new FieldDefEntry(annotationEntry, name, type, AccessFlags.PUBLIC)); | 39 | FieldEntry annotationField = translator.getTranslatedField(new FieldEntry(annotationEntry, name, type)); |
| 41 | FieldDefEntry enumField = translator.getTranslatedFieldDef(new FieldDefEntry(type.getTypeEntry(), value, type, AccessFlags.PUBLIC_STATIC_FINAL)); | 40 | FieldEntry enumField = translator.getTranslatedField(new FieldEntry(type.getTypeEntry(), value, type)); |
| 42 | super.visitEnum(annotationField.getName(), annotationField.getDesc().toString(), enumField.getName()); | 41 | super.visitEnum(annotationField.getName(), annotationField.getDesc().toString(), enumField.getName()); |
| 43 | } | 42 | } |
| 44 | } | 43 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java index 89772dbb..0137155c 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java | |||
| @@ -14,6 +14,7 @@ package cuchaz.enigma.bytecode.translators; | |||
| 14 | import cuchaz.enigma.analysis.JarIndex; | 14 | import cuchaz.enigma.analysis.JarIndex; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.bytecode.AccessFlags; |
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | 16 | import cuchaz.enigma.mapping.MethodDescriptor; |
| 17 | import cuchaz.enigma.mapping.Signature; | ||
| 17 | import cuchaz.enigma.mapping.Translator; | 18 | import cuchaz.enigma.mapping.Translator; |
| 18 | import cuchaz.enigma.mapping.TypeDescriptor; | 19 | import cuchaz.enigma.mapping.TypeDescriptor; |
| 19 | import cuchaz.enigma.mapping.entry.*; | 20 | import cuchaz.enigma.mapping.entry.*; |
| @@ -25,6 +26,7 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 25 | private final ReferencedEntryPool entryPool; | 26 | private final ReferencedEntryPool entryPool; |
| 26 | 27 | ||
| 27 | private ClassDefEntry obfClassEntry; | 28 | private ClassDefEntry obfClassEntry; |
| 29 | private Signature obfSignature; | ||
| 28 | 30 | ||
| 29 | public TranslationClassVisitor(Translator translator, JarIndex jarIndex, ReferencedEntryPool entryPool, int api, ClassVisitor cv) { | 31 | public TranslationClassVisitor(Translator translator, JarIndex jarIndex, ReferencedEntryPool entryPool, int api, ClassVisitor cv) { |
| 30 | super(api, cv); | 32 | super(api, cv); |
| @@ -35,29 +37,28 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 35 | 37 | ||
| 36 | @Override | 38 | @Override |
| 37 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { | 39 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { |
| 38 | obfClassEntry = new ClassDefEntry(name, new AccessFlags(access)); | 40 | obfSignature = Signature.createSignature(signature); |
| 39 | ClassDefEntry entry = translator.getTranslatedClassDef(obfClassEntry); | 41 | obfClassEntry = new ClassDefEntry(name, obfSignature, new AccessFlags(access)); |
| 42 | ClassDefEntry translatedEntry = translator.getTranslatedClassDef(obfClassEntry); | ||
| 40 | ClassEntry superEntry = translator.getTranslatedClass(entryPool.getClass(superName)); | 43 | ClassEntry superEntry = translator.getTranslatedClass(entryPool.getClass(superName)); |
| 41 | String[] translatedInterfaces = new String[interfaces.length]; | 44 | String[] translatedInterfaces = new String[interfaces.length]; |
| 42 | for (int i = 0; i < interfaces.length; i++) { | 45 | for (int i = 0; i < interfaces.length; i++) { |
| 43 | translatedInterfaces[i] = translator.getTranslatedClass(entryPool.getClass(interfaces[i])).getName(); | 46 | translatedInterfaces[i] = translator.getTranslatedClass(entryPool.getClass(interfaces[i])).getName(); |
| 44 | } | 47 | } |
| 45 | String translatedSignature = translator.getTranslatedSignature(signature, false, api); | 48 | super.visit(version, translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getSignature().toString(), superEntry.getName(), translatedInterfaces); |
| 46 | super.visit(version, entry.getAccess().getFlags(), entry.getName(), translatedSignature, superEntry.getName(), translatedInterfaces); | ||
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | @Override | 51 | @Override |
| 50 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { | 52 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { |
| 51 | FieldDefEntry entry = new FieldDefEntry(obfClassEntry, name, new TypeDescriptor(desc), new AccessFlags(access)); | 53 | FieldDefEntry entry = new FieldDefEntry(obfClassEntry, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access)); |
| 52 | FieldDefEntry translatedEntry = translator.getTranslatedFieldDef(entry); | 54 | FieldDefEntry translatedEntry = translator.getTranslatedFieldDef(entry); |
| 53 | String translatedSignature = translator.getTranslatedSignature(signature, true, api); | 55 | FieldVisitor fv = super.visitField(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), value); |
| 54 | FieldVisitor fv = super.visitField(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedSignature, value); | ||
| 55 | return new TranslationFieldVisitor(translator, translatedEntry, api, fv); | 56 | return new TranslationFieldVisitor(translator, translatedEntry, api, fv); |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | @Override | 59 | @Override |
| 59 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | 60 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { |
| 60 | MethodDefEntry entry = new MethodDefEntry(obfClassEntry, name, new MethodDescriptor(desc), new AccessFlags(access)); | 61 | MethodDefEntry entry = new MethodDefEntry(obfClassEntry, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access)); |
| 61 | MethodDefEntry translatedEntry = translator.getTranslatedMethodDef(entry); | 62 | MethodDefEntry translatedEntry = translator.getTranslatedMethodDef(entry); |
| 62 | if (jarIndex.getBridgedMethod(entry) != null) { | 63 | if (jarIndex.getBridgedMethod(entry) != null) { |
| 63 | translatedEntry.getAccess().setBridged(); | 64 | translatedEntry.getAccess().setBridged(); |
| @@ -66,12 +67,23 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 66 | for (int i = 0; i < exceptions.length; i++) { | 67 | for (int i = 0; i < exceptions.length; i++) { |
| 67 | translatedExceptions[i] = translator.getTranslatedClass(entryPool.getClass(exceptions[i])).getName(); | 68 | translatedExceptions[i] = translator.getTranslatedClass(entryPool.getClass(exceptions[i])).getName(); |
| 68 | } | 69 | } |
| 69 | String translatedSignature = translator.getTranslatedSignature(signature, false, api); | 70 | MethodVisitor mv = super.visitMethod(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedEntry.getSignature().toString(), translatedExceptions); |
| 70 | MethodVisitor mv = super.visitMethod(translatedEntry.getAccess().getFlags(), translatedEntry.getName(), translatedEntry.getDesc().toString(), translatedSignature, translatedExceptions); | ||
| 71 | return new TranslationMethodVisitor(translator, translatedEntry, api, mv); | 71 | return new TranslationMethodVisitor(translator, translatedEntry, api, mv); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
| 75 | public void visitInnerClass(String name, String outerName, String innerName, int access) { | ||
| 76 | ClassDefEntry translatedEntry = translator.getTranslatedClassDef(new ClassDefEntry(name, obfSignature, new AccessFlags(access))); | ||
| 77 | String translatedName = translatedEntry.getName(); | ||
| 78 | int separatorIndex = translatedName.lastIndexOf("$"); | ||
| 79 | String parentName = translatedName.substring(0, separatorIndex); | ||
| 80 | String childName = translatedName.substring(separatorIndex + 1); | ||
| 81 | |||
| 82 | ClassEntry outerEntry = translator.getTranslatedClass(entryPool.getClass(parentName)); | ||
| 83 | super.visitInnerClass(translatedName, outerEntry.getName(), childName, translatedEntry.getAccess().getFlags()); | ||
| 84 | } | ||
| 85 | |||
| 86 | @Override | ||
| 75 | public void visitOuterClass(String owner, String name, String desc) { | 87 | public void visitOuterClass(String owner, String name, String desc) { |
| 76 | if (desc != null) { | 88 | if (desc != null) { |
| 77 | MethodEntry translatedEntry = translator.getTranslatedMethod(new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc))); | 89 | MethodEntry translatedEntry = translator.getTranslatedMethod(new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc))); |
| @@ -94,16 +106,4 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 94 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, translatedDesc.toString(), visible); | 106 | AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, translatedDesc.toString(), visible); |
| 95 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); | 107 | return new TranslationAnnotationVisitor(translator, translatedDesc.getTypeEntry(), api, av); |
| 96 | } | 108 | } |
| 97 | |||
| 98 | @Override | ||
| 99 | public void visitInnerClass(String name, String outerName, String innerName, int access) { | ||
| 100 | ClassDefEntry translatedEntry = translator.getTranslatedClassDef(new ClassDefEntry(name, new AccessFlags(access))); | ||
| 101 | String translatedName = translatedEntry.getName(); | ||
| 102 | int separatorIndex = translatedName.lastIndexOf("$"); | ||
| 103 | String parentName = translatedName.substring(0, separatorIndex); | ||
| 104 | String childName = translatedName.substring(separatorIndex + 1); | ||
| 105 | |||
| 106 | ClassEntry outerEntry = translator.getTranslatedClass(entryPool.getClass(parentName)); | ||
| 107 | super.visitInnerClass(translatedName, outerEntry.getName(), childName, translatedEntry.getAccess().getFlags()); | ||
| 108 | } | ||
| 109 | } | 109 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java index cce91db3..eeabdfad 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.mapping.MethodDescriptor; | 3 | import cuchaz.enigma.mapping.MethodDescriptor; |
| 4 | import cuchaz.enigma.mapping.Signature; | ||
| 4 | import cuchaz.enigma.mapping.Translator; | 5 | import cuchaz.enigma.mapping.Translator; |
| 5 | import cuchaz.enigma.mapping.TypeDescriptor; | 6 | import cuchaz.enigma.mapping.TypeDescriptor; |
| 6 | import cuchaz.enigma.mapping.entry.*; | 7 | import cuchaz.enigma.mapping.entry.*; |
| @@ -102,7 +103,7 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 102 | } | 103 | } |
| 103 | translatedName = nameBuilder.toString(); | 104 | translatedName = nameBuilder.toString(); |
| 104 | } | 105 | } |
| 105 | String translatedSignature = translator.getTranslatedSignature(signature, true, api); | 106 | String translatedSignature = translator.getTranslatedSignature(Signature.createTypedSignature(signature)).toString(); |
| 106 | super.visitLocalVariable(translatedName, translatedEntry.getDesc().toString(), translatedSignature, start, end, index); | 107 | super.visitLocalVariable(translatedName, translatedEntry.getDesc().toString(), translatedSignature, start, end, index); |
| 107 | } | 108 | } |
| 108 | 109 | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationSignatureVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationSignatureVisitor.java index e1dcea5c..2bb80a83 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationSignatureVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationSignatureVisitor.java | |||
| @@ -1,37 +1,36 @@ | |||
| 1 | package cuchaz.enigma.bytecode.translators; | 1 | package cuchaz.enigma.bytecode.translators; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.mapping.Translator; | 3 | import org.objectweb.asm.Opcodes; |
| 4 | import cuchaz.enigma.mapping.entry.ClassEntry; | ||
| 5 | import org.objectweb.asm.signature.SignatureVisitor; | 4 | import org.objectweb.asm.signature.SignatureVisitor; |
| 6 | 5 | ||
| 7 | import java.util.Stack; | 6 | import java.util.Stack; |
| 7 | import java.util.function.Function; | ||
| 8 | 8 | ||
| 9 | public class TranslationSignatureVisitor extends SignatureVisitor { | 9 | public class TranslationSignatureVisitor extends SignatureVisitor { |
| 10 | private final Translator translator; | 10 | private final Function<String, String> remapper; |
| 11 | 11 | ||
| 12 | private final SignatureVisitor sv; | 12 | private final SignatureVisitor sv; |
| 13 | private final Stack<ClassEntry> classes = new Stack<>(); | 13 | private final Stack<String> classes = new Stack<>(); |
| 14 | 14 | ||
| 15 | public TranslationSignatureVisitor(Translator translator, int api, SignatureVisitor sv) { | 15 | public TranslationSignatureVisitor(Function<String, String> remapper, SignatureVisitor sv) { |
| 16 | super(api); | 16 | super(Opcodes.ASM5); |
| 17 | this.translator = translator; | 17 | this.remapper = remapper; |
| 18 | this.sv = sv; | 18 | this.sv = sv; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | @Override | 21 | @Override |
| 22 | public void visitClassType(String name) { | 22 | public void visitClassType(String name) { |
| 23 | ClassEntry entry = new ClassEntry(name); | 23 | String translatedEntry = this.remapper.apply(name); |
| 24 | ClassEntry translatedEntry = this.translator.getTranslatedClass(entry); | 24 | this.classes.push(name); |
| 25 | this.classes.push(entry); | 25 | this.sv.visitClassType(translatedEntry); |
| 26 | this.sv.visitClassType(translatedEntry.getName()); | ||
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | @Override | 28 | @Override |
| 30 | public void visitInnerClassType(String name) { | 29 | public void visitInnerClassType(String name) { |
| 31 | ClassEntry outerEntry = this.classes.pop(); | 30 | String outerName = this.classes.pop(); |
| 32 | ClassEntry entry = new ClassEntry(outerEntry + "$" + name); | 31 | String className = outerName + "$" + name; |
| 33 | this.classes.push(entry); | 32 | this.classes.push(className); |
| 34 | String translatedEntry = this.translator.getTranslatedClass(entry).getName(); | 33 | String translatedEntry = this.remapper.apply(className); |
| 35 | this.sv.visitInnerClassType(translatedEntry.substring(translatedEntry.lastIndexOf('$') + 1)); | 34 | this.sv.visitInnerClassType(translatedEntry.substring(translatedEntry.lastIndexOf('$') + 1)); |
| 36 | } | 35 | } |
| 37 | 36 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java b/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java index dec5acf4..fe141c66 100644 --- a/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java +++ b/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java | |||
| @@ -15,20 +15,13 @@ import com.google.common.collect.Lists; | |||
| 15 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 16 | import cuchaz.enigma.analysis.TranslationIndex; | 16 | import cuchaz.enigma.analysis.TranslationIndex; |
| 17 | import cuchaz.enigma.bytecode.AccessFlags; | 17 | import cuchaz.enigma.bytecode.AccessFlags; |
| 18 | import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor; | ||
| 19 | import cuchaz.enigma.mapping.entry.*; | 18 | import cuchaz.enigma.mapping.entry.*; |
| 20 | import org.objectweb.asm.signature.SignatureReader; | ||
| 21 | import org.objectweb.asm.signature.SignatureVisitor; | ||
| 22 | import org.objectweb.asm.signature.SignatureWriter; | ||
| 23 | 19 | ||
| 24 | import java.util.ArrayList; | 20 | import java.util.ArrayList; |
| 25 | import java.util.List; | 21 | import java.util.List; |
| 26 | import java.util.Map; | 22 | import java.util.Map; |
| 27 | import java.util.regex.Pattern; | ||
| 28 | 23 | ||
| 29 | public class DirectionalTranslator implements Translator { | 24 | public class DirectionalTranslator implements Translator { |
| 30 | private static final Pattern OBJECT_PATTERN = Pattern.compile(".*:Ljava/lang/Object;:.*"); | ||
| 31 | |||
| 32 | private final TranslationDirection direction; | 25 | private final TranslationDirection direction; |
| 33 | private final Map<String, ClassMapping> classes; | 26 | private final Map<String, ClassMapping> classes; |
| 34 | private final TranslationIndex index; | 27 | private final TranslationIndex index; |
| @@ -62,7 +55,7 @@ public class DirectionalTranslator implements Translator { | |||
| 62 | @Override | 55 | @Override |
| 63 | public ClassDefEntry getTranslatedClassDef(ClassDefEntry entry) { | 56 | public ClassDefEntry getTranslatedClassDef(ClassDefEntry entry) { |
| 64 | String className = entry.isInnerClass() ? translateInnerClassName(entry) : translateClassName(entry); | 57 | String className = entry.isInnerClass() ? translateInnerClassName(entry) : translateClassName(entry); |
| 65 | return new ClassDefEntry(className, getClassModifier(entry).transform(entry.getAccess())); | 58 | return new ClassDefEntry(className, entry.getSignature(), getClassModifier(entry).transform(entry.getAccess())); |
| 66 | } | 59 | } |
| 67 | 60 | ||
| 68 | private String translateClassName(ClassEntry entry) { | 61 | private String translateClassName(ClassEntry entry) { |
| @@ -108,8 +101,9 @@ public class DirectionalTranslator implements Translator { | |||
| 108 | } | 101 | } |
| 109 | ClassEntry translatedOwner = getTranslatedClass(entry.getOwnerClassEntry()); | 102 | ClassEntry translatedOwner = getTranslatedClass(entry.getOwnerClassEntry()); |
| 110 | TypeDescriptor translatedDesc = getTranslatedTypeDesc(entry.getDesc()); | 103 | TypeDescriptor translatedDesc = getTranslatedTypeDesc(entry.getDesc()); |
| 104 | Signature translatedSignature = getTranslatedSignature(entry.getSignature()); | ||
| 111 | AccessFlags translatedAccess = getFieldModifier(entry).transform(entry.getAccess()); | 105 | AccessFlags translatedAccess = getFieldModifier(entry).transform(entry.getAccess()); |
| 112 | return new FieldDefEntry(translatedOwner, translatedName, translatedDesc, translatedAccess); | 106 | return new FieldDefEntry(translatedOwner, translatedName, translatedDesc, translatedSignature, translatedAccess); |
| 113 | } | 107 | } |
| 114 | 108 | ||
| 115 | @Override | 109 | @Override |
| @@ -148,8 +142,9 @@ public class DirectionalTranslator implements Translator { | |||
| 148 | } | 142 | } |
| 149 | ClassEntry translatedOwner = getTranslatedClass(entry.getOwnerClassEntry()); | 143 | ClassEntry translatedOwner = getTranslatedClass(entry.getOwnerClassEntry()); |
| 150 | MethodDescriptor translatedDesc = getTranslatedMethodDesc(entry.getDesc()); | 144 | MethodDescriptor translatedDesc = getTranslatedMethodDesc(entry.getDesc()); |
| 145 | Signature translatedSignature = getTranslatedSignature(entry.getSignature()); | ||
| 151 | AccessFlags access = getMethodModifier(entry).transform(entry.getAccess()); | 146 | AccessFlags access = getMethodModifier(entry).transform(entry.getAccess()); |
| 152 | return new MethodDefEntry(translatedOwner, translatedName, translatedDesc, access); | 147 | return new MethodDefEntry(translatedOwner, translatedName, translatedDesc, translatedSignature, access); |
| 153 | } | 148 | } |
| 154 | 149 | ||
| 155 | @Override | 150 | @Override |
| @@ -265,7 +260,7 @@ public class DirectionalTranslator implements Translator { | |||
| 265 | 260 | ||
| 266 | @Override | 261 | @Override |
| 267 | public TypeDescriptor getTranslatedTypeDesc(TypeDescriptor desc) { | 262 | public TypeDescriptor getTranslatedTypeDesc(TypeDescriptor desc) { |
| 268 | return desc.remap(name -> getTranslatedClass(new ClassEntry(name)).getName()); | 263 | return desc.remap(this::remapClass); |
| 269 | } | 264 | } |
| 270 | 265 | ||
| 271 | @Override | 266 | @Override |
| @@ -279,23 +274,11 @@ public class DirectionalTranslator implements Translator { | |||
| 279 | } | 274 | } |
| 280 | 275 | ||
| 281 | @Override | 276 | @Override |
| 282 | public String getTranslatedSignature(String signature, boolean isType, int api) { | 277 | public Signature getTranslatedSignature(Signature signature) { |
| 283 | if (signature == null) { | 278 | if (signature == null) { |
| 284 | return null; | 279 | return null; |
| 285 | } | 280 | } |
| 286 | SignatureReader reader = new SignatureReader(signature); | 281 | return signature.remap(this::remapClass); |
| 287 | SignatureWriter writer = new SignatureWriter(); | ||
| 288 | SignatureVisitor visitor = new TranslationSignatureVisitor(this, api, writer); | ||
| 289 | if (isType) { | ||
| 290 | reader.acceptType(visitor); | ||
| 291 | } else { | ||
| 292 | reader.accept(visitor); | ||
| 293 | } | ||
| 294 | String translatedSignature = writer.toString(); | ||
| 295 | if (OBJECT_PATTERN.matcher(signature).matches()) { | ||
| 296 | translatedSignature = signature.replaceAll(":Ljava/lang/Object;:", "::"); | ||
| 297 | } | ||
| 298 | return translatedSignature; | ||
| 299 | } | 282 | } |
| 300 | 283 | ||
| 301 | private ClassMapping findClassMapping(ClassEntry entry) { | 284 | private ClassMapping findClassMapping(ClassEntry entry) { |
| @@ -360,4 +343,13 @@ public class DirectionalTranslator implements Translator { | |||
| 360 | } | 343 | } |
| 361 | return Mappings.EntryModifier.UNCHANGED; | 344 | return Mappings.EntryModifier.UNCHANGED; |
| 362 | } | 345 | } |
| 346 | |||
| 347 | private String remapClass(String name) { | ||
| 348 | String translatedName = getTranslatedClass(new ClassEntry(name)).getName(); | ||
| 349 | int separatorIndex = translatedName.lastIndexOf("$"); | ||
| 350 | if (separatorIndex != -1) { | ||
| 351 | translatedName = translatedName.substring(separatorIndex + 1); | ||
| 352 | } | ||
| 353 | return translatedName; | ||
| 354 | } | ||
| 363 | } | 355 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java new file mode 100644 index 00000000..071e4afa --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/Signature.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor; | ||
| 4 | import org.objectweb.asm.signature.SignatureReader; | ||
| 5 | import org.objectweb.asm.signature.SignatureVisitor; | ||
| 6 | import org.objectweb.asm.signature.SignatureWriter; | ||
| 7 | |||
| 8 | import java.util.function.Function; | ||
| 9 | import java.util.regex.Pattern; | ||
| 10 | |||
| 11 | public class Signature { | ||
| 12 | private static final Pattern OBJECT_PATTERN = Pattern.compile(".*:Ljava/lang/Object;:.*"); | ||
| 13 | |||
| 14 | private final String signature; | ||
| 15 | private final boolean isType; | ||
| 16 | |||
| 17 | private Signature(String signature, boolean isType) { | ||
| 18 | if (signature != null && OBJECT_PATTERN.matcher(signature).matches()) { | ||
| 19 | signature = signature.replaceAll(":Ljava/lang/Object;:", "::"); | ||
| 20 | } | ||
| 21 | |||
| 22 | this.signature = signature; | ||
| 23 | this.isType = isType; | ||
| 24 | } | ||
| 25 | |||
| 26 | public static Signature createTypedSignature(String signature) { | ||
| 27 | if (signature != null && !signature.isEmpty()) { | ||
| 28 | return new Signature(signature, true); | ||
| 29 | } | ||
| 30 | return new Signature(null, true); | ||
| 31 | } | ||
| 32 | |||
| 33 | public static Signature createSignature(String signature) { | ||
| 34 | if (signature != null && !signature.isEmpty()) { | ||
| 35 | return new Signature(signature, false); | ||
| 36 | } | ||
| 37 | return new Signature(null, false); | ||
| 38 | } | ||
| 39 | |||
| 40 | public String getSignature() { | ||
| 41 | return signature; | ||
| 42 | } | ||
| 43 | |||
| 44 | public boolean isType() { | ||
| 45 | return isType; | ||
| 46 | } | ||
| 47 | |||
| 48 | public Signature remap(Function<String, String> remapper) { | ||
| 49 | if (signature == null) { | ||
| 50 | return this; | ||
| 51 | } | ||
| 52 | SignatureWriter writer = new SignatureWriter(); | ||
| 53 | SignatureVisitor visitor = new TranslationSignatureVisitor(remapper, writer); | ||
| 54 | if (isType) { | ||
| 55 | new SignatureReader(signature).acceptType(visitor); | ||
| 56 | } else { | ||
| 57 | new SignatureReader(signature).accept(visitor); | ||
| 58 | } | ||
| 59 | return new Signature(writer.toString(), isType); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | public boolean equals(Object obj) { | ||
| 64 | if (obj instanceof Signature) { | ||
| 65 | Signature other = (Signature) obj; | ||
| 66 | return (other.signature == null && signature == null || other.signature != null | ||
| 67 | && signature != null && other.signature.equals(signature)) | ||
| 68 | && other.isType == this.isType; | ||
| 69 | } | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | |||
| 73 | @Override | ||
| 74 | public int hashCode() { | ||
| 75 | return signature.hashCode() | (isType ? 1 : 0) << 16; | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | public String toString() { | ||
| 80 | return signature; | ||
| 81 | } | ||
| 82 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index 1bc2f373..a9ff1cbb 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java | |||
| @@ -44,7 +44,7 @@ public interface Translator { | |||
| 44 | 44 | ||
| 45 | MethodDescriptor getTranslatedMethodDesc(MethodDescriptor descriptor); | 45 | MethodDescriptor getTranslatedMethodDesc(MethodDescriptor descriptor); |
| 46 | 46 | ||
| 47 | String getTranslatedSignature(String signature, boolean isType, int api); | 47 | Signature getTranslatedSignature(Signature signature); |
| 48 | 48 | ||
| 49 | default Type getTranslatedType(Type type) { | 49 | default Type getTranslatedType(Type type) { |
| 50 | String descString = type.getDescriptor(); | 50 | String descString = type.getDescriptor(); |
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java index 75e7f1bd..ac1fe2ab 100644 --- a/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/entry/ClassDefEntry.java | |||
| @@ -13,16 +13,24 @@ package cuchaz.enigma.mapping.entry; | |||
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.bytecode.AccessFlags; |
| 16 | import cuchaz.enigma.mapping.Signature; | ||
| 16 | 17 | ||
| 17 | public class ClassDefEntry extends ClassEntry { | 18 | public class ClassDefEntry extends ClassEntry { |
| 18 | private final AccessFlags access; | 19 | private final AccessFlags access; |
| 20 | private final Signature signature; | ||
| 19 | 21 | ||
| 20 | public ClassDefEntry(String className, AccessFlags access) { | 22 | public ClassDefEntry(String className, Signature signature, AccessFlags access) { |
| 21 | super(className); | 23 | super(className); |
| 24 | Preconditions.checkNotNull(signature, "Class signature cannot be null"); | ||
| 22 | Preconditions.checkNotNull(access, "Class access cannot be null"); | 25 | Preconditions.checkNotNull(access, "Class access cannot be null"); |
| 26 | this.signature = signature; | ||
| 23 | this.access = access; | 27 | this.access = access; |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 30 | public Signature getSignature() { | ||
| 31 | return signature; | ||
| 32 | } | ||
| 33 | |||
| 26 | public AccessFlags getAccess() { | 34 | public AccessFlags getAccess() { |
| 27 | return access; | 35 | return access; |
| 28 | } | 36 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java index 78ea5f76..d18115bf 100644 --- a/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/entry/FieldDefEntry.java | |||
| @@ -13,23 +13,31 @@ package cuchaz.enigma.mapping.entry; | |||
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.bytecode.AccessFlags; |
| 16 | import cuchaz.enigma.mapping.Signature; | ||
| 16 | import cuchaz.enigma.mapping.TypeDescriptor; | 17 | import cuchaz.enigma.mapping.TypeDescriptor; |
| 17 | 18 | ||
| 18 | public class FieldDefEntry extends FieldEntry { | 19 | public class FieldDefEntry extends FieldEntry { |
| 19 | private final AccessFlags access; | 20 | private final AccessFlags access; |
| 21 | private final Signature signature; | ||
| 20 | 22 | ||
| 21 | public FieldDefEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc, AccessFlags access) { | 23 | public FieldDefEntry(ClassEntry ownerEntry, String name, TypeDescriptor desc, Signature signature, AccessFlags access) { |
| 22 | super(ownerEntry, name, desc); | 24 | super(ownerEntry, name, desc); |
| 23 | Preconditions.checkNotNull(access, "Field access cannot be null"); | 25 | Preconditions.checkNotNull(access, "Field access cannot be null"); |
| 26 | Preconditions.checkNotNull(signature, "Field signature cannot be null"); | ||
| 24 | this.access = access; | 27 | this.access = access; |
| 28 | this.signature = signature; | ||
| 25 | } | 29 | } |
| 26 | 30 | ||
| 27 | public AccessFlags getAccess() { | 31 | public AccessFlags getAccess() { |
| 28 | return access; | 32 | return access; |
| 29 | } | 33 | } |
| 30 | 34 | ||
| 35 | public Signature getSignature() { | ||
| 36 | return signature; | ||
| 37 | } | ||
| 38 | |||
| 31 | @Override | 39 | @Override |
| 32 | public FieldDefEntry updateOwnership(ClassEntry owner) { | 40 | public FieldDefEntry updateOwnership(ClassEntry owner) { |
| 33 | return new FieldDefEntry(owner, this.name, this.desc, access); | 41 | return new FieldDefEntry(owner, this.name, this.desc, signature, access); |
| 34 | } | 42 | } |
| 35 | } | 43 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java index 1d2c094d..ec3af694 100644 --- a/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/entry/MethodDefEntry.java | |||
| @@ -14,23 +14,31 @@ package cuchaz.enigma.mapping.entry; | |||
| 14 | import com.google.common.base.Preconditions; | 14 | import com.google.common.base.Preconditions; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.bytecode.AccessFlags; |
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | 16 | import cuchaz.enigma.mapping.MethodDescriptor; |
| 17 | import cuchaz.enigma.mapping.Signature; | ||
| 17 | 18 | ||
| 18 | public class MethodDefEntry extends MethodEntry { | 19 | public class MethodDefEntry extends MethodEntry { |
| 19 | 20 | ||
| 20 | private final AccessFlags access; | 21 | private final AccessFlags access; |
| 22 | private final Signature signature; | ||
| 21 | 23 | ||
| 22 | public MethodDefEntry(ClassEntry classEntry, String name, MethodDescriptor descriptor, AccessFlags access) { | 24 | public MethodDefEntry(ClassEntry classEntry, String name, MethodDescriptor descriptor, Signature signature, AccessFlags access) { |
| 23 | super(classEntry, name, descriptor); | 25 | super(classEntry, name, descriptor); |
| 24 | Preconditions.checkNotNull(access, "Method access cannot be null"); | 26 | Preconditions.checkNotNull(access, "Method access cannot be null"); |
| 27 | Preconditions.checkNotNull(signature, "Method signature cannot be null"); | ||
| 25 | this.access = access; | 28 | this.access = access; |
| 29 | this.signature = signature; | ||
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | public AccessFlags getAccess() { | 32 | public AccessFlags getAccess() { |
| 29 | return access; | 33 | return access; |
| 30 | } | 34 | } |
| 31 | 35 | ||
| 36 | public Signature getSignature() { | ||
| 37 | return signature; | ||
| 38 | } | ||
| 39 | |||
| 32 | @Override | 40 | @Override |
| 33 | public MethodDefEntry updateOwnership(ClassEntry classEntry) { | 41 | public MethodDefEntry updateOwnership(ClassEntry classEntry) { |
| 34 | return new MethodDefEntry(new ClassEntry(classEntry.getName()), name, descriptor, access); | 42 | return new MethodDefEntry(new ClassEntry(classEntry.getName()), name, descriptor, signature, access); |
| 35 | } | 43 | } |
| 36 | } | 44 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java b/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java index e42a334e..5892a03e 100644 --- a/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java +++ b/src/main/java/cuchaz/enigma/mapping/entry/ProcyonEntryFactory.java | |||
| @@ -14,6 +14,7 @@ package cuchaz.enigma.mapping.entry; | |||
| 14 | import com.strobel.assembler.metadata.*; | 14 | import com.strobel.assembler.metadata.*; |
| 15 | import cuchaz.enigma.bytecode.AccessFlags; | 15 | import cuchaz.enigma.bytecode.AccessFlags; |
| 16 | import cuchaz.enigma.mapping.MethodDescriptor; | 16 | import cuchaz.enigma.mapping.MethodDescriptor; |
| 17 | import cuchaz.enigma.mapping.Signature; | ||
| 17 | import cuchaz.enigma.mapping.TypeDescriptor; | 18 | import cuchaz.enigma.mapping.TypeDescriptor; |
| 18 | 19 | ||
| 19 | import java.util.List; | 20 | import java.util.List; |
| @@ -56,7 +57,7 @@ public class ProcyonEntryFactory { | |||
| 56 | 57 | ||
| 57 | public FieldDefEntry getFieldDefEntry(FieldDefinition def) { | 58 | public FieldDefEntry getFieldDefEntry(FieldDefinition def) { |
| 58 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | 59 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); |
| 59 | return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), new AccessFlags(def.getModifiers())); | 60 | return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers())); |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | public MethodEntry getMethodEntry(MemberReference def) { | 63 | public MethodEntry getMethodEntry(MemberReference def) { |
| @@ -66,6 +67,6 @@ public class ProcyonEntryFactory { | |||
| 66 | 67 | ||
| 67 | public MethodDefEntry getMethodDefEntry(MethodDefinition def) { | 68 | public MethodDefEntry getMethodDefEntry(MethodDefinition def) { |
| 68 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); | 69 | ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); |
| 69 | return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), new AccessFlags(def.getModifiers())); | 70 | return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers())); |
| 70 | } | 71 | } |
| 71 | } | 72 | } |