mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Implement tunneld flag for tools
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
use std::io::Write;
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
net::{IpAddr, SocketAddr},
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use idevice::{
|
use idevice::{
|
||||||
core_device_proxy::CoreDeviceProxy, debug_proxy::DebugProxyClient, xpc::XPCDevice,
|
core_device_proxy::CoreDeviceProxy, debug_proxy::DebugProxyClient,
|
||||||
IdeviceService,
|
tunneld::get_tunneld_devices, xpc::XPCDevice, IdeviceService,
|
||||||
};
|
};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
@@ -34,6 +39,12 @@ async fn main() {
|
|||||||
.help("UDID of the device (overrides host/pairing file)")
|
.help("UDID of the device (overrides host/pairing file)")
|
||||||
.index(1),
|
.index(1),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("tunneld")
|
||||||
|
.long("tunneld")
|
||||||
|
.help("Use tunneld")
|
||||||
|
.action(clap::ArgAction::SetTrue),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("about")
|
Arg::new("about")
|
||||||
.long("about")
|
.long("about")
|
||||||
@@ -52,6 +63,47 @@ async fn main() {
|
|||||||
let pairing_file = matches.get_one::<String>("pairing_file");
|
let pairing_file = matches.get_one::<String>("pairing_file");
|
||||||
let host = matches.get_one::<String>("host");
|
let host = matches.get_one::<String>("host");
|
||||||
|
|
||||||
|
let mut dp = if matches.get_flag("tunneld") {
|
||||||
|
let socket = SocketAddr::new(
|
||||||
|
IpAddr::from_str("127.0.0.1").unwrap(),
|
||||||
|
idevice::tunneld::DEFAULT_PORT,
|
||||||
|
);
|
||||||
|
let mut devices = get_tunneld_devices(socket)
|
||||||
|
.await
|
||||||
|
.expect("Failed to get tunneld devices");
|
||||||
|
|
||||||
|
let (_udid, device) = match udid {
|
||||||
|
Some(u) => (
|
||||||
|
u.to_owned(),
|
||||||
|
devices.remove(u).expect("Device not in tunneld"),
|
||||||
|
),
|
||||||
|
None => devices.into_iter().next().expect("No devices"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make the connection to RemoteXPC
|
||||||
|
let client = XPCDevice::new(Box::new(
|
||||||
|
TcpStream::connect((device.tunnel_address.as_str(), device.tunnel_port))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Get the debug proxy
|
||||||
|
let service = client
|
||||||
|
.services
|
||||||
|
.get(idevice::debug_proxy::SERVICE_NAME)
|
||||||
|
.expect("Client did not contain debug proxy service");
|
||||||
|
|
||||||
|
let stream = TcpStream::connect(SocketAddr::new(
|
||||||
|
IpAddr::from_str(&device.tunnel_address).unwrap(),
|
||||||
|
service.port,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.expect("Failed to connect");
|
||||||
|
|
||||||
|
DebugProxyClient::new(Box::new(stream))
|
||||||
|
} else {
|
||||||
let provider =
|
let provider =
|
||||||
match common::get_provider(udid, host, pairing_file, "debug-proxy-jkcoxson").await {
|
match common::get_provider(udid, host, pairing_file, "debug-proxy-jkcoxson").await {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
@@ -60,7 +112,6 @@ async fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let proxy = CoreDeviceProxy::connect(&*provider)
|
let proxy = CoreDeviceProxy::connect(&*provider)
|
||||||
.await
|
.await
|
||||||
.expect("no core proxy");
|
.expect("no core proxy");
|
||||||
@@ -83,7 +134,8 @@ async fn main() {
|
|||||||
adapter.close().await.unwrap();
|
adapter.close().await.unwrap();
|
||||||
adapter.connect(service.port).await.unwrap();
|
adapter.connect(service.port).await.unwrap();
|
||||||
|
|
||||||
let mut dp = DebugProxyClient::new(Box::new(adapter));
|
DebugProxyClient::new(Box::new(adapter))
|
||||||
|
};
|
||||||
|
|
||||||
println!("Shell connected!");
|
println!("Shell connected!");
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
net::{IpAddr, SocketAddr},
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use idevice::{core_device_proxy::CoreDeviceProxy, xpc::XPCDevice, IdeviceService};
|
use idevice::{
|
||||||
|
core_device_proxy::CoreDeviceProxy, tunneld::get_tunneld_devices, xpc::XPCDevice,
|
||||||
|
IdeviceService,
|
||||||
|
};
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
@@ -35,6 +44,12 @@ async fn main() {
|
|||||||
.help("Show about information")
|
.help("Show about information")
|
||||||
.action(clap::ArgAction::SetTrue),
|
.action(clap::ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("tunneld")
|
||||||
|
.long("tunneld")
|
||||||
|
.help("Use tunneld for connection")
|
||||||
|
.action(clap::ArgAction::SetTrue),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("bundle_id")
|
Arg::new("bundle_id")
|
||||||
.value_name("Bundle ID")
|
.value_name("Bundle ID")
|
||||||
@@ -52,18 +67,81 @@ async fn main() {
|
|||||||
let udid = matches.get_one::<String>("udid");
|
let udid = matches.get_one::<String>("udid");
|
||||||
let pairing_file = matches.get_one::<String>("pairing_file");
|
let pairing_file = matches.get_one::<String>("pairing_file");
|
||||||
let host = matches.get_one::<String>("host");
|
let host = matches.get_one::<String>("host");
|
||||||
|
let bundle_id = matches
|
||||||
|
.get_one::<String>("bundle_id")
|
||||||
|
.expect("No bundle ID specified");
|
||||||
|
|
||||||
let provider =
|
if matches.get_flag("tunneld") {
|
||||||
match common::get_provider(udid, host, pairing_file, "heartbeat_client-jkcoxson").await {
|
let socket = SocketAddr::new(
|
||||||
|
IpAddr::from_str("127.0.0.1").unwrap(),
|
||||||
|
idevice::tunneld::DEFAULT_PORT,
|
||||||
|
);
|
||||||
|
let mut devices = get_tunneld_devices(socket)
|
||||||
|
.await
|
||||||
|
.expect("Failed to get tunneld devices");
|
||||||
|
|
||||||
|
let (_udid, device) = match udid {
|
||||||
|
Some(u) => (
|
||||||
|
u.to_owned(),
|
||||||
|
devices.remove(u).expect("Device not in tunneld"),
|
||||||
|
),
|
||||||
|
None => devices.into_iter().next().expect("No devices"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make the connection to RemoteXPC
|
||||||
|
let client = XPCDevice::new(Box::new(
|
||||||
|
TcpStream::connect((device.tunnel_address.as_str(), device.tunnel_port))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Get the debug proxy
|
||||||
|
let service = client
|
||||||
|
.services
|
||||||
|
.get(idevice::dvt::SERVICE_NAME)
|
||||||
|
.expect("Client did not contain DVT service");
|
||||||
|
|
||||||
|
let stream = TcpStream::connect(SocketAddr::new(
|
||||||
|
IpAddr::from_str(&device.tunnel_address).unwrap(),
|
||||||
|
service.port,
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.expect("Failed to connect");
|
||||||
|
|
||||||
|
let mut rs_client =
|
||||||
|
idevice::dvt::remote_server::RemoteServerClient::new(Box::new(stream)).unwrap();
|
||||||
|
rs_client.read_message(0).await.expect("no read??");
|
||||||
|
let mut pc_client =
|
||||||
|
idevice::dvt::process_control::ProcessControlClient::new(&mut rs_client)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let pid = pc_client
|
||||||
|
.launch_app(bundle_id, None, None, true, false)
|
||||||
|
.await
|
||||||
|
.expect("no launch??");
|
||||||
|
pc_client
|
||||||
|
.disable_memory_limit(pid)
|
||||||
|
.await
|
||||||
|
.expect("no disable??");
|
||||||
|
println!("PID: {pid}");
|
||||||
|
} else {
|
||||||
|
let provider = match common::get_provider(
|
||||||
|
udid,
|
||||||
|
host,
|
||||||
|
pairing_file,
|
||||||
|
"process_control-jkcoxson",
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{e}");
|
eprintln!("{e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let bundle_id = matches
|
|
||||||
.get_one::<String>("bundle_id")
|
|
||||||
.expect("No bundle ID specified");
|
|
||||||
|
|
||||||
let proxy = CoreDeviceProxy::connect(&*provider)
|
let proxy = CoreDeviceProxy::connect(&*provider)
|
||||||
.await
|
.await
|
||||||
@@ -89,7 +167,8 @@ async fn main() {
|
|||||||
let mut rs_client =
|
let mut rs_client =
|
||||||
idevice::dvt::remote_server::RemoteServerClient::new(Box::new(adapter)).unwrap();
|
idevice::dvt::remote_server::RemoteServerClient::new(Box::new(adapter)).unwrap();
|
||||||
rs_client.read_message(0).await.expect("no read??");
|
rs_client.read_message(0).await.expect("no read??");
|
||||||
let mut pc_client = idevice::dvt::process_control::ProcessControlClient::new(&mut rs_client)
|
let mut pc_client =
|
||||||
|
idevice::dvt::process_control::ProcessControlClient::new(&mut rs_client)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -102,4 +181,8 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.expect("no disable??");
|
.expect("no disable??");
|
||||||
println!("PID: {pid}");
|
println!("PID: {pid}");
|
||||||
|
|
||||||
|
// let mut adapter = rs_client.into_inner();
|
||||||
|
// adapter.close().await.expect("no close??");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user