feat: update internal framework to API 31 (12 Release) (#2743)

* feat: update internal framework to API 31 (12 Release)

* refactor: rename enums for new overlays/stagedAliases

* fix: introduce basic staged alias support

* feat: update internal framework to API 32 (12L Release)

* fix: add support for overlay spec skipping
This commit is contained in:
Connor Tumbleson 2022-03-21 07:20:04 -04:00 committed by GitHub
commit 49071d0fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 12 deletions

View File

@ -87,7 +87,7 @@ public class ARSCDecoder {
} }
private ResPackage readTablePackage() throws IOException, AndrolibException { private ResPackage readTablePackage() throws IOException, AndrolibException {
checkChunkType(Header.TYPE_PACKAGE); checkChunkType(Header.XML_TYPE_PACKAGE);
int id = mIn.readInt(); int id = mIn.readInt();
if (id == 0) { if (id == 0) {
@ -128,11 +128,17 @@ public class ARSCDecoder {
boolean flag = true; boolean flag = true;
while (flag) { while (flag) {
switch (mHeader.type) { switch (mHeader.type) {
case Header.TYPE_LIBRARY: case Header.XML_TYPE_SPEC_TYPE:
readTableTypeSpec();
break;
case Header.XML_TYPE_LIBRARY:
readLibraryType(); readLibraryType();
break; break;
case Header.TYPE_SPEC_TYPE: case Header.XML_TYPE_OVERLAY:
readTableTypeSpec(); readOverlaySpec();
break;
case Header.XML_TYPE_STAGED_ALIAS:
readStagedAliasSpec();
break; break;
default: default:
flag = false; flag = false;
@ -144,7 +150,7 @@ public class ARSCDecoder {
} }
private void readLibraryType() throws AndrolibException, IOException { private void readLibraryType() throws AndrolibException, IOException {
checkChunkType(Header.TYPE_LIBRARY); checkChunkType(Header.XML_TYPE_LIBRARY);
int libraryCount = mIn.readInt(); int libraryCount = mIn.readInt();
int packageId; int packageId;
@ -156,11 +162,32 @@ public class ARSCDecoder {
LOGGER.info(String.format("Decoding Shared Library (%s), pkgId: %d", packageName, packageId)); LOGGER.info(String.format("Decoding Shared Library (%s), pkgId: %d", packageName, packageId));
} }
while(nextChunk().type == Header.TYPE_TYPE) { while(nextChunk().type == Header.XML_TYPE_TYPE) {
readTableTypeSpec(); readTableTypeSpec();
} }
} }
private void readStagedAliasSpec() throws IOException {
int count = mIn.readInt();
for (int i = 0; i < count; i++) {
LOGGER.info(String.format("Skipping staged alias stagedId (%h) finalId: %h", mIn.readInt(), mIn.readInt()));
}
nextChunk();
}
private void readOverlaySpec() throws IOException {
/* policyFlags */mIn.skipInt();
int count = mIn.readInt();
for (int i = 0; i < count; i++) {
LOGGER.info(String.format("Skipping overlay (%h)", mIn.readInt()));
}
nextChunk();
}
private void readTableTypeSpec() throws AndrolibException, IOException { private void readTableTypeSpec() throws AndrolibException, IOException {
mTypeSpec = readSingleTableTypeSpec(); mTypeSpec = readSingleTableTypeSpec();
addTypeSpec(mTypeSpec); addTypeSpec(mTypeSpec);
@ -168,7 +195,7 @@ public class ARSCDecoder {
int type = nextChunk().type; int type = nextChunk().type;
ResTypeSpec resTypeSpec; ResTypeSpec resTypeSpec;
while (type == Header.TYPE_SPEC_TYPE) { while (type == Header.XML_TYPE_SPEC_TYPE) {
resTypeSpec = readSingleTableTypeSpec(); resTypeSpec = readSingleTableTypeSpec();
addTypeSpec(resTypeSpec); addTypeSpec(resTypeSpec);
type = nextChunk().type; type = nextChunk().type;
@ -180,7 +207,7 @@ public class ARSCDecoder {
} }
} }
while (type == Header.TYPE_TYPE) { while (type == Header.XML_TYPE_TYPE) {
readTableType(); readTableType();
// 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
@ -196,7 +223,7 @@ public class ARSCDecoder {
} }
private ResTypeSpec readSingleTableTypeSpec() throws AndrolibException, IOException { private ResTypeSpec readSingleTableTypeSpec() throws AndrolibException, IOException {
checkChunkType(Header.TYPE_SPEC_TYPE); checkChunkType(Header.XML_TYPE_SPEC_TYPE);
int id = mIn.readUnsignedByte(); int id = mIn.readUnsignedByte();
mIn.skipBytes(3); mIn.skipBytes(3);
int entryCount = mIn.readInt(); int entryCount = mIn.readInt();
@ -212,7 +239,7 @@ public class ARSCDecoder {
} }
private ResType readTableType() throws IOException, AndrolibException { private ResType readTableType() throws IOException, AndrolibException {
checkChunkType(Header.TYPE_TYPE); checkChunkType(Header.XML_TYPE_TYPE);
int typeId = mIn.readUnsignedByte() - mTypeIdOffset; 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;
@ -604,8 +631,18 @@ public class ARSCDecoder {
return new Header(type, in.readShort(), in.readInt(), start); return new Header(type, in.readShort(), in.readInt(), start);
} }
public final static short TYPE_NONE = -1, TYPE_TABLE = 0x0002, public final static short TYPE_NONE = -1;
TYPE_PACKAGE = 0x0200, TYPE_TYPE = 0x0201, TYPE_SPEC_TYPE = 0x0202, TYPE_LIBRARY = 0x0203; public final static short TYPE_STRING_POOL = 0x0001;
public final static short TYPE_TABLE = 0x0002;
public final static short TYPE_XML = 0x0003;
public final static short XML_TYPE_PACKAGE = 0x0200;
public final static short XML_TYPE_TYPE = 0x0201;
public final static short XML_TYPE_SPEC_TYPE = 0x0202;
public final static short XML_TYPE_LIBRARY = 0x0203;
public final static short XML_TYPE_OVERLAY = 0x0204;
public final static short XML_TYPE_OVERLAY_POLICY = 0x0205;
public final static short XML_TYPE_STAGED_ALIAS = 0x0206;
} }
public static class FlagsOffset { public static class FlagsOffset {