From c607909beb0f765126751a236ef248ec004e48e2 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Thu, 14 Aug 2025 18:07:56 -0600 Subject: [PATCH] Implement ideviceinfo in cpp --- cpp/examples/ideviceinfo.cpp | 12 +++++++++++- cpp/include/idevice++/provider.hpp | 2 ++ cpp/src/provider.cpp | 11 +++++++++++ ffi/src/lockdown.rs | 2 +- ffi/src/provider.rs | 30 ++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/cpp/examples/ideviceinfo.cpp b/cpp/examples/ideviceinfo.cpp index a45968f..8c3246c 100644 --- a/cpp/examples/ideviceinfo.cpp +++ b/cpp/examples/ideviceinfo.cpp @@ -15,16 +15,19 @@ int main() { if (!u) { std::cerr << "failed to connect to usbmuxd"; std::cerr << e.message; + return 1; } auto devices = u->get_devices(e); if (!devices) { std::cerr << "failed to get devices from usbmuxd"; std::cerr << e.message; + return 1; } if (devices->empty()) { std::cerr << "no devices connected"; std::cerr << e.message; + return 1; } auto& dev = (*devices)[0]; @@ -55,7 +58,14 @@ int main() { return 1; } - auto values = client->get_value("", "", e); + auto pf = prov->get_pairing_file(e); + if (!pf) { + std::cerr << "failed to get pairing file: " << e.message << "\n"; + return 1; + } + client->start_session(*pf, e); + + auto values = client->get_value(NULL, NULL, e); if (!values) { std::cerr << "get values failed: " << e.message << "\n"; return 1; diff --git a/cpp/include/idevice++/provider.hpp b/cpp/include/idevice++/provider.hpp index 72a7175..e976058 100644 --- a/cpp/include/idevice++/provider.hpp +++ b/cpp/include/idevice++/provider.hpp @@ -37,6 +37,8 @@ class Provider { Provider(const Provider&) = delete; Provider& operator=(const Provider&) = delete; + std::optional get_pairing_file(FfiError& err); + IdeviceProviderHandle* raw() const noexcept { return handle_.get(); } static Provider adopt(IdeviceProviderHandle* h) noexcept { return Provider(h); } IdeviceProviderHandle* release() noexcept { return handle_.release(); } diff --git a/cpp/src/provider.cpp b/cpp/src/provider.cpp index 80c9c3c..6a5f606 100644 --- a/cpp/src/provider.cpp +++ b/cpp/src/provider.cpp @@ -49,4 +49,15 @@ std::optional Provider::usbmuxd_new(UsbmuxdAddr&& addr, return Provider::adopt(out); } +std::optional Provider::get_pairing_file(FfiError& err) { + + IdevicePairingFile* out = nullptr; + if (IdeviceFfiError* e = idevice_provider_get_pairing_file(handle_.get(), &out)) { + err = FfiError(e); + return std::nullopt; + } + + return PairingFile(out); +} + } // namespace IdeviceFFI diff --git a/ffi/src/lockdown.rs b/ffi/src/lockdown.rs index 63bf36d..a6f8959 100644 --- a/ffi/src/lockdown.rs +++ b/ffi/src/lockdown.rs @@ -179,7 +179,7 @@ pub unsafe extern "C" fn lockdownd_get_value( domain: *const libc::c_char, out_plist: *mut plist_t, ) -> *mut IdeviceFfiError { - if key.is_null() || out_plist.is_null() { + if out_plist.is_null() { return ffi_err!(IdeviceError::FfiInvalidArg); } diff --git a/ffi/src/provider.rs b/ffi/src/provider.rs index 95fd169..4ef967c 100644 --- a/ffi/src/provider.rs +++ b/ffi/src/provider.rs @@ -7,6 +7,7 @@ use std::{ffi::CStr, ptr::null_mut}; use crate::util::{SockAddr, idevice_sockaddr}; use crate::{IdeviceFfiError, ffi_err, usbmuxd::UsbmuxdAddrHandle, util}; +use crate::{IdevicePairingFile, RUNTIME}; pub struct IdeviceProviderHandle(pub Box); @@ -136,3 +137,32 @@ pub unsafe extern "C" fn usbmuxd_provider_new( null_mut() } + +/// Gets the pairing file for the device +/// +/// # Arguments +/// * [`provider`] - A pointer to the provider +/// * [`pairing_file`] - A pointer to the newly allocated pairing file +/// +/// # Returns +/// An IdeviceFfiError on error, null on success +/// +/// # Safety +/// `provider` must be a valid, non-null pointer to the provider +#[unsafe(no_mangle)] +pub unsafe extern "C" fn idevice_provider_get_pairing_file( + provider: *mut IdeviceProviderHandle, + pairing_file: *mut *mut IdevicePairingFile, +) -> *mut IdeviceFfiError { + let provider = unsafe { &mut *provider }; + + let res = RUNTIME.block_on(async move { provider.0.get_pairing_file().await }); + match res { + Ok(pf) => { + let pf = Box::new(IdevicePairingFile(pf)); + unsafe { *pairing_file = Box::into_raw(pf) }; + null_mut() + } + Err(e) => ffi_err!(e), + } +}