summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java')
-rw-r--r--src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java
index 8b4ef9c..878e30a 100644
--- a/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java
+++ b/src/main/java/cuchaz/enigma/bytecode/LocalVariableRenamer.java
@@ -38,7 +38,7 @@ public class LocalVariableRenamer {
38 38
39 LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag); 39 LocalVariableAttribute table = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
40 if (table != null) { 40 if (table != null) {
41 renameLVT(behaviorEntry, constants, table); 41 renameLVT(behaviorEntry, constants, table, c);
42 } 42 }
43 43
44 LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag); 44 LocalVariableTypeAttribute typeTable = (LocalVariableTypeAttribute) codeAttribute.getAttribute(LocalVariableAttribute.typeTag);
@@ -58,7 +58,7 @@ public class LocalVariableRenamer {
58 } 58 }
59 } 59 }
60 60
61 private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table) { 61 private void renameLVT(BehaviorEntry behaviorEntry, ConstPool constants, LocalVariableAttribute table, CtClass ctClass) {
62 62
63 // skip empty tables 63 // skip empty tables
64 if (table.tableLength() <= 0) { 64 if (table.tableLength() <= 0) {
@@ -69,14 +69,13 @@ public class LocalVariableRenamer {
69 int starti = 0; 69 int starti = 0;
70 if (table.variableName(0).equals("this")) { 70 if (table.variableName(0).equals("this")) {
71 // skip the "this" variable 71 // skip the "this" variable
72 starti = 1; 72 starti++;
73 } 73 }
74 74
75 // rename method arguments first 75 // rename method arguments first
76 int numArgs = 0; 76 int numArgs = 0;
77 if (behaviorEntry.getSignature() != null) { 77 if (behaviorEntry.getSignature() != null) {
78 numArgs = behaviorEntry.getSignature().getArgumentTypes().size(); 78 numArgs = behaviorEntry.getSignature().getArgumentTypes().size();
79
80 boolean isNestedClassConstructor = false; 79 boolean isNestedClassConstructor = false;
81 80
82 // If the behavior is a constructor and if it have more than one arg, it's probably from a nested! 81 // If the behavior is a constructor and if it have more than one arg, it's probably from a nested!
@@ -93,21 +92,28 @@ public class LocalVariableRenamer {
93 92
94 for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) { 93 for (int i = starti; i < starti + numArgs && i < table.tableLength(); i++) {
95 int argi = i - starti; 94 int argi = i - starti;
95 if (ctClass.isEnum())
96 argi += 2;
97 if (behaviorEntry.getClassEntry().getName().contains("ahd") && behaviorEntry instanceof ConstructorEntry)
98 System.out.println(behaviorEntry.getClassEntry() + " " + i);
96 String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, "")); 99 String argName = this.translator.translate(new ArgumentEntry(behaviorEntry, argi, ""));
97 if (argName == null) { 100 if (argName == null) {
98 Type argType = behaviorEntry.getSignature().getArgumentTypes().get(isNestedClassConstructor ? argi + 1 : argi); 101 int argIndex = isNestedClassConstructor ? argi + 1 : argi;
102 if (ctClass.isEnum())
103 argIndex -= 2;
104 Type argType = behaviorEntry.getSignature().getArgumentTypes().get(argIndex);
99 // Unfortunately each of these have different name getters, so they have different code paths 105 // Unfortunately each of these have different name getters, so they have different code paths
100 if (argType.isPrimitive()) { 106 if (argType.isPrimitive()) {
101 Type.Primitive argCls = argType.getPrimitive(); 107 Type.Primitive argCls = argType.getPrimitive();
102 argName = "a" + argCls.name() + (argi + 1); 108 argName = "a" + argCls.name() + (argIndex + 1);
103 } else if (argType.isArray()) { 109 } else if (argType.isArray()) {
104 // List types would require this whole block again, so just go with aListx 110 // List types would require this whole block again, so just go with aListx
105 argName = "aList" + (argi + 1); 111 argName = "aList" + (argIndex + 1);
106 } else if (argType.isClass()) { 112 } else if (argType.isClass()) {
107 ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry()); 113 ClassEntry argClsTrans = this.translator.translateEntry(argType.getClassEntry());
108 argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argi + 1); 114 argName = "a" + argClsTrans.getSimpleName().replace("$", "") + (argIndex + 1);
109 } else { 115 } else {
110 argName = "a" + (argi + 1); 116 argName = "a" + (argIndex + 1);
111 } 117 }
112 } 118 }
113 renameVariable(table, i, constants.addUtf8Info(argName)); 119 renameVariable(table, i, constants.addUtf8Info(argName));