Create pair program

This commit is contained in:
Jackson Coxson
2025-04-29 15:32:50 -06:00
parent 521fe088cd
commit 388aaef42e
3 changed files with 738 additions and 292 deletions

View File

@@ -65,6 +65,10 @@ path = "src/afc.rs"
name = "amfi"
path = "src/amfi.rs"
[[bin]]
name = "pair"
path = "src/pair.rs"
[dependencies]
idevice = { path = "../idevice", features = ["full"] }
tokio = { version = "1.43", features = ["io-util", "macros", "time", "full"] }
@@ -76,3 +80,12 @@ ureq = { version = "3" }
clap = { version = "4.5" }
plist = { version = "1.7" }
ns-keyed-archive = "0.1.2"
uuid = "1.16"
mac_address = "1.1"
# When testing the pair binary, creating certificates takes forever
[profile.dev.package.idevice]
opt-level = 3
[profile.dev]
opt-level = 3

81
tools/src/pair.rs Normal file
View File

@@ -0,0 +1,81 @@
// Jackson Coxson
use clap::{Arg, Command};
use idevice::{
lockdown::LockdownClient,
usbmuxd::{Connection, UsbmuxdAddr, UsbmuxdConnection},
IdeviceService,
};
use mac_address::get_mac_address;
mod common;
#[tokio::main]
async fn main() {
env_logger::init();
let matches = Command::new("pair")
.about("Pair with the device")
.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),
)
.get_matches();
if matches.get_flag("about") {
println!("pair - pair with the device");
println!("Copyright (c) 2025 Jackson Coxson");
return;
}
let udid = matches.get_one::<String>("udid");
let mut u = UsbmuxdConnection::default()
.await
.expect("Failed to connect to usbmuxd");
let dev = match udid {
Some(udid) => u
.get_device(udid)
.await
.expect("Failed to get device with specific udid"),
None => u
.get_devices()
.await
.expect("Failed to get devices")
.into_iter()
.find(|x| x.connection_type == Connection::Usb)
.expect("No devices connected via USB"),
};
let provider = dev.to_provider(UsbmuxdAddr::default(), "pair-jkcoxson");
let mut lockdown_client = match LockdownClient::connect(&provider).await {
Ok(l) => l,
Err(e) => {
eprintln!("Unable to connect to lockdown: {e:?}");
return;
}
};
let mac_address = get_mac_address()
.expect("Failed to get MAC")
.expect("No MAC??")
.to_string();
let id = uuid::Uuid::new_v4().to_string().to_uppercase();
let pairing_file = lockdown_client
.pair(id, mac_address, u.get_buid().await.unwrap())
.await
.expect("Failed to pair");
println!(
"{}",
String::from_utf8(pairing_file.serialize().unwrap()).unwrap()
);
}