From 620b71abd39fb74c05432d93800cd971cfe23c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Tue, 1 Jun 2010 10:25:38 +0200 Subject: [PATCH] ARSCDecoder: automatically adding missing resources. --- .../androlib/res/decoder/ARSCDecoder.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/brut/androlib/res/decoder/ARSCDecoder.java b/src/brut/androlib/res/decoder/ARSCDecoder.java index d0efc306..52fd9299 100644 --- a/src/brut/androlib/res/decoder/ARSCDecoder.java +++ b/src/brut/androlib/res/decoder/ARSCDecoder.java @@ -24,8 +24,7 @@ import brut.util.Duo; import brut.util.ExtDataInput; import com.mindprod.ledatastream.LEDataInputStream; import java.io.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.logging.Logger; import org.apache.commons.io.input.CountingInputStream; @@ -112,6 +111,9 @@ public class ARSCDecoder { mIn.skipBytes(3); int entryCount = mIn.readInt(); + mMissingResSpecs = new boolean[entryCount]; + Arrays.fill(mMissingResSpecs, true); + if (mFlagsOffsets != null) { mFlagsOffsets.add(new FlagsOffset(mCountIn.getCount(), entryCount)); } @@ -125,6 +127,8 @@ public class ARSCDecoder { readConfig(); } + addMissingResSpecs(); + return mType; } @@ -148,6 +152,7 @@ public class ARSCDecoder { for (int i = 0; i < entryOffsets.length; i++) { if (entryOffsets[i] != -1) { + mMissingResSpecs[i] = false; mResId = (mResId & 0xffff0000) | i; readEntry(); } @@ -253,6 +258,28 @@ public class ARSCDecoder { screenWidth, screenHeight, screenLayout, sdkVersion); } + private void addMissingResSpecs() throws AndrolibException { + int resId = mResId & 0xffff0000; + + for (int i = 0; i < mMissingResSpecs.length; i++) { + if (! mMissingResSpecs[i]) { + continue; + } + + ResResSpec spec = new ResResSpec(new ResID(resId | i), + String.format("APKTOOL_DUMMY_%04x", i), mPkg, mType); + mPkg.addResSpec(spec); + mType.addResSpec(spec); + + ResValue value = new ResBoolValue(false); + ResResource res = new ResResource( + mPkg.getConfig(new ResConfigFlags()), spec, value); + mPkg.addResource(res); + mConfig.addResource(res); + spec.addResource(res); + } + } + private Header nextChunk() throws IOException { return mHeader = Header.read(mIn); } @@ -284,6 +311,7 @@ public class ARSCDecoder { private ResType mType; private ResConfig mConfig; private int mResId; + private boolean[] mMissingResSpecs; private final static short ENTRY_FLAG_COMPLEX = 0x0001;