Java 如何反编译整个Jar文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/647116/
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 17:21:34  来源:igfitidea点击:

How to decompile a whole Jar file?

javajardecompiler

提问by StoneHeart

Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class

有谁知道可以反编译整个 Jar 文件而不是单个类的免费反编译器?我有像 name$1.class name$2.class name.class 这样的子类的问题

采纳答案by VonC

2009: JavaDecompilercan do a good job with a jar: since 0.2.5, All files, in JAR files, are displayed.

2009 年:JavaDecompiler可以很好地使用 jar:从 0.2.5 开始,显示 JAR 文件中的所有文件。

http://java.decompiler.free.fr/sites/default/screenshots/screenshot1.png

http://java.decompiler.free.fr/sites/default/screenshots/screenshot1.png

See also the question "How do I “decompile” Java class files?".

另请参阅问题“如何“反编译”Java 类文件?.

The JD-Eclipse doesn't seem to have changed since late 2009 though (see Changes).
So its integration with latest Eclipse (3.8, 4.2+) might be problematic.

不过,JD-Eclipse 自 2009 年末以来似乎没有改变(请参阅Changes)。
因此,它与最新的 Eclipse(3.8、4.2+)的集成可能会出现问题。

JD-Core is actively maintained.

JD-Core 正在积极维护。

Both are the result of the fantastic work of (SO user) Emmanuel Dupuy.

两者都是(SO 用户)Emmanuel Dupuy出色工作的结果。



2018: A more modern option, mentioned in the commentsby David Kennedy Araujo:

2018:一个更现代的选项,提到在评论大卫·肯尼迪阿劳霍

JetBrains/intellij-community/plugins/java-decompiler/engine

JetBrains/intellij-community/plugins/java-decompiler/engine

Fernflower is the first actually working analytical decompiler for Java and probably for a high-level programming language in general.

java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>

java -jar fernflower.jar -hes=0 -hdc=0 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\

Fernflower 是第一个实际工作的 Java 分析反编译器,一般来说可能是一种高级编程语言。

java -jar fernflower.jar [-<option>=<value>]* [<source>]+ <destination>

java -jar fernflower.jar -hes=0 -hdc=0 c:\Temp\binary\ -e=c:\Java\rt.jar c:\Temp\source\

See also How to decompile to java files intellij ideafor a command working with recent IntelliJ IDEA.

另请参阅如何反编译为 java 文件 intellij idea用于使用最近的 IntelliJ IDEA 的命令。

回答by yanchenko

You extract it and then use jad against the dir.

您提取它,然后对目录使用 jad。

回答by Cadoo

A jar file is just a zip file with jar extension. You should be able to unzip(winzip) a jar just like a zip file.

jar 文件只是一个带有 jar 扩展名的 zip 文件。您应该能够像 zip 文件一样解压缩 (winzip) jar。

回答by Chris R

If you happen to have both a bash shell and jad:

如果您碰巧同时拥有 bash shell 和 jad:

JAR=(your jar file name)
unzip -d $JAR.tmp $JAR
pushd $JAR.tmp
for f in `find . -name '*.class'`; do
    jad -d $(dirname $f) -s java -lnc $f
done
popd

I might be a tiny, tiny bit off with that, but it should work more or less as advertised. You should end up with $JAR.tmpcontaining your decompiled files.

我可能对此有点不以为然,但它应该或多或少像宣传的那样工作。你应该最终$JAR.tmp包含你的反编译文件。

回答by Yuval Adam

First of all, it's worth remembering that all Java archive files (.jar/.war/etc...) are all basically just fancy.zipfiles, with a few added manifests and metadata.

首先,值得记住的是,所有 Java 存档文件 ( .jar/ .war/etc...)基本上都只是花哨的.zip文件,添加了一些清单和元数据。

Second, to tackle this problem I personally use several tools which handle this problem on all levels:

其次,为了解决这个问题,我个人使用了几个工具来处理各个层面的问题:

  • Jad+ Jadclipsewhile working in IDE for decompiling .classfiles
  • WinRAR, my favorite compression tool natively supports Java archives (again, see first paragraph).
  • Beyond Compare, my favorite diff tool, when configured correctly can do on-the-fly comparisons between any archive file, including jars. Well worth a try.
  • Jad+Jadclipse在 IDE 中工作以反编译.class文件
  • WinRAR,我最喜欢的压缩工具本身就支持 Java 档案(再次参见第一段)。
  • Beyond Compare是我最喜欢的 diff 工具,如果配置正确,可以在任何存档文件之间进行即时比较,包括jars。非常值得一试。

The advantage of all the aforementioned, is that I do not need to hold any other external tool which clutters my work environment. Everything I will ever need from one of those files can be handled inside my IDE or diffed with other files natively.

上述所有内容的优点是,我不需要持有任何其他使我的工作环境变得混乱的外部工具。我从这些文件之一中需要的所有内容都可以在我的 IDE 中处理,也可以与其他文件本地进行比较。

回答by Joel S

Note: This solution only works for Mac and *nix users.

注意:此解决方案仅适用于 Mac 和 *nix 用户。

I also tried to find Jad with no luck. My quick solution was to download MacJadthat contains jad. Once you downloaded it you can find jad in [where-you-downloaded-macjad]/MacJAD/Contents/Resources/jad.

我也试图找到杰德,但没有运气。我的快速解决方案是下载包含 jad 的MacJad。下载后,您可以在 [where-you-downloaded-macjad]/MacJAD/Contents/Resources/jad 中找到 jad。

回答by Adam Paynter

I have had reasonable success with a tool named (frustratingly) "JD: Java Decompiler".

我使用名为(令人沮丧的)“ JD:Java Decompiler”的工具取得了合理的成功。

I have found it better than most decompilers when dealing with classes compiled for Java 5 and higher. Unfortunately, it can still have some hiccups where JAD would normally succeed.

在处理为 Java 5 及更高版本编译的类时,我发现它比大多数反编译器更好。不幸的是,它仍然可能会出现一些问题,而 JAD 通常会成功。

回答by cybertoast

Something like:

就像是:

jar -xf foo.jar && find . -iname "*.class" | xargs /opt/local/bin/jad -r

maybe?

也许?

回答by merzod

Insert the following into decompile.jar.sh

在 decompile.jar.sh 中插入以下内容

# Usage: decompile.jar.sh some.jar [-d]

# clean target folders
function clean_target {
  rm -rf $unjar $src $jad_log
}

# clean all debug stuff
function clean_stuff {
  rm -rf $unjar $jad_log
}

# the main function
function work {
  jar=
  unjar=`basename $jar.unjar`
  src=`basename $jar.src`
  jad_log=jad.log

  clean_target

  unzip -q $jar -d $unjar
  jad -d $src -ff -r -lnc -o -s java $unjar/**/*.class > $jad_log 2>&1

  if [ ! $debug ]; then
    clean_stuff
  fi

  if [ -d $src ] 
    then
      echo "$jar has been decompiled to $src"
    else
      echo "Got some problems check output or run in debug mode"
  fi
}

function usage {
  echo "This script extract and decompile JAR file"
  echo "Usage: ##代码## some.jar [-d]"
  echo "    where: some.jar is the target to decompile"
  echo "    use -d for debug mode"
}

# check params
if [ -n "" ]
  then
    if [ "" == "-d" ]; then
      debug=true
      set -x
    fi
    work 
  else
    usage
fi
  • chmod +x decomplie.jar.sh //executable
  • ln -s ./decomplie.jar.s /usr/bin/dj
  • chmod +x decomplie.jar.sh //可执行
  • ln -s ./decomplie.jar.s /usr/bin/dj

Ready to use, just type dj your.jarand you will get your.jar.srcfolder with sources. Use -doption for debug mode.

准备使用,只需键入dj your.jar,您将获得your.jar.src包含源的文件夹。使用-d调试模式选项。