反编译java class文件并与svn比较

发布于 2024-11-13 06:54:48 字数 240 浏览 11 评论 0原文

我们在 SVN 中驻留有普通的 java 文件。我们对这些文件做了一些更改,但碰巧这些文件丢失了(它们不在 SVN 中)。但是我们拥有使用新更改的文件生成的类文件。

我们可以使用类文件,反编译它们并将其与 SVN 进行比较吗?最简单的方法是什么?

大约有 400 个已更改的文件。所以一一比较是不可行的。

我正在寻找任何工具或脚本。

还有没有反编译器,可以一次性反编译整个文件夹?

谢谢

We have normal java files residing in the SVN. We have made some changes in those files , but it happens that , those files are lost (they are not in SVN). But we have the class files that are generated using the newly changed files.

Can we use the class files , decompile them and compare it against SVN. What is the easiest way to do it?

There are about 400 changed files. So comparing one by one is not feasible.

I am looking for any tool or scripts.

Also is there any decompiler , that would decompile a whole folder at one go?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

小鸟爱天空丶 2024-11-20 06:54:48

反编译使用最常用的工具JAD。不过,比较有点棘手。我建议采用以下方案:

  1. 从 SVN 获取最新的源代码
  2. 构建它
  3. 反编译它(!)
  4. 获取包含一些修改但没有源代码的已编译类
  5. 也反编译它们
  6. 比较两个反编译的源代码目录

为什么要编译和反编译原始源代码?因为 JAD 会产生相当好的结果,但它永远不会生成与所使用的完全相同的源。因此,如果您想在比较原始源和反编译源时避免麻烦(并快速查明实际差异),则必须比较两个 JAD 输出,而不是原始源和合成 JAD 输出。

我希望比较两个目录结构对您来说不会成为问题。您可以在 Windows 上使用 Total Commander 在 Linux 上使用各种实用程序/脚本,例如:

$ diff -r dir1 dir2

For decompiling use JAD, most commonly used tool. Comparing is a bit tricky though. I would suggest the following scenario:

  1. Grab the latest source code from SVN
  2. Build it
  3. Decompile it (!)
  4. Take your compiled classes that include some modifications but you don't have sources
  5. Decompile them as well
  6. Compare both decompiled sources directories

Why compiling and decompiling the original source codes? Because JAD produces pretty good results, but it will never generate the exact same sources that were used. So if you want to avoid headaches when comparing original sources and decompiled ones (and pinpoint the actual differences quickly), you have to compare two JAD outputs rather than original source and synthetic JAD output.

I hope having two directory structures to compare won't be a problem for you. You can use Total Commander on Windows or various utilities/scripts on Linux, like:

$ diff -r dir1 dir2
帅气尐潴 2024-11-20 06:54:48

jad 可以反编译整个文件夹,但结果取决于几个因素。首先,JAD 只能很好地支持 Java 4。 Java 5 及更高版本将包含 JAD 无法理解的奇怪字节代码块。

如果代码是使用调试符号编译的,您可以重新对齐行号(jadclipse 插件可以做到这一点)但JAD本身做不到。

如果使用 -g:source 编译代码,则类文件包含完整的源代码。乍一看,我不知道如何实现这一点,但是像 javap (JDK 附带)或 ASM 应该允许您获取它。

jad can decompile a whole folder but the result depends on a couple of factors. First, JAD only supports Java 4 well. Java 5 and up will contain odd byte code chunks that JAD didn't understand.

If the code is compiled with debug symbols, you can realign line numbers (the jadclipse plugin can do that) but JAD itself can't do it.

If you compiled the code with -g:source, then the class files contain the complete source code. At first glance, I don't know how to get at this but tools like javap (comes with the JDK) or ASM should allow you to get it.

吃颗糖壮壮胆 2024-11-20 06:54:48

如果您在生成类文件时没有使用混淆,则可以将反编译的源文件与原始文件进行比较。然而,自动比较会很困难,因为反编译的源代码通常由于编译器优化等原因而与原始源代码略有不同。
我个人使用 jad 作为反编译器,但我不确定你可以提供一次性完成整个文件夹。

It is possible to compare a decompiled source file with the orginal, provided you did not use obfuscation when generating class files. However, automated comparison will be difficult because the decompiled source is often slightly different than the original source due to compiler optimization for example.
Personally I use jad as a decompiler, but I'm not sure you can provide it with a whole folder at one go.

窗影残 2024-11-20 06:54:48

我使用下面的命令(jad decompiler)一次性编译文件夹中的所有类文件。

             jad -o -r -sjava -dsrc tree/**/*.class 

I used the below command(jad decompiler) to compile all the class files in a folder in one go.

             jad -o -r -sjava -dsrc tree/**/*.class 
分开我的手 2024-11-20 06:54:48

使用jd-gui,非常好的反编译器,但是编译......它会很痛苦。

Use jd-gui, very good decompiler, but the compering ... its going to be painful.

与君绝 2024-11-20 06:54:48

现在我正是这样做的,使用 http://java.decompiler.free.fr/ 进行反编译以及其他比较 (http://www.scootersoftware.com/) 来比较软件包和文件。与编译和反编译的实际版本(svn)进行快速比较,以检查哪些文件(以及哪些部分)是最新的,这看起来是个好主意。

Right now im doing exactly that, using http://java.decompiler.free.fr/ to decompile and beyond compare (http://www.scootersoftware.com/) to compare packages and files. It looks like a great idea to make a fast compare against the actual version (svn) compiled and decompiled, to check which files (and which sections) are up to date.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文