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

标签 java java-bytecode-asm

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

最佳答案

我会检查 ASMifier 的来源和 Textifier类如何打印东西..

关于Java、ASM : How to Get Opcode Name and TagValue from ASM InsnNode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26575111/

相关文章:

java - 如何在ASM java中将ClassVisitor转换为ClassNode

java - payara micro 5.182 不部署用 java10 编译的 Web 应用程序

java - IntelliJ IDEA 17 - ASM 字节码大纲不起作用

java - Spring 3.2 mvc 测试 post 请求

java - ASM库中MethodNode的 'visitMethodInsn'方法的实现

java - 检查方法是否对 permgen 内存有贡献

java - Android获取保存的网络SSID

Java 枚举继承 : Is it possible to somehow extract the enums' toString() method to a common super class/enum?

java - 根据 JComboBox.SelectedItem 启用和禁用 JCheckBox

java - 按下按钮时使用 ZEST 框架绘制图形不起作用?