diff --git a/tools/src/afc.rs b/tools/src/afc.rs index d70c926..e2dcefe 100644 --- a/tools/src/afc.rs +++ b/tools/src/afc.rs @@ -2,11 +2,11 @@ use std::path::PathBuf; -use clap::{value_parser, Arg, Command}; +use clap::{Arg, Command, value_parser}; use idevice::{ - afc::{opcode::AfcFopenMode, AfcClient}, - house_arrest::HouseArrestClient, IdeviceService, + afc::{AfcClient, opcode::AfcFopenMode}, + house_arrest::HouseArrestClient, }; mod common; diff --git a/tools/src/amfi.rs b/tools/src/amfi.rs index ff0b4fa..48d1e37 100644 --- a/tools/src/amfi.rs +++ b/tools/src/amfi.rs @@ -1,7 +1,7 @@ // Jackson Coxson use clap::{Arg, Command}; -use idevice::{amfi::AmfiClient, IdeviceService}; +use idevice::{IdeviceService, amfi::AmfiClient}; mod common; diff --git a/tools/src/app_service.rs b/tools/src/app_service.rs index 27f95df..9751e28 100644 --- a/tools/src/app_service.rs +++ b/tools/src/app_service.rs @@ -2,8 +2,8 @@ use clap::{Arg, Command}; use idevice::{ - core_device::AppServiceClient, core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake, - IdeviceService, RsdService, + IdeviceService, RsdService, core_device::AppServiceClient, core_device_proxy::CoreDeviceProxy, + rsd::RsdHandshake, }; mod common; diff --git a/tools/src/companion_proxy.rs b/tools/src/companion_proxy.rs index 4c1df7c..2568df5 100644 --- a/tools/src/companion_proxy.rs +++ b/tools/src/companion_proxy.rs @@ -1,9 +1,10 @@ // Jackson Coxson -use clap::{arg, Arg, Command}; +use clap::{Arg, Command, arg}; use idevice::{ - companion_proxy::CompanionProxy, core_device_proxy::CoreDeviceProxy, pretty_print_dictionary, - pretty_print_plist, rsd::RsdHandshake, IdeviceService, RsdService, + IdeviceService, RsdService, companion_proxy::CompanionProxy, + core_device_proxy::CoreDeviceProxy, pretty_print_dictionary, pretty_print_plist, + rsd::RsdHandshake, }; mod common; diff --git a/tools/src/crash_logs.rs b/tools/src/crash_logs.rs index 69e79b2..9cbfc24 100644 --- a/tools/src/crash_logs.rs +++ b/tools/src/crash_logs.rs @@ -2,8 +2,8 @@ use clap::{Arg, Command}; use idevice::{ - crashreportcopymobile::{flush_reports, CrashReportCopyMobileClient}, IdeviceService, + crashreportcopymobile::{CrashReportCopyMobileClient, flush_reports}, }; mod common; diff --git a/tools/src/debug_proxy.rs b/tools/src/debug_proxy.rs index 7aa983e..b7e5625 100644 --- a/tools/src/debug_proxy.rs +++ b/tools/src/debug_proxy.rs @@ -4,8 +4,8 @@ use std::io::Write; use clap::{Arg, Command}; use idevice::{ - core_device_proxy::CoreDeviceProxy, debug_proxy::DebugProxyClient, rsd::RsdHandshake, - IdeviceService, RsdService, + IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, debug_proxy::DebugProxyClient, + rsd::RsdHandshake, }; mod common; diff --git a/tools/src/diagnostics.rs b/tools/src/diagnostics.rs index c6a007d..3ea5fe1 100644 --- a/tools/src/diagnostics.rs +++ b/tools/src/diagnostics.rs @@ -1,8 +1,8 @@ // Jackson Coxson // idevice Rust implementation of libimobiledevice's idevicediagnostics -use clap::{Arg, Command, ArgMatches}; -use idevice::{services::diagnostics_relay::DiagnosticsRelayClient, IdeviceService}; +use clap::{Arg, ArgMatches, Command}; +use idevice::{IdeviceService, services::diagnostics_relay::DiagnosticsRelayClient}; mod common; @@ -43,20 +43,20 @@ async fn main() { Arg::new("plane") .long("plane") .value_name("PLANE") - .help("IORegistry plane to query (e.g., IODeviceTree, IOService)") + .help("IORegistry plane to query (e.g., IODeviceTree, IOService)"), ) .arg( Arg::new("name") .long("name") .value_name("NAME") - .help("Entry name to filter by") + .help("Entry name to filter by"), ) .arg( Arg::new("class") .long("class") .value_name("CLASS") - .help("Entry class to filter by") - ) + .help("Entry class to filter by"), + ), ) .subcommand( Command::new("mobilegestalt") @@ -67,45 +67,23 @@ async fn main() { .value_name("KEYS") .help("Comma-separated list of keys to query") .value_delimiter(',') - .num_args(1..) - ) - ) - .subcommand( - Command::new("gasguage") - .about("Print gas gauge (battery) information") - ) - .subcommand( - Command::new("nand") - .about("Print NAND flash information") - ) - .subcommand( - Command::new("all") - .about("Print all available diagnostics information") - ) - .subcommand( - Command::new("wifi") - .about("Print WiFi diagnostics information") - ) - .subcommand( - Command::new("goodbye") - .about("Send Goodbye to diagnostics relay") - ) - .subcommand( - Command::new("restart") - .about("Restart the device") - ) - .subcommand( - Command::new("shutdown") - .about("Shutdown the device") - ) - .subcommand( - Command::new("sleep") - .about("Put the device to sleep") + .num_args(1..), + ), ) + .subcommand(Command::new("gasguage").about("Print gas gauge (battery) information")) + .subcommand(Command::new("nand").about("Print NAND flash information")) + .subcommand(Command::new("all").about("Print all available diagnostics information")) + .subcommand(Command::new("wifi").about("Print WiFi diagnostics information")) + .subcommand(Command::new("goodbye").about("Send Goodbye to diagnostics relay")) + .subcommand(Command::new("restart").about("Restart the device")) + .subcommand(Command::new("shutdown").about("Shutdown the device")) + .subcommand(Command::new("sleep").about("Put the device to sleep")) .get_matches(); if matches.get_flag("about") { - println!("idevicediagnostics - interact with the diagnostics interface of a device. Reimplementation of libimobiledevice's binary."); + println!( + "idevicediagnostics - interact with the diagnostics interface of a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } @@ -187,7 +165,8 @@ async fn handle_ioregistry(client: &mut DiagnosticsRelayClient, matches: &ArgMat } async fn handle_mobilegestalt(client: &mut DiagnosticsRelayClient, matches: &ArgMatches) { - let keys = matches.get_many::("keys") + let keys = matches + .get_many::("keys") .map(|values| values.map(|s| s.to_string()).collect::>()); match client.mobilegestalt(keys).await { @@ -297,4 +276,4 @@ async fn handle_goodbye(client: &mut DiagnosticsRelayClient) { Ok(()) => println!("Goodbye acknowledged by device"), Err(e) => eprintln!("Goodbye failed: {e:?}"), } -} \ No newline at end of file +} diff --git a/tools/src/heartbeat_client.rs b/tools/src/heartbeat_client.rs index bfb8d80..2ed1979 100644 --- a/tools/src/heartbeat_client.rs +++ b/tools/src/heartbeat_client.rs @@ -2,7 +2,7 @@ // Heartbeat client use clap::{Arg, Command}; -use idevice::{heartbeat::HeartbeatClient, IdeviceService}; +use idevice::{IdeviceService, heartbeat::HeartbeatClient}; mod common; diff --git a/tools/src/ideviceinfo.rs b/tools/src/ideviceinfo.rs index 1ec95b7..60bdf34 100644 --- a/tools/src/ideviceinfo.rs +++ b/tools/src/ideviceinfo.rs @@ -2,7 +2,7 @@ // idevice Rust implementation of libimobiledevice's ideviceinfo use clap::{Arg, Command}; -use idevice::{lockdown::LockdownClient, IdeviceService}; +use idevice::{IdeviceService, lockdown::LockdownClient}; mod common; @@ -39,7 +39,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("ideviceinfo - get information from the idevice. Reimplementation of libimobiledevice's binary."); + println!( + "ideviceinfo - get information from the idevice. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/instproxy.rs b/tools/src/instproxy.rs index f22b838..960a80c 100644 --- a/tools/src/instproxy.rs +++ b/tools/src/instproxy.rs @@ -2,7 +2,7 @@ // Just lists apps for now use clap::{Arg, Command}; -use idevice::{installation_proxy::InstallationProxyClient, IdeviceService}; +use idevice::{IdeviceService, installation_proxy::InstallationProxyClient}; mod common; @@ -47,7 +47,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("instproxy - query and manage apps installed on a device. Reimplementation of libimobiledevice's binary."); + println!( + "instproxy - query and manage apps installed on a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/location_simulation.rs b/tools/src/location_simulation.rs index 02c0a6d..10f62a0 100644 --- a/tools/src/location_simulation.rs +++ b/tools/src/location_simulation.rs @@ -2,7 +2,7 @@ // Just lists apps for now use clap::{Arg, Command}; -use idevice::{core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake, IdeviceService, RsdService}; +use idevice::{IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake}; mod common; diff --git a/tools/src/lockdown.rs b/tools/src/lockdown.rs index 842c7b4..ec164c5 100644 --- a/tools/src/lockdown.rs +++ b/tools/src/lockdown.rs @@ -1,7 +1,7 @@ // Jackson Coxson -use clap::{arg, Arg, Command}; -use idevice::{lockdown::LockdownClient, pretty_print_plist, IdeviceService}; +use clap::{Arg, Command, arg}; +use idevice::{IdeviceService, lockdown::LockdownClient, pretty_print_plist}; use plist::Value; mod common; @@ -52,7 +52,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("lockdown - query and manage values on a device. Reimplementation of libimobiledevice's binary."); + println!( + "lockdown - query and manage values on a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/misagent.rs b/tools/src/misagent.rs index 04057ac..966b86f 100644 --- a/tools/src/misagent.rs +++ b/tools/src/misagent.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; -use clap::{arg, value_parser, Arg, Command}; -use idevice::{misagent::MisagentClient, IdeviceService}; +use clap::{Arg, Command, arg, value_parser}; +use idevice::{IdeviceService, misagent::MisagentClient}; mod common; @@ -52,7 +52,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary."); + println!( + "mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/mobilebackup2.rs b/tools/src/mobilebackup2.rs index 4ec7259..e852d8f 100644 --- a/tools/src/mobilebackup2.rs +++ b/tools/src/mobilebackup2.rs @@ -2,7 +2,10 @@ // Mobile Backup 2 tool for iOS devices use clap::{Arg, Command}; -use idevice::{mobilebackup2::{MobileBackup2Client, RestoreOptions}, IdeviceService}; +use idevice::{ + IdeviceService, + mobilebackup2::{MobileBackup2Client, RestoreOptions}, +}; use plist::Dictionary; use std::fs; use std::io::{Read, Write}; @@ -44,13 +47,18 @@ async fn main() { Command::new("info") .about("Get backup information from a local backup directory") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) - .arg(Arg::new("source").long("source").value_name("SOURCE").help("Source identifier (defaults to current UDID)")) + .arg( + Arg::new("source") + .long("source") + .value_name("SOURCE") + .help("Source identifier (defaults to current UDID)"), + ), ) .subcommand( Command::new("list") .about("List files of the last backup from a local backup directory") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) - .arg(Arg::new("source").long("source").value_name("SOURCE")) + .arg(Arg::new("source").long("source").value_name("SOURCE")), ) .subcommand( Command::new("backup") @@ -79,41 +87,81 @@ async fn main() { Command::new("restore") .about("Restore from a local backup directory (DeviceLink)") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) - .arg(Arg::new("source").long("source").value_name("SOURCE").help("Source UDID; defaults to current device UDID")) - .arg(Arg::new("password").long("password").value_name("PWD").help("Backup password if encrypted")) - .arg(Arg::new("no-reboot").long("no-reboot").action(clap::ArgAction::SetTrue)) - .arg(Arg::new("no-copy").long("no-copy").action(clap::ArgAction::SetTrue)) - .arg(Arg::new("no-settings").long("no-settings").action(clap::ArgAction::SetTrue)) - .arg(Arg::new("system").long("system").action(clap::ArgAction::SetTrue)) - .arg(Arg::new("remove").long("remove").action(clap::ArgAction::SetTrue)) + .arg( + Arg::new("source") + .long("source") + .value_name("SOURCE") + .help("Source UDID; defaults to current device UDID"), + ) + .arg( + Arg::new("password") + .long("password") + .value_name("PWD") + .help("Backup password if encrypted"), + ) + .arg( + Arg::new("no-reboot") + .long("no-reboot") + .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("no-copy") + .long("no-copy") + .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("no-settings") + .long("no-settings") + .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("system") + .long("system") + .action(clap::ArgAction::SetTrue), + ) + .arg( + Arg::new("remove") + .long("remove") + .action(clap::ArgAction::SetTrue), + ), ) .subcommand( Command::new("unback") .about("Unpack a complete backup to device hierarchy") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) .arg(Arg::new("source").long("source").value_name("SOURCE")) - .arg(Arg::new("password").long("password").value_name("PWD")) + .arg(Arg::new("password").long("password").value_name("PWD")), ) .subcommand( Command::new("extract") .about("Extract a file from a previous backup") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) .arg(Arg::new("source").long("source").value_name("SOURCE")) - .arg(Arg::new("domain").long("domain").value_name("DOMAIN").required(true)) - .arg(Arg::new("path").long("path").value_name("REL_PATH").required(true)) - .arg(Arg::new("password").long("password").value_name("PWD")) + .arg( + Arg::new("domain") + .long("domain") + .value_name("DOMAIN") + .required(true), + ) + .arg( + Arg::new("path") + .long("path") + .value_name("REL_PATH") + .required(true), + ) + .arg(Arg::new("password").long("password").value_name("PWD")), ) .subcommand( Command::new("change-password") .about("Change backup password") .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) .arg(Arg::new("old").long("old").value_name("OLD")) - .arg(Arg::new("new").long("new").value_name("NEW")) + .arg(Arg::new("new").long("new").value_name("NEW")), ) .subcommand( Command::new("erase-device") .about("Erase the device via mobilebackup2") - .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)) + .arg(Arg::new("dir").long("dir").value_name("DIR").required(true)), ) .subcommand(Command::new("freespace").about("Get free space information")) .subcommand(Command::new("encryption").about("Check backup encryption status")) @@ -129,14 +177,14 @@ async fn main() { let host = matches.get_one::("host"); let pairing_file = matches.get_one::("pairing_file"); - let provider = match common::get_provider(udid, host, pairing_file, "mobilebackup2-jkcoxson").await - { - Ok(p) => p, - Err(e) => { - eprintln!("Error creating provider: {e}"); - return; - } - }; + let provider = + match common::get_provider(udid, host, pairing_file, "mobilebackup2-jkcoxson").await { + Ok(p) => p, + Err(e) => { + eprintln!("Error creating provider: {e}"); + return; + } + }; let mut backup_client = match MobileBackup2Client::connect(&*provider).await { Ok(client) => client, @@ -153,7 +201,9 @@ async fn main() { match backup_client.info_from_path(Path::new(dir), source).await { Ok(dict) => { println!("Backup Information:"); - for (k, v) in dict { println!(" {k}: {v:?}"); } + for (k, v) in dict { + println!(" {k}: {v:?}"); + } } Err(e) => eprintln!("Failed to get info: {e}"), } @@ -164,7 +214,9 @@ async fn main() { match backup_client.list_from_path(Path::new(dir), source).await { Ok(dict) => { println!("List Response:"); - for (k, v) in dict { println!(" {k}: {v:?}"); } + for (k, v) in dict { + println!(" {k}: {v:?}"); + } } Err(e) => eprintln!("Failed to list: {e}"), } @@ -172,7 +224,9 @@ async fn main() { Some(("backup", sub_matches)) => { let target = sub_matches.get_one::("target").map(|s| s.as_str()); let source = sub_matches.get_one::("source").map(|s| s.as_str()); - let dir = sub_matches.get_one::("dir").expect("dir is required"); + let dir = sub_matches + .get_one::("dir") + .expect("dir is required"); println!("Starting backup operation..."); let res = backup_client @@ -190,13 +244,28 @@ async fn main() { let dir = sub.get_one::("dir").unwrap(); let source = sub.get_one::("source").map(|s| s.as_str()); let mut ropts = RestoreOptions::new(); - if sub.get_flag("no-reboot") { ropts = ropts.with_reboot(false); } - if sub.get_flag("no-copy") { ropts = ropts.with_copy(false); } - if sub.get_flag("no-settings") { ropts = ropts.with_preserve_settings(false); } - if sub.get_flag("system") { ropts = ropts.with_system_files(true); } - if sub.get_flag("remove") { ropts = ropts.with_remove_items_not_restored(true); } - if let Some(pw) = sub.get_one::("password") { ropts = ropts.with_password(pw); } - match backup_client.restore_from_path(Path::new(dir), source, Some(ropts)).await { + if sub.get_flag("no-reboot") { + ropts = ropts.with_reboot(false); + } + if sub.get_flag("no-copy") { + ropts = ropts.with_copy(false); + } + if sub.get_flag("no-settings") { + ropts = ropts.with_preserve_settings(false); + } + if sub.get_flag("system") { + ropts = ropts.with_system_files(true); + } + if sub.get_flag("remove") { + ropts = ropts.with_remove_items_not_restored(true); + } + if let Some(pw) = sub.get_one::("password") { + ropts = ropts.with_password(pw); + } + match backup_client + .restore_from_path(Path::new(dir), source, Some(ropts)) + .await + { Ok(_) => println!("Restore flow finished"), Err(e) => eprintln!("Restore failed: {e}"), } @@ -205,7 +274,10 @@ async fn main() { let dir = sub.get_one::("dir").unwrap(); let source = sub.get_one::("source").map(|s| s.as_str()); let password = sub.get_one::("password").map(|s| s.as_str()); - match backup_client.unback_from_path(Path::new(dir), password, source).await { + match backup_client + .unback_from_path(Path::new(dir), password, source) + .await + { Ok(_) => println!("Unback finished"), Err(e) => eprintln!("Unback failed: {e}"), } @@ -216,7 +288,10 @@ async fn main() { let domain = sub.get_one::("domain").unwrap(); let rel = sub.get_one::("path").unwrap(); let password = sub.get_one::("password").map(|s| s.as_str()); - match backup_client.extract_from_path(domain, rel, Path::new(dir), password, source).await { + match backup_client + .extract_from_path(domain, rel, Path::new(dir), password, source) + .await + { Ok(_) => println!("Extract finished"), Err(e) => eprintln!("Extract failed: {e}"), } @@ -225,7 +300,10 @@ async fn main() { let dir = sub.get_one::("dir").unwrap(); let old = sub.get_one::("old").map(|s| s.as_str()); let newv = sub.get_one::("new").map(|s| s.as_str()); - match backup_client.change_password_from_path(Path::new(dir), old, newv).await { + match backup_client + .change_password_from_path(Path::new(dir), old, newv) + .await + { Ok(_) => println!("Change password finished"), Err(e) => eprintln!("Change password failed: {e}"), } @@ -237,23 +315,22 @@ async fn main() { Err(e) => eprintln!("Erase device failed: {e}"), } } - Some(("freespace", _)) => { - match backup_client.get_freespace().await { - Ok(freespace) => { - let freespace_gb = freespace as f64 / (1024.0 * 1024.0 * 1024.0); - println!("Free space: {freespace} bytes ({freespace_gb:.2} GB)"); - } - Err(e) => eprintln!("Failed to get free space: {e}"), + Some(("freespace", _)) => match backup_client.get_freespace().await { + Ok(freespace) => { + let freespace_gb = freespace as f64 / (1024.0 * 1024.0 * 1024.0); + println!("Free space: {freespace} bytes ({freespace_gb:.2} GB)"); } - } - Some(("encryption", _)) => { - match backup_client.check_backup_encryption().await { - Ok(is_encrypted) => { - println!("Backup encryption: {}", if is_encrypted { "Enabled" } else { "Disabled" }); - } - Err(e) => eprintln!("Failed to check backup encryption: {e}"), + Err(e) => eprintln!("Failed to get free space: {e}"), + }, + Some(("encryption", _)) => match backup_client.check_backup_encryption().await { + Ok(is_encrypted) => { + println!( + "Backup encryption: {}", + if is_encrypted { "Enabled" } else { "Disabled" } + ); } - } + Err(e) => eprintln!("Failed to check backup encryption: {e}"), + }, _ => { println!("No subcommand provided. Use --help for available commands."); } @@ -266,8 +343,7 @@ async fn main() { } use idevice::services::mobilebackup2::{ - DL_CODE_ERROR_LOCAL as CODE_ERROR_LOCAL, - DL_CODE_FILE_DATA as CODE_FILE_DATA, + DL_CODE_ERROR_LOCAL as CODE_ERROR_LOCAL, DL_CODE_FILE_DATA as CODE_FILE_DATA, DL_CODE_SUCCESS as CODE_SUCCESS, }; @@ -297,26 +373,36 @@ async fn process_dl_loop( } "DLMessageCreateDirectory" => { let status = create_directory_from_message(&value, host_dir); - client - .send_status_response(status, None, None) - .await?; + client.send_status_response(status, None, None).await?; } "DLMessageMoveFiles" | "DLMessageMoveItems" => { let status = move_files_from_message(&value, host_dir); client - .send_status_response(status, None, Some(plist::Value::Dictionary(Dictionary::new()))) + .send_status_response( + status, + None, + Some(plist::Value::Dictionary(Dictionary::new())), + ) .await?; } "DLMessageRemoveFiles" | "DLMessageRemoveItems" => { let status = remove_files_from_message(&value, host_dir); client - .send_status_response(status, None, Some(plist::Value::Dictionary(Dictionary::new()))) + .send_status_response( + status, + None, + Some(plist::Value::Dictionary(Dictionary::new())), + ) .await?; } "DLMessageCopyItem" => { let status = copy_item_from_message(&value, host_dir); client - .send_status_response(status, None, Some(plist::Value::Dictionary(Dictionary::new()))) + .send_status_response( + status, + None, + Some(plist::Value::Dictionary(Dictionary::new())), + ) .await?; } "DLMessageProcessMessage" => { @@ -353,23 +439,24 @@ async fn handle_download_files( && let Some(plist::Value::Array(files)) = arr.get(1) { for pv in files { - if let Some(path) = pv.as_string() - && let Err(e) = send_single_file(client, host_dir, path).await - { - eprintln!("Failed to send file {path}: {e}"); + if let Some(path) = pv.as_string() + && let Err(e) = send_single_file(client, host_dir, path).await + { + eprintln!("Failed to send file {path}: {e}"); err_any = true; } } } // terminating zero dword - client - .idevice - .send_raw(&0u32.to_be_bytes()) - .await?; + client.idevice.send_raw(&0u32.to_be_bytes()).await?; // status response if err_any { client - .send_status_response(-13, Some("Multi status"), Some(plist::Value::Dictionary(Dictionary::new()))) + .send_status_response( + -13, + Some("Multi status"), + Some(plist::Value::Dictionary(Dictionary::new())), + ) .await } else { client @@ -446,7 +533,8 @@ async fn handle_upload_files( if let Some(parent) = dst.parent() { let _ = fs::create_dir_all(parent); } - let mut file = std::fs::File::create(&dst).map_err(|e| idevice::IdeviceError::InternalError(e.to_string()))?; + let mut file = std::fs::File::create(&dst) + .map_err(|e| idevice::IdeviceError::InternalError(e.to_string()))?; loop { let nlen = read_be_u32(client).await?; if nlen == 0 { @@ -456,7 +544,8 @@ async fn handle_upload_files( if code == CODE_FILE_DATA { let size = (nlen - 1) as usize; let data = read_exact(client, size).await?; - file.write_all(&data).map_err(|e| idevice::IdeviceError::InternalError(e.to_string()))?; + file.write_all(&data) + .map_err(|e| idevice::IdeviceError::InternalError(e.to_string()))?; } else { let _ = read_exact(client, (nlen - 1) as usize).await?; } @@ -478,11 +567,17 @@ async fn read_one(client: &mut MobileBackup2Client) -> Result Result, idevice::IdeviceError> { +async fn read_exact( + client: &mut MobileBackup2Client, + size: usize, +) -> Result, idevice::IdeviceError> { client.idevice.read_raw(size).await } -async fn read_exact_string(client: &mut MobileBackup2Client, size: usize) -> Result { +async fn read_exact_string( + client: &mut MobileBackup2Client, + size: usize, +) -> Result { let buf = client.idevice.read_raw(size).await?; Ok(String::from_utf8_lossy(&buf).to_string()) } @@ -532,7 +627,9 @@ fn remove_files_from_message(dl_value: &plist::Value, host_dir: &Path) -> i64 { if let Some(p) = it.as_string() { let path = host_dir.join(p); if path.is_dir() { - if fs::remove_dir_all(&path).is_err() { return -1; } + if fs::remove_dir_all(&path).is_err() { + return -1; + } } else if path.exists() && fs::remove_file(&path).is_err() { return -1; } @@ -546,17 +643,26 @@ fn remove_files_from_message(dl_value: &plist::Value, host_dir: &Path) -> i64 { fn copy_item_from_message(dl_value: &plist::Value, host_dir: &Path) -> i64 { if let plist::Value::Array(arr) = dl_value && arr.len() >= 3 - && let (Some(plist::Value::String(src)), Some(plist::Value::String(dst))) = (arr.get(1), arr.get(2)) + && let (Some(plist::Value::String(src)), Some(plist::Value::String(dst))) = + (arr.get(1), arr.get(2)) { let from = host_dir.join(src); let to = host_dir.join(dst); - if let Some(parent) = to.parent() { let _ = fs::create_dir_all(parent); } + if let Some(parent) = to.parent() { + let _ = fs::create_dir_all(parent); + } if from.is_dir() { // shallow copy: create dir - return match fs::create_dir_all(&to) { Ok(_) => 0, Err(_) => -1 }; + return match fs::create_dir_all(&to) { + Ok(_) => 0, + Err(_) => -1, + }; } else { - return match fs::copy(&from, &to) { Ok(_) => 0, Err(_) => -1 }; + return match fs::copy(&from, &to) { + Ok(_) => 0, + Err(_) => -1, + }; } } -1 -} \ No newline at end of file +} diff --git a/tools/src/mounter.rs b/tools/src/mounter.rs index c59a472..1564a9d 100644 --- a/tools/src/mounter.rs +++ b/tools/src/mounter.rs @@ -3,10 +3,10 @@ use std::{io::Write, path::PathBuf}; -use clap::{arg, value_parser, Arg, Command}; +use clap::{Arg, Command, arg, value_parser}; use idevice::{ - lockdown::LockdownClient, mobile_image_mounter::ImageMounter, pretty_print_plist, - IdeviceService, + IdeviceService, lockdown::LockdownClient, mobile_image_mounter::ImageMounter, + pretty_print_plist, }; mod common; @@ -67,7 +67,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary."); + println!( + "mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/os_trace_relay.rs b/tools/src/os_trace_relay.rs index 45c1b76..b04d0f7 100644 --- a/tools/src/os_trace_relay.rs +++ b/tools/src/os_trace_relay.rs @@ -1,7 +1,7 @@ // Jackson Coxson use clap::{Arg, Command}; -use idevice::{os_trace_relay::OsTraceRelayClient, IdeviceService}; +use idevice::{IdeviceService, os_trace_relay::OsTraceRelayClient}; mod common; diff --git a/tools/src/pair.rs b/tools/src/pair.rs index 4ca173d..baf3315 100644 --- a/tools/src/pair.rs +++ b/tools/src/pair.rs @@ -2,9 +2,9 @@ use clap::{Arg, Command}; use idevice::{ + IdeviceService, lockdown::LockdownClient, usbmuxd::{Connection, UsbmuxdAddr, UsbmuxdConnection}, - IdeviceService, }; #[tokio::main] diff --git a/tools/src/process_control.rs b/tools/src/process_control.rs index 511df79..e74b4e9 100644 --- a/tools/src/process_control.rs +++ b/tools/src/process_control.rs @@ -1,7 +1,7 @@ // Jackson Coxson use clap::{Arg, Command}; -use idevice::{core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake, IdeviceService, RsdService}; +use idevice::{IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake}; mod common; diff --git a/tools/src/remotexpc.rs b/tools/src/remotexpc.rs index e4bc551..38a1a8a 100644 --- a/tools/src/remotexpc.rs +++ b/tools/src/remotexpc.rs @@ -3,8 +3,8 @@ use clap::{Arg, Command}; use idevice::{ - core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake, tcp::stream::AdapterStream, - IdeviceService, + IdeviceService, core_device_proxy::CoreDeviceProxy, rsd::RsdHandshake, + tcp::stream::AdapterStream, }; mod common; diff --git a/tools/src/restore_service.rs b/tools/src/restore_service.rs index e2dcd8a..448bd8c 100644 --- a/tools/src/restore_service.rs +++ b/tools/src/restore_service.rs @@ -2,8 +2,8 @@ use clap::{Arg, Command}; use idevice::{ - core_device_proxy::CoreDeviceProxy, pretty_print_dictionary, - restore_service::RestoreServiceClient, rsd::RsdHandshake, IdeviceService, RsdService, + IdeviceService, RsdService, core_device_proxy::CoreDeviceProxy, pretty_print_dictionary, + restore_service::RestoreServiceClient, rsd::RsdHandshake, }; mod common; @@ -51,7 +51,9 @@ async fn main() { .get_matches(); if matches.get_flag("about") { - println!("mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary."); + println!( + "mounter - query and manage images mounted on a device. Reimplementation of libimobiledevice's binary." + ); println!("Copyright (c) 2025 Jackson Coxson"); return; } diff --git a/tools/src/syslog_relay.rs b/tools/src/syslog_relay.rs index 0ebf483..c556fec 100644 --- a/tools/src/syslog_relay.rs +++ b/tools/src/syslog_relay.rs @@ -1,7 +1,7 @@ // Jackson Coxson use clap::{Arg, Command}; -use idevice::{syslog_relay::SyslogRelayClient, IdeviceService}; +use idevice::{IdeviceService, syslog_relay::SyslogRelayClient}; mod common;