diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 68 | ||||
-rw-r--r-- | src/common.h | 8 | ||||
-rw-r--r-- | src/dfu.c | 19 | ||||
-rw-r--r-- | src/idevicerestore.h | 3 | ||||
-rw-r--r-- | src/limera1n.c | 9 | ||||
-rw-r--r-- | src/recovery.c | 18 | ||||
-rw-r--r-- | src/restore.c | 44 |
7 files changed, 120 insertions, 49 deletions
diff --git a/src/common.c b/src/common.c index 2b364cb..a250a40 100644 --- a/src/common.c +++ b/src/common.c @@ -29,6 +29,74 @@ int idevicerestore_debug = 0; +static FILE* info_stream = NULL; +static FILE* error_stream = NULL; +static FILE* debug_stream = NULL; + +static int info_disabled = 0; +static int error_disabled = 0; +static int debug_disabled = 0; + +void info(const char* format, ...) +{ + if (info_disabled) return; + va_list vargs; + va_start(vargs, format); + vfprintf((info_stream) ? info_stream : stdout, format, vargs); + va_end(vargs); +} + +void error(const char* format, ...) +{ + if (error_disabled) return; + va_list vargs; + va_start(vargs, format); + vfprintf((error_stream) ? error_stream : stderr, format, vargs); + va_end(vargs); +} + +void debug(const char* format, ...) +{ + if (debug_disabled) return; + if (!idevicerestore_debug) { + return; + } + va_list vargs; + va_start(vargs, format); + vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); + va_end(vargs); +} + +void idevicerestore_set_info_stream(FILE* strm) +{ + if (strm) { + info_disabled = 0; + info_stream = strm; + } else { + info_disabled = 1; + } +} + +void idevicerestore_set_error_stream(FILE* strm) +{ + if (strm) { + error_disabled = 0; + error_stream = strm; + } else { + error_disabled = 1; + } +} + +void idevicerestore_set_debug_stream(FILE* strm) +{ + if (strm) { + debug_disabled = 0; + debug_stream = strm; + } else { + debug_disabled = 1; + } +} + int write_file(const char* filename, const void* data, size_t size) { size_t bytes = 0; FILE* file = NULL; diff --git a/src/common.h b/src/common.h index dae1eea..9a27262 100644 --- a/src/common.h +++ b/src/common.h @@ -31,10 +31,6 @@ extern "C" { #include "idevicerestore.h" -#define info(...) printf(__VA_ARGS__) -#define error(...) fprintf(stderr, __VA_ARGS__) -#define debug(...) if(idevicerestore_debug) fprintf(stderr, __VA_ARGS__) - #define MODE_UNKNOWN -1 #define MODE_WTF 0 #define MODE_DFU 1 @@ -102,6 +98,10 @@ static struct idevicerestore_mode_t idevicerestore_modes[] = { extern int idevicerestore_debug; +void info(const char* format, ...); +void error(const char* format, ...); +void debug(const char* format, ...); + void debug_plist(plist_t plist); void print_progress_bar(double progress); int read_file(const char* filename, void** data, size_t* size); @@ -27,6 +27,7 @@ #include "dfu.h" #include "recovery.h" #include "idevicerestore.h" +#include "common.h" int dfu_progress_callback(irecv_client_t client, const irecv_event_t* event) { if (event->type == IRECV_PROGRESS) { @@ -108,18 +109,18 @@ int dfu_check_mode(struct idevicerestore_client_t* client, int* mode) { int dfu_send_buffer(struct idevicerestore_client_t* client, char* buffer, uint32_t size) { - irecv_error_t error = 0; + irecv_error_t err = 0; info("Sending data (%d bytes)...\n", size); - error = irecv_send_buffer(client->dfu->client, buffer, size, 1); - if (error != IRECV_E_SUCCESS) { - error("ERROR: Unable to send data: %s\n", irecv_strerror(error)); + err = irecv_send_buffer(client->dfu->client, buffer, size, 1); + if (err != IRECV_E_SUCCESS) { + error("ERROR: Unable to send data: %s\n", irecv_strerror(err)); return -1; } - error = irecv_reset(client->dfu->client); - if (error != IRECV_E_SUCCESS) { + err = irecv_reset(client->dfu->client); + if (err != IRECV_E_SUCCESS) { error("ERROR: Unable to reset device\n"); irecv_close(client->dfu->client); client->dfu->client = NULL; @@ -134,7 +135,7 @@ int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_ide char* data = NULL; char* path = NULL; char* blob = NULL; - irecv_error_t error = 0; + irecv_error_t err = 0; int flag = 1; if (client->tss) { @@ -185,10 +186,10 @@ int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_ide info("Sending %s (%d bytes)...\n", component, size); // FIXME: Did I do this right???? - error = irecv_send_buffer(client->dfu->client, data, size, flag); + err = irecv_send_buffer(client->dfu->client, data, size, flag); free(path); if (error != IRECV_E_SUCCESS) { - error("ERROR: Unable to send %s component: %s\n", component, irecv_strerror(error)); + error("ERROR: Unable to send %s component: %s\n", component, irecv_strerror(err)); free(data); return -1; } diff --git a/src/idevicerestore.h b/src/idevicerestore.h index c7c80dc..6f34743 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -61,6 +61,9 @@ void idevicerestore_set_flags(struct idevicerestore_client_t* client, int flags) void idevicerestore_set_ipsw(struct idevicerestore_client_t* client, const char* path); void idevicerestore_set_progress_callback(struct idevicerestore_client_t* client, idevicerestore_progress_cb_t cbfunc, void* userdata); +void idevicerestore_set_info_stream(FILE* strm); +void idevicerestore_set_error_stream(FILE* strm); +void idevicerestore_set_debug_stream(FILE* strm); int idevicerestore_start(struct idevicerestore_client_t* client); diff --git a/src/limera1n.c b/src/limera1n.c index c4b11f9..0d0edcc 100644 --- a/src/limera1n.c +++ b/src/limera1n.c @@ -30,7 +30,7 @@ int limera1n_exploit(struct irecv_device *device, irecv_client_t client) { - irecv_error_t error = IRECV_E_SUCCESS; + irecv_error_t err = IRECV_E_SUCCESS; unsigned int i = 0; unsigned char buf[0x800]; unsigned char shellcode[0x800]; @@ -57,9 +57,9 @@ int limera1n_exploit(struct irecv_device *device, irecv_client_t client) memcpy(shellcode, limera1n_payload, sizeof(limera1n_payload)); debug("Resetting device counters\n"); - error = irecv_reset_counters(client); - if (error != IRECV_E_SUCCESS) { - error("%s\n", irecv_strerror(error)); + err = irecv_reset_counters(client); + if (err != IRECV_E_SUCCESS) { + error("%s\n", irecv_strerror(err)); return -1; } @@ -98,7 +98,6 @@ int limera1n_exploit(struct irecv_device *device, irecv_client_t client) debug("Reconnecting to device\n"); client = irecv_reconnect(client, 7); if (client == NULL) { - debug("%s\n", irecv_strerror(error)); error("Unable to reconnect\n"); return -1; } diff --git a/src/recovery.c b/src/recovery.c index 13073d1..4d288e2 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -221,16 +221,16 @@ int recovery_send_ticket(struct idevicerestore_client_t* client) } info("Sending APTicket (%d bytes)\n", size); - irecv_error_t error = irecv_send_buffer(client->recovery->client, data, size, 0); - if (error != IRECV_E_SUCCESS) { - error("ERROR: Unable to send APTicket: %s\n", irecv_strerror(error)); + irecv_error_t err = irecv_send_buffer(client->recovery->client, data, size, 0); + if (err != IRECV_E_SUCCESS) { + error("ERROR: Unable to send APTicket: %s\n", irecv_strerror(err)); free(data); return -1; } free(data); - error = irecv_send_command(client->recovery->client, "ticket"); - if (error != IRECV_E_SUCCESS) { + err = irecv_send_command(client->recovery->client, "ticket"); + if (err != IRECV_E_SUCCESS) { error("ERROR: Unable to send ticket command\n"); return -1; } @@ -243,7 +243,7 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil char* data = NULL; char* path = NULL; char* blob = NULL; - irecv_error_t error = 0; + irecv_error_t err = 0; if (client->tss) { if (tss_get_entry_path(client->tss, component, &path) < 0) { @@ -271,10 +271,10 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil info("Sending %s (%d bytes)...\n", component, size); // FIXME: Did I do this right???? - error = irecv_send_buffer(client->recovery->client, data, size, 0); + err = irecv_send_buffer(client->recovery->client, data, size, 0); free(path); - if (error != IRECV_E_SUCCESS) { - error("ERROR: Unable to send %s component: %s\n", component, irecv_strerror(error)); + if (err != IRECV_E_SUCCESS) { + error("ERROR: Unable to send %s component: %s\n", component, irecv_strerror(err)); free(data); return -1; } diff --git a/src/restore.c b/src/restore.c index 2529afe..965e6c9 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1477,12 +1477,12 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev } int restore_device(struct idevicerestore_client_t* client, plist_t build_identity, const char* filesystem) { - int error = 0; + int err = 0; char* type = NULL; char* kernel = NULL; plist_t node = NULL; plist_t message = NULL; - plist_t info = NULL; + plist_t hwinfo = NULL; idevice_t device = NULL; restored_client_t restore = NULL; idevice_error_t device_error = IDEVICE_E_SUCCESS; @@ -1491,53 +1491,53 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit restore_finished = 0; // open our connection to the device and verify we're in restore mode - error = restore_open_with_timeout(client); - if (error < 0) { + err = restore_open_with_timeout(client); + if (err < 0) { error("ERROR: Unable to open device in restore mode\n"); - return (error == -2) ? -1: -2; + return (err == -2) ? -1: -2; } info("Device has successfully entered restore mode\n"); restore = client->restore->client; device = client->restore->device; - restore_error = restored_query_value(restore, "HardwareInfo", &info); + restore_error = restored_query_value(restore, "HardwareInfo", &hwinfo); if (restore_error == RESTORE_E_SUCCESS) { uint64_t i = 0; uint8_t b = 0; info("Hardware Information:\n"); - node = plist_dict_get_item(info, "BoardID"); + node = plist_dict_get_item(hwinfo, "BoardID"); if (node && plist_get_node_type(node) == PLIST_UINT) { plist_get_uint_val(node, &i); info("BoardID: %d\n", (int)i); } - node = plist_dict_get_item(info, "ChipID"); + node = plist_dict_get_item(hwinfo, "ChipID"); if (node && plist_get_node_type(node) == PLIST_UINT) { plist_get_uint_val(node, &i); info("ChipID: %d\n", (int)i); } - node = plist_dict_get_item(info, "UniqueChipID"); + node = plist_dict_get_item(hwinfo, "UniqueChipID"); if (node && plist_get_node_type(node) == PLIST_UINT) { plist_get_uint_val(node, &i); info("UniqueChipID: " FMT_qu "\n", (long long unsigned int)i); } - node = plist_dict_get_item(info, "ProductionMode"); + node = plist_dict_get_item(hwinfo, "ProductionMode"); if (node && plist_get_node_type(node) == PLIST_BOOLEAN) { plist_get_bool_val(node, &b); info("ProductionMode: %s\n", (b==1) ? "true":"false"); } - plist_free(info); + plist_free(hwinfo); } - restore_error = restored_query_value(restore, "SavedDebugInfo", &info); + restore_error = restored_query_value(restore, "SavedDebugInfo", &hwinfo); if (restore_error == RESTORE_E_SUCCESS) { char* sval = NULL; - node = plist_dict_get_item(info, "PreviousExitStatus"); + node = plist_dict_get_item(hwinfo, "PreviousExitStatus"); if (node && plist_get_node_type(node) == PLIST_STRING) { plist_get_string_val(node, &sval); info("Previous restore exit status: %s\n", sval); @@ -1545,7 +1545,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit sval = NULL; } - node = plist_dict_get_item(info, "USBLog"); + node = plist_dict_get_item(hwinfo, "USBLog"); if (node && plist_get_node_type(node) == PLIST_STRING) { plist_get_string_val(node, &sval); info("USB log is available:\n%s\n", sval); @@ -1553,14 +1553,14 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit sval = NULL; } - node = plist_dict_get_item(info, "PanicLog"); + node = plist_dict_get_item(hwinfo, "PanicLog"); if (node && plist_get_node_type(node) == PLIST_STRING) { plist_get_string_val(node, &sval); info("Panic log is available:\n%s\n", sval); free(sval); sval = NULL; } - plist_free(info); + plist_free(hwinfo); } plist_t opts = plist_new_dict(); @@ -1662,24 +1662,24 @@ 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")) { - error = restore_handle_data_request_msg(client, device, restore, message, build_identity, filesystem); + err = restore_handle_data_request_msg(client, device, restore, message, build_identity, filesystem); } // restore logs are available if a previous restore failed else if (!strcmp(type, "PreviousRestoreLogMsg")) { - error = restore_handle_previous_restore_log_msg(restore, message); + err = restore_handle_previous_restore_log_msg(restore, message); } // progress notification messages sent by the restored inform the client // of it's current operation and sometimes percent of progress is complete else if (!strcmp(type, "ProgressMsg")) { - error = restore_handle_progress_msg(client, message); + err = restore_handle_progress_msg(client, message); } // status messages usually indicate the current state of the restored // process or often to signal an error has been encountered else if (!strcmp(type, "StatusMsg")) { - error = restore_handle_status_msg(restore, message); + err = restore_handle_status_msg(restore, message); if (restore_finished) { client->flags |= FLAG_QUIT; } @@ -1687,7 +1687,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit // baseband update message else if (!strcmp(type, "BBUpdateStatusMsg")) { - error = restore_handle_bb_update_status_msg(restore, message); + err = restore_handle_bb_update_status_msg(restore, message); } // there might be some other message types i'm not aware of, but I think @@ -1703,5 +1703,5 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit } restore_client_free(client); - return error; + return err; } |