mirror of
https://github.com/revanced/Apktool.git
synced 2025-06-12 21:27:36 +02:00
cleanup of various functions
Removed attr sorting that was never enabled and never worked, added @todo elements for unknown file handling, updated usage output
This commit is contained in:
@ -47,17 +47,17 @@ import org.jf.util.ConsoleUtil;
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException,
|
||||
InterruptedException, BrutException {
|
||||
|
||||
|
||||
// set verbosity default
|
||||
Verbosity verbosity = Verbosity.NORMAL;
|
||||
|
||||
|
||||
// cli parser
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLine commandLine = null;
|
||||
|
||||
|
||||
// load options
|
||||
_Options();
|
||||
|
||||
|
||||
try {
|
||||
commandLine = parser.parse(allOptions, args, false);
|
||||
} catch (ParseException ex) {
|
||||
@ -65,7 +65,7 @@ public class Main {
|
||||
usage(commandLine);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check for verbose / quiet
|
||||
if (commandLine.hasOption("-v") || commandLine.hasOption("--verbose")) {
|
||||
verbosity = Verbosity.VERBOSE;
|
||||
@ -73,7 +73,7 @@ public class Main {
|
||||
verbosity = Verbosity.QUIET;
|
||||
}
|
||||
setupLogging(verbosity);
|
||||
|
||||
|
||||
// check for advance mode
|
||||
if (commandLine.hasOption("advance") || commandLine.hasOption("advanced")) {
|
||||
setAdvanceMode(true);
|
||||
@ -81,7 +81,7 @@ public class Main {
|
||||
|
||||
// @todo use new ability of apache-commons-cli to check hasOption for non-prefixed items
|
||||
boolean cmdFound = false;
|
||||
for (String opt : commandLine.getArgs()) {
|
||||
for (String opt : commandLine.getArgs()) {
|
||||
if (opt.equalsIgnoreCase("d") || opt.equalsIgnoreCase("decode")) {
|
||||
cmdDecode(commandLine);
|
||||
cmdFound = true;
|
||||
@ -96,7 +96,7 @@ public class Main {
|
||||
cmdFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if no commands ran, run the version / usage check.
|
||||
if (cmdFound == false) {
|
||||
if (commandLine.hasOption("version") || commandLine.hasOption("version")) {
|
||||
@ -109,11 +109,11 @@ public class Main {
|
||||
|
||||
private static void cmdDecode(CommandLine cli) throws AndrolibException {
|
||||
ApkDecoder decoder = new ApkDecoder();
|
||||
|
||||
|
||||
int paraCount = cli.getArgList().size();
|
||||
String apkName = (String) cli.getArgList().get(paraCount - 1);
|
||||
File outDir = null;
|
||||
|
||||
|
||||
// check for options
|
||||
if (cli.hasOption("s") || cli.hasOption("no-src")) {
|
||||
decoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_NONE);
|
||||
@ -142,18 +142,18 @@ public class Main {
|
||||
if (cli.hasOption("o") || cli.hasOption("output")) {
|
||||
decoder.setOutDir(new File(cli.getOptionValue("o")));
|
||||
} else {
|
||||
|
||||
|
||||
// make out folder manually using name of apk
|
||||
String outName = apkName;
|
||||
outName = outName.endsWith(".apk") ? outName.substring(0,
|
||||
outName.length() - 4) : outName + ".out";
|
||||
|
||||
|
||||
// make file from path
|
||||
outName = new File(outName).getName();
|
||||
outDir = new File(outName);
|
||||
decoder.setOutDir(outDir);
|
||||
}
|
||||
|
||||
|
||||
decoder.setApkFile(new File(apkName));
|
||||
|
||||
try {
|
||||
@ -189,7 +189,7 @@ public class Main {
|
||||
String appDirName = ".";
|
||||
File outFile = null;
|
||||
Androlib instance = new Androlib();
|
||||
|
||||
|
||||
// hold all the fields
|
||||
HashMap<String, Boolean> flags = new HashMap<String, Boolean>();
|
||||
flags.put("forceBuildAll", false);
|
||||
@ -223,11 +223,11 @@ public class Main {
|
||||
} else {
|
||||
outFile = null;
|
||||
}
|
||||
|
||||
|
||||
if (apkName != null) {
|
||||
appDirName = apkName;
|
||||
}
|
||||
|
||||
|
||||
// try and build apk
|
||||
instance.build(new File(appDirName), outFile, flags,mAaptPath);
|
||||
}
|
||||
@ -238,7 +238,7 @@ public class Main {
|
||||
String apkName = (String) cli.getArgList().get(paraCount - 1);
|
||||
String tag = null;
|
||||
String frame_path = null;
|
||||
|
||||
|
||||
if (cli.hasOption("p") || cli.hasOption("frame-path")) {
|
||||
frame_path = cli.getOptionValue("p");
|
||||
}
|
||||
@ -262,112 +262,112 @@ public class Main {
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
private static void _Options() {
|
||||
|
||||
|
||||
// create options
|
||||
Option versionOption = OptionBuilder.withLongOpt("version")
|
||||
.withDescription("prints the version then exits")
|
||||
.create("version");
|
||||
|
||||
|
||||
Option advanceOption = OptionBuilder.withLongOpt("advanced")
|
||||
.withDescription("prints advance information.")
|
||||
.create("advance");
|
||||
|
||||
|
||||
Option noSrcOption = OptionBuilder.withLongOpt("no-src")
|
||||
.withDescription("Do not decode sources.")
|
||||
.create("s");
|
||||
|
||||
|
||||
Option noResOption = OptionBuilder.withLongOpt("no-res")
|
||||
.withDescription("Do not decode resources.")
|
||||
.create("r");
|
||||
|
||||
|
||||
Option debugDecOption = OptionBuilder.withLongOpt("debug")
|
||||
.withDescription("Decode in debug mode. Check project page for more info.")
|
||||
.create("d");
|
||||
|
||||
|
||||
Option debugBuiOption = OptionBuilder.withLongOpt("debug")
|
||||
.withDescription("Builds in debug mode. Check project page for more info.")
|
||||
.create("d");
|
||||
|
||||
|
||||
Option noDbgOption = OptionBuilder.withLongOpt("no-debug-info")
|
||||
.withDescription("don't write out debug info (.local, .param, .line, etc.)")
|
||||
.create("b");
|
||||
|
||||
|
||||
Option forceDecOption = OptionBuilder.withLongOpt("force")
|
||||
.withDescription("Force delete destination directory.")
|
||||
.create("f");
|
||||
|
||||
|
||||
Option frameTagOption = OptionBuilder.withLongOpt("frame-tag")
|
||||
.withDescription("Uses framework files tagged by <tag>.")
|
||||
.hasArg(true)
|
||||
.withArgName("tag")
|
||||
.create("t");
|
||||
|
||||
|
||||
Option frameDirOption = OptionBuilder.withLongOpt("frame-path")
|
||||
.withDescription("Uses framework files located in <dir>.")
|
||||
.hasArg(true)
|
||||
.withArgName("dir")
|
||||
.create("p");
|
||||
|
||||
|
||||
Option keepResOption = OptionBuilder.withLongOpt("keep-broken-res")
|
||||
.withDescription("Use if there was an error and some resources were dropped, e.g.\n"
|
||||
+ " \"Invalid config flags detected. Dropping resources\", but you\n"
|
||||
+ " want to decode them anyway, even with errors. You will have to\n"
|
||||
+ " fix them manually before building.")
|
||||
.create("k");
|
||||
|
||||
|
||||
Option forceBuiOption = OptionBuilder.withLongOpt("force-all")
|
||||
.withDescription("Skip changes detection and build all files.")
|
||||
.create("f");
|
||||
|
||||
|
||||
Option aaptOption = OptionBuilder.withLongOpt("aapt")
|
||||
.hasArg(true)
|
||||
.withArgName("loc")
|
||||
.withDescription("Loads aapt from specified location.")
|
||||
.create("a");
|
||||
|
||||
|
||||
Option originalOption = OptionBuilder.withLongOpt("copy-original")
|
||||
.withDescription("Copies original AndroidManifest.xml and META-INF. See project page for more info.")
|
||||
.create("c");
|
||||
|
||||
|
||||
Option tagOption = OptionBuilder.withLongOpt("tag")
|
||||
.withDescription("Tag frameworks using <tag>.")
|
||||
.hasArg(true)
|
||||
.withArgName("tag")
|
||||
.create("t");
|
||||
|
||||
|
||||
Option outputBuiOption = OptionBuilder.withLongOpt("output")
|
||||
.withDescription("The name of apk that gets written. Default is dist/name.apk")
|
||||
.hasArg(true)
|
||||
.withArgName("dir")
|
||||
.create("o");
|
||||
|
||||
|
||||
Option outputDecOption = OptionBuilder.withLongOpt("output")
|
||||
.withDescription("The name of folder that gets written. Default is apk.out")
|
||||
.hasArg(true)
|
||||
.withArgName("dir")
|
||||
.create("o");
|
||||
|
||||
|
||||
Option quietOption = OptionBuilder.withLongOpt("quiet")
|
||||
.create("q");
|
||||
|
||||
|
||||
Option verboseOption = OptionBuilder.withLongOpt("verbose")
|
||||
.create("v");
|
||||
|
||||
|
||||
// check for advance mode
|
||||
if (advanceMode) {
|
||||
DecodeOptions.addOption(debugDecOption);
|
||||
DecodeOptions.addOption(noDbgOption);
|
||||
DecodeOptions.addOption(keepResOption);
|
||||
|
||||
|
||||
BuildOptions.addOption(debugBuiOption);
|
||||
BuildOptions.addOption(aaptOption);
|
||||
BuildOptions.addOption(originalOption);
|
||||
}
|
||||
|
||||
|
||||
// add global options
|
||||
normalOptions.addOption(versionOption);
|
||||
normalOptions.addOption(advanceOption);
|
||||
|
||||
|
||||
// add basic decode options
|
||||
DecodeOptions.addOption(frameTagOption);
|
||||
DecodeOptions.addOption(outputDecOption);
|
||||
@ -375,16 +375,16 @@ public class Main {
|
||||
DecodeOptions.addOption(forceDecOption);
|
||||
DecodeOptions.addOption(noSrcOption);
|
||||
DecodeOptions.addOption(noResOption);
|
||||
|
||||
|
||||
// add basic build options
|
||||
BuildOptions.addOption(outputBuiOption);
|
||||
BuildOptions.addOption(frameDirOption);
|
||||
BuildOptions.addOption(forceBuiOption);
|
||||
|
||||
|
||||
// add basic framework options
|
||||
frameOptions.addOption(tagOption);
|
||||
frameOptions.addOption(frameDirOption);
|
||||
|
||||
|
||||
// add all, loop existing cats then manually add advance
|
||||
for (Object op : normalOptions.getOptions()) {
|
||||
allOptions.addOption((Option)op);
|
||||
@ -415,20 +415,20 @@ public class Main {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void usage(CommandLine commandLine) {
|
||||
|
||||
|
||||
// load basicOptions
|
||||
_Options();
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
|
||||
|
||||
// max their window to 120, if small.
|
||||
int consoleWidth = ConsoleUtil.getConsoleWidth();
|
||||
if (consoleWidth <= 0) {
|
||||
consoleWidth = 120;
|
||||
}
|
||||
formatter.setWidth(consoleWidth);
|
||||
|
||||
|
||||
// print out license info prior to formatter.
|
||||
System.out.println(
|
||||
"Apktool v" + Androlib.getVersion() + " - a tool for reengineering Android apk files\n" +
|
||||
@ -441,19 +441,19 @@ public class Main {
|
||||
}else {
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
|
||||
// 4 usage outputs (general, frameworks, decode, build)
|
||||
formatter.printHelp("apktool " + verbosityHelp(), normalOptions);
|
||||
formatter.printHelp("apktool " + verbosityHelp() + "if|install-framework [options] <framework.apk>", frameOptions);
|
||||
formatter.printHelp("apktool " + verbosityHelp() + "d[ecode] [options] <file_apk>", DecodeOptions);
|
||||
formatter.printHelp("apktool " + verbosityHelp() + "b[uild] [options] <app_path>", BuildOptions);
|
||||
if (advanceMode) {
|
||||
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>",
|
||||
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>",
|
||||
"Make all framework resources public.", emptyOptions, null);
|
||||
} else {
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
|
||||
// print out more information
|
||||
System.out.println(
|
||||
"For additional info, see: http://code.google.com/p/android-apktool/ \n"
|
||||
@ -487,9 +487,9 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAdvanceMode() {
|
||||
return advanceMode;
|
||||
}
|
||||
public static boolean isAdvanceMode() {
|
||||
return advanceMode;
|
||||
}
|
||||
|
||||
public static void setAdvanceMode(boolean advanceMode) {
|
||||
Main.advanceMode = advanceMode;
|
||||
@ -507,7 +507,7 @@ public class Main {
|
||||
private final static Options frameOptions;
|
||||
private final static Options allOptions;
|
||||
private final static Options emptyOptions;
|
||||
|
||||
|
||||
static {
|
||||
//normal and advance usage output
|
||||
normalOptions = new Options();
|
||||
|
Reference in New Issue
Block a user