summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..4cde3d9
--- /dev/null
+++ b/main.c
@@ -0,0 +1,84 @@
1/*
2 * libiphone main.c written by FxChiP
3 * With much help from Daniel Brownlees
4 */
5
6#include <stdio.h>
7#include <string.h>
8#include <errno.h>
9#include <usb.h>
10
11#include "usbmux.h"
12#include "iphone.h"
13
14#include <libxml/parser.h>
15#include <libxml/tree.h>
16#include "plist.h"
17#include "lockdown.h"
18#include "AFC.h"
19
20int debug = 1;
21
22int main(int argc, char *argv[]) {
23 iPhone *phone = get_iPhone();
24 if (argc > 1 && !strcasecmp(argv[1], "--debug")) debug = 1;
25 else debug = 0;
26 char *response = (char*)malloc(sizeof(char) * 2048);
27 int bytes = 0, port = 0, i = 0;
28 if (phone) printf("I got a phone.\n");
29 else { printf("oops\n"); return -1; }
30
31 lockdownd_client *control = new_lockdownd_client(phone);
32 if (!lockdownd_hello(control)) {
33 printf("Something went wrong in the lockdownd client, go take a look.\n");
34 } else {
35 printf("We said hello. :)\n");
36 }
37
38 printf("Now starting SSL.\n");
39 if (!lockdownd_start_SSL_session(control, "29942970-207913891623273984")) {
40 printf("Error happened in GnuTLS...\n");
41 } else {
42 printf("... we're in SSL with the phone... !?\n");
43 }
44 port = lockdownd_start_service(control, "com.apple.afc");
45 if (port) {
46 printf("Start Service successful -- connect on port %i\n", port);
47 AFClient *afc = afc_connect(phone, 3432, port);
48 if (afc) {
49 char **dirs;
50 dirs = afc_get_dir_list(afc, "/eafaedf");
51 if (!dirs) dirs = afc_get_dir_list(afc, "/");
52 printf("Directory time.\n");
53 for (i = 0; strcmp(dirs[i], ""); i++) {
54 printf("/%s\n", dirs[i]);
55 }
56
57 free_dictionary(dirs);
58 AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ);
59 if (my_file) {
60 printf("A file size: %i\n", my_file->size);
61 char *file_data = (char*)malloc(sizeof(char) * my_file->size);
62 bytes = afc_read_file(afc, my_file, file_data, my_file->size);
63 if (bytes >= 0) {
64 printf("The file's data:\n");
65 fwrite(file_data, 1, bytes, stdout);
66 }
67 printf("\nClosing my file.\n");
68 afc_close_file(afc, my_file);
69 free(my_file);
70 free(file_data);
71 } else printf("couldn't open a file\n");
72 }
73 afc_disconnect(afc);
74 } else {
75 printf("Start service failure.\n");
76 }
77
78 printf("All done.\n");
79
80 free_iPhone(phone);
81
82 return 0;
83}
84