summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-06-21 03:47:54 -0400
committerGravatar Joshua Hill2010-06-21 03:59:31 -0400
commit930f4b350474435e011b9dca18424dd1c42ea353 (patch)
tree68b5631b4877710b9aa39e4aa68cbc538bf5d324 /src
parent24afafe06f902bfd9f5652beb8797f24033c68bc (diff)
downloadidevicerestore-930f4b350474435e011b9dca18424dd1c42ea353.tar.gz
idevicerestore-930f4b350474435e011b9dca18424dd1c42ea353.tar.bz2
Finally fixed the out of control problem
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/common.c2
-rw-r--r--src/common.h4
-rw-r--r--src/dfu.c29
-rw-r--r--src/idevicerestore.c23
-rw-r--r--src/idevicerestore.h1
-rw-r--r--src/img3.c1
-rw-r--r--src/normal.c100
-rw-r--r--src/normal.h4
-rw-r--r--src/recovery.c197
-rw-r--r--src/recovery.h26
-rw-r--r--src/restore.c6
12 files changed, 221 insertions, 174 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a44640f..009f2dd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,6 @@ AM_LDFLAGS =\
bin_PROGRAMS = idevicerestore
-idevicerestore_SOURCES = idevicerestore.c dfu.c asr.c tss.c img3.c ipsw.c normal.c restore.c recovery.c activate.c
+idevicerestore_SOURCES = idevicerestore.c common.c tss.c img3.c ipsw.c normal.c dfu.c recovery.c restore.c asr.c activate.c
idevicerestore_CFLAGS = $(AM_CFLAGS)
idevicerestore_LDFLAGS = $(AM_LDFLAGS) \ No newline at end of file
diff --git a/src/common.c b/src/common.c
index 07a7075..8e76697 100644
--- a/src/common.c
+++ b/src/common.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdio.h>
+
#include "common.h"
int idevicerestore_debug = 0;
diff --git a/src/common.h b/src/common.h
index cb774a5..50f682f 100644
--- a/src/common.h
+++ b/src/common.h
@@ -22,12 +22,12 @@
#ifndef IDEVICERESTORE_COMMON_H
#define IDEVICERESTORE_COMMON_H
-#include <plist/plist.h>
-
#ifdef __cplusplus
extern "C" {
#endif
+#include <plist/plist.h>
+
#define info(...) printf(__VA_ARGS__)
#define error(...) fprintf(stderr, __VA_ARGS__)
#define debug(...) if(idevicerestore_debug) fprintf(stderr, __VA_ARGS__)
diff --git a/src/dfu.c b/src/dfu.c
index b53803e..6fd2648 100644
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -24,7 +24,7 @@
#include <libirecovery.h>
#include "dfu.h"
-//#include "recovery.h"
+#include "recovery.h"
#include "idevicerestore.h"
int dfu_progress_callback(irecv_client_t client, const irecv_event_t* event) {
@@ -100,46 +100,51 @@ int dfu_open_with_timeout(struct idevicerestore_client_t* client, uint32_t timeo
}
irecv_event_subscribe(recovery, IRECV_PROGRESS, &dfu_progress_callback, NULL);
- client->dfu = recovery;
+ client->dfu->client = recovery;
return 0;
}
+int dfu_check_mode() {
+ return -1;
+}
+
int dfu_enter_recovery(struct idevicerestore_client_t* client) {
irecv_client_t dfu = NULL;
const char* component = "iBSS";
irecv_error_t dfu_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&dfu) < 0 || dfu->mode != kDfuMode) {
+ if (recovery_open_with_timeout(client) < 0 || dfu->mode != kDfuMode) {
error("ERROR: Unable to connect to DFU device\n");
if (dfu)
irecv_close(dfu);
return -1;
}
- if (recovery_send_signed_component(dfu, client->ipsw, client->tss, "iBSS") < 0) {
+ if (recovery_send_signed_component(client, "iBSS") < 0) {
error("ERROR: Unable to send %s to device\n", component);
irecv_close(dfu);
return -1;
}
- dfu_error = irecv_reset(dfu);
+ dfu_error = irecv_reset(client->dfu->client);
if (dfu_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to reset device\n");
irecv_close(dfu);
return -1;
}
- irecv_close(dfu);
- dfu = NULL;
+ irecv_close(client->dfu->client);
+ client->dfu->client = NULL;
// Reconnect to device, but this time make sure we're not still in DFU mode
- if (recovery_open_with_timeout(&dfu) < 0 || dfu->mode == kDfuMode) {
+ if (recovery_open_with_timeout(client) < 0 || client->mode->index != kDfuMode) {
error("ERROR: Unable to connect to recovery device\n");
- if (dfu)
- irecv_close(dfu);
+ if (client->dfu->client)
+ irecv_close(client->dfu->client);
return -1;
}
client->mode = &idevicerestore_modes[MODE_RECOVERY];
- irecv_close(dfu);
- dfu = NULL;
+ irecv_close(client->dfu->client);
+ client->dfu->client = NULL;
return 0;
}
+
diff --git a/src/idevicerestore.c b/src/idevicerestore.c
index cdbff27..606062c 100644
--- a/src/idevicerestore.c
+++ b/src/idevicerestore.c
@@ -26,15 +26,15 @@
#include <getopt.h>
#include <plist/plist.h>
-#include "idevicerestore.h"
-//#include "recovery.h"
-#include "restore.h"
-#include "common.h"
-#include "normal.h"
-#include "img3.h"
-#include "ipsw.h"
#include "dfu.h"
#include "tss.h"
+#include "img3.h"
+#include "ipsw.h"
+#include "common.h"
+#include "normal.h"
+#include "restore.h"
+#include "recovery.h"
+#include "idevicerestore.h"
static struct option longopts[] = {
{ "uuid", required_argument, NULL, 'u' },
@@ -100,7 +100,6 @@ int main(int argc, char* argv[]) {
return -1;
}
memset(client, '\0', sizeof(struct idevicerestore_client_t));
- idevicerestore = client;
while ((opt = getopt_long(argc, argv, "dhcexu:", longopts, &optindex)) > 0) {
switch (opt) {
@@ -277,7 +276,7 @@ int main(int argc, char* argv[]) {
// if the device is in normal mode, place device into recovery mode
if (client->mode->index == MODE_NORMAL) {
info("Entering recovery mode...\n");
- if (normal_enter_recovery(uuid) < 0) {
+ if (normal_enter_recovery(client) < 0) {
error("ERROR: Unable to place device into recovery mode\n");
if (tss)
plist_free(tss);
@@ -468,7 +467,7 @@ int get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid) {
case MODE_DFU:
case MODE_RECOVERY:
- if (recovery_get_bdid(&client->device->board_id) < 0) {
+ if (recovery_get_bdid(client, &client->device->board_id) < 0) {
client->device->board_id = -1;
return -1;
}
@@ -493,7 +492,7 @@ int get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid) {
case MODE_DFU:
case MODE_RECOVERY:
- if (recovery_get_cpid(&client->device->chip_id) < 0) {
+ if (recovery_get_cpid(client, &client->device->chip_id) < 0) {
client->device->chip_id = -1;
return -1;
}
@@ -523,7 +522,7 @@ int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) {
case MODE_DFU:
case MODE_RECOVERY:
- if (recovery_get_ecid(ecid) < 0) {
+ if (recovery_get_ecid(client, ecid) < 0) {
*ecid = 0;
return -1;
}
diff --git a/src/idevicerestore.h b/src/idevicerestore.h
index 7e5873b..1fadf15 100644
--- a/src/idevicerestore.h
+++ b/src/idevicerestore.h
@@ -29,7 +29,6 @@ extern "C" {
#include <stdint.h>
#include <plist/plist.h>
-#include <plist/plist.h>
#include "common.h"
void usage(int argc, char* argv[]);
diff --git a/src/img3.c b/src/img3.c
index 5c79e54..902bea4 100644
--- a/src/img3.c
+++ b/src/img3.c
@@ -24,6 +24,7 @@
#include <string.h>
#include "img3.h"
+#include "common.h"
#include "idevicerestore.h"
img3_file* img3_parse_file(char* data, int size) {
diff --git a/src/normal.c b/src/normal.c
index 7ae4774..29f3911 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -20,34 +20,43 @@
*/
#include <stdio.h>
-#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include <libirecovery.h>
#include <libimobiledevice/lockdown.h>
#include <libimobiledevice/libimobiledevice.h>
#include "common.h"
#include "normal.h"
-//#include "recovery.h"
+#include "recovery.h"
-int normal_client_new(struct normal_client_t** normal) {
- struct normal_client_t* client = (struct normal_client_t*) malloc(sizeof(struct normal_client_t));
- if (client == NULL) {
- error("ERROR: Out of memory\n");
- return -1;
+static int normal_device_connected = 0;
+
+void normal_device_callback(const idevice_event_t* event, void* userdata) {
+ struct idevicerestore_client_t* client = (struct idevicerestore_client_t*) userdata;
+ if (event->event == IDEVICE_DEVICE_ADD) {
+ normal_device_connected = 1;
+
+ } else if (event->event == IDEVICE_DEVICE_REMOVE) {
+ normal_device_connected = 0;
+ client->flags &= FLAG_QUIT;
}
+}
- if (normal_open_with_timeout(client) < 0) {
- normal_client_free(client);
+int normal_client_new(struct idevicerestore_client_t* client) {
+ struct normal_client_t* normal = (struct normal_client_t*) malloc(sizeof(struct normal_client_t));
+ if (normal == NULL) {
+ error("ERROR: Out of memory\n");
return -1;
}
- if(normal_check_mode(client) < 0) {
+ if (normal_open_with_timeout(client) < 0) {
normal_client_free(client);
return -1;
}
- *normal = client;
- return client;
+ client->normal = normal;
+ return 0;
}
void normal_client_free(struct idevicerestore_client_t* client) {
@@ -101,6 +110,73 @@ int normal_check_mode(const char* uuid) {
return 0;
}
+int normal_open_with_timeout(struct idevicerestore_client_t* client) {
+ int i = 0;
+ int attempts = 10;
+ idevice_t device = NULL;
+ lockdownd_client_t lockdownd = NULL;
+ idevice_error_t device_error = IDEVICE_E_SUCCESS;
+ lockdownd_error_t lockdownd_error = LOCKDOWN_E_SUCCESS;
+
+ // no context exists so bail
+ if(client == NULL) {
+ return -1;
+ }
+
+ // create our normal client if it doesn't yet exist
+ if(client->normal == NULL) {
+ client->normal = (struct normal_client_t*) malloc(sizeof(struct normal_client_t));
+ if(client->normal == NULL) {
+ error("ERROR: Out of memory\n");
+ return -1;
+ }
+ }
+
+ device_error = idevice_event_subscribe(&normal_device_callback, NULL);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ error("ERROR: Unable to subscribe to device events\n");
+ return -1;
+ }
+
+ for (i = 1; i <= attempts; i++) {
+ if (normal_device_connected == 1) {
+ break;
+ }
+
+ if (i == attempts) {
+ error("ERROR: Unable to connect to device in normal mode\n");
+ return -1;
+ }
+
+ sleep(2);
+ }
+
+ device_error = idevice_new(&device, client->uuid);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ return -1;
+ }
+
+ lockdownd_error = lockdownd_client_new(device, &lockdownd, "idevicerestore");
+ if (lockdownd_error != LOCKDOWN_E_SUCCESS) {
+ //idevice_event_unsubscribe();
+ idevice_free(device);
+ return -1;
+ }
+
+ char* type = NULL;
+ lockdownd_error = lockdownd_query_type(lockdownd, &type);
+ if (lockdownd_error != LOCKDOWN_E_SUCCESS) {
+ lockdownd_client_free(lockdownd);
+ //idevice_event_unsubscribe();
+ idevice_free(device);
+ return -1;
+ }
+
+ client->normal->device = device;
+ client->normal->client = lockdownd;
+ return 0;
+}
+
int normal_check_device(const char* uuid) {
int i = 0;
idevice_t device = NULL;
diff --git a/src/normal.h b/src/normal.h
index 352e643..836d495 100644
--- a/src/normal.h
+++ b/src/normal.h
@@ -37,8 +37,12 @@ struct normal_client_t {
plist_t tss;
};
+
int normal_check_mode(const char* uuid);
int normal_check_device(const char* uuid);
+int normal_client_new(struct idevicerestore_client_t* client);
+void normal_client_free(struct idevicerestore_client_t* client);
+int normal_open_with_timeout(struct idevicerestore_client_t* client);
int normal_enter_recovery(const char* uuid);
int normal_get_cpid(const char* uuid, uint32_t* cpid);
int normal_get_bdid(const char* uuid, uint32_t* cpid);
diff --git a/src/recovery.c b/src/recovery.c
index bacfac7..290f368 100644
--- a/src/recovery.c
+++ b/src/recovery.c
@@ -21,7 +21,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <libirecovery.h>
#include <libimobiledevice/restore.h>
#include <libimobiledevice/libimobiledevice.h>
@@ -29,6 +28,7 @@
#include "tss.h"
#include "img3.h"
#include "common.h"
+#include "restore.h"
#include "recovery.h"
#include "idevicerestore.h"
@@ -46,13 +46,8 @@ int recovery_client_new(struct idevicerestore_client_t* client) {
return -1;
}
- if (recovery_open_with_timeout(recovery) < 0) {
- recovery_client_free(recovery);
- return -1;
- }
-
- if(recovery_check_mode(recovery) < 0) {
- recovery_client_free(recovery);
+ if (recovery_open_with_timeout(client) < 0) {
+ recovery_client_free(client);
return -1;
}
@@ -61,16 +56,42 @@ int recovery_client_new(struct idevicerestore_client_t* client) {
}
void recovery_client_free(struct idevicerestore_client_t* client) {
- struct recovery_client_t* recovery = client->recovery;
- if (recovery) {
- if(recovery->client) {
- irecv_close(recovery);
- recovery = NULL;
+ if(client) {
+ if (client->recovery) {
+ if(client->recovery->client) {
+ irecv_close(client->recovery->client);
+ client->recovery->client = NULL;
+ }
+ free(client->recovery);
+ client->recovery = NULL;
+ }
+ }
+}
+
+int recovery_open_with_timeout(struct idevicerestore_client_t* client) {
+ int i = 0;
+ int attempts = 10;
+ irecv_client_t recovery = NULL;
+ irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR;
+
+ for (i = 1; i <= attempts; i++) {
+ recovery_error = irecv_open(&recovery);
+ if (recovery_error == IRECV_E_SUCCESS) {
+ break;
}
- free(recovery);
- client->recovery = NULL;
+ if (i >= attempts) {
+ error("ERROR: Unable to connect to device in recovery mode\n");
+ return -1;
+ }
+
+ sleep(2);
+ debug("Retrying connection...\n");
}
+
+ irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL);
+ client->recovery->client = recovery;
+ return 0;
}
int recovery_check_mode() {
@@ -92,28 +113,28 @@ int recovery_check_mode() {
return 0;
}
-int recovery_enter_restore(const char* uuid, const char* ipsw, plist_t tss) {
+int recovery_enter_restore(struct idevicerestore_client_t* client) {
idevice_t device = NULL;
restored_client_t restore = NULL;
// upload data to make device boot restore mode
- if (recovery_send_ibec(ipsw, tss) < 0) {
+ if (recovery_send_ibec(client) < 0) {
error("ERROR: Unable to send iBEC\n");
return -1;
}
sleep(1);
- if (recovery_send_applelogo(ipsw, tss) < 0) {
+ if (recovery_send_applelogo(client) < 0) {
error("ERROR: Unable to send AppleLogo\n");
return -1;
}
- if (recovery_send_devicetree(ipsw, tss) < 0) {
+ if (recovery_send_devicetree(client) < 0) {
error("ERROR: Unable to send DeviceTree\n");
return -1;
}
- if (recovery_send_ramdisk(ipsw, tss) < 0) {
+ if (recovery_send_ramdisk(client) < 0) {
error("ERROR: Unable to send Ramdisk\n");
return -1;
}
@@ -124,35 +145,35 @@ int recovery_enter_restore(const char* uuid, const char* ipsw, plist_t tss) {
printf("Hit any key to continue...");
getchar();
- if (recovery_send_kernelcache(ipsw, tss) < 0) {
+ if (recovery_send_kernelcache(client) < 0) {
error("ERROR: Unable to send KernelCache\n");
return -1;
}
info("Waiting for device to enter restore mode\n");
- if (restore_open_with_timeout(uuid, &device, &restore) < 0) {
+ if (restore_open_with_timeout(client) < 0) {
error("ERROR: Unable to connect to device in restore mode\n");
return -1;
}
- restore_close(device, restore);
+ restore_client_free(client);
client->mode = &idevicerestore_modes[MODE_RESTORE];
return 0;
}
-int recovery_send_signed_component(struct idevicerestore_client_t client, const char* ipsw, plist_t tss, char* component) {
+int recovery_send_signed_component(struct idevicerestore_client_t* client, const char* component) {
int size = 0;
char* data = NULL;
char* path = NULL;
char* blob = NULL;
irecv_error_t error = 0;
- if (tss_get_entry_path(tss, component, &path) < 0) {
+ if (tss_get_entry_path(client->tss, component, &path) < 0) {
error("ERROR: Unable to get component path\n");
return -1;
}
- if (get_signed_component(client, ipsw, tss, path, &data, &size) < 0) {
+ if (get_signed_component(client, client->ipsw, client->tss, path, &data, &size) < 0) {
error("ERROR: Unable to get signed component: %s\n", component);
free(path);
return -1;
@@ -160,7 +181,7 @@ int recovery_send_signed_component(struct idevicerestore_client_t client, const
free(path);
info("Sending %s...\n", component);
- error = irecv_send_buffer(client, data, size);
+ error = irecv_send_buffer(client->recovery->client, data, size);
if (error != IRECV_E_SUCCESS) {
error("ERROR: Unable to send component: %s\n", component);
free(data);
@@ -171,84 +192,47 @@ int recovery_send_signed_component(struct idevicerestore_client_t client, const
return 0;
}
-int recovery_open_with_timeout(irecv_client_t* client) {
- int i = 0;
- int attempts = 10;
- irecv_client_t recovery = NULL;
- irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR;
-
- for (i = 1; i <= attempts; i++) {
- recovery_error = irecv_open(&recovery);
- if (recovery_error == IRECV_E_SUCCESS) {
- break;
- }
-
- if (i >= attempts) {
- error("ERROR: Unable to connect to device in recovery mode\n");
- return -1;
- }
-
- sleep(2);
- debug("Retrying connection...\n");
- }
-
- irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL);
- *client = recovery;
- return 0;
-}
-
-int recovery_send_ibec(const char* ipsw, plist_t tss) {
- irecv_client_t recovery = NULL;
+int recovery_send_ibec(struct idevicerestore_client_t* client) {
const char* component = "iBEC";
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
- return -1;
- }
-
- recovery_error = irecv_send_command(recovery, "setenv auto-boot true");
+ recovery_error = irecv_send_command(client->recovery->client, "setenv auto-boot true");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to set auto-boot environmental variable\n");
- irecv_close(recovery);
return -1;
}
- recovery_error = irecv_send_command(recovery, "saveenv");
+ recovery_error = irecv_send_command(client->recovery->client, "saveenv");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to save environmental variable\n");
- irecv_close(recovery);
return -1;
}
- if (recovery_send_signed_component(recovery, ipsw, tss, "iBEC") < 0) {
+ if (recovery_send_signed_component(client, "iBEC") < 0) {
error("ERROR: Unable to send %s to device.\n", component);
- irecv_close(recovery);
return -1;
}
- recovery_error = irecv_send_command(recovery, "go");
+ recovery_error = irecv_send_command(client->recovery->client, "go");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to execute %s\n", component);
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_send_applelogo(const char* ipsw, plist_t tss) {
+int recovery_send_applelogo(struct idevicerestore_client_t* client) {
irecv_client_t recovery = NULL;
const char* component = "applelogo";
irecv_error_t recovery_error = IRECV_E_SUCCESS;
info("Sending %s...\n", component);
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- if (recovery_send_signed_component(recovery, ipsw, tss, "AppleLogo") < 0) {
+ if (recovery_send_signed_component(client, "AppleLogo") < 0) {
error("ERROR: Unable to send %s to device.\n", component);
irecv_close(recovery);
return -1;
@@ -273,141 +257,114 @@ int recovery_send_applelogo(const char* ipsw, plist_t tss) {
return 0;
}
-int recovery_send_devicetree(const char* ipsw, plist_t tss) {
- irecv_client_t recovery = NULL;
+int recovery_send_devicetree(struct idevicerestore_client_t* client) {
const char* component = "devicetree";
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- if (recovery_send_signed_component(recovery, ipsw, tss, "RestoreDeviceTree") < 0) {
+ if (recovery_send_signed_component(client, "RestoreDeviceTree") < 0) {
error("ERROR: Unable to send %s to device.\n", component);
- irecv_close(recovery);
return -1;
}
- recovery_error = irecv_send_command(recovery, "devicetree");
+ recovery_error = irecv_send_command(client->recovery->client, "devicetree");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to execute %s\n", component);
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_send_ramdisk(const char* ipsw, plist_t tss) {
+int recovery_send_ramdisk(struct idevicerestore_client_t* client) {
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- irecv_client_t recovery = NULL;
const char *component = "ramdisk";
- recovery_error = recovery_open_with_timeout(&recovery);
+ recovery_error = recovery_open_with_timeout(client);
if (recovery_error != IRECV_E_SUCCESS) {
return -1;
}
- if (recovery_send_signed_component(recovery, ipsw, tss, "RestoreRamDisk") < 0) {
+ if (recovery_send_signed_component(client, "RestoreRamDisk") < 0) {
error("ERROR: Unable to send %s to device.\n", component);
- irecv_close(recovery);
return -1;
}
- recovery_error = irecv_send_command(recovery, "ramdisk");
+ recovery_error = irecv_send_command(client->recovery->client, "ramdisk");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to execute %s\n", component);
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_send_kernelcache(const char* ipsw, plist_t tss) {
- irecv_client_t recovery = NULL;
+int recovery_send_kernelcache(struct idevicerestore_client_t* client) {
const char* component = "kernelcache";
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- if (recovery_send_signed_component(recovery, ipsw, tss, "RestoreKernelCache") < 0) {
+ if (recovery_send_signed_component(client, "RestoreKernelCache") < 0) {
error("ERROR: Unable to send %s to device.\n", component);
- irecv_close(recovery);
return -1;
}
- recovery_error = irecv_send_command(recovery, "bootx");
+ recovery_error = irecv_send_command(client->recovery->client, "bootx");
if (recovery_error != IRECV_E_SUCCESS) {
error("ERROR: Unable to execute %s\n", component);
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_get_ecid(uint64_t* ecid) {
- irecv_client_t recovery = NULL;
+int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) {
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- recovery_error = irecv_get_ecid(recovery, ecid);
+ recovery_error = irecv_get_ecid(client->recovery->client, ecid);
if (recovery_error != IRECV_E_SUCCESS) {
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_get_cpid(uint32_t* cpid) {
- irecv_client_t recovery = NULL;
+int recovery_get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid) {
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- recovery_error = irecv_get_cpid(recovery, cpid);
+ recovery_error = irecv_get_cpid(client->recovery->client, cpid);
if (recovery_error != IRECV_E_SUCCESS) {
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
-int recovery_get_bdid(uint32_t* bdid) {
- irecv_client_t recovery = NULL;
+int recovery_get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid) {
irecv_error_t recovery_error = IRECV_E_SUCCESS;
- if (recovery_open_with_timeout(&recovery) < 0) {
+ if (recovery_open_with_timeout(client) < 0) {
return -1;
}
- recovery_error = irecv_get_bdid(recovery, bdid);
+ recovery_error = irecv_get_bdid(client->recovery->client, bdid);
if (recovery_error != IRECV_E_SUCCESS) {
- irecv_close(recovery);
return -1;
}
- irecv_close(recovery);
- recovery = NULL;
return 0;
}
diff --git a/src/recovery.h b/src/recovery.h
index 6cd467c..5d1129f 100644
--- a/src/recovery.h
+++ b/src/recovery.h
@@ -28,8 +28,11 @@ extern "C" {
#include <stdint.h>
#include <plist/plist.h>
-#include <libirecovery.h>
+#include "common.h"
+
+struct irecv_client;
+typedef struct irecv_client* irecv_client_t;
struct recovery_client_t {
irecv_client_t client;
const char* ipsw;
@@ -37,18 +40,19 @@ struct recovery_client_t {
};
int recovery_check_mode();
+int recovery_open_with_timeout(struct idevicerestore_client_t* client);
int recovery_client_new(struct idevicerestore_client_t* client);
void recovery_client_free(struct idevicerestore_client_t* client);
-int recovery_send_signed_component(struct idevicerestore_client_t* client, const char* ipsw, plist_t tss, char* component) {
-irecv_error_t recovery_open_with_timeout(irecv_client_t* client);
-int recovery_send_ibec(const char* ipsw, plist_t tss);
-int recovery_send_applelogo(const char* ipsw, plist_t tss);
-int recovery_send_devicetree(const char* ipsw, plist_t tss);
-int recovery_send_ramdisk(const char* ipsw, plist_t tss);
-int recovery_send_kernelcache(const char* ipsw, plist_t tss);
-int recovery_get_ecid(uint64_t* ecid);
-int recovery_get_cpid(uint32_t* cpid);
-int recovery_get_bdid(uint32_t* bdid);
+int recovery_send_signed_component(struct idevicerestore_client_t* client, const char* component);
+int recovery_send_ibec(struct idevicerestore_client_t* client);
+int recovery_send_applelogo(struct idevicerestore_client_t* client);
+int recovery_send_devicetree(struct idevicerestore_client_t* client);
+int recovery_send_ramdisk(struct idevicerestore_client_t* client);
+int recovery_send_kernelcache(struct idevicerestore_client_t* client);
+int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid);
+int recovery_get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid);
+int recovery_get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid);
+
#ifdef __cplusplus
}
diff --git a/src/restore.c b/src/restore.c
index b4cf0b2..bf4b62f 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -193,7 +193,7 @@ int restore_reboot(struct idevicerestore_client_t* client) {
}
}
- restore_error = restored_reboot(client);
+ restore_error = restored_reboot(client->restore->client);
if (restore_error != RESTORE_E_SUCCESS) {
error("ERROR: Unable to reboot the device from restore mode\n");
return -1;
@@ -590,7 +590,7 @@ int restore_device(struct idevicerestore_client_t* client, const char* uuid, con
restore_error = restored_start_restore(restore);
if (restore_error != RESTORE_E_SUCCESS) {
error("ERROR: Unable to start the restore process\n");
- restore_close(device, restore);
+ restore_client_free(client);
return -1;
}
@@ -652,6 +652,6 @@ int restore_device(struct idevicerestore_client_t* client, const char* uuid, con
message = NULL;
}
- restore_close(device, restore);
+ restore_client_free(client);
return 0;
}