package the.bytecode.club.bytecodeviewer;
import java.io.File;
import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.translation.Language;
import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see . *
***************************************************************************/
/**
* Used to allow BCV to be integrated as CLI instead of GUI.
*
* @author Konloch
*/
public class CommandLineInput {
private static final Options options = new Options();
private static final CommandLineParser parser = new DefaultParser();
/*BECAUSE WHO DOESN'T LOVE MAGIC NUMBERS*/
public static int STOP = -1;
public static int GUI = 0;
public static int CLI = 1;
static {
options.addOption("help", false, "prints the help menu.");
options.addOption("list", false, "lists all the available decompilers for BCV " + VERSION + ".");
options.addOption("decompiler", true, "sets the decompiler, procyon by default.");
options.addOption("i", true, "sets the input.");
options.addOption("o", true, "sets the output.");
options.addOption("t", true, "sets the target class to decompile, append all to decomp all as zip.");
options.addOption("nowait", true, "won't wait the 5 seconds to allow the user to read the CLI.");
}
public static boolean containsCommand(String[] args) {
if (args == null || args.length == 0)
return false;
try {
CommandLine cmd = parser.parse(options, args);
if (
cmd.hasOption("help") ||
cmd.hasOption("clean") ||
cmd.hasOption("english") ||
cmd.hasOption("list") ||
cmd.hasOption("decompiler") ||
cmd.hasOption("i") ||
cmd.hasOption("o") ||
cmd.hasOption("t") ||
cmd.hasOption("nowait")
) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static int parseCommandLine(String[] args) {
if (!containsCommand(args))
return GUI;
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("list")) {
System.out.println("Procyon");
System.out.println("CFR");
System.out.println("FernFlower");
System.out.println("Krakatau");
System.out.println("Krakatau-Bytecode");
System.out.println("JD-GUI");
System.out.println("Smali");
return STOP;
} else if (cmd.hasOption("clean")) {
new File(Constants.getBCVDirectory()).delete();
if(cmd.getOptionValue("i") == null && cmd.getOptionValue("o") == null
&& cmd.getOptionValue("t") == null)
return GUI;
} else if (cmd.hasOption("english")) {
Configuration.language = Language.ENGLISH;
return GUI;
} else if (cmd.hasOption("help")) {
for (String s : new String[]{
"-help Displays the help menu",
"-clean Deletes the BCV directory",
"-english Forces English language translations",
"-list Displays the available decompilers",
"-decompiler Selects the decompiler, procyon by default",
"-i Selects the input file",
"-o