Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle apks that utilize Shared Resources
 - shared resource is currently hardcoded to pkgId 2 like AOSP
 - merry christmas
  • Loading branch information
iBotPeaches committed Dec 25, 2014
1 parent 2bd1e59 commit e9d21f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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)
Expand Down
Expand Up @@ -83,6 +83,15 @@ private ResPackage[] readTable() throws IOException, AndrolibException {
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();
Expand All @@ -96,13 +105,35 @@ private ResPackage readPackage() throws IOException, AndrolibException {
mPkg = new ResPackage(mResTable, id, name);

nextChunk();
while (mHeader.type == Header.TYPE_LIBRARY) {
readLibraryType();
}

while (mHeader.type == Header.TYPE_TYPE) {
readType();
}

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();
Expand Down Expand Up @@ -370,7 +401,7 @@ public static Header read(ExtDataInput in) throws IOException {
}

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;
}

Expand Down

0 comments on commit e9d21f8

Please sign in to comment.