From e9d21f84af8522ef797a4016b0266f394b9a5650 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Thu, 25 Dec 2014 09:56:25 -0600 Subject: [PATCH] Handle apks that utilize Shared Resources - shared resource is currently hardcoded to pkgId 2 like AOSP - merry christmas --- CHANGES | 2 ++ .../androlib/res/decoder/ARSCDecoder.java | 33 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 77c9419a..8f3c2d93 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,8 @@ v2.0.0 (TBA) -Fixed (issue #689) - Fixed issue with hard coding extension as PNG. -Fixed (issue #653) - Added Android Lollipop support. -Fixed (issue #706) - Added support for TYPE_DYNAMIC_REFERENCE. +-Fixed (issue #685) - Fixed invalid attrs values with Android Lollipop. +-Fixed (issue #713) - Fixed issue with packages that had shared library resources. -Fixed issue with APKs with multiple dex files. -Fixed issue with using Apktool without smali/baksmali for ApktoolProperties (Thanks teprrr) -Fixed issue with non-URI standard characters in apk name (Thanks rover12421) 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 b7fadd44..622e9c30 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 @@ -83,6 +83,15 @@ public class ARSCDecoder { private ResPackage readPackage() throws IOException, AndrolibException { checkChunkType(Header.TYPE_PACKAGE); int id = (byte) mIn.readInt(); + + if (id == 0) { + // This means we are dealing with a Library Package, we should just temporarily + // set the packageId to the next available id . This will be set at runtime regardless, but + // for Apktool's use we need a non-zero packageId. + // AOSP indicates 0x02 is next, as 0x01 is system and 0x7F is private. + id = 2; + } + String name = mIn.readNullEndedString(128, true); /* typeStrings */mIn.skipInt(); /* lastPublicType */mIn.skipInt(); @@ -96,6 +105,10 @@ public class ARSCDecoder { mPkg = new ResPackage(mResTable, id, name); nextChunk(); + while (mHeader.type == Header.TYPE_LIBRARY) { + readLibraryType(); + } + while (mHeader.type == Header.TYPE_TYPE) { readType(); } @@ -103,6 +116,24 @@ public class ARSCDecoder { return mPkg; } + private void readLibraryType() throws AndrolibException, IOException { + checkChunkType(Header.TYPE_LIBRARY); + int libraryCount = mIn.readInt(); + + int packageId; + String packageName; + + for (int i = 0; i < libraryCount; i++) { + packageId = mIn.readInt(); + packageName = mIn.readNullEndedString(128, true); + LOGGER.info(String.format("Decoding Shared Library (%s), pkgId: %d", packageName, packageId)); + } + + while(nextChunk().type == Header.TYPE_CONFIG) { + readConfig(); + } + } + private ResType readType() throws AndrolibException, IOException { checkChunkType(Header.TYPE_TYPE); byte id = mIn.readByte(); @@ -370,7 +401,7 @@ public class ARSCDecoder { } public final static short TYPE_NONE = -1, TYPE_TABLE = 0x0002, - TYPE_PACKAGE = 0x0200, TYPE_TYPE = 0x0202, + TYPE_PACKAGE = 0x0200, TYPE_TYPE = 0x0202, TYPE_LIBRARY = 0x0203, TYPE_CONFIG = 0x0201; }