Files
reverse-engineering-anything/docs/android-boot-image.md
T
3e8f6a43a9 feat(artifacts): decode Android Verified Boot vbmeta images offline (#13239)
* feat(artifacts): decode Android Verified Boot vbmeta images offline

* fix(artifacts): locate vbmeta tail-length failures at their length fields

* fix(artifacts): make vbmeta admission budgets adjustable per call

* fix(firmware): refuse vbmeta fields too long to hex-encode

With raised descriptor_bytes and auxiliary_block_bytes limits, a valid
KERNEL_CMDLINE longer than half the host string bound passed the byte
limits, and toString("hex") then threw ERR_STRING_TOO_LONG, which
surfaced as an I/O error. Check the field against the host bound before
hex encoding and report a typed capacity failure with its own limit.

* fix(firmware): check vbmeta extents before admission budgets

A header whose declared blocks do not fit the file, or whose descriptor
range does not fit its auxiliary block, now reports truncation or a
malformed range instead of a limit a larger budget cannot repair. The
over-budget fixtures are now fully present so they still prove the limit.

* perf(firmware): count vbmeta descriptor tags in one pass and reuse readers

The summary counts every descriptor tag in a single loop instead of six
filtered arrays, and androidVbmeta reuses one BinaryReader per buffer.
The malformed-header refusal fixtures follow main's unsupported_target
classification for malformed target bytes.

* chore: regenerate advertised schema hash after merging main

* docs(android-vbmeta): name unsupported_target for structural refusals

Malformed vbmeta headers classify as unsupported_target, not
invalid_request, matching analysisErrorClassification and the refusal
fixtures.

* chore: regenerate advertised schema hashes after merging main

* chore: regenerate advertised schema hashes after merging main

* fix: restore Android vbmeta artifact reader after merging main

* test(artifacts): expect partial for the CLI vbmeta descriptor refusal

* feat(artifacts): preserve vbmeta descriptor bytes and partial refusals

Co-authored-by: iamcipherdev <268238676+iamcipherdev@users.noreply.github.com>

* fix(artifacts): use Buffer.equals in vbmeta tests and update advertised schema summaries

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Matt Van Horn <mvanhorn@MacBook-Pro-10.local>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Co-authored-by: iamcipherdev <268238676+iamcipherdev@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-26 20:05:59 +00:00

6.5 KiB

Android boot and vendor_boot images

inspect-artifact and extract-artifact recognize ANDROID! boot images (header versions 0 through 4) and VNDRBOOT vendor_boot images (header versions 3 and 4) regardless of filename. They read local stored bytes without booting, executing, decompressing, or modifying the image.

The same header facts and artifact reader serve CLI and MCP. The root is an archive with unknown executable architecture. ANDROID! covers boot, init_boot, and recovery images; the header does not record which role the file had.

Header facts

Versions 0 through 2 store a page size from 2048 through 65536, a power of two. The header occupies the first page. Kernel, ramdisk, and second stage follow, each padded up to the next page. Version 1 adds a recovery DTBO at a page-aligned file offset. Version 2 adds a DTB after that offset. The 32-byte header digest is recorded and not checked.

Versions 3 and 4 use a fixed 4096-byte page. The kernel and ramdisk follow the header page. Version 4 can append a signature. That signature is a stored range with a size. It is not verified.

Vendor_boot versions 3 and 4 record the kernel, ramdisk, and tags load addresses, the board name, a 2048-byte command line, the vendor ramdisk, and a DTB. Version 3 exposes one vendor_ramdisk child when that section is non-empty. Version 4 exposes each ramdisk table entry as vendor_ramdisk/<name>, then the DTB, then bootconfig. The table itself is not a child. Each entry is at least the 108-byte v4 structure: size, offset, type, a 32-byte name, and 16 board-id words. A larger entry_size keeps those fields and leaves the trailing bytes undecoded. Entry names that are empty, ., .., or contain / become ramdisk-<index>. A repeated name gains -<index>. If that name is already used, the suffix gains another number until the path is unique.

OS version and security patch level are decoded from the packed os_version word. A month outside 1 through 12 leaves the patch level null and keeps the raw word. Vendor_boot has no OS version field.

Command line, board name, and vendor ramdisk names are target-derived and untrusted. Versions 0 through 2 concatenate cmdline and extra_cmdline with no separator. Versions 3 and 4 store one combined command line. Invalid UTF-8 stays null and the raw field bytes are kept as hex.

Children

Non-empty components become children:

Path Role
kernel kernel
ramdisk ramdisk
second second stage
recovery_dtbo recovery DTBO
dtb devicetree blob
vendor_ramdisk version 3 vendor ramdisk section
vendor_ramdisk/<name> version 4 ramdisk table entry
bootconfig bootconfig
signature version 4 boot signature

The header and the version 4 ramdisk table are read as metadata, not children. Every other declared range of the image layout must be a child for coverage to be complete. A vendor ramdisk section that the version 4 table entries do not cover, or bytes between the sequential layout and a version 1 or 2 recovery_dtbo, leave coverage unknown with a limitation naming them.

A child whose first bytes match gzip (1f 8b), an lz4 frame (04 22 4d 18), legacy lz4 (02 21 4c 18), or zstd (28 b5 2f fd) records that compression. Other prefixes stay unknown, which does not prove the bytes are uncompressed. Nothing in this reader decompresses a payload. A kernel that starts with the ELF magic is classified as elf by the existing content check. A dtb child stays a file; extract it and run inspect-devicetree on the extracted file.

The reader checks the final 64 bytes for an AVBf footer when those bytes begin at or after the end of the last declared image component, even if they start before the page-rounded image end. A matching footer records its version, original image size, and vbmeta offset and size. The footer and the embedded vbmeta remain unverified metadata; this reader does not decode that vbmeta. A standalone vbmeta.img is a separate AVB0 image. See Android Verified Boot vbmeta images. If no footer is recognized, the reader reports undecoded trailing bytes beyond the page-rounded image end. A vbmeta range that overlaps the header, a component, or the footer is malformed.

Bounded work

The reader admits at most 4,096 vendor ramdisk table entries and an entry size of at most 4,096 bytes. It verifies that the table dimensions agree and the declared bytes fit in the image before applying those limits and reading the table. A vendor header_size above 1 MiB also exceeds a capacity limit. Unsupported header revisions, truncated declared structures and malformed layouts all return unsupported_target. Truncated and malformed refusals carry details.failure_kind (truncated or malformed), details.format (android-boot-image) and, when the parser names them, details.offset and details.field. The page padding after the last component carries no data and may be absent. These refusals do not produce an empty successful inventory. Gaps inside a vendor ramdisk section, or bytes between the sequential layout and a recovery DTBO, are named in limitations instead of being invented as entries.

rea inspect-artifact boot.img --detail summary \
  --evidence_output boot.evidence.json --json
rea extract-artifact vendor_boot.img --json

With MCP, inspect_artifact with detail: "summary" retains the complete Evidence. Use inspect_analysis_view and its parent_evidence_id for exact logical paths, batches of occurrence/content IDs, selected fields and pages.

Verification scope

Source and compiled CLI/MCP tests cover stored component bytes, compression magics, unsupported revisions, truncation, overlapping ranges, capacity, cancellation, and cleanup. An independent offline check used AOSP mkbootimg.py and unpack_bootimg.py at commit d2bb0af5ba6d3198a3e99529c97eda1be0b5a093: boot versions 0 through 4 and vendor_boot versions 3 and 4 had component ranges and digests matching their small inert input files and official unpacked output. Version 4 vendor_boot extraction also matched those inputs. No device-dumped image, signature verification, AVB digest verification, or payload decompression was checked.