From 29639be29aa2140766a3ac1390f39880554f64ad Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Wed, 8 Jan 2025 19:34:51 -0700 Subject: [PATCH] Add tool binaries --- Cargo.toml | 8 +++ src/tools/heartbeat_client.rs | 93 +++++++++++++++++++++++++++++++++++ src/tools/ideviceinfo.rs | 75 ++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 src/tools/heartbeat_client.rs create mode 100644 src/tools/ideviceinfo.rs diff --git a/Cargo.toml b/Cargo.toml index 123a3e9..74440f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,14 @@ name = "idevice" version = "0.1.0" edition = "2021" +[[bin]] +name = "ideviceinfo" +path = "src/tools/ideviceinfo.rs" + +[[bin]] +name = "heartbeat_client" +path = "src/tools/heartbeat_client.rs" + [dependencies] plist = { version = "1.7" } serde = { version = "1", features = ["derive"] } diff --git a/src/tools/heartbeat_client.rs b/src/tools/heartbeat_client.rs new file mode 100644 index 0000000..9558e8b --- /dev/null +++ b/src/tools/heartbeat_client.rs @@ -0,0 +1,93 @@ +// Jackson Coxson +// Heartbeat client + +use idevice::{ + heartbeat::HeartbeatClient, + lockdownd::{self, LockdowndClient}, + pairing_file::PairingFile, + Idevice, +}; + +use std::{ + net::{Ipv4Addr, SocketAddrV4}, + str::FromStr, +}; + +fn main() { + env_logger::init(); + let mut host = None; + let mut pairing_file = None; + + // Loop through args + let mut i = 0; + while i < std::env::args().len() { + match std::env::args().nth(i).unwrap().as_str() { + "--host" => { + host = Some(std::env::args().nth(i + 1).unwrap().to_string()); + i += 2; + } + "--pairing-file" => { + pairing_file = Some(std::env::args().nth(i + 1).unwrap().to_string()); + i += 2; + } + "-h" | "--help" => { + println!("ideviceinfo - get information from the idevice"); + println!("Usage:"); + println!(" ideviceinfo [options]"); + println!("Options:"); + println!(" --host "); + println!(" --pairing_file "); + println!(" -h, --help"); + println!(" --about"); + println!("\n\nSet RUST_LOG to info, debug, warn, error, or trace to see more logs. Default is error."); + std::process::exit(0); + } + "--about" => { + println!("ideviceinfo - get information from the idevice. Reimplementation of libimobiledevice's binary."); + println!("Copyright (c) 2025 Jackson Coxson"); + } + _ => { + i += 1; + } + } + } + if host.is_none() { + println!("Invalid arguments! Pass the IP of the device with --host"); + return; + } + if pairing_file.is_none() { + println!("Invalid arguments! Pass the path the the pairing file with --pairing-file"); + return; + } + let ip = Ipv4Addr::from_str(host.unwrap().as_str()).unwrap(); + let socket = SocketAddrV4::new(ip, lockdownd::LOCKDOWND_PORT); + + let socket = std::net::TcpStream::connect(socket).unwrap(); + let socket = Box::new(socket); + let idevice = Idevice::new(socket, "heartbeat_client"); + + let p = PairingFile::read_from_file(pairing_file.as_ref().unwrap()).unwrap(); + + let mut lockdown_client = LockdowndClient { idevice }; + lockdown_client.start_session(p).unwrap(); + + let (port, _) = lockdown_client + .start_service("com.apple.mobile.heartbeat") + .unwrap(); + + let socket = SocketAddrV4::new(ip, port); + let socket = std::net::TcpStream::connect(socket).unwrap(); + let socket = Box::new(socket); + let mut idevice = Idevice::new(socket, "heartbeat_client"); + + let p = PairingFile::read_from_file(pairing_file.unwrap()).unwrap(); + + idevice.start_session(p).unwrap(); + + let mut heartbeat_client = HeartbeatClient { idevice }; + + loop { + heartbeat_client.get_marco().unwrap(); + heartbeat_client.send_polo().unwrap(); + } +} diff --git a/src/tools/ideviceinfo.rs b/src/tools/ideviceinfo.rs new file mode 100644 index 0000000..e1e680a --- /dev/null +++ b/src/tools/ideviceinfo.rs @@ -0,0 +1,75 @@ +// Jackson Coxson +// idevice Rust implementation of libimobiledevice's ideviceinfo + +use std::{ + net::{Ipv4Addr, SocketAddrV4}, + str::FromStr, +}; + +use idevice::{ + lockdownd::{self, LockdowndClient}, + pairing_file::PairingFile, + Idevice, +}; + +fn main() { + env_logger::init(); + let mut host = None; + let mut pairing_file = None; + + // Loop through args + let mut i = 0; + while i < std::env::args().len() { + match std::env::args().nth(i).unwrap().as_str() { + "--host" => { + host = Some(std::env::args().nth(i + 1).unwrap().to_string()); + i += 2; + } + "--pairing-file" => { + pairing_file = Some(std::env::args().nth(i + 1).unwrap().to_string()); + i += 2; + } + "-h" | "--help" => { + println!("ideviceinfo - get information from the idevice"); + println!("Usage:"); + println!(" ideviceinfo [options]"); + println!("Options:"); + println!(" --host "); + println!(" --pairing_file "); + println!(" -h, --help"); + println!(" --about"); + println!("\n\nSet RUST_LOG to info, debug, warn, error, or trace to see more logs. Default is error."); + std::process::exit(0); + } + "--about" => { + println!("ideviceinfo - get information from the idevice. Reimplementation of libimobiledevice's binary."); + println!("Copyright (c) 2025 Jackson Coxson"); + } + _ => { + i += 1; + } + } + } + if host.is_none() { + println!("Invalid arguments! Pass the IP of the device with --host"); + return; + } + if pairing_file.is_none() { + println!("Invalid arguments! Pass the path the the pairing file with --pairing-file"); + return; + } + let ip = Ipv4Addr::from_str(host.unwrap().as_str()).unwrap(); + let socket = SocketAddrV4::new(ip, lockdownd::LOCKDOWND_PORT); + + let socket = std::net::TcpStream::connect(socket).unwrap(); + let socket = Box::new(socket); + let idevice = Idevice::new(socket, "ideviceinfo-jkcoxson"); + + let mut lockdown_client = LockdowndClient::new(idevice); + println!("{:?}", lockdown_client.get_value("ProductVersion")); + + let p = PairingFile::read_from_file(pairing_file.unwrap()).unwrap(); + println!("{:?}", lockdown_client.start_session(p)); + println!("{:?}", lockdown_client.idevice.get_type().unwrap()); + println!("{:#?}", lockdown_client.get_all_values()); +}