diff options
| author | 2010-05-14 16:15:39 +0200 | |
|---|---|---|
| committer | 2010-05-14 16:15:39 +0200 | |
| commit | 2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08 (patch) | |
| tree | 81781824d0b76aa87b5ed4183c30cc2a5f695f09 | |
| parent | 47d6d8f3289c705144629a2658079c4dae9fb0c3 (diff) | |
| download | libirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.gz libirecovery-2d126cde8a31ec79d7c728cecbdd8e5b55fc7e08.tar.bz2 | |
Added shell with 'internal' commands using readline.
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/irecovery.c | 51 |
2 files changed, 52 insertions, 5 deletions
| @@ -9,15 +9,15 @@ static: | |||
| 9 | linux: | 9 | linux: |
| 10 | gcc -o libirecovery.o -c src/libirecovery.c -g -I./include -lreadline -fPIC | 10 | gcc -o libirecovery.o -c src/libirecovery.c -g -I./include -lreadline -fPIC |
| 11 | gcc -o libirecovery.so libirecovery.o -g -shared -Wl,-soname,libirecovery.so -lusb-1.0 | 11 | gcc -o libirecovery.so libirecovery.o -g -shared -Wl,-soname,libirecovery.so -lusb-1.0 |
| 12 | gcc -o irecovery src/irecovery.c -g -I./include -L. -lirecovery | 12 | gcc -o irecovery src/irecovery.c -g -I./include -L. -lirecovery -lreadline |
| 13 | 13 | ||
| 14 | macosx: | 14 | macosx: |
| 15 | gcc -o libirecovery.dylib -c src/libirecovery.c -dynamiclib | 15 | gcc -o libirecovery.dylib -c src/libirecovery.c -dynamiclib |
| 16 | gcc -o irecovery irecovery.c -I. -lirecovery | 16 | gcc -o irecovery irecovery.c -I. -lirecovery -lreadline |
| 17 | 17 | ||
| 18 | windows: | 18 | windows: |
| 19 | gcc -o libirecovery.dll -c src/libirecovery.c -I. -lusb-1.0 -lreadline -shared -fPIC | 19 | gcc -o libirecovery.dll -c src/libirecovery.c -I. -lusb-1.0 -lreadline -shared -fPIC |
| 20 | gcc -o irecovery irecovery.c -I. -lirecovery | 20 | gcc -o irecovery irecovery.c -I. -lirecovery -lreadline |
| 21 | 21 | ||
| 22 | clean: | 22 | clean: |
| 23 | rm -rf irecovery libirecovery.o libirecovery.so libirecovery.a | 23 | rm -rf irecovery libirecovery.o libirecovery.so libirecovery.a |
diff --git a/src/irecovery.c b/src/irecovery.c index e2696d9..13d8be1 100644 --- a/src/irecovery.c +++ b/src/irecovery.c | |||
| @@ -20,11 +20,49 @@ | |||
| 20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
| 21 | #include <unistd.h> | 21 | #include <unistd.h> |
| 22 | #include <libirecovery.h> | 22 | #include <libirecovery.h> |
| 23 | #include <readline/readline.h> | ||
| 24 | #include <readline/history.h> | ||
| 23 | 25 | ||
| 24 | enum { | 26 | enum { |
| 25 | kResetDevice, kSendCommand, kSendFile | 27 | kResetDevice, kStartShell, kSendCommand, kSendFile |
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| 30 | void print_shell_usage() { | ||
| 31 | printf("Usage:\n"); | ||
| 32 | printf("\t:f <file>\tSend file to device.\n"); | ||
| 33 | printf("\t:h\t\tShow this help.\n"); | ||
| 34 | printf("\t:q\t\tQuit interactive shell.\n"); | ||
| 35 | } | ||
| 36 | |||
| 37 | void init_shell(irecv_device* device) { | ||
| 38 | int ret; | ||
| 39 | |||
| 40 | for(;;) { | ||
| 41 | char* cmd = readline("iRecovery> "); | ||
| 42 | if(cmd && *cmd) { | ||
| 43 | add_history(cmd); | ||
| 44 | if(cmd[0] == ':') { | ||
| 45 | strtok(cmd, " "); | ||
| 46 | char* arg = strtok(0, " "); | ||
| 47 | |||
| 48 | if(cmd[1] == 'q') { | ||
| 49 | break; | ||
| 50 | } else if(cmd[1] == 'h') { | ||
| 51 | print_shell_usage(); | ||
| 52 | } else if(cmd[1] == 'f') { | ||
| 53 | ret = irecv_send_file(device, arg); | ||
| 54 | // TODO: error messages | ||
| 55 | } | ||
| 56 | } else { | ||
| 57 | ret = irecv_send_command(device, cmd); | ||
| 58 | // TODO: error messages | ||
| 59 | } | ||
| 60 | |||
| 61 | free(cmd); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 28 | void print_usage() { | 66 | void print_usage() { |
| 29 | printf("iRecovery - iDevice Recovery Utility\n"); | 67 | printf("iRecovery - iDevice Recovery Utility\n"); |
| 30 | printf("Usage: ./irecovery [args]\n"); | 68 | printf("Usage: ./irecovery [args]\n"); |
| @@ -33,6 +71,7 @@ void print_usage() { | |||
| 33 | printf("\t-f <file>\tSend file to device.\n"); | 71 | printf("\t-f <file>\tSend file to device.\n"); |
| 34 | printf("\t-h\t\tShow this help.\n"); | 72 | printf("\t-h\t\tShow this help.\n"); |
| 35 | printf("\t-r\t\tReset device.\n"); | 73 | printf("\t-r\t\tReset device.\n"); |
| 74 | printf("\t-s\t\tStart interactive shell.\n"); | ||
| 36 | exit(1); | 75 | exit(1); |
| 37 | } | 76 | } |
| 38 | 77 | ||
| @@ -41,7 +80,7 @@ int main(int argc, char** argv) { | |||
| 41 | int action = 0; | 80 | int action = 0; |
| 42 | char* argument = NULL; | 81 | char* argument = NULL; |
| 43 | if(argc == 1) print_usage(); | 82 | if(argc == 1) print_usage(); |
| 44 | while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { | 83 | while ((opt = getopt(argc, argv, "dhrsc:f:")) > 0) { |
| 45 | switch (opt) { | 84 | switch (opt) { |
| 46 | case 'd': | 85 | case 'd': |
| 47 | irecv_set_debug(1); | 86 | irecv_set_debug(1); |
| @@ -55,6 +94,10 @@ int main(int argc, char** argv) { | |||
| 55 | action = kResetDevice; | 94 | action = kResetDevice; |
| 56 | break; | 95 | break; |
| 57 | 96 | ||
| 97 | case 's': | ||
| 98 | action = kStartShell; | ||
| 99 | break; | ||
| 100 | |||
| 58 | case 'c': | 101 | case 'c': |
| 59 | action = kSendCommand; | 102 | action = kSendCommand; |
| 60 | argument = optarg; | 103 | argument = optarg; |
| @@ -95,6 +138,10 @@ int main(int argc, char** argv) { | |||
| 95 | irecv_send_command(device, argument); | 138 | irecv_send_command(device, argument); |
| 96 | break; | 139 | break; |
| 97 | 140 | ||
| 141 | case kStartShell: | ||
| 142 | init_shell(device); | ||
| 143 | break; | ||
| 144 | |||
| 98 | default: | 145 | default: |
| 99 | fprintf(stderr, "Unknown action\n"); | 146 | fprintf(stderr, "Unknown action\n"); |
| 100 | break; | 147 | break; |
