Line | Count | Source |
1 | | /* |
2 | | * This file is auto-generated, do not modify! |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include <glib.h> |
10 | | |
11 | | #include "fu-zip-struct.h" |
12 | | #include "fu-byte-array.h" |
13 | | #include "fu-bytes.h" |
14 | | #include "fu-mem-private.h" |
15 | | #include "fu-string.h" |
16 | | |
17 | | #ifdef G_LOG_DOMAIN |
18 | | #undef G_LOG_DOMAIN |
19 | | #endif |
20 | 0 | #define G_LOG_DOMAIN "FuStruct" |
21 | | |
22 | | /** |
23 | | * fu_zip_compression_to_string: |
24 | | * @val: value, e.g. %FU_ZIP_COMPRESSION_SHRUNK |
25 | | * |
26 | | * Converts an enumerated value to a string. |
27 | | * |
28 | | * Returns: identifier string |
29 | | **/ |
30 | | const gchar * |
31 | | fu_zip_compression_to_string(FuZipCompression val) |
32 | 54 | { |
33 | 54 | if (val == FU_ZIP_COMPRESSION_NONE) |
34 | 0 | return "none"; |
35 | 54 | if (val == FU_ZIP_COMPRESSION_SHRUNK) |
36 | 1 | return "shrunk"; |
37 | 53 | if (val == FU_ZIP_COMPRESSION_IMPLODE) |
38 | 1 | return "implode"; |
39 | 52 | if (val == FU_ZIP_COMPRESSION_TOKENIZE) |
40 | 1 | return "tokenize"; |
41 | 51 | if (val == FU_ZIP_COMPRESSION_DEFLATE) |
42 | 0 | return "deflate"; |
43 | 51 | if (val == FU_ZIP_COMPRESSION_DEFLATE64) |
44 | 1 | return "deflate64"; |
45 | 50 | if (val == FU_ZIP_COMPRESSION_BZIP2) |
46 | 1 | return "bzip2"; |
47 | 49 | if (val == FU_ZIP_COMPRESSION_LZMA) |
48 | 1 | return "lzma"; |
49 | 48 | if (val == FU_ZIP_COMPRESSION_TERSE) |
50 | 1 | return "terse"; |
51 | 47 | if (val == FU_ZIP_COMPRESSION_ZSTANDARD) |
52 | 1 | return "zstandard"; |
53 | 46 | if (val == FU_ZIP_COMPRESSION_XZ) |
54 | 1 | return "xz"; |
55 | 45 | return NULL; |
56 | 46 | } |
57 | | /** |
58 | | * fu_zip_compression_from_string: |
59 | | * @val: (nullable): a string, e.g. `shrunk` |
60 | | * |
61 | | * Converts a string to an enumerated value. |
62 | | * |
63 | | * Returns: enumerated value |
64 | | **/ |
65 | | FuZipCompression |
66 | | fu_zip_compression_from_string(const gchar *val) |
67 | 0 | { |
68 | 0 | if (g_strcmp0(val, "none") == 0) |
69 | 0 | return FU_ZIP_COMPRESSION_NONE; |
70 | 0 | if (g_strcmp0(val, "shrunk") == 0) |
71 | 0 | return FU_ZIP_COMPRESSION_SHRUNK; |
72 | 0 | if (g_strcmp0(val, "implode") == 0) |
73 | 0 | return FU_ZIP_COMPRESSION_IMPLODE; |
74 | 0 | if (g_strcmp0(val, "tokenize") == 0) |
75 | 0 | return FU_ZIP_COMPRESSION_TOKENIZE; |
76 | 0 | if (g_strcmp0(val, "deflate") == 0) |
77 | 0 | return FU_ZIP_COMPRESSION_DEFLATE; |
78 | 0 | if (g_strcmp0(val, "deflate64") == 0) |
79 | 0 | return FU_ZIP_COMPRESSION_DEFLATE64; |
80 | 0 | if (g_strcmp0(val, "bzip2") == 0) |
81 | 0 | return FU_ZIP_COMPRESSION_BZIP2; |
82 | 0 | if (g_strcmp0(val, "lzma") == 0) |
83 | 0 | return FU_ZIP_COMPRESSION_LZMA; |
84 | 0 | if (g_strcmp0(val, "terse") == 0) |
85 | 0 | return FU_ZIP_COMPRESSION_TERSE; |
86 | 0 | if (g_strcmp0(val, "zstandard") == 0) |
87 | 0 | return FU_ZIP_COMPRESSION_ZSTANDARD; |
88 | 0 | if (g_strcmp0(val, "xz") == 0) |
89 | 0 | return FU_ZIP_COMPRESSION_XZ; |
90 | 0 | return FU_ZIP_COMPRESSION_NONE; |
91 | 0 | } |
92 | | |
93 | | /** |
94 | | * fu_zip_flags_to_string: |
95 | | * @val: value, e.g. %FU_ZIP_FLAG_ENCRYPTED |
96 | | * |
97 | | * Converts an enumerated value to a string. |
98 | | * |
99 | | * Returns: identifier string |
100 | | * |
101 | | **/ |
102 | | static gchar * |
103 | | fu_zip_flags_to_string(FuZipFlags val) |
104 | 0 | { |
105 | 0 | const gchar *data[6] = {0}; |
106 | 0 | guint idx = 0; |
107 | 0 | if (val == FU_ZIP_FLAG_NONE) |
108 | 0 | return g_strdup("none"); |
109 | 0 | if (val & FU_ZIP_FLAG_ENCRYPTED) |
110 | 0 | data[idx++] = "encrypted"; |
111 | 0 | if (val & FU_ZIP_FLAG_DEFLATE_HI) |
112 | 0 | data[idx++] = "deflate-hi"; |
113 | 0 | if (val & FU_ZIP_FLAG_DEFLATE_LO) |
114 | 0 | data[idx++] = "deflate-lo"; |
115 | 0 | if (val & FU_ZIP_FLAG_DATA_DESCRIPTOR) |
116 | 0 | data[idx++] = "data-descriptor"; |
117 | 0 | if (val & FU_ZIP_FLAG_COMPRESSED_PATCHED) |
118 | 0 | data[idx++] = "compressed-patched"; |
119 | 0 | return g_strjoinv(",", (gchar **)data); |
120 | 0 | } |
121 | | |
122 | | /** |
123 | | * fu_zip_extra_header_id_to_string: |
124 | | * @val: value, e.g. %FU_ZIP_EXTRA_HEADER_ID_EXTENDED_TIMESTAMP |
125 | | * |
126 | | * Converts an enumerated value to a string. |
127 | | * |
128 | | * Returns: identifier string |
129 | | **/ |
130 | | static const gchar * |
131 | | fu_zip_extra_header_id_to_string(FuZipExtraHeaderId val) |
132 | 0 | { |
133 | 0 | if (val == FU_ZIP_EXTRA_HEADER_ID_NONE) |
134 | 0 | return "none"; |
135 | 0 | if (val == FU_ZIP_EXTRA_HEADER_ID_EXTENDED_TIMESTAMP) |
136 | 0 | return "extended-timestamp"; |
137 | 0 | if (val == FU_ZIP_EXTRA_HEADER_ID_INFO_ZIP_UNIX) |
138 | 0 | return "info-zip-unix"; |
139 | 0 | if (val == FU_ZIP_EXTRA_HEADER_ID_INFO_ZIP_UNIX_UID_GID) |
140 | 0 | return "info-zip-unix-uid-gid"; |
141 | 0 | return NULL; |
142 | 0 | } |
143 | | /** |
144 | | * fu_struct_zip_extra_hdr_ref: (skip): |
145 | | **/ |
146 | | FuStructZipExtraHdr * |
147 | | fu_struct_zip_extra_hdr_ref(FuStructZipExtraHdr *st) |
148 | 0 | { |
149 | 0 | g_return_val_if_fail(st != NULL, NULL); |
150 | 0 | st->refcount++; |
151 | 0 | return st; |
152 | 0 | } |
153 | | /** |
154 | | * fu_struct_zip_extra_hdr_unref: (skip): |
155 | | **/ |
156 | | void |
157 | | fu_struct_zip_extra_hdr_unref(FuStructZipExtraHdr *st) |
158 | 31.5k | { |
159 | 31.5k | g_return_if_fail(st != NULL); |
160 | 31.5k | if (st->refcount == 0) { |
161 | 0 | g_critical("FuStructZipExtraHdr refcount already zero"); |
162 | 0 | return; |
163 | 0 | } |
164 | 31.5k | if (--st->refcount > 0) |
165 | 0 | return; |
166 | 31.5k | if (st->buf != NULL) |
167 | 31.4k | g_byte_array_unref(st->buf); |
168 | 31.5k | g_free(st); |
169 | 31.5k | } |
170 | | /** |
171 | | * fu_struct_zip_extra_hdr_new_internal: (skip): |
172 | | **/ |
173 | | static FuStructZipExtraHdr * |
174 | | fu_struct_zip_extra_hdr_new_internal(void) |
175 | 31.5k | { |
176 | 31.5k | FuStructZipExtraHdr *st = g_new0(FuStructZipExtraHdr, 1); |
177 | 31.5k | st->refcount = 1; |
178 | 31.5k | return st; |
179 | 31.5k | } |
180 | | |
181 | | /* getters */ |
182 | | /** |
183 | | * fu_struct_zip_extra_hdr_get_header_id: (skip): |
184 | | **/ |
185 | | FuZipExtraHeaderId |
186 | | fu_struct_zip_extra_hdr_get_header_id(const FuStructZipExtraHdr *st) |
187 | 0 | { |
188 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
189 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
190 | 0 | } |
191 | | /** |
192 | | * fu_struct_zip_extra_hdr_get_datasz: (skip): |
193 | | **/ |
194 | | guint16 |
195 | | fu_struct_zip_extra_hdr_get_datasz(const FuStructZipExtraHdr *st) |
196 | 31.4k | { |
197 | 31.4k | g_return_val_if_fail(st != NULL, 0x0); |
198 | 31.4k | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
199 | 31.4k | } |
200 | | |
201 | | /* setters */ |
202 | | /** |
203 | | * fu_struct_zip_extra_hdr_set_header_id: (skip): |
204 | | **/ |
205 | | void |
206 | | fu_struct_zip_extra_hdr_set_header_id(FuStructZipExtraHdr *st, FuZipExtraHeaderId value) |
207 | 0 | { |
208 | 0 | g_return_if_fail(st != NULL); |
209 | 0 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
210 | 0 | } |
211 | | /** |
212 | | * fu_struct_zip_extra_hdr_set_datasz: (skip): |
213 | | **/ |
214 | | void |
215 | | fu_struct_zip_extra_hdr_set_datasz(FuStructZipExtraHdr *st, guint16 value) |
216 | 0 | { |
217 | 0 | g_return_if_fail(st != NULL); |
218 | 0 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
219 | 0 | } |
220 | | /** |
221 | | * fu_struct_zip_extra_hdr_new: (skip): |
222 | | **/ |
223 | | FuStructZipExtraHdr * |
224 | | fu_struct_zip_extra_hdr_new(void) |
225 | 0 | { |
226 | 0 | FuStructZipExtraHdr *st = fu_struct_zip_extra_hdr_new_internal(); |
227 | 0 | st->buf = g_byte_array_sized_new(4); |
228 | 0 | fu_byte_array_set_size(st->buf, 4, 0x0); |
229 | 0 | return st; |
230 | 0 | } |
231 | | /** |
232 | | * fu_struct_zip_extra_hdr_to_string: (skip): |
233 | | **/ |
234 | | static gchar * |
235 | | fu_struct_zip_extra_hdr_to_string(const FuStructZipExtraHdr *st) |
236 | 0 | { |
237 | 0 | g_autoptr(GString) str = g_string_new("FuStructZipExtraHdr:\n"); |
238 | 0 | g_return_val_if_fail(st != NULL, NULL); |
239 | 0 | { |
240 | 0 | const gchar *tmp = fu_zip_extra_header_id_to_string(fu_struct_zip_extra_hdr_get_header_id(st)); |
241 | 0 | if (tmp != NULL) { |
242 | 0 | g_string_append_printf(str, " header_id: 0x%x [%s]\n", (guint) fu_struct_zip_extra_hdr_get_header_id(st), tmp); |
243 | 0 | } else { |
244 | 0 | g_string_append_printf(str, " header_id: 0x%x\n", (guint) fu_struct_zip_extra_hdr_get_header_id(st)); |
245 | 0 | } |
246 | 0 | } |
247 | 0 | g_string_append_printf(str, " datasz: 0x%x\n", |
248 | 0 | (guint) fu_struct_zip_extra_hdr_get_datasz(st)); |
249 | 0 | if (str->len > 0) |
250 | 0 | g_string_set_size(str, str->len - 1); |
251 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
252 | 0 | } |
253 | | static gboolean |
254 | | fu_struct_zip_extra_hdr_parse_internal(FuStructZipExtraHdr *st, GError **error) |
255 | 31.4k | { |
256 | 31.4k | if (g_log_get_debug_enabled()) { |
257 | 0 | g_autofree gchar *str = fu_struct_zip_extra_hdr_to_string(st); |
258 | 0 | g_debug("%s", str); |
259 | 0 | } |
260 | 31.4k | return TRUE; |
261 | 31.4k | } |
262 | | /** |
263 | | * fu_struct_zip_extra_hdr_parse_stream: (skip): |
264 | | **/ |
265 | | FuStructZipExtraHdr * |
266 | | fu_struct_zip_extra_hdr_parse_stream(GInputStream *stream, gsize offset, GError **error) |
267 | 31.5k | { |
268 | 31.5k | g_autoptr(FuStructZipExtraHdr) st = fu_struct_zip_extra_hdr_new_internal(); |
269 | 31.5k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
270 | 31.5k | if (st->buf == NULL) { |
271 | 99 | g_prefix_error(error, "FuStructZipExtraHdr failed read of 0x%x: ", (guint) 4); |
272 | 99 | return NULL; |
273 | 99 | } |
274 | 31.4k | if (st->buf->len != 4) { |
275 | 40 | g_set_error(error, |
276 | 40 | FWUPD_ERROR, |
277 | 40 | FWUPD_ERROR_INVALID_DATA, |
278 | 40 | "FuStructZipExtraHdr requested 0x%x and got 0x%x", |
279 | 40 | (guint) 4, |
280 | 40 | (guint) st->buf->len); |
281 | 40 | return NULL; |
282 | 40 | } |
283 | 31.4k | if (!fu_struct_zip_extra_hdr_parse_internal(st, error)) |
284 | 0 | return NULL; |
285 | 31.4k | return g_steal_pointer(&st); |
286 | 31.4k | } |
287 | | /** |
288 | | * fu_struct_zip_cdfh_ref: (skip): |
289 | | **/ |
290 | | FuStructZipCdfh * |
291 | | fu_struct_zip_cdfh_ref(FuStructZipCdfh *st) |
292 | 0 | { |
293 | 0 | g_return_val_if_fail(st != NULL, NULL); |
294 | 0 | st->refcount++; |
295 | 0 | return st; |
296 | 0 | } |
297 | | /** |
298 | | * fu_struct_zip_cdfh_unref: (skip): |
299 | | **/ |
300 | | void |
301 | | fu_struct_zip_cdfh_unref(FuStructZipCdfh *st) |
302 | 15.1k | { |
303 | 15.1k | g_return_if_fail(st != NULL); |
304 | 15.1k | if (st->refcount == 0) { |
305 | 0 | g_critical("FuStructZipCdfh refcount already zero"); |
306 | 0 | return; |
307 | 0 | } |
308 | 15.1k | if (--st->refcount > 0) |
309 | 0 | return; |
310 | 15.1k | if (st->buf != NULL) |
311 | 15.0k | g_byte_array_unref(st->buf); |
312 | 15.1k | g_free(st); |
313 | 15.1k | } |
314 | | /** |
315 | | * fu_struct_zip_cdfh_new_internal: (skip): |
316 | | **/ |
317 | | static FuStructZipCdfh * |
318 | | fu_struct_zip_cdfh_new_internal(void) |
319 | 15.1k | { |
320 | 15.1k | FuStructZipCdfh *st = g_new0(FuStructZipCdfh, 1); |
321 | 15.1k | st->refcount = 1; |
322 | 15.1k | return st; |
323 | 15.1k | } |
324 | | |
325 | | /* getters */ |
326 | | /** |
327 | | * fu_struct_zip_cdfh_get_magic: (skip): |
328 | | **/ |
329 | | static gchar * |
330 | | fu_struct_zip_cdfh_get_magic(const FuStructZipCdfh *st) |
331 | 48 | { |
332 | 48 | g_return_val_if_fail(st != NULL, NULL); |
333 | 48 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
334 | 48 | } |
335 | | /** |
336 | | * fu_struct_zip_cdfh_get_version_generated: (skip): |
337 | | **/ |
338 | | guint16 |
339 | | fu_struct_zip_cdfh_get_version_generated(const FuStructZipCdfh *st) |
340 | 0 | { |
341 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
342 | 0 | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
343 | 0 | } |
344 | | /** |
345 | | * fu_struct_zip_cdfh_get_version_extract: (skip): |
346 | | **/ |
347 | | guint16 |
348 | | fu_struct_zip_cdfh_get_version_extract(const FuStructZipCdfh *st) |
349 | 0 | { |
350 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
351 | 0 | return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN); |
352 | 0 | } |
353 | | /** |
354 | | * fu_struct_zip_cdfh_get_flags: (skip): |
355 | | **/ |
356 | | FuZipFlags |
357 | | fu_struct_zip_cdfh_get_flags(const FuStructZipCdfh *st) |
358 | 13.7k | { |
359 | 13.7k | g_return_val_if_fail(st != NULL, 0x0); |
360 | 13.7k | return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN); |
361 | 13.7k | } |
362 | | /** |
363 | | * fu_struct_zip_cdfh_get_compression: (skip): |
364 | | **/ |
365 | | FuZipCompression |
366 | | fu_struct_zip_cdfh_get_compression(const FuStructZipCdfh *st) |
367 | 0 | { |
368 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
369 | 0 | return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN); |
370 | 0 | } |
371 | | /** |
372 | | * fu_struct_zip_cdfh_get_file_time: (skip): |
373 | | **/ |
374 | | guint16 |
375 | | fu_struct_zip_cdfh_get_file_time(const FuStructZipCdfh *st) |
376 | 0 | { |
377 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
378 | 0 | return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN); |
379 | 0 | } |
380 | | /** |
381 | | * fu_struct_zip_cdfh_get_file_date: (skip): |
382 | | **/ |
383 | | guint16 |
384 | | fu_struct_zip_cdfh_get_file_date(const FuStructZipCdfh *st) |
385 | 0 | { |
386 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
387 | 0 | return fu_memread_uint16(st->buf->data + 14, G_LITTLE_ENDIAN); |
388 | 0 | } |
389 | | /** |
390 | | * fu_struct_zip_cdfh_get_uncompressed_crc: (skip): |
391 | | **/ |
392 | | guint32 |
393 | | fu_struct_zip_cdfh_get_uncompressed_crc(const FuStructZipCdfh *st) |
394 | 4.07k | { |
395 | 4.07k | g_return_val_if_fail(st != NULL, 0x0); |
396 | 4.07k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
397 | 4.07k | } |
398 | | /** |
399 | | * fu_struct_zip_cdfh_get_compressed_size: (skip): |
400 | | **/ |
401 | | guint32 |
402 | | fu_struct_zip_cdfh_get_compressed_size(const FuStructZipCdfh *st) |
403 | 13.3k | { |
404 | 13.3k | g_return_val_if_fail(st != NULL, 0x0); |
405 | 13.3k | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
406 | 13.3k | } |
407 | | /** |
408 | | * fu_struct_zip_cdfh_get_uncompressed_size: (skip): |
409 | | **/ |
410 | | guint32 |
411 | | fu_struct_zip_cdfh_get_uncompressed_size(const FuStructZipCdfh *st) |
412 | 13.2k | { |
413 | 13.2k | g_return_val_if_fail(st != NULL, 0x0); |
414 | 13.2k | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
415 | 13.2k | } |
416 | | /** |
417 | | * fu_struct_zip_cdfh_get_filename_size: (skip): |
418 | | **/ |
419 | | guint16 |
420 | | fu_struct_zip_cdfh_get_filename_size(const FuStructZipCdfh *st) |
421 | 12.5k | { |
422 | 12.5k | g_return_val_if_fail(st != NULL, 0x0); |
423 | 12.5k | return fu_memread_uint16(st->buf->data + 28, G_LITTLE_ENDIAN); |
424 | 12.5k | } |
425 | | /** |
426 | | * fu_struct_zip_cdfh_get_extra_size: (skip): |
427 | | **/ |
428 | | guint16 |
429 | | fu_struct_zip_cdfh_get_extra_size(const FuStructZipCdfh *st) |
430 | 25.0k | { |
431 | 25.0k | g_return_val_if_fail(st != NULL, 0x0); |
432 | 25.0k | return fu_memread_uint16(st->buf->data + 30, G_LITTLE_ENDIAN); |
433 | 25.0k | } |
434 | | /** |
435 | | * fu_struct_zip_cdfh_get_comment_size: (skip): |
436 | | **/ |
437 | | guint16 |
438 | | fu_struct_zip_cdfh_get_comment_size(const FuStructZipCdfh *st) |
439 | 12.5k | { |
440 | 12.5k | g_return_val_if_fail(st != NULL, 0x0); |
441 | 12.5k | return fu_memread_uint16(st->buf->data + 32, G_LITTLE_ENDIAN); |
442 | 12.5k | } |
443 | | /** |
444 | | * fu_struct_zip_cdfh_get_disk_number: (skip): |
445 | | **/ |
446 | | guint16 |
447 | | fu_struct_zip_cdfh_get_disk_number(const FuStructZipCdfh *st) |
448 | 0 | { |
449 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
450 | 0 | return fu_memread_uint16(st->buf->data + 34, G_LITTLE_ENDIAN); |
451 | 0 | } |
452 | | /** |
453 | | * fu_struct_zip_cdfh_get_internal_attrs: (skip): |
454 | | **/ |
455 | | guint16 |
456 | | fu_struct_zip_cdfh_get_internal_attrs(const FuStructZipCdfh *st) |
457 | 0 | { |
458 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
459 | 0 | return fu_memread_uint16(st->buf->data + 36, G_LITTLE_ENDIAN); |
460 | 0 | } |
461 | | /** |
462 | | * fu_struct_zip_cdfh_get_external_attrs: (skip): |
463 | | **/ |
464 | | guint32 |
465 | | fu_struct_zip_cdfh_get_external_attrs(const FuStructZipCdfh *st) |
466 | 0 | { |
467 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
468 | 0 | return fu_memread_uint32(st->buf->data + 38, G_LITTLE_ENDIAN); |
469 | 0 | } |
470 | | /** |
471 | | * fu_struct_zip_cdfh_get_offset_lfh: (skip): |
472 | | **/ |
473 | | guint32 |
474 | | fu_struct_zip_cdfh_get_offset_lfh(const FuStructZipCdfh *st) |
475 | 13.7k | { |
476 | 13.7k | g_return_val_if_fail(st != NULL, 0x0); |
477 | 13.7k | return fu_memread_uint32(st->buf->data + 42, G_LITTLE_ENDIAN); |
478 | 13.7k | } |
479 | | |
480 | | /* setters */ |
481 | | /** |
482 | | * fu_struct_zip_cdfh_set_magic: (skip): |
483 | | **/ |
484 | | static gboolean |
485 | | fu_struct_zip_cdfh_set_magic(FuStructZipCdfh *st, const gchar *value, GError **error) |
486 | 1.18k | { |
487 | 1.18k | gsize len; |
488 | 1.18k | g_return_val_if_fail(st != NULL, FALSE); |
489 | 1.18k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
490 | 1.18k | if (value == NULL) { |
491 | 0 | memset(st->buf->data + 0, 0x0, 4); |
492 | 0 | return TRUE; |
493 | 0 | } |
494 | 1.18k | len = strlen(value); |
495 | 1.18k | if (len > 4) { |
496 | 0 | g_set_error(error, |
497 | 0 | FWUPD_ERROR, |
498 | 0 | FWUPD_ERROR_INVALID_DATA, |
499 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructZipCdfh.magic (0x%x bytes)", |
500 | 0 | value, (guint) len, (guint) 4); |
501 | 0 | return FALSE; |
502 | 0 | } |
503 | 1.18k | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
504 | 1.18k | } |
505 | | /** |
506 | | * fu_struct_zip_cdfh_set_version_generated: (skip): |
507 | | **/ |
508 | | void |
509 | | fu_struct_zip_cdfh_set_version_generated(FuStructZipCdfh *st, guint16 value) |
510 | 1.18k | { |
511 | 1.18k | g_return_if_fail(st != NULL); |
512 | 1.18k | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
513 | 1.18k | } |
514 | | /** |
515 | | * fu_struct_zip_cdfh_set_version_extract: (skip): |
516 | | **/ |
517 | | void |
518 | | fu_struct_zip_cdfh_set_version_extract(FuStructZipCdfh *st, guint16 value) |
519 | 1.18k | { |
520 | 1.18k | g_return_if_fail(st != NULL); |
521 | 1.18k | fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN); |
522 | 1.18k | } |
523 | | /** |
524 | | * fu_struct_zip_cdfh_set_flags: (skip): |
525 | | **/ |
526 | | void |
527 | | fu_struct_zip_cdfh_set_flags(FuStructZipCdfh *st, FuZipFlags value) |
528 | 0 | { |
529 | 0 | g_return_if_fail(st != NULL); |
530 | 0 | fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
531 | 0 | } |
532 | | /** |
533 | | * fu_struct_zip_cdfh_set_compression: (skip): |
534 | | **/ |
535 | | void |
536 | | fu_struct_zip_cdfh_set_compression(FuStructZipCdfh *st, FuZipCompression value) |
537 | 1.18k | { |
538 | 1.18k | g_return_if_fail(st != NULL); |
539 | 1.18k | fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN); |
540 | 1.18k | } |
541 | | /** |
542 | | * fu_struct_zip_cdfh_set_file_time: (skip): |
543 | | **/ |
544 | | void |
545 | | fu_struct_zip_cdfh_set_file_time(FuStructZipCdfh *st, guint16 value) |
546 | 0 | { |
547 | 0 | g_return_if_fail(st != NULL); |
548 | 0 | fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
549 | 0 | } |
550 | | /** |
551 | | * fu_struct_zip_cdfh_set_file_date: (skip): |
552 | | **/ |
553 | | void |
554 | | fu_struct_zip_cdfh_set_file_date(FuStructZipCdfh *st, guint16 value) |
555 | 0 | { |
556 | 0 | g_return_if_fail(st != NULL); |
557 | 0 | fu_memwrite_uint16(st->buf->data + 14, value, G_LITTLE_ENDIAN); |
558 | 0 | } |
559 | | /** |
560 | | * fu_struct_zip_cdfh_set_uncompressed_crc: (skip): |
561 | | **/ |
562 | | void |
563 | | fu_struct_zip_cdfh_set_uncompressed_crc(FuStructZipCdfh *st, guint32 value) |
564 | 1.18k | { |
565 | 1.18k | g_return_if_fail(st != NULL); |
566 | 1.18k | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
567 | 1.18k | } |
568 | | /** |
569 | | * fu_struct_zip_cdfh_set_compressed_size: (skip): |
570 | | **/ |
571 | | void |
572 | | fu_struct_zip_cdfh_set_compressed_size(FuStructZipCdfh *st, guint32 value) |
573 | 1.18k | { |
574 | 1.18k | g_return_if_fail(st != NULL); |
575 | 1.18k | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
576 | 1.18k | } |
577 | | /** |
578 | | * fu_struct_zip_cdfh_set_uncompressed_size: (skip): |
579 | | **/ |
580 | | void |
581 | | fu_struct_zip_cdfh_set_uncompressed_size(FuStructZipCdfh *st, guint32 value) |
582 | 1.18k | { |
583 | 1.18k | g_return_if_fail(st != NULL); |
584 | 1.18k | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
585 | 1.18k | } |
586 | | /** |
587 | | * fu_struct_zip_cdfh_set_filename_size: (skip): |
588 | | **/ |
589 | | void |
590 | | fu_struct_zip_cdfh_set_filename_size(FuStructZipCdfh *st, guint16 value) |
591 | 1.18k | { |
592 | 1.18k | g_return_if_fail(st != NULL); |
593 | 1.18k | fu_memwrite_uint16(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
594 | 1.18k | } |
595 | | /** |
596 | | * fu_struct_zip_cdfh_set_extra_size: (skip): |
597 | | **/ |
598 | | void |
599 | | fu_struct_zip_cdfh_set_extra_size(FuStructZipCdfh *st, guint16 value) |
600 | 0 | { |
601 | 0 | g_return_if_fail(st != NULL); |
602 | 0 | fu_memwrite_uint16(st->buf->data + 30, value, G_LITTLE_ENDIAN); |
603 | 0 | } |
604 | | /** |
605 | | * fu_struct_zip_cdfh_set_comment_size: (skip): |
606 | | **/ |
607 | | void |
608 | | fu_struct_zip_cdfh_set_comment_size(FuStructZipCdfh *st, guint16 value) |
609 | 0 | { |
610 | 0 | g_return_if_fail(st != NULL); |
611 | 0 | fu_memwrite_uint16(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
612 | 0 | } |
613 | | /** |
614 | | * fu_struct_zip_cdfh_set_disk_number: (skip): |
615 | | **/ |
616 | | void |
617 | | fu_struct_zip_cdfh_set_disk_number(FuStructZipCdfh *st, guint16 value) |
618 | 0 | { |
619 | 0 | g_return_if_fail(st != NULL); |
620 | 0 | fu_memwrite_uint16(st->buf->data + 34, value, G_LITTLE_ENDIAN); |
621 | 0 | } |
622 | | /** |
623 | | * fu_struct_zip_cdfh_set_internal_attrs: (skip): |
624 | | **/ |
625 | | void |
626 | | fu_struct_zip_cdfh_set_internal_attrs(FuStructZipCdfh *st, guint16 value) |
627 | 0 | { |
628 | 0 | g_return_if_fail(st != NULL); |
629 | 0 | fu_memwrite_uint16(st->buf->data + 36, value, G_LITTLE_ENDIAN); |
630 | 0 | } |
631 | | /** |
632 | | * fu_struct_zip_cdfh_set_external_attrs: (skip): |
633 | | **/ |
634 | | void |
635 | | fu_struct_zip_cdfh_set_external_attrs(FuStructZipCdfh *st, guint32 value) |
636 | 0 | { |
637 | 0 | g_return_if_fail(st != NULL); |
638 | 0 | fu_memwrite_uint32(st->buf->data + 38, value, G_LITTLE_ENDIAN); |
639 | 0 | } |
640 | | /** |
641 | | * fu_struct_zip_cdfh_set_offset_lfh: (skip): |
642 | | **/ |
643 | | void |
644 | | fu_struct_zip_cdfh_set_offset_lfh(FuStructZipCdfh *st, guint32 value) |
645 | 1.18k | { |
646 | 1.18k | g_return_if_fail(st != NULL); |
647 | 1.18k | fu_memwrite_uint32(st->buf->data + 42, value, G_LITTLE_ENDIAN); |
648 | 1.18k | } |
649 | | /** |
650 | | * fu_struct_zip_cdfh_new: (skip): |
651 | | **/ |
652 | | FuStructZipCdfh * |
653 | | fu_struct_zip_cdfh_new(void) |
654 | 1.18k | { |
655 | 1.18k | FuStructZipCdfh *st = fu_struct_zip_cdfh_new_internal(); |
656 | 1.18k | st->buf = g_byte_array_sized_new(46); |
657 | 1.18k | fu_byte_array_set_size(st->buf, 46, 0x0); |
658 | 1.18k | fu_struct_zip_cdfh_set_magic(st, "PK\x01\x02", NULL); |
659 | 1.18k | fu_struct_zip_cdfh_set_version_generated(st, 0xA); |
660 | 1.18k | fu_struct_zip_cdfh_set_version_extract(st, 0xA); |
661 | 1.18k | return st; |
662 | 1.18k | } |
663 | | /** |
664 | | * fu_struct_zip_cdfh_to_string: (skip): |
665 | | **/ |
666 | | static gchar * |
667 | | fu_struct_zip_cdfh_to_string(const FuStructZipCdfh *st) |
668 | 0 | { |
669 | 0 | g_autoptr(GString) str = g_string_new("FuStructZipCdfh:\n"); |
670 | 0 | g_return_val_if_fail(st != NULL, NULL); |
671 | 0 | { |
672 | 0 | g_autofree gchar *tmp = fu_struct_zip_cdfh_get_magic(st); |
673 | 0 | if (tmp != NULL) |
674 | 0 | g_string_append_printf(str, " magic: %s\n", tmp); |
675 | 0 | } |
676 | 0 | g_string_append_printf(str, " version_generated: 0x%x\n", |
677 | 0 | (guint) fu_struct_zip_cdfh_get_version_generated(st)); |
678 | 0 | g_string_append_printf(str, " version_extract: 0x%x\n", |
679 | 0 | (guint) fu_struct_zip_cdfh_get_version_extract(st)); |
680 | 0 | { |
681 | 0 | g_autofree gchar *tmp = fu_zip_flags_to_string(fu_struct_zip_cdfh_get_flags(st)); |
682 | 0 | if (tmp != NULL) { |
683 | 0 | g_string_append_printf(str, " flags: 0x%x [%s]\n", (guint) fu_struct_zip_cdfh_get_flags(st), tmp); |
684 | 0 | } else { |
685 | 0 | g_string_append_printf(str, " flags: 0x%x\n", (guint) fu_struct_zip_cdfh_get_flags(st)); |
686 | 0 | } |
687 | 0 | } |
688 | 0 | { |
689 | 0 | const gchar *tmp = fu_zip_compression_to_string(fu_struct_zip_cdfh_get_compression(st)); |
690 | 0 | if (tmp != NULL) { |
691 | 0 | g_string_append_printf(str, " compression: 0x%x [%s]\n", (guint) fu_struct_zip_cdfh_get_compression(st), tmp); |
692 | 0 | } else { |
693 | 0 | g_string_append_printf(str, " compression: 0x%x\n", (guint) fu_struct_zip_cdfh_get_compression(st)); |
694 | 0 | } |
695 | 0 | } |
696 | 0 | g_string_append_printf(str, " file_time: 0x%x\n", |
697 | 0 | (guint) fu_struct_zip_cdfh_get_file_time(st)); |
698 | 0 | g_string_append_printf(str, " file_date: 0x%x\n", |
699 | 0 | (guint) fu_struct_zip_cdfh_get_file_date(st)); |
700 | 0 | g_string_append_printf(str, " uncompressed_crc: 0x%x\n", |
701 | 0 | (guint) fu_struct_zip_cdfh_get_uncompressed_crc(st)); |
702 | 0 | g_string_append_printf(str, " compressed_size: 0x%x\n", |
703 | 0 | (guint) fu_struct_zip_cdfh_get_compressed_size(st)); |
704 | 0 | g_string_append_printf(str, " uncompressed_size: 0x%x\n", |
705 | 0 | (guint) fu_struct_zip_cdfh_get_uncompressed_size(st)); |
706 | 0 | g_string_append_printf(str, " filename_size: 0x%x\n", |
707 | 0 | (guint) fu_struct_zip_cdfh_get_filename_size(st)); |
708 | 0 | g_string_append_printf(str, " extra_size: 0x%x\n", |
709 | 0 | (guint) fu_struct_zip_cdfh_get_extra_size(st)); |
710 | 0 | g_string_append_printf(str, " comment_size: 0x%x\n", |
711 | 0 | (guint) fu_struct_zip_cdfh_get_comment_size(st)); |
712 | 0 | g_string_append_printf(str, " disk_number: 0x%x\n", |
713 | 0 | (guint) fu_struct_zip_cdfh_get_disk_number(st)); |
714 | 0 | g_string_append_printf(str, " internal_attrs: 0x%x\n", |
715 | 0 | (guint) fu_struct_zip_cdfh_get_internal_attrs(st)); |
716 | 0 | g_string_append_printf(str, " external_attrs: 0x%x\n", |
717 | 0 | (guint) fu_struct_zip_cdfh_get_external_attrs(st)); |
718 | 0 | g_string_append_printf(str, " offset_lfh: 0x%x\n", |
719 | 0 | (guint) fu_struct_zip_cdfh_get_offset_lfh(st)); |
720 | 0 | if (str->len > 0) |
721 | 0 | g_string_set_size(str, str->len - 1); |
722 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
723 | 0 | } |
724 | | static gboolean |
725 | | fu_struct_zip_cdfh_validate_internal(FuStructZipCdfh *st, GError **error) |
726 | 13.7k | { |
727 | 13.7k | g_return_val_if_fail(st != NULL, FALSE); |
728 | 13.7k | if (strncmp((const gchar *) (st->buf->data + 0), "PK\x01\x02", 4) != 0) { |
729 | 48 | g_autofree gchar *str = fu_struct_zip_cdfh_get_magic(st); |
730 | 48 | g_set_error(error, |
731 | 48 | FWUPD_ERROR, |
732 | 48 | FWUPD_ERROR_INVALID_DATA, |
733 | 48 | "constant FuStructZipCdfh.magic was not valid, " |
734 | 48 | "expected 'PK\x01\x02' and got '%s'", |
735 | 48 | str); |
736 | 48 | return FALSE; |
737 | 48 | } |
738 | 13.7k | return TRUE; |
739 | 13.7k | } |
740 | | static gboolean |
741 | | fu_struct_zip_cdfh_parse_internal(FuStructZipCdfh *st, GError **error) |
742 | 13.7k | { |
743 | 13.7k | if (g_log_get_debug_enabled()) { |
744 | 0 | g_autofree gchar *str = fu_struct_zip_cdfh_to_string(st); |
745 | 0 | g_debug("%s", str); |
746 | 0 | } |
747 | 13.7k | if (!fu_struct_zip_cdfh_validate_internal(st, error)) |
748 | 48 | return FALSE; |
749 | 13.7k | return TRUE; |
750 | 13.7k | } |
751 | | /** |
752 | | * fu_struct_zip_cdfh_parse_stream: (skip): |
753 | | **/ |
754 | | FuStructZipCdfh * |
755 | | fu_struct_zip_cdfh_parse_stream(GInputStream *stream, gsize offset, GError **error) |
756 | 13.9k | { |
757 | 13.9k | g_autoptr(FuStructZipCdfh) st = fu_struct_zip_cdfh_new_internal(); |
758 | 13.9k | st->buf = fu_input_stream_read_byte_array(stream, offset, 46, NULL, error); |
759 | 13.9k | if (st->buf == NULL) { |
760 | 125 | g_prefix_error(error, "FuStructZipCdfh failed read of 0x%x: ", (guint) 46); |
761 | 125 | return NULL; |
762 | 125 | } |
763 | 13.8k | if (st->buf->len != 46) { |
764 | 56 | g_set_error(error, |
765 | 56 | FWUPD_ERROR, |
766 | 56 | FWUPD_ERROR_INVALID_DATA, |
767 | 56 | "FuStructZipCdfh requested 0x%x and got 0x%x", |
768 | 56 | (guint) 46, |
769 | 56 | (guint) st->buf->len); |
770 | 56 | return NULL; |
771 | 56 | } |
772 | 13.7k | if (!fu_struct_zip_cdfh_parse_internal(st, error)) |
773 | 48 | return NULL; |
774 | 13.7k | return g_steal_pointer(&st); |
775 | 13.7k | } |
776 | | /** |
777 | | * fu_struct_zip_eocd_ref: (skip): |
778 | | **/ |
779 | | FuStructZipEocd * |
780 | | fu_struct_zip_eocd_ref(FuStructZipEocd *st) |
781 | 0 | { |
782 | 0 | g_return_val_if_fail(st != NULL, NULL); |
783 | 0 | st->refcount++; |
784 | 0 | return st; |
785 | 0 | } |
786 | | /** |
787 | | * fu_struct_zip_eocd_unref: (skip): |
788 | | **/ |
789 | | void |
790 | | fu_struct_zip_eocd_unref(FuStructZipEocd *st) |
791 | 1.84k | { |
792 | 1.84k | g_return_if_fail(st != NULL); |
793 | 1.84k | if (st->refcount == 0) { |
794 | 0 | g_critical("FuStructZipEocd refcount already zero"); |
795 | 0 | return; |
796 | 0 | } |
797 | 1.84k | if (--st->refcount > 0) |
798 | 0 | return; |
799 | 1.84k | if (st->buf != NULL) |
800 | 1.84k | g_byte_array_unref(st->buf); |
801 | 1.84k | g_free(st); |
802 | 1.84k | } |
803 | | /** |
804 | | * fu_struct_zip_eocd_new_internal: (skip): |
805 | | **/ |
806 | | static FuStructZipEocd * |
807 | | fu_struct_zip_eocd_new_internal(void) |
808 | 1.84k | { |
809 | 1.84k | FuStructZipEocd *st = g_new0(FuStructZipEocd, 1); |
810 | 1.84k | st->refcount = 1; |
811 | 1.84k | return st; |
812 | 1.84k | } |
813 | | |
814 | | /* getters */ |
815 | | /** |
816 | | * fu_struct_zip_eocd_get_magic: (skip): |
817 | | **/ |
818 | | static gchar * |
819 | | fu_struct_zip_eocd_get_magic(const FuStructZipEocd *st) |
820 | 0 | { |
821 | 0 | g_return_val_if_fail(st != NULL, NULL); |
822 | 0 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
823 | 0 | } |
824 | | /** |
825 | | * fu_struct_zip_eocd_get_disk_number: (skip): |
826 | | **/ |
827 | | guint16 |
828 | | fu_struct_zip_eocd_get_disk_number(const FuStructZipEocd *st) |
829 | 1.68k | { |
830 | 1.68k | g_return_val_if_fail(st != NULL, 0x0); |
831 | 1.68k | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
832 | 1.68k | } |
833 | | /** |
834 | | * fu_struct_zip_eocd_get_cd_disk: (skip): |
835 | | **/ |
836 | | guint16 |
837 | | fu_struct_zip_eocd_get_cd_disk(const FuStructZipEocd *st) |
838 | 1.66k | { |
839 | 1.66k | g_return_val_if_fail(st != NULL, 0x0); |
840 | 1.66k | return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN); |
841 | 1.66k | } |
842 | | /** |
843 | | * fu_struct_zip_eocd_get_cd_number_disk: (skip): |
844 | | **/ |
845 | | guint16 |
846 | | fu_struct_zip_eocd_get_cd_number_disk(const FuStructZipEocd *st) |
847 | 1.65k | { |
848 | 1.65k | g_return_val_if_fail(st != NULL, 0x0); |
849 | 1.65k | return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN); |
850 | 1.65k | } |
851 | | /** |
852 | | * fu_struct_zip_eocd_get_cd_number: (skip): |
853 | | **/ |
854 | | guint16 |
855 | | fu_struct_zip_eocd_get_cd_number(const FuStructZipEocd *st) |
856 | 17.4k | { |
857 | 17.4k | g_return_val_if_fail(st != NULL, 0x0); |
858 | 17.4k | return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN); |
859 | 17.4k | } |
860 | | /** |
861 | | * fu_struct_zip_eocd_get_cd_size: (skip): |
862 | | **/ |
863 | | guint32 |
864 | | fu_struct_zip_eocd_get_cd_size(const FuStructZipEocd *st) |
865 | 1.62k | { |
866 | 1.62k | g_return_val_if_fail(st != NULL, 0x0); |
867 | 1.62k | return fu_memread_uint32(st->buf->data + 12, G_LITTLE_ENDIAN); |
868 | 1.62k | } |
869 | | /** |
870 | | * fu_struct_zip_eocd_get_cd_offset: (skip): |
871 | | **/ |
872 | | guint32 |
873 | | fu_struct_zip_eocd_get_cd_offset(const FuStructZipEocd *st) |
874 | 1.61k | { |
875 | 1.61k | g_return_val_if_fail(st != NULL, 0x0); |
876 | 1.61k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
877 | 1.61k | } |
878 | | /** |
879 | | * fu_struct_zip_eocd_get_comment_size: (skip): |
880 | | **/ |
881 | | guint16 |
882 | | fu_struct_zip_eocd_get_comment_size(const FuStructZipEocd *st) |
883 | 0 | { |
884 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
885 | 0 | return fu_memread_uint16(st->buf->data + 20, G_LITTLE_ENDIAN); |
886 | 0 | } |
887 | | |
888 | | /* setters */ |
889 | | /** |
890 | | * fu_struct_zip_eocd_set_magic: (skip): |
891 | | **/ |
892 | | static gboolean |
893 | | fu_struct_zip_eocd_set_magic(FuStructZipEocd *st, const gchar *value, GError **error) |
894 | 146 | { |
895 | 146 | gsize len; |
896 | 146 | g_return_val_if_fail(st != NULL, FALSE); |
897 | 146 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
898 | 146 | if (value == NULL) { |
899 | 0 | memset(st->buf->data + 0, 0x0, 4); |
900 | 0 | return TRUE; |
901 | 0 | } |
902 | 146 | len = strlen(value); |
903 | 146 | if (len > 4) { |
904 | 0 | g_set_error(error, |
905 | 0 | FWUPD_ERROR, |
906 | 0 | FWUPD_ERROR_INVALID_DATA, |
907 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructZipEocd.magic (0x%x bytes)", |
908 | 0 | value, (guint) len, (guint) 4); |
909 | 0 | return FALSE; |
910 | 0 | } |
911 | 146 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
912 | 146 | } |
913 | | /** |
914 | | * fu_struct_zip_eocd_set_disk_number: (skip): |
915 | | **/ |
916 | | void |
917 | | fu_struct_zip_eocd_set_disk_number(FuStructZipEocd *st, guint16 value) |
918 | 0 | { |
919 | 0 | g_return_if_fail(st != NULL); |
920 | 0 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
921 | 0 | } |
922 | | /** |
923 | | * fu_struct_zip_eocd_set_cd_disk: (skip): |
924 | | **/ |
925 | | void |
926 | | fu_struct_zip_eocd_set_cd_disk(FuStructZipEocd *st, guint16 value) |
927 | 0 | { |
928 | 0 | g_return_if_fail(st != NULL); |
929 | 0 | fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN); |
930 | 0 | } |
931 | | /** |
932 | | * fu_struct_zip_eocd_set_cd_number_disk: (skip): |
933 | | **/ |
934 | | void |
935 | | fu_struct_zip_eocd_set_cd_number_disk(FuStructZipEocd *st, guint16 value) |
936 | 133 | { |
937 | 133 | g_return_if_fail(st != NULL); |
938 | 133 | fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
939 | 133 | } |
940 | | /** |
941 | | * fu_struct_zip_eocd_set_cd_number: (skip): |
942 | | **/ |
943 | | void |
944 | | fu_struct_zip_eocd_set_cd_number(FuStructZipEocd *st, guint16 value) |
945 | 133 | { |
946 | 133 | g_return_if_fail(st != NULL); |
947 | 133 | fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN); |
948 | 133 | } |
949 | | /** |
950 | | * fu_struct_zip_eocd_set_cd_size: (skip): |
951 | | **/ |
952 | | void |
953 | | fu_struct_zip_eocd_set_cd_size(FuStructZipEocd *st, guint32 value) |
954 | 133 | { |
955 | 133 | g_return_if_fail(st != NULL); |
956 | 133 | fu_memwrite_uint32(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
957 | 133 | } |
958 | | /** |
959 | | * fu_struct_zip_eocd_set_cd_offset: (skip): |
960 | | **/ |
961 | | void |
962 | | fu_struct_zip_eocd_set_cd_offset(FuStructZipEocd *st, guint32 value) |
963 | 133 | { |
964 | 133 | g_return_if_fail(st != NULL); |
965 | 133 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
966 | 133 | } |
967 | | /** |
968 | | * fu_struct_zip_eocd_set_comment_size: (skip): |
969 | | **/ |
970 | | void |
971 | | fu_struct_zip_eocd_set_comment_size(FuStructZipEocd *st, guint16 value) |
972 | 0 | { |
973 | 0 | g_return_if_fail(st != NULL); |
974 | 0 | fu_memwrite_uint16(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
975 | 0 | } |
976 | | /** |
977 | | * fu_struct_zip_eocd_new: (skip): |
978 | | **/ |
979 | | FuStructZipEocd * |
980 | | fu_struct_zip_eocd_new(void) |
981 | 146 | { |
982 | 146 | FuStructZipEocd *st = fu_struct_zip_eocd_new_internal(); |
983 | 146 | st->buf = g_byte_array_sized_new(22); |
984 | 146 | fu_byte_array_set_size(st->buf, 22, 0x0); |
985 | 146 | fu_struct_zip_eocd_set_magic(st, "PK\x05\x06", NULL); |
986 | 146 | return st; |
987 | 146 | } |
988 | | /** |
989 | | * fu_struct_zip_eocd_to_string: (skip): |
990 | | **/ |
991 | | static gchar * |
992 | | fu_struct_zip_eocd_to_string(const FuStructZipEocd *st) |
993 | 0 | { |
994 | 0 | g_autoptr(GString) str = g_string_new("FuStructZipEocd:\n"); |
995 | 0 | g_return_val_if_fail(st != NULL, NULL); |
996 | 0 | { |
997 | 0 | g_autofree gchar *tmp = fu_struct_zip_eocd_get_magic(st); |
998 | 0 | if (tmp != NULL) |
999 | 0 | g_string_append_printf(str, " magic: %s\n", tmp); |
1000 | 0 | } |
1001 | 0 | g_string_append_printf(str, " disk_number: 0x%x\n", |
1002 | 0 | (guint) fu_struct_zip_eocd_get_disk_number(st)); |
1003 | 0 | g_string_append_printf(str, " cd_disk: 0x%x\n", |
1004 | 0 | (guint) fu_struct_zip_eocd_get_cd_disk(st)); |
1005 | 0 | g_string_append_printf(str, " cd_number_disk: 0x%x\n", |
1006 | 0 | (guint) fu_struct_zip_eocd_get_cd_number_disk(st)); |
1007 | 0 | g_string_append_printf(str, " cd_number: 0x%x\n", |
1008 | 0 | (guint) fu_struct_zip_eocd_get_cd_number(st)); |
1009 | 0 | g_string_append_printf(str, " cd_size: 0x%x\n", |
1010 | 0 | (guint) fu_struct_zip_eocd_get_cd_size(st)); |
1011 | 0 | g_string_append_printf(str, " cd_offset: 0x%x\n", |
1012 | 0 | (guint) fu_struct_zip_eocd_get_cd_offset(st)); |
1013 | 0 | g_string_append_printf(str, " comment_size: 0x%x\n", |
1014 | 0 | (guint) fu_struct_zip_eocd_get_comment_size(st)); |
1015 | 0 | if (str->len > 0) |
1016 | 0 | g_string_set_size(str, str->len - 1); |
1017 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1018 | 0 | } |
1019 | | static gboolean |
1020 | | fu_struct_zip_eocd_validate_internal(FuStructZipEocd *st, GError **error) |
1021 | 1.68k | { |
1022 | 1.68k | g_return_val_if_fail(st != NULL, FALSE); |
1023 | 1.68k | if (strncmp((const gchar *) (st->buf->data + 0), "PK\x05\x06", 4) != 0) { |
1024 | 0 | g_autofree gchar *str = fu_struct_zip_eocd_get_magic(st); |
1025 | 0 | g_set_error(error, |
1026 | 0 | FWUPD_ERROR, |
1027 | 0 | FWUPD_ERROR_INVALID_DATA, |
1028 | 0 | "constant FuStructZipEocd.magic was not valid, " |
1029 | 0 | "expected 'PK\x05\x06' and got '%s'", |
1030 | 0 | str); |
1031 | 0 | return FALSE; |
1032 | 0 | } |
1033 | 1.68k | return TRUE; |
1034 | 1.68k | } |
1035 | | static gboolean |
1036 | | fu_struct_zip_eocd_parse_internal(FuStructZipEocd *st, GError **error) |
1037 | 1.68k | { |
1038 | 1.68k | if (g_log_get_debug_enabled()) { |
1039 | 0 | g_autofree gchar *str = fu_struct_zip_eocd_to_string(st); |
1040 | 0 | g_debug("%s", str); |
1041 | 0 | } |
1042 | 1.68k | if (!fu_struct_zip_eocd_validate_internal(st, error)) |
1043 | 0 | return FALSE; |
1044 | 1.68k | return TRUE; |
1045 | 1.68k | } |
1046 | | /** |
1047 | | * fu_struct_zip_eocd_parse_stream: (skip): |
1048 | | **/ |
1049 | | FuStructZipEocd * |
1050 | | fu_struct_zip_eocd_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1051 | 1.70k | { |
1052 | 1.70k | g_autoptr(FuStructZipEocd) st = fu_struct_zip_eocd_new_internal(); |
1053 | 1.70k | st->buf = fu_input_stream_read_byte_array(stream, offset, 22, NULL, error); |
1054 | 1.70k | if (st->buf == NULL) { |
1055 | 0 | g_prefix_error(error, "FuStructZipEocd failed read of 0x%x: ", (guint) 22); |
1056 | 0 | return NULL; |
1057 | 0 | } |
1058 | 1.70k | if (st->buf->len != 22) { |
1059 | 20 | g_set_error(error, |
1060 | 20 | FWUPD_ERROR, |
1061 | 20 | FWUPD_ERROR_INVALID_DATA, |
1062 | 20 | "FuStructZipEocd requested 0x%x and got 0x%x", |
1063 | 20 | (guint) 22, |
1064 | 20 | (guint) st->buf->len); |
1065 | 20 | return NULL; |
1066 | 20 | } |
1067 | 1.68k | if (!fu_struct_zip_eocd_parse_internal(st, error)) |
1068 | 0 | return NULL; |
1069 | 1.68k | return g_steal_pointer(&st); |
1070 | 1.68k | } |
1071 | | /** |
1072 | | * fu_struct_zip_lfh_ref: (skip): |
1073 | | **/ |
1074 | | FuStructZipLfh * |
1075 | | fu_struct_zip_lfh_ref(FuStructZipLfh *st) |
1076 | 0 | { |
1077 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1078 | 0 | st->refcount++; |
1079 | 0 | return st; |
1080 | 0 | } |
1081 | | /** |
1082 | | * fu_struct_zip_lfh_unref: (skip): |
1083 | | **/ |
1084 | | void |
1085 | | fu_struct_zip_lfh_unref(FuStructZipLfh *st) |
1086 | 15.2k | { |
1087 | 15.2k | g_return_if_fail(st != NULL); |
1088 | 15.2k | if (st->refcount == 0) { |
1089 | 0 | g_critical("FuStructZipLfh refcount already zero"); |
1090 | 0 | return; |
1091 | 0 | } |
1092 | 15.2k | if (--st->refcount > 0) |
1093 | 0 | return; |
1094 | 15.2k | if (st->buf != NULL) |
1095 | 15.1k | g_byte_array_unref(st->buf); |
1096 | 15.2k | g_free(st); |
1097 | 15.2k | } |
1098 | | /** |
1099 | | * fu_struct_zip_lfh_new_internal: (skip): |
1100 | | **/ |
1101 | | static FuStructZipLfh * |
1102 | | fu_struct_zip_lfh_new_internal(void) |
1103 | 15.2k | { |
1104 | 15.2k | FuStructZipLfh *st = g_new0(FuStructZipLfh, 1); |
1105 | 15.2k | st->refcount = 1; |
1106 | 15.2k | return st; |
1107 | 15.2k | } |
1108 | | |
1109 | | /* getters */ |
1110 | | /** |
1111 | | * fu_struct_zip_lfh_get_magic: (skip): |
1112 | | **/ |
1113 | | static gchar * |
1114 | | fu_struct_zip_lfh_get_magic(const FuStructZipLfh *st) |
1115 | 31 | { |
1116 | 31 | g_return_val_if_fail(st != NULL, NULL); |
1117 | 31 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
1118 | 31 | } |
1119 | | /** |
1120 | | * fu_struct_zip_lfh_get_version_extract: (skip): |
1121 | | **/ |
1122 | | guint16 |
1123 | | fu_struct_zip_lfh_get_version_extract(const FuStructZipLfh *st) |
1124 | 0 | { |
1125 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1126 | 0 | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
1127 | 0 | } |
1128 | | /** |
1129 | | * fu_struct_zip_lfh_get_flags: (skip): |
1130 | | **/ |
1131 | | FuZipFlags |
1132 | | fu_struct_zip_lfh_get_flags(const FuStructZipLfh *st) |
1133 | 13.3k | { |
1134 | 13.3k | g_return_val_if_fail(st != NULL, 0x0); |
1135 | 13.3k | return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN); |
1136 | 13.3k | } |
1137 | | /** |
1138 | | * fu_struct_zip_lfh_get_compression: (skip): |
1139 | | **/ |
1140 | | FuZipCompression |
1141 | | fu_struct_zip_lfh_get_compression(const FuStructZipLfh *st) |
1142 | 12.7k | { |
1143 | 12.7k | g_return_val_if_fail(st != NULL, 0x0); |
1144 | 12.7k | return fu_memread_uint16(st->buf->data + 8, G_LITTLE_ENDIAN); |
1145 | 12.7k | } |
1146 | | /** |
1147 | | * fu_struct_zip_lfh_get_file_time: (skip): |
1148 | | **/ |
1149 | | guint16 |
1150 | | fu_struct_zip_lfh_get_file_time(const FuStructZipLfh *st) |
1151 | 0 | { |
1152 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1153 | 0 | return fu_memread_uint16(st->buf->data + 10, G_LITTLE_ENDIAN); |
1154 | 0 | } |
1155 | | /** |
1156 | | * fu_struct_zip_lfh_get_file_date: (skip): |
1157 | | **/ |
1158 | | guint16 |
1159 | | fu_struct_zip_lfh_get_file_date(const FuStructZipLfh *st) |
1160 | 0 | { |
1161 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1162 | 0 | return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN); |
1163 | 0 | } |
1164 | | /** |
1165 | | * fu_struct_zip_lfh_get_uncompressed_crc: (skip): |
1166 | | **/ |
1167 | | guint32 |
1168 | | fu_struct_zip_lfh_get_uncompressed_crc(const FuStructZipLfh *st) |
1169 | 9.30k | { |
1170 | 9.30k | g_return_val_if_fail(st != NULL, 0x0); |
1171 | 9.30k | return fu_memread_uint32(st->buf->data + 14, G_LITTLE_ENDIAN); |
1172 | 9.30k | } |
1173 | | /** |
1174 | | * fu_struct_zip_lfh_get_compressed_size: (skip): |
1175 | | **/ |
1176 | | guint32 |
1177 | | fu_struct_zip_lfh_get_compressed_size(const FuStructZipLfh *st) |
1178 | 13.3k | { |
1179 | 13.3k | g_return_val_if_fail(st != NULL, 0x0); |
1180 | 13.3k | return fu_memread_uint32(st->buf->data + 18, G_LITTLE_ENDIAN); |
1181 | 13.3k | } |
1182 | | /** |
1183 | | * fu_struct_zip_lfh_get_uncompressed_size: (skip): |
1184 | | **/ |
1185 | | guint32 |
1186 | | fu_struct_zip_lfh_get_uncompressed_size(const FuStructZipLfh *st) |
1187 | 13.2k | { |
1188 | 13.2k | g_return_val_if_fail(st != NULL, 0x0); |
1189 | 13.2k | return fu_memread_uint32(st->buf->data + 22, G_LITTLE_ENDIAN); |
1190 | 13.2k | } |
1191 | | /** |
1192 | | * fu_struct_zip_lfh_get_filename_size: (skip): |
1193 | | **/ |
1194 | | guint16 |
1195 | | fu_struct_zip_lfh_get_filename_size(const FuStructZipLfh *st) |
1196 | 27.1k | { |
1197 | 27.1k | g_return_val_if_fail(st != NULL, 0x0); |
1198 | 27.1k | return fu_memread_uint16(st->buf->data + 26, G_LITTLE_ENDIAN); |
1199 | 27.1k | } |
1200 | | /** |
1201 | | * fu_struct_zip_lfh_get_extra_size: (skip): |
1202 | | **/ |
1203 | | guint16 |
1204 | | fu_struct_zip_lfh_get_extra_size(const FuStructZipLfh *st) |
1205 | 26.8k | { |
1206 | 26.8k | g_return_val_if_fail(st != NULL, 0x0); |
1207 | 26.8k | return fu_memread_uint16(st->buf->data + 28, G_LITTLE_ENDIAN); |
1208 | 26.8k | } |
1209 | | |
1210 | | /* setters */ |
1211 | | /** |
1212 | | * fu_struct_zip_lfh_set_magic: (skip): |
1213 | | **/ |
1214 | | static gboolean |
1215 | | fu_struct_zip_lfh_set_magic(FuStructZipLfh *st, const gchar *value, GError **error) |
1216 | 1.49k | { |
1217 | 1.49k | gsize len; |
1218 | 1.49k | g_return_val_if_fail(st != NULL, FALSE); |
1219 | 1.49k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
1220 | 1.49k | if (value == NULL) { |
1221 | 0 | memset(st->buf->data + 0, 0x0, 4); |
1222 | 0 | return TRUE; |
1223 | 0 | } |
1224 | 1.49k | len = strlen(value); |
1225 | 1.49k | if (len > 4) { |
1226 | 0 | g_set_error(error, |
1227 | 0 | FWUPD_ERROR, |
1228 | 0 | FWUPD_ERROR_INVALID_DATA, |
1229 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructZipLfh.magic (0x%x bytes)", |
1230 | 0 | value, (guint) len, (guint) 4); |
1231 | 0 | return FALSE; |
1232 | 0 | } |
1233 | 1.49k | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
1234 | 1.49k | } |
1235 | | /** |
1236 | | * fu_struct_zip_lfh_set_version_extract: (skip): |
1237 | | **/ |
1238 | | void |
1239 | | fu_struct_zip_lfh_set_version_extract(FuStructZipLfh *st, guint16 value) |
1240 | 1.49k | { |
1241 | 1.49k | g_return_if_fail(st != NULL); |
1242 | 1.49k | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
1243 | 1.49k | } |
1244 | | /** |
1245 | | * fu_struct_zip_lfh_set_flags: (skip): |
1246 | | **/ |
1247 | | void |
1248 | | fu_struct_zip_lfh_set_flags(FuStructZipLfh *st, FuZipFlags value) |
1249 | 0 | { |
1250 | 0 | g_return_if_fail(st != NULL); |
1251 | 0 | fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN); |
1252 | 0 | } |
1253 | | /** |
1254 | | * fu_struct_zip_lfh_set_compression: (skip): |
1255 | | **/ |
1256 | | void |
1257 | | fu_struct_zip_lfh_set_compression(FuStructZipLfh *st, FuZipCompression value) |
1258 | 1.48k | { |
1259 | 1.48k | g_return_if_fail(st != NULL); |
1260 | 1.48k | fu_memwrite_uint16(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
1261 | 1.48k | } |
1262 | | /** |
1263 | | * fu_struct_zip_lfh_set_file_time: (skip): |
1264 | | **/ |
1265 | | void |
1266 | | fu_struct_zip_lfh_set_file_time(FuStructZipLfh *st, guint16 value) |
1267 | 0 | { |
1268 | 0 | g_return_if_fail(st != NULL); |
1269 | 0 | fu_memwrite_uint16(st->buf->data + 10, value, G_LITTLE_ENDIAN); |
1270 | 0 | } |
1271 | | /** |
1272 | | * fu_struct_zip_lfh_set_file_date: (skip): |
1273 | | **/ |
1274 | | void |
1275 | | fu_struct_zip_lfh_set_file_date(FuStructZipLfh *st, guint16 value) |
1276 | 0 | { |
1277 | 0 | g_return_if_fail(st != NULL); |
1278 | 0 | fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
1279 | 0 | } |
1280 | | /** |
1281 | | * fu_struct_zip_lfh_set_uncompressed_crc: (skip): |
1282 | | **/ |
1283 | | void |
1284 | | fu_struct_zip_lfh_set_uncompressed_crc(FuStructZipLfh *st, guint32 value) |
1285 | 1.48k | { |
1286 | 1.48k | g_return_if_fail(st != NULL); |
1287 | 1.48k | fu_memwrite_uint32(st->buf->data + 14, value, G_LITTLE_ENDIAN); |
1288 | 1.48k | } |
1289 | | /** |
1290 | | * fu_struct_zip_lfh_set_compressed_size: (skip): |
1291 | | **/ |
1292 | | void |
1293 | | fu_struct_zip_lfh_set_compressed_size(FuStructZipLfh *st, guint32 value) |
1294 | 1.48k | { |
1295 | 1.48k | g_return_if_fail(st != NULL); |
1296 | 1.48k | fu_memwrite_uint32(st->buf->data + 18, value, G_LITTLE_ENDIAN); |
1297 | 1.48k | } |
1298 | | /** |
1299 | | * fu_struct_zip_lfh_set_uncompressed_size: (skip): |
1300 | | **/ |
1301 | | void |
1302 | | fu_struct_zip_lfh_set_uncompressed_size(FuStructZipLfh *st, guint32 value) |
1303 | 1.48k | { |
1304 | 1.48k | g_return_if_fail(st != NULL); |
1305 | 1.48k | fu_memwrite_uint32(st->buf->data + 22, value, G_LITTLE_ENDIAN); |
1306 | 1.48k | } |
1307 | | /** |
1308 | | * fu_struct_zip_lfh_set_filename_size: (skip): |
1309 | | **/ |
1310 | | void |
1311 | | fu_struct_zip_lfh_set_filename_size(FuStructZipLfh *st, guint16 value) |
1312 | 1.48k | { |
1313 | 1.48k | g_return_if_fail(st != NULL); |
1314 | 1.48k | fu_memwrite_uint16(st->buf->data + 26, value, G_LITTLE_ENDIAN); |
1315 | 1.48k | } |
1316 | | /** |
1317 | | * fu_struct_zip_lfh_set_extra_size: (skip): |
1318 | | **/ |
1319 | | void |
1320 | | fu_struct_zip_lfh_set_extra_size(FuStructZipLfh *st, guint16 value) |
1321 | 0 | { |
1322 | 0 | g_return_if_fail(st != NULL); |
1323 | 0 | fu_memwrite_uint16(st->buf->data + 28, value, G_LITTLE_ENDIAN); |
1324 | 0 | } |
1325 | | /** |
1326 | | * fu_struct_zip_lfh_new: (skip): |
1327 | | **/ |
1328 | | FuStructZipLfh * |
1329 | | fu_struct_zip_lfh_new(void) |
1330 | 1.49k | { |
1331 | 1.49k | FuStructZipLfh *st = fu_struct_zip_lfh_new_internal(); |
1332 | 1.49k | st->buf = g_byte_array_sized_new(30); |
1333 | 1.49k | fu_byte_array_set_size(st->buf, 30, 0x0); |
1334 | 1.49k | fu_struct_zip_lfh_set_magic(st, "PK\x03\x04", NULL); |
1335 | 1.49k | fu_struct_zip_lfh_set_version_extract(st, 0xA); |
1336 | 1.49k | return st; |
1337 | 1.49k | } |
1338 | | /** |
1339 | | * fu_struct_zip_lfh_to_string: (skip): |
1340 | | **/ |
1341 | | static gchar * |
1342 | | fu_struct_zip_lfh_to_string(const FuStructZipLfh *st) |
1343 | 0 | { |
1344 | 0 | g_autoptr(GString) str = g_string_new("FuStructZipLfh:\n"); |
1345 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1346 | 0 | { |
1347 | 0 | g_autofree gchar *tmp = fu_struct_zip_lfh_get_magic(st); |
1348 | 0 | if (tmp != NULL) |
1349 | 0 | g_string_append_printf(str, " magic: %s\n", tmp); |
1350 | 0 | } |
1351 | 0 | g_string_append_printf(str, " version_extract: 0x%x\n", |
1352 | 0 | (guint) fu_struct_zip_lfh_get_version_extract(st)); |
1353 | 0 | { |
1354 | 0 | g_autofree gchar *tmp = fu_zip_flags_to_string(fu_struct_zip_lfh_get_flags(st)); |
1355 | 0 | if (tmp != NULL) { |
1356 | 0 | g_string_append_printf(str, " flags: 0x%x [%s]\n", (guint) fu_struct_zip_lfh_get_flags(st), tmp); |
1357 | 0 | } else { |
1358 | 0 | g_string_append_printf(str, " flags: 0x%x\n", (guint) fu_struct_zip_lfh_get_flags(st)); |
1359 | 0 | } |
1360 | 0 | } |
1361 | 0 | { |
1362 | 0 | const gchar *tmp = fu_zip_compression_to_string(fu_struct_zip_lfh_get_compression(st)); |
1363 | 0 | if (tmp != NULL) { |
1364 | 0 | g_string_append_printf(str, " compression: 0x%x [%s]\n", (guint) fu_struct_zip_lfh_get_compression(st), tmp); |
1365 | 0 | } else { |
1366 | 0 | g_string_append_printf(str, " compression: 0x%x\n", (guint) fu_struct_zip_lfh_get_compression(st)); |
1367 | 0 | } |
1368 | 0 | } |
1369 | 0 | g_string_append_printf(str, " file_time: 0x%x\n", |
1370 | 0 | (guint) fu_struct_zip_lfh_get_file_time(st)); |
1371 | 0 | g_string_append_printf(str, " file_date: 0x%x\n", |
1372 | 0 | (guint) fu_struct_zip_lfh_get_file_date(st)); |
1373 | 0 | g_string_append_printf(str, " uncompressed_crc: 0x%x\n", |
1374 | 0 | (guint) fu_struct_zip_lfh_get_uncompressed_crc(st)); |
1375 | 0 | g_string_append_printf(str, " compressed_size: 0x%x\n", |
1376 | 0 | (guint) fu_struct_zip_lfh_get_compressed_size(st)); |
1377 | 0 | g_string_append_printf(str, " uncompressed_size: 0x%x\n", |
1378 | 0 | (guint) fu_struct_zip_lfh_get_uncompressed_size(st)); |
1379 | 0 | g_string_append_printf(str, " filename_size: 0x%x\n", |
1380 | 0 | (guint) fu_struct_zip_lfh_get_filename_size(st)); |
1381 | 0 | g_string_append_printf(str, " extra_size: 0x%x\n", |
1382 | 0 | (guint) fu_struct_zip_lfh_get_extra_size(st)); |
1383 | 0 | if (str->len > 0) |
1384 | 0 | g_string_set_size(str, str->len - 1); |
1385 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1386 | 0 | } |
1387 | | static gboolean |
1388 | | fu_struct_zip_lfh_validate_internal(FuStructZipLfh *st, GError **error) |
1389 | 13.7k | { |
1390 | 13.7k | g_return_val_if_fail(st != NULL, FALSE); |
1391 | 13.7k | if (strncmp((const gchar *) (st->buf->data + 0), "PK\x03\x04", 4) != 0) { |
1392 | 31 | g_autofree gchar *str = fu_struct_zip_lfh_get_magic(st); |
1393 | 31 | g_set_error(error, |
1394 | 31 | FWUPD_ERROR, |
1395 | 31 | FWUPD_ERROR_INVALID_DATA, |
1396 | 31 | "constant FuStructZipLfh.magic was not valid, " |
1397 | 31 | "expected 'PK\x03\x04' and got '%s'", |
1398 | 31 | str); |
1399 | 31 | return FALSE; |
1400 | 31 | } |
1401 | 13.6k | return TRUE; |
1402 | 13.7k | } |
1403 | | static gboolean |
1404 | | fu_struct_zip_lfh_parse_internal(FuStructZipLfh *st, GError **error) |
1405 | 13.7k | { |
1406 | 13.7k | if (g_log_get_debug_enabled()) { |
1407 | 0 | g_autofree gchar *str = fu_struct_zip_lfh_to_string(st); |
1408 | 0 | g_debug("%s", str); |
1409 | 0 | } |
1410 | 13.7k | if (!fu_struct_zip_lfh_validate_internal(st, error)) |
1411 | 31 | return FALSE; |
1412 | 13.6k | return TRUE; |
1413 | 13.7k | } |
1414 | | /** |
1415 | | * fu_struct_zip_lfh_parse_stream: (skip): |
1416 | | **/ |
1417 | | FuStructZipLfh * |
1418 | | fu_struct_zip_lfh_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1419 | 13.7k | { |
1420 | 13.7k | g_autoptr(FuStructZipLfh) st = fu_struct_zip_lfh_new_internal(); |
1421 | 13.7k | st->buf = fu_input_stream_read_byte_array(stream, offset, 30, NULL, error); |
1422 | 13.7k | if (st->buf == NULL) { |
1423 | 43 | g_prefix_error(error, "FuStructZipLfh failed read of 0x%x: ", (guint) 30); |
1424 | 43 | return NULL; |
1425 | 43 | } |
1426 | 13.7k | if (st->buf->len != 30) { |
1427 | 4 | g_set_error(error, |
1428 | 4 | FWUPD_ERROR, |
1429 | 4 | FWUPD_ERROR_INVALID_DATA, |
1430 | 4 | "FuStructZipLfh requested 0x%x and got 0x%x", |
1431 | 4 | (guint) 30, |
1432 | 4 | (guint) st->buf->len); |
1433 | 4 | return NULL; |
1434 | 4 | } |
1435 | 13.7k | if (!fu_struct_zip_lfh_parse_internal(st, error)) |
1436 | 31 | return NULL; |
1437 | 13.6k | return g_steal_pointer(&st); |
1438 | 13.7k | } |