Implement restore_service

Remove pcap dump
This commit is contained in:
Jackson Coxson
2025-07-18 19:35:55 -06:00
parent ff76efd7bb
commit e4646ddffd
5 changed files with 370 additions and 5 deletions

View File

@@ -71,6 +71,7 @@ mobile_image_mounter = ["dep:sha2"]
location_simulation = []
pair = ["chrono/default", "tokio/time", "dep:sha2", "dep:rsa", "dep:x509-cert"]
obfuscate = ["dep:obfstr"]
restore_service = []
rsd = ["xpc"]
syslog_relay = ["dep:bytes"]
tcp = ["tokio/net"]
@@ -89,19 +90,20 @@ full = [
"heartbeat",
"house_arrest",
"installation_proxy",
"location_simulation",
"misagent",
"mobile_image_mounter",
"pair",
"usbmuxd",
"xpc",
"location_simulation",
"restore_service",
"rsd",
"springboardservices",
"syslog_relay",
"tcp",
"tunnel_tcp_stack",
"tss",
"tunneld",
"springboardservices",
"syslog_relay",
"usbmuxd",
"xpc",
]
[package.metadata.docs.rs]

View File

@@ -23,6 +23,8 @@ pub mod misagent;
pub mod mobile_image_mounter;
#[cfg(feature = "syslog_relay")]
pub mod os_trace_relay;
#[cfg(feature = "restore_service")]
pub mod restore_service;
#[cfg(feature = "rsd")]
pub mod rsd;
#[cfg(feature = "springboardservices")]

View File

@@ -0,0 +1,232 @@
//! Restore Service
use log::warn;
use plist::Dictionary;
use crate::{obf, IdeviceError, ReadWrite, RemoteXpcClient, RsdService};
/// Client for interacting with the Restore Service
pub struct RestoreServiceClient<R: ReadWrite> {
/// The underlying device connection with established Restore Service service
pub stream: RemoteXpcClient<R>,
}
impl<R: ReadWrite> RsdService for RestoreServiceClient<R> {
fn rsd_service_name() -> std::borrow::Cow<'static, str> {
obf!("com.apple.RestoreRemoteServices.restoreserviced")
}
async fn from_stream(stream: R) -> Result<Self, IdeviceError> {
Self::new(stream).await
}
type Stream = R;
}
impl<R: ReadWrite> RestoreServiceClient<R> {
/// Creates a new Restore Service client a socket connection,
/// and connects to the RemoteXPC service.
///
/// # Arguments
/// * `idevice` - Pre-established device connection
pub async fn new(stream: R) -> Result<Self, IdeviceError> {
let mut stream = RemoteXpcClient::new(stream).await?;
stream.do_handshake().await?;
Ok(Self { stream })
}
/// Enter recovery
pub async fn enter_recovery(&mut self) -> Result<(), IdeviceError> {
let mut req = Dictionary::new();
req.insert("command".into(), "recovery".into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
match res.remove("result") {
Some(plist::Value::String(r)) => {
if r == "success" {
Ok(())
} else {
warn!("Failed to enter recovery");
Err(IdeviceError::UnexpectedResponse)
}
}
_ => {
warn!("XPC dictionary did not contain result");
Err(IdeviceError::UnexpectedResponse)
}
}
}
/// Reboot
pub async fn reboot(&mut self) -> Result<(), IdeviceError> {
let mut req = Dictionary::new();
req.insert("command".into(), "reboot".into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
match res.remove("result") {
Some(plist::Value::String(r)) => {
if r == "success" {
Ok(())
} else {
warn!("Failed to enter recovery");
Err(IdeviceError::UnexpectedResponse)
}
}
_ => {
warn!("XPC dictionary did not contain result");
Err(IdeviceError::UnexpectedResponse)
}
}
}
/// Get preflightinfo
pub async fn get_preflightinfo(&mut self) -> Result<Dictionary, IdeviceError> {
let mut req = Dictionary::new();
req.insert("command".into(), "getpreflightinfo".into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
let res = match res.remove("preflightinfo") {
Some(plist::Value::Dictionary(i)) => i,
_ => {
warn!("XPC dictionary did not contain preflight info");
return Err(IdeviceError::UnexpectedResponse);
}
};
Ok(res)
}
/// Get nonces
/// Doesn't seem to work
pub async fn get_nonces(&mut self) -> Result<Dictionary, IdeviceError> {
let mut req = Dictionary::new();
req.insert("command".into(), "getnonces".into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
let res = match res.remove("nonces") {
Some(plist::Value::Dictionary(i)) => i,
_ => {
warn!("XPC dictionary did not contain nonces");
return Err(IdeviceError::UnexpectedResponse);
}
};
Ok(res)
}
/// Get app parameters
/// Doesn't seem to work
pub async fn get_app_parameters(&mut self) -> Result<Dictionary, IdeviceError> {
let mut req = Dictionary::new();
req.insert("command".into(), "getappparameters".into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
let res = match res.remove("appparameters") {
Some(plist::Value::Dictionary(i)) => i,
_ => {
warn!("XPC dictionary did not contain parameters");
return Err(IdeviceError::UnexpectedResponse);
}
};
Ok(res)
}
/// Restores the language
/// Doesn't seem to work
pub async fn restore_lang(&mut self, language: impl Into<String>) -> Result<(), IdeviceError> {
let language = language.into();
let mut req = Dictionary::new();
req.insert("command".into(), "restorelang".into());
req.insert("argument".into(), language.into());
self.stream
.send_object(plist::Value::Dictionary(req), true)
.await?;
let res = self.stream.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("Did not receive dictionary response from XPC");
return Err(IdeviceError::UnexpectedResponse);
}
};
match res.remove("result") {
Some(plist::Value::String(r)) => {
if r == "success" {
Ok(())
} else {
warn!("Failed to restore language");
Err(IdeviceError::UnexpectedResponse)
}
}
_ => {
warn!("XPC dictionary did not contain result");
Err(IdeviceError::UnexpectedResponse)
}
}
}
}