Create files for mobileactivationd

This commit is contained in:
Jackson Coxson
2025-09-21 10:45:12 -06:00
parent 54dbbbb558
commit 7506ecd62e
5 changed files with 213 additions and 1 deletions

View File

@@ -90,6 +90,7 @@ installation_proxy = [
springboardservices = []
misagent = []
mobile_image_mounter = ["dep:sha2"]
mobileactivationd = ["dep:reqwest"]
mobilebackup2 = []
location_simulation = []
pair = ["chrono/default", "tokio/time", "dep:sha2", "dep:rsa", "dep:x509-cert"]
@@ -129,6 +130,7 @@ full = [
"location_simulation",
"misagent",
"mobile_image_mounter",
"mobileactivationd",
"mobilebackup2",
"pair",
"pcapd",

View File

@@ -0,0 +1,91 @@
//! mobileactivationd activates iOS devices.
//! This isn't a normal service, as it requires a new connection for each request.
//! As such, this service requires a provider itself, instead of temporary usage of one.
use plist::Dictionary;
use crate::{Idevice, IdeviceError, IdeviceService, lockdown::LockdownClient, obf};
pub struct MobileActivationdClient<'a> {
provider: &'a dyn crate::provider::IdeviceProvider,
}
/// Internal structure for temporary service connections.
/// This struct exists to take advantage of the service trait.
struct MobileActivationdInternal {
pub idevice: Idevice,
}
impl IdeviceService for MobileActivationdInternal {
/// Returns the service name as registered with lockdownd
fn service_name() -> std::borrow::Cow<'static, str> {
obf!("com.apple.mobileactivationd")
}
async fn from_stream(idevice: Idevice) -> Result<Self, crate::IdeviceError> {
Ok(Self::new(idevice))
}
}
impl MobileActivationdInternal {
fn new(idevice: Idevice) -> Self {
Self { idevice }
}
}
impl<'a> MobileActivationdClient<'a> {
pub fn new(provider: &'a dyn crate::provider::IdeviceProvider) -> Self {
Self { provider }
}
pub async fn state(&self) -> Result<String, IdeviceError> {
if let Ok(res) = self.send_command("GetActivationStateRequest", None).await
&& let Some(v) = res.get("Value").and_then(|x| x.as_string())
{
Ok(v.to_string())
} else {
let mut lc = LockdownClient::connect(self.provider).await?;
lc.start_session(&self.provider.get_pairing_file().await?)
.await?;
let res = lc.get_value(Some("ActivationState"), None).await?;
if let Some(v) = res.as_string() {
Ok(v.to_string())
} else {
Err(IdeviceError::UnexpectedResponse)
}
}
}
pub async fn activated(&self) -> Result<bool, IdeviceError> {
Ok(self.state().await? == "Activated")
}
/// Deactivates the device.
/// Protocol gives no response on whether it worked or not, so good luck
pub async fn deactivate(&self) -> Result<(), IdeviceError> {
self.send_command("DeactivateRequest", None).await?;
Ok(())
}
async fn send_command(
&self,
command: impl Into<String>,
value: Option<&str>,
) -> Result<Dictionary, IdeviceError> {
let mut service = self.service_connect().await?;
let command = command.into();
let req = crate::plist!({
"Command": command,
"Value":? value,
});
service.send_plist(req).await?;
service.read_plist().await
}
async fn service_connect(&self) -> Result<Idevice, IdeviceError> {
Ok(MobileActivationdInternal::connect(self.provider)
.await?
.idevice)
}
}

View File

@@ -29,6 +29,8 @@ pub mod lockdown;
pub mod misagent;
#[cfg(feature = "mobile_image_mounter")]
pub mod mobile_image_mounter;
#[cfg(feature = "mobileactivationd")]
pub mod mobileactivationd;
#[cfg(feature = "mobilebackup2")]
pub mod mobilebackup2;
#[cfg(feature = "syslog_relay")]