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

fix: accept empty resources.arsc #2998

Merged
merged 2 commits into from
Feb 19, 2023
Merged

fix: accept empty resources.arsc #2998

merged 2 commits into from
Feb 19, 2023

Conversation

IgorEisberg
Copy link
Contributor

Apktool treats APKs with stub resources.arsc like criminals:

I: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: arsc files with zero packages or no arsc file found.
        at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:84)
        at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:56)
        at brut.androlib.Androlib.getResTable(Androlib.java:74)
        at brut.androlib.ApkDecoder.getResTable(ApkDecoder.java:270)
        at brut.androlib.ApkDecoder.decode(ApkDecoder.java:110)
        at brut.apktool.Main.cmdDecode(Main.java:175)
        at brut.apktool.Main.main(Main.java:79)

But in fact, those APKs are valid and very common among overlay APKs, but here's a non-overlay example as well:
https://drive.google.com/file/d/1seAnndB9cH6_qo04FC7_1JPW5CVXLMnt/view

This change creates a "fake ResPackage", exactly as done in decodeManifest, if resources.arsc was loaded but contains 0 packages.
The output is valid and recompilation already produces an identical 40 bytes stub resources.arsc without any additional changes needed.

P.S. also fixed a few missing spaces for cleanliness.

iBotPeaches
iBotPeaches previously approved these changes Feb 18, 2023
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.

Thanks. Looks good.

@IgorEisberg
Copy link
Contributor Author

A note to anyone who plans to inject any resources to a empty APK like that:
By being empty, these packages don't have a package ID at all, so you'll see this in apktool.yml:

packageInfo: null

If you plan on adding resources and naturally your resource IDs are prefixed with package ID 0x7f, you'll have to update this line in apktool.yml to:

packageInfo:
  forcedPackageId: '127'
  renameManifestPackage: null

@IgorEisberg
Copy link
Contributor Author

Small tweak to make sure apktool.yml doesn't falsely state "isFrameworkApk: true" when it should be "false" for empty packages.

@iBotPeaches iBotPeaches merged commit 1206118 into iBotPeaches:master Feb 19, 2023
iBotPeaches added a commit that referenced this pull request Feb 19, 2023
@iBotPeaches
Copy link
Owner

thanks again - merged/changelog updated.

@iBotPeaches iBotPeaches added this to the v2.8.0 milestone Jul 16, 2023
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.

None yet

2 participants