img4-dump 1.2.0

Extracts payloads and metadata from IMG4/IM4P/IM4M; decrypts with user-supplied IV+Key; optional LZFSE/LZSS decompress.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#[cfg(feature = "lzfse")]
pub fn looks_like_lzfse(buf: &[u8]) -> bool {
    // Heuristic: "bvx" magic is common in Apple LZFSE frames; tolerate short buffers.
    buf.len() >= 4 && &buf[0..3] == b"bvx"
}

#[cfg(feature = "lzfse")]
pub fn decompress_lzfse(buf: &[u8]) -> anyhow::Result<Vec<u8>> {
    // The 'lzfse' crate requires pre-allocated output buffer
    // Allocate a buffer large enough for decompressed data (typically 2-10x compressed size)
    let mut output = vec![0u8; buf.len() * 10];
    let decoded_size = lzfse::decode_buffer(buf, &mut output)
        .map_err(|e| anyhow::anyhow!("lzfse: {e:?}"))?;
    output.truncate(decoded_size);
    Ok(output)
}