diff options
author | Martin Szulecki | 2009-08-01 18:54:59 +0200 |
---|---|---|
committer | Martin Szulecki | 2009-08-01 18:54:59 +0200 |
commit | 5844d66be35d300ffb47dd03917a921900963fd5 (patch) | |
tree | d69b94d19b656a7ae6f630d064da0fcfaad85b35 /dev | |
parent | 14868dc30c7e59f9838a6b67e2e15673f0f1557b (diff) | |
download | libimobiledevice-5844d66be35d300ffb47dd03917a921900963fd5.tar.gz libimobiledevice-5844d66be35d300ffb47dd03917a921900963fd5.tar.bz2 |
Add new iphoneenterrecovery dev tool to make a device enter recovery mode
Diffstat (limited to 'dev')
-rw-r--r-- | dev/Makefile.am | 7 | ||||
-rw-r--r-- | dev/iphoneenterrecovery.c | 94 |
2 files changed, 100 insertions, 1 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am index 70cd52b..c41b663 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) -noinst_PROGRAMS = iphoneclient lckd-client afccheck msyncclient +noinst_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneenterrecovery iphoneclient_SOURCES = iphoneclient.c iphoneclient_LDADD = ../src/libiphone.la @@ -22,3 +22,8 @@ msyncclient_SOURCES = msyncclient.c msyncclient_CFLAGS = $(AM_CFLAGS) msyncclient_LDFLAGS = $(AM_LDFLAGS) msyncclient_LDADD = ../src/libiphone.la + +iphoneenterrecovery_SOURCES = iphoneenterrecovery.c +iphoneenterrecovery_CFLAGS = $(AM_CFLAGS) +iphoneenterrecovery_LDFLAGS = $(AM_LDFLAGS) +iphoneenterrecovery_LDADD = ../src/libiphone.la diff --git a/dev/iphoneenterrecovery.c b/dev/iphoneenterrecovery.c new file mode 100644 index 0000000..2f7891c --- /dev/null +++ b/dev/iphoneenterrecovery.c @@ -0,0 +1,94 @@ +/* + * iphoneenterrecovery.c + * Simple utility to make a device in normal mode enter recovery mode. + * + * Copyright (c) 2009 Martin Szulecki All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +#include <libiphone/libiphone.h> +#include <libiphone/lockdown.h> + +static void print_usage(int argc, char **argv) +{ + char *name = NULL; + + name = strrchr(argv[0], '/'); + printf("Usage: %s [OPTIONS] UUID\n", (name ? name + 1: argv[0])); + printf("Makes a device with the supplied 40-digit UUID enter recovery mode immediately.\n\n"); + printf(" -d, --debug\t\tenable communication debugging\n"); + printf(" -h, --help\t\tprints usage information\n"); + printf("\n"); +} + +int main(int argc, char *argv[]) +{ + lockdownd_client_t client = NULL; + iphone_device_t phone = NULL; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + int i; + char uuid[41]; + uuid[0] = 0; + + /* parse cmdline args */ + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { + iphone_set_debug_mask(DBGMASK_ALL); + iphone_set_debug_level(1); + continue; + } + else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + print_usage(argc, argv); + return 0; + } + } + + i--; + if (!argv[i] || (strlen(argv[i]) != 40)) { + print_usage(argc, argv); + return 0; + } + strcpy(uuid, argv[i]); + + ret = iphone_get_device_by_uuid(&phone, uuid); + if (ret != IPHONE_E_SUCCESS) { + printf("No device found with uuid %s, is it plugged in?\n", uuid); + return -1; + } + + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { + iphone_device_free(phone); + return -1; + } + + /* run query and output information */ + printf("Telling device with uuid %s to enter recovery mode.}\n", uuid); + if(lockdownd_enter_recovery(client) != LOCKDOWN_E_SUCCESS) + { + printf("Failed to enter recovery mode.\n"); + } + printf("Device is successfully switching to recovery mode.\n"); + + lockdownd_client_free(client); + iphone_device_free(phone); + + return 0; +} |