summaryrefslogtreecommitdiffstats
path: root/tools/irecovery.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-05-13 03:37:38 +0200
committerGravatar Nikias Bassen2023-05-13 03:37:38 +0200
commit0360cdc603abbfbce76c4c10d20cf80d98c0b1d6 (patch)
tree6771cee2c78aeb43f0bb900384e299b745b8284c /tools/irecovery.c
parent3b4ef6a3d109702694435087311258355df1b63a (diff)
downloadlibirecovery-0360cdc603abbfbce76c4c10d20cf80d98c0b1d6.tar.gz
libirecovery-0360cdc603abbfbce76c4c10d20cf80d98c0b1d6.tar.bz2
Coding style changes
Diffstat (limited to 'tools/irecovery.c')
-rw-r--r--tools/irecovery.c61
1 files changed, 38 insertions, 23 deletions
diff --git a/tools/irecovery.c b/tools/irecovery.c
index faf0a92..34e80bf 100644
--- a/tools/irecovery.c
+++ b/tools/irecovery.c
@@ -2,7 +2,7 @@
2 * irecovery.c 2 * irecovery.c
3 * Software frontend for iBoot/iBSS communication with iOS devices 3 * Software frontend for iBoot/iBSS communication with iOS devices
4 * 4 *
5 * Copyright (c) 2012-2020 Nikias Bassen <nikias@gmx.li> 5 * Copyright (c) 2012-2023 Nikias Bassen <nikias@gmx.li>
6 * Copyright (c) 2012-2015 Martin Szulecki <martin.szulecki@libimobiledevice.org> 6 * Copyright (c) 2012-2015 Martin Szulecki <martin.szulecki@libimobiledevice.org>
7 * Copyright (c) 2010-2011 Chronic-Dev Team 7 * Copyright (c) 2010-2011 Chronic-Dev Team
8 * Copyright (c) 2010-2011 Joshua Hill 8 * Copyright (c) 2010-2011 Joshua Hill
@@ -43,7 +43,7 @@
43#endif 43#endif
44 44
45#define FILE_HISTORY_PATH ".irecovery" 45#define FILE_HISTORY_PATH ".irecovery"
46#define debug(...) if(verbose) fprintf(stderr, __VA_ARGS__) 46#define debug(...) if (verbose) fprintf(stderr, __VA_ARGS__)
47 47
48enum { 48enum {
49 kNoAction, 49 kNoAction,
@@ -68,7 +68,8 @@ int progress_cb(irecv_client_t client, const irecv_event_t* event);
68int precommand_cb(irecv_client_t client, const irecv_event_t* event); 68int precommand_cb(irecv_client_t client, const irecv_event_t* event);
69int postcommand_cb(irecv_client_t client, const irecv_event_t* event); 69int postcommand_cb(irecv_client_t client, const irecv_event_t* event);
70 70
71static void shell_usage() { 71static void shell_usage()
72{
72 printf("Usage:\n"); 73 printf("Usage:\n");
73 printf(" /upload FILE\t\tsend FILE to device\n"); 74 printf(" /upload FILE\t\tsend FILE to device\n");
74 printf(" /limera1n [FILE]\trun limera1n exploit and send optional payload from FILE\n"); 75 printf(" /limera1n [FILE]\trun limera1n exploit and send optional payload from FILE\n");
@@ -77,7 +78,8 @@ static void shell_usage() {
77 printf(" /exit\t\t\texit interactive shell\n"); 78 printf(" /exit\t\t\texit interactive shell\n");
78} 79}
79 80
80static const char* mode_to_str(int mode) { 81static const char* mode_to_str(int mode)
82{
81 switch (mode) { 83 switch (mode) {
82 case IRECV_K_RECOVERY_MODE_1: 84 case IRECV_K_RECOVERY_MODE_1:
83 case IRECV_K_RECOVERY_MODE_2: 85 case IRECV_K_RECOVERY_MODE_2:
@@ -97,7 +99,8 @@ static const char* mode_to_str(int mode) {
97 } 99 }
98} 100}
99 101
100static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) { 102static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length)
103{
101 FILE *f; 104 FILE *f;
102 uint64_t size; 105 uint64_t size;
103 106
@@ -187,7 +190,8 @@ static void print_device_info(irecv_client_t client)
187 } 190 }
188} 191}
189 192
190static void print_devices() { 193static void print_devices()
194{
191 struct irecv_device *devices = irecv_devices_get_all(); 195 struct irecv_device *devices = irecv_devices_get_all();
192 struct irecv_device *device = NULL; 196 struct irecv_device *device = NULL;
193 int i = 0; 197 int i = 0;
@@ -209,7 +213,8 @@ static int _is_breq_command(const char* cmd)
209 ); 213 );
210} 214}
211 215
212static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { 216static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size)
217{
213 char* cmd = strdup((char*)command); 218 char* cmd = strdup((char*)command);
214 char* action = strtok(cmd, " "); 219 char* action = strtok(cmd, " ");
215 220
@@ -254,16 +259,19 @@ static void parse_command(irecv_client_t client, unsigned char* command, unsigne
254 free(action); 259 free(action);
255} 260}
256 261
257static void load_command_history() { 262static void load_command_history()
263{
258 read_history(FILE_HISTORY_PATH); 264 read_history(FILE_HISTORY_PATH);
259} 265}
260 266
261static void append_command_to_history(char* cmd) { 267static void append_command_to_history(char* cmd)
268{
262 add_history(cmd); 269 add_history(cmd);
263 write_history(FILE_HISTORY_PATH); 270 write_history(FILE_HISTORY_PATH);
264} 271}
265 272
266static void init_shell(irecv_client_t client) { 273static void init_shell(irecv_client_t client)
274{
267 irecv_error_t error = 0; 275 irecv_error_t error = 0;
268 load_command_history(); 276 load_command_history();
269 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL); 277 irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
@@ -294,7 +302,8 @@ static void init_shell(irecv_client_t client) {
294 } 302 }
295} 303}
296 304
297int received_cb(irecv_client_t client, const irecv_event_t* event) { 305int received_cb(irecv_client_t client, const irecv_event_t* event)
306{
298 if (event->type == IRECV_RECEIVED) { 307 if (event->type == IRECV_RECEIVED) {
299 int i = 0; 308 int i = 0;
300 int size = event->size; 309 int size = event->size;
@@ -307,7 +316,8 @@ int received_cb(irecv_client_t client, const irecv_event_t* event) {
307 return 0; 316 return 0;
308} 317}
309 318
310int precommand_cb(irecv_client_t client, const irecv_event_t* event) { 319int precommand_cb(irecv_client_t client, const irecv_event_t* event)
320{
311 if (event->type == IRECV_PRECOMMAND) { 321 if (event->type == IRECV_PRECOMMAND) {
312 if (event->data[0] == '/') { 322 if (event->data[0] == '/') {
313 parse_command(client, (unsigned char*)event->data, event->size); 323 parse_command(client, (unsigned char*)event->data, event->size);
@@ -318,7 +328,8 @@ int precommand_cb(irecv_client_t client, const irecv_event_t* event) {
318 return 0; 328 return 0;
319} 329}
320 330
321int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { 331int postcommand_cb(irecv_client_t client, const irecv_event_t* event)
332{
322 char* value = NULL; 333 char* value = NULL;
323 char* action = NULL; 334 char* action = NULL;
324 char* command = NULL; 335 char* command = NULL;
@@ -350,7 +361,8 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
350 return 0; 361 return 0;
351} 362}
352 363
353int progress_cb(irecv_client_t client, const irecv_event_t* event) { 364int progress_cb(irecv_client_t client, const irecv_event_t* event)
365{
354 if (event->type == IRECV_PROGRESS) { 366 if (event->type == IRECV_PROGRESS) {
355 print_progress_bar(event->progress); 367 print_progress_bar(event->progress);
356 } 368 }
@@ -358,21 +370,22 @@ int progress_cb(irecv_client_t client, const irecv_event_t* event) {
358 return 0; 370 return 0;
359} 371}
360 372
361void print_progress_bar(double progress) { 373void print_progress_bar(double progress)
374{
362 int i = 0; 375 int i = 0;
363 376
364 if(progress < 0) { 377 if (progress < 0) {
365 return; 378 return;
366 } 379 }
367 380
368 if(progress > 100) { 381 if (progress > 100) {
369 progress = 100; 382 progress = 100;
370 } 383 }
371 384
372 printf("\r["); 385 printf("\r[");
373 386
374 for(i = 0; i < 50; i++) { 387 for (i = 0; i < 50; i++) {
375 if(i < progress / 2) { 388 if (i < progress / 2) {
376 printf("="); 389 printf("=");
377 } else { 390 } else {
378 printf(" "); 391 printf(" ");
@@ -383,12 +396,13 @@ void print_progress_bar(double progress) {
383 396
384 fflush(stdout); 397 fflush(stdout);
385 398
386 if(progress == 100) { 399 if (progress == 100) {
387 printf("\n"); 400 printf("\n");
388 } 401 }
389} 402}
390 403
391static void print_usage(int argc, char **argv) { 404static void print_usage(int argc, char **argv)
405{
392 char *name = NULL; 406 char *name = NULL;
393 name = strrchr(argv[0], '/'); 407 name = strrchr(argv[0], '/');
394 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); 408 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
@@ -415,7 +429,8 @@ static void print_usage(int argc, char **argv) {
415 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n"); 429 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n");
416} 430}
417 431
418int main(int argc, char* argv[]) { 432int main(int argc, char* argv[])
433{
419 static struct option longopts[] = { 434 static struct option longopts[] = {
420 { "ecid", required_argument, NULL, 'i' }, 435 { "ecid", required_argument, NULL, 'i' },
421 { "command", required_argument, NULL, 'c' }, 436 { "command", required_argument, NULL, 'c' },
@@ -605,7 +620,7 @@ int main(int argc, char* argv[]) {
605 buffer[buffer_length] = '\0'; 620 buffer[buffer_length] = '\0';
606 621
607 error = irecv_execute_script(client, buffer); 622 error = irecv_execute_script(client, buffer);
608 if(error != IRECV_E_SUCCESS) { 623 if (error != IRECV_E_SUCCESS) {
609 debug("%s\n", irecv_strerror(error)); 624 debug("%s\n", irecv_strerror(error));
610 } 625 }
611 626