summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am16
-rw-r--r--src/afccheck.c136
-rw-r--r--src/lckdclient.c103
-rw-r--r--src/main.c157
4 files changed, 0 insertions, 412 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a66c05b..785aacf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,22 +5,6 @@ AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $
5 5
6bin_PROGRAMS = libiphone-initconf 6bin_PROGRAMS = libiphone-initconf
7 7
8if BUILD_DEV_TOOLS
9 bin_PROGRAMS += iphoneclient lckd-client afccheck
10endif
11
12iphoneclient_SOURCES = main.c
13iphoneclient_LDADD = libiphone.la
14
15lckd_client_SOURCES = lckdclient.c
16lckd_client_CFLAGS = $(AM_CFLAGS)
17lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
18lckd_client_LDADD = libiphone.la
19
20afccheck_SOURCES = afccheck.c
21afccheck_CFLAGS = $(AM_CFLAGS)
22afccheck_LDFLAGS = $(AM_LDFLAGS)
23afccheck_LDADD = libiphone.la
24 8
25libiphone_initconf_SOURCES = initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c utils.c 9libiphone_initconf_SOURCES = initconf.c userpref.c lockdown.c plist.c usbmux.c iphone.c utils.c
26libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS) $(AM_CFLAGS) 10libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS) $(AM_CFLAGS)
diff --git a/src/afccheck.c b/src/afccheck.c
deleted file mode 100644
index e772d99..0000000
--- a/src/afccheck.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/*
2 * afccheck.c
3 * creates threads and check communication through AFC is done rigth
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <glib.h>
25
26#include "usbmux.h"
27#include "iphone.h"
28#include <libiphone/libiphone.h>
29
30#define BUFFER_SIZE 20000
31#define NB_THREADS 10
32
33int debug = 0;
34
35typedef struct {
36 iphone_afc_client_t afc;
37 int id;
38} param;
39
40
41void check_afc(gpointer data)
42{
43 //prepare a buffer
44 int buffersize = BUFFER_SIZE * sizeof(int);
45 int *buf = (int *) malloc(buffersize);
46 int *buf2 = (int *) malloc(buffersize);
47 int bytes = 0;
48 //fill buffer
49 int i = 0;
50 for (i = 0; i < BUFFER_SIZE; i++) {
51 buf[i] = ((param *) data)->id * i;
52 }
53
54 //now writes buffer on iphone
55 iphone_afc_file_t file = NULL;
56 char path[50];
57 sprintf(path, "/Buf%i", ((param *) data)->id);
58 iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_WRITE, &file);
59 iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes);
60 iphone_afc_close_file(((param *) data)->afc, file);
61 file = NULL;
62 if (bytes != buffersize)
63 printf("Write operation failed\n");
64
65 //now read it
66 bytes = 0;
67 iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_READ, &file);
68 iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes);
69 iphone_afc_close_file(((param *) data)->afc, file);
70 if (bytes != buffersize)
71 printf("Read operation failed\n");
72
73 //compare buffers
74 for (i = 0; i < BUFFER_SIZE; i++) {
75 if (buf[i] != buf2[i]) {
76 printf("Buffers are differents, stream corrupted\n");
77 break;
78 }
79 }
80
81 //cleanup
82 iphone_afc_delete_file(((param *) data)->afc, path);
83 g_thread_exit(0);
84}
85
86int main(int argc, char *argv[])
87{
88 iphone_lckd_client_t control = NULL;
89 iphone_device_t phone = NULL;
90 GError *err;
91 int port = 0;
92 iphone_afc_client_t afc = NULL;
93
94 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
95 printf("No iPhone found, is it plugged in?\n");
96 return 1;
97 }
98
99 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
100 iphone_free_device(phone);
101 return 1;
102 }
103
104 if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) {
105 iphone_lckd_free_client(control);
106 iphone_free_device(phone);
107 fprintf(stderr, "Something went wrong when starting AFC.");
108 return 1;
109 }
110
111 iphone_afc_new_client(phone, 3432, port, &afc);
112
113 //makes sure thread environment is available
114 if (!g_thread_supported())
115 g_thread_init(NULL);
116
117 GThread *threads[NB_THREADS];
118 param data[NB_THREADS];
119
120 int i = 0;
121 for (i = 0; i < NB_THREADS; i++) {
122 data[i].afc = afc;
123 data[i].id = i + 1;
124 threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err);
125 }
126
127 for (i = 0; i < NB_THREADS; i++) {
128 g_thread_join(threads[i]);
129 }
130
131
132 iphone_lckd_free_client(control);
133 iphone_free_device(phone);
134
135 return 0;
136}
diff --git a/src/lckdclient.c b/src/lckdclient.c
deleted file mode 100644
index b3b9942..0000000
--- a/src/lckdclient.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 * lckdclient.c
3 * Rudimentary command line interface to the Lockdown protocol
4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <glib.h>
25#include <readline/readline.h>
26#include <readline/history.h>
27
28
29#include "usbmux.h"
30#include "iphone.h"
31#include <libiphone/libiphone.h>
32
33
34int main(int argc, char *argv[])
35{
36 int bytes = 0, port = 0, i = 0;
37 iphone_lckd_client_t control = NULL;
38 iphone_device_t phone = NULL;
39
40 iphone_set_debug(1);
41
42 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
43 printf("No iPhone found, is it plugged in?\n");
44 return -1;
45 }
46
47 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
48 iphone_free_device(phone);
49 return -1;
50 }
51
52 char *uid = NULL;
53 if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
54 printf("DeviceUniqueID : %s\n", uid);
55 free(uid);
56 }
57
58 using_history();
59 int loop = TRUE;
60 while (loop) {
61 char *cmd = readline("> ");
62 if (cmd) {
63
64 gchar **args = g_strsplit(cmd, " ", 0);
65
66 int len = 0;
67 if (args) {
68 while (*(args + len)) {
69 g_strstrip(*(args + len));
70 len++;
71 }
72 }
73
74 if (len > 0) {
75 add_history(cmd);
76 if (!strcmp(*args, "quit"))
77 loop = FALSE;
78
79 if (!strcmp(*args, "get") && len == 3) {
80 char *value = NULL;
81 if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args + 1), *(args + 2), &value))
82 printf("Success : value = %s\n", value);
83 else
84 printf("Error\n");
85 }
86
87 if (!strcmp(*args, "start") && len == 2) {
88 int port = 0;
89 iphone_lckd_start_service(control, *(args + 1), &port);
90 printf("%i\n", port);
91 }
92 }
93 g_strfreev(args);
94 }
95 free(cmd);
96 cmd = NULL;
97 }
98 clear_history();
99 iphone_lckd_free_client(control);
100 iphone_free_device(phone);
101
102 return 0;
103}
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 055cb4b..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 * main.c
3 * Rudimentary interface to the iPhone
4 *
5 * Copyright (c) 2008 Zach C. All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <usb.h>
26
27#include "usbmux.h"
28#include "iphone.h"
29
30#include <libxml/parser.h>
31#include <libxml/tree.h>
32
33#include <libiphone/libiphone.h>
34
35
36int main(int argc, char *argv[])
37{
38 int bytes = 0, port = 0, i = 0;
39 iphone_lckd_client_t control = NULL;
40 iphone_device_t phone = NULL;
41
42 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
43 iphone_set_debug(1);
44 } else {
45 iphone_set_debug(0);
46 }
47
48 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
49 printf("No iPhone found, is it plugged in?\n");
50 return -1;
51 }
52
53 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
54 iphone_free_device(phone);
55 return -1;
56 }
57
58 char *uid = NULL;
59 if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
60 printf("DeviceUniqueID : %s\n", uid);
61 free(uid);
62 }
63
64 iphone_lckd_start_service(control, "com.apple.afc", &port);
65
66 if (port) {
67 iphone_afc_client_t afc = NULL;
68 iphone_afc_new_client(phone, 3432, port, &afc);
69 if (afc) {
70 char **dirs = NULL;
71 iphone_afc_get_dir_list(afc, "/eafaedf", &dirs);
72 if (!dirs)
73 iphone_afc_get_dir_list(afc, "/", &dirs);
74 printf("Directory time.\n");
75 for (i = 0; dirs[i]; i++) {
76 printf("/%s\n", dirs[i]);
77 }
78
79 g_strfreev(dirs);
80 iphone_afc_get_devinfo(afc, &dirs);
81 if (dirs) {
82 for (i = 0; dirs[i]; i += 2) {
83 printf("%s: %s\n", dirs[i], dirs[i + 1]);
84 }
85 }
86 g_strfreev(dirs);
87
88 iphone_afc_file_t my_file = NULL;
89 struct stat stbuf;
90 iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf);
91 if (IPHONE_E_SUCCESS ==
92 iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) {
93 printf("A file size: %i\n", stbuf.st_size);
94 char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size);
95 iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes);
96 if (bytes >= 0) {
97 printf("The file's data:\n");
98 fwrite(file_data, 1, bytes, stdout);
99 }
100 printf("\nClosing my file.\n");
101 iphone_afc_close_file(afc, my_file);
102 free(file_data);
103 } else
104 printf("couldn't open a file\n");
105
106 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_WRITE, &my_file);
107 if (my_file) {
108 char *outdatafile = strdup("this is a bitchin text file\n");
109 iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes);
110 free(outdatafile);
111 if (bytes > 0)
112 printf("Wrote a surprise. ;)\n");
113 else
114 printf("I wanted to write a surprise, but... :(\n");
115 iphone_afc_close_file(afc, my_file);
116 }
117 printf("Deleting a file...\n");
118 bytes = iphone_afc_delete_file(afc, "/delme");
119 if (bytes)
120 printf("Success.\n");
121 else
122 printf("Failure. (expected unless you have a /delme file on your phone)\n");
123
124 printf("Renaming a file...\n");
125 bytes = iphone_afc_rename_file(afc, "/renme", "/renme2");
126 if (bytes > 0)
127 printf("Success.\n");
128 else
129 printf("Failure. (expected unless you have a /renme file on your phone)\n");
130
131 printf("Seek & read\n");
132 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_READ, &my_file);
133 if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5))
134 printf("WARN: SEEK DID NOT WORK\n");
135 char *threeletterword = (char *) malloc(sizeof(char) * 5);
136 iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes);
137 threeletterword[3] = '\0';
138 if (bytes > 0)
139 printf("Result: %s\n", threeletterword);
140 else
141 printf("Couldn't read!\n");
142 free(threeletterword);
143 iphone_afc_close_file(afc, my_file);
144
145 }
146 iphone_afc_free_client(afc);
147 } else {
148 printf("Start service failure.\n");
149 }
150
151 printf("All done.\n");
152
153 iphone_lckd_free_client(control);
154 iphone_free_device(phone);
155
156 return 0;
157}