blob: 53f207ca945b9cf156e7bb30f629a3ca8ba641cd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package cuchaz.enigma.bytecode;
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.bytecode.ByteArray;
import javassist.bytecode.ConstPool;
import javassist.bytecode.LocalVariableAttribute;
public class LocalVariableRenamer {
public void rename(CtClass c) {
for (CtBehavior behavior : c.getDeclaredBehaviors()) {
// if there's a local variable table, just rename everything to v1, v2, v3, ... for now
LocalVariableAttribute table = (LocalVariableAttribute)behavior.getMethodInfo().getCodeAttribute().getAttribute(LocalVariableAttribute.tag);
if (table == null) {
continue;
}
ConstPool constants = c.getClassFile().getConstPool();
for (int i=0; i<table.tableLength(); i++) {
renameVariable(table, i, constants.addUtf8Info("v" + i));
}
}
}
private void renameVariable(LocalVariableAttribute table, int i, int stringId) {
// based off of LocalVariableAttribute.nameIndex()
ByteArray.write16bit(stringId, table.get(), i*10 + 6);
}
}
|