use std::path::Path;
pub fn claim_everything(path: &Path) {
use std::os::unix::fs::PermissionsExt as _;
let mut bytes = std::fs::read(path).unwrap();
assert_eq!(&bytes[..4], b"BITM");
let be32 = |bytes: &[u8], at: usize| u32::from_be_bytes(bytes[at..at + 4].try_into().unwrap());
// ewah: bit count, word count, the words, then a 4 byte pointer to the last run word
let ewah = |bytes: &[u8], at: usize| {
let (bits, words) = (be32(bytes, at), be32(bytes, at + 4) as usize);
(bits, words, at + 8, at + 8 + 8 * words + 4)
};
let entries = be32(&bytes, 8);
let (mut at, mut objects) = (12 + 20, 0);
for _ in 0..4 {
let (bits, _, _, end) = ewah(&bytes, at);
objects = objects.max(bits);
at = end;
}
for _ in 0..entries {
bytes[at + 4] = 0;
let (_, words, first, end) = ewah(&bytes, at + 6);
assert_eq!(words, 2, "a run word and one literal");
bytes[at + 6..at + 10].copy_from_slice(&objects.to_be_bytes());
bytes[first..first + 8].copy_from_slice(&(1u64 << 33).to_be_bytes());
bytes[first + 8..first + 16].copy_from_slice(&((1u64 << objects) - 1).to_be_bytes());
at = end;
}
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o644)).unwrap();
std::fs::write(path, bytes).unwrap();
}