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: crash when decompiling framework-res.apk with a tag (regression) #3193

Merged
merged 1 commit into from
Jul 22, 2023
Merged

Conversation

IgorEisberg
Copy link
Contributor

@IgorEisberg IgorEisberg commented Jul 22, 2023

This fixes a regression since 2.8.0 that causes apktool to crash when decompiling framework-res.apk (which has no other framework dependencies) with the -t tag option:

$ java -jar apktool.jar d -f -t mytag framework-res.apk -o framework-res
I: Using Apktool 2.8.1-SNAPSHOT on framework-res.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
Exception in thread "main" java.lang.NullPointerException
        at brut.androlib.res.ResourcesDecoder.decodeResources(ResourcesDecoder.java:247)
        at brut.androlib.ApkDecoder.decode(ApkDecoder.java:98)
        at brut.apktool.Main.cmdDecode(Main.java:190)
        at brut.apktool.Main.main(Main.java:93)

This is caused by the fact that mApkInfo.usesFramework is null if there are no framework dependencies for a given APK (which is true for any base framework, i.e. framework-res.apk), and then doing mApkInfo.usesFramework.tag = mConfig.frameworkTag; in ResourcesDecoder, causing a NullPointerException.
How wasn't it caught during development? Perhaps due to the previous framework loading regression that recently got fixed, that loaded frameworks with arbitrary IDs, which caused UsesFramework to always be created because ids array was never empty, even when it should have been.
And so:

  1. There is no good reason not to always create a UsesFramework object, regardless of content.
  2. There is no good reason to set the tag in ResourcesDecoder.decodeResources rather than ResTable.initApkInfo that has reference to the Config object as well.
  3. There is also no need for null-checking mConfig.frameworkTag, because if it's null then info.tag (which is already null by default) will simply be set to null again.

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. appears my smoke test of decoding a basic framework failed since I didn't use -t

@iBotPeaches iBotPeaches merged commit 24b0c32 into iBotPeaches:master Jul 22, 2023
31 checks passed
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