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_list(struct usb_dev_handle* handle, char* filename) { if (handle == NULL) { printf("irecv_list: Device has not been initialized!\n"); return -1; } //max command length char line[0x200]; FILE* script = fopen(filename, "rb"); if (script == NULL) { printf("irecv_list: unable to find file!\n"); return -1; } printf("\n"); //irecv_command(handle, temp_len, &line); while (fgets(line, 0x200, script) != NULL) { printf("irecv_list: sending> %s\n", line); char *command[1]; command[0] = line; irecv_command(handle, 1, command); } fclose(script); }
int irecv_list(struct usb_dev_handle* handle, char* filename) { if (handle == NULL) { printf("irecv_list: Device has not been initialized!\n"); return -1; } //max command length char line[0x200]; FILE* script = fopen(filename, "rb"); if (script == NULL) { printf("irecv_list: unable to find file!\n"); return -1; } printf("\n"); //irecv_command(handle, temp_len, &line); while (fgets(line, 0x200, script) != NULL) { if(!((line[0]=='/') && (line[1]=='/'))) { if(line[0] == '/') { printf("irecv_list: handling> %s", line); char byte; int offset=strlen(line)-1; while(offset>0) { if (line[offset]==0x0D || line[offset]==0x0A) line[offset--]=0x00; else break; }; irecv_parse(handle, &line[1]); } else { printf("irecv_list: sending> %s", line); char *command[1]; command[0] = line; irecv_command(handle, 1, command); } } } fclose(script); }
int irecv_console(struct usb_dev_handle *handle, char* logfile) { if(usb_set_configuration(handle, 1) < 0) { printf("irecv_console: Error setting configuration!\n"); return -1; } if(usb_claim_interface(handle, 1) < 0) { printf("irecv_console: Error claiming interface!\n"); return -1; } if(usb_set_altinterface(handle, 1) < 0) { printf("irecv_console: Error setting alt interface!\n"); return -1; } char* buffer = malloc(BUF_SIZE); if(buffer == NULL) { printf("irecv_console: Error allocating memory!\n"); return -1; } FILE* fd = NULL; if(logfile != NULL) { fd = fopen(logfile, "w"); if(fd == NULL) { printf("irecv_console: Unable to open log file!\n"); free(buffer); return -1; } } while(1) { int bytes = 0; while(bytes >= 0) { memset(buffer, 0, BUF_SIZE); bytes = usb_bulk_read(handle, 0x81, buffer, BUF_SIZE, 500); int i; for(i = 0; i < bytes; ++i) { fprintf(stdout, "%c", buffer[i]); if(fd) fprintf(fd, "%c", buffer[i]); } } char* command = readline("iRecovery> "); if(command && *command) { add_history(command); } if(command[0] == '/') { if(irecv_parse(handle, &command[1]) < 0) { free(command); break; } } else { if(irecv_command(handle, 1, &command) < 0) { free(command); break; } } free(command); } free(buffer); if(fd) fclose(fd); usb_release_interface(handle, 1); }
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; }