mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add afc2 abstractions (#55)
This commit is contained in:
@@ -54,6 +54,44 @@ pub unsafe extern "C" fn afc_client_connect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Connects to the AFC2 service using a TCP provider
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * [`provider`] - An IdeviceProvider
|
||||||
|
/// * [`client`] - On success, will be set to point to a newly allocated AfcClient handle
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// An IdeviceFfiError on error, null on success
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// `provider` must be a valid pointer to a handle allocated by this library
|
||||||
|
/// `client` must be a valid, non-null pointer to a location where the handle will be stored
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub unsafe extern "C" fn afc2_client_connect(
|
||||||
|
provider: *mut IdeviceProviderHandle,
|
||||||
|
client: *mut *mut AfcClientHandle,
|
||||||
|
) -> *mut IdeviceFfiError {
|
||||||
|
if provider.is_null() || client.is_null() {
|
||||||
|
tracing::error!("Null pointer provided");
|
||||||
|
return ffi_err!(IdeviceError::FfiInvalidArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = run_sync_local(async {
|
||||||
|
let provider_ref: &dyn IdeviceProvider = unsafe { &*(*provider).0 };
|
||||||
|
|
||||||
|
AfcClient::new_afc2(provider_ref).await
|
||||||
|
});
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(r) => {
|
||||||
|
let boxed = Box::new(AfcClientHandle(r));
|
||||||
|
unsafe { *client = Box::into_raw(boxed) };
|
||||||
|
null_mut()
|
||||||
|
}
|
||||||
|
Err(e) => ffi_err!(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new AfcClient from an existing Idevice connection
|
/// Creates a new AfcClient from an existing Idevice connection
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ pub trait IdeviceService: Sized {
|
|||||||
async fn connect(provider: &dyn IdeviceProvider) -> Result<Self, IdeviceError> {
|
async fn connect(provider: &dyn IdeviceProvider) -> Result<Self, IdeviceError> {
|
||||||
let mut lockdown = LockdownClient::connect(provider).await?;
|
let mut lockdown = LockdownClient::connect(provider).await?;
|
||||||
|
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
let legacy = lockdown
|
let legacy = lockdown
|
||||||
.get_value(Some("ProductVersion"), None)
|
.get_value(Some("ProductVersion"), None)
|
||||||
.await
|
.await
|
||||||
@@ -87,6 +88,9 @@ pub trait IdeviceService: Sized {
|
|||||||
.map(|x| x < 5)
|
.map(|x| x < 5)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "openssl"))]
|
||||||
|
let legacy = false;
|
||||||
|
|
||||||
lockdown
|
lockdown
|
||||||
.start_session(&provider.get_pairing_file().await?)
|
.start_session(&provider.get_pairing_file().await?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use tracing::warn;
|
|||||||
use crate::{
|
use crate::{
|
||||||
Idevice, IdeviceError, IdeviceService,
|
Idevice, IdeviceError, IdeviceService,
|
||||||
afc::file::{FileDescriptor, OwnedFileDescriptor},
|
afc::file::{FileDescriptor, OwnedFileDescriptor},
|
||||||
|
lockdown::LockdownClient,
|
||||||
obf,
|
obf,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,6 +92,43 @@ impl AfcClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Connects to afc2 from a provider
|
||||||
|
pub async fn new_afc2(
|
||||||
|
provider: &dyn crate::provider::IdeviceProvider,
|
||||||
|
) -> Result<Self, IdeviceError> {
|
||||||
|
let mut lockdown = LockdownClient::connect(provider).await?;
|
||||||
|
|
||||||
|
#[cfg(feature = "openssl")]
|
||||||
|
let legacy = lockdown
|
||||||
|
.get_value(Some("ProductVersion"), None)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|x| x.as_string())
|
||||||
|
.and_then(|x| x.split(".").next())
|
||||||
|
.and_then(|x| x.parse::<u8>().ok())
|
||||||
|
.map(|x| x < 5)
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "openssl"))]
|
||||||
|
let legacy = false;
|
||||||
|
|
||||||
|
lockdown
|
||||||
|
.start_session(&provider.get_pairing_file().await?)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let (port, ssl) = lockdown.start_service(obf!("com.apple.afc2")).await?;
|
||||||
|
|
||||||
|
let mut idevice = provider.connect(port).await?;
|
||||||
|
if ssl {
|
||||||
|
idevice
|
||||||
|
.start_session(&provider.get_pairing_file().await?, legacy)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::from_stream(idevice).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Lists the contents of a directory on the device
|
/// Lists the contents of a directory on the device
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user