Partial implementation of core_device app list

This commit is contained in:
Jackson Coxson
2025-07-18 23:46:33 -06:00
parent 31b4849b17
commit 366165304c
6 changed files with 311 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ bytes = "1.10.1"
[features]
afc = ["dep:chrono"]
amfi = []
core_device = ["xpc", "dep:uuid"]
core_device_proxy = ["dep:serde_json", "dep:json", "dep:byteorder"]
crashreportcopymobile = ["afc"]
debug_proxy = []
@@ -83,6 +84,7 @@ xpc = ["dep:indexmap", "dep:uuid"]
full = [
"afc",
"amfi",
"core_device",
"core_device_proxy",
"crashreportcopymobile",
"debug_proxy",

View File

@@ -0,0 +1,99 @@
// Jackson Coxson
use log::warn;
use serde::Deserialize;
use crate::{obf, IdeviceError, ReadWrite, RsdService};
use super::CoreDeviceServiceClient;
impl<R: ReadWrite> RsdService for AppServiceClient<R> {
fn rsd_service_name() -> std::borrow::Cow<'static, str> {
obf!("com.apple.coredevice.appservice")
}
async fn from_stream(stream: R) -> Result<Self, IdeviceError> {
Ok(Self {
inner: CoreDeviceServiceClient::new(stream).await?,
})
}
type Stream = R;
}
pub struct AppServiceClient<R: ReadWrite> {
inner: CoreDeviceServiceClient<R>,
}
#[derive(Deserialize, Debug)]
pub struct AppListEntry {
#[serde(rename = "isRemovable")]
pub is_removable: bool,
pub name: String,
#[serde(rename = "isFirstParty")]
pub is_first_party: bool,
pub path: String,
#[serde(rename = "bundleIdentifier")]
pub bundle_identifier: String,
#[serde(rename = "isDeveloperApp")]
pub is_developer_app: bool,
#[serde(rename = "bundleVersion")]
pub bundle_version: Option<String>,
#[serde(rename = "isInternal")]
pub is_internal: bool,
#[serde(rename = "isHidden")]
pub is_hidden: bool,
#[serde(rename = "isAppClip")]
pub is_app_clip: bool,
pub version: Option<String>,
}
impl<R: ReadWrite> AppServiceClient<R> {
pub async fn new(stream: R) -> Result<Self, IdeviceError> {
Ok(Self {
inner: CoreDeviceServiceClient::new(stream).await?,
})
}
pub async fn list_apps(
&mut self,
app_clips: bool,
removable_apps: bool,
hidden_apps: bool,
internal_apps: bool,
default_apps: bool,
) -> Result<Vec<AppListEntry>, IdeviceError> {
let mut options = plist::Dictionary::new();
options.insert("includeAppClips".into(), app_clips.into());
options.insert("includeRemovableApps".into(), removable_apps.into());
options.insert("includeHiddenApps".into(), hidden_apps.into());
options.insert("includeInternalApps".into(), internal_apps.into());
options.insert("includeDefaultApps".into(), default_apps.into());
let res = self
.inner
.invoke("com.apple.coredevice.feature.listapps", Some(options))
.await?;
let res = match res.as_array() {
Some(a) => a,
None => {
warn!("CoreDevice result was not an array");
return Err(IdeviceError::UnexpectedResponse);
}
};
let mut desd = Vec::new();
for r in res {
let r: AppListEntry = match plist::from_value(r) {
Ok(r) => r,
Err(e) => {
warn!("Failed to parse app entry: {e:?}");
return Err(IdeviceError::UnexpectedResponse);
}
};
desd.push(r);
}
Ok(desd)
}
}

View File

@@ -0,0 +1,101 @@
// Jackson Coxson
// Ported from pymobiledevice3
use log::warn;
use crate::{
xpc::{self, XPCObject},
IdeviceError, ReadWrite, RemoteXpcClient,
};
mod app_service;
pub use app_service::{AppListEntry, AppServiceClient};
const CORE_SERVICE_VERSION: &str = "443.18";
pub struct CoreDeviceServiceClient<R: ReadWrite> {
inner: RemoteXpcClient<R>,
}
impl<R: ReadWrite> CoreDeviceServiceClient<R> {
pub async fn new(inner: R) -> Result<Self, IdeviceError> {
let mut client = RemoteXpcClient::new(inner).await?;
client.do_handshake().await?;
Ok(Self { inner: client })
}
pub async fn invoke(
&mut self,
feature: impl Into<String>,
input: Option<plist::Dictionary>,
) -> Result<plist::Value, IdeviceError> {
let feature = feature.into();
let input = input.unwrap_or_default();
let mut req = xpc::Dictionary::new();
req.insert(
"CoreDevice.CoreDeviceDDIProtocolVersion".into(),
XPCObject::Int64(0),
);
req.insert("CoreDevice.action".into(), xpc::Dictionary::new().into());
req.insert(
"CoreDevice.coreDeviceVersion".into(),
create_xpc_version_from_string(CORE_SERVICE_VERSION).into(),
);
req.insert(
"CoreDevice.deviceIdentifier".into(),
XPCObject::String(uuid::Uuid::new_v4().to_string()),
);
req.insert(
"CoreDevice.featureIdentifier".into(),
XPCObject::String(feature),
);
req.insert(
"CoreDevice.input".into(),
plist::Value::Dictionary(input).into(),
);
req.insert(
"CoreDevice.invocationIdentifier".into(),
XPCObject::String(uuid::Uuid::new_v4().to_string()),
);
self.inner.send_object(req, true).await?;
let res = self.inner.recv().await?;
let mut res = match res {
plist::Value::Dictionary(d) => d,
_ => {
warn!("XPC response was not a dictionary");
return Err(IdeviceError::UnexpectedResponse);
}
};
let res = match res.remove("CoreDevice.output") {
Some(r) => r,
None => {
warn!("XPC response did not have an output");
return Err(IdeviceError::UnexpectedResponse);
}
};
Ok(res)
}
}
fn create_xpc_version_from_string(version: impl Into<String>) -> xpc::Dictionary {
let version: String = version.into();
let mut collected_version = Vec::new();
version.split('.').for_each(|x| {
if let Ok(x) = x.parse() {
collected_version.push(XPCObject::UInt64(x));
}
});
let mut res = xpc::Dictionary::new();
res.insert(
"originalComponentsCount".into(),
XPCObject::Int64(collected_version.len() as i64),
);
res.insert("components".into(), XPCObject::Array(collected_version));
res.insert("stringValue".into(), XPCObject::String(version));
res
}

View File

@@ -2,6 +2,8 @@
pub mod afc;
#[cfg(feature = "amfi")]
pub mod amfi;
#[cfg(feature = "core_device")]
pub mod core_device;
#[cfg(feature = "core_device_proxy")]
pub mod core_device_proxy;
#[cfg(feature = "crashreportcopymobile")]