diff options
| author | 2008-12-13 12:21:03 +0100 | |
|---|---|---|
| committer | 2008-12-13 12:21:03 +0100 | |
| commit | 3fdd24aea06a9bf38d9d34fb8bccbb7023ed3100 (patch) | |
| tree | 1080d26eca01c885efb33f3f98821a981a25e8b4 /dev | |
| parent | 3d8ba053deeacd74e621469d3d45d1db38ee411a (diff) | |
| download | libplist-3fdd24aea06a9bf38d9d34fb8bccbb7023ed3100.tar.gz libplist-3fdd24aea06a9bf38d9d34fb8bccbb7023ed3100.tar.bz2 | |
Fork libiphone and remove anything non plist specific.
Update library and make related files acordingly .
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Makefile.am | 24 | ||||
| -rw-r--r-- | dev/afccheck.c | 134 | ||||
| -rw-r--r-- | dev/lckdclient.c | 101 | ||||
| -rw-r--r-- | dev/main.c | 154 | ||||
| -rw-r--r-- | dev/plutil.c | 118 | ||||
| -rw-r--r-- | dev/plutil.h | 13 |
6 files changed, 0 insertions, 544 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am deleted file mode 100644 index 95b4d61..0000000 --- a/dev/Makefile.am +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | INCLUDES = -I$(top_srcdir)/include | ||
| 2 | |||
| 3 | AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g | ||
| 4 | AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) | ||
| 5 | |||
| 6 | bin_PROGRAMS = iphoneclient lckd-client afccheck plutil | ||
| 7 | |||
| 8 | iphoneclient_SOURCES = main.c | ||
| 9 | iphoneclient_LDADD = ../src/libiphone.la | ||
| 10 | |||
| 11 | lckd_client_SOURCES = lckdclient.c | ||
| 12 | lckd_client_CFLAGS = $(AM_CFLAGS) | ||
| 13 | lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) | ||
| 14 | lckd_client_LDADD = ../src/libiphone.la | ||
| 15 | |||
| 16 | afccheck_SOURCES = afccheck.c | ||
| 17 | afccheck_CFLAGS = $(AM_CFLAGS) | ||
| 18 | afccheck_LDFLAGS = $(AM_LDFLAGS) | ||
| 19 | afccheck_LDADD = ../src/libiphone.la | ||
| 20 | |||
| 21 | plutil_SOURCES = plutil.c | ||
| 22 | plutil_CFLAGS = $(AM_CFLAGS) | ||
| 23 | plutil_LDFLAGS = $(AM_LDFLAGS) | ||
| 24 | plutil_LDADD = ../src/libiphone.la | ||
diff --git a/dev/afccheck.c b/dev/afccheck.c deleted file mode 100644 index 0ff420a..0000000 --- a/dev/afccheck.c +++ /dev/null | |||
| @@ -1,134 +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 <stdlib.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <glib.h> | ||
| 26 | |||
| 27 | #include <libiphone/libiphone.h> | ||
| 28 | |||
| 29 | #define BUFFER_SIZE 20000 | ||
| 30 | #define NB_THREADS 10 | ||
| 31 | |||
| 32 | |||
| 33 | typedef struct { | ||
| 34 | iphone_afc_client_t afc; | ||
| 35 | int id; | ||
| 36 | } param; | ||
| 37 | |||
| 38 | |||
| 39 | void check_afc(gpointer data) | ||
| 40 | { | ||
| 41 | //prepare a buffer | ||
| 42 | int buffersize = BUFFER_SIZE * sizeof(int); | ||
| 43 | int *buf = (int *) malloc(buffersize); | ||
| 44 | int *buf2 = (int *) malloc(buffersize); | ||
| 45 | int bytes = 0; | ||
| 46 | //fill buffer | ||
| 47 | int i = 0; | ||
| 48 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 49 | buf[i] = ((param *) data)->id * i; | ||
| 50 | } | ||
| 51 | |||
| 52 | //now writes buffer on iphone | ||
| 53 | iphone_afc_file_t file = NULL; | ||
| 54 | char path[50]; | ||
| 55 | sprintf(path, "/Buf%i", ((param *) data)->id); | ||
| 56 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_WRITE, &file); | ||
| 57 | iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | ||
| 58 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 59 | file = NULL; | ||
| 60 | if (bytes != buffersize) | ||
| 61 | printf("Write operation failed\n"); | ||
| 62 | |||
| 63 | //now read it | ||
| 64 | bytes = 0; | ||
| 65 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_READ, &file); | ||
| 66 | iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); | ||
| 67 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 68 | if (bytes != buffersize) | ||
| 69 | printf("Read operation failed\n"); | ||
| 70 | |||
| 71 | //compare buffers | ||
| 72 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 73 | if (buf[i] != buf2[i]) { | ||
| 74 | printf("Buffers are differents, stream corrupted\n"); | ||
| 75 | break; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | //cleanup | ||
| 80 | iphone_afc_delete_file(((param *) data)->afc, path); | ||
| 81 | g_thread_exit(0); | ||
| 82 | } | ||
| 83 | |||
| 84 | int main(int argc, char *argv[]) | ||
| 85 | { | ||
| 86 | iphone_lckd_client_t control = NULL; | ||
| 87 | iphone_device_t phone = NULL; | ||
| 88 | GError *err; | ||
| 89 | int port = 0; | ||
| 90 | iphone_afc_client_t afc = NULL; | ||
| 91 | |||
| 92 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 93 | printf("No iPhone found, is it plugged in?\n"); | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 98 | iphone_free_device(phone); | ||
| 99 | return 1; | ||
| 100 | } | ||
| 101 | |||
| 102 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { | ||
| 103 | iphone_lckd_free_client(control); | ||
| 104 | iphone_free_device(phone); | ||
| 105 | fprintf(stderr, "Something went wrong when starting AFC."); | ||
| 106 | return 1; | ||
| 107 | } | ||
| 108 | |||
| 109 | iphone_afc_new_client(phone, 3432, port, &afc); | ||
| 110 | |||
| 111 | //makes sure thread environment is available | ||
| 112 | if (!g_thread_supported()) | ||
| 113 | g_thread_init(NULL); | ||
| 114 | |||
| 115 | GThread *threads[NB_THREADS]; | ||
| 116 | param data[NB_THREADS]; | ||
| 117 | |||
| 118 | int i = 0; | ||
| 119 | for (i = 0; i < NB_THREADS; i++) { | ||
| 120 | data[i].afc = afc; | ||
| 121 | data[i].id = i + 1; | ||
| 122 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | ||
| 123 | } | ||
| 124 | |||
| 125 | for (i = 0; i < NB_THREADS; i++) { | ||
| 126 | g_thread_join(threads[i]); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | iphone_lckd_free_client(control); | ||
| 131 | iphone_free_device(phone); | ||
| 132 | |||
| 133 | return 0; | ||
| 134 | } | ||
diff --git a/dev/lckdclient.c b/dev/lckdclient.c deleted file mode 100644 index c96f052..0000000 --- a/dev/lckdclient.c +++ /dev/null | |||
| @@ -1,101 +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 <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <glib.h> | ||
| 26 | #include <readline/readline.h> | ||
| 27 | #include <readline/history.h> | ||
| 28 | |||
| 29 | #include <libiphone/libiphone.h> | ||
| 30 | |||
| 31 | |||
| 32 | int main(int argc, char *argv[]) | ||
| 33 | { | ||
| 34 | int bytes = 0, port = 0, i = 0; | ||
| 35 | iphone_lckd_client_t control = NULL; | ||
| 36 | iphone_device_t phone = NULL; | ||
| 37 | |||
| 38 | iphone_set_debug(1); | ||
| 39 | |||
| 40 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 41 | printf("No iPhone found, is it plugged in?\n"); | ||
| 42 | return -1; | ||
| 43 | } | ||
| 44 | |||
| 45 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 46 | iphone_free_device(phone); | ||
| 47 | return -1; | ||
| 48 | } | ||
| 49 | |||
| 50 | char *uid = NULL; | ||
| 51 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { | ||
| 52 | printf("DeviceUniqueID : %s\n", uid); | ||
| 53 | free(uid); | ||
| 54 | } | ||
| 55 | |||
| 56 | using_history(); | ||
| 57 | int loop = TRUE; | ||
| 58 | while (loop) { | ||
| 59 | char *cmd = readline("> "); | ||
| 60 | if (cmd) { | ||
| 61 | |||
| 62 | gchar **args = g_strsplit(cmd, " ", 0); | ||
| 63 | |||
| 64 | int len = 0; | ||
| 65 | if (args) { | ||
| 66 | while (*(args + len)) { | ||
| 67 | g_strstrip(*(args + len)); | ||
| 68 | len++; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | if (len > 0) { | ||
| 73 | add_history(cmd); | ||
| 74 | if (!strcmp(*args, "quit")) | ||
| 75 | loop = FALSE; | ||
| 76 | |||
| 77 | if (!strcmp(*args, "get") && len == 3) { | ||
| 78 | char *value = NULL; | ||
| 79 | if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args + 1), *(args + 2), &value)) | ||
| 80 | printf("Success : value = %s\n", value); | ||
| 81 | else | ||
| 82 | printf("Error\n"); | ||
| 83 | } | ||
| 84 | |||
| 85 | if (!strcmp(*args, "start") && len == 2) { | ||
| 86 | int port = 0; | ||
| 87 | iphone_lckd_start_service(control, *(args + 1), &port); | ||
| 88 | printf("%i\n", port); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | g_strfreev(args); | ||
| 92 | } | ||
| 93 | free(cmd); | ||
| 94 | cmd = NULL; | ||
| 95 | } | ||
| 96 | clear_history(); | ||
| 97 | iphone_lckd_free_client(control); | ||
| 98 | iphone_free_device(phone); | ||
| 99 | |||
| 100 | return 0; | ||
| 101 | } | ||
diff --git a/dev/main.c b/dev/main.c deleted file mode 100644 index 4974eef..0000000 --- a/dev/main.c +++ /dev/null | |||
| @@ -1,154 +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 <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", (int) 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 | } | ||
diff --git a/dev/plutil.c b/dev/plutil.c deleted file mode 100644 index 3d93797..0000000 --- a/dev/plutil.c +++ /dev/null | |||
| @@ -1,118 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * main.c for plistutil | ||
| 3 | * right now just prints debug shit | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "../src/plist.h" | ||
| 7 | #include "plutil.h" | ||
| 8 | #include <glib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | |||
| 13 | |||
| 14 | int main(int argc, char *argv[]) | ||
| 15 | { | ||
| 16 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | ||
| 17 | Options *options = parse_arguments(argc, argv); | ||
| 18 | |||
| 19 | if (!options) { | ||
| 20 | print_usage(); | ||
| 21 | return 0; | ||
| 22 | } | ||
| 23 | |||
| 24 | iphone_set_debug(options->debug); | ||
| 25 | |||
| 26 | //read input file | ||
| 27 | FILE *iplist = fopen(options->in_file, "r"); | ||
| 28 | if (!iplist) | ||
| 29 | return 1; | ||
| 30 | stat(options->in_file, filestats); | ||
| 31 | char *plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); | ||
| 32 | fread(plist_entire, sizeof(char), filestats->st_size, iplist); | ||
| 33 | fclose(iplist); | ||
| 34 | |||
| 35 | |||
| 36 | //convert one format to another | ||
| 37 | plist_t root_node = NULL; | ||
| 38 | char *plist_out = NULL; | ||
| 39 | int size = 0; | ||
| 40 | |||
| 41 | if (memcmp(plist_entire, "bplist00", 8) == 0) { | ||
| 42 | bin_to_plist(plist_entire, filestats->st_size, &root_node); | ||
| 43 | plist_to_xml(root_node, &plist_out, &size); | ||
| 44 | } else { | ||
| 45 | xml_to_plist(plist_entire, filestats->st_size, &root_node); | ||
| 46 | plist_to_bin(root_node, &plist_out, &size); | ||
| 47 | } | ||
| 48 | |||
| 49 | if (plist_out) { | ||
| 50 | if (options->out_file != NULL) { | ||
| 51 | FILE *oplist = fopen(options->out_file, "wb"); | ||
| 52 | if (!oplist) | ||
| 53 | return 1; | ||
| 54 | fwrite(plist_out, size, sizeof(char), oplist); | ||
| 55 | fclose(oplist); | ||
| 56 | } | ||
| 57 | //if no output file specified, write to stdout | ||
| 58 | else | ||
| 59 | fwrite(plist_out, size, sizeof(char), stdout); | ||
| 60 | } else | ||
| 61 | printf("ERROR\n"); | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | Options *parse_arguments(int argc, char *argv[]) | ||
| 66 | { | ||
| 67 | int i = 0; | ||
| 68 | |||
| 69 | Options *options = (Options *) malloc(sizeof(Options)); | ||
| 70 | memset(options, 0, sizeof(Options)); | ||
| 71 | |||
| 72 | for (i = 1; i < argc; i++) { | ||
| 73 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { | ||
| 74 | if ((i + 1) == argc) { | ||
| 75 | free(options); | ||
| 76 | return NULL; | ||
| 77 | } | ||
| 78 | options->in_file = argv[i + 1]; | ||
| 79 | i++; | ||
| 80 | continue; | ||
| 81 | } | ||
| 82 | |||
| 83 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { | ||
| 84 | if ((i + 1) == argc) { | ||
| 85 | free(options); | ||
| 86 | return NULL; | ||
| 87 | } | ||
| 88 | options->out_file = argv[i + 1]; | ||
| 89 | i++; | ||
| 90 | continue; | ||
| 91 | } | ||
| 92 | |||
| 93 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { | ||
| 94 | options->debug = 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { | ||
| 98 | free(options); | ||
| 99 | return NULL; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | if (!options->in_file /*|| !options->out_file */ ) { | ||
| 104 | free(options); | ||
| 105 | return NULL; | ||
| 106 | } | ||
| 107 | |||
| 108 | return options; | ||
| 109 | } | ||
| 110 | |||
| 111 | void print_usage() | ||
| 112 | { | ||
| 113 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); | ||
| 114 | printf("\n"); | ||
| 115 | printf("\t-i or --infile: The file to read in.\n"); | ||
| 116 | printf("\t-o or --outfile: The file to convert to.\n"); | ||
| 117 | printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); | ||
| 118 | } | ||
diff --git a/dev/plutil.h b/dev/plutil.h deleted file mode 100644 index 2146307..0000000 --- a/dev/plutil.h +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | |||
| 2 | /* | ||
| 3 | * main.h - header for plistutil | ||
| 4 | * Written by FxChiP | ||
| 5 | */ | ||
| 6 | |||
| 7 | typedef struct _options { | ||
| 8 | char *in_file, *out_file; | ||
| 9 | uint8_t debug, in_fmt, out_fmt; | ||
| 10 | } Options; | ||
| 11 | |||
| 12 | Options *parse_arguments(int argc, char *argv[]); | ||
| 13 | void print_usage(); | ||
