Files
unixtract/src/main.rs
T

148 lines
5.6 KiB
Rust
Raw Normal View History

2025-09-27 00:31:18 +02:00
mod formats;
mod keys;
mod utils;
2025-09-27 00:31:18 +02:00
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>> {
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) {
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!();
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
}
if formats::invincible_image::is_invincible_image_file(&file) {
println!("INVINCIBLE_IMAGE file detected!");
formats::invincible_image::extract_invincible_image(&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) {
println!("MSD11 file detected!");
formats::msd11::extract_msd11(&file, &output_path)?;
2025-10-07 21:43:49 +02:00
}
else if formats::nvt_timg::is_nvt_timg_file(&file) {
println!("Novatek TIMG file detected!");
formats::nvt_timg::extract_nvt_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
}
2025-10-29 18:36:42 +01:00
else if formats::slp::is_slp_file(&file) {
println!("SLP file detected!");
formats::slp::extract_slp(&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-08 00:40:29 +02:00
}
//epk2 with unencrypted header
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)?;
2025-10-08 00:40:29 +02:00
}
//epk with encrypted header - it can be epk2 or epk3 so we need to check
else if formats::epk::is_epk_file(&file) {
println!("EPK file detected!");
formats::epk::extract_epk(&file, &output_path)?;
}
2025-10-19 14:56:51 +02:00
else if formats::ruf::is_ruf_file(&file) {
println!("RUF file detected!");
formats::ruf::extract_ruf(&file, &output_path)?;
}
2025-11-05 22:57:54 +01:00
else if formats::funai_upg::is_funai_upg_file(&file) {
println!("Funai UPG file detected!");
formats::funai_upg::extract_funai_upg(&file, &output_path)?;
}
2025-10-07 21:43:49 +02:00
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
}
2025-11-19 23:39:33 +01:00
else if formats::pana_dvd::is_pana_dvd_file(&file) {
println!("PANA_DVD file detected!");
formats::pana_dvd::extract_pana_dvd(&file, &output_path)?;
}
2025-10-19 22:12:21 +02:00
else if formats::pup::is_pup_file(&file) {
println!("PUP file detected!");
formats::pup::extract_pup(&file, &output_path)?;
}
2025-10-31 19:37:03 +01:00
else if formats::sony_bdp::is_sony_bdp_file(&file) {
println!("Sony BDP file detected!");
formats::sony_bdp::extract_sony_bdp(&file, &output_path)?;
}
2025-11-02 12:40:46 +01:00
else if formats::rvp::is_rvp_file(&file) {
println!("RVP/MVP file detected!");
formats::rvp::extract_rvp(&file, &output_path)?;
}
2025-10-31 19:37:03 +01:00
else if formats::mstar::is_mstar_file(&file) {
println!("Mstar upgrade file detected!");
formats::mstar::extract_mstar(&file, &output_path)?;
}
else if formats::roku::is_roku_file(&file) {
println!("Roku file detected!");
formats::roku::extract_roku(&file, &output_path)?;
}
2025-10-12 19:08:46 +02:00
else if formats::mtk_pkg::is_mtk_pkg_file(&file) {
println!("MTK Pkg file detected!");
formats::mtk_pkg::extract_mtk_pkg(&file, &output_path)?;
}
else if formats::mtk_upgrade_loader::is_mtk_upgrade_loader_file(&file) {
println!("MTK upgrade_loader file detected!");
formats::mtk_upgrade_loader::extract_mtk_upgrade_loader(&file, &output_path)?;
2025-10-16 21:04:49 +02:00
}
else if formats::mtk_bdp::is_mtk_bdp_file(&file) {
println!("MTK BDP file detected!");
formats::mtk_bdp::extract_mtk_bdp(&file, &output_path)?;
}
2025-10-07 21:43:49 +02:00
else {
println!("Input format not recognized!");
2025-09-11 20:26:51 +02:00
}
}
Ok(())
}