diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bplist.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/bplist.c b/src/bplist.c index 29900e8..7ab9380 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -194,7 +194,7 @@ struct bplist_data { | |||
| 194 | const char* data; | 194 | const char* data; |
| 195 | uint64_t size; | 195 | uint64_t size; |
| 196 | uint64_t num_objects; | 196 | uint64_t num_objects; |
| 197 | uint8_t dict_size; | 197 | uint8_t ref_size; |
| 198 | uint8_t offset_size; | 198 | uint8_t offset_size; |
| 199 | const char* offset_table; | 199 | const char* offset_table; |
| 200 | uint32_t level; | 200 | uint32_t level; |
| @@ -400,19 +400,19 @@ static plist_t parse_dict_node(struct bplist_data *bplist, const char** bnode, u | |||
| 400 | plist_t node = node_create(NULL, data); | 400 | plist_t node = node_create(NULL, data); |
| 401 | 401 | ||
| 402 | for (j = 0; j < data->length; j++) { | 402 | for (j = 0; j < data->length; j++) { |
| 403 | str_i = j * bplist->dict_size; | 403 | str_i = j * bplist->ref_size; |
| 404 | str_j = (j + size) * bplist->dict_size; | 404 | str_j = (j + size) * bplist->ref_size; |
| 405 | index1_ptr = (*bnode) + str_i; | 405 | index1_ptr = (*bnode) + str_i; |
| 406 | index2_ptr = (*bnode) + str_j; | 406 | index2_ptr = (*bnode) + str_j; |
| 407 | 407 | ||
| 408 | if ((index1_ptr < bplist->data || index1_ptr + bplist->dict_size >= end_data) || | 408 | if ((index1_ptr < bplist->data || index1_ptr + bplist->ref_size >= end_data) || |
| 409 | (index2_ptr < bplist->data || index2_ptr + bplist->dict_size >= end_data)) { | 409 | (index2_ptr < bplist->data || index2_ptr + bplist->ref_size >= end_data)) { |
| 410 | plist_free(node); | 410 | plist_free(node); |
| 411 | return NULL; | 411 | return NULL; |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | index1 = UINT_TO_HOST(index1_ptr, bplist->dict_size); | 414 | index1 = UINT_TO_HOST(index1_ptr, bplist->ref_size); |
| 415 | index2 = UINT_TO_HOST(index2_ptr, bplist->dict_size); | 415 | index2 = UINT_TO_HOST(index2_ptr, bplist->ref_size); |
| 416 | 416 | ||
| 417 | if (index1 >= bplist->num_objects) { | 417 | if (index1 >= bplist->num_objects) { |
| 418 | plist_free(node); | 418 | plist_free(node); |
| @@ -474,8 +474,8 @@ static plist_t parse_array_node(struct bplist_data *bplist, const char** bnode, | |||
| 474 | plist_t node = node_create(NULL, data); | 474 | plist_t node = node_create(NULL, data); |
| 475 | 475 | ||
| 476 | for (j = 0; j < data->length; j++) { | 476 | for (j = 0; j < data->length; j++) { |
| 477 | str_j = j * bplist->dict_size; | 477 | str_j = j * bplist->ref_size; |
| 478 | index1 = UINT_TO_HOST((*bnode) + str_j, bplist->dict_size); | 478 | index1 = UINT_TO_HOST((*bnode) + str_j, bplist->ref_size); |
| 479 | 479 | ||
| 480 | if (index1 >= bplist->num_objects) { | 480 | if (index1 >= bplist->num_objects) { |
| 481 | plist_free(node); | 481 | plist_free(node); |
| @@ -743,7 +743,7 @@ PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * | |||
| 743 | bplist.data = plist_bin; | 743 | bplist.data = plist_bin; |
| 744 | bplist.size = length; | 744 | bplist.size = length; |
| 745 | bplist.num_objects = num_objects; | 745 | bplist.num_objects = num_objects; |
| 746 | bplist.dict_size = ref_size; | 746 | bplist.ref_size = ref_size; |
| 747 | bplist.offset_size = offset_size; | 747 | bplist.offset_size = offset_size; |
| 748 | bplist.offset_table = offset_table; | 748 | bplist.offset_table = offset_table; |
| 749 | bplist.level = 0; | 749 | bplist.level = 0; |
| @@ -950,7 +950,7 @@ static void write_unicode(bytearray_t * bplist, uint16_t * val, uint64_t size) | |||
| 950 | free(buff); | 950 | free(buff); |
| 951 | } | 951 | } |
| 952 | 952 | ||
| 953 | static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t dict_param_size) | 953 | static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) |
| 954 | { | 954 | { |
| 955 | uint64_t idx = 0; | 955 | uint64_t idx = 0; |
| 956 | uint8_t *buff = NULL; | 956 | uint8_t *buff = NULL; |
| @@ -969,25 +969,25 @@ static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_tab | |||
| 969 | byte_array_free(int_buff); | 969 | byte_array_free(int_buff); |
| 970 | } | 970 | } |
| 971 | 971 | ||
| 972 | buff = (uint8_t *) malloc(size * dict_param_size); | 972 | buff = (uint8_t *) malloc(size * ref_size); |
| 973 | 973 | ||
| 974 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(cur), i++) | 974 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(cur), i++) |
| 975 | { | 975 | { |
| 976 | idx = *(uint64_t *) (hash_table_lookup(ref_table, cur)); | 976 | idx = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
| 977 | #ifdef __BIG_ENDIAN__ | 977 | #ifdef __BIG_ENDIAN__ |
| 978 | idx = idx << ((sizeof(uint64_t) - dict_param_size) * 8); | 978 | idx = idx << ((sizeof(uint64_t) - ref_size) * 8); |
| 979 | #endif | 979 | #endif |
| 980 | memcpy(buff + i * dict_param_size, &idx, dict_param_size); | 980 | memcpy(buff + i * ref_size, &idx, ref_size); |
| 981 | byte_convert(buff + i * dict_param_size, dict_param_size); | 981 | byte_convert(buff + i * ref_size, ref_size); |
| 982 | } | 982 | } |
| 983 | 983 | ||
| 984 | //now append to bplist | 984 | //now append to bplist |
| 985 | byte_array_append(bplist, buff, size * dict_param_size); | 985 | byte_array_append(bplist, buff, size * ref_size); |
| 986 | free(buff); | 986 | free(buff); |
| 987 | 987 | ||
| 988 | } | 988 | } |
| 989 | 989 | ||
| 990 | static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t dict_param_size) | 990 | static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) |
| 991 | { | 991 | { |
| 992 | uint64_t idx1 = 0; | 992 | uint64_t idx1 = 0; |
| 993 | uint64_t idx2 = 0; | 993 | uint64_t idx2 = 0; |
| @@ -1007,26 +1007,26 @@ static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_tabl | |||
| 1007 | byte_array_free(int_buff); | 1007 | byte_array_free(int_buff); |
| 1008 | } | 1008 | } |
| 1009 | 1009 | ||
| 1010 | buff = (uint8_t *) malloc(size * 2 * dict_param_size); | 1010 | buff = (uint8_t *) malloc(size * 2 * ref_size); |
| 1011 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(node_next_sibling(cur)), i++) | 1011 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(node_next_sibling(cur)), i++) |
| 1012 | { | 1012 | { |
| 1013 | idx1 = *(uint64_t *) (hash_table_lookup(ref_table, cur)); | 1013 | idx1 = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
| 1014 | #ifdef __BIG_ENDIAN__ | 1014 | #ifdef __BIG_ENDIAN__ |
| 1015 | idx1 = idx1 << ((sizeof(uint64_t) - dict_param_size) * 8); | 1015 | idx1 = idx1 << ((sizeof(uint64_t) - ref_size) * 8); |
| 1016 | #endif | 1016 | #endif |
| 1017 | memcpy(buff + i * dict_param_size, &idx1, dict_param_size); | 1017 | memcpy(buff + i * ref_size, &idx1, ref_size); |
| 1018 | byte_convert(buff + i * dict_param_size, dict_param_size); | 1018 | byte_convert(buff + i * ref_size, ref_size); |
| 1019 | 1019 | ||
| 1020 | idx2 = *(uint64_t *) (hash_table_lookup(ref_table, cur->next)); | 1020 | idx2 = *(uint64_t *) (hash_table_lookup(ref_table, cur->next)); |
| 1021 | #ifdef __BIG_ENDIAN__ | 1021 | #ifdef __BIG_ENDIAN__ |
| 1022 | idx2 = idx2 << ((sizeof(uint64_t) - dict_param_size) * 8); | 1022 | idx2 = idx2 << ((sizeof(uint64_t) - ref_size) * 8); |
| 1023 | #endif | 1023 | #endif |
| 1024 | memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size); | 1024 | memcpy(buff + (i + size) * ref_size, &idx2, ref_size); |
| 1025 | byte_convert(buff + (i + size) * dict_param_size, dict_param_size); | 1025 | byte_convert(buff + (i + size) * ref_size, ref_size); |
| 1026 | } | 1026 | } |
| 1027 | 1027 | ||
| 1028 | //now append to bplist | 1028 | //now append to bplist |
| 1029 | byte_array_append(bplist, buff, size * 2 * dict_param_size); | 1029 | byte_array_append(bplist, buff, size * 2 * ref_size); |
| 1030 | free(buff); | 1030 | free(buff); |
| 1031 | 1031 | ||
| 1032 | } | 1032 | } |
| @@ -1125,7 +1125,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1125 | hashtable_t* ref_table = NULL; | 1125 | hashtable_t* ref_table = NULL; |
| 1126 | struct serialize_s ser_s; | 1126 | struct serialize_s ser_s; |
| 1127 | uint8_t offset_size = 0; | 1127 | uint8_t offset_size = 0; |
| 1128 | uint8_t dict_param_size = 0; | 1128 | uint8_t ref_size = 0; |
| 1129 | uint64_t num_objects = 0; | 1129 | uint64_t num_objects = 0; |
| 1130 | uint64_t root_object = 0; | 1130 | uint64_t root_object = 0; |
| 1131 | uint64_t offset_table_index = 0; | 1131 | uint64_t offset_table_index = 0; |
| @@ -1159,7 +1159,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1159 | //now stream to output buffer | 1159 | //now stream to output buffer |
| 1160 | offset_size = 0; //unknown yet | 1160 | offset_size = 0; //unknown yet |
| 1161 | objects_len = objects->len; | 1161 | objects_len = objects->len; |
| 1162 | dict_param_size = get_needed_bytes(objects_len); | 1162 | ref_size = get_needed_bytes(objects_len); |
| 1163 | num_objects = objects->len; | 1163 | num_objects = objects->len; |
| 1164 | root_object = 0; //root is first in list | 1164 | root_object = 0; //root is first in list |
| 1165 | offset_table_index = 0; //unknown yet | 1165 | offset_table_index = 0; //unknown yet |
| @@ -1217,10 +1217,10 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1217 | case PLIST_DATA: | 1217 | case PLIST_DATA: |
| 1218 | write_data(bplist_buff, data->buff, data->length); | 1218 | write_data(bplist_buff, data->buff, data->length); |
| 1219 | case PLIST_ARRAY: | 1219 | case PLIST_ARRAY: |
| 1220 | write_array(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size); | 1220 | write_array(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size); |
| 1221 | break; | 1221 | break; |
| 1222 | case PLIST_DICT: | 1222 | case PLIST_DICT: |
| 1223 | write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, dict_param_size); | 1223 | write_dict(bplist_buff, ptr_array_index(objects, i), ref_table, ref_size); |
| 1224 | break; | 1224 | break; |
| 1225 | case PLIST_DATE: | 1225 | case PLIST_DATE: |
| 1226 | write_date(bplist_buff, data->realval); | 1226 | write_date(bplist_buff, data->realval); |
| @@ -1258,7 +1258,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1258 | //setup trailer | 1258 | //setup trailer |
| 1259 | memset(trailer.unused, '\0', sizeof(trailer.unused)); | 1259 | memset(trailer.unused, '\0', sizeof(trailer.unused)); |
| 1260 | trailer.offset_size = offset_size; | 1260 | trailer.offset_size = offset_size; |
| 1261 | trailer.ref_size = dict_param_size; | 1261 | trailer.ref_size = ref_size; |
| 1262 | trailer.num_objects = be64toh(num_objects); | 1262 | trailer.num_objects = be64toh(num_objects); |
| 1263 | trailer.root_object_index = be64toh(root_object); | 1263 | trailer.root_object_index = be64toh(root_object); |
| 1264 | trailer.offset_table_offset = be64toh(offset_table_index); | 1264 | trailer.offset_table_offset = be64toh(offset_table_index); |
