Java,ASM:如何从ASM InsnNode获取操作码名称和TagValue?

2024-04-28

我正在研究一些类文件分析,并且正在研究使用 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

在加载字符串和常量等的情况下,我也需要访问这些值。这通常来自tagValuejavap的。我不仅需要打印这些值,还需要以编程方式访问这些值。

我需要访问基本操作信息,例如这些字段:

 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
    }]

我会检查的来源 and 课程他们如何打印东西..

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java,ASM:如何从ASM InsnNode获取操作码名称和TagValue? 的相关文章

随机推荐