Skip to content

Commit

Permalink
We are ignoring typeIdOffset
Browse files Browse the repository at this point in the history
 - missing sample that experiences this
 - needs tests
 - samples requested: #1728
 - refs: iBotPeaches/platform_frameworks_base@f90f2f8
  • Loading branch information
iBotPeaches committed Feb 16, 2018
1 parent 9fc1ede commit b7b449e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private ResPackage[] readTableHeader() throws IOException, AndrolibException {

nextChunk();
for (int i = 0; i < packageCount; i++) {
mTypeIdOffset = 0;
packages[i] = readTablePackage();
}
return packages;
Expand All @@ -103,6 +104,17 @@ private ResPackage readTablePackage() throws IOException, AndrolibException {
/* keyStrings */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);
mSpecNames = StringBlock.read(mIn);

Expand Down Expand Up @@ -157,6 +169,7 @@ private ResTypeSpec readTableTypeSpec() throws AndrolibException, IOException {

// skip "TYPE 8 chunks" and/or padding data at the end of this chunk
if (mCountIn.getCount() < mHeader.endPosition) {
LOGGER.warning("Unknown data detected. Skipping: " + (mHeader.endPosition - mCountIn.getCount()) + " byte(s)");
mCountIn.skip(mHeader.endPosition - mCountIn.getCount());
}

Expand Down Expand Up @@ -186,7 +199,7 @@ private ResTypeSpec readSingleTableTypeSpec() throws AndrolibException, IOExcept

private ResType readTableType() throws IOException, AndrolibException {
checkChunkType(Header.TYPE_TYPE);
int typeId = mIn.readUnsignedByte();
int typeId = mIn.readUnsignedByte() - mTypeIdOffset;
if (mResTypeSpecs.containsKey(typeId)) {
mResId = (0xff000000 & mResId) | mResTypeSpecs.get(typeId).getId() << 16;
mTypeSpec = mResTypeSpecs.get(typeId);
Expand All @@ -205,6 +218,7 @@ private ResType readTableType() throws IOException, AndrolibException {
// For some APKs there is a disconnect between the reported size of Configs
// If we find a mismatch skip those bytes.
if (position != mCountIn.getCount()) {
LOGGER.warning("Invalid data detected. Skipping: " + (position - mCountIn.getCount()) + " byte(s)");
mIn.skipBytes(position - mCountIn.getCount());
}

Expand Down Expand Up @@ -544,6 +558,7 @@ private void nextChunkCheckType(int expectedType) throws IOException, AndrolibEx
private ResTypeSpec mTypeSpec;
private ResType mType;
private int mResId;
private int mTypeIdOffset = 0;
private boolean[] mMissingResSpecs;
private HashMap<Integer, ResTypeSpec> mResTypeSpecs = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class StringBlock {
* be at the chunk type.
*/
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();

// ResStringPool_header
Expand Down

0 comments on commit b7b449e

Please sign in to comment.