Java: Newer and supported decompilers (not JAD)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bc_for_life
    Journeyman
    • Jul 2010
    • 12

    Java: Newer and supported decompilers (not JAD)

    TOPIC: Java: Newer and supported decompilers (not JAD)

    (1) Thank you Scooter. BC is great.
    (2) We all need you to keep supporting decompilation of warfile and jarfile s and the resulting seamless comparison within BC.
    (3) You seem to be using the venerable JAD decompiler. This has become an unsupported tool.
    (4) Good news is that there are a few, new and supported decompilers out there. These decompilers are also trying to support the newer features of Java 7 and Java 8
    (5) Here are some URLs for Scooter to reference, to possibly start shipping a new decompiler with BC.
    (6) https://bitbucket.org/mstrobel/procy...a%20Decompiler
    (7) http://www.benf.org/other/cfr/
    (8) http://javapapers.com/core-java/java-decompiler/

    Thank you. Many of us love this feature and will *rely* on it for years and years to com.
  • Aaron
    Team Scooter
    • Oct 2007
    • 16009

    #2
    To clarify, Beyond Compare 3 does not ship with a decompiler for Java class files. Our File Formats are able to be customized to use External Conversion command lines, such as JAD, to help convert from one file type into plain text.

    We do have some previously created formats available for download (including a JAD based one) on our website. We can certainly review the resources you've posted here to see if we can update or create an alternate format, but Scooter Software does not directly support JAD or the other external programs used by the File Formats.

    If you are comfortable and familiar with using any of the above resources from the command line, all you would need to do is create a new Text format in the Tools menu -> File Formats dialog, with an external conversion command line which takes in a source file (file.class) and outputs a target temp text file (temp.txt). The target temp file is the one that would be opened in BC3, using %s and %t to represent the files in the External Conversion. We have a sample KB article (detailing a custom format for *.resx files) here:
    http://www.scootersoftware.com/suppo...rnalconversion
    Aaron P Scooter Software

    Comment

    • bc_for_life
      Journeyman
      • Jul 2010
      • 12

      #3
      Thanks Aaron.
      (1) I wonder how many people feel that the seamless comparison of Java warfiles / jarfiles is a "killer feature" for this product ? (I know that I do)
      (2) Java 6, 7, 8 ... changes. Bytecodes change. JAD is not supported.
      (3) I'm guessing that I must have downloaded "these extra formats", as you mentioned. ( " ... We do have some previously created formats available for download ... ").
      If so, then I find your Java decompiler formats extremely important.
      (4) I did a quick peek-under-the-covers, and here is what I can see, without going to too much effort.
      Perhaps others are also interested.
      ---------------
      BeyondCompare >> Tools >> File Formats

      ###############################################
      (1) Name: Java Class to Source
      ###############################################
      Mask: *.class
      Description:
      {
      - Compares Java class files decompiled to source.
      - Uses Java decompiler, Jad:
      http://www.kpdus.com/jad.html
      }
      Tab:Coversion/Loading: Helpers\Java\CLASS_to_JAVA.bat %s %t

      Where: C:\Program Files (x86)\Beyond Compare 3\Helpers\Java\CLASS_to_JAVA.bat"
      {
      Helpers\Java\jad.exe -p %1 > %2
      }

      Tab:Grammar
      {
      Keyword=LOTS_OF_STUFF
      Identifier=LOTS_OF_STUFF
      Number=LOTS_OF_STUFF
      String=LOTS_OF_STUFF
      String=LOTS_OF_STUFF
      Comment=LOTS_OF_STUFF
      Comment=LOTS_OF_STUFF
      Operator=LOTS_OF_STUFF
      }

      ###############################################
      (2) Java Class to Source Tidied
      ###############################################
      Mask: *.class
      Descriptions:
      {
      - Compares Java class files decompiled to tidied source.
      - Uses Java decompiler, Jad: , http://www.kpdus.com/jad.html
      - Uses freeware converter, Jalopy: , http://jalopy.sourceforge.net
      - Requires Java JRE: , http://java.sun.com
      }

      Tab:Conversion/Loading: Helpers\Java\CLASS_to_JAVA_tidied.bat %s %t

      Where: "C:\Program Files (x86)\Beyond Compare 3\Helpers\Java\CLASS_to_JAVA_tidied.bat"
      {
      :GetTempName

      set tmpfile=%TMP%.\JadTidied-%RANDOM%-%TIME:~6,5%.tmp
      if exist "%tmpfile%" goto :GetTempName
      Helpers\Java\jad.exe -p %1 > "%tmpfile%"
      for %%F in (%tmpfile%) do set size=%%~zF
      if /I %size% equ 0 goto :SkipJalopy
      type "%tmpfile%" | java -classpath Helpers\Java\jalopy\lib\getopt.jar;Helpers\Java\ja lopy\lib\jalopy.jar;Helpers\Java\jalopy\lib\jalopy-console.jar;Helpers\Java\jalopy\lib\log4j.jar de.hunsicker.jalopy.plugin.console.ConsolePlugin > %2

      :SkipJalopy
      del "%tmpfile%"


      }

      Comment

      • dr_barnowl
        Expert
        • Apr 2008
        • 71

        #4
        The main problem is that JAD will not decompile newer Java class files.

        There are hacks like a program that "downgrades" the classes so that JAD has an easier time of it, but really, what's needed is a Java decompiler that copes with modern classes.

        This claims to fit the bill :

        http://jd.benow.ca/

        .. but it's not distributable for commercial purposes, and not open-source. Alas, there's no command-line variant that just takes a class file and dumps it to a Java source file - just a monolithic executable and an Eclipse plugin.

        Perhaps Scooter could enter into partnership with this guy and license his software? Wouldn't even mind a small extra license fee to buy this as a plugin for BC.

        Comment

        • dr_barnowl
          Expert
          • Apr 2008
          • 71

          #5
          Slightly more laborious : manual mode

          What this application will do, is open a JAR file and save all the sources as a zip archive.

          So you can use the manual method ...

          * Open a JAR
          * Use the "Save all source" command
          * Do this for another JAR
          * Compare the two ZIP files in BC

          If only you could use this on the command line...

          ... looking at the innards of the Eclipse plugin (which helpfully comes with libraries and source code) it ought to be possible to rig up a command line utility to produce Java output. But because of the licensing, people would have to do this for themselves (at least assemble it themselves like a kit).

          Comment

          • Zoë
            Team Scooter
            • Oct 2007
            • 2666

            #6
            I can't find the work I did on it previously, but the one we'd likely switch to would be the FernFlower decompiler included with IntelliJ. It's open source, can run from the command line, and produces good results. What I remember from testing was that it was substantially slower than JAD though, which is why we haven't pursued it more actively.

            Edit: To clarify, the speed difference was annoying but manageable for a single pair of files, but added up quickly if you did a rules-based comparison of an entire .jar.
            Last edited by Zoë; 21-Jan-2015, 12:39 PM.
            Zoë P Scooter Software

            Comment

            • bluebossa63
              New User
              • Feb 2016
              • 1

              #7
              Support for Java Decompiler supporting Java 8

              I have written an addition to the Java Decompiler JD.
              Please find the ready to use bcpkg formats.

              Comment

              • Crack
                Visitor
                • Jun 2012
                • 7

                #8
                Wow, I was just trying to use JD and found your work. Thanks!

                Comment

                • yunlei
                  New User
                  • Nov 2019
                  • 1

                  #9
                  The following plugin was made based on fernflower.jar.
                  https://github.com/caiyunlei/BeyondC...lugin/releases

                  Comment

                  • typesafe
                    New User
                    • Jan 2020
                    • 1

                    #10
                    There is also a way to use FernFlower decompiler online at http://www.decompiler.com/
                    Last edited by typesafe; 14-Jan-2020, 09:34 AM.

                    Comment

                    • Crack
                      Visitor
                      • Jun 2012
                      • 7

                      #11
                      You can also use Fernflower by writing a simple wrapper. I'd like to improve upon it a bit, but probably won't find motivation as this works for me.

                      Script below requires you to get IntelliJ IDEA or compile it yourself (https://github.com/JetBrains/intelli...ompiler/engine), and adjust paths to match your system:
                      Code:
                      @echo off
                      
                      set JAVA_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\jbr
                      set FERNFLOWER_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 2022.1.1\plugins\java-decompiler\lib
                      
                      set CLASS_NAME=%~n1
                      set JAVA_FILE=%CLASS_NAME%.java
                      
                      echo [%DATE% %TIME%] decompile '%1' to '%2' > decompile.log
                      echo [%DATE% %TIME%] expecting .java file '%JAVA_FILE%' >> decompile.log
                      
                      echo [%DATE% %TIME%] "%JAVA_HOME%\bin\java" -cp "%FERNFLOWER_HOME%\java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler "%1" . >> decompile.log
                      "%JAVA_HOME%\bin\java" -cp "%FERNFLOWER_HOME%\java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler "%1" . 2>> decompile.log
                      if %errorlevel% == 0 (
                        move /y "%JAVA_FILE%" "%2" >> decompile.log
                      ) else (
                        set EL=%errorlevel%
                        echo "Failed (%EL%)"
                        copy /y decompile.log "%2"
                        exit /b %EL%
                      )
                      Save to eg. class_to_java.cmd, and add as en external conversion program, calling it as "class_to_java.cmd %s %t".

                      Comment

                      Working...