diff options
| author | 2008-11-25 19:14:27 +0100 | |
|---|---|---|
| committer | 2008-11-25 19:14:27 +0100 | |
| commit | aed2c025f6e47dc769675e564cc574adc496a88a (patch) | |
| tree | 6cb14e4c511dabc40fdf6c24714a2be48567f847 | |
| parent | 0bca81e7c8ce5ba53390271e5c7eaa7a5f281c91 (diff) | |
| download | libimobiledevice-aed2c025f6e47dc769675e564cc574adc496a88a.tar.gz libimobiledevice-aed2c025f6e47dc769675e564cc574adc496a88a.tar.bz2 | |
fix some warnings and indent
| -rw-r--r-- | dev/lckdclient.c | 1 | ||||
| -rw-r--r-- | dev/main.c | 2 | ||||
| -rw-r--r-- | dev/plutil.c | 219 | ||||
| -rw-r--r-- | src/plist.c | 335 | ||||
| -rw-r--r-- | src/plist.h | 11 |
5 files changed, 294 insertions, 274 deletions
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 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> | ||
| 23 | #include <string.h> | 24 | #include <string.h> |
| 24 | #include <glib.h> | 25 | #include <glib.h> |
| 25 | #include <readline/readline.h> | 26 | #include <readline/readline.h> |
| @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) | |||
| 87 | iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); | 87 | iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); |
| 88 | if (IPHONE_E_SUCCESS == | 88 | if (IPHONE_E_SUCCESS == |
| 89 | iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { | 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); | 90 | printf("A file size: %i\n", (int) stbuf.st_size); |
| 91 | char *file_data = (char *) malloc(sizeof(char) * 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); | 92 | iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); |
| 93 | if (bytes >= 0) { | 93 | 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 @@ | |||
| 5 | 5 | ||
| 6 | #include "../src/plist.h" | 6 | #include "../src/plist.h" |
| 7 | #include "plutil.h" | 7 | #include "plutil.h" |
| 8 | #include <glib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 8 | 12 | ||
| 9 | int debug = 0; | 13 | void print_nodes(bplist_node * root_node) |
| 10 | 14 | { | |
| 11 | void print_nodes(bplist_node *root_node) { | ||
| 12 | // Yay, great. Let's print the list of nodes recursively... | 15 | // Yay, great. Let's print the list of nodes recursively... |
| 13 | int i = 0; | 16 | int i = 0; |
| 14 | if (!root_node) return; // or not, because the programmer's stupid. | 17 | if (!root_node) |
| 15 | 18 | return; // or not, because the programmer's stupid. | |
| 19 | |||
| 16 | switch (root_node->type) { | 20 | switch (root_node->type) { |
| 17 | case BPLIST_DICT: | 21 | case BPLIST_DICT: |
| 18 | printf("Dictionary node.\nLength %i\n", root_node->length); | 22 | printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length); |
| 19 | for (i = 0; i < (root_node->length * 2); i+=2) { | 23 | for (i = 0; i < (root_node->length * 2); i += 2) { |
| 20 | // HI! | 24 | // HI! |
| 21 | printf("Key: "); | 25 | printf("Key: "); |
| 22 | print_nodes(root_node->subnodes[i]); | 26 | print_nodes(root_node->subnodes[i]); |
| 23 | printf("Value: "); | 27 | printf("Value: "); |
| 24 | print_nodes(root_node->subnodes[i+1]); | 28 | print_nodes(root_node->subnodes[i + 1]); |
| 25 | } | 29 | } |
| 26 | printf("End dictionary node.\n\n"); | 30 | printf("End dictionary node.\n\n"); |
| 27 | break; | 31 | break; |
| 28 | 32 | ||
| 29 | case BPLIST_ARRAY: | 33 | case BPLIST_ARRAY: |
| 30 | printf("Array node.\n"); | 34 | printf("Array node.\n"); |
| 31 | for (i = 0; i < root_node->length; i++) { | 35 | for (i = 0; i < root_node->length; i++) { |
| 32 | printf("\tElement %i: ", i); | 36 | printf("\tElement %i: ", i); |
| 33 | print_nodes(root_node->subnodes[i]); | 37 | print_nodes(root_node->subnodes[i]); |
| 34 | } | 38 | } |
| 35 | break; | 39 | break; |
| 36 | 40 | ||
| 37 | case BPLIST_INT: | 41 | case BPLIST_INT: |
| 38 | if (root_node->length == sizeof(uint8_t)) { | 42 | if (root_node->length == sizeof(uint8_t)) { |
| 39 | printf("Integer: %i\n", root_node->intval8); | 43 | printf("Integer: %i\n", root_node->intval8); |
| 40 | } else if (root_node->length == sizeof(uint16_t)) { | 44 | } else if (root_node->length == sizeof(uint16_t)) { |
| 41 | printf("Integer: %i\n", root_node->intval16); | 45 | printf("Integer: %i\n", root_node->intval16); |
| 42 | } else if (root_node->length == sizeof(uint32_t)) { | 46 | } else if (root_node->length == sizeof(uint32_t)) { |
| 43 | printf("Integer: %i\n", root_node->intval32); | 47 | printf("Integer: %i\n", root_node->intval32); |
| 44 | } | 48 | } |
| 45 | break; | 49 | break; |
| 46 | 50 | ||
| 47 | case BPLIST_STRING: | 51 | case BPLIST_STRING: |
| 48 | printf("String: "); | 52 | printf("String: "); |
| 49 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); | 53 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); |
| 50 | fflush(stdout); | 54 | fflush(stdout); |
| 51 | printf("\n"); | 55 | printf("\n"); |
| 52 | break; | 56 | break; |
| 53 | 57 | ||
| 54 | case BPLIST_DATA: | 58 | case BPLIST_DATA: |
| 55 | printf("Data: "); | 59 | printf("Data: "); |
| 56 | char* data = g_base64_encode(root_node->strval,root_node->length); | 60 | char *data = g_base64_encode(root_node->strval, root_node->length); |
| 57 | fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); | 61 | fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); |
| 58 | fflush(stdout); | 62 | fflush(stdout); |
| 59 | printf("\n"); | 63 | printf("\n"); |
| 60 | break; | 64 | break; |
| 61 | 65 | ||
| 62 | case BPLIST_UNICODE: | 66 | case BPLIST_UNICODE: |
| 63 | printf("Unicode data, may appear crappy: "); | 67 | printf("Unicode data, may appear crappy: "); |
| 64 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); | 68 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); |
| 65 | fflush(stdout); | 69 | fflush(stdout); |
| 66 | printf("\n"); | 70 | printf("\n"); |
| 67 | break; | 71 | break; |
| 68 | 72 | ||
| 69 | case BPLIST_TRUE: | 73 | case BPLIST_TRUE: |
| 70 | printf("True.\n"); | 74 | printf("True.\n"); |
| 71 | break; | 75 | break; |
| 72 | 76 | ||
| 73 | case BPLIST_FALSE: | 77 | case BPLIST_FALSE: |
| 74 | printf("False.\n"); | 78 | printf("False.\n"); |
| 75 | break; | 79 | break; |
| 76 | 80 | ||
| 77 | case BPLIST_REAL: | 81 | case BPLIST_REAL: |
| 78 | case BPLIST_DATE: | 82 | case BPLIST_DATE: |
| 79 | printf("Real(?): %f\n", root_node->realval); | 83 | printf("Real(?): %f\n", root_node->realval); |
| 80 | break; | 84 | break; |
| 81 | 85 | ||
| 82 | default: | 86 | default: |
| 83 | printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length); | 87 | printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length); |
| 84 | break; | 88 | break; |
| 85 | } | 89 | } |
| 86 | } | 90 | } |
| 87 | 91 | ||
| 88 | int main(int argc, char *argv[]) { | 92 | int main(int argc, char *argv[]) |
| 89 | struct stat *filestats = (struct stat *)malloc(sizeof(struct stat)); | 93 | { |
| 94 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | ||
| 90 | uint32_t position = 0; | 95 | uint32_t position = 0; |
| 91 | Options *options = parse_arguments(argc, argv); | 96 | Options *options = parse_arguments(argc, argv); |
| 92 | int argh = 0; | 97 | int argh = 0; |
| 93 | 98 | ||
| 94 | printf("plistutil version 0.2 written by FxChiP\n"); | 99 | printf("plistutil version 0.2 written by FxChiP\n"); |
| 95 | 100 | ||
| 96 | if (!options) { | 101 | if (!options) { |
| 97 | print_usage(); | 102 | print_usage(); |
| 98 | return 0; | 103 | return 0; |
| 99 | } | 104 | } |
| 100 | 105 | ||
| 101 | debug = options->debug; | 106 | iphone_set_debug(options->debug); |
| 102 | 107 | ||
| 103 | FILE *bplist = fopen(options->in_file, "r"); | 108 | FILE *bplist = fopen(options->in_file, "r"); |
| 104 | 109 | ||
| 105 | stat(options->in_file, filestats); | 110 | stat(options->in_file, filestats); |
| 106 | 111 | ||
| 107 | printf("here?\n"); | 112 | printf("here?\n"); |
| 108 | char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1)); | 113 | char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); |
| 109 | //argh = fgets(bplist_entire, filestats->st_size, bplist); | 114 | //argh = fgets(bplist_entire, filestats->st_size, bplist); |
| 110 | argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); | 115 | argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); |
| 111 | printf("read %i bytes\n", argh); | 116 | printf("read %i bytes\n", argh); |
| 112 | fclose(bplist); | 117 | fclose(bplist); |
| 113 | printf("or here?\n"); | 118 | printf("or here?\n"); |
| 114 | // bplist_entire contains our stuff | 119 | // bplist_entire contains our stuff |
| 115 | bplist_node *root_node; | 120 | bplist_node *root_node; |
| 116 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); | 121 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); |
| 117 | printf("plutil debug mode\n\n"); | 122 | printf("plutil debug mode\n\n"); |
| 118 | printf("file size %i\n\n", filestats->st_size); | 123 | printf("file size %i\n\n", (int) filestats->st_size); |
| 119 | if (!root_node) { | 124 | if (!root_node) { |
| 120 | printf("Invalid binary plist (or some other error occurred.)\n"); | 125 | printf("Invalid binary plist (or some other error occurred.)\n"); |
| 121 | return 0; | 126 | return 0; |
| 122 | } | 127 | } |
| 123 | print_nodes(root_node); | 128 | print_nodes(root_node); |
| 124 | return 0; | 129 | return 0; |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | Options *parse_arguments(int argc, char *argv[]) { | 132 | Options *parse_arguments(int argc, char *argv[]) |
| 133 | { | ||
| 128 | int i = 0; | 134 | int i = 0; |
| 129 | 135 | ||
| 130 | Options *options = (Options*)malloc(sizeof(Options)); | 136 | Options *options = (Options *) malloc(sizeof(Options)); |
| 131 | memset(options, 0, sizeof(Options)); | 137 | memset(options, 0, sizeof(Options)); |
| 132 | 138 | ||
| 133 | for (i = 1; i < argc; i++) { | 139 | for (i = 1; i < argc; i++) { |
| 134 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { | 140 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { |
| 135 | if ((i+1) == argc) { | 141 | if ((i + 1) == argc) { |
| 136 | free(options); | 142 | free(options); |
| 137 | return NULL; | 143 | return NULL; |
| 138 | } | 144 | } |
| 139 | options->in_file = argv[i+1]; | 145 | options->in_file = argv[i + 1]; |
| 140 | i++; | 146 | i++; |
| 141 | continue; | 147 | continue; |
| 142 | } | 148 | } |
| 143 | 149 | ||
| 144 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { | 150 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { |
| 145 | if ((i+1) == argc) { | 151 | if ((i + 1) == argc) { |
| 146 | free(options); | 152 | free(options); |
| 147 | return NULL; | 153 | return NULL; |
| 148 | } | 154 | } |
| 149 | options->out_file = argv[i+1]; | 155 | options->out_file = argv[i + 1]; |
| 150 | i++; | 156 | i++; |
| 151 | continue; | 157 | continue; |
| 152 | } | 158 | } |
| 153 | 159 | ||
| 154 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { | 160 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { |
| 155 | options->debug = 1; | 161 | options->debug = 1; |
| 156 | } | 162 | } |
| 157 | 163 | ||
| 158 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { | 164 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { |
| 159 | free(options); | 165 | free(options); |
| 160 | return NULL; | 166 | return NULL; |
| 161 | } | 167 | } |
| 162 | } | 168 | } |
| 163 | 169 | ||
| 164 | if (!options->in_file /*|| !options->out_file*/) { | 170 | if (!options->in_file /*|| !options->out_file */ ) { |
| 165 | free(options); | 171 | free(options); |
| 166 | return NULL; | 172 | return NULL; |
| 167 | } | 173 | } |
| 168 | 174 | ||
| 169 | return options; | 175 | return options; |
| 170 | } | 176 | } |
| 171 | 177 | ||
| 172 | void print_usage() { | 178 | void print_usage() |
| 179 | { | ||
| 173 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); | 180 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); |
| 174 | printf("\n"); | 181 | printf("\n"); |
| 175 | printf("\t-i or --infile: The file to read in.\n"); | 182 | printf("\t-i or --infile: The file to read in.\n"); |
diff --git a/src/plist.c b/src/plist.c index 0024577..7a09b4d 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -261,8 +261,10 @@ void free_dictionary(char **dictionary) | |||
| 261 | * - parse_nodes() will return the first node it encounters, which is usually the "root" node. | 261 | * - parse_nodes() will return the first node it encounters, which is usually the "root" node. |
| 262 | */ | 262 | */ |
| 263 | 263 | ||
| 264 | uint32_t uipow(uint32_t value, uint32_t power) { | 264 | uint32_t uipow(uint32_t value, uint32_t power) |
| 265 | if (!power) return 1; | 265 | { |
| 266 | if (!power) | ||
| 267 | return 1; | ||
| 266 | int i = 0, oVal = value; | 268 | int i = 0, oVal = value; |
| 267 | for (i = 1; i < power; i++) { | 269 | for (i = 1; i < power; i++) { |
| 268 | value *= oVal; | 270 | value *= oVal; |
| @@ -270,50 +272,55 @@ uint32_t uipow(uint32_t value, uint32_t power) { | |||
| 270 | return value; | 272 | return value; |
| 271 | } | 273 | } |
| 272 | 274 | ||
| 273 | void byte_convert(char *address, size_t size) { | 275 | void byte_convert(char *address, size_t size) |
| 276 | { | ||
| 274 | int i = 0, j = 0; | 277 | int i = 0, j = 0; |
| 275 | char tmp = '\0'; | 278 | char tmp = '\0'; |
| 276 | 279 | ||
| 277 | for (i = 0; i < (size / 2); i++) { | 280 | for (i = 0; i < (size / 2); i++) { |
| 278 | tmp = address[i]; | 281 | tmp = address[i]; |
| 279 | j = ((size-1) + 0) - i; | 282 | j = ((size - 1) + 0) - i; |
| 280 | address[i] = address[j]; | 283 | address[i] = address[j]; |
| 281 | address[j] = tmp; | 284 | address[j] = tmp; |
| 282 | } | 285 | } |
| 283 | } | 286 | } |
| 284 | 287 | ||
| 285 | bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *position, uint8_t ref_size) { | 288 | bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t * position, uint8_t ref_size) |
| 286 | if (!position || !bpbuffer || !bplength) return NULL; | 289 | { |
| 287 | 290 | if (!position || !bpbuffer || !bplength) | |
| 291 | return NULL; | ||
| 292 | |||
| 288 | uint8_t modifier = 0; | 293 | uint8_t modifier = 0; |
| 289 | bplist_node *new_node = (bplist_node*)malloc(sizeof(bplist_node)); | 294 | bplist_node *new_node = (bplist_node *) malloc(sizeof(bplist_node)); |
| 290 | bplist_node *length_stupidity = NULL; | 295 | bplist_node *length_stupidity = NULL; |
| 291 | memset(new_node, 0, sizeof(bplist_node)); // initialize the new struct | 296 | memset(new_node, 0, sizeof(bplist_node)); // initialize the new struct |
| 292 | 297 | ||
| 293 | int myPos = *position; | 298 | int myPos = *position; |
| 294 | if (myPos == bplength || (myPos+1) == bplength) { free(new_node); return NULL; } // end of string | 299 | if (myPos == bplength || (myPos + 1) == bplength) { |
| 295 | 300 | free(new_node); | |
| 301 | return NULL; | ||
| 302 | } // end of string | ||
| 303 | |||
| 296 | uint32_t length = 0; | 304 | uint32_t length = 0; |
| 297 | if (!myPos) { | 305 | if (!myPos) { |
| 298 | if (strncmp(bpbuffer, "bplist00", strlen("bplist00"))) { | 306 | if (strncmp(bpbuffer, "bplist00", strlen("bplist00"))) { |
| 299 | return NULL; // badness! | 307 | return NULL; // badness! |
| 300 | } | 308 | } |
| 301 | myPos += strlen("bplist00"); | 309 | myPos += strlen("bplist00"); |
| 302 | } | 310 | } |
| 303 | |||
| 304 | // Get the node's type. | 311 | // Get the node's type. |
| 305 | if (bpbuffer[myPos] == BPLIST_DATE) { // handle date separately, but do it as a real | 312 | if (bpbuffer[myPos] == BPLIST_DATE) { // handle date separately, but do it as a real |
| 306 | // better handling of date; basically interpret as real or double | 313 | // better handling of date; basically interpret as real or double |
| 307 | new_node->type = BPLIST_DATE; | 314 | new_node->type = BPLIST_DATE; |
| 308 | new_node->length = 8; // always 8 for "date" (Apple intended it, not me) | 315 | new_node->length = 8; // always 8 for "date" (Apple intended it, not me) |
| 309 | myPos++; | 316 | myPos++; |
| 310 | memcpy(&new_node->realval, bpbuffer+myPos, sizeof(new_node->realval)); | 317 | memcpy(&new_node->realval, bpbuffer + myPos, sizeof(new_node->realval)); |
| 311 | byte_convert(&new_node->realval, sizeof(new_node->realval)); | 318 | byte_convert((char *) &new_node->realval, sizeof(new_node->realval)); |
| 312 | myPos += new_node->length; | 319 | myPos += new_node->length; |
| 313 | *position = myPos; | 320 | *position = myPos; |
| 314 | return new_node; | 321 | return new_node; |
| 315 | } | 322 | } |
| 316 | 323 | ||
| 317 | new_node->type = bpbuffer[myPos] & BPLIST_MASK; | 324 | new_node->type = bpbuffer[myPos] & BPLIST_MASK; |
| 318 | new_node->length = bpbuffer[myPos] & BPLIST_FILL; | 325 | new_node->length = bpbuffer[myPos] & BPLIST_FILL; |
| 319 | if (!new_node->type) { | 326 | if (!new_node->type) { |
| @@ -322,151 +329,153 @@ bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *p | |||
| 322 | // okay, so it is. Carry on. | 329 | // okay, so it is. Carry on. |
| 323 | new_node->type = bpbuffer[myPos]; | 330 | new_node->type = bpbuffer[myPos]; |
| 324 | new_node->length = 0; | 331 | new_node->length = 0; |
| 325 | } else { | 332 | } else { |
| 326 | // er, what? we have a bad type here. Return NULL. | 333 | // er, what? we have a bad type here. Return NULL. |
| 327 | free(new_node); | 334 | free(new_node); |
| 328 | //printf("parse_raw_node: lol type: type given %x\n", bpbuffer[myPos]); | 335 | //printf("parse_raw_node: lol type: type given %x\n", bpbuffer[myPos]); |
| 329 | return NULL; | 336 | return NULL; |
| 330 | } | 337 | } |
| 331 | } | 338 | } |
| 332 | 339 | ||
| 333 | myPos++; // puts us in the data. | 340 | myPos++; // puts us in the data. |
| 334 | if (new_node->length == BPLIST_FILL) { // Data happens to contain length... | 341 | if (new_node->length == BPLIST_FILL) { // Data happens to contain length... |
| 335 | // what? you're going to make me parse an int for the length. You suck. | 342 | // what? you're going to make me parse an int for the length. You suck. |
| 336 | *position = myPos; | 343 | *position = myPos; |
| 337 | length_stupidity = parse_raw_node(bpbuffer, bplength, &myPos, ref_size); | 344 | length_stupidity = parse_raw_node(bpbuffer, bplength, &myPos, ref_size); |
| 338 | switch (length_stupidity->length) { | 345 | switch (length_stupidity->length) { |
| 339 | case sizeof(uint8_t): | 346 | case sizeof(uint8_t): |
| 340 | new_node->length = length_stupidity->intval8; | 347 | new_node->length = length_stupidity->intval8; |
| 341 | break; | 348 | break; |
| 342 | case sizeof(uint16_t): | 349 | case sizeof(uint16_t): |
| 343 | new_node->length = length_stupidity->intval16; | 350 | new_node->length = length_stupidity->intval16; |
| 344 | break; | 351 | break; |
| 345 | case sizeof(uint32_t): | 352 | case sizeof(uint32_t): |
| 346 | new_node->length = length_stupidity->intval32; | 353 | new_node->length = length_stupidity->intval32; |
| 347 | break; | 354 | break; |
| 348 | case sizeof(uint64_t): | 355 | case sizeof(uint64_t): |
| 349 | new_node->length = length_stupidity->intval64; | 356 | new_node->length = length_stupidity->intval64; |
| 350 | break; | 357 | break; |
| 351 | default: | 358 | default: |
| 352 | free(new_node); | 359 | free(new_node); |
| 353 | free(length_stupidity); | 360 | free(length_stupidity); |
| 354 | return NULL; | 361 | return NULL; |
| 355 | } | 362 | } |
| 356 | // There, we have our fucking length now. | 363 | // There, we have our fucking length now. |
| 357 | *position = myPos; | 364 | *position = myPos; |
| 358 | free(length_stupidity); // cleanup | 365 | free(length_stupidity); // cleanup |
| 359 | } | 366 | } |
| 360 | |||
| 361 | // Now we're in the data. | 367 | // Now we're in the data. |
| 362 | // Error-checking sorta | 368 | // Error-checking sorta |
| 363 | if ((myPos + new_node->length) >= bplength) { | 369 | if ((myPos + new_node->length) >= bplength) { |
| 364 | new_node->length = bplength - myPos; // truncate the object | 370 | new_node->length = bplength - myPos; // truncate the object |
| 365 | } | 371 | } |
| 366 | |||
| 367 | // And now for the greatest show on earth: the giant fucking switch statement. | 372 | // And now for the greatest show on earth: the giant fucking switch statement. |
| 368 | switch (new_node->type) { | 373 | switch (new_node->type) { |
| 369 | case BPLIST_INT: | 374 | case BPLIST_INT: |
| 370 | new_node->length = uipow(2, new_node->length); // make length less misleading | 375 | new_node->length = uipow(2, new_node->length); // make length less misleading |
| 371 | switch (new_node->length) { | 376 | switch (new_node->length) { |
| 372 | case sizeof(uint8_t): | 377 | case sizeof(uint8_t): |
| 373 | new_node->intval8 = bpbuffer[myPos]; | 378 | new_node->intval8 = bpbuffer[myPos]; |
| 374 | break; | ||
| 375 | case sizeof(uint16_t): | ||
| 376 | memcpy(&new_node->intval16, bpbuffer+myPos, sizeof(uint16_t)); | ||
| 377 | new_node->intval16 = ntohs(new_node->intval16); | ||
| 378 | break; | ||
| 379 | case sizeof(uint32_t): | ||
| 380 | memcpy(&new_node->intval32, bpbuffer+myPos, sizeof(uint32_t)); | ||
| 381 | new_node->intval32 = ntohl(new_node->intval32); | ||
| 382 | break; | ||
| 383 | case sizeof(uint64_t): | ||
| 384 | memcpy(&new_node->intval64, bpbuffer+myPos, sizeof(uint64_t)); | ||
| 385 | byte_convert(&new_node->intval64, sizeof(uint64_t)); | ||
| 386 | break; | ||
| 387 | default: | ||
| 388 | free(new_node); | ||
| 389 | printf("parse_raw_node: lol: invalid int: size given %i\n", new_node->length); | ||
| 390 | printf("parse_raw_node: lol: by the way sizeof(uint64) = %i\n", sizeof(uint64_t)); | ||
| 391 | return NULL; | ||
| 392 | } | ||
| 393 | break; | 379 | break; |
| 394 | 380 | case sizeof(uint16_t): | |
| 395 | case BPLIST_REAL: | 381 | memcpy(&new_node->intval16, bpbuffer + myPos, sizeof(uint16_t)); |
| 396 | new_node->length = uipow(2, new_node->length); | 382 | new_node->intval16 = ntohs(new_node->intval16); |
| 397 | memcpy(&new_node->realval, bpbuffer+myPos, new_node->length); // XXX: probable buffer overflow here | ||
| 398 | //new_node->realval = bpbuffer[myPos]; // why not | ||
| 399 | byte_convert(&new_node->realval, sizeof(double)); | ||
| 400 | break; | 383 | break; |
| 401 | 384 | case sizeof(uint32_t): | |
| 402 | case BPLIST_DICT: /* returning a raw dict, it forward-references, so. */ | 385 | memcpy(&new_node->intval32, bpbuffer + myPos, sizeof(uint32_t)); |
| 403 | new_node->length = new_node->length * 2; // dicts lie | 386 | new_node->intval32 = ntohl(new_node->intval32); |
| 404 | case BPLIST_ARRAY: /* returning a raw array, it forward-references, so. */ | ||
| 405 | new_node->intval8 = ref_size; // in arrays and dicts, the "ref size" alluded to in the trailer applies, and should be stored in intval8 so as to save space. | ||
| 406 | case BPLIST_STRING: | ||
| 407 | case BPLIST_DATA: | ||
| 408 | default: /* made to hold raw data. */ | ||
| 409 | modifier = (new_node->intval8 > 0) ? new_node->intval8 : 1; | ||
| 410 | new_node->strval = (char*)malloc(sizeof(char) * (new_node->length * modifier)); | ||
| 411 | memcpy(new_node->strval, bpbuffer+myPos, (new_node->length * modifier)); | ||
| 412 | break; | 387 | break; |
| 413 | 388 | case sizeof(uint64_t): | |
| 414 | case BPLIST_UNICODE: | 389 | memcpy(&new_node->intval64, bpbuffer + myPos, sizeof(uint64_t)); |
| 415 | new_node->unicodeval = (wchar_t*)malloc(sizeof(wchar_t) * new_node->length); | 390 | byte_convert((char *) &new_node->intval64, sizeof(uint64_t)); |
| 416 | memcpy(new_node->unicodeval, bpbuffer+myPos, new_node->length); | ||
| 417 | break; | 391 | break; |
| 392 | default: | ||
| 393 | free(new_node); | ||
| 394 | printf("parse_raw_node: lol: invalid int: size given %lu\n", (long unsigned int) new_node->length); | ||
| 395 | printf("parse_raw_node: lol: by the way sizeof(uint64) = %i\n", sizeof(uint64_t)); | ||
| 396 | return NULL; | ||
| 397 | } | ||
| 398 | break; | ||
| 399 | |||
| 400 | case BPLIST_REAL: | ||
| 401 | new_node->length = uipow(2, new_node->length); | ||
| 402 | memcpy(&new_node->realval, bpbuffer + myPos, new_node->length); // XXX: probable buffer overflow here | ||
| 403 | //new_node->realval = bpbuffer[myPos]; // why not | ||
| 404 | byte_convert((char *) &new_node->realval, sizeof(double)); | ||
| 405 | break; | ||
| 406 | |||
| 407 | case BPLIST_DICT: /* returning a raw dict, it forward-references, so. */ | ||
| 408 | new_node->length = new_node->length * 2; // dicts lie | ||
| 409 | case BPLIST_ARRAY: /* returning a raw array, it forward-references, so. */ | ||
| 410 | new_node->intval8 = ref_size; // in arrays and dicts, the "ref size" alluded to in the trailer applies, and should be stored in intval8 so as to save space. | ||
| 411 | case BPLIST_STRING: | ||
| 412 | case BPLIST_DATA: | ||
| 413 | default: /* made to hold raw data. */ | ||
| 414 | modifier = (new_node->intval8 > 0) ? new_node->intval8 : 1; | ||
| 415 | new_node->strval = (char *) malloc(sizeof(char) * (new_node->length * modifier)); | ||
| 416 | memcpy(new_node->strval, bpbuffer + myPos, (new_node->length * modifier)); | ||
| 417 | break; | ||
| 418 | |||
| 419 | case BPLIST_UNICODE: | ||
| 420 | new_node->unicodeval = (wchar_t *) malloc(sizeof(wchar_t) * new_node->length); | ||
| 421 | memcpy(new_node->unicodeval, bpbuffer + myPos, new_node->length); | ||
| 422 | break; | ||
| 418 | } | 423 | } |
| 419 | 424 | ||
| 420 | myPos += new_node->length; | 425 | myPos += new_node->length; |
| 421 | *position = myPos; | 426 | *position = myPos; |
| 422 | return new_node; | 427 | return new_node; |
| 423 | } | 428 | } |
| 424 | 429 | ||
| 425 | void print_bytes(char *val, size_t size) { | 430 | void print_bytes(char *val, size_t size) |
| 431 | { | ||
| 426 | int i = 0; | 432 | int i = 0; |
| 427 | for (i = 0; i < size; i++) { | 433 | for (i = 0; i < size; i++) { |
| 428 | printf("Byte %i: 0x%x\n", i, val[i]); | 434 | printf("Byte %i: 0x%x\n", i, val[i]); |
| 429 | } | 435 | } |
| 430 | } | 436 | } |
| 431 | 437 | ||
| 432 | bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *position) { | 438 | bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t * position) |
| 439 | { | ||
| 433 | bplist_node **nodeslist = NULL, **newaddr = NULL; | 440 | bplist_node **nodeslist = NULL, **newaddr = NULL; |
| 434 | bplist_node *new_node = NULL, *root_node = NULL; | 441 | bplist_node *new_node = NULL, *root_node = NULL; |
| 435 | 442 | ||
| 436 | uint32_t nodeslength = 0; | 443 | uint32_t nodeslength = 0; |
| 437 | uint8_t offset_size = 0, dict_param_size = 0; | 444 | uint8_t offset_size = 0, dict_param_size = 0; |
| 438 | offset_size = bpbuffer[bplength-26]; | 445 | offset_size = bpbuffer[bplength - 26]; |
| 439 | dict_param_size = bpbuffer[bplength-25]; | 446 | dict_param_size = bpbuffer[bplength - 25]; |
| 440 | uint64_t current_offset = 0; | 447 | uint64_t current_offset = 0; |
| 441 | //uint64_t num_objects = *(bpbuffer+(bplength-24)), root_object = *(bpbuffer+(bplength-16)), offset_table_index = *(bpbuffer+(bplength-8)); | 448 | //uint64_t num_objects = *(bpbuffer+(bplength-24)), root_object = *(bpbuffer+(bplength-16)), offset_table_index = *(bpbuffer+(bplength-8)); |
| 442 | uint64_t num_objects = 0, root_object = 0, offset_table_index = 0; | 449 | uint64_t num_objects = 0, root_object = 0, offset_table_index = 0; |
| 443 | memcpy(&num_objects, bpbuffer+bplength-24, sizeof(uint64_t)); | 450 | memcpy(&num_objects, bpbuffer + bplength - 24, sizeof(uint64_t)); |
| 444 | memcpy(&root_object, bpbuffer+bplength-16, sizeof(uint64_t)); | 451 | memcpy(&root_object, bpbuffer + bplength - 16, sizeof(uint64_t)); |
| 445 | memcpy(&offset_table_index, bpbuffer+bplength-8, sizeof(uint64_t)); | 452 | memcpy(&offset_table_index, bpbuffer + bplength - 8, sizeof(uint64_t)); |
| 446 | byte_convert(&num_objects, sizeof(uint64_t)); | 453 | byte_convert((char *) &num_objects, sizeof(uint64_t)); |
| 447 | byte_convert(&root_object, sizeof(uint64_t)); | 454 | byte_convert((char *) &root_object, sizeof(uint64_t)); |
| 448 | byte_convert(&offset_table_index, sizeof(uint64_t)); | 455 | byte_convert((char *) &offset_table_index, sizeof(uint64_t)); |
| 449 | 456 | ||
| 450 | log_debug_msg("Offset size: %i\nGiven: %i\n", offset_size, bpbuffer[bplength-26]); | 457 | log_debug_msg("Offset size: %i\nGiven: %i\n", offset_size, bpbuffer[bplength - 26]); |
| 451 | log_debug_msg("Ref size: %i\nGiven: %i\n", dict_param_size, bpbuffer[bplength-25]); | 458 | log_debug_msg("Ref size: %i\nGiven: %i\n", dict_param_size, bpbuffer[bplength - 25]); |
| 452 | log_debug_msg("Number of objects: %lli\nGiven: %llu\n", num_objects, *(bpbuffer+bplength-24)); | 459 | log_debug_msg("Number of objects: %lli\nGiven: %llu\n", num_objects, *(bpbuffer + bplength - 24)); |
| 453 | log_debug_msg("Root object index: %lli\nGiven: %llu\n", root_object, *(bpbuffer+bplength-16)); | 460 | log_debug_msg("Root object index: %lli\nGiven: %llu\n", root_object, *(bpbuffer + bplength - 16)); |
| 454 | log_debug_msg("Offset table index: %lli\nGiven: %llu\n", offset_table_index, *(bpbuffer+bplength-8)); | 461 | log_debug_msg("Offset table index: %lli\nGiven: %llu\n", offset_table_index, *(bpbuffer + bplength - 8)); |
| 455 | log_debug_msg("Size of uint64: %i\n", sizeof(uint64_t)); | 462 | log_debug_msg("Size of uint64: %i\n", sizeof(uint64_t)); |
| 456 | 463 | ||
| 457 | int i = 0, j = 0, k = 0, str_i = 0, str_j = 0; | 464 | int i = 0, j = 0, k = 0, str_i = 0, str_j = 0; |
| 458 | uint32_t index1 = 0, index2 = 0; | 465 | uint32_t index1 = 0, index2 = 0; |
| 459 | 466 | ||
| 460 | nodeslist = (bplist_node**)malloc(sizeof(bplist_node*) * num_objects); | 467 | nodeslist = (bplist_node **) malloc(sizeof(bplist_node *) * num_objects); |
| 461 | if (!nodeslist) return NULL; | 468 | if (!nodeslist) |
| 469 | return NULL; | ||
| 462 | 470 | ||
| 463 | for (i = 0; i < num_objects; i++) { | 471 | for (i = 0; i < num_objects; i++) { |
| 464 | memcpy(¤t_offset, bpbuffer+(offset_table_index+(i*offset_size)), offset_size); | 472 | memcpy(¤t_offset, bpbuffer + (offset_table_index + (i * offset_size)), offset_size); |
| 465 | //current_offset = (offset_size == 2) ? ntohs(current_offset) : (offset_size == 4) ? ntohl(current_offset) : current_offset; | 473 | //current_offset = (offset_size == 2) ? ntohs(current_offset) : (offset_size == 4) ? ntohl(current_offset) : current_offset; |
| 466 | //if (offset_size == 8) byte_convert(¤t_offset, 8); | 474 | //if (offset_size == 8) byte_convert(¤t_offset, 8); |
| 467 | byte_convert(¤t_offset, (offset_size <= sizeof(current_offset)) ? offset_size : sizeof(current_offset)); | 475 | byte_convert((char *) ¤t_offset, |
| 476 | (offset_size <= sizeof(current_offset)) ? offset_size : sizeof(current_offset)); | ||
| 468 | log_debug_msg("parse_nodes: current_offset = %x\n", current_offset); | 477 | log_debug_msg("parse_nodes: current_offset = %x\n", current_offset); |
| 469 | nodeslist[i] = parse_raw_node(bpbuffer, bplength, ¤t_offset, dict_param_size); | 478 | nodeslist[i] = parse_raw_node(bpbuffer, bplength, (uint32_t *) & current_offset, dict_param_size); |
| 470 | log_debug_msg("parse_nodes: parse_raw_node done\n"); | 479 | log_debug_msg("parse_nodes: parse_raw_node done\n"); |
| 471 | } | 480 | } |
| 472 | 481 | ||
| @@ -475,55 +484,55 @@ bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *posi | |||
| 475 | // set elements for dicts and arrays and leave the rest alone | 484 | // set elements for dicts and arrays and leave the rest alone |
| 476 | log_debug_msg("parse_nodes: on node %i\n", i); | 485 | log_debug_msg("parse_nodes: on node %i\n", i); |
| 477 | switch (nodeslist[i]->type) { | 486 | switch (nodeslist[i]->type) { |
| 478 | case BPLIST_DICT: | 487 | case BPLIST_DICT: |
| 479 | log_debug_msg("parse_nodes: dictionary found\n"); | 488 | log_debug_msg("parse_nodes: dictionary found\n"); |
| 480 | nodeslist[i]->subnodes = (bplist_node*)malloc(sizeof(bplist_node) * nodeslist[i]->length); | 489 | nodeslist[i]->subnodes = (bplist_node **) malloc(sizeof(bplist_node) * nodeslist[i]->length); |
| 481 | for (j = 0; j < (nodeslist[i]->length / 2); j++) { | 490 | for (j = 0; j < (nodeslist[i]->length / 2); j++) { |
| 482 | str_i = j * nodeslist[i]->intval8; | 491 | str_i = j * nodeslist[i]->intval8; |
| 483 | str_j = (j + (nodeslist[i]->length / 2)) * nodeslist[i]->intval8; | 492 | str_j = (j + (nodeslist[i]->length / 2)) * nodeslist[i]->intval8; |
| 484 | 493 | ||
| 485 | memcpy(&index1, nodeslist[i]->strval+str_i, nodeslist[i]->intval8); | 494 | memcpy(&index1, nodeslist[i]->strval + str_i, nodeslist[i]->intval8); |
| 486 | memcpy(&index2, nodeslist[i]->strval+str_j, nodeslist[i]->intval8); | 495 | memcpy(&index2, nodeslist[i]->strval + str_j, nodeslist[i]->intval8); |
| 487 | //index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1; | 496 | //index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1; |
| 488 | //index2 = (dict_param_size == 1) ? index2 : (dict_param_size == 2) ? ntohs(index2) : (dict_param_size == 4) ? ntohl(index2) : index2; | 497 | //index2 = (dict_param_size == 1) ? index2 : (dict_param_size == 2) ? ntohs(index2) : (dict_param_size == 4) ? ntohl(index2) : index2; |
| 489 | byte_convert(&index1, (dict_param_size <= sizeof(index1)) ? dict_param_size : sizeof(index2)); | 498 | byte_convert((char *) &index1, (dict_param_size <= sizeof(index1)) ? dict_param_size : sizeof(index2)); |
| 490 | byte_convert(&index2, (dict_param_size <= sizeof(index2)) ? dict_param_size : sizeof(index2)); | 499 | byte_convert((char *) &index2, (dict_param_size <= sizeof(index2)) ? dict_param_size : sizeof(index2)); |
| 491 | //printf("parse_nodes: key index %i value %i\n", index1, index2); | 500 | //printf("parse_nodes: key index %i value %i\n", index1, index2); |
| 492 | //printf("parse_nodes: key type %x and length %i\n", nodeslist[index1]->type, nodeslist[index1]->length); | 501 | //printf("parse_nodes: key type %x and length %i\n", nodeslist[index1]->type, nodeslist[index1]->length); |
| 493 | //printf("parse_nodes: value type %x and length %i\n", nodeslist[index2]->type, nodeslist[index2]->length); | 502 | //printf("parse_nodes: value type %x and length %i\n", nodeslist[index2]->type, nodeslist[index2]->length); |
| 494 | nodeslist[i]->subnodes[k++] = nodeslist[index1]; | 503 | nodeslist[i]->subnodes[k++] = nodeslist[index1]; |
| 495 | nodeslist[i]->subnodes[k++] = nodeslist[index2]; | 504 | nodeslist[i]->subnodes[k++] = nodeslist[index2]; |
| 496 | } | 505 | } |
| 497 | 506 | ||
| 498 | nodeslist[i]->length = nodeslist[i]->length / 2; | 507 | nodeslist[i]->length = nodeslist[i]->length / 2; |
| 499 | free(nodeslist[i]->strval); | 508 | free(nodeslist[i]->strval); |
| 500 | k = 0; | 509 | k = 0; |
| 501 | break; | 510 | break; |
| 502 | 511 | ||
| 503 | case BPLIST_ARRAY: | 512 | case BPLIST_ARRAY: |
| 504 | log_debug_msg("parse_nodes: array found\n"); | 513 | log_debug_msg("parse_nodes: array found\n"); |
| 505 | nodeslist[i]->subnodes = (bplist_node*)malloc(sizeof(bplist_node) * nodeslist[i]->length); // memory allocation helps a lot when storing data | 514 | nodeslist[i]->subnodes = (bplist_node **) malloc(sizeof(bplist_node) * nodeslist[i]->length); // memory allocation helps a lot when storing data |
| 506 | 515 | ||
| 507 | for (j = 0; j < nodeslist[i]->length; j++) { | 516 | for (j = 0; j < nodeslist[i]->length; j++) { |
| 508 | log_debug_msg("parse_nodes: array index %i\n", j); | 517 | log_debug_msg("parse_nodes: array index %i\n", j); |
| 509 | str_j = j * nodeslist[i]->intval8; | 518 | str_j = j * nodeslist[i]->intval8; |
| 510 | //index1 = nodeslist[i]->strval[j]; | 519 | //index1 = nodeslist[i]->strval[j]; |
| 511 | memcpy(&index1, nodeslist[i]->strval+str_j, nodeslist[i]->intval8); | 520 | memcpy(&index1, nodeslist[i]->strval + str_j, nodeslist[i]->intval8); |
| 512 | log_debug_msg("parse_nodes: post-memcpy\n"); | 521 | log_debug_msg("parse_nodes: post-memcpy\n"); |
| 513 | //index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1; | 522 | //index1 = (dict_param_size == 1) ? index1 : (dict_param_size == 2) ? ntohs(index1) : (dict_param_size == 4) ? ntohl(index1) : index1; |
| 514 | byte_convert(&index1, (dict_param_size <= sizeof(index1)) ? dict_param_size : sizeof(index1)); | 523 | byte_convert((char *) &index1, (dict_param_size <= sizeof(index1)) ? dict_param_size : sizeof(index1)); |
| 515 | log_debug_msg("parse_nodes: post-ntohl\nindex1 = %i\n", index1); | 524 | log_debug_msg("parse_nodes: post-ntohl\nindex1 = %i\n", index1); |
| 516 | nodeslist[i]->subnodes[j] = nodeslist[index1]; | 525 | nodeslist[i]->subnodes[j] = nodeslist[index1]; |
| 517 | log_debug_msg("parse_nodes: post-assignment\n"); | 526 | log_debug_msg("parse_nodes: post-assignment\n"); |
| 518 | } | 527 | } |
| 519 | free(nodeslist[i]->strval); | 528 | free(nodeslist[i]->strval); |
| 520 | break; | 529 | break; |
| 521 | default: | 530 | default: |
| 522 | //printf("lol... type %x\n", nodeslist[i]->type); | 531 | //printf("lol... type %x\n", nodeslist[i]->type); |
| 523 | break; | 532 | break; |
| 524 | } // those are the only two we need to correct for. | 533 | } // those are the only two we need to correct for. |
| 525 | } | 534 | } |
| 526 | 535 | ||
| 527 | root_node = nodeslist[root_object]; | 536 | root_node = nodeslist[root_object]; |
| 528 | return root_node; | 537 | return root_node; |
| 529 | } | 538 | } |
diff --git a/src/plist.h b/src/plist.h index 98c7d91..5f31281 100644 --- a/src/plist.h +++ b/src/plist.h | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
| 32 | #include <unistd.h> | 32 | #include <unistd.h> |
| 33 | 33 | ||
| 34 | char *format_string(const char *buf, int cols, int depth); | ||
| 34 | xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); | 35 | xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); |
| 35 | xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); | 36 | xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); |
| 36 | xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); | 37 | xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); |
| @@ -47,7 +48,7 @@ void free_dictionary(char **dictionary); | |||
| 47 | enum { | 48 | enum { |
| 48 | BPLIST_TRUE = 0x08, | 49 | BPLIST_TRUE = 0x08, |
| 49 | BPLIST_FALSE = 0x09, | 50 | BPLIST_FALSE = 0x09, |
| 50 | BPLIST_FILL = 0x0F, /* will be used for length grabbing */ | 51 | BPLIST_FILL = 0x0F, /* will be used for length grabbing */ |
| 51 | BPLIST_INT = 0x10, | 52 | BPLIST_INT = 0x10, |
| 52 | BPLIST_REAL = 0x20, | 53 | BPLIST_REAL = 0x20, |
| 53 | BPLIST_DATE = 0x33, | 54 | BPLIST_DATE = 0x33, |
| @@ -62,15 +63,17 @@ enum { | |||
| 62 | }; | 63 | }; |
| 63 | 64 | ||
| 64 | typedef struct _bplist_node { | 65 | typedef struct _bplist_node { |
| 65 | struct _bplist_node *next, **subnodes; // subnodes is for arrays, dicts and (potentially) sets. | 66 | struct _bplist_node *next, **subnodes; // subnodes is for arrays, dicts and (potentially) sets. |
| 66 | uint64_t length, intval64; | 67 | uint64_t length, intval64; |
| 67 | uint32_t intval32; // length = subnodes | 68 | uint32_t intval32; // length = subnodes |
| 68 | uint16_t intval16; | 69 | uint16_t intval16; |
| 69 | uint8_t intval8; | 70 | uint8_t intval8; |
| 70 | uint8_t type, *indexes; // indexes for array-types; essentially specify the order in which to access for key => value pairs | 71 | uint8_t type, *indexes; // indexes for array-types; essentially specify the order in which to access for key => value pairs |
| 71 | char *strval; | 72 | char *strval; |
| 72 | double realval; | 73 | double realval; |
| 73 | wchar_t *unicodeval; | 74 | wchar_t *unicodeval; |
| 74 | } bplist_node; | 75 | } bplist_node; |
| 75 | 76 | ||
| 77 | bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t * position); | ||
| 78 | |||
| 76 | #endif | 79 | #endif |
