查找 Java 类文件版本之间的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/88216/
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-29 11:00:40  来源:igfitidea点击:

Finding differences between versions of a Java class file

javadecompiling

提问by Anonymoose

I am working with a large Java web application from a commercial vendor. I've received a patch from the vendor in the form of a new .class file that is supposed to resolve an issue we're having with the software. In the past, applying patches from this vendor have caused new and completely unrelated problems to arise, so I want to understand the change being made even before applying it to a test instance.

我正在使用来自商业供应商的大型 Java Web 应用程序。我从供应商那里收到了一个新的 .class 文件形式的补丁,它应该可以解决我们在软件中遇到的问题。过去,应用来自该供应商的补丁会导致出现新的完全不相关的问题,因此我想在将其应用于测试实例之前了解所做的更改。

I've got the two .class files side by side, the one extracted from the currently running version and the updated one from the vendor. JADand JReverseProboth decompile and disassemble (respectively) the two versions to the same output. However, the .class files are different sizes and I see differences in the output of od -x, so they're definitely not identical.

我有两个 .class 文件,一个是从当前运行的版本中提取的,另一个是从供应商那里获取的。 JADJReversePro都反编译和反汇编(分别)两个版本到相同的输出。但是,.class 文件的大小不同,我看到 .class 的输出存在差异od -x,因此它们绝对不相同。

What other steps could I take to determine the difference between the two files?

我还可以采取哪些其他步骤来确定两个文件之间的差异?



结论:

Thanks for the great responses. Since javap -coutput is also identical for the two class files, I am going to conclude that Davr's right and the vendor sent me a placebo. While I'm accepting Davr's answer for that reason, it was Chris Marshall and John Meagher who turned me on to javap, so thanks to all three of you.

感谢您的精彩回复。由于javap -c这两个类文件的输出也相同,我将得出结论,Davr 是正确的,供应商给我发送了安慰剂。由于这个原因,我接受了 Davr 的回答,是 Chris Marshall 和 John Meagher 让我转向 javap,所以感谢你们三个。

回答by davr

It's possible that they just compiled it with a new version of the java compiler, or with different optimization settings etc, so that the functionality is the same, and the code is the same, but the output bytecode is slightly different.

有可能他们只是用新版本的java编译器编译它,或者用不同的优化设置等等,所以功能是一样的,代码是一样的,但输出的字节码略有不同。

回答by John Meagher

If you are looking for API level differences the javaptool can be a big help. It will output the method signatures and those can be output to a plain text files and compared using normal diff tools.

如果您正在寻找 API 级别差异,javap工具可能会有很大帮助。它将输出方法签名,这些签名可以输出到纯文本文件并使用普通差异工具进行比较。

回答by alastairs

You could try using a diff tool (such as SourceGear's free DiffMerge tool) on the decompiled sources. That should pick up the file differences, although it will likely pick up "insignificant" differences, for example if variables have been named differently in the two versions.

您可以尝试在反编译的源代码上使用差异工具(例如 SourceGear 的免费 DiffMerge 工具)。这应该会找出文件差异,尽管它可能会发现“无关紧要”的差异,例如,如果变量在两个版本中的命名不同。

http://www.sourcegear.com/diffmerge/

http://www.sourcegear.com/diffmerge/

回答by oxbow_lakes

You can use javap (in $JDK_HOME/bin) to decompile java .class files. It will tell you (for example) the class file version among other things

您可以使用 javap(在 $JDK_HOME/bin 中)来反编译 java .class 文件。它会告诉您(例如)类文件版本等