diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/idevicerestore.c | 79 | ||||
-rw-r--r-- | src/tss.c | 2 |
3 files changed, 80 insertions, 10 deletions
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 <string.h> #include <unistd.h> #include <plist/plist.h> +#include <libirecovery.h> +#include <libimobiledevice/lockdown.h> +#include <libimobiledevice/libimobiledevice.h> #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"); @@ -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; } |