From 30fd56859f50dea5712492807a1b9784da9fec11 Mon Sep 17 00:00:00 2001 From: Joshua Hill Date: Sun, 30 May 2010 03:33:03 -0400 Subject: Implemented a few more events, got rid of the old ones and cleaned up a little --- src/irecovery.c | 106 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'src/irecovery.c') diff --git a/src/irecovery.c b/src/irecovery.c index d53cf9b..a763272 100644 --- a/src/irecovery.c +++ b/src/irecovery.c @@ -33,25 +33,28 @@ enum { static unsigned int quit = 0; static unsigned int verbose = 0; +int received_cb(irecv_client_t client, const irecv_event_t* event); int precommand_cb(irecv_client_t client, const irecv_event_t* event); int postcommand_cb(irecv_client_t client, const irecv_event_t* event); -void print_shell_usage() { +void shell_usage() { printf("Usage:\n"); printf("\t/upload \tSend file to client.\n"); + printf("\t/exploit [file]\tSend usb exploit with optional payload\n"); printf("\t/help\t\tShow this help.\n"); printf("\t/exit\t\tExit interactive shell.\n"); } void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { - char* cmd = strtok(strdup(command), " "); - debug("Executing %s %s\n", cmd, command); + char* cmd = strdup(command); + char* action = strtok(cmd, " "); + debug("Executing %s\n", action); if (!strcmp(cmd, "/exit")) { quit = 1; } else if (!strcmp(cmd, "/help")) { - print_shell_usage(); + shell_usage(); } else if (!strcmp(cmd, "/upload")) { @@ -60,22 +63,18 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s if (filename != NULL) { irecv_send_file(client, filename); } - } - free(cmd); -} + } else -int recv_callback(irecv_client_t client, unsigned char* data, int size) { - int i = 0; - for (i = 0; i < size; i++) { - printf("%c", data[i]); + if (!strcmp(cmd, "/exploit")) { + char* filename = strtok(NULL, " "); + debug("Sending %s\n", filename); + if (filename != NULL) { + irecv_send_file(client, filename); + } + irecv_send_exploit(client); } - return size; -} -int send_callback(irecv_client_t client, unsigned char* command, int size) { - - - return size; + free(action); } void load_command_history() { @@ -90,7 +89,7 @@ void append_command_to_history(char* cmd) { void init_shell(irecv_client_t client) { irecv_error_t error = 0; load_command_history(); - irecv_set_receiver(client, &recv_callback); + irecv_event_subscribe(client, IRECV_RECEIVED, &received_cb, NULL); irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL); irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); while (!quit) { @@ -113,49 +112,64 @@ void init_shell(irecv_client_t client) { } } -void print_usage() { - printf("iRecovery - iDevice Recovery Utility\n"); - printf("Usage: ./irecovery [args]\n"); - printf("\t-v\t\tStart irecovery in verbose mode.\n"); - printf("\t-c \tSend command to client.\n"); - printf("\t-f \tSend file to client.\n"); - printf("\t-k [exploit]\tSend usb exploit to client.\n"); - printf("\t-h\t\tShow this help.\n"); - printf("\t-r\t\tReset client.\n"); - printf("\t-s\t\tStart interactive shell.\n"); - exit(1); +int received_cb(irecv_client_t client, const irecv_event_t* event) { + if (event->type == IRECV_RECEIVED) { + int i = 0; + int size = event->size; + char* data = event->data; + for (i = 0; i < size; i++) { + printf("%c", data[i]); + } + } + return 0; } int precommand_cb(irecv_client_t client, const irecv_event_t* event) { - irecv_error_t error = 0; - if (event->data[0] == '/') { - parse_command(client, event->data, strlen(event->data)); - return -1; + if (event->type == IRECV_PRECOMMAND) { + irecv_error_t error = 0; + if (event->data[0] == '/') { + parse_command(client, event->data, event->size); + return -1; + } } return 0; } int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { - irecv_error_t error = 0; - if (strstr(event->data, "getenv") != NULL) { - unsigned char* value = NULL; - error = irecv_getenv(client, &value); - if (error != IRECV_E_SUCCESS) { - debug("%s\n", irecv_strerror(error)); - return error; + unsigned char* value = NULL; + if (event->type == IRECV_POSTCOMMAND) { + irecv_error_t error = 0; + if (strstr(event->data, "getenv") != NULL) { + error = irecv_getenv(client, &value); + if (error != IRECV_E_SUCCESS) { + debug("%s\n", irecv_strerror(error)); + return error; + } + printf("%s\n", value); } - printf("%s\n", value); - free(value); - } - - if (!strcmp(event->data, "reboot")) { - quit = 1; + if (!strcmp(event->data, "reboot")) { + quit = 1; + } } + if (value != NULL) free(value); return 0; } +void print_usage() { + printf("iRecovery - iDevice Recovery Utility\n"); + printf("Usage: ./irecovery [args]\n"); + printf("\t-v\t\tStart irecovery in verbose mode.\n"); + printf("\t-c \tSend command to client.\n"); + printf("\t-f \tSend file to client.\n"); + printf("\t-k [payload]\tSend usb exploit to client.\n"); + printf("\t-h\t\tShow this help.\n"); + printf("\t-r\t\tReset client.\n"); + printf("\t-s\t\tStart interactive shell.\n"); + exit(1); +} + int main(int argc, char** argv) { int i = 0; int opt = 0; -- cgit v1.1-32-gdbae