From 4a02f5321c9ca7b27ac66653c465f4b716c5c7c2 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Mon, 15 Feb 2016 11:13:49 -0500 Subject: [PATCH] decoder: Extend "keep-broken-res" to also ignore duplicate resources --- .../src/main/java/brut/androlib/ApkDecoder.java | 3 ++- .../brut/androlib/res/decoder/ARSCDecoder.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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 40965bb9..002e8b56 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 @@ -73,6 +73,8 @@ public class ApkDecoder { public void decode() throws AndrolibException, IOException, DirectoryException { File outDir = getOutDir(); + AndrolibResources.sKeepBroken = mKeepBrokenResources; + if (!mForceDelete && outDir.exists()) { throw new OutDirExistsException(); } @@ -239,7 +241,6 @@ public class ApkDecoder { throw new AndrolibException( "Apk doesn't contain either AndroidManifest.xml file or resources.arsc file"); } - AndrolibResources.sKeepBroken = mKeepBrokenResources; mResTable = mAndrolib.getResTable(mApkFile, hasResources); } return mResTable; diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index 497433f3..78ce8057 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -249,8 +249,18 @@ public class ARSCDecoder { } ResResource res = new ResResource(mType, spec, value); - mType.addResource(res); - spec.addResource(res); + try { + mType.addResource(res); + spec.addResource(res); + } catch (AndrolibException e) { + if (mKeepBroken) { + mType.addResource(res, true); + spec.addResource(res, true); + System.err.println("ignoring exception: " + e); + } else { + throw e; + } + } mPkg.addResource(res); }