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 @@
* irecovery.c
* Software frontend for iBoot/iBSS communication with iOS devices
*
- * Copyright (c) 2012-2020 Nikias Bassen <nikias@gmx.li>
+ * Copyright (c) 2012-2023 Nikias Bassen <nikias@gmx.li>
* Copyright (c) 2012-2015 Martin Szulecki <martin.szulecki@libimobiledevice.org>
* Copyright (c) 2010-2011 Chronic-Dev Team
* Copyright (c) 2010-2011 Joshua Hill
@@ -43,7 +43,7 @@
#endif
#define FILE_HISTORY_PATH ".irecovery"
-#define debug(...) if(verbose) fprintf(stderr, __VA_ARGS__)
+#define debug(...) if (verbose) fprintf(stderr, __VA_ARGS__)
enum {
kNoAction,
@@ -68,7 +68,8 @@ int progress_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);
-static void shell_usage() {
+static void shell_usage()
+{
printf("Usage:\n");
printf(" /upload FILE\t\tsend FILE to device\n");
printf(" /limera1n [FILE]\trun limera1n exploit and send optional payload from FILE\n");
@@ -77,7 +78,8 @@ static void shell_usage() {
printf(" /exit\t\t\texit interactive shell\n");
}
-static const char* mode_to_str(int mode) {
+static const char* mode_to_str(int mode)
+{
switch (mode) {
case IRECV_K_RECOVERY_MODE_1:
case IRECV_K_RECOVERY_MODE_2:
@@ -97,7 +99,8 @@ static const char* mode_to_str(int mode) {
}
}
-static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) {
+static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length)
+{
FILE *f;
uint64_t size;
@@ -187,7 +190,8 @@ static void print_device_info(irecv_client_t client)
}
}
-static void print_devices() {
+static void print_devices()
+{
struct irecv_device *devices = irecv_devices_get_all();
struct irecv_device *device = NULL;
int i = 0;
@@ -209,7 +213,8 @@ static int _is_breq_command(const char* cmd)
);
}
-static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
+static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size)
+{
char* cmd = strdup((char*)command);
char* action = strtok(cmd, " ");
@@ -254,16 +259,19 @@ static void parse_command(irecv_client_t client, unsigned char* command, unsigne
free(action);
}
-static void load_command_history() {
+static void load_command_history()
+{
read_history(FILE_HISTORY_PATH);
}
-static void append_command_to_history(char* cmd) {
+static void append_command_to_history(char* cmd)
+{
add_history(cmd);
write_history(FILE_HISTORY_PATH);
}
-static void init_shell(irecv_client_t client) {
+static void init_shell(irecv_client_t client)
+{
irecv_error_t error = 0;
load_command_history();
irecv_event_subscribe(client, IRECV_PROGRESS, &progress_cb, NULL);
@@ -294,7 +302,8 @@ static void init_shell(irecv_client_t client) {
}
}
-int received_cb(irecv_client_t client, const irecv_event_t* event) {
+int received_cb(irecv_client_t client, const irecv_event_t* event)
+{
if (event->type == IRECV_RECEIVED) {
int i = 0;
int size = event->size;
@@ -307,7 +316,8 @@ int received_cb(irecv_client_t client, const irecv_event_t* event) {
return 0;
}
-int precommand_cb(irecv_client_t client, const irecv_event_t* event) {
+int precommand_cb(irecv_client_t client, const irecv_event_t* event)
+{
if (event->type == IRECV_PRECOMMAND) {
if (event->data[0] == '/') {
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) {
return 0;
}
-int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
+int postcommand_cb(irecv_client_t client, const irecv_event_t* event)
+{
char* value = NULL;
char* action = NULL;
char* command = NULL;
@@ -350,7 +361,8 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
return 0;
}
-int progress_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->progress);
}
@@ -358,21 +370,22 @@ int progress_cb(irecv_client_t client, const irecv_event_t* event) {
return 0;
}
-void print_progress_bar(double progress) {
+void print_progress_bar(double progress)
+{
int i = 0;
- if(progress < 0) {
+ if (progress < 0) {
return;
}
- if(progress > 100) {
+ if (progress > 100) {
progress = 100;
}
printf("\r[");
- for(i = 0; i < 50; i++) {
- if(i < progress / 2) {
+ for (i = 0; i < 50; i++) {
+ if (i < progress / 2) {
printf("=");
} else {
printf(" ");
@@ -383,12 +396,13 @@ void print_progress_bar(double progress) {
fflush(stdout);
- if(progress == 100) {
+ if (progress == 100) {
printf("\n");
}
}
-static void print_usage(int argc, char **argv) {
+static void print_usage(int argc, char **argv)
+{
char *name = NULL;
name = strrchr(argv[0], '/');
printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
@@ -415,7 +429,8 @@ static void print_usage(int argc, char **argv) {
printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n");
}
-int main(int argc, char* argv[]) {
+int main(int argc, char* argv[])
+{
static struct option longopts[] = {
{ "ecid", required_argument, NULL, 'i' },
{ "command", required_argument, NULL, 'c' },
@@ -605,7 +620,7 @@ int main(int argc, char* argv[]) {
buffer[buffer_length] = '\0';
error = irecv_execute_script(client, buffer);
- if(error != IRECV_E_SUCCESS) {
+ if (error != IRECV_E_SUCCESS) {
debug("%s\n", irecv_strerror(error));
}