diff --git a/ffi/src/lockdown.rs b/ffi/src/lockdown.rs index acfa5f4..1034394 100644 --- a/ffi/src/lockdown.rs +++ b/ffi/src/lockdown.rs @@ -210,7 +210,8 @@ pub unsafe extern "C" fn lockdownd_start_service( /// /// # Arguments /// * `client` - A valid LockdowndClient handle -/// * `value` - The value to get (null-terminated string) +/// * `key` - The value to get (null-terminated string) +/// * `domain` - The value to get (null-terminated string) /// * `out_plist` - Pointer to store the returned plist value /// /// # Returns @@ -223,21 +224,32 @@ pub unsafe extern "C" fn lockdownd_start_service( #[unsafe(no_mangle)] pub unsafe extern "C" fn lockdownd_get_value( client: *mut LockdowndClientHandle, - value: *const libc::c_char, + key: *const libc::c_char, + domain: *const libc::c_char, out_plist: *mut *mut c_void, ) -> IdeviceErrorCode { - if value.is_null() || out_plist.is_null() { + if key.is_null() || out_plist.is_null() { return IdeviceErrorCode::InvalidArg; } - let value = unsafe { std::ffi::CStr::from_ptr(value) } + let value = unsafe { std::ffi::CStr::from_ptr(key) } .to_string_lossy() .into_owned(); + let domain = if domain.is_null() { + None + } else { + Some( + unsafe { std::ffi::CStr::from_ptr(domain) } + .to_string_lossy() + .into_owned(), + ) + }; + let res: Result = RUNTIME.block_on(async move { let mut client_box = unsafe { Box::from_raw(client) }; let client_ref = &mut client_box.0; - let res = client_ref.get_value(value).await; + let res = client_ref.get_value(value, domain).await; std::mem::forget(client_box); res }); diff --git a/idevice/src/lockdown.rs b/idevice/src/lockdown.rs index f690e02..4e301b0 100644 --- a/idevice/src/lockdown.rs +++ b/idevice/src/lockdown.rs @@ -84,14 +84,25 @@ impl LockdownClient { /// let device_name = client.get_value("DeviceName").await?; /// println!("Device name: {:?}", device_name); /// ``` - pub async fn get_value(&mut self, value: impl Into) -> Result { - let req = LockdownRequest { - label: self.idevice.label.clone(), - key: Some(value.into()), - request: "GetValue".to_string(), - }; - let message = plist::to_value(&req)?; - self.idevice.send_plist(message).await?; + pub async fn get_value( + &mut self, + key: impl Into, + domain: Option, + ) -> Result { + let key = key.into(); + + let mut request = plist::Dictionary::new(); + request.insert("Label".into(), self.idevice.label.clone().into()); + request.insert("Request".into(), "GetValue".into()); + request.insert("Key".into(), key.into()); + + if let Some(domain) = domain { + request.insert("Domain".into(), domain.into()); + } + + self.idevice + .send_plist(plist::Value::Dictionary(request)) + .await?; let message: plist::Dictionary = self.idevice.read_plist().await?; match message.get("Value") { Some(m) => Ok(m.to_owned()), diff --git a/tools/src/ideviceinfo.rs b/tools/src/ideviceinfo.rs index e47ad1a..d882ebd 100644 --- a/tools/src/ideviceinfo.rs +++ b/tools/src/ideviceinfo.rs @@ -65,7 +65,10 @@ async fn main() { } }; - println!("{:?}", lockdown_client.get_value("ProductVersion").await); + println!( + "{:?}", + lockdown_client.get_value("ProductVersion", None).await + ); println!( "{:?}", diff --git a/tools/src/mounter.rs b/tools/src/mounter.rs index 56a28a9..8e7eff1 100644 --- a/tools/src/mounter.rs +++ b/tools/src/mounter.rs @@ -89,14 +89,17 @@ async fn main() { .await .expect("Unable to connect to lockdown"); - let product_version = match lockdown_client.get_value("ProductVersion").await { + let product_version = match lockdown_client.get_value("ProductVersion", None).await { Ok(p) => p, Err(_) => { lockdown_client .start_session(&provider.get_pairing_file().await.unwrap()) .await .unwrap(); - lockdown_client.get_value("ProductVersion").await.unwrap() + lockdown_client + .get_value("ProductVersion", None) + .await + .unwrap() } }; let product_version = product_version @@ -179,7 +182,7 @@ async fn main() { .await .expect("Unable to read signature"); - let unique_chip_id = match lockdown_client.get_value("UniqueChipID").await { + let unique_chip_id = match lockdown_client.get_value("UniqueChipID", None).await { Ok(u) => u, Err(_) => { lockdown_client @@ -187,7 +190,7 @@ async fn main() { .await .expect("Unable to start session"); lockdown_client - .get_value("UniqueChipID") + .get_value("UniqueChipID", None) .await .expect("Unable to get UniqueChipID") }