用于在javassist中标识交换机案例的操作码
如何使用javassist或asm在java类中查找用于标识开关大小写的操作代码 我使用了下面的代码片段用于在javassist中标识交换机案例的操作码,java,reflection,asmx,javassist,Java,Reflection,Asmx,Javassist,如何使用javassist或asm在java类中查找用于标识开关大小写的操作代码 我使用了下面的代码片段 List methods = lClassFile.getMethods(); for (Object m : methods) { MethodInfo lMethodInfo = (MethodInfo) m; System.out.println("method name: " + lMethodInfo.getName(
List methods = lClassFile.getMethods();
for (Object m : methods) {
MethodInfo lMethodInfo = (MethodInfo) m;
System.out.println("method name: " + lMethodInfo.getName());
CodeAttribute ca = lMethodInfo.getCodeAttribute();
for (CodeIterator ci = ca.iterator(); ci.hasNext();) {
int index = ci.next();
int op = ci.byteAt(index);
if (op == Opcode.TABLESWITCH) {
int a1 = ci.s16bitAt(index + 1);
String fieldrefType = " " + lClassFile.getConstPool().getFieldrefType(a1);
String fieldName = " " + lClassFile.getConstPool().getFieldrefName(a1);
String fieldrefClassName = " " + lClassFile.getConstPool().getFieldrefClassName(a1);
System.out.println("1 -> FieldrefType = " + fieldrefType + " field name: " + fieldName + " FieldrefClassName name: " + fieldrefClassName);
}
if (op == Opcode.LOOKUPSWITCH) {
int a1 = ci.s16bitAt(index + 1);
String fieldrefType = " " + lClassFile.getConstPool().getFieldrefType(a1);
String fieldName = " " + lClassFile.getConstPool().getFieldrefName(a1);
String fieldrefClassName = " " + lClassFile.getConstPool().getFieldrefClassName(a1);
System.out.println("2 -> FieldrefType = " + fieldrefType + " field name: " + fieldName + " FieldrefClassName name: " + fieldrefClassName);
}
}
}
我得到的输出是:
method name: <init>
method name: execute
2 -> FieldrefType = null field name: null FieldrefClassName name: null
1 -> FieldrefType = null field name: null FieldrefClassName name: null
method name: validate
2 -> FieldrefType = null field name: null FieldrefClassName name: null
2 -> FieldrefType = null field name: null FieldrefClassName name: null
method name: postExecute
2 -> FieldrefType = null field name: null FieldrefClassName name: null
2 -> FieldrefType = null field name: null FieldrefClassName name: null
方法名称:
方法名称:execute
2->FieldrefType=null字段名称:null FieldrefClassName名称:null
1->FieldrefType=null字段名称:null FieldrefClassName名称:null
方法名称:验证
2->FieldrefType=null字段名称:null FieldrefClassName名称:null
2->FieldrefType=null字段名称:null FieldrefClassName名称:null
方法名称:postExecute
2->FieldrefType=null字段名称:null FieldrefClassName名称:null
2->FieldrefType=null字段名称:null FieldrefClassName名称:null
无法获取开关箱值。
请帮帮我
javap-cmyclass查看字节码
TABLESWITCH
或LOOKUPSWITCH
,javassistsOpcode
类具有相应的静态字段