diff options
Diffstat (limited to 'src/irecovery.c')
| -rw-r--r-- | src/irecovery.c | 42 |
1 files changed, 32 insertions, 10 deletions
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 @@ | |||
| 27 | #define debug(...) if(verbose) fprintf(stderr, __VA_ARGS__) | 27 | #define debug(...) if(verbose) fprintf(stderr, __VA_ARGS__) |
| 28 | 28 | ||
| 29 | enum { | 29 | enum { |
| 30 | kResetDevice, kStartShell, kSendCommand, kSendFile, kSendExploit | 30 | kResetDevice, kStartShell, kSendCommand, kSendFile, kSendExploit, kSendScript |
| 31 | }; | 31 | }; |
| 32 | 32 | ||
| 33 | static unsigned int quit = 0; | 33 | static unsigned int quit = 0; |
| 34 | static unsigned int verbose = 0; | 34 | static unsigned int verbose = 0; |
| 35 | 35 | ||
| 36 | void print_progress_bar(const char* operation, double progress); | 36 | void print_progress_bar(double progress); |
| 37 | int received_cb(irecv_client_t client, const irecv_event_t* event); | 37 | int received_cb(irecv_client_t client, const irecv_event_t* event); |
| 38 | int progress_cb(irecv_client_t client, const irecv_event_t* event); | 38 | int progress_cb(irecv_client_t client, const irecv_event_t* event); |
| 39 | int precommand_cb(irecv_client_t client, const irecv_event_t* event); | 39 | 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 | |||
| 61 | 61 | ||
| 62 | if (!strcmp(cmd, "/upload")) { | 62 | if (!strcmp(cmd, "/upload")) { |
| 63 | char* filename = strtok(NULL, " "); | 63 | char* filename = strtok(NULL, " "); |
| 64 | debug("Sending %s\n", filename); | 64 | debug("Uploading files %s\n", filename); |
| 65 | if (filename != NULL) { | 65 | if (filename != NULL) { |
| 66 | irecv_send_file(client, filename); | 66 | irecv_send_file(client, filename); |
| 67 | } | 67 | } |
| @@ -69,12 +69,21 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s | |||
| 69 | 69 | ||
| 70 | if (!strcmp(cmd, "/exploit")) { | 70 | if (!strcmp(cmd, "/exploit")) { |
| 71 | char* filename = strtok(NULL, " "); | 71 | char* filename = strtok(NULL, " "); |
| 72 | debug("Sending %s\n", filename); | 72 | debug("Sending exploit %s\n", filename); |
| 73 | if (filename != NULL) { | 73 | if (filename != NULL) { |
| 74 | irecv_send_file(client, filename); | 74 | irecv_send_file(client, filename); |
| 75 | } | 75 | } |
| 76 | irecv_send_exploit(client); | 76 | irecv_send_exploit(client); |
| 77 | } | 77 | } else |
| 78 | |||
| 79 | if (!strcmp(cmd, "/execute")) { | ||
| 80 | char* filename = strtok(NULL, " "); | ||
| 81 | debug("Executing script %s\n", filename); | ||
| 82 | if (filename != NULL) { | ||
| 83 | irecv_execute_script(client, filename); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 78 | 87 | ||
| 79 | free(action); | 88 | free(action); |
| 80 | } | 89 | } |
| @@ -171,12 +180,12 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { | |||
| 171 | 180 | ||
| 172 | int progress_cb(irecv_client_t client, const irecv_event_t* event) { | 181 | int progress_cb(irecv_client_t client, const irecv_event_t* event) { |
| 173 | if (event->type == IRECV_PROGRESS) { | 182 | if (event->type == IRECV_PROGRESS) { |
| 174 | print_progress_bar(event->data, event->progress); | 183 | print_progress_bar(event->progress); |
| 175 | } | 184 | } |
| 176 | return 0; | 185 | return 0; |
| 177 | } | 186 | } |
| 178 | 187 | ||
| 179 | void print_progress_bar(const char* operation, double progress) { | 188 | void print_progress_bar(double progress) { |
| 180 | int i = 0; | 189 | int i = 0; |
| 181 | if(progress < 0) { | 190 | if(progress < 0) { |
| 182 | return; | 191 | return; |
| @@ -186,7 +195,7 @@ void print_progress_bar(const char* operation, double progress) { | |||
| 186 | progress = 100; | 195 | progress = 100; |
| 187 | } | 196 | } |
| 188 | 197 | ||
| 189 | printf("\r%s [", operation); | 198 | printf("\r["); |
| 190 | for(i = 0; i < 50; i++) { | 199 | for(i = 0; i < 50; i++) { |
| 191 | if(i < progress / 2) { | 200 | if(i < progress / 2) { |
| 192 | printf("="); | 201 | printf("="); |
| @@ -212,6 +221,7 @@ void print_usage() { | |||
| 212 | printf("\t-h\t\tShow this help.\n"); | 221 | printf("\t-h\t\tShow this help.\n"); |
| 213 | printf("\t-r\t\tReset client.\n"); | 222 | printf("\t-r\t\tReset client.\n"); |
| 214 | printf("\t-s\t\tStart interactive shell.\n"); | 223 | printf("\t-s\t\tStart interactive shell.\n"); |
| 224 | printf("\t-e <script>\tExecutes recovery shell script."); | ||
| 215 | exit(1); | 225 | exit(1); |
| 216 | } | 226 | } |
| 217 | 227 | ||
| @@ -222,7 +232,7 @@ int main(int argc, char** argv) { | |||
| 222 | char* argument = NULL; | 232 | char* argument = NULL; |
| 223 | irecv_error_t error = 0; | 233 | irecv_error_t error = 0; |
| 224 | if (argc == 1) print_usage(); | 234 | if (argc == 1) print_usage(); |
| 225 | while ((opt = getopt(argc, argv, "vhrsc:f:k::")) > 0) { | 235 | while ((opt = getopt(argc, argv, "vhrsc:f:e:k::")) > 0) { |
| 226 | switch (opt) { | 236 | switch (opt) { |
| 227 | case 'v': | 237 | case 'v': |
| 228 | verbose += 1; | 238 | verbose += 1; |
| @@ -255,6 +265,11 @@ int main(int argc, char** argv) { | |||
| 255 | argument = optarg; | 265 | argument = optarg; |
| 256 | break; | 266 | break; |
| 257 | 267 | ||
| 268 | case 'e': | ||
| 269 | action = kSendScript; | ||
| 270 | argument = optarg; | ||
| 271 | break; | ||
| 272 | |||
| 258 | default: | 273 | default: |
| 259 | fprintf(stderr, "Unknown argument\n"); | 274 | fprintf(stderr, "Unknown argument\n"); |
| 260 | return -1; | 275 | return -1; |
| @@ -275,7 +290,7 @@ int main(int argc, char** argv) { | |||
| 275 | } | 290 | } |
| 276 | } | 291 | } |
| 277 | 292 | ||
| 278 | if (verbose) irecv_set_debug(client, verbose); | 293 | if (verbose) irecv_set_debug_level(verbose); |
| 279 | 294 | ||
| 280 | switch (action) { | 295 | switch (action) { |
| 281 | case kResetDevice: | 296 | case kResetDevice: |
| @@ -310,6 +325,13 @@ int main(int argc, char** argv) { | |||
| 310 | init_shell(client); | 325 | init_shell(client); |
| 311 | break; | 326 | break; |
| 312 | 327 | ||
| 328 | case kSendScript: | ||
| 329 | error = irecv_execute_script(client, argument); | ||
| 330 | if(error != IRECV_E_SUCCESS) { | ||
| 331 | debug("%s\n", irecv_strerror(error)); | ||
| 332 | } | ||
| 333 | break; | ||
| 334 | |||
| 313 | default: | 335 | default: |
| 314 | fprintf(stderr, "Unknown action\n"); | 336 | fprintf(stderr, "Unknown action\n"); |
| 315 | break; | 337 | break; |
