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 3d22a11a..ff4a2510 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 @@ -193,7 +193,7 @@ public class Androlib { return false; } - public void decodeUnknownFiles(ExtFile apkFile, File outDir, ResTable resTable) + public void decodeUnknownFiles(ExtFile apkFile, File outDir) throws AndrolibException { LOGGER.info("Copying unknown files..."); File unknownOut = new File(outDir, UNK_DIRNAME); 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 cffaca4e..c6fc4ba0 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 @@ -97,6 +97,9 @@ public class ApkDecoder { LOGGER.info("Using Apktool " + Androlib.getVersion() + " on " + mApkFile.getName()); + // recreate the resource table in case it was already created + mResTable = null; + if (hasResources()) { switch (mDecodeResources) { case DECODE_RESOURCES_NONE: @@ -168,7 +171,7 @@ public class ApkDecoder { } mAndrolib.decodeRawFiles(mApkFile, outDir, mDecodeAssets); - mAndrolib.decodeUnknownFiles(mApkFile, outDir, mResTable); + mAndrolib.decodeUnknownFiles(mApkFile, outDir); mUncompressedFiles = new ArrayList(); mAndrolib.recordUncompressedFiles(mApkFile, mUncompressedFiles); mAndrolib.writeOriginalFiles(mApkFile, outDir); @@ -324,8 +327,8 @@ public class ApkDecoder { meta.version = Androlib.getVersion(); meta.apkFileName = mApkFile.getName(); - if (mDecodeResources != DECODE_RESOURCES_NONE && (hasManifest() || hasResources())) { - meta.isFrameworkApk = mAndrolib.isFrameworkApk(getResTable()); + if (mResTable != null) { + meta.isFrameworkApk = mAndrolib.isFrameworkApk(mResTable); putUsesFramework(meta); putSdkInfo(meta); putPackageInfo(meta); @@ -340,7 +343,7 @@ public class ApkDecoder { } private void putUsesFramework(MetaInfo meta) throws AndrolibException { - Set pkgs = getResTable().listFramePackages(); + Set pkgs = mResTable.listFramePackages(); if (pkgs.isEmpty()) { return; } @@ -361,7 +364,7 @@ public class ApkDecoder { } private void putSdkInfo(MetaInfo meta) throws AndrolibException { - Map info = getResTable().getSdkInfo(); + Map info = mResTable.getSdkInfo(); if (info.size() > 0) { String refValue; if (info.get("minSdkVersion") != null) { @@ -387,12 +390,12 @@ public class ApkDecoder { } private void putPackageInfo(MetaInfo meta) throws AndrolibException { - String renamed = getResTable().getPackageRenamed(); - String original = getResTable().getPackageOriginal(); + String renamed = mResTable.getPackageRenamed(); + String original = mResTable.getPackageOriginal(); - int id = getResTable().getPackageId(); + int id = mResTable.getPackageId(); try { - id = getResTable().getPackage(renamed).getId(); + id = mResTable.getPackage(renamed).getId(); } catch (UndefinedResObjectException ignored) {} if (Strings.isNullOrEmpty(original)) { @@ -409,7 +412,7 @@ public class ApkDecoder { } private void putVersionInfo(MetaInfo meta) throws AndrolibException { - VersionInfo info = getResTable().getVersionInfo(); + VersionInfo info = mResTable.getVersionInfo(); String refValue = ResXmlPatcher.pullValueFromStrings(mOutDir, info.versionName); if (refValue != null) { info.versionName = refValue; @@ -417,6 +420,14 @@ public class ApkDecoder { meta.versionInfo = info; } + private void putSharedLibraryInfo(MetaInfo meta) { + meta.sharedLibrary = mResTable.getSharedLibrary(); + } + + private void putSparseResourcesInfo(MetaInfo meta) { + meta.sparseResources = mResTable.getSparseResources(); + } + private void putUnknownInfo(MetaInfo meta) { meta.unknownFiles = mAndrolib.mResUnknownFiles.getUnknownFiles(); } @@ -427,14 +438,6 @@ public class ApkDecoder { } } - private void putSparseResourcesInfo(MetaInfo meta) { - meta.sparseResources = mResTable.getSparseResources(); - } - - private void putSharedLibraryInfo(MetaInfo meta) { - meta.sharedLibrary = mResTable.getSharedLibrary(); - } - private final Androlib mAndrolib; private final static Logger LOGGER = Logger.getLogger(Androlib.class.getName());