Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support config flags as low as 8 bytes #2982

Merged
merged 1 commit into from
Jan 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ private ResPackage readTablePackage() throws IOException, AndrolibException {
}

String name = mIn.readNullEndedString(128, true);
/* typeStrings */mIn.skipInt();
/* lastPublicType */mIn.skipInt();
/* keyStrings */mIn.skipInt();
/* lastPublicKey */mIn.skipInt();
mIn.skipInt(); // typeStrings
mIn.skipInt(); // lastPublicType
mIn.skipInt(); // keyStrings
mIn.skipInt(); // lastPublicKey

// TypeIdOffset was added platform_frameworks_base/@f90f2f8dc36e7243b85e0b6a7fd5a590893c827e
// which is only in split/new applications.
Expand Down Expand Up @@ -191,7 +191,7 @@ private void readOverlaySpec() throws AndrolibException, IOException {

private void readOverlayPolicySpec() throws AndrolibException, IOException {
checkChunkType(Header.XML_TYPE_OVERLAY_POLICY);
/* policyFlags */mIn.skipInt();
mIn.skipInt(); // policyFlags
int count = mIn.readInt();

for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -245,7 +245,7 @@ private ResTypeSpec readSingleTableTypeSpec() throws AndrolibException, IOExcept
mFlagsOffsets.add(new FlagsOffset(mCountIn.getCount(), entryCount));
}

/* flags */mIn.skipBytes(entryCount * 4);
mIn.skipBytes(entryCount * 4); // flags
mTypeSpec = new ResTypeSpec(mTypeNames.getString(id - 1), mResTable, mPkg, id, entryCount);
mPkg.addType(mTypeSpec);
return mTypeSpec;
Expand All @@ -260,7 +260,7 @@ private ResType readTableType() throws IOException, AndrolibException {
}

int typeFlags = mIn.readByte();
/* reserved */mIn.skipBytes(2);
mIn.skipBytes(2); // reserved
int entryCount = mIn.readInt();
int entriesStart = mIn.readInt();
mMissingResSpecMap = new LinkedHashMap();
Expand Down Expand Up @@ -396,8 +396,8 @@ private ResBagValue readComplexEntry() throws IOException, AndrolibException {
}

private ResIntBasedValue readValue() throws IOException, AndrolibException {
/* size */mIn.skipCheckShort((short) 8);
/* zero */mIn.skipCheckByte((byte) 0);
mIn.skipCheckShort((short) 8); // size
mIn.skipCheckByte((byte) 0); // zero
byte type = mIn.readByte();
int data = mIn.readInt();

Expand All @@ -408,35 +408,61 @@ private ResIntBasedValue readValue() throws IOException, AndrolibException {

private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
int size = mIn.readInt();
int read = 28;
int read = 8;

if (size < 28) {
throw new AndrolibException("Config size < 28");
if (size < 8) {
throw new AndrolibException("Config size < 8");
}

boolean isInvalid = false;

short mcc = mIn.readShort();
short mnc = mIn.readShort();

char[] language = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), 'a');
char[] country = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), '0');
char[] language = new char[0];
char[] country = new char[0];
if (size >= 12) {
language = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), 'a');
country = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), '0');
read = 12;
}

byte orientation = mIn.readByte();
byte touchscreen = mIn.readByte();
byte orientation = 0;
byte touchscreen = 0;
if (size >= 14) {
orientation = mIn.readByte();
touchscreen = mIn.readByte();
read = 14;
}

int density = mIn.readUnsignedShort();
int density = 0;
if (size >= 16) {
density = mIn.readUnsignedShort();
read = 16;
}

byte keyboard = mIn.readByte();
byte navigation = mIn.readByte();
byte inputFlags = mIn.readByte();
/* inputPad0 */mIn.skipBytes(1);
byte keyboard = 0;
byte navigation = 0;
byte inputFlags = 0;
if (size >= 20) {
keyboard = mIn.readByte();
navigation = mIn.readByte();
inputFlags = mIn.readByte();
mIn.skipBytes(1); // inputPad0
read = 20;
}

short screenWidth = mIn.readShort();
short screenHeight = mIn.readShort();
short screenWidth = 0;
short screenHeight = 0;
short sdkVersion = 0;
if (size >= 28) {
screenWidth = mIn.readShort();
screenHeight = mIn.readShort();

short sdkVersion = mIn.readShort();
/* minorVersion, now must always be 0 */mIn.skipBytes(2);
sdkVersion = mIn.readShort();
mIn.skipBytes(2); // minorVersion
read = 28;
}

byte screenLayout = 0;
byte uiMode = 0;
Expand Down