Handle apks that utilize Shared Resources

- shared resource is currently hardcoded to pkgId 2 like AOSP
 - merry christmas
This commit is contained in:
Connor Tumbleson 2014-12-25 09:56:25 -06:00
parent 2bd1e595df
commit e9d21f84af
2 changed files with 34 additions and 1 deletions

View File

@ -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)

View File

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