From daa1e1d7538eb20843d9f7046924bdc25e48ebe5 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sun, 19 Apr 2015 10:29:28 -0500 Subject: [PATCH] Updating Framework Support --- .../src/main/java/brut/apktool/Main.java | 32 +++++++++++++------ .../src/main/java/brut/androlib/Androlib.java | 4 +++ .../main/java/brut/androlib/ApkOptions.java | 1 + .../brut/androlib/res/AndrolibResources.java | 13 ++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java index d0609585..b550e3d0 100644 --- a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java +++ b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java @@ -48,7 +48,7 @@ public class Main { // cli parser CommandLineParser parser = new PosixParser(); - CommandLine commandLine = null; + CommandLine commandLine; // load options _Options(); @@ -57,7 +57,7 @@ public class Main { commandLine = parser.parse(allOptions, args, false); } catch (ParseException ex) { System.err.println(ex.getMessage()); - usage(commandLine); + usage(); return; } @@ -86,6 +86,9 @@ 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); + cmdFound = true; } else if (opt.equalsIgnoreCase("publicize-resources")) { cmdPublicizeResources(commandLine); cmdFound = true; @@ -97,7 +100,7 @@ public class Main { if (commandLine.hasOption("version")) { _version(); } else { - usage(commandLine); + usage(); } } } @@ -107,7 +110,7 @@ public class Main { int paraCount = cli.getArgList().size(); String apkName = (String) cli.getArgList().get(paraCount - 1); - File outDir = null; + File outDir; // check for options if (cli.hasOption("s") || cli.hasOption("no-src")) { @@ -224,8 +227,7 @@ public class Main { new Androlib(apkOptions).build(new File(appDirName), outFile); } - private static void cmdInstallFramework(CommandLine cli) - throws AndrolibException { + private static void cmdInstallFramework(CommandLine cli) throws AndrolibException { int paraCount = cli.getArgList().size(); String apkName = (String) cli.getArgList().get(paraCount - 1); @@ -239,14 +241,26 @@ public class Main { new Androlib(apkOptions).installFramework(new File(apkName)); } - private static void cmdPublicizeResources(CommandLine cli) - throws AndrolibException { + private static void cmdPublicizeResources(CommandLine cli) throws AndrolibException { int paraCount = cli.getArgList().size(); String apkName = (String) cli.getArgList().get(paraCount - 1); new Androlib().publicizeResources(new File(apkName)); } + private static void cmdUpdateFramework(CommandLine cli) throws AndrolibException { + ApkOptions apkOptions = new ApkOptions(); + + if (cli.hasOption("f") || cli.hasOption("force")) { + apkOptions.forceDeleteFramework = true; + } + if (cli.hasOption("p") || cli.hasOption("frame-path")) { + apkOptions.frameworkFolderLocation = cli.getOptionValue("p"); + } + + new Androlib(apkOptions).updateFramework(); + } + private static void _version() { System.out.println(Androlib.getVersion()); } @@ -426,7 +440,7 @@ public class Main { } } - private static void usage(CommandLine commandLine) { + private static void usage() { // load basicOptions _Options(); diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index 0660f196..15f4aa28 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -684,6 +684,10 @@ public class Androlib { mAndRes.installFramework(frameFile); } + public void updateFramework() throws AndrolibException { + mAndRes.updateFramework(); + } + public boolean isFrameworkApk(ResTable resTable) { for (ResPackage pkg : resTable.listMainPackages()) { if (pkg.getId() < 64) { diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java index df4774fd..b188d541 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkOptions.java @@ -19,6 +19,7 @@ import java.util.Collection; public class ApkOptions { public boolean forceBuildAll = false; + public boolean forceDeleteFramework = false; public boolean debugMode = false; public boolean verbose = false; public boolean copyOriginalFiles = false; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index e0dbf644..d767edea 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -591,6 +591,19 @@ final public class AndrolibResources { throw new CantFindFrameworkResException(id); } + public void updateFramework() 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()); + } else { + + } + } + public void installFramework(File frameFile) throws AndrolibException { installFramework(frameFile, apkOptions.frameworkTag); }