diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/irecovery.c | 51 | 
2 files changed, 52 insertions, 5 deletions
| @@ -9,15 +9,15 @@ static:  linux:  	gcc -o libirecovery.o -c src/libirecovery.c -g -I./include -lreadline -fPIC   	gcc -o libirecovery.so libirecovery.o -g -shared -Wl,-soname,libirecovery.so -lusb-1.0 -	gcc -o irecovery src/irecovery.c -g -I./include -L. -lirecovery +	gcc -o irecovery src/irecovery.c -g -I./include -L. -lirecovery -lreadline  macosx:  	gcc -o libirecovery.dylib -c src/libirecovery.c -dynamiclib -	gcc -o irecovery irecovery.c -I. -lirecovery +	gcc -o irecovery irecovery.c -I. -lirecovery -lreadline  windows:  	gcc -o libirecovery.dll -c src/libirecovery.c -I. -lusb-1.0 -lreadline -shared -fPIC -	gcc -o irecovery irecovery.c -I. -lirecovery +	gcc -o irecovery irecovery.c -I. -lirecovery -lreadline  clean:  	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 @@  #include <stdlib.h>  #include <unistd.h>  #include <libirecovery.h> +#include <readline/readline.h> +#include <readline/history.h>  enum { -	kResetDevice, kSendCommand, kSendFile +	kResetDevice, kStartShell, kSendCommand, kSendFile  }; +void print_shell_usage() { +	printf("Usage:\n"); +	printf("\t:f <file>\tSend file to device.\n"); +	printf("\t:h\t\tShow this help.\n"); +	printf("\t:q\t\tQuit interactive shell.\n"); +} + +void init_shell(irecv_device* device) { +	int ret; + +	for(;;) { +		char* cmd = readline("iRecovery> "); +		if(cmd && *cmd) { +			add_history(cmd); +			if(cmd[0] == ':') { +				strtok(cmd, " "); +				char* arg = strtok(0, " "); +				 +				if(cmd[1] == 'q') { +					break; +				} else if(cmd[1] == 'h') { +					print_shell_usage(); +				} else if(cmd[1] == 'f') { +					ret = irecv_send_file(device, arg); +					// TODO: error messages +				} +			} else { +				ret = irecv_send_command(device, cmd); +				// TODO: error messages +			} + +			free(cmd); +		} +	} +} +  void print_usage() {  	printf("iRecovery - iDevice Recovery Utility\n");  	printf("Usage: ./irecovery [args]\n"); @@ -33,6 +71,7 @@ void print_usage() {  	printf("\t-f <file>\tSend file to device.\n");  	printf("\t-h\t\tShow this help.\n");  	printf("\t-r\t\tReset device.\n"); +	printf("\t-s\t\tStart interactive shell.\n");  	exit(1);  } @@ -41,7 +80,7 @@ int main(int argc, char** argv) {  	int action = 0;  	char* argument = NULL;  	if(argc == 1) print_usage(); -	while ((opt = getopt(argc, argv, "dhrc:f:")) > 0) { +	while ((opt = getopt(argc, argv, "dhrsc:f:")) > 0) {  		switch (opt) {  		case 'd':  			irecv_set_debug(1); @@ -55,6 +94,10 @@ int main(int argc, char** argv) {  			action = kResetDevice;  			break; +		case 's': +			action = kStartShell; +			break; +  		case 'c':  			action = kSendCommand;  			argument = optarg; @@ -95,6 +138,10 @@ int main(int argc, char** argv) {  		irecv_send_command(device, argument);  		break; +	case kStartShell: +		init_shell(device); +		break; +  	default:  		fprintf(stderr, "Unknown action\n");  		break; | 
