int recovery_open_with_timeout(irecv_client_t* client) { int i = 0; int attempts = 10; irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR; for (i = 1; i <= attempts; i++) { recovery_error = irecv_open(&recovery); if (recovery_error == IRECV_E_SUCCESS) { break; } if (i >= attempts) { error("ERROR: Unable to connect to device in recovery mode\n"); return -1; } sleep(2); debug("Retrying connection...\n"); } irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL); *client = recovery; return 0; }
int dfu_client_new(struct idevicerestore_client_t* client) { int i = 0; int attempts = 10; irecv_client_t dfu = NULL; irecv_error_t dfu_error = IRECV_E_UNKNOWN_ERROR; if (client->dfu == NULL) { client->dfu = (struct dfu_client_t*)malloc(sizeof(struct dfu_client_t)); memset(client->dfu, 0, sizeof(struct dfu_client_t)); if (client->dfu == NULL) { error("ERROR: Out of memory\n"); return -1; } } for (i = 1; i <= attempts; i++) { dfu_error = irecv_open(&dfu, client->ecid); if (dfu_error == IRECV_E_SUCCESS) { break; } if (i >= attempts) { error("ERROR: Unable to connect to device in DFU mode\n"); return -1; } sleep(1); debug("Retrying connection...\n"); } irecv_event_subscribe(dfu, IRECV_PROGRESS, &dfu_progress_callback, NULL); client->dfu->client = dfu; return 0; }
irecv_error_t irecv_open_attempts(irecv_client_t* pclient, int attempts) { int i; for (i = 0; i < attempts; i++) { if (irecv_open(pclient) != IRECV_E_SUCCESS) { debug("Connection failed. Waiting 1 sec before retry.\n"); sleep(1); } else { return IRECV_E_SUCCESS; } } return IRECV_E_UNABLE_TO_CONNECT; }
/* * Class: Jsyringe * Method: wait_for_connect * Signature: (I)Ljava/lang/Boolean; */ JNIEXPORT jboolean JNICALL Java_Jsyringe_wait_1for_1connect (JNIEnv *env, jclass jClass) { jboolean jresult = JNI_FALSE; if (g_syringe_client != NULL) { irecv_close(&g_syringe_client); } if (0 == irecv_open(&g_syringe_client) && g_syringe_client->mode == kDfuMode) { if (irecv_get_device(g_syringe_client, &g_syringe_device) == IRECV_E_SUCCESS) { g_model = g_syringe_device->model; jresult = JNI_TRUE; } } cleanup: if (g_syringe_client != NULL) irecv_close(&g_syringe_client); return jresult; }
int recovery_check_mode() { irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_SUCCESS; recovery_error = irecv_open(&recovery); if (recovery_error != IRECV_E_SUCCESS) { return -1; } if (recovery->mode == kDfuMode) { irecv_close(recovery); return -1; } irecv_close(recovery); recovery = NULL; return 0; }
int recovery_client_new(struct idevicerestore_client_t* client) { int i = 0; int attempts = 10; irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR; if(client->recovery == NULL) { client->recovery = (struct recovery_client_t*)malloc(sizeof(struct recovery_client_t)); if (client->recovery == NULL) { error("ERROR: Out of memory\n"); return -1; } memset(client->recovery, 0, sizeof(struct recovery_client_t)); } for (i = 1; i <= attempts; i++) { recovery_error = irecv_open(&recovery, client->ecid); if (recovery_error == IRECV_E_SUCCESS) { break; } if (i >= attempts) { error("ERROR: Unable to connect to device in recovery mode\n"); return -1; } sleep(4); debug("Retrying connection...\n"); } if (client->srnm == NULL) { char snbuf[256]; snbuf[0] = '\0'; irecv_get_srnm(recovery, snbuf); if (snbuf[0] != '\0') { client->srnm = strdup(snbuf); info("INFO: device serial number is %s\n", client->srnm); } } irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL); client->recovery->client = recovery; return 0; }
int recovery_check_mode(struct idevicerestore_client_t* client) { irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_SUCCESS; irecv_init(); recovery_error=irecv_open(&recovery, client->ecid); if (recovery_error != IRECV_E_SUCCESS) { return -1; } if ((recovery->mode == kDfuMode) || (recovery->mode == kWTFMode)) { irecv_close(recovery); return -1; } irecv_close(recovery); recovery = NULL; return 0; }
int dfu_check_mode(struct idevicerestore_client_t* client, int* mode) { irecv_client_t dfu = NULL; irecv_error_t dfu_error = IRECV_E_SUCCESS; irecv_init(); dfu_error=irecv_open(&dfu, client->ecid); if (dfu_error != IRECV_E_SUCCESS) { return -1; } if ((dfu->mode != kDfuMode) && (dfu->mode != kWTFMode)) { irecv_close(dfu); return -1; } *mode = (dfu->mode == kWTFMode) ? MODE_WTF : MODE_DFU; irecv_close(dfu); return 0; }
int pois0n_is_ready() { irecv_error_t error = IRECV_E_SUCCESS; ////////////////////////////////////// // Begin // debug("Connecting to device\n"); error = irecv_open(&client, device->chip_id); if (error != IRECV_E_SUCCESS) { debug("Device must be in DFU mode to continue\n"); return -1; } irecv_event_subscribe(client, IRECV_PROGRESS, &recovery_callback, NULL); ////////////////////////////////////// // Check device // debug("Checking the device mode\n"); if (client->mode != kDfuMode) { error("Device must be in DFU mode to continue\n"); irecv_close(client); return -1; } return 0; }
int dfu_open_with_timeout(struct idevicerestore_client_t* client, uint32_t timeout) { int i = 0; irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR; for (i = 1; i <= timeout; i++) { recovery_error = irecv_open(&recovery); if (recovery_error == IRECV_E_SUCCESS) { break; } if (i == timeout) { error("ERROR: Unable to connect to device in DFU mode\n"); return -1; } sleep(1); debug("Retrying connection...\n"); } irecv_event_subscribe(recovery, IRECV_PROGRESS, &dfu_progress_callback, NULL); client->dfu->client = recovery; return 0; }
int main(int argc, char* argv[]) { int i = 0; int opt = 0; int action = 0; char* argument = NULL; irecv_error_t error = 0; if (argc == 1) print_usage(); while ((opt = getopt(argc, argv, "vhrsc:f:e:k::")) > 0) { switch (opt) { case 'v': verbose += 1; break; case 'h': print_usage(); break; case 'r': action = kResetDevice; break; case 's': action = kStartShell; break; case 'f': action = kSendFile; argument = optarg; break; case 'c': action = kSendCommand; argument = optarg; break; case 'k': action = kSendExploit; argument = optarg; break; case 'e': action = kSendScript; argument = optarg; break; default: fprintf(stderr, "Unknown argument\n"); return -1; } } if (verbose) irecv_set_debug_level(verbose); irecv_init(); irecv_client_t client = NULL; for (i = 0; i <= 5; i++) { debug("Attempting to connect... \n"); if (irecv_open(&client) != IRECV_E_SUCCESS) sleep(1); else break; if (i == 5) { return -1; } } switch (action) { case kResetDevice: irecv_reset(client); break; case kSendFile: irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); error = irecv_send_file(client, argument, 1); debug("%s\n", irecv_strerror(error)); break; case kSendCommand: error = irecv_send_command(client, argument); debug("%s\n", irecv_strerror(error)); break; case kSendExploit: if (argument != NULL) { irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); error = irecv_send_file(client, argument, 0); if (error != IRECV_E_SUCCESS) { debug("%s\n", irecv_strerror(error)); break; } } error = irecv_send_exploit(client); debug("%s\n", irecv_strerror(error)); break; case kStartShell: init_shell(client); break; case kSendScript: error = irecv_execute_script(client, argument); if(error != IRECV_E_SUCCESS) { debug("%s\n", irecv_strerror(error)); } break; default: fprintf(stderr, "Unknown action\n"); break; } irecv_close(client); return 0; }