7

I used to work with BeyondCompare and it was able to compare *.class files by configuring it to run a decompiler before comparison.

Is there something like that for WinMerge? Or a plug-in that can do it instead?

RonK
  • 1,480
  • 2
  • 14
  • 27

3 Answers3

11

I have spent the day writing a DLL plugin for Winmerge to do this - it isn't the world's greatest thing, but it gets the job done.

Takes the filename, splits it into directory and class name, then calls javap for each class file. It is rather slow unfortunately (javap's fault I'd say).

It would be nice if winmerge compared the files before unpacking them to see if they are different - that would save a bit of time. Maybe this can be accomplished in the plugin somehow but as I said I really just hacked this together as quick as I could.

Source, prebuilt DLL, and instructions here: https://gitlab.com/wayneuroda/winmerge-unpack-java-class-files

Wayne Uroda
  • 245
  • 4
  • 10
  • Thanks - I missed the notification about this answer, i just saw it now. I really appreciate your effort - I'll test it ASAP :) – RonK Oct 26 '11 at 20:45
  • 1
    to enable automatic diffing (upon double clicking), do this (Plugins > Automatic Unpacking) - WinMerge 2.14.0 – Gary Tsui Jan 07 '14 at 10:22
  • @GaryTsui thanks, but what I mean is that in the list view (say you compare a whole folder of class files) it will show class files as different, even though upon unpacking they are identical. I think this comes about because they can have binary differences (due to recompilation etc) however the method/field signatures have not changed. When comparing two binary APIs for example, you have to check every different class manually, when you double click on it you will be met with "the files are identical" or similar, even though they were marked as different in the list! – Wayne Uroda Jan 13 '14 at 10:58
  • great trick .. you save my night :) – Ahmed Nabil Jan 16 '16 at 15:06
  • The links seems to be broken :( – Alireza Fattahi Apr 07 '21 at 06:42
  • 1
    @AlirezaFattahi I updated the links – Wayne Uroda Apr 13 '21 at 04:23
  • publishing it to github, gitlab or any similar sites would be far more reliable than a onedrive link – phuclv Jun 07 '23 at 15:17
  • @phuclv I love gitlab, but I feel the urge to make a joke about how nobody has yet deleted the onedrive database ;) you're right. Dunno why I never did publish this. I don't feel it's very polished. Will put it on my todo list. – Wayne Uroda Jun 15 '23 at 05:40
1

If comparing disassembled JVM bytecode (see my other answer) is not enough, maybe decompiling to Java source code might be more helpful…

After learning about the "currently undocumented" Plugins.xml (Plugins in the improved plugin system) as an alternative to sct and dll plugins, I have sucessfully "created" a plugin decompiling Java *.class files using procyon Java Decompiler in WinMerge 2.16.30.0:

  1. Create directory %APPDATA%\WinMerge\MergePlugins, if it doesn't exist.
  2. Create file %APPDATA%\WinMerge\MergePlugins\Plugins.xml, if it doesn't exist.
    • Use C:\Program Files\WinMerge\MergePlugins\Plugins.xml as template removing <plugin> elements.
  3. Insert a custom <plugin> with your path\to\procyon-decompiler.jar:
<?xml version="1.0"?>
<plugins>
  <plugin name="MyDecompileJavaClass">
    <event value="FILE_PACK_UNPACK" />
    <description value="My JVM class decompiler with Procyon. &#xD;&#xA;Arguments: Command line options passed to the java command." />
    <file-filters value="\.class$" />
    <is-automatic value="false" />
    <unpacked-file-extension value=".class.java" />
    <extended-properties value="ProcessType=Decompilation;MenuCaption=My Decompile Java Class" />
    <arguments value="A:\path\to\procyon-decompiler.jar" />
    <unpack-file>
      <command>cmd /c java -jar ${*} "${SRC_FILE}" > "${DST_FILE}"</command>
    </unpack-file>
  </plugin>
</plugins>
  1. Reload plugins (WinMerge menu command).
  2. If necessary, adjust the path to Procyon JAR (arguments) in WinMerge plugin settings.
  3. Use the new plugin for unpacking/comparing in WinMerge.
fheub
  • 186
  • 1
  • 9
0

The DecompileJVM plugin DisassembleJVM has been added in WinMerge 2.16.15 - 2021-09-20. Look for "Disassemble JVM Bytecode" in the list of plugins.

It is an unpacker plugin allowing you to compare JVM bytecode disassembled with javap.

fheub
  • 186
  • 1
  • 9