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