Fix disassembly of WhatsApp w/ un-ordered resources. #3799
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
readEntry
toparseEntryData
becauseread
suggests reading data from stream, which it does not