summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2012-07-17 15:44:10 +0200
committerGravatar Nikias Bassen2012-07-17 15:44:10 +0200
commitfefa8515c620771d0c76fe41cabfef77c1b439bb (patch)
tree431077485b25295776b2910f071baa2f3eec3b8c
parentc4d1da0e7148f35bd2b3a95920aa9ea426dfbd1e (diff)
downloadidevicerestore-fefa8515c620771d0c76fe41cabfef77c1b439bb.tar.gz
idevicerestore-fefa8515c620771d0c76fe41cabfef77c1b439bb.tar.bz2
Support restoring passcode locked devices from normal mode
-rw-r--r--src/normal.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/normal.c b/src/normal.c
index 21a51c7..fa5c9a5 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -223,16 +223,48 @@ int normal_check_device(struct idevicerestore_client_t* client) {
}
lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore");
+ if (lockdown_error == LOCKDOWN_E_PASSWORD_PROTECTED) {
+ lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore");
+ } else if (lockdown_error == LOCKDOWN_E_INVALID_HOST_ID) {
+ char* udid = NULL;
+ lockdownd_unpair(lockdown, NULL);
+ idevice_get_udid(device, &udid);
+ if (udid) {
+ userpref_remove_device_public_key(udid);
+ }
+ lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore");
+ }
if (lockdown_error != LOCKDOWN_E_SUCCESS) {
idevice_free(device);
return -1;
}
- lockdown_error = lockdownd_get_value(lockdown, NULL, "ProductType", &product_type_node);
- if (lockdown_error != LOCKDOWN_E_SUCCESS) {
- lockdownd_client_free(lockdown);
- idevice_free(device);
- return -1;
+ plist_t pval = NULL;
+ lockdownd_get_value(lockdown, NULL, "HardwareModel", &pval);
+ if (pval && (plist_get_node_type(pval) == PLIST_STRING)) {
+ char* strval = NULL;
+ plist_get_string_val(pval, &strval);
+ if (strval) {
+ for (i = 0; irecv_devices[i].model != NULL; i++) {
+ if (!strcasecmp(strval, irecv_devices[i].model)) {
+ product_type = (char*)irecv_devices[i].product;
+ break;
+ }
+ }
+ free(strval);
+ }
+ }
+ if (pval) {
+ plist_free(pval);
+ }
+
+ if (product_type == NULL) {
+ lockdown_error = lockdownd_get_value(lockdown, NULL, "ProductType", &product_type_node);
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
}
lockdownd_client_free(lockdown);
@@ -240,16 +272,18 @@ int normal_check_device(struct idevicerestore_client_t* client) {
lockdown = NULL;
device = NULL;
- if (!product_type_node || plist_get_node_type(product_type_node) != PLIST_STRING) {
- if (product_type_node)
- plist_free(product_type_node);
- return -1;
+ if (product_type_node != NULL) {
+ if (!product_type_node || plist_get_node_type(product_type_node) != PLIST_STRING) {
+ if (product_type_node)
+ plist_free(product_type_node);
+ return -1;
+ }
+ plist_get_string_val(product_type_node, &product_type);
+ plist_free(product_type_node);
}
- plist_get_string_val(product_type_node, &product_type);
- plist_free(product_type_node);
for (i = 0; irecv_devices[i].product != NULL; i++) {
- if (!strcmp(product_type, irecv_devices[i].product)) {
+ if (!strcasecmp(product_type, irecv_devices[i].product)) {
break;
}
}
@@ -321,7 +355,7 @@ int normal_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) {
return -1;
}
- lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore");
+ lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore");
if (lockdown_error != LOCKDOWN_E_SUCCESS) {
error("ERROR: Unable to connect to lockdownd\n");
idevice_free(device);