summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common.h3
-rw-r--r--src/idevicerestore.c10
-rw-r--r--src/idevicerestore.h5
-rw-r--r--src/restore.c16
4 files changed, 29 insertions, 5 deletions
diff --git a/src/common.h b/src/common.h
index b01e471..3e50867 100644
--- a/src/common.h
+++ b/src/common.h
@@ -129,6 +129,9 @@ struct idevicerestore_client_t {
char* filesystem;
int delete_fs;
int async_err;
+ /* The Status of the last StatusMsg the restore OS sent, once one did. */
+ int final_status_received;
+ uint64_t final_status;
};
extern int global_quit_flag;
diff --git a/src/idevicerestore.c b/src/idevicerestore.c
index 23db769..c1162a9 100644
--- a/src/idevicerestore.c
+++ b/src/idevicerestore.c
@@ -370,6 +370,8 @@ int idevicerestore_start(struct idevicerestore_client_t* client)
return -1;
}
+ client->final_status_received = 0;
+
if ((client->flags & FLAG_LATEST) && (client->flags & FLAG_CUSTOM)) {
logger(LL_ERROR, "FLAG_LATEST cannot be used with FLAG_CUSTOM.\n");
return -1;
@@ -1717,6 +1719,14 @@ void idevicerestore_set_ipsw(struct idevicerestore_client_t* client, const char*
}
}
+int idevicerestore_get_final_status(struct idevicerestore_client_t* client, uint64_t* status)
+{
+ if (!client || !status || !client->final_status_received)
+ return -1;
+ *status = client->final_status;
+ return 0;
+}
+
void idevicerestore_set_post_restore_action(struct idevicerestore_client_t* client, const char* action)
{
if (!client)
diff --git a/src/idevicerestore.h b/src/idevicerestore.h
index 2b98191..b79ad36 100644
--- a/src/idevicerestore.h
+++ b/src/idevicerestore.h
@@ -90,6 +90,11 @@ void idevicerestore_set_progress_callback(struct idevicerestore_client_t* client
void idevicerestore_set_post_restore_action(struct idevicerestore_client_t* client, const char* action);
int idevicerestore_start(struct idevicerestore_client_t* client);
+/* Returns 0 and sets *status to the last raw unsigned Status value the restore
+ * OS sent during the current restore attempt. A finished restore reports 0
+ * and a verification error reports 0xFFFFFFFFFFFFFFFF. Returns -1 if no
+ * integer Status was received or either argument is NULL. */
+int idevicerestore_get_final_status(struct idevicerestore_client_t* client, uint64_t* status);
const char* idevicerestore_get_error(void);
irecv_device_t get_irecv_device(struct idevicerestore_client_t* client);
diff --git a/src/restore.c b/src/restore.c
index 251f2ec..a69c581 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -119,8 +119,6 @@
#define SEALING_SYSTEM_VOLUME 77
#define UPDATING_APPLETCON 81
-static int restore_finished = 0;
-
static int restore_device_connected = 0;
int restore_client_new(struct idevicerestore_client_t* client)
@@ -937,12 +935,18 @@ int restore_handle_status_msg(struct idevicerestore_client_t* client, plist_t ms
// read status code
plist_t node = plist_dict_get_item(msg, "Status");
+ if (!node || plist_get_node_type(node) != PLIST_INT) {
+ logger(LL_WARNING, "Ignoring status message without an integer Status\n");
+ logger_dump_plist(LL_VERBOSE, msg, 1);
+ return 0;
+ }
plist_get_uint_val(node, &value);
+ client->final_status = value;
+ client->final_status_received = 1;
switch(value) {
case 0:
logger(LL_INFO, "Status: Restore Finished\n");
- restore_finished = 1;
break;
case 0xFFFFFFFFFFFFFFFFLL:
logger(LL_INFO, "Status: Verification Error\n");
@@ -5489,7 +5493,9 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit
THREAD_T fdr_thread = THREAD_T_NULL;
#endif
- restore_finished = 0;
+ if (client) {
+ client->final_status_received = 0;
+ }
// open our connection to the device and verify we're in restore mode
err = restore_open_with_timeout(client);
@@ -5887,7 +5893,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit
// process or often to signal an error has been encountered
else if (!strcmp(type, "StatusMsg")) {
err = restore_handle_status_msg(client, message);
- if (restore_finished) {
+ if (client->final_status_received && client->final_status == 0) {
plist_t dict = plist_new_dict();
plist_dict_set_item(dict, "MsgType", plist_new_string("ReceivedFinalStatusMsg"));
restored_send(restore, dict);