summaryrefslogtreecommitdiffstats
path: root/src/irecovery.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/irecovery.c')
-rw-r--r--src/irecovery.c106
1 files changed, 60 insertions, 46 deletions
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 {
33static unsigned int quit = 0; 33static unsigned int quit = 0;
34static unsigned int verbose = 0; 34static unsigned int verbose = 0;
35 35
36int received_cb(irecv_client_t client, const irecv_event_t* event);
36int precommand_cb(irecv_client_t client, const irecv_event_t* event); 37int precommand_cb(irecv_client_t client, const irecv_event_t* event);
37int postcommand_cb(irecv_client_t client, const irecv_event_t* event); 38int postcommand_cb(irecv_client_t client, const irecv_event_t* event);
38 39
39void print_shell_usage() { 40void shell_usage() {
40 printf("Usage:\n"); 41 printf("Usage:\n");
41 printf("\t/upload <file>\tSend file to client.\n"); 42 printf("\t/upload <file>\tSend file to client.\n");
43 printf("\t/exploit [file]\tSend usb exploit with optional payload\n");
42 printf("\t/help\t\tShow this help.\n"); 44 printf("\t/help\t\tShow this help.\n");
43 printf("\t/exit\t\tExit interactive shell.\n"); 45 printf("\t/exit\t\tExit interactive shell.\n");
44} 46}
45 47
46void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { 48void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
47 char* cmd = strtok(strdup(command), " "); 49 char* cmd = strdup(command);
48 debug("Executing %s %s\n", cmd, command); 50 char* action = strtok(cmd, " ");
51 debug("Executing %s\n", action);
49 if (!strcmp(cmd, "/exit")) { 52 if (!strcmp(cmd, "/exit")) {
50 quit = 1; 53 quit = 1;
51 } else 54 } else
52 55
53 if (!strcmp(cmd, "/help")) { 56 if (!strcmp(cmd, "/help")) {
54 print_shell_usage(); 57 shell_usage();
55 } else 58 } else
56 59
57 if (!strcmp(cmd, "/upload")) { 60 if (!strcmp(cmd, "/upload")) {
@@ -60,22 +63,18 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s
60 if (filename != NULL) { 63 if (filename != NULL) {
61 irecv_send_file(client, filename); 64 irecv_send_file(client, filename);
62 } 65 }
63 } 66 } else
64 free(cmd);
65}
66 67
67int recv_callback(irecv_client_t client, unsigned char* data, int size) { 68 if (!strcmp(cmd, "/exploit")) {
68 int i = 0; 69 char* filename = strtok(NULL, " ");
69 for (i = 0; i < size; i++) { 70 debug("Sending %s\n", filename);
70 printf("%c", data[i]); 71 if (filename != NULL) {
72 irecv_send_file(client, filename);
73 }
74 irecv_send_exploit(client);
71 } 75 }
72 return size;
73}
74 76
75int send_callback(irecv_client_t client, unsigned char* command, int size) { 77 free(action);
76
77
78 return size;
79} 78}
80 79
81void load_command_history() { 80void load_command_history() {
@@ -90,7 +89,7 @@ void append_command_to_history(char* cmd) {
90void init_shell(irecv_client_t client) { 89void init_shell(irecv_client_t client) {
91 irecv_error_t error = 0; 90 irecv_error_t error = 0;
92 load_command_history(); 91 load_command_history();
93 irecv_set_receiver(client, &recv_callback); 92 irecv_event_subscribe(client, IRECV_RECEIVED, &received_cb, NULL);
94 irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL); 93 irecv_event_subscribe(client, IRECV_PRECOMMAND, &precommand_cb, NULL);
95 irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); 94 irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL);
96 while (!quit) { 95 while (!quit) {
@@ -113,49 +112,64 @@ void init_shell(irecv_client_t client) {
113 } 112 }
114} 113}
115 114
116void print_usage() { 115int received_cb(irecv_client_t client, const irecv_event_t* event) {
117 printf("iRecovery - iDevice Recovery Utility\n"); 116 if (event->type == IRECV_RECEIVED) {
118 printf("Usage: ./irecovery [args]\n"); 117 int i = 0;
119 printf("\t-v\t\tStart irecovery in verbose mode.\n"); 118 int size = event->size;
120 printf("\t-c <cmd>\tSend command to client.\n"); 119 char* data = event->data;
121 printf("\t-f <file>\tSend file to client.\n"); 120 for (i = 0; i < size; i++) {
122 printf("\t-k [exploit]\tSend usb exploit to client.\n"); 121 printf("%c", data[i]);
123 printf("\t-h\t\tShow this help.\n"); 122 }
124 printf("\t-r\t\tReset client.\n"); 123 }
125 printf("\t-s\t\tStart interactive shell.\n"); 124 return 0;
126 exit(1);
127} 125}
128 126
129int precommand_cb(irecv_client_t client, const irecv_event_t* event) { 127int precommand_cb(irecv_client_t client, const irecv_event_t* event) {
130 irecv_error_t error = 0; 128 if (event->type == IRECV_PRECOMMAND) {
131 if (event->data[0] == '/') { 129 irecv_error_t error = 0;
132 parse_command(client, event->data, strlen(event->data)); 130 if (event->data[0] == '/') {
133 return -1; 131 parse_command(client, event->data, event->size);
132 return -1;
133 }
134 } 134 }
135 return 0; 135 return 0;
136} 136}
137 137
138int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { 138int postcommand_cb(irecv_client_t client, const irecv_event_t* event) {
139 irecv_error_t error = 0; 139 unsigned char* value = NULL;
140 if (strstr(event->data, "getenv") != NULL) { 140 if (event->type == IRECV_POSTCOMMAND) {
141 unsigned char* value = NULL; 141 irecv_error_t error = 0;
142 error = irecv_getenv(client, &value); 142 if (strstr(event->data, "getenv") != NULL) {
143 if (error != IRECV_E_SUCCESS) { 143 error = irecv_getenv(client, &value);
144 debug("%s\n", irecv_strerror(error)); 144 if (error != IRECV_E_SUCCESS) {
145 return error; 145 debug("%s\n", irecv_strerror(error));
146 return error;
147 }
148 printf("%s\n", value);
146 } 149 }
147 150
148 printf("%s\n", value); 151 if (!strcmp(event->data, "reboot")) {
149 free(value); 152 quit = 1;
150 } 153 }
151
152 if (!strcmp(event->data, "reboot")) {
153 quit = 1;
154 } 154 }
155 155
156 if (value != NULL) free(value);
156 return 0; 157 return 0;
157} 158}
158 159
160void print_usage() {
161 printf("iRecovery - iDevice Recovery Utility\n");
162 printf("Usage: ./irecovery [args]\n");
163 printf("\t-v\t\tStart irecovery in verbose mode.\n");
164 printf("\t-c <cmd>\tSend command to client.\n");
165 printf("\t-f <file>\tSend file to client.\n");
166 printf("\t-k [payload]\tSend usb exploit to client.\n");
167 printf("\t-h\t\tShow this help.\n");
168 printf("\t-r\t\tReset client.\n");
169 printf("\t-s\t\tStart interactive shell.\n");
170 exit(1);
171}
172
159int main(int argc, char** argv) { 173int main(int argc, char** argv) {
160 int i = 0; 174 int i = 0;
161 int opt = 0; 175 int opt = 0;