Java Program to disassemble Java Byte Code [closed]

岁酱吖の 提交于 2019-12-12 14:09:58

问题


I am recently reading about bytecode analysis and I need a help with the below query:

Which JDK packages/APIs I have to look for if I wanted to write a Java program which disassembles a Java Byte Code (by reading a class file) and print Opcodes without using any external libraries like ASM and without using javap command ?

In simple words, are there any JDK APIs available to disassemble Java Byte Code ?

If possible, can anybody share a sample code snippet for doing the same ?

This is purely for my understanding about the Core Java APIs support on bytecode and make myself aware if there any core Java libraries for byte code analysis.

Thank you.


回答1:


No there are no API's in the JRE for disassembling bytecode. Its easy to find out by looking at the javadoc package tree, the names already tell you about the scope of functionality found inside. Few are even remotely related and need checking out in detail.

Note that there is no javadoc for the com.sun packages and those are not considered part of the JDK.

But basically, everything is there. You can read files, and you can process them however you want. Documentation is also available about byte code and class files. So you could write everything yourself.

So...

Can we write a simple Java program to disassemble Java Byte Code and print Opcodes without using any external libraries like ASM and without using javap command ?

Yes. (depends on what qualifies as simple, a pure disassembler falls on the boundary IMO).

In other words, are there any JDK APIs available to disassemble Java Byte Code ?

No.



来源:https://stackoverflow.com/questions/32073897/java-program-to-disassemble-java-byte-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!