commit 169e2e88b93f5e78075c79f6eeae04aebe8f40b5 Author: sad Date: Tue Jul 16 23:35:27 2024 -0600 i have a boner diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..79c0741 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,249 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "wipedicks" +version = "0.1.0" +dependencies = [ + "clap", + "rand", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4b7a245 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "wipedicks" +version = "0.1.0" +edition = "2021" + +[dependencies] +rand = "0.8.5" +clap = "4.5.9" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..1a7da05 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,175 @@ +use std::fs::{self, OpenOptions}; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; +use std::thread; +use rand::prelude::*; +use clap::{Command, Arg}; +use rand::thread_rng; + +const DICKS: &[&str] = &[ + "8=D ", "8=D~ ", "8=D~~ ", "8=D~~~ ", "8==D ", "8==D~ ", "8==D~~ ", "8==D~~~ ", "8===D ", "8===D~ ", "8===D~~ ", "8===D~~~ ", "8====D ", "8====D~ ", "8====D~~ ", "8====D~~~ ", "8=====D ", "8=====D~ ", "8=====D~~ ", "8=====D~~~ ", "8======D ", "8======D~ ", "8======D~~ ", "8======D~~~ ", "8=======D ", "8=======D~ ", "8=======D~~ ", "8=======D~~~ ", "8========D ", "8========D~ ", "8========D~~ ", "8========D~~~ ", "8=========D ", "8=========D~ ", "8=========D~~ ", "8=========D~~~ ", "8==========D ", "8==========D~ ", "8==========D~~ ", "8==========D~~~ ", "8===========D ", "8===========D~ ", "8===========D~~ ", "8===========D~~~ ", "8============D ", "8============D~ ", "8============D~~ ", "8============D~~~ ", "8#=D ", "8#=D~ ", "8#=D~~ ", "8#=D~~~ ", "8#==D ", "8#==D~ ", "8#==D~~ ", "8#==D~~~ ", "8#===D ", "8#===D~ ", "8#===D~~ ", "8#===D~~~ ", "8#====D ", "8#====D~ ", "8#====D~~ ", "8#====D~~~ ", "8#=====D ", "8#=====D~ ", "8#=====D~~ ", "8#=====D~~~ ", "8#======D ", "8#======D~ ", "8#======D~~ ", "8#======D~~~ ", "8#=======D ", "8#=======D~ ", "8#=======D~~ ", "8#=======D~~~ ", "8#========D ", "8#========D~ ", "8#========D~~ ", "8#========D~~~ ", "8#=========D ", "8#=========D~ ", "8#=========D~~ ", "8#=========D~~~ ", "8#==========D ", "8#==========D~ ", "8#==========D~~ ", "8#==========D~~~ ", "8#===========D ", "8#===========D~ ", "8#===========D~~ ", "8#===========D~~~ ", "8#============D ", "8#============D~ ", "8#============D~~ ", "8#============D~~~ ", +]; + +fn generate_dicks() -> Vec { + let mut dicks = Vec::new(); + for a in 0..2 { + for b in 1..13 { + for c in 0..4 { + let dick = format!("8{}{}D{} ", "#".repeat(a), "=".repeat(b), "~".repeat(c)); + dicks.push(dick); + } + } + } + dicks +} + +fn rand_dick(rng: &mut ThreadRng) -> &'static str { + let index = rng.gen_range(0..DICKS.len()); + DICKS[index] +} + +fn fast_rand_dick<'a>(cache: &'a mut String, count: &mut usize, rng: &mut ThreadRng) -> &'a str { + if cache.is_empty() || *count == 0 { + *cache = String::new(); + *count = rng.gen_range(1000..10000); + for _ in 0..rng.gen_range(150..300) { + cache.push_str(rand_dick(rng)); + } + } + *count -= 1; + cache +} + +fn wipe(dev: &Path, rounds: usize, rng: &mut ThreadRng) -> io::Result<()> { + let size = fs::metadata(dev).map(|m| m.len()).unwrap_or(0); + + for _ in 0..rounds { + let mut file = OpenOptions::new().write(true).open(dev)?; + + if size == 0 { + loop { + let dick = rand_dick(rng); + if file.write_all(dick.as_bytes()).is_err() { + break; + } + } + } else { + let mut dlen = 0; + while dlen < size { + let dick = rand_dick(rng); + dlen += dick.len() as u64; + if file.write_all(dick.as_bytes()).is_err() { + break; + } + } + } + } + + fs::remove_file(dev)?; + + Ok(()) +} + +fn parse_dir(dir: &Path, recursive: bool) -> io::Result> { + let mut filelist = Vec::new(); + + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + if recursive { + filelist.extend(parse_dir(&path, recursive)?); + } + } else { + filelist.push(path); + } + } + Ok(filelist) +} + +fn parse_filelist(filelist: &[PathBuf], recursive: bool) -> io::Result> { + let mut files = Vec::new(); + for item in filelist { + if item.is_dir() { + if recursive { + files.extend(parse_dir(item, recursive)?); + } else { + eprintln!("WARNING: {:?} is a directory and recursive is off.", item) + } + } else if item.exists() { + files.push(item.to_path_buf()); + } + } + Ok(files) +} + +fn main() { + let matches = Command::new("Wipe files/devices with dicks") + .version("0.0.1") + .author("vxfemboy") + .arg(Arg::new("recursive") + .short('r') + .long("recursive") + .help("Recursively wipe directories") + .action(clap::ArgAction::SetTrue) + ) + .arg(Arg::new("numrounds") + .short('n') + .long("numrounds") + .help("The number of rounds to wipe the file/device") + .value_parser(clap::value_parser!(usize)) + .default_value("1") + ) + .arg(Arg::new("wipefree") + .short('w') + .long("wipefree") + .help("Wipe free space on device") + .action(clap::ArgAction::SetTrue) + ) + .arg(Arg::new("slow") + .short('s') + .long("slow") + .help("Use more randomness, tends to be slower") + .action(clap::ArgAction::SetTrue) + ) + .arg(Arg::new("files") + .help("Files or directories to wipe") + .num_args(1..) + .required(true) + ) + .get_matches(); + + let recursive = matches.get_flag("recursive"); + let numrounds: usize = *matches.get_one("numrounds").unwrap(); + let slow = matches.get_flag("slow"); + let wipefree = matches.get_flag("wipefree"); + + let initial_file_list: Vec = matches.get_many::("files").unwrap().map(|s| PathBuf::from(s)).collect(); + + let file_list = parse_filelist(&initial_file_list, recursive).unwrap(); + + let file_list = if wipefree { + let mut fl = file_list; + fl.push(PathBuf::from("dick.tmp")); + fl + } else { + file_list + }; + + let mut handles = Vec::new(); + + for f in file_list { + let handle = thread::spawn(move || { + let mut rng = thread_rng(); // create new threads uwu + if let Err(e) = wipe(&f, numrounds, &mut rng) { + eprintln!("ERROR: {:?}: {:?}", f, e); + } + }); + handles.push(handle); + } + + for handle in handles { + handle.join().unwrap(); + } +} +