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