From f4c4b783c8dbe2fe8e7e6f6b5f19f0d44b489c9a Mon Sep 17 00:00:00 2001 From: Zach C Date: Sun, 31 Aug 2008 11:25:22 -0700 Subject: Added binary-plist support (tweaked slightly to move stuff around) Signed-off-by: Matt Colyer fix makefile to take correct main function into account --- dev/Makefile.am | 9 ++- dev/plutil.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dev/plutil.h | 13 +++++ 3 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 dev/plutil.c create mode 100644 dev/plutil.h (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index 4833728..95b4d61 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) -bin_PROGRAMS = iphoneclient lckd-client afccheck +bin_PROGRAMS = iphoneclient lckd-client afccheck plutil iphoneclient_SOURCES = main.c iphoneclient_LDADD = ../src/libiphone.la @@ -16,4 +16,9 @@ lckd_client_LDADD = ../src/libiphone.la afccheck_SOURCES = afccheck.c afccheck_CFLAGS = $(AM_CFLAGS) afccheck_LDFLAGS = $(AM_LDFLAGS) -afccheck_LDADD = ../src/libiphone.la \ No newline at end of file +afccheck_LDADD = ../src/libiphone.la + +plutil_SOURCES = plutil.c +plutil_CFLAGS = $(AM_CFLAGS) +plutil_LDFLAGS = $(AM_LDFLAGS) +plutil_LDADD = ../src/libiphone.la diff --git a/dev/plutil.c b/dev/plutil.c new file mode 100644 index 0000000..208d7df --- /dev/null +++ b/dev/plutil.c @@ -0,0 +1,171 @@ +/* + * main.c for plistutil + * right now just prints debug shit + */ + +#include "../src/plist.h" +#include "plutil.h" + +int debug = 0; + +void print_nodes(bplist_node *root_node) { + // Yay, great. Let's print the list of nodes recursively... + int i = 0; + if (!root_node) return; // or not, because the programmer's stupid. + + switch (root_node->type) { + case BPLIST_DICT: + printf("Dictionary node.\nLength %i\n", root_node->length); + for (i = 0; i < (root_node->length * 2); i+=2) { + // HI! + printf("Key: "); + print_nodes(root_node->subnodes[i]); + printf("Value: "); + print_nodes(root_node->subnodes[i+1]); + } + printf("End dictionary node.\n\n"); + break; + + case BPLIST_ARRAY: + printf("Array node.\n"); + for (i = 0; i < root_node->length; i++) { + printf("\tElement %i: ", i); + print_nodes(root_node->subnodes[i]); + } + break; + + case BPLIST_INT: + if (root_node->length == sizeof(uint8_t)) { + printf("Integer: %i\n", root_node->intval8); + } else if (root_node->length == sizeof(uint16_t)) { + printf("Integer: %i\n", root_node->intval16); + } else if (root_node->length == sizeof(uint32_t)) { + printf("Integer: %i\n", root_node->intval32); + } + break; + + case BPLIST_STRING: + case BPLIST_DATA: + printf("String/data: "); + fwrite(root_node->strval, sizeof(char), root_node->length, stdout); + fflush(stdout); + printf("\n"); + break; + + case BPLIST_UNICODE: + printf("Unicode data, may appear crappy: "); + fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); + fflush(stdout); + printf("\n"); + break; + + case BPLIST_TRUE: + printf("True.\n"); + break; + + case BPLIST_FALSE: + printf("False.\n"); + break; + + case BPLIST_REAL: + case BPLIST_DATE: + printf("Real(?): %f\n", root_node->realval); + break; + + default: + printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length); + break; + } +} + +int main(int argc, char *argv[]) { + struct stat *filestats = (struct stat *)malloc(sizeof(struct stat)); + uint32_t position = 0; + Options *options = parse_arguments(argc, argv); + int argh = 0; + + printf("plistutil version 0.2 written by FxChiP\n"); + + if (!options) { + print_usage(); + return 0; + } + + debug = options->debug; + + FILE *bplist = fopen(options->in_file, "r"); + + stat(options->in_file, filestats); + + printf("here?\n"); + char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1)); + //argh = fgets(bplist_entire, filestats->st_size, bplist); + argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); + printf("read %i bytes\n", argh); + fclose(bplist); + printf("or here?\n"); + // bplist_entire contains our stuff + bplist_node *root_node; + root_node = parse_nodes(bplist_entire, filestats->st_size, &position); + printf("plutil debug mode\n\n"); + printf("file size %i\n\n", filestats->st_size); + if (!root_node) { + printf("Invalid binary plist (or some other error occurred.)\n"); + return 0; + } + print_nodes(root_node); + return 0; + } + +Options *parse_arguments(int argc, char *argv[]) { + int i = 0; + + Options *options = (Options*)malloc(sizeof(Options)); + memset(options, 0, sizeof(Options)); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { + if ((i+1) == argc) { + free(options); + return NULL; + } + options->in_file = argv[i+1]; + i++; + continue; + } + + if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { + if ((i+1) == argc) { + free(options); + return NULL; + } + options->out_file = argv[i+1]; + i++; + continue; + } + + if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { + options->debug = 1; + } + + if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { + free(options); + return NULL; + } + } + + if (!options->in_file /*|| !options->out_file*/) { + free(options); + return NULL; + } + + return options; +} + +void print_usage() { + printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); + printf("\n"); + printf("\t-i or --infile: The file to read in.\n"); + printf("\t-o or --outfile: The file to convert to.\n"); + printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); +} diff --git a/dev/plutil.h b/dev/plutil.h new file mode 100644 index 0000000..2146307 --- /dev/null +++ b/dev/plutil.h @@ -0,0 +1,13 @@ + +/* + * main.h - header for plistutil + * Written by FxChiP + */ + +typedef struct _options { + char *in_file, *out_file; + uint8_t debug, in_fmt, out_fmt; +} Options; + +Options *parse_arguments(int argc, char *argv[]); +void print_usage(); -- cgit v1.1-32-gdbae From 0bca81e7c8ce5ba53390271e5c7eaa7a5f281c91 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sun, 31 Aug 2008 22:50:37 +0200 Subject: Output binary data base64 encoded (and 60 cols wide) --- dev/plutil.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index 208d7df..1c7b140 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -45,12 +45,19 @@ void print_nodes(bplist_node *root_node) { break; case BPLIST_STRING: - case BPLIST_DATA: - printf("String/data: "); + printf("String: "); fwrite(root_node->strval, sizeof(char), root_node->length, stdout); fflush(stdout); printf("\n"); break; + + case BPLIST_DATA: + printf("Data: "); + char* data = g_base64_encode(root_node->strval,root_node->length); + fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); + fflush(stdout); + printf("\n"); + break; case BPLIST_UNICODE: printf("Unicode data, may appear crappy: "); -- cgit v1.1-32-gdbae From aed2c025f6e47dc769675e564cc574adc496a88a Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Tue, 25 Nov 2008 19:14:27 +0100 Subject: fix some warnings and indent --- dev/lckdclient.c | 1 + dev/main.c | 2 +- dev/plutil.c | 219 ++++++++++++++++++++++++++++--------------------------- 3 files changed, 115 insertions(+), 107 deletions(-) (limited to 'dev') diff --git a/dev/lckdclient.c b/dev/lckdclient.c index 96bc27d..c96f052 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -20,6 +20,7 @@ */ #include +#include #include #include #include diff --git a/dev/main.c b/dev/main.c index 2dbfb4a..4974eef 100644 --- a/dev/main.c +++ b/dev/main.c @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { - printf("A file size: %i\n", stbuf.st_size); + printf("A file size: %i\n", (int) stbuf.st_size); char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size); iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); if (bytes >= 0) { diff --git a/dev/plutil.c b/dev/plutil.c index 1c7b140..d1c3ddd 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -5,171 +5,178 @@ #include "../src/plist.h" #include "plutil.h" +#include +#include +#include +#include -int debug = 0; - -void print_nodes(bplist_node *root_node) { +void print_nodes(bplist_node * root_node) +{ // Yay, great. Let's print the list of nodes recursively... int i = 0; - if (!root_node) return; // or not, because the programmer's stupid. - + if (!root_node) + return; // or not, because the programmer's stupid. + switch (root_node->type) { - case BPLIST_DICT: - printf("Dictionary node.\nLength %i\n", root_node->length); - for (i = 0; i < (root_node->length * 2); i+=2) { - // HI! - printf("Key: "); - print_nodes(root_node->subnodes[i]); - printf("Value: "); - print_nodes(root_node->subnodes[i+1]); - } - printf("End dictionary node.\n\n"); - break; - - case BPLIST_ARRAY: - printf("Array node.\n"); - for (i = 0; i < root_node->length; i++) { - printf("\tElement %i: ", i); - print_nodes(root_node->subnodes[i]); - } - break; - - case BPLIST_INT: - if (root_node->length == sizeof(uint8_t)) { - printf("Integer: %i\n", root_node->intval8); - } else if (root_node->length == sizeof(uint16_t)) { - printf("Integer: %i\n", root_node->intval16); - } else if (root_node->length == sizeof(uint32_t)) { - printf("Integer: %i\n", root_node->intval32); - } - break; - - case BPLIST_STRING: - printf("String: "); - fwrite(root_node->strval, sizeof(char), root_node->length, stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_DATA: - printf("Data: "); - char* data = g_base64_encode(root_node->strval,root_node->length); - fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_UNICODE: - printf("Unicode data, may appear crappy: "); - fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_TRUE: - printf("True.\n"); - break; - - case BPLIST_FALSE: - printf("False.\n"); - break; - - case BPLIST_REAL: - case BPLIST_DATE: - printf("Real(?): %f\n", root_node->realval); - break; - - default: - printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length); - break; + case BPLIST_DICT: + printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length); + for (i = 0; i < (root_node->length * 2); i += 2) { + // HI! + printf("Key: "); + print_nodes(root_node->subnodes[i]); + printf("Value: "); + print_nodes(root_node->subnodes[i + 1]); + } + printf("End dictionary node.\n\n"); + break; + + case BPLIST_ARRAY: + printf("Array node.\n"); + for (i = 0; i < root_node->length; i++) { + printf("\tElement %i: ", i); + print_nodes(root_node->subnodes[i]); + } + break; + + case BPLIST_INT: + if (root_node->length == sizeof(uint8_t)) { + printf("Integer: %i\n", root_node->intval8); + } else if (root_node->length == sizeof(uint16_t)) { + printf("Integer: %i\n", root_node->intval16); + } else if (root_node->length == sizeof(uint32_t)) { + printf("Integer: %i\n", root_node->intval32); + } + break; + + case BPLIST_STRING: + printf("String: "); + fwrite(root_node->strval, sizeof(char), root_node->length, stdout); + fflush(stdout); + printf("\n"); + break; + + case BPLIST_DATA: + printf("Data: "); + char *data = g_base64_encode(root_node->strval, root_node->length); + fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); + fflush(stdout); + printf("\n"); + break; + + case BPLIST_UNICODE: + printf("Unicode data, may appear crappy: "); + fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); + fflush(stdout); + printf("\n"); + break; + + case BPLIST_TRUE: + printf("True.\n"); + break; + + case BPLIST_FALSE: + printf("False.\n"); + break; + + case BPLIST_REAL: + case BPLIST_DATE: + printf("Real(?): %f\n", root_node->realval); + break; + + default: + printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length); + break; } } -int main(int argc, char *argv[]) { - struct stat *filestats = (struct stat *)malloc(sizeof(struct stat)); +int main(int argc, char *argv[]) +{ + struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); uint32_t position = 0; Options *options = parse_arguments(argc, argv); int argh = 0; - + printf("plistutil version 0.2 written by FxChiP\n"); - + if (!options) { print_usage(); return 0; } - debug = options->debug; - + iphone_set_debug(options->debug); + FILE *bplist = fopen(options->in_file, "r"); - + stat(options->in_file, filestats); printf("here?\n"); - char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1)); + char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); //argh = fgets(bplist_entire, filestats->st_size, bplist); argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); printf("read %i bytes\n", argh); fclose(bplist); printf("or here?\n"); // bplist_entire contains our stuff - bplist_node *root_node; - root_node = parse_nodes(bplist_entire, filestats->st_size, &position); - printf("plutil debug mode\n\n"); - printf("file size %i\n\n", filestats->st_size); - if (!root_node) { - printf("Invalid binary plist (or some other error occurred.)\n"); - return 0; + bplist_node *root_node; + root_node = parse_nodes(bplist_entire, filestats->st_size, &position); + printf("plutil debug mode\n\n"); + printf("file size %i\n\n", (int) filestats->st_size); + if (!root_node) { + printf("Invalid binary plist (or some other error occurred.)\n"); + return 0; } - print_nodes(root_node); - return 0; - } + print_nodes(root_node); + return 0; +} -Options *parse_arguments(int argc, char *argv[]) { +Options *parse_arguments(int argc, char *argv[]) +{ int i = 0; - - Options *options = (Options*)malloc(sizeof(Options)); + + Options *options = (Options *) malloc(sizeof(Options)); memset(options, 0, sizeof(Options)); - + for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { - if ((i+1) == argc) { + if ((i + 1) == argc) { free(options); return NULL; } - options->in_file = argv[i+1]; + options->in_file = argv[i + 1]; i++; continue; } - + if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { - if ((i+1) == argc) { + if ((i + 1) == argc) { free(options); return NULL; } - options->out_file = argv[i+1]; + options->out_file = argv[i + 1]; i++; continue; } - + if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { options->debug = 1; } - + if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { free(options); return NULL; } } - - if (!options->in_file /*|| !options->out_file*/) { + + if (!options->in_file /*|| !options->out_file */ ) { free(options); return NULL; } - + return options; } -void print_usage() { +void print_usage() +{ printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); printf("\n"); printf("\t-i or --infile: The file to read in.\n"); -- cgit v1.1-32-gdbae From 889cb32a1231c41762d7e2bbe6c891bd3a6c9a7d Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sun, 30 Nov 2008 16:36:18 +0100 Subject: Continue abstraction of xml and binary plist. --- dev/plutil.c | 87 ++++-------------------------------------------------------- 1 file changed, 5 insertions(+), 82 deletions(-) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index d1c3ddd..d1f1cd4 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -10,85 +10,6 @@ #include #include -void print_nodes(bplist_node * root_node) -{ - // Yay, great. Let's print the list of nodes recursively... - int i = 0; - if (!root_node) - return; // or not, because the programmer's stupid. - - switch (root_node->type) { - case BPLIST_DICT: - printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length); - for (i = 0; i < (root_node->length * 2); i += 2) { - // HI! - printf("Key: "); - print_nodes(root_node->subnodes[i]); - printf("Value: "); - print_nodes(root_node->subnodes[i + 1]); - } - printf("End dictionary node.\n\n"); - break; - - case BPLIST_ARRAY: - printf("Array node.\n"); - for (i = 0; i < root_node->length; i++) { - printf("\tElement %i: ", i); - print_nodes(root_node->subnodes[i]); - } - break; - - case BPLIST_INT: - if (root_node->length == sizeof(uint8_t)) { - printf("Integer: %i\n", root_node->intval8); - } else if (root_node->length == sizeof(uint16_t)) { - printf("Integer: %i\n", root_node->intval16); - } else if (root_node->length == sizeof(uint32_t)) { - printf("Integer: %i\n", root_node->intval32); - } - break; - - case BPLIST_STRING: - printf("String: "); - fwrite(root_node->strval, sizeof(char), root_node->length, stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_DATA: - printf("Data: "); - char *data = g_base64_encode(root_node->strval, root_node->length); - fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_UNICODE: - printf("Unicode data, may appear crappy: "); - fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); - fflush(stdout); - printf("\n"); - break; - - case BPLIST_TRUE: - printf("True.\n"); - break; - - case BPLIST_FALSE: - printf("False.\n"); - break; - - case BPLIST_REAL: - case BPLIST_DATE: - printf("Real(?): %f\n", root_node->realval); - break; - - default: - printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length); - break; - } -} - int main(int argc, char *argv[]) { struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); @@ -117,15 +38,17 @@ int main(int argc, char *argv[]) fclose(bplist); printf("or here?\n"); // bplist_entire contains our stuff - bplist_node *root_node; - root_node = parse_nodes(bplist_entire, filestats->st_size, &position); + plist_t root_node = NULL; + bin_to_plist(bplist_entire, filestats->st_size, &root_node); printf("plutil debug mode\n\n"); printf("file size %i\n\n", (int) filestats->st_size); if (!root_node) { printf("Invalid binary plist (or some other error occurred.)\n"); return 0; } - print_nodes(root_node); + char *plist_xml = NULL; + plist_to_xml(root_node, &plist_xml); + printf("%s\n", plist_xml); return 0; } -- cgit v1.1-32-gdbae From d560cf5a15d1aef74e95b208ed69b7d324d94354 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sun, 30 Nov 2008 21:49:56 +0100 Subject: complete xml plist abstraction and migrate lockdownd_hello to new plist API. --- dev/plutil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index d1f1cd4..0e25291 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -47,7 +47,8 @@ int main(int argc, char *argv[]) return 0; } char *plist_xml = NULL; - plist_to_xml(root_node, &plist_xml); + int size = 0; + plist_to_xml(root_node, &plist_xml, &size); printf("%s\n", plist_xml); return 0; } -- cgit v1.1-32-gdbae From 7563917755cf58cee80fbd5bc56a1ab0f563963a Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Mon, 1 Dec 2008 21:23:58 +0100 Subject: cleanup unused functions. --- dev/plutil.c | 1 + 1 file changed, 1 insertion(+) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index 0e25291..4a34077 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -10,6 +10,7 @@ #include #include + int main(int argc, char *argv[]) { struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); -- cgit v1.1-32-gdbae From cd95e9bc6e23949b5cef3996132b79bd8803467a Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Wed, 10 Dec 2008 23:42:21 +0100 Subject: fix minor programming erro plus enhance plutil to convert bin to xml and xml to bin. --- dev/plutil.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index 4a34077..e76506e 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -18,8 +18,6 @@ int main(int argc, char *argv[]) Options *options = parse_arguments(argc, argv); int argh = 0; - printf("plistutil version 0.2 written by FxChiP\n"); - if (!options) { print_usage(); return 0; @@ -31,26 +29,25 @@ int main(int argc, char *argv[]) stat(options->in_file, filestats); - printf("here?\n"); char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); - //argh = fgets(bplist_entire, filestats->st_size, bplist); argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); - printf("read %i bytes\n", argh); fclose(bplist); - printf("or here?\n"); // bplist_entire contains our stuff + plist_t root_node = NULL; - bin_to_plist(bplist_entire, filestats->st_size, &root_node); - printf("plutil debug mode\n\n"); - printf("file size %i\n\n", (int) filestats->st_size); - if (!root_node) { - printf("Invalid binary plist (or some other error occurred.)\n"); - return 0; - } - char *plist_xml = NULL; + char *plist_out = NULL; int size = 0; - plist_to_xml(root_node, &plist_xml, &size); - printf("%s\n", plist_xml); + + if (memcmp(bplist_entire, "bplist00", 8) == 0) { + bin_to_plist(bplist_entire, filestats->st_size, &root_node); + plist_to_xml(root_node, &plist_out, &size); + } else { + xml_to_plist(bplist_entire, filestats->st_size, &root_node); + plist_to_bin(root_node, &plist_out, &size); + } + + + printf("%s\n", plist_out); return 0; } -- cgit v1.1-32-gdbae From 9ca887308d59e6cb5bf684f9f3bd968118e8014f Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Fri, 12 Dec 2008 22:05:44 +0100 Subject: Fix some bugs in binary plist generation. --- dev/plutil.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'dev') diff --git a/dev/plutil.c b/dev/plutil.c index e76506e..3d93797 100644 --- a/dev/plutil.c +++ b/dev/plutil.c @@ -14,9 +14,7 @@ int main(int argc, char *argv[]) { struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); - uint32_t position = 0; Options *options = parse_arguments(argc, argv); - int argh = 0; if (!options) { print_usage(); @@ -25,29 +23,42 @@ int main(int argc, char *argv[]) iphone_set_debug(options->debug); - FILE *bplist = fopen(options->in_file, "r"); - + //read input file + FILE *iplist = fopen(options->in_file, "r"); + if (!iplist) + return 1; stat(options->in_file, filestats); + char *plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); + fread(plist_entire, sizeof(char), filestats->st_size, iplist); + fclose(iplist); - char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); - argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); - fclose(bplist); - // bplist_entire contains our stuff + //convert one format to another plist_t root_node = NULL; char *plist_out = NULL; int size = 0; - if (memcmp(bplist_entire, "bplist00", 8) == 0) { - bin_to_plist(bplist_entire, filestats->st_size, &root_node); + if (memcmp(plist_entire, "bplist00", 8) == 0) { + bin_to_plist(plist_entire, filestats->st_size, &root_node); plist_to_xml(root_node, &plist_out, &size); } else { - xml_to_plist(bplist_entire, filestats->st_size, &root_node); + xml_to_plist(plist_entire, filestats->st_size, &root_node); plist_to_bin(root_node, &plist_out, &size); } - - printf("%s\n", plist_out); + if (plist_out) { + if (options->out_file != NULL) { + FILE *oplist = fopen(options->out_file, "wb"); + if (!oplist) + return 1; + fwrite(plist_out, size, sizeof(char), oplist); + fclose(oplist); + } + //if no output file specified, write to stdout + else + fwrite(plist_out, size, sizeof(char), stdout); + } else + printf("ERROR\n"); return 0; } -- cgit v1.1-32-gdbae From 4301ef9bb8e9d06ffa4e9172191d58ede5e16f5d Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Sat, 13 Dec 2008 18:12:46 +0100 Subject: fork out plist stuff in libplist and migrate libiphone to use it. --- dev/Makefile.am | 6 +-- dev/plutil.c | 118 -------------------------------------------------------- dev/plutil.h | 13 ------- 3 files changed, 1 insertion(+), 136 deletions(-) delete mode 100644 dev/plutil.c delete mode 100644 dev/plutil.h (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index 95b4d61..d116581 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) -bin_PROGRAMS = iphoneclient lckd-client afccheck plutil +bin_PROGRAMS = iphoneclient lckd-client afccheck iphoneclient_SOURCES = main.c iphoneclient_LDADD = ../src/libiphone.la @@ -18,7 +18,3 @@ afccheck_CFLAGS = $(AM_CFLAGS) afccheck_LDFLAGS = $(AM_LDFLAGS) afccheck_LDADD = ../src/libiphone.la -plutil_SOURCES = plutil.c -plutil_CFLAGS = $(AM_CFLAGS) -plutil_LDFLAGS = $(AM_LDFLAGS) -plutil_LDADD = ../src/libiphone.la 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 @@ -/* - * main.c for plistutil - * right now just prints debug shit - */ - -#include "../src/plist.h" -#include "plutil.h" -#include -#include -#include -#include - - -int main(int argc, char *argv[]) -{ - struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); - Options *options = parse_arguments(argc, argv); - - if (!options) { - print_usage(); - return 0; - } - - iphone_set_debug(options->debug); - - //read input file - FILE *iplist = fopen(options->in_file, "r"); - if (!iplist) - return 1; - stat(options->in_file, filestats); - char *plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); - fread(plist_entire, sizeof(char), filestats->st_size, iplist); - fclose(iplist); - - - //convert one format to another - plist_t root_node = NULL; - char *plist_out = NULL; - int size = 0; - - if (memcmp(plist_entire, "bplist00", 8) == 0) { - bin_to_plist(plist_entire, filestats->st_size, &root_node); - plist_to_xml(root_node, &plist_out, &size); - } else { - xml_to_plist(plist_entire, filestats->st_size, &root_node); - plist_to_bin(root_node, &plist_out, &size); - } - - if (plist_out) { - if (options->out_file != NULL) { - FILE *oplist = fopen(options->out_file, "wb"); - if (!oplist) - return 1; - fwrite(plist_out, size, sizeof(char), oplist); - fclose(oplist); - } - //if no output file specified, write to stdout - else - fwrite(plist_out, size, sizeof(char), stdout); - } else - printf("ERROR\n"); - return 0; -} - -Options *parse_arguments(int argc, char *argv[]) -{ - int i = 0; - - Options *options = (Options *) malloc(sizeof(Options)); - memset(options, 0, sizeof(Options)); - - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { - if ((i + 1) == argc) { - free(options); - return NULL; - } - options->in_file = argv[i + 1]; - i++; - continue; - } - - if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { - if ((i + 1) == argc) { - free(options); - return NULL; - } - options->out_file = argv[i + 1]; - i++; - continue; - } - - if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { - options->debug = 1; - } - - if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { - free(options); - return NULL; - } - } - - if (!options->in_file /*|| !options->out_file */ ) { - free(options); - return NULL; - } - - return options; -} - -void print_usage() -{ - printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); - printf("\n"); - printf("\t-i or --infile: The file to read in.\n"); - printf("\t-o or --outfile: The file to convert to.\n"); - printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); -} 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 @@ - -/* - * main.h - header for plistutil - * Written by FxChiP - */ - -typedef struct _options { - char *in_file, *out_file; - uint8_t debug, in_fmt, out_fmt; -} Options; - -Options *parse_arguments(int argc, char *argv[]); -void print_usage(); -- cgit v1.1-32-gdbae From 8f239549c124d11eb8899aec6c048d6a496e3911 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Thu, 8 Jan 2009 23:27:28 +0100 Subject: Implement skeleton of MobileSync protocol (handshake and goodbye). --- dev/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index d116581..7ca7e99 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) -bin_PROGRAMS = iphoneclient lckd-client afccheck +bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneclient_SOURCES = main.c iphoneclient_LDADD = ../src/libiphone.la @@ -18,3 +18,7 @@ afccheck_CFLAGS = $(AM_CFLAGS) afccheck_LDFLAGS = $(AM_LDFLAGS) afccheck_LDADD = ../src/libiphone.la +msyncclient_SOURCES = msyncclient.c +msyncclient_CFLAGS = $(AM_CFLAGS) +msyncclient_LDFLAGS = $(AM_LDFLAGS) +msyncclient_LDADD = ../src/libiphone.la -- cgit v1.1-32-gdbae From d01cc63dc48349456b2d34cccab69d39eb1930cf Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Fri, 9 Jan 2009 17:51:01 +0100 Subject: add msync test client. --- dev/msyncclient.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 dev/msyncclient.c (limited to 'dev') diff --git a/dev/msyncclient.c b/dev/msyncclient.c new file mode 100644 index 0000000..55d07c4 --- /dev/null +++ b/dev/msyncclient.c @@ -0,0 +1,73 @@ +/* + * msyncclient.c + * Rudimentary interface to the MobileSync iPhone + * + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include "../src/MobileSync.h" + + +int main(int argc, char *argv[]) +{ + int bytes = 0, port = 0, i = 0; + iphone_lckd_client_t control = NULL; + iphone_device_t phone = NULL; + + if (argc > 1 && !strcasecmp(argv[1], "--debug")) { + iphone_set_debug(1); + } else { + iphone_set_debug(0); + } + + if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { + printf("No iPhone found, is it plugged in?\n"); + return -1; + } + + if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + iphone_free_device(phone); + return -1; + } + + iphone_lckd_start_service(control, "com.apple.mobilesync", &port); + + if (port) { + iphone_msync_client_t msync = NULL; + iphone_msync_new_client(phone, 3432, port, &msync); + if (msync) + iphone_msync_free_client(msync); + } else { + printf("Start service failure.\n"); + } + + printf("All done.\n"); + + iphone_lckd_free_client(control); + iphone_free_device(phone); + + return 0; +} -- cgit v1.1-32-gdbae From f3c08cfad0833d55a69ca3d54d9920a3cb558328 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Fri, 9 Jan 2009 19:24:27 +0100 Subject: Change msync recv and send functions to only deal with abstract plists. Start full address book dump function. Update to new logging mechanism. --- dev/msyncclient.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'dev') diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 55d07c4..a6764b4 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -29,6 +29,7 @@ #include #include "../src/MobileSync.h" +#include "../src/utils.h" int main(int argc, char *argv[]) @@ -37,11 +38,9 @@ int main(int argc, char *argv[]) iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; - if (argc > 1 && !strcasecmp(argv[1], "--debug")) { - iphone_set_debug(1); - } else { - iphone_set_debug(0); - } + if (argc > 1 && !strcasecmp(argv[1], "--debug")) + iphone_set_debug_mask(DBGMASK_MOBILESYNC); + if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); @@ -58,8 +57,10 @@ int main(int argc, char *argv[]) if (port) { iphone_msync_client_t msync = NULL; iphone_msync_new_client(phone, 3432, port, &msync); - if (msync) + if (msync) { + iphone_msync_get_all_contacts(msync); iphone_msync_free_client(msync); + } } else { printf("Start service failure.\n"); } -- cgit v1.1-32-gdbae From 564aebf941f2f0c5fb57d2f86091b37d6331b9d9 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Mon, 12 Jan 2009 20:07:06 +0100 Subject: Update lockdownd transfer function to take abstract plist as argument. Simplify code accordingly. Use new libplist API to make code cleaner. --- dev/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dev') diff --git a/dev/main.c b/dev/main.c index 4974eef..f865e52 100644 --- a/dev/main.c +++ b/dev/main.c @@ -28,6 +28,7 @@ #include #include +#include "../src/utils.h" int main(int argc, char *argv[]) @@ -38,8 +39,10 @@ int main(int argc, char *argv[]) if (argc > 1 && !strcasecmp(argv[1], "--debug")) { iphone_set_debug(1); + iphone_set_debug_mask(DBGMASK_ALL); } else { iphone_set_debug(0); + iphone_set_debug_mask(DBGMASK_NONE); } if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { -- cgit v1.1-32-gdbae From 47347ff723dd3c03b0006c150b02abaa2b9f4a76 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Tue, 13 Jan 2009 22:56:35 +0100 Subject: Fix some bugs in interface (Receive() still doesn't work). --- dev/msync.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 dev/msync.py (limited to 'dev') diff --git a/dev/msync.py b/dev/msync.py new file mode 100755 index 0000000..4170f87 --- /dev/null +++ b/dev/msync.py @@ -0,0 +1,40 @@ +#! /usr/bin/env python + +from libiphone.iPhone import * + +# get msync client +def GetMobileSyncClient() : + phone = iPhone() + if not phone.InitDevice() : + print "Couldn't find device, is it connected ?\n" + return None + lckd = phone.GetLockdownClient() + if not lckd : + print "Failed to start lockdown service.\n" + return None + msync = lckd.GetMobileSyncClient() + if not msync : + print "Failed to start mobilesync service.\n" + return None + return msync + + +msync = GetMobileSyncClient() + +if not msync : + exit(1) + +array = PListNode(PLIST_ARRAY) +array.AddSubString("SDMessageSyncDataClassWithDevice") +array.AddSubString("com.apple.Contacts"); +array.AddSubString("---"); +array.AddSubString("2009-01-13 22:25:58 +0100"); +array.AddSubUInt(106); +array.AddSubString("___EmptyParameterString___"); + +msync.Send(array) +array = msync.Receive() +print array.ToXml() + + + -- cgit v1.1-32-gdbae From 0934d1ac021dfb7907e4b580b38aa4a938cf2180 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Thu, 22 Jan 2009 22:21:12 +0100 Subject: Move things around and clean up some code. --- dev/msyncclient.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'dev') diff --git a/dev/msyncclient.c b/dev/msyncclient.c index a6764b4..2762f04 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -28,8 +28,6 @@ #include #include -#include "../src/MobileSync.h" -#include "../src/utils.h" int main(int argc, char *argv[]) -- cgit v1.1-32-gdbae From 185294a0f9a689a231d3d0d8cde1864d4b0bdaa0 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Thu, 29 Jan 2009 18:35:38 +0100 Subject: Add more warning flags and remove useless libxml2 dependency. --- dev/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index 7ca7e99..f976ccc 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g -AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) +AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g +AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient -- cgit v1.1-32-gdbae From c00d8d76c04273f796c3d992300068dd21c7bd3e Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Thu, 29 Jan 2009 18:47:46 +0100 Subject: Completly remove libxml dependency and change libplist-1.0 dependency to libplist. --- dev/main.c | 3 --- dev/msyncclient.c | 3 --- 2 files changed, 6 deletions(-) (limited to 'dev') diff --git a/dev/main.c b/dev/main.c index f865e52..6514bf8 100644 --- a/dev/main.c +++ b/dev/main.c @@ -24,9 +24,6 @@ #include #include -#include -#include - #include #include "../src/utils.h" diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 2762f04..804e1ed 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -24,9 +24,6 @@ #include #include -#include -#include - #include -- cgit v1.1-32-gdbae