Java, ASM: how to get the opcode name and TagValue from ASM InsnNode?

I am working on some analysis of class files, and I am working on using ASM to read classes. In Javap, the operation code and tagName and tagValue are printed inline, but in each AbstractInsnNode I see only fields for int (and not tagValue)

for(AbstractInsnNode abstractInsnNode : instructionList) { System.out.println("\tOpcode: " + + abstractInsnNode.getOpcode() + " type: " + abstractInsnNode.getType()); } 

How to get instructions from ASM, for example:

 5: invokeinterface #6, 2 // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z 

And in the case of loading strings and constants, etc. I also need access to these values. This usually comes from tagValue javap. I just don't need to print them, I also need programmatic access to the values.

I need access to the basic operation information, for example, 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
source share
1 answer

I would check the source of ASMifier and Textifier , how they print the material ..

0
source

Source: https://habr.com/ru/post/1204965/


All Articles