From c2249545efe5451f25e08fbc57e19b9c91a855c5 Mon Sep 17 00:00:00 2001 From: Joshua Hill Date: Wed, 16 Jun 2010 03:38:47 -0400 Subject: Changed debug variable to be a static global variable to allow set once always enabled style debug flag Added -e flag to load and execute a premade script file along with a sample script --- TODO | 25 +++++---- include/libirecovery.h | 5 +- scripts/test.irs | 21 ++++++++ src/irecovery.c | 42 +++++++++++---- src/libirecovery.c | 142 ++++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 184 insertions(+), 51 deletions(-) create mode 100644 scripts/test.irs diff --git a/TODO b/TODO index 306a1ae..411f6e6 100644 --- a/TODO +++ b/TODO @@ -1,16 +1,15 @@ TODO List ------------------------------------------------ -1) libirecovery debug should be as static variable so the client doesn't need to be passed and can be set only once. -2) Need to implement irecv_saveenv() -3) Need to implement irecv_bootx() -4) Neex to implement irecv_go() -5) Need to implement irecv_bgcolor() -6) Need to implememt irecv_setpicture() -7) Need to impelemnt irecv_reboot() -8) Should figure out a better place to store callbacks so the CONNECTED callback can actually be used -9) would be nice to change to use asyncronous connections -10) could add a function to identify whether we're connected to iBoot/iBEC/iBSS or DFU -11) could add a function to identify which version we're connected to -12) could add a function to return the device serial number -13) fix command parsing to strip quotes \ No newline at end of file +o) Need to implement irecv_saveenv() +o) Need to implement irecv_bootx() +o) Neex to implement irecv_go() +o) Need to implement irecv_bgcolor() +o) Need to implememt irecv_setpicture() +o) Need to impelemnt irecv_reboot() +o) Should figure out a better place to store callbacks so the CONNECTED callback can actually be used +o) would be nice to change to use asyncronous connections +o) could add a function to identify whether we're connected to iBoot/iBEC/iBSS or DFU +o) could add a function to identify which version we're connected to +o) could add a function to return the device serial number +o) fix command parsing to strip quotes \ No newline at end of file diff --git a/include/libirecovery.h b/include/libirecovery.h index 50ec5be..d30dd73 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h @@ -71,7 +71,6 @@ struct irecv_client { int interface; int alt_interface; unsigned short mode; - libusb_context* context; libusb_device_handle* handle; irecv_event_cb_t progress_callback; irecv_event_cb_t received_callback; @@ -89,12 +88,12 @@ irecv_error_t irecv_reset(irecv_client_t client); irecv_error_t irecv_close(irecv_client_t client); irecv_error_t irecv_receive(irecv_client_t client); irecv_error_t irecv_send_exploit(irecv_client_t client); -irecv_error_t irecv_set_debug(irecv_client_t client, int level); +void irecv_set_debug_level(int level); +irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename); irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value); irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid); irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid); irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid); -irecv_error_t irecv_send(irecv_client_t client, unsigned char* command); irecv_error_t irecv_send_file(irecv_client_t client, const char* filename); irecv_error_t irecv_send_command(irecv_client_t client, unsigned char* command); irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration); diff --git a/scripts/test.irs b/scripts/test.irs new file mode 100644 index 0000000..77f959d --- /dev/null +++ b/scripts/test.irs @@ -0,0 +1,21 @@ +# This small script should make the device flash +# Red, Green, Blue a few times then reboot. +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +bgcolor 255 0 0 +bgcolor 0 255 0 +bgcolor 0 0 255 +reboot diff --git a/src/irecovery.c b/src/irecovery.c index baae17e..c282cda 100644 --- a/src/irecovery.c +++ b/src/irecovery.c @@ -27,13 +27,13 @@ #define debug(...) if(verbose) fprintf(stderr, __VA_ARGS__) enum { - kResetDevice, kStartShell, kSendCommand, kSendFile, kSendExploit + kResetDevice, kStartShell, kSendCommand, kSendFile, kSendExploit, kSendScript }; static unsigned int quit = 0; static unsigned int verbose = 0; -void print_progress_bar(const char* operation, double progress); +void print_progress_bar(double progress); int received_cb(irecv_client_t client, const irecv_event_t* event); int progress_cb(irecv_client_t client, const irecv_event_t* event); int precommand_cb(irecv_client_t client, const irecv_event_t* event); @@ -61,7 +61,7 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s if (!strcmp(cmd, "/upload")) { char* filename = strtok(NULL, " "); - debug("Sending %s\n", filename); + debug("Uploading files %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename); } @@ -69,12 +69,21 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s if (!strcmp(cmd, "/exploit")) { char* filename = strtok(NULL, " "); - debug("Sending %s\n", filename); + debug("Sending exploit %s\n", filename); if (filename != NULL) { irecv_send_file(client, filename); } irecv_send_exploit(client); - } + } else + + if (!strcmp(cmd, "/execute")) { + char* filename = strtok(NULL, " "); + debug("Executing script %s\n", filename); + if (filename != NULL) { + irecv_execute_script(client, filename); + } + } + free(action); } @@ -171,12 +180,12 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { int progress_cb(irecv_client_t client, const irecv_event_t* event) { if (event->type == IRECV_PROGRESS) { - print_progress_bar(event->data, event->progress); + print_progress_bar(event->progress); } return 0; } -void print_progress_bar(const char* operation, double progress) { +void print_progress_bar(double progress) { int i = 0; if(progress < 0) { return; @@ -186,7 +195,7 @@ void print_progress_bar(const char* operation, double progress) { progress = 100; } - printf("\r%s [", operation); + printf("\r["); for(i = 0; i < 50; i++) { if(i < progress / 2) { printf("="); @@ -212,6 +221,7 @@ void print_usage() { printf("\t-h\t\tShow this help.\n"); printf("\t-r\t\tReset client.\n"); printf("\t-s\t\tStart interactive shell.\n"); + printf("\t-e