Skip to content

Commit

Permalink
handle null type chunk in resource table
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiafan committed Dec 5, 2017
1 parent 2edad17 commit d1c79dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/main/java/net/dongliu/apk/parser/Main.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package net.dongliu.apk.parser;

import net.dongliu.apk.parser.bean.Icon;

import java.io.IOException;
import java.security.cert.CertificateException;
import java.util.List;

/**
* Main method for parser apk
Expand All @@ -14,10 +11,7 @@
public class Main {
public static void main(String[] args) throws IOException, CertificateException {
try (ApkFile apkFile = new ApkFile(args[0])) {
List<Icon> iconFiles = apkFile.getIconFiles();
for (Icon iconFile : iconFiles) {
System.out.println(iconFile);
}
System.out.println(apkFile.getApkMeta());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import java.util.Set;

/**
* parse android resource table file.
* see http://justanapplication.wordpress.com/category/android/android-resources/
* https://github.com/aosp-mirror/platform_frameworks_base/blob/master/libs/androidfw/include/androidfw/ResourceTypes.h
* https://github.com/aosp-mirror/platform_frameworks_base/blob/master/libs/androidfw/ResourceTypes.cpp
* Parse android resource table file.
*
* @author dongliu
* @see <a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/master/libs/androidfw/include/androidfw/ResourceTypes.h">ResourceTypes.h</a>
* @see <a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/master/libs/androidfw/ResourceTypes.cpp">ResourceTypes.cpp</a>
*/
public class ResourceTableParser {

Expand Down Expand Up @@ -147,6 +146,10 @@ private Pair<ResourcePackage, PackageHeader> readPackage(PackageHeader packageHe
}
ByteBuffers.position(buffer, chunkBegin + chunkHeader.getBodySize());
break;
case ChunkType.NULL:
// ByteBuffers.position(buffer, chunkBegin + chunkHeader.getBodySize());
ByteBuffers.position(buffer, buffer.position() + buffer.remaining());
break;
default:
throw new ParserException("unexpected chunk type: 0x" + chunkHeader.getChunkType());
}
Expand Down Expand Up @@ -216,7 +219,8 @@ private ChunkHeader readChunkHeader() {
return libraryHeader;

case ChunkType.NULL:
//buffer.skip((int) (chunkSize - headerSize));
ByteBuffers.position(buffer, begin + headerSize);
return new NullHeader(chunkType, headerSize, chunkSize);
default:
throw new ParserException("Unexpected chunk Type: 0x" + Integer.toHexString(chunkType));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/dongliu/apk/parser/struct/ChunkHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* <pre>
* chunk header struct.
* struct ResChunk_header {
* uint16_t type;
* uint16_t headerSize;
* uint32_t size;
* uint16_t type;
* uint16_t headerSize;
* uint32_t size;
* }
* </pre>
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.dongliu.apk.parser.struct.resource;

import net.dongliu.apk.parser.struct.ChunkHeader;

public class NullHeader extends ChunkHeader {
public NullHeader(int chunkType, int headerSize, long chunkSize) {
super(chunkType, headerSize, chunkSize);
}
}

0 comments on commit d1c79dc

Please sign in to comment.