summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar BALATON Zoltan2017-02-09 00:37:06 +0100
committerGravatar BALATON Zoltan2017-11-13 22:12:44 +0100
commita87ce4efcbdb9ad3aff3eb52ee9fd9da8e4ab922 (patch)
tree78dba41813b8037db98212a8647ec4bf940b2fc7 /src
parent08d610d5811ed0aa3fecf48ff9e9cee2190b1981 (diff)
downloadidevicerestore-a87ce4efcbdb9ad3aff3eb52ee9fd9da8e4ab922.tar.gz
idevicerestore-a87ce4efcbdb9ad3aff3eb52ee9fd9da8e4ab922.tar.bz2
Change check_hardware_model() to get_irecv_device()
The check_hardware_model() function has a misleading name. It returns a string with the hardware model but this is not used. Instead, this function is only called for its side effect to initialise an irecv device in the passed client struct which it creates from the hardware model name returned by mode specific implementations. But these mode specific implementations already create an irecv device to get the hardware model name so instead of going through this unnecessary complication just return the irecv device directly and rename the function accordingly to make this clear. (This may also prevent leaking an irecv device in the mode specific functions.)
Diffstat (limited to 'src')
-rw-r--r--src/dfu.c4
-rw-r--r--src/dfu.h2
-rw-r--r--src/idevicerestore.c26
-rw-r--r--src/idevicerestore.h3
-rw-r--r--src/normal.c4
-rw-r--r--src/normal.h2
-rw-r--r--src/restore.c7
-rw-r--r--src/restore.h2
8 files changed, 20 insertions, 30 deletions
diff --git a/src/dfu.c b/src/dfu.c
index 124d2c7..11aa843 100644
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -109,7 +109,7 @@ int dfu_check_mode(struct idevicerestore_client_t* client, int* mode) {
return 0;
}
-const char* dfu_check_hardware_model(struct idevicerestore_client_t* client) {
+irecv_device_t dfu_get_irecv_device(struct idevicerestore_client_t* client) {
irecv_client_t dfu = NULL;
irecv_error_t dfu_error = IRECV_E_SUCCESS;
irecv_device_t device = NULL;
@@ -125,7 +125,7 @@ const char* dfu_check_hardware_model(struct idevicerestore_client_t* client) {
return NULL;
}
- return device->hardware_model;
+ return device;
}
int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffer, unsigned int size)
diff --git a/src/dfu.h b/src/dfu.h
index f56862c..2af1a6e 100644
--- a/src/dfu.h
+++ b/src/dfu.h
@@ -40,7 +40,7 @@ struct dfu_client_t {
int dfu_client_new(struct idevicerestore_client_t* client);
void dfu_client_free(struct idevicerestore_client_t* client);
int dfu_check_mode(struct idevicerestore_client_t* client, int* mode);
-const char* dfu_check_hardware_model(struct idevicerestore_client_t* client);
+irecv_device_t dfu_get_irecv_device(struct idevicerestore_client_t* client);
int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffer, unsigned int size);
int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component);
int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid);
diff --git a/src/idevicerestore.c b/src/idevicerestore.c
index 423d79c..a051b95 100644
--- a/src/idevicerestore.c
+++ b/src/idevicerestore.c
@@ -284,8 +284,9 @@ int idevicerestore_start(struct idevicerestore_client_t* client)
}
// discover the device type
- if (check_hardware_model(client) == NULL || client->device == NULL) {
- error("ERROR: Unable to discover device model\n");
+ client->device = get_irecv_device(client);
+ if (client->device == NULL) {
+ error("ERROR: Unable to discover device type\n");
return -1;
}
idevicerestore_progress(client, RESTORE_STEP_DETECT, 0.2);
@@ -1193,8 +1194,7 @@ int check_mode(struct idevicerestore_client_t* client) {
return mode;
}
-const char* check_hardware_model(struct idevicerestore_client_t* client) {
- const char* hw_model = NULL;
+irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) {
int mode = MODE_UNKNOWN;
if (client->mode) {
@@ -1203,26 +1203,18 @@ const char* check_hardware_model(struct idevicerestore_client_t* client) {
switch (mode) {
case MODE_RESTORE:
- hw_model = restore_check_hardware_model(client);
- break;
+ return restore_get_irecv_device(client);
case MODE_NORMAL:
- hw_model = normal_check_hardware_model(client);
- break;
+ return normal_get_irecv_device(client);
case MODE_DFU:
case MODE_RECOVERY:
- hw_model = dfu_check_hardware_model(client);
- break;
- default:
- break;
- }
+ return dfu_get_irecv_device(client);
- if (hw_model != NULL) {
- irecv_devices_get_device_by_hardware_model(hw_model, &client->device);
+ default:
+ return NULL;
}
-
- return hw_model;
}
int is_image4_supported(struct idevicerestore_client_t* client)
diff --git a/src/idevicerestore.h b/src/idevicerestore.h
index 54009a7..0338dde 100644
--- a/src/idevicerestore.h
+++ b/src/idevicerestore.h
@@ -31,6 +31,7 @@ extern "C" {
#include <stdio.h>
#include <stdint.h>
#include <plist/plist.h>
+#include <libirecovery.h>
// the flag with value 1 is reserved for internal use only. don't use it.
#define FLAG_DEBUG 1 << 1
@@ -74,7 +75,7 @@ const char* idevicerestore_get_error(void);
void usage(int argc, char* argv[]);
int check_mode(struct idevicerestore_client_t* client);
-const char* check_hardware_model(struct idevicerestore_client_t* client);
+irecv_device_t get_irecv_device(struct idevicerestore_client_t* client);
int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid);
int is_image4_supported(struct idevicerestore_client_t* client);
int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size);
diff --git a/src/normal.c b/src/normal.c
index 8101b72..921a157 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -218,7 +218,7 @@ int normal_open_with_timeout(struct idevicerestore_client_t* client) {
return 0;
}
-const char* normal_check_hardware_model(struct idevicerestore_client_t* client) {
+irecv_device_t normal_get_irecv_device(struct idevicerestore_client_t* client) {
idevice_t device = NULL;
lockdownd_client_t lockdown = NULL;
lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS;
@@ -253,7 +253,7 @@ const char* normal_check_hardware_model(struct idevicerestore_client_t* client)
lockdownd_client_free(lockdown);
idevice_free(device);
- return (irecv_device) ? irecv_device->hardware_model : NULL;
+ return irecv_device;
}
int normal_enter_recovery(struct idevicerestore_client_t* client) {
diff --git a/src/normal.h b/src/normal.h
index be3fa39..ddd8a58 100644
--- a/src/normal.h
+++ b/src/normal.h
@@ -41,7 +41,7 @@ struct normal_client_t {
int normal_check_mode(struct idevicerestore_client_t* client);
-const char* normal_check_hardware_model(struct idevicerestore_client_t* client);
+irecv_device_t normal_get_irecv_device(struct idevicerestore_client_t* client);
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);
diff --git a/src/restore.c b/src/restore.c
index 83eef83..05ec228 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -222,7 +222,7 @@ int restore_check_mode(struct idevicerestore_client_t* client) {
return 0;
}
-const char* restore_check_hardware_model(struct idevicerestore_client_t* client) {
+irecv_device_t restore_get_irecv_device(struct idevicerestore_client_t* client) {
char* model = NULL;
plist_t node = NULL;
idevice_t device = NULL;
@@ -274,11 +274,8 @@ const char* restore_check_hardware_model(struct idevicerestore_client_t* client)
plist_get_string_val(node, &model);
irecv_devices_get_device_by_hardware_model(model, &irecv_device);
free(model);
- if (irecv_device && irecv_device->product_type) {
- return irecv_device->hardware_model;
- }
- return NULL;
+ return irecv_device;
}
void restore_device_callback(const idevice_event_t* event, void* userdata) {
diff --git a/src/restore.h b/src/restore.h
index e63f6bc..d4cfc46 100644
--- a/src/restore.h
+++ b/src/restore.h
@@ -44,7 +44,7 @@ struct restore_client_t {
};
int restore_check_mode(struct idevicerestore_client_t* client);
-const char* restore_check_hardware_model(struct idevicerestore_client_t* client);
+irecv_device_t restore_get_irecv_device(struct idevicerestore_client_t* client);
int restore_client_new(struct idevicerestore_client_t* client);
void restore_client_free(struct idevicerestore_client_t* client);
int restore_reboot(struct idevicerestore_client_t* client);