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?

3 Answers 3

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

8
  • 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, 2011 at 20:45
  • 1
    to enable automatic diffing (upon double clicking), do this (Plugins > Automatic Unpacking) - WinMerge 2.14.0
    – Gary Tsui
    Jan 7, 2014 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! Jan 13, 2014 at 10:58
  • great trick .. you save my night :) Jan 16, 2016 at 15:06
  • 1
    @AlirezaFattahi I updated the links Apr 13, 2021 at 4:23
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.
1
  • Wow, this is so much nicer to the user than making them write a DLL :D Jun 15, 2023 at 4:28
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .