Punch holes in extra field in local headers inside apk
Apk files are essentially zip files. Zip files contain
central directory which has local file header offsets.
Local file header contains 'extra' field and its length info.
This info can be seen with zipinfo -v <apk_name>
Example zip entry:
Central directory entry #3:
---------------------------
lib/x86_64/libpunchtest.so
offset of local header from start of archive: 202
(00000000000000CAh) bytes
file system or operating system of origin: Unix
version of encoding software: 1.0
minimum file system compatibility required: MS-DOS, OS/2 or NT FAT
minimum software version required to extract: 1.0
compression method: none (stored)
file security status: not encrypted
extended local header: no
file last modified on (DOS date/time): 2009 Jan 1 00:00:00
32-bit CRC value (hex): 1f180260
compressed size: 133376 bytes
uncompressed size: 133376 bytes
length of filename: 26 characters
length of extra field: 16126 bytes
length of file comment: 0 characters
Note the length of extra field which is 16126.
Extra field is followed by actual content of the zip entry.
When aligning Apks, Alignment tool add padding inside extra field so that
uncompressed shared libs are page aligned. ZipFileRO already provides
offset to content of a zip entry. For uncompressed libs, padding can be found
by going to the start of the extra field and looking for zero ranges.
This ranges are punched with help of fallocate(2)
Size before punching holes st_blocks: 1832, st_blksize: 4096, st_size: 1058429
Size after punching holes st_blocks: 1808, st_blksize: 4096, st_size: 1058429
Test: acloud delete --all && m && acloud create --local-instance --local-image && adb logcat -c && m FileSystemUtilsTests && atest -c FileSystemUtilsTests
Bug: 301631861
Change-Id: I35ac4a061828d84401d6f2d38ceb5b1a6907c00a
3 files changed