diff options
| author | 2018-06-24 19:50:40 +0200 | |
|---|---|---|
| committer | 2018-06-24 19:50:40 +0200 | |
| commit | 732ae7336ef91e418adec6eec5233b20876cc41d (patch) | |
| tree | ef81d81a88a8a9afdd88a6d740a325b1de33c6a4 | |
| parent | Parameter translation in interfaces (diff) | |
| download | enigma-732ae7336ef91e418adec6eec5233b20876cc41d.tar.gz enigma-732ae7336ef91e418adec6eec5233b20876cc41d.tar.xz enigma-732ae7336ef91e418adec6eec5233b20876cc41d.zip | |
Fix enum parameter index offset
3 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java b/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java index 152f4629..21b24897 100644 --- a/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java +++ b/src/main/java/cuchaz/enigma/bytecode/AccessFlags.java | |||
| @@ -5,12 +5,6 @@ import org.objectweb.asm.Opcodes; | |||
| 5 | import java.lang.reflect.Modifier; | 5 | import java.lang.reflect.Modifier; |
| 6 | 6 | ||
| 7 | public class AccessFlags { | 7 | public class AccessFlags { |
| 8 | public static final AccessFlags PUBLIC = new AccessFlags(Modifier.PUBLIC); | ||
| 9 | public static final AccessFlags PUBLIC_STATIC_FINAL = new AccessFlags(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL); | ||
| 10 | |||
| 11 | private static final int SYNTHETIC_FLAG = 0x00001000; | ||
| 12 | private static final int BRIDGED_FLAG = 0x00000040; | ||
| 13 | |||
| 14 | private int flags; | 8 | private int flags; |
| 15 | 9 | ||
| 16 | public AccessFlags(int flags) { | 10 | public AccessFlags(int flags) { |
| @@ -30,13 +24,17 @@ public class AccessFlags { | |||
| 30 | } | 24 | } |
| 31 | 25 | ||
| 32 | public boolean isSynthetic() { | 26 | public boolean isSynthetic() { |
| 33 | return (this.flags & SYNTHETIC_FLAG) != 0; | 27 | return (this.flags & Opcodes.ACC_SYNTHETIC) != 0; |
| 34 | } | 28 | } |
| 35 | 29 | ||
| 36 | public boolean isStatic() { | 30 | public boolean isStatic() { |
| 37 | return Modifier.isStatic(this.flags); | 31 | return Modifier.isStatic(this.flags); |
| 38 | } | 32 | } |
| 39 | 33 | ||
| 34 | public boolean isEnum() { | ||
| 35 | return (flags & Opcodes.ACC_ENUM) != 0; | ||
| 36 | } | ||
| 37 | |||
| 40 | public AccessFlags setPrivate() { | 38 | public AccessFlags setPrivate() { |
| 41 | this.setVisibility(Opcodes.ACC_PRIVATE); | 39 | this.setVisibility(Opcodes.ACC_PRIVATE); |
| 42 | return this; | 40 | return this; |
| @@ -53,7 +51,7 @@ public class AccessFlags { | |||
| 53 | } | 51 | } |
| 54 | 52 | ||
| 55 | public AccessFlags setBridged() { | 53 | public AccessFlags setBridged() { |
| 56 | this.setVisibility(BRIDGED_FLAG); | 54 | this.setVisibility(Opcodes.ACC_BRIDGE); |
| 57 | return this; | 55 | return this; |
| 58 | } | 56 | } |
| 59 | 57 | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java index b0d17b3e..234d11f3 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationClassVisitor.java | |||
| @@ -68,7 +68,7 @@ public class TranslationClassVisitor extends ClassVisitor { | |||
| 68 | translatedExceptions[i] = translator.getTranslatedClass(entryPool.getClass(exceptions[i])).getName(); | 68 | translatedExceptions[i] = translator.getTranslatedClass(entryPool.getClass(exceptions[i])).getName(); |
| 69 | } | 69 | } |
| 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(), translatedEntry.getSignature().toString(), translatedExceptions); |
| 71 | return new TranslationMethodVisitor(translator, entry, api, mv); | 71 | return new TranslationMethodVisitor(translator, obfClassEntry, entry, api, mv); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java index a2ebc203..82a1263b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java | |||
| @@ -11,14 +11,16 @@ import java.util.List; | |||
| 11 | import java.util.Locale; | 11 | import java.util.Locale; |
| 12 | 12 | ||
| 13 | public class TranslationMethodVisitor extends MethodVisitor { | 13 | public class TranslationMethodVisitor extends MethodVisitor { |
| 14 | private final ClassDefEntry ownerEntry; | ||
| 14 | private final MethodDefEntry methodEntry; | 15 | private final MethodDefEntry methodEntry; |
| 15 | private final Translator translator; | 16 | private final Translator translator; |
| 16 | 17 | ||
| 17 | private boolean hasParameterMeta; | 18 | private boolean hasParameterMeta; |
| 18 | 19 | ||
| 19 | public TranslationMethodVisitor(Translator translator, MethodDefEntry methodEntry, int api, MethodVisitor mv) { | 20 | public TranslationMethodVisitor(Translator translator, ClassDefEntry ownerEntry, MethodDefEntry methodEntry, int api, MethodVisitor mv) { |
| 20 | super(api, mv); | 21 | super(api, mv); |
| 21 | this.translator = translator; | 22 | this.translator = translator; |
| 23 | this.ownerEntry = ownerEntry; | ||
| 22 | this.methodEntry = methodEntry; | 24 | this.methodEntry = methodEntry; |
| 23 | } | 25 | } |
| 24 | 26 | ||
| @@ -85,7 +87,13 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 85 | String translatedSignature = translator.getTranslatedSignature(Signature.createTypedSignature(signature)).toString(); | 87 | String translatedSignature = translator.getTranslatedSignature(Signature.createTypedSignature(signature)).toString(); |
| 86 | 88 | ||
| 87 | // If we're not static, "this" is bound to index 0 | 89 | // If we're not static, "this" is bound to index 0 |
| 88 | int offsetIndex = index - (methodEntry.getAccess().isStatic() ? 0 : 1); | 90 | int offset = methodEntry.getAccess().isStatic() ? 0 : 1; |
| 91 | if (ownerEntry.getAccess().isEnum() && methodEntry.getName().startsWith("<")) { | ||
| 92 | // Enum constructors have an implicit "name" and "ordinal" parameter as well as "this" | ||
| 93 | offset = 3; | ||
| 94 | } | ||
| 95 | |||
| 96 | int offsetIndex = index - offset; | ||
| 89 | if (offsetIndex >= 0) { | 97 | if (offsetIndex >= 0) { |
| 90 | LocalVariableDefEntry entry = new LocalVariableDefEntry(methodEntry, offsetIndex, name, new TypeDescriptor(desc)); | 98 | LocalVariableDefEntry entry = new LocalVariableDefEntry(methodEntry, offsetIndex, name, new TypeDescriptor(desc)); |
| 91 | LocalVariableDefEntry translatedEntry = translator.getTranslatedVariableDef(entry); | 99 | LocalVariableDefEntry translatedEntry = translator.getTranslatedVariableDef(entry); |
| @@ -170,7 +178,7 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 170 | nameBuilder.append(argCls.name()); | 178 | nameBuilder.append(argCls.name()); |
| 171 | } else if (desc.isArray()) { | 179 | } else if (desc.isArray()) { |
| 172 | // List types would require this whole block again, so just go with aListx | 180 | // List types would require this whole block again, so just go with aListx |
| 173 | nameBuilder.append(nameIndex); | 181 | nameBuilder.append("Arr"); |
| 174 | } else if (desc.isType()) { | 182 | } else if (desc.isType()) { |
| 175 | String typeName = desc.getTypeEntry().getSimpleName().replace("$", ""); | 183 | String typeName = desc.getTypeEntry().getSimpleName().replace("$", ""); |
| 176 | typeName = typeName.substring(0, 1).toUpperCase(Locale.ROOT) + typeName.substring(1); | 184 | typeName = typeName.substring(0, 1).toUpperCase(Locale.ROOT) + typeName.substring(1); |