diff options
Diffstat (limited to 'dev/plutil.c')
| -rw-r--r-- | dev/plutil.c | 87 |
1 files changed, 5 insertions, 82 deletions
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 @@ | |||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 12 | 12 | ||
| 13 | void print_nodes(bplist_node * root_node) | ||
| 14 | { | ||
| 15 | // Yay, great. Let's print the list of nodes recursively... | ||
| 16 | int i = 0; | ||
| 17 | if (!root_node) | ||
| 18 | return; // or not, because the programmer's stupid. | ||
| 19 | |||
| 20 | switch (root_node->type) { | ||
| 21 | case BPLIST_DICT: | ||
| 22 | printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length); | ||
| 23 | for (i = 0; i < (root_node->length * 2); i += 2) { | ||
| 24 | // HI! | ||
| 25 | printf("Key: "); | ||
| 26 | print_nodes(root_node->subnodes[i]); | ||
| 27 | printf("Value: "); | ||
| 28 | print_nodes(root_node->subnodes[i + 1]); | ||
| 29 | } | ||
| 30 | printf("End dictionary node.\n\n"); | ||
| 31 | break; | ||
| 32 | |||
| 33 | case BPLIST_ARRAY: | ||
| 34 | printf("Array node.\n"); | ||
| 35 | for (i = 0; i < root_node->length; i++) { | ||
| 36 | printf("\tElement %i: ", i); | ||
| 37 | print_nodes(root_node->subnodes[i]); | ||
| 38 | } | ||
| 39 | break; | ||
| 40 | |||
| 41 | case BPLIST_INT: | ||
| 42 | if (root_node->length == sizeof(uint8_t)) { | ||
| 43 | printf("Integer: %i\n", root_node->intval8); | ||
| 44 | } else if (root_node->length == sizeof(uint16_t)) { | ||
| 45 | printf("Integer: %i\n", root_node->intval16); | ||
| 46 | } else if (root_node->length == sizeof(uint32_t)) { | ||
| 47 | printf("Integer: %i\n", root_node->intval32); | ||
| 48 | } | ||
| 49 | break; | ||
| 50 | |||
| 51 | case BPLIST_STRING: | ||
| 52 | printf("String: "); | ||
| 53 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); | ||
| 54 | fflush(stdout); | ||
| 55 | printf("\n"); | ||
| 56 | break; | ||
| 57 | |||
| 58 | case BPLIST_DATA: | ||
| 59 | printf("Data: "); | ||
| 60 | char *data = g_base64_encode(root_node->strval, root_node->length); | ||
| 61 | fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); | ||
| 62 | fflush(stdout); | ||
| 63 | printf("\n"); | ||
| 64 | break; | ||
| 65 | |||
| 66 | case BPLIST_UNICODE: | ||
| 67 | printf("Unicode data, may appear crappy: "); | ||
| 68 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); | ||
| 69 | fflush(stdout); | ||
| 70 | printf("\n"); | ||
| 71 | break; | ||
| 72 | |||
| 73 | case BPLIST_TRUE: | ||
| 74 | printf("True.\n"); | ||
| 75 | break; | ||
| 76 | |||
| 77 | case BPLIST_FALSE: | ||
| 78 | printf("False.\n"); | ||
| 79 | break; | ||
| 80 | |||
| 81 | case BPLIST_REAL: | ||
| 82 | case BPLIST_DATE: | ||
| 83 | printf("Real(?): %f\n", root_node->realval); | ||
| 84 | break; | ||
| 85 | |||
| 86 | default: | ||
| 87 | printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length); | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | int main(int argc, char *argv[]) | 13 | int main(int argc, char *argv[]) |
| 93 | { | 14 | { |
| 94 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | 15 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); |
| @@ -117,15 +38,17 @@ int main(int argc, char *argv[]) | |||
| 117 | fclose(bplist); | 38 | fclose(bplist); |
| 118 | printf("or here?\n"); | 39 | printf("or here?\n"); |
| 119 | // bplist_entire contains our stuff | 40 | // bplist_entire contains our stuff |
| 120 | bplist_node *root_node; | 41 | plist_t root_node = NULL; |
| 121 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); | 42 | bin_to_plist(bplist_entire, filestats->st_size, &root_node); |
| 122 | printf("plutil debug mode\n\n"); | 43 | printf("plutil debug mode\n\n"); |
| 123 | printf("file size %i\n\n", (int) filestats->st_size); | 44 | printf("file size %i\n\n", (int) filestats->st_size); |
| 124 | if (!root_node) { | 45 | if (!root_node) { |
| 125 | printf("Invalid binary plist (or some other error occurred.)\n"); | 46 | printf("Invalid binary plist (or some other error occurred.)\n"); |
| 126 | return 0; | 47 | return 0; |
| 127 | } | 48 | } |
| 128 | print_nodes(root_node); | 49 | char *plist_xml = NULL; |
| 50 | plist_to_xml(root_node, &plist_xml); | ||
| 51 | printf("%s\n", plist_xml); | ||
| 129 | return 0; | 52 | return 0; |
| 130 | } | 53 | } |
| 131 | 54 | ||
