Skip to content

Commit

Permalink
Merge branch 'master' into streamline_decode_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches authored Jul 23, 2023
2 parents 7564bc4 + d1a0c94 commit 7ead27a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class ResConfigFlags {
private final byte screenLayout2;
private final byte colorMode;

private final char[] localeNumberingSystem;

public final boolean isInvalid;

private final String mQualifiers;
Expand Down Expand Up @@ -80,6 +82,7 @@ public ResConfigFlags() {
localeVariant = null;
screenLayout2 = 0;
colorMode = COLOR_WIDE_UNDEFINED;
localeNumberingSystem = null;
isInvalid = false;
mQualifiers = "";
size = 0;
Expand All @@ -92,7 +95,8 @@ public ResConfigFlags(short mcc, short mnc, char[] language,
short sdkVersion, byte screenLayout, byte uiMode,
short smallestScreenWidthDp, short screenWidthDp,
short screenHeightDp, char[] localeScript, char[] localeVariant,
byte screenLayout2, byte colorMode, boolean isInvalid, int size) {
byte screenLayout2, byte colorMode, char[] localeNumberingSystem,
boolean isInvalid, int size) {
if (orientation < 0 || orientation > 3) {
LOGGER.warning("Invalid orientation value: " + orientation);
orientation = 0;
Expand Down Expand Up @@ -157,6 +161,7 @@ public ResConfigFlags(short mcc, short mnc, char[] language,
this.localeVariant = localeVariant;
this.screenLayout2 = screenLayout2;
this.colorMode = colorMode;
this.localeNumberingSystem = localeNumberingSystem;
this.isInvalid = isInvalid;
this.size = size;
mQualifiers = generateQualifiers();
Expand Down Expand Up @@ -466,6 +471,12 @@ private String getLocaleString() {
if (localeVariant != null && localeVariant.length >= 5) {
sb.append("+").append(toUpper(localeVariant));
}

// If we have a numbering system - it isn't used in qualifiers for build tools, but AOSP understands it
// So chances are - this may be valid, but aapt 1/2 will not like it.
if (localeNumberingSystem != null && localeNumberingSystem.length > 0) {
sb.append("+u+nu+").append(localeNumberingSystem);
}
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
char[] localeScript = null;
char[] localeVariant = null;
if (size >= 48) {
localeScript = readScriptOrVariantChar(4).toCharArray();
localeVariant = readScriptOrVariantChar(8).toCharArray();
localeScript = readVariantLengthString(4).toCharArray();
localeVariant = readVariantLengthString(8).toCharArray();
read = 48;
}

Expand All @@ -511,16 +511,16 @@ private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
read = 52;
}

if (size > 52) {
int length = size - read;
mIn.skipBytes(length); // localeNumberingSystem
read += length;
char[] localeNumberingSystem = null;
if (size >= 60) {
localeNumberingSystem = readVariantLengthString(8).toCharArray();
read = 60;
}

int exceedingSize = size - KNOWN_CONFIG_BYTES;
if (exceedingSize > 0) {
byte[] buf = new byte[exceedingSize];
read += exceedingSize;
int exceedingKnownSize = size - KNOWN_CONFIG_BYTES;
if (exceedingKnownSize > 0) {
byte[] buf = new byte[exceedingKnownSize];
read += exceedingKnownSize;
mIn.readFully(buf);
BigInteger exceedingBI = new BigInteger(1, buf);

Expand All @@ -545,7 +545,7 @@ private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
inputFlags, screenWidth, screenHeight, sdkVersion,
screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp,
screenHeightDp, localeScript, localeVariant, screenLayout2,
colorMode, isInvalid, size);
colorMode, localeNumberingSystem, isInvalid, size);
}

private char[] unpackLanguageOrRegion(byte in0, byte in1, char base) {
Expand All @@ -562,17 +562,17 @@ private char[] unpackLanguageOrRegion(byte in0, byte in1, char base) {
return new char[] { (char) in0, (char) in1 };
}

private String readScriptOrVariantChar(int length) throws IOException {
private String readVariantLengthString(int maxLength) throws IOException {
StringBuilder string = new StringBuilder(16);

while (length-- != 0) {
while (maxLength-- != 0) {
short ch = mIn.readByte();
if (ch == 0) {
break;
}
string.append((char) ch);
}
mIn.skipBytes(length);
mIn.skipBytes(maxLength);

return string.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public void valuesMaxLengthTest() throws BrutException {
compareValuesFiles("values-es/strings.xml");
}

@Test
public void valuesBcp47LanguageVariantTest() throws BrutException {
compareValuesFiles("values-b+iw+660/strings.xml");
}

@Test
public void valuesBcp47LanguageScriptRegionVariantTest() throws BrutException {
compareValuesFiles("values-b+ast+Latn+IT+AREVELA/strings.xml");
compareValuesFiles("values-b+ast+Hant+IT+ARABEXT/strings.xml");
}

@Test
public void confirmZeroByteFileExtensionIsNotStored() throws BrutException {
ApkInfo apkInfo = ApkInfo.load(sTestNewDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">testapp</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">testapp</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">testapp</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">testapp</string>
</resources>

0 comments on commit 7ead27a

Please sign in to comment.