diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/afccheck.c | 133 | ||||
| -rw-r--r-- | dev/lckdclient.c | 100 | ||||
| -rw-r--r-- | dev/main.c | 154 |
3 files changed, 387 insertions, 0 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c new file mode 100644 index 0000000..028110a --- /dev/null +++ b/dev/afccheck.c | |||
| @@ -0,0 +1,133 @@ | |||
| 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 <libiphone/libiphone.h> | ||
| 27 | |||
| 28 | #define BUFFER_SIZE 20000 | ||
| 29 | #define NB_THREADS 10 | ||
| 30 | |||
| 31 | |||
| 32 | typedef struct { | ||
| 33 | iphone_afc_client_t afc; | ||
| 34 | int id; | ||
| 35 | } param; | ||
| 36 | |||
| 37 | |||
| 38 | void check_afc(gpointer data) | ||
| 39 | { | ||
| 40 | //prepare a buffer | ||
| 41 | int buffersize = BUFFER_SIZE * sizeof(int); | ||
| 42 | int *buf = (int *) malloc(buffersize); | ||
| 43 | int *buf2 = (int *) malloc(buffersize); | ||
| 44 | int bytes = 0; | ||
| 45 | //fill buffer | ||
| 46 | int i = 0; | ||
| 47 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 48 | buf[i] = ((param *) data)->id * i; | ||
| 49 | } | ||
| 50 | |||
| 51 | //now writes buffer on iphone | ||
| 52 | iphone_afc_file_t file = NULL; | ||
| 53 | char path[50]; | ||
| 54 | sprintf(path, "/Buf%i", ((param *) data)->id); | ||
| 55 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_WRITE, &file); | ||
| 56 | iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | ||
| 57 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 58 | file = NULL; | ||
| 59 | if (bytes != buffersize) | ||
| 60 | printf("Write operation failed\n"); | ||
| 61 | |||
| 62 | //now read it | ||
| 63 | bytes = 0; | ||
| 64 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_READ, &file); | ||
| 65 | iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); | ||
| 66 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 67 | if (bytes != buffersize) | ||
| 68 | printf("Read operation failed\n"); | ||
| 69 | |||
| 70 | //compare buffers | ||
| 71 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 72 | if (buf[i] != buf2[i]) { | ||
| 73 | printf("Buffers are differents, stream corrupted\n"); | ||
| 74 | break; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | //cleanup | ||
| 79 | iphone_afc_delete_file(((param *) data)->afc, path); | ||
| 80 | g_thread_exit(0); | ||
| 81 | } | ||
| 82 | |||
| 83 | int main(int argc, char *argv[]) | ||
| 84 | { | ||
| 85 | iphone_lckd_client_t control = NULL; | ||
| 86 | iphone_device_t phone = NULL; | ||
| 87 | GError *err; | ||
| 88 | int port = 0; | ||
| 89 | iphone_afc_client_t afc = NULL; | ||
| 90 | |||
| 91 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 92 | printf("No iPhone found, is it plugged in?\n"); | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 97 | iphone_free_device(phone); | ||
| 98 | return 1; | ||
| 99 | } | ||
| 100 | |||
| 101 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { | ||
| 102 | iphone_lckd_free_client(control); | ||
| 103 | iphone_free_device(phone); | ||
| 104 | fprintf(stderr, "Something went wrong when starting AFC."); | ||
| 105 | return 1; | ||
| 106 | } | ||
| 107 | |||
| 108 | iphone_afc_new_client(phone, 3432, port, &afc); | ||
| 109 | |||
| 110 | //makes sure thread environment is available | ||
| 111 | if (!g_thread_supported()) | ||
| 112 | g_thread_init(NULL); | ||
| 113 | |||
| 114 | GThread *threads[NB_THREADS]; | ||
| 115 | param data[NB_THREADS]; | ||
| 116 | |||
| 117 | int i = 0; | ||
| 118 | for (i = 0; i < NB_THREADS; i++) { | ||
| 119 | data[i].afc = afc; | ||
| 120 | data[i].id = i + 1; | ||
| 121 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | ||
| 122 | } | ||
| 123 | |||
| 124 | for (i = 0; i < NB_THREADS; i++) { | ||
| 125 | g_thread_join(threads[i]); | ||
| 126 | } | ||
| 127 | |||
| 128 | |||
| 129 | iphone_lckd_free_client(control); | ||
| 130 | iphone_free_device(phone); | ||
| 131 | |||
| 132 | return 0; | ||
| 133 | } | ||
diff --git a/dev/lckdclient.c b/dev/lckdclient.c new file mode 100644 index 0000000..96bc27d --- /dev/null +++ b/dev/lckdclient.c | |||
| @@ -0,0 +1,100 @@ | |||
| 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 | #include <libiphone/libiphone.h> | ||
| 29 | |||
| 30 | |||
| 31 | int main(int argc, char *argv[]) | ||
| 32 | { | ||
| 33 | int bytes = 0, port = 0, i = 0; | ||
| 34 | iphone_lckd_client_t control = NULL; | ||
| 35 | iphone_device_t phone = NULL; | ||
| 36 | |||
| 37 | iphone_set_debug(1); | ||
| 38 | |||
| 39 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 40 | printf("No iPhone found, is it plugged in?\n"); | ||
| 41 | return -1; | ||
| 42 | } | ||
| 43 | |||
| 44 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 45 | iphone_free_device(phone); | ||
| 46 | return -1; | ||
| 47 | } | ||
| 48 | |||
| 49 | char *uid = NULL; | ||
| 50 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { | ||
| 51 | printf("DeviceUniqueID : %s\n", uid); | ||
| 52 | free(uid); | ||
| 53 | } | ||
| 54 | |||
| 55 | using_history(); | ||
| 56 | int loop = TRUE; | ||
| 57 | while (loop) { | ||
| 58 | char *cmd = readline("> "); | ||
| 59 | if (cmd) { | ||
| 60 | |||
| 61 | gchar **args = g_strsplit(cmd, " ", 0); | ||
| 62 | |||
| 63 | int len = 0; | ||
| 64 | if (args) { | ||
| 65 | while (*(args + len)) { | ||
| 66 | g_strstrip(*(args + len)); | ||
| 67 | len++; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | if (len > 0) { | ||
| 72 | add_history(cmd); | ||
| 73 | if (!strcmp(*args, "quit")) | ||
| 74 | loop = FALSE; | ||
| 75 | |||
| 76 | if (!strcmp(*args, "get") && len == 3) { | ||
| 77 | char *value = NULL; | ||
| 78 | if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args + 1), *(args + 2), &value)) | ||
| 79 | printf("Success : value = %s\n", value); | ||
| 80 | else | ||
| 81 | printf("Error\n"); | ||
| 82 | } | ||
| 83 | |||
| 84 | if (!strcmp(*args, "start") && len == 2) { | ||
| 85 | int port = 0; | ||
| 86 | iphone_lckd_start_service(control, *(args + 1), &port); | ||
| 87 | printf("%i\n", port); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | g_strfreev(args); | ||
| 91 | } | ||
| 92 | free(cmd); | ||
| 93 | cmd = NULL; | ||
| 94 | } | ||
| 95 | clear_history(); | ||
| 96 | iphone_lckd_free_client(control); | ||
| 97 | iphone_free_device(phone); | ||
| 98 | |||
| 99 | return 0; | ||
| 100 | } | ||
diff --git a/dev/main.c b/dev/main.c new file mode 100644 index 0000000..2dbfb4a --- /dev/null +++ b/dev/main.c | |||
| @@ -0,0 +1,154 @@ | |||
| 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 <libxml/parser.h> | ||
| 28 | #include <libxml/tree.h> | ||
| 29 | |||
| 30 | #include <libiphone/libiphone.h> | ||
| 31 | |||
| 32 | |||
| 33 | int main(int argc, char *argv[]) | ||
| 34 | { | ||
| 35 | int bytes = 0, port = 0, i = 0; | ||
| 36 | iphone_lckd_client_t control = NULL; | ||
| 37 | iphone_device_t phone = NULL; | ||
| 38 | |||
| 39 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { | ||
| 40 | iphone_set_debug(1); | ||
| 41 | } else { | ||
| 42 | iphone_set_debug(0); | ||
| 43 | } | ||
| 44 | |||
| 45 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 46 | printf("No iPhone found, is it plugged in?\n"); | ||
| 47 | return -1; | ||
| 48 | } | ||
| 49 | |||
| 50 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 51 | iphone_free_device(phone); | ||
| 52 | return -1; | ||
| 53 | } | ||
| 54 | |||
| 55 | char *uid = NULL; | ||
| 56 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { | ||
| 57 | printf("DeviceUniqueID : %s\n", uid); | ||
| 58 | free(uid); | ||
| 59 | } | ||
| 60 | |||
| 61 | iphone_lckd_start_service(control, "com.apple.afc", &port); | ||
| 62 | |||
| 63 | if (port) { | ||
| 64 | iphone_afc_client_t afc = NULL; | ||
| 65 | iphone_afc_new_client(phone, 3432, port, &afc); | ||
| 66 | if (afc) { | ||
| 67 | char **dirs = NULL; | ||
| 68 | iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); | ||
| 69 | if (!dirs) | ||
| 70 | iphone_afc_get_dir_list(afc, "/", &dirs); | ||
| 71 | printf("Directory time.\n"); | ||
| 72 | for (i = 0; dirs[i]; i++) { | ||
| 73 | printf("/%s\n", dirs[i]); | ||
| 74 | } | ||
| 75 | |||
| 76 | g_strfreev(dirs); | ||
| 77 | iphone_afc_get_devinfo(afc, &dirs); | ||
| 78 | if (dirs) { | ||
| 79 | for (i = 0; dirs[i]; i += 2) { | ||
| 80 | printf("%s: %s\n", dirs[i], dirs[i + 1]); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | g_strfreev(dirs); | ||
| 84 | |||
| 85 | iphone_afc_file_t my_file = NULL; | ||
| 86 | struct stat stbuf; | ||
| 87 | iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); | ||
| 88 | if (IPHONE_E_SUCCESS == | ||
| 89 | iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { | ||
| 90 | printf("A file size: %i\n", stbuf.st_size); | ||
| 91 | char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size); | ||
| 92 | iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); | ||
| 93 | if (bytes >= 0) { | ||
| 94 | printf("The file's data:\n"); | ||
| 95 | fwrite(file_data, 1, bytes, stdout); | ||
| 96 | } | ||
| 97 | printf("\nClosing my file.\n"); | ||
| 98 | iphone_afc_close_file(afc, my_file); | ||
| 99 | free(file_data); | ||
| 100 | } else | ||
| 101 | printf("couldn't open a file\n"); | ||
| 102 | |||
| 103 | iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_WRITE, &my_file); | ||
| 104 | if (my_file) { | ||
| 105 | char *outdatafile = strdup("this is a bitchin text file\n"); | ||
| 106 | iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); | ||
| 107 | free(outdatafile); | ||
| 108 | if (bytes > 0) | ||
| 109 | printf("Wrote a surprise. ;)\n"); | ||
| 110 | else | ||
| 111 | printf("I wanted to write a surprise, but... :(\n"); | ||
| 112 | iphone_afc_close_file(afc, my_file); | ||
| 113 | } | ||
| 114 | printf("Deleting a file...\n"); | ||
| 115 | bytes = iphone_afc_delete_file(afc, "/delme"); | ||
| 116 | if (bytes) | ||
| 117 | printf("Success.\n"); | ||
| 118 | else | ||
| 119 | printf("Failure. (expected unless you have a /delme file on your phone)\n"); | ||
| 120 | |||
| 121 | printf("Renaming a file...\n"); | ||
| 122 | bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); | ||
| 123 | if (bytes > 0) | ||
| 124 | printf("Success.\n"); | ||
| 125 | else | ||
| 126 | printf("Failure. (expected unless you have a /renme file on your phone)\n"); | ||
| 127 | |||
| 128 | printf("Seek & read\n"); | ||
| 129 | iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_READ, &my_file); | ||
| 130 | if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5)) | ||
| 131 | printf("WARN: SEEK DID NOT WORK\n"); | ||
| 132 | char *threeletterword = (char *) malloc(sizeof(char) * 5); | ||
| 133 | iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); | ||
| 134 | threeletterword[3] = '\0'; | ||
| 135 | if (bytes > 0) | ||
| 136 | printf("Result: %s\n", threeletterword); | ||
| 137 | else | ||
| 138 | printf("Couldn't read!\n"); | ||
| 139 | free(threeletterword); | ||
| 140 | iphone_afc_close_file(afc, my_file); | ||
| 141 | |||
| 142 | } | ||
| 143 | iphone_afc_free_client(afc); | ||
| 144 | } else { | ||
| 145 | printf("Start service failure.\n"); | ||
| 146 | } | ||
| 147 | |||
| 148 | printf("All done.\n"); | ||
| 149 | |||
| 150 | iphone_lckd_free_client(control); | ||
| 151 | iphone_free_device(phone); | ||
| 152 | |||
| 153 | return 0; | ||
| 154 | } | ||
