diff options
| author | 2017-01-28 04:46:37 +0100 | |
|---|---|---|
| committer | 2017-01-28 04:46:37 +0100 | |
| commit | b937059c4dfb1f966cd835d456e91a625d27cf49 (patch) | |
| tree | 74653ad3d3597c8b85f2c8e784cb476d2acb2fdf /src | |
| parent | 962d4064b690af1c479f7676b3e36f08eaa593c6 (diff) | |
| download | libplist-b937059c4dfb1f966cd835d456e91a625d27cf49.tar.gz libplist-b937059c4dfb1f966cd835d456e91a625d27cf49.tar.bz2 | |
bplist: Improve writing of UID nodes
Diffstat (limited to 'src')
| -rw-r--r-- | src/bplist.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/bplist.c b/src/bplist.c index ed3c0b9..94b0793 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -1009,22 +1009,16 @@ static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_tabl | |||
| 1009 | static void write_uid(bytearray_t * bplist, uint64_t val) | 1009 | static void write_uid(bytearray_t * bplist, uint64_t val) |
| 1010 | { | 1010 | { |
| 1011 | val = (uint32_t)val; | 1011 | val = (uint32_t)val; |
| 1012 | uint64_t size = get_needed_bytes(val); | 1012 | int size = get_needed_bytes(val); |
| 1013 | uint8_t *buff = NULL; | 1013 | uint8_t sz; |
| 1014 | //do not write 3bytes int node | 1014 | //do not write 3bytes int node |
| 1015 | if (size == 3) | 1015 | if (size == 3) |
| 1016 | size++; | 1016 | size++; |
| 1017 | sz = BPLIST_UID | (size-1); // yes, this is what Apple does... | ||
| 1017 | 1018 | ||
| 1018 | #ifdef __BIG_ENDIAN__ | 1019 | val = be64toh(val); |
| 1019 | val = val << ((sizeof(uint64_t) - size) * 8); | 1020 | byte_array_append(bplist, &sz, 1); |
| 1020 | #endif | 1021 | byte_array_append(bplist, (uint8_t*)&val + (8-size), size); |
| 1021 | |||
| 1022 | buff = (uint8_t *) malloc(sizeof(uint8_t) + size); | ||
| 1023 | buff[0] = BPLIST_UID | (size-1); // yes, this is what Apple does... | ||
| 1024 | memcpy(buff + 1, &val, size); | ||
| 1025 | byte_convert(buff + 1, size); | ||
| 1026 | byte_array_append(bplist, buff, sizeof(uint8_t) + size); | ||
| 1027 | free(buff); | ||
| 1028 | } | 1022 | } |
| 1029 | 1023 | ||
| 1030 | static int is_ascii_string(char* s, int len) | 1024 | static int is_ascii_string(char* s, int len) |
