diff options
author | 2021-06-29 04:21:25 +0200 | |
---|---|---|
committer | 2021-06-29 04:21:25 +0200 | |
commit | 8567650b1c2f44e2c53fb54b0e916ee3a0869add (patch) | |
tree | c9bc011956a7f7019796996bb72cd5f99673301b /src | |
parent | b09706b48b00d00cfd61638d9e9b932484b29b79 (diff) | |
download | idevicerestore-8567650b1c2f44e2c53fb54b0e916ee3a0869add.tar.gz idevicerestore-8567650b1c2f44e2c53fb54b0e916ee3a0869add.tar.bz2 |
Make device mode specific code more consistent
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 12 | ||||
-rw-r--r-- | src/common.h | 19 | ||||
-rw-r--r-- | src/dfu.c | 12 | ||||
-rw-r--r-- | src/idevicerestore.c | 103 | ||||
-rw-r--r-- | src/normal.c | 7 | ||||
-rw-r--r-- | src/recovery.c | 2 | ||||
-rw-r--r-- | src/restore.c | 32 |
7 files changed, 102 insertions, 85 deletions
diff --git a/src/common.c b/src/common.c index b5c88ee..4dbabc0 100644 --- a/src/common.c +++ b/src/common.c @@ -57,12 +57,12 @@ #define MAX_PRINT_LEN 64*1024 struct idevicerestore_mode_t idevicerestore_modes[] = { - { 0, "WTF" }, - { 1, "DFU" }, - { 2, "Recovery" }, - { 3, "Restore" }, - { 4, "Normal" }, - { -1, NULL } + { 0, "Unknown" }, + { 1, "WTF" }, + { 2, "DFU" }, + { 3, "Recovery" }, + { 4, "Restore" }, + { 5, "Normal" }, }; int idevicerestore_debug = 0; diff --git a/src/common.h b/src/common.h index 5d23299..3a4c069 100644 --- a/src/common.h +++ b/src/common.h @@ -41,12 +41,19 @@ extern "C" { #include "idevicerestore.h" #include "thread.h" -#define MODE_UNKNOWN -1 -#define MODE_WTF 0 -#define MODE_DFU 1 -#define MODE_RECOVERY 2 -#define MODE_RESTORE 3 -#define MODE_NORMAL 4 +#define _MODE_UNKNOWN 0 +#define _MODE_WTF 1 +#define _MODE_DFU 2 +#define _MODE_RECOVERY 3 +#define _MODE_RESTORE 4 +#define _MODE_NORMAL 5 + +#define MODE_UNKNOWN &idevicerestore_modes[_MODE_UNKNOWN] +#define MODE_WTF &idevicerestore_modes[_MODE_WTF] +#define MODE_DFU &idevicerestore_modes[_MODE_DFU] +#define MODE_RECOVERY &idevicerestore_modes[_MODE_RECOVERY] +#define MODE_RESTORE &idevicerestore_modes[_MODE_RESTORE] +#define MODE_NORMAL &idevicerestore_modes[_MODE_NORMAL] #define FLAG_QUIT 1 @@ -399,7 +399,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide if (mode != IRECV_K_DFU_MODE) { info("NOTE: device is not in DFU mode, assuming recovery mode.\n"); - client->mode = &idevicerestore_modes[MODE_RECOVERY]; + client->mode = MODE_RECOVERY; return 0; } @@ -417,7 +417,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide /* reconnect */ debug("Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { error("ERROR: Device did not disconnect. Possibly invalid iBSS. Reset device and try again.\n"); @@ -426,7 +426,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide } debug("Waiting for device to reconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if ((client->mode != &idevicerestore_modes[MODE_DFU] && client->mode != &idevicerestore_modes[MODE_RECOVERY]) || (client->flags & FLAG_QUIT)) { + if ((client->mode != MODE_DFU && client->mode != MODE_RECOVERY) || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { error("ERROR: Device did not reconnect in DFU or recovery mode. Possibly invalid iBSS. Reset device and try again.\n"); @@ -560,7 +560,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide return -1; } - if (client->mode == &idevicerestore_modes[MODE_RECOVERY]) { + if (client->mode == MODE_RECOVERY) { sleep(1); if (irecv_send_command_breq(client->dfu->client, "go", 1) != IRECV_E_SUCCESS) { mutex_unlock(&client->device_event_mutex); @@ -577,7 +577,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide debug("Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { error("ERROR: Device did not disconnect. Possibly invalid %s. Reset device and try again.\n", (client->build_major > 8) ? "iBEC" : "iBSS"); @@ -586,7 +586,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide } debug("Waiting for device to reconnect in recovery mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { error("ERROR: Device did not reconnect in recovery mode. Possibly invalid %s. Reset device and try again.\n", (client->build_major > 8) ? "iBEC" : "iBSS"); diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 024e60b..fa25ff4 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -247,13 +247,13 @@ static void idevice_event_cb(const idevice_event_t *event, void *userdata) } if (normal_check_mode(client) == 0) { mutex_lock(&client->device_event_mutex); - client->mode = &idevicerestore_modes[MODE_NORMAL]; + client->mode = MODE_NORMAL; debug("%s: device %016" PRIx64 " (udid: %s) connected in normal mode\n", __func__, client->ecid, client->udid); cond_signal(&client->device_event_cond); mutex_unlock(&client->device_event_mutex); } else if (client->ecid && restore_check_mode(client) == 0) { mutex_lock(&client->device_event_mutex); - client->mode = &idevicerestore_modes[MODE_RESTORE]; + client->mode = MODE_RESTORE; debug("%s: device %016" PRIx64 " (udid: %s) connected in restore mode\n", __func__, client->ecid, client->udid); cond_signal(&client->device_event_cond); mutex_unlock(&client->device_event_mutex); @@ -261,7 +261,7 @@ static void idevice_event_cb(const idevice_event_t *event, void *userdata) } else if (event->event == IDEVICE_DEVICE_REMOVE) { if (client->udid && !strcmp(event->udid, client->udid)) { mutex_lock(&client->device_event_mutex); - client->mode = &idevicerestore_modes[MODE_UNKNOWN]; + client->mode = MODE_UNKNOWN; debug("%s: device %016" PRIx64 " (udid: %s) disconnected\n", __func__, client->ecid, client->udid); client->ignore_device_add_events = 0; cond_signal(&client->device_event_cond); @@ -281,19 +281,19 @@ static void irecv_event_cb(const irecv_device_event_t* event, void *userdata) mutex_lock(&client->device_event_mutex); switch (event->mode) { case IRECV_K_WTF_MODE: - client->mode = &idevicerestore_modes[MODE_WTF]; + client->mode = MODE_WTF; break; case IRECV_K_DFU_MODE: - client->mode = &idevicerestore_modes[MODE_DFU]; + client->mode = MODE_DFU; break; case IRECV_K_RECOVERY_MODE_1: case IRECV_K_RECOVERY_MODE_2: case IRECV_K_RECOVERY_MODE_3: case IRECV_K_RECOVERY_MODE_4: - client->mode = &idevicerestore_modes[MODE_RECOVERY]; + client->mode = MODE_RECOVERY; break; default: - client->mode = &idevicerestore_modes[MODE_UNKNOWN]; + client->mode = MODE_UNKNOWN; } debug("%s: device %016" PRIx64 " (udid: %s) connected in %s mode\n", __func__, client->ecid, (client->udid) ? client->udid : "N/A", client->mode->string); cond_signal(&client->device_event_cond); @@ -302,7 +302,7 @@ static void irecv_event_cb(const irecv_device_event_t* event, void *userdata) } else if (event->type == IRECV_DEVICE_REMOVE) { if (client->ecid && event->device_info->ecid == client->ecid) { mutex_lock(&client->device_event_mutex); - client->mode = &idevicerestore_modes[MODE_UNKNOWN]; + client->mode = MODE_UNKNOWN; debug("%s: device %016" PRIx64 " (udid: %s) disconnected\n", __func__, client->ecid, (client->udid) ? client->udid : "N/A"); cond_signal(&client->device_event_cond); mutex_unlock(&client->device_event_mutex); @@ -345,7 +345,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) // check which mode the device is currently in so we know where to start mutex_lock(&client->device_event_mutex); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode == &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (client->mode == MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Unable to discover device mode. Please make sure a device is attached.\n"); return -1; @@ -354,7 +354,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) info("Found device in %s mode\n", client->mode->string); mutex_unlock(&client->device_event_mutex); - if (client->mode->index == MODE_WTF) { + if (client->mode == MODE_WTF) { unsigned int cpid = 0; if (dfu_client_new(client) != 0) { @@ -429,7 +429,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) free(wtftmp); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_DFU] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_DFU || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); /* TODO: verify if it actually goes from 0x1222 -> 0x1227 */ error("ERROR: Failed to put device into DFU from WTF mode\n"); @@ -447,7 +447,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) idevicerestore_progress(client, RESTORE_STEP_DETECT, 0.2); info("Identified device as %s, %s\n", client->device->hardware_model, client->device->product_type); - if ((client->flags & FLAG_PWN) && (client->mode->index != MODE_DFU)) { + if ((client->flags & FLAG_PWN) && (client->mode != MODE_DFU)) { error("ERROR: you need to put your device into DFU mode to pwn it.\n"); return -1; } @@ -455,7 +455,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) if (client->flags & FLAG_PWN) { recovery_client_free(client); - if (client->mode->index != MODE_DFU) { + if (client->mode != MODE_DFU) { error("ERROR: Device needs to be in DFU mode for this option.\n"); return -1; } @@ -590,7 +590,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) return 0; } - if (client->mode->index == MODE_RESTORE) { + if (client->mode == MODE_RESTORE) { if (client->flags & FLAG_ALLOW_RESTORE_MODE) { tss_enabled = 0; if (!client->root_ticket) { @@ -606,7 +606,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) // we need to refresh the current mode again mutex_lock(&client->device_event_mutex); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000); - if (client->mode == &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (client->mode == MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Unable to discover device mode. Please make sure a device is attached.\n"); return -1; @@ -831,7 +831,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) /* print information about current build identity */ build_identity_print_information(build_identity); - if (client->mode->index == MODE_NORMAL && !(client->flags & FLAG_ERASE) && !(client->flags & FLAG_SHSHONLY)) { + if (client->mode == MODE_NORMAL && !(client->flags & FLAG_ERASE) && !(client->flags & FLAG_SHSHONLY)) { plist_t pver = normal_get_lockdown_value(client, NULL, "ProductVersion"); char *device_version = NULL; if (pver) { @@ -1030,7 +1030,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } info("Found ECID %" PRIu64 "\n", client->ecid); - if (client->mode->index == MODE_NORMAL && !(client->flags & FLAG_ERASE) && !(client->flags & FLAG_SHSHONLY)) { + if (client->mode == MODE_NORMAL && !(client->flags & FLAG_ERASE) && !(client->flags & FLAG_SHSHONLY)) { plist_t node = normal_get_lockdown_value(client, NULL, "HasSiDP"); uint8_t needs_preboard = 0; if (node && plist_get_node_type(node) == PLIST_BOOLEAN) { @@ -1179,7 +1179,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } // if the device is in normal mode, place device into recovery mode - if (client->mode->index == MODE_NORMAL) { + if (client->mode == MODE_NORMAL) { info("Entering recovery mode...\n"); if (normal_enter_recovery(client) < 0) { error("ERROR: Unable to place device into recovery mode from normal mode\n"); @@ -1197,7 +1197,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) return -1; } - if (client->mode->index == MODE_DFU) { + if (client->mode == MODE_DFU) { // if the device is in DFU mode, place it into recovery mode dfu_client_free(client); recovery_client_free(client); @@ -1229,7 +1229,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) unlink(filesystem); return -2; } - } else if (client->mode->index == MODE_RECOVERY) { + } else if (client->mode == MODE_RECOVERY) { // device is in recovery mode if ((client->build_major > 8) && !(client->flags & FLAG_CUSTOM)) { if (!client->image4supported) { @@ -1257,7 +1257,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) debug("Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_UNKNOWN] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { @@ -1269,7 +1269,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } debug("Waiting for device to reconnect in recovery mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - if (client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { error("ERROR: Device did not reconnect in recovery mode. Possibly invalid iBEC. Reset device and try again.\n"); @@ -1337,7 +1337,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } // now finally do the magic to put the device into restore mode - if (client->mode->index == MODE_RECOVERY) { + if (client->mode == MODE_RECOVERY) { if (client->srnm == NULL) { error("ERROR: could not retrieve device serial number. Can't continue.\n"); if (delete_fs && filesystem) @@ -1357,11 +1357,11 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } idevicerestore_progress(client, RESTORE_STEP_PREPARE, 0.9); - if (client->mode->index != MODE_RESTORE) { + if (client->mode != MODE_RESTORE) { mutex_lock(&client->device_event_mutex); info("Waiting for device to enter restore mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 180000); - if (client->mode != &idevicerestore_modes[MODE_RESTORE] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_RESTORE || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Device failed to enter restore mode.\n"); error("Please make sure that usbmuxd is running.\n"); @@ -1373,7 +1373,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) } // device is finally in restore mode, let's do this - if (client->mode->index == MODE_RESTORE) { + if (client->mode == MODE_RESTORE) { if ((client->flags & FLAG_NO_RESTORE) != 0) { info("Device is now in restore mode. Exiting as requested."); return 0; @@ -1429,7 +1429,7 @@ struct idevicerestore_client_t* idevicerestore_client_new(void) return NULL; } memset(client, '\0', sizeof(struct idevicerestore_client_t)); - client->mode = &idevicerestore_modes[MODE_UNKNOWN]; + client->mode = MODE_UNKNOWN; mutex_init(&client->device_event_mutex); cond_init(&client->device_event_cond); return client; @@ -1564,8 +1564,7 @@ void plain_progress_cb(int step, double step_progress, void* userdata) fflush(stdout); } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { int opt = 0; int optindex = 0; char* ipsw = NULL; @@ -1744,21 +1743,21 @@ int main(int argc, char* argv[]) irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) { - int mode = MODE_UNKNOWN; + int mode = _MODE_UNKNOWN; if (client->mode) { mode = client->mode->index; } switch (mode) { - case MODE_RESTORE: + case _MODE_RESTORE: return restore_get_irecv_device(client); - case MODE_NORMAL: + case _MODE_NORMAL: return normal_get_irecv_device(client); - case MODE_DFU: - case MODE_RECOVERY: + case _MODE_DFU: + case _MODE_RECOVERY: return dfu_get_irecv_device(client); default: @@ -1769,23 +1768,23 @@ irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) int is_image4_supported(struct idevicerestore_client_t* client) { int res = 0; - int mode = MODE_UNKNOWN; + int mode = _MODE_UNKNOWN; if (client->mode) { mode = client->mode->index; } switch (mode) { - case MODE_NORMAL: + case _MODE_NORMAL: res = normal_is_image4_supported(client); break; - case MODE_RESTORE: + case _MODE_RESTORE: res = restore_is_image4_supported(client); break; - case MODE_DFU: + case _MODE_DFU: res = dfu_is_image4_supported(client); break; - case MODE_RECOVERY: + case _MODE_RECOVERY: res = recovery_is_image4_supported(client); break; default: @@ -1797,28 +1796,28 @@ int is_image4_supported(struct idevicerestore_client_t* client) int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { - int mode = MODE_UNKNOWN; + int mode = _MODE_UNKNOWN; if (client->mode) { mode = client->mode->index; } switch (mode) { - case MODE_NORMAL: + case _MODE_NORMAL: if (normal_get_ecid(client, ecid) < 0) { *ecid = 0; return -1; } break; - case MODE_DFU: + case _MODE_DFU: if (dfu_get_ecid(client, ecid) < 0) { *ecid = 0; return -1; } break; - case MODE_RECOVERY: + case _MODE_RECOVERY: if (recovery_get_ecid(client, ecid) < 0) { *ecid = 0; return -1; @@ -1836,7 +1835,7 @@ int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { - int mode = MODE_UNKNOWN; + int mode = _MODE_UNKNOWN; *nonce = NULL; *nonce_size = 0; @@ -1848,21 +1847,21 @@ int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, } switch (mode) { - case MODE_NORMAL: + case _MODE_NORMAL: info("in normal mode... "); if (normal_get_ap_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } break; - case MODE_DFU: + case _MODE_DFU: info("in dfu mode... "); if (dfu_get_ap_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } break; - case MODE_RECOVERY: + case _MODE_RECOVERY: info("in recovery mode... "); if (recovery_get_ap_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); @@ -1887,7 +1886,7 @@ int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { - int mode = MODE_UNKNOWN; + int mode = _MODE_UNKNOWN; *nonce = NULL; *nonce_size = 0; @@ -1899,21 +1898,21 @@ int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, } switch (mode) { - case MODE_NORMAL: + case _MODE_NORMAL: info("in normal mode... "); if (normal_get_sep_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } break; - case MODE_DFU: + case _MODE_DFU: info("in dfu mode... "); if (dfu_get_sep_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); return -1; } break; - case MODE_RECOVERY: + case _MODE_RECOVERY: info("in recovery mode... "); if (recovery_get_sep_nonce(client, nonce, nonce_size) < 0) { info("failed\n"); @@ -2262,7 +2261,7 @@ int get_tss_response(struct idevicerestore_client_t* client, plist_t build_ident } } - if (client->mode->index == MODE_NORMAL) { + if (client->mode == MODE_NORMAL) { /* normal mode; request baseband ticket aswell */ plist_t pinfo = NULL; normal_get_preflight_info(client, &pinfo); diff --git a/src/normal.c b/src/normal.c index 93ace67..301dbbe 100644 --- a/src/normal.c +++ b/src/normal.c @@ -138,7 +138,8 @@ static int normal_idevice_new(struct idevicerestore_client_t* client, idevice_t* return 0; } -int normal_check_mode(struct idevicerestore_client_t* client) { +int normal_check_mode(struct idevicerestore_client_t* client) +{ idevice_t device = NULL; normal_idevice_new(client, &device); @@ -260,7 +261,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) mutex_lock(&client->device_event_mutex); debug("DEBUG: Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000); - if (client->mode == &idevicerestore_modes[MODE_NORMAL] || (client->flags & FLAG_QUIT)) { + if (client->mode == MODE_NORMAL || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Failed to place device in recovery mode\n"); return -1; @@ -268,7 +269,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) debug("DEBUG: Waiting for device to connect in recovery mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000); - if (client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) { + if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Failed to enter recovery mode\n"); return -1; diff --git a/src/recovery.c b/src/recovery.c index 6048382..b6a6f51 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -220,7 +220,7 @@ int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build debug("DEBUG: Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 30000); - if (client->mode == &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) { + if (client->mode == MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Failed to place device in restore mode\n"); return -1; diff --git a/src/restore.c b/src/restore.c index 984b3ab..e090594 100644 --- a/src/restore.c +++ b/src/restore.c @@ -359,7 +359,7 @@ int restore_reboot(struct idevicerestore_client_t* client) restored_client_free(client->restore->client); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 30000); - if (client->mode == &idevicerestore_modes[MODE_RESTORE]) { + if (client->mode == MODE_RESTORE) { mutex_unlock(&client->device_event_mutex); return -1; } @@ -2718,7 +2718,8 @@ error_out: return -1; } -plist_t restore_get_build_identity(struct idevicerestore_client_t* client, uint8_t is_recover_os) { +plist_t restore_get_build_identity(struct idevicerestore_client_t* client, uint8_t is_recover_os) +{ unsigned int size = 0; unsigned char* data = NULL; plist_t buildmanifest = NULL; @@ -2738,7 +2739,8 @@ plist_t restore_get_build_identity(struct idevicerestore_client_t* client, uint8 return build_identity; } -plist_t restore_get_build_identity_from_request(struct idevicerestore_client_t* client, plist_t msg) { +plist_t restore_get_build_identity_from_request(struct idevicerestore_client_t* client, plist_t msg) +{ plist_t args = plist_dict_get_item(msg, "Arguments"); plist_t is_recovery_node = plist_dict_get_item(args, "IsRecoveryOS"); uint8_t is_recovery = 0; @@ -2747,7 +2749,8 @@ plist_t restore_get_build_identity_from_request(struct idevicerestore_client_t* return restore_get_build_identity(client, is_recovery); } -int extract_macos_variant(plist_t build_identity, char** output) { +int extract_macos_variant(plist_t build_identity, char** output) +{ plist_t build_info = plist_dict_get_item(build_identity, "Info"); if (!build_info) { error("ERROR: build identity does not contain an 'Info' element\n"); @@ -2764,7 +2767,8 @@ int extract_macos_variant(plist_t build_identity, char** output) { return 0; } -int extract_global_manifest(struct idevicerestore_client_t* client, plist_t build_identity, unsigned char** pbuffer, unsigned int* psize) { +int extract_global_manifest(struct idevicerestore_client_t* client, plist_t build_identity, unsigned char** pbuffer, unsigned int* psize) +{ plist_t build_info = plist_dict_get_item(build_identity, "Info"); if (!build_info) { error("ERROR: build identity does not contain an 'Info' element\n"); @@ -2804,7 +2808,8 @@ int extract_global_manifest(struct idevicerestore_client_t* client, plist_t buil return 0; } -int restore_send_personalized_boot_object_v3(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity) { +int restore_send_personalized_boot_object_v3(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity) +{ debug_plist(msg); char *image_name = NULL; @@ -2927,7 +2932,8 @@ int restore_send_personalized_boot_object_v3(restored_client_t restore, struct i return 0; } -int restore_send_source_boot_object_v4(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity) { +int restore_send_source_boot_object_v4(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity) +{ debug_plist(msg); char *image_name = NULL; @@ -3036,7 +3042,8 @@ int restore_send_source_boot_object_v4(restored_client_t restore, struct idevice return 0; } -int restore_send_restore_local_policy(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg) { +int restore_send_restore_local_policy(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg) +{ unsigned int size = 0; unsigned char* data = NULL; @@ -3081,7 +3088,8 @@ int restore_send_restore_local_policy(restored_client_t restore, struct idevicer return 0; } -int restore_send_buildidentity(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg) { +int restore_send_buildidentity(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg) +{ restored_error_t restore_error; plist_t dict; @@ -3274,7 +3282,8 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev } // Extracted from ac2 -plist_t restore_supported_data_types() { +plist_t restore_supported_data_types() +{ plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "BasebandBootData", plist_new_bool(0)); plist_dict_set_item(dict, "BasebandData", plist_new_bool(0)); @@ -3334,7 +3343,8 @@ plist_t restore_supported_data_types() { } // Extracted from ac2 -plist_t restore_supported_message_types() { +plist_t restore_supported_message_types() +{ plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "BBUpdateStatusMsg", plist_new_bool(0)); plist_dict_set_item(dict, "CheckpointMsg", plist_new_bool(1)); |