Skip to content

Commit

Permalink
restore: Remove device from the parameters of the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Jun 22, 2024
1 parent e083987 commit de1d17d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
42 changes: 26 additions & 16 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ int restore_handle_status_msg(restored_client_t client, plist_t msg)
return result;
}

static int restore_handle_baseband_updater_output_data(restored_client_t restore, struct idevicerestore_client_t* client, idevice_t device, plist_t msg)
static int restore_handle_baseband_updater_output_data(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg)
{
int result = -1;
plist_t node = plist_dict_get_item(msg, "DataPort");
Expand All @@ -793,9 +793,14 @@ static int restore_handle_baseband_updater_output_data(restored_client_t restore
idevice_connection_t connection = NULL;
idevice_error_t device_error = IDEVICE_E_SUCCESS;

if (!client || !client->restore || !client->restore->build_identity || !client->restore->device) {
error("ERROR: %s: idevicerestore client not initialized?!\n", __func__);
return -1;
}

debug("Connecting to baseband updater data port\n");
while (--attempts > 0) {
device_error = idevice_connect(device, data_port, &connection);
device_error = idevice_connect(client->restore->device, data_port, &connection);
if (device_error == IDEVICE_E_SUCCESS) {
break;
}
Expand Down Expand Up @@ -898,14 +903,14 @@ static void restore_asr_progress_cb(double progress, void* userdata)
}
}

int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t device)
int restore_send_filesystem(struct idevicerestore_client_t* client)
{
asr_client_t asr = NULL;
ipsw_archive_t ipsw_dummy = NULL;
ipsw_file_handle_t file = NULL;
char* fsname = NULL;

if (!client || !client->restore || !client->restore->build_identity) {
if (!client || !client->restore || !client->restore->build_identity || !client->restore->device) {
error("ERROR: %s: idevicerestore client not initialized?!\n", __func__);
return -1;
}
Expand All @@ -931,7 +936,7 @@ int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t de
free(fsname);
}

if (asr_open_with_timeout(device, &asr) < 0) {
if (asr_open_with_timeout(client->restore->device, &asr) < 0) {
ipsw_file_close(file);
ipsw_close(ipsw_dummy);
error("ERROR: Unable to connect to ASR\n");
Expand Down Expand Up @@ -2006,7 +2011,7 @@ static int restore_send_baseband_data(restored_client_t restore, struct idevicer
return res;
}

int restore_send_fdr_trust_data(restored_client_t restore, idevice_t device)
int restore_send_fdr_trust_data(restored_client_t restore)
{
restored_error_t restore_error;
plist_t dict;
Expand Down Expand Up @@ -3455,7 +3460,7 @@ static int restore_bootability_send_one(void *ctx, ipsw_archive_t ipsw, const ch
return ret;
}

static int restore_send_bootability_bundle_data(restored_client_t restore, struct idevicerestore_client_t* client, plist_t message, idevice_t device)
static int restore_send_bootability_bundle_data(restored_client_t restore, struct idevicerestore_client_t* client, plist_t message)
{
if (idevicerestore_debug) {
debug("DEBUG: %s: Got BootabilityBundle request:\n", __func__);
Expand All @@ -3471,9 +3476,14 @@ static int restore_send_bootability_bundle_data(restored_client_t restore, struc
idevice_connection_t connection = NULL;
idevice_error_t device_error = IDEVICE_E_SUCCESS;

if (!client || !client->restore || !client->restore->build_identity || !client->restore->device) {
error("ERROR: %s: idevicerestore client not initialized?!\n", __func__);
return -1;
}

debug("Connecting to BootabilityBundle data port\n");
while (--attempts > 0) {
device_error = idevice_connect(device, data_port, &connection);
device_error = idevice_connect(client->restore->device, data_port, &connection);
if (device_error == IDEVICE_E_SUCCESS) {
break;
}
Expand Down Expand Up @@ -3918,7 +3928,7 @@ int restore_send_buildidentity(restored_client_t restore, struct idevicerestore_
return 0;
}

int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idevice_t device, restored_client_t restore, plist_t message)
int restore_handle_data_request_msg(struct idevicerestore_client_t* client, restored_client_t restore, plist_t message)
{
plist_t node = NULL;

Expand All @@ -3930,7 +3940,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev

// this request is sent when restored is ready to receive the filesystem
if (!strcmp(type, "SystemImageData")) {
if(restore_send_filesystem(client, device) < 0) {
if(restore_send_filesystem(client) < 0) {
error("ERROR: Unable to send filesystem\n");
return -2;
}
Expand Down Expand Up @@ -3966,7 +3976,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev

// this request is sent when restored is ready to receive the filesystem
else if (!strcmp(type, "RecoveryOSASRImage")) {
if(restore_send_filesystem(client, device) < 0) {
if(restore_send_filesystem(client) < 0) {
error("ERROR: Unable to send filesystem\n");
return -2;
}
Expand Down Expand Up @@ -4036,7 +4046,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev
}

else if (!strcmp(type, "FDRTrustData")) {
if(restore_send_fdr_trust_data(restore, device) < 0) {
if(restore_send_fdr_trust_data(restore) < 0) {
error("ERROR: Unable to send FDR Trust data\n");
return -1;
}
Expand Down Expand Up @@ -4078,7 +4088,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev
}

else if (!strcmp(type, "BootabilityBundle")) {
if (restore_send_bootability_bundle_data(restore, client, message, device) < 0) {
if (restore_send_bootability_bundle_data(restore, client, message) < 0) {
error("ERROR: Unable to send BootabilityBundle data\n");
return -1;
}
Expand All @@ -4092,7 +4102,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev
}

else if (!strcmp(type, "BasebandUpdaterOutputData")) {
if (restore_handle_baseband_updater_output_data(restore, client, device, message) < 0) {
if (restore_handle_baseband_updater_output_data(restore, client, message) < 0) {
error("ERROR: Unable to send BasebandUpdaterOutputData data\n");
return -1;
}
Expand Down Expand Up @@ -4533,7 +4543,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit
// files sent to the server by the client. these data requests include
// SystemImageData, RootTicket, KernelCache, NORData and BasebandData requests
if (!strcmp(type, "DataRequestMsg")) {
err = restore_handle_data_request_msg(client, device, restore, message);
err = restore_handle_data_request_msg(client, restore, message);
}

// restore logs are available if a previous restore failed
Expand Down Expand Up @@ -4610,7 +4620,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit

// baseband updater output data request
else if (!strcmp(type, "BasebandUpdaterOutputData")) {
err = restore_handle_baseband_updater_output_data(restore, client, device, message);
err = restore_handle_baseband_updater_output_data(restore, client, message);
}

// there might be some other message types i'm not aware of, but I think
Expand Down
6 changes: 3 additions & 3 deletions src/restore.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ int restore_reboot(struct idevicerestore_client_t* client);
const char* restore_progress_string(unsigned int operation);
int restore_handle_status_msg(restored_client_t client, plist_t msg);
int restore_handle_progress_msg(struct idevicerestore_client_t* client, plist_t msg);
int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idevice_t device, restored_client_t restore, plist_t message);
int restore_handle_data_request_msg(struct idevicerestore_client_t* client, restored_client_t restore, plist_t message);
int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t* client, plist_t message);
int restore_send_root_ticket(restored_client_t restore, struct idevicerestore_client_t* client);
int restore_send_component(restored_client_t restore, struct idevicerestore_client_t* client, const char* component, const char* component_name);
int restore_device(struct idevicerestore_client_t* client, plist_t build_identity);
int restore_open_with_timeout(struct idevicerestore_client_t* client);
int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t device);
int restore_send_fdr_trust_data(restored_client_t restore, idevice_t device);
int restore_send_filesystem(struct idevicerestore_client_t* client);
int restore_send_fdr_trust_data(restored_client_t restore);

#ifdef __cplusplus
}
Expand Down

0 comments on commit de1d17d

Please sign in to comment.