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

View File

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

View File

@ -591,16 +591,29 @@ final public class AndrolibResources {
throw new CantFindFrameworkResException(id);
}
public void updateFramework() throws AndrolibException {
public void emptyFrameworkDirectory() throws AndrolibException {
File dir = getFrameworkDir();
File apk;
apk = new File(dir, "1.apk");
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 {
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);
}
}
}