分解Java字节码的Java程序 [英] Java Program to disassemble Java Byte Code

查看:55
本文介绍了分解Java字节码的Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近正在阅读有关字节码分析的信息,我需要以下查询的帮助:


我必须使用哪些JDK包/ API寻找我是否想编写一个Java程序,该程序反汇编Java字节码(通过读取类文件)并在不使用任何外部库(例如ASM)且不使用 javap $ c>命令吗?


简单来说,是否有任何JDK API可用于反汇编Java字节码?



如果可能,任何人都可以共享一个示例代码片段来执行相同的操作吗?



这纯粹是出于我对字节码的核心Java API支持的理解,并让我知道是否存在用于字节码分析的核心Java库。



谢谢。

解决方案

JRE中没有用于拆卸字节码的API。通过查看javadoc软件包树可以很容易地找到它们,这些名称已经告诉您有关内部功能范围的信息。很少有人甚至与远程相关,因此需要详细检查。



请注意,com.sun软件包没有javadoc,它们不被视为JDK的一部分。 / p>

但是基本上,所有都是。您可以读取文件,也可以根据需要对其进行处理。也提供有关字节码和类文件的文档。因此,您可以自己编写所有内容。



所以...


我们可以编写一个简单的Java程序来分解Java字节码并打印操作码,而无需使用任何外部库(例如ASM)并且不使用javap命令吗?


是。 (取决于符合 simple 的条件,一个纯反汇编程序将落在IMO边界上。)


,是否有任何JDK API可用于反汇编Java字节码?


否。


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.

解决方案

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.

这篇关于分解Java字节码的Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆