我正在进行一些类文件分析,我正在使用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
}]