Implement new library for tools

This commit is contained in:
Jackson Coxson
2025-02-01 15:49:23 -07:00
parent e61ac5ba45
commit 235de5dab9
8 changed files with 378 additions and 352 deletions

View File

@@ -1,72 +1,77 @@
// Jackson Coxson
// idevice Rust implementation of libimobiledevice's ideviceinfo
use std::{
net::{Ipv4Addr, SocketAddrV4},
str::FromStr,
};
use clap::{Arg, Command};
use idevice::{lockdownd::LockdowndClient, pairing_file::PairingFile, IdeviceService};
use idevice::{
lockdownd::{self, LockdowndClient},
pairing_file::PairingFile,
Idevice,
};
mod common;
#[tokio::main]
async 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 <host>");
println!(" --pairing_file <path>");
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;
let matches = Command::new("core_device_proxy_tun")
.about("Start a tunnel")
.arg(
Arg::new("host")
.long("host")
.value_name("HOST")
.help("IP address of the device"),
)
.arg(
Arg::new("pairing_file")
.long("pairing-file")
.value_name("PATH")
.help("Path to the pairing file"),
)
.arg(
Arg::new("udid")
.value_name("UDID")
.help("UDID of the device (overrides host/pairing file)")
.index(1),
)
.arg(
Arg::new("about")
.long("about")
.help("Show about information")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("help")
.short('h')
.long("help")
.help("Show this help message")
.action(clap::ArgAction::SetTrue),
)
.get_matches();
if matches.get_flag("about") {
println!("ideviceinfo - get information from the idevice. Reimplementation of libimobiledevice's binary.");
println!("Copyright (c) 2025 Jackson Coxson");
return;
}
let udid = matches.get_one::<String>("udid");
let host = matches.get_one::<String>("host");
let pairing_file = matches.get_one::<String>("pairing_file");
let provider =
match common::get_provider(udid, host, pairing_file, "ideviceinfo-jkcoxson").await {
Ok(p) => p,
Err(e) => {
eprintln!("{e}");
return;
}
};
let mut lockdown_client = match LockdowndClient::connect(&*provider).await {
Ok(l) => l,
Err(e) => {
eprintln!("Unable to connect to lockdown: {e:?}");
return;
}
}
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 = tokio::net::TcpStream::connect(socket).await.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").await);
let p = PairingFile::read_from_file(pairing_file.unwrap()).unwrap();