我正在进行一些类文件分析,并且正在使用ASM读取类。在Javap中,操作码以及tagName和tagValue内联打印,但是在每个AbstractInsnNode中,我仅看到int的字段(而不是tagValue)
for(AbstractInsnNode abstractInsnNode : instructionList)
{
System.out.println("\tOpcode: " + + abstractInsnNode.getOpcode() +
" type: " + abstractInsnNode.getType());
}
如何使用ASM获得该指令的信息,例如:
5: invokeinterface #6, 2 // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
在加载字符串和常量等的情况下,我也需要访问这些值。这通常来自javap的
tagValue
。我不仅需要打印这些,还需要以编程方式访问这些值。我需要访问基本操作信息,例如以下字段:
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
}]
最佳答案