Java, ASM: How to Get Opcode Name and TagValue from ASM InsnNode?

我与影子孤独终老i 提交于 2019-12-11 07:48:28

问题


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:


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



来源:https://stackoverflow.com/questions/26575111/java-asm-how-to-get-opcode-name-and-tagvalue-from-asm-insnnode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!