Allow for domain lookups for get_all

This commit is contained in:
Jackson Coxson
2025-07-03 09:43:00 -06:00
parent 4059e47a6e
commit 71a223f669
4 changed files with 148 additions and 8 deletions

View File

@@ -127,13 +127,18 @@ impl LockdownClient {
/// println!("{}: {:?}", key, value);
/// }
/// ```
pub async fn get_all_values(&mut self) -> Result<plist::Dictionary, IdeviceError> {
let req = LockdownRequest {
label: self.idevice.label.clone(),
key: None,
request: "GetValue".to_string(),
};
let message = plist::to_value(&req)?;
pub async fn get_all_values(
&mut self,
domain: Option<String>,
) -> Result<plist::Dictionary, IdeviceError> {
let mut request = plist::Dictionary::new();
request.insert("Label".into(), self.idevice.label.clone().into());
request.insert("Request".into(), "GetValue".into());
if let Some(domain) = domain {
request.insert("Domain".into(), domain.into());
}
let message = plist::to_value(&request)?;
self.idevice.send_plist(message).await?;
let message: plist::Dictionary = self.idevice.read_plist().await?;
match message.get("Value") {

View File

@@ -81,6 +81,10 @@ path = "src/syslog_relay.rs"
name = "os_trace_relay"
path = "src/os_trace_relay.rs"
[[bin]]
name = "lockdown"
path = "src/lockdown.rs"
[dependencies]
idevice = { path = "../idevice", features = ["full"] }
tokio = { version = "1.43", features = ["io-util", "macros", "time", "full"] }

View File

@@ -82,5 +82,5 @@ async fn main() {
.await
);
println!("{:?}", lockdown_client.idevice.get_type().await.unwrap());
println!("{:#?}", lockdown_client.get_all_values().await);
println!("{:#?}", lockdown_client.get_all_values(None).await);
}

131
tools/src/lockdown.rs Normal file
View File

@@ -0,0 +1,131 @@
// Jackson Coxson
use clap::{arg, Arg, Command};
use idevice::{lockdown::LockdownClient, pretty_print_plist, IdeviceService};
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(true))
.arg(arg!(-d --domain <STRING> "the domain to get in").required(false)),
)
.subcommand(
Command::new("get_all")
.about("Gets all")
.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").unwrap();
let domain = sub_m.get_one::<String>("domain").cloned();
match lockdown_client.get_value(key, domain).await {
Ok(value) => {
println!("{}", pretty_print_plist(&value));
}
Err(e) => {
eprintln!("Error getting value: {e}");
}
}
}
Some(("get_all", sub_m)) => {
let domain = sub_m.get_one::<String>("domain").cloned();
match lockdown_client.get_all_values(domain).await {
Ok(value) => {
println!("{}", pretty_print_plist(&plist::Value::Dictionary(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").cloned();
let value = Value::String(value_str.clone());
match lockdown_client.set_value(key, value, domain).await {
Ok(()) => println!("Successfully set"),
Err(e) => eprintln!("Error setting value: {e}"),
}
}
_ => {
eprintln!("No subcommand provided. Try `--help` for usage.");
}
}
}