mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add location simulation instrument
This commit is contained in:
@@ -50,6 +50,7 @@ heartbeat = []
|
|||||||
installation_proxy = []
|
installation_proxy = []
|
||||||
misagent = []
|
misagent = []
|
||||||
mounter = ["dep:sha2"]
|
mounter = ["dep:sha2"]
|
||||||
|
location_simulation = []
|
||||||
tcp = ["tokio/net"]
|
tcp = ["tokio/net"]
|
||||||
tunnel_tcp_stack = ["dep:rand", "dep:futures", "tokio/fs"]
|
tunnel_tcp_stack = ["dep:rand", "dep:futures", "tokio/fs"]
|
||||||
tss = ["dep:uuid", "dep:reqwest"]
|
tss = ["dep:uuid", "dep:reqwest"]
|
||||||
@@ -73,6 +74,7 @@ full = [
|
|||||||
"mounter",
|
"mounter",
|
||||||
"usbmuxd",
|
"usbmuxd",
|
||||||
"xpc",
|
"xpc",
|
||||||
|
"location_simulation",
|
||||||
"tcp",
|
"tcp",
|
||||||
"tunnel_tcp_stack",
|
"tunnel_tcp_stack",
|
||||||
"tss",
|
"tss",
|
||||||
|
|||||||
51
idevice/src/dvt/location_simulation.rs
Normal file
51
idevice/src/dvt/location_simulation.rs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// Jackson Coxson
|
||||||
|
|
||||||
|
use plist::Value;
|
||||||
|
|
||||||
|
use crate::{dvt::message::AuxValue, IdeviceError, ReadWrite};
|
||||||
|
|
||||||
|
use super::remote_server::{Channel, RemoteServerClient};
|
||||||
|
|
||||||
|
const IDENTIFIER: &str = "com.apple.instruments.server.services.LocationSimulation";
|
||||||
|
|
||||||
|
pub struct LocationSimulationClient<'a, R: ReadWrite> {
|
||||||
|
channel: Channel<'a, R>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, R: ReadWrite> LocationSimulationClient<'a, R> {
|
||||||
|
pub async fn new(client: &'a mut RemoteServerClient<R>) -> Result<Self, IdeviceError> {
|
||||||
|
let channel = client.make_channel(IDENTIFIER).await?; // Drop `&mut client` before continuing
|
||||||
|
|
||||||
|
Ok(Self { channel })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn clear(&mut self) -> Result<(), IdeviceError> {
|
||||||
|
let method = Value::String("stopLocationSimulation".into());
|
||||||
|
|
||||||
|
self.channel.call_method(Some(method), None, true).await?;
|
||||||
|
|
||||||
|
let _ = self.channel.read_message().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set(&mut self, latitude: f64, longitude: f64) -> Result<(), IdeviceError> {
|
||||||
|
let method = Value::String("simulateLocationWithLatitude:longitude:".into());
|
||||||
|
|
||||||
|
self.channel
|
||||||
|
.call_method(
|
||||||
|
Some(method),
|
||||||
|
Some(vec![
|
||||||
|
AuxValue::archived_value(latitude),
|
||||||
|
AuxValue::archived_value(longitude),
|
||||||
|
]),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// We don't actually care what's in the response, but we need to request one and read it
|
||||||
|
let _ = self.channel.read_message().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
|
#[cfg(feature = "location_simulation")]
|
||||||
|
pub mod location_simulation;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod process_control;
|
pub mod process_control;
|
||||||
pub mod remote_server;
|
pub mod remote_server;
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ path = "src/debug_proxy.rs"
|
|||||||
name = "misagent"
|
name = "misagent"
|
||||||
path = "src/misagent.rs"
|
path = "src/misagent.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "location_simulation"
|
||||||
|
path = "src/location_simulation.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
idevice = { path = "../idevice", features = ["full"] }
|
idevice = { path = "../idevice", features = ["full"] }
|
||||||
tokio = { version = "1.43", features = ["io-util", "macros", "time", "full"] }
|
tokio = { version = "1.43", features = ["io-util", "macros", "time", "full"] }
|
||||||
|
|||||||
129
tools/src/location_simulation.rs
Normal file
129
tools/src/location_simulation.rs
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
// Jackson Coxson
|
||||||
|
// Just lists apps for now
|
||||||
|
|
||||||
|
use clap::{Arg, Command};
|
||||||
|
use idevice::{core_device_proxy::CoreDeviceProxy, xpc::XPCDevice, IdeviceService};
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
|
let matches = Command::new("simulate_location")
|
||||||
|
.about("Simulate device location")
|
||||||
|
.arg(
|
||||||
|
Arg::new("host")
|
||||||
|
.long("host")
|
||||||
|
.value_name("HOST")
|
||||||
|
.help("IP address of the device"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("pairing_file")
|
||||||
|
.long("pairing-file")
|
||||||
|
.value_name("PATH")
|
||||||
|
.help("Path to the pairing file"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("udid")
|
||||||
|
.value_name("UDID")
|
||||||
|
.help("UDID of the device (overrides host/pairing file)")
|
||||||
|
.index(1),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("about")
|
||||||
|
.long("about")
|
||||||
|
.help("Show about information")
|
||||||
|
.action(clap::ArgAction::SetTrue),
|
||||||
|
)
|
||||||
|
.subcommand(Command::new("clear").about("Clears the location set on the device"))
|
||||||
|
.subcommand(
|
||||||
|
Command::new("set")
|
||||||
|
.about("Set the location on the device")
|
||||||
|
.arg(Arg::new("latitude").required(true))
|
||||||
|
.arg(Arg::new("longitude").required(true)),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
|
if matches.get_flag("about") {
|
||||||
|
println!("simulate_location - Sets the simlulated location on an iOS device");
|
||||||
|
println!("Copyright (c) 2025 Jackson Coxson");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let udid = matches.get_one::<String>("udid");
|
||||||
|
let host = matches.get_one::<String>("host");
|
||||||
|
let pairing_file = matches.get_one::<String>("pairing_file");
|
||||||
|
|
||||||
|
let provider =
|
||||||
|
match common::get_provider(udid, host, pairing_file, "simulate_location-jkcoxson").await {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let proxy = CoreDeviceProxy::connect(&*provider)
|
||||||
|
.await
|
||||||
|
.expect("no core proxy");
|
||||||
|
let rsd_port = proxy.handshake.server_rsd_port;
|
||||||
|
|
||||||
|
let mut adapter = proxy.create_software_tunnel().expect("no software tunnel");
|
||||||
|
adapter.connect(rsd_port).await.expect("no RSD connect");
|
||||||
|
|
||||||
|
// Make the connection to RemoteXPC
|
||||||
|
let client = XPCDevice::new(Box::new(adapter)).await.unwrap();
|
||||||
|
|
||||||
|
// Get the debug proxy
|
||||||
|
let service = client
|
||||||
|
.services
|
||||||
|
.get(idevice::dvt::SERVICE_NAME)
|
||||||
|
.expect("Client did not contain DVT service")
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
|
let mut adapter = client.into_inner();
|
||||||
|
adapter.connect(service.port).await.unwrap();
|
||||||
|
|
||||||
|
let mut rs_client = idevice::dvt::remote_server::RemoteServerClient::new(Box::new(adapter));
|
||||||
|
rs_client.read_message(0).await.expect("no read??");
|
||||||
|
|
||||||
|
let mut ls_client =
|
||||||
|
idevice::dvt::location_simulation::LocationSimulationClient::new(&mut rs_client)
|
||||||
|
.await
|
||||||
|
.expect("Unable to get channel for location simulation");
|
||||||
|
|
||||||
|
if matches.subcommand_matches("clear").is_some() {
|
||||||
|
ls_client.clear().await.expect("Unable to clear");
|
||||||
|
println!("Location cleared!");
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("set") {
|
||||||
|
let latitude: &String = match matches.get_one("latitude") {
|
||||||
|
Some(l) => l,
|
||||||
|
None => {
|
||||||
|
eprintln!("No latitude passed! Pass -h for help");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let latitude: f64 = latitude.parse().expect("Failed to parse as float");
|
||||||
|
let longitude: &String = match matches.get_one("longitude") {
|
||||||
|
Some(l) => l,
|
||||||
|
None => {
|
||||||
|
eprintln!("No longitude passed! Pass -h for help");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let longitude: f64 = longitude.parse().expect("Failed to parse as float");
|
||||||
|
ls_client
|
||||||
|
.set(latitude, longitude)
|
||||||
|
.await
|
||||||
|
.expect("Failed to set location");
|
||||||
|
|
||||||
|
println!("Location set!");
|
||||||
|
println!("Press ctrl-c to stop");
|
||||||
|
loop {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Invalid usage, pass -h for help");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user