Commit Graph

79 Commits

Author SHA1 Message Date
topjohnwu
f4ed6274a4 Invert vbmeta header patching config
vbmeta header should not be patched in most cases
2021-12-14 04:52:25 -08:00
topjohnwu
1443a5b175 Use mmap_data more widely 2021-11-30 01:50:55 -08:00
topjohnwu
2d82ad93dd Macro -> template 2021-11-29 19:56:37 -08:00
topjohnwu
0a28dfe1e2 AVB blobs expect to be 4096-byte aligned 2021-11-28 13:21:05 -08:00
topjohnwu
228570640e Introduce KEEPVBMETAFLAG env variable
Close #4447, close #4906, close #4901, close #4964
2021-11-23 22:14:12 -08:00
topjohnwu
24984ea4f2 Optimize stream for full-file writes 2021-11-23 18:08:14 -08:00
topjohnwu
449989ddd9 Always use zopfli for zImage compression 2021-11-23 14:24:05 -08:00
topjohnwu
01ebe5724a Cleanup zImage parsing code 2021-11-23 13:39:15 -08:00
topjohnwu
632971af15 Properly support v4 image headers 2021-11-21 06:07:21 -08:00
topjohnwu
9ea3169ca9 Do not allow modifying page sizes 2021-11-20 22:51:22 -08:00
topjohnwu
aebf2672cd Fix unpacking vendor boot images 2021-11-20 22:44:38 -08:00
topjohnwu
528601d25a Fix integer overflow and workaround seccomp
- Use ftruncate64 instead of ftruncate to workaround seccomp
- Cast uint32_t to off64_t before making it negative

Note: Using ftruncate with a modern NDK libc should actually be
fine as the syscall wrapper in bionic will use ftruncate64 internally.
However, since we are using the libc.a from r10e built for Gingerbread,
seccomp wasn't a thing back then, and also the ftruncate64 symbol is
missing; we have to create our own wrapper and call it instead on
32-bit ABIs.

Props to @jnotuo for discovering the overflow bug and seccomp issue

Fix #3703, close #4915
2021-11-10 03:07:20 -08:00
Chaosmaster
16322ab30c Use full gzip-signature to find gzip-data.
Fall back to raw image if gzip is not found.

Fixes #4849
2021-11-03 22:23:21 -07:00
topjohnwu
84e19ceef0 Tidy up bootimg.h
Close #4796
2021-10-31 10:52:12 -07:00
vvb2060
439d497a13 boot image header v4 2021-08-29 03:14:23 -07:00
topjohnwu
34e5a7cd24 Zopfli is not always smaller 2021-08-28 17:16:20 -07:00
topjohnwu
0af041b54e Cleanup magiskboot code 2021-08-28 14:07:34 -07:00
Chaosmaster
f41575d8b0 Add support for legacy ARM32 zImage 2021-08-28 10:53:45 -07:00
topjohnwu
7df23ceb74 Prevent undefined behavior in magiskboot 2021-05-10 18:38:30 -07:00
Shaka Huang
e3801d6965
Fix overflow
`totalsize` might be a big (invalid) number so instead of checking the end address we check the size of the image.

Fix #4049
2021-03-24 03:02:46 -07:00
topjohnwu
027ec70262 Patch AVB structures
Disable vbmeta verification in flags
2021-03-02 20:37:37 -08:00
topjohnwu
55fdee4d65 Use memmem for searching byte patterns 2021-02-28 14:37:12 -08:00
topjohnwu
0d42f937dd Refactor magiskboot 2021-02-28 14:37:12 -08:00
topjohnwu
aec06a6f61 Get proper total image size 2021-01-14 03:55:27 -08:00
topjohnwu
f9bde347bc Convert indentation to spaces
The tab war is lost
2020-12-30 22:11:24 -08:00
topjohnwu
552ec1eb35 Header v3 does not have name entry 2020-11-20 22:52:09 -08:00
topjohnwu
02ea3ca525 Headers doesn't always occupy 1 page 2020-10-25 06:25:42 -07:00
topjohnwu
0632b146b8 Add vendor boot image support to magiskboot 2020-10-25 06:09:36 -07:00
topjohnwu
aaaaa3d044 Minor refactoring 2020-10-15 00:19:11 -07:00
topjohnwu
f3cd4da026 Make lz4_lg an exception of lz4_legacy 2020-10-14 23:45:06 -07:00
topjohnwu
339ca6d666 Improve magiskboot info logging 2020-10-12 01:55:33 -07:00
topjohnwu
4aeac3b8f4 Support header_version 3 2020-10-12 01:06:42 -07:00
topjohnwu
8b5652ced5 Skip image padding on Pixel C 2020-09-29 02:49:10 -07:00
topjohnwu
c91ebfbcc1 Pad images to original sizes with zero
Close #2005
2020-09-26 14:36:57 -07:00
topjohnwu
1e2f776b83 Move logging.hpp 2020-06-17 01:17:28 -07:00
osm0sis
e50295d337 magiskboot: add support for lz4 compressed dt (extra)
- legacy devices brought up to Android 10 may now use a compressed dt in a hdr_v0 AOSP dt variant extra section, so detect, decompress and recompress this
- so far these have only been done using lz4 compression (latest format revision magic), e.g. LOS 17.1 victara (Moto X)
2020-05-30 12:52:15 -07:00
topjohnwu
a0998009c1 Small native code reorganization 2020-03-09 01:50:30 -07:00
topjohnwu
78c64d39ec Add split command to magiskboot
Allow splitting image.*-dtb files to kernel and dtb
2019-12-30 13:04:39 +08:00
topjohnwu
af060b3132 General QoL changes 2019-12-13 00:37:06 -05:00
topjohnwu
01253f050a Use smart pointers 2019-11-23 04:57:52 -05:00
topjohnwu
5bee1c56a9 Properly use RAII to reduce complication 2019-11-22 03:01:49 -05:00
topjohnwu
d26d804cc2 Migrate to generic stream implementation 2019-11-21 06:08:02 -05:00
osm0sis
7f6a6016d6 magiskboot: add simple workaround for Samsung offset header variant
- some Samsung devices (e.g. Galaxy S5 SMG-900H) use a slightly different AOSP bootimg.h variant with `#define BOOT_NAME_SIZE 20` instead of 16
- since all known examples of these device images do not have anything in the NAME or CMDLINE fields, and the bootloader also accepts standard AOSP images, simply offset the SHA1/SHA256 detection by 4 bytes to avoid false positives from these images, remain an equally effective detection shortcut, and ensure a proper SHA1 checksum on repack

aosp-dtbhdt2-4offhash-seandroid-256sig-samsung_gs5-smg900h-boot.img
UNPACK CHECKSUM [00000000b11580f7d20f70297cdc31e02626def0356c82b90000000000000000]
REPACK CHECKSUM [73b18751202e56c433f89dfd1902c290eaf4eef3e167fcf03b814b59a5e984b6]
AIK CHECKSUM    [b11580f7d20f70297cdc31e02626def0356c82b9000000000000000000000000]

This patch should result in a `magiskboot unpack -n boot.img; magiskboot repack boot.img` new-boot.img matching the AIK CHECKSUM above.
2019-11-16 03:23:49 -05:00
John Wu
17a77e2577 Shortcut booleans 2019-10-31 02:44:25 -04:00
osm0sis
353c3c7d81 magiskboot: add unpack -n to help with repack validity tests
- support unpack without decompression to allow easy testing of magiskboot's header, structure and hashing handling by comparing repack checksum versus origbootimg
- make -n first to match repack
2019-10-31 02:44:25 -04:00
topjohnwu
9867a3bd60 Pedantic boot_img_hdr multi-version support 2019-10-15 01:46:29 -04:00
topjohnwu
23c1a1dab8 Some code reorganizing 2019-10-09 16:01:21 -04:00
topjohnwu
da3fd92b31 Prevent unsigned overflow
Close #1898
2019-10-08 15:55:27 -04:00
topjohnwu
f87ee3fcf9 Refactor boot image unpack/repack code base 2019-10-07 04:35:02 -04:00
topjohnwu
947dae4900 Rename classes and small adjustments 2019-09-25 23:55:39 -04:00