summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/recovery.c38
-rw-r--r--src/restore.c131
2 files changed, 76 insertions, 93 deletions
diff --git a/src/recovery.c b/src/recovery.c
index 91c43f3..5930db6 100644
--- a/src/recovery.c
+++ b/src/recovery.c
@@ -172,16 +172,14 @@ int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build
char* value = NULL;
irecv_getenv(client->recovery->client, "build-version", &value);
info("iBoot build-version=%s\n", (value) ? value : "(unknown)");
- if (value) {
- free(value);
- value = NULL;
- }
+ free(value);
+ value = NULL;
+
irecv_getenv(client->recovery->client, "build-style", &value);
info("iBoot build-style=%s\n", (value) ? value : "(unknown)");
- if (value) {
- free(value);
- value = NULL;
- }
+ free(value);
+ value = NULL;
+
unsigned long radio_error = 0;
irecv_getenv(client->recovery->client, "radio-error", &value);
if (value) {
@@ -242,12 +240,11 @@ int recovery_send_ticket(struct idevicerestore_client_t* client)
info("Sending APTicket (%d bytes)\n", size);
irecv_error_t err = irecv_send_buffer(client->recovery->client, data, size, 0);
+ free(data);
if (err != IRECV_E_SUCCESS) {
error("ERROR: Unable to send APTicket: %s\n", irecv_strerror(err));
- free(data);
return -1;
}
- free(data);
err = irecv_send_command(client->recovery->client, "ticket");
if (err != IRECV_E_SUCCESS) {
@@ -272,42 +269,37 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil
if (!path) {
if (build_identity_get_component_path(build_identity, component, &path) < 0) {
error("ERROR: Unable to get path for component '%s'\n", component);
- if (path)
- free(path);
+ free(path);
return -1;
}
}
unsigned char* component_data = NULL;
unsigned int component_size = 0;
-
- if (extract_component(client->ipsw, path, &component_data, &component_size) < 0) {
+ int ret = extract_component(client->ipsw, path, &component_data, &component_size);
+ free(path);
+ if (ret < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(path);
return -1;
}
- if (personalize_component(component, component_data, component_size, client->tss, &data, &size) < 0) {
+ ret = personalize_component(component, component_data, component_size, client->tss, &data, &size);
+ free(component_data);
+ if (ret < 0) {
error("ERROR: Unable to get personalized component: %s\n", component);
- free(component_data);
- free(path);
return -1;
}
- free(component_data);
- component_data = NULL;
info("Sending %s (%d bytes)...\n", component, size);
// FIXME: Did I do this right????
err = irecv_send_buffer(client->recovery->client, data, size, 0);
- free(path);
+ free(data);
if (err != IRECV_E_SUCCESS) {
error("ERROR: Unable to send %s component: %s\n", component, irecv_strerror(err));
- free(data);
return -1;
}
- free(data);
return 0;
}
diff --git a/src/restore.c b/src/restore.c
index 9775562..79e1828 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -80,23 +80,21 @@ int restore_client_new(struct idevicerestore_client_t* client) {
}
void restore_client_free(struct idevicerestore_client_t* client) {
- if (client) {
- if(client->restore) {
- if(client->restore->client) {
- restored_client_free(client->restore->client);
- client->restore->client = NULL;
- }
- if(client->restore->device) {
- idevice_free(client->restore->device);
- client->restore->device = NULL;
- }
- if(client->restore->bbtss) {
- plist_free(client->restore->bbtss);
- client->restore->bbtss = NULL;
- }
- free(client->restore);
- client->restore = NULL;
+ if (client && client->restore) {
+ if(client->restore->client) {
+ restored_client_free(client->restore->client);
+ client->restore->client = NULL;
}
+ if(client->restore->device) {
+ idevice_free(client->restore->device);
+ client->restore->device = NULL;
+ }
+ if(client->restore->bbtss) {
+ plist_free(client->restore->bbtss);
+ client->restore->bbtss = NULL;
+ }
+ free(client->restore);
+ client->restore = NULL;
}
}
@@ -781,8 +779,7 @@ int restore_send_kernelcache(restored_client_t restore, struct idevicerestore_cl
if (!path) {
if (build_identity_get_component_path(build_identity, "KernelCache", &path) < 0) {
error("ERROR: Unable to find kernelcache path\n");
- if (path)
- free(path);
+ free(path);
return -1;
}
}
@@ -790,37 +787,36 @@ int restore_send_kernelcache(restored_client_t restore, struct idevicerestore_cl
const char* component = "KernelCache";
unsigned char* component_data = NULL;
unsigned int component_size = 0;
-
- if (extract_component(client->ipsw, path, &component_data, &component_size) < 0) {
+ int ret = extract_component(client->ipsw, path, &component_data, &component_size);
+ free(path);
+ path = NULL;
+ if (ret < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(path);
return -1;
}
- if (personalize_component(component, component_data, component_size, client->tss, &data, &size) < 0) {
+ ret = personalize_component(component, component_data, component_size, client->tss, &data, &size);
+ free(component_data);
+ component_data = NULL;
+ if (ret < 0) {
error("ERROR: Unable to get personalized component: %s\n", component);
- free(component_data);
- free(path);
return -1;
}
- free(component_data);
- component_data = NULL;
dict = plist_new_dict();
blob = plist_new_data((char*)data, size);
plist_dict_set_item(dict, "KernelCacheFile", blob);
+ free(data);
info("Sending KernelCache now...\n");
restore_error = restored_send(restore, dict);
+ plist_free(dict);
if (restore_error != RESTORE_E_SUCCESS) {
error("ERROR: Unable to send kernelcache data\n");
- plist_free(dict);
return -1;
}
info("Done sending KernelCache\n");
- plist_free(dict);
- free(data);
return 0;
}
@@ -841,7 +837,6 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
unsigned int nor_size = 0;
unsigned char* nor_data = NULL;
plist_t norimage_array = NULL;
- restored_error_t ret = RESTORE_E_SUCCESS;
info("About to send NORData...\n");
@@ -853,8 +848,7 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
if (llb_path == NULL) {
if (build_identity_get_component_path(build_identity, "LLB", &llb_path) < 0) {
error("ERROR: Unable to get component path for LLB\n");
- if (llb_path)
- free(llb_path);
+ free(llb_path);
return -1;
}
}
@@ -883,27 +877,25 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
const char* component = "LLB";
unsigned char* component_data = NULL;
unsigned int component_size = 0;
-
- if (extract_component(client->ipsw, llb_path, &component_data, &component_size) < 0) {
+ int ret = extract_component(client->ipsw, llb_path, &component_data, &component_size);
+ free(llb_path);
+ if (ret < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(llb_path);
return -1;
}
- if (personalize_component(component, component_data, component_size, client->tss, &llb_data, &llb_size) < 0) {
- error("ERROR: Unable to get personalized component: %s\n", component);
- free(component_data);
- free(llb_path);
- return -1;
- }
+ ret = personalize_component(component, component_data, component_size, client->tss, &llb_data, &llb_size);
free(component_data);
component_data = NULL;
component_size = 0;
+ if (ret < 0) {
+ error("ERROR: Unable to get personalized component: %s\n", component);
+ return -1;
+ }
dict = plist_new_dict();
plist_dict_set_item(dict, "LlbImageData", plist_new_data((char*)llb_data, (uint64_t) llb_size));
- if (llb_data)
- free(llb_data);
+ free(llb_data);
norimage_array = plist_new_array();
@@ -923,14 +915,12 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
if (extract_component(client->ipsw, firmware_filename, &component_data, &component_size) < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(llb_path);
return -1;
}
if (personalize_component(component, component_data, component_size, client->tss, &nor_data, &nor_size) < 0) {
error("ERROR: Unable to get personalized component: %s\n", component);
free(component_data);
- free(llb_path);
return -1;
}
free(component_data);
@@ -954,23 +944,24 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
unsigned char* personalized_data = NULL;
unsigned int personalized_size = 0;
- if (!build_identity_has_component(build_identity, "RestoreSEP") && build_identity_get_component_path(build_identity, "RestoreSEP", &restore_sep_path) == 0) {
+ if (!build_identity_has_component(build_identity, "RestoreSEP") &&
+ build_identity_get_component_path(build_identity, "RestoreSEP", &restore_sep_path) == 0) {
component = "RestoreSEP";
- if (extract_component(client->ipsw, restore_sep_path, &component_data, &component_size) < 0) {
+ ret = extract_component(client->ipsw, restore_sep_path, &component_data, &component_size);
+ free(restore_sep_path);
+ if (ret < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(restore_sep_path);
return -1;
}
- if (personalize_component(component, component_data, component_size, client->tss, &personalized_data, &personalized_size) < 0) {
- error("ERROR: Unable to get personalized component: %s\n", component);
- free(component_data);
- free(restore_sep_path);
- return -1;
- }
+ ret = personalize_component(component, component_data, component_size, client->tss, &personalized_data, &personalized_size);
free(component_data);
component_data = NULL;
component_size = 0;
+ if (ret < 0) {
+ error("ERROR: Unable to get personalized component: %s\n", component);
+ return -1;
+ }
plist_dict_set_item(dict, "RestoreSEPImageData", plist_new_data((char*)personalized_data, (uint64_t) personalized_size));
free(personalized_data);
@@ -978,23 +969,24 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
personalized_size = 0;
}
- if (!build_identity_has_component(build_identity, "SEP") && build_identity_get_component_path(build_identity, "SEP", &sep_path) == 0) {
+ if (!build_identity_has_component(build_identity, "SEP") &&
+ build_identity_get_component_path(build_identity, "SEP", &sep_path) == 0) {
component = "SEP";
- if (extract_component(client->ipsw, sep_path, &component_data, &component_size) < 0) {
+ ret = extract_component(client->ipsw, sep_path, &component_data, &component_size);
+ free(sep_path);
+ if (ret < 0) {
error("ERROR: Unable to extract component: %s\n", component);
- free(sep_path);
return -1;
}
- if (personalize_component(component, component_data, component_size, client->tss, &personalized_data, &personalized_size) < 0) {
- error("ERROR: Unable to get personalized component: %s\n", component);
- free(component_data);
- free(sep_path);
- return -1;
- }
+ ret = personalize_component(component, component_data, component_size, client->tss, &personalized_data, &personalized_size);
free(component_data);
component_data = NULL;
component_size = 0;
+ if (ret < 0) {
+ error("ERROR: Unable to get personalized component: %s\n", component);
+ return -1;
+ }
plist_dict_set_item(dict, "SEPImageData", plist_new_data((char*)personalized_data, (uint64_t) personalized_size));
free(personalized_data);
@@ -1006,8 +998,7 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
debug_plist(dict);
info("Sending NORData now...\n");
- ret = restored_send(restore, dict);
- if (ret != RESTORE_E_SUCCESS) {
+ if (restored_send(restore, dict) != RESTORE_E_SUCCESS) {
error("ERROR: Unable to send NORImageData data\n");
plist_free(dict);
return -1;
@@ -1919,11 +1910,11 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit
debug_plist(message);
}
- if (type)
- free(type);
-
- plist_free(message);
- message = NULL;
+ free(type);
+ if (message) {
+ plist_free(message);
+ message = NULL;
+ }
}
restore_client_free(client);