From 6479f06c0ee4c65559eb46085433d60cec62fd3e Mon Sep 17 00:00:00 2001 From: nir Date: Mon, 2 Dec 2024 12:42:31 +0000 Subject: [PATCH] Revert "AWS backup" This reverts commit b7d5c4a88d5b4b93183c768f7ee907cf2fd1a5d8. --- .gitignore | 1 + src/asr.c | 23 +++++++---------------- src/common.c | 17 ----------------- src/dfu.c | 23 ++++++++--------------- src/fdr.c | 2 +- src/idevicerestore.c | 20 +------------------- src/normal.c | 10 ---------- src/recovery.c | 7 +------ src/restore.c | 7 +------ 9 files changed, 20 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index e8c1b827..bdfaa099 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ ltmain.sh missing mkinstalldirs libtool +*Makefile py-compile stamp-h1 src/.libs diff --git a/src/asr.c b/src/asr.c index 0caf3918..15396c4a 100644 --- a/src/asr.c +++ b/src/asr.c @@ -44,8 +44,8 @@ #define ASR_FEC_SLICE_STRIDE 40 #define ASR_PACKETS_PER_FEC 25 #define ASR_PAYLOAD_PACKET_SIZE 1450 -#define ASR_PAYLOAD_CHUNK_SIZE 32768 -#define ASR_CHECKSUM_CHUNK_SIZE 32768 +#define ASR_PAYLOAD_CHUNK_SIZE 131072 +#define ASR_CHECKSUM_CHUNK_SIZE 131072 int asr_open_with_timeout(idevice_t device, asr_client_t* asr, uint16_t port) { @@ -354,11 +354,9 @@ int asr_handle_oob_data_request(asr_client_t asr, plist_t packet, ipsw_file_hand free(oob_data); return 0; } -int g_count = 0 ; + int asr_send_payload(asr_client_t asr, ipsw_file_handle_t file) { - g_count++; - info("asr_send_payload small packets") ; char *data = NULL; uint64_t i, length, bytes = 0; double progress = 0; @@ -377,20 +375,18 @@ int asr_send_payload(asr_client_t asr, ipsw_file_handle_t file) if (i < ASR_PAYLOAD_CHUNK_SIZE) { size = i; } - //info("\r\nipsw_file_read"); + if (ipsw_file_read(file, data, size) != (int64_t)size) { - info("Error reading filesystem\n"); + error("Error reading filesystem\n"); retry--; continue; } - //info("ipsw_file_read read done"); + sendsize = size; if (asr->checksum_chunks) { sha1((unsigned char*)data, size, (unsigned char*)(data+size)); sendsize += 20; } - - // info("\r\nasr_send_buffer"); if (asr_send_buffer(asr, data, sendsize) < 0) { error("Unable to send filesystem payload chunk, retrying...\n"); retry--; @@ -405,13 +401,8 @@ int asr_send_payload(asr_client_t asr, ipsw_file_handle_t file) } i -= size; - if(g_count%20==0) - Sleep(1) ; - //info("again"); } - info("\r\nfree"); + free(data); - info("\r\nreturn"); return (i == 0) ? 0 : -1; - } diff --git a/src/common.c b/src/common.c index 4e7d71b0..c7be4f66 100644 --- a/src/common.c +++ b/src/common.c @@ -79,15 +79,6 @@ static FILE* debug_stream = NULL; static int info_disabled = 0; static int error_disabled = 0; static int debug_disabled = 0; -void printTime() -{ - time_t rawtime; - struct tm * timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - // Print current time in human-readable format - printf("\nCurrent time: %02d:%02d:%02d\n %d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); -} static mutex_t log_mutex; static thread_once_t init_once = THREAD_ONCE_INIT; @@ -106,11 +97,8 @@ void info(const char* format, ...) va_start(vargs, format); vfprintf((info_stream) ? info_stream : stdout, format, vargs); va_end(vargs); - printTime() ; fflush(info_stream?info_stream:stdout); - mutex_unlock(&log_mutex); - } void error(const char* format, ...) @@ -126,11 +114,8 @@ void error(const char* format, ...) vfprintf((error_stream) ? error_stream : stderr, format, vargs2); } va_end(vargs2); - printTime() ; - fflush(error_stream?error_stream:stderr); mutex_unlock(&log_mutex); - } void debug(const char* format, ...) @@ -145,10 +130,8 @@ void debug(const char* format, ...) va_start(vargs, format); vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); va_end(vargs); - printTime(); fflush(debug_stream?debug_stream:stderr); mutex_unlock(&log_mutex); - } void idevicerestore_set_info_stream(FILE* strm) diff --git a/src/dfu.c b/src/dfu.c index 0c2719b8..508b4f61 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -465,16 +465,19 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide } dfu_client_free(client); - int tries = 3; if (client->build_major > 8) { /* reconnect */ debug("Waiting for device to disconnect...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); - tries = 3 ; - while(tries-- && ((client->mode != MODE_DFU && client->mode != MODE_RECOVERY) || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); + 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"); + } + return -1; } + debug("Waiting for device to reconnect...\n"); + cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); if ((client->mode != MODE_DFU && client->mode != MODE_RECOVERY) || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { @@ -641,11 +644,6 @@ 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); - tries = 3 ; - while(tries-- && (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { @@ -654,11 +652,6 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide return -1; } debug("Waiting for device to reconnect in recovery mode...\n"); - tries = 3 ; - while(tries-- && (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 10000); if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); diff --git a/src/fdr.c b/src/fdr.c index 9e30ac65..ca9b7c75 100644 --- a/src/fdr.c +++ b/src/fdr.c @@ -142,7 +142,7 @@ int fdr_poll_and_handle_message(fdr_client_t fdr) return -1; } - device_error = idevice_connection_receive_timeout(fdr->connection, (char *)&cmd, sizeof(cmd), &bytes, 40000); + device_error = idevice_connection_receive_timeout(fdr->connection, (char *)&cmd, sizeof(cmd), &bytes, 20000); #ifdef HAVE_IDEVICE_E_TIMEOUT if (device_error == IDEVICE_E_TIMEOUT || (device_error == IDEVICE_E_SUCCESS && bytes != sizeof(cmd))) #else diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 1f5d9ec8..b8bb1d06 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -1436,11 +1436,6 @@ 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, 60000); - int tries = 3 ; - while(tries-- && (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode != MODE_UNKNOWN || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); @@ -1452,11 +1447,6 @@ int idevicerestore_start(struct idevicerestore_client_t* client) recovery_client_free(client); debug("Waiting for device to reconnect in recovery mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000); - tries = 3 ; - while(tries-- && (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); if (!(client->flags & FLAG_QUIT)) { @@ -1520,6 +1510,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) plist_free(client->tss); return -2; } + recovery_client_free(client); } idevicerestore_progress(client, RESTORE_STEP_PREPARE, 0.9); @@ -1527,11 +1518,6 @@ int idevicerestore_start(struct idevicerestore_client_t* client) 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); - int tries = 13 ; - while(tries-- && (client->mode != MODE_RESTORE || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode != MODE_RESTORE || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Device failed to enter restore mode.\n"); @@ -1741,12 +1727,9 @@ void plain_progress_cb(int step, double step_progress, void* userdata) { printf("progress: %u %f\n", step, step_progress); fflush(stdout); - fflush(stderr); } int main(int argc, char* argv[]) { - //setbuf(stdout, NULL); - //setbuf(stderr, NULL); int opt = 0; int optindex = 0; char* ipsw = NULL; @@ -1984,7 +1967,6 @@ int main(int argc, char* argv[]) { irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) { - info("get_irecv_device"); int mode = _MODE_UNKNOWN; if (client->mode) { diff --git a/src/normal.c b/src/normal.c index b61c63d0..9e460803 100644 --- a/src/normal.c +++ b/src/normal.c @@ -260,11 +260,6 @@ 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); - int tries = 3 ; - while(tries-- && (client->mode == MODE_NORMAL || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } 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"); @@ -273,11 +268,6 @@ 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); - tries = 3 ; - while(tries-- && (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode != MODE_RECOVERY || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Failed to enter recovery mode\n"); diff --git a/src/recovery.c b/src/recovery.c index 8031b493..c4513502 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -234,12 +234,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, 40000); - int tries = 13 ; - while(tries-- && (client->mode == MODE_RECOVERY || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } + cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 30000); 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"); diff --git a/src/restore.c b/src/restore.c index e51edc44..2daeea2b 100644 --- a/src/restore.c +++ b/src/restore.c @@ -364,11 +364,6 @@ 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); - int tries = 3 ; - while(tries-- && (client->mode == MODE_RECOVERY || (client->flags & FLAG_QUIT))) { - debug("cond_wait_timeout retry\n"); - cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 3000); - } if (client->mode == MODE_RESTORE) { mutex_unlock(&client->device_event_mutex); return -1; @@ -5710,4 +5705,4 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit restore_client_free(client); return err; -} \ No newline at end of file +}