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

View File

@@ -379,7 +379,20 @@ impl Idevice {
debug!("Received plist: {}", pretty_print_dictionary(&res)); debug!("Received plist: {}", pretty_print_dictionary(&res));
if let Some(e) = res.get("Error") { 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) { if let Some(e) = IdeviceError::from_device_error_type(e.as_str(), &res) {
return Err(e); return Err(e);
} else { } else {
@@ -698,6 +711,8 @@ pub enum IdeviceError {
MalformedCommand = -64, MalformedCommand = -64,
#[error("integer overflow")] #[error("integer overflow")]
IntegerOverflow = -65, IntegerOverflow = -65,
#[error("canceled by user")]
CanceledByUser = -66,
} }
impl IdeviceError { impl IdeviceError {
@@ -710,6 +725,9 @@ impl IdeviceError {
/// # Returns /// # Returns
/// Some(IdeviceError) if the string maps to a known error type, None otherwise /// 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> { 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 { match e {
"GetProhibited" => Some(Self::GetProhibited), "GetProhibited" => Some(Self::GetProhibited),
"InvalidHostID" => Some(Self::InvalidHostID), "InvalidHostID" => Some(Self::InvalidHostID),
@@ -849,6 +867,7 @@ impl IdeviceError {
IdeviceError::UnsupportedWatchKey => -63, IdeviceError::UnsupportedWatchKey => -63,
IdeviceError::MalformedCommand => -64, IdeviceError::MalformedCommand => -64,
IdeviceError::IntegerOverflow => -65, IdeviceError::IntegerOverflow => -65,
IdeviceError::CanceledByUser => -66,
} }
} }
} }

View File

@@ -35,6 +35,8 @@ pub mod mobilebackup2;
pub mod os_trace_relay; pub mod os_trace_relay;
#[cfg(feature = "pcapd")] #[cfg(feature = "pcapd")]
pub mod pcapd; pub mod pcapd;
#[cfg(feature = "preboard_service")]
pub mod preboard_service;
#[cfg(feature = "restore_service")] #[cfg(feature = "restore_service")]
pub mod restore_service; pub mod restore_service;
#[cfg(feature = "rsd")] #[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!()
}
}

View File

@@ -121,6 +121,10 @@ path = "src/bt_packet_logger.rs"
name = "pcapd" name = "pcapd"
path = "src/pcapd.rs" path = "src/pcapd.rs"
[[bin]]
name = "preboard"
path = "src/preboard.rs"
[dependencies] [dependencies]
idevice = { path = "../idevice", features = ["full"], default-features = false } idevice = { path = "../idevice", features = ["full"], default-features = false }
tokio = { version = "1.43", features = ["full"] } tokio = { version = "1.43", features = ["full"] }

76
tools/src/preboard.rs Normal file
View File

@@ -0,0 +1,76 @@
// Jackson Coxson
use clap::{Arg, Command};
use idevice::{IdeviceService, preboard_service::PreboardServiceClient};
mod common;
#[tokio::main]
async fn main() {
env_logger::init();
let matches = Command::new("preboard")
.about("Mess with developer mode")
.arg(
Arg::new("host")
.long("host")
.value_name("HOST")
.help("IP address of the device"),
)
.arg(
Arg::new("pairing_file")
.long("pairing-file")
.value_name("PATH")
.help("Path to the pairing file"),
)
.arg(
Arg::new("udid")
.value_name("UDID")
.help("UDID of the device (overrides host/pairing file)")
.index(1),
)
.arg(
Arg::new("about")
.long("about")
.help("Show about information")
.action(clap::ArgAction::SetTrue),
)
.subcommand(Command::new("create").about("Create a stashbag??"))
.subcommand(Command::new("commit").about("Commit a stashbag??"))
.get_matches();
if matches.get_flag("about") {
println!("preboard - no idea what this does");
println!("Copyright (c) 2025 Jackson Coxson");
return;
}
let udid = matches.get_one::<String>("udid");
let host = matches.get_one::<String>("host");
let pairing_file = matches.get_one::<String>("pairing_file");
let provider = match common::get_provider(udid, host, pairing_file, "amfi-jkcoxson").await {
Ok(p) => p,
Err(e) => {
eprintln!("{e}");
return;
}
};
let mut pc = PreboardServiceClient::connect(&*provider)
.await
.expect("Failed to connect to Preboard");
if matches.subcommand_matches("create").is_some() {
pc.create_stashbag(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
.await
.expect("Failed to create");
} else if matches.subcommand_matches("commit").is_some() {
pc.commit_stashbag(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
.await
.expect("Failed to create");
} else {
eprintln!("Invalid usage, pass -h for help");
}
return;
}