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