2025-09-27 00:31:18 +02:00
|
|
|
mod common;
|
|
|
|
|
mod formats;
|
|
|
|
|
|
2025-09-11 20:26:51 +02:00
|
|
|
use clap::Parser;
|
|
|
|
|
use std::path::{PathBuf};
|
2025-10-07 21:43:49 +02:00
|
|
|
use std::io::{self};
|
|
|
|
|
use std::fs::{self, File};
|
2025-09-11 20:26:51 +02:00
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
struct Args {
|
|
|
|
|
input_target: String,
|
|
|
|
|
output_folder: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2025-10-07 16:00:32 +02:00
|
|
|
println!("unixtract Firmware extractor");
|
2025-09-11 20:26:51 +02:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
|
|
let target_path = args.input_target;
|
|
|
|
|
println!("Input target: {}", target_path);
|
|
|
|
|
|
|
|
|
|
let output_path = args.output_folder;
|
|
|
|
|
println!("Output folder: {}", output_path);
|
|
|
|
|
|
2025-10-07 21:43:49 +02:00
|
|
|
let output_folder_path = PathBuf::from(&output_path);
|
|
|
|
|
if output_folder_path.exists() {
|
|
|
|
|
if output_folder_path.is_dir() {
|
|
|
|
|
let is_empty = fs::read_dir(&output_folder_path)?.next().is_none();
|
|
|
|
|
if !is_empty {
|
|
|
|
|
println!("\nWarning: Output folder exists and is NOT empty! Files may be overwritten!");
|
|
|
|
|
println!("Press Enter if you want to continue...");
|
|
|
|
|
io::stdin().read_line(&mut String::new())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 20:26:51 +02:00
|
|
|
let path = PathBuf::from(target_path);
|
|
|
|
|
if path.is_dir() {
|
2025-09-12 22:18:53 +02:00
|
|
|
if formats::samsung_old::is_samsung_old_dir(&path) {
|
2025-10-07 16:00:32 +02:00
|
|
|
println!("Samsung old firmware dir detected!\n");
|
2025-09-12 22:18:53 +02:00
|
|
|
formats::samsung_old::extract_samsung_old(&path, &output_path)?
|
|
|
|
|
} else {
|
|
|
|
|
println!("Input format not recognized!");
|
|
|
|
|
}
|
2025-09-11 20:26:51 +02:00
|
|
|
} else {
|
|
|
|
|
let file = File::open(path)?;
|
|
|
|
|
|
2025-09-11 22:04:50 +02:00
|
|
|
println!();
|
|
|
|
|
|
2025-10-07 16:00:32 +02:00
|
|
|
if formats::sddl_sec::is_sddl_sec_file(&file) {
|
|
|
|
|
println!("SDDL.SEC file detected!");
|
|
|
|
|
formats::sddl_sec::extract_sddl_sec(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::msd10::is_msd10_file(&file) {
|
2025-10-07 13:29:44 +02:00
|
|
|
println!("MSD10 file detected!");
|
|
|
|
|
formats::msd10::extract_msd10(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::msd11::is_msd11_file(&file) {
|
2025-10-07 16:00:32 +02:00
|
|
|
println!("MSD11 file detected!");
|
|
|
|
|
formats::msd11::extract_msd11(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::tpv_timg::is_tpv_timg_file(&file) {
|
2025-09-25 17:49:02 +02:00
|
|
|
println!("TPV TIMG file detected!");
|
|
|
|
|
formats::tpv_timg::extract_tpv_timg(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::novatek::is_novatek_file(&file) {
|
2025-10-07 00:04:47 +02:00
|
|
|
println!("Novatek file detected!");
|
|
|
|
|
formats::novatek::extract_novatek(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::epk1::is_epk1_file(&file) {
|
2025-10-06 22:44:30 +02:00
|
|
|
println!("EPK1 file detected!");
|
|
|
|
|
formats::epk1::extract_epk1(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::epk2::is_epk2_file(&file) {
|
|
|
|
|
println!("EPK2 file detected!");
|
|
|
|
|
formats::epk2::extract_epk2(&file, &output_path)?;
|
|
|
|
|
}
|
|
|
|
|
else if formats::pfl_upg::is_pfl_upg_file(&file) {
|
2025-09-27 00:31:18 +02:00
|
|
|
println!("PFL UPG file detected!");
|
|
|
|
|
formats::pfl_upg::extract_pfl_upg(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else if formats::mstar::is_mstar_file(&file) {
|
2025-09-11 20:26:51 +02:00
|
|
|
println!("Mstar upgrade file detected!");
|
2025-09-11 22:04:50 +02:00
|
|
|
formats::mstar::extract_mstar(&file, &output_path)?;
|
2025-10-07 21:43:49 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2025-09-12 22:18:53 +02:00
|
|
|
println!("Input format not recognized!");
|
2025-09-11 20:26:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|