summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plist.c335
-rw-r--r--src/plist.h11
2 files changed, 179 insertions, 167 deletions
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
264uint32_t uipow(uint32_t value, uint32_t power) { 264uint32_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
273void byte_convert(char *address, size_t size) { 275void 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
285bplist_node *parse_raw_node(const char *bpbuffer, uint32_t bplength, uint32_t *position, uint8_t ref_size) { 288bplist_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
425void print_bytes(char *val, size_t size) { 430void 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
432bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t *position) { 438bplist_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(&current_offset, bpbuffer+(offset_table_index+(i*offset_size)), offset_size); 472 memcpy(&current_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(&current_offset, 8); 474 //if (offset_size == 8) byte_convert(&current_offset, 8);
467 byte_convert(&current_offset, (offset_size <= sizeof(current_offset)) ? offset_size : sizeof(current_offset)); 475 byte_convert((char *) &current_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, &current_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
34char *format_string(const char *buf, int cols, int depth);
34xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); 35xmlNode *add_key_dict_node(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth);
35xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); 36xmlNode *add_key_str_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth);
36xmlNode *add_key_data_dict_element(xmlDocPtr plist, xmlNode * dict, const char *key, const char *value, int depth); 37xmlNode *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);
47enum { 48enum {
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
64typedef struct _bplist_node { 65typedef 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
77bplist_node *parse_nodes(const char *bpbuffer, uint32_t bplength, uint32_t * position);
78
76#endif 79#endif