将Java代码进行反编译
环境是Ubuntu 16.04。
因为10年前创建的 classfile 源代码已经丢失了,所以需要对其进行反编译。
您好
「使用Jad工具反编译class文件」
我要试着看看。
Jad 1.5.8e for Linux on Intel platform (214917 bytes).
Jad 1.5.8e for Linux (statically linked) (389972 bytes) - take this version if the one above crashes or displays the "seek error" message.
下载并运行上面的东西
./jad: error while loading shared libraries: libstdc++-libc6.2-2.so.3: cannot open shared object file: No such file or directory
因为这样,下载并运行下方的内容。尝试将../PDFConverter.class反编译。
$ ./jad ../PDFConverter.class
Parsing ../PDFConverter.class...The class file version is 49.0 (only 45.3, 46.0 and 47.0 are supported)
Generating PDFConverter.jad
Overlapped try statements detected. Not all exception handlers will be resolved in the method main
Couldn't fully decompile method main
Couldn't resolve all exception handlers in method main
唉,看起来只支持45.3、46.0和47.0版本。我一直觉得不太对劲,结果发现有一个名为PDFConverter.jad的文件生成了。
$ head -30 PDFConverter.jad
// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3)
// Source File Name: PDFConverter.java
import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XCloseable;
import java.io.File;
public class PDFConverter
{
public PDFConverter()
{
}
public static void main(String args[])
{
String s = convertToURL(args[0]);
String s1 = getFilterName(args[0]);
String s2 = s.replaceAll("\\..{3}\\Z", ".pdf");
XComponentContext xcomponentcontext = Bootstrap.bootstrap();
XMultiComponentFactory xmulticomponentfactory = xcomponentcontext.getServiceManager();
京东-Java反编译器
可以从这个网址下载:http://jd.benow.ca/
因为屏幕截图是Windows的,所以我有一种不好的预感,但是多平台让我感到安心。我要下载 jd-gui_1.4.0-0_all.deb。
$ sudo dpkg -i jd-gui_1.4.0-0_all.deb
[sudo] nanbuwks のパスワード:
以前に未選択のパッケージ jd-gui を選択しています。
(データベースを読み込んでいます ... 現在 793826 個のファイルとディレクトリがインストールされています。)
jd-gui_1.4.0-0_all.deb を展開する準備をしています ...
jd-gui (1.4.0-0) を展開しています...
jd-gui (1.4.0-0) を設定しています ...
使用Unity的Dash调用JD-GUI并执行
事情进展得不错。
在中文中,只需要一個選項就可以解釋這個詞,就是「对比」。
$ diff PDFConverter.jad ../PDFConverter-jdgui.java
1,5d0
< // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
< // Jad home page: http://www.geocities.com/kpdus/jad.html
< // Decompiler options: packimports(3)
< // Source File Name: PDFConverter.java
<
19,20c14,16
<
< public PDFConverter()
---
> public static void main(String[] paramArrayOfString)
> {
> try
21a18,61
> String str1 = convertToURL(paramArrayOfString[0]);
> String str2 = getFilterName(paramArrayOfString[0]);
> String str3 = str1.replaceAll("\\..{3}\\Z", ".pdf");
>
> XComponentContext localXComponentContext = Bootstrap.bootstrap();
> XMultiComponentFactory localXMultiComponentFactory = localXComponentContext.getServiceManager();
>
> Object localObject1 = localXMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", localXComponentContext);
>
> XComponentLoader localXComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class, localObject1);
>
> PropertyValue[] arrayOfPropertyValue = new PropertyValue[2];
>
> arrayOfPropertyValue[0] = new PropertyValue();
> arrayOfPropertyValue[0].Name = "Hidden";
> arrayOfPropertyValue[0].Value = new Boolean(true);
> arrayOfPropertyValue[1] = new PropertyValue();
> arrayOfPropertyValue[1].Name = "ReadOnly";
> arrayOfPropertyValue[1].Value = new Boolean(true);
>
> XComponent localXComponent1 = localXComponentLoader.loadComponentFromURL(str1, "_blank", 0, arrayOfPropertyValue);
>
> arrayOfPropertyValue[0] = new PropertyValue();
> arrayOfPropertyValue[0].Name = "FilterName";
> arrayOfPropertyValue[0].Value = str2;
> arrayOfPropertyValue[1] = new PropertyValue();
> arrayOfPropertyValue[1].Name = "Overwrite";
> arrayOfPropertyValue[1].Value = new Boolean(true);
>
> XStorable localXStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, localXComponent1);
>
> localXStorable.storeToURL(str3, arrayOfPropertyValue);
>
> XCloseable localXCloseable = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, localXStorable);
> if (localXCloseable != null)
> {
> localXCloseable.close(false);
> }
> else
> {
> XComponent localXComponent2 = (XComponent)UnoRuntime.queryInterface(XComponent.class, localXStorable);
>
> localXComponent2.dispose();
> }
23,24c63
<
< public static void main(String args[])
---
> catch (Exception localException)
26,69c65,66
< String s = convertToURL(args[0]);
< String s1 = getFilterName(args[0]);
< String s2 = s.replaceAll("\\..{3}\\Z", ".pdf");
< XComponentContext xcomponentcontext = Bootstrap.bootstrap();
< XMultiComponentFactory xmulticomponentfactory = xcomponentcontext.getServiceManager();
< Object obj = xmulticomponentfactory.createInstanceWithContext("com.sun.star.frame.Desktop", xcomponentcontext);
< XComponentLoader xcomponentloader = (XComponentLoader)UnoRuntime.queryInterface(com/sun/star/frame/XComponentLoader, obj);
< PropertyValue apropertyvalue[] = new PropertyValue[2];
< apropertyvalue[0] = new PropertyValue();
< apropertyvalue[0].Name = "Hidden";
< apropertyvalue[0].Value = new Boolean(true);
< apropertyvalue[1] = new PropertyValue();
< apropertyvalue[1].Name = "ReadOnly";
< apropertyvalue[1].Value = new Boolean(true);
< XComponent xcomponent = xcomponentloader.loadComponentFromURL(s, "_blank", 0, apropertyvalue);
< apropertyvalue[0] = new PropertyValue();
< apropertyvalue[0].Name = "FilterName";
< apropertyvalue[0].Value = s1;
< apropertyvalue[1] = new PropertyValue();
< apropertyvalue[1].Name = "Overwrite";
< apropertyvalue[1].Value = new Boolean(true);
< XStorable xstorable = (XStorable)UnoRuntime.queryInterface(com/sun/star/frame/XStorable, xcomponent);
< xstorable.storeToURL(s2, apropertyvalue);
< XCloseable xcloseable = (XCloseable)UnoRuntime.queryInterface(com/sun/star/util/XCloseable, xstorable);
< if(xcloseable != null)
< {
< xcloseable.close(false);
< } else
< {
< XComponent xcomponent1 = (XComponent)UnoRuntime.queryInterface(com/sun/star/lang/XComponent, xstorable);
< xcomponent1.dispose();
< }
< System.exit(0);
< break MISSING_BLOCK_LABEL_321;
< Exception exception;
< exception;
< exception.printStackTrace();
< System.exit(1);
< System.exit(0);
< break MISSING_BLOCK_LABEL_321;
< Exception exception1;
< exception1;
< System.exit(0);
< throw exception1;
---
> localException.printStackTrace();
> System.exit(1);
71,73c68
<
< private static String convertToURL(String s)
< throws Exception
---
> finally
75,78c70
< File file = new File(s);
< StringBuffer stringbuffer = new StringBuffer("file:///");
< stringbuffer.append(file.getCanonicalPath().replace('\\', '/'));
< return stringbuffer.toString();
---
> System.exit(0);
80,99c72,97
<
< private static String getFilterName(String s)
< throws Exception
< {
< String s1 = s.substring(s.length() - 4).toLowerCase();
< String s2 = "";
< if(s1.equals(".doc") || s1.equals(".dot") || s1.equals(".sxw") || s1.equals(".stw") || s1.equals(".odt") || s1.equals(".ott"))
< s2 = "writer_pdf_Export";
< else
< if(s1.equals(".xls") || s1.equals(".xlt") || s1.equals(".sxc") || s1.equals(".stc") || s1.equals(".ods") || s1.equals(".ots"))
< s2 = "calc_pdf_Export";
< else
< if(s1.equals(".ppt") || s1.equals(".pot") || s1.equals(".sxi") || s1.equals(".sti") || s1.equals(".odp") || s1.equals(".otp"))
< s2 = "impress_pdf_Export";
< else
< if(s1.equals(".sxd") || s1.equals(".std") || s1.equals(".odg") || s1.equals(".otg"))
< s2 = "draw_pdf_Export";
< else
< throw new Exception("There is no corresponding filter.");
< return s2;
---
> }
>
> private static String convertToURL(String paramString)
> throws Exception
> {
> File localFile = new File(paramString);
> StringBuffer localStringBuffer = new StringBuffer("file:///");
> localStringBuffer.append(localFile.getCanonicalPath().replace('\\', '/'));
> return localStringBuffer.toString();
> }
>
> private static String getFilterName(String paramString)
> throws Exception
> {
> String str1 = paramString.substring(paramString.length() - 4).toLowerCase();
> String str2 = "";
> if ((str1.equals(".doc")) || (str1.equals(".dot")) || (str1.equals(".sxw")) || (str1.equals(".stw")) || (str1.equals(".odt")) || (str1.equals(".ott"))) {
> str2 = "writer_pdf_Export";
> } else if ((str1.equals(".xls")) || (str1.equals(".xlt")) || (str1.equals(".sxc")) || (str1.equals(".stc")) || (str1.equals(".ods")) || (str1.equals(".ots"))) {
> str2 = "calc_pdf_Export";
> } else if ((str1.equals(".ppt")) || (str1.equals(".pot")) || (str1.equals(".sxi")) || (str1.equals(".sti")) || (str1.equals(".odp")) || (str1.equals(".otp"))) {
> str2 = "impress_pdf_Export";
> } else if ((str1.equals(".sxd")) || (str1.equals(".std")) || (str1.equals(".odg")) || (str1.equals(".otg"))) {
> str2 = "draw_pdf_Export";
> } else {
> throw new Exception("There is no corresponding filter.");
100a99,100
> return str2;
> }