Merge branch 'master' of https://github.com/xpirt/Apktool into xpirt-master

This commit is contained in:
Connor Tumbleson 2017-09-01 15:55:52 -04:00
commit f4ae717c96

View File

@ -21,21 +21,13 @@ import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.err.InFileNotFoundException; import brut.androlib.err.InFileNotFoundException;
import brut.androlib.err.OutDirExistsException; import brut.androlib.err.OutDirExistsException;
import brut.common.BrutException; import brut.common.BrutException;
import brut.directory.DirectoryException;
import org.apache.commons.cli.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.*; import java.util.logging.*;
import brut.directory.DirectoryException;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
/** /**
* @author Ryszard Wiśniewski <brut.alll@gmail.com> * @author Ryszard Wiśniewski <brut.alll@gmail.com>
* @author Connor Tumbleson <connor.tumbleson@gmail.com> * @author Connor Tumbleson <connor.tumbleson@gmail.com>
@ -47,7 +39,7 @@ public class Main {
Verbosity verbosity = Verbosity.NORMAL; Verbosity verbosity = Verbosity.NORMAL;
// cli parser // cli parser
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new DefaultParser();
CommandLine commandLine; CommandLine commandLine;
// load options // load options
@ -141,14 +133,13 @@ public class Main {
if (cli.hasOption("m") || cli.hasOption("match-original")) { if (cli.hasOption("m") || cli.hasOption("match-original")) {
decoder.setAnalysisMode(true, false); decoder.setAnalysisMode(true, false);
} }
if (cli.hasOption("api")) { if (cli.hasOption("api") || cli.hasOption("api-level")) {
decoder.setApi(Integer.parseInt(cli.getOptionValue("api"))); decoder.setApi(Integer.parseInt(cli.getOptionValue("api")));
} }
if (cli.hasOption("o") || cli.hasOption("output")) { if (cli.hasOption("o") || cli.hasOption("output")) {
outDir = new File(cli.getOptionValue("o")); outDir = new File(cli.getOptionValue("o"));
decoder.setOutDir(outDir); decoder.setOutDir(outDir);
} else { } else {
// make out folder manually using name of apk // make out folder manually using name of apk
String outName = apkName; String outName = apkName;
outName = outName.endsWith(".apk") ? outName.substring(0, outName = outName.endsWith(".apk") ? outName.substring(0,
@ -272,110 +263,132 @@ public class Main {
private static void _Options() { private static void _Options() {
// create options // create options
Option versionOption = OptionBuilder.withLongOpt("version") Option versionOption = Option.builder("version")
.withDescription("prints the version then exits") .longOpt("version")
.create("version"); .desc("prints the version then exits")
.build();
Option advanceOption = OptionBuilder.withLongOpt("advanced") Option advanceOption = Option.builder("advance")
.withDescription("prints advance information.") .longOpt("advanced")
.create("advance"); .desc("prints advance information.")
.build();
Option noSrcOption = OptionBuilder.withLongOpt("no-src") Option noSrcOption = Option.builder("s")
.withDescription("Do not decode sources.") .longOpt("no-src")
.create("s"); .desc("Do not decode sources.")
.build();
Option noResOption = OptionBuilder.withLongOpt("no-res") Option noResOption = Option.builder("r")
.withDescription("Do not decode resources.") .longOpt("no-res")
.create("r"); .desc("Do not decode resources.")
.build();
Option debugDecOption = OptionBuilder.withLongOpt("debug") Option debugDecOption = Option.builder("d")
.withDescription("REMOVED (DOES NOT WORK): Decode in debug mode.") .longOpt("debug")
.create("d"); .desc("REMOVED (DOES NOT WORK): Decode in debug mode.")
.build();
Option analysisOption = OptionBuilder.withLongOpt("match-original") Option analysisOption = Option.builder("m")
.withDescription("Keeps files to closest to original as possible. Prevents rebuild.") .longOpt("match-original")
.create("m"); .desc("Keeps files to closest to original as possible. Prevents rebuild.")
.build();
Option apiLevelOption = OptionBuilder.withLongOpt("api") Option apiLevelOption = Option.builder("api")
.withDescription("The numeric api-level of the file to generate, e.g. 14 for ICS.") .longOpt("api-level")
.desc("The numeric api-level of the file to generate, e.g. 14 for ICS.")
.hasArg(true) .hasArg(true)
.withArgName("API") .argName("API")
.create(); .build();
Option debugBuiOption = OptionBuilder.withLongOpt("debug") Option debugBuiOption = Option.builder("d")
.withDescription("Sets android:debuggable to \"true\" in the APK's compiled manifest") .longOpt("debug")
.create("d"); .desc("Sets android:debuggable to \"true\" in the APK's compiled manifest")
.build();
Option noDbgOption = OptionBuilder.withLongOpt("no-debug-info") Option noDbgOption = Option.builder("b")
.withDescription("don't write out debug info (.local, .param, .line, etc.)") .longOpt("no-debug-info")
.create("b"); .desc("don't write out debug info (.local, .param, .line, etc.)")
.build();
Option forceDecOption = OptionBuilder.withLongOpt("force") Option forceDecOption = Option.builder("f")
.withDescription("Force delete destination directory.") .longOpt("force")
.create("f"); .desc("Force delete destination directory.")
.build();
Option frameTagOption = OptionBuilder.withLongOpt("frame-tag") Option frameTagOption = Option.builder("t")
.withDescription("Uses framework files tagged by <tag>.") .longOpt("frame-tag")
.desc("Uses framework files tagged by <tag>.")
.hasArg(true) .hasArg(true)
.withArgName("tag") .argName("tag")
.create("t"); .build();
Option frameDirOption = OptionBuilder.withLongOpt("frame-path") Option frameDirOption = Option.builder("p")
.withDescription("Uses framework files located in <dir>.") .longOpt("frame-path")
.desc("Uses framework files located in <dir>.")
.hasArg(true) .hasArg(true)
.withArgName("dir") .argName("dir")
.create("p"); .build();
Option frameIfDirOption = OptionBuilder.withLongOpt("frame-path") Option frameIfDirOption = Option.builder("p")
.withDescription("Stores framework files into <dir>.") .longOpt("frame-path")
.desc("Stores framework files into <dir>.")
.hasArg(true) .hasArg(true)
.withArgName("dir") .argName("dir")
.create("p"); .build();
Option keepResOption = OptionBuilder.withLongOpt("keep-broken-res") Option keepResOption = Option.builder("k")
.withDescription("Use if there was an error and some resources were dropped, e.g.\n" .longOpt("keep-broken-res")
.desc("Use if there was an error and some resources were dropped, e.g.\n"
+ " \"Invalid config flags detected. Dropping resources\", but you\n" + " \"Invalid config flags detected. Dropping resources\", but you\n"
+ " want to decode them anyway, even with errors. You will have to\n" + " want to decode them anyway, even with errors. You will have to\n"
+ " fix them manually before building.") + " fix them manually before building.")
.create("k"); .build();
Option forceBuiOption = OptionBuilder.withLongOpt("force-all") Option forceBuiOption = Option.builder("f")
.withDescription("Skip changes detection and build all files.") .longOpt("force-all")
.create("f"); .desc("Skip changes detection and build all files.")
.build();
Option aaptOption = OptionBuilder.withLongOpt("aapt") Option aaptOption = Option.builder("a")
.longOpt("aapt")
.hasArg(true) .hasArg(true)
.withArgName("loc") .argName("loc")
.withDescription("Loads aapt from specified location.") .desc("Loads aapt from specified location.")
.create("a"); .build();
Option originalOption = OptionBuilder.withLongOpt("copy-original") Option originalOption = Option.builder("c")
.withDescription("Copies original AndroidManifest.xml and META-INF. See project page for more info.") .longOpt("copy-original")
.create("c"); .desc("Copies original AndroidManifest.xml and META-INF. See project page for more info.")
.build();
Option tagOption = OptionBuilder.withLongOpt("tag") Option tagOption = Option.builder("t")
.withDescription("Tag frameworks using <tag>.") .longOpt("tag")
.desc("Tag frameworks using <tag>.")
.hasArg(true) .hasArg(true)
.withArgName("tag") .argName("tag")
.create("t"); .build();
Option outputBuiOption = OptionBuilder.withLongOpt("output") Option outputBuiOption = Option.builder("o")
.withDescription("The name of apk that gets written. Default is dist/name.apk") .longOpt("output")
.desc("The name of apk that gets written. Default is dist/name.apk")
.hasArg(true) .hasArg(true)
.withArgName("dir") .argName("dir")
.create("o"); .build();
Option outputDecOption = OptionBuilder.withLongOpt("output") Option outputDecOption = Option.builder("o")
.withDescription("The name of folder that gets written. Default is apk.out") .longOpt("output")
.desc("The name of folder that gets written. Default is apk.out")
.hasArg(true) .hasArg(true)
.withArgName("dir") .argName("dir")
.create("o"); .build();
Option quietOption = OptionBuilder.withLongOpt("quiet") Option quietOption = Option.builder("q")
.create("q"); .longOpt("quiet")
.build();
Option verboseOption = OptionBuilder.withLongOpt("verbose") Option verboseOption = Option.builder("v")
.create("v"); .longOpt("verbose")
.build();
// check for advance mode // check for advance mode
if (isAdvanceMode()) { if (isAdvanceMode()) {
@ -427,6 +440,7 @@ public class Main {
for (Object op : frameOptions.getOptions()) { for (Object op : frameOptions.getOptions()) {
allOptions.addOption((Option)op); allOptions.addOption((Option)op);
} }
allOptions.addOption(apiLevelOption);
allOptions.addOption(analysisOption); allOptions.addOption(analysisOption);
allOptions.addOption(debugDecOption); allOptions.addOption(debugDecOption);
allOptions.addOption(noDbgOption); allOptions.addOption(noDbgOption);
@ -541,11 +555,11 @@ public class Main {
} }
} }
public static boolean isAdvanceMode() { private static boolean isAdvanceMode() {
return advanceMode; return advanceMode;
} }
public static void setAdvanceMode(boolean advanceMode) { private static void setAdvanceMode(boolean advanceMode) {
Main.advanceMode = advanceMode; Main.advanceMode = advanceMode;
} }