summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/irecovery.c19
-rw-r--r--src/libirecovery.c40
2 files changed, 27 insertions, 32 deletions
diff --git a/src/irecovery.c b/src/irecovery.c
index 89f30a6..c4a698d 100644
--- a/src/irecovery.c
+++ b/src/irecovery.c
@@ -42,7 +42,7 @@ int progress_cb(irecv_client_t client, const irecv_event_t* event);
42int precommand_cb(irecv_client_t client, const irecv_event_t* event); 42int precommand_cb(irecv_client_t client, const irecv_event_t* event);
43int postcommand_cb(irecv_client_t client, const irecv_event_t* event); 43int postcommand_cb(irecv_client_t client, const irecv_event_t* event);
44 44
45void shell_usage() { 45static void shell_usage() {
46 printf("Usage:\n"); 46 printf("Usage:\n");
47 printf("\t/upload <file>\tSend file to client.\n"); 47 printf("\t/upload <file>\tSend file to client.\n");
48 printf("\t/exploit [file]\tSend usb exploit with optional payload\n"); 48 printf("\t/exploit [file]\tSend usb exploit with optional payload\n");
@@ -51,8 +51,8 @@ void shell_usage() {
51 printf("\t/exit\t\tExit interactive shell.\n"); 51 printf("\t/exit\t\tExit interactive shell.\n");
52} 52}
53 53
54void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { 54static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
55 char* cmd = strdup(command); 55 char* cmd = strdup((char*)command);
56 char* action = strtok(cmd, " "); 56 char* action = strtok(cmd, " ");
57 debug("Executing %s\n", action); 57 debug("Executing %s\n", action);
58 if (!strcmp(cmd, "/exit")) { 58 if (!strcmp(cmd, "/exit")) {
@@ -75,7 +75,7 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s
75 int ret; 75 int ret;
76 unsigned int cpid, bdid; 76 unsigned int cpid, bdid;
77 unsigned long long ecid; 77 unsigned long long ecid;
78 unsigned char srnm[12], imei[15], bt[15]; 78 char srnm[12], imei[15];
79 79
80 ret = irecv_get_cpid(client, &cpid); 80 ret = irecv_get_cpid(client, &cpid);
81 if(ret == IRECV_E_SUCCESS) { 81 if(ret == IRECV_E_SUCCESS) {
@@ -124,16 +124,16 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s
124 free(action); 124 free(action);
125} 125}
126 126
127void load_command_history() { 127static void load_command_history() {
128 read_history(FILE_HISTORY_PATH); 128 read_history(FILE_HISTORY_PATH);
129} 129}
130 130
131void append_command_to_history(char* cmd) { 131static void append_command_to_history(char* cmd) {
132 add_history(cmd); 132 add_history(cmd);
133 write_history(FILE_HISTORY_PATH); 133 write_history(FILE_HISTORY_PATH);
134} 134}
135 135
136void init_shell(irecv_client_t client) { 136static void init_shell(irecv_client_t client) {
137 irecv_error_t error = 0; 137 irecv_error_t error = 0;
138 load_command_history(); 138 load_command_history();
139 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); 139 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
@@ -175,9 +175,8 @@ int received_cb(irecv_client_t client, const irecv_event_t* event) {
175 175
176int precommand_cb(irecv_client_t client, const irecv_event_t* event) { 176int precommand_cb(irecv_client_t client, const irecv_event_t* event) {
177 if (event->type == IRECV_PRECOMMAND) { 177 if (event->type == IRECV_PRECOMMAND) {
178 irecv_error_t error = 0;
179 if (event->data[0] == '/') { 178 if (event->data[0] == '/') {
180 parse_command(client, event->data, event->size); 179 parse_command(client, (unsigned char*)event->data, event->size);
181 return -1; 180 return -1;
182 } 181 }
183 } 182 }
@@ -248,7 +247,7 @@ void print_progress_bar(double progress) {
248 } 247 }
249} 248}
250 249
251void print_usage() { 250static void print_usage() {
252 printf("iRecovery - iDevice Recovery Utility\n"); 251 printf("iRecovery - iDevice Recovery Utility\n");
253 printf("Usage: irecovery [args]\n"); 252 printf("Usage: irecovery [args]\n");
254 printf("\t-i <ecid>\tTarget specific device by its hexadecimal ECID\n"); 253 printf("\t-i <ecid>\tTarget specific device by its hexadecimal ECID\n");
diff --git a/src/libirecovery.c b/src/libirecovery.c
index 4419b50..4ca177b 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -135,7 +135,7 @@ typedef struct usb_control_request {
135 char data[]; 135 char data[];
136} usb_control_request; 136} usb_control_request;
137 137
138int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size); 138static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size);
139 139
140irecv_error_t mobiledevice_openpipes(irecv_client_t client); 140irecv_error_t mobiledevice_openpipes(irecv_client_t client);
141void mobiledevice_closepipes(irecv_client_t client); 141void mobiledevice_closepipes(irecv_client_t client);
@@ -369,7 +369,7 @@ void mobiledevice_closepipes(irecv_client_t client) {
369} 369}
370#endif 370#endif
371 371
372int check_context(irecv_client_t client) { 372static int check_context(irecv_client_t client) {
373 if (client == NULL || client->handle == NULL) { 373 if (client == NULL || client->handle == NULL) {
374 return IRECV_E_NO_DEVICE; 374 return IRECV_E_NO_DEVICE;
375 } 375 }
@@ -396,7 +396,7 @@ void irecv_exit() {
396 void dummy_callback() { } 396 void dummy_callback() { }
397#endif 397#endif
398 398
399int irecv_control_transfer( irecv_client_t client, 399static int irecv_control_transfer( irecv_client_t client,
400 uint8_t bmRequestType, 400 uint8_t bmRequestType,
401 uint8_t bRequest, 401 uint8_t bRequest,
402 uint16_t wValue, 402 uint16_t wValue,
@@ -448,7 +448,7 @@ int irecv_control_transfer( irecv_client_t client,
448#endif 448#endif
449} 449}
450 450
451int irecv_bulk_transfer(irecv_client_t client, 451static int irecv_bulk_transfer(irecv_client_t client,
452 unsigned char endpoint, 452 unsigned char endpoint,
453 unsigned char *data, 453 unsigned char *data,
454 int length, 454 int length,
@@ -473,7 +473,7 @@ int irecv_bulk_transfer(irecv_client_t client,
473 return ret; 473 return ret;
474} 474}
475 475
476int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) { 476static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) {
477#ifndef WIN32 477#ifndef WIN32
478 return libusb_get_string_descriptor_ascii(client->handle, desc_index, buffer, size); 478 return libusb_get_string_descriptor_ascii(client->handle, desc_index, buffer, size);
479#else 479#else
@@ -822,7 +822,7 @@ void irecv_set_debug_level(int level) {
822#endif 822#endif
823} 823}
824 824
825static irecv_error_t irecv_send_command_raw(irecv_client_t client, char* command) { 825static irecv_error_t irecv_send_command_raw(irecv_client_t client, const char* command) {
826 unsigned int length = strlen(command); 826 unsigned int length = strlen(command);
827 if (length >= 0x100) { 827 if (length >= 0x100) {
828 length = 0xFF; 828 length = 0xFF;
@@ -899,12 +899,12 @@ irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int d
899 return IRECV_E_UNKNOWN_ERROR; 899 return IRECV_E_UNKNOWN_ERROR;
900 } 900 }
901 901
902 irecv_error_t error = irecv_send_buffer(client, buffer, length, dfuNotifyFinished); 902 irecv_error_t error = irecv_send_buffer(client, (unsigned char*)buffer, length, dfuNotifyFinished);
903 free(buffer); 903 free(buffer);
904 return error; 904 return error;
905} 905}
906 906
907irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) { 907static irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) {
908 if (check_context(client) != IRECV_E_SUCCESS) { 908 if (check_context(client) != IRECV_E_SUCCESS) {
909 *status = 0; 909 *status = 0;
910 return IRECV_E_NO_DEVICE; 910 return IRECV_E_NO_DEVICE;
@@ -941,7 +941,7 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un
941 if (recovery_mode) { 941 if (recovery_mode) {
942 error = irecv_control_transfer(client, 0x41, 0, 0, 0, NULL, 0, USB_TIMEOUT); 942 error = irecv_control_transfer(client, 0x41, 0, 0, 0, NULL, 0, USB_TIMEOUT);
943 } else { 943 } else {
944 char dump[4]; 944 unsigned char dump[4];
945 if (irecv_control_transfer(client, 0xa1, 5, 0, 0, dump, 1, USB_TIMEOUT) == 1) { 945 if (irecv_control_transfer(client, 0xa1, 5, 0, 0, dump, 1, USB_TIMEOUT) == 1) {
946 error = IRECV_E_SUCCESS; 946 error = IRECV_E_SUCCESS;
947 } else { 947 } else {
@@ -953,7 +953,6 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un
953 } 953 }
954 954
955 int i = 0; 955 int i = 0;
956 double progress = 0;
957 unsigned long count = 0; 956 unsigned long count = 0;
958 unsigned int status = 0; 957 unsigned int status = 0;
959 int bytes = 0; 958 int bytes = 0;
@@ -986,7 +985,7 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un
986 newbuf[size+14] = (h1 >> 16) & 0xFF; 985 newbuf[size+14] = (h1 >> 16) & 0xFF;
987 newbuf[size+15] = (h1 >> 24) & 0xFF; 986 newbuf[size+15] = (h1 >> 24) & 0xFF;
988 size += 16; 987 size += 16;
989 bytes = irecv_control_transfer(client, 0x21, 1, i, 0, newbuf, size, USB_TIMEOUT); 988 bytes = irecv_control_transfer(client, 0x21, 1, i, 0, (unsigned char*)newbuf, size, USB_TIMEOUT);
990 free(newbuf); 989 free(newbuf);
991 } else { 990 } else {
992 bytes = irecv_control_transfer(client, 0x21, 1, i, 0, &buffer[i * packet_size], size, USB_TIMEOUT); 991 bytes = irecv_control_transfer(client, 0x21, 1, i, 0, &buffer[i * packet_size], size, USB_TIMEOUT);
@@ -1024,7 +1023,7 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un
1024 irecv_event_t event; 1023 irecv_event_t event;
1025 event.progress = ((double) count/ (double) length) * 100.0; 1024 event.progress = ((double) count/ (double) length) * 100.0;
1026 event.type = IRECV_PROGRESS; 1025 event.type = IRECV_PROGRESS;
1027 event.data = "Uploading"; 1026 event.data = (char*)"Uploading";
1028 event.size = count; 1027 event.size = count;
1029 client->progress_callback(client, &event); 1028 client->progress_callback(client, &event);
1030 } else { 1029 } else {
@@ -1174,13 +1173,13 @@ irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid) {
1174 return IRECV_E_SUCCESS; 1173 return IRECV_E_SUCCESS;
1175} 1174}
1176 1175
1177irecv_error_t irecv_get_srnm(irecv_client_t client, unsigned char* srnm) { 1176irecv_error_t irecv_get_srnm(irecv_client_t client, char* srnm) {
1178 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; 1177 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
1179 1178
1180 char* srnmp; 1179 char* srnmp;
1181 char* srnm_string = strstr(client->serial, "SRNM:["); 1180 char* srnm_string = strstr(client->serial, "SRNM:[");
1182 if(srnm_string == NULL) { 1181 if(srnm_string == NULL) {
1183 srnm = NULL; 1182 *srnm = 0;
1184 return IRECV_E_UNKNOWN_ERROR; 1183 return IRECV_E_UNKNOWN_ERROR;
1185 } 1184 }
1186 1185
@@ -1193,7 +1192,7 @@ irecv_error_t irecv_get_srnm(irecv_client_t client, unsigned char* srnm) {
1193 return IRECV_E_SUCCESS; 1192 return IRECV_E_SUCCESS;
1194} 1193}
1195 1194
1196irecv_error_t irecv_get_imei(irecv_client_t client, unsigned char* imei) { 1195irecv_error_t irecv_get_imei(irecv_client_t client, char* imei) {
1197 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; 1196 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
1198 1197
1199 char* imeip; 1198 char* imeip;
@@ -1231,7 +1230,7 @@ irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int*
1231 buf[len] = 0; 1230 buf[len] = 0;
1232 debug("%s: buf='%s'\n", __func__, buf); 1231 debug("%s: buf='%s'\n", __func__, buf);
1233 1232
1234 char* nonce_string = strstr(buf, "NONC:"); 1233 char* nonce_string = strstr((char*)buf, "NONC:");
1235 if (nonce_string == NULL) { 1234 if (nonce_string == NULL) {
1236 return IRECV_E_UNKNOWN_ERROR; 1235 return IRECV_E_UNKNOWN_ERROR;
1237 } 1236 }
@@ -1443,7 +1442,6 @@ irecv_error_t irecv_reset_counters(irecv_client_t client) {
1443} 1442}
1444 1443
1445irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length) { 1444irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length) {
1446 irecv_error_t error = 0;
1447 int recovery_mode = ((client->mode != kDfuMode) && (client->mode != kWTFMode)); 1445 int recovery_mode = ((client->mode != kDfuMode) && (client->mode != kWTFMode));
1448 1446
1449 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; 1447 if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE;
@@ -1459,12 +1457,10 @@ irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned lo
1459 1457
1460 int i = 0; 1458 int i = 0;
1461 int bytes = 0; 1459 int bytes = 0;
1462 double progress = 0;
1463 unsigned long count = 0; 1460 unsigned long count = 0;
1464 unsigned int status = 0;
1465 for (i = 0; i < packets; i++) { 1461 for (i = 0; i < packets; i++) {
1466 unsigned short size = (i+1) < packets ? packet_size : last; 1462 unsigned short size = (i+1) < packets ? packet_size : last;
1467 bytes = irecv_control_transfer(client, 0xA1, 2, 0, 0, &buffer[i * packet_size], size, USB_TIMEOUT); 1463 bytes = irecv_control_transfer(client, 0xA1, 2, 0, 0, (unsigned char*)&buffer[i * packet_size], size, USB_TIMEOUT);
1468 1464
1469 if (bytes != size) { 1465 if (bytes != size) {
1470 return IRECV_E_USB_UPLOAD; 1466 return IRECV_E_USB_UPLOAD;
@@ -1475,7 +1471,7 @@ irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned lo
1475 irecv_event_t event; 1471 irecv_event_t event;
1476 event.progress = ((double) count/ (double) length) * 100.0; 1472 event.progress = ((double) count/ (double) length) * 100.0;
1477 event.type = IRECV_PROGRESS; 1473 event.type = IRECV_PROGRESS;
1478 event.data = "Downloading"; 1474 event.data = (char*)"Downloading";
1479 event.size = count; 1475 event.size = count;
1480 client->progress_callback(client, &event); 1476 client->progress_callback(client, &event);
1481 } else { 1477 } else {
@@ -1650,7 +1646,7 @@ irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause) {
1650void irecv_hexdump(unsigned char* buf, unsigned int len, unsigned int addr) { 1646void irecv_hexdump(unsigned char* buf, unsigned int len, unsigned int addr) {
1651 int i, j; 1647 int i, j;
1652 printf("0x%08x: ", addr); 1648 printf("0x%08x: ", addr);
1653 for (i = 0; i < len; i++) { 1649 for (i = 0; i < (int)len; i++) {
1654 if (i % 16 == 0 && i != 0) { 1650 if (i % 16 == 0 && i != 0) {
1655 for (j=i-16; j < i; j++) { 1651 for (j=i-16; j < i; j++) {
1656 unsigned char car = buf[j]; 1652 unsigned char car = buf[j];