Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于在javassist中标识交换机案例的操作码_Java_Reflection_Asmx_Javassist - Fatal编程技术网

用于在javassist中标识交换机案例的操作码

用于在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(

如何使用javassist或asm在java类中查找用于标识开关大小写的操作代码

我使用了下面的代码片段

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
无法获取开关箱值。 请帮帮我

  • 使用只包含非常简单的switch/case语句的方法编写一个类
  • 编译那个类
  • 使用
    javap-cmyclass查看字节码
  • 字节码包含
    TABLESWITCH
    LOOKUPSWITCH
    ,javassists
    Opcode
    类具有相应的静态字段