是否可以查看 Java 类文件的字节码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16774744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:59:00  来源:igfitidea点击:

Is it possible to view a Java class files bytecode

javabytecode

提问by Popgalop

I am working on a bytecode manipulation/generation in Java and I was just wondering if there is an easy way I could check the bytecode. I do not want to decompile the file, I would like to actually look at the compiled bytecode. I do not need to edit it. Any links or programs for doing this would be acceptable answers.

我正在 Java 中进行字节码操作/生成,我只是想知道是否有一种简单的方法可以检查字节码。我不想反编译文件,我想实际看看编译后的字节码。我不需要编辑它。任何用于执行此操作的链接或程序都是可以接受的答案。

采纳答案by Mike Strobel

I've been working on a decompilerthat has a color-coded bytecode output mode (which I find far more readable than javap). It can also output Java code or an intermediate 'bytecode AST'.

我一直在研究具有颜色编码字节码输出模式的反编译器(我发现它比 javap 更具可读性)。它还可以输出 Java 代码或中间的“字节码 AST”。

回答by maba

Since you wanted to be guided to some program that can easily show you the byte code then my suggestion is to use IntelliJ IDEA since it has built-in support for viewing byte code.

由于您希望被引导到一些可以轻松向您显示字节码的程序,因此我的建议是使用 IntelliJ IDEA,因为它具有查看字节码的内置支持。

Here's an example how to do it (it can also be mapped to some keys of your choice):

这是一个如何做到的示例(它也可以映射到您选择的某些键):

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

It is very easy, and it can surely be done in eclipse or NetBeans as well.

这很容易,当然也可以在 eclipse 或 NetBeans 中完成。

回答by Bozho

Not sure what exactly you need, but apart from javap, which is a command-line tool for displaying the bytecode, you can take a look at javassist, asmand cglib- they allow you to parse the bytecode with java code.

不确定您到底需要什么,但除了javap是用于显示字节码的命令行工具之外,您还可以查看javassistasmcglib- 它们允许您使用 java 代码解析字节码。

回答by Oak

The javapcommand-line tool, which is bundled with Oracle's JDK, gives a detailed textual dump of .class files along with the constant pool and all functions' bytecode content. Just run it with -vto get a full dump.

javap与 Oracle 的 JDK 捆绑在一起命令行工具提供了 .class 文件的详细文本转储以及常量池和所有函数的字节码内容。只需运行它-v即可获得完整的转储。