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 b228a42c..9672f8c2 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 @@ -183,9 +183,11 @@ public class Main { flags.put("verbose", false); flags.put("framework", false); flags.put("update", false); + flags.put("copyOriginal", false); int i; int skip = 0; + ExtFile mOrigApk = null; String mAaptPath = ""; for (i = 0; i < args.length; i++) { @@ -202,6 +204,8 @@ public class Main { } else if ("-a".equals(opt) || "--aapt".equals(opt)) { mAaptPath = args[i + 1]; skip = 1; + } else if ("-c".equals(opt) || "--copy-original".equals(opt)) { + flags.put("copyOriginal", true); } else if ("--frame-path".equals(opt)) { i++; instance.setFrameworkFolder(args[i]); @@ -329,6 +333,8 @@ public class Main { + " Build in debug mode. Check project page for more info.\n" + " -a, --aapt\n" + " Loads aapt from specified location.\n" + + " -c, --copy-original\n" + + " Copies original AndroidManifest.xml and META-INF.\n" + " --frame-path \n" + " Use the specified directory for framework files\n" + "\n" 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 1bc096e3..3eb79bb7 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 @@ -16,7 +16,6 @@ package brut.androlib; -import brut.androlib.err.InFileNotFoundException; import brut.androlib.java.AndrolibJava; import brut.androlib.res.AndrolibResources; import brut.androlib.res.data.ResPackage; @@ -129,6 +128,27 @@ public class Androlib { } } + public void writeOriginalFiles(ExtFile apkFile, File outDir) + throws AndrolibException { + LOGGER.info("Copying original files..."); + File originalDir = new File(outDir, "original"); + if (!originalDir.exists()) { + originalDir.mkdirs(); + } + + try { + Directory in = apkFile.getDirectory(); + if(in.containsFile("AndroidManifest.xml")) { + in.copyToDir(originalDir, "AndroidManifest.xml"); + } + if (in.containsDir("META-INF")) { + in.copyToDir(originalDir, "META-INF"); + } + } catch (DirectoryException ex) { + throw new AndrolibException(ex); + } + } + public void writeMetaFile(File mOutDir, Map meta) throws AndrolibException { DumperOptions options = new DumperOptions(); @@ -200,6 +220,7 @@ public class Androlib { buildResources(appDir, flags, (Map) meta.get("usesFramework")); buildLib(appDir, flags); + buildCopyOriginalFiles(appDir, flags); buildApk(appDir, outFile, flags); } @@ -424,6 +445,29 @@ public class Androlib { } } + public void buildCopyOriginalFiles(File appDir, + HashMap flags) throws AndrolibException { + if (flags.get("copyOriginal")) { + File originalDir = new File(appDir, "original"); + if(originalDir.exists()) { + try { + LOGGER.info("Copy original files..."); + Directory in = (new ExtFile(originalDir)).getDirectory(); + if(in.containsFile("AndroidManifest.xml")) { + LOGGER.info("Copy AndroidManifest.xml..."); + in.copyToDir(new File(appDir, APK_DIRNAME), "AndroidManifest.xml"); + } + if (in.containsDir("META-INF")) { + LOGGER.info("Copy META-INF..."); + in.copyToDir(new File(appDir, APK_DIRNAME), "META-INF"); + } + } catch (DirectoryException ex) { + throw new AndrolibException(ex); + } + } + } + } + public void buildApk(File appDir, File outApk, HashMap flags) throws AndrolibException { LOGGER.info("Building apk file..."); @@ -514,16 +558,11 @@ public class Androlib { } return files; } - - public void setApkFile(File apkFile) { - mOrigApkFile = new ExtFile(apkFile); - } public void setFrameworkFolder(String path) { mAndRes.setFrameworkFolder(path); } - private ExtFile mOrigApkFile = null; private String mAaptPath = null; private final static Logger LOGGER = Logger.getLogger(Androlib.class diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java index 672b2b72..21f7bb3f 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java @@ -133,6 +133,7 @@ public class ApkDecoder { } mAndrolib.decodeRawFiles(mApkFile, outDir); + mAndrolib.writeOriginalFiles(mApkFile, outDir); writeMetaFile(); } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java index e177407d..1c4d25ac 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/BuildAndDecodeTest.java @@ -184,6 +184,7 @@ public class BuildAndDecodeTest { tmp.put("verbose", false); tmp.put("framework", false); tmp.put("update", false); + tmp.put("copyOriginal", false); return tmp; }