Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Android sparse image

From ReverseEngineering.wiki
Format
Magic 3A FF 26 ED (0xED26FF3A little-endian)
Extensions .img
Endianness little
License Apache-2.0 (AOSP libsparse)
On this wiki Facts · Code · Notes · Topics

Android's sparse image container (magic 0xED26FF3A, bytes 3A FF 26 ED): a 28-byte header and chunks of type RAW, FILL, DONT_CARE or CRC32 that fastboot and simg2img expand into a raw ext4/f2fs partition image.

Overview

A sparse image stores a partition image (system.img, vendor.img, userdata.img, often one of several system_N.img parts) without its runs of zeros or repeated words, so fastboot can flash it in pieces. simg2img (AOSP libsparse) expands it to the raw image, which is usually an ext4, f2fs or erofs filesystem; img2simg does the reverse.

File header (sparse_header, 28 bytes, little-endian)

Offset Field Notes
0 magic u32 0xED26FF3A (file bytes 3A FF 26 ED)
4 major_version u16 1; readers reject higher major versions
6 minor_version u16 0; higher minor versions are accepted
8 file_hdr_sz u16 28 in the first revision
10 chunk_hdr_sz u16 12 in the first revision
12 blk_sz u32 block size in bytes, multiple of 4 (normally 4096)
16 total_blks u32 blocks in the expanded output image
20 total_chunks u32 chunks in this sparse file
24 image_checksum u32 CRC32 of the original data, DONT_CARE counted as zero

The offsets are computed from the field order of the struct; the field comments are quoted from the header.

Chunk header (12 bytes)

chunk_type u16, reserved1 u16, chunk_sz u32 (size in blocks in the output image), total_sz u32 (bytes in the sparse file including this header and the data).

chunk_type Name Data following the header
0xCAC1 RAW chunk_sz * blk_sz bytes copied to the output
0xCAC2 FILL 4 bytes; the output block range is that word repeated
0xCAC3 DONT_CARE none; output offset advances, content undefined (skipped)
0xCAC4 CRC32 4 bytes of CRC32

Reversing notes

  • To reach a filesystem, expand with simg2img and then identify the result (ext4 superblock magic 0xEF53 at offset 0x438, F2FS 0xF2F52010 at 0x400, EROFS 0xE0F5E1E2 at 0x400). The ext4 and F2FS values were checked in Linux c03c1a14 (include/uapi/linux/magic.h EXT4_SUPER_MAGIC 0xEF53, F2FS_SUPER_MAGIC 0xF2F52010; fs/ext4/ext4.h superblock at byte 1024 with s_magic at +0x38; include/linux/f2fs_fs.h F2FS_SUPER_OFFSET 1024); see Format:Ext2, ext3 and ext4 and Format:F2FS. Unverified: the EROFS magic and offset (not read).
  • The output offset of each chunk is the running sum of chunk_sz * blk_sz of the previous chunks; a parser needs no index.
  • Large images may arrive as several sparse files that fastboot flashes one after another into the same partition.
  • A super.img can also be sparse; expand it first and then read Format:Android LP metadata.

See Technique:Unpacking firmware update containers for the other containers met on the way to a filesystem.

Sources: AOSP platform/system/core libsparse/sparse_format.h.

Code & repositories

  • https://android.googlesource.com/platform/system/core @ a3b721a32242006b59cb12bd62c9133632af3a2d · license: Apache-2.0 (declared by the contributor; GitHub's detector did not recognize a license file)
    libsparse/sparse_format.h and fs_mgr/liblp/include/liblp/metadata_format.h
    Tested on: source read, not run · checked 2026-10-18; last activity 2025-03-27