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-efi-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_efi_status_to_string: |
24 | | * @val: value, e.g. %FU_EFI_STATUS_LOAD_ERROR |
25 | | * |
26 | | * Converts an enumerated value to a string. |
27 | | * |
28 | | * Returns: identifier string |
29 | | **/ |
30 | | const gchar * |
31 | | fu_efi_status_to_string(FuEfiStatus val) |
32 | 0 | { |
33 | 0 | if (val == FU_EFI_STATUS_SUCCESS) |
34 | 0 | return "success"; |
35 | 0 | if (val == FU_EFI_STATUS_LOAD_ERROR) |
36 | 0 | return "load-error"; |
37 | 0 | if (val == FU_EFI_STATUS_INVALID_PARAMETER) |
38 | 0 | return "invalid-parameter"; |
39 | 0 | if (val == FU_EFI_STATUS_UNSUPPORTED) |
40 | 0 | return "unsupported"; |
41 | 0 | if (val == FU_EFI_STATUS_BAD_BUFFER_SIZE) |
42 | 0 | return "bad-buffer-size"; |
43 | 0 | if (val == FU_EFI_STATUS_BUFFER_TOO_SMALL) |
44 | 0 | return "buffer-too-small"; |
45 | 0 | if (val == FU_EFI_STATUS_NOT_READY) |
46 | 0 | return "not-ready"; |
47 | 0 | if (val == FU_EFI_STATUS_DEVICE_ERROR) |
48 | 0 | return "device-error"; |
49 | 0 | if (val == FU_EFI_STATUS_WRITE_PROTECTED) |
50 | 0 | return "write-protected"; |
51 | 0 | if (val == FU_EFI_STATUS_OUT_OF_RESOURCES) |
52 | 0 | return "out-of-resources"; |
53 | 0 | if (val == FU_EFI_STATUS_VOLUME_CORRUPTED) |
54 | 0 | return "volume-corrupted"; |
55 | 0 | if (val == FU_EFI_STATUS_VOLUME_FULL) |
56 | 0 | return "volume-full"; |
57 | 0 | if (val == FU_EFI_STATUS_NO_MEDIA) |
58 | 0 | return "no-media"; |
59 | 0 | if (val == FU_EFI_STATUS_MEDIA_CHANGED) |
60 | 0 | return "media-changed"; |
61 | 0 | if (val == FU_EFI_STATUS_NOT_FOUND) |
62 | 0 | return "not-found"; |
63 | 0 | if (val == FU_EFI_STATUS_ACCESS_DENIED) |
64 | 0 | return "access-denied"; |
65 | 0 | if (val == FU_EFI_STATUS_NO_RESPONSE) |
66 | 0 | return "no-response"; |
67 | 0 | if (val == FU_EFI_STATUS_NO_MAPPING) |
68 | 0 | return "no-mapping"; |
69 | 0 | if (val == FU_EFI_STATUS_TIMEOUT) |
70 | 0 | return "timeout"; |
71 | 0 | if (val == FU_EFI_STATUS_NOT_STARTED) |
72 | 0 | return "not-started"; |
73 | 0 | if (val == FU_EFI_STATUS_ALREADY_STARTED) |
74 | 0 | return "already-started"; |
75 | 0 | if (val == FU_EFI_STATUS_ABORTED) |
76 | 0 | return "aborted"; |
77 | 0 | if (val == FU_EFI_STATUS_ICMP_ERROR) |
78 | 0 | return "icmp-error"; |
79 | 0 | if (val == FU_EFI_STATUS_TFTP_ERROR) |
80 | 0 | return "tftp-error"; |
81 | 0 | if (val == FU_EFI_STATUS_PROTOCOL_ERROR) |
82 | 0 | return "protocol-error"; |
83 | 0 | if (val == FU_EFI_STATUS_INCOMPATIBLE_VERSION) |
84 | 0 | return "incompatible-version"; |
85 | 0 | if (val == FU_EFI_STATUS_SECURITY_VIOLATION) |
86 | 0 | return "security-violation"; |
87 | 0 | if (val == FU_EFI_STATUS_CRC_ERROR) |
88 | 0 | return "crc-error"; |
89 | 0 | if (val == FU_EFI_STATUS_END_OF_MEDIA) |
90 | 0 | return "end-of-media"; |
91 | 0 | if (val == FU_EFI_STATUS_END_OF_FILE) |
92 | 0 | return "end-of-file"; |
93 | 0 | if (val == FU_EFI_STATUS_INVALID_LANGUAGE) |
94 | 0 | return "invalid-language"; |
95 | 0 | if (val == FU_EFI_STATUS_COMPROMISED_DATA) |
96 | 0 | return "compromised-data"; |
97 | 0 | if (val == FU_EFI_STATUS_IP_ADDRESS_CONFLICT) |
98 | 0 | return "ip-address-conflict"; |
99 | 0 | if (val == FU_EFI_STATUS_HTTP_ERROR) |
100 | 0 | return "http-error"; |
101 | 0 | return NULL; |
102 | 0 | } |
103 | | |
104 | | /** |
105 | | * fu_efi_signature_kind_to_string: |
106 | | * @val: value, e.g. %FU_EFI_SIGNATURE_KIND_SHA256 |
107 | | * |
108 | | * Converts an enumerated value to a string. |
109 | | * |
110 | | * Returns: identifier string |
111 | | **/ |
112 | | const gchar * |
113 | | fu_efi_signature_kind_to_string(FuEfiSignatureKind val) |
114 | 0 | { |
115 | 0 | if (val == FU_EFI_SIGNATURE_KIND_SHA256) |
116 | 0 | return "sha256"; |
117 | 0 | if (val == FU_EFI_SIGNATURE_KIND_X509) |
118 | 0 | return "x509"; |
119 | 0 | return NULL; |
120 | 0 | } |
121 | | /** |
122 | | * fu_efi_signature_kind_from_string: |
123 | | * @val: (nullable): a string, e.g. `sha256` |
124 | | * |
125 | | * Converts a string to an enumerated value. |
126 | | * |
127 | | * Returns: enumerated value |
128 | | **/ |
129 | | FuEfiSignatureKind |
130 | | fu_efi_signature_kind_from_string(const gchar *val) |
131 | 0 | { |
132 | 0 | if (g_strcmp0(val, "sha256") == 0) |
133 | 0 | return FU_EFI_SIGNATURE_KIND_SHA256; |
134 | 0 | if (g_strcmp0(val, "x509") == 0) |
135 | 0 | return FU_EFI_SIGNATURE_KIND_X509; |
136 | 0 | return FU_EFI_SIGNATURE_KIND_UNKNOWN; |
137 | 0 | } |
138 | | |
139 | | |
140 | | /** |
141 | | * fu_efi_file_type_to_string: |
142 | | * @val: value, e.g. %FU_EFI_FILE_TYPE_RAW |
143 | | * |
144 | | * Converts an enumerated value to a string. |
145 | | * |
146 | | * Returns: identifier string |
147 | | **/ |
148 | | const gchar * |
149 | | fu_efi_file_type_to_string(FuEfiFileType val) |
150 | 0 | { |
151 | 0 | if (val == FU_EFI_FILE_TYPE_ALL) |
152 | 0 | return "all"; |
153 | 0 | if (val == FU_EFI_FILE_TYPE_RAW) |
154 | 0 | return "raw"; |
155 | 0 | if (val == FU_EFI_FILE_TYPE_FREEFORM) |
156 | 0 | return "freeform"; |
157 | 0 | if (val == FU_EFI_FILE_TYPE_SECURITY_CORE) |
158 | 0 | return "security-core"; |
159 | 0 | if (val == FU_EFI_FILE_TYPE_PEI_CORE) |
160 | 0 | return "pei-core"; |
161 | 0 | if (val == FU_EFI_FILE_TYPE_DXE_CORE) |
162 | 0 | return "dxe-core"; |
163 | 0 | if (val == FU_EFI_FILE_TYPE_PEIM) |
164 | 0 | return "peim"; |
165 | 0 | if (val == FU_EFI_FILE_TYPE_DRIVER) |
166 | 0 | return "driver"; |
167 | 0 | if (val == FU_EFI_FILE_TYPE_COMBINED_PEIM_DRIVER) |
168 | 0 | return "combined-peim-driver"; |
169 | 0 | if (val == FU_EFI_FILE_TYPE_APPLICATION) |
170 | 0 | return "application"; |
171 | 0 | if (val == FU_EFI_FILE_TYPE_MM) |
172 | 0 | return "mm"; |
173 | 0 | if (val == FU_EFI_FILE_TYPE_FIRMWARE_VOLUME_IMAGE) |
174 | 0 | return "firmware-volume-image"; |
175 | 0 | if (val == FU_EFI_FILE_TYPE_COMBINED_MM_DXE) |
176 | 0 | return "combined-mm-dxe"; |
177 | 0 | if (val == FU_EFI_FILE_TYPE_MM_CORE) |
178 | 0 | return "mm-core"; |
179 | 0 | if (val == FU_EFI_FILE_TYPE_MM_STANDALONE) |
180 | 0 | return "mm-standalone"; |
181 | 0 | if (val == FU_EFI_FILE_TYPE_MM_CORE_STANDALONE) |
182 | 0 | return "mm-core-standalone"; |
183 | 0 | if (val == FU_EFI_FILE_TYPE_FFS_PAD) |
184 | 0 | return "ffs-pad"; |
185 | 0 | return NULL; |
186 | 0 | } |
187 | | |
188 | | /** |
189 | | * fu_efi_compression_type_to_string: |
190 | | * @val: value, e.g. %FU_EFI_COMPRESSION_TYPE_STANDARD_COMPRESSION |
191 | | * |
192 | | * Converts an enumerated value to a string. |
193 | | * |
194 | | * Returns: identifier string |
195 | | **/ |
196 | | static const gchar * |
197 | | fu_efi_compression_type_to_string(FuEfiCompressionType val) |
198 | 0 | { |
199 | 0 | if (val == FU_EFI_COMPRESSION_TYPE_NOT_COMPRESSED) |
200 | 0 | return "not-compressed"; |
201 | 0 | if (val == FU_EFI_COMPRESSION_TYPE_STANDARD_COMPRESSION) |
202 | 0 | return "standard-compression"; |
203 | 0 | return NULL; |
204 | 0 | } |
205 | | |
206 | | /** |
207 | | * fu_efi_lz77_decompressor_version_to_string: |
208 | | * @val: value, e.g. %FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY |
209 | | * |
210 | | * Converts an enumerated value to a string. |
211 | | * |
212 | | * Returns: identifier string |
213 | | **/ |
214 | | const gchar * |
215 | | fu_efi_lz77_decompressor_version_to_string(FuEfiLz77DecompressorVersion val) |
216 | 2.01k | { |
217 | 2.01k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_NONE) |
218 | 0 | return "none"; |
219 | 2.01k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY) |
220 | 1.40k | return "legacy"; |
221 | 607 | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_TIANO) |
222 | 607 | return "tiano"; |
223 | 0 | return NULL; |
224 | 607 | } |
225 | | |
226 | | /** |
227 | | * fu_efi_section_type_to_string: |
228 | | * @val: value, e.g. %FU_EFI_SECTION_TYPE_GUID_DEFINED |
229 | | * |
230 | | * Converts an enumerated value to a string. |
231 | | * |
232 | | * Returns: identifier string |
233 | | **/ |
234 | | const gchar * |
235 | | fu_efi_section_type_to_string(FuEfiSectionType val) |
236 | 21.5k | { |
237 | 21.5k | if (val == FU_EFI_SECTION_TYPE_COMPRESSION) |
238 | 0 | return "compression"; |
239 | 21.5k | if (val == FU_EFI_SECTION_TYPE_GUID_DEFINED) |
240 | 0 | return "guid-defined"; |
241 | 21.5k | if (val == FU_EFI_SECTION_TYPE_DISPOSABLE) |
242 | 399 | return "disposable"; |
243 | 21.1k | if (val == FU_EFI_SECTION_TYPE_PE32) |
244 | 596 | return "pe32"; |
245 | 20.5k | if (val == FU_EFI_SECTION_TYPE_PIC) |
246 | 364 | return "pic"; |
247 | 20.1k | if (val == FU_EFI_SECTION_TYPE_TE) |
248 | 185 | return "te"; |
249 | 19.9k | if (val == FU_EFI_SECTION_TYPE_DXE_DEPEX) |
250 | 253 | return "dxe-depex"; |
251 | 19.7k | if (val == FU_EFI_SECTION_TYPE_VERSION) |
252 | 0 | return "version"; |
253 | 19.7k | if (val == FU_EFI_SECTION_TYPE_USER_INTERFACE) |
254 | 0 | return "user-interface"; |
255 | 19.7k | if (val == FU_EFI_SECTION_TYPE_COMPATIBILITY16) |
256 | 2.09k | return "compatibility16"; |
257 | 17.6k | if (val == FU_EFI_SECTION_TYPE_VOLUME_IMAGE) |
258 | 0 | return "volume-image"; |
259 | 17.6k | if (val == FU_EFI_SECTION_TYPE_FREEFORM_SUBTYPE_GUID) |
260 | 0 | return "freeform-subtype-guid"; |
261 | 17.6k | if (val == FU_EFI_SECTION_TYPE_RAW) |
262 | 406 | return "raw"; |
263 | 17.2k | if (val == FU_EFI_SECTION_TYPE_PEI_DEPEX) |
264 | 1.06k | return "pei-depex"; |
265 | 16.1k | if (val == FU_EFI_SECTION_TYPE_MM_DEPEX) |
266 | 292 | return "mm-depex"; |
267 | 15.8k | if (val == FU_EFI_SECTION_TYPE_PHOENIX_SECTION_POSTCODE) |
268 | 2.40k | return "phoenix-section-postcode"; |
269 | 13.4k | if (val == FU_EFI_SECTION_TYPE_INSYDE_SECTION_POSTCODE) |
270 | 362 | return "insyde-section-postcode"; |
271 | 13.1k | return NULL; |
272 | 13.4k | } |
273 | | |
274 | | /** |
275 | | * fu_efi_volume_ext_entry_type_to_string: |
276 | | * @val: value, e.g. %FU_EFI_VOLUME_EXT_ENTRY_TYPE_GUID |
277 | | * |
278 | | * Converts an enumerated value to a string. |
279 | | * |
280 | | * Returns: identifier string |
281 | | **/ |
282 | | const gchar * |
283 | | fu_efi_volume_ext_entry_type_to_string(FuEfiVolumeExtEntryType val) |
284 | 0 | { |
285 | 0 | if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_OEM) |
286 | 0 | return "oem"; |
287 | 0 | if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_GUID) |
288 | 0 | return "guid"; |
289 | 0 | if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_SIZE) |
290 | 0 | return "size"; |
291 | 0 | return NULL; |
292 | 0 | } |
293 | | |
294 | | /** |
295 | | * fu_efi_load_option_attrs_to_string: |
296 | | * @val: value, e.g. %FU_EFI_LOAD_OPTION_ATTR_FORCE_RECONNECT |
297 | | * |
298 | | * Converts an enumerated value to a string. |
299 | | * |
300 | | * Returns: identifier string |
301 | | **/ |
302 | | static const gchar * |
303 | | fu_efi_load_option_attrs_to_string(FuEfiLoadOptionAttrs val) |
304 | 0 | { |
305 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_ACTIVE) |
306 | 0 | return "active"; |
307 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_FORCE_RECONNECT) |
308 | 0 | return "force-reconnect"; |
309 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_HIDDEN) |
310 | 0 | return "hidden"; |
311 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_CATEGORY) |
312 | 0 | return "category"; |
313 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_CATEGORY_BOOT) |
314 | 0 | return "category-boot"; |
315 | 0 | if (val == FU_EFI_LOAD_OPTION_ATTR_CATEGORY_AP) |
316 | 0 | return "category-ap"; |
317 | 0 | return NULL; |
318 | 0 | } |
319 | | |
320 | | /** |
321 | | * fu_efi_load_option_kind_to_string: |
322 | | * @val: value, e.g. %FU_EFI_LOAD_OPTION_KIND_PATH |
323 | | * |
324 | | * Converts an enumerated value to a string. |
325 | | * |
326 | | * Returns: identifier string |
327 | | **/ |
328 | | const gchar * |
329 | | fu_efi_load_option_kind_to_string(FuEfiLoadOptionKind val) |
330 | 0 | { |
331 | 0 | if (val == FU_EFI_LOAD_OPTION_KIND_PATH) |
332 | 0 | return "path"; |
333 | 0 | if (val == FU_EFI_LOAD_OPTION_KIND_HIVE) |
334 | 0 | return "hive"; |
335 | 0 | if (val == FU_EFI_LOAD_OPTION_KIND_DATA) |
336 | 0 | return "data"; |
337 | 0 | return NULL; |
338 | 0 | } |
339 | | /** |
340 | | * fu_efi_load_option_kind_from_string: |
341 | | * @val: (nullable): a string, e.g. `path` |
342 | | * |
343 | | * Converts a string to an enumerated value. |
344 | | * |
345 | | * Returns: enumerated value |
346 | | **/ |
347 | | FuEfiLoadOptionKind |
348 | | fu_efi_load_option_kind_from_string(const gchar *val) |
349 | 0 | { |
350 | 0 | if (g_strcmp0(val, "path") == 0) |
351 | 0 | return FU_EFI_LOAD_OPTION_KIND_PATH; |
352 | 0 | if (g_strcmp0(val, "hive") == 0) |
353 | 0 | return FU_EFI_LOAD_OPTION_KIND_HIVE; |
354 | 0 | if (g_strcmp0(val, "data") == 0) |
355 | 0 | return FU_EFI_LOAD_OPTION_KIND_DATA; |
356 | 0 | return FU_EFI_LOAD_OPTION_KIND_UNKNOWN; |
357 | 0 | } |
358 | | |
359 | | /** |
360 | | * fu_efi_device_path_type_to_string: |
361 | | * @val: value, e.g. %FU_EFI_DEVICE_PATH_TYPE_ACPI |
362 | | * |
363 | | * Converts an enumerated value to a string. |
364 | | * |
365 | | * Returns: identifier string |
366 | | **/ |
367 | | static const gchar * |
368 | | fu_efi_device_path_type_to_string(FuEfiDevicePathType val) |
369 | 0 | { |
370 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_HARDWARE) |
371 | 0 | return "hardware"; |
372 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_ACPI) |
373 | 0 | return "acpi"; |
374 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_MESSAGE) |
375 | 0 | return "message"; |
376 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_MEDIA) |
377 | 0 | return "media"; |
378 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_BIOS_BOOT) |
379 | 0 | return "bios-boot"; |
380 | 0 | if (val == FU_EFI_DEVICE_PATH_TYPE_END) |
381 | 0 | return "end"; |
382 | 0 | return NULL; |
383 | 0 | } |
384 | | |
385 | | /** |
386 | | * fu_efi_hard_drive_device_path_subtype_to_string: |
387 | | * @val: value, e.g. %FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_CDROM |
388 | | * |
389 | | * Converts an enumerated value to a string. |
390 | | * |
391 | | * Returns: identifier string |
392 | | **/ |
393 | | static const gchar * |
394 | | fu_efi_hard_drive_device_path_subtype_to_string(FuEfiHardDriveDevicePathSubtype val) |
395 | 0 | { |
396 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE) |
397 | 0 | return "hard-drive"; |
398 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_CDROM) |
399 | 0 | return "cdrom"; |
400 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_VENDOR) |
401 | 0 | return "vendor"; |
402 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_FILE_PATH) |
403 | 0 | return "file-path"; |
404 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_MEDIA_PROTOCOL) |
405 | 0 | return "media-protocol"; |
406 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_PIWG_FIRMWARE_FILE) |
407 | 0 | return "piwg-firmware-file"; |
408 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_PIWG_FIRMWARE_VOLUME) |
409 | 0 | return "piwg-firmware-volume"; |
410 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_RELATIVE_OFFSET_RANGE) |
411 | 0 | return "relative-offset-range"; |
412 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_RAM_DISK_DEVICE_PATH) |
413 | 0 | return "ram-disk-device-path"; |
414 | 0 | return NULL; |
415 | 0 | } |
416 | | |
417 | | /** |
418 | | * fu_efi_hard_drive_device_path_partition_format_to_string: |
419 | | * @val: value, e.g. %FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE |
420 | | * |
421 | | * Converts an enumerated value to a string. |
422 | | * |
423 | | * Returns: identifier string |
424 | | **/ |
425 | | const gchar * |
426 | | fu_efi_hard_drive_device_path_partition_format_to_string(FuEfiHardDriveDevicePathPartitionFormat val) |
427 | 0 | { |
428 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR) |
429 | 0 | return "legacy-mbr"; |
430 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE) |
431 | 0 | return "guid-partition-table"; |
432 | 0 | return NULL; |
433 | 0 | } |
434 | | /** |
435 | | * fu_efi_hard_drive_device_path_partition_format_from_string: |
436 | | * @val: (nullable): a string, e.g. `guid-partition-table` |
437 | | * |
438 | | * Converts a string to an enumerated value. |
439 | | * |
440 | | * Returns: enumerated value |
441 | | **/ |
442 | | FuEfiHardDriveDevicePathPartitionFormat |
443 | | fu_efi_hard_drive_device_path_partition_format_from_string(const gchar *val) |
444 | 0 | { |
445 | 0 | if (g_strcmp0(val, "legacy-mbr") == 0) |
446 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR; |
447 | 0 | if (g_strcmp0(val, "guid-partition-table") == 0) |
448 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE; |
449 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR; |
450 | 0 | } |
451 | | |
452 | | /** |
453 | | * fu_efi_hard_drive_device_path_signature_type_to_string: |
454 | | * @val: value, e.g. %FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_ADDR1B8 |
455 | | * |
456 | | * Converts an enumerated value to a string. |
457 | | * |
458 | | * Returns: identifier string |
459 | | **/ |
460 | | const gchar * |
461 | | fu_efi_hard_drive_device_path_signature_type_to_string(FuEfiHardDriveDevicePathSignatureType val) |
462 | 0 | { |
463 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE) |
464 | 0 | return "none"; |
465 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_ADDR1B8) |
466 | 0 | return "addr1b8"; |
467 | 0 | if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID) |
468 | 0 | return "guid"; |
469 | 0 | return NULL; |
470 | 0 | } |
471 | | /** |
472 | | * fu_efi_hard_drive_device_path_signature_type_from_string: |
473 | | * @val: (nullable): a string, e.g. `addr1b8` |
474 | | * |
475 | | * Converts a string to an enumerated value. |
476 | | * |
477 | | * Returns: enumerated value |
478 | | **/ |
479 | | FuEfiHardDriveDevicePathSignatureType |
480 | | fu_efi_hard_drive_device_path_signature_type_from_string(const gchar *val) |
481 | 0 | { |
482 | 0 | if (g_strcmp0(val, "none") == 0) |
483 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE; |
484 | 0 | if (g_strcmp0(val, "addr1b8") == 0) |
485 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_ADDR1B8; |
486 | 0 | if (g_strcmp0(val, "guid") == 0) |
487 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID; |
488 | 0 | return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE; |
489 | 0 | } |
490 | | |
491 | | /** |
492 | | * fu_efi_variable_store_state_to_string: |
493 | | * @val: value, e.g. %FU_EFI_VARIABLE_STORE_STATE_HEALTHY |
494 | | * |
495 | | * Converts an enumerated value to a string. |
496 | | * |
497 | | * Returns: identifier string |
498 | | **/ |
499 | | const gchar * |
500 | | fu_efi_variable_store_state_to_string(FuEfiVariableStoreState val) |
501 | 112 | { |
502 | 112 | if (val == FU_EFI_VARIABLE_STORE_STATE_UNSET) |
503 | 15 | return "unset"; |
504 | 97 | if (val == FU_EFI_VARIABLE_STORE_STATE_HEALTHY) |
505 | 0 | return "healthy"; |
506 | 97 | if (val == FU_EFI_VARIABLE_STORE_STATE_EMPTY) |
507 | 18 | return "empty"; |
508 | 79 | return NULL; |
509 | 97 | } |
510 | | /** |
511 | | * fu_efi_variable_store_state_from_string: |
512 | | * @val: (nullable): a string, e.g. `healthy` |
513 | | * |
514 | | * Converts a string to an enumerated value. |
515 | | * |
516 | | * Returns: enumerated value |
517 | | **/ |
518 | | FuEfiVariableStoreState |
519 | | fu_efi_variable_store_state_from_string(const gchar *val) |
520 | 0 | { |
521 | 0 | if (g_strcmp0(val, "unset") == 0) |
522 | 0 | return FU_EFI_VARIABLE_STORE_STATE_UNSET; |
523 | 0 | if (g_strcmp0(val, "healthy") == 0) |
524 | 0 | return FU_EFI_VARIABLE_STORE_STATE_HEALTHY; |
525 | 0 | if (g_strcmp0(val, "empty") == 0) |
526 | 0 | return FU_EFI_VARIABLE_STORE_STATE_EMPTY; |
527 | 0 | return FU_EFI_VARIABLE_STORE_STATE_UNSET; |
528 | 0 | } |
529 | | |
530 | | /** |
531 | | * fu_efi_variable_store_format_to_string: |
532 | | * @val: value |
533 | | * |
534 | | * Converts an enumerated value to a string. |
535 | | * |
536 | | * Returns: identifier string |
537 | | **/ |
538 | | static const gchar * |
539 | | fu_efi_variable_store_format_to_string(FuEfiVariableStoreFormat val) |
540 | 1.83k | { |
541 | 1.83k | if (val == FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) |
542 | 0 | return "formatted"; |
543 | 1.83k | return NULL; |
544 | 1.83k | } |
545 | | |
546 | | /** |
547 | | * fu_efi_variable_state_to_string: |
548 | | * @val: value, e.g. %FU_EFI_VARIABLE_STATE_VARIABLE_IN_DELETED_TRANSITION |
549 | | * |
550 | | * Converts an enumerated value to a string. |
551 | | * |
552 | | * Returns: identifier string |
553 | | **/ |
554 | | const gchar * |
555 | | fu_efi_variable_state_to_string(FuEfiVariableState val) |
556 | 0 | { |
557 | 0 | if (val == FU_EFI_VARIABLE_STATE_UNSET) |
558 | 0 | return "unset"; |
559 | 0 | if (val == FU_EFI_VARIABLE_STATE_VARIABLE_IN_DELETED_TRANSITION) |
560 | 0 | return "variable-in-deleted-transition"; |
561 | 0 | if (val == FU_EFI_VARIABLE_STATE_VARIABLE_DELETED) |
562 | 0 | return "variable-deleted"; |
563 | 0 | if (val == FU_EFI_VARIABLE_STATE_VARIABLE_HEADER_VALID) |
564 | 0 | return "variable-header-valid"; |
565 | 0 | if (val == FU_EFI_VARIABLE_STATE_VARIABLE_ADDED) |
566 | 0 | return "variable-added"; |
567 | 0 | if (val == FU_EFI_VARIABLE_STATE_INTEL_VARIABLE_VALID) |
568 | 0 | return "intel-variable-valid"; |
569 | 0 | if (val == FU_EFI_VARIABLE_STATE_INTEL_VARIABLE_INVALID) |
570 | 0 | return "intel-variable-invalid"; |
571 | 0 | return NULL; |
572 | 0 | } |
573 | | /** |
574 | | * fu_efi_variable_state_from_string: |
575 | | * @val: (nullable): a string, e.g. `variable-in-deleted-transition` |
576 | | * |
577 | | * Converts a string to an enumerated value. |
578 | | * |
579 | | * Returns: enumerated value |
580 | | **/ |
581 | | FuEfiVariableState |
582 | | fu_efi_variable_state_from_string(const gchar *val) |
583 | 0 | { |
584 | 0 | if (g_strcmp0(val, "unset") == 0) |
585 | 0 | return FU_EFI_VARIABLE_STATE_UNSET; |
586 | 0 | if (g_strcmp0(val, "variable-in-deleted-transition") == 0) |
587 | 0 | return FU_EFI_VARIABLE_STATE_VARIABLE_IN_DELETED_TRANSITION; |
588 | 0 | if (g_strcmp0(val, "variable-deleted") == 0) |
589 | 0 | return FU_EFI_VARIABLE_STATE_VARIABLE_DELETED; |
590 | 0 | if (g_strcmp0(val, "variable-header-valid") == 0) |
591 | 0 | return FU_EFI_VARIABLE_STATE_VARIABLE_HEADER_VALID; |
592 | 0 | if (g_strcmp0(val, "variable-added") == 0) |
593 | 0 | return FU_EFI_VARIABLE_STATE_VARIABLE_ADDED; |
594 | 0 | if (g_strcmp0(val, "intel-variable-valid") == 0) |
595 | 0 | return FU_EFI_VARIABLE_STATE_INTEL_VARIABLE_VALID; |
596 | 0 | if (g_strcmp0(val, "intel-variable-invalid") == 0) |
597 | 0 | return FU_EFI_VARIABLE_STATE_INTEL_VARIABLE_INVALID; |
598 | 0 | return FU_EFI_VARIABLE_STATE_UNSET; |
599 | 0 | } |
600 | | |
601 | | /** |
602 | | * fu_efi_variable_attrs_to_string: |
603 | | * @val: value, e.g. %FU_EFI_VARIABLE_ATTR_NON_VOLATILE |
604 | | * |
605 | | * Converts an enumerated value to a string. |
606 | | * |
607 | | * Returns: identifier string |
608 | | * |
609 | | **/ |
610 | | gchar * |
611 | | fu_efi_variable_attrs_to_string(FuEfiVariableAttrs val) |
612 | 0 | { |
613 | 0 | const gchar *data[8] = {0}; |
614 | 0 | guint idx = 0; |
615 | 0 | if (val == FU_EFI_VARIABLE_ATTR_NONE) |
616 | 0 | return g_strdup("none"); |
617 | 0 | if (val & FU_EFI_VARIABLE_ATTR_NON_VOLATILE) |
618 | 0 | data[idx++] = "non-volatile"; |
619 | 0 | if (val & FU_EFI_VARIABLE_ATTR_BOOTSERVICE_ACCESS) |
620 | 0 | data[idx++] = "bootservice-access"; |
621 | 0 | if (val & FU_EFI_VARIABLE_ATTR_RUNTIME_ACCESS) |
622 | 0 | data[idx++] = "runtime-access"; |
623 | 0 | if (val & FU_EFI_VARIABLE_ATTR_HARDWARE_ERROR_RECORD) |
624 | 0 | data[idx++] = "hardware-error-record"; |
625 | 0 | if (val & FU_EFI_VARIABLE_ATTR_AUTHENTICATED_WRITE_ACCESS) |
626 | 0 | data[idx++] = "authenticated-write-access"; |
627 | 0 | if (val & FU_EFI_VARIABLE_ATTR_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) |
628 | 0 | data[idx++] = "time-based-authenticated-write-access"; |
629 | 0 | if (val & FU_EFI_VARIABLE_ATTR_APPEND_WRITE) |
630 | 0 | data[idx++] = "append-write"; |
631 | 0 | return g_strjoinv(",", (gchar **)data); |
632 | 0 | } |
633 | | /** |
634 | | * fu_efi_variable_attrs_from_string: |
635 | | * @val: (nullable): a string, e.g. `non-volatile` |
636 | | * |
637 | | * Converts a string to an enumerated value. |
638 | | * |
639 | | * Returns: enumerated value |
640 | | **/ |
641 | | FuEfiVariableAttrs |
642 | | fu_efi_variable_attrs_from_string(const gchar *val) |
643 | 0 | { |
644 | 0 | FuEfiVariableAttrs value = 0; |
645 | 0 | g_auto(GStrv) split = NULL; |
646 | 0 | g_return_val_if_fail(val != NULL, 0); |
647 | 0 | split = g_strsplit(val, ",", -1); |
648 | 0 | for (guint i = 0; split[i] != NULL; i++) { |
649 | 0 | if (g_strcmp0(split[i], "none") == 0) { |
650 | 0 | value |= FU_EFI_VARIABLE_ATTR_NONE; |
651 | 0 | continue; |
652 | 0 | } |
653 | 0 | if (g_strcmp0(split[i], "non-volatile") == 0) { |
654 | 0 | value |= FU_EFI_VARIABLE_ATTR_NON_VOLATILE; |
655 | 0 | continue; |
656 | 0 | } |
657 | 0 | if (g_strcmp0(split[i], "bootservice-access") == 0) { |
658 | 0 | value |= FU_EFI_VARIABLE_ATTR_BOOTSERVICE_ACCESS; |
659 | 0 | continue; |
660 | 0 | } |
661 | 0 | if (g_strcmp0(split[i], "runtime-access") == 0) { |
662 | 0 | value |= FU_EFI_VARIABLE_ATTR_RUNTIME_ACCESS; |
663 | 0 | continue; |
664 | 0 | } |
665 | 0 | if (g_strcmp0(split[i], "hardware-error-record") == 0) { |
666 | 0 | value |= FU_EFI_VARIABLE_ATTR_HARDWARE_ERROR_RECORD; |
667 | 0 | continue; |
668 | 0 | } |
669 | 0 | if (g_strcmp0(split[i], "authenticated-write-access") == 0) { |
670 | 0 | value |= FU_EFI_VARIABLE_ATTR_AUTHENTICATED_WRITE_ACCESS; |
671 | 0 | continue; |
672 | 0 | } |
673 | 0 | if (g_strcmp0(split[i], "time-based-authenticated-write-access") == 0) { |
674 | 0 | value |= FU_EFI_VARIABLE_ATTR_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; |
675 | 0 | continue; |
676 | 0 | } |
677 | 0 | if (g_strcmp0(split[i], "append-write") == 0) { |
678 | 0 | value |= FU_EFI_VARIABLE_ATTR_APPEND_WRITE; |
679 | 0 | continue; |
680 | 0 | } |
681 | 0 | } |
682 | 0 | return value; |
683 | 0 | } |
684 | | |
685 | | /** |
686 | | * fu_struct_efi_file_ref: (skip): |
687 | | **/ |
688 | | FuStructEfiFile * |
689 | | fu_struct_efi_file_ref(FuStructEfiFile *st) |
690 | 0 | { |
691 | 0 | g_return_val_if_fail(st != NULL, NULL); |
692 | 0 | st->refcount++; |
693 | 0 | return st; |
694 | 0 | } |
695 | | /** |
696 | | * fu_struct_efi_file_unref: (skip): |
697 | | **/ |
698 | | void |
699 | | fu_struct_efi_file_unref(FuStructEfiFile *st) |
700 | 10.4k | { |
701 | 10.4k | g_return_if_fail(st != NULL); |
702 | 10.4k | if (st->refcount == 0) { |
703 | 0 | g_critical("FuStructEfiFile refcount already zero"); |
704 | 0 | return; |
705 | 0 | } |
706 | 10.4k | if (--st->refcount > 0) |
707 | 0 | return; |
708 | 10.4k | if (st->buf != NULL) |
709 | 8.49k | g_byte_array_unref(st->buf); |
710 | 10.4k | g_free(st); |
711 | 10.4k | } |
712 | | /** |
713 | | * fu_struct_efi_file_new_internal: (skip): |
714 | | **/ |
715 | | static FuStructEfiFile * |
716 | | fu_struct_efi_file_new_internal(void) |
717 | 10.2k | { |
718 | 10.2k | FuStructEfiFile *st = g_new0(FuStructEfiFile, 1); |
719 | 10.2k | st->refcount = 1; |
720 | 10.2k | return st; |
721 | 10.2k | } |
722 | | |
723 | | /* getters */ |
724 | | /** |
725 | | * fu_struct_efi_file_get_name: (skip): |
726 | | **/ |
727 | | const fwupd_guid_t * |
728 | | fu_struct_efi_file_get_name(const FuStructEfiFile *st) |
729 | 8.02k | { |
730 | 8.02k | g_return_val_if_fail(st != NULL, NULL); |
731 | 8.02k | return (const fwupd_guid_t *) (st->buf->data + 0); |
732 | 8.02k | } |
733 | | /** |
734 | | * fu_struct_efi_file_get_hdr_checksum: (skip): |
735 | | **/ |
736 | | guint8 |
737 | | fu_struct_efi_file_get_hdr_checksum(const FuStructEfiFile *st) |
738 | 0 | { |
739 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
740 | 0 | return st->buf->data[16]; |
741 | 0 | } |
742 | | /** |
743 | | * fu_struct_efi_file_get_data_checksum: (skip): |
744 | | **/ |
745 | | guint8 |
746 | | fu_struct_efi_file_get_data_checksum(const FuStructEfiFile *st) |
747 | 0 | { |
748 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
749 | 0 | return st->buf->data[17]; |
750 | 0 | } |
751 | | /** |
752 | | * fu_struct_efi_file_get_type: (skip): |
753 | | **/ |
754 | | FuEfiFileType |
755 | | fu_struct_efi_file_get_type(const FuStructEfiFile *st) |
756 | 8.02k | { |
757 | 8.02k | g_return_val_if_fail(st != NULL, 0x0); |
758 | 8.02k | return st->buf->data[18]; |
759 | 8.02k | } |
760 | | /** |
761 | | * fu_struct_efi_file_get_attrs: (skip): |
762 | | **/ |
763 | | guint8 |
764 | | fu_struct_efi_file_get_attrs(const FuStructEfiFile *st) |
765 | 8.02k | { |
766 | 8.02k | g_return_val_if_fail(st != NULL, 0x0); |
767 | 8.02k | return st->buf->data[19]; |
768 | 8.02k | } |
769 | | /** |
770 | | * fu_struct_efi_file_get_size: (skip): |
771 | | **/ |
772 | | guint32 |
773 | | fu_struct_efi_file_get_size(const FuStructEfiFile *st) |
774 | 8.08k | { |
775 | 8.08k | g_return_val_if_fail(st != NULL, 0x0); |
776 | 8.08k | return fu_memread_uint24(st->buf->data + 20, G_LITTLE_ENDIAN); |
777 | 8.08k | } |
778 | | /** |
779 | | * fu_struct_efi_file_get_state: (skip): |
780 | | **/ |
781 | | guint8 |
782 | | fu_struct_efi_file_get_state(const FuStructEfiFile *st) |
783 | 0 | { |
784 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
785 | 0 | return st->buf->data[23]; |
786 | 0 | } |
787 | | |
788 | | /* setters */ |
789 | | /** |
790 | | * fu_struct_efi_file_set_name: (skip): |
791 | | **/ |
792 | | void |
793 | | fu_struct_efi_file_set_name(FuStructEfiFile *st, const fwupd_guid_t *value) |
794 | 1.91k | { |
795 | 1.91k | g_return_if_fail(st != NULL); |
796 | 1.91k | g_return_if_fail(value != NULL); |
797 | 1.91k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
798 | 1.91k | } |
799 | | /** |
800 | | * fu_struct_efi_file_set_hdr_checksum: (skip): |
801 | | **/ |
802 | | void |
803 | | fu_struct_efi_file_set_hdr_checksum(FuStructEfiFile *st, guint8 value) |
804 | 3.82k | { |
805 | 3.82k | g_return_if_fail(st != NULL); |
806 | 3.82k | st->buf->data[16] = value; |
807 | 3.82k | } |
808 | | /** |
809 | | * fu_struct_efi_file_set_data_checksum: (skip): |
810 | | **/ |
811 | | void |
812 | | fu_struct_efi_file_set_data_checksum(FuStructEfiFile *st, guint8 value) |
813 | 1.91k | { |
814 | 1.91k | g_return_if_fail(st != NULL); |
815 | 1.91k | st->buf->data[17] = value; |
816 | 1.91k | } |
817 | | /** |
818 | | * fu_struct_efi_file_set_type: (skip): |
819 | | **/ |
820 | | void |
821 | | fu_struct_efi_file_set_type(FuStructEfiFile *st, FuEfiFileType value) |
822 | 1.91k | { |
823 | 1.91k | g_return_if_fail(st != NULL); |
824 | 1.91k | st->buf->data[18] = value; |
825 | 1.91k | } |
826 | | /** |
827 | | * fu_struct_efi_file_set_attrs: (skip): |
828 | | **/ |
829 | | void |
830 | | fu_struct_efi_file_set_attrs(FuStructEfiFile *st, guint8 value) |
831 | 1.91k | { |
832 | 1.91k | g_return_if_fail(st != NULL); |
833 | 1.91k | st->buf->data[19] = value; |
834 | 1.91k | } |
835 | | /** |
836 | | * fu_struct_efi_file_set_size: (skip): |
837 | | **/ |
838 | | void |
839 | | fu_struct_efi_file_set_size(FuStructEfiFile *st, guint32 value) |
840 | 1.91k | { |
841 | 1.91k | g_return_if_fail(st != NULL); |
842 | 1.91k | fu_memwrite_uint24(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
843 | 1.91k | } |
844 | | /** |
845 | | * fu_struct_efi_file_set_state: (skip): |
846 | | **/ |
847 | | void |
848 | | fu_struct_efi_file_set_state(FuStructEfiFile *st, guint8 value) |
849 | 2.13k | { |
850 | 2.13k | g_return_if_fail(st != NULL); |
851 | 2.13k | st->buf->data[23] = value; |
852 | 2.13k | } |
853 | | /** |
854 | | * fu_struct_efi_file_new: (skip): |
855 | | **/ |
856 | | FuStructEfiFile * |
857 | | fu_struct_efi_file_new(void) |
858 | 2.13k | { |
859 | 2.13k | FuStructEfiFile *st = fu_struct_efi_file_new_internal(); |
860 | 2.13k | st->buf = g_byte_array_sized_new(24); |
861 | 2.13k | fu_byte_array_set_size(st->buf, 24, 0x0); |
862 | 2.13k | fu_struct_efi_file_set_state(st, 0xF8); |
863 | 2.13k | return st; |
864 | 2.13k | } |
865 | | /** |
866 | | * fu_struct_efi_file_to_string: (skip): |
867 | | **/ |
868 | | static gchar * |
869 | | fu_struct_efi_file_to_string(const FuStructEfiFile *st) |
870 | 0 | { |
871 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiFile:\n"); |
872 | 0 | g_return_val_if_fail(st != NULL, NULL); |
873 | 0 | { |
874 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_file_get_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
875 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
876 | 0 | } |
877 | 0 | g_string_append_printf(str, " hdr_checksum: 0x%x\n", |
878 | 0 | (guint) fu_struct_efi_file_get_hdr_checksum(st)); |
879 | 0 | g_string_append_printf(str, " data_checksum: 0x%x\n", |
880 | 0 | (guint) fu_struct_efi_file_get_data_checksum(st)); |
881 | 0 | { |
882 | 0 | const gchar *tmp = fu_efi_file_type_to_string(fu_struct_efi_file_get_type(st)); |
883 | 0 | if (tmp != NULL) { |
884 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_file_get_type(st), tmp); |
885 | 0 | } else { |
886 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_file_get_type(st)); |
887 | 0 | } |
888 | 0 | } |
889 | 0 | g_string_append_printf(str, " attrs: 0x%x\n", |
890 | 0 | (guint) fu_struct_efi_file_get_attrs(st)); |
891 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
892 | 0 | (guint) fu_struct_efi_file_get_size(st)); |
893 | 0 | g_string_append_printf(str, " state: 0x%x\n", |
894 | 0 | (guint) fu_struct_efi_file_get_state(st)); |
895 | 0 | if (str->len > 0) |
896 | 0 | g_string_set_size(str, str->len - 1); |
897 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
898 | 0 | } |
899 | | static gboolean |
900 | | fu_struct_efi_file_validate_internal(FuStructEfiFile *st, GError **error) |
901 | 8.16k | { |
902 | 8.16k | g_return_val_if_fail(st != NULL, FALSE); |
903 | 8.16k | return TRUE; |
904 | 8.16k | } |
905 | | /** |
906 | | * fu_struct_efi_file_validate: (skip): |
907 | | **/ |
908 | | gboolean |
909 | | fu_struct_efi_file_validate(const guint8 *buf, gsize bufsz, gsize offset, GError **error) |
910 | 0 | { |
911 | 0 | GByteArray st_buf = {.data = (guint8 *) buf + offset, .len = bufsz - offset, }; |
912 | 0 | FuStructEfiFile st_tmp = {.buf = &st_buf }; |
913 | 0 | g_return_val_if_fail(buf != NULL, FALSE); |
914 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
915 | 0 | if (!fu_memchk_read(bufsz, offset, 24, error)) { |
916 | 0 | g_prefix_error_literal(error, "invalid struct FuStructEfiFile: "); |
917 | 0 | return FALSE; |
918 | 0 | } |
919 | 0 | if (!fu_struct_efi_file_validate_internal(&st_tmp, error)) |
920 | 0 | return FALSE; |
921 | 0 | return TRUE; |
922 | 0 | } |
923 | | static gboolean |
924 | | fu_struct_efi_file_parse_internal(FuStructEfiFile *st, GError **error) |
925 | 8.02k | { |
926 | 8.02k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
927 | 0 | g_autofree gchar *str = fu_struct_efi_file_to_string(st); |
928 | 0 | g_debug("%s", str); |
929 | 0 | } |
930 | 8.02k | if (!fu_struct_efi_file_validate_internal(st, error)) |
931 | 0 | return FALSE; |
932 | 8.02k | return TRUE; |
933 | 8.02k | } |
934 | | /** |
935 | | * fu_struct_efi_file_parse_stream: (skip): |
936 | | **/ |
937 | | FuStructEfiFile * |
938 | | fu_struct_efi_file_parse_stream(GInputStream *stream, gsize offset, GError **error) |
939 | 8.13k | { |
940 | 8.13k | g_autoptr(FuStructEfiFile) st = fu_struct_efi_file_new_internal(); |
941 | 8.13k | st->buf = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error); |
942 | 8.13k | if (st->buf == NULL) { |
943 | 0 | g_prefix_error(error, "FuStructEfiFile failed read of 0x%x: ", (guint) 24); |
944 | 0 | return NULL; |
945 | 0 | } |
946 | 8.13k | if (st->buf->len != 24) { |
947 | 109 | g_set_error(error, |
948 | 109 | FWUPD_ERROR, |
949 | 109 | FWUPD_ERROR_INVALID_DATA, |
950 | 109 | "FuStructEfiFile requested 0x%x and got 0x%x", |
951 | 109 | (guint) 24, |
952 | 109 | (guint) st->buf->len); |
953 | 109 | return NULL; |
954 | 109 | } |
955 | 8.02k | if (!fu_struct_efi_file_parse_internal(st, error)) |
956 | 0 | return NULL; |
957 | 8.02k | return g_steal_pointer(&st); |
958 | 8.02k | } |
959 | | /** |
960 | | * fu_struct_efi_file2_ref: (skip): |
961 | | **/ |
962 | | FuStructEfiFile2 * |
963 | | fu_struct_efi_file2_ref(FuStructEfiFile2 *st) |
964 | 0 | { |
965 | 0 | g_return_val_if_fail(st != NULL, NULL); |
966 | 0 | st->refcount++; |
967 | 0 | return st; |
968 | 0 | } |
969 | | /** |
970 | | * fu_struct_efi_file2_unref: (skip): |
971 | | **/ |
972 | | void |
973 | | fu_struct_efi_file2_unref(FuStructEfiFile2 *st) |
974 | 13 | { |
975 | 13 | g_return_if_fail(st != NULL); |
976 | 13 | if (st->refcount == 0) { |
977 | 0 | g_critical("FuStructEfiFile2 refcount already zero"); |
978 | 0 | return; |
979 | 0 | } |
980 | 13 | if (--st->refcount > 0) |
981 | 0 | return; |
982 | 13 | if (st->buf != NULL) |
983 | 13 | g_byte_array_unref(st->buf); |
984 | 13 | g_free(st); |
985 | 13 | } |
986 | | /** |
987 | | * fu_struct_efi_file2_new_internal: (skip): |
988 | | **/ |
989 | | static FuStructEfiFile2 * |
990 | | fu_struct_efi_file2_new_internal(void) |
991 | 155 | { |
992 | 155 | FuStructEfiFile2 *st = g_new0(FuStructEfiFile2, 1); |
993 | 155 | st->refcount = 1; |
994 | 155 | return st; |
995 | 155 | } |
996 | | |
997 | | /* getters */ |
998 | | /** |
999 | | * fu_struct_efi_file2_get_extended_size: (skip): |
1000 | | **/ |
1001 | | guint64 |
1002 | | fu_struct_efi_file2_get_extended_size(const FuStructEfiFile2 *st) |
1003 | 142 | { |
1004 | 142 | g_return_val_if_fail(st != NULL, 0x0); |
1005 | 142 | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
1006 | 142 | } |
1007 | | |
1008 | | /* setters */ |
1009 | | /** |
1010 | | * fu_struct_efi_file2_to_string: (skip): |
1011 | | **/ |
1012 | | static gchar * |
1013 | | fu_struct_efi_file2_to_string(const FuStructEfiFile2 *st) |
1014 | 0 | { |
1015 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiFile2:\n"); |
1016 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1017 | 0 | g_string_append_printf(str, " extended_size: 0x%x\n", |
1018 | 0 | (guint) fu_struct_efi_file2_get_extended_size(st)); |
1019 | 0 | if (str->len > 0) |
1020 | 0 | g_string_set_size(str, str->len - 1); |
1021 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1022 | 0 | } |
1023 | | static gboolean |
1024 | | fu_struct_efi_file2_validate_internal(FuStructEfiFile2 *st, GError **error) |
1025 | 142 | { |
1026 | 142 | g_return_val_if_fail(st != NULL, FALSE); |
1027 | 142 | { |
1028 | 142 | GByteArray buf_tmp = { |
1029 | 142 | .data = (guint8*) st->buf->data + 0x0, |
1030 | 142 | .len = 24, |
1031 | 142 | }; |
1032 | 142 | FuStructEfiFile st_tmp = { .buf = &buf_tmp }; |
1033 | 142 | if (!fu_struct_efi_file_validate_internal(&st_tmp, error)) |
1034 | 0 | return FALSE; |
1035 | 142 | } |
1036 | 142 | return TRUE; |
1037 | 142 | } |
1038 | | static gboolean |
1039 | | fu_struct_efi_file2_parse_internal(FuStructEfiFile2 *st, GError **error) |
1040 | 142 | { |
1041 | 142 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1042 | 0 | g_autofree gchar *str = fu_struct_efi_file2_to_string(st); |
1043 | 0 | g_debug("%s", str); |
1044 | 0 | } |
1045 | 142 | if (!fu_struct_efi_file2_validate_internal(st, error)) |
1046 | 0 | return FALSE; |
1047 | 142 | return TRUE; |
1048 | 142 | } |
1049 | | /** |
1050 | | * fu_struct_efi_file2_parse_stream: (skip): |
1051 | | **/ |
1052 | | FuStructEfiFile2 * |
1053 | | fu_struct_efi_file2_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1054 | 155 | { |
1055 | 155 | g_autoptr(FuStructEfiFile2) st = fu_struct_efi_file2_new_internal(); |
1056 | 155 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
1057 | 155 | if (st->buf == NULL) { |
1058 | 0 | g_prefix_error(error, "FuStructEfiFile2 failed read of 0x%x: ", (guint) 32); |
1059 | 0 | return NULL; |
1060 | 0 | } |
1061 | 155 | if (st->buf->len != 32) { |
1062 | 13 | g_set_error(error, |
1063 | 13 | FWUPD_ERROR, |
1064 | 13 | FWUPD_ERROR_INVALID_DATA, |
1065 | 13 | "FuStructEfiFile2 requested 0x%x and got 0x%x", |
1066 | 13 | (guint) 32, |
1067 | 13 | (guint) st->buf->len); |
1068 | 13 | return NULL; |
1069 | 13 | } |
1070 | 142 | if (!fu_struct_efi_file2_parse_internal(st, error)) |
1071 | 0 | return NULL; |
1072 | 142 | return g_steal_pointer(&st); |
1073 | 142 | } |
1074 | | /** |
1075 | | * fu_struct_efi_section_compression_ref: (skip): |
1076 | | **/ |
1077 | | FuStructEfiSectionCompression * |
1078 | | fu_struct_efi_section_compression_ref(FuStructEfiSectionCompression *st) |
1079 | 0 | { |
1080 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1081 | 0 | st->refcount++; |
1082 | 0 | return st; |
1083 | 0 | } |
1084 | | /** |
1085 | | * fu_struct_efi_section_compression_unref: (skip): |
1086 | | **/ |
1087 | | void |
1088 | | fu_struct_efi_section_compression_unref(FuStructEfiSectionCompression *st) |
1089 | 2.89k | { |
1090 | 2.89k | g_return_if_fail(st != NULL); |
1091 | 2.89k | if (st->refcount == 0) { |
1092 | 0 | g_critical("FuStructEfiSectionCompression refcount already zero"); |
1093 | 0 | return; |
1094 | 0 | } |
1095 | 2.89k | if (--st->refcount > 0) |
1096 | 0 | return; |
1097 | 2.89k | if (st->buf != NULL) |
1098 | 2.88k | g_byte_array_unref(st->buf); |
1099 | 2.89k | g_free(st); |
1100 | 2.89k | } |
1101 | | /** |
1102 | | * fu_struct_efi_section_compression_new_internal: (skip): |
1103 | | **/ |
1104 | | static FuStructEfiSectionCompression * |
1105 | | fu_struct_efi_section_compression_new_internal(void) |
1106 | 2.89k | { |
1107 | 2.89k | FuStructEfiSectionCompression *st = g_new0(FuStructEfiSectionCompression, 1); |
1108 | 2.89k | st->refcount = 1; |
1109 | 2.89k | return st; |
1110 | 2.89k | } |
1111 | | |
1112 | | /* getters */ |
1113 | | /** |
1114 | | * fu_struct_efi_section_compression_get_uncompressed_length: (skip): |
1115 | | **/ |
1116 | | guint32 |
1117 | | fu_struct_efi_section_compression_get_uncompressed_length(const FuStructEfiSectionCompression *st) |
1118 | 0 | { |
1119 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1120 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
1121 | 0 | } |
1122 | | /** |
1123 | | * fu_struct_efi_section_compression_get_compression_type: (skip): |
1124 | | **/ |
1125 | | FuEfiCompressionType |
1126 | | fu_struct_efi_section_compression_get_compression_type(const FuStructEfiSectionCompression *st) |
1127 | 2.87k | { |
1128 | 2.87k | g_return_val_if_fail(st != NULL, 0x0); |
1129 | 2.87k | return st->buf->data[4]; |
1130 | 2.87k | } |
1131 | | |
1132 | | /* setters */ |
1133 | | /** |
1134 | | * fu_struct_efi_section_compression_to_string: (skip): |
1135 | | **/ |
1136 | | static gchar * |
1137 | | fu_struct_efi_section_compression_to_string(const FuStructEfiSectionCompression *st) |
1138 | 0 | { |
1139 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSectionCompression:\n"); |
1140 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1141 | 0 | g_string_append_printf(str, " uncompressed_length: 0x%x\n", |
1142 | 0 | (guint) fu_struct_efi_section_compression_get_uncompressed_length(st)); |
1143 | 0 | { |
1144 | 0 | const gchar *tmp = fu_efi_compression_type_to_string(fu_struct_efi_section_compression_get_compression_type(st)); |
1145 | 0 | if (tmp != NULL) { |
1146 | 0 | g_string_append_printf(str, " compression_type: 0x%x [%s]\n", (guint) fu_struct_efi_section_compression_get_compression_type(st), tmp); |
1147 | 0 | } else { |
1148 | 0 | g_string_append_printf(str, " compression_type: 0x%x\n", (guint) fu_struct_efi_section_compression_get_compression_type(st)); |
1149 | 0 | } |
1150 | 0 | } |
1151 | 0 | if (str->len > 0) |
1152 | 0 | g_string_set_size(str, str->len - 1); |
1153 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1154 | 0 | } |
1155 | | static gboolean |
1156 | | fu_struct_efi_section_compression_validate_internal(FuStructEfiSectionCompression *st, GError **error) |
1157 | 2.87k | { |
1158 | 2.87k | g_return_val_if_fail(st != NULL, FALSE); |
1159 | 2.87k | return TRUE; |
1160 | 2.87k | } |
1161 | | static gboolean |
1162 | | fu_struct_efi_section_compression_parse_internal(FuStructEfiSectionCompression *st, GError **error) |
1163 | 2.87k | { |
1164 | 2.87k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1165 | 0 | g_autofree gchar *str = fu_struct_efi_section_compression_to_string(st); |
1166 | 0 | g_debug("%s", str); |
1167 | 0 | } |
1168 | 2.87k | if (!fu_struct_efi_section_compression_validate_internal(st, error)) |
1169 | 0 | return FALSE; |
1170 | 2.87k | return TRUE; |
1171 | 2.87k | } |
1172 | | /** |
1173 | | * fu_struct_efi_section_compression_parse_stream: (skip): |
1174 | | **/ |
1175 | | FuStructEfiSectionCompression * |
1176 | | fu_struct_efi_section_compression_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1177 | 2.89k | { |
1178 | 2.89k | g_autoptr(FuStructEfiSectionCompression) st = fu_struct_efi_section_compression_new_internal(); |
1179 | 2.89k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
1180 | 2.89k | if (st->buf == NULL) { |
1181 | 13 | g_prefix_error(error, "FuStructEfiSectionCompression failed read of 0x%x: ", (guint) 5); |
1182 | 13 | return NULL; |
1183 | 13 | } |
1184 | 2.88k | if (st->buf->len != 5) { |
1185 | 4 | g_set_error(error, |
1186 | 4 | FWUPD_ERROR, |
1187 | 4 | FWUPD_ERROR_INVALID_DATA, |
1188 | 4 | "FuStructEfiSectionCompression requested 0x%x and got 0x%x", |
1189 | 4 | (guint) 5, |
1190 | 4 | (guint) st->buf->len); |
1191 | 4 | return NULL; |
1192 | 4 | } |
1193 | 2.87k | if (!fu_struct_efi_section_compression_parse_internal(st, error)) |
1194 | 0 | return NULL; |
1195 | 2.87k | return g_steal_pointer(&st); |
1196 | 2.87k | } |
1197 | | /** |
1198 | | * fu_struct_efi_lz77_decompressor_header_ref: (skip): |
1199 | | **/ |
1200 | | FuStructEfiLz77DecompressorHeader * |
1201 | | fu_struct_efi_lz77_decompressor_header_ref(FuStructEfiLz77DecompressorHeader *st) |
1202 | 0 | { |
1203 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1204 | 0 | st->refcount++; |
1205 | 0 | return st; |
1206 | 0 | } |
1207 | | /** |
1208 | | * fu_struct_efi_lz77_decompressor_header_unref: (skip): |
1209 | | **/ |
1210 | | void |
1211 | | fu_struct_efi_lz77_decompressor_header_unref(FuStructEfiLz77DecompressorHeader *st) |
1212 | 2.16k | { |
1213 | 2.16k | g_return_if_fail(st != NULL); |
1214 | 2.16k | if (st->refcount == 0) { |
1215 | 0 | g_critical("FuStructEfiLz77DecompressorHeader refcount already zero"); |
1216 | 0 | return; |
1217 | 0 | } |
1218 | 2.16k | if (--st->refcount > 0) |
1219 | 0 | return; |
1220 | 2.16k | if (st->buf != NULL) |
1221 | 2.16k | g_byte_array_unref(st->buf); |
1222 | 2.16k | g_free(st); |
1223 | 2.16k | } |
1224 | | /** |
1225 | | * fu_struct_efi_lz77_decompressor_header_new_internal: (skip): |
1226 | | **/ |
1227 | | static FuStructEfiLz77DecompressorHeader * |
1228 | | fu_struct_efi_lz77_decompressor_header_new_internal(void) |
1229 | 2.16k | { |
1230 | 2.16k | FuStructEfiLz77DecompressorHeader *st = g_new0(FuStructEfiLz77DecompressorHeader, 1); |
1231 | 2.16k | st->refcount = 1; |
1232 | 2.16k | return st; |
1233 | 2.16k | } |
1234 | | |
1235 | | /* getters */ |
1236 | | /** |
1237 | | * fu_struct_efi_lz77_decompressor_header_get_src_size: (skip): |
1238 | | **/ |
1239 | | guint32 |
1240 | | fu_struct_efi_lz77_decompressor_header_get_src_size(const FuStructEfiLz77DecompressorHeader *st) |
1241 | 2.16k | { |
1242 | 2.16k | g_return_val_if_fail(st != NULL, 0x0); |
1243 | 2.16k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
1244 | 2.16k | } |
1245 | | /** |
1246 | | * fu_struct_efi_lz77_decompressor_header_get_dst_size: (skip): |
1247 | | **/ |
1248 | | guint32 |
1249 | | fu_struct_efi_lz77_decompressor_header_get_dst_size(const FuStructEfiLz77DecompressorHeader *st) |
1250 | 2.10k | { |
1251 | 2.10k | g_return_val_if_fail(st != NULL, 0x0); |
1252 | 2.10k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1253 | 2.10k | } |
1254 | | |
1255 | | /* setters */ |
1256 | | /** |
1257 | | * fu_struct_efi_lz77_decompressor_header_to_string: (skip): |
1258 | | **/ |
1259 | | static gchar * |
1260 | | fu_struct_efi_lz77_decompressor_header_to_string(const FuStructEfiLz77DecompressorHeader *st) |
1261 | 0 | { |
1262 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiLz77DecompressorHeader:\n"); |
1263 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1264 | 0 | g_string_append_printf(str, " src_size: 0x%x\n", |
1265 | 0 | (guint) fu_struct_efi_lz77_decompressor_header_get_src_size(st)); |
1266 | 0 | g_string_append_printf(str, " dst_size: 0x%x\n", |
1267 | 0 | (guint) fu_struct_efi_lz77_decompressor_header_get_dst_size(st)); |
1268 | 0 | if (str->len > 0) |
1269 | 0 | g_string_set_size(str, str->len - 1); |
1270 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1271 | 0 | } |
1272 | | static gboolean |
1273 | | fu_struct_efi_lz77_decompressor_header_validate_internal(FuStructEfiLz77DecompressorHeader *st, GError **error) |
1274 | 2.16k | { |
1275 | 2.16k | g_return_val_if_fail(st != NULL, FALSE); |
1276 | 2.16k | return TRUE; |
1277 | 2.16k | } |
1278 | | static gboolean |
1279 | | fu_struct_efi_lz77_decompressor_header_parse_internal(FuStructEfiLz77DecompressorHeader *st, GError **error) |
1280 | 2.16k | { |
1281 | 2.16k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1282 | 0 | g_autofree gchar *str = fu_struct_efi_lz77_decompressor_header_to_string(st); |
1283 | 0 | g_debug("%s", str); |
1284 | 0 | } |
1285 | 2.16k | if (!fu_struct_efi_lz77_decompressor_header_validate_internal(st, error)) |
1286 | 0 | return FALSE; |
1287 | 2.16k | return TRUE; |
1288 | 2.16k | } |
1289 | | /** |
1290 | | * fu_struct_efi_lz77_decompressor_header_parse_stream: (skip): |
1291 | | **/ |
1292 | | FuStructEfiLz77DecompressorHeader * |
1293 | | fu_struct_efi_lz77_decompressor_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1294 | 2.16k | { |
1295 | 2.16k | g_autoptr(FuStructEfiLz77DecompressorHeader) st = fu_struct_efi_lz77_decompressor_header_new_internal(); |
1296 | 2.16k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1297 | 2.16k | if (st->buf == NULL) { |
1298 | 0 | g_prefix_error(error, "FuStructEfiLz77DecompressorHeader failed read of 0x%x: ", (guint) 8); |
1299 | 0 | return NULL; |
1300 | 0 | } |
1301 | 2.16k | if (st->buf->len != 8) { |
1302 | 5 | g_set_error(error, |
1303 | 5 | FWUPD_ERROR, |
1304 | 5 | FWUPD_ERROR_INVALID_DATA, |
1305 | 5 | "FuStructEfiLz77DecompressorHeader requested 0x%x and got 0x%x", |
1306 | 5 | (guint) 8, |
1307 | 5 | (guint) st->buf->len); |
1308 | 5 | return NULL; |
1309 | 5 | } |
1310 | 2.16k | if (!fu_struct_efi_lz77_decompressor_header_parse_internal(st, error)) |
1311 | 0 | return NULL; |
1312 | 2.16k | return g_steal_pointer(&st); |
1313 | 2.16k | } |
1314 | | /** |
1315 | | * fu_struct_efi_section_ref: (skip): |
1316 | | **/ |
1317 | | FuStructEfiSection * |
1318 | | fu_struct_efi_section_ref(FuStructEfiSection *st) |
1319 | 0 | { |
1320 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1321 | 0 | st->refcount++; |
1322 | 0 | return st; |
1323 | 0 | } |
1324 | | /** |
1325 | | * fu_struct_efi_section_unref: (skip): |
1326 | | **/ |
1327 | | void |
1328 | | fu_struct_efi_section_unref(FuStructEfiSection *st) |
1329 | 32.4k | { |
1330 | 32.4k | g_return_if_fail(st != NULL); |
1331 | 32.4k | if (st->refcount == 0) { |
1332 | 0 | g_critical("FuStructEfiSection refcount already zero"); |
1333 | 0 | return; |
1334 | 0 | } |
1335 | 32.4k | if (--st->refcount > 0) |
1336 | 0 | return; |
1337 | 32.4k | if (st->buf != NULL) |
1338 | 29.9k | g_byte_array_unref(st->buf); |
1339 | 32.4k | g_free(st); |
1340 | 32.4k | } |
1341 | | /** |
1342 | | * fu_struct_efi_section_new_internal: (skip): |
1343 | | **/ |
1344 | | static FuStructEfiSection * |
1345 | | fu_struct_efi_section_new_internal(void) |
1346 | 32.4k | { |
1347 | 32.4k | FuStructEfiSection *st = g_new0(FuStructEfiSection, 1); |
1348 | 32.4k | st->refcount = 1; |
1349 | 32.4k | return st; |
1350 | 32.4k | } |
1351 | | |
1352 | | /* getters */ |
1353 | | /** |
1354 | | * fu_struct_efi_section_get_size: (skip): |
1355 | | **/ |
1356 | | guint32 |
1357 | | fu_struct_efi_section_get_size(const FuStructEfiSection *st) |
1358 | 58.9k | { |
1359 | 58.9k | g_return_val_if_fail(st != NULL, 0x0); |
1360 | 58.9k | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1361 | 58.9k | } |
1362 | | /** |
1363 | | * fu_struct_efi_section_get_type: (skip): |
1364 | | **/ |
1365 | | FuEfiSectionType |
1366 | | fu_struct_efi_section_get_type(const FuStructEfiSection *st) |
1367 | 29.2k | { |
1368 | 29.2k | g_return_val_if_fail(st != NULL, 0x0); |
1369 | 29.2k | return st->buf->data[3]; |
1370 | 29.2k | } |
1371 | | |
1372 | | /* setters */ |
1373 | | /** |
1374 | | * fu_struct_efi_section_set_size: (skip): |
1375 | | **/ |
1376 | | void |
1377 | | fu_struct_efi_section_set_size(FuStructEfiSection *st, guint32 value) |
1378 | 2.52k | { |
1379 | 2.52k | g_return_if_fail(st != NULL); |
1380 | 2.52k | fu_memwrite_uint24(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
1381 | 2.52k | } |
1382 | | /** |
1383 | | * fu_struct_efi_section_set_type: (skip): |
1384 | | **/ |
1385 | | void |
1386 | | fu_struct_efi_section_set_type(FuStructEfiSection *st, FuEfiSectionType value) |
1387 | 2.52k | { |
1388 | 2.52k | g_return_if_fail(st != NULL); |
1389 | 2.52k | st->buf->data[3] = value; |
1390 | 2.52k | } |
1391 | | /** |
1392 | | * fu_struct_efi_section_new: (skip): |
1393 | | **/ |
1394 | | FuStructEfiSection * |
1395 | | fu_struct_efi_section_new(void) |
1396 | 2.70k | { |
1397 | 2.70k | FuStructEfiSection *st = fu_struct_efi_section_new_internal(); |
1398 | 2.70k | st->buf = g_byte_array_sized_new(4); |
1399 | 2.70k | fu_byte_array_set_size(st->buf, 4, 0x0); |
1400 | 2.70k | return st; |
1401 | 2.70k | } |
1402 | | /** |
1403 | | * fu_struct_efi_section_to_string: (skip): |
1404 | | **/ |
1405 | | static gchar * |
1406 | | fu_struct_efi_section_to_string(const FuStructEfiSection *st) |
1407 | 0 | { |
1408 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSection:\n"); |
1409 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1410 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
1411 | 0 | (guint) fu_struct_efi_section_get_size(st)); |
1412 | 0 | { |
1413 | 0 | const gchar *tmp = fu_efi_section_type_to_string(fu_struct_efi_section_get_type(st)); |
1414 | 0 | if (tmp != NULL) { |
1415 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_section_get_type(st), tmp); |
1416 | 0 | } else { |
1417 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_section_get_type(st)); |
1418 | 0 | } |
1419 | 0 | } |
1420 | 0 | if (str->len > 0) |
1421 | 0 | g_string_set_size(str, str->len - 1); |
1422 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1423 | 0 | } |
1424 | | static gboolean |
1425 | | fu_struct_efi_section_validate_internal(FuStructEfiSection *st, GError **error) |
1426 | 29.6k | { |
1427 | 29.6k | g_return_val_if_fail(st != NULL, FALSE); |
1428 | 29.6k | return TRUE; |
1429 | 29.6k | } |
1430 | | static gboolean |
1431 | | fu_struct_efi_section_parse_internal(FuStructEfiSection *st, GError **error) |
1432 | 29.6k | { |
1433 | 29.6k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1434 | 0 | g_autofree gchar *str = fu_struct_efi_section_to_string(st); |
1435 | 0 | g_debug("%s", str); |
1436 | 0 | } |
1437 | 29.6k | if (!fu_struct_efi_section_validate_internal(st, error)) |
1438 | 0 | return FALSE; |
1439 | 29.6k | return TRUE; |
1440 | 29.6k | } |
1441 | | /** |
1442 | | * fu_struct_efi_section_parse_stream: (skip): |
1443 | | **/ |
1444 | | FuStructEfiSection * |
1445 | | fu_struct_efi_section_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1446 | 29.7k | { |
1447 | 29.7k | g_autoptr(FuStructEfiSection) st = fu_struct_efi_section_new_internal(); |
1448 | 29.7k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
1449 | 29.7k | if (st->buf == NULL) { |
1450 | 0 | g_prefix_error(error, "FuStructEfiSection failed read of 0x%x: ", (guint) 4); |
1451 | 0 | return NULL; |
1452 | 0 | } |
1453 | 29.7k | if (st->buf->len != 4) { |
1454 | 69 | g_set_error(error, |
1455 | 69 | FWUPD_ERROR, |
1456 | 69 | FWUPD_ERROR_INVALID_DATA, |
1457 | 69 | "FuStructEfiSection requested 0x%x and got 0x%x", |
1458 | 69 | (guint) 4, |
1459 | 69 | (guint) st->buf->len); |
1460 | 69 | return NULL; |
1461 | 69 | } |
1462 | 29.6k | if (!fu_struct_efi_section_parse_internal(st, error)) |
1463 | 0 | return NULL; |
1464 | 29.6k | return g_steal_pointer(&st); |
1465 | 29.6k | } |
1466 | | /** |
1467 | | * fu_struct_efi_section2_ref: (skip): |
1468 | | **/ |
1469 | | FuStructEfiSection2 * |
1470 | | fu_struct_efi_section2_ref(FuStructEfiSection2 *st) |
1471 | 0 | { |
1472 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1473 | 0 | st->refcount++; |
1474 | 0 | return st; |
1475 | 0 | } |
1476 | | /** |
1477 | | * fu_struct_efi_section2_unref: (skip): |
1478 | | **/ |
1479 | | void |
1480 | | fu_struct_efi_section2_unref(FuStructEfiSection2 *st) |
1481 | 369 | { |
1482 | 369 | g_return_if_fail(st != NULL); |
1483 | 369 | if (st->refcount == 0) { |
1484 | 0 | g_critical("FuStructEfiSection2 refcount already zero"); |
1485 | 0 | return; |
1486 | 0 | } |
1487 | 369 | if (--st->refcount > 0) |
1488 | 0 | return; |
1489 | 369 | if (st->buf != NULL) |
1490 | 369 | g_byte_array_unref(st->buf); |
1491 | 369 | g_free(st); |
1492 | 369 | } |
1493 | | /** |
1494 | | * fu_struct_efi_section2_new_internal: (skip): |
1495 | | **/ |
1496 | | static FuStructEfiSection2 * |
1497 | | fu_struct_efi_section2_new_internal(void) |
1498 | 369 | { |
1499 | 369 | FuStructEfiSection2 *st = g_new0(FuStructEfiSection2, 1); |
1500 | 369 | st->refcount = 1; |
1501 | 369 | return st; |
1502 | 369 | } |
1503 | | |
1504 | | /* getters */ |
1505 | | /** |
1506 | | * fu_struct_efi_section2_get_size: (skip): |
1507 | | **/ |
1508 | | static guint32 |
1509 | | fu_struct_efi_section2_get_size(const FuStructEfiSection2 *st) |
1510 | 350 | { |
1511 | 350 | g_return_val_if_fail(st != NULL, 0x0); |
1512 | 350 | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1513 | 350 | } |
1514 | | /** |
1515 | | * fu_struct_efi_section2_get_type: (skip): |
1516 | | **/ |
1517 | | FuEfiSectionType |
1518 | | fu_struct_efi_section2_get_type(const FuStructEfiSection2 *st) |
1519 | 350 | { |
1520 | 350 | g_return_val_if_fail(st != NULL, 0x0); |
1521 | 350 | return st->buf->data[3]; |
1522 | 350 | } |
1523 | | /** |
1524 | | * fu_struct_efi_section2_get_extended_size: (skip): |
1525 | | **/ |
1526 | | guint32 |
1527 | | fu_struct_efi_section2_get_extended_size(const FuStructEfiSection2 *st) |
1528 | 350 | { |
1529 | 350 | g_return_val_if_fail(st != NULL, 0x0); |
1530 | 350 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1531 | 350 | } |
1532 | | |
1533 | | /* setters */ |
1534 | | /** |
1535 | | * fu_struct_efi_section2_to_string: (skip): |
1536 | | **/ |
1537 | | static gchar * |
1538 | | fu_struct_efi_section2_to_string(const FuStructEfiSection2 *st) |
1539 | 0 | { |
1540 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSection2:\n"); |
1541 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1542 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
1543 | 0 | (guint) fu_struct_efi_section2_get_size(st)); |
1544 | 0 | { |
1545 | 0 | const gchar *tmp = fu_efi_section_type_to_string(fu_struct_efi_section2_get_type(st)); |
1546 | 0 | if (tmp != NULL) { |
1547 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_section2_get_type(st), tmp); |
1548 | 0 | } else { |
1549 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_section2_get_type(st)); |
1550 | 0 | } |
1551 | 0 | } |
1552 | 0 | g_string_append_printf(str, " extended_size: 0x%x\n", |
1553 | 0 | (guint) fu_struct_efi_section2_get_extended_size(st)); |
1554 | 0 | if (str->len > 0) |
1555 | 0 | g_string_set_size(str, str->len - 1); |
1556 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1557 | 0 | } |
1558 | | static gboolean |
1559 | | fu_struct_efi_section2_validate_internal(FuStructEfiSection2 *st, GError **error) |
1560 | 350 | { |
1561 | 350 | g_return_val_if_fail(st != NULL, FALSE); |
1562 | 350 | if (fu_struct_efi_section2_get_size(st) != 0xFFFFFF) { |
1563 | 0 | g_set_error(error, |
1564 | 0 | FWUPD_ERROR, |
1565 | 0 | FWUPD_ERROR_INVALID_DATA, |
1566 | 0 | "constant FuStructEfiSection2.size was not valid, " |
1567 | 0 | "expected 0x%x and got 0x%x", |
1568 | 0 | (guint) 0xFFFFFF, |
1569 | 0 | (guint) fu_struct_efi_section2_get_size(st)); |
1570 | 0 | return FALSE; |
1571 | 0 | } |
1572 | 350 | return TRUE; |
1573 | 350 | } |
1574 | | static gboolean |
1575 | | fu_struct_efi_section2_parse_internal(FuStructEfiSection2 *st, GError **error) |
1576 | 350 | { |
1577 | 350 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1578 | 0 | g_autofree gchar *str = fu_struct_efi_section2_to_string(st); |
1579 | 0 | g_debug("%s", str); |
1580 | 0 | } |
1581 | 350 | if (!fu_struct_efi_section2_validate_internal(st, error)) |
1582 | 0 | return FALSE; |
1583 | 350 | return TRUE; |
1584 | 350 | } |
1585 | | /** |
1586 | | * fu_struct_efi_section2_parse_stream: (skip): |
1587 | | **/ |
1588 | | FuStructEfiSection2 * |
1589 | | fu_struct_efi_section2_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1590 | 369 | { |
1591 | 369 | g_autoptr(FuStructEfiSection2) st = fu_struct_efi_section2_new_internal(); |
1592 | 369 | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1593 | 369 | if (st->buf == NULL) { |
1594 | 0 | g_prefix_error(error, "FuStructEfiSection2 failed read of 0x%x: ", (guint) 8); |
1595 | 0 | return NULL; |
1596 | 0 | } |
1597 | 369 | if (st->buf->len != 8) { |
1598 | 19 | g_set_error(error, |
1599 | 19 | FWUPD_ERROR, |
1600 | 19 | FWUPD_ERROR_INVALID_DATA, |
1601 | 19 | "FuStructEfiSection2 requested 0x%x and got 0x%x", |
1602 | 19 | (guint) 8, |
1603 | 19 | (guint) st->buf->len); |
1604 | 19 | return NULL; |
1605 | 19 | } |
1606 | 350 | if (!fu_struct_efi_section2_parse_internal(st, error)) |
1607 | 0 | return NULL; |
1608 | 350 | return g_steal_pointer(&st); |
1609 | 350 | } |
1610 | | /** |
1611 | | * fu_struct_efi_section_freeform_subtype_guid_ref: (skip): |
1612 | | **/ |
1613 | | FuStructEfiSectionFreeformSubtypeGuid * |
1614 | | fu_struct_efi_section_freeform_subtype_guid_ref(FuStructEfiSectionFreeformSubtypeGuid *st) |
1615 | 0 | { |
1616 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1617 | 0 | st->refcount++; |
1618 | 0 | return st; |
1619 | 0 | } |
1620 | | /** |
1621 | | * fu_struct_efi_section_freeform_subtype_guid_unref: (skip): |
1622 | | **/ |
1623 | | void |
1624 | | fu_struct_efi_section_freeform_subtype_guid_unref(FuStructEfiSectionFreeformSubtypeGuid *st) |
1625 | 346 | { |
1626 | 346 | g_return_if_fail(st != NULL); |
1627 | 346 | if (st->refcount == 0) { |
1628 | 0 | g_critical("FuStructEfiSectionFreeformSubtypeGuid refcount already zero"); |
1629 | 0 | return; |
1630 | 0 | } |
1631 | 346 | if (--st->refcount > 0) |
1632 | 0 | return; |
1633 | 346 | if (st->buf != NULL) |
1634 | 344 | g_byte_array_unref(st->buf); |
1635 | 346 | g_free(st); |
1636 | 346 | } |
1637 | | /** |
1638 | | * fu_struct_efi_section_freeform_subtype_guid_new_internal: (skip): |
1639 | | **/ |
1640 | | static FuStructEfiSectionFreeformSubtypeGuid * |
1641 | | fu_struct_efi_section_freeform_subtype_guid_new_internal(void) |
1642 | 346 | { |
1643 | 346 | FuStructEfiSectionFreeformSubtypeGuid *st = g_new0(FuStructEfiSectionFreeformSubtypeGuid, 1); |
1644 | 346 | st->refcount = 1; |
1645 | 346 | return st; |
1646 | 346 | } |
1647 | | |
1648 | | /* getters */ |
1649 | | /** |
1650 | | * fu_struct_efi_section_freeform_subtype_guid_get_guid: (skip): |
1651 | | **/ |
1652 | | const fwupd_guid_t * |
1653 | | fu_struct_efi_section_freeform_subtype_guid_get_guid(const FuStructEfiSectionFreeformSubtypeGuid *st) |
1654 | 336 | { |
1655 | 336 | g_return_val_if_fail(st != NULL, NULL); |
1656 | 336 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1657 | 336 | } |
1658 | | |
1659 | | /* setters */ |
1660 | | /** |
1661 | | * fu_struct_efi_section_freeform_subtype_guid_to_string: (skip): |
1662 | | **/ |
1663 | | static gchar * |
1664 | | fu_struct_efi_section_freeform_subtype_guid_to_string(const FuStructEfiSectionFreeformSubtypeGuid *st) |
1665 | 0 | { |
1666 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSectionFreeformSubtypeGuid:\n"); |
1667 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1668 | 0 | { |
1669 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_freeform_subtype_guid_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
1670 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
1671 | 0 | } |
1672 | 0 | if (str->len > 0) |
1673 | 0 | g_string_set_size(str, str->len - 1); |
1674 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1675 | 0 | } |
1676 | | static gboolean |
1677 | | fu_struct_efi_section_freeform_subtype_guid_validate_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error) |
1678 | 336 | { |
1679 | 336 | g_return_val_if_fail(st != NULL, FALSE); |
1680 | 336 | return TRUE; |
1681 | 336 | } |
1682 | | static gboolean |
1683 | | fu_struct_efi_section_freeform_subtype_guid_parse_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error) |
1684 | 336 | { |
1685 | 336 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1686 | 0 | g_autofree gchar *str = fu_struct_efi_section_freeform_subtype_guid_to_string(st); |
1687 | 0 | g_debug("%s", str); |
1688 | 0 | } |
1689 | 336 | if (!fu_struct_efi_section_freeform_subtype_guid_validate_internal(st, error)) |
1690 | 0 | return FALSE; |
1691 | 336 | return TRUE; |
1692 | 336 | } |
1693 | | /** |
1694 | | * fu_struct_efi_section_freeform_subtype_guid_parse_stream: (skip): |
1695 | | **/ |
1696 | | FuStructEfiSectionFreeformSubtypeGuid * |
1697 | | fu_struct_efi_section_freeform_subtype_guid_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1698 | 346 | { |
1699 | 346 | g_autoptr(FuStructEfiSectionFreeformSubtypeGuid) st = fu_struct_efi_section_freeform_subtype_guid_new_internal(); |
1700 | 346 | st->buf = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error); |
1701 | 346 | if (st->buf == NULL) { |
1702 | 2 | g_prefix_error(error, "FuStructEfiSectionFreeformSubtypeGuid failed read of 0x%x: ", (guint) 16); |
1703 | 2 | return NULL; |
1704 | 2 | } |
1705 | 344 | if (st->buf->len != 16) { |
1706 | 8 | g_set_error(error, |
1707 | 8 | FWUPD_ERROR, |
1708 | 8 | FWUPD_ERROR_INVALID_DATA, |
1709 | 8 | "FuStructEfiSectionFreeformSubtypeGuid requested 0x%x and got 0x%x", |
1710 | 8 | (guint) 16, |
1711 | 8 | (guint) st->buf->len); |
1712 | 8 | return NULL; |
1713 | 8 | } |
1714 | 336 | if (!fu_struct_efi_section_freeform_subtype_guid_parse_internal(st, error)) |
1715 | 0 | return NULL; |
1716 | 336 | return g_steal_pointer(&st); |
1717 | 336 | } |
1718 | | /** |
1719 | | * fu_struct_efi_section_guid_defined_ref: (skip): |
1720 | | **/ |
1721 | | FuStructEfiSectionGuidDefined * |
1722 | | fu_struct_efi_section_guid_defined_ref(FuStructEfiSectionGuidDefined *st) |
1723 | 0 | { |
1724 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1725 | 0 | st->refcount++; |
1726 | 0 | return st; |
1727 | 0 | } |
1728 | | /** |
1729 | | * fu_struct_efi_section_guid_defined_unref: (skip): |
1730 | | **/ |
1731 | | void |
1732 | | fu_struct_efi_section_guid_defined_unref(FuStructEfiSectionGuidDefined *st) |
1733 | 1.28k | { |
1734 | 1.28k | g_return_if_fail(st != NULL); |
1735 | 1.28k | if (st->refcount == 0) { |
1736 | 0 | g_critical("FuStructEfiSectionGuidDefined refcount already zero"); |
1737 | 0 | return; |
1738 | 0 | } |
1739 | 1.28k | if (--st->refcount > 0) |
1740 | 0 | return; |
1741 | 1.28k | if (st->buf != NULL) |
1742 | 1.28k | g_byte_array_unref(st->buf); |
1743 | 1.28k | g_free(st); |
1744 | 1.28k | } |
1745 | | /** |
1746 | | * fu_struct_efi_section_guid_defined_new_internal: (skip): |
1747 | | **/ |
1748 | | static FuStructEfiSectionGuidDefined * |
1749 | | fu_struct_efi_section_guid_defined_new_internal(void) |
1750 | 1.28k | { |
1751 | 1.28k | FuStructEfiSectionGuidDefined *st = g_new0(FuStructEfiSectionGuidDefined, 1); |
1752 | 1.28k | st->refcount = 1; |
1753 | 1.28k | return st; |
1754 | 1.28k | } |
1755 | | |
1756 | | /* getters */ |
1757 | | /** |
1758 | | * fu_struct_efi_section_guid_defined_get_name: (skip): |
1759 | | **/ |
1760 | | const fwupd_guid_t * |
1761 | | fu_struct_efi_section_guid_defined_get_name(const FuStructEfiSectionGuidDefined *st) |
1762 | 934 | { |
1763 | 934 | g_return_val_if_fail(st != NULL, NULL); |
1764 | 934 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1765 | 934 | } |
1766 | | /** |
1767 | | * fu_struct_efi_section_guid_defined_get_offset: (skip): |
1768 | | **/ |
1769 | | guint16 |
1770 | | fu_struct_efi_section_guid_defined_get_offset(const FuStructEfiSectionGuidDefined *st) |
1771 | 1.86k | { |
1772 | 1.86k | g_return_val_if_fail(st != NULL, 0x0); |
1773 | 1.86k | return fu_memread_uint16(st->buf->data + 16, G_LITTLE_ENDIAN); |
1774 | 1.86k | } |
1775 | | /** |
1776 | | * fu_struct_efi_section_guid_defined_get_attr: (skip): |
1777 | | **/ |
1778 | | guint16 |
1779 | | fu_struct_efi_section_guid_defined_get_attr(const FuStructEfiSectionGuidDefined *st) |
1780 | 0 | { |
1781 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1782 | 0 | return fu_memread_uint16(st->buf->data + 18, G_LITTLE_ENDIAN); |
1783 | 0 | } |
1784 | | |
1785 | | /* setters */ |
1786 | | /** |
1787 | | * fu_struct_efi_section_guid_defined_set_name: (skip): |
1788 | | **/ |
1789 | | void |
1790 | | fu_struct_efi_section_guid_defined_set_name(FuStructEfiSectionGuidDefined *st, const fwupd_guid_t *value) |
1791 | 344 | { |
1792 | 344 | g_return_if_fail(st != NULL); |
1793 | 344 | g_return_if_fail(value != NULL); |
1794 | 344 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
1795 | 344 | } |
1796 | | /** |
1797 | | * fu_struct_efi_section_guid_defined_set_offset: (skip): |
1798 | | **/ |
1799 | | void |
1800 | | fu_struct_efi_section_guid_defined_set_offset(FuStructEfiSectionGuidDefined *st, guint16 value) |
1801 | 344 | { |
1802 | 344 | g_return_if_fail(st != NULL); |
1803 | 344 | fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
1804 | 344 | } |
1805 | | /** |
1806 | | * fu_struct_efi_section_guid_defined_set_attr: (skip): |
1807 | | **/ |
1808 | | void |
1809 | | fu_struct_efi_section_guid_defined_set_attr(FuStructEfiSectionGuidDefined *st, guint16 value) |
1810 | 0 | { |
1811 | 0 | g_return_if_fail(st != NULL); |
1812 | 0 | fu_memwrite_uint16(st->buf->data + 18, value, G_LITTLE_ENDIAN); |
1813 | 0 | } |
1814 | | /** |
1815 | | * fu_struct_efi_section_guid_defined_new: (skip): |
1816 | | **/ |
1817 | | FuStructEfiSectionGuidDefined * |
1818 | | fu_struct_efi_section_guid_defined_new(void) |
1819 | 344 | { |
1820 | 344 | FuStructEfiSectionGuidDefined *st = fu_struct_efi_section_guid_defined_new_internal(); |
1821 | 344 | st->buf = g_byte_array_sized_new(20); |
1822 | 344 | fu_byte_array_set_size(st->buf, 20, 0x0); |
1823 | 344 | return st; |
1824 | 344 | } |
1825 | | /** |
1826 | | * fu_struct_efi_section_guid_defined_to_string: (skip): |
1827 | | **/ |
1828 | | static gchar * |
1829 | | fu_struct_efi_section_guid_defined_to_string(const FuStructEfiSectionGuidDefined *st) |
1830 | 0 | { |
1831 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSectionGuidDefined:\n"); |
1832 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1833 | 0 | { |
1834 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_guid_defined_get_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
1835 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
1836 | 0 | } |
1837 | 0 | g_string_append_printf(str, " offset: 0x%x\n", |
1838 | 0 | (guint) fu_struct_efi_section_guid_defined_get_offset(st)); |
1839 | 0 | g_string_append_printf(str, " attr: 0x%x\n", |
1840 | 0 | (guint) fu_struct_efi_section_guid_defined_get_attr(st)); |
1841 | 0 | if (str->len > 0) |
1842 | 0 | g_string_set_size(str, str->len - 1); |
1843 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1844 | 0 | } |
1845 | | static gboolean |
1846 | | fu_struct_efi_section_guid_defined_validate_internal(FuStructEfiSectionGuidDefined *st, GError **error) |
1847 | 934 | { |
1848 | 934 | g_return_val_if_fail(st != NULL, FALSE); |
1849 | 934 | return TRUE; |
1850 | 934 | } |
1851 | | static gboolean |
1852 | | fu_struct_efi_section_guid_defined_parse_internal(FuStructEfiSectionGuidDefined *st, GError **error) |
1853 | 934 | { |
1854 | 934 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1855 | 0 | g_autofree gchar *str = fu_struct_efi_section_guid_defined_to_string(st); |
1856 | 0 | g_debug("%s", str); |
1857 | 0 | } |
1858 | 934 | if (!fu_struct_efi_section_guid_defined_validate_internal(st, error)) |
1859 | 0 | return FALSE; |
1860 | 934 | return TRUE; |
1861 | 934 | } |
1862 | | /** |
1863 | | * fu_struct_efi_section_guid_defined_parse_stream: (skip): |
1864 | | **/ |
1865 | | FuStructEfiSectionGuidDefined * |
1866 | | fu_struct_efi_section_guid_defined_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1867 | 945 | { |
1868 | 945 | g_autoptr(FuStructEfiSectionGuidDefined) st = fu_struct_efi_section_guid_defined_new_internal(); |
1869 | 945 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
1870 | 945 | if (st->buf == NULL) { |
1871 | 2 | g_prefix_error(error, "FuStructEfiSectionGuidDefined failed read of 0x%x: ", (guint) 20); |
1872 | 2 | return NULL; |
1873 | 2 | } |
1874 | 943 | if (st->buf->len != 20) { |
1875 | 9 | g_set_error(error, |
1876 | 9 | FWUPD_ERROR, |
1877 | 9 | FWUPD_ERROR_INVALID_DATA, |
1878 | 9 | "FuStructEfiSectionGuidDefined requested 0x%x and got 0x%x", |
1879 | 9 | (guint) 20, |
1880 | 9 | (guint) st->buf->len); |
1881 | 9 | return NULL; |
1882 | 9 | } |
1883 | 934 | if (!fu_struct_efi_section_guid_defined_parse_internal(st, error)) |
1884 | 0 | return NULL; |
1885 | 934 | return g_steal_pointer(&st); |
1886 | 934 | } |
1887 | | /** |
1888 | | * fu_struct_efi_volume_ref: (skip): |
1889 | | **/ |
1890 | | FuStructEfiVolume * |
1891 | | fu_struct_efi_volume_ref(FuStructEfiVolume *st) |
1892 | 0 | { |
1893 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1894 | 0 | st->refcount++; |
1895 | 0 | return st; |
1896 | 0 | } |
1897 | | /** |
1898 | | * fu_struct_efi_volume_unref: (skip): |
1899 | | **/ |
1900 | | void |
1901 | | fu_struct_efi_volume_unref(FuStructEfiVolume *st) |
1902 | 47.7k | { |
1903 | 47.7k | g_return_if_fail(st != NULL); |
1904 | 47.7k | if (st->refcount == 0) { |
1905 | 0 | g_critical("FuStructEfiVolume refcount already zero"); |
1906 | 0 | return; |
1907 | 0 | } |
1908 | 47.7k | if (--st->refcount > 0) |
1909 | 0 | return; |
1910 | 47.7k | if (st->buf != NULL) |
1911 | 44.7k | g_byte_array_unref(st->buf); |
1912 | 47.7k | g_free(st); |
1913 | 47.7k | } |
1914 | | /** |
1915 | | * fu_struct_efi_volume_new_internal: (skip): |
1916 | | **/ |
1917 | | static FuStructEfiVolume * |
1918 | | fu_struct_efi_volume_new_internal(void) |
1919 | 47.7k | { |
1920 | 47.7k | FuStructEfiVolume *st = g_new0(FuStructEfiVolume, 1); |
1921 | 47.7k | st->refcount = 1; |
1922 | 47.7k | return st; |
1923 | 47.7k | } |
1924 | | |
1925 | | /* getters */ |
1926 | | /** |
1927 | | * fu_struct_efi_volume_get_zero_vector: (skip): |
1928 | | **/ |
1929 | | const fwupd_guid_t * |
1930 | | fu_struct_efi_volume_get_zero_vector(const FuStructEfiVolume *st) |
1931 | 0 | { |
1932 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1933 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1934 | 0 | } |
1935 | | /** |
1936 | | * fu_struct_efi_volume_get_guid: (skip): |
1937 | | **/ |
1938 | | const fwupd_guid_t * |
1939 | | fu_struct_efi_volume_get_guid(const FuStructEfiVolume *st) |
1940 | 11.2k | { |
1941 | 11.2k | g_return_val_if_fail(st != NULL, NULL); |
1942 | 11.2k | return (const fwupd_guid_t *) (st->buf->data + 16); |
1943 | 11.2k | } |
1944 | | /** |
1945 | | * fu_struct_efi_volume_get_length: (skip): |
1946 | | **/ |
1947 | | guint64 |
1948 | | fu_struct_efi_volume_get_length(const FuStructEfiVolume *st) |
1949 | 11.2k | { |
1950 | 11.2k | g_return_val_if_fail(st != NULL, 0x0); |
1951 | 11.2k | return fu_memread_uint64(st->buf->data + 32, G_LITTLE_ENDIAN); |
1952 | 11.2k | } |
1953 | | /** |
1954 | | * fu_struct_efi_volume_get_signature: (skip): |
1955 | | **/ |
1956 | | static guint32 |
1957 | | fu_struct_efi_volume_get_signature(const FuStructEfiVolume *st) |
1958 | 66.3k | { |
1959 | 66.3k | g_return_val_if_fail(st != NULL, 0x0); |
1960 | 66.3k | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
1961 | 66.3k | } |
1962 | | /** |
1963 | | * fu_struct_efi_volume_get_attrs: (skip): |
1964 | | **/ |
1965 | | guint32 |
1966 | | fu_struct_efi_volume_get_attrs(const FuStructEfiVolume *st) |
1967 | 8.27k | { |
1968 | 8.27k | g_return_val_if_fail(st != NULL, 0x0); |
1969 | 8.27k | return fu_memread_uint32(st->buf->data + 44, G_LITTLE_ENDIAN); |
1970 | 8.27k | } |
1971 | | /** |
1972 | | * fu_struct_efi_volume_get_hdr_len: (skip): |
1973 | | **/ |
1974 | | guint16 |
1975 | | fu_struct_efi_volume_get_hdr_len(const FuStructEfiVolume *st) |
1976 | 8.22k | { |
1977 | 8.22k | g_return_val_if_fail(st != NULL, 0x0); |
1978 | 8.22k | return fu_memread_uint16(st->buf->data + 48, G_LITTLE_ENDIAN); |
1979 | 8.22k | } |
1980 | | /** |
1981 | | * fu_struct_efi_volume_get_checksum: (skip): |
1982 | | **/ |
1983 | | guint16 |
1984 | | fu_struct_efi_volume_get_checksum(const FuStructEfiVolume *st) |
1985 | 0 | { |
1986 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1987 | 0 | return fu_memread_uint16(st->buf->data + 50, G_LITTLE_ENDIAN); |
1988 | 0 | } |
1989 | | /** |
1990 | | * fu_struct_efi_volume_get_ext_hdr: (skip): |
1991 | | **/ |
1992 | | guint16 |
1993 | | fu_struct_efi_volume_get_ext_hdr(const FuStructEfiVolume *st) |
1994 | 8.62k | { |
1995 | 8.62k | g_return_val_if_fail(st != NULL, 0x0); |
1996 | 8.62k | return fu_memread_uint16(st->buf->data + 52, G_LITTLE_ENDIAN); |
1997 | 8.62k | } |
1998 | | /** |
1999 | | * fu_struct_efi_volume_get_revision: (skip): |
2000 | | **/ |
2001 | | static guint8 |
2002 | | fu_struct_efi_volume_get_revision(const FuStructEfiVolume *st) |
2003 | 22.5k | { |
2004 | 22.5k | g_return_val_if_fail(st != NULL, 0x0); |
2005 | 22.5k | return st->buf->data[55]; |
2006 | 22.5k | } |
2007 | | |
2008 | | /* setters */ |
2009 | | /** |
2010 | | * fu_struct_efi_volume_set_zero_vector: (skip): |
2011 | | **/ |
2012 | | void |
2013 | | fu_struct_efi_volume_set_zero_vector(FuStructEfiVolume *st, const fwupd_guid_t *value) |
2014 | 0 | { |
2015 | 0 | g_return_if_fail(st != NULL); |
2016 | 0 | g_return_if_fail(value != NULL); |
2017 | 0 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
2018 | 0 | } |
2019 | | /** |
2020 | | * fu_struct_efi_volume_set_guid: (skip): |
2021 | | **/ |
2022 | | void |
2023 | | fu_struct_efi_volume_set_guid(FuStructEfiVolume *st, const fwupd_guid_t *value) |
2024 | 2.97k | { |
2025 | 2.97k | g_return_if_fail(st != NULL); |
2026 | 2.97k | g_return_if_fail(value != NULL); |
2027 | 2.97k | memcpy(st->buf->data + 16, value, sizeof(*value)); /* nocheck:blocked */ |
2028 | 2.97k | } |
2029 | | /** |
2030 | | * fu_struct_efi_volume_set_length: (skip): |
2031 | | **/ |
2032 | | void |
2033 | | fu_struct_efi_volume_set_length(FuStructEfiVolume *st, guint64 value) |
2034 | 2.97k | { |
2035 | 2.97k | g_return_if_fail(st != NULL); |
2036 | 2.97k | fu_memwrite_uint64(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
2037 | 2.97k | } |
2038 | | /** |
2039 | | * fu_struct_efi_volume_set_signature: (skip): |
2040 | | **/ |
2041 | | static void |
2042 | | fu_struct_efi_volume_set_signature(FuStructEfiVolume *st, guint32 value) |
2043 | 3.15k | { |
2044 | 3.15k | g_return_if_fail(st != NULL); |
2045 | 3.15k | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
2046 | 3.15k | } |
2047 | | /** |
2048 | | * fu_struct_efi_volume_set_attrs: (skip): |
2049 | | **/ |
2050 | | void |
2051 | | fu_struct_efi_volume_set_attrs(FuStructEfiVolume *st, guint32 value) |
2052 | 2.97k | { |
2053 | 2.97k | g_return_if_fail(st != NULL); |
2054 | 2.97k | fu_memwrite_uint32(st->buf->data + 44, value, G_LITTLE_ENDIAN); |
2055 | 2.97k | } |
2056 | | /** |
2057 | | * fu_struct_efi_volume_set_hdr_len: (skip): |
2058 | | **/ |
2059 | | void |
2060 | | fu_struct_efi_volume_set_hdr_len(FuStructEfiVolume *st, guint16 value) |
2061 | 2.97k | { |
2062 | 2.97k | g_return_if_fail(st != NULL); |
2063 | 2.97k | fu_memwrite_uint16(st->buf->data + 48, value, G_LITTLE_ENDIAN); |
2064 | 2.97k | } |
2065 | | /** |
2066 | | * fu_struct_efi_volume_set_checksum: (skip): |
2067 | | **/ |
2068 | | void |
2069 | | fu_struct_efi_volume_set_checksum(FuStructEfiVolume *st, guint16 value) |
2070 | 2.97k | { |
2071 | 2.97k | g_return_if_fail(st != NULL); |
2072 | 2.97k | fu_memwrite_uint16(st->buf->data + 50, value, G_LITTLE_ENDIAN); |
2073 | 2.97k | } |
2074 | | /** |
2075 | | * fu_struct_efi_volume_set_ext_hdr: (skip): |
2076 | | **/ |
2077 | | void |
2078 | | fu_struct_efi_volume_set_ext_hdr(FuStructEfiVolume *st, guint16 value) |
2079 | 0 | { |
2080 | 0 | g_return_if_fail(st != NULL); |
2081 | 0 | fu_memwrite_uint16(st->buf->data + 52, value, G_LITTLE_ENDIAN); |
2082 | 0 | } |
2083 | | /** |
2084 | | * fu_struct_efi_volume_set_revision: (skip): |
2085 | | **/ |
2086 | | static void |
2087 | | fu_struct_efi_volume_set_revision(FuStructEfiVolume *st, guint8 value) |
2088 | 3.15k | { |
2089 | 3.15k | g_return_if_fail(st != NULL); |
2090 | 3.15k | st->buf->data[55] = value; |
2091 | 3.15k | } |
2092 | | /** |
2093 | | * fu_struct_efi_volume_new: (skip): |
2094 | | **/ |
2095 | | FuStructEfiVolume * |
2096 | | fu_struct_efi_volume_new(void) |
2097 | 3.15k | { |
2098 | 3.15k | FuStructEfiVolume *st = fu_struct_efi_volume_new_internal(); |
2099 | 3.15k | st->buf = g_byte_array_sized_new(56); |
2100 | 3.15k | fu_byte_array_set_size(st->buf, 56, 0x0); |
2101 | 3.15k | fu_struct_efi_volume_set_signature(st, 0x4856465F); |
2102 | 3.15k | fu_struct_efi_volume_set_revision(st, 0x02); |
2103 | 3.15k | return st; |
2104 | 3.15k | } |
2105 | | /** |
2106 | | * fu_struct_efi_volume_to_string: (skip): |
2107 | | **/ |
2108 | | static gchar * |
2109 | | fu_struct_efi_volume_to_string(const FuStructEfiVolume *st) |
2110 | 0 | { |
2111 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolume:\n"); |
2112 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2113 | 0 | { |
2114 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_zero_vector(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2115 | 0 | g_string_append_printf(str, " zero_vector: %s\n", tmp); |
2116 | 0 | } |
2117 | 0 | { |
2118 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2119 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
2120 | 0 | } |
2121 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2122 | 0 | (guint) fu_struct_efi_volume_get_length(st)); |
2123 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
2124 | 0 | (guint) fu_struct_efi_volume_get_signature(st)); |
2125 | 0 | g_string_append_printf(str, " attrs: 0x%x\n", |
2126 | 0 | (guint) fu_struct_efi_volume_get_attrs(st)); |
2127 | 0 | g_string_append_printf(str, " hdr_len: 0x%x\n", |
2128 | 0 | (guint) fu_struct_efi_volume_get_hdr_len(st)); |
2129 | 0 | g_string_append_printf(str, " checksum: 0x%x\n", |
2130 | 0 | (guint) fu_struct_efi_volume_get_checksum(st)); |
2131 | 0 | g_string_append_printf(str, " ext_hdr: 0x%x\n", |
2132 | 0 | (guint) fu_struct_efi_volume_get_ext_hdr(st)); |
2133 | 0 | g_string_append_printf(str, " revision: 0x%x\n", |
2134 | 0 | (guint) fu_struct_efi_volume_get_revision(st)); |
2135 | 0 | if (str->len > 0) |
2136 | 0 | g_string_set_size(str, str->len - 1); |
2137 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2138 | 0 | } |
2139 | | static gboolean |
2140 | | fu_struct_efi_volume_validate_internal(FuStructEfiVolume *st, GError **error) |
2141 | 44.4k | { |
2142 | 44.4k | g_return_val_if_fail(st != NULL, FALSE); |
2143 | 44.4k | if (fu_struct_efi_volume_get_signature(st) != 0x4856465F) { |
2144 | 21.8k | g_set_error(error, |
2145 | 21.8k | FWUPD_ERROR, |
2146 | 21.8k | FWUPD_ERROR_INVALID_DATA, |
2147 | 21.8k | "constant FuStructEfiVolume.signature was not valid, " |
2148 | 21.8k | "expected 0x%x and got 0x%x", |
2149 | 21.8k | (guint) 0x4856465F, |
2150 | 21.8k | (guint) fu_struct_efi_volume_get_signature(st)); |
2151 | 21.8k | return FALSE; |
2152 | 21.8k | } |
2153 | 22.5k | if (fu_struct_efi_volume_get_revision(st) != 0x02) { |
2154 | 62 | g_set_error_literal(error, |
2155 | 62 | FWUPD_ERROR, |
2156 | 62 | FWUPD_ERROR_INVALID_DATA, |
2157 | 62 | "constant FuStructEfiVolume.revision was not valid"); |
2158 | 62 | return FALSE; |
2159 | 62 | } |
2160 | 22.5k | return TRUE; |
2161 | 22.5k | } |
2162 | | /** |
2163 | | * fu_struct_efi_volume_validate_stream: (skip): |
2164 | | **/ |
2165 | | gboolean |
2166 | | fu_struct_efi_volume_validate_stream(GInputStream *stream, gsize offset, GError **error) |
2167 | 33.3k | { |
2168 | 33.3k | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
2169 | 33.3k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
2170 | 33.3k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
2171 | 33.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
2172 | 33.3k | if (st->buf == NULL) { |
2173 | 0 | g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56); |
2174 | 0 | return FALSE; |
2175 | 0 | } |
2176 | 33.3k | if (st->buf->len != 56) { |
2177 | 150 | g_set_error(error, |
2178 | 150 | FWUPD_ERROR, |
2179 | 150 | FWUPD_ERROR_INVALID_DATA, |
2180 | 150 | "FuStructEfiVolume requested 0x%x and got 0x%x", |
2181 | 150 | (guint) 56, |
2182 | 150 | (guint) st->buf->len); |
2183 | 150 | return FALSE; |
2184 | 150 | } |
2185 | 33.1k | return fu_struct_efi_volume_validate_internal(st, error); |
2186 | 33.3k | } |
2187 | | static gboolean |
2188 | | fu_struct_efi_volume_parse_internal(FuStructEfiVolume *st, GError **error) |
2189 | 11.2k | { |
2190 | 11.2k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2191 | 0 | g_autofree gchar *str = fu_struct_efi_volume_to_string(st); |
2192 | 0 | g_debug("%s", str); |
2193 | 0 | } |
2194 | 11.2k | if (!fu_struct_efi_volume_validate_internal(st, error)) |
2195 | 0 | return FALSE; |
2196 | 11.2k | return TRUE; |
2197 | 11.2k | } |
2198 | | /** |
2199 | | * fu_struct_efi_volume_parse_stream: (skip): |
2200 | | **/ |
2201 | | FuStructEfiVolume * |
2202 | | fu_struct_efi_volume_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2203 | 11.2k | { |
2204 | 11.2k | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
2205 | 11.2k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
2206 | 11.2k | if (st->buf == NULL) { |
2207 | 0 | g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56); |
2208 | 0 | return NULL; |
2209 | 0 | } |
2210 | 11.2k | if (st->buf->len != 56) { |
2211 | 0 | g_set_error(error, |
2212 | 0 | FWUPD_ERROR, |
2213 | 0 | FWUPD_ERROR_INVALID_DATA, |
2214 | 0 | "FuStructEfiVolume requested 0x%x and got 0x%x", |
2215 | 0 | (guint) 56, |
2216 | 0 | (guint) st->buf->len); |
2217 | 0 | return NULL; |
2218 | 0 | } |
2219 | 11.2k | if (!fu_struct_efi_volume_parse_internal(st, error)) |
2220 | 0 | return NULL; |
2221 | 11.2k | return g_steal_pointer(&st); |
2222 | 11.2k | } |
2223 | | /** |
2224 | | * fu_struct_efi_volume_ext_header_ref: (skip): |
2225 | | **/ |
2226 | | FuStructEfiVolumeExtHeader * |
2227 | | fu_struct_efi_volume_ext_header_ref(FuStructEfiVolumeExtHeader *st) |
2228 | 0 | { |
2229 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2230 | 0 | st->refcount++; |
2231 | 0 | return st; |
2232 | 0 | } |
2233 | | /** |
2234 | | * fu_struct_efi_volume_ext_header_unref: (skip): |
2235 | | **/ |
2236 | | void |
2237 | | fu_struct_efi_volume_ext_header_unref(FuStructEfiVolumeExtHeader *st) |
2238 | 635 | { |
2239 | 635 | g_return_if_fail(st != NULL); |
2240 | 635 | if (st->refcount == 0) { |
2241 | 0 | g_critical("FuStructEfiVolumeExtHeader refcount already zero"); |
2242 | 0 | return; |
2243 | 0 | } |
2244 | 635 | if (--st->refcount > 0) |
2245 | 0 | return; |
2246 | 635 | if (st->buf != NULL) |
2247 | 567 | g_byte_array_unref(st->buf); |
2248 | 635 | g_free(st); |
2249 | 635 | } |
2250 | | /** |
2251 | | * fu_struct_efi_volume_ext_header_new_internal: (skip): |
2252 | | **/ |
2253 | | static FuStructEfiVolumeExtHeader * |
2254 | | fu_struct_efi_volume_ext_header_new_internal(void) |
2255 | 635 | { |
2256 | 635 | FuStructEfiVolumeExtHeader *st = g_new0(FuStructEfiVolumeExtHeader, 1); |
2257 | 635 | st->refcount = 1; |
2258 | 635 | return st; |
2259 | 635 | } |
2260 | | |
2261 | | /* getters */ |
2262 | | /** |
2263 | | * fu_struct_efi_volume_ext_header_get_fv_name: (skip): |
2264 | | **/ |
2265 | | const fwupd_guid_t * |
2266 | | fu_struct_efi_volume_ext_header_get_fv_name(const FuStructEfiVolumeExtHeader *st) |
2267 | 0 | { |
2268 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2269 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
2270 | 0 | } |
2271 | | /** |
2272 | | * fu_struct_efi_volume_ext_header_get_size: (skip): |
2273 | | **/ |
2274 | | guint32 |
2275 | | fu_struct_efi_volume_ext_header_get_size(const FuStructEfiVolumeExtHeader *st) |
2276 | 552 | { |
2277 | 552 | g_return_val_if_fail(st != NULL, 0x0); |
2278 | 552 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
2279 | 552 | } |
2280 | | |
2281 | | /* setters */ |
2282 | | /** |
2283 | | * fu_struct_efi_volume_ext_header_to_string: (skip): |
2284 | | **/ |
2285 | | static gchar * |
2286 | | fu_struct_efi_volume_ext_header_to_string(const FuStructEfiVolumeExtHeader *st) |
2287 | 0 | { |
2288 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtHeader:\n"); |
2289 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2290 | 0 | { |
2291 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_ext_header_get_fv_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2292 | 0 | g_string_append_printf(str, " fv_name: %s\n", tmp); |
2293 | 0 | } |
2294 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
2295 | 0 | (guint) fu_struct_efi_volume_ext_header_get_size(st)); |
2296 | 0 | if (str->len > 0) |
2297 | 0 | g_string_set_size(str, str->len - 1); |
2298 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2299 | 0 | } |
2300 | | static gboolean |
2301 | | fu_struct_efi_volume_ext_header_validate_internal(FuStructEfiVolumeExtHeader *st, GError **error) |
2302 | 552 | { |
2303 | 552 | g_return_val_if_fail(st != NULL, FALSE); |
2304 | 552 | return TRUE; |
2305 | 552 | } |
2306 | | static gboolean |
2307 | | fu_struct_efi_volume_ext_header_parse_internal(FuStructEfiVolumeExtHeader *st, GError **error) |
2308 | 552 | { |
2309 | 552 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2310 | 0 | g_autofree gchar *str = fu_struct_efi_volume_ext_header_to_string(st); |
2311 | 0 | g_debug("%s", str); |
2312 | 0 | } |
2313 | 552 | if (!fu_struct_efi_volume_ext_header_validate_internal(st, error)) |
2314 | 0 | return FALSE; |
2315 | 552 | return TRUE; |
2316 | 552 | } |
2317 | | /** |
2318 | | * fu_struct_efi_volume_ext_header_parse_stream: (skip): |
2319 | | **/ |
2320 | | FuStructEfiVolumeExtHeader * |
2321 | | fu_struct_efi_volume_ext_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2322 | 635 | { |
2323 | 635 | g_autoptr(FuStructEfiVolumeExtHeader) st = fu_struct_efi_volume_ext_header_new_internal(); |
2324 | 635 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
2325 | 635 | if (st->buf == NULL) { |
2326 | 68 | g_prefix_error(error, "FuStructEfiVolumeExtHeader failed read of 0x%x: ", (guint) 20); |
2327 | 68 | return NULL; |
2328 | 68 | } |
2329 | 567 | if (st->buf->len != 20) { |
2330 | 15 | g_set_error(error, |
2331 | 15 | FWUPD_ERROR, |
2332 | 15 | FWUPD_ERROR_INVALID_DATA, |
2333 | 15 | "FuStructEfiVolumeExtHeader requested 0x%x and got 0x%x", |
2334 | 15 | (guint) 20, |
2335 | 15 | (guint) st->buf->len); |
2336 | 15 | return NULL; |
2337 | 15 | } |
2338 | 552 | if (!fu_struct_efi_volume_ext_header_parse_internal(st, error)) |
2339 | 0 | return NULL; |
2340 | 552 | return g_steal_pointer(&st); |
2341 | 552 | } |
2342 | | /** |
2343 | | * fu_struct_efi_volume_ext_entry_ref: (skip): |
2344 | | **/ |
2345 | | FuStructEfiVolumeExtEntry * |
2346 | | fu_struct_efi_volume_ext_entry_ref(FuStructEfiVolumeExtEntry *st) |
2347 | 0 | { |
2348 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2349 | 0 | st->refcount++; |
2350 | 0 | return st; |
2351 | 0 | } |
2352 | | /** |
2353 | | * fu_struct_efi_volume_ext_entry_unref: (skip): |
2354 | | **/ |
2355 | | void |
2356 | | fu_struct_efi_volume_ext_entry_unref(FuStructEfiVolumeExtEntry *st) |
2357 | 5.80k | { |
2358 | 5.80k | g_return_if_fail(st != NULL); |
2359 | 5.80k | if (st->refcount == 0) { |
2360 | 0 | g_critical("FuStructEfiVolumeExtEntry refcount already zero"); |
2361 | 0 | return; |
2362 | 0 | } |
2363 | 5.80k | if (--st->refcount > 0) |
2364 | 0 | return; |
2365 | 5.80k | if (st->buf != NULL) |
2366 | 5.66k | g_byte_array_unref(st->buf); |
2367 | 5.80k | g_free(st); |
2368 | 5.80k | } |
2369 | | /** |
2370 | | * fu_struct_efi_volume_ext_entry_new_internal: (skip): |
2371 | | **/ |
2372 | | static FuStructEfiVolumeExtEntry * |
2373 | | fu_struct_efi_volume_ext_entry_new_internal(void) |
2374 | 5.80k | { |
2375 | 5.80k | FuStructEfiVolumeExtEntry *st = g_new0(FuStructEfiVolumeExtEntry, 1); |
2376 | 5.80k | st->refcount = 1; |
2377 | 5.80k | return st; |
2378 | 5.80k | } |
2379 | | |
2380 | | /* getters */ |
2381 | | /** |
2382 | | * fu_struct_efi_volume_ext_entry_get_size: (skip): |
2383 | | **/ |
2384 | | guint16 |
2385 | | fu_struct_efi_volume_ext_entry_get_size(const FuStructEfiVolumeExtEntry *st) |
2386 | 16.8k | { |
2387 | 16.8k | g_return_val_if_fail(st != NULL, 0x0); |
2388 | 16.8k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
2389 | 16.8k | } |
2390 | | /** |
2391 | | * fu_struct_efi_volume_ext_entry_get_type: (skip): |
2392 | | **/ |
2393 | | FuEfiVolumeExtEntryType |
2394 | | fu_struct_efi_volume_ext_entry_get_type(const FuStructEfiVolumeExtEntry *st) |
2395 | 0 | { |
2396 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2397 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
2398 | 0 | } |
2399 | | |
2400 | | /* setters */ |
2401 | | /** |
2402 | | * fu_struct_efi_volume_ext_entry_to_string: (skip): |
2403 | | **/ |
2404 | | static gchar * |
2405 | | fu_struct_efi_volume_ext_entry_to_string(const FuStructEfiVolumeExtEntry *st) |
2406 | 0 | { |
2407 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtEntry:\n"); |
2408 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2409 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
2410 | 0 | (guint) fu_struct_efi_volume_ext_entry_get_size(st)); |
2411 | 0 | { |
2412 | 0 | const gchar *tmp = fu_efi_volume_ext_entry_type_to_string(fu_struct_efi_volume_ext_entry_get_type(st)); |
2413 | 0 | if (tmp != NULL) { |
2414 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st), tmp); |
2415 | 0 | } else { |
2416 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st)); |
2417 | 0 | } |
2418 | 0 | } |
2419 | 0 | if (str->len > 0) |
2420 | 0 | g_string_set_size(str, str->len - 1); |
2421 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2422 | 0 | } |
2423 | | static gboolean |
2424 | | fu_struct_efi_volume_ext_entry_validate_internal(FuStructEfiVolumeExtEntry *st, GError **error) |
2425 | 5.64k | { |
2426 | 5.64k | g_return_val_if_fail(st != NULL, FALSE); |
2427 | 5.64k | return TRUE; |
2428 | 5.64k | } |
2429 | | static gboolean |
2430 | | fu_struct_efi_volume_ext_entry_parse_internal(FuStructEfiVolumeExtEntry *st, GError **error) |
2431 | 5.64k | { |
2432 | 5.64k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2433 | 0 | g_autofree gchar *str = fu_struct_efi_volume_ext_entry_to_string(st); |
2434 | 0 | g_debug("%s", str); |
2435 | 0 | } |
2436 | 5.64k | if (!fu_struct_efi_volume_ext_entry_validate_internal(st, error)) |
2437 | 0 | return FALSE; |
2438 | 5.64k | return TRUE; |
2439 | 5.64k | } |
2440 | | /** |
2441 | | * fu_struct_efi_volume_ext_entry_parse_stream: (skip): |
2442 | | **/ |
2443 | | FuStructEfiVolumeExtEntry * |
2444 | | fu_struct_efi_volume_ext_entry_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2445 | 5.80k | { |
2446 | 5.80k | g_autoptr(FuStructEfiVolumeExtEntry) st = fu_struct_efi_volume_ext_entry_new_internal(); |
2447 | 5.80k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
2448 | 5.80k | if (st->buf == NULL) { |
2449 | 141 | g_prefix_error(error, "FuStructEfiVolumeExtEntry failed read of 0x%x: ", (guint) 4); |
2450 | 141 | return NULL; |
2451 | 141 | } |
2452 | 5.66k | if (st->buf->len != 4) { |
2453 | 24 | g_set_error(error, |
2454 | 24 | FWUPD_ERROR, |
2455 | 24 | FWUPD_ERROR_INVALID_DATA, |
2456 | 24 | "FuStructEfiVolumeExtEntry requested 0x%x and got 0x%x", |
2457 | 24 | (guint) 4, |
2458 | 24 | (guint) st->buf->len); |
2459 | 24 | return NULL; |
2460 | 24 | } |
2461 | 5.64k | if (!fu_struct_efi_volume_ext_entry_parse_internal(st, error)) |
2462 | 0 | return NULL; |
2463 | 5.64k | return g_steal_pointer(&st); |
2464 | 5.64k | } |
2465 | | /** |
2466 | | * fu_struct_efi_volume_block_map_ref: (skip): |
2467 | | **/ |
2468 | | FuStructEfiVolumeBlockMap * |
2469 | | fu_struct_efi_volume_block_map_ref(FuStructEfiVolumeBlockMap *st) |
2470 | 0 | { |
2471 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2472 | 0 | st->refcount++; |
2473 | 0 | return st; |
2474 | 0 | } |
2475 | | /** |
2476 | | * fu_struct_efi_volume_block_map_unref: (skip): |
2477 | | **/ |
2478 | | void |
2479 | | fu_struct_efi_volume_block_map_unref(FuStructEfiVolumeBlockMap *st) |
2480 | 1.97M | { |
2481 | 1.97M | g_return_if_fail(st != NULL); |
2482 | 1.97M | if (st->refcount == 0) { |
2483 | 0 | g_critical("FuStructEfiVolumeBlockMap refcount already zero"); |
2484 | 0 | return; |
2485 | 0 | } |
2486 | 1.97M | if (--st->refcount > 0) |
2487 | 0 | return; |
2488 | 1.97M | if (st->buf != NULL) |
2489 | 1.97M | g_byte_array_unref(st->buf); |
2490 | 1.97M | g_free(st); |
2491 | 1.97M | } |
2492 | | /** |
2493 | | * fu_struct_efi_volume_block_map_new_internal: (skip): |
2494 | | **/ |
2495 | | static FuStructEfiVolumeBlockMap * |
2496 | | fu_struct_efi_volume_block_map_new_internal(void) |
2497 | 1.97M | { |
2498 | 1.97M | FuStructEfiVolumeBlockMap *st = g_new0(FuStructEfiVolumeBlockMap, 1); |
2499 | 1.97M | st->refcount = 1; |
2500 | 1.97M | return st; |
2501 | 1.97M | } |
2502 | | |
2503 | | /* getters */ |
2504 | | /** |
2505 | | * fu_struct_efi_volume_block_map_get_num_blocks: (skip): |
2506 | | **/ |
2507 | | guint32 |
2508 | | fu_struct_efi_volume_block_map_get_num_blocks(const FuStructEfiVolumeBlockMap *st) |
2509 | 1.96M | { |
2510 | 1.96M | g_return_val_if_fail(st != NULL, 0x0); |
2511 | 1.96M | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
2512 | 1.96M | } |
2513 | | /** |
2514 | | * fu_struct_efi_volume_block_map_get_length: (skip): |
2515 | | **/ |
2516 | | guint32 |
2517 | | fu_struct_efi_volume_block_map_get_length(const FuStructEfiVolumeBlockMap *st) |
2518 | 1.96M | { |
2519 | 1.96M | g_return_val_if_fail(st != NULL, 0x0); |
2520 | 1.96M | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
2521 | 1.96M | } |
2522 | | |
2523 | | /* setters */ |
2524 | | /** |
2525 | | * fu_struct_efi_volume_block_map_set_num_blocks: (skip): |
2526 | | **/ |
2527 | | void |
2528 | | fu_struct_efi_volume_block_map_set_num_blocks(FuStructEfiVolumeBlockMap *st, guint32 value) |
2529 | 5.94k | { |
2530 | 5.94k | g_return_if_fail(st != NULL); |
2531 | 5.94k | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2532 | 5.94k | } |
2533 | | /** |
2534 | | * fu_struct_efi_volume_block_map_set_length: (skip): |
2535 | | **/ |
2536 | | void |
2537 | | fu_struct_efi_volume_block_map_set_length(FuStructEfiVolumeBlockMap *st, guint32 value) |
2538 | 5.94k | { |
2539 | 5.94k | g_return_if_fail(st != NULL); |
2540 | 5.94k | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
2541 | 5.94k | } |
2542 | | /** |
2543 | | * fu_struct_efi_volume_block_map_new: (skip): |
2544 | | **/ |
2545 | | FuStructEfiVolumeBlockMap * |
2546 | | fu_struct_efi_volume_block_map_new(void) |
2547 | 3.15k | { |
2548 | 3.15k | FuStructEfiVolumeBlockMap *st = fu_struct_efi_volume_block_map_new_internal(); |
2549 | 3.15k | st->buf = g_byte_array_sized_new(8); |
2550 | 3.15k | fu_byte_array_set_size(st->buf, 8, 0x0); |
2551 | 3.15k | return st; |
2552 | 3.15k | } |
2553 | | /** |
2554 | | * fu_struct_efi_volume_block_map_to_string: (skip): |
2555 | | **/ |
2556 | | static gchar * |
2557 | | fu_struct_efi_volume_block_map_to_string(const FuStructEfiVolumeBlockMap *st) |
2558 | 0 | { |
2559 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeBlockMap:\n"); |
2560 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2561 | 0 | g_string_append_printf(str, " num_blocks: 0x%x\n", |
2562 | 0 | (guint) fu_struct_efi_volume_block_map_get_num_blocks(st)); |
2563 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2564 | 0 | (guint) fu_struct_efi_volume_block_map_get_length(st)); |
2565 | 0 | if (str->len > 0) |
2566 | 0 | g_string_set_size(str, str->len - 1); |
2567 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2568 | 0 | } |
2569 | | static gboolean |
2570 | | fu_struct_efi_volume_block_map_validate_internal(FuStructEfiVolumeBlockMap *st, GError **error) |
2571 | 1.96M | { |
2572 | 1.96M | g_return_val_if_fail(st != NULL, FALSE); |
2573 | 1.96M | return TRUE; |
2574 | 1.96M | } |
2575 | | static gboolean |
2576 | | fu_struct_efi_volume_block_map_parse_internal(FuStructEfiVolumeBlockMap *st, GError **error) |
2577 | 1.96M | { |
2578 | 1.96M | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2579 | 0 | g_autofree gchar *str = fu_struct_efi_volume_block_map_to_string(st); |
2580 | 0 | g_debug("%s", str); |
2581 | 0 | } |
2582 | 1.96M | if (!fu_struct_efi_volume_block_map_validate_internal(st, error)) |
2583 | 0 | return FALSE; |
2584 | 1.96M | return TRUE; |
2585 | 1.96M | } |
2586 | | /** |
2587 | | * fu_struct_efi_volume_block_map_parse_stream: (skip): |
2588 | | **/ |
2589 | | FuStructEfiVolumeBlockMap * |
2590 | | fu_struct_efi_volume_block_map_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2591 | 1.96M | { |
2592 | 1.96M | g_autoptr(FuStructEfiVolumeBlockMap) st = fu_struct_efi_volume_block_map_new_internal(); |
2593 | 1.96M | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
2594 | 1.96M | if (st->buf == NULL) { |
2595 | 0 | g_prefix_error(error, "FuStructEfiVolumeBlockMap failed read of 0x%x: ", (guint) 8); |
2596 | 0 | return NULL; |
2597 | 0 | } |
2598 | 1.96M | if (st->buf->len != 8) { |
2599 | 1.92k | g_set_error(error, |
2600 | 1.92k | FWUPD_ERROR, |
2601 | 1.92k | FWUPD_ERROR_INVALID_DATA, |
2602 | 1.92k | "FuStructEfiVolumeBlockMap requested 0x%x and got 0x%x", |
2603 | 1.92k | (guint) 8, |
2604 | 1.92k | (guint) st->buf->len); |
2605 | 1.92k | return NULL; |
2606 | 1.92k | } |
2607 | 1.96M | if (!fu_struct_efi_volume_block_map_parse_internal(st, error)) |
2608 | 0 | return NULL; |
2609 | 1.96M | return g_steal_pointer(&st); |
2610 | 1.96M | } |
2611 | | /** |
2612 | | * fu_struct_efi_time_ref: (skip): |
2613 | | **/ |
2614 | | FuStructEfiTime * |
2615 | | fu_struct_efi_time_ref(FuStructEfiTime *st) |
2616 | 0 | { |
2617 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2618 | 0 | st->refcount++; |
2619 | 0 | return st; |
2620 | 0 | } |
2621 | | /** |
2622 | | * fu_struct_efi_time_unref: (skip): |
2623 | | **/ |
2624 | | void |
2625 | | fu_struct_efi_time_unref(FuStructEfiTime *st) |
2626 | 10.6k | { |
2627 | 10.6k | g_return_if_fail(st != NULL); |
2628 | 10.6k | if (st->refcount == 0) { |
2629 | 0 | g_critical("FuStructEfiTime refcount already zero"); |
2630 | 0 | return; |
2631 | 0 | } |
2632 | 10.6k | if (--st->refcount > 0) |
2633 | 0 | return; |
2634 | 10.6k | if (st->buf != NULL) |
2635 | 10.6k | g_byte_array_unref(st->buf); |
2636 | 10.6k | g_free(st); |
2637 | 10.6k | } |
2638 | | /** |
2639 | | * fu_struct_efi_time_new_internal: (skip): |
2640 | | **/ |
2641 | | FuStructEfiTime * |
2642 | | fu_struct_efi_time_new_internal(void) |
2643 | 10.6k | { |
2644 | 10.6k | FuStructEfiTime *st = g_new0(FuStructEfiTime, 1); |
2645 | 10.6k | st->refcount = 1; |
2646 | 10.6k | return st; |
2647 | 10.6k | } |
2648 | | |
2649 | | /* getters */ |
2650 | | /** |
2651 | | * fu_struct_efi_time_get_year: (skip): |
2652 | | **/ |
2653 | | guint16 |
2654 | | fu_struct_efi_time_get_year(const FuStructEfiTime *st) |
2655 | 0 | { |
2656 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2657 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
2658 | 0 | } |
2659 | | /** |
2660 | | * fu_struct_efi_time_get_month: (skip): |
2661 | | **/ |
2662 | | guint8 |
2663 | | fu_struct_efi_time_get_month(const FuStructEfiTime *st) |
2664 | 0 | { |
2665 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2666 | 0 | return st->buf->data[2]; |
2667 | 0 | } |
2668 | | /** |
2669 | | * fu_struct_efi_time_get_day: (skip): |
2670 | | **/ |
2671 | | guint8 |
2672 | | fu_struct_efi_time_get_day(const FuStructEfiTime *st) |
2673 | 0 | { |
2674 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2675 | 0 | return st->buf->data[3]; |
2676 | 0 | } |
2677 | | /** |
2678 | | * fu_struct_efi_time_get_hour: (skip): |
2679 | | **/ |
2680 | | guint8 |
2681 | | fu_struct_efi_time_get_hour(const FuStructEfiTime *st) |
2682 | 0 | { |
2683 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2684 | 0 | return st->buf->data[4]; |
2685 | 0 | } |
2686 | | /** |
2687 | | * fu_struct_efi_time_get_minute: (skip): |
2688 | | **/ |
2689 | | guint8 |
2690 | | fu_struct_efi_time_get_minute(const FuStructEfiTime *st) |
2691 | 0 | { |
2692 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2693 | 0 | return st->buf->data[5]; |
2694 | 0 | } |
2695 | | /** |
2696 | | * fu_struct_efi_time_get_second: (skip): |
2697 | | **/ |
2698 | | guint8 |
2699 | | fu_struct_efi_time_get_second(const FuStructEfiTime *st) |
2700 | 0 | { |
2701 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2702 | 0 | return st->buf->data[6]; |
2703 | 0 | } |
2704 | | /** |
2705 | | * fu_struct_efi_time_get_nanosecond: (skip): |
2706 | | **/ |
2707 | | guint32 |
2708 | | fu_struct_efi_time_get_nanosecond(const FuStructEfiTime *st) |
2709 | 0 | { |
2710 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2711 | 0 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
2712 | 0 | } |
2713 | | /** |
2714 | | * fu_struct_efi_time_get_timezone: (skip): |
2715 | | **/ |
2716 | | guint16 |
2717 | | fu_struct_efi_time_get_timezone(const FuStructEfiTime *st) |
2718 | 0 | { |
2719 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2720 | 0 | return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN); |
2721 | 0 | } |
2722 | | /** |
2723 | | * fu_struct_efi_time_get_daylight: (skip): |
2724 | | **/ |
2725 | | guint8 |
2726 | | fu_struct_efi_time_get_daylight(const FuStructEfiTime *st) |
2727 | 0 | { |
2728 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2729 | 0 | return st->buf->data[14]; |
2730 | 0 | } |
2731 | | |
2732 | | /* setters */ |
2733 | | /** |
2734 | | * fu_struct_efi_time_set_year: (skip): |
2735 | | **/ |
2736 | | void |
2737 | | fu_struct_efi_time_set_year(FuStructEfiTime *st, guint16 value) |
2738 | 0 | { |
2739 | 0 | g_return_if_fail(st != NULL); |
2740 | 0 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2741 | 0 | } |
2742 | | /** |
2743 | | * fu_struct_efi_time_set_month: (skip): |
2744 | | **/ |
2745 | | void |
2746 | | fu_struct_efi_time_set_month(FuStructEfiTime *st, guint8 value) |
2747 | 0 | { |
2748 | 0 | g_return_if_fail(st != NULL); |
2749 | 0 | st->buf->data[2] = value; |
2750 | 0 | } |
2751 | | /** |
2752 | | * fu_struct_efi_time_set_day: (skip): |
2753 | | **/ |
2754 | | void |
2755 | | fu_struct_efi_time_set_day(FuStructEfiTime *st, guint8 value) |
2756 | 0 | { |
2757 | 0 | g_return_if_fail(st != NULL); |
2758 | 0 | st->buf->data[3] = value; |
2759 | 0 | } |
2760 | | /** |
2761 | | * fu_struct_efi_time_set_hour: (skip): |
2762 | | **/ |
2763 | | void |
2764 | | fu_struct_efi_time_set_hour(FuStructEfiTime *st, guint8 value) |
2765 | 0 | { |
2766 | 0 | g_return_if_fail(st != NULL); |
2767 | 0 | st->buf->data[4] = value; |
2768 | 0 | } |
2769 | | /** |
2770 | | * fu_struct_efi_time_set_minute: (skip): |
2771 | | **/ |
2772 | | void |
2773 | | fu_struct_efi_time_set_minute(FuStructEfiTime *st, guint8 value) |
2774 | 0 | { |
2775 | 0 | g_return_if_fail(st != NULL); |
2776 | 0 | st->buf->data[5] = value; |
2777 | 0 | } |
2778 | | /** |
2779 | | * fu_struct_efi_time_set_second: (skip): |
2780 | | **/ |
2781 | | void |
2782 | | fu_struct_efi_time_set_second(FuStructEfiTime *st, guint8 value) |
2783 | 0 | { |
2784 | 0 | g_return_if_fail(st != NULL); |
2785 | 0 | st->buf->data[6] = value; |
2786 | 0 | } |
2787 | | /** |
2788 | | * fu_struct_efi_time_set_nanosecond: (skip): |
2789 | | **/ |
2790 | | void |
2791 | | fu_struct_efi_time_set_nanosecond(FuStructEfiTime *st, guint32 value) |
2792 | 0 | { |
2793 | 0 | g_return_if_fail(st != NULL); |
2794 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
2795 | 0 | } |
2796 | | /** |
2797 | | * fu_struct_efi_time_set_timezone: (skip): |
2798 | | **/ |
2799 | | void |
2800 | | fu_struct_efi_time_set_timezone(FuStructEfiTime *st, guint16 value) |
2801 | 0 | { |
2802 | 0 | g_return_if_fail(st != NULL); |
2803 | 0 | fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
2804 | 0 | } |
2805 | | /** |
2806 | | * fu_struct_efi_time_set_daylight: (skip): |
2807 | | **/ |
2808 | | void |
2809 | | fu_struct_efi_time_set_daylight(FuStructEfiTime *st, guint8 value) |
2810 | 0 | { |
2811 | 0 | g_return_if_fail(st != NULL); |
2812 | 0 | st->buf->data[14] = value; |
2813 | 0 | } |
2814 | | /** |
2815 | | * fu_struct_efi_time_new: (skip): |
2816 | | **/ |
2817 | | FuStructEfiTime * |
2818 | | fu_struct_efi_time_new(void) |
2819 | 1.01k | { |
2820 | 1.01k | FuStructEfiTime *st = fu_struct_efi_time_new_internal(); |
2821 | 1.01k | st->buf = g_byte_array_sized_new(16); |
2822 | 1.01k | fu_byte_array_set_size(st->buf, 16, 0x0); |
2823 | 1.01k | return st; |
2824 | 1.01k | } |
2825 | | /** |
2826 | | * fu_struct_efi_time_to_string: (skip): |
2827 | | **/ |
2828 | | gchar * |
2829 | | fu_struct_efi_time_to_string(const FuStructEfiTime *st) |
2830 | 0 | { |
2831 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiTime:\n"); |
2832 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2833 | 0 | g_string_append_printf(str, " year: 0x%x\n", |
2834 | 0 | (guint) fu_struct_efi_time_get_year(st)); |
2835 | 0 | g_string_append_printf(str, " month: 0x%x\n", |
2836 | 0 | (guint) fu_struct_efi_time_get_month(st)); |
2837 | 0 | g_string_append_printf(str, " day: 0x%x\n", |
2838 | 0 | (guint) fu_struct_efi_time_get_day(st)); |
2839 | 0 | g_string_append_printf(str, " hour: 0x%x\n", |
2840 | 0 | (guint) fu_struct_efi_time_get_hour(st)); |
2841 | 0 | g_string_append_printf(str, " minute: 0x%x\n", |
2842 | 0 | (guint) fu_struct_efi_time_get_minute(st)); |
2843 | 0 | g_string_append_printf(str, " second: 0x%x\n", |
2844 | 0 | (guint) fu_struct_efi_time_get_second(st)); |
2845 | 0 | g_string_append_printf(str, " nanosecond: 0x%x\n", |
2846 | 0 | (guint) fu_struct_efi_time_get_nanosecond(st)); |
2847 | 0 | g_string_append_printf(str, " timezone: 0x%x\n", |
2848 | 0 | (guint) fu_struct_efi_time_get_timezone(st)); |
2849 | 0 | g_string_append_printf(str, " daylight: 0x%x\n", |
2850 | 0 | (guint) fu_struct_efi_time_get_daylight(st)); |
2851 | 0 | if (str->len > 0) |
2852 | 0 | g_string_set_size(str, str->len - 1); |
2853 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2854 | 0 | } |
2855 | | gboolean |
2856 | | fu_struct_efi_time_validate_internal(FuStructEfiTime *st, GError **error) |
2857 | 10.0k | { |
2858 | 10.0k | g_return_val_if_fail(st != NULL, FALSE); |
2859 | 10.0k | return TRUE; |
2860 | 10.0k | } |
2861 | | /** |
2862 | | * fu_struct_efi_win_certificate_ref: (skip): |
2863 | | **/ |
2864 | | FuStructEfiWinCertificate * |
2865 | | fu_struct_efi_win_certificate_ref(FuStructEfiWinCertificate *st) |
2866 | 0 | { |
2867 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2868 | 0 | st->refcount++; |
2869 | 0 | return st; |
2870 | 0 | } |
2871 | | /** |
2872 | | * fu_struct_efi_win_certificate_unref: (skip): |
2873 | | **/ |
2874 | | void |
2875 | | fu_struct_efi_win_certificate_unref(FuStructEfiWinCertificate *st) |
2876 | 0 | { |
2877 | 0 | g_return_if_fail(st != NULL); |
2878 | 0 | if (st->refcount == 0) { |
2879 | 0 | g_critical("FuStructEfiWinCertificate refcount already zero"); |
2880 | 0 | return; |
2881 | 0 | } |
2882 | 0 | if (--st->refcount > 0) |
2883 | 0 | return; |
2884 | 0 | if (st->buf != NULL) |
2885 | 0 | g_byte_array_unref(st->buf); |
2886 | 0 | g_free(st); |
2887 | 0 | } |
2888 | | /** |
2889 | | * fu_struct_efi_win_certificate_new_internal: (skip): |
2890 | | **/ |
2891 | | static FuStructEfiWinCertificate * |
2892 | | fu_struct_efi_win_certificate_new_internal(void) |
2893 | 0 | { |
2894 | 0 | FuStructEfiWinCertificate *st = g_new0(FuStructEfiWinCertificate, 1); |
2895 | 0 | st->refcount = 1; |
2896 | 0 | return st; |
2897 | 0 | } |
2898 | | |
2899 | | /* getters */ |
2900 | | /** |
2901 | | * fu_struct_efi_win_certificate_get_length: (skip): |
2902 | | **/ |
2903 | | guint32 |
2904 | | fu_struct_efi_win_certificate_get_length(const FuStructEfiWinCertificate *st) |
2905 | 0 | { |
2906 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2907 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
2908 | 0 | } |
2909 | | /** |
2910 | | * fu_struct_efi_win_certificate_get_revision: (skip): |
2911 | | **/ |
2912 | | static guint16 |
2913 | | fu_struct_efi_win_certificate_get_revision(const FuStructEfiWinCertificate *st) |
2914 | 0 | { |
2915 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2916 | 0 | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
2917 | 0 | } |
2918 | | /** |
2919 | | * fu_struct_efi_win_certificate_get_certificate_type: (skip): |
2920 | | **/ |
2921 | | static guint16 |
2922 | | fu_struct_efi_win_certificate_get_certificate_type(const FuStructEfiWinCertificate *st) |
2923 | 0 | { |
2924 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2925 | 0 | return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN); |
2926 | 0 | } |
2927 | | /** |
2928 | | * fu_struct_efi_win_certificate_get_guid: (skip): |
2929 | | **/ |
2930 | | static const fwupd_guid_t * |
2931 | | fu_struct_efi_win_certificate_get_guid(const FuStructEfiWinCertificate *st) |
2932 | 0 | { |
2933 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2934 | 0 | return (const fwupd_guid_t *) (st->buf->data + 8); |
2935 | 0 | } |
2936 | | |
2937 | | /* setters */ |
2938 | | /** |
2939 | | * fu_struct_efi_win_certificate_set_length: (skip): |
2940 | | **/ |
2941 | | void |
2942 | | fu_struct_efi_win_certificate_set_length(FuStructEfiWinCertificate *st, guint32 value) |
2943 | 0 | { |
2944 | 0 | g_return_if_fail(st != NULL); |
2945 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2946 | 0 | } |
2947 | | /** |
2948 | | * fu_struct_efi_win_certificate_set_revision: (skip): |
2949 | | **/ |
2950 | | static void |
2951 | | fu_struct_efi_win_certificate_set_revision(FuStructEfiWinCertificate *st, guint16 value) |
2952 | 0 | { |
2953 | 0 | g_return_if_fail(st != NULL); |
2954 | 0 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
2955 | 0 | } |
2956 | | /** |
2957 | | * fu_struct_efi_win_certificate_set_certificate_type: (skip): |
2958 | | **/ |
2959 | | static void |
2960 | | fu_struct_efi_win_certificate_set_certificate_type(FuStructEfiWinCertificate *st, guint16 value) |
2961 | 0 | { |
2962 | 0 | g_return_if_fail(st != NULL); |
2963 | 0 | fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN); |
2964 | 0 | } |
2965 | | /** |
2966 | | * fu_struct_efi_win_certificate_set_guid: (skip): |
2967 | | **/ |
2968 | | static void |
2969 | | fu_struct_efi_win_certificate_set_guid(FuStructEfiWinCertificate *st, const fwupd_guid_t *value) |
2970 | 0 | { |
2971 | 0 | g_return_if_fail(st != NULL); |
2972 | 0 | g_return_if_fail(value != NULL); |
2973 | 0 | memcpy(st->buf->data + 8, value, sizeof(*value)); /* nocheck:blocked */ |
2974 | 0 | } |
2975 | | /** |
2976 | | * fu_struct_efi_win_certificate_new: (skip): |
2977 | | **/ |
2978 | | static FuStructEfiWinCertificate * |
2979 | | fu_struct_efi_win_certificate_new(void) |
2980 | 0 | { |
2981 | 0 | FuStructEfiWinCertificate *st = fu_struct_efi_win_certificate_new_internal(); |
2982 | 0 | st->buf = g_byte_array_sized_new(24); |
2983 | 0 | fu_byte_array_set_size(st->buf, 24, 0x0); |
2984 | 0 | fu_struct_efi_win_certificate_set_length(st, 24); |
2985 | 0 | fu_struct_efi_win_certificate_set_revision(st, 0x0200); |
2986 | 0 | fu_struct_efi_win_certificate_set_certificate_type(st, 0x0EF1); |
2987 | 0 | fu_struct_efi_win_certificate_set_guid(st, (fwupd_guid_t *) "\x9d\xd2\xaf\x4a\xdf\x68\xee\x49\x8a\xa9\x34\x7d\x37\x56\x65\xa7"); |
2988 | 0 | return st; |
2989 | 0 | } |
2990 | | /** |
2991 | | * fu_struct_efi_win_certificate_to_string: (skip): |
2992 | | **/ |
2993 | | static gchar * |
2994 | | fu_struct_efi_win_certificate_to_string(const FuStructEfiWinCertificate *st) |
2995 | 0 | { |
2996 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiWinCertificate:\n"); |
2997 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2998 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2999 | 0 | (guint) fu_struct_efi_win_certificate_get_length(st)); |
3000 | 0 | g_string_append_printf(str, " revision: 0x%x\n", |
3001 | 0 | (guint) fu_struct_efi_win_certificate_get_revision(st)); |
3002 | 0 | g_string_append_printf(str, " certificate_type: 0x%x\n", |
3003 | 0 | (guint) fu_struct_efi_win_certificate_get_certificate_type(st)); |
3004 | 0 | { |
3005 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_win_certificate_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
3006 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
3007 | 0 | } |
3008 | 0 | if (str->len > 0) |
3009 | 0 | g_string_set_size(str, str->len - 1); |
3010 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3011 | 0 | } |
3012 | | static gboolean |
3013 | | fu_struct_efi_win_certificate_validate_internal(FuStructEfiWinCertificate *st, GError **error) |
3014 | 0 | { |
3015 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3016 | 0 | if (fu_struct_efi_win_certificate_get_revision(st) != 0x0200) { |
3017 | 0 | g_set_error(error, |
3018 | 0 | FWUPD_ERROR, |
3019 | 0 | FWUPD_ERROR_INVALID_DATA, |
3020 | 0 | "constant FuStructEfiWinCertificate.revision was not valid, " |
3021 | 0 | "expected 0x%x and got 0x%x", |
3022 | 0 | (guint) 0x0200, |
3023 | 0 | (guint) fu_struct_efi_win_certificate_get_revision(st)); |
3024 | 0 | return FALSE; |
3025 | 0 | } |
3026 | 0 | if (fu_struct_efi_win_certificate_get_certificate_type(st) != 0x0EF1) { |
3027 | 0 | g_set_error(error, |
3028 | 0 | FWUPD_ERROR, |
3029 | 0 | FWUPD_ERROR_INVALID_DATA, |
3030 | 0 | "constant FuStructEfiWinCertificate.certificate_type was not valid, " |
3031 | 0 | "expected 0x%x and got 0x%x", |
3032 | 0 | (guint) 0x0EF1, |
3033 | 0 | (guint) fu_struct_efi_win_certificate_get_certificate_type(st)); |
3034 | 0 | return FALSE; |
3035 | 0 | } |
3036 | 0 | if (memcmp(fu_struct_efi_win_certificate_get_guid(st), "\x9d\xd2\xaf\x4a\xdf\x68\xee\x49\x8a\xa9\x34\x7d\x37\x56\x65\xa7", 16) != 0) { |
3037 | 0 | g_set_error_literal(error, |
3038 | 0 | FWUPD_ERROR, |
3039 | 0 | FWUPD_ERROR_INVALID_DATA, |
3040 | 0 | "constant FuStructEfiWinCertificate.guid was not valid"); |
3041 | 0 | return FALSE; |
3042 | 0 | } |
3043 | 0 | return TRUE; |
3044 | 0 | } |
3045 | | /** |
3046 | | * fu_struct_efi_variable_authentication2_ref: (skip): |
3047 | | **/ |
3048 | | FuStructEfiVariableAuthentication2 * |
3049 | | fu_struct_efi_variable_authentication2_ref(FuStructEfiVariableAuthentication2 *st) |
3050 | 0 | { |
3051 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3052 | 0 | st->refcount++; |
3053 | 0 | return st; |
3054 | 0 | } |
3055 | | /** |
3056 | | * fu_struct_efi_variable_authentication2_unref: (skip): |
3057 | | **/ |
3058 | | void |
3059 | | fu_struct_efi_variable_authentication2_unref(FuStructEfiVariableAuthentication2 *st) |
3060 | 0 | { |
3061 | 0 | g_return_if_fail(st != NULL); |
3062 | 0 | if (st->refcount == 0) { |
3063 | 0 | g_critical("FuStructEfiVariableAuthentication2 refcount already zero"); |
3064 | 0 | return; |
3065 | 0 | } |
3066 | 0 | if (--st->refcount > 0) |
3067 | 0 | return; |
3068 | 0 | if (st->buf != NULL) |
3069 | 0 | g_byte_array_unref(st->buf); |
3070 | 0 | g_free(st); |
3071 | 0 | } |
3072 | | /** |
3073 | | * fu_struct_efi_variable_authentication2_new_internal: (skip): |
3074 | | **/ |
3075 | | static FuStructEfiVariableAuthentication2 * |
3076 | | fu_struct_efi_variable_authentication2_new_internal(void) |
3077 | 0 | { |
3078 | 0 | FuStructEfiVariableAuthentication2 *st = g_new0(FuStructEfiVariableAuthentication2, 1); |
3079 | 0 | st->refcount = 1; |
3080 | 0 | return st; |
3081 | 0 | } |
3082 | | |
3083 | | /* getters */ |
3084 | | /** |
3085 | | * fu_struct_efi_variable_authentication2_get_timestamp: (skip): |
3086 | | **/ |
3087 | | FuStructEfiTime * |
3088 | | fu_struct_efi_variable_authentication2_get_timestamp(const FuStructEfiVariableAuthentication2 *st) |
3089 | 0 | { |
3090 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_time_new_internal(); |
3091 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3092 | 0 | st_tmp->buf = g_byte_array_new(); |
3093 | 0 | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, 16); |
3094 | 0 | return g_steal_pointer(&st_tmp); |
3095 | 0 | } |
3096 | | /** |
3097 | | * fu_struct_efi_variable_authentication2_get_auth_info: (skip): |
3098 | | **/ |
3099 | | FuStructEfiWinCertificate * |
3100 | | fu_struct_efi_variable_authentication2_get_auth_info(const FuStructEfiVariableAuthentication2 *st) |
3101 | 0 | { |
3102 | 0 | g_autoptr(FuStructEfiWinCertificate) st_tmp = fu_struct_efi_win_certificate_new_internal(); |
3103 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3104 | 0 | st_tmp->buf = g_byte_array_new(); |
3105 | 0 | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, 24); |
3106 | 0 | return g_steal_pointer(&st_tmp); |
3107 | 0 | } |
3108 | | |
3109 | | /* setters */ |
3110 | | /** |
3111 | | * fu_struct_efi_variable_authentication2_set_timestamp: (skip): |
3112 | | **/ |
3113 | | gboolean |
3114 | | fu_struct_efi_variable_authentication2_set_timestamp(FuStructEfiVariableAuthentication2 *st, const FuStructEfiTime *st_donor, GError **error) |
3115 | 0 | { |
3116 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3117 | 0 | g_return_val_if_fail(st_donor != NULL, FALSE); |
3118 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3119 | | |
3120 | 0 | if (st_donor->buf->len > FU_STRUCT_EFI_TIME_SIZE) { |
3121 | 0 | g_set_error(error, |
3122 | 0 | FWUPD_ERROR, |
3123 | 0 | FWUPD_ERROR_INVALID_DATA, |
3124 | 0 | "donor 'FuStructEfiTime' (0x%x bytes) does not fit in " |
3125 | 0 | "FuStructEfiVariableAuthentication2.timestamp (0x%x bytes)", |
3126 | 0 | (guint) st_donor->buf->len, |
3127 | 0 | (guint) FU_STRUCT_EFI_TIME_SIZE); |
3128 | 0 | return FALSE; |
3129 | 0 | } |
3130 | 0 | memcpy(st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, st_donor->buf->data, st_donor->buf->len); |
3131 | 0 | return TRUE; |
3132 | 0 | } |
3133 | | /** |
3134 | | * fu_struct_efi_variable_authentication2_set_auth_info: (skip): |
3135 | | **/ |
3136 | | gboolean |
3137 | | fu_struct_efi_variable_authentication2_set_auth_info(FuStructEfiVariableAuthentication2 *st, const FuStructEfiWinCertificate *st_donor, GError **error) |
3138 | 0 | { |
3139 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3140 | 0 | g_return_val_if_fail(st_donor != NULL, FALSE); |
3141 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3142 | | |
3143 | 0 | if (st_donor->buf->len > FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE) { |
3144 | 0 | g_set_error(error, |
3145 | 0 | FWUPD_ERROR, |
3146 | 0 | FWUPD_ERROR_INVALID_DATA, |
3147 | 0 | "donor 'FuStructEfiWinCertificate' (0x%x bytes) does not fit in " |
3148 | 0 | "FuStructEfiVariableAuthentication2.auth_info (0x%x bytes)", |
3149 | 0 | (guint) st_donor->buf->len, |
3150 | 0 | (guint) FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE); |
3151 | 0 | return FALSE; |
3152 | 0 | } |
3153 | 0 | memcpy(st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, st_donor->buf->data, st_donor->buf->len); |
3154 | 0 | return TRUE; |
3155 | 0 | } |
3156 | | /** |
3157 | | * fu_struct_efi_variable_authentication2_new: (skip): |
3158 | | **/ |
3159 | | FuStructEfiVariableAuthentication2 * |
3160 | | fu_struct_efi_variable_authentication2_new(void) |
3161 | 0 | { |
3162 | 0 | FuStructEfiVariableAuthentication2 *st = fu_struct_efi_variable_authentication2_new_internal(); |
3163 | 0 | st->buf = g_byte_array_sized_new(40); |
3164 | 0 | fu_byte_array_set_size(st->buf, 40, 0x0); |
3165 | 0 | { |
3166 | 0 | g_autoptr(FuStructEfiTime) st_donor = fu_struct_efi_time_new(); |
3167 | 0 | memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
3168 | 0 | } |
3169 | 0 | { |
3170 | 0 | g_autoptr(FuStructEfiWinCertificate) st_donor = fu_struct_efi_win_certificate_new(); |
3171 | 0 | memcpy(st->buf->data + 0x10, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
3172 | 0 | } |
3173 | 0 | return st; |
3174 | 0 | } |
3175 | | /** |
3176 | | * fu_struct_efi_variable_authentication2_to_string: (skip): |
3177 | | **/ |
3178 | | static gchar * |
3179 | | fu_struct_efi_variable_authentication2_to_string(const FuStructEfiVariableAuthentication2 *st) |
3180 | 0 | { |
3181 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVariableAuthentication2:\n"); |
3182 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3183 | 0 | { |
3184 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_variable_authentication2_get_timestamp(st); |
3185 | 0 | g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp); |
3186 | 0 | g_string_append_printf(str, " timestamp: %s\n", tmp); |
3187 | 0 | } |
3188 | 0 | { |
3189 | 0 | g_autoptr(FuStructEfiWinCertificate) st_tmp = fu_struct_efi_variable_authentication2_get_auth_info(st); |
3190 | 0 | g_autofree gchar *tmp = fu_struct_efi_win_certificate_to_string(st_tmp); |
3191 | 0 | g_string_append_printf(str, " auth_info: %s\n", tmp); |
3192 | 0 | } |
3193 | 0 | if (str->len > 0) |
3194 | 0 | g_string_set_size(str, str->len - 1); |
3195 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3196 | 0 | } |
3197 | | static gboolean |
3198 | | fu_struct_efi_variable_authentication2_validate_internal(FuStructEfiVariableAuthentication2 *st, GError **error) |
3199 | 0 | { |
3200 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3201 | 0 | { |
3202 | 0 | GByteArray buf_tmp = { |
3203 | 0 | .data = (guint8*) st->buf->data + 0x0, |
3204 | 0 | .len = 16, |
3205 | 0 | }; |
3206 | 0 | FuStructEfiTime st_tmp = { .buf = &buf_tmp }; |
3207 | 0 | if (!fu_struct_efi_time_validate_internal(&st_tmp, error)) |
3208 | 0 | return FALSE; |
3209 | 0 | } |
3210 | 0 | { |
3211 | 0 | GByteArray buf_tmp = { |
3212 | 0 | .data = (guint8*) st->buf->data + 0x10, |
3213 | 0 | .len = 24, |
3214 | 0 | }; |
3215 | 0 | FuStructEfiWinCertificate st_tmp = { .buf = &buf_tmp }; |
3216 | 0 | if (!fu_struct_efi_win_certificate_validate_internal(&st_tmp, error)) |
3217 | 0 | return FALSE; |
3218 | 0 | } |
3219 | 0 | return TRUE; |
3220 | 0 | } |
3221 | | /** |
3222 | | * fu_struct_efi_variable_authentication2_validate_stream: (skip): |
3223 | | **/ |
3224 | | gboolean |
3225 | | fu_struct_efi_variable_authentication2_validate_stream(GInputStream *stream, gsize offset, GError **error) |
3226 | 0 | { |
3227 | 0 | g_autoptr(FuStructEfiVariableAuthentication2) st = fu_struct_efi_variable_authentication2_new_internal(); |
3228 | 0 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
3229 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3230 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error); |
3231 | 0 | if (st->buf == NULL) { |
3232 | 0 | g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40); |
3233 | 0 | return FALSE; |
3234 | 0 | } |
3235 | 0 | if (st->buf->len != 40) { |
3236 | 0 | g_set_error(error, |
3237 | 0 | FWUPD_ERROR, |
3238 | 0 | FWUPD_ERROR_INVALID_DATA, |
3239 | 0 | "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x", |
3240 | 0 | (guint) 40, |
3241 | 0 | (guint) st->buf->len); |
3242 | 0 | return FALSE; |
3243 | 0 | } |
3244 | 0 | return fu_struct_efi_variable_authentication2_validate_internal(st, error); |
3245 | 0 | } |
3246 | | static gboolean |
3247 | | fu_struct_efi_variable_authentication2_parse_internal(FuStructEfiVariableAuthentication2 *st, GError **error) |
3248 | 0 | { |
3249 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3250 | 0 | g_autofree gchar *str = fu_struct_efi_variable_authentication2_to_string(st); |
3251 | 0 | g_debug("%s", str); |
3252 | 0 | } |
3253 | 0 | if (!fu_struct_efi_variable_authentication2_validate_internal(st, error)) |
3254 | 0 | return FALSE; |
3255 | 0 | return TRUE; |
3256 | 0 | } |
3257 | | /** |
3258 | | * fu_struct_efi_variable_authentication2_parse_stream: (skip): |
3259 | | **/ |
3260 | | FuStructEfiVariableAuthentication2 * |
3261 | | fu_struct_efi_variable_authentication2_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3262 | 0 | { |
3263 | 0 | g_autoptr(FuStructEfiVariableAuthentication2) st = fu_struct_efi_variable_authentication2_new_internal(); |
3264 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error); |
3265 | 0 | if (st->buf == NULL) { |
3266 | 0 | g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40); |
3267 | 0 | return NULL; |
3268 | 0 | } |
3269 | 0 | if (st->buf->len != 40) { |
3270 | 0 | g_set_error(error, |
3271 | 0 | FWUPD_ERROR, |
3272 | 0 | FWUPD_ERROR_INVALID_DATA, |
3273 | 0 | "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x", |
3274 | 0 | (guint) 40, |
3275 | 0 | (guint) st->buf->len); |
3276 | 0 | return NULL; |
3277 | 0 | } |
3278 | 0 | if (!fu_struct_efi_variable_authentication2_parse_internal(st, error)) |
3279 | 0 | return NULL; |
3280 | 0 | return g_steal_pointer(&st); |
3281 | 0 | } |
3282 | | /** |
3283 | | * fu_struct_efi_signature_list_ref: (skip): |
3284 | | **/ |
3285 | | FuStructEfiSignatureList * |
3286 | | fu_struct_efi_signature_list_ref(FuStructEfiSignatureList *st) |
3287 | 0 | { |
3288 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3289 | 0 | st->refcount++; |
3290 | 0 | return st; |
3291 | 0 | } |
3292 | | /** |
3293 | | * fu_struct_efi_signature_list_unref: (skip): |
3294 | | **/ |
3295 | | void |
3296 | | fu_struct_efi_signature_list_unref(FuStructEfiSignatureList *st) |
3297 | 0 | { |
3298 | 0 | g_return_if_fail(st != NULL); |
3299 | 0 | if (st->refcount == 0) { |
3300 | 0 | g_critical("FuStructEfiSignatureList refcount already zero"); |
3301 | 0 | return; |
3302 | 0 | } |
3303 | 0 | if (--st->refcount > 0) |
3304 | 0 | return; |
3305 | 0 | if (st->buf != NULL) |
3306 | 0 | g_byte_array_unref(st->buf); |
3307 | 0 | g_free(st); |
3308 | 0 | } |
3309 | | /** |
3310 | | * fu_struct_efi_signature_list_new_internal: (skip): |
3311 | | **/ |
3312 | | static FuStructEfiSignatureList * |
3313 | | fu_struct_efi_signature_list_new_internal(void) |
3314 | 0 | { |
3315 | 0 | FuStructEfiSignatureList *st = g_new0(FuStructEfiSignatureList, 1); |
3316 | 0 | st->refcount = 1; |
3317 | 0 | return st; |
3318 | 0 | } |
3319 | | |
3320 | | /* getters */ |
3321 | | /** |
3322 | | * fu_struct_efi_signature_list_get_type: (skip): |
3323 | | **/ |
3324 | | const fwupd_guid_t * |
3325 | | fu_struct_efi_signature_list_get_type(const FuStructEfiSignatureList *st) |
3326 | 0 | { |
3327 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3328 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
3329 | 0 | } |
3330 | | /** |
3331 | | * fu_struct_efi_signature_list_get_list_size: (skip): |
3332 | | **/ |
3333 | | guint32 |
3334 | | fu_struct_efi_signature_list_get_list_size(const FuStructEfiSignatureList *st) |
3335 | 0 | { |
3336 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3337 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
3338 | 0 | } |
3339 | | /** |
3340 | | * fu_struct_efi_signature_list_get_header_size: (skip): |
3341 | | **/ |
3342 | | guint32 |
3343 | | fu_struct_efi_signature_list_get_header_size(const FuStructEfiSignatureList *st) |
3344 | 0 | { |
3345 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3346 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
3347 | 0 | } |
3348 | | /** |
3349 | | * fu_struct_efi_signature_list_get_size: (skip): |
3350 | | **/ |
3351 | | guint32 |
3352 | | fu_struct_efi_signature_list_get_size(const FuStructEfiSignatureList *st) |
3353 | 0 | { |
3354 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3355 | 0 | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
3356 | 0 | } |
3357 | | |
3358 | | /* setters */ |
3359 | | /** |
3360 | | * fu_struct_efi_signature_list_set_type: (skip): |
3361 | | **/ |
3362 | | void |
3363 | | fu_struct_efi_signature_list_set_type(FuStructEfiSignatureList *st, const fwupd_guid_t *value) |
3364 | 0 | { |
3365 | 0 | g_return_if_fail(st != NULL); |
3366 | 0 | g_return_if_fail(value != NULL); |
3367 | 0 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
3368 | 0 | } |
3369 | | /** |
3370 | | * fu_struct_efi_signature_list_set_list_size: (skip): |
3371 | | **/ |
3372 | | void |
3373 | | fu_struct_efi_signature_list_set_list_size(FuStructEfiSignatureList *st, guint32 value) |
3374 | 0 | { |
3375 | 0 | g_return_if_fail(st != NULL); |
3376 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
3377 | 0 | } |
3378 | | /** |
3379 | | * fu_struct_efi_signature_list_set_header_size: (skip): |
3380 | | **/ |
3381 | | void |
3382 | | fu_struct_efi_signature_list_set_header_size(FuStructEfiSignatureList *st, guint32 value) |
3383 | 0 | { |
3384 | 0 | g_return_if_fail(st != NULL); |
3385 | 0 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
3386 | 0 | } |
3387 | | /** |
3388 | | * fu_struct_efi_signature_list_set_size: (skip): |
3389 | | **/ |
3390 | | void |
3391 | | fu_struct_efi_signature_list_set_size(FuStructEfiSignatureList *st, guint32 value) |
3392 | 0 | { |
3393 | 0 | g_return_if_fail(st != NULL); |
3394 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
3395 | 0 | } |
3396 | | /** |
3397 | | * fu_struct_efi_signature_list_new: (skip): |
3398 | | **/ |
3399 | | FuStructEfiSignatureList * |
3400 | | fu_struct_efi_signature_list_new(void) |
3401 | 0 | { |
3402 | 0 | FuStructEfiSignatureList *st = fu_struct_efi_signature_list_new_internal(); |
3403 | 0 | st->buf = g_byte_array_sized_new(28); |
3404 | 0 | fu_byte_array_set_size(st->buf, 28, 0x0); |
3405 | 0 | return st; |
3406 | 0 | } |
3407 | | /** |
3408 | | * fu_struct_efi_signature_list_to_string: (skip): |
3409 | | **/ |
3410 | | static gchar * |
3411 | | fu_struct_efi_signature_list_to_string(const FuStructEfiSignatureList *st) |
3412 | 0 | { |
3413 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSignatureList:\n"); |
3414 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3415 | 0 | { |
3416 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_signature_list_get_type(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
3417 | 0 | g_string_append_printf(str, " type: %s\n", tmp); |
3418 | 0 | } |
3419 | 0 | g_string_append_printf(str, " list_size: 0x%x\n", |
3420 | 0 | (guint) fu_struct_efi_signature_list_get_list_size(st)); |
3421 | 0 | g_string_append_printf(str, " header_size: 0x%x\n", |
3422 | 0 | (guint) fu_struct_efi_signature_list_get_header_size(st)); |
3423 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
3424 | 0 | (guint) fu_struct_efi_signature_list_get_size(st)); |
3425 | 0 | if (str->len > 0) |
3426 | 0 | g_string_set_size(str, str->len - 1); |
3427 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3428 | 0 | } |
3429 | | static gboolean |
3430 | | fu_struct_efi_signature_list_validate_internal(FuStructEfiSignatureList *st, GError **error) |
3431 | 0 | { |
3432 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3433 | 0 | return TRUE; |
3434 | 0 | } |
3435 | | static gboolean |
3436 | | fu_struct_efi_signature_list_parse_internal(FuStructEfiSignatureList *st, GError **error) |
3437 | 0 | { |
3438 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3439 | 0 | g_autofree gchar *str = fu_struct_efi_signature_list_to_string(st); |
3440 | 0 | g_debug("%s", str); |
3441 | 0 | } |
3442 | 0 | if (!fu_struct_efi_signature_list_validate_internal(st, error)) |
3443 | 0 | return FALSE; |
3444 | 0 | return TRUE; |
3445 | 0 | } |
3446 | | /** |
3447 | | * fu_struct_efi_signature_list_parse_stream: (skip): |
3448 | | **/ |
3449 | | FuStructEfiSignatureList * |
3450 | | fu_struct_efi_signature_list_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3451 | 0 | { |
3452 | 0 | g_autoptr(FuStructEfiSignatureList) st = fu_struct_efi_signature_list_new_internal(); |
3453 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
3454 | 0 | if (st->buf == NULL) { |
3455 | 0 | g_prefix_error(error, "FuStructEfiSignatureList failed read of 0x%x: ", (guint) 28); |
3456 | 0 | return NULL; |
3457 | 0 | } |
3458 | 0 | if (st->buf->len != 28) { |
3459 | 0 | g_set_error(error, |
3460 | 0 | FWUPD_ERROR, |
3461 | 0 | FWUPD_ERROR_INVALID_DATA, |
3462 | 0 | "FuStructEfiSignatureList requested 0x%x and got 0x%x", |
3463 | 0 | (guint) 28, |
3464 | 0 | (guint) st->buf->len); |
3465 | 0 | return NULL; |
3466 | 0 | } |
3467 | 0 | if (!fu_struct_efi_signature_list_parse_internal(st, error)) |
3468 | 0 | return NULL; |
3469 | 0 | return g_steal_pointer(&st); |
3470 | 0 | } |
3471 | | /** |
3472 | | * fu_struct_efi_load_option_ref: (skip): |
3473 | | **/ |
3474 | | FuStructEfiLoadOption * |
3475 | | fu_struct_efi_load_option_ref(FuStructEfiLoadOption *st) |
3476 | 0 | { |
3477 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3478 | 0 | st->refcount++; |
3479 | 0 | return st; |
3480 | 0 | } |
3481 | | /** |
3482 | | * fu_struct_efi_load_option_unref: (skip): |
3483 | | **/ |
3484 | | void |
3485 | | fu_struct_efi_load_option_unref(FuStructEfiLoadOption *st) |
3486 | 2.81k | { |
3487 | 2.81k | g_return_if_fail(st != NULL); |
3488 | 2.81k | if (st->refcount == 0) { |
3489 | 0 | g_critical("FuStructEfiLoadOption refcount already zero"); |
3490 | 0 | return; |
3491 | 0 | } |
3492 | 2.81k | if (--st->refcount > 0) |
3493 | 0 | return; |
3494 | 2.81k | if (st->buf != NULL) |
3495 | 2.10k | g_byte_array_unref(st->buf); |
3496 | 2.81k | g_free(st); |
3497 | 2.81k | } |
3498 | | /** |
3499 | | * fu_struct_efi_load_option_new_internal: (skip): |
3500 | | **/ |
3501 | | static FuStructEfiLoadOption * |
3502 | | fu_struct_efi_load_option_new_internal(void) |
3503 | 2.81k | { |
3504 | 2.81k | FuStructEfiLoadOption *st = g_new0(FuStructEfiLoadOption, 1); |
3505 | 2.81k | st->refcount = 1; |
3506 | 2.81k | return st; |
3507 | 2.81k | } |
3508 | | |
3509 | | /* getters */ |
3510 | | /** |
3511 | | * fu_struct_efi_load_option_get_attrs: (skip): |
3512 | | **/ |
3513 | | FuEfiLoadOptionAttrs |
3514 | | fu_struct_efi_load_option_get_attrs(const FuStructEfiLoadOption *st) |
3515 | 1.87k | { |
3516 | 1.87k | g_return_val_if_fail(st != NULL, 0x0); |
3517 | 1.87k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
3518 | 1.87k | } |
3519 | | /** |
3520 | | * fu_struct_efi_load_option_get_dp_size: (skip): |
3521 | | **/ |
3522 | | guint16 |
3523 | | fu_struct_efi_load_option_get_dp_size(const FuStructEfiLoadOption *st) |
3524 | 1.38k | { |
3525 | 1.38k | g_return_val_if_fail(st != NULL, 0x0); |
3526 | 1.38k | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
3527 | 1.38k | } |
3528 | | |
3529 | | /* setters */ |
3530 | | /** |
3531 | | * fu_struct_efi_load_option_set_attrs: (skip): |
3532 | | **/ |
3533 | | void |
3534 | | fu_struct_efi_load_option_set_attrs(FuStructEfiLoadOption *st, FuEfiLoadOptionAttrs value) |
3535 | 933 | { |
3536 | 933 | g_return_if_fail(st != NULL); |
3537 | 933 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
3538 | 933 | } |
3539 | | /** |
3540 | | * fu_struct_efi_load_option_set_dp_size: (skip): |
3541 | | **/ |
3542 | | void |
3543 | | fu_struct_efi_load_option_set_dp_size(FuStructEfiLoadOption *st, guint16 value) |
3544 | 714 | { |
3545 | 714 | g_return_if_fail(st != NULL); |
3546 | 714 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
3547 | 714 | } |
3548 | | /** |
3549 | | * fu_struct_efi_load_option_new: (skip): |
3550 | | **/ |
3551 | | FuStructEfiLoadOption * |
3552 | | fu_struct_efi_load_option_new(void) |
3553 | 933 | { |
3554 | 933 | FuStructEfiLoadOption *st = fu_struct_efi_load_option_new_internal(); |
3555 | 933 | st->buf = g_byte_array_sized_new(6); |
3556 | 933 | fu_byte_array_set_size(st->buf, 6, 0x0); |
3557 | 933 | return st; |
3558 | 933 | } |
3559 | | /** |
3560 | | * fu_struct_efi_load_option_to_string: (skip): |
3561 | | **/ |
3562 | | static gchar * |
3563 | | fu_struct_efi_load_option_to_string(const FuStructEfiLoadOption *st) |
3564 | 0 | { |
3565 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiLoadOption:\n"); |
3566 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3567 | 0 | { |
3568 | 0 | const gchar *tmp = fu_efi_load_option_attrs_to_string(fu_struct_efi_load_option_get_attrs(st)); |
3569 | 0 | if (tmp != NULL) { |
3570 | 0 | g_string_append_printf(str, " attrs: 0x%x [%s]\n", (guint) fu_struct_efi_load_option_get_attrs(st), tmp); |
3571 | 0 | } else { |
3572 | 0 | g_string_append_printf(str, " attrs: 0x%x\n", (guint) fu_struct_efi_load_option_get_attrs(st)); |
3573 | 0 | } |
3574 | 0 | } |
3575 | 0 | g_string_append_printf(str, " dp_size: 0x%x\n", |
3576 | 0 | (guint) fu_struct_efi_load_option_get_dp_size(st)); |
3577 | 0 | if (str->len > 0) |
3578 | 0 | g_string_set_size(str, str->len - 1); |
3579 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3580 | 0 | } |
3581 | | static gboolean |
3582 | | fu_struct_efi_load_option_validate_internal(FuStructEfiLoadOption *st, GError **error) |
3583 | 1.87k | { |
3584 | 1.87k | g_return_val_if_fail(st != NULL, FALSE); |
3585 | 1.87k | return TRUE; |
3586 | 1.87k | } |
3587 | | static gboolean |
3588 | | fu_struct_efi_load_option_parse_internal(FuStructEfiLoadOption *st, GError **error) |
3589 | 1.87k | { |
3590 | 1.87k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3591 | 0 | g_autofree gchar *str = fu_struct_efi_load_option_to_string(st); |
3592 | 0 | g_debug("%s", str); |
3593 | 0 | } |
3594 | 1.87k | if (!fu_struct_efi_load_option_validate_internal(st, error)) |
3595 | 0 | return FALSE; |
3596 | 1.87k | return TRUE; |
3597 | 1.87k | } |
3598 | | /** |
3599 | | * fu_struct_efi_load_option_parse_stream: (skip): |
3600 | | **/ |
3601 | | FuStructEfiLoadOption * |
3602 | | fu_struct_efi_load_option_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3603 | 1.88k | { |
3604 | 1.88k | g_autoptr(FuStructEfiLoadOption) st = fu_struct_efi_load_option_new_internal(); |
3605 | 1.88k | st->buf = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error); |
3606 | 1.88k | if (st->buf == NULL) { |
3607 | 0 | g_prefix_error(error, "FuStructEfiLoadOption failed read of 0x%x: ", (guint) 6); |
3608 | 0 | return NULL; |
3609 | 0 | } |
3610 | 1.88k | if (st->buf->len != 6) { |
3611 | 9 | g_set_error(error, |
3612 | 9 | FWUPD_ERROR, |
3613 | 9 | FWUPD_ERROR_INVALID_DATA, |
3614 | 9 | "FuStructEfiLoadOption requested 0x%x and got 0x%x", |
3615 | 9 | (guint) 6, |
3616 | 9 | (guint) st->buf->len); |
3617 | 9 | return NULL; |
3618 | 9 | } |
3619 | 1.87k | if (!fu_struct_efi_load_option_parse_internal(st, error)) |
3620 | 0 | return NULL; |
3621 | 1.87k | return g_steal_pointer(&st); |
3622 | 1.87k | } |
3623 | | /** |
3624 | | * fu_struct_efi_device_path_ref: (skip): |
3625 | | **/ |
3626 | | FuStructEfiDevicePath * |
3627 | | fu_struct_efi_device_path_ref(FuStructEfiDevicePath *st) |
3628 | 0 | { |
3629 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3630 | 0 | st->refcount++; |
3631 | 0 | return st; |
3632 | 0 | } |
3633 | | /** |
3634 | | * fu_struct_efi_device_path_unref: (skip): |
3635 | | **/ |
3636 | | void |
3637 | | fu_struct_efi_device_path_unref(FuStructEfiDevicePath *st) |
3638 | 46.8k | { |
3639 | 46.8k | g_return_if_fail(st != NULL); |
3640 | 46.8k | if (st->refcount == 0) { |
3641 | 0 | g_critical("FuStructEfiDevicePath refcount already zero"); |
3642 | 0 | return; |
3643 | 0 | } |
3644 | 46.8k | if (--st->refcount > 0) |
3645 | 0 | return; |
3646 | 46.8k | if (st->buf != NULL) |
3647 | 41.7k | g_byte_array_unref(st->buf); |
3648 | 46.8k | g_free(st); |
3649 | 46.8k | } |
3650 | | /** |
3651 | | * fu_struct_efi_device_path_new_internal: (skip): |
3652 | | **/ |
3653 | | static FuStructEfiDevicePath * |
3654 | | fu_struct_efi_device_path_new_internal(void) |
3655 | 46.8k | { |
3656 | 46.8k | FuStructEfiDevicePath *st = g_new0(FuStructEfiDevicePath, 1); |
3657 | 46.8k | st->refcount = 1; |
3658 | 46.8k | return st; |
3659 | 46.8k | } |
3660 | | |
3661 | | /* getters */ |
3662 | | /** |
3663 | | * fu_struct_efi_device_path_get_type: (skip): |
3664 | | **/ |
3665 | | FuEfiDevicePathType |
3666 | | fu_struct_efi_device_path_get_type(const FuStructEfiDevicePath *st) |
3667 | 65.5k | { |
3668 | 65.5k | g_return_val_if_fail(st != NULL, 0x0); |
3669 | 65.5k | return st->buf->data[0]; |
3670 | 65.5k | } |
3671 | | /** |
3672 | | * fu_struct_efi_device_path_get_subtype: (skip): |
3673 | | **/ |
3674 | | guint8 |
3675 | | fu_struct_efi_device_path_get_subtype(const FuStructEfiDevicePath *st) |
3676 | 37.2k | { |
3677 | 37.2k | g_return_val_if_fail(st != NULL, 0x0); |
3678 | 37.2k | return st->buf->data[1]; |
3679 | 37.2k | } |
3680 | | /** |
3681 | | * fu_struct_efi_device_path_get_length: (skip): |
3682 | | **/ |
3683 | | guint16 |
3684 | | fu_struct_efi_device_path_get_length(const FuStructEfiDevicePath *st) |
3685 | 39.3k | { |
3686 | 39.3k | g_return_val_if_fail(st != NULL, 0x0); |
3687 | 39.3k | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3688 | 39.3k | } |
3689 | | |
3690 | | /* setters */ |
3691 | | /** |
3692 | | * fu_struct_efi_device_path_set_type: (skip): |
3693 | | **/ |
3694 | | void |
3695 | | fu_struct_efi_device_path_set_type(FuStructEfiDevicePath *st, FuEfiDevicePathType value) |
3696 | 5.77k | { |
3697 | 5.77k | g_return_if_fail(st != NULL); |
3698 | 5.77k | st->buf->data[0] = value; |
3699 | 5.77k | } |
3700 | | /** |
3701 | | * fu_struct_efi_device_path_set_subtype: (skip): |
3702 | | **/ |
3703 | | void |
3704 | | fu_struct_efi_device_path_set_subtype(FuStructEfiDevicePath *st, guint8 value) |
3705 | 11.7k | { |
3706 | 11.7k | g_return_if_fail(st != NULL); |
3707 | 11.7k | st->buf->data[1] = value; |
3708 | 11.7k | } |
3709 | | /** |
3710 | | * fu_struct_efi_device_path_set_length: (skip): |
3711 | | **/ |
3712 | | void |
3713 | | fu_struct_efi_device_path_set_length(FuStructEfiDevicePath *st, guint16 value) |
3714 | 11.0k | { |
3715 | 11.0k | g_return_if_fail(st != NULL); |
3716 | 11.0k | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
3717 | 11.0k | } |
3718 | | /** |
3719 | | * fu_struct_efi_device_path_new: (skip): |
3720 | | **/ |
3721 | | FuStructEfiDevicePath * |
3722 | | fu_struct_efi_device_path_new(void) |
3723 | 5.99k | { |
3724 | 5.99k | FuStructEfiDevicePath *st = fu_struct_efi_device_path_new_internal(); |
3725 | 5.99k | st->buf = g_byte_array_sized_new(4); |
3726 | 5.99k | fu_byte_array_set_size(st->buf, 4, 0x0); |
3727 | 5.99k | fu_struct_efi_device_path_set_subtype(st, 0xFF); |
3728 | 5.99k | fu_struct_efi_device_path_set_length(st, 4); |
3729 | 5.99k | return st; |
3730 | 5.99k | } |
3731 | | /** |
3732 | | * fu_struct_efi_device_path_to_string: (skip): |
3733 | | **/ |
3734 | | static gchar * |
3735 | | fu_struct_efi_device_path_to_string(const FuStructEfiDevicePath *st) |
3736 | 0 | { |
3737 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiDevicePath:\n"); |
3738 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3739 | 0 | { |
3740 | 0 | const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_device_path_get_type(st)); |
3741 | 0 | if (tmp != NULL) { |
3742 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_device_path_get_type(st), tmp); |
3743 | 0 | } else { |
3744 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_device_path_get_type(st)); |
3745 | 0 | } |
3746 | 0 | } |
3747 | 0 | g_string_append_printf(str, " subtype: 0x%x\n", |
3748 | 0 | (guint) fu_struct_efi_device_path_get_subtype(st)); |
3749 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
3750 | 0 | (guint) fu_struct_efi_device_path_get_length(st)); |
3751 | 0 | if (str->len > 0) |
3752 | 0 | g_string_set_size(str, str->len - 1); |
3753 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3754 | 0 | } |
3755 | | static gboolean |
3756 | | fu_struct_efi_device_path_validate_internal(FuStructEfiDevicePath *st, GError **error) |
3757 | 40.8k | { |
3758 | 40.8k | g_return_val_if_fail(st != NULL, FALSE); |
3759 | 40.8k | return TRUE; |
3760 | 40.8k | } |
3761 | | static gboolean |
3762 | | fu_struct_efi_device_path_parse_internal(FuStructEfiDevicePath *st, GError **error) |
3763 | 40.8k | { |
3764 | 40.8k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3765 | 0 | g_autofree gchar *str = fu_struct_efi_device_path_to_string(st); |
3766 | 0 | g_debug("%s", str); |
3767 | 0 | } |
3768 | 40.8k | if (!fu_struct_efi_device_path_validate_internal(st, error)) |
3769 | 0 | return FALSE; |
3770 | 40.8k | return TRUE; |
3771 | 40.8k | } |
3772 | | /** |
3773 | | * fu_struct_efi_device_path_parse_stream: (skip): |
3774 | | **/ |
3775 | | FuStructEfiDevicePath * |
3776 | | fu_struct_efi_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3777 | 40.8k | { |
3778 | 40.8k | g_autoptr(FuStructEfiDevicePath) st = fu_struct_efi_device_path_new_internal(); |
3779 | 40.8k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
3780 | 40.8k | if (st->buf == NULL) { |
3781 | 0 | g_prefix_error(error, "FuStructEfiDevicePath failed read of 0x%x: ", (guint) 4); |
3782 | 0 | return NULL; |
3783 | 0 | } |
3784 | 40.8k | if (st->buf->len != 4) { |
3785 | 41 | g_set_error(error, |
3786 | 41 | FWUPD_ERROR, |
3787 | 41 | FWUPD_ERROR_INVALID_DATA, |
3788 | 41 | "FuStructEfiDevicePath requested 0x%x and got 0x%x", |
3789 | 41 | (guint) 4, |
3790 | 41 | (guint) st->buf->len); |
3791 | 41 | return NULL; |
3792 | 41 | } |
3793 | 40.8k | if (!fu_struct_efi_device_path_parse_internal(st, error)) |
3794 | 0 | return NULL; |
3795 | 40.8k | return g_steal_pointer(&st); |
3796 | 40.8k | } |
3797 | | /** |
3798 | | * fu_struct_efi_hard_drive_device_path_ref: (skip): |
3799 | | **/ |
3800 | | FuStructEfiHardDriveDevicePath * |
3801 | | fu_struct_efi_hard_drive_device_path_ref(FuStructEfiHardDriveDevicePath *st) |
3802 | 0 | { |
3803 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3804 | 0 | st->refcount++; |
3805 | 0 | return st; |
3806 | 0 | } |
3807 | | /** |
3808 | | * fu_struct_efi_hard_drive_device_path_unref: (skip): |
3809 | | **/ |
3810 | | void |
3811 | | fu_struct_efi_hard_drive_device_path_unref(FuStructEfiHardDriveDevicePath *st) |
3812 | 1.04k | { |
3813 | 1.04k | g_return_if_fail(st != NULL); |
3814 | 1.04k | if (st->refcount == 0) { |
3815 | 0 | g_critical("FuStructEfiHardDriveDevicePath refcount already zero"); |
3816 | 0 | return; |
3817 | 0 | } |
3818 | 1.04k | if (--st->refcount > 0) |
3819 | 0 | return; |
3820 | 1.04k | if (st->buf != NULL) |
3821 | 658 | g_byte_array_unref(st->buf); |
3822 | 1.04k | g_free(st); |
3823 | 1.04k | } |
3824 | | /** |
3825 | | * fu_struct_efi_hard_drive_device_path_new_internal: (skip): |
3826 | | **/ |
3827 | | static FuStructEfiHardDriveDevicePath * |
3828 | | fu_struct_efi_hard_drive_device_path_new_internal(void) |
3829 | 1.04k | { |
3830 | 1.04k | FuStructEfiHardDriveDevicePath *st = g_new0(FuStructEfiHardDriveDevicePath, 1); |
3831 | 1.04k | st->refcount = 1; |
3832 | 1.04k | return st; |
3833 | 1.04k | } |
3834 | | |
3835 | | /* getters */ |
3836 | | /** |
3837 | | * fu_struct_efi_hard_drive_device_path_get_type: (skip): |
3838 | | **/ |
3839 | | static FuEfiDevicePathType |
3840 | | fu_struct_efi_hard_drive_device_path_get_type(const FuStructEfiHardDriveDevicePath *st) |
3841 | 644 | { |
3842 | 644 | g_return_val_if_fail(st != NULL, 0x0); |
3843 | 644 | return st->buf->data[0]; |
3844 | 644 | } |
3845 | | /** |
3846 | | * fu_struct_efi_hard_drive_device_path_get_subtype: (skip): |
3847 | | **/ |
3848 | | FuEfiHardDriveDevicePathSubtype |
3849 | | fu_struct_efi_hard_drive_device_path_get_subtype(const FuStructEfiHardDriveDevicePath *st) |
3850 | 0 | { |
3851 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3852 | 0 | return st->buf->data[1]; |
3853 | 0 | } |
3854 | | /** |
3855 | | * fu_struct_efi_hard_drive_device_path_get_length: (skip): |
3856 | | **/ |
3857 | | static guint16 |
3858 | | fu_struct_efi_hard_drive_device_path_get_length(const FuStructEfiHardDriveDevicePath *st) |
3859 | 661 | { |
3860 | 661 | g_return_val_if_fail(st != NULL, 0x0); |
3861 | 661 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3862 | 661 | } |
3863 | | /** |
3864 | | * fu_struct_efi_hard_drive_device_path_get_partition_number: (skip): |
3865 | | **/ |
3866 | | guint32 |
3867 | | fu_struct_efi_hard_drive_device_path_get_partition_number(const FuStructEfiHardDriveDevicePath *st) |
3868 | 627 | { |
3869 | 627 | g_return_val_if_fail(st != NULL, 0x0); |
3870 | 627 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
3871 | 627 | } |
3872 | | /** |
3873 | | * fu_struct_efi_hard_drive_device_path_get_partition_start: (skip): |
3874 | | **/ |
3875 | | guint64 |
3876 | | fu_struct_efi_hard_drive_device_path_get_partition_start(const FuStructEfiHardDriveDevicePath *st) |
3877 | 627 | { |
3878 | 627 | g_return_val_if_fail(st != NULL, 0x0); |
3879 | 627 | return fu_memread_uint64(st->buf->data + 8, G_LITTLE_ENDIAN); |
3880 | 627 | } |
3881 | | /** |
3882 | | * fu_struct_efi_hard_drive_device_path_get_partition_size: (skip): |
3883 | | **/ |
3884 | | guint64 |
3885 | | fu_struct_efi_hard_drive_device_path_get_partition_size(const FuStructEfiHardDriveDevicePath *st) |
3886 | 627 | { |
3887 | 627 | g_return_val_if_fail(st != NULL, 0x0); |
3888 | 627 | return fu_memread_uint64(st->buf->data + 16, G_LITTLE_ENDIAN); |
3889 | 627 | } |
3890 | | /** |
3891 | | * fu_struct_efi_hard_drive_device_path_get_partition_signature: (skip): |
3892 | | **/ |
3893 | | const fwupd_guid_t * |
3894 | | fu_struct_efi_hard_drive_device_path_get_partition_signature(const FuStructEfiHardDriveDevicePath *st) |
3895 | 627 | { |
3896 | 627 | g_return_val_if_fail(st != NULL, NULL); |
3897 | 627 | return (const fwupd_guid_t *) (st->buf->data + 24); |
3898 | 627 | } |
3899 | | /** |
3900 | | * fu_struct_efi_hard_drive_device_path_get_partition_format: (skip): |
3901 | | **/ |
3902 | | FuEfiHardDriveDevicePathPartitionFormat |
3903 | | fu_struct_efi_hard_drive_device_path_get_partition_format(const FuStructEfiHardDriveDevicePath *st) |
3904 | 627 | { |
3905 | 627 | g_return_val_if_fail(st != NULL, 0x0); |
3906 | 627 | return st->buf->data[40]; |
3907 | 627 | } |
3908 | | /** |
3909 | | * fu_struct_efi_hard_drive_device_path_get_signature_type: (skip): |
3910 | | **/ |
3911 | | FuEfiHardDriveDevicePathSignatureType |
3912 | | fu_struct_efi_hard_drive_device_path_get_signature_type(const FuStructEfiHardDriveDevicePath *st) |
3913 | 627 | { |
3914 | 627 | g_return_val_if_fail(st != NULL, 0x0); |
3915 | 627 | return st->buf->data[41]; |
3916 | 627 | } |
3917 | | |
3918 | | /* setters */ |
3919 | | /** |
3920 | | * fu_struct_efi_hard_drive_device_path_set_type: (skip): |
3921 | | **/ |
3922 | | static void |
3923 | | fu_struct_efi_hard_drive_device_path_set_type(FuStructEfiHardDriveDevicePath *st, FuEfiDevicePathType value) |
3924 | 390 | { |
3925 | 390 | g_return_if_fail(st != NULL); |
3926 | 390 | st->buf->data[0] = value; |
3927 | 390 | } |
3928 | | /** |
3929 | | * fu_struct_efi_hard_drive_device_path_set_subtype: (skip): |
3930 | | **/ |
3931 | | void |
3932 | | fu_struct_efi_hard_drive_device_path_set_subtype(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSubtype value) |
3933 | 390 | { |
3934 | 390 | g_return_if_fail(st != NULL); |
3935 | 390 | st->buf->data[1] = value; |
3936 | 390 | } |
3937 | | /** |
3938 | | * fu_struct_efi_hard_drive_device_path_set_length: (skip): |
3939 | | **/ |
3940 | | static void |
3941 | | fu_struct_efi_hard_drive_device_path_set_length(FuStructEfiHardDriveDevicePath *st, guint16 value) |
3942 | 390 | { |
3943 | 390 | g_return_if_fail(st != NULL); |
3944 | 390 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
3945 | 390 | } |
3946 | | /** |
3947 | | * fu_struct_efi_hard_drive_device_path_set_partition_number: (skip): |
3948 | | **/ |
3949 | | void |
3950 | | fu_struct_efi_hard_drive_device_path_set_partition_number(FuStructEfiHardDriveDevicePath *st, guint32 value) |
3951 | 390 | { |
3952 | 390 | g_return_if_fail(st != NULL); |
3953 | 390 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
3954 | 390 | } |
3955 | | /** |
3956 | | * fu_struct_efi_hard_drive_device_path_set_partition_start: (skip): |
3957 | | **/ |
3958 | | void |
3959 | | fu_struct_efi_hard_drive_device_path_set_partition_start(FuStructEfiHardDriveDevicePath *st, guint64 value) |
3960 | 390 | { |
3961 | 390 | g_return_if_fail(st != NULL); |
3962 | 390 | fu_memwrite_uint64(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
3963 | 390 | } |
3964 | | /** |
3965 | | * fu_struct_efi_hard_drive_device_path_set_partition_size: (skip): |
3966 | | **/ |
3967 | | void |
3968 | | fu_struct_efi_hard_drive_device_path_set_partition_size(FuStructEfiHardDriveDevicePath *st, guint64 value) |
3969 | 390 | { |
3970 | 390 | g_return_if_fail(st != NULL); |
3971 | 390 | fu_memwrite_uint64(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
3972 | 390 | } |
3973 | | /** |
3974 | | * fu_struct_efi_hard_drive_device_path_set_partition_signature: (skip): |
3975 | | **/ |
3976 | | void |
3977 | | fu_struct_efi_hard_drive_device_path_set_partition_signature(FuStructEfiHardDriveDevicePath *st, const fwupd_guid_t *value) |
3978 | 390 | { |
3979 | 390 | g_return_if_fail(st != NULL); |
3980 | 390 | g_return_if_fail(value != NULL); |
3981 | 390 | memcpy(st->buf->data + 24, value, sizeof(*value)); /* nocheck:blocked */ |
3982 | 390 | } |
3983 | | /** |
3984 | | * fu_struct_efi_hard_drive_device_path_set_partition_format: (skip): |
3985 | | **/ |
3986 | | void |
3987 | | fu_struct_efi_hard_drive_device_path_set_partition_format(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathPartitionFormat value) |
3988 | 780 | { |
3989 | 780 | g_return_if_fail(st != NULL); |
3990 | 780 | st->buf->data[40] = value; |
3991 | 780 | } |
3992 | | /** |
3993 | | * fu_struct_efi_hard_drive_device_path_set_signature_type: (skip): |
3994 | | **/ |
3995 | | void |
3996 | | fu_struct_efi_hard_drive_device_path_set_signature_type(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSignatureType value) |
3997 | 780 | { |
3998 | 780 | g_return_if_fail(st != NULL); |
3999 | 780 | st->buf->data[41] = value; |
4000 | 780 | } |
4001 | | /** |
4002 | | * fu_struct_efi_hard_drive_device_path_new: (skip): |
4003 | | **/ |
4004 | | FuStructEfiHardDriveDevicePath * |
4005 | | fu_struct_efi_hard_drive_device_path_new(void) |
4006 | 390 | { |
4007 | 390 | FuStructEfiHardDriveDevicePath *st = fu_struct_efi_hard_drive_device_path_new_internal(); |
4008 | 390 | st->buf = g_byte_array_sized_new(42); |
4009 | 390 | fu_byte_array_set_size(st->buf, 42, 0x0); |
4010 | 390 | fu_struct_efi_hard_drive_device_path_set_type(st, FU_EFI_DEVICE_PATH_TYPE_MEDIA); |
4011 | 390 | fu_struct_efi_hard_drive_device_path_set_subtype(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE); |
4012 | 390 | fu_struct_efi_hard_drive_device_path_set_length(st, 42); |
4013 | 390 | fu_struct_efi_hard_drive_device_path_set_partition_format(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE); |
4014 | 390 | fu_struct_efi_hard_drive_device_path_set_signature_type(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID); |
4015 | 390 | return st; |
4016 | 390 | } |
4017 | | /** |
4018 | | * fu_struct_efi_hard_drive_device_path_to_string: (skip): |
4019 | | **/ |
4020 | | static gchar * |
4021 | | fu_struct_efi_hard_drive_device_path_to_string(const FuStructEfiHardDriveDevicePath *st) |
4022 | 0 | { |
4023 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiHardDriveDevicePath:\n"); |
4024 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4025 | 0 | { |
4026 | 0 | const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_hard_drive_device_path_get_type(st)); |
4027 | 0 | if (tmp != NULL) { |
4028 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_type(st), tmp); |
4029 | 0 | } else { |
4030 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_type(st)); |
4031 | 0 | } |
4032 | 0 | } |
4033 | 0 | { |
4034 | 0 | const gchar *tmp = fu_efi_hard_drive_device_path_subtype_to_string(fu_struct_efi_hard_drive_device_path_get_subtype(st)); |
4035 | 0 | if (tmp != NULL) { |
4036 | 0 | g_string_append_printf(str, " subtype: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st), tmp); |
4037 | 0 | } else { |
4038 | 0 | g_string_append_printf(str, " subtype: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st)); |
4039 | 0 | } |
4040 | 0 | } |
4041 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
4042 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_length(st)); |
4043 | 0 | g_string_append_printf(str, " partition_number: 0x%x\n", |
4044 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_number(st)); |
4045 | 0 | g_string_append_printf(str, " partition_start: 0x%x\n", |
4046 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_start(st)); |
4047 | 0 | g_string_append_printf(str, " partition_size: 0x%x\n", |
4048 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_size(st)); |
4049 | 0 | { |
4050 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_hard_drive_device_path_get_partition_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4051 | 0 | g_string_append_printf(str, " partition_signature: %s\n", tmp); |
4052 | 0 | } |
4053 | 0 | { |
4054 | 0 | const gchar *tmp = fu_efi_hard_drive_device_path_partition_format_to_string(fu_struct_efi_hard_drive_device_path_get_partition_format(st)); |
4055 | 0 | if (tmp != NULL) { |
4056 | 0 | g_string_append_printf(str, " partition_format: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_partition_format(st), tmp); |
4057 | 0 | } else { |
4058 | 0 | g_string_append_printf(str, " partition_format: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_partition_format(st)); |
4059 | 0 | } |
4060 | 0 | } |
4061 | 0 | { |
4062 | 0 | const gchar *tmp = fu_efi_hard_drive_device_path_signature_type_to_string(fu_struct_efi_hard_drive_device_path_get_signature_type(st)); |
4063 | 0 | if (tmp != NULL) { |
4064 | 0 | g_string_append_printf(str, " signature_type: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_signature_type(st), tmp); |
4065 | 0 | } else { |
4066 | 0 | g_string_append_printf(str, " signature_type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_signature_type(st)); |
4067 | 0 | } |
4068 | 0 | } |
4069 | 0 | if (str->len > 0) |
4070 | 0 | g_string_set_size(str, str->len - 1); |
4071 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4072 | 0 | } |
4073 | | static gboolean |
4074 | | fu_struct_efi_hard_drive_device_path_validate_internal(FuStructEfiHardDriveDevicePath *st, GError **error) |
4075 | 644 | { |
4076 | 644 | g_return_val_if_fail(st != NULL, FALSE); |
4077 | 644 | if (fu_struct_efi_hard_drive_device_path_get_type(st) != FU_EFI_DEVICE_PATH_TYPE_MEDIA) { |
4078 | 0 | g_set_error(error, |
4079 | 0 | FWUPD_ERROR, |
4080 | 0 | FWUPD_ERROR_INVALID_DATA, |
4081 | 0 | "constant FuStructEfiHardDriveDevicePath.type was not valid, " |
4082 | 0 | "expected 'FU_EFI_DEVICE_PATH_TYPE_MEDIA' and got 0x%x '%s'", |
4083 | 0 | fu_struct_efi_hard_drive_device_path_get_type(st), |
4084 | 0 | fu_efi_device_path_type_to_string(fu_struct_efi_hard_drive_device_path_get_type(st))); |
4085 | 0 | return FALSE; |
4086 | 0 | } |
4087 | 644 | if (fu_struct_efi_hard_drive_device_path_get_length(st) != 42) { |
4088 | 17 | g_set_error(error, |
4089 | 17 | FWUPD_ERROR, |
4090 | 17 | FWUPD_ERROR_INVALID_DATA, |
4091 | 17 | "constant FuStructEfiHardDriveDevicePath.length was not valid, " |
4092 | 17 | "expected 0x%x and got 0x%x", |
4093 | 17 | (guint) 42, |
4094 | 17 | (guint) fu_struct_efi_hard_drive_device_path_get_length(st)); |
4095 | 17 | return FALSE; |
4096 | 17 | } |
4097 | 627 | return TRUE; |
4098 | 644 | } |
4099 | | static gboolean |
4100 | | fu_struct_efi_hard_drive_device_path_parse_internal(FuStructEfiHardDriveDevicePath *st, GError **error) |
4101 | 644 | { |
4102 | 644 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4103 | 0 | g_autofree gchar *str = fu_struct_efi_hard_drive_device_path_to_string(st); |
4104 | 0 | g_debug("%s", str); |
4105 | 0 | } |
4106 | 644 | if (!fu_struct_efi_hard_drive_device_path_validate_internal(st, error)) |
4107 | 17 | return FALSE; |
4108 | 627 | return TRUE; |
4109 | 644 | } |
4110 | | /** |
4111 | | * fu_struct_efi_hard_drive_device_path_parse_stream: (skip): |
4112 | | **/ |
4113 | | FuStructEfiHardDriveDevicePath * |
4114 | | fu_struct_efi_hard_drive_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4115 | 658 | { |
4116 | 658 | g_autoptr(FuStructEfiHardDriveDevicePath) st = fu_struct_efi_hard_drive_device_path_new_internal(); |
4117 | 658 | st->buf = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error); |
4118 | 658 | if (st->buf == NULL) { |
4119 | 0 | g_prefix_error(error, "FuStructEfiHardDriveDevicePath failed read of 0x%x: ", (guint) 42); |
4120 | 0 | return NULL; |
4121 | 0 | } |
4122 | 658 | if (st->buf->len != 42) { |
4123 | 14 | g_set_error(error, |
4124 | 14 | FWUPD_ERROR, |
4125 | 14 | FWUPD_ERROR_INVALID_DATA, |
4126 | 14 | "FuStructEfiHardDriveDevicePath requested 0x%x and got 0x%x", |
4127 | 14 | (guint) 42, |
4128 | 14 | (guint) st->buf->len); |
4129 | 14 | return NULL; |
4130 | 14 | } |
4131 | 644 | if (!fu_struct_efi_hard_drive_device_path_parse_internal(st, error)) |
4132 | 17 | return NULL; |
4133 | 627 | return g_steal_pointer(&st); |
4134 | 644 | } |
4135 | | /** |
4136 | | * fu_struct_efi_vss2_variable_store_header_ref: (skip): |
4137 | | **/ |
4138 | | FuStructEfiVss2VariableStoreHeader * |
4139 | | fu_struct_efi_vss2_variable_store_header_ref(FuStructEfiVss2VariableStoreHeader *st) |
4140 | 0 | { |
4141 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4142 | 0 | st->refcount++; |
4143 | 0 | return st; |
4144 | 0 | } |
4145 | | /** |
4146 | | * fu_struct_efi_vss2_variable_store_header_unref: (skip): |
4147 | | **/ |
4148 | | void |
4149 | | fu_struct_efi_vss2_variable_store_header_unref(FuStructEfiVss2VariableStoreHeader *st) |
4150 | 86.2k | { |
4151 | 86.2k | g_return_if_fail(st != NULL); |
4152 | 86.2k | if (st->refcount == 0) { |
4153 | 0 | g_critical("FuStructEfiVss2VariableStoreHeader refcount already zero"); |
4154 | 0 | return; |
4155 | 0 | } |
4156 | 86.2k | if (--st->refcount > 0) |
4157 | 0 | return; |
4158 | 86.2k | if (st->buf != NULL) |
4159 | 85.8k | g_byte_array_unref(st->buf); |
4160 | 86.2k | g_free(st); |
4161 | 86.2k | } |
4162 | | /** |
4163 | | * fu_struct_efi_vss2_variable_store_header_new_internal: (skip): |
4164 | | **/ |
4165 | | static FuStructEfiVss2VariableStoreHeader * |
4166 | | fu_struct_efi_vss2_variable_store_header_new_internal(void) |
4167 | 86.2k | { |
4168 | 86.2k | FuStructEfiVss2VariableStoreHeader *st = g_new0(FuStructEfiVss2VariableStoreHeader, 1); |
4169 | 86.2k | st->refcount = 1; |
4170 | 86.2k | return st; |
4171 | 86.2k | } |
4172 | | |
4173 | | /* getters */ |
4174 | | /** |
4175 | | * fu_struct_efi_vss2_variable_store_header_get_signature: (skip): |
4176 | | **/ |
4177 | | static const fwupd_guid_t * |
4178 | | fu_struct_efi_vss2_variable_store_header_get_signature(const FuStructEfiVss2VariableStoreHeader *st) |
4179 | 85.3k | { |
4180 | 85.3k | g_return_val_if_fail(st != NULL, NULL); |
4181 | 85.3k | return (const fwupd_guid_t *) (st->buf->data + 0); |
4182 | 85.3k | } |
4183 | | /** |
4184 | | * fu_struct_efi_vss2_variable_store_header_get_size: (skip): |
4185 | | **/ |
4186 | | guint32 |
4187 | | fu_struct_efi_vss2_variable_store_header_get_size(const FuStructEfiVss2VariableStoreHeader *st) |
4188 | 14.5k | { |
4189 | 14.5k | g_return_val_if_fail(st != NULL, 0x0); |
4190 | 14.5k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
4191 | 14.5k | } |
4192 | | /** |
4193 | | * fu_struct_efi_vss2_variable_store_header_get_format: (skip): |
4194 | | **/ |
4195 | | static FuEfiVariableStoreFormat |
4196 | | fu_struct_efi_vss2_variable_store_header_get_format(const FuStructEfiVss2VariableStoreHeader *st) |
4197 | 13.9k | { |
4198 | 13.9k | g_return_val_if_fail(st != NULL, 0x0); |
4199 | 13.9k | return st->buf->data[20]; |
4200 | 13.9k | } |
4201 | | /** |
4202 | | * fu_struct_efi_vss2_variable_store_header_get_state: (skip): |
4203 | | **/ |
4204 | | static FuEfiVariableStoreState |
4205 | | fu_struct_efi_vss2_variable_store_header_get_state(const FuStructEfiVss2VariableStoreHeader *st) |
4206 | 8.65k | { |
4207 | 8.65k | g_return_val_if_fail(st != NULL, 0x0); |
4208 | 8.65k | return st->buf->data[21]; |
4209 | 8.65k | } |
4210 | | |
4211 | | /* setters */ |
4212 | | /** |
4213 | | * fu_struct_efi_vss2_variable_store_header_set_signature: (skip): |
4214 | | **/ |
4215 | | static void |
4216 | | fu_struct_efi_vss2_variable_store_header_set_signature(FuStructEfiVss2VariableStoreHeader *st, const fwupd_guid_t *value) |
4217 | 531 | { |
4218 | 531 | g_return_if_fail(st != NULL); |
4219 | 531 | g_return_if_fail(value != NULL); |
4220 | 531 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
4221 | 531 | } |
4222 | | /** |
4223 | | * fu_struct_efi_vss2_variable_store_header_set_size: (skip): |
4224 | | **/ |
4225 | | void |
4226 | | fu_struct_efi_vss2_variable_store_header_set_size(FuStructEfiVss2VariableStoreHeader *st, guint32 value) |
4227 | 398 | { |
4228 | 398 | g_return_if_fail(st != NULL); |
4229 | 398 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
4230 | 398 | } |
4231 | | /** |
4232 | | * fu_struct_efi_vss2_variable_store_header_set_format: (skip): |
4233 | | **/ |
4234 | | static void |
4235 | | fu_struct_efi_vss2_variable_store_header_set_format(FuStructEfiVss2VariableStoreHeader *st, FuEfiVariableStoreFormat value) |
4236 | 531 | { |
4237 | 531 | g_return_if_fail(st != NULL); |
4238 | 531 | st->buf->data[20] = value; |
4239 | 531 | } |
4240 | | /** |
4241 | | * fu_struct_efi_vss2_variable_store_header_set_state: (skip): |
4242 | | **/ |
4243 | | static void |
4244 | | fu_struct_efi_vss2_variable_store_header_set_state(FuStructEfiVss2VariableStoreHeader *st, FuEfiVariableStoreState value) |
4245 | 531 | { |
4246 | 531 | g_return_if_fail(st != NULL); |
4247 | 531 | st->buf->data[21] = value; |
4248 | 531 | } |
4249 | | /** |
4250 | | * fu_struct_efi_vss2_variable_store_header_new: (skip): |
4251 | | **/ |
4252 | | FuStructEfiVss2VariableStoreHeader * |
4253 | | fu_struct_efi_vss2_variable_store_header_new(void) |
4254 | 531 | { |
4255 | 531 | FuStructEfiVss2VariableStoreHeader *st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4256 | 531 | st->buf = g_byte_array_sized_new(28); |
4257 | 531 | fu_byte_array_set_size(st->buf, 28, 0x0); |
4258 | 531 | fu_struct_efi_vss2_variable_store_header_set_signature(st, (fwupd_guid_t *) "\x78\x2c\xf3\xaa\x7b\x94\x9a\x43\xa1\x80\x2e\x14\x4e\xc3\x77\x92"); |
4259 | 531 | fu_struct_efi_vss2_variable_store_header_set_format(st, FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED); |
4260 | 531 | fu_struct_efi_vss2_variable_store_header_set_state(st, FU_EFI_VARIABLE_STORE_STATE_HEALTHY); |
4261 | 531 | return st; |
4262 | 531 | } |
4263 | | /** |
4264 | | * fu_struct_efi_vss2_variable_store_header_to_string: (skip): |
4265 | | **/ |
4266 | | static gchar * |
4267 | | fu_struct_efi_vss2_variable_store_header_to_string(const FuStructEfiVss2VariableStoreHeader *st) |
4268 | 0 | { |
4269 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVss2VariableStoreHeader:\n"); |
4270 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4271 | 0 | { |
4272 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_vss2_variable_store_header_get_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4273 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
4274 | 0 | } |
4275 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
4276 | 0 | (guint) fu_struct_efi_vss2_variable_store_header_get_size(st)); |
4277 | 0 | { |
4278 | 0 | const gchar *tmp = fu_efi_variable_store_format_to_string(fu_struct_efi_vss2_variable_store_header_get_format(st)); |
4279 | 0 | if (tmp != NULL) { |
4280 | 0 | g_string_append_printf(str, " format: 0x%x [%s]\n", (guint) fu_struct_efi_vss2_variable_store_header_get_format(st), tmp); |
4281 | 0 | } else { |
4282 | 0 | g_string_append_printf(str, " format: 0x%x\n", (guint) fu_struct_efi_vss2_variable_store_header_get_format(st)); |
4283 | 0 | } |
4284 | 0 | } |
4285 | 0 | { |
4286 | 0 | const gchar *tmp = fu_efi_variable_store_state_to_string(fu_struct_efi_vss2_variable_store_header_get_state(st)); |
4287 | 0 | if (tmp != NULL) { |
4288 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_vss2_variable_store_header_get_state(st), tmp); |
4289 | 0 | } else { |
4290 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_vss2_variable_store_header_get_state(st)); |
4291 | 0 | } |
4292 | 0 | } |
4293 | 0 | if (str->len > 0) |
4294 | 0 | g_string_set_size(str, str->len - 1); |
4295 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4296 | 0 | } |
4297 | | static gboolean |
4298 | | fu_struct_efi_vss2_variable_store_header_validate_internal(FuStructEfiVss2VariableStoreHeader *st, GError **error) |
4299 | 85.3k | { |
4300 | 85.3k | g_return_val_if_fail(st != NULL, FALSE); |
4301 | 85.3k | if (memcmp(fu_struct_efi_vss2_variable_store_header_get_signature(st), "\x78\x2c\xf3\xaa\x7b\x94\x9a\x43\xa1\x80\x2e\x14\x4e\xc3\x77\x92", 16) != 0) { |
4302 | 75.1k | g_set_error_literal(error, |
4303 | 75.1k | FWUPD_ERROR, |
4304 | 75.1k | FWUPD_ERROR_INVALID_DATA, |
4305 | 75.1k | "constant FuStructEfiVss2VariableStoreHeader.signature was not valid"); |
4306 | 75.1k | return FALSE; |
4307 | 75.1k | } |
4308 | 10.2k | if (fu_struct_efi_vss2_variable_store_header_get_format(st) != FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) { |
4309 | 1.83k | g_set_error(error, |
4310 | 1.83k | FWUPD_ERROR, |
4311 | 1.83k | FWUPD_ERROR_INVALID_DATA, |
4312 | 1.83k | "constant FuStructEfiVss2VariableStoreHeader.format was not valid, " |
4313 | 1.83k | "expected 'FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED' and got 0x%x '%s'", |
4314 | 1.83k | fu_struct_efi_vss2_variable_store_header_get_format(st), |
4315 | 1.83k | fu_efi_variable_store_format_to_string(fu_struct_efi_vss2_variable_store_header_get_format(st))); |
4316 | 1.83k | return FALSE; |
4317 | 1.83k | } |
4318 | 8.43k | if (fu_struct_efi_vss2_variable_store_header_get_state(st) != FU_EFI_VARIABLE_STORE_STATE_HEALTHY) { |
4319 | 112 | g_set_error(error, |
4320 | 112 | FWUPD_ERROR, |
4321 | 112 | FWUPD_ERROR_INVALID_DATA, |
4322 | 112 | "constant FuStructEfiVss2VariableStoreHeader.state was not valid, " |
4323 | 112 | "expected 'FU_EFI_VARIABLE_STORE_STATE_HEALTHY' and got 0x%x '%s'", |
4324 | 112 | fu_struct_efi_vss2_variable_store_header_get_state(st), |
4325 | 112 | fu_efi_variable_store_state_to_string(fu_struct_efi_vss2_variable_store_header_get_state(st))); |
4326 | 112 | return FALSE; |
4327 | 112 | } |
4328 | 8.31k | return TRUE; |
4329 | 8.43k | } |
4330 | | /** |
4331 | | * fu_struct_efi_vss2_variable_store_header_validate_stream: (skip): |
4332 | | **/ |
4333 | | gboolean |
4334 | | fu_struct_efi_vss2_variable_store_header_validate_stream(GInputStream *stream, gsize offset, GError **error) |
4335 | 83.3k | { |
4336 | 83.3k | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4337 | 83.3k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
4338 | 83.3k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4339 | 83.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
4340 | 83.3k | if (st->buf == NULL) { |
4341 | 0 | g_prefix_error(error, "FuStructEfiVss2VariableStoreHeader failed read of 0x%x: ", (guint) 28); |
4342 | 0 | return FALSE; |
4343 | 0 | } |
4344 | 83.3k | if (st->buf->len != 28) { |
4345 | 307 | g_set_error(error, |
4346 | 307 | FWUPD_ERROR, |
4347 | 307 | FWUPD_ERROR_INVALID_DATA, |
4348 | 307 | "FuStructEfiVss2VariableStoreHeader requested 0x%x and got 0x%x", |
4349 | 307 | (guint) 28, |
4350 | 307 | (guint) st->buf->len); |
4351 | 307 | return FALSE; |
4352 | 307 | } |
4353 | 82.9k | return fu_struct_efi_vss2_variable_store_header_validate_internal(st, error); |
4354 | 83.3k | } |
4355 | | static gboolean |
4356 | | fu_struct_efi_vss2_variable_store_header_parse_internal(FuStructEfiVss2VariableStoreHeader *st, GError **error) |
4357 | 2.39k | { |
4358 | 2.39k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4359 | 0 | g_autofree gchar *str = fu_struct_efi_vss2_variable_store_header_to_string(st); |
4360 | 0 | g_debug("%s", str); |
4361 | 0 | } |
4362 | 2.39k | if (!fu_struct_efi_vss2_variable_store_header_validate_internal(st, error)) |
4363 | 0 | return FALSE; |
4364 | 2.39k | return TRUE; |
4365 | 2.39k | } |
4366 | | /** |
4367 | | * fu_struct_efi_vss2_variable_store_header_parse_stream: (skip): |
4368 | | **/ |
4369 | | FuStructEfiVss2VariableStoreHeader * |
4370 | | fu_struct_efi_vss2_variable_store_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4371 | 2.39k | { |
4372 | 2.39k | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4373 | 2.39k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
4374 | 2.39k | if (st->buf == NULL) { |
4375 | 0 | g_prefix_error(error, "FuStructEfiVss2VariableStoreHeader failed read of 0x%x: ", (guint) 28); |
4376 | 0 | return NULL; |
4377 | 0 | } |
4378 | 2.39k | if (st->buf->len != 28) { |
4379 | 0 | g_set_error(error, |
4380 | 0 | FWUPD_ERROR, |
4381 | 0 | FWUPD_ERROR_INVALID_DATA, |
4382 | 0 | "FuStructEfiVss2VariableStoreHeader requested 0x%x and got 0x%x", |
4383 | 0 | (guint) 28, |
4384 | 0 | (guint) st->buf->len); |
4385 | 0 | return NULL; |
4386 | 0 | } |
4387 | 2.39k | if (!fu_struct_efi_vss2_variable_store_header_parse_internal(st, error)) |
4388 | 0 | return NULL; |
4389 | 2.39k | return g_steal_pointer(&st); |
4390 | 2.39k | } |
4391 | | /** |
4392 | | * fu_struct_efi_vss_auth_variable_header_ref: (skip): |
4393 | | **/ |
4394 | | FuStructEfiVssAuthVariableHeader * |
4395 | | fu_struct_efi_vss_auth_variable_header_ref(FuStructEfiVssAuthVariableHeader *st) |
4396 | 0 | { |
4397 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4398 | 0 | st->refcount++; |
4399 | 0 | return st; |
4400 | 0 | } |
4401 | | /** |
4402 | | * fu_struct_efi_vss_auth_variable_header_unref: (skip): |
4403 | | **/ |
4404 | | void |
4405 | | fu_struct_efi_vss_auth_variable_header_unref(FuStructEfiVssAuthVariableHeader *st) |
4406 | 11.3k | { |
4407 | 11.3k | g_return_if_fail(st != NULL); |
4408 | 11.3k | if (st->refcount == 0) { |
4409 | 0 | g_critical("FuStructEfiVssAuthVariableHeader refcount already zero"); |
4410 | 0 | return; |
4411 | 0 | } |
4412 | 11.3k | if (--st->refcount > 0) |
4413 | 0 | return; |
4414 | 11.3k | if (st->buf != NULL) |
4415 | 10.3k | g_byte_array_unref(st->buf); |
4416 | 11.3k | g_free(st); |
4417 | 11.3k | } |
4418 | | /** |
4419 | | * fu_struct_efi_vss_auth_variable_header_new_internal: (skip): |
4420 | | **/ |
4421 | | static FuStructEfiVssAuthVariableHeader * |
4422 | | fu_struct_efi_vss_auth_variable_header_new_internal(void) |
4423 | 11.3k | { |
4424 | 11.3k | FuStructEfiVssAuthVariableHeader *st = g_new0(FuStructEfiVssAuthVariableHeader, 1); |
4425 | 11.3k | st->refcount = 1; |
4426 | 11.3k | return st; |
4427 | 11.3k | } |
4428 | | |
4429 | | /* getters */ |
4430 | | /** |
4431 | | * fu_struct_efi_vss_auth_variable_header_get_start_id: (skip): |
4432 | | **/ |
4433 | | guint16 |
4434 | | fu_struct_efi_vss_auth_variable_header_get_start_id(const FuStructEfiVssAuthVariableHeader *st) |
4435 | 20.1k | { |
4436 | 20.1k | g_return_val_if_fail(st != NULL, 0x0); |
4437 | 20.1k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
4438 | 20.1k | } |
4439 | | /** |
4440 | | * fu_struct_efi_vss_auth_variable_header_get_state: (skip): |
4441 | | **/ |
4442 | | FuEfiVariableState |
4443 | | fu_struct_efi_vss_auth_variable_header_get_state(const FuStructEfiVssAuthVariableHeader *st) |
4444 | 9.65k | { |
4445 | 9.65k | g_return_val_if_fail(st != NULL, 0x0); |
4446 | 9.65k | return st->buf->data[2]; |
4447 | 9.65k | } |
4448 | | /** |
4449 | | * fu_struct_efi_vss_auth_variable_header_get_attributes: (skip): |
4450 | | **/ |
4451 | | FuEfiVariableAttrs |
4452 | | fu_struct_efi_vss_auth_variable_header_get_attributes(const FuStructEfiVssAuthVariableHeader *st) |
4453 | 9.65k | { |
4454 | 9.65k | g_return_val_if_fail(st != NULL, 0x0); |
4455 | 9.65k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
4456 | 9.65k | } |
4457 | | /** |
4458 | | * fu_struct_efi_vss_auth_variable_header_get_monotonic_counter: (skip): |
4459 | | **/ |
4460 | | guint64 |
4461 | | fu_struct_efi_vss_auth_variable_header_get_monotonic_counter(const FuStructEfiVssAuthVariableHeader *st) |
4462 | 0 | { |
4463 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4464 | 0 | return fu_memread_uint64(st->buf->data + 8, G_LITTLE_ENDIAN); |
4465 | 0 | } |
4466 | | /** |
4467 | | * fu_struct_efi_vss_auth_variable_header_get_timestamp: (skip): |
4468 | | **/ |
4469 | | FuStructEfiTime * |
4470 | | fu_struct_efi_vss_auth_variable_header_get_timestamp(const FuStructEfiVssAuthVariableHeader *st) |
4471 | 9.65k | { |
4472 | 9.65k | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_time_new_internal(); |
4473 | 9.65k | g_return_val_if_fail(st != NULL, NULL); |
4474 | 9.65k | st_tmp->buf = g_byte_array_new(); |
4475 | 9.65k | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, 16); |
4476 | 9.65k | return g_steal_pointer(&st_tmp); |
4477 | 9.65k | } |
4478 | | /** |
4479 | | * fu_struct_efi_vss_auth_variable_header_get_pubkey_index: (skip): |
4480 | | **/ |
4481 | | guint32 |
4482 | | fu_struct_efi_vss_auth_variable_header_get_pubkey_index(const FuStructEfiVssAuthVariableHeader *st) |
4483 | 0 | { |
4484 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4485 | 0 | return fu_memread_uint32(st->buf->data + 32, G_LITTLE_ENDIAN); |
4486 | 0 | } |
4487 | | /** |
4488 | | * fu_struct_efi_vss_auth_variable_header_get_name_size: (skip): |
4489 | | **/ |
4490 | | guint32 |
4491 | | fu_struct_efi_vss_auth_variable_header_get_name_size(const FuStructEfiVssAuthVariableHeader *st) |
4492 | 19.0k | { |
4493 | 19.0k | g_return_val_if_fail(st != NULL, 0x0); |
4494 | 19.0k | return fu_memread_uint32(st->buf->data + 36, G_LITTLE_ENDIAN); |
4495 | 19.0k | } |
4496 | | /** |
4497 | | * fu_struct_efi_vss_auth_variable_header_get_data_size: (skip): |
4498 | | **/ |
4499 | | guint32 |
4500 | | fu_struct_efi_vss_auth_variable_header_get_data_size(const FuStructEfiVssAuthVariableHeader *st) |
4501 | 18.2k | { |
4502 | 18.2k | g_return_val_if_fail(st != NULL, 0x0); |
4503 | 18.2k | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
4504 | 18.2k | } |
4505 | | /** |
4506 | | * fu_struct_efi_vss_auth_variable_header_get_vendor_guid: (skip): |
4507 | | **/ |
4508 | | const fwupd_guid_t * |
4509 | | fu_struct_efi_vss_auth_variable_header_get_vendor_guid(const FuStructEfiVssAuthVariableHeader *st) |
4510 | 9.65k | { |
4511 | 9.65k | g_return_val_if_fail(st != NULL, NULL); |
4512 | 9.65k | return (const fwupd_guid_t *) (st->buf->data + 44); |
4513 | 9.65k | } |
4514 | | |
4515 | | /* setters */ |
4516 | | /** |
4517 | | * fu_struct_efi_vss_auth_variable_header_set_start_id: (skip): |
4518 | | **/ |
4519 | | void |
4520 | | fu_struct_efi_vss_auth_variable_header_set_start_id(FuStructEfiVssAuthVariableHeader *st, guint16 value) |
4521 | 1.01k | { |
4522 | 1.01k | g_return_if_fail(st != NULL); |
4523 | 1.01k | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
4524 | 1.01k | } |
4525 | | /** |
4526 | | * fu_struct_efi_vss_auth_variable_header_set_state: (skip): |
4527 | | **/ |
4528 | | void |
4529 | | fu_struct_efi_vss_auth_variable_header_set_state(FuStructEfiVssAuthVariableHeader *st, FuEfiVariableState value) |
4530 | 1.01k | { |
4531 | 1.01k | g_return_if_fail(st != NULL); |
4532 | 1.01k | st->buf->data[2] = value; |
4533 | 1.01k | } |
4534 | | /** |
4535 | | * fu_struct_efi_vss_auth_variable_header_set_attributes: (skip): |
4536 | | **/ |
4537 | | void |
4538 | | fu_struct_efi_vss_auth_variable_header_set_attributes(FuStructEfiVssAuthVariableHeader *st, FuEfiVariableAttrs value) |
4539 | 1.01k | { |
4540 | 1.01k | g_return_if_fail(st != NULL); |
4541 | 1.01k | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
4542 | 1.01k | } |
4543 | | /** |
4544 | | * fu_struct_efi_vss_auth_variable_header_set_monotonic_counter: (skip): |
4545 | | **/ |
4546 | | void |
4547 | | fu_struct_efi_vss_auth_variable_header_set_monotonic_counter(FuStructEfiVssAuthVariableHeader *st, guint64 value) |
4548 | 0 | { |
4549 | 0 | g_return_if_fail(st != NULL); |
4550 | 0 | fu_memwrite_uint64(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
4551 | 0 | } |
4552 | | /** |
4553 | | * fu_struct_efi_vss_auth_variable_header_set_timestamp: (skip): |
4554 | | **/ |
4555 | | gboolean |
4556 | | fu_struct_efi_vss_auth_variable_header_set_timestamp(FuStructEfiVssAuthVariableHeader *st, const FuStructEfiTime *st_donor, GError **error) |
4557 | 1.01k | { |
4558 | 1.01k | g_return_val_if_fail(st != NULL, FALSE); |
4559 | 1.01k | g_return_val_if_fail(st_donor != NULL, FALSE); |
4560 | 1.01k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4561 | | |
4562 | 1.01k | if (st_donor->buf->len > FU_STRUCT_EFI_TIME_SIZE) { |
4563 | 0 | g_set_error(error, |
4564 | 0 | FWUPD_ERROR, |
4565 | 0 | FWUPD_ERROR_INVALID_DATA, |
4566 | 0 | "donor 'FuStructEfiTime' (0x%x bytes) does not fit in " |
4567 | 0 | "FuStructEfiVssAuthVariableHeader.timestamp (0x%x bytes)", |
4568 | 0 | (guint) st_donor->buf->len, |
4569 | 0 | (guint) FU_STRUCT_EFI_TIME_SIZE); |
4570 | 0 | return FALSE; |
4571 | 0 | } |
4572 | 1.01k | memcpy(st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, st_donor->buf->data, st_donor->buf->len); |
4573 | 1.01k | return TRUE; |
4574 | 1.01k | } |
4575 | | /** |
4576 | | * fu_struct_efi_vss_auth_variable_header_set_pubkey_index: (skip): |
4577 | | **/ |
4578 | | void |
4579 | | fu_struct_efi_vss_auth_variable_header_set_pubkey_index(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4580 | 0 | { |
4581 | 0 | g_return_if_fail(st != NULL); |
4582 | 0 | fu_memwrite_uint32(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
4583 | 0 | } |
4584 | | /** |
4585 | | * fu_struct_efi_vss_auth_variable_header_set_name_size: (skip): |
4586 | | **/ |
4587 | | void |
4588 | | fu_struct_efi_vss_auth_variable_header_set_name_size(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4589 | 1.01k | { |
4590 | 1.01k | g_return_if_fail(st != NULL); |
4591 | 1.01k | fu_memwrite_uint32(st->buf->data + 36, value, G_LITTLE_ENDIAN); |
4592 | 1.01k | } |
4593 | | /** |
4594 | | * fu_struct_efi_vss_auth_variable_header_set_data_size: (skip): |
4595 | | **/ |
4596 | | void |
4597 | | fu_struct_efi_vss_auth_variable_header_set_data_size(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4598 | 1.01k | { |
4599 | 1.01k | g_return_if_fail(st != NULL); |
4600 | 1.01k | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
4601 | 1.01k | } |
4602 | | /** |
4603 | | * fu_struct_efi_vss_auth_variable_header_set_vendor_guid: (skip): |
4604 | | **/ |
4605 | | void |
4606 | | fu_struct_efi_vss_auth_variable_header_set_vendor_guid(FuStructEfiVssAuthVariableHeader *st, const fwupd_guid_t *value) |
4607 | 1.01k | { |
4608 | 1.01k | g_return_if_fail(st != NULL); |
4609 | 1.01k | g_return_if_fail(value != NULL); |
4610 | 1.01k | memcpy(st->buf->data + 44, value, sizeof(*value)); /* nocheck:blocked */ |
4611 | 1.01k | } |
4612 | | /** |
4613 | | * fu_struct_efi_vss_auth_variable_header_new: (skip): |
4614 | | **/ |
4615 | | FuStructEfiVssAuthVariableHeader * |
4616 | | fu_struct_efi_vss_auth_variable_header_new(void) |
4617 | 1.01k | { |
4618 | 1.01k | FuStructEfiVssAuthVariableHeader *st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4619 | 1.01k | st->buf = g_byte_array_sized_new(60); |
4620 | 1.01k | fu_byte_array_set_size(st->buf, 60, 0x0); |
4621 | 1.01k | { |
4622 | 1.01k | g_autoptr(FuStructEfiTime) st_donor = fu_struct_efi_time_new(); |
4623 | 1.01k | memcpy(st->buf->data + 0x10, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
4624 | 1.01k | } |
4625 | 1.01k | fu_struct_efi_vss_auth_variable_header_set_start_id(st, 0x55AA); |
4626 | 1.01k | return st; |
4627 | 1.01k | } |
4628 | | /** |
4629 | | * fu_struct_efi_vss_auth_variable_header_to_string: (skip): |
4630 | | **/ |
4631 | | static gchar * |
4632 | | fu_struct_efi_vss_auth_variable_header_to_string(const FuStructEfiVssAuthVariableHeader *st) |
4633 | 0 | { |
4634 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVssAuthVariableHeader:\n"); |
4635 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4636 | 0 | g_string_append_printf(str, " start_id: 0x%x\n", |
4637 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_start_id(st)); |
4638 | 0 | { |
4639 | 0 | const gchar *tmp = fu_efi_variable_state_to_string(fu_struct_efi_vss_auth_variable_header_get_state(st)); |
4640 | 0 | if (tmp != NULL) { |
4641 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_vss_auth_variable_header_get_state(st), tmp); |
4642 | 0 | } else { |
4643 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_vss_auth_variable_header_get_state(st)); |
4644 | 0 | } |
4645 | 0 | } |
4646 | 0 | { |
4647 | 0 | g_autofree gchar *tmp = fu_efi_variable_attrs_to_string(fu_struct_efi_vss_auth_variable_header_get_attributes(st)); |
4648 | 0 | if (tmp != NULL) { |
4649 | 0 | g_string_append_printf(str, " attributes: 0x%x [%s]\n", (guint) fu_struct_efi_vss_auth_variable_header_get_attributes(st), tmp); |
4650 | 0 | } else { |
4651 | 0 | g_string_append_printf(str, " attributes: 0x%x\n", (guint) fu_struct_efi_vss_auth_variable_header_get_attributes(st)); |
4652 | 0 | } |
4653 | 0 | } |
4654 | 0 | g_string_append_printf(str, " monotonic_counter: 0x%x\n", |
4655 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_monotonic_counter(st)); |
4656 | 0 | { |
4657 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_vss_auth_variable_header_get_timestamp(st); |
4658 | 0 | g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp); |
4659 | 0 | g_string_append_printf(str, " timestamp: %s\n", tmp); |
4660 | 0 | } |
4661 | 0 | g_string_append_printf(str, " pubkey_index: 0x%x\n", |
4662 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_pubkey_index(st)); |
4663 | 0 | g_string_append_printf(str, " name_size: 0x%x\n", |
4664 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_name_size(st)); |
4665 | 0 | g_string_append_printf(str, " data_size: 0x%x\n", |
4666 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_data_size(st)); |
4667 | 0 | { |
4668 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_vss_auth_variable_header_get_vendor_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4669 | 0 | g_string_append_printf(str, " vendor_guid: %s\n", tmp); |
4670 | 0 | } |
4671 | 0 | if (str->len > 0) |
4672 | 0 | g_string_set_size(str, str->len - 1); |
4673 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4674 | 0 | } |
4675 | | static gboolean |
4676 | | fu_struct_efi_vss_auth_variable_header_validate_internal(FuStructEfiVssAuthVariableHeader *st, GError **error) |
4677 | 10.0k | { |
4678 | 10.0k | g_return_val_if_fail(st != NULL, FALSE); |
4679 | 10.0k | { |
4680 | 10.0k | GByteArray buf_tmp = { |
4681 | 10.0k | .data = (guint8*) st->buf->data + 0x10, |
4682 | 10.0k | .len = 16, |
4683 | 10.0k | }; |
4684 | 10.0k | FuStructEfiTime st_tmp = { .buf = &buf_tmp }; |
4685 | 10.0k | if (!fu_struct_efi_time_validate_internal(&st_tmp, error)) |
4686 | 0 | return FALSE; |
4687 | 10.0k | } |
4688 | 10.0k | return TRUE; |
4689 | 10.0k | } |
4690 | | static gboolean |
4691 | | fu_struct_efi_vss_auth_variable_header_parse_internal(FuStructEfiVssAuthVariableHeader *st, GError **error) |
4692 | 10.0k | { |
4693 | 10.0k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4694 | 0 | g_autofree gchar *str = fu_struct_efi_vss_auth_variable_header_to_string(st); |
4695 | 0 | g_debug("%s", str); |
4696 | 0 | } |
4697 | 10.0k | if (!fu_struct_efi_vss_auth_variable_header_validate_internal(st, error)) |
4698 | 0 | return FALSE; |
4699 | 10.0k | return TRUE; |
4700 | 10.0k | } |
4701 | | /** |
4702 | | * fu_struct_efi_vss_auth_variable_header_parse_stream: (skip): |
4703 | | **/ |
4704 | | FuStructEfiVssAuthVariableHeader * |
4705 | | fu_struct_efi_vss_auth_variable_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4706 | 10.3k | { |
4707 | 10.3k | g_autoptr(FuStructEfiVssAuthVariableHeader) st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4708 | 10.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 60, NULL, error); |
4709 | 10.3k | if (st->buf == NULL) { |
4710 | 0 | g_prefix_error(error, "FuStructEfiVssAuthVariableHeader failed read of 0x%x: ", (guint) 60); |
4711 | 0 | return NULL; |
4712 | 0 | } |
4713 | 10.3k | if (st->buf->len != 60) { |
4714 | 310 | g_set_error(error, |
4715 | 310 | FWUPD_ERROR, |
4716 | 310 | FWUPD_ERROR_INVALID_DATA, |
4717 | 310 | "FuStructEfiVssAuthVariableHeader requested 0x%x and got 0x%x", |
4718 | 310 | (guint) 60, |
4719 | 310 | (guint) st->buf->len); |
4720 | 310 | return NULL; |
4721 | 310 | } |
4722 | 10.0k | if (!fu_struct_efi_vss_auth_variable_header_parse_internal(st, error)) |
4723 | 0 | return NULL; |
4724 | 10.0k | return g_steal_pointer(&st); |
4725 | 10.0k | } |
4726 | | /** |
4727 | | * fu_struct_efi_fault_tolerant_working_block_header64_ref: (skip): |
4728 | | **/ |
4729 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4730 | | fu_struct_efi_fault_tolerant_working_block_header64_ref(FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4731 | 0 | { |
4732 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4733 | 0 | st->refcount++; |
4734 | 0 | return st; |
4735 | 0 | } |
4736 | | /** |
4737 | | * fu_struct_efi_fault_tolerant_working_block_header64_unref: (skip): |
4738 | | **/ |
4739 | | void |
4740 | | fu_struct_efi_fault_tolerant_working_block_header64_unref(FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4741 | 83.0k | { |
4742 | 83.0k | g_return_if_fail(st != NULL); |
4743 | 83.0k | if (st->refcount == 0) { |
4744 | 0 | g_critical("FuStructEfiFaultTolerantWorkingBlockHeader64 refcount already zero"); |
4745 | 0 | return; |
4746 | 0 | } |
4747 | 83.0k | if (--st->refcount > 0) |
4748 | 0 | return; |
4749 | 83.0k | if (st->buf != NULL) |
4750 | 82.9k | g_byte_array_unref(st->buf); |
4751 | 83.0k | g_free(st); |
4752 | 83.0k | } |
4753 | | /** |
4754 | | * fu_struct_efi_fault_tolerant_working_block_header64_new_internal: (skip): |
4755 | | **/ |
4756 | | static FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4757 | | fu_struct_efi_fault_tolerant_working_block_header64_new_internal(void) |
4758 | 83.0k | { |
4759 | 83.0k | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = g_new0(FuStructEfiFaultTolerantWorkingBlockHeader64, 1); |
4760 | 83.0k | st->refcount = 1; |
4761 | 83.0k | return st; |
4762 | 83.0k | } |
4763 | | |
4764 | | /* getters */ |
4765 | | /** |
4766 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_signature: (skip): |
4767 | | **/ |
4768 | | static const fwupd_guid_t * |
4769 | | fu_struct_efi_fault_tolerant_working_block_header64_get_signature(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4770 | 82.2k | { |
4771 | 82.2k | g_return_val_if_fail(st != NULL, NULL); |
4772 | 82.2k | return (const fwupd_guid_t *) (st->buf->data + 0); |
4773 | 82.2k | } |
4774 | | /** |
4775 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_crc: (skip): |
4776 | | **/ |
4777 | | guint32 |
4778 | | fu_struct_efi_fault_tolerant_working_block_header64_get_crc(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4779 | 0 | { |
4780 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4781 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
4782 | 0 | } |
4783 | | /** |
4784 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_state: (skip): |
4785 | | **/ |
4786 | | FuEfiVariableStoreState |
4787 | | fu_struct_efi_fault_tolerant_working_block_header64_get_state(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4788 | 240 | { |
4789 | 240 | g_return_val_if_fail(st != NULL, 0x0); |
4790 | 240 | return st->buf->data[20]; |
4791 | 240 | } |
4792 | | /** |
4793 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size: (skip): |
4794 | | **/ |
4795 | | guint64 |
4796 | | fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4797 | 960 | { |
4798 | 960 | g_return_val_if_fail(st != NULL, 0x0); |
4799 | 960 | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
4800 | 960 | } |
4801 | | |
4802 | | /* setters */ |
4803 | | /** |
4804 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_signature: (skip): |
4805 | | **/ |
4806 | | static void |
4807 | | fu_struct_efi_fault_tolerant_working_block_header64_set_signature(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, const fwupd_guid_t *value) |
4808 | 160 | { |
4809 | 160 | g_return_if_fail(st != NULL); |
4810 | 160 | g_return_if_fail(value != NULL); |
4811 | 160 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
4812 | 160 | } |
4813 | | /** |
4814 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_crc: (skip): |
4815 | | **/ |
4816 | | void |
4817 | | fu_struct_efi_fault_tolerant_working_block_header64_set_crc(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, guint32 value) |
4818 | 320 | { |
4819 | 320 | g_return_if_fail(st != NULL); |
4820 | 320 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
4821 | 320 | } |
4822 | | /** |
4823 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_state: (skip): |
4824 | | **/ |
4825 | | void |
4826 | | fu_struct_efi_fault_tolerant_working_block_header64_set_state(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, FuEfiVariableStoreState value) |
4827 | 320 | { |
4828 | 320 | g_return_if_fail(st != NULL); |
4829 | 320 | st->buf->data[20] = value; |
4830 | 320 | } |
4831 | | /** |
4832 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_write_queue_size: (skip): |
4833 | | **/ |
4834 | | void |
4835 | | fu_struct_efi_fault_tolerant_working_block_header64_set_write_queue_size(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, guint64 value) |
4836 | 160 | { |
4837 | 160 | g_return_if_fail(st != NULL); |
4838 | 160 | fu_memwrite_uint64(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
4839 | 160 | } |
4840 | | /** |
4841 | | * fu_struct_efi_fault_tolerant_working_block_header64_new: (skip): |
4842 | | **/ |
4843 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4844 | | fu_struct_efi_fault_tolerant_working_block_header64_new(void) |
4845 | 160 | { |
4846 | 160 | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4847 | 160 | st->buf = g_byte_array_sized_new(32); |
4848 | 160 | fu_byte_array_set_size(st->buf, 32, 0x0); |
4849 | 160 | fu_struct_efi_fault_tolerant_working_block_header64_set_signature(st, (fwupd_guid_t *) "\x2b\x29\x58\x9e\x68\x7c\x7d\x49\xa0\xce\x65\x0\xfd\x9f\x1b\x95"); |
4850 | 160 | fu_struct_efi_fault_tolerant_working_block_header64_set_crc(st, 0xFFFFFFFF); |
4851 | 160 | fu_struct_efi_fault_tolerant_working_block_header64_set_state(st, FU_EFI_VARIABLE_STORE_STATE_EMPTY); |
4852 | 160 | memcpy(st->buf->data + 0x15, "\xFF\xFF\xFF", 3); /* nocheck:blocked */ |
4853 | 160 | return st; |
4854 | 160 | } |
4855 | | /** |
4856 | | * fu_struct_efi_fault_tolerant_working_block_header64_to_string: (skip): |
4857 | | **/ |
4858 | | static gchar * |
4859 | | fu_struct_efi_fault_tolerant_working_block_header64_to_string(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4860 | 0 | { |
4861 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiFaultTolerantWorkingBlockHeader64:\n"); |
4862 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4863 | 0 | { |
4864 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_fault_tolerant_working_block_header64_get_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4865 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
4866 | 0 | } |
4867 | 0 | g_string_append_printf(str, " crc: 0x%x\n", |
4868 | 0 | (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_crc(st)); |
4869 | 0 | { |
4870 | 0 | const gchar *tmp = fu_efi_variable_store_state_to_string(fu_struct_efi_fault_tolerant_working_block_header64_get_state(st)); |
4871 | 0 | if (tmp != NULL) { |
4872 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_state(st), tmp); |
4873 | 0 | } else { |
4874 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_state(st)); |
4875 | 0 | } |
4876 | 0 | } |
4877 | 0 | g_string_append_printf(str, " write_queue_size: 0x%x\n", |
4878 | 0 | (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size(st)); |
4879 | 0 | if (str->len > 0) |
4880 | 0 | g_string_set_size(str, str->len - 1); |
4881 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4882 | 0 | } |
4883 | | static gboolean |
4884 | | fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, GError **error) |
4885 | 82.2k | { |
4886 | 82.2k | g_return_val_if_fail(st != NULL, FALSE); |
4887 | 82.2k | if (memcmp(fu_struct_efi_fault_tolerant_working_block_header64_get_signature(st), "\x2b\x29\x58\x9e\x68\x7c\x7d\x49\xa0\xce\x65\x0\xfd\x9f\x1b\x95", 16) != 0) { |
4888 | 78.7k | g_set_error_literal(error, |
4889 | 78.7k | FWUPD_ERROR, |
4890 | 78.7k | FWUPD_ERROR_INVALID_DATA, |
4891 | 78.7k | "constant FuStructEfiFaultTolerantWorkingBlockHeader64.signature was not valid"); |
4892 | 78.7k | return FALSE; |
4893 | 78.7k | } |
4894 | 3.42k | return TRUE; |
4895 | 82.2k | } |
4896 | | /** |
4897 | | * fu_struct_efi_fault_tolerant_working_block_header64_validate_stream: (skip): |
4898 | | **/ |
4899 | | gboolean |
4900 | | fu_struct_efi_fault_tolerant_working_block_header64_validate_stream(GInputStream *stream, gsize offset, GError **error) |
4901 | 82.4k | { |
4902 | 82.4k | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4903 | 82.4k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
4904 | 82.4k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4905 | 82.4k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4906 | 82.4k | if (st->buf == NULL) { |
4907 | 0 | g_prefix_error(error, "FuStructEfiFaultTolerantWorkingBlockHeader64 failed read of 0x%x: ", (guint) 32); |
4908 | 0 | return FALSE; |
4909 | 0 | } |
4910 | 82.4k | if (st->buf->len != 32) { |
4911 | 697 | g_set_error(error, |
4912 | 697 | FWUPD_ERROR, |
4913 | 697 | FWUPD_ERROR_INVALID_DATA, |
4914 | 697 | "FuStructEfiFaultTolerantWorkingBlockHeader64 requested 0x%x and got 0x%x", |
4915 | 697 | (guint) 32, |
4916 | 697 | (guint) st->buf->len); |
4917 | 697 | return FALSE; |
4918 | 697 | } |
4919 | 81.7k | return fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error); |
4920 | 82.4k | } |
4921 | | static gboolean |
4922 | | fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, GError **error) |
4923 | 480 | { |
4924 | 480 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4925 | 0 | g_autofree gchar *str = fu_struct_efi_fault_tolerant_working_block_header64_to_string(st); |
4926 | 0 | g_debug("%s", str); |
4927 | 0 | } |
4928 | 480 | if (!fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error)) |
4929 | 0 | return FALSE; |
4930 | 480 | return TRUE; |
4931 | 480 | } |
4932 | | /** |
4933 | | * fu_struct_efi_fault_tolerant_working_block_header64_parse_stream: (skip): |
4934 | | **/ |
4935 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4936 | | fu_struct_efi_fault_tolerant_working_block_header64_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4937 | 480 | { |
4938 | 480 | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4939 | 480 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4940 | 480 | if (st->buf == NULL) { |
4941 | 0 | g_prefix_error(error, "FuStructEfiFaultTolerantWorkingBlockHeader64 failed read of 0x%x: ", (guint) 32); |
4942 | 0 | return NULL; |
4943 | 0 | } |
4944 | 480 | if (st->buf->len != 32) { |
4945 | 0 | g_set_error(error, |
4946 | 0 | FWUPD_ERROR, |
4947 | 0 | FWUPD_ERROR_INVALID_DATA, |
4948 | 0 | "FuStructEfiFaultTolerantWorkingBlockHeader64 requested 0x%x and got 0x%x", |
4949 | 0 | (guint) 32, |
4950 | 0 | (guint) st->buf->len); |
4951 | 0 | return NULL; |
4952 | 0 | } |
4953 | 480 | if (!fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(st, error)) |
4954 | 0 | return NULL; |
4955 | 480 | return g_steal_pointer(&st); |
4956 | 480 | } |
4957 | | /** |
4958 | | * fu_struct_shim_hive_ref: (skip): |
4959 | | **/ |
4960 | | FuStructShimHive * |
4961 | | fu_struct_shim_hive_ref(FuStructShimHive *st) |
4962 | 0 | { |
4963 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4964 | 0 | st->refcount++; |
4965 | 0 | return st; |
4966 | 0 | } |
4967 | | /** |
4968 | | * fu_struct_shim_hive_unref: (skip): |
4969 | | **/ |
4970 | | void |
4971 | | fu_struct_shim_hive_unref(FuStructShimHive *st) |
4972 | 1.43k | { |
4973 | 1.43k | g_return_if_fail(st != NULL); |
4974 | 1.43k | if (st->refcount == 0) { |
4975 | 0 | g_critical("FuStructShimHive refcount already zero"); |
4976 | 0 | return; |
4977 | 0 | } |
4978 | 1.43k | if (--st->refcount > 0) |
4979 | 0 | return; |
4980 | 1.43k | if (st->buf != NULL) |
4981 | 1.18k | g_byte_array_unref(st->buf); |
4982 | 1.43k | g_free(st); |
4983 | 1.43k | } |
4984 | | /** |
4985 | | * fu_struct_shim_hive_new_internal: (skip): |
4986 | | **/ |
4987 | | static FuStructShimHive * |
4988 | | fu_struct_shim_hive_new_internal(void) |
4989 | 1.43k | { |
4990 | 1.43k | FuStructShimHive *st = g_new0(FuStructShimHive, 1); |
4991 | 1.43k | st->refcount = 1; |
4992 | 1.43k | return st; |
4993 | 1.43k | } |
4994 | | |
4995 | | /* getters */ |
4996 | | /** |
4997 | | * fu_struct_shim_hive_get_magic: (skip): |
4998 | | **/ |
4999 | | static gchar * |
5000 | | fu_struct_shim_hive_get_magic(const FuStructShimHive *st) |
5001 | 411 | { |
5002 | 411 | g_return_val_if_fail(st != NULL, NULL); |
5003 | 411 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
5004 | 411 | } |
5005 | | /** |
5006 | | * fu_struct_shim_hive_get_header_version: (skip): |
5007 | | **/ |
5008 | | guint8 |
5009 | | fu_struct_shim_hive_get_header_version(const FuStructShimHive *st) |
5010 | 716 | { |
5011 | 716 | g_return_val_if_fail(st != NULL, 0x0); |
5012 | 716 | return st->buf->data[4]; |
5013 | 716 | } |
5014 | | /** |
5015 | | * fu_struct_shim_hive_get_items_count: (skip): |
5016 | | **/ |
5017 | | guint8 |
5018 | | fu_struct_shim_hive_get_items_count(const FuStructShimHive *st) |
5019 | 714 | { |
5020 | 714 | g_return_val_if_fail(st != NULL, 0x0); |
5021 | 714 | return st->buf->data[5]; |
5022 | 714 | } |
5023 | | /** |
5024 | | * fu_struct_shim_hive_get_items_offset: (skip): |
5025 | | **/ |
5026 | | guint8 |
5027 | | fu_struct_shim_hive_get_items_offset(const FuStructShimHive *st) |
5028 | 714 | { |
5029 | 714 | g_return_val_if_fail(st != NULL, 0x0); |
5030 | 714 | return st->buf->data[6]; |
5031 | 714 | } |
5032 | | /** |
5033 | | * fu_struct_shim_hive_get_crc32: (skip): |
5034 | | **/ |
5035 | | guint32 |
5036 | | fu_struct_shim_hive_get_crc32(const FuStructShimHive *st) |
5037 | 0 | { |
5038 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
5039 | 0 | return fu_memread_uint32(st->buf->data + 7, G_LITTLE_ENDIAN); |
5040 | 0 | } |
5041 | | |
5042 | | /* setters */ |
5043 | | /** |
5044 | | * fu_struct_shim_hive_set_magic: (skip): |
5045 | | **/ |
5046 | | static gboolean |
5047 | | fu_struct_shim_hive_set_magic(FuStructShimHive *st, const gchar *value, GError **error) |
5048 | 248 | { |
5049 | 248 | gsize len; |
5050 | 248 | g_return_val_if_fail(st != NULL, FALSE); |
5051 | 248 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
5052 | 248 | if (value == NULL) { |
5053 | 0 | memset(st->buf->data + 0, 0x0, 4); |
5054 | 0 | return TRUE; |
5055 | 0 | } |
5056 | 248 | len = strlen(value); |
5057 | 248 | if (len > 4) { |
5058 | 0 | g_set_error(error, |
5059 | 0 | FWUPD_ERROR, |
5060 | 0 | FWUPD_ERROR_INVALID_DATA, |
5061 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructShimHive.magic (0x%x bytes)", |
5062 | 0 | value, (guint) len, (guint) 4); |
5063 | 0 | return FALSE; |
5064 | 0 | } |
5065 | 248 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
5066 | 248 | } |
5067 | | /** |
5068 | | * fu_struct_shim_hive_set_header_version: (skip): |
5069 | | **/ |
5070 | | void |
5071 | | fu_struct_shim_hive_set_header_version(FuStructShimHive *st, guint8 value) |
5072 | 248 | { |
5073 | 248 | g_return_if_fail(st != NULL); |
5074 | 248 | st->buf->data[4] = value; |
5075 | 248 | } |
5076 | | /** |
5077 | | * fu_struct_shim_hive_set_items_count: (skip): |
5078 | | **/ |
5079 | | void |
5080 | | fu_struct_shim_hive_set_items_count(FuStructShimHive *st, guint8 value) |
5081 | 248 | { |
5082 | 248 | g_return_if_fail(st != NULL); |
5083 | 248 | st->buf->data[5] = value; |
5084 | 248 | } |
5085 | | /** |
5086 | | * fu_struct_shim_hive_set_items_offset: (skip): |
5087 | | **/ |
5088 | | void |
5089 | | fu_struct_shim_hive_set_items_offset(FuStructShimHive *st, guint8 value) |
5090 | 248 | { |
5091 | 248 | g_return_if_fail(st != NULL); |
5092 | 248 | st->buf->data[6] = value; |
5093 | 248 | } |
5094 | | /** |
5095 | | * fu_struct_shim_hive_set_crc32: (skip): |
5096 | | **/ |
5097 | | void |
5098 | | fu_struct_shim_hive_set_crc32(FuStructShimHive *st, guint32 value) |
5099 | 248 | { |
5100 | 248 | g_return_if_fail(st != NULL); |
5101 | 248 | fu_memwrite_uint32(st->buf->data + 7, value, G_LITTLE_ENDIAN); |
5102 | 248 | } |
5103 | | /** |
5104 | | * fu_struct_shim_hive_new: (skip): |
5105 | | **/ |
5106 | | FuStructShimHive * |
5107 | | fu_struct_shim_hive_new(void) |
5108 | 248 | { |
5109 | 248 | FuStructShimHive *st = fu_struct_shim_hive_new_internal(); |
5110 | 248 | st->buf = g_byte_array_sized_new(11); |
5111 | 248 | fu_byte_array_set_size(st->buf, 11, 0x0); |
5112 | 248 | fu_struct_shim_hive_set_magic(st, "HIVE", NULL); |
5113 | 248 | fu_struct_shim_hive_set_header_version(st, 0x1); |
5114 | 248 | return st; |
5115 | 248 | } |
5116 | | /** |
5117 | | * fu_struct_shim_hive_to_string: (skip): |
5118 | | **/ |
5119 | | static gchar * |
5120 | | fu_struct_shim_hive_to_string(const FuStructShimHive *st) |
5121 | 0 | { |
5122 | 0 | g_autoptr(GString) str = g_string_new("FuStructShimHive:\n"); |
5123 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5124 | 0 | { |
5125 | 0 | g_autofree gchar *tmp = fu_struct_shim_hive_get_magic(st); |
5126 | 0 | if (tmp != NULL) |
5127 | 0 | g_string_append_printf(str, " magic: %s\n", tmp); |
5128 | 0 | } |
5129 | 0 | g_string_append_printf(str, " header_version: 0x%x\n", |
5130 | 0 | (guint) fu_struct_shim_hive_get_header_version(st)); |
5131 | 0 | g_string_append_printf(str, " items_count: 0x%x\n", |
5132 | 0 | (guint) fu_struct_shim_hive_get_items_count(st)); |
5133 | 0 | g_string_append_printf(str, " items_offset: 0x%x\n", |
5134 | 0 | (guint) fu_struct_shim_hive_get_items_offset(st)); |
5135 | 0 | g_string_append_printf(str, " crc32: 0x%x\n", |
5136 | 0 | (guint) fu_struct_shim_hive_get_crc32(st)); |
5137 | 0 | if (str->len > 0) |
5138 | 0 | g_string_set_size(str, str->len - 1); |
5139 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
5140 | 0 | } |
5141 | | static gboolean |
5142 | | fu_struct_shim_hive_validate_internal(FuStructShimHive *st, GError **error) |
5143 | 1.12k | { |
5144 | 1.12k | g_return_val_if_fail(st != NULL, FALSE); |
5145 | 1.12k | if (strncmp((const gchar *) (st->buf->data + 0), "HIVE", 4) != 0) { |
5146 | 411 | g_autofree gchar *str = fu_struct_shim_hive_get_magic(st); |
5147 | 411 | g_set_error(error, |
5148 | 411 | FWUPD_ERROR, |
5149 | 411 | FWUPD_ERROR_INVALID_DATA, |
5150 | 411 | "constant FuStructShimHive.magic was not valid, " |
5151 | 411 | "expected 'HIVE' and got '%s'", |
5152 | 411 | str); |
5153 | 411 | return FALSE; |
5154 | 411 | } |
5155 | 715 | return TRUE; |
5156 | 1.12k | } |
5157 | | static gboolean |
5158 | | fu_struct_shim_hive_parse_internal(FuStructShimHive *st, GError **error) |
5159 | 1.12k | { |
5160 | 1.12k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
5161 | 0 | g_autofree gchar *str = fu_struct_shim_hive_to_string(st); |
5162 | 0 | g_debug("%s", str); |
5163 | 0 | } |
5164 | 1.12k | if (!fu_struct_shim_hive_validate_internal(st, error)) |
5165 | 411 | return FALSE; |
5166 | 715 | return TRUE; |
5167 | 1.12k | } |
5168 | | /** |
5169 | | * fu_struct_shim_hive_parse_stream: (skip): |
5170 | | **/ |
5171 | | FuStructShimHive * |
5172 | | fu_struct_shim_hive_parse_stream(GInputStream *stream, gsize offset, GError **error) |
5173 | 1.18k | { |
5174 | 1.18k | g_autoptr(FuStructShimHive) st = fu_struct_shim_hive_new_internal(); |
5175 | 1.18k | st->buf = fu_input_stream_read_byte_array(stream, offset, 11, NULL, error); |
5176 | 1.18k | if (st->buf == NULL) { |
5177 | 0 | g_prefix_error(error, "FuStructShimHive failed read of 0x%x: ", (guint) 11); |
5178 | 0 | return NULL; |
5179 | 0 | } |
5180 | 1.18k | if (st->buf->len != 11) { |
5181 | 61 | g_set_error(error, |
5182 | 61 | FWUPD_ERROR, |
5183 | 61 | FWUPD_ERROR_INVALID_DATA, |
5184 | 61 | "FuStructShimHive requested 0x%x and got 0x%x", |
5185 | 61 | (guint) 11, |
5186 | 61 | (guint) st->buf->len); |
5187 | 61 | return NULL; |
5188 | 61 | } |
5189 | 1.12k | if (!fu_struct_shim_hive_parse_internal(st, error)) |
5190 | 411 | return NULL; |
5191 | 715 | return g_steal_pointer(&st); |
5192 | 1.12k | } |
5193 | | /** |
5194 | | * fu_struct_shim_hive_item_ref: (skip): |
5195 | | **/ |
5196 | | FuStructShimHiveItem * |
5197 | | fu_struct_shim_hive_item_ref(FuStructShimHiveItem *st) |
5198 | 0 | { |
5199 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5200 | 0 | st->refcount++; |
5201 | 0 | return st; |
5202 | 0 | } |
5203 | | /** |
5204 | | * fu_struct_shim_hive_item_unref: (skip): |
5205 | | **/ |
5206 | | void |
5207 | | fu_struct_shim_hive_item_unref(FuStructShimHiveItem *st) |
5208 | 4.67k | { |
5209 | 4.67k | g_return_if_fail(st != NULL); |
5210 | 4.67k | if (st->refcount == 0) { |
5211 | 0 | g_critical("FuStructShimHiveItem refcount already zero"); |
5212 | 0 | return; |
5213 | 0 | } |
5214 | 4.67k | if (--st->refcount > 0) |
5215 | 0 | return; |
5216 | 4.67k | if (st->buf != NULL) |
5217 | 4.40k | g_byte_array_unref(st->buf); |
5218 | 4.67k | g_free(st); |
5219 | 4.67k | } |
5220 | | /** |
5221 | | * fu_struct_shim_hive_item_new_internal: (skip): |
5222 | | **/ |
5223 | | static FuStructShimHiveItem * |
5224 | | fu_struct_shim_hive_item_new_internal(void) |
5225 | 4.67k | { |
5226 | 4.67k | FuStructShimHiveItem *st = g_new0(FuStructShimHiveItem, 1); |
5227 | 4.67k | st->refcount = 1; |
5228 | 4.67k | return st; |
5229 | 4.67k | } |
5230 | | |
5231 | | /* getters */ |
5232 | | /** |
5233 | | * fu_struct_shim_hive_item_get_key_length: (skip): |
5234 | | **/ |
5235 | | guint8 |
5236 | | fu_struct_shim_hive_item_get_key_length(const FuStructShimHiveItem *st) |
5237 | 3.64k | { |
5238 | 3.64k | g_return_val_if_fail(st != NULL, 0x0); |
5239 | 3.64k | return st->buf->data[0]; |
5240 | 3.64k | } |
5241 | | /** |
5242 | | * fu_struct_shim_hive_item_get_value_length: (skip): |
5243 | | **/ |
5244 | | guint32 |
5245 | | fu_struct_shim_hive_item_get_value_length(const FuStructShimHiveItem *st) |
5246 | 3.55k | { |
5247 | 3.55k | g_return_val_if_fail(st != NULL, 0x0); |
5248 | 3.55k | return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN); |
5249 | 3.55k | } |
5250 | | |
5251 | | /* setters */ |
5252 | | /** |
5253 | | * fu_struct_shim_hive_item_set_key_length: (skip): |
5254 | | **/ |
5255 | | void |
5256 | | fu_struct_shim_hive_item_set_key_length(FuStructShimHiveItem *st, guint8 value) |
5257 | 745 | { |
5258 | 745 | g_return_if_fail(st != NULL); |
5259 | 745 | st->buf->data[0] = value; |
5260 | 745 | } |
5261 | | /** |
5262 | | * fu_struct_shim_hive_item_set_value_length: (skip): |
5263 | | **/ |
5264 | | void |
5265 | | fu_struct_shim_hive_item_set_value_length(FuStructShimHiveItem *st, guint32 value) |
5266 | 745 | { |
5267 | 745 | g_return_if_fail(st != NULL); |
5268 | 745 | fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN); |
5269 | 745 | } |
5270 | | /** |
5271 | | * fu_struct_shim_hive_item_new: (skip): |
5272 | | **/ |
5273 | | FuStructShimHiveItem * |
5274 | | fu_struct_shim_hive_item_new(void) |
5275 | 745 | { |
5276 | 745 | FuStructShimHiveItem *st = fu_struct_shim_hive_item_new_internal(); |
5277 | 745 | st->buf = g_byte_array_sized_new(5); |
5278 | 745 | fu_byte_array_set_size(st->buf, 5, 0x0); |
5279 | 745 | return st; |
5280 | 745 | } |
5281 | | /** |
5282 | | * fu_struct_shim_hive_item_to_string: (skip): |
5283 | | **/ |
5284 | | static gchar * |
5285 | | fu_struct_shim_hive_item_to_string(const FuStructShimHiveItem *st) |
5286 | 0 | { |
5287 | 0 | g_autoptr(GString) str = g_string_new("FuStructShimHiveItem:\n"); |
5288 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5289 | 0 | g_string_append_printf(str, " key_length: 0x%x\n", |
5290 | 0 | (guint) fu_struct_shim_hive_item_get_key_length(st)); |
5291 | 0 | g_string_append_printf(str, " value_length: 0x%x\n", |
5292 | 0 | (guint) fu_struct_shim_hive_item_get_value_length(st)); |
5293 | 0 | if (str->len > 0) |
5294 | 0 | g_string_set_size(str, str->len - 1); |
5295 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
5296 | 0 | } |
5297 | | static gboolean |
5298 | | fu_struct_shim_hive_item_validate_internal(FuStructShimHiveItem *st, GError **error) |
5299 | 3.64k | { |
5300 | 3.64k | g_return_val_if_fail(st != NULL, FALSE); |
5301 | 3.64k | return TRUE; |
5302 | 3.64k | } |
5303 | | static gboolean |
5304 | | fu_struct_shim_hive_item_parse_internal(FuStructShimHiveItem *st, GError **error) |
5305 | 3.64k | { |
5306 | 3.64k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
5307 | 0 | g_autofree gchar *str = fu_struct_shim_hive_item_to_string(st); |
5308 | 0 | g_debug("%s", str); |
5309 | 0 | } |
5310 | 3.64k | if (!fu_struct_shim_hive_item_validate_internal(st, error)) |
5311 | 0 | return FALSE; |
5312 | 3.64k | return TRUE; |
5313 | 3.64k | } |
5314 | | /** |
5315 | | * fu_struct_shim_hive_item_parse_stream: (skip): |
5316 | | **/ |
5317 | | FuStructShimHiveItem * |
5318 | | fu_struct_shim_hive_item_parse_stream(GInputStream *stream, gsize offset, GError **error) |
5319 | 3.93k | { |
5320 | 3.93k | g_autoptr(FuStructShimHiveItem) st = fu_struct_shim_hive_item_new_internal(); |
5321 | 3.93k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
5322 | 3.93k | if (st->buf == NULL) { |
5323 | 269 | g_prefix_error(error, "FuStructShimHiveItem failed read of 0x%x: ", (guint) 5); |
5324 | 269 | return NULL; |
5325 | 269 | } |
5326 | 3.66k | if (st->buf->len != 5) { |
5327 | 15 | g_set_error(error, |
5328 | 15 | FWUPD_ERROR, |
5329 | 15 | FWUPD_ERROR_INVALID_DATA, |
5330 | 15 | "FuStructShimHiveItem requested 0x%x and got 0x%x", |
5331 | 15 | (guint) 5, |
5332 | 15 | (guint) st->buf->len); |
5333 | 15 | return NULL; |
5334 | 15 | } |
5335 | 3.64k | if (!fu_struct_shim_hive_item_parse_internal(st, error)) |
5336 | 0 | return NULL; |
5337 | 3.64k | return g_steal_pointer(&st); |
5338 | 3.64k | } |