mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Implement new mounter cli
This commit is contained in:
@@ -43,3 +43,4 @@ tun-rs = { version = "1.5", features = ["async"] }
|
||||
sha2 = { version = "0.10" }
|
||||
ureq = { version = "3" }
|
||||
clap = { version = "4.5" }
|
||||
plist = { version = "1.7" }
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// Jackson Coxson
|
||||
// Common functions between tools
|
||||
|
||||
use std::{net::IpAddr, str::FromStr};
|
||||
use std::{
|
||||
net::{IpAddr, SocketAddr},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use idevice::{
|
||||
pairing_file::PairingFile,
|
||||
@@ -17,16 +20,26 @@ pub async fn get_provider(
|
||||
) -> Result<Box<dyn IdeviceProvider>, String> {
|
||||
let provider: Box<dyn IdeviceProvider> = if udid.is_some() {
|
||||
let udid = udid.unwrap();
|
||||
let mut usbmuxd = UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud");
|
||||
|
||||
let mut usbmuxd = if let Ok(var) = std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
||||
let socket = SocketAddr::from_str(&var).expect("Bad USBMUXD_SOCKET_ADDRESS");
|
||||
let socket = tokio::net::TcpStream::connect(socket)
|
||||
.await
|
||||
.expect("unable to connect to socket address");
|
||||
UsbmuxdConnection::new(Box::new(socket), 1)
|
||||
} else {
|
||||
UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud")
|
||||
};
|
||||
|
||||
let dev = match usbmuxd.get_device(udid).await {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
return Err(format!("Device not found: {e:?}"));
|
||||
}
|
||||
};
|
||||
Box::new(dev.to_provider(UsbmuxdAddr::default(), 1, label))
|
||||
Box::new(dev.to_provider(UsbmuxdAddr::from_env_var().unwrap(), 1, label))
|
||||
} else if host.is_some() && pairing_file.is_some() {
|
||||
let host = match IpAddr::from_str(host.unwrap()) {
|
||||
Ok(h) => h,
|
||||
@@ -47,9 +60,17 @@ pub async fn get_provider(
|
||||
label: "ideviceinfo-jkcoxson".to_string(),
|
||||
})
|
||||
} else {
|
||||
let mut usbmuxd = UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud");
|
||||
let mut usbmuxd = if let Ok(var) = std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
||||
let socket = SocketAddr::from_str(&var).expect("Bad USBMUXD_SOCKET_ADDRESS");
|
||||
let socket = tokio::net::TcpStream::connect(socket)
|
||||
.await
|
||||
.expect("unable to connect to socket address");
|
||||
UsbmuxdConnection::new(Box::new(socket), 1)
|
||||
} else {
|
||||
UsbmuxdConnection::default()
|
||||
.await
|
||||
.expect("Unable to connect to usbmxud")
|
||||
};
|
||||
let devs = match usbmuxd.get_devices().await {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
@@ -59,7 +80,7 @@ pub async fn get_provider(
|
||||
if devs.is_empty() {
|
||||
return Err("No devices connected!".to_string());
|
||||
}
|
||||
Box::new(devs[0].to_provider(UsbmuxdAddr::default(), 0, label))
|
||||
Box::new(devs[0].to_provider(UsbmuxdAddr::from_env_var().unwrap(), 0, label))
|
||||
};
|
||||
Ok(provider)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Jackson Coxson
|
||||
// Just lists apps for now
|
||||
|
||||
use clap::{Arg, Command};
|
||||
use idevice::{mounter::ImageMounter, IdeviceService};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use sha2::{Digest, Sha384};
|
||||
use clap::{arg, value_parser, Arg, Command};
|
||||
use idevice::{
|
||||
lockdownd::LockdowndClient, mounter::ImageMounter, pretty_print_plist, IdeviceService,
|
||||
};
|
||||
|
||||
mod common;
|
||||
|
||||
@@ -38,6 +40,29 @@ async fn main() {
|
||||
.help("Show about information")
|
||||
.action(clap::ArgAction::SetTrue),
|
||||
)
|
||||
.subcommand(Command::new("list").about("Lists the images mounted on the device"))
|
||||
.subcommand(Command::new("unmount").about("Unmounts the developer disk image"))
|
||||
.subcommand(
|
||||
Command::new("mount")
|
||||
.about("Mounts the developer disk image")
|
||||
.arg(
|
||||
arg!(-i --image <FILE> "the developer disk image to mount")
|
||||
.value_parser(value_parser!(PathBuf))
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
arg!(-b --manifest <FILE> "the build manifest (iOS 17+)")
|
||||
.value_parser(value_parser!(PathBuf)),
|
||||
)
|
||||
.arg(
|
||||
arg!(-t --trustcache <FILE> "the trust cache (iOS 17+)")
|
||||
.value_parser(value_parser!(PathBuf)),
|
||||
)
|
||||
.arg(
|
||||
arg!(-s --signature <FILE> "the image signature (iOS < 17.0")
|
||||
.value_parser(value_parser!(PathBuf)),
|
||||
),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if matches.get_flag("about") {
|
||||
@@ -59,21 +84,121 @@ async fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let mut lockdown_client = LockdowndClient::connect(&*provider)
|
||||
.await
|
||||
.expect("Unable to connect to lockdown");
|
||||
|
||||
let product_version = match lockdown_client.get_value("ProductVersion").await {
|
||||
Ok(p) => p,
|
||||
Err(_) => {
|
||||
lockdown_client
|
||||
.start_session(&provider.get_pairing_file().await.unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
lockdown_client.get_value("ProductVersion").await.unwrap()
|
||||
}
|
||||
};
|
||||
let product_version = product_version
|
||||
.as_string()
|
||||
.unwrap()
|
||||
.split('.')
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.parse::<u8>()
|
||||
.unwrap();
|
||||
|
||||
let mut mounter_client = ImageMounter::connect(&*provider)
|
||||
.await
|
||||
.expect("Unable to connect to image mounter");
|
||||
|
||||
let images = mounter_client.copy_devices().await.unwrap();
|
||||
println!("Images: {images:#?}");
|
||||
if matches.subcommand_matches("list").is_some() {
|
||||
let images = mounter_client
|
||||
.copy_devices()
|
||||
.await
|
||||
.expect("Unable to get images");
|
||||
for i in images {
|
||||
println!("{}", pretty_print_plist(&i));
|
||||
}
|
||||
} else if matches.subcommand_matches("unmount").is_some() {
|
||||
if product_version < 17 {
|
||||
mounter_client
|
||||
.unmount_image("/Developer")
|
||||
.await
|
||||
.expect("Failed to unmount");
|
||||
} else {
|
||||
mounter_client
|
||||
.unmount_image("/System/Developer")
|
||||
.await
|
||||
.expect("Failed to unmount");
|
||||
}
|
||||
} else if let Some(matches) = matches.subcommand_matches("mount") {
|
||||
let image: &PathBuf = match matches.get_one("image") {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
eprintln!("No image was passed! Pass -h for help");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let image = tokio::fs::read(image).await.expect("Unable to read image");
|
||||
if product_version < 17 {
|
||||
let signature: &PathBuf = match matches.get_one("signature") {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
eprintln!("No signature was passed! Pass -h for help");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let signature = tokio::fs::read(signature)
|
||||
.await
|
||||
.expect("Unable to read signature");
|
||||
|
||||
let image = std::fs::read("Image.dmg").unwrap();
|
||||
let mut hasher = Sha384::new();
|
||||
hasher.update(image);
|
||||
let hash = hasher.finalize();
|
||||
mounter_client
|
||||
.mount_developer(&image, signature)
|
||||
.await
|
||||
.expect("Unable to mount");
|
||||
} else {
|
||||
let manifest: &PathBuf = match matches.get_one("manifest") {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
eprintln!("No build manifest was passed! Pass -h for help");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let build_manifest = &tokio::fs::read(manifest)
|
||||
.await
|
||||
.expect("Unable to read signature");
|
||||
|
||||
let manifest = mounter_client
|
||||
.query_personalization_manifest("DeveloperDiskImage", hash.to_vec())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("len: {}", manifest.len());
|
||||
let trust_cache: &PathBuf = match matches.get_one("trustcache") {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
eprintln!("No trust cache was passed! Pass -h for help");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let trust_cache = tokio::fs::read(trust_cache)
|
||||
.await
|
||||
.expect("Unable to read signature");
|
||||
|
||||
let unique_chip_id = lockdown_client
|
||||
.get_value("UniqueChipID")
|
||||
.await
|
||||
.expect("Failed to get UniqueChipID")
|
||||
.as_unsigned_integer()
|
||||
.expect("Unexpected value for chip IP");
|
||||
|
||||
mounter_client
|
||||
.mount_personalized(
|
||||
&*provider,
|
||||
image,
|
||||
trust_cache,
|
||||
build_manifest,
|
||||
None,
|
||||
unique_chip_id,
|
||||
)
|
||||
.await
|
||||
.expect("Unable to mount");
|
||||
}
|
||||
} else {
|
||||
eprintln!("Invalid usage, pass -h for help");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user