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
/// * `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<plist::Value, IdeviceError> = 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
});

View File

@@ -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<String>) -> Result<Value, IdeviceError> {
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<String>,
domain: Option<String>,
) -> Result<Value, IdeviceError> {
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()),

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!(
"{:?}",

View File

@@ -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")
}