diff options
Diffstat (limited to 'src/cuchaz/enigma/bytecode/LocalVariableRenamer.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/LocalVariableRenamer.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/LocalVariableRenamer.java b/src/cuchaz/enigma/bytecode/LocalVariableRenamer.java new file mode 100644 index 0000000..53f207c --- /dev/null +++ b/src/cuchaz/enigma/bytecode/LocalVariableRenamer.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | package cuchaz.enigma.bytecode; | ||
| 2 | |||
| 3 | import javassist.CtBehavior; | ||
| 4 | import javassist.CtClass; | ||
| 5 | import javassist.bytecode.ByteArray; | ||
| 6 | import javassist.bytecode.ConstPool; | ||
| 7 | import javassist.bytecode.LocalVariableAttribute; | ||
| 8 | |||
| 9 | |||
| 10 | public class LocalVariableRenamer { | ||
| 11 | |||
| 12 | public void rename(CtClass c) { | ||
| 13 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | ||
| 14 | |||
| 15 | // if there's a local variable table, just rename everything to v1, v2, v3, ... for now | ||
| 16 | LocalVariableAttribute table = (LocalVariableAttribute)behavior.getMethodInfo().getCodeAttribute().getAttribute(LocalVariableAttribute.tag); | ||
| 17 | if (table == null) { | ||
| 18 | continue; | ||
| 19 | } | ||
| 20 | |||
| 21 | ConstPool constants = c.getClassFile().getConstPool(); | ||
| 22 | for (int i=0; i<table.tableLength(); i++) { | ||
| 23 | renameVariable(table, i, constants.addUtf8Info("v" + i)); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | private void renameVariable(LocalVariableAttribute table, int i, int stringId) { | ||
| 29 | // based off of LocalVariableAttribute.nameIndex() | ||
| 30 | ByteArray.write16bit(stringId, table.get(), i*10 + 6); | ||
| 31 | } | ||
| 32 | } | ||