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 disassembly of WhatsApp w/ un-ordered resources. #3799

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

iBotPeaches
Copy link
Owner

@iBotPeaches iBotPeaches commented Feb 2, 2025

Fixes #3778.

It was noticed that resources were crashing out during disassembly. It seemed a premature exit, but instead the offsets were behind the current location in the stream. Apktool historically had always read entries in order and for the better part of a decade - that worked.

Recently (years ago) obfuscation techniques led Apktool to leveraging a buffered stream alongside a counting stream to properly detect positions in a chunk for skipping, etc. This allowed Apktool to check its current position in order to skip bytes to re-align itself for parsing.

These applications required rewinding the location to the beginning of the chunk so the offset could be properly skipped towards it. So this made a few changes:

  • We start a buffered stream as we enter the TYPE chunk (mark)
  • If our expected entry start is behind our current position we reset and jump back (reset)
  • We continue on.

This seemed valid in theory, but failed in actuality because Apktool offsets for sparse/16bit had been broken since introduction in early 2023. This meant as this patch had put a dependency on valid offsets so it could properly skip meant it exposed a flaw that offsets were encoded improperly.

Changes:

  • Remove manual alignment to beginning of entry chunk (because we have a jumpTo now)
  • Rename readEntry to parseEntryData because read suggests reading data from stream, which it does not
  • Automatically reset stream to mark point (beginning of chunk) if offset is behind current location
  • Correct 16bit offset storage to store real offset (offset * 4u)
  • Correct an NPE for serializing null

@iBotPeaches iBotPeaches marked this pull request as ready for review February 3, 2025 02:06
@iBotPeaches iBotPeaches merged commit dc324b1 into master Feb 3, 2025
25 checks passed
@iBotPeaches iBotPeaches deleted the apktool-3778 branch February 3, 2025 11:08
iBotPeaches added a commit that referenced this pull request Feb 3, 2025
@iBotPeaches iBotPeaches added this to the v2.11.1 milestone Feb 3, 2025
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.

[BUG] Several resources are missing (skipped)
1 participant