【发布时间】:2014-06-06 17:27:32
【问题描述】:
我目前正在从事一个项目,该项目要求我以编程方式将 .class 文件反编译为 java 文件。 IE。我有一个程序应该读取一个类文件并对其进行反编译,然后将生成的 java 源代码写入一个文件。请帮我做。
编辑:
我对反编译器的世界完全陌生。我已经使用了一些 API,但我不知道如何使用以及使用哪一个。任何形式的帮助都会非常显着
编辑:
我尝试使用:
import com.strobel.decompiler.*;
import java.io.*;
public class JavaDecode {
public static void main(String[] args)throws Exception {
decompileee();
}
private static void decompileee()throws Exception
{
final DecompilerSettings settings = DecompilerSettings.javaDefaults();
final FileOutputStream stream = new FileOutputStream("C:/jp/decompiled.java");
final OutputStreamWriter writer = new OutputStreamWriter(stream);
Decompiler.decompile("C:/jp/X.class",
new PlainTextOutput(writer),
settings
);
System.out.println("Success");
}
}
但上面的代码只是在指定目录下创建了一个名为“decompiled.java”的文件。但该文件是一个空文件。
【问题讨论】:
-
没有足够的信息让我们能够为您提供帮助。你试过什么程序?你是如何尝试的?你期待什么结果?你得到了什么结果?
-
这绝非易事——您应该找到一个现有的开源反编译器并使用代码。
标签: java decompiler