From 0827b2b7a2b7f354d25b83e44865ae83d7baf0cf Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Thu, 15 Feb 2018 18:04:23 -0500 Subject: [PATCH] aapt2: read the type spec and infer if sparsely packed --- .../java/brut/androlib/res/decoder/ARSCDecoder.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java index ebaacb1c..f98a34aa 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java @@ -151,7 +151,7 @@ public class ARSCDecoder { } } - private ResTypeSpec readTableTypeSpec() throws AndrolibException, IOException { + private void readTableTypeSpec() throws AndrolibException, IOException { mTypeSpec = readSingleTableTypeSpec(); addTypeSpec(mTypeSpec); @@ -162,6 +162,12 @@ public class ARSCDecoder { resTypeSpec = readSingleTableTypeSpec(); addTypeSpec(resTypeSpec); type = nextChunk().type; + + // We've detected sparse resources, lets record this so we can rebuild in that same format (sparse/not) + // with aapt2. aapt1 will ignore this. + if (! mResTable.getSparseResources()) { + mResTable.setSparseResources(true); + } } while (type == Header.TYPE_TYPE) { @@ -177,8 +183,6 @@ public class ARSCDecoder { addMissingResSpecs(); } - - return mTypeSpec; } private ResTypeSpec readSingleTableTypeSpec() throws AndrolibException, IOException {