From bb587b216f9e50918491b1edcafc298452026a2b Mon Sep 17 00:00:00 2001 From: Joshua Hill Date: Thu, 20 May 2010 20:45:27 -0400 Subject: Added support to detect device and which mode it's in, and linking for libirecovery --- src/Makefile.am | 9 ++++-- src/idevicerestore.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++------ src/tss.c | 2 ++ 3 files changed, 80 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b997ca6..b876ecc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,15 +1,20 @@ +libirecovery_CFLAGS = -I/usr/local/include +libirecovery_LIBS = -L/usr/local/lib -lirecovery -lusb-1.0 + AM_CFLAGS = \ $(GLOBAL_CFLAGS) \ $(libimobiledevice_CFLAGS) \ $(libplist_CFLAGS) \ $(libzip_CFLAGS) \ - $(libcurl_CFLAGS) + $(libcurl_CFLAGS) \ + $(libirecovery_CFLAGS) AM_LDFLAGS =\ $(libimobiledevice_LIBS) \ $(libplist_LIBS) \ $(libzip_LIBS) \ - $(libcurl_LIBS) + $(libcurl_LIBS) \ + $(libirecovery_LIBS) bin_PROGRAMS = idevicerestore diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 51c74d0..4c504e0 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -24,13 +24,19 @@ #include #include #include +#include +#include +#include #include "ipsw.h" #define error(...) fprintf(stderr, __VA_ARGS__) -#define info(...) if(verbose >= 2) fprintf(stderr, __VA_ARGS__) -#define warn(...) if(verbose >= 1) fprintf(stderr, __VA_ARGS__) -#define debug(...) if(verbose >= 3) fprintf(stderr, __VA_ARGS__) +#define info(...) if(verbose >= 1) fprintf(stderr, __VA_ARGS__) +#define debug(...) if(verbose >= 2) fprintf(stderr, __VA_ARGS__) + +#define UNKNOWN_MODE 0 +#define RECOVERY_MODE 1 +#define NORMAL_MODE 2 static int verbose = 0; @@ -38,8 +44,10 @@ void usage(int argc, char* argv[]); int main(int argc, char* argv[]) { int opt = 0; + int mode = 0; char* ipsw = NULL; - while ((opt = getopt(argc, argv, "vhi:")) > 0) { + char* uuid = NULL; + while ((opt = getopt(argc, argv, "vdhi:u:")) > 0) { switch (opt) { case 'h': usage(argc, argv); @@ -49,10 +57,18 @@ int main(int argc, char* argv[]) { verbose += 1; break; + case 'd': + verbose = 3; + break; + case 'i': ipsw = optarg; break; + case 'u': + uuid = optarg; + break; + default: usage(argc, argv); break; @@ -64,7 +80,53 @@ int main(int argc, char* argv[]) { return -1; } - debug("Extracting BuildManifest.plist from IPSW\n"); + idevice_t device = NULL; + irecv_device_t* recovery = NULL; + irecv_error_t recovery_error = IRECV_SUCCESS; + idevice_error_t device_error = IDEVICE_E_SUCCESS; + info("Checking for device in normal mode\n"); + if(uuid != NULL) { + device_error = idevice_new(&device, uuid); + if(device_error != IDEVICE_E_SUCCESS) { + info("Unable to find device in normal mode\n"); + recovery = irecv_init(); + recovery_error = irecv_open(recovery, uuid); + if(recovery_error != IRECV_SUCCESS) { + info("Unable to find device in recovery mode\n"); + error("ERROR: Unable to find device, is it plugged in?\n"); + irecv_exit(recovery); + return -1; + } + info("Found device in recovery mode\n"); + mode = RECOVERY_MODE; + + } else { + info("Found device in normal mode\n"); + mode = NORMAL_MODE; + } + + } else { + device_error = idevice_new(&device, NULL); + if(device_error != IDEVICE_E_SUCCESS) { + info("Unable to find device in normal mode\n"); + recovery = irecv_init(); + recovery_error = irecv_open(recovery, NULL); + if(recovery_error != IRECV_SUCCESS) { + info("Unable to find device in recovery mode\n"); + error("ERROR: Unable to find device, is it plugged in?\n"); + irecv_exit(recovery); + return -1; + } + info("Found device in recovery mode\n"); + mode = RECOVERY_MODE; + + } else { + info("Found device in normal mode\n"); + mode = NORMAL_MODE; + } + } + + info("Extracting BuildManifest.plist from IPSW\n"); ipsw_archive* archive = ipsw_open(ipsw); ipsw_file* buildmanifest = ipsw_extract_file(archive, "BuildManifest.plist"); if(buildmanifest == NULL) { @@ -78,9 +140,9 @@ int main(int argc, char* argv[]) { ipsw_free_file(buildmanifest); ipsw_close(archive); - debug("Creating TSS request\n"); + info("Creating TSS request\n"); plist_t tss_request = tss_create_request(manifest); - if(tss_request != NULL) { + if(tss_request == NULL) { error("ERROR: Unable to create TSS request\n"); plist_free(manifest); return -1; @@ -95,7 +157,8 @@ void usage(int argc, char* argv[]) { printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); printf("Restore firmware and filesystem to iPhone/iPod Touch.\n"); printf(" -d, \t\tenable communication debugging\n"); - printf(" -r, \t\tput device into recovery mode\n"); + printf(" -v, \t\tenable incremental levels of verboseness\n"); + //printf(" -r, \t\tput device into recovery mode\n"); printf(" -i, \t\ttarget filesystem to install onto device\n"); printf(" -u, \t\ttarget specific device by its 40-digit device UUID\n"); printf(" -h, \t\tprints usage information\n"); diff --git a/src/tss.c b/src/tss.c index c557604..a854bc9 100644 --- a/src/tss.c +++ b/src/tss.c @@ -72,5 +72,7 @@ plist_t tss_create_request(plist_t buildmanifest) { plist_get_string_val(security_domain_node, &security_domain_string); sscanf(security_domain_string, "%x", &security_domain); + + return NULL; } -- cgit v1.1-32-gdbae