I’ve been doing some class bytecode stuff lately, trying to decompile class files into Java files. I tried a lot of tools, such as JD-GUI and its plug-ins as well as various online decomcompilations, but I still felt that it was not cool enough. After all, I am a person who relies on terminals, so I tried to find some tools that can realize decomcompilations in terminals.

Google was good, and soon found a tool that I was very happy with.

  • It is a JAR package
  • It’s called CFR(Class File Reader)
  • Decompiling class files and JAR packages is supported

The following describes two common commands

Decompile the class file


12 3 4 5 6 7 8 9 10 11 12 13 14 15Copy the code
Java -jar ~/Documents/scripts/ CFR-0.139. jar JavaTest. Class /* * Decomcompiled with CFR 0.139. */ import java.io.PrintStream; public class JavaTest { public void functionOne() { System.out.println("functionOne"); } public void functionTwo() { System.out.println("functionTwo"); }}Copy the code

Decompile the JAR package


One, two, three, four, five, six, sevenCopy the code
Jar ~/Documents/scripts/cfr-0.139.jar --outputdir/TMP /outputdir Processing org.benf.cfr.reader.api.CfrDriver Processing org.benf.cfr.reader.api.ClassFileSource Processing org.benf.cfr.reader.api.OutputSinkFactory Processing org.benf.cfr.reader.api.SinkReturns Processing org.benf.cfr.reader.bytecode.analysis.opgraph.Graph ...Copy the code

After running the preceding command, you can find the corresponding Java file in the outputdir directory.

Wrapped as script

Decompile a class file


1
2
Copy the code
#! /bin/bash Java -jar ~/Documents/scripts/cfr-0.139.jar $1Copy the code

Decompile a JAR package


1
2
Copy the code
#! /bin/bash Java -jar ~/Documents/scripts/cfr-0.139.jar $1 --outputdir $2Copy the code

resources

  • www.benf.org/other/cfr/i…