REFERENCE GUIDE
File carving and validating embedded formats
Carving recovers candidate files from recognizable structures inside a larger byte stream.
Also known as: carving · magic bytes
Mechanism
Carving recovers candidate files from recognizable structures inside a larger byte stream. Magic values identify possible starts, but accurate boundaries require format-specific length fields, end markers, checksums, or parsers. Fragmented storage can break the assumption that the entire embedded file occupies one contiguous region.
Practical method
Scan for candidate headers, record offsets, and inspect nearby bytes manually. Use the format grammar to calculate an end boundary. Extract a small candidate and validate it with an independent parser. Keep overlapping or nested candidates separate until their relationship is understood.
blob = open("image.bin", "rb").read()
offset = blob.find(b"\x89PNG\r\n\x1a\n")
print(offset)
Interpreting evidence
A valid header is not a recovered file. Confirm structural consistency and expected content. A parser warning can reveal truncation, fragmentation, or deliberate corruption rather than a simple false positive.
Pitfalls and limits
Random data can contain short signatures. Compressed streams can include accidental headers. Extracting from a disk image without filesystem context loses filenames and allocation provenance.