Skip to content

Commit 0a3c759

Browse files
authored
feat: support config flags as low as 8 bytes (#2982)
1 parent a73ace2 commit 0a3c759

File tree

1 file changed

+51
-25
lines changed
  • brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder

1 file changed

+51
-25
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ private ResPackage readTablePackage() throws IOException, AndrolibException {
103103
}
104104

105105
String name = mIn.readNullEndedString(128, true);
106-
/* typeStrings */mIn.skipInt();
107-
/* lastPublicType */mIn.skipInt();
108-
/* keyStrings */mIn.skipInt();
109-
/* lastPublicKey */mIn.skipInt();
106+
mIn.skipInt(); // typeStrings
107+
mIn.skipInt(); // lastPublicType
108+
mIn.skipInt(); // keyStrings
109+
mIn.skipInt(); // lastPublicKey
110110

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

192192
private void readOverlayPolicySpec() throws AndrolibException, IOException {
193193
checkChunkType(Header.XML_TYPE_OVERLAY_POLICY);
194-
/* policyFlags */mIn.skipInt();
194+
mIn.skipInt(); // policyFlags
195195
int count = mIn.readInt();
196196

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

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

262262
int typeFlags = mIn.readByte();
263-
/* reserved */mIn.skipBytes(2);
263+
mIn.skipBytes(2); // reserved
264264
int entryCount = mIn.readInt();
265265
int entriesStart = mIn.readInt();
266266
mMissingResSpecMap = new LinkedHashMap();
@@ -396,8 +396,8 @@ private ResBagValue readComplexEntry() throws IOException, AndrolibException {
396396
}
397397

398398
private ResIntBasedValue readValue() throws IOException, AndrolibException {
399-
/* size */mIn.skipCheckShort((short) 8);
400-
/* zero */mIn.skipCheckByte((byte) 0);
399+
mIn.skipCheckShort((short) 8); // size
400+
mIn.skipCheckByte((byte) 0); // zero
401401
byte type = mIn.readByte();
402402
int data = mIn.readInt();
403403

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

409409
private ResConfigFlags readConfigFlags() throws IOException, AndrolibException {
410410
int size = mIn.readInt();
411-
int read = 28;
411+
int read = 8;
412412

413-
if (size < 28) {
414-
throw new AndrolibException("Config size < 28");
413+
if (size < 8) {
414+
throw new AndrolibException("Config size < 8");
415415
}
416416

417417
boolean isInvalid = false;
418418

419419
short mcc = mIn.readShort();
420420
short mnc = mIn.readShort();
421421

422-
char[] language = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), 'a');
423-
char[] country = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), '0');
422+
char[] language = new char[0];
423+
char[] country = new char[0];
424+
if (size >= 12) {
425+
language = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), 'a');
426+
country = this.unpackLanguageOrRegion(mIn.readByte(), mIn.readByte(), '0');
427+
read = 12;
428+
}
424429

425-
byte orientation = mIn.readByte();
426-
byte touchscreen = mIn.readByte();
430+
byte orientation = 0;
431+
byte touchscreen = 0;
432+
if (size >= 14) {
433+
orientation = mIn.readByte();
434+
touchscreen = mIn.readByte();
435+
read = 14;
436+
}
427437

428-
int density = mIn.readUnsignedShort();
438+
int density = 0;
439+
if (size >= 16) {
440+
density = mIn.readUnsignedShort();
441+
read = 16;
442+
}
429443

430-
byte keyboard = mIn.readByte();
431-
byte navigation = mIn.readByte();
432-
byte inputFlags = mIn.readByte();
433-
/* inputPad0 */mIn.skipBytes(1);
444+
byte keyboard = 0;
445+
byte navigation = 0;
446+
byte inputFlags = 0;
447+
if (size >= 20) {
448+
keyboard = mIn.readByte();
449+
navigation = mIn.readByte();
450+
inputFlags = mIn.readByte();
451+
mIn.skipBytes(1); // inputPad0
452+
read = 20;
453+
}
434454

435-
short screenWidth = mIn.readShort();
436-
short screenHeight = mIn.readShort();
455+
short screenWidth = 0;
456+
short screenHeight = 0;
457+
short sdkVersion = 0;
458+
if (size >= 28) {
459+
screenWidth = mIn.readShort();
460+
screenHeight = mIn.readShort();
437461

438-
short sdkVersion = mIn.readShort();
439-
/* minorVersion, now must always be 0 */mIn.skipBytes(2);
462+
sdkVersion = mIn.readShort();
463+
mIn.skipBytes(2); // minorVersion
464+
read = 28;
465+
}
440466

441467
byte screenLayout = 0;
442468
byte uiMode = 0;

0 commit comments

Comments
 (0)