int main(int argc, char *argv[]) { printf("iRecovery - Recovery Utility\n"); printf("by westbaer\nThanks to pod2g, tom3q, planetbeing, geohot and posixninja.\n\n"); if(argc < 2) { irecv_usage(); return -1; } struct usb_dev_handle* handle = irecv_init(RECV_MODE); if (handle == NULL) { handle = irecv_init(WTF_MODE); if (handle == NULL) { printf("No iPhone/iPod found.\n"); return -1; } else { printf("Found iPhone/iPod in DFU/WTF mode\n"); } } else { printf("Found iPhone/iPod in Recovery mode\n"); } if(!strcmp(argv[1], "-f")) { if(argc == 3) { irecv_upload(handle, argv[2]); } } else if(!strcmp(argv[1], "-c")) { if(argc >= 3) { irecv_command(handle, argc-2, &argv[2]); } } else if(!strcmp(argv[1], "-k")) { if(argc >= 3) { irecv_exploit(handle, argv[2]); } else { irecv_exploit(handle, NULL); } } else if(!strcmp(argv[1], "-s")) { if(argc >= 3) { irecv_console(handle, argv[2]); } else { irecv_console(handle, NULL); } } else if(!strcmp(argv[1], "-r")) { irecv_reset(handle); } else if (!strcmp(argv[1], "-l")) { irecv_list(handle, argv[2]); } else if (!strcmp(argv[1], "-x")) { if(argc == 3) { irecv_upload(handle, argv[2]); irecv_reset(handle); } } irecv_close(handle); return 0; }
int irecv_parse(struct usb_dev_handle* handle, char* command) { unsigned int status = 0; char* action = strtok(strdup(command), " "); if(!strcmp(action, "help")) { printf("Commands:\n"); printf("\t/exit\t\t\texit from recovery console.\n"); printf("\t/upload <file>\t\tupload file to device.\n"); printf("\t/exploit [payload]\tsend usb exploit packet.\n"); } else if(!strcmp(action, "exit")) { free(action); return -1; } else if(strcmp(action, "upload") == 0) { char* filename = strtok(NULL, " "); if(filename != NULL) { irecv_upload(handle, filename); } } else if(strcmp(action, "exploit") == 0) { char* payload = strtok(NULL, " "); if (payload != NULL) { irecv_exploit(handle, payload); } else { irecv_exploit(handle, NULL); } } free(action); return 0; }
int irecv_exploit(struct usb_dev_handle* handle, char* payload) { if(handle == NULL) { printf("irecv_exploit: Device has not been initialized!\n"); return -1; } if(payload != NULL) { if(irecv_upload(handle, payload) < 0) { printf("irecv_exploit: Error uploading payload!\n"); return -1; } } if(!usb_control_msg(handle, 0x21, 2, 0, 0, 0, 0, 1000)) { printf("irecv_exploit: Error sending exploit!\n"); return -1; } return 0; }
int main(int argc, char *argv[]) { printf("iRecovery - Recovery Utility\n"); printf("by westbaer\nThanks to pod2g, tom3q, planetbeing, geohot and posixninja.\n\n"); if(argc < 2) { irecv_usage(); return -1; } if(!strcmp(argv[1], "-q")) { enter_recovery(); } struct usb_dev_handle* handle = irecv_init(RECV_MODE); if (handle == NULL) { handle = irecv_init(WTF_MODE); if (handle == NULL) { printf("No iPhone/iPod found.\n"); return -1; } else { printf("Found iPhone/iPod in DFU/WTF mode\n"); } } else { printf("Found iPhone/iPod in Recovery mode\n"); } if (((irecv_command(handle, 1, "setenv auto-boot true")) == -1) || ((irecv_command(handle, 1, "saveenv")) == -1)) printf("Failed to set auto-boot"); if(!strcmp(argv[1], "-f")) { if(argc == 3) { irecv_upload(handle, argv[2]); } } else if(!strcmp(argv[1], "-c")) { if(argc >= 3) { irecv_command(handle, argc-2, &argv[2]); } } else if(!strcmp(argv[1], "-k")) { if(argc >= 3) { irecv_exploit(handle, argv[2]); } else { irecv_exploit(handle, NULL); } } else if(!strcmp(argv[1], "-k")) { if(argc >= 3) { irecv_exploit(handle, argv[2]); } } else if(!strcmp(argv[1], "-x40")) { if(argc >= 3) { irecv_sendrawusb0x40(handle, argv[2]); } } else if(!strcmp(argv[1], "-x21")) { if(argc >= 3) { irecv_sendrawusb0x21(handle, argv[2]); } } else if(!strcmp(argv[1], "-xA1")) { if(argc >= 3) { irecv_sendrawusb0xA1(handle, argv[2]); } } else if(!strcmp(argv[1], "-s")) { if(argc >= 3) { irecv_console(handle, argv[2]); } else { irecv_console(handle, NULL); } } else if(!strcmp(argv[1], "-r")) { irecv_reset(handle); } else if (!strcmp(argv[1], "-l")) { irecv_list(handle, argv[2]); } else if (!strcmp(argv[1], "-x")) { if (argc == 3) { irecv_upload(handle, argv[2]); irecv_reset(handle); } } irecv_close(handle); return 0; }