Implement lockdown enter recovery

This commit is contained in:
Jackson Coxson
2026-01-05 12:00:11 -07:00
parent a4e17ea076
commit bb64dc0b1c
3 changed files with 55 additions and 1 deletions

View File

@@ -179,7 +179,7 @@ pub unsafe extern "C" fn lockdownd_get_value(
domain: *const libc::c_char, domain: *const libc::c_char,
out_plist: *mut plist_t, out_plist: *mut plist_t,
) -> *mut IdeviceFfiError { ) -> *mut IdeviceFfiError {
if out_plist.is_null() { if client.is_null() || out_plist.is_null() {
return ffi_err!(IdeviceError::FfiInvalidArg); return ffi_err!(IdeviceError::FfiInvalidArg);
} }
@@ -221,6 +221,35 @@ pub unsafe extern "C" fn lockdownd_get_value(
} }
} }
/// Tells the device to enter recovery mode
///
/// # Arguments
/// * `client` - A valid LockdowndClient handle
///
/// # Returns
/// An IdeviceFfiError on error, null on success
///
/// # Safety
/// `client` must be a valid pointer to a handle allocated by this library
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lockdownd_enter_recovery(
client: *mut LockdowndClientHandle,
) -> *mut IdeviceFfiError {
if client.is_null() {
return ffi_err!(IdeviceError::FfiInvalidArg);
}
let res: Result<(), IdeviceError> = run_sync_local(async move {
let client_ref = unsafe { &mut (*client).0 };
client_ref.enter_recovery().await
});
match res {
Ok(_) => null_mut(),
Err(e) => ffi_err!(e),
}
}
/// Frees a LockdowndClient handle /// Frees a LockdowndClient handle
/// ///
/// # Arguments /// # Arguments

View File

@@ -326,6 +326,23 @@ impl LockdownClient {
} }
} }
} }
/// Tell the device to enter recovery mode
pub async fn enter_recovery(&mut self) -> Result<(), IdeviceError> {
self.idevice
.send_plist(crate::plist!({
"Request": "EnterRecovery"
}))
.await?;
let res = self.idevice.read_plist().await?;
if res.get("Request").and_then(|x| x.as_string()) == Some("EnterRecovery") {
Ok(())
} else {
Err(IdeviceError::UnexpectedResponse)
}
}
} }
impl From<Idevice> for LockdownClient { impl From<Idevice> for LockdownClient {

View File

@@ -29,6 +29,10 @@ pub fn register() -> JkCommand {
.required(true), .required(true),
), ),
) )
.with_subcommand(
"recovery",
JkCommand::new().help("Tell the device to enter recovery mode"),
)
.with_flag( .with_flag(
JkFlag::new("domain") JkFlag::new("domain")
.with_help("The domain to set/get in") .with_help("The domain to set/get in")
@@ -86,6 +90,10 @@ pub async fn main(arguments: &CollectedArguments, provider: Box<dyn IdeviceProvi
Err(e) => eprintln!("Error setting value: {e}"), Err(e) => eprintln!("Error setting value: {e}"),
} }
} }
"recovery" => lockdown_client
.enter_recovery()
.await
.expect("Failed to enter recovery"),
_ => unreachable!(), _ => unreachable!(),
} }
} }