summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-05-20 20:45:27 -0400
committerGravatar Joshua Hill2010-05-20 20:45:27 -0400
commitbb587b216f9e50918491b1edcafc298452026a2b (patch)
treecf342b597984d7d7722fab0e6788c6fe482575f2
parent332faac3f152e14fb43351e82e3be034e72b73b3 (diff)
downloadidevicerestore-bb587b216f9e50918491b1edcafc298452026a2b.tar.gz
idevicerestore-bb587b216f9e50918491b1edcafc298452026a2b.tar.bz2
Added support to detect device and which mode it's in, and linking for libirecovery
-rw-r--r--TODO1
-rw-r--r--src/Makefile.am9
-rw-r--r--src/idevicerestore.c79
-rw-r--r--src/tss.c2
4 files changed, 81 insertions, 10 deletions
diff --git a/TODO b/TODO
index 099ffe0..8ca8d4f 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,6 @@
+ Unzip IPSW
* Parse BuildManifest.plist
+* Build TSS request
* Submit TSS request to apple
* Stitch new signatures onto firmware
* Connect to iBoot
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");
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;
}