Skip to content

Conversation

@IgorEisberg
Copy link
Collaborator

@IgorEisberg IgorEisberg commented Dec 16, 2025

Fixed decoding for #4051.

The only persisting part of a standard 64-byte res config are the first 52 bytes.
The last 12 bytes are expected to be empty; they are later populated by Android.
Some vendors, like Motorola, are using these extra bytes for their own customized aapt, and also a res config size of 76 bytes.
We handle the 52 standard bytes, and everything after that is expected to be empty bytes, otherwise we make a unique config marked as invalid and named -unk<hash of unknown bytes>. Using a hash ensures resources with the same unknown bytes are grouped together.
Resources with these configs can't be rebuilt by any public aapt2 and are normally dropped (with proper logging).
To preserve them for whatever reason, --keep-broken-res can be used.

With the broken resources excluded, the resulting output can be rebuilt normally.
No changes for APKs with standard res configs.

Example output for the Motorola framework-res.apk from the issue mentioned above:

I: Using Apktool 3.0.0-SNAPSHOT on framework-res.apk with 8 threads
I: Loading resource table...
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-en-rXA-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-en-rXA-neuter-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-en-rXA-feminine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-en-rXA-masculine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-ar-rXB-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-ar-rXB-neuter-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-ar-rXB-feminine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc240-ar-rXB-masculine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-en-rXA-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-en-rXA-neuter-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-en-rXA-feminine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-en-rXA-masculine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-ar-rXB-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-ar-rXB-neuter-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-ar-rXB-feminine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000008FE1180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc260-ar-rXB-masculine-unkCBCC099B]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc311-mnc480-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc590-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc591-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc592-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc593-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc594-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc595-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc596-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc597-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc598-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: string [mcc310-mnc599-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000002000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: dimen [unk475408BF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000003000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: dimen [unk28E5E69E]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000004000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: dimen [unk0A77C47D]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000002000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: color [unk475408BF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000001666221400000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc204-mnc04-unkC6A10C43]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000003106000000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc525-mnc05-unkAC289FB6]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000100C000000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc234-mnc30-unkA24A47FD]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000001FD2E0000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc330-mnc110-unk55099FAF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000CEDD180000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc260-unk95F643F8]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000005E21190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc260-unk46D2B2CB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000001FD2E0000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc260-unk55099FAF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000DC51190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk36962ABD]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000E051190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkD51D8439]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000005C59190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk74D46845]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000006459190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkB1E31B3D]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000001D5D190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkAAAA2DE8]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000235D190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk18753422]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000255D190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkE7B8E0E0]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000E060190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkE2193E88]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000E460190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk80A09804]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000E660190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk4FE444C2]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000009F64190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk48AB576D]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000A564190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkB6765DA7]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000A764190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk85BA0A65]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000039C6190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unkB0DDF775]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000BBCD190000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc313-mnc340-unk4EDF20FA]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc311-mnc480-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc590-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc591-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc592-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc593-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc594-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc595-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc596-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc597-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc598-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 0000000085101A3900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: array [mcc310-mnc599-unk00B7CECB]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000002000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: drawable [unk475408BF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000000000000002000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: layout [unk475408BF]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: ED0C00000000000000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc466-mnc01-unk4A65E180]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 000000001666221400000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc204-mnc04-unkC6A10C43]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 086AAC090000000000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc204-mnc04-unk6A459E40]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000C63D757900000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc234-mnc30-unk02154D1C]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000EEB8170000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc310-mnc240-unk0BFF0CD4]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000D3091A0000000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc310-mnc240-unkFE8C053D]
W: Config size: 76 bytes, read: 52 bytes. Exceeding bytes: 00000000C1F5B31E00000000000000000000000000000000
W: Invalid resource config detected. Dropping resources: bool [mcc311-mnc480-unk01115920]
I: Decoding value resources...
I: Decoding file resources...
I: Generating values XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Copying original files...
I: Copying assets...
I: Copying unknown files...

@IgorEisberg IgorEisberg enabled auto-merge (squash) December 16, 2025 20:02
@iBotPeaches
Copy link
Owner

Is this the end of BCP47 support? Can you point me to where aapt/2 gave that up?

@IgorEisberg
Copy link
Collaborator Author

Is this the end of BCP47 support? Can you point me to where aapt/2 gave that up?

No, BCP47 works fine, but numbering system is not supported in BCP47 in resource dir names.
Only language, script, region and variant are allowed:
https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/libs/androidfw/Locale.cpp;l=139;drc=61197364367c9e404c7da6900658f1b16c42d0da
So the bytes after the first 52-bytes are never filled on standard APKs, despite keeping the 64-byte config size (probably since it's serialized from a fixed struct). Even if they were filled - we could not have used that data since aapt2 doesn't read numbering system in BCP47 tags.

Copy link
Owner

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to keep commented out code. If we removed some chunks, might as well remove the rest instead of keeping it around in a comment.

@IgorEisberg
Copy link
Collaborator Author

I don't think we need to keep commented out code. If we removed some chunks, might as well remove the rest instead of keeping it around in a comment.

Fine by me, cleaned.

@iBotPeaches iBotPeaches added this to the 3.0.0 milestone Dec 17, 2025
@IgorEisberg IgorEisberg merged commit ee970f5 into main Dec 17, 2025
18 checks passed
@IgorEisberg IgorEisberg deleted the unk-res-cfg branch December 17, 2025 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants