From d85c38efeca4e16ef8f7aeb5c6b70cacdb562857 Mon Sep 17 00:00:00 2001 From: loyoi <1019748371@qq.com> Date: Sun, 8 Dec 2024 08:32:21 +0800 Subject: [PATCH] =?UTF-8?q?try=20one's=20hand=20at=20=20=E5=B0=8F=E8=AF=95?= =?UTF-8?q?=E7=89=9B=E5=88=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Justfile | 11 ++++ crates/jsxer_cli/src/main.rs | 105 ++++++++++++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 Justfile diff --git a/.gitignore b/.gitignore index edda281..b8fc204 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /cmake-build-debug/ /cmake-build-release/ /cmake-build-*/ +target/ node_modules/ diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..1036727 --- /dev/null +++ b/Justfile @@ -0,0 +1,11 @@ +list: + just -l + +cli-run: + cargo run --package jsxer_cli --bin jsxer_cli --help + +cli-build: + cargo build --package jsxer_cli --bin jsxer_cli + +cli-dev argument: + ./target/debug/jsxer_cli.exe --help {{argument}} \ No newline at end of file diff --git a/crates/jsxer_cli/src/main.rs b/crates/jsxer_cli/src/main.rs index ed1ffda..c1a7954 100644 --- a/crates/jsxer_cli/src/main.rs +++ b/crates/jsxer_cli/src/main.rs @@ -1,5 +1,108 @@ +use clap::{Arg, Command}; +use std::fs; +use std::path::Path; +use std::process; fn main() { - println!("Hello, world!"); + let matches = Command::new("JSXER - A fast and accurate JSXBIN decompiler.") + .version(env!("CARGO_PKG_VERSION")) + .author("Angelo DeLuca and contributors.") + .about("Decompiles JSXBIN files to JSX source code.") + .arg( + Arg::new("input") + .help("Name of file to read") + .required(true) + .index(1), + ) + .arg( + Arg::new("output") + .short('o') + .long("output") + .value_name("FILE") + .help("Output path for the decompiled file"), + ) + .arg( + Arg::new("unblind") + .short('b') + .long("unblind") + .help("Try renaming symbols which are obfuscated by 'JsxBlind' (experimental)"), + ) + // Uncomment if you want to add a verbose flag + /* + .arg( + Arg::new("verbose") + .short('v') + .long("verbose") + .help("Display verbose log"), + ) + */ + .get_matches(); + + let input = matches.get_one::("input").expect("Input file is required"); + let output = matches.get_one::("output").map(|s| s.as_str()); + let unblind = matches.get_flag("unblind"); + + let input_path = Path::new(input); + if !input_path.exists() || !input_path.is_file() { + eprintln!("Error: Input file does not exist or is not a file."); + process::exit(1); + } + + let output_path = match output { + Some(output) => Path::new(output).to_owned(), + None => { + let parent = input_path.parent().unwrap_or_else(|| Path::new(".")); + parent.join(format!("{}.jsx", input_path.file_stem().unwrap().to_string_lossy())) + } + }; + + if let Some(parent) = output_path.parent() { + if !parent.exists() { + if let Err(err) = fs::create_dir_all(parent) { + eprintln!("Error: Failed to create directory for output file: {}", err); + process::exit(1); + } + } + } + + // Read in the JSXBIN file contents... + let contents = match read_file_contents(&input_path) { + Ok(contents) => contents, + Err(err) => { + eprintln!("Error: Failed to read input file: {}", err); + process::exit(1); + } + }; + + // Begin de-compilation... + println!("[i] Decompiling..."); + let decompiled = match decompile_jsxbin(&contents, unblind) { + Ok(decompiled) => decompiled, + Err(err) => { + eprintln!("Error: Failed to decompile JSXBIN content: {}", err); + process::exit(1); + } + }; + println!("[i] Finished."); + + // Write the decompiled content to the output file... + if let Err(err) = write_file_contents(&output_path, &decompiled) { + eprintln!("Error: Failed to write output file: {}", err); + process::exit(1); + } +} + +// Implement these functions as per your requirements +fn read_file_contents(path: &Path) -> Result { + fs::read_to_string(path) +} + +fn decompile_jsxbin(contents: &str, unblind: bool) -> Result { + // Placeholder for actual decompilation logic + Ok(String::from("/* decompiled content */")) +} + +fn write_file_contents(path: &Path, contents: &str) -> Result<(), std::io::Error> { + fs::write(path, contents) }