summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-07-29 10:13:37 -0700
committerGravatar Matt Colyer2008-07-29 10:13:37 -0700
commit3dc130f3049e250b2d5c0b48af1995fda2fad3d4 (patch)
tree9d801459ef68e83a0d4ca038c0589d8e4c8aa2b2 /src/main.c
parent6039e5bbfc36aa5210295c38f251ed178ce5adbb (diff)
downloadlibimobiledevice-3dc130f3049e250b2d5c0b48af1995fda2fad3d4.tar.gz
libimobiledevice-3dc130f3049e250b2d5c0b48af1995fda2fad3d4.tar.bz2
Autotooled the project with very basic versioning support.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..e4007e9
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,104 @@
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 port = lockdownd_start_service(control, "com.apple.afc");
44 }
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 my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE);
74 if (my_file) {
75 char *outdatafile = strdup("this is a bitchin text file\n");
76 bytes = afc_write_file(afc, my_file, outdatafile, strlen(outdatafile));
77 free(outdatafile);
78 if (bytes > 0) printf("Wrote a surprise. ;)\n");
79 else printf("I wanted to write a surprise, but... :(\n");
80 afc_close_file(afc, my_file);
81 free(my_file);
82 }
83 printf("Deleting a file...\n");
84 bytes = afc_delete_file(afc, "/delme");
85 if (bytes) printf("Success.\n");
86 else printf("Failure.\n");
87
88 printf("Renaming a file...\n");
89 bytes = afc_rename_file(afc, "/renme", "/renme2");
90 if (bytes > 0) printf("Success.\n");
91 else printf("Failure.\n");
92 }
93 afc_disconnect(afc);
94 } else {
95 printf("Start service failure.\n");
96 }
97
98 printf("All done.\n");
99
100 free_iPhone(phone);
101
102 return 0;
103}
104