Skip to content

Commit

Permalink
restore: Always try to use DeviceGeneratedRequest data for TSS reques…
Browse files Browse the repository at this point in the history
…ts if present
  • Loading branch information
nikias committed Jun 26, 2024
1 parent 28c1dab commit 63094e7
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ static plist_t restore_get_se_firmware_data(struct idevicerestore_client_t* clie
return response;
}

static plist_t restore_get_savage_firmware_data(struct idevicerestore_client_t* client, plist_t p_info)
static plist_t restore_get_savage_firmware_data(struct idevicerestore_client_t* client, plist_t p_info, plist_t arguments)
{
char *comp_name = NULL;
char *comp_path = NULL;
Expand All @@ -2704,6 +2704,12 @@ static plist_t restore_get_savage_firmware_data(struct idevicerestore_client_t*
return NULL;
}

plist_t device_generated_request = plist_dict_get_item(arguments, "DeviceGeneratedRequest");
if (device_generated_request && !PLIST_IS_DICT(device_generated_request)) {
error("ERROR: %s: DeviceGeneratedRequest has invalid type!\n", __func__);
return NULL;
}

/* create Savage request */
request = tss_request_new(NULL);
if (request == NULL) {
Expand All @@ -2720,7 +2726,7 @@ static plist_t restore_get_savage_firmware_data(struct idevicerestore_client_t*
plist_dict_merge(&parameters, p_info);

/* add required tags for Savage TSS request */
tss_request_add_savage_tags(request, parameters, NULL, &comp_name);
tss_request_add_savage_tags(request, parameters, device_generated_request, &comp_name);

plist_free(parameters);

Expand Down Expand Up @@ -2783,7 +2789,7 @@ static plist_t restore_get_savage_firmware_data(struct idevicerestore_client_t*
return response;
}

static plist_t restore_get_yonkers_firmware_data(struct idevicerestore_client_t* client, plist_t p_info)
static plist_t restore_get_yonkers_firmware_data(struct idevicerestore_client_t* client, plist_t p_info, plist_t arguments)
{
char *comp_name = NULL;
char *comp_path = NULL;
Expand All @@ -2799,6 +2805,12 @@ static plist_t restore_get_yonkers_firmware_data(struct idevicerestore_client_t*
return NULL;
}

plist_t device_generated_request = plist_dict_get_item(arguments, "DeviceGeneratedRequest");
if (device_generated_request && !PLIST_IS_DICT(device_generated_request)) {
error("ERROR: %s: DeviceGeneratedRequest has invalid type!\n", __func__);
return NULL;
}

/* create Yonkers request */
request = tss_request_new(NULL);
if (request == NULL) {
Expand All @@ -2817,7 +2829,7 @@ static plist_t restore_get_yonkers_firmware_data(struct idevicerestore_client_t*
plist_dict_merge(&parameters, p_info);

/* add required tags for Yonkers TSS request */
tss_request_add_yonkers_tags(request, parameters, NULL, &comp_name);
tss_request_add_yonkers_tags(request, parameters, device_generated_request, &comp_name);

plist_free(parameters);

Expand Down Expand Up @@ -3024,7 +3036,7 @@ static plist_t restore_get_rose_firmware_data(struct idevicerestore_client_t* cl
return response;
}

static plist_t restore_get_veridian_firmware_data(struct idevicerestore_client_t* client, plist_t p_info)
static plist_t restore_get_veridian_firmware_data(struct idevicerestore_client_t* client, plist_t p_info, plist_t arguments)
{
char *comp_name = "BMU,FirmwareMap";
char *comp_path = NULL;
Expand All @@ -3040,6 +3052,12 @@ static plist_t restore_get_veridian_firmware_data(struct idevicerestore_client_t
return NULL;
}

plist_t device_generated_request = plist_dict_get_item(arguments, "DeviceGeneratedRequest");
if (device_generated_request && !PLIST_IS_DICT(device_generated_request)) {
error("ERROR: %s: DeviceGeneratedRequest has invalid type!\n", __func__);
return NULL;
}

/* create Veridian request */
request = tss_request_new(NULL);
if (request == NULL) {
Expand All @@ -3057,7 +3075,7 @@ static plist_t restore_get_veridian_firmware_data(struct idevicerestore_client_t
plist_dict_merge(&parameters, p_info);

/* add required tags for Veridian TSS request */
tss_request_add_veridian_tags(request, parameters, NULL);
tss_request_add_veridian_tags(request, parameters, device_generated_request);

plist_free(parameters);

Expand Down Expand Up @@ -3180,7 +3198,7 @@ static plist_t restore_get_generic_firmware_data(struct idevicerestore_client_t*
return response;
}

static plist_t restore_get_tcon_firmware_data(struct idevicerestore_client_t* client, plist_t p_info)
static plist_t restore_get_tcon_firmware_data(struct idevicerestore_client_t* client, plist_t p_info, plist_t arguments)
{
char *comp_name = "Baobab,TCON";
char *comp_path = NULL;
Expand All @@ -3196,6 +3214,12 @@ static plist_t restore_get_tcon_firmware_data(struct idevicerestore_client_t* cl
return NULL;
}

plist_t device_generated_request = plist_dict_get_item(arguments, "DeviceGeneratedRequest");
if (device_generated_request && !PLIST_IS_DICT(device_generated_request)) {
error("ERROR: %s: DeviceGeneratedRequest has invalid type!\n", __func__);
return NULL;
}

/* create Baobab request */
request = tss_request_new(NULL);
if (request == NULL) {
Expand All @@ -3213,7 +3237,7 @@ static plist_t restore_get_tcon_firmware_data(struct idevicerestore_client_t* cl
plist_dict_merge(&parameters, p_info);

/* add required tags for Baobab TSS request */
tss_request_add_tcon_tags(request, parameters, NULL);
tss_request_add_tcon_tags(request, parameters, device_generated_request);

plist_free(parameters);

Expand Down Expand Up @@ -3254,7 +3278,7 @@ static plist_t restore_get_tcon_firmware_data(struct idevicerestore_client_t* cl
return response;
}

static plist_t restore_get_timer_firmware_data(struct idevicerestore_client_t* client, plist_t p_info)
static plist_t restore_get_timer_firmware_data(struct idevicerestore_client_t* client, plist_t p_info, plist_t arguments)
{
char comp_name[64];
char *comp_path = NULL;
Expand All @@ -3275,6 +3299,12 @@ static plist_t restore_get_timer_firmware_data(struct idevicerestore_client_t* c
return NULL;
}

plist_t device_generated_request = plist_dict_get_item(arguments, "DeviceGeneratedRequest");
if (device_generated_request && !PLIST_IS_DICT(device_generated_request)) {
error("ERROR: %s: DeviceGeneratedRequest has invalid type!\n", __func__);
return NULL;
}

/* create Timer request */
request = tss_request_new(NULL);
if (request == NULL) {
Expand Down Expand Up @@ -3345,7 +3375,7 @@ static plist_t restore_get_timer_firmware_data(struct idevicerestore_client_t* c
}

/* add required tags for Timer TSS request */
tss_request_add_timer_tags(request, parameters, NULL);
tss_request_add_timer_tags(request, parameters, device_generated_request);

plist_free(parameters);

Expand Down Expand Up @@ -3642,9 +3672,9 @@ static int restore_send_firmware_updater_data(struct idevicerestore_client_t* cl
plist_t p_info2 = plist_dict_get_item(p_info, "YonkersDeviceInfo");
if (p_info2 && plist_get_node_type(p_info2) == PLIST_DICT) {
fwtype = "Yonkers";
fwdict = restore_get_yonkers_firmware_data(client, p_info2);
fwdict = restore_get_yonkers_firmware_data(client, p_info2, arguments);
} else {
fwdict = restore_get_savage_firmware_data(client, p_info);
fwdict = restore_get_savage_firmware_data(client, p_info, arguments);
}
if (fwdict == NULL) {
error("ERROR: %s: Couldn't get %s firmware data\n", __func__, fwtype);
Expand All @@ -3657,13 +3687,13 @@ static int restore_send_firmware_updater_data(struct idevicerestore_client_t* cl
goto error_out;
}
} else if (strcmp(s_updater_name, "T200") == 0) {
fwdict = restore_get_veridian_firmware_data(client, p_info);
fwdict = restore_get_veridian_firmware_data(client, p_info, arguments);
if (fwdict == NULL) {
error("ERROR: %s: Couldn't get Veridian firmware data\n", __func__);
goto error_out;
}
} else if (strcmp(s_updater_name, "AppleTCON") == 0) {
fwdict = restore_get_tcon_firmware_data(client, p_info);
fwdict = restore_get_tcon_firmware_data(client, p_info, arguments);
if (fwdict == NULL) {
error("ERROR: %s: Couldn't get AppleTCON firmware data\n", __func__);
goto error_out;
Expand All @@ -3675,7 +3705,7 @@ static int restore_send_firmware_updater_data(struct idevicerestore_client_t* cl
goto error_out;
}
} else if (strcmp(s_updater_name, "AppleTypeCRetimer") == 0) {
fwdict = restore_get_timer_firmware_data(client, p_info);
fwdict = restore_get_timer_firmware_data(client, p_info, arguments);
if (fwdict == NULL) {
error("ERROR: %s: Couldn't get AppleTypeCRetimer firmware data\n", __func__);
goto error_out;
Expand Down

0 comments on commit 63094e7

Please sign in to comment.