0%

Ubuntu下反编译JAR包获取源代码包

有诸多候选工具:JAD,JD-GUI,FernFlower,Procyon,Krakatau等[1]。FernFlower是自Intellij Idea 14以后版本的默认反编译工具,因此作者选择FernFlower作为完成本文任务的工具。

一、获取工具

有两种途径获取工具。需要注意的是,通过两种途径获取到的工具基于相同主线源代码。

1.1、途径1

在Intellij Idea安装目录的“plugins/java-decompiler/lib”子路径下,获取“java-decompiler.jar”JAR包,该JAR包就是FernFlower工具包。

1.2、途径2

这里获取FernFlower工具包的源代码,自行编译,获取得到的JAR包名称为“fernflower.jar”。

二、使用工具

这里给出了工具使用说明,由于通过两种途径获取到的工具基于相同主线源代码,因此,工具使用说明也是通用的。
结合[3][4][5],最终工具使用脚本如下:

1
2
3
4
5
6
7
8
#!/bin/bash

Jar=java-decompiler.jar
#Jar=fernflower.jar
ToDecompileJar=$1
TargetDir=$2

java -cp $Jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -hdc=0 -dgs=1 -rsy=1 -rbr=1 -lit=1 -nls=1 -mpm=60 $ToDecompileJar $TargetDir

参考文献: [1]https://reverseengineering.stackexchange.com/questions/1370/what-is-a-good-java-decompiler-and-deobfuscator [2]https://github.com/fesh0r/fernflower [3]https://gist.github.com/mslinn/0e6fe9a2504a54e74e8c [4]https://stackoverflow.com/questions/28389006/how-to-decompile-to-java-files-intellij-idea [5]https://github.com/JetBrains/intellij-community/blob/master/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.kt
您的支持将鼓励我继续分享!