summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Zach C2008-07-29 01:13:51 -0700
committerGravatar Matt Colyer2008-07-29 01:13:51 -0700
commit0f4aeb11abce2f36d840b19d028e5aa34ccf5aba (patch)
tree978d11b1f46fb323db044fa76e2020c09aab89d4
parente2ff1128351d75eafd5426af7f96f9719c1af3e6 (diff)
downloadlibimobiledevice-0f4aeb11abce2f36d840b19d028e5aa34ccf5aba.tar.gz
libimobiledevice-0f4aeb11abce2f36d840b19d028e5aa34ccf5aba.tar.bz2
Version 0.09, added ability to talk to 2.0 firmware.
-rw-r--r--AFC.c162
-rw-r--r--AFC.h8
-rw-r--r--lockdown.c22
-rw-r--r--main.c25
4 files changed, 180 insertions, 37 deletions
diff --git a/AFC.c b/AFC.c
index 29c0f97..f3d538e 100644
--- a/AFC.c
+++ b/AFC.c
@@ -17,7 +17,7 @@ AFClient *afc_connect(iPhone *phone, int s_port, int d_port) {
17 if (client->afc_packet) { 17 if (client->afc_packet) {
18 client->phone = phone; 18 client->phone = phone;
19 client->afc_packet->packet_num = 0; 19 client->afc_packet->packet_num = 0;
20 client->afc_packet->unknown1 = client->afc_packet->unknown2 = client->afc_packet->unknown3 = client->afc_packet->unknown4 = 0; 20 client->afc_packet->unknown1 = client->afc_packet->unknown2 = client->afc_packet->unknown3 = client->afc_packet->unknown4 = client->afc_packet->entire_length = client->afc_packet->this_length = 0;
21 client->afc_packet->header1 = 0x36414643; 21 client->afc_packet->header1 = 0x36414643;
22 client->afc_packet->header2 = 0x4141504C; 22 client->afc_packet->header2 = 0x4141504C;
23 client->file_handle = 0; 23 client->file_handle = 0;
@@ -50,29 +50,55 @@ int count_nullspaces(char *string, int number) {
50 50
51int dispatch_AFC_packet(AFClient *client, char *data, int length) { 51int dispatch_AFC_packet(AFClient *client, char *data, int length) {
52 char *buffer; 52 char *buffer;
53 int bytes = 0; 53 int bytes = 0, offset = 0;
54 if (!client || !client->connection || !client->phone || !client->afc_packet) return 0; 54 if (!client || !client->connection || !client->phone || !client->afc_packet) return 0;
55 if (!data || !length) length = 0; 55 if (!data || !length) length = 0;
56 56
57 client->afc_packet->packet_num++; 57 client->afc_packet->packet_num++;
58 client->afc_packet->entire_length = client->afc_packet->this_length = (length) ? sizeof(AFCPacket) + length + 1 : sizeof(AFCPacket); 58 if (!client->afc_packet->entire_length) client->afc_packet->entire_length = client->afc_packet->this_length = (length) ? sizeof(AFCPacket) + length + 1 : sizeof(AFCPacket);
59 59 if (!client->afc_packet->this_length) client->afc_packet->this_length = sizeof(AFCPacket);
60 if (!length) { 60
61 bytes = mux_send(client->phone, client->connection, (char*)client->afc_packet, client->afc_packet->this_length); 61 if (client->afc_packet->this_length != client->afc_packet->entire_length) {
62 if (bytes <= 0) return 0; 62 // We want to send two segments; buffer+sizeof(AFCPacket) to this_length is the parameters
63 else return bytes; 63 // And everything beyond that is the next packet. (for writing)
64 } else { 64 char *buffer = (char*)malloc(client->afc_packet->this_length);
65 buffer = (char*)malloc(sizeof(char) * client->afc_packet->this_length); 65 memcpy(buffer, (char*)client->afc_packet, sizeof(AFCPacket));
66 memcpy(buffer, client->afc_packet, sizeof(AFCPacket)); 66 offset = client->afc_packet->this_length - sizeof(AFCPacket);
67 memcpy(buffer+sizeof(AFCPacket), data, length); 67 if (debug) printf("dispatch_AFC_packet: Offset: %i\n", offset);
68 buffer[client->afc_packet->this_length-1] = '\0'; 68 if ((length) < (client->afc_packet->entire_length - client->afc_packet->this_length)) {
69 if (debug) printf("dispatch_AFC_packet: Length did not resemble what it was supposed to based on the packet.\nlength minus offset: %i\nrest of packet: %i\n", length-offset, client->afc_packet->entire_length - client->afc_packet->this_length);
70 free(buffer);
71 return 0;
72 }
73 if (debug) printf("dispatch_AFC_packet: fucked-up packet method (probably a write)\n");
74 memcpy(buffer+sizeof(AFCPacket), data, offset);
75 bytes = mux_send(client->phone, client->connection, buffer, client->afc_packet->this_length);
76 free(buffer);
77 if (bytes <= 0) { return 0; }
78 if (debug) {
79 printf("dispatch_AFC_packet: sent the first now go with the second\n");
80 printf("Length: %i\n", length-offset);
81 printf("Buffer: \n");
82 fwrite(data+offset, 1, length-offset, stdout);
83 }
84
69 85
86 bytes = mux_send(client->phone, client->connection, data+offset, length-offset);
87 if (bytes <= 0) { return 0; }
88 else { return bytes; }
89 } else {
90 if (debug) printf("dispatch_AFC_packet doin things the old way\n");
91 char *buffer = (char*)malloc(sizeof(char) * client->afc_packet->this_length);
92 if (debug) printf("dispatch_AFC_packet packet length = %i\n", client->afc_packet->this_length);
93 memcpy(buffer, (char*)client->afc_packet, sizeof(AFCPacket));
94 if (debug) printf("dispatch_AFC_packet packet data follows\n");
95 if (length > 0) { memcpy(buffer+sizeof(AFCPacket), data, length); buffer[sizeof(AFCPacket)+length] = '\0'; }
96 if (debug) fwrite(buffer, 1, client->afc_packet->this_length, stdout);
97 if (debug) printf("\n");
70 bytes = mux_send(client->phone, client->connection, buffer, client->afc_packet->this_length); 98 bytes = mux_send(client->phone, client->connection, buffer, client->afc_packet->this_length);
71 free(buffer); // don't need it
72 if (bytes <= 0) return 0; 99 if (bytes <= 0) return 0;
73 else return bytes; 100 else return bytes;
74 } 101 }
75
76 return 0; 102 return 0;
77} 103}
78 104
@@ -103,19 +129,23 @@ int receive_AFC_data(AFClient *client, char **dump_here) {
103 uint32 param1 = buffer[sizeof(AFCPacket)]; 129 uint32 param1 = buffer[sizeof(AFCPacket)];
104 free(buffer); 130 free(buffer);
105 131
106 if (r_packet->operation == 0x01) { 132 if (r_packet->operation == 0x01 && !((client->afc_packet->operation == AFC_DELETE && param1 == 7))) {
107 printf("Oops? Bad operation code received.\n"); 133 if (debug) printf("Oops? Bad operation code received.\n");
108 if (param1 == 0) printf("... false alarm, but still\n"); 134 if (param1 == 0) {
109 else printf("Errno %i\n", param1); 135 if (debug) printf("... false alarm, but still\n");
136 return 1;
137 }
138 else { if (debug) printf("Errno %i\n", param1); }
110 free(r_packet); 139 free(r_packet);
111 *dump_here = NULL; 140 *dump_here = NULL;
112 return 0; 141 return 0;
113 } else { 142 } else {
114 printf("Operation code %x\nFull length %i and this length %i\n", r_packet->operation, r_packet->entire_length, r_packet->this_length); 143 if (debug) printf("Operation code %x\nFull length %i and this length %i\n", r_packet->operation, r_packet->entire_length, r_packet->this_length);
115 } 144 }
116 145
117 recv_len = r_packet->entire_length - r_packet->this_length; 146 recv_len = r_packet->entire_length - r_packet->this_length;
118 free(r_packet); 147 free(r_packet);
148 if (!recv_len) return bytes;
119 buffer = (char*)malloc(sizeof(char) * recv_len); 149 buffer = (char*)malloc(sizeof(char) * recv_len);
120 bytes = mux_recv(client->phone, client->connection, buffer, recv_len); 150 bytes = mux_recv(client->phone, client->connection, buffer, recv_len);
121 if (bytes <= 0) { 151 if (bytes <= 0) {
@@ -133,6 +163,7 @@ char **afc_get_dir_list(AFClient *client, char *dir) {
133 client->afc_packet->operation = AFC_LIST_DIR; 163 client->afc_packet->operation = AFC_LIST_DIR;
134 int bytes = 0; 164 int bytes = 0;
135 char *blah = NULL, **list = NULL; 165 char *blah = NULL, **list = NULL;
166 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
136 bytes = dispatch_AFC_packet(client, dir, strlen(dir)); 167 bytes = dispatch_AFC_packet(client, dir, strlen(dir));
137 if (!bytes) return NULL; 168 if (!bytes) return NULL;
138 169
@@ -159,8 +190,49 @@ char **make_strings_list(char *tokens, int true_length) {
159 return list; 190 return list;
160} 191}
161 192
193int afc_delete_file(AFClient *client, const char *path) {
194 if (!client || !path || !client->afc_packet || !client->phone ||!client->connection) return 0;
195
196 char *receive = NULL;
197 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
198 client->afc_packet->operation = AFC_DELETE;
199 int bytes;
200 bytes = dispatch_AFC_packet(client, path, strlen(path));
201 if (bytes <= 0) return 0;
202
203 bytes = receive_AFC_data(client, &receive);
204 free(receive);
205 if (bytes <= 0) return 0;
206 else return 1;
207}
208
209int afc_rename_file(AFClient *client, const char *from, const char *to) {
210 if (!client || !from || !to || !client->afc_packet || !client->phone || !client->connection) return 0;
211
212 char *receive = NULL;
213 char *send = (char*)malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32)));
214 int bytes = 0;
215
216 memcpy(send, from, strlen(from)+1);
217 memcpy(send+strlen(from)+1, to, strlen(to));
218 fwrite(send, 1, strlen(from)+1+strlen(to), stdout);
219 printf("\n");
220 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
221 client->afc_packet->operation = AFC_RENAME;
222 bytes = dispatch_AFC_packet(client, send, strlen(to) + strlen(from) + 2);
223 if (bytes <= 0) return 0;
224
225 bytes = receive_AFC_data(client, &receive);
226 free(receive);
227 if (bytes <= 0) return 0;
228 else return 1;
229}
230
231
232
162AFCFile *afc_get_file_info(AFClient *client, char *path) { 233AFCFile *afc_get_file_info(AFClient *client, char *path) {
163 client->afc_packet->operation = AFC_GET_INFO; 234 client->afc_packet->operation = AFC_GET_INFO;
235 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
164 dispatch_AFC_packet(client, path, strlen(path)); 236 dispatch_AFC_packet(client, path, strlen(path));
165 237
166 char *received, **list; 238 char *received, **list;
@@ -210,26 +282,24 @@ AFCFile *afc_open_file(AFClient *client, const char *filename, uint32 file_mode)
210 int bytes = 0, length_thing = 0; 282 int bytes = 0, length_thing = 0;
211 client->afc_packet->operation = AFC_FILE_OPEN; 283 client->afc_packet->operation = AFC_FILE_OPEN;
212 284
285 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
213 bytes = dispatch_AFC_packet(client, further_data, 8+strlen(filename)); 286 bytes = dispatch_AFC_packet(client, further_data, 8+strlen(filename));
214 free(further_data); 287 free(further_data);
215 if (bytes <= 0) { 288 if (bytes <= 0) {
216 printf("didn't read enough\n"); 289 if (debug) printf("didn't read enough\n");
217 return NULL; 290 return NULL;
218 } else { 291 } else {
219 printf("O HAI\n");
220 length_thing = receive_AFC_data(client, &further_data); 292 length_thing = receive_AFC_data(client, &further_data);
221 if (length_thing && further_data) { 293 if (length_thing && further_data) {
222 printf("ARA\n");
223 file_infos = afc_get_file_info(client, filename); 294 file_infos = afc_get_file_info(client, filename);
224 memcpy(&file_infos->filehandle, further_data, 4); 295 memcpy(&file_infos->filehandle, further_data, 4);
225 printf("gr\n");
226 return file_infos; 296 return file_infos;
227 } else { 297 } else {
228 printf("didn't get further data or something\n"); 298 if (debug) printf("didn't get further data or something\n");
229 return NULL; 299 return NULL;
230 } 300 }
231 } 301 }
232 printf("what the fuck\n"); 302 if (debug) printf("what the fuck\n");
233 return NULL; 303 return NULL;
234} 304}
235 305
@@ -243,14 +313,17 @@ int afc_read_file(AFClient *client, AFCFile *file, char *data, int length) {
243 int bytes = 0; 313 int bytes = 0;
244 314
245 client->afc_packet->operation = AFC_READ; 315 client->afc_packet->operation = AFC_READ;
246 bytes = dispatch_AFC_packet(client, packet, sizeof(AFCFilePacket)); 316 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
317 bytes = dispatch_AFC_packet(client, (char*)packet, sizeof(AFCFilePacket));
247 318
248 if (bytes > 0) { 319 if (bytes > 0) {
249 bytes = receive_AFC_data(client, &input); 320 bytes = receive_AFC_data(client, &input);
250 if (bytes <= 0) { 321 if (bytes <= 0) {
322 if (input) free(input);
251 return -1; 323 return -1;
252 } else { 324 } else {
253 memcpy(data, input, (bytes > length) ? length : bytes); 325 memcpy(data, input, (bytes > length) ? length : bytes);
326 free(input);
254 return (bytes > length) ? length : bytes; 327 return (bytes > length) ? length : bytes;
255 } 328 }
256 } else { 329 } else {
@@ -259,21 +332,50 @@ int afc_read_file(AFClient *client, AFCFile *file, char *data, int length) {
259 return 0; 332 return 0;
260} 333}
261 334
335int afc_write_file(AFClient *client, AFCFile *file, char *data, int length) {
336 char *acknowledgement = NULL;
337 if (!client ||!client->afc_packet ||!client->phone || !client->connection || !file) return -1;
338 client->afc_packet->this_length = sizeof(AFCPacket) + 8;
339 client->afc_packet->entire_length = client->afc_packet->this_length + length;
340 client->afc_packet->operation = AFC_WRITE;
341 if (debug) printf("afc_write_file: Write length: %i\n", length);
342 uint32 zero = 0, bytes = 0;
343
344 char *out_buffer = NULL;
345 out_buffer = (char*)malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
346 memcpy(out_buffer, (char*)&file->filehandle, sizeof(uint32));
347 memcpy(out_buffer+4, (char*)&zero, sizeof(uint32));
348 memcpy(out_buffer+8, data, length);
349
350 bytes = dispatch_AFC_packet(client, out_buffer, length + 8);
351 if (!bytes) return -1;
352
353 zero = bytes;
354 bytes = receive_AFC_data(client, &acknowledgement);
355 if (bytes <= 0) {
356 if (debug) printf("afc_write_file: uh oh?\n");
357 }
358
359 return zero;
360}
361
262void afc_close_file(AFClient *client, AFCFile *file) { 362void afc_close_file(AFClient *client, AFCFile *file) {
263 char *buffer = malloc(sizeof(char) * 8); 363 char *buffer = malloc(sizeof(char) * 8);
264 uint32 zero = 0; 364 uint32 zero = 0;
265 if (debug) printf("File handle %i\n", file->filehandle); 365 if (debug) printf("File handle %i\n", file->filehandle);
266 memcpy(buffer, &file->filehandle, sizeof(uint32)); 366 memcpy(buffer, &file->filehandle, sizeof(uint32));
267 memcpy(buffer, &zero, sizeof(zero)); 367 memcpy(buffer+sizeof(uint32), &zero, sizeof(zero));
268 client->afc_packet->operation = AFC_FILE_CLOSE; 368 client->afc_packet->operation = AFC_FILE_CLOSE;
269 int bytes = 0; 369 int bytes = 0;
370 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
270 bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8); 371 bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8);
372
271 free(buffer); 373 free(buffer);
374 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
272 if (!bytes) return; 375 if (!bytes) return;
273 376
274 bytes = receive_AFC_data(client, &buffer); 377 bytes = receive_AFC_data(client, &buffer);
275 if (bytes<=0 && !buffer) printf("closefile: all went as expected\n"); 378 return;
276 else { printf("We have a buffer!??!?\nLength %i\n", bytes); fwrite(buffer, 1, bytes, stdout); printf("\n"); }
277 if (buffer) free(buffer); // we're *SUPPOSED* to get an "error" here. 379 if (buffer) free(buffer); // we're *SUPPOSED* to get an "error" here.
278} 380}
279 381
diff --git a/AFC.h b/AFC.h
index 281e624..787b9fe 100644
--- a/AFC.h
+++ b/AFC.h
@@ -53,11 +53,14 @@ enum {
53 AFC_GET_INFO = 0x0000000a, 53 AFC_GET_INFO = 0x0000000a,
54 AFC_GET_DEVINFO = 0x0000000b, 54 AFC_GET_DEVINFO = 0x0000000b,
55 AFC_LIST_DIR = 0x00000003, 55 AFC_LIST_DIR = 0x00000003,
56 AFC_DELETE = 0x00000008,
57 AFC_RENAME = 0x00000018,
56 AFC_SUCCESS_RESPONSE = 0x00000002, 58 AFC_SUCCESS_RESPONSE = 0x00000002,
57 AFC_FILE_OPEN = 0x0000000d, 59 AFC_FILE_OPEN = 0x0000000d,
58 AFC_FILE_CLOSE = 0x00000014, 60 AFC_FILE_CLOSE = 0x00000014,
59 AFC_FILE_HANDLE = 0x0000000e, 61 AFC_FILE_HANDLE = 0x0000000e,
60 AFC_READ = 0x0000000f 62 AFC_READ = 0x0000000f,
63 AFC_WRITE = 0x00000010
61}; 64};
62 65
63AFClient *afc_connect(iPhone *phone, int s_port, int d_port); 66AFClient *afc_connect(iPhone *phone, int s_port, int d_port);
@@ -72,3 +75,6 @@ AFCFile *afc_get_file_info(AFClient *client, char *path);
72AFCFile *afc_open_file(AFClient *client, const char *filename, uint32 file_mode); 75AFCFile *afc_open_file(AFClient *client, const char *filename, uint32 file_mode);
73void afc_close_file(AFClient *client, AFCFile *file); 76void afc_close_file(AFClient *client, AFCFile *file);
74int afc_read_file(AFClient *client, AFCFile *file, char *data, int length); 77int afc_read_file(AFClient *client, AFCFile *file, char *data, int length);
78int afc_write_file(AFClient *client, AFCFile *file, char *data, int length);
79int afc_delete_file(AFClient *client, const char *path);
80int afc_rename_file(AFClient *client, const char *from, const char *to);
diff --git a/lockdown.c b/lockdown.c
index 5ca6001..45b4245 100644
--- a/lockdown.c
+++ b/lockdown.c
@@ -149,15 +149,16 @@ int lockdownd_start_SSL_session(lockdownd_client *control, const char *HostID) {
149 for (i = 0; strcmp(dictionary[i], ""); i+=2) { 149 for (i = 0; strcmp(dictionary[i], ""); i+=2) {
150 if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i+1], "Success")) { 150 if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i+1], "Success")) {
151 // Set up GnuTLS... 151 // Set up GnuTLS...
152 //gnutls_anon_client_credentials_t anoncred;
152 gnutls_certificate_credentials_t xcred; 153 gnutls_certificate_credentials_t xcred;
153
154 if (debug) printf("We started the session OK, now trying GnuTLS\n"); 154 if (debug) printf("We started the session OK, now trying GnuTLS\n");
155 errno = 0; 155 errno = 0;
156 gnutls_global_init(); 156 gnutls_global_init();
157 //gnutls_anon_allocate_client_credentials(&anoncred);
157 gnutls_certificate_allocate_credentials(&xcred); 158 gnutls_certificate_allocate_credentials(&xcred);
158 gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM); 159 gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM);
159 gnutls_init(control->ssl_session, GNUTLS_CLIENT); 160 gnutls_init(control->ssl_session, GNUTLS_CLIENT);
160 if ((return_me = gnutls_priority_set_direct(*control->ssl_session, "NORMAL:+VERS-SSL3.0", NULL)) < 0) { 161 if ((return_me = gnutls_priority_set_direct(*control->ssl_session, "NONE:+VERS-SSL3.0:+ANON-DH:+RSA:+AES-128-CBC:+AES-256-CBC:+SHA1:+SHA256:+SHA512:+MD5:+COMP-NULL", NULL)) < 0) {
161 printf("oops? bad options?\n"); 162 printf("oops? bad options?\n");
162 gnutls_perror(return_me); 163 gnutls_perror(return_me);
163 return 0; 164 return 0;
@@ -214,6 +215,14 @@ ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size
214 if (debug) printf("pre-send\nlength = %i\n", length); 215 if (debug) printf("pre-send\nlength = %i\n", length);
215 bytes = mux_send(control->iphone, control->connection, buffer, length); 216 bytes = mux_send(control->iphone, control->connection, buffer, length);
216 if (debug) printf("post-send\nsent %i bytes\n", bytes); 217 if (debug) printf("post-send\nsent %i bytes\n", bytes);
218 if (debug) {
219 FILE *my_ssl_packet = fopen("sslpacketwrite.out", "w+");
220 fwrite(buffer, 1, length, my_ssl_packet);
221 fflush(my_ssl_packet);
222 printf("Wrote SSL packet to drive, too.\n");
223 fclose(my_ssl_packet);
224 }
225
217 return bytes; 226 return bytes;
218} 227}
219 228
@@ -251,11 +260,16 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
251 } 260 }
252 } 261 }
253 // End buffering hack! 262 // End buffering hack!
254 char *recv_buffer = (char*)malloc(sizeof(char) * (length * 400)); // ensuring nothing stupid happens 263 char *recv_buffer = (char*)malloc(sizeof(char) * (length * 1000)); // ensuring nothing stupid happens
255 264
256 if (debug) printf("pre-read\nclient wants %i bytes\n", length); 265 if (debug) printf("pre-read\nclient wants %i bytes\n", length);
257 bytes = mux_recv(control->iphone, control->connection, recv_buffer, (length * 400)); 266 bytes = mux_recv(control->iphone, control->connection, recv_buffer, (length * 1000));
258 if (debug) printf("post-read\nwe got %i bytes\n", bytes); 267 if (debug) printf("post-read\nwe got %i bytes\n", bytes);
268 if (debug && bytes < 0) {
269 printf("lockdownd_securead(): uh oh\n");
270 printf("I believe what we have here is a failure to communicate... libusb says %s but strerror says %s\n", usb_strerror(), strerror(errno));
271 return bytes + 28; // an errno
272 }
259 if (bytes >= length) { 273 if (bytes >= length) {
260 if (bytes > length) { 274 if (bytes > length) {
261 if (debug) printf("lockdownd_securead: Client deliberately read less data than was there; resorting to GnuTLS buffering hack.\n"); 275 if (debug) printf("lockdownd_securead: Client deliberately read less data than was there; resorting to GnuTLS buffering hack.\n");
diff --git a/main.c b/main.c
index 4cde3d9..d5c2dfa 100644
--- a/main.c
+++ b/main.c
@@ -36,12 +36,13 @@ int main(int argc, char *argv[]) {
36 } 36 }
37 37
38 printf("Now starting SSL.\n"); 38 printf("Now starting SSL.\n");
39 if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) { 39// if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) {
40 if (!lockdownd_start_SSL_session(control, "2994593482385678618538736")) {
40 printf("Error happened in GnuTLS...\n"); 41 printf("Error happened in GnuTLS...\n");
41 } else { 42 } else {
42 printf("... we're in SSL with the phone... !?\n"); 43 printf("... we're in SSL with the phone... !?\n");
44 port = lockdownd_start_service(control, "com.apple.afc");
43 } 45 }
44 port = lockdownd_start_service(control, "com.apple.afc");
45 if (port) { 46 if (port) {
46 printf("Start Service successful -- connect on port %i\n", port); 47 printf("Start Service successful -- connect on port %i\n", port);
47 AFClient *afc = afc_connect(phone, 3432, port); 48 AFClient *afc = afc_connect(phone, 3432, port);
@@ -69,6 +70,26 @@ int main(int argc, char *argv[]) {
69 free(my_file); 70 free(my_file);
70 free(file_data); 71 free(file_data);
71 } else printf("couldn't open a file\n"); 72 } else printf("couldn't open a file\n");
73
74 my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE);
75 if (my_file) {
76 char *outdatafile = strdup("this is a bitchin text file\n");
77 bytes = afc_write_file(afc, my_file, outdatafile, strlen(outdatafile));
78 free(outdatafile);
79 if (bytes > 0) printf("Wrote a surprise. ;)\n");
80 else printf("I wanted to write a surprise, but... :(\n");
81 afc_close_file(afc, my_file);
82 free(my_file);
83 }
84 printf("Deleting a file...\n");
85 bytes = afc_delete_file(afc, "/delme");
86 if (bytes) printf("Success.\n");
87 else printf("Failure.\n");
88
89 printf("Renaming a file...\n");
90 bytes = afc_rename_file(afc, "/renme", "/renme2");
91 if (bytes > 0) printf("Success.\n");
92 else printf("Failure.\n");
72 } 93 }
73 afc_disconnect(afc); 94 afc_disconnect(afc);
74 } else { 95 } else {