From 022dbec73e60fff230e5b322125471956462e203 Mon Sep 17 00:00:00 2001 From: endernon Date: Wed, 4 Dec 2024 00:26:25 +0000 Subject: [PATCH] shits fucked --- log.txt | 5 +++ readme.md | 23 ++++++++++--- src/main.rs | 94 ++++++++++++++++++++++++++++------------------------- 3 files changed, 74 insertions(+), 48 deletions(-) create mode 100644 log.txt diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..2b16ec3 --- /dev/null +++ b/log.txt @@ -0,0 +1,5 @@ +input path DIR +Filepath: "/new2/git/wynn-pack-temp/assets/minecraft/textures/colormap/foliage.png" +Dimensions: (256, 256) +Colorspace: RGB +BitDepth: Eight diff --git a/readme.md b/readme.md index d569b75..0778549 100644 --- a/readme.md +++ b/readme.md @@ -1,15 +1,30 @@ # respack-decrypter -This tool +This tool allows you to unfuck corrupted images in a resource pack that have been corrupted to be protected. -# I want some logs +# Usage + +- download the Rust-Lang for your system +- download this repository +- run `cargo build --release` in the directory +- check `./target/release` +- run `respack-decrypter` if you are on linux/mac (RUN `chmod +x respack-decrypter` ON IT FIRST) +- run `respack-decrypter.exe` if you are on windows + +# syntax + +Check `--help` for syntax or `-h` for shortened explanation + +# I want some logs for checking wtf is happening Pipe your output to a new filename. Note: It might not work for SOME linux shells. But major ones e.g. `zsh`,`bash` support it. -`respack-decrypter --path ~/somedir > ~/log.txt` +`respack-decrypter --path ~/somedir/ --debug > ~/log.txt` # License -It's all MIT, except the example inventory.png which is courtesy of Wynncraft. Zeer you better not come after me for this one \ No newline at end of file +It's all MIT, except the example corrupted inventory.png which is courtesy of Wynncraft. + +Zeer you better not come after me for this one, you still haven't answered my gdpr req yet \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index af2549c..a5ded83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ -use image::ImageBuffer; -use zune_png::{zune_core::options::DecoderOptions, PngDecoder}; use clap::Parser; use glob::glob; -use std::fs::metadata; -use std::path::{Path, PathBuf}; +use image::ImageBuffer; +use std::io::{BufReader, Read}; +use std::{ + fs::{metadata, File}, + path::{Path, PathBuf}, +}; +use zune_png::{zune_core::options::DecoderOptions, PngDecoder}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -11,75 +14,70 @@ struct Args { /// Input path /// /// Include a file path or a directory path. Do not use any asterisks or wildcards. + /// If the path includes spaces you may find it useful to use speechmarks (" ") around the path. #[arg(short, long)] path: PathBuf, - /// Output path - #[arg(short, long,default_value="")] - out: PathBuf, - + // /// Output path + // #[arg(short, long,default_value="")] + // out: PathBuf, /// Debug mode - #[arg(short, long, default_value_t=false)] + /// + /// Either "true" or "false" + #[arg(short, long, default_value_t = false)] debug: bool, - } fn main() { - // argument parsing yep let Args: Args = Args::parse(); let pathfr = Args.path.clone(); - let outfr = match Args.out { - Some(realoutpath) => { - realoutpath - }, - None => { - Args.path - } - }; - let realdebugmode = Args.debug; - - let mut filelist: Vec = Vec::new(); + let debugmode = Args.debug; + let mut filelist: Vec = Vec::new(); let pathtype = metadata(&pathfr).unwrap(); if pathtype.is_file() { - - } - else if pathtype.is_dir() { + filelist.push(PathBuf::from(format!("{:?}", pathtype))); + println!("input path FILE"); + } else if pathtype.is_dir() { + println!("input path DIR"); // parse file list if it's a dir - for entry in glob(&format!("{}/**/*.png", pathfr.clone().display())).expect("Failed to read glob pattern (you should panic)") { + for entry in glob(&format!("{}/**/*.png", pathfr.clone().display())) + .expect("Failed to read glob pattern (you should panic)") + { match entry { Ok(path) => { // println!("{:?}", path.display()); - filelist.push(path.display().to_string()); - }, + filelist.push(path.display().to_string().parse().unwrap()); + } Err(e) => { println!("Shell globbing error"); } } } - } - else { - panic!("that input is neither file nor dir and thats scary") + } else { + panic!("that input is neither file nor dir and thats scary...") } + // if debugmode { + // for i in filelist.clone() { + // println!("List of files: {}",i.display()) + // } + // } - - if realdebugmode { - for i in filelist { - println!("List of files: {i}") - } + for thatpath in filelist { + encoder(thatpath, debugmode) } +} +fn encoder(filepath: PathBuf, modeDebug: bool) { + let file = File::open(&filepath).unwrap(); + let mut data = BufReader::new(file); + let mut buf = Vec::new(); + data.read_to_end(&mut buf).unwrap(); - let data = include_bytes!("../inventory.png"); - - - - - let mut decoder = PngDecoder::new_with_options(data, DecoderOptions::new_cmd()); - + let mut decoder = PngDecoder::new_with_options(buf, DecoderOptions::new_cmd()); decoder.decode_headers().unwrap(); let dim = decoder.get_dimensions().unwrap(); //dbg!(dim); @@ -89,10 +87,18 @@ fn main() { //dbg!(&data); let depth = decoder.get_depth().unwrap(); + if modeDebug { + println!("Filepath: {:?}", filepath); + println!("Dimensions: {:?}", dim); + println!("Colorspace: {:?}", col); + println!("BitDepth: {:?}", depth); + } + // TODO: figure out propper color checks rn we assume data is RGBA let out: ImageBuffer, Vec> = ImageBuffer::from_raw(dim.0 as u32, dim.1 as u32, data).unwrap(); - out.save("out.png").unwrap(); + out.save(filepath.clone()).unwrap(); + println!("wrote file {:?}\n",filepath) }