如何反编译为java文件intellij idea

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28389006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:08:20  来源:igfitidea点击:

How to decompile to java files intellij idea

javaintellij-ideajava-8decompiling

提问by

IDEA has a great built-in feature - decompiler. It works great.I can copy source code, but I cannot find option to extract all decompiled java classes to java files.
This project has a lot of java classes and packages, so I will be to long to copy this manually.
Does anyone know how to extract to java source files. Thx

IDEA 有一个很棒的内置功能——反编译器。它工作得很好。我可以复制源代码,但我找不到将所有反编译的 java 类提取到 java 文件的选项。
这个项目有很多 java 类和包,所以我会很长时间手动复制它。
有谁知道如何提取到java源文件。谢谢

采纳答案by nicordesigns

To use the IntelliJ Java decompiler from the command line for a jar package follow the instructions provided here: https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine

要从命令行为 jar 包使用 IntelliJ Java 反编译器,请按照此处提供的说明进行操作:https: //github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine

回答by Mike Nakis

The decompiler of IntelliJ IDEA was not built with this kind of usage in mind. It is only meant to help programmers peek at the bytecode of the java classes that they are developing. For decompiling lots of class files of which you do not have source code, you will need some other java decompiler, which is specialized for this job, and most likely runs standalone. If you google you should find a bunch.

IntelliJ IDEA 的反编译器并没有考虑到这种用法。它只是为了帮助程序员查看他们正在开发的 Java 类的字节码。要反编译许多没有源代码的类文件,您将需要一些其他的 Java 反编译器,它专门用于这项工作,并且很可能独立运行。如果你谷歌你应该找到一堆。

回答by theadam

Some time ago I used JAD (JAva Decompiler) to achieve this - I do not think IntelliJ's decompiler was incorporated with exporting in mind. It is more of a tool to help look through classes where sources are not available.

前段时间我使用 JAD (JAva Decompiler) 来实现这一点——我认为 IntelliJ 的反编译器并没有考虑到导出。它更像是一种工具,可以帮助查看源不可用的类。

JAD is still available for download, but I do not think anyone maintains it anymore: http://varaneckas.com/jad/

JAD 仍然可以下载,但我认为没有人再维护它了:http: //varaneckas.com/jad/

There were numerous plugins for it, namely Jadclipse (you guessed it, a way to use JAD in Eclipse - see decompiled classes where code is not available :)).

它有许多插件,即 Jadclipse(您猜对了,这是一种在 Eclipse 中使用 JAD 的方法 - 请参阅代码不可用的反编译类:))。

回答by Bluexin

You could use one of these (you can both use them online or download them, there is some info about each of them) : http://www.javadecompilers.com/

您可以使用其中之一(您可以在线使用它们或下载它们,每个都有一些信息):http: //www.javadecompilers.com/

The one IntelliJ IDEA uses is fernflower, but it can't handle recent things - like String/Enum switches, generics (didn't test this one personally, only read about it), ... I just tried cfr from the above website and the result was the same as with the built-in decompiler (except for the Enum switch I had in my class).

IntelliJ IDEA 使用的一种是 fernflower,但它无法处理最近的事情 - 比如 String/Enum 开关、泛型(没有亲自测试过这个,只是阅读了它),......我刚刚从上面的网站上尝试了 cfr结果与内置反编译器相同(除了我在课堂上的 Enum 开关)。

回答by naXa

Follow instructions for IntelliJ JD plugin. Or see an excerpt from the instructions below.

按照IntelliJ JD 插件的说明进行操作。或查看以下说明的摘录。

java -jar fernflower.jar [<source>]+ <destination>

+means 1 or more times
<source>: file or directory with files to be decompiled. Directories are recursively scanned. Allowed file extensions are class, zip and jar.
<destination>: destination directory

+表示 1 次或多次
<source>:要反编译的文件或目录。目录被递归扫描。允许的文件扩展名是 class、zip 和 jar。
<destination>: 目标目录

Example:

例子:

java -jar fernflower.jar -hdc=0 -dgs=1 -rsy=1 -lit=1 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\

Be aware that if you pass it a ".jar" file for the source, it will create another ".jar" file in the destination, however, within the new ".jar" file, the files will be .java instead of .class files (it doesn't explode the jar).

请注意,如果您将源的“.jar”文件传递给它,它将在目标中创建另一个“.jar”文件,但是,在新的“.jar”文件中,文件将是 .java 而不是 .类文件(它不会爆炸 jar)。



UPDATE

更新

People ask me: How do I get the fernflower.jar?

人们问我:我如何获得 fernflower.jar?

If you have any IntelliJ product installed, chances are that you already have the Fernflower decompiler on your computer. IntelliJ IDEA comes with Java Bytecode Decompilerplugin (bundled) which is a modern extension of Fernflower.

如果您安装了任何 IntelliJ 产品,很可能您的计算机上已经安装了 Fernflower 反编译器。IntelliJ IDEA 附带Java 字节码反编译器插件(捆绑),它是 Fernflower 的现代扩展。

  1. Locate the file in ${IntelliJ_INSTALL_DIR}\plugins\java-decompiler\lib\java-decompiler.jar(example: C:\Program Files\JetBrains\IntelliJ IDEA 2018\plugins\java-decompiler\lib).
  2. Copy it somewhere and rename to fernflower.jar (optional).
  3. This JAR is not executable, so we can't run it using java -jar. However something like this works:

    java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler [<source>]+ <destination>
    

    org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompileris the class that contains the main method to run the decompiler.

    Example:

    mkdir output_src
    java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -hdc=0 -dgs=1 -rsy=1 -lit=1 ./input.jar ./output_src
    
  1. ${IntelliJ_INSTALL_DIR}\plugins\java-decompiler\lib\java-decompiler.jar(例如:C:\Program Files\JetBrains\IntelliJ IDEA 2018\plugins\java-decompiler\lib)中找到该文件。
  2. 将它复制到某个地方并重命名为 fernflower.jar(可选)。
  3. 此 JAR 不可执行,因此我们无法使用java -jar. 然而,像这样的工作:

    java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler [<source>]+ <destination>
    

    org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler是包含运行反编译器的主要方法的类。

    例子:

    mkdir output_src
    java -cp fernflower.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -hdc=0 -dgs=1 -rsy=1 -lit=1 ./input.jar ./output_src
    

If you don't have IntelliJ products installed, either download it now (available on jetbrains.com) or make your own decompiler executable from sources (available on Github).

如果您没有安装 IntelliJ 产品,请立即下载(可在jetbrains.com获得)或从源代码(可在Github获得)制作您自己的反编译器可执行文件。

回答by yan

As of August 2017 and IntelliJ V2017.2, the accepted answer does not seem to be entirely accurate anymore: there is no fernflower.jarto use.

截至 2017 年 8 月和 IntelliJ V2017.2,接受的答案似乎不再完全准确:没有fernflower.jar使用。

The jar file is called java-decompiler.jarand does not include a main manifest... Instead you can use the following command (from a Mac install):

jar 文件被调用java-decompiler.jar并且不包含主清单......相反,您可以使用以下命令(来自 Mac 安装):

java -cp "/Applications/IntelliJ IDEA.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler

(you will get the wrong Usagecommand, but it does work).

(你会得到错误的Usage命令,但它确实有效)。

回答by Prasobh.Kollattu

Try

尝试

https://github.com/fesh0r/fernflower

https://github.com/fesh0r/fernflower

Download jar from

从 jar 下载

http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/

http://files.minecraftforge.net/maven/net/minecraftforge/fernflower/

Command :

命令 :

java -jar fernflower.jar -hes=0 -hdc=0 C:\binary  C:\source

Place your jar file in folder C:\binary and source will be extracted and packed in a jar inside C:\source.

将您的 jar 文件放在文件夹 C:\binary 中,源代码将被提取并打包在 C:\source 中的一个 jar 中。

Enjoy!

享受!

回答by tecdoc ukr net

I use JD-GUI for extract all decompiled java classes to java files.

我使用 JD-GUI 将所有反编译的 java 类提取到 java 文件。

回答by Victor Choy

Someone had gave good answers. I made another instruction clue step by step. First, open your studio and search. You can find the decompier is Fernflower.

有人给出了很好的答案。我一步一步地制作了另一个指令线索。首先,打开你的工作室并搜索。你可以找到反编译器是 Fernflower。

enter image description here

在此处输入图片说明

Second, we can find it in the plugins directory.

其次,我们可以在 plugins 目录中找到它。

/Applications/Android Studio.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar

Third, run it, you will get the usage

三、运行它,你会得到用法

java -cp "/Applications/Android Studio.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler

Usage: java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>
Example: java -jar fernflower.jar -dgs=true c:\my\source\ c:\my.jar d:\decompiled\

Finally, The studio's nest options for decompiler list as follows according IdeaDecompiler.kt

最后,根据IdeaDecompiler.kt,工作室的反编译器嵌套选项列表如下

-hdc=0 -dgs=1 -rsy=1 -rbr=1 -lit=1 -nls=1 -mpm=60 -lac=1

-hdc=0 -dgs=1 -rsy=1 -rbr=1 -lit=1 -nls=1 -mpm=60 -lac=1

IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR to "0",
        IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES to "1",
        IFernflowerPreferences.REMOVE_SYNTHETIC to "1",
        IFernflowerPreferences.REMOVE_BRIDGE to "1",
        IFernflowerPreferences.LITERALS_AS_IS to "1",
        IFernflowerPreferences.NEW_LINE_SEPARATOR to "1",
        **IFernflowerPreferences.BANNER to BANNER,**
        IFernflowerPreferences.MAX_PROCESSING_METHOD to 60,
        **IFernflowerPreferences.INDENT_STRING to indent,**
        **IFernflowerPreferences.IGNORE_INVALID_BYTECODE to "1",**
        IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES to "1",
         **IFernflowerPreferences.UNIT_TEST_MODE to if (ApplicationManager.getApplication().isUnitTestMode) "1" else "0")**

I cant find the sutialbe option for the asterisk items.

我找不到星号项目的 sutialbe 选项。

Hope these steps will make the question clear.

希望这些步骤能让问题变得清晰。