shits fucked

This commit is contained in:
endernon 2024-12-04 00:26:25 +00:00
parent 60daca96ca
commit 022dbec73e
3 changed files with 74 additions and 48 deletions

5
log.txt Normal file
View file

@ -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

View file

@ -1,15 +1,30 @@
# respack-decrypter # 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. 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. 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 # 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 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

View file

@ -1,9 +1,12 @@
use image::ImageBuffer;
use zune_png::{zune_core::options::DecoderOptions, PngDecoder};
use clap::Parser; use clap::Parser;
use glob::glob; use glob::glob;
use std::fs::metadata; use image::ImageBuffer;
use std::path::{Path, PathBuf}; use std::io::{BufReader, Read};
use std::{
fs::{metadata, File},
path::{Path, PathBuf},
};
use zune_png::{zune_core::options::DecoderOptions, PngDecoder};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
@ -11,75 +14,70 @@ struct Args {
/// Input path /// Input path
/// ///
/// Include a file path or a directory path. Do not use any asterisks or wildcards. /// 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)] #[arg(short, long)]
path: PathBuf, path: PathBuf,
/// Output path // /// Output path
#[arg(short, long,default_value="")] // #[arg(short, long,default_value="")]
out: PathBuf, // out: PathBuf,
/// Debug mode /// Debug mode
#[arg(short, long, default_value_t=false)] ///
/// Either "true" or "false"
#[arg(short, long, default_value_t = false)]
debug: bool, debug: bool,
} }
fn main() { fn main() {
// argument parsing yep // argument parsing yep
let Args: Args = Args::parse(); let Args: Args = Args::parse();
let pathfr = Args.path.clone(); let pathfr = Args.path.clone();
let outfr = match Args.out { let debugmode = Args.debug;
Some(realoutpath) => {
realoutpath
},
None => {
Args.path
}
};
let realdebugmode = Args.debug;
let mut filelist: Vec<String> = Vec::new();
let mut filelist: Vec<PathBuf> = Vec::new();
let pathtype = metadata(&pathfr).unwrap(); let pathtype = metadata(&pathfr).unwrap();
if pathtype.is_file() { if pathtype.is_file() {
filelist.push(PathBuf::from(format!("{:?}", pathtype)));
} println!("input path FILE");
else if pathtype.is_dir() { } else if pathtype.is_dir() {
println!("input path DIR");
// parse file list if it's a 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 { match entry {
Ok(path) => { Ok(path) => {
// println!("{:?}", path.display()); // println!("{:?}", path.display());
filelist.push(path.display().to_string()); filelist.push(path.display().to_string().parse().unwrap());
}, }
Err(e) => { Err(e) => {
println!("Shell globbing error"); println!("Shell globbing error");
} }
} }
} }
} } else {
else { panic!("that input is neither file nor dir and thats scary...")
panic!("that input is neither file nor dir and thats scary")
} }
// if debugmode {
// for i in filelist.clone() {
// println!("List of files: {}",i.display())
// }
// }
for thatpath in filelist {
if realdebugmode { encoder(thatpath, debugmode)
for i in filelist {
println!("List of files: {i}")
}
} }
}
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(buf, DecoderOptions::new_cmd());
let mut decoder = PngDecoder::new_with_options(data, DecoderOptions::new_cmd());
decoder.decode_headers().unwrap(); decoder.decode_headers().unwrap();
let dim = decoder.get_dimensions().unwrap(); let dim = decoder.get_dimensions().unwrap();
//dbg!(dim); //dbg!(dim);
@ -89,10 +87,18 @@ fn main() {
//dbg!(&data); //dbg!(&data);
let depth = decoder.get_depth().unwrap(); 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 // TODO: figure out propper color checks rn we assume data is RGBA
let out: ImageBuffer<image::Rgba<u8>, Vec<u8>> = let out: ImageBuffer<image::Rgba<u8>, Vec<u8>> =
ImageBuffer::from_raw(dim.0 as u32, dim.1 as u32, data).unwrap(); 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)
} }