diff options
Diffstat (limited to 'tools/ideviceenterrecovery.c')
| -rw-r--r-- | tools/ideviceenterrecovery.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/ideviceenterrecovery.c b/tools/ideviceenterrecovery.c new file mode 100644 index 0000000..a5cc48a --- /dev/null +++ b/tools/ideviceenterrecovery.c | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | /* | ||
| 2 | * ideviceenterrecovery.c | ||
| 3 | * Simple utility to make a device in normal mode enter recovery mode. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Martin Szulecki All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <errno.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | |||
| 27 | #include <libimobiledevice/libimobiledevice.h> | ||
| 28 | #include <libimobiledevice/lockdown.h> | ||
| 29 | |||
| 30 | static void print_usage(int argc, char **argv) | ||
| 31 | { | ||
| 32 | char *name = NULL; | ||
| 33 | |||
| 34 | name = strrchr(argv[0], '/'); | ||
| 35 | printf("Usage: %s [OPTIONS] UUID\n", (name ? name + 1: argv[0])); | ||
| 36 | printf("Makes a device with the supplied 40-digit UUID enter recovery mode immediately.\n\n"); | ||
| 37 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
| 38 | printf(" -h, --help\t\tprints usage information\n"); | ||
| 39 | printf("\n"); | ||
| 40 | } | ||
| 41 | |||
| 42 | int main(int argc, char *argv[]) | ||
| 43 | { | ||
| 44 | lockdownd_client_t client = NULL; | ||
| 45 | idevice_t phone = NULL; | ||
| 46 | idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; | ||
| 47 | int i; | ||
| 48 | char uuid[41]; | ||
| 49 | uuid[0] = 0; | ||
| 50 | |||
| 51 | /* parse cmdline args */ | ||
| 52 | for (i = 1; i < argc; i++) { | ||
| 53 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | ||
| 54 | idevice_set_debug_level(1); | ||
| 55 | continue; | ||
| 56 | } | ||
| 57 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | ||
| 58 | print_usage(argc, argv); | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | i--; | ||
| 64 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 65 | print_usage(argc, argv); | ||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | strcpy(uuid, argv[i]); | ||
| 69 | |||
| 70 | ret = idevice_new(&phone, uuid); | ||
| 71 | if (ret != IDEVICE_E_SUCCESS) { | ||
| 72 | printf("No device found with uuid %s, is it plugged in?\n", uuid); | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "ideviceenterrecovery")) { | ||
| 77 | idevice_free(phone); | ||
| 78 | return -1; | ||
| 79 | } | ||
| 80 | |||
| 81 | /* run query and output information */ | ||
| 82 | printf("Telling device with uuid %s to enter recovery mode.}\n", uuid); | ||
| 83 | if(lockdownd_enter_recovery(client) != LOCKDOWN_E_SUCCESS) | ||
| 84 | { | ||
| 85 | printf("Failed to enter recovery mode.\n"); | ||
| 86 | } | ||
| 87 | printf("Device is successfully switching to recovery mode.\n"); | ||
| 88 | |||
| 89 | lockdownd_client_free(client); | ||
| 90 | idevice_free(phone); | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
