From 21f2060266be290283eae0e53a87de679364159f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 7 Oct 2019 02:58:45 +0200 Subject: Recovery: Properly detect iBEC execution (via device reconnect) --- src/idevicerestore.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/idevicerestore.c b/src/idevicerestore.c index f354b12..6a9add0 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -1163,10 +1163,27 @@ int idevicerestore_start(struct idevicerestore_client_t* client) return -2; } recovery_client_free(client); - - /* this must be long enough to allow the device to run the iBEC */ - /* FIXME: Probably better to detect if the device is back then */ - sleep(7); + + debug("Waiting for device to disconnect...\n"); + WAIT_FOR(client->mode == &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT), 10); + if (client->mode != &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (!(client->flags & FLAG_QUIT)) { + error("ERROR: Device did not disconnect. Possibly invalid iBEC. Reset device and try again.\n"); + } + if (delete_fs && filesystem) + unlink(filesystem); + return -2; + } + debug("Waiting for device to reconnect in recovery mode...\n"); + WAIT_FOR(client->mode == &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT), 10); + if (client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) { + if (!(client->flags & FLAG_QUIT)) { + error("ERROR: Device did not reconnect in recovery mode. Possibly invalid iBEC. Reset device and try again.\n"); + } + if (delete_fs && filesystem) + unlink(filesystem); + return -2; + } } idevicerestore_progress(client, RESTORE_STEP_PREPARE, 0.5); if (client->flags & FLAG_QUIT) { -- cgit v1.1-32-gdbae