mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
120 lines
3.8 KiB
Rust
120 lines
3.8 KiB
Rust
// Jackson Coxson
|
|
|
|
use clap::{Arg, Command, arg};
|
|
use idevice::{IdeviceService, lockdown::LockdownClient, pretty_print_plist};
|
|
use plist::Value;
|
|
|
|
mod common;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
env_logger::init();
|
|
|
|
let matches = Command::new("lockdown")
|
|
.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),
|
|
)
|
|
.subcommand(
|
|
Command::new("get")
|
|
.about("Gets a value")
|
|
.arg(arg!(-v --value <STRING> "the value to get").required(false))
|
|
.arg(arg!(-d --domain <STRING> "the domain to get in").required(false)),
|
|
)
|
|
.subcommand(
|
|
Command::new("set")
|
|
.about("Sets a lockdown value")
|
|
.arg(arg!(-k --key <STRING> "the key to set").required(true))
|
|
.arg(arg!(-v --value <STRING> "the value to set the key to").required(true))
|
|
.arg(arg!(-d --domain <STRING> "the domain to get in").required(false)),
|
|
)
|
|
.get_matches();
|
|
|
|
if matches.get_flag("about") {
|
|
println!(
|
|
"lockdown - query and manage values on a device. 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 = LockdownClient::connect(&*provider)
|
|
.await
|
|
.expect("Unable to connect to lockdown");
|
|
|
|
lockdown_client
|
|
.start_session(&provider.get_pairing_file().await.expect("no pairing file"))
|
|
.await
|
|
.expect("no session");
|
|
|
|
match matches.subcommand() {
|
|
Some(("get", sub_m)) => {
|
|
let key = sub_m.get_one::<String>("value").map(|x| x.as_str());
|
|
let domain = sub_m.get_one::<String>("domain").map(|x| x.as_str());
|
|
|
|
match lockdown_client.get_value(key, domain).await {
|
|
Ok(value) => {
|
|
println!("{}", pretty_print_plist(&value));
|
|
}
|
|
Err(e) => {
|
|
eprintln!("Error getting value: {e}");
|
|
}
|
|
}
|
|
}
|
|
|
|
Some(("set", sub_m)) => {
|
|
let key = sub_m.get_one::<String>("key").unwrap();
|
|
let value_str = sub_m.get_one::<String>("value").unwrap();
|
|
let domain = sub_m.get_one::<String>("domain");
|
|
|
|
let value = Value::String(value_str.clone());
|
|
|
|
match lockdown_client
|
|
.set_value(key, value, domain.map(|x| x.as_str()))
|
|
.await
|
|
{
|
|
Ok(()) => println!("Successfully set"),
|
|
Err(e) => eprintln!("Error setting value: {e}"),
|
|
}
|
|
}
|
|
|
|
_ => {
|
|
eprintln!("No subcommand provided. Try `--help` for usage.");
|
|
}
|
|
}
|
|
}
|