Merge pull request #1690 from iBotPeaches/type-id-offset

We are ignoring typeIdOffset
This commit is contained in:
Connor Tumbleson 2018-02-16 08:42:28 -05:00 committed by GitHub
commit 17bad5a9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -77,6 +77,7 @@ public class ARSCDecoder {
nextChunk(); nextChunk();
for (int i = 0; i < packageCount; i++) { for (int i = 0; i < packageCount; i++) {
mTypeIdOffset = 0;
packages[i] = readTablePackage(); packages[i] = readTablePackage();
} }
return packages; return packages;
@ -103,6 +104,17 @@ public class ARSCDecoder {
/* keyStrings */mIn.skipInt(); /* keyStrings */mIn.skipInt();
/* lastPublicKey */mIn.skipInt(); /* lastPublicKey */mIn.skipInt();
// TypeIdOffset was added platform_frameworks_base/@f90f2f8dc36e7243b85e0b6a7fd5a590893c827e
// which is only in split/new applications.
int splitHeaderSize = (2 + 2 + 4 + 4 + (2 * 128) + (4 * 5)); // short, short, int, int, char[128], int * 4
if (mHeader.headerSize == splitHeaderSize) {
mTypeIdOffset = mIn.readInt();
}
if (mTypeIdOffset > 0) {
LOGGER.warning("Please report this application to Apktool for a fix: https://github.com/iBotPeaches/Apktool/issues/1728");
}
mTypeNames = StringBlock.read(mIn); mTypeNames = StringBlock.read(mIn);
mSpecNames = StringBlock.read(mIn); mSpecNames = StringBlock.read(mIn);
@ -157,6 +169,7 @@ public class ARSCDecoder {
// skip "TYPE 8 chunks" and/or padding data at the end of this chunk // skip "TYPE 8 chunks" and/or padding data at the end of this chunk
if (mCountIn.getCount() < mHeader.endPosition) { if (mCountIn.getCount() < mHeader.endPosition) {
LOGGER.warning("Unknown data detected. Skipping: " + (mHeader.endPosition - mCountIn.getCount()) + " byte(s)");
mCountIn.skip(mHeader.endPosition - mCountIn.getCount()); mCountIn.skip(mHeader.endPosition - mCountIn.getCount());
} }
@ -186,7 +199,7 @@ public class ARSCDecoder {
private ResType readTableType() throws IOException, AndrolibException { private ResType readTableType() throws IOException, AndrolibException {
checkChunkType(Header.TYPE_TYPE); checkChunkType(Header.TYPE_TYPE);
int typeId = mIn.readUnsignedByte(); int typeId = mIn.readUnsignedByte() - mTypeIdOffset;
if (mResTypeSpecs.containsKey(typeId)) { if (mResTypeSpecs.containsKey(typeId)) {
mResId = (0xff000000 & mResId) | mResTypeSpecs.get(typeId).getId() << 16; mResId = (0xff000000 & mResId) | mResTypeSpecs.get(typeId).getId() << 16;
mTypeSpec = mResTypeSpecs.get(typeId); mTypeSpec = mResTypeSpecs.get(typeId);
@ -205,6 +218,7 @@ public class ARSCDecoder {
// For some APKs there is a disconnect between the reported size of Configs // For some APKs there is a disconnect between the reported size of Configs
// If we find a mismatch skip those bytes. // If we find a mismatch skip those bytes.
if (position != mCountIn.getCount()) { if (position != mCountIn.getCount()) {
LOGGER.warning("Invalid data detected. Skipping: " + (position - mCountIn.getCount()) + " byte(s)");
mIn.skipBytes(position - mCountIn.getCount()); mIn.skipBytes(position - mCountIn.getCount());
} }
@ -544,6 +558,7 @@ public class ARSCDecoder {
private ResTypeSpec mTypeSpec; private ResTypeSpec mTypeSpec;
private ResType mType; private ResType mType;
private int mResId; private int mResId;
private int mTypeIdOffset = 0;
private boolean[] mMissingResSpecs; private boolean[] mMissingResSpecs;
private HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>(); private HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();

View File

@ -41,7 +41,7 @@ public class StringBlock {
* be at the chunk type. * be at the chunk type.
*/ */
public static StringBlock read(ExtDataInput reader) throws IOException { public static StringBlock read(ExtDataInput reader) throws IOException {
reader.skipCheckChunkTypeInt(CHUNK_STRINGPOOL_TYPE, CHUNK_NULL_TYPE); reader.skipCheckInt(CHUNK_STRINGPOOL_TYPE);
int chunkSize = reader.readInt(); int chunkSize = reader.readInt();
// ResStringPool_header // ResStringPool_header