summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bplist.c29
-rw-r--r--src/lockdown.c105
-rw-r--r--src/plist.c27
-rw-r--r--src/plist.h20
-rw-r--r--src/xplist.c26
5 files changed, 105 insertions, 102 deletions
diff --git a/src/bplist.c b/src/bplist.c
index 6136fe9..a5b1c9b 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -567,15 +567,15 @@ void serialize_plist(GNode * node, gpointer data)
567 return; 567 return;
568} 568}
569 569
570 570#define Log2(x) (x == 8 ? 3 : (x == 4 ? 2 : (x == 2 ? 1 : 0)))
571 571
572void write_int(GByteArray * bplist, uint64_t val) 572void write_int(GByteArray * bplist, uint64_t val)
573{ 573{
574 uint64_t size = get_needed_bytes(val); 574 uint64_t size = get_needed_bytes(val);
575 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size); 575 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
576 buff[0] = BPLIST_UINT | size >> 1; 576 buff[0] = BPLIST_UINT | Log2(size);
577 memcpy(buff + 1, &val, size); 577 memcpy(buff + 1, &val, size);
578 swap_n_bytes(buff + 1, size); 578 byte_convert(buff + 1, size);
579 g_byte_array_append(bplist, buff, sizeof(uint8_t) + size); 579 g_byte_array_append(bplist, buff, sizeof(uint8_t) + size);
580 free(buff); 580 free(buff);
581} 581}
@@ -584,9 +584,9 @@ void write_real(GByteArray * bplist, double val)
584{ 584{
585 uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space 585 uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space
586 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size); 586 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
587 buff[0] = BPLIST_REAL | size >> 1; 587 buff[0] = BPLIST_REAL | Log2(size);
588 memcpy(buff + 1, &val, size); 588 memcpy(buff + 1, &val, size);
589 swap_n_bytes(buff + 1, size); 589 byte_convert(buff + 1, size);
590 g_byte_array_append(bplist, buff, sizeof(uint8_t) + size); 590 g_byte_array_append(bplist, buff, sizeof(uint8_t) + size);
591 free(buff); 591 free(buff);
592} 592}
@@ -638,7 +638,7 @@ void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint
638 for (i = 0, cur = node->children; cur && i < size; cur = cur->next, i++) { 638 for (i = 0, cur = node->children; cur && i < size; cur = cur->next, i++) {
639 idx = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur)); 639 idx = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur));
640 memcpy(buff + i * dict_param_size, &idx, dict_param_size); 640 memcpy(buff + i * dict_param_size, &idx, dict_param_size);
641 swap_n_bytes(buff + i * dict_param_size, dict_param_size); 641 byte_convert(buff + i * dict_param_size, dict_param_size);
642 } 642 }
643 643
644 //now append to bplist 644 //now append to bplist
@@ -650,7 +650,7 @@ void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint
650void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) 650void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size)
651{ 651{
652 uint64_t size = g_node_n_children(node) / 2; 652 uint64_t size = g_node_n_children(node) / 2;
653 uint8_t marker = BPLIST_ARRAY | (size < 15 ? size : 0xf); 653 uint8_t marker = BPLIST_DICT | (size < 15 ? size : 0xf);
654 g_byte_array_append(bplist, &marker, sizeof(uint8_t)); 654 g_byte_array_append(bplist, &marker, sizeof(uint8_t));
655 if (size >= 15) { 655 if (size >= 15) {
656 GByteArray *int_buff = g_byte_array_new(); 656 GByteArray *int_buff = g_byte_array_new();
@@ -668,22 +668,24 @@ void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8
668 for (i = 0, cur = node->children; cur && i < size; cur = cur->next->next, i++) { 668 for (i = 0, cur = node->children; cur && i < size; cur = cur->next->next, i++) {
669 idx1 = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur)); 669 idx1 = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur));
670 memcpy(buff + i * dict_param_size, &idx1, dict_param_size); 670 memcpy(buff + i * dict_param_size, &idx1, dict_param_size);
671 swap_n_bytes(buff + i * dict_param_size, dict_param_size); 671 byte_convert(buff + i * dict_param_size, dict_param_size);
672 672
673 idx2 = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur->next)); 673 idx2 = GPOINTER_TO_UINT(g_hash_table_lookup(ref_table, cur->next));
674 memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size); 674 memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size);
675 swap_n_bytes(buff + (i + size) * dict_param_size, dict_param_size); 675 byte_convert(buff + (i + size) * dict_param_size, dict_param_size);
676 } 676 }
677 677
678 //now append to bplist 678 //now append to bplist
679 g_byte_array_append(bplist, buff, size * dict_param_size); 679 g_byte_array_append(bplist, buff, size * 2 * dict_param_size);
680 free(buff); 680 free(buff);
681 681
682} 682}
683 683
684void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) 684void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
685{ 685{
686 //first serialize tree 686 //check for valid input
687 if (!plist || !plist_bin || *plist_bin || !length)
688 return;
687 689
688 //list of objects 690 //list of objects
689 GPtrArray *objects = g_ptr_array_new(); 691 GPtrArray *objects = g_ptr_array_new();
@@ -692,7 +694,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
692 694
693 //serialize plist 695 //serialize plist
694 struct serialize_s ser_s = { objects, ref_table }; 696 struct serialize_s ser_s = { objects, ref_table };
695 g_node_children_foreach(plist, G_TRAVERSE_ALL, serialize_plist, &ser_s); 697 serialize_plist(plist, &ser_s);
696 698
697 //now stream to output buffer 699 //now stream to output buffer
698 uint8_t offset_size = 0; //unknown yet 700 uint8_t offset_size = 0; //unknown yet
@@ -759,10 +761,11 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
759 761
760 //write offsets 762 //write offsets
761 offset_size = get_needed_bytes(bplist_buff->len); 763 offset_size = get_needed_bytes(bplist_buff->len);
764 offset_table_index = bplist_buff->len;
762 for (i = 0; i <= num_objects; i++) { 765 for (i = 0; i <= num_objects; i++) {
763 uint8_t *buff = (uint8_t *) malloc(offset_size); 766 uint8_t *buff = (uint8_t *) malloc(offset_size);
764 memcpy(buff, offsets + i, offset_size); 767 memcpy(buff, offsets + i, offset_size);
765 swap_n_bytes(buff, offset_size); 768 byte_convert(buff, offset_size);
766 g_byte_array_append(bplist_buff, buff, offset_size); 769 g_byte_array_append(bplist_buff, buff, offset_size);
767 free(buff); 770 free(buff);
768 } 771 }
diff --git a/src/lockdown.c b/src/lockdown.c
index 0957fa2..4c96a7d 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -177,11 +177,8 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control)
177 int bytes = 0, i = 0; 177 int bytes = 0, i = 0;
178 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 178 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
179 179
180 plist_t plist = NULL; 180 plist_t dict = NULL;
181 plist_new_plist(&plist); 181 plist_new_dict(&dict);
182
183 dict_t dict = NULL;
184 plist_new_dict_in_plist(plist, &dict);
185 182
186 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "QueryType"); 183 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "QueryType");
187 184
@@ -189,23 +186,23 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control)
189 char *XML_content = NULL; 186 char *XML_content = NULL;
190 uint32_t length = 0; 187 uint32_t length = 0;
191 188
192 plist_to_xml(plist, &XML_content, &length); 189 plist_to_xml(dict, &XML_content, &length);
193 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); 190 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content);
194 ret = iphone_lckd_send(control, XML_content, length, &bytes); 191 ret = iphone_lckd_send(control, XML_content, length, &bytes);
195 192
196 xmlFree(XML_content); 193 xmlFree(XML_content);
197 XML_content = NULL; 194 XML_content = NULL;
198 plist_free(plist); 195 plist_free(dict);
199 plist = NULL; 196 dict = NULL;
200 197
201 ret = iphone_lckd_recv(control, &XML_content, &bytes); 198 ret = iphone_lckd_recv(control, &XML_content, &bytes);
202 log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); 199 log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content);
203 xml_to_plist(XML_content, bytes, &plist); 200 xml_to_plist(XML_content, bytes, &dict);
204 201
205 if (!plist) 202 if (!dict)
206 return IPHONE_E_PLIST_ERROR; 203 return IPHONE_E_PLIST_ERROR;
207 204
208 plist_t query_node = find_query_node(plist, "Request", "QueryType"); 205 plist_t query_node = find_query_node(dict, "Request", "QueryType");
209 plist_t result_node = g_node_next_sibling(query_node); 206 plist_t result_node = g_node_next_sibling(query_node);
210 plist_t value_node = g_node_next_sibling(result_node); 207 plist_t value_node = g_node_next_sibling(result_node);
211 208
@@ -239,19 +236,18 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
239{ 236{
240 if (!control || !req_key || !value || (value && *value)) 237 if (!control || !req_key || !value || (value && *value))
241 return IPHONE_E_INVALID_ARG; 238 return IPHONE_E_INVALID_ARG;
242 plist_t plist = NULL; 239
243 dict_t dict = NULL; 240 plist_t dict = NULL;
244 int bytes = 0, i = 0; 241 int bytes = 0, i = 0;
245 char *XML_content = NULL; 242 char *XML_content = NULL;
246 uint32_t length = 0; 243 uint32_t length = 0;
247 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 244 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
248 245
249 /* Setup DevicePublicKey request plist */ 246 /* Setup DevicePublicKey request plist */
250 plist_new_plist(&plist); 247 plist_new_dict(&dict);
251 plist_new_dict_in_plist(plist, &dict);
252 plist_add_dict_element(dict, req_key, PLIST_STRING, (void *) req_string); 248 plist_add_dict_element(dict, req_key, PLIST_STRING, (void *) req_string);
253 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "GetValue"); 249 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "GetValue");
254 plist_to_xml(plist, &XML_content, &length); 250 plist_to_xml(dict, &XML_content, &length);
255 251
256 /* send to iPhone */ 252 /* send to iPhone */
257 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); 253 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content);
@@ -259,8 +255,8 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
259 255
260 xmlFree(XML_content); 256 xmlFree(XML_content);
261 XML_content = NULL; 257 XML_content = NULL;
262 plist_free(plist); 258 plist_free(dict);
263 plist = NULL; 259 dict = NULL;
264 260
265 if (ret != IPHONE_E_SUCCESS) 261 if (ret != IPHONE_E_SUCCESS)
266 return ret; 262 return ret;
@@ -272,11 +268,11 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
272 if (ret != IPHONE_E_SUCCESS) 268 if (ret != IPHONE_E_SUCCESS)
273 return ret; 269 return ret;
274 270
275 xml_to_plist(XML_content, bytes, &plist); 271 xml_to_plist(XML_content, bytes, &dict);
276 if (!plist) 272 if (!dict)
277 return IPHONE_E_PLIST_ERROR; 273 return IPHONE_E_PLIST_ERROR;
278 274
279 plist_t query_node = find_query_node(plist, "Request", "GetValue"); 275 plist_t query_node = find_query_node(dict, "Request", "GetValue");
280 plist_t result_key_node = g_node_next_sibling(query_node); 276 plist_t result_key_node = g_node_next_sibling(query_node);
281 plist_t result_value_node = g_node_next_sibling(result_key_node); 277 plist_t result_value_node = g_node_next_sibling(result_key_node);
282 278
@@ -314,7 +310,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
314 ret = IPHONE_E_SUCCESS; 310 ret = IPHONE_E_SUCCESS;
315 } 311 }
316 312
317 plist_free(plist); 313 plist_free(dict);
318 free(XML_content); 314 free(XML_content);
319 return ret; 315 return ret;
320} 316}
@@ -408,9 +404,8 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client
408iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id) 404iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id)
409{ 405{
410 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 406 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
411 plist_t plist = NULL; 407 plist_t dict = NULL;
412 dict_t dict = NULL; 408 plist_t dict_record = NULL;
413 dict_t dict_record = NULL;
414 int bytes = 0, i = 0; 409 int bytes = 0, i = 0;
415 char *XML_content = NULL; 410 char *XML_content = NULL;
416 uint32_t length = 0; 411 uint32_t length = 0;
@@ -433,8 +428,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch
433 } 428 }
434 429
435 /* Setup Pair request plist */ 430 /* Setup Pair request plist */
436 plist_new_plist(&plist); 431 plist_new_dict(&dict);
437 plist_new_dict_in_plist(plist, &dict);
438 plist_add_dict_element(dict, "PairRecord", PLIST_DICT, NULL); 432 plist_add_dict_element(dict, "PairRecord", PLIST_DICT, NULL);
439 dict_record = g_node_last_child(dict); 433 dict_record = g_node_last_child(dict);
440 plist_add_dict_element(dict_record, "DeviceCertificate", PLIST_DATA, (void *) device_cert_b64); 434 plist_add_dict_element(dict_record, "DeviceCertificate", PLIST_DATA, (void *) device_cert_b64);
@@ -442,15 +436,15 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch
442 plist_add_dict_element(dict_record, "HostID", PLIST_STRING, (void *) host_id); 436 plist_add_dict_element(dict_record, "HostID", PLIST_STRING, (void *) host_id);
443 plist_add_dict_element(dict_record, "RootCertificate", PLIST_DATA, (void *) root_cert_b64); 437 plist_add_dict_element(dict_record, "RootCertificate", PLIST_DATA, (void *) root_cert_b64);
444 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "Pair"); 438 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "Pair");
445 plist_to_xml(plist, &XML_content, &length); 439 plist_to_xml(dict, &XML_content, &length);
446 log_debug_msg("XML Pairing request :\nsize : %i\nxml :\n %s", length, XML_content); 440 log_debug_msg("XML Pairing request :\nsize : %i\nxml :\n %s", length, XML_content);
447 441
448 /* send to iPhone */ 442 /* send to iPhone */
449 ret = iphone_lckd_send(control, XML_content, length, &bytes); 443 ret = iphone_lckd_send(control, XML_content, length, &bytes);
450 444
451 xmlFree(XML_content); 445 xmlFree(XML_content);
452 plist_free(plist); 446 plist_free(dict);
453 plist = NULL; 447 dict = NULL;
454 448
455 if (ret != IPHONE_E_SUCCESS) 449 if (ret != IPHONE_E_SUCCESS)
456 return ret; 450 return ret;
@@ -465,11 +459,11 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch
465 log_debug_msg(XML_content); 459 log_debug_msg(XML_content);
466 log_debug_msg("\n\n"); 460 log_debug_msg("\n\n");
467 461
468 xml_to_plist(XML_content, bytes, &plist); 462 xml_to_plist(XML_content, bytes, &dict);
469 if (!plist) 463 if (!dict)
470 return IPHONE_E_PLIST_ERROR; 464 return IPHONE_E_PLIST_ERROR;
471 465
472 plist_t query_node = find_query_node(plist, "Request", "Pair"); 466 plist_t query_node = find_query_node(dict, "Request", "Pair");
473 plist_t result_key_node = g_node_next_sibling(query_node); 467 plist_t result_key_node = g_node_next_sibling(query_node);
474 plist_t result_value_node = g_node_next_sibling(result_key_node); 468 plist_t result_value_node = g_node_next_sibling(result_key_node);
475 469
@@ -635,27 +629,25 @@ iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_
635 */ 629 */
636iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) 630iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID)
637{ 631{
638 plist_t plist = NULL; 632 plist_t dict = NULL;
639 dict_t dict = NULL;
640 char *XML_content = NULL; 633 char *XML_content = NULL;
641 uint32_t length = 0, bytes = 0, return_me = 0; 634 uint32_t length = 0, bytes = 0, return_me = 0;
642 635
643 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 636 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
644 637
645 /* Setup DevicePublicKey request plist */ 638 /* Setup DevicePublicKey request plist */
646 plist_new_plist(&plist); 639 plist_new_dict(&dict);
647 plist_new_dict_in_plist(plist, &dict);
648 plist_add_dict_element(dict, "HostID", PLIST_STRING, (void *) HostID); 640 plist_add_dict_element(dict, "HostID", PLIST_STRING, (void *) HostID);
649 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartSession"); 641 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartSession");
650 plist_to_xml(plist, &XML_content, &length); 642 plist_to_xml(dict, &XML_content, &length);
651 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); 643 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content);
652 644
653 ret = iphone_lckd_send(control, XML_content, length, &bytes); 645 ret = iphone_lckd_send(control, XML_content, length, &bytes);
654 646
655 xmlFree(XML_content); 647 xmlFree(XML_content);
656 XML_content = NULL; 648 XML_content = NULL;
657 plist_free(plist); 649 plist_free(dict);
658 plist = NULL; 650 dict = NULL;
659 651
660 if (ret != IPHONE_E_SUCCESS) 652 if (ret != IPHONE_E_SUCCESS)
661 return ret; 653 return ret;
@@ -663,11 +655,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c
663 if (bytes > 0) { 655 if (bytes > 0) {
664 ret = iphone_lckd_recv(control, &XML_content, &bytes); 656 ret = iphone_lckd_recv(control, &XML_content, &bytes);
665 log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); 657 log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content);
666 xml_to_plist(XML_content, bytes, &plist); 658 xml_to_plist(XML_content, bytes, &dict);
667 if (!plist) 659 if (!dict)
668 return IPHONE_E_PLIST_ERROR; 660 return IPHONE_E_PLIST_ERROR;
669 661
670 plist_t query_node = find_query_node(plist, "Request", "StartSession"); 662 plist_t query_node = find_query_node(dict, "Request", "StartSession");
671 plist_t result_key_node = g_node_next_sibling(query_node); 663 plist_t result_key_node = g_node_next_sibling(query_node);
672 plist_t result_value_node = g_node_next_sibling(result_key_node); 664 plist_t result_value_node = g_node_next_sibling(result_key_node);
673 665
@@ -681,8 +673,8 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c
681 673
682 xmlFree(XML_content); 674 xmlFree(XML_content);
683 XML_content = NULL; 675 XML_content = NULL;
684 plist_free(plist); 676 plist_free(dict);
685 plist = NULL; 677 dict = NULL;
686 678
687 if (result_key_type == PLIST_KEY && 679 if (result_key_type == PLIST_KEY &&
688 result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { 680 result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) {
@@ -871,8 +863,7 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
871 return IPHONE_E_SSL_ERROR; 863 return IPHONE_E_SSL_ERROR;
872 864
873 865
874 plist_t plist = NULL; 866 plist_t dict = NULL;
875 dict_t dict = NULL;
876 char *XML_content = NULL; 867 char *XML_content = NULL;
877 uint32_t length, i = 0, port_loc = 0, bytes = 0; 868 uint32_t length, i = 0, port_loc = 0, bytes = 0;
878 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 869 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
@@ -880,11 +871,10 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
880 free(host_id); 871 free(host_id);
881 host_id = NULL; 872 host_id = NULL;
882 873
883 plist_new_plist(&plist); 874 plist_new_dict(&dict);
884 plist_new_dict_in_plist(plist, &dict);
885 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartService"); 875 plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "StartService");
886 plist_add_dict_element(dict, "Service", PLIST_STRING, (void *) service); 876 plist_add_dict_element(dict, "Service", PLIST_STRING, (void *) service);
887 plist_to_xml(plist, &XML_content, &length); 877 plist_to_xml(dict, &XML_content, &length);
888 878
889 /* send to iPhone */ 879 /* send to iPhone */
890 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); 880 log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content);
@@ -892,8 +882,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
892 882
893 xmlFree(XML_content); 883 xmlFree(XML_content);
894 XML_content = NULL; 884 XML_content = NULL;
895 plist_free(plist); 885 plist_free(dict);
896 plist = NULL; 886 dict = NULL;
897 887
898 if (IPHONE_E_SUCCESS != ret) 888 if (IPHONE_E_SUCCESS != ret)
899 return ret; 889 return ret;
@@ -903,8 +893,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
903 if (IPHONE_E_SUCCESS != ret) 893 if (IPHONE_E_SUCCESS != ret)
904 return ret; 894 return ret;
905 895
906 xml_to_plist(XML_content, bytes, &plist); 896 xml_to_plist(XML_content, bytes, &dict);
907 if (!plist) 897 if (!dict)
908 return IPHONE_E_PLIST_ERROR; 898 return IPHONE_E_PLIST_ERROR;
909 899
910 900
@@ -912,11 +902,11 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
912 return IPHONE_E_NOT_ENOUGH_DATA; 902 return IPHONE_E_NOT_ENOUGH_DATA;
913 else { 903 else {
914 904
915 plist_t query_node = find_query_node(plist, "Request", "StartService"); 905 plist_t query_node = find_query_node(dict, "Request", "StartService");
916 plist_t result_key_node = g_node_next_sibling(query_node); 906 plist_t result_key_node = g_node_next_sibling(query_node);
917 plist_t result_value_node = g_node_next_sibling(result_key_node); 907 plist_t result_value_node = g_node_next_sibling(result_key_node);
918 908
919 plist_t port_key_node = find_node(plist, PLIST_KEY, "Port"); 909 plist_t port_key_node = find_node(dict, PLIST_KEY, "Port");
920 plist_t port_value_node = g_node_next_sibling(port_key_node); 910 plist_t port_value_node = g_node_next_sibling(port_key_node);
921 911
922 plist_type result_key_type; 912 plist_type result_key_type;
@@ -947,7 +937,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
947 log_debug_msg("end data received by lockdownd_start_service()\n"); 937 log_debug_msg("end data received by lockdownd_start_service()\n");
948 938
949 free(XML_content); 939 free(XML_content);
950 plist_free(plist); 940 plist_free(dict);
941 dict = NULL;
951 if (port && ret == IPHONE_E_SUCCESS) { 942 if (port && ret == IPHONE_E_SUCCESS) {
952 *port = port_loc; 943 *port = port_loc;
953 return IPHONE_E_SUCCESS; 944 return IPHONE_E_SUCCESS;
diff --git a/src/plist.c b/src/plist.c
index 76ae954..66a74c3 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -29,7 +29,7 @@
29#include <stdio.h> 29#include <stdio.h>
30 30
31 31
32void plist_new_plist(plist_t * plist) 32void plist_new_dict(plist_t * plist)
33{ 33{
34 if (*plist != NULL) 34 if (*plist != NULL)
35 return; 35 return;
@@ -38,7 +38,16 @@ void plist_new_plist(plist_t * plist)
38 *plist = g_node_new(data); 38 *plist = g_node_new(data);
39} 39}
40 40
41void plist_new_dict_in_plist(plist_t plist, dict_t * dict) 41void plist_new_array(plist_t * plist)
42{
43 if (*plist != NULL)
44 return;
45 struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1);
46 data->type = PLIST_ARRAY;
47 *plist = g_node_new(data);
48}
49
50void plist_new_dict_in_plist(plist_t plist, plist_t * dict)
42{ 51{
43 if (!plist || *dict) 52 if (!plist || *dict)
44 return; 53 return;
@@ -49,9 +58,6 @@ void plist_new_dict_in_plist(plist_t plist, dict_t * dict)
49 g_node_append(plist, *dict); 58 g_node_append(plist, *dict);
50} 59}
51 60
52void plist_new_array_in_plist(plist_t plist, int length, plist_type type, void **values, array_t * array)
53{
54}
55 61
56/** Adds a new key pair to a dict. 62/** Adds a new key pair to a dict.
57 * 63 *
@@ -61,7 +67,7 @@ void plist_new_array_in_plist(plist_t plist, int length, plist_type type, void *
61 * @param value a pointer to the actual buffer containing the value. WARNING : the buffer is supposed to match the type of the value 67 * @param value a pointer to the actual buffer containing the value. WARNING : the buffer is supposed to match the type of the value
62 * 68 *
63 */ 69 */
64void plist_add_dict_element(dict_t dict, char *key, plist_type type, void *value) 70void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value)
65{ 71{
66 if (!dict || !key || !value) 72 if (!dict || !key || !value)
67 return; 73 return;
@@ -110,7 +116,7 @@ void plist_free(plist_t plist)
110 g_node_destroy(plist); 116 g_node_destroy(plist);
111} 117}
112 118
113GNode *find_query_node(plist_t plist, char *key, char *request) 119plist_t find_query_node(plist_t plist, char *key, char *request)
114{ 120{
115 if (!plist) 121 if (!plist)
116 return NULL; 122 return NULL;
@@ -167,7 +173,7 @@ char compare_node_value(plist_type type, struct plist_data *data, void *value)
167 return res; 173 return res;
168} 174}
169 175
170GNode *find_node(plist_t plist, plist_type type, void *value) 176plist_t find_node(plist_t plist, plist_type type, void *value)
171{ 177{
172 if (!plist) 178 if (!plist)
173 return NULL; 179 return NULL;
@@ -228,7 +234,10 @@ void get_type_and_value(GNode * node, plist_type * type, void *value)
228 234
229plist_type plist_get_node_type(plist_t node) 235plist_type plist_get_node_type(plist_t node)
230{ 236{
231 return ((struct plist_data *) node->data)->type; 237 if (node && node->data)
238 return ((struct plist_data *) node->data)->type;
239 else
240 return PLIST_NONE;
232} 241}
233 242
234uint64_t plist_get_node_uint_val(plist_t node) 243uint64_t plist_get_node_uint_val(plist_t node)
diff --git a/src/plist.h b/src/plist.h
index e3f3f59..ff4bdbf 100644
--- a/src/plist.h
+++ b/src/plist.h
@@ -30,8 +30,6 @@
30#include <unistd.h> 30#include <unistd.h>
31#include <glib.h> 31#include <glib.h>
32 32
33char *format_string(const char *buf, int cols, int depth);
34
35 33
36typedef enum { 34typedef enum {
37 PLIST_BOOLEAN, 35 PLIST_BOOLEAN,
@@ -44,6 +42,7 @@ typedef enum {
44 PLIST_DATE, 42 PLIST_DATE,
45 PLIST_DATA, 43 PLIST_DATA,
46 PLIST_KEY, 44 PLIST_KEY,
45 PLIST_NONE
47} plist_type; 46} plist_type;
48 47
49 48
@@ -63,13 +62,12 @@ struct plist_data {
63 62
64 63
65typedef GNode *plist_t; 64typedef GNode *plist_t;
66typedef GNode *dict_t;
67typedef GNode *array_t;
68 65
69void plist_new_plist(plist_t * plist); 66
70void plist_new_dict_in_plist(plist_t plist, dict_t * dict); 67void plist_new_dict(plist_t * plist);
71void plist_new_array_in_plist(plist_t plist, int length, plist_type type, void **values, array_t * array); 68void plist_new_array(plist_t * plist);
72void plist_add_dict_element(dict_t dict, char *key, plist_type type, void *value); 69void plist_new_dict_in_plist(plist_t plist, plist_t * dict);
70void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value);
73void plist_free(plist_t plist); 71void plist_free(plist_t plist);
74 72
75void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); 73void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
@@ -78,8 +76,8 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
78void xml_to_plist(const char *plist_xml, uint32_t length, plist_t * plist); 76void xml_to_plist(const char *plist_xml, uint32_t length, plist_t * plist);
79void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist); 77void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist);
80 78
81GNode *find_query_node(plist_t plist, char *key, char *request); 79plist_t find_query_node(plist_t plist, char *key, char *request);
82GNode *find_node(plist_t plist, plist_type type, void *value); 80plist_t find_node(plist_t plist, plist_type type, void *value);
83void get_type_and_value(GNode * node, plist_type * type, void *value); 81void get_type_and_value(plist_t node, plist_type * type, void *value);
84 82
85#endif 83#endif
diff --git a/src/xplist.c b/src/xplist.c
index a87b259..3e975f6 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -89,7 +89,7 @@ struct xml_node {
89 * 89 *
90 * @return The plist XML document. 90 * @return The plist XML document.
91 */ 91 */
92xmlDocPtr new_plist() 92xmlDocPtr new_xml_plist()
93{ 93{
94 char *plist = strdup(plist_base); 94 char *plist = strdup(plist_base);
95 xmlDocPtr plist_xml = xmlReadMemory(plist, strlen(plist), NULL, NULL, 0); 95 xmlDocPtr plist_xml = xmlReadMemory(plist, strlen(plist), NULL, NULL, 0);
@@ -207,7 +207,7 @@ void node_to_xml(GNode * node, gpointer xml_struct)
207 return; 207 return;
208} 208}
209 209
210void xml_to_node(xmlNodePtr xml_node, GNode * plist_node) 210void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
211{ 211{
212 xmlNodePtr node = NULL; 212 xmlNodePtr node = NULL;
213 213
@@ -220,7 +220,10 @@ void xml_to_node(xmlNodePtr xml_node, GNode * plist_node)
220 220
221 struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); 221 struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1);
222 GNode *subnode = g_node_new(data); 222 GNode *subnode = g_node_new(data);
223 g_node_append(plist_node, subnode); 223 if (*plist_node)
224 g_node_append(*plist_node, subnode);
225 else
226 *plist_node = subnode;
224 227
225 if (!xmlStrcmp(node->name, "true")) { 228 if (!xmlStrcmp(node->name, "true")) {
226 data->boolval = 1; 229 data->boolval = 1;
@@ -236,7 +239,7 @@ void xml_to_node(xmlNodePtr xml_node, GNode * plist_node)
236 239
237 if (!xmlStrcmp(node->name, "integer")) { 240 if (!xmlStrcmp(node->name, "integer")) {
238 char *strval = xmlNodeGetContent(node); 241 char *strval = xmlNodeGetContent(node);
239 data->intval = atoi(strval); 242 data->intval = g_ascii_strtoull(strval, NULL, 0);
240 data->type = PLIST_UINT; 243 data->type = PLIST_UINT;
241 continue; 244 continue;
242 } 245 }
@@ -271,13 +274,13 @@ void xml_to_node(xmlNodePtr xml_node, GNode * plist_node)
271 274
272 if (!xmlStrcmp(node->name, "array")) { 275 if (!xmlStrcmp(node->name, "array")) {
273 data->type = PLIST_ARRAY; 276 data->type = PLIST_ARRAY;
274 xml_to_node(node, subnode); 277 xml_to_node(node, &subnode);
275 continue; 278 continue;
276 } 279 }
277 280
278 if (!xmlStrcmp(node->name, "dict")) { 281 if (!xmlStrcmp(node->name, "dict")) {
279 data->type = PLIST_DICT; 282 data->type = PLIST_DICT;
280 xml_to_node(node, subnode); 283 xml_to_node(node, &subnode);
281 continue; 284 continue;
282 } 285 }
283 } 286 }
@@ -287,10 +290,12 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
287{ 290{
288 if (!plist || !plist_xml || *plist_xml) 291 if (!plist || !plist_xml || *plist_xml)
289 return; 292 return;
290 xmlDocPtr plist_doc = new_plist(); 293 xmlDocPtr plist_doc = new_xml_plist();
291 xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); 294 xmlNodePtr root_node = xmlDocGetRootElement(plist_doc);
292 struct xml_node root = { root_node, 0 }; 295 struct xml_node root = { root_node, 0 };
293 g_node_children_foreach(plist, G_TRAVERSE_ALL, node_to_xml, &root); 296
297 node_to_xml(plist, &root);
298
294 xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, length); 299 xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, length);
295} 300}
296 301
@@ -299,8 +304,5 @@ void xml_to_plist(const char *plist_xml, uint32_t length, plist_t * plist)
299 xmlDocPtr plist_doc = xmlReadMemory(plist_xml, length, NULL, NULL, 0); 304 xmlDocPtr plist_doc = xmlReadMemory(plist_xml, length, NULL, NULL, 0);
300 xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); 305 xmlNodePtr root_node = xmlDocGetRootElement(plist_doc);
301 306
302 struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); 307 xml_to_node(root_node, plist);
303 *plist = g_node_new(data);
304 data->type = PLIST_DICT;
305 xml_to_node(root_node, *plist);
306} 308}