fix: tolerate spurious encrypted zip CEN headers on decode - #4208
Conversation
APKs that AOSP accepts can set the encrypted-entry bit (or bogus compression methods) without actually encrypting entries. java.util.zip rejects those CEN headers while libziparchive ignores them. Repair headers in a temp copy when ZipFile fails with invalid CEN header, so apktool d works on the same class of packages reported in iBotPeaches#4028. Fixes iBotPeaches#4028 Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>
Track the user path separately from the repaired zip source, delete the repair copy after decode, and set zip64 validation bypass for library entrypoints. Extend the regression test to cover apktool.yml and rebuild output naming. Signed-off-by: Atirna <288419661+atirna@users.noreply.github.com>
|
Always thought we'd need a complex return of ZipUtils, but this creation with AI might be a shortened version. |
e38997c to
f7cef94
Compare
|
yeah its a shorter path than wrapping ZipUtils. decode still repairs CEN/local flags in a temp copy when java.util.zip rejects encrypted-entry bits that AOSP accepts, then it keeps the original apkFileName for rebuild. |
|
So ultimately its a choice whether maintaining a chunk of code is worth it vs an alternative library. I'm sure @IgorEisberg has some opinions as well |
|
So here are my impressions:
|
|
If we make |
iBotPeaches
left a comment
There was a problem hiding this comment.
As discussed a bit. Onboard if we introduce a new area (brut.j.zip) and can do with no userland changes, as everything should be handled via ExtFile.
If you have to change anything elsewhere. Please let me know what led to that and why.
Description
I changed decode so apktool can open APKs that set the zip encrypted-entry bit (or bogus compression methods) without actually encrypting payload data. AOSP/libziparchive accepts those packages;
java.util.zip.ZipFilerejects them withinvalid CEN header (encrypted entry).When that happens, apktool now repairs the central-directory and local-header flags in a temp copy, keeps the original
apkFileNamefor rebuild, and deletes the repair copy after decode.Fixes #4028
Why
Malware and packer APKs that install fine on Android were failing at the first zip open during
apktool d, blocking analysis on the same samples reporters attached to #4028 and related threads.Verification
main:./gradlew :brut.apktool:apktool-lib:test --tests brut.androlib.EncryptedCenHeaderTest— test did not exist; manual corrupt-bit APK fails withZipDexContainer$NotAZipFileExceptionapktool.ymlkeepsencrypted_cen.apk+ rebuild writesdist/encrypted_cen.apk)Made with Cursor