1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//! Chromium **Simple Cache** on-disk format constants.
//!
//! The Simple Cache is one of Chromium's two disk-cache backends (the default on
//! Android, ChromeOS, Linux and macOS, and the backend for `CacheStorage`
//! everywhere). It keeps roughly **one file per cache entry** plus a single
//! `the-real-index` file, which makes it robust against crashes and the reason
//! forensic recovery of Discord/Slack/Teams/Electron cached media so often lands
//! here. Each entry file is bracketed by a fixed header and an EOF trailer; the
//! index is a `base::Pickle` guarded by a checksum.
//!
//! This module is **facts only** — the magic numbers, format versions, the
//! header/EOF/sparse field offsets, and the EOF flag bits. The reader that walks
//! the directory, validates the trailer, and carves the streams lives in the
//! consuming crate (`browser-forensic` / a cache carver), per forensicnomicon's
//! knowledge-only charter (no I/O, no parsing here).
//!
//! # Checksum: CRC-32, NOT Fletcher
//!
//! A common DFIR misconception holds that the Simple Cache index is protected by
//! a **Fletcher** checksum. It is not. The index pickle is checksummed with a
//! standard **CRC-32** (`CalculatePickleCRC` → `simple_util::Crc32`), and each
//! entry stream is likewise protected by the CRC-32 stored in
//! [`FLAG_HAS_CRC32`]-guarded `data_crc32`. There is no Fletcher checksum anywhere
//! in the Simple Cache backend — a mismatch simply triggers an index rebuild by
//! rescanning the entry files.
//!
//! # Authoritative sources
//!
//! - Chromium `net/disk_cache/simple/simple_entry_format.h` — the
//! `SimpleFileHeader`, `SimpleFileEOF` and `SimpleFileSparseRangeHeader` structs
//! and the `kSimple*MagicNumber` constants:
//! <https://github.com/chromium/chromium/blob/main/net/disk_cache/simple/simple_entry_format.h>
//! - Chromium `net/disk_cache/simple/simple_backend_version.h` — `kSimpleVersion`
//! (fake-index version) and `kSimpleEntryVersionOnDisk`:
//! <https://github.com/chromium/chromium/blob/main/net/disk_cache/simple/simple_backend_version.h>
//! - Chromium `net/disk_cache/simple/simple_version_upgrade.cc` —
//! `kMinVersionAbleToUpgrade` and the fake-index rebuild:
//! <https://github.com/chromium/chromium/blob/main/net/disk_cache/simple/simple_version_upgrade.cc>
//! - Chromium `net/disk_cache/simple/simple_index_file.cc` — `CalculatePickleCRC`
//! (the CRC-32, refuting the Fletcher claim) and `kSimpleIndexMagicNumber`:
//! <https://github.com/chromium/chromium/blob/main/net/disk_cache/simple/simple_index_file.cc>
//! - Chromium design doc, *Very Simple Backend*:
//! <https://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend/>
// ── Magic numbers (u64, stored little-endian on disk) ────────────────────────
/// `SimpleFileHeader::initial_magic_number` — the magic that opens every entry
/// file (`kSimpleInitialMagicNumber`).
pub const INITIAL_MAGIC: u64 = 0xfcfb_6d1b_a772_5c30;
/// `SimpleFileEOF::final_magic_number` — the magic that closes every entry
/// stream trailer (`kSimpleFinalMagicNumber`).
pub const FINAL_MAGIC: u64 = 0xf4fa_6f45_970d_41d8;
/// `SimpleFileSparseRangeHeader::sparse_range_magic_number` — opens each sparse
/// range record.
pub const SPARSE_RANGE_MAGIC: u64 = 0xeb97_bf01_6553_676b;
/// `kSimpleIndexMagicNumber` — the magic in the `the-real-index` pickle header
/// (ASCII `"enter yo"` read as a little-endian u64).
pub const INDEX_MAGIC: u64 = 0x656e_7465_7220_796f;
// ── Versions ─────────────────────────────────────────────────────────────────
/// `kSimpleVersion` — current fake-index / backend format version.
pub const SIMPLE_VERSION: u32 = 9;
/// `kSimpleEntryVersionOnDisk` — version written into each entry file's header.
pub const ENTRY_VERSION_ON_DISK: u32 = 5;
/// `kMinVersionAbleToUpgrade` — the oldest version the backend can migrate.
pub const MIN_VERSION_ABLE_TO_UPGRADE: u32 = 8;
/// `kSimpleEntryStreamCount` — number of data streams stored per entry.
pub const ENTRY_STREAM_COUNT: usize = 3;
// ── SimpleFileHeader field offsets (24-byte struct) ──────────────────────────
/// Byte offset of `initial_magic_number` (u64 LE) in `SimpleFileHeader`.
pub const HEADER_MAGIC_OFFSET: usize = 0;
/// Byte offset of `version` (u32 LE) in `SimpleFileHeader`.
pub const HEADER_VERSION_OFFSET: usize = 8;
/// Byte offset of `key_length` (u32 LE) in `SimpleFileHeader`.
pub const HEADER_KEY_LENGTH_OFFSET: usize = 12;
/// Byte offset of `key_hash` (u32 LE) in `SimpleFileHeader`.
pub const HEADER_KEY_HASH_OFFSET: usize = 16;
/// Total size of `SimpleFileHeader` (incl. `unused_padding`).
pub const HEADER_LEN: usize = 24;
// ── SimpleFileEOF field offsets (24-byte trailer) ────────────────────────────
/// Byte offset of `final_magic_number` (u64 LE) in `SimpleFileEOF`.
pub const EOF_MAGIC_OFFSET: usize = 0;
/// Byte offset of `flags` (u32 LE) in `SimpleFileEOF`.
pub const EOF_FLAGS_OFFSET: usize = 8;
/// Byte offset of `data_crc32` (u32 LE) in `SimpleFileEOF`.
pub const EOF_DATA_CRC32_OFFSET: usize = 12;
/// Byte offset of `stream_size` (u32 LE) in `SimpleFileEOF`.
pub const EOF_STREAM_SIZE_OFFSET: usize = 16;
/// Total size of `SimpleFileEOF` (incl. `unused_padding`).
pub const EOF_LEN: usize = 24;
// ── SimpleFileEOF flag bits ──────────────────────────────────────────────────
/// `SimpleFileEOF::FLAG_HAS_CRC32` — the trailer carries a valid `data_crc32`.
pub const FLAG_HAS_CRC32: u32 = 1 << 0;
/// `SimpleFileEOF::FLAG_HAS_KEY_SHA256` — the trailer is followed by a SHA-256 of
/// the key.
pub const FLAG_HAS_KEY_SHA256: u32 = 1 << 1;
// ── Sparse range header offsets (32-byte struct) ─────────────────────────────
/// Byte offset of `offset` (u64 LE) in `SimpleFileSparseRangeHeader`.
pub const SPARSE_OFFSET_OFFSET: usize = 8;
/// Byte offset of `length` (u64 LE) in `SimpleFileSparseRangeHeader`.
pub const SPARSE_LENGTH_OFFSET: usize = 16;
/// Byte offset of `data_crc32` (u32 LE) in `SimpleFileSparseRangeHeader`.
pub const SPARSE_DATA_CRC32_OFFSET: usize = 24;
/// Total size of `SimpleFileSparseRangeHeader`.
pub const SPARSE_HEADER_LEN: usize = 32;
/// Which Simple Cache structure a leading magic identifies.
/// Identify which Simple Cache structure a leading 64-bit magic belongs to.
///
/// Returns `None` for any value that is not one of the four documented magics —
/// the caller must fail loud rather than assume a structure.
/// Whether an EOF `flags` word asserts a valid `data_crc32`.
pub const
/// Whether an EOF `flags` word asserts a trailing key SHA-256.
pub const