1

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

Vinoth Kumar C M
  • 9,668
  • 27
  • 81
  • 125
  • This is likely to be tricky, since decompilation is always a guess of sorts. It won't result in the *original* source, just source that would compile to the same bytecode. Hence you'll get a **lot** of spurious differences - it's probably fine if you're going through manually and have a rough idea of the changes, but it will be a real challenge to do this automatically. – Andrzej Doyle Jun 06 '11 at 08:39
  • 4
    If you were using Eclipse for your development, chances are - they aren't yet lost. You can attempt restoring from local history. – adarshr Jun 06 '11 at 08:40
  • I am not talking about doing it automatically, but atleast it should compare and say which files are different. – Vinoth Kumar C M Jun 06 '11 at 08:41

6 Answers6

8

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
Tomasz Nurkiewicz
  • 311,858
  • 65
  • 665
  • 652
  • 1
    +1: JAD will not restore comments, original line spacing, using of import * vs import each class, the names of local variables, SOURCE retention annotations and much more because this information is not in the class. – Peter Lawrey Jun 06 '11 at 09:15
2

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.

Ozair Kafray
  • 13,001
  • 7
  • 52
  • 76
THelper
  • 14,136
  • 6
  • 59
  • 95
2

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.

Aaron Digulla
  • 297,790
  • 101
  • 558
  • 777
2

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 
Vinoth Kumar C M
  • 9,668
  • 27
  • 81
  • 125
1

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

Op De Cirkel
  • 26,245
  • 6
  • 37
  • 52
0

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.

keyser
  • 17,711
  • 16
  • 54
  • 93