Evolve Update-Framework to Empty Framework Directory

- allows emptying of framework via (empty-framework-dir)
 - checks in place to only delete files that are APKs, non recursive
This commit is contained in:
Connor Tumbleson 2016-10-06 09:18:16 -04:00
parent daa1e1d753
commit 6361fa9725
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75
3 changed files with 31 additions and 12 deletions

View File

@ -86,8 +86,8 @@ public class Main {
} else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) { } else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) {
cmdInstallFramework(commandLine); cmdInstallFramework(commandLine);
cmdFound = true; cmdFound = true;
} else if (opt.equalsIgnoreCase("u") || opt.equalsIgnoreCase("update-framework")) { } else if (opt.equalsIgnoreCase("empty-framework-dir")) {
cmdUpdateFramework(commandLine); cmdEmptyFrameworkDirectory(commandLine);
cmdFound = true; cmdFound = true;
} else if (opt.equalsIgnoreCase("publicize-resources")) { } else if (opt.equalsIgnoreCase("publicize-resources")) {
cmdPublicizeResources(commandLine); cmdPublicizeResources(commandLine);
@ -248,7 +248,7 @@ public class Main {
new Androlib().publicizeResources(new File(apkName)); new Androlib().publicizeResources(new File(apkName));
} }
private static void cmdUpdateFramework(CommandLine cli) throws AndrolibException { private static void cmdEmptyFrameworkDirectory(CommandLine cli) throws AndrolibException {
ApkOptions apkOptions = new ApkOptions(); ApkOptions apkOptions = new ApkOptions();
if (cli.hasOption("f") || cli.hasOption("force")) { if (cli.hasOption("f") || cli.hasOption("force")) {
@ -258,7 +258,7 @@ public class Main {
apkOptions.frameworkFolderLocation = cli.getOptionValue("p"); apkOptions.frameworkFolderLocation = cli.getOptionValue("p");
} }
new Androlib(apkOptions).updateFramework(); new Androlib(apkOptions).emptyFrameworkDirectory();
} }
private static void _version() { private static void _version() {
@ -376,7 +376,6 @@ public class Main {
// check for advance mode // check for advance mode
if (isAdvanceMode()) { if (isAdvanceMode()) {
DecodeOptions.addOption(debugDecOption);
DecodeOptions.addOption(noDbgOption); DecodeOptions.addOption(noDbgOption);
DecodeOptions.addOption(keepResOption); DecodeOptions.addOption(keepResOption);
DecodeOptions.addOption(analysisOption); DecodeOptions.addOption(analysisOption);
@ -408,6 +407,10 @@ public class Main {
frameOptions.addOption(tagOption); frameOptions.addOption(tagOption);
frameOptions.addOption(frameIfDirOption); frameOptions.addOption(frameIfDirOption);
// add empty framework options
emptyFrameworkOptions.addOption(forceDecOption);
emptyFrameworkOptions.addOption(frameIfDirOption);
// add all, loop existing cats then manually add advance // add all, loop existing cats then manually add advance
for (Object op : normalOptions.getOptions()) { for (Object op : normalOptions.getOptions()) {
allOptions.addOption((Option)op); allOptions.addOption((Option)op);
@ -466,8 +469,9 @@ public class Main {
formatter.printHelp("apktool " + verbosityHelp() + "d[ecode] [options] <file_apk>", DecodeOptions); formatter.printHelp("apktool " + verbosityHelp() + "d[ecode] [options] <file_apk>", DecodeOptions);
formatter.printHelp("apktool " + verbosityHelp() + "b[uild] [options] <app_path>", BuildOptions); formatter.printHelp("apktool " + verbosityHelp() + "b[uild] [options] <app_path>", BuildOptions);
if (isAdvanceMode()) { if (isAdvanceMode()) {
formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>", formatter.printHelp("apktool " + verbosityHelp() + "publicize-resources <file_path>", emptyOptions);
"Make all framework resources public.", emptyOptions, null); formatter.printHelp("apktool " + verbosityHelp() + "empty-framework-dir [options]", emptyFrameworkOptions);
System.out.println("");
} else { } else {
System.out.println(""); System.out.println("");
} }
@ -550,6 +554,7 @@ public class Main {
private final static Options frameOptions; private final static Options frameOptions;
private final static Options allOptions; private final static Options allOptions;
private final static Options emptyOptions; private final static Options emptyOptions;
private final static Options emptyFrameworkOptions;
static { static {
//normal and advance usage output //normal and advance usage output
@ -559,5 +564,6 @@ public class Main {
frameOptions = new Options(); frameOptions = new Options();
allOptions = new Options(); allOptions = new Options();
emptyOptions = new Options(); emptyOptions = new Options();
emptyFrameworkOptions = new Options();
} }
} }

View File

@ -684,8 +684,8 @@ public class Androlib {
mAndRes.installFramework(frameFile); mAndRes.installFramework(frameFile);
} }
public void updateFramework() throws AndrolibException { public void emptyFrameworkDirectory() throws AndrolibException {
mAndRes.updateFramework(); mAndRes.emptyFrameworkDirectory();
} }
public boolean isFrameworkApk(ResTable resTable) { public boolean isFrameworkApk(ResTable resTable) {

View File

@ -591,16 +591,29 @@ final public class AndrolibResources {
throw new CantFindFrameworkResException(id); throw new CantFindFrameworkResException(id);
} }
public void updateFramework() throws AndrolibException { public void emptyFrameworkDirectory() throws AndrolibException {
File dir = getFrameworkDir(); File dir = getFrameworkDir();
File apk; File apk;
apk = new File(dir, "1.apk"); apk = new File(dir, "1.apk");
if (! apk.exists()) { if (! apk.exists()) {
LOGGER.warning("Can't update framework, no file found at: " + apk.getAbsolutePath()); LOGGER.warning("Can't empty framework directory, no file found at: " + apk.getAbsolutePath());
} else { } else {
try {
if (apk.exists() && dir.listFiles().length > 1 && ! apkOptions.forceDeleteFramework) {
LOGGER.warning("More than default framework detected. Please run command with `--force` parameter to wipe framework directory.");
} else {
for (File file : dir.listFiles()) {
if (file.isFile() && file.getName().endsWith(".apk")) {
LOGGER.info("Removing " + file.getName() + " framework file...");
file.delete();
}
}
}
} catch (NullPointerException e) {
throw new AndrolibException(e);
}
} }
} }