From b09706b48b00d00cfd61638d9e9b932484b29b79 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 29 Jun 2021 03:59:10 +0200 Subject: Remove unused functions --- src/dfu.c | 52 +++++++++++----------------------- src/dfu.h | 1 - src/idevicerestore.c | 79 ++++++++++++++++++++++------------------------------ src/idevicerestore.h | 1 - src/recovery.c | 66 ++++++++++++++++--------------------------- src/recovery.h | 1 - 6 files changed, 74 insertions(+), 126 deletions(-) (limited to 'src') diff --git a/src/dfu.c b/src/dfu.c index 4277def..ac4f1cd 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -40,7 +40,8 @@ static int dfu_progress_callback(irecv_client_t client, const irecv_event_t* eve return 0; } -int dfu_client_new(struct idevicerestore_client_t* client) { +int dfu_client_new(struct idevicerestore_client_t* client) +{ int i = 0; int attempts = 10; irecv_client_t dfu = NULL; @@ -73,7 +74,8 @@ int dfu_client_new(struct idevicerestore_client_t* client) { return 0; } -void dfu_client_free(struct idevicerestore_client_t* client) { +void dfu_client_free(struct idevicerestore_client_t* client) +{ if(client != NULL) { if (client->dfu != NULL) { if(client->dfu->client != NULL) { @@ -86,35 +88,8 @@ void dfu_client_free(struct idevicerestore_client_t* client) { } } -int dfu_check_mode(struct idevicerestore_client_t* client, int* mode) { - irecv_client_t dfu = NULL; - int probe_mode = -1; - - if (client->udid && client->ecid == 0) { - /* if we have a UDID but no ECID we can't make sure this is the correct device */ - return -1; - } - - irecv_init(); - if (irecv_open_with_ecid(&dfu, client->ecid) != IRECV_E_SUCCESS) { - return -1; - } - - irecv_get_mode(dfu, &probe_mode); - - if ((probe_mode != IRECV_K_DFU_MODE) && (probe_mode != IRECV_K_WTF_MODE)) { - irecv_close(dfu); - return -1; - } - - *mode = (probe_mode == IRECV_K_WTF_MODE) ? MODE_WTF : MODE_DFU; - - irecv_close(dfu); - - return 0; -} - -irecv_device_t dfu_get_irecv_device(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; @@ -148,7 +123,8 @@ int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffe return 0; } -int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component) { +int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component) +{ char* path = NULL; // Use a specific TSS ticket for the Ap,LocalPolicy component @@ -233,7 +209,8 @@ int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_ide return 0; } -int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid) { +int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid) +{ if(client->dfu == NULL) { if (dfu_client_new(client) < 0) { return -1; @@ -250,7 +227,8 @@ int dfu_get_cpid(struct idevicerestore_client_t* client, unsigned int* cpid) { return 0; } -int dfu_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { +int dfu_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) +{ if(client->dfu == NULL) { if (dfu_client_new(client) < 0) { return -1; @@ -283,7 +261,8 @@ int dfu_is_image4_supported(struct idevicerestore_client_t* client) return (device_info->ibfl & IBOOT_FLAG_IMAGE4_AWARE); } -int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ if(client->dfu == NULL) { if (dfu_client_new(client) < 0) { return -1; @@ -307,7 +286,8 @@ int dfu_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** non return 0; } -int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int dfu_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ if(client->dfu == NULL) { if (dfu_client_new(client) < 0) { return -1; diff --git a/src/dfu.h b/src/dfu.h index 2af1a6e..f501531 100644 --- a/src/dfu.h +++ b/src/dfu.h @@ -39,7 +39,6 @@ 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); 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); diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 2f2b643..024e60b 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -1564,7 +1564,8 @@ void plain_progress_cb(int step, double step_progress, void* userdata) fflush(stdout); } -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ int opt = 0; int optindex = 0; char* ipsw = NULL; @@ -1741,35 +1742,8 @@ int main(int argc, char* argv[]) { } #endif -int check_mode(struct idevicerestore_client_t* client) { - int mode = MODE_UNKNOWN; - int dfumode = MODE_UNKNOWN; - - if (recovery_check_mode(client) == 0) { - mode = MODE_RECOVERY; - } - - else if (dfu_check_mode(client, &dfumode) == 0) { - mode = dfumode; - } - - else if (normal_check_mode(client) == 0) { - mode = MODE_NORMAL; - } - - else if (restore_check_mode(client) == 0) { - mode = MODE_RESTORE; - } - - if (mode == MODE_UNKNOWN) { - client->mode = NULL; - } else { - client->mode = &idevicerestore_modes[mode]; - } - return mode; -} - -irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) { +irecv_device_t get_irecv_device(struct idevicerestore_client_t *client) +{ int mode = MODE_UNKNOWN; if (client->mode) { @@ -1821,7 +1795,8 @@ int is_image4_supported(struct idevicerestore_client_t* client) return res; } -int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { +int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) +{ int mode = MODE_UNKNOWN; if (client->mode) { @@ -1859,7 +1834,8 @@ int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { return 0; } -int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ int mode = MODE_UNKNOWN; *nonce = NULL; @@ -1909,7 +1885,8 @@ int get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, return 0; } -int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ int mode = MODE_UNKNOWN; *nonce = NULL; @@ -2150,7 +2127,8 @@ int get_preboard_manifest(struct idevicerestore_client_t* client, plist_t build_ return res; } -int get_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) { +int get_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) +{ plist_t request = NULL; plist_t response = NULL; *tss = NULL; @@ -2360,7 +2338,8 @@ int get_tss_response(struct idevicerestore_client_t* client, plist_t build_ident return 0; } -int get_recoveryos_root_ticket_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) { +int get_recoveryos_root_ticket_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) +{ plist_t request = NULL; plist_t response = NULL; *tss = NULL; @@ -2458,7 +2437,8 @@ int get_recovery_os_local_policy_tss_response( struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss, - plist_t args) { + plist_t args) +{ plist_t request = NULL; plist_t response = NULL; *tss = NULL; @@ -2544,7 +2524,8 @@ int get_recovery_os_local_policy_tss_response( return 0; } -int get_local_policy_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) { +int get_local_policy_tss_response(struct idevicerestore_client_t* client, plist_t build_identity, plist_t* tss) +{ plist_t request = NULL; plist_t response = NULL; *tss = NULL; @@ -2658,7 +2639,8 @@ void fixup_tss(plist_t tss) } } -int build_manifest_get_identity_count(plist_t build_manifest) { +int build_manifest_get_identity_count(plist_t build_manifest) +{ // fetch build identities array from BuildManifest plist_t build_identities_array = plist_dict_get_item(build_manifest, "BuildIdentities"); if (!build_identities_array || plist_get_node_type(build_identities_array) != PLIST_ARRAY) { @@ -2692,7 +2674,8 @@ int extract_component(const char* ipsw, const char* path, unsigned char** compon return 0; } -int personalize_component(const char *component_name, const unsigned char* component_data, unsigned int component_size, plist_t tss_response, unsigned char** personalized_component, unsigned int* personalized_component_size) { +int personalize_component(const char *component_name, const unsigned char* component_data, unsigned int component_size, plist_t tss_response, unsigned char** personalized_component, unsigned int* personalized_component_size) +{ unsigned char* component_blob = NULL; unsigned int component_blob_size = 0; unsigned char* stitched_component = NULL; @@ -2733,7 +2716,8 @@ int personalize_component(const char *component_name, const unsigned char* compo return 0; } -int build_manifest_check_compatibility(plist_t build_manifest, const char* product) { +int build_manifest_check_compatibility(plist_t build_manifest, const char* product) +{ int res = -1; plist_t node = plist_dict_get_item(build_manifest, "SupportedProductTypes"); if (!node || (plist_get_node_type(node) != PLIST_ARRAY)) { @@ -2759,7 +2743,8 @@ int build_manifest_check_compatibility(plist_t build_manifest, const char* produ return res; } -void build_manifest_get_version_information(plist_t build_manifest, struct idevicerestore_client_t* client) { +void build_manifest_get_version_information(plist_t build_manifest, struct idevicerestore_client_t* client) +{ plist_t node = NULL; client->version = NULL; client->build = NULL; @@ -2781,7 +2766,8 @@ void build_manifest_get_version_information(plist_t build_manifest, struct idevi client->build_major = strtoul(client->build, NULL, 10); } -void build_identity_print_information(plist_t build_identity) { +void build_identity_print_information(plist_t build_identity) +{ char* value = NULL; plist_t info_node = NULL; plist_t node = NULL; @@ -2855,7 +2841,8 @@ int build_identity_check_components_in_ipsw(plist_t build_identity, const char * return res; } -int build_identity_has_component(plist_t build_identity, const char* component) { +int build_identity_has_component(plist_t build_identity, const char* component) +{ plist_t manifest_node = plist_dict_get_item(build_identity, "Manifest"); if (!manifest_node || plist_get_node_type(manifest_node) != PLIST_DICT) { return 0; @@ -2869,7 +2856,8 @@ int build_identity_has_component(plist_t build_identity, const char* component) return 1; } -int build_identity_get_component_path(plist_t build_identity, const char* component, char** path) { +int build_identity_get_component_path(plist_t build_identity, const char* component, char** path) +{ char* filename = NULL; plist_t manifest_node = plist_dict_get_item(build_identity, "Manifest"); @@ -2909,7 +2897,8 @@ int build_identity_get_component_path(plist_t build_identity, const char* compon return 0; } -const char* get_component_name(const char* filename) { +const char* get_component_name(const char* filename) +{ if (!strncmp(filename, "LLB", 3)) { return "LLB"; } else if (!strncmp(filename, "iBoot", 5)) { diff --git a/src/idevicerestore.h b/src/idevicerestore.h index e7690c2..a7f3609 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -82,7 +82,6 @@ void idevicerestore_set_debug_stream(FILE* strm); int idevicerestore_start(struct idevicerestore_client_t* client); const char* idevicerestore_get_error(void); -int check_mode(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); diff --git a/src/recovery.c b/src/recovery.c index 415a5d1..6048382 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -35,14 +35,16 @@ #include "restore.h" #include "recovery.h" -static int recovery_progress_callback(irecv_client_t client, const irecv_event_t* event) { +static int recovery_progress_callback(irecv_client_t client, const irecv_event_t* event) +{ if (event->type == IRECV_PROGRESS) { //print_progress_bar(event->progress); } return 0; } -void recovery_client_free(struct idevicerestore_client_t* client) { +void recovery_client_free(struct idevicerestore_client_t* client) +{ if(client) { if (client->recovery) { if(client->recovery->client) { @@ -55,7 +57,8 @@ void recovery_client_free(struct idevicerestore_client_t* client) { } } -int recovery_client_new(struct idevicerestore_client_t* client) { +int recovery_client_new(struct idevicerestore_client_t* client) +{ int i = 0; int attempts = 20; irecv_client_t recovery = NULL; @@ -98,37 +101,8 @@ int recovery_client_new(struct idevicerestore_client_t* client) { return 0; } -int recovery_check_mode(struct idevicerestore_client_t* client) { - irecv_client_t recovery = NULL; - irecv_error_t recovery_error = IRECV_E_SUCCESS; - int mode = 0; - - if (client->udid && client->ecid == 0) { - /* if we have a UDID but no ECID we can't make sure this is the correct device */ - return -1; - } - - irecv_init(); - recovery_error=irecv_open_with_ecid(&recovery, client->ecid); - - if (recovery_error != IRECV_E_SUCCESS) { - return -1; - } - - irecv_get_mode(recovery, &mode); - - if ((mode == IRECV_K_DFU_MODE) || (mode == IRECV_K_WTF_MODE)) { - irecv_close(recovery); - return -1; - } - - irecv_close(recovery); - recovery = NULL; - - return 0; -} - -int recovery_set_autoboot(struct idevicerestore_client_t* client, int enable) { +int recovery_set_autoboot(struct idevicerestore_client_t* client, int enable) +{ irecv_error_t recovery_error = IRECV_E_SUCCESS; recovery_error = irecv_send_command(client->recovery->client, (enable) ? "setenv auto-boot true" : "setenv auto-boot false"); @@ -146,7 +120,8 @@ int recovery_set_autoboot(struct idevicerestore_client_t* client, int enable) { return 0; } -int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build_identity) +{ if (client->build_major >= 8) { client->restore_boot_args = strdup("rd=md0 nand-enable-reformat=1 -progress"); } else if (client->build_major >= 20) { @@ -353,7 +328,8 @@ int recovery_send_component_and_command(struct idevicerestore_client_t* client, return 0; } -int recovery_send_ibec(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_send_ibec(struct idevicerestore_client_t* client, plist_t build_identity) +{ const char* component = "iBEC"; irecv_error_t recovery_error = IRECV_E_SUCCESS; @@ -378,7 +354,8 @@ int recovery_send_ibec(struct idevicerestore_client_t* client, plist_t build_ide return 0; } -int recovery_send_applelogo(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_send_applelogo(struct idevicerestore_client_t* client, plist_t build_identity) +{ const char* component = "RestoreLogo"; irecv_error_t recovery_error = IRECV_E_SUCCESS; @@ -461,7 +438,8 @@ int recovery_send_loaded_by_iboot(struct idevicerestore_client_t* client, plist_ return (err) ? -1 : 0; } -int recovery_send_ramdisk(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_send_ramdisk(struct idevicerestore_client_t* client, plist_t build_identity) +{ const char *component = "RestoreRamDisk"; irecv_error_t recovery_error = IRECV_E_SUCCESS; @@ -495,7 +473,8 @@ int recovery_send_ramdisk(struct idevicerestore_client_t* client, plist_t build_ return 0; } -int recovery_send_kernelcache(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_send_kernelcache(struct idevicerestore_client_t* client, plist_t build_identity) +{ const char* component = "RestoreKernelCache"; irecv_error_t recovery_error = IRECV_E_SUCCESS; @@ -528,7 +507,8 @@ int recovery_send_kernelcache(struct idevicerestore_client_t* client, plist_t bu return 0; } -int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { +int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) +{ if(client->recovery == NULL) { if (recovery_client_new(client) < 0) { return -1; @@ -561,7 +541,8 @@ int recovery_is_image4_supported(struct idevicerestore_client_t* client) return (device_info->ibfl & IBOOT_FLAG_IMAGE4_AWARE); } -int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ if(client->recovery == NULL) { if (recovery_client_new(client) < 0) { return -1; @@ -585,7 +566,8 @@ int recovery_get_ap_nonce(struct idevicerestore_client_t* client, unsigned char* return 0; } -int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) { +int recovery_get_sep_nonce(struct idevicerestore_client_t* client, unsigned char** nonce, int* nonce_size) +{ if(client->recovery == NULL) { if (recovery_client_new(client) < 0) { return -1; diff --git a/src/recovery.h b/src/recovery.h index 714943a..154d7d1 100644 --- a/src/recovery.h +++ b/src/recovery.h @@ -40,7 +40,6 @@ struct recovery_client_t { plist_t tss; }; -int recovery_check_mode(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_enter_restore(struct idevicerestore_client_t* client, plist_t build_identity); -- cgit v1.1-32-gdbae