diff options
Diffstat (limited to 'src/irecovery.c')
| -rw-r--r-- | src/irecovery.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/irecovery.c b/src/irecovery.c index 90f975b..51320a5 100644 --- a/src/irecovery.c +++ b/src/irecovery.c | |||
| @@ -17,9 +17,50 @@ | |||
| 17 | **/ | 17 | **/ |
| 18 | 18 | ||
| 19 | #include <stdio.h> | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> | ||
| 21 | #include <unistd.h> | ||
| 20 | #include <libirecovery.h> | 22 | #include <libirecovery.h> |
| 21 | 23 | ||
| 24 | enum { | ||
| 25 | kResetDevice, kSendCommand | ||
| 26 | }; | ||
| 27 | |||
| 28 | void print_usage() { | ||
| 29 | printf("iRecovery - iDevice Recovery Utility\n"); | ||
| 30 | printf("Usage: ./irecovery [args]\n"); | ||
| 31 | exit(1); | ||
| 32 | } | ||
| 33 | |||
| 22 | int main(int argc, char** argv) { | 34 | int main(int argc, char** argv) { |
| 35 | int opt = 0; | ||
| 36 | int action = 0; | ||
| 37 | char* argument = NULL; | ||
| 38 | if(argc == 1) print_usage(); | ||
| 39 | while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { | ||
| 40 | switch (opt) { | ||
| 41 | case 'd': | ||
| 42 | irecv_set_debug(1); | ||
| 43 | break; | ||
| 44 | |||
| 45 | case 'h': | ||
| 46 | print_usage(); | ||
| 47 | break; | ||
| 48 | |||
| 49 | case 'r': | ||
| 50 | action = kResetDevice; | ||
| 51 | break; | ||
| 52 | |||
| 53 | case 'c': | ||
| 54 | argument = optarg; | ||
| 55 | action = kSendCommand; | ||
| 56 | break; | ||
| 57 | |||
| 58 | default: | ||
| 59 | fprintf(stderr, "Unknown argument\n"); | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 23 | irecv_device* device = NULL; | 64 | irecv_device* device = NULL; |
| 24 | if(irecv_init(&device) < 0) { | 65 | if(irecv_init(&device) < 0) { |
| 25 | fprintf(stderr, "Unable to initialize libirecovery\n"); | 66 | fprintf(stderr, "Unable to initialize libirecovery\n"); |
| @@ -31,27 +72,20 @@ int main(int argc, char** argv) { | |||
| 31 | return -1; | 72 | return -1; |
| 32 | } | 73 | } |
| 33 | 74 | ||
| 34 | switch (device->mode) { | 75 | switch(action) { |
| 35 | case kRecoveryMode: | 76 | case kResetDevice: |
| 36 | printf("Found device in recovery mode\n"); | 77 | irecv_reset(device); |
| 37 | break; | 78 | break; |
| 38 | 79 | ||
| 39 | case kDfuMode: | 80 | case kSendCommand: |
| 40 | printf("Found device in DFU mode\n"); | 81 | irecv_command(device, argument); |
| 41 | break; | ||
| 42 | |||
| 43 | case kKernelMode: | ||
| 44 | printf("Found device in kernel mode\n"); | ||
| 45 | break; | 82 | break; |
| 46 | 83 | ||
| 47 | default: | 84 | default: |
| 48 | printf("No device found\n"); | 85 | fprintf(stderr, "Unknown action\n"); |
| 49 | break; | 86 | break; |
| 50 | } | 87 | } |
| 51 | 88 | ||
| 52 | printf("Sending USB reset...\n"); | ||
| 53 | irecv_reset(device); | ||
| 54 | |||
| 55 | irecv_exit(device); | 89 | irecv_exit(device); |
| 56 | return 0; | 90 | return 0; |
| 57 | } | 91 | } |
