Partial implementation for preboard sevice

This commit is contained in:
Jackson Coxson
2025-09-05 11:40:13 -06:00
parent 3a9c9f4705
commit a9739b4ce3
6 changed files with 176 additions and 1 deletions

View File

@@ -86,6 +86,7 @@ mobilebackup2 = []
location_simulation = []
pair = ["chrono/default", "tokio/time", "dep:sha2", "dep:rsa", "dep:x509-cert"]
pcapd = []
preboard_service = []
obfuscate = ["dep:obfstr"]
restore_service = []
rsd = ["xpc"]
@@ -122,6 +123,7 @@ full = [
"mobilebackup2",
"pair",
"pcapd",
"preboard_service",
"restore_service",
"rsd",
"springboardservices",

View File

@@ -379,7 +379,20 @@ impl Idevice {
debug!("Received plist: {}", pretty_print_dictionary(&res));
if let Some(e) = res.get("Error") {
let e: String = plist::from_value(e)?;
let e = match e {
plist::Value::String(e) => e.to_string(),
plist::Value::Integer(e) => {
if let Some(error_string) = res.get("ErrorString").and_then(|x| x.as_string()) {
error_string.to_string()
} else {
e.to_string()
}
}
_ => {
log::error!("Error is not a string or integer from read_plist: {e:?}");
return Err(IdeviceError::UnexpectedResponse);
}
};
if let Some(e) = IdeviceError::from_device_error_type(e.as_str(), &res) {
return Err(e);
} else {
@@ -698,6 +711,8 @@ pub enum IdeviceError {
MalformedCommand = -64,
#[error("integer overflow")]
IntegerOverflow = -65,
#[error("canceled by user")]
CanceledByUser = -66,
}
impl IdeviceError {
@@ -710,6 +725,9 @@ impl IdeviceError {
/// # Returns
/// Some(IdeviceError) if the string maps to a known error type, None otherwise
fn from_device_error_type(e: &str, context: &plist::Dictionary) -> Option<Self> {
if e.contains("NSDebugDescription=Canceled by user.") {
return Some(Self::CanceledByUser);
}
match e {
"GetProhibited" => Some(Self::GetProhibited),
"InvalidHostID" => Some(Self::InvalidHostID),
@@ -849,6 +867,7 @@ impl IdeviceError {
IdeviceError::UnsupportedWatchKey => -63,
IdeviceError::MalformedCommand => -64,
IdeviceError::IntegerOverflow => -65,
IdeviceError::CanceledByUser => -66,
}
}
}

View File

@@ -35,6 +35,8 @@ pub mod mobilebackup2;
pub mod os_trace_relay;
#[cfg(feature = "pcapd")]
pub mod pcapd;
#[cfg(feature = "preboard_service")]
pub mod preboard_service;
#[cfg(feature = "restore_service")]
pub mod restore_service;
#[cfg(feature = "rsd")]

View File

@@ -0,0 +1,72 @@
//! Abstraction for preboard
use crate::{Idevice, IdeviceError, IdeviceService, RsdService, obf};
/// Client for interacting with the preboard service on the device.
pub struct PreboardServiceClient {
/// The underlying device connection with established service
pub idevice: Idevice,
}
impl IdeviceService for PreboardServiceClient {
fn service_name() -> std::borrow::Cow<'static, str> {
obf!("com.apple.preboardservice_v2")
}
async fn from_stream(idevice: Idevice) -> Result<Self, crate::IdeviceError> {
Ok(Self::new(idevice))
}
}
impl RsdService for PreboardServiceClient {
fn rsd_service_name() -> std::borrow::Cow<'static, str> {
obf!("com.apple.preboardservice_v2.shim.remote")
}
async fn from_stream(stream: Box<dyn crate::ReadWrite>) -> Result<Self, crate::IdeviceError> {
let mut idevice = Idevice::new(stream, "");
idevice.rsd_checkin().await?;
Ok(Self::new(idevice))
}
}
impl PreboardServiceClient {
pub fn new(idevice: Idevice) -> Self {
Self { idevice }
}
pub async fn create_stashbag(&mut self, manifest: &[u8]) -> Result<(), IdeviceError> {
let req = crate::plist!({
"Command": "CreateStashbag",
"Manifest": manifest
});
self.idevice.send_plist(req).await?;
let res = self.idevice.read_plist().await?;
if let Some(res) = res.get("ShowDialog").and_then(|x| x.as_boolean()) {
if !res {
log::warn!("ShowDialog is not true");
return Err(IdeviceError::UnexpectedResponse);
}
} else {
log::warn!("No ShowDialog in response from service");
return Err(IdeviceError::UnexpectedResponse);
}
self.idevice.read_plist().await?;
Ok(())
}
pub async fn commit_stashbag(&mut self, manifest: &[u8]) -> Result<(), IdeviceError> {
let req = crate::plist!({
"Command": "CommitStashbag",
"Manifest": manifest
});
self.idevice.send_plist(req).await?;
self.idevice.read_plist().await?;
Ok(())
}
pub async fn clear_system_token(&mut self) -> Result<(), IdeviceError> {
todo!()
}
}