Skip to content

Instantly share code, notes, and snippets.

@kangalio
Created July 2, 2018 13:10
Show Gist options
  • Save kangalio/a47f760480ad420daf5f70d91f2f4985 to your computer and use it in GitHub Desktop.
Save kangalio/a47f760480ad420daf5f70d91f2f4985 to your computer and use it in GitHub Desktop.
Script to repair ISO files (doesn't really work)
use std::fs::File;
use std::io::prelude::*;
const BUF_SIZE: usize = 65536;
fn process_bytes(bytes: Vec<Box<[u8; BUF_SIZE]>>) {
let mut out_buf = [0_u8; BUF_SIZE];
for i in 0..BUF_SIZE {
let sum: usize = bytes.iter().map(|s| s[i] as usize).sum();
let result = (sum as f32 / bytes.len() as f32).round();
out_buf[i] = result as u8;
}
std::io::stdout().write(&out_buf).unwrap();
}
fn main() {
let paths = ["corrupt.iso", "corrupt2.iso", "corrupt3.iso"];
let mut files: Vec<File> = paths.iter()
.map(|p| File::open(format!("/home/kangalioo/misc/{}", p)).unwrap())
.collect();
loop {
let mut bytes = Vec::new();
for mut file in &mut files {
let mut buf = [0_u8; BUF_SIZE];
file.read_exact(&mut buf).unwrap();
bytes.push(Box::new(buf));
}
process_bytes(bytes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment