Crate idevice

Crate idevice 

Source
Expand description

§idevice

A Rust library for interacting with iOS services. Inspired by libimobiledevice and pymobiledevice3, this library interfaces with lockdownd and usbmuxd to perform actions on an iOS device that a Mac normally would.

For help and information, join the idevice Discord

§State

IMPORTANT: Breaking changes will happen at each point release until 0.2.0. Pin your Cargo.toml to a specific version to avoid breakage.

This library is in development and research stage. Releases are being published to crates.io for use in other projects, but the API and feature-set are far from final or even planned.

§Features

To keep dependency bloat and compile time down, everything is contained in features.

FeatureDescription
afcApple File Conduit for file system access.
amfiApple mobile file integrity service
core_device_proxyStart a secure tunnel to access protected services.
crashreportcopymobileCopy crash reports.
debug_proxySend GDB commands to the device.
diagnostics_relayAccess device diagnostics information (IORegistry, MobileGestalt, battery, NAND, device control).
dvtAccess Apple developer tools (e.g. Instruments).
heartbeatMaintain a heartbeat connection.
house_arrestManage files in app containers
installation_proxyManage app installation and uninstallation.
springboardservicesControl SpringBoard (e.g. UI interactions). Partial support.
misagentManage provisioning profiles on the device.
mobilebackup2Manage backups.
mobile_image_mounterManage DDI images.
location_simulationSimulate GPS locations on the device.
pairPair the device.
syslog_relayRelay system logs from the device
tcpConnect to devices over TCP.
tunnel_tcp_stackNaive in-process TCP stack for core_device_proxy.
tssMake requests to Apple’s TSS servers. Partial support.
tunneldInterface with pymobiledevice3’s tunneld.
usbmuxdConnect using the usbmuxd daemon.
xpcAccess protected services via XPC over RSD.

§Planned/TODO

Finish the following:

  • springboard

Implement the following:

  • companion_proxy
  • diagnostics
  • mobilebackup2
  • notification_proxy
  • screenshot
  • webinspector

As this project is done in my free time within my busy schedule, there is no ETA for any of these. Feel free to contribute or donate!

§Usage

idevice is purposefully verbose to allow for powerful configurations. No size fits all, but effort is made to reduce boilerplate via providers.

// enable the usbmuxd feature
use idevice::{lockdown::LockdowndClient, IdeviceService};
use idevice::usbmuxd::{UsbmuxdAddr, UsbmuxdConnection},

#[tokio::main]
async fn main() {
    // usbmuxd is Apple's daemon for connecting to devices over USB.
    // We'll ask usbmuxd for a device
    let mut usbmuxd = UsbmuxdConnection::default()
        .await
        .expect("Unable to connect to usbmxud")
    let devs = usbmuxd.get_devices().unwrap();
    if devs.is_empty() {
        eprintln!("No devices connected!");
        return;
    }

    // Create a provider to automatically create connections to the device.
    // Many services require opening multiple connections to get where you want.
    let provider = devs[0].to_provider(UsbmuxdAddr::from_env_var().unwrap(), 0, "example-program")

    // ``connect`` takes an object with the provider trait
    let mut lockdown_client = match LockdowndClient::connect(&provider).await {
        Ok(l) => l,
        Err(e) => {
            eprintln!("Unable to connect to lockdown: {e:?}");
            return;
        }
    };

    println!("{:?}", lockdown_client.get_value("ProductVersion").await);
    println!(
        "{:?}",
        lockdown_client
            .start_session(
                &provider
                    .get_pairing_file()
                    .await
                    .expect("failed to get pairing file")
            )
            .await
    );
    println!("{:?}", lockdown_client.idevice.get_type().await.unwrap());
    println!("{:#?}", lockdown_client.get_all_values().await);
}

More examples are in the tools crate and in the crate documentation.

§FFI

For use in other languages, a small FFI crate has been created to start exposing idevice. Example C programs can be found in this repository.

§Version Policy

As Apple prohibits downgrading to older versions, this library will not keep compatibility for older versions than the current stable release.

§Developer Disk Images

doronz88 is kind enough to maintain a repo for disk images and personalized images. On MacOS, you can find them at ~/Library/Developer/DeveloperDiskImages.

§License

MIT

Re-exports§

pub use xpc::RemoteXpcClient;
pub use services::*;

Modules§

pairing_file
iOS Device Pairing File Handling
provider
iOS Device Connection Providers
services
tcp
tss
Ticket Signature Server (TSS) Client
tunneld
Tunneld Client Implementation
usbmuxd
USB Multiplexing Daemon (usbmuxd) Client
utils
xpc

Macros§

obf
plist
Construct a plist::Value from a JSON-like literal.

Structs§

Idevice
Main handle for communicating with an iOS device

Enums§

IdeviceError
Comprehensive error type for all device communication failures

Traits§

IdeviceService
Interface for services that can be connected to on an iOS device
ReadWrite
A trait combining all required characteristics for a device communication socket
RsdService

Functions§

pretty_print_dictionary
Pretty-prints a PLIST dictionary with key-value pairs
pretty_print_plist
Pretty-prints a PLIST value with indentation

Type Aliases§

IdeviceSocket
Type alias for boxed device connection sockets