Created
July 2, 2018 13:10
Script to repair ISO files (doesn't really work)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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