Java, ASM: How to Get Opcode Name and TagValue fro

2019-08-08 02:38发布

I am working on some class file analysis and I am working on using ASM to read classes. In Javap the opcode and the tagName and tagValue are printed inline, but in each AbstractInsnNode, I see only fields for the int (and not the tagValue)

for(AbstractInsnNode abstractInsnNode : instructionList)
{
   System.out.println("\tOpcode: " + + abstractInsnNode.getOpcode()  +
        " type: " + abstractInsnNode.getType());
}  

How do I get the of the instruction with ASM, such as:

5: invokeinterface #6,  2 // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z

And in the case of loading strings and constants etc, I need access to those values as well. This usually come from the tagValue of javap. I don't just need to print these, I also need programatic access to the values.

I need access to the basic operation information, eg these fields:

 jvmOperations": [{
        "byteOffset": 0,
        "constantPoolIndex": null,
        "opCode": 42,
        "opCodeName": "aload_0",
        "type": null,
        "tagName": null,
        "tagValue": null
    }, {
        "byteOffset": 1,
        "constantPoolIndex": null,
        "opCode": 180,
        "opCodeName": "getfield",
        "type": null,
        "tagName": "Field",
        "tagValue": "val$foo:Lcom/example/graph/demo/Foo;"
    }, {
        "byteOffset": 4,
        "constantPoolIndex": null,
        "opCode": 182,
        "opCodeName": "invokevirtual",
        "type": null,
        "tagName": "Method",
        "tagValue": "com/example/graph/demo/Foo.doSomething:()Ljava/lang/Integer;"
    }, {
        "byteOffset": 7,
        "constantPoolIndex": null,
        "opCode": 176,
        "opCodeName": "areturn",
        "type": null,
        "tagName": null,
        "tagValue": null
    }]

1条回答
叛逆
2楼-- · 2019-08-08 02:55

I would check the source of the ASMifier and Textifier classes how they print stuff out..

查看更多
登录 后发表回答