Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompile .class files to .java source code using java libraries

I am working on project of java that needs to decompile .class file to source code, I've found many ways such as such as JAD decompiler and 'javap -p' method... , but I think these methods are cannot be done programatically (please tell if can), Is there any way to done this programatically, It would be appreciated if you show me any Libraries.

like image 630
droidev Avatar asked Feb 28 '14 04:02

droidev


1 Answers

Procyon is a Java decompiler written in Java, and it can be called directly from Java code. For example:

final PrintWriter writer = new PrintWriter(System.out);

try {
    com.strobel.decompiler.Decompiler.decompile(
        "W:\\Hello.class",
        new com.strobel.decompiler.PlainTextOutput(writer)
    );
}
finally {
    writer.flush();
}

There is also a decompile() overload that accepts a DecompilerSettings instance, which you can use to toggle certain features and give the decompiler hints on how to resolve class dependencies. Feel free to contact me on BitBucket with any questions.

like image 155
Mike Strobel Avatar answered Oct 03 '22 09:10

Mike Strobel