8 static inline uint8_t
uint8le(
unsigned char *data) {
return data[0]; }
9 static inline uint16_t
uint16le(
unsigned char *data) {
return data[0] | data[1] << 8; }
10 static inline uint32_t
uint32le(
unsigned char *data) {
return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; }
14 unsigned char header_data[7];
15 size_t read =
ar_read(ar->
stream, header_data,
sizeof(header_data));
20 if (read <
sizeof(header_data))
30 unsigned char size_data[4];
32 log(
"File header without LHD_LONG_BLOCK set");
34 if (read <
sizeof(header_data) +
sizeof(size_data))
39 if (header->
size < read) {
40 warn(
"Invalid header size %d", header->
size);
49 unsigned char buffer[256];
68 crc32 =
ar_crc32(crc32, buffer,
smin(size,
sizeof(buffer)));
69 size -= (uint16_t)
smin(size,
sizeof(buffer));
71 return (crc32 & 0xFFFF) == crc16;
76 unsigned char data[21];
89 unsigned char more_data[8];
98 log(
"Skipping LHD_SALT");
116 #define Check(cond) if (!(cond)) { free(str); return NULL; } else ((void)0)
118 uint8_t highbyte, flagbyte, flagbits,
size, length, i;
119 const uint8_t *in = (uint8_t *)data + strlen(data) + 1;
120 const uint8_t *end_in = (uint8_t *)data + len;
121 char *str = calloc(len + 1, 3);
123 char *end_out = str + len * 3;
127 if (end_in - in <= 1) {
137 while (in < end_in && out < end_out) {
143 switch ((flagbyte >> flagbits) & 3) {
145 Check(in + 1 <= end_in);
150 Check(in + 1 <= end_in);
155 Check(in + 2 <= end_in);
161 Check(in + 1 <= end_in);
163 if ((length & 0x80)) {
164 uint8_t correction = *in++;
165 for (i = 0; i < (length & 0x7F) + 2; i++) {
167 out +=
ar_conv_rune_to_utf8(((uint16_t)highbyte << 8) | (data[size] + (correction & 0xFF)), out, end_out - out);
172 for (i = 0; i < (length & 0x7F) + 2; i++) {
191 unsigned char data[21];
206 name = malloc(namelen + 1);
207 if (!name ||
ar_read(ar->
stream, name, namelen) != namelen) {
211 name[namelen] =
'\0';
217 else if (namelen == strlen(name)) {
227 while ((p =
strchr(p,
'\\')) != NULL) {
233 warn(
"Couldn't seek back to the end of the entry header");