diff --git a/idevice/src/usbmuxd/mod.rs b/idevice/src/usbmuxd/mod.rs index d1eebad..9953feb 100644 --- a/idevice/src/usbmuxd/mod.rs +++ b/idevice/src/usbmuxd/mod.rs @@ -335,6 +335,32 @@ impl UsbmuxdConnection { } } + /// Tells usbmuxd to save the pairing record in its storage + /// + /// # Arguments + /// * `device_id` - usbmuxd device ID + /// * `udid` - the device UDID/serial + /// * `pair_record` - a serialized plist of the pair record + pub async fn save_pair_record( + &mut self, + device_id: u32, + udid: &str, + pair_record: Vec, + ) -> Result<(), IdeviceError> { + let req = crate::plist!(dict { + "MessageType": "SavePairRecord", + "PairRecordData": pair_record, + "DeviceID": device_id, + "PairRecordID": udid, + }); + self.write_plist(req).await?; + let res = self.read_plist().await?; + match res.get("Number").and_then(|x| x.as_unsigned_integer()) { + Some(0) => Ok(()), + _ => Err(IdeviceError::UnexpectedResponse), + } + } + /// Writes a PLIST message to usbmuxd async fn write_plist(&mut self, req: plist::Dictionary) -> Result<(), IdeviceError> { let raw = raw_packet::RawPacket::new( diff --git a/tools/src/pair.rs b/tools/src/pair.rs index baf3315..3425e1f 100644 --- a/tools/src/pair.rs +++ b/tools/src/pair.rs @@ -74,10 +74,13 @@ async fn main() { .expect("Pairing file test failed"); // Add the UDID (jitterbug spec) - pairing_file.udid = Some(dev.udid); + pairing_file.udid = Some(dev.udid.clone()); + let pairing_file = pairing_file.serialize().expect("failed to serialize"); - println!( - "{}", - String::from_utf8(pairing_file.serialize().unwrap()).unwrap() - ); + println!("{}", String::from_utf8(pairing_file.clone()).unwrap()); + + // Save with usbmuxd + u.save_pair_record(dev.device_id, &dev.udid, pairing_file) + .await + .expect("no save"); }