Add domain to lockdown get value

This commit is contained in:
Jackson Coxson
2025-04-06 22:36:38 -06:00
parent 8a7fc3cc4b
commit 6056fddf3f
4 changed files with 47 additions and 18 deletions

View File

@@ -210,7 +210,8 @@ pub unsafe extern "C" fn lockdownd_start_service(
/// ///
/// # Arguments /// # Arguments
/// * `client` - A valid LockdowndClient handle /// * `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 /// * `out_plist` - Pointer to store the returned plist value
/// ///
/// # Returns /// # Returns
@@ -223,21 +224,32 @@ pub unsafe extern "C" fn lockdownd_start_service(
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
pub unsafe extern "C" fn lockdownd_get_value( pub unsafe extern "C" fn lockdownd_get_value(
client: *mut LockdowndClientHandle, client: *mut LockdowndClientHandle,
value: *const libc::c_char, key: *const libc::c_char,
domain: *const libc::c_char,
out_plist: *mut *mut c_void, out_plist: *mut *mut c_void,
) -> IdeviceErrorCode { ) -> IdeviceErrorCode {
if value.is_null() || out_plist.is_null() { if key.is_null() || out_plist.is_null() {
return IdeviceErrorCode::InvalidArg; return IdeviceErrorCode::InvalidArg;
} }
let value = unsafe { std::ffi::CStr::from_ptr(value) } let value = unsafe { std::ffi::CStr::from_ptr(key) }
.to_string_lossy() .to_string_lossy()
.into_owned(); .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<plist::Value, IdeviceError> = RUNTIME.block_on(async move { let res: Result<plist::Value, IdeviceError> = RUNTIME.block_on(async move {
let mut client_box = unsafe { Box::from_raw(client) }; let mut client_box = unsafe { Box::from_raw(client) };
let client_ref = &mut client_box.0; 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); std::mem::forget(client_box);
res res
}); });

View File

@@ -84,14 +84,25 @@ impl LockdownClient {
/// let device_name = client.get_value("DeviceName").await?; /// let device_name = client.get_value("DeviceName").await?;
/// println!("Device name: {:?}", device_name); /// println!("Device name: {:?}", device_name);
/// ``` /// ```
pub async fn get_value(&mut self, value: impl Into<String>) -> Result<Value, IdeviceError> { pub async fn get_value(
let req = LockdownRequest { &mut self,
label: self.idevice.label.clone(), key: impl Into<String>,
key: Some(value.into()), domain: Option<String>,
request: "GetValue".to_string(), ) -> Result<Value, IdeviceError> {
}; let key = key.into();
let message = plist::to_value(&req)?;
self.idevice.send_plist(message).await?; 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?; let message: plist::Dictionary = self.idevice.read_plist().await?;
match message.get("Value") { match message.get("Value") {
Some(m) => Ok(m.to_owned()), Some(m) => Ok(m.to_owned()),

View File

@@ -65,7 +65,10 @@ async fn main() {
} }
}; };
println!("{:?}", lockdown_client.get_value("ProductVersion").await); println!(
"{:?}",
lockdown_client.get_value("ProductVersion", None).await
);
println!( println!(
"{:?}", "{:?}",

View File

@@ -89,14 +89,17 @@ async fn main() {
.await .await
.expect("Unable to connect to lockdown"); .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, Ok(p) => p,
Err(_) => { Err(_) => {
lockdown_client lockdown_client
.start_session(&provider.get_pairing_file().await.unwrap()) .start_session(&provider.get_pairing_file().await.unwrap())
.await .await
.unwrap(); .unwrap();
lockdown_client.get_value("ProductVersion").await.unwrap() lockdown_client
.get_value("ProductVersion", None)
.await
.unwrap()
} }
}; };
let product_version = product_version let product_version = product_version
@@ -179,7 +182,7 @@ async fn main() {
.await .await
.expect("Unable to read signature"); .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, Ok(u) => u,
Err(_) => { Err(_) => {
lockdown_client lockdown_client
@@ -187,7 +190,7 @@ async fn main() {
.await .await
.expect("Unable to start session"); .expect("Unable to start session");
lockdown_client lockdown_client
.get_value("UniqueChipID") .get_value("UniqueChipID", None)
.await .await
.expect("Unable to get UniqueChipID") .expect("Unable to get UniqueChipID")
} }