Handle APKs with NULL padding on StringPools

- issue 664
This commit is contained in:
Connor Tumbleson 2014-10-05 12:05:08 -05:00
parent 76bf5ead25
commit 62db52fe7b
2 changed files with 19 additions and 6 deletions

View File

@ -41,10 +41,12 @@ public class StringBlock {
* be at the chunk type.
*/
public static StringBlock read(ExtDataInput reader) throws IOException {
reader.skipCheckInt(CHUNK_TYPE);
reader.skipCheckChunkTypeInt(CHUNK_STRINGPOOL_TYPE, CHUNK_NULL_TYPE);
int chunkSize = reader.readInt();
// ResStringPool_header
int stringCount = reader.readInt();
int styleOffsetCount = reader.readInt();
int styleCount = reader.readInt();
int flags = reader.readInt();
int stringsOffset = reader.readInt();
int stylesOffset = reader.readInt();
@ -55,8 +57,8 @@ public class StringBlock {
block.m_stringOwns = new int[stringCount];
Arrays.fill(block.m_stringOwns, -1);
if (styleOffsetCount != 0) {
block.m_styleOffsets = reader.readIntArray(styleOffsetCount);
if (styleCount != 0) {
block.m_styleOffsets = reader.readIntArray(styleCount);
}
{
int size = ((stylesOffset == 0) ? chunkSize : stylesOffset)
@ -343,6 +345,7 @@ public class StringBlock {
private static final Logger LOGGER = Logger.getLogger(StringBlock.class.getName());
// ResChunk_header = header.type (0x0001) + header.headerSize (0x001C)
private static final int CHUNK_TYPE = 0x001C0001;
private static final int CHUNK_STRINGPOOL_TYPE = 0x001C0001;
private static final int CHUNK_NULL_TYPE = 0x00000000;
private static final int UTF8_FLAG = 0x00000100;
}

View File

@ -62,7 +62,17 @@ public class ExtDataInput extends DataInputDelegate {
byte got = readByte();
if (got != expected) {
throw new IOException(String.format(
"Expected: 0x%08x, got: 0x%08x", expected, got));
"Expected: 0x%08x, got: 0x%08x", expected, got));
}
}
public void skipCheckChunkTypeInt(int expected, int possible) throws IOException {
int got = readInt();
if (got == possible) {
skipCheckChunkTypeInt(expected, -1);
} else if (got != expected) {
throw new IOException(String.format("Expected: 0x%08x, got: 0x%08x", expected, got));
}
}