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 | 2.85k | { |
216 | 2.85k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_NONE) |
217 | 0 | return "none"; |
218 | 2.85k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY) |
219 | 1.83k | return "legacy"; |
220 | 1.02k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_TIANO) |
221 | 1.02k | return "tiano"; |
222 | 0 | return NULL; |
223 | 1.02k | } |
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 | 16.4k | { |
236 | 16.4k | if (val == FU_EFI_SECTION_TYPE_COMPRESSION) |
237 | 0 | return "compression"; |
238 | 16.4k | if (val == FU_EFI_SECTION_TYPE_GUID_DEFINED) |
239 | 0 | return "guid-defined"; |
240 | 16.4k | if (val == FU_EFI_SECTION_TYPE_DISPOSABLE) |
241 | 448 | return "disposable"; |
242 | 15.9k | if (val == FU_EFI_SECTION_TYPE_PE32) |
243 | 588 | return "pe32"; |
244 | 15.3k | if (val == FU_EFI_SECTION_TYPE_PIC) |
245 | 335 | return "pic"; |
246 | 15.0k | if (val == FU_EFI_SECTION_TYPE_TE) |
247 | 194 | return "te"; |
248 | 14.8k | if (val == FU_EFI_SECTION_TYPE_DXE_DEPEX) |
249 | 284 | return "dxe-depex"; |
250 | 14.5k | if (val == FU_EFI_SECTION_TYPE_VERSION) |
251 | 0 | return "version"; |
252 | 14.5k | if (val == FU_EFI_SECTION_TYPE_USER_INTERFACE) |
253 | 0 | return "user-interface"; |
254 | 14.5k | if (val == FU_EFI_SECTION_TYPE_COMPATIBILITY16) |
255 | 2.55k | return "compatibility16"; |
256 | 12.0k | if (val == FU_EFI_SECTION_TYPE_VOLUME_IMAGE) |
257 | 0 | return "volume-image"; |
258 | 12.0k | if (val == FU_EFI_SECTION_TYPE_FREEFORM_SUBTYPE_GUID) |
259 | 0 | return "freeform-subtype-guid"; |
260 | 12.0k | if (val == FU_EFI_SECTION_TYPE_RAW) |
261 | 404 | return "raw"; |
262 | 11.6k | if (val == FU_EFI_SECTION_TYPE_PEI_DEPEX) |
263 | 1.16k | return "pei-depex"; |
264 | 10.4k | if (val == FU_EFI_SECTION_TYPE_MM_DEPEX) |
265 | 275 | return "mm-depex"; |
266 | 10.1k | if (val == FU_EFI_SECTION_TYPE_PHOENIX_SECTION_POSTCODE) |
267 | 1.84k | return "phoenix-section-postcode"; |
268 | 8.33k | if (val == FU_EFI_SECTION_TYPE_INSYDE_SECTION_POSTCODE) |
269 | 242 | return "insyde-section-postcode"; |
270 | 8.09k | return NULL; |
271 | 8.33k | } |
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 | 204 | { |
501 | 204 | if (val == FU_EFI_VARIABLE_STORE_STATE_UNSET) |
502 | 85 | return "unset"; |
503 | 119 | if (val == FU_EFI_VARIABLE_STORE_STATE_HEALTHY) |
504 | 0 | return "healthy"; |
505 | 119 | if (val == FU_EFI_VARIABLE_STORE_STATE_EMPTY) |
506 | 39 | return "empty"; |
507 | 80 | return NULL; |
508 | 119 | } |
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 | 1.32k | { |
540 | 1.32k | if (val == FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) |
541 | 0 | return "formatted"; |
542 | 1.32k | return NULL; |
543 | 1.32k | } |
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 | 9.87k | { |
700 | 9.87k | g_return_if_fail(st != NULL); |
701 | 9.87k | if (st->refcount == 0) { |
702 | 0 | g_critical("FuStructEfiFile refcount already zero"); |
703 | 0 | return; |
704 | 0 | } |
705 | 9.87k | if (--st->refcount > 0) |
706 | 0 | return; |
707 | 9.87k | if (st->buf != NULL) |
708 | 8.03k | g_byte_array_unref(st->buf); |
709 | 9.87k | g_free(st); |
710 | 9.87k | } |
711 | | /** |
712 | | * fu_struct_efi_file_new_internal: (skip): |
713 | | **/ |
714 | | static FuStructEfiFile * |
715 | | fu_struct_efi_file_new_internal(void) |
716 | 9.70k | { |
717 | 9.70k | FuStructEfiFile *st = g_new0(FuStructEfiFile, 1); |
718 | 9.70k | st->refcount = 1; |
719 | 9.70k | return st; |
720 | 9.70k | } |
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 | 7.55k | { |
729 | 7.55k | g_return_val_if_fail(st != NULL, NULL); |
730 | 7.55k | return (const fwupd_guid_t *) (st->buf->data + 0); |
731 | 7.55k | } |
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 | 7.55k | { |
738 | 7.55k | g_return_val_if_fail(st != NULL, 0x0); |
739 | 7.55k | return st->buf->data[16]; |
740 | 7.55k | } |
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 | 697 | { |
747 | 697 | g_return_val_if_fail(st != NULL, 0x0); |
748 | 697 | return st->buf->data[17]; |
749 | 697 | } |
750 | | /** |
751 | | * fu_struct_efi_file_get_type: (skip): |
752 | | **/ |
753 | | FuEfiFileType |
754 | | fu_struct_efi_file_get_type(const FuStructEfiFile *st) |
755 | 7.55k | { |
756 | 7.55k | g_return_val_if_fail(st != NULL, 0x0); |
757 | 7.55k | return st->buf->data[18]; |
758 | 7.55k | } |
759 | | /** |
760 | | * fu_struct_efi_file_get_attrs: (skip): |
761 | | **/ |
762 | | guint8 |
763 | | fu_struct_efi_file_get_attrs(const FuStructEfiFile *st) |
764 | 7.55k | { |
765 | 7.55k | g_return_val_if_fail(st != NULL, 0x0); |
766 | 7.55k | return st->buf->data[19]; |
767 | 7.55k | } |
768 | | /** |
769 | | * fu_struct_efi_file_get_size: (skip): |
770 | | **/ |
771 | | guint32 |
772 | | fu_struct_efi_file_get_size(const FuStructEfiFile *st) |
773 | 7.59k | { |
774 | 7.59k | g_return_val_if_fail(st != NULL, 0x0); |
775 | 7.59k | return fu_memread_uint24(st->buf->data + 20, G_LITTLE_ENDIAN); |
776 | 7.59k | } |
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 | 1.84k | { |
794 | 1.84k | g_return_if_fail(st != NULL); |
795 | 1.84k | g_return_if_fail(value != NULL); |
796 | 1.84k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
797 | 1.84k | } |
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 | 3.69k | { |
804 | 3.69k | g_return_if_fail(st != NULL); |
805 | 3.69k | st->buf->data[16] = value; |
806 | 3.69k | } |
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 | 1.84k | { |
813 | 1.84k | g_return_if_fail(st != NULL); |
814 | 1.84k | st->buf->data[17] = value; |
815 | 1.84k | } |
816 | | /** |
817 | | * fu_struct_efi_file_set_type: (skip): |
818 | | **/ |
819 | | void |
820 | | fu_struct_efi_file_set_type(FuStructEfiFile *st, FuEfiFileType value) |
821 | 1.84k | { |
822 | 1.84k | g_return_if_fail(st != NULL); |
823 | 1.84k | st->buf->data[18] = value; |
824 | 1.84k | } |
825 | | /** |
826 | | * fu_struct_efi_file_set_attrs: (skip): |
827 | | **/ |
828 | | void |
829 | | fu_struct_efi_file_set_attrs(FuStructEfiFile *st, guint8 value) |
830 | 1.84k | { |
831 | 1.84k | g_return_if_fail(st != NULL); |
832 | 1.84k | st->buf->data[19] = value; |
833 | 1.84k | } |
834 | | /** |
835 | | * fu_struct_efi_file_set_size: (skip): |
836 | | **/ |
837 | | void |
838 | | fu_struct_efi_file_set_size(FuStructEfiFile *st, guint32 value) |
839 | 1.84k | { |
840 | 1.84k | g_return_if_fail(st != NULL); |
841 | 1.84k | fu_memwrite_uint24(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
842 | 1.84k | } |
843 | | /** |
844 | | * fu_struct_efi_file_set_state: (skip): |
845 | | **/ |
846 | | void |
847 | | fu_struct_efi_file_set_state(FuStructEfiFile *st, guint8 value) |
848 | 2.06k | { |
849 | 2.06k | g_return_if_fail(st != NULL); |
850 | 2.06k | st->buf->data[23] = value; |
851 | 2.06k | } |
852 | | /** |
853 | | * fu_struct_efi_file_new: (skip): |
854 | | **/ |
855 | | FuStructEfiFile * |
856 | | fu_struct_efi_file_new(void) |
857 | 2.06k | { |
858 | 2.06k | FuStructEfiFile *st = fu_struct_efi_file_new_internal(); |
859 | 2.06k | st->buf = g_byte_array_sized_new(24); |
860 | 2.06k | fu_byte_array_set_size(st->buf, 24, 0x0); |
861 | 2.06k | fu_struct_efi_file_set_state(st, 0xF8); |
862 | 2.06k | return st; |
863 | 2.06k | } |
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 | 7.72k | { |
901 | 7.72k | g_return_val_if_fail(st != NULL, FALSE); |
902 | 7.72k | return TRUE; |
903 | 7.72k | } |
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 | 7.55k | { |
925 | 7.55k | 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 | 7.55k | if (!fu_struct_efi_file_validate_internal(st, error)) |
930 | 0 | return FALSE; |
931 | 7.55k | return TRUE; |
932 | 7.55k | } |
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 | 7.64k | { |
939 | 7.64k | g_autoptr(FuStructEfiFile) st = fu_struct_efi_file_new_internal(); |
940 | 7.64k | st->buf = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error); |
941 | 7.64k | 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 | 7.64k | if (st->buf->len != 24) { |
946 | 82 | g_set_error(error, |
947 | 82 | FWUPD_ERROR, |
948 | 82 | FWUPD_ERROR_INVALID_DATA, |
949 | 82 | "FuStructEfiFile requested 0x%x and got 0x%x", |
950 | 82 | (guint) 24, |
951 | 82 | (guint) st->buf->len); |
952 | 82 | return NULL; |
953 | 82 | } |
954 | 7.55k | if (!fu_struct_efi_file_parse_internal(st, error)) |
955 | 0 | return NULL; |
956 | 7.55k | return g_steal_pointer(&st); |
957 | 7.55k | } |
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 | 177 | { |
991 | 177 | FuStructEfiFile2 *st = g_new0(FuStructEfiFile2, 1); |
992 | 177 | st->refcount = 1; |
993 | 177 | return st; |
994 | 177 | } |
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 | 168 | { |
1003 | 168 | g_return_val_if_fail(st != NULL, 0x0); |
1004 | 168 | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
1005 | 168 | } |
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 | 168 | { |
1025 | 168 | g_return_val_if_fail(st != NULL, FALSE); |
1026 | 168 | { |
1027 | 168 | GByteArray buf_tmp = { |
1028 | 168 | .data = (guint8*) st->buf->data + 0x0, |
1029 | 168 | .len = 24, |
1030 | 168 | }; |
1031 | 168 | FuStructEfiFile st_tmp = { .buf = &buf_tmp }; |
1032 | 168 | if (!fu_struct_efi_file_validate_internal(&st_tmp, error)) |
1033 | 0 | return FALSE; |
1034 | 168 | } |
1035 | 168 | return TRUE; |
1036 | 168 | } |
1037 | | static gboolean |
1038 | | fu_struct_efi_file2_parse_internal(FuStructEfiFile2 *st, GError **error) |
1039 | 168 | { |
1040 | 168 | 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 | 168 | if (!fu_struct_efi_file2_validate_internal(st, error)) |
1045 | 0 | return FALSE; |
1046 | 168 | return TRUE; |
1047 | 168 | } |
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 | 177 | { |
1054 | 177 | g_autoptr(FuStructEfiFile2) st = fu_struct_efi_file2_new_internal(); |
1055 | 177 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
1056 | 177 | 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 | 177 | 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 | 168 | if (!fu_struct_efi_file2_parse_internal(st, error)) |
1070 | 0 | return NULL; |
1071 | 168 | return g_steal_pointer(&st); |
1072 | 168 | } |
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 | 2.43k | { |
1089 | 2.43k | g_return_if_fail(st != NULL); |
1090 | 2.43k | if (st->refcount == 0) { |
1091 | 0 | g_critical("FuStructEfiSectionCompression refcount already zero"); |
1092 | 0 | return; |
1093 | 0 | } |
1094 | 2.43k | if (--st->refcount > 0) |
1095 | 0 | return; |
1096 | 2.43k | if (st->buf != NULL) |
1097 | 2.42k | g_byte_array_unref(st->buf); |
1098 | 2.43k | g_free(st); |
1099 | 2.43k | } |
1100 | | /** |
1101 | | * fu_struct_efi_section_compression_new_internal: (skip): |
1102 | | **/ |
1103 | | static FuStructEfiSectionCompression * |
1104 | | fu_struct_efi_section_compression_new_internal(void) |
1105 | 2.43k | { |
1106 | 2.43k | FuStructEfiSectionCompression *st = g_new0(FuStructEfiSectionCompression, 1); |
1107 | 2.43k | st->refcount = 1; |
1108 | 2.43k | return st; |
1109 | 2.43k | } |
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 | 2.42k | { |
1127 | 2.42k | g_return_val_if_fail(st != NULL, 0x0); |
1128 | 2.42k | return st->buf->data[4]; |
1129 | 2.42k | } |
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 | 2.42k | { |
1157 | 2.42k | g_return_val_if_fail(st != NULL, FALSE); |
1158 | 2.42k | return TRUE; |
1159 | 2.42k | } |
1160 | | static gboolean |
1161 | | fu_struct_efi_section_compression_parse_internal(FuStructEfiSectionCompression *st, GError **error) |
1162 | 2.42k | { |
1163 | 2.42k | 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 | 2.42k | if (!fu_struct_efi_section_compression_validate_internal(st, error)) |
1168 | 0 | return FALSE; |
1169 | 2.42k | return TRUE; |
1170 | 2.42k | } |
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 | 2.43k | { |
1177 | 2.43k | g_autoptr(FuStructEfiSectionCompression) st = fu_struct_efi_section_compression_new_internal(); |
1178 | 2.43k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
1179 | 2.43k | 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 | 2.42k | if (st->buf->len != 5) { |
1184 | 3 | g_set_error(error, |
1185 | 3 | FWUPD_ERROR, |
1186 | 3 | FWUPD_ERROR_INVALID_DATA, |
1187 | 3 | "FuStructEfiSectionCompression requested 0x%x and got 0x%x", |
1188 | 3 | (guint) 5, |
1189 | 3 | (guint) st->buf->len); |
1190 | 3 | return NULL; |
1191 | 3 | } |
1192 | 2.42k | if (!fu_struct_efi_section_compression_parse_internal(st, error)) |
1193 | 0 | return NULL; |
1194 | 2.42k | return g_steal_pointer(&st); |
1195 | 2.42k | } |
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 | 2.66k | { |
1212 | 2.66k | g_return_if_fail(st != NULL); |
1213 | 2.66k | if (st->refcount == 0) { |
1214 | 0 | g_critical("FuStructEfiLz77DecompressorHeader refcount already zero"); |
1215 | 0 | return; |
1216 | 0 | } |
1217 | 2.66k | if (--st->refcount > 0) |
1218 | 0 | return; |
1219 | 2.66k | if (st->buf != NULL) |
1220 | 2.66k | g_byte_array_unref(st->buf); |
1221 | 2.66k | g_free(st); |
1222 | 2.66k | } |
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 | 2.66k | { |
1229 | 2.66k | FuStructEfiLz77DecompressorHeader *st = g_new0(FuStructEfiLz77DecompressorHeader, 1); |
1230 | 2.66k | st->refcount = 1; |
1231 | 2.66k | return st; |
1232 | 2.66k | } |
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 | 2.64k | { |
1241 | 2.64k | g_return_val_if_fail(st != NULL, 0x0); |
1242 | 2.64k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
1243 | 2.64k | } |
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 | 2.57k | { |
1250 | 2.57k | g_return_val_if_fail(st != NULL, 0x0); |
1251 | 2.57k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1252 | 2.57k | } |
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 | 2.64k | { |
1274 | 2.64k | g_return_val_if_fail(st != NULL, FALSE); |
1275 | 2.64k | return TRUE; |
1276 | 2.64k | } |
1277 | | static gboolean |
1278 | | fu_struct_efi_lz77_decompressor_header_parse_internal(FuStructEfiLz77DecompressorHeader *st, GError **error) |
1279 | 2.64k | { |
1280 | 2.64k | 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 | 2.64k | if (!fu_struct_efi_lz77_decompressor_header_validate_internal(st, error)) |
1285 | 0 | return FALSE; |
1286 | 2.64k | return TRUE; |
1287 | 2.64k | } |
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 | 2.66k | { |
1294 | 2.66k | g_autoptr(FuStructEfiLz77DecompressorHeader) st = fu_struct_efi_lz77_decompressor_header_new_internal(); |
1295 | 2.66k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1296 | 2.66k | 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 | 2.66k | if (st->buf->len != 8) { |
1301 | 17 | g_set_error(error, |
1302 | 17 | FWUPD_ERROR, |
1303 | 17 | FWUPD_ERROR_INVALID_DATA, |
1304 | 17 | "FuStructEfiLz77DecompressorHeader requested 0x%x and got 0x%x", |
1305 | 17 | (guint) 8, |
1306 | 17 | (guint) st->buf->len); |
1307 | 17 | return NULL; |
1308 | 17 | } |
1309 | 2.64k | if (!fu_struct_efi_lz77_decompressor_header_parse_internal(st, error)) |
1310 | 0 | return NULL; |
1311 | 2.64k | return g_steal_pointer(&st); |
1312 | 2.64k | } |
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 | 26.3k | { |
1329 | 26.3k | g_return_if_fail(st != NULL); |
1330 | 26.3k | if (st->refcount == 0) { |
1331 | 0 | g_critical("FuStructEfiSection refcount already zero"); |
1332 | 0 | return; |
1333 | 0 | } |
1334 | 26.3k | if (--st->refcount > 0) |
1335 | 0 | return; |
1336 | 26.3k | if (st->buf != NULL) |
1337 | 23.7k | g_byte_array_unref(st->buf); |
1338 | 26.3k | g_free(st); |
1339 | 26.3k | } |
1340 | | /** |
1341 | | * fu_struct_efi_section_new_internal: (skip): |
1342 | | **/ |
1343 | | static FuStructEfiSection * |
1344 | | fu_struct_efi_section_new_internal(void) |
1345 | 26.3k | { |
1346 | 26.3k | FuStructEfiSection *st = g_new0(FuStructEfiSection, 1); |
1347 | 26.3k | st->refcount = 1; |
1348 | 26.3k | return st; |
1349 | 26.3k | } |
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 | 46.8k | { |
1358 | 46.8k | g_return_val_if_fail(st != NULL, 0x0); |
1359 | 46.8k | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1360 | 46.8k | } |
1361 | | /** |
1362 | | * fu_struct_efi_section_get_type: (skip): |
1363 | | **/ |
1364 | | FuEfiSectionType |
1365 | | fu_struct_efi_section_get_type(const FuStructEfiSection *st) |
1366 | 23.2k | { |
1367 | 23.2k | g_return_val_if_fail(st != NULL, 0x0); |
1368 | 23.2k | return st->buf->data[3]; |
1369 | 23.2k | } |
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 | 2.56k | { |
1378 | 2.56k | g_return_if_fail(st != NULL); |
1379 | 2.56k | fu_memwrite_uint24(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
1380 | 2.56k | } |
1381 | | /** |
1382 | | * fu_struct_efi_section_set_type: (skip): |
1383 | | **/ |
1384 | | void |
1385 | | fu_struct_efi_section_set_type(FuStructEfiSection *st, FuEfiSectionType value) |
1386 | 2.56k | { |
1387 | 2.56k | g_return_if_fail(st != NULL); |
1388 | 2.56k | st->buf->data[3] = value; |
1389 | 2.56k | } |
1390 | | /** |
1391 | | * fu_struct_efi_section_new: (skip): |
1392 | | **/ |
1393 | | FuStructEfiSection * |
1394 | | fu_struct_efi_section_new(void) |
1395 | 2.74k | { |
1396 | 2.74k | FuStructEfiSection *st = fu_struct_efi_section_new_internal(); |
1397 | 2.74k | st->buf = g_byte_array_sized_new(4); |
1398 | 2.74k | fu_byte_array_set_size(st->buf, 4, 0x0); |
1399 | 2.74k | return st; |
1400 | 2.74k | } |
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 | 23.5k | { |
1426 | 23.5k | g_return_val_if_fail(st != NULL, FALSE); |
1427 | 23.5k | return TRUE; |
1428 | 23.5k | } |
1429 | | static gboolean |
1430 | | fu_struct_efi_section_parse_internal(FuStructEfiSection *st, GError **error) |
1431 | 23.5k | { |
1432 | 23.5k | 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 | 23.5k | if (!fu_struct_efi_section_validate_internal(st, error)) |
1437 | 0 | return FALSE; |
1438 | 23.5k | return TRUE; |
1439 | 23.5k | } |
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 | 23.6k | { |
1446 | 23.6k | g_autoptr(FuStructEfiSection) st = fu_struct_efi_section_new_internal(); |
1447 | 23.6k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
1448 | 23.6k | 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 | 23.6k | if (st->buf->len != 4) { |
1453 | 45 | g_set_error(error, |
1454 | 45 | FWUPD_ERROR, |
1455 | 45 | FWUPD_ERROR_INVALID_DATA, |
1456 | 45 | "FuStructEfiSection requested 0x%x and got 0x%x", |
1457 | 45 | (guint) 4, |
1458 | 45 | (guint) st->buf->len); |
1459 | 45 | return NULL; |
1460 | 45 | } |
1461 | 23.5k | if (!fu_struct_efi_section_parse_internal(st, error)) |
1462 | 0 | return NULL; |
1463 | 23.5k | return g_steal_pointer(&st); |
1464 | 23.5k | } |
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 | 277 | { |
1481 | 277 | g_return_if_fail(st != NULL); |
1482 | 277 | if (st->refcount == 0) { |
1483 | 0 | g_critical("FuStructEfiSection2 refcount already zero"); |
1484 | 0 | return; |
1485 | 0 | } |
1486 | 277 | if (--st->refcount > 0) |
1487 | 0 | return; |
1488 | 277 | if (st->buf != NULL) |
1489 | 277 | g_byte_array_unref(st->buf); |
1490 | 277 | g_free(st); |
1491 | 277 | } |
1492 | | /** |
1493 | | * fu_struct_efi_section2_new_internal: (skip): |
1494 | | **/ |
1495 | | static FuStructEfiSection2 * |
1496 | | fu_struct_efi_section2_new_internal(void) |
1497 | 277 | { |
1498 | 277 | FuStructEfiSection2 *st = g_new0(FuStructEfiSection2, 1); |
1499 | 277 | st->refcount = 1; |
1500 | 277 | return st; |
1501 | 277 | } |
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 | 268 | { |
1510 | 268 | g_return_val_if_fail(st != NULL, 0x0); |
1511 | 268 | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1512 | 268 | } |
1513 | | /** |
1514 | | * fu_struct_efi_section2_get_type: (skip): |
1515 | | **/ |
1516 | | FuEfiSectionType |
1517 | | fu_struct_efi_section2_get_type(const FuStructEfiSection2 *st) |
1518 | 268 | { |
1519 | 268 | g_return_val_if_fail(st != NULL, 0x0); |
1520 | 268 | return st->buf->data[3]; |
1521 | 268 | } |
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 | 268 | { |
1528 | 268 | g_return_val_if_fail(st != NULL, 0x0); |
1529 | 268 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1530 | 268 | } |
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 | g_string_append_printf(str, " size: 0x%x\n", |
1542 | 0 | (guint) fu_struct_efi_section2_get_size(st)); |
1543 | 0 | { |
1544 | 0 | const gchar *tmp = fu_efi_section_type_to_string(fu_struct_efi_section2_get_type(st)); |
1545 | 0 | if (tmp != NULL) { |
1546 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_section2_get_type(st), tmp); |
1547 | 0 | } else { |
1548 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_section2_get_type(st)); |
1549 | 0 | } |
1550 | 0 | } |
1551 | 0 | g_string_append_printf(str, " extended_size: 0x%x\n", |
1552 | 0 | (guint) fu_struct_efi_section2_get_extended_size(st)); |
1553 | 0 | if (str->len > 0) |
1554 | 0 | g_string_set_size(str, str->len - 1); |
1555 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1556 | 0 | } |
1557 | | static gboolean |
1558 | | fu_struct_efi_section2_validate_internal(FuStructEfiSection2 *st, GError **error) |
1559 | 268 | { |
1560 | 268 | g_return_val_if_fail(st != NULL, FALSE); |
1561 | 268 | if (fu_struct_efi_section2_get_size(st) != 0xFFFFFF) { |
1562 | 0 | g_set_error(error, |
1563 | 0 | FWUPD_ERROR, |
1564 | 0 | FWUPD_ERROR_INVALID_DATA, |
1565 | 0 | "constant FuStructEfiSection2.size was not valid, " |
1566 | 0 | "expected 0x%x and got 0x%x", |
1567 | 0 | (guint) 0xFFFFFF, |
1568 | 0 | (guint) fu_struct_efi_section2_get_size(st)); |
1569 | 0 | return FALSE; |
1570 | 0 | } |
1571 | 268 | return TRUE; |
1572 | 268 | } |
1573 | | static gboolean |
1574 | | fu_struct_efi_section2_parse_internal(FuStructEfiSection2 *st, GError **error) |
1575 | 268 | { |
1576 | 268 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1577 | 0 | g_autofree gchar *str = fu_struct_efi_section2_to_string(st); |
1578 | 0 | g_debug("%s", str); |
1579 | 0 | } |
1580 | 268 | if (!fu_struct_efi_section2_validate_internal(st, error)) |
1581 | 0 | return FALSE; |
1582 | 268 | return TRUE; |
1583 | 268 | } |
1584 | | /** |
1585 | | * fu_struct_efi_section2_parse_stream: (skip): |
1586 | | **/ |
1587 | | FuStructEfiSection2 * |
1588 | | fu_struct_efi_section2_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1589 | 277 | { |
1590 | 277 | g_autoptr(FuStructEfiSection2) st = fu_struct_efi_section2_new_internal(); |
1591 | 277 | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1592 | 277 | if (st->buf == NULL) { |
1593 | 0 | g_prefix_error(error, "FuStructEfiSection2 failed read of 0x%x: ", (guint) 8); |
1594 | 0 | return NULL; |
1595 | 0 | } |
1596 | 277 | if (st->buf->len != 8) { |
1597 | 9 | g_set_error(error, |
1598 | 9 | FWUPD_ERROR, |
1599 | 9 | FWUPD_ERROR_INVALID_DATA, |
1600 | 9 | "FuStructEfiSection2 requested 0x%x and got 0x%x", |
1601 | 9 | (guint) 8, |
1602 | 9 | (guint) st->buf->len); |
1603 | 9 | return NULL; |
1604 | 9 | } |
1605 | 268 | if (!fu_struct_efi_section2_parse_internal(st, error)) |
1606 | 0 | return NULL; |
1607 | 268 | return g_steal_pointer(&st); |
1608 | 268 | } |
1609 | | /** |
1610 | | * fu_struct_efi_section_freeform_subtype_guid_ref: (skip): |
1611 | | **/ |
1612 | | FuStructEfiSectionFreeformSubtypeGuid * |
1613 | | fu_struct_efi_section_freeform_subtype_guid_ref(FuStructEfiSectionFreeformSubtypeGuid *st) |
1614 | 0 | { |
1615 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1616 | 0 | st->refcount++; |
1617 | 0 | return st; |
1618 | 0 | } |
1619 | | /** |
1620 | | * fu_struct_efi_section_freeform_subtype_guid_unref: (skip): |
1621 | | **/ |
1622 | | void |
1623 | | fu_struct_efi_section_freeform_subtype_guid_unref(FuStructEfiSectionFreeformSubtypeGuid *st) |
1624 | 268 | { |
1625 | 268 | g_return_if_fail(st != NULL); |
1626 | 268 | if (st->refcount == 0) { |
1627 | 0 | g_critical("FuStructEfiSectionFreeformSubtypeGuid refcount already zero"); |
1628 | 0 | return; |
1629 | 0 | } |
1630 | 268 | if (--st->refcount > 0) |
1631 | 0 | return; |
1632 | 268 | if (st->buf != NULL) |
1633 | 267 | g_byte_array_unref(st->buf); |
1634 | 268 | g_free(st); |
1635 | 268 | } |
1636 | | /** |
1637 | | * fu_struct_efi_section_freeform_subtype_guid_new_internal: (skip): |
1638 | | **/ |
1639 | | static FuStructEfiSectionFreeformSubtypeGuid * |
1640 | | fu_struct_efi_section_freeform_subtype_guid_new_internal(void) |
1641 | 268 | { |
1642 | 268 | FuStructEfiSectionFreeformSubtypeGuid *st = g_new0(FuStructEfiSectionFreeformSubtypeGuid, 1); |
1643 | 268 | st->refcount = 1; |
1644 | 268 | return st; |
1645 | 268 | } |
1646 | | |
1647 | | /* getters */ |
1648 | | /** |
1649 | | * fu_struct_efi_section_freeform_subtype_guid_get_guid: (skip): |
1650 | | **/ |
1651 | | const fwupd_guid_t * |
1652 | | fu_struct_efi_section_freeform_subtype_guid_get_guid(const FuStructEfiSectionFreeformSubtypeGuid *st) |
1653 | 262 | { |
1654 | 262 | g_return_val_if_fail(st != NULL, NULL); |
1655 | 262 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1656 | 262 | } |
1657 | | |
1658 | | /* setters */ |
1659 | | /** |
1660 | | * fu_struct_efi_section_freeform_subtype_guid_to_string: (skip): |
1661 | | **/ |
1662 | | static gchar * |
1663 | | fu_struct_efi_section_freeform_subtype_guid_to_string(const FuStructEfiSectionFreeformSubtypeGuid *st) |
1664 | 0 | { |
1665 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSectionFreeformSubtypeGuid:\n"); |
1666 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1667 | 0 | { |
1668 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_freeform_subtype_guid_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
1669 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
1670 | 0 | } |
1671 | 0 | if (str->len > 0) |
1672 | 0 | g_string_set_size(str, str->len - 1); |
1673 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1674 | 0 | } |
1675 | | static gboolean |
1676 | | fu_struct_efi_section_freeform_subtype_guid_validate_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error) |
1677 | 262 | { |
1678 | 262 | g_return_val_if_fail(st != NULL, FALSE); |
1679 | 262 | return TRUE; |
1680 | 262 | } |
1681 | | static gboolean |
1682 | | fu_struct_efi_section_freeform_subtype_guid_parse_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error) |
1683 | 262 | { |
1684 | 262 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1685 | 0 | g_autofree gchar *str = fu_struct_efi_section_freeform_subtype_guid_to_string(st); |
1686 | 0 | g_debug("%s", str); |
1687 | 0 | } |
1688 | 262 | if (!fu_struct_efi_section_freeform_subtype_guid_validate_internal(st, error)) |
1689 | 0 | return FALSE; |
1690 | 262 | return TRUE; |
1691 | 262 | } |
1692 | | /** |
1693 | | * fu_struct_efi_section_freeform_subtype_guid_parse_stream: (skip): |
1694 | | **/ |
1695 | | FuStructEfiSectionFreeformSubtypeGuid * |
1696 | | fu_struct_efi_section_freeform_subtype_guid_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1697 | 268 | { |
1698 | 268 | g_autoptr(FuStructEfiSectionFreeformSubtypeGuid) st = fu_struct_efi_section_freeform_subtype_guid_new_internal(); |
1699 | 268 | st->buf = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error); |
1700 | 268 | if (st->buf == NULL) { |
1701 | 1 | g_prefix_error(error, "FuStructEfiSectionFreeformSubtypeGuid failed read of 0x%x: ", (guint) 16); |
1702 | 1 | return NULL; |
1703 | 1 | } |
1704 | 267 | if (st->buf->len != 16) { |
1705 | 5 | g_set_error(error, |
1706 | 5 | FWUPD_ERROR, |
1707 | 5 | FWUPD_ERROR_INVALID_DATA, |
1708 | 5 | "FuStructEfiSectionFreeformSubtypeGuid requested 0x%x and got 0x%x", |
1709 | 5 | (guint) 16, |
1710 | 5 | (guint) st->buf->len); |
1711 | 5 | return NULL; |
1712 | 5 | } |
1713 | 262 | if (!fu_struct_efi_section_freeform_subtype_guid_parse_internal(st, error)) |
1714 | 0 | return NULL; |
1715 | 262 | return g_steal_pointer(&st); |
1716 | 262 | } |
1717 | | /** |
1718 | | * fu_struct_efi_section_guid_defined_ref: (skip): |
1719 | | **/ |
1720 | | FuStructEfiSectionGuidDefined * |
1721 | | fu_struct_efi_section_guid_defined_ref(FuStructEfiSectionGuidDefined *st) |
1722 | 0 | { |
1723 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1724 | 0 | st->refcount++; |
1725 | 0 | return st; |
1726 | 0 | } |
1727 | | /** |
1728 | | * fu_struct_efi_section_guid_defined_unref: (skip): |
1729 | | **/ |
1730 | | void |
1731 | | fu_struct_efi_section_guid_defined_unref(FuStructEfiSectionGuidDefined *st) |
1732 | 1.19k | { |
1733 | 1.19k | g_return_if_fail(st != NULL); |
1734 | 1.19k | if (st->refcount == 0) { |
1735 | 0 | g_critical("FuStructEfiSectionGuidDefined refcount already zero"); |
1736 | 0 | return; |
1737 | 0 | } |
1738 | 1.19k | if (--st->refcount > 0) |
1739 | 0 | return; |
1740 | 1.19k | if (st->buf != NULL) |
1741 | 1.18k | g_byte_array_unref(st->buf); |
1742 | 1.19k | g_free(st); |
1743 | 1.19k | } |
1744 | | /** |
1745 | | * fu_struct_efi_section_guid_defined_new_internal: (skip): |
1746 | | **/ |
1747 | | static FuStructEfiSectionGuidDefined * |
1748 | | fu_struct_efi_section_guid_defined_new_internal(void) |
1749 | 1.19k | { |
1750 | 1.19k | FuStructEfiSectionGuidDefined *st = g_new0(FuStructEfiSectionGuidDefined, 1); |
1751 | 1.19k | st->refcount = 1; |
1752 | 1.19k | return st; |
1753 | 1.19k | } |
1754 | | |
1755 | | /* getters */ |
1756 | | /** |
1757 | | * fu_struct_efi_section_guid_defined_get_name: (skip): |
1758 | | **/ |
1759 | | const fwupd_guid_t * |
1760 | | fu_struct_efi_section_guid_defined_get_name(const FuStructEfiSectionGuidDefined *st) |
1761 | 925 | { |
1762 | 925 | g_return_val_if_fail(st != NULL, NULL); |
1763 | 925 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1764 | 925 | } |
1765 | | /** |
1766 | | * fu_struct_efi_section_guid_defined_get_offset: (skip): |
1767 | | **/ |
1768 | | guint16 |
1769 | | fu_struct_efi_section_guid_defined_get_offset(const FuStructEfiSectionGuidDefined *st) |
1770 | 1.85k | { |
1771 | 1.85k | g_return_val_if_fail(st != NULL, 0x0); |
1772 | 1.85k | return fu_memread_uint16(st->buf->data + 16, G_LITTLE_ENDIAN); |
1773 | 1.85k | } |
1774 | | /** |
1775 | | * fu_struct_efi_section_guid_defined_get_attr: (skip): |
1776 | | **/ |
1777 | | guint16 |
1778 | | fu_struct_efi_section_guid_defined_get_attr(const FuStructEfiSectionGuidDefined *st) |
1779 | 0 | { |
1780 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
1781 | 0 | return fu_memread_uint16(st->buf->data + 18, G_LITTLE_ENDIAN); |
1782 | 0 | } |
1783 | | |
1784 | | /* setters */ |
1785 | | /** |
1786 | | * fu_struct_efi_section_guid_defined_set_name: (skip): |
1787 | | **/ |
1788 | | void |
1789 | | fu_struct_efi_section_guid_defined_set_name(FuStructEfiSectionGuidDefined *st, const fwupd_guid_t *value) |
1790 | 260 | { |
1791 | 260 | g_return_if_fail(st != NULL); |
1792 | 260 | g_return_if_fail(value != NULL); |
1793 | 260 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
1794 | 260 | } |
1795 | | /** |
1796 | | * fu_struct_efi_section_guid_defined_set_offset: (skip): |
1797 | | **/ |
1798 | | void |
1799 | | fu_struct_efi_section_guid_defined_set_offset(FuStructEfiSectionGuidDefined *st, guint16 value) |
1800 | 260 | { |
1801 | 260 | g_return_if_fail(st != NULL); |
1802 | 260 | fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
1803 | 260 | } |
1804 | | /** |
1805 | | * fu_struct_efi_section_guid_defined_set_attr: (skip): |
1806 | | **/ |
1807 | | void |
1808 | | fu_struct_efi_section_guid_defined_set_attr(FuStructEfiSectionGuidDefined *st, guint16 value) |
1809 | 0 | { |
1810 | 0 | g_return_if_fail(st != NULL); |
1811 | 0 | fu_memwrite_uint16(st->buf->data + 18, value, G_LITTLE_ENDIAN); |
1812 | 0 | } |
1813 | | /** |
1814 | | * fu_struct_efi_section_guid_defined_new: (skip): |
1815 | | **/ |
1816 | | FuStructEfiSectionGuidDefined * |
1817 | | fu_struct_efi_section_guid_defined_new(void) |
1818 | 260 | { |
1819 | 260 | FuStructEfiSectionGuidDefined *st = fu_struct_efi_section_guid_defined_new_internal(); |
1820 | 260 | st->buf = g_byte_array_sized_new(20); |
1821 | 260 | fu_byte_array_set_size(st->buf, 20, 0x0); |
1822 | 260 | return st; |
1823 | 260 | } |
1824 | | /** |
1825 | | * fu_struct_efi_section_guid_defined_to_string: (skip): |
1826 | | **/ |
1827 | | static gchar * |
1828 | | fu_struct_efi_section_guid_defined_to_string(const FuStructEfiSectionGuidDefined *st) |
1829 | 0 | { |
1830 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSectionGuidDefined:\n"); |
1831 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1832 | 0 | { |
1833 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_guid_defined_get_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
1834 | 0 | g_string_append_printf(str, " name: %s\n", tmp); |
1835 | 0 | } |
1836 | 0 | g_string_append_printf(str, " offset: 0x%x\n", |
1837 | 0 | (guint) fu_struct_efi_section_guid_defined_get_offset(st)); |
1838 | 0 | g_string_append_printf(str, " attr: 0x%x\n", |
1839 | 0 | (guint) fu_struct_efi_section_guid_defined_get_attr(st)); |
1840 | 0 | if (str->len > 0) |
1841 | 0 | g_string_set_size(str, str->len - 1); |
1842 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
1843 | 0 | } |
1844 | | static gboolean |
1845 | | fu_struct_efi_section_guid_defined_validate_internal(FuStructEfiSectionGuidDefined *st, GError **error) |
1846 | 925 | { |
1847 | 925 | g_return_val_if_fail(st != NULL, FALSE); |
1848 | 925 | return TRUE; |
1849 | 925 | } |
1850 | | static gboolean |
1851 | | fu_struct_efi_section_guid_defined_parse_internal(FuStructEfiSectionGuidDefined *st, GError **error) |
1852 | 925 | { |
1853 | 925 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
1854 | 0 | g_autofree gchar *str = fu_struct_efi_section_guid_defined_to_string(st); |
1855 | 0 | g_debug("%s", str); |
1856 | 0 | } |
1857 | 925 | if (!fu_struct_efi_section_guid_defined_validate_internal(st, error)) |
1858 | 0 | return FALSE; |
1859 | 925 | return TRUE; |
1860 | 925 | } |
1861 | | /** |
1862 | | * fu_struct_efi_section_guid_defined_parse_stream: (skip): |
1863 | | **/ |
1864 | | FuStructEfiSectionGuidDefined * |
1865 | | fu_struct_efi_section_guid_defined_parse_stream(GInputStream *stream, gsize offset, GError **error) |
1866 | 930 | { |
1867 | 930 | g_autoptr(FuStructEfiSectionGuidDefined) st = fu_struct_efi_section_guid_defined_new_internal(); |
1868 | 930 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
1869 | 930 | if (st->buf == NULL) { |
1870 | 1 | g_prefix_error(error, "FuStructEfiSectionGuidDefined failed read of 0x%x: ", (guint) 20); |
1871 | 1 | return NULL; |
1872 | 1 | } |
1873 | 929 | if (st->buf->len != 20) { |
1874 | 4 | g_set_error(error, |
1875 | 4 | FWUPD_ERROR, |
1876 | 4 | FWUPD_ERROR_INVALID_DATA, |
1877 | 4 | "FuStructEfiSectionGuidDefined requested 0x%x and got 0x%x", |
1878 | 4 | (guint) 20, |
1879 | 4 | (guint) st->buf->len); |
1880 | 4 | return NULL; |
1881 | 4 | } |
1882 | 925 | if (!fu_struct_efi_section_guid_defined_parse_internal(st, error)) |
1883 | 0 | return NULL; |
1884 | 925 | return g_steal_pointer(&st); |
1885 | 925 | } |
1886 | | /** |
1887 | | * fu_struct_efi_volume_ref: (skip): |
1888 | | **/ |
1889 | | FuStructEfiVolume * |
1890 | | fu_struct_efi_volume_ref(FuStructEfiVolume *st) |
1891 | 0 | { |
1892 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1893 | 0 | st->refcount++; |
1894 | 0 | return st; |
1895 | 0 | } |
1896 | | /** |
1897 | | * fu_struct_efi_volume_unref: (skip): |
1898 | | **/ |
1899 | | void |
1900 | | fu_struct_efi_volume_unref(FuStructEfiVolume *st) |
1901 | 106M | { |
1902 | 106M | g_return_if_fail(st != NULL); |
1903 | 106M | if (st->refcount == 0) { |
1904 | 0 | g_critical("FuStructEfiVolume refcount already zero"); |
1905 | 0 | return; |
1906 | 0 | } |
1907 | 106M | if (--st->refcount > 0) |
1908 | 0 | return; |
1909 | 106M | if (st->buf != NULL) |
1910 | 106M | g_byte_array_unref(st->buf); |
1911 | 106M | g_free(st); |
1912 | 106M | } |
1913 | | /** |
1914 | | * fu_struct_efi_volume_new_internal: (skip): |
1915 | | **/ |
1916 | | static FuStructEfiVolume * |
1917 | | fu_struct_efi_volume_new_internal(void) |
1918 | 106M | { |
1919 | 106M | FuStructEfiVolume *st = g_new0(FuStructEfiVolume, 1); |
1920 | 106M | st->refcount = 1; |
1921 | 106M | return st; |
1922 | 106M | } |
1923 | | |
1924 | | /* getters */ |
1925 | | /** |
1926 | | * fu_struct_efi_volume_get_zero_vector: (skip): |
1927 | | **/ |
1928 | | const fwupd_guid_t * |
1929 | | fu_struct_efi_volume_get_zero_vector(const FuStructEfiVolume *st) |
1930 | 0 | { |
1931 | 0 | g_return_val_if_fail(st != NULL, NULL); |
1932 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1933 | 0 | } |
1934 | | /** |
1935 | | * fu_struct_efi_volume_get_guid: (skip): |
1936 | | **/ |
1937 | | const fwupd_guid_t * |
1938 | | fu_struct_efi_volume_get_guid(const FuStructEfiVolume *st) |
1939 | 34.2k | { |
1940 | 34.2k | g_return_val_if_fail(st != NULL, NULL); |
1941 | 34.2k | return (const fwupd_guid_t *) (st->buf->data + 16); |
1942 | 34.2k | } |
1943 | | /** |
1944 | | * fu_struct_efi_volume_get_length: (skip): |
1945 | | **/ |
1946 | | guint64 |
1947 | | fu_struct_efi_volume_get_length(const FuStructEfiVolume *st) |
1948 | 34.2k | { |
1949 | 34.2k | g_return_val_if_fail(st != NULL, 0x0); |
1950 | 34.2k | return fu_memread_uint64(st->buf->data + 32, G_LITTLE_ENDIAN); |
1951 | 34.2k | } |
1952 | | /** |
1953 | | * fu_struct_efi_volume_get_signature: (skip): |
1954 | | **/ |
1955 | | static guint32 |
1956 | | fu_struct_efi_volume_get_signature(const FuStructEfiVolume *st) |
1957 | 213M | { |
1958 | 213M | g_return_val_if_fail(st != NULL, 0x0); |
1959 | 213M | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
1960 | 213M | } |
1961 | | /** |
1962 | | * fu_struct_efi_volume_get_attrs: (skip): |
1963 | | **/ |
1964 | | guint32 |
1965 | | fu_struct_efi_volume_get_attrs(const FuStructEfiVolume *st) |
1966 | 30.8k | { |
1967 | 30.8k | g_return_val_if_fail(st != NULL, 0x0); |
1968 | 30.8k | return fu_memread_uint32(st->buf->data + 44, G_LITTLE_ENDIAN); |
1969 | 30.8k | } |
1970 | | /** |
1971 | | * fu_struct_efi_volume_get_hdr_len: (skip): |
1972 | | **/ |
1973 | | guint16 |
1974 | | fu_struct_efi_volume_get_hdr_len(const FuStructEfiVolume *st) |
1975 | 30.7k | { |
1976 | 30.7k | g_return_val_if_fail(st != NULL, 0x0); |
1977 | 30.7k | return fu_memread_uint16(st->buf->data + 48, G_LITTLE_ENDIAN); |
1978 | 30.7k | } |
1979 | | /** |
1980 | | * fu_struct_efi_volume_get_checksum: (skip): |
1981 | | **/ |
1982 | | guint16 |
1983 | | fu_struct_efi_volume_get_checksum(const FuStructEfiVolume *st) |
1984 | 535 | { |
1985 | 535 | g_return_val_if_fail(st != NULL, 0x0); |
1986 | 535 | return fu_memread_uint16(st->buf->data + 50, G_LITTLE_ENDIAN); |
1987 | 535 | } |
1988 | | /** |
1989 | | * fu_struct_efi_volume_get_ext_hdr: (skip): |
1990 | | **/ |
1991 | | guint16 |
1992 | | fu_struct_efi_volume_get_ext_hdr(const FuStructEfiVolume *st) |
1993 | 43.1k | { |
1994 | 43.1k | g_return_val_if_fail(st != NULL, 0x0); |
1995 | 43.1k | return fu_memread_uint16(st->buf->data + 52, G_LITTLE_ENDIAN); |
1996 | 43.1k | } |
1997 | | /** |
1998 | | * fu_struct_efi_volume_get_revision: (skip): |
1999 | | **/ |
2000 | | static guint8 |
2001 | | fu_struct_efi_volume_get_revision(const FuStructEfiVolume *st) |
2002 | 122k | { |
2003 | 122k | g_return_val_if_fail(st != NULL, 0x0); |
2004 | 122k | return st->buf->data[55]; |
2005 | 122k | } |
2006 | | |
2007 | | /* setters */ |
2008 | | /** |
2009 | | * fu_struct_efi_volume_set_zero_vector: (skip): |
2010 | | **/ |
2011 | | void |
2012 | | fu_struct_efi_volume_set_zero_vector(FuStructEfiVolume *st, const fwupd_guid_t *value) |
2013 | 0 | { |
2014 | 0 | g_return_if_fail(st != NULL); |
2015 | 0 | g_return_if_fail(value != NULL); |
2016 | 0 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
2017 | 0 | } |
2018 | | /** |
2019 | | * fu_struct_efi_volume_set_guid: (skip): |
2020 | | **/ |
2021 | | void |
2022 | | fu_struct_efi_volume_set_guid(FuStructEfiVolume *st, const fwupd_guid_t *value) |
2023 | 27.7k | { |
2024 | 27.7k | g_return_if_fail(st != NULL); |
2025 | 27.7k | g_return_if_fail(value != NULL); |
2026 | 27.7k | memcpy(st->buf->data + 16, value, sizeof(*value)); /* nocheck:blocked */ |
2027 | 27.7k | } |
2028 | | /** |
2029 | | * fu_struct_efi_volume_set_length: (skip): |
2030 | | **/ |
2031 | | void |
2032 | | fu_struct_efi_volume_set_length(FuStructEfiVolume *st, guint64 value) |
2033 | 27.7k | { |
2034 | 27.7k | g_return_if_fail(st != NULL); |
2035 | 27.7k | fu_memwrite_uint64(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
2036 | 27.7k | } |
2037 | | /** |
2038 | | * fu_struct_efi_volume_set_signature: (skip): |
2039 | | **/ |
2040 | | static void |
2041 | | fu_struct_efi_volume_set_signature(FuStructEfiVolume *st, guint32 value) |
2042 | 27.8k | { |
2043 | 27.8k | g_return_if_fail(st != NULL); |
2044 | 27.8k | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
2045 | 27.8k | } |
2046 | | /** |
2047 | | * fu_struct_efi_volume_set_attrs: (skip): |
2048 | | **/ |
2049 | | void |
2050 | | fu_struct_efi_volume_set_attrs(FuStructEfiVolume *st, guint32 value) |
2051 | 27.7k | { |
2052 | 27.7k | g_return_if_fail(st != NULL); |
2053 | 27.7k | fu_memwrite_uint32(st->buf->data + 44, value, G_LITTLE_ENDIAN); |
2054 | 27.7k | } |
2055 | | /** |
2056 | | * fu_struct_efi_volume_set_hdr_len: (skip): |
2057 | | **/ |
2058 | | void |
2059 | | fu_struct_efi_volume_set_hdr_len(FuStructEfiVolume *st, guint16 value) |
2060 | 27.7k | { |
2061 | 27.7k | g_return_if_fail(st != NULL); |
2062 | 27.7k | fu_memwrite_uint16(st->buf->data + 48, value, G_LITTLE_ENDIAN); |
2063 | 27.7k | } |
2064 | | /** |
2065 | | * fu_struct_efi_volume_set_checksum: (skip): |
2066 | | **/ |
2067 | | void |
2068 | | fu_struct_efi_volume_set_checksum(FuStructEfiVolume *st, guint16 value) |
2069 | 27.7k | { |
2070 | 27.7k | g_return_if_fail(st != NULL); |
2071 | 27.7k | fu_memwrite_uint16(st->buf->data + 50, value, G_LITTLE_ENDIAN); |
2072 | 27.7k | } |
2073 | | /** |
2074 | | * fu_struct_efi_volume_set_ext_hdr: (skip): |
2075 | | **/ |
2076 | | void |
2077 | | fu_struct_efi_volume_set_ext_hdr(FuStructEfiVolume *st, guint16 value) |
2078 | 0 | { |
2079 | 0 | g_return_if_fail(st != NULL); |
2080 | 0 | fu_memwrite_uint16(st->buf->data + 52, value, G_LITTLE_ENDIAN); |
2081 | 0 | } |
2082 | | /** |
2083 | | * fu_struct_efi_volume_set_revision: (skip): |
2084 | | **/ |
2085 | | static void |
2086 | | fu_struct_efi_volume_set_revision(FuStructEfiVolume *st, guint8 value) |
2087 | 27.8k | { |
2088 | 27.8k | g_return_if_fail(st != NULL); |
2089 | 27.8k | st->buf->data[55] = value; |
2090 | 27.8k | } |
2091 | | /** |
2092 | | * fu_struct_efi_volume_new: (skip): |
2093 | | **/ |
2094 | | FuStructEfiVolume * |
2095 | | fu_struct_efi_volume_new(void) |
2096 | 27.8k | { |
2097 | 27.8k | FuStructEfiVolume *st = fu_struct_efi_volume_new_internal(); |
2098 | 27.8k | st->buf = g_byte_array_sized_new(56); |
2099 | 27.8k | fu_byte_array_set_size(st->buf, 56, 0x0); |
2100 | 27.8k | fu_struct_efi_volume_set_signature(st, 0x4856465F); |
2101 | 27.8k | fu_struct_efi_volume_set_revision(st, 0x02); |
2102 | 27.8k | return st; |
2103 | 27.8k | } |
2104 | | /** |
2105 | | * fu_struct_efi_volume_to_string: (skip): |
2106 | | **/ |
2107 | | static gchar * |
2108 | | fu_struct_efi_volume_to_string(const FuStructEfiVolume *st) |
2109 | 0 | { |
2110 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolume:\n"); |
2111 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2112 | 0 | { |
2113 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_zero_vector(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2114 | 0 | g_string_append_printf(str, " zero_vector: %s\n", tmp); |
2115 | 0 | } |
2116 | 0 | { |
2117 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2118 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
2119 | 0 | } |
2120 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2121 | 0 | (guint) fu_struct_efi_volume_get_length(st)); |
2122 | 0 | g_string_append_printf(str, " signature: 0x%x\n", |
2123 | 0 | (guint) fu_struct_efi_volume_get_signature(st)); |
2124 | 0 | g_string_append_printf(str, " attrs: 0x%x\n", |
2125 | 0 | (guint) fu_struct_efi_volume_get_attrs(st)); |
2126 | 0 | g_string_append_printf(str, " hdr_len: 0x%x\n", |
2127 | 0 | (guint) fu_struct_efi_volume_get_hdr_len(st)); |
2128 | 0 | g_string_append_printf(str, " checksum: 0x%x\n", |
2129 | 0 | (guint) fu_struct_efi_volume_get_checksum(st)); |
2130 | 0 | g_string_append_printf(str, " ext_hdr: 0x%x\n", |
2131 | 0 | (guint) fu_struct_efi_volume_get_ext_hdr(st)); |
2132 | 0 | g_string_append_printf(str, " revision: 0x%x\n", |
2133 | 0 | (guint) fu_struct_efi_volume_get_revision(st)); |
2134 | 0 | if (str->len > 0) |
2135 | 0 | g_string_set_size(str, str->len - 1); |
2136 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2137 | 0 | } |
2138 | | static gboolean |
2139 | | fu_struct_efi_volume_validate_internal(FuStructEfiVolume *st, GError **error) |
2140 | 106M | { |
2141 | 106M | g_return_val_if_fail(st != NULL, FALSE); |
2142 | 106M | if (fu_struct_efi_volume_get_signature(st) != 0x4856465F) { |
2143 | 106M | g_set_error(error, |
2144 | 106M | FWUPD_ERROR, |
2145 | 106M | FWUPD_ERROR_INVALID_DATA, |
2146 | 106M | "constant FuStructEfiVolume.signature was not valid, " |
2147 | 106M | "expected 0x%x and got 0x%x", |
2148 | 106M | (guint) 0x4856465F, |
2149 | 106M | (guint) fu_struct_efi_volume_get_signature(st)); |
2150 | 106M | return FALSE; |
2151 | 106M | } |
2152 | 122k | if (fu_struct_efi_volume_get_revision(st) != 0x02) { |
2153 | 53.5k | g_set_error_literal(error, |
2154 | 53.5k | FWUPD_ERROR, |
2155 | 53.5k | FWUPD_ERROR_INVALID_DATA, |
2156 | 53.5k | "constant FuStructEfiVolume.revision was not valid"); |
2157 | 53.5k | return FALSE; |
2158 | 53.5k | } |
2159 | 68.5k | return TRUE; |
2160 | 122k | } |
2161 | | /** |
2162 | | * fu_struct_efi_volume_validate_stream: (skip): |
2163 | | **/ |
2164 | | gboolean |
2165 | | fu_struct_efi_volume_validate_stream(GInputStream *stream, gsize offset, GError **error) |
2166 | 106M | { |
2167 | 106M | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
2168 | 106M | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
2169 | 106M | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
2170 | 106M | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
2171 | 106M | if (st->buf == NULL) { |
2172 | 0 | g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56); |
2173 | 0 | return FALSE; |
2174 | 0 | } |
2175 | 106M | if (st->buf->len != 56) { |
2176 | 52.0k | g_set_error(error, |
2177 | 52.0k | FWUPD_ERROR, |
2178 | 52.0k | FWUPD_ERROR_INVALID_DATA, |
2179 | 52.0k | "FuStructEfiVolume requested 0x%x and got 0x%x", |
2180 | 52.0k | (guint) 56, |
2181 | 52.0k | (guint) st->buf->len); |
2182 | 52.0k | return FALSE; |
2183 | 52.0k | } |
2184 | 106M | return fu_struct_efi_volume_validate_internal(st, error); |
2185 | 106M | } |
2186 | | static gboolean |
2187 | | fu_struct_efi_volume_parse_internal(FuStructEfiVolume *st, GError **error) |
2188 | 34.2k | { |
2189 | 34.2k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2190 | 0 | g_autofree gchar *str = fu_struct_efi_volume_to_string(st); |
2191 | 0 | g_debug("%s", str); |
2192 | 0 | } |
2193 | 34.2k | if (!fu_struct_efi_volume_validate_internal(st, error)) |
2194 | 0 | return FALSE; |
2195 | 34.2k | return TRUE; |
2196 | 34.2k | } |
2197 | | /** |
2198 | | * fu_struct_efi_volume_parse_stream: (skip): |
2199 | | **/ |
2200 | | FuStructEfiVolume * |
2201 | | fu_struct_efi_volume_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2202 | 34.2k | { |
2203 | 34.2k | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
2204 | 34.2k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
2205 | 34.2k | if (st->buf == NULL) { |
2206 | 0 | g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56); |
2207 | 0 | return NULL; |
2208 | 0 | } |
2209 | 34.2k | if (st->buf->len != 56) { |
2210 | 0 | g_set_error(error, |
2211 | 0 | FWUPD_ERROR, |
2212 | 0 | FWUPD_ERROR_INVALID_DATA, |
2213 | 0 | "FuStructEfiVolume requested 0x%x and got 0x%x", |
2214 | 0 | (guint) 56, |
2215 | 0 | (guint) st->buf->len); |
2216 | 0 | return NULL; |
2217 | 0 | } |
2218 | 34.2k | if (!fu_struct_efi_volume_parse_internal(st, error)) |
2219 | 0 | return NULL; |
2220 | 34.2k | return g_steal_pointer(&st); |
2221 | 34.2k | } |
2222 | | /** |
2223 | | * fu_struct_efi_volume_ext_header_ref: (skip): |
2224 | | **/ |
2225 | | FuStructEfiVolumeExtHeader * |
2226 | | fu_struct_efi_volume_ext_header_ref(FuStructEfiVolumeExtHeader *st) |
2227 | 0 | { |
2228 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2229 | 0 | st->refcount++; |
2230 | 0 | return st; |
2231 | 0 | } |
2232 | | /** |
2233 | | * fu_struct_efi_volume_ext_header_unref: (skip): |
2234 | | **/ |
2235 | | void |
2236 | | fu_struct_efi_volume_ext_header_unref(FuStructEfiVolumeExtHeader *st) |
2237 | 13.3k | { |
2238 | 13.3k | g_return_if_fail(st != NULL); |
2239 | 13.3k | if (st->refcount == 0) { |
2240 | 0 | g_critical("FuStructEfiVolumeExtHeader refcount already zero"); |
2241 | 0 | return; |
2242 | 0 | } |
2243 | 13.3k | if (--st->refcount > 0) |
2244 | 0 | return; |
2245 | 13.3k | if (st->buf != NULL) |
2246 | 13.2k | g_byte_array_unref(st->buf); |
2247 | 13.3k | g_free(st); |
2248 | 13.3k | } |
2249 | | /** |
2250 | | * fu_struct_efi_volume_ext_header_new_internal: (skip): |
2251 | | **/ |
2252 | | static FuStructEfiVolumeExtHeader * |
2253 | | fu_struct_efi_volume_ext_header_new_internal(void) |
2254 | 13.3k | { |
2255 | 13.3k | FuStructEfiVolumeExtHeader *st = g_new0(FuStructEfiVolumeExtHeader, 1); |
2256 | 13.3k | st->refcount = 1; |
2257 | 13.3k | return st; |
2258 | 13.3k | } |
2259 | | |
2260 | | /* getters */ |
2261 | | /** |
2262 | | * fu_struct_efi_volume_ext_header_get_fv_name: (skip): |
2263 | | **/ |
2264 | | const fwupd_guid_t * |
2265 | | fu_struct_efi_volume_ext_header_get_fv_name(const FuStructEfiVolumeExtHeader *st) |
2266 | 0 | { |
2267 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2268 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
2269 | 0 | } |
2270 | | /** |
2271 | | * fu_struct_efi_volume_ext_header_get_size: (skip): |
2272 | | **/ |
2273 | | guint32 |
2274 | | fu_struct_efi_volume_ext_header_get_size(const FuStructEfiVolumeExtHeader *st) |
2275 | 13.1k | { |
2276 | 13.1k | g_return_val_if_fail(st != NULL, 0x0); |
2277 | 13.1k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
2278 | 13.1k | } |
2279 | | |
2280 | | /* setters */ |
2281 | | /** |
2282 | | * fu_struct_efi_volume_ext_header_to_string: (skip): |
2283 | | **/ |
2284 | | static gchar * |
2285 | | fu_struct_efi_volume_ext_header_to_string(const FuStructEfiVolumeExtHeader *st) |
2286 | 0 | { |
2287 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtHeader:\n"); |
2288 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2289 | 0 | { |
2290 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_ext_header_get_fv_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
2291 | 0 | g_string_append_printf(str, " fv_name: %s\n", tmp); |
2292 | 0 | } |
2293 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
2294 | 0 | (guint) fu_struct_efi_volume_ext_header_get_size(st)); |
2295 | 0 | if (str->len > 0) |
2296 | 0 | g_string_set_size(str, str->len - 1); |
2297 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2298 | 0 | } |
2299 | | static gboolean |
2300 | | fu_struct_efi_volume_ext_header_validate_internal(FuStructEfiVolumeExtHeader *st, GError **error) |
2301 | 13.1k | { |
2302 | 13.1k | g_return_val_if_fail(st != NULL, FALSE); |
2303 | 13.1k | return TRUE; |
2304 | 13.1k | } |
2305 | | static gboolean |
2306 | | fu_struct_efi_volume_ext_header_parse_internal(FuStructEfiVolumeExtHeader *st, GError **error) |
2307 | 13.1k | { |
2308 | 13.1k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2309 | 0 | g_autofree gchar *str = fu_struct_efi_volume_ext_header_to_string(st); |
2310 | 0 | g_debug("%s", str); |
2311 | 0 | } |
2312 | 13.1k | if (!fu_struct_efi_volume_ext_header_validate_internal(st, error)) |
2313 | 0 | return FALSE; |
2314 | 13.1k | return TRUE; |
2315 | 13.1k | } |
2316 | | /** |
2317 | | * fu_struct_efi_volume_ext_header_parse_stream: (skip): |
2318 | | **/ |
2319 | | FuStructEfiVolumeExtHeader * |
2320 | | fu_struct_efi_volume_ext_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2321 | 13.3k | { |
2322 | 13.3k | g_autoptr(FuStructEfiVolumeExtHeader) st = fu_struct_efi_volume_ext_header_new_internal(); |
2323 | 13.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
2324 | 13.3k | if (st->buf == NULL) { |
2325 | 102 | g_prefix_error(error, "FuStructEfiVolumeExtHeader failed read of 0x%x: ", (guint) 20); |
2326 | 102 | return NULL; |
2327 | 102 | } |
2328 | 13.2k | if (st->buf->len != 20) { |
2329 | 50 | g_set_error(error, |
2330 | 50 | FWUPD_ERROR, |
2331 | 50 | FWUPD_ERROR_INVALID_DATA, |
2332 | 50 | "FuStructEfiVolumeExtHeader requested 0x%x and got 0x%x", |
2333 | 50 | (guint) 20, |
2334 | 50 | (guint) st->buf->len); |
2335 | 50 | return NULL; |
2336 | 50 | } |
2337 | 13.1k | if (!fu_struct_efi_volume_ext_header_parse_internal(st, error)) |
2338 | 0 | return NULL; |
2339 | 13.1k | return g_steal_pointer(&st); |
2340 | 13.1k | } |
2341 | | /** |
2342 | | * fu_struct_efi_volume_ext_entry_ref: (skip): |
2343 | | **/ |
2344 | | FuStructEfiVolumeExtEntry * |
2345 | | fu_struct_efi_volume_ext_entry_ref(FuStructEfiVolumeExtEntry *st) |
2346 | 0 | { |
2347 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2348 | 0 | st->refcount++; |
2349 | 0 | return st; |
2350 | 0 | } |
2351 | | /** |
2352 | | * fu_struct_efi_volume_ext_entry_unref: (skip): |
2353 | | **/ |
2354 | | void |
2355 | | fu_struct_efi_volume_ext_entry_unref(FuStructEfiVolumeExtEntry *st) |
2356 | 20.4k | { |
2357 | 20.4k | g_return_if_fail(st != NULL); |
2358 | 20.4k | if (st->refcount == 0) { |
2359 | 0 | g_critical("FuStructEfiVolumeExtEntry refcount already zero"); |
2360 | 0 | return; |
2361 | 0 | } |
2362 | 20.4k | if (--st->refcount > 0) |
2363 | 0 | return; |
2364 | 20.4k | if (st->buf != NULL) |
2365 | 20.2k | g_byte_array_unref(st->buf); |
2366 | 20.4k | g_free(st); |
2367 | 20.4k | } |
2368 | | /** |
2369 | | * fu_struct_efi_volume_ext_entry_new_internal: (skip): |
2370 | | **/ |
2371 | | static FuStructEfiVolumeExtEntry * |
2372 | | fu_struct_efi_volume_ext_entry_new_internal(void) |
2373 | 20.4k | { |
2374 | 20.4k | FuStructEfiVolumeExtEntry *st = g_new0(FuStructEfiVolumeExtEntry, 1); |
2375 | 20.4k | st->refcount = 1; |
2376 | 20.4k | return st; |
2377 | 20.4k | } |
2378 | | |
2379 | | /* getters */ |
2380 | | /** |
2381 | | * fu_struct_efi_volume_ext_entry_get_size: (skip): |
2382 | | **/ |
2383 | | guint16 |
2384 | | fu_struct_efi_volume_ext_entry_get_size(const FuStructEfiVolumeExtEntry *st) |
2385 | 59.1k | { |
2386 | 59.1k | g_return_val_if_fail(st != NULL, 0x0); |
2387 | 59.1k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
2388 | 59.1k | } |
2389 | | /** |
2390 | | * fu_struct_efi_volume_ext_entry_get_type: (skip): |
2391 | | **/ |
2392 | | FuEfiVolumeExtEntryType |
2393 | | fu_struct_efi_volume_ext_entry_get_type(const FuStructEfiVolumeExtEntry *st) |
2394 | 0 | { |
2395 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2396 | 0 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
2397 | 0 | } |
2398 | | |
2399 | | /* setters */ |
2400 | | /** |
2401 | | * fu_struct_efi_volume_ext_entry_to_string: (skip): |
2402 | | **/ |
2403 | | static gchar * |
2404 | | fu_struct_efi_volume_ext_entry_to_string(const FuStructEfiVolumeExtEntry *st) |
2405 | 0 | { |
2406 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtEntry:\n"); |
2407 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2408 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
2409 | 0 | (guint) fu_struct_efi_volume_ext_entry_get_size(st)); |
2410 | 0 | { |
2411 | 0 | const gchar *tmp = fu_efi_volume_ext_entry_type_to_string(fu_struct_efi_volume_ext_entry_get_type(st)); |
2412 | 0 | if (tmp != NULL) { |
2413 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st), tmp); |
2414 | 0 | } else { |
2415 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st)); |
2416 | 0 | } |
2417 | 0 | } |
2418 | 0 | if (str->len > 0) |
2419 | 0 | g_string_set_size(str, str->len - 1); |
2420 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2421 | 0 | } |
2422 | | static gboolean |
2423 | | fu_struct_efi_volume_ext_entry_validate_internal(FuStructEfiVolumeExtEntry *st, GError **error) |
2424 | 20.1k | { |
2425 | 20.1k | g_return_val_if_fail(st != NULL, FALSE); |
2426 | 20.1k | return TRUE; |
2427 | 20.1k | } |
2428 | | static gboolean |
2429 | | fu_struct_efi_volume_ext_entry_parse_internal(FuStructEfiVolumeExtEntry *st, GError **error) |
2430 | 20.1k | { |
2431 | 20.1k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2432 | 0 | g_autofree gchar *str = fu_struct_efi_volume_ext_entry_to_string(st); |
2433 | 0 | g_debug("%s", str); |
2434 | 0 | } |
2435 | 20.1k | if (!fu_struct_efi_volume_ext_entry_validate_internal(st, error)) |
2436 | 0 | return FALSE; |
2437 | 20.1k | return TRUE; |
2438 | 20.1k | } |
2439 | | /** |
2440 | | * fu_struct_efi_volume_ext_entry_parse_stream: (skip): |
2441 | | **/ |
2442 | | FuStructEfiVolumeExtEntry * |
2443 | | fu_struct_efi_volume_ext_entry_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2444 | 20.4k | { |
2445 | 20.4k | g_autoptr(FuStructEfiVolumeExtEntry) st = fu_struct_efi_volume_ext_entry_new_internal(); |
2446 | 20.4k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
2447 | 20.4k | if (st->buf == NULL) { |
2448 | 208 | g_prefix_error(error, "FuStructEfiVolumeExtEntry failed read of 0x%x: ", (guint) 4); |
2449 | 208 | return NULL; |
2450 | 208 | } |
2451 | 20.2k | if (st->buf->len != 4) { |
2452 | 73 | g_set_error(error, |
2453 | 73 | FWUPD_ERROR, |
2454 | 73 | FWUPD_ERROR_INVALID_DATA, |
2455 | 73 | "FuStructEfiVolumeExtEntry requested 0x%x and got 0x%x", |
2456 | 73 | (guint) 4, |
2457 | 73 | (guint) st->buf->len); |
2458 | 73 | return NULL; |
2459 | 73 | } |
2460 | 20.1k | if (!fu_struct_efi_volume_ext_entry_parse_internal(st, error)) |
2461 | 0 | return NULL; |
2462 | 20.1k | return g_steal_pointer(&st); |
2463 | 20.1k | } |
2464 | | /** |
2465 | | * fu_struct_efi_volume_block_map_ref: (skip): |
2466 | | **/ |
2467 | | FuStructEfiVolumeBlockMap * |
2468 | | fu_struct_efi_volume_block_map_ref(FuStructEfiVolumeBlockMap *st) |
2469 | 0 | { |
2470 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2471 | 0 | st->refcount++; |
2472 | 0 | return st; |
2473 | 0 | } |
2474 | | /** |
2475 | | * fu_struct_efi_volume_block_map_unref: (skip): |
2476 | | **/ |
2477 | | void |
2478 | | fu_struct_efi_volume_block_map_unref(FuStructEfiVolumeBlockMap *st) |
2479 | 1.43M | { |
2480 | 1.43M | g_return_if_fail(st != NULL); |
2481 | 1.43M | if (st->refcount == 0) { |
2482 | 0 | g_critical("FuStructEfiVolumeBlockMap refcount already zero"); |
2483 | 0 | return; |
2484 | 0 | } |
2485 | 1.43M | if (--st->refcount > 0) |
2486 | 0 | return; |
2487 | 1.43M | if (st->buf != NULL) |
2488 | 1.43M | g_byte_array_unref(st->buf); |
2489 | 1.43M | g_free(st); |
2490 | 1.43M | } |
2491 | | /** |
2492 | | * fu_struct_efi_volume_block_map_new_internal: (skip): |
2493 | | **/ |
2494 | | static FuStructEfiVolumeBlockMap * |
2495 | | fu_struct_efi_volume_block_map_new_internal(void) |
2496 | 1.43M | { |
2497 | 1.43M | FuStructEfiVolumeBlockMap *st = g_new0(FuStructEfiVolumeBlockMap, 1); |
2498 | 1.43M | st->refcount = 1; |
2499 | 1.43M | return st; |
2500 | 1.43M | } |
2501 | | |
2502 | | /* getters */ |
2503 | | /** |
2504 | | * fu_struct_efi_volume_block_map_get_num_blocks: (skip): |
2505 | | **/ |
2506 | | guint32 |
2507 | | fu_struct_efi_volume_block_map_get_num_blocks(const FuStructEfiVolumeBlockMap *st) |
2508 | 1.40M | { |
2509 | 1.40M | g_return_val_if_fail(st != NULL, 0x0); |
2510 | 1.40M | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
2511 | 1.40M | } |
2512 | | /** |
2513 | | * fu_struct_efi_volume_block_map_get_length: (skip): |
2514 | | **/ |
2515 | | guint32 |
2516 | | fu_struct_efi_volume_block_map_get_length(const FuStructEfiVolumeBlockMap *st) |
2517 | 1.40M | { |
2518 | 1.40M | g_return_val_if_fail(st != NULL, 0x0); |
2519 | 1.40M | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
2520 | 1.40M | } |
2521 | | |
2522 | | /* setters */ |
2523 | | /** |
2524 | | * fu_struct_efi_volume_block_map_set_num_blocks: (skip): |
2525 | | **/ |
2526 | | void |
2527 | | fu_struct_efi_volume_block_map_set_num_blocks(FuStructEfiVolumeBlockMap *st, guint32 value) |
2528 | 55.5k | { |
2529 | 55.5k | g_return_if_fail(st != NULL); |
2530 | 55.5k | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2531 | 55.5k | } |
2532 | | /** |
2533 | | * fu_struct_efi_volume_block_map_set_length: (skip): |
2534 | | **/ |
2535 | | void |
2536 | | fu_struct_efi_volume_block_map_set_length(FuStructEfiVolumeBlockMap *st, guint32 value) |
2537 | 55.5k | { |
2538 | 55.5k | g_return_if_fail(st != NULL); |
2539 | 55.5k | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
2540 | 55.5k | } |
2541 | | /** |
2542 | | * fu_struct_efi_volume_block_map_new: (skip): |
2543 | | **/ |
2544 | | FuStructEfiVolumeBlockMap * |
2545 | | fu_struct_efi_volume_block_map_new(void) |
2546 | 27.8k | { |
2547 | 27.8k | FuStructEfiVolumeBlockMap *st = fu_struct_efi_volume_block_map_new_internal(); |
2548 | 27.8k | st->buf = g_byte_array_sized_new(8); |
2549 | 27.8k | fu_byte_array_set_size(st->buf, 8, 0x0); |
2550 | 27.8k | return st; |
2551 | 27.8k | } |
2552 | | /** |
2553 | | * fu_struct_efi_volume_block_map_to_string: (skip): |
2554 | | **/ |
2555 | | static gchar * |
2556 | | fu_struct_efi_volume_block_map_to_string(const FuStructEfiVolumeBlockMap *st) |
2557 | 0 | { |
2558 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVolumeBlockMap:\n"); |
2559 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2560 | 0 | g_string_append_printf(str, " num_blocks: 0x%x\n", |
2561 | 0 | (guint) fu_struct_efi_volume_block_map_get_num_blocks(st)); |
2562 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2563 | 0 | (guint) fu_struct_efi_volume_block_map_get_length(st)); |
2564 | 0 | if (str->len > 0) |
2565 | 0 | g_string_set_size(str, str->len - 1); |
2566 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2567 | 0 | } |
2568 | | static gboolean |
2569 | | fu_struct_efi_volume_block_map_validate_internal(FuStructEfiVolumeBlockMap *st, GError **error) |
2570 | 1.40M | { |
2571 | 1.40M | g_return_val_if_fail(st != NULL, FALSE); |
2572 | 1.40M | return TRUE; |
2573 | 1.40M | } |
2574 | | static gboolean |
2575 | | fu_struct_efi_volume_block_map_parse_internal(FuStructEfiVolumeBlockMap *st, GError **error) |
2576 | 1.40M | { |
2577 | 1.40M | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
2578 | 0 | g_autofree gchar *str = fu_struct_efi_volume_block_map_to_string(st); |
2579 | 0 | g_debug("%s", str); |
2580 | 0 | } |
2581 | 1.40M | if (!fu_struct_efi_volume_block_map_validate_internal(st, error)) |
2582 | 0 | return FALSE; |
2583 | 1.40M | return TRUE; |
2584 | 1.40M | } |
2585 | | /** |
2586 | | * fu_struct_efi_volume_block_map_parse_stream: (skip): |
2587 | | **/ |
2588 | | FuStructEfiVolumeBlockMap * |
2589 | | fu_struct_efi_volume_block_map_parse_stream(GInputStream *stream, gsize offset, GError **error) |
2590 | 1.40M | { |
2591 | 1.40M | g_autoptr(FuStructEfiVolumeBlockMap) st = fu_struct_efi_volume_block_map_new_internal(); |
2592 | 1.40M | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
2593 | 1.40M | if (st->buf == NULL) { |
2594 | 0 | g_prefix_error(error, "FuStructEfiVolumeBlockMap failed read of 0x%x: ", (guint) 8); |
2595 | 0 | return NULL; |
2596 | 0 | } |
2597 | 1.40M | if (st->buf->len != 8) { |
2598 | 883 | g_set_error(error, |
2599 | 883 | FWUPD_ERROR, |
2600 | 883 | FWUPD_ERROR_INVALID_DATA, |
2601 | 883 | "FuStructEfiVolumeBlockMap requested 0x%x and got 0x%x", |
2602 | 883 | (guint) 8, |
2603 | 883 | (guint) st->buf->len); |
2604 | 883 | return NULL; |
2605 | 883 | } |
2606 | 1.40M | if (!fu_struct_efi_volume_block_map_parse_internal(st, error)) |
2607 | 0 | return NULL; |
2608 | 1.40M | return g_steal_pointer(&st); |
2609 | 1.40M | } |
2610 | | /** |
2611 | | * fu_struct_efi_time_ref: (skip): |
2612 | | **/ |
2613 | | FuStructEfiTime * |
2614 | | fu_struct_efi_time_ref(FuStructEfiTime *st) |
2615 | 0 | { |
2616 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2617 | 0 | st->refcount++; |
2618 | 0 | return st; |
2619 | 0 | } |
2620 | | /** |
2621 | | * fu_struct_efi_time_unref: (skip): |
2622 | | **/ |
2623 | | void |
2624 | | fu_struct_efi_time_unref(FuStructEfiTime *st) |
2625 | 5.56k | { |
2626 | 5.56k | g_return_if_fail(st != NULL); |
2627 | 5.56k | if (st->refcount == 0) { |
2628 | 0 | g_critical("FuStructEfiTime refcount already zero"); |
2629 | 0 | return; |
2630 | 0 | } |
2631 | 5.56k | if (--st->refcount > 0) |
2632 | 0 | return; |
2633 | 5.56k | if (st->buf != NULL) |
2634 | 5.56k | g_byte_array_unref(st->buf); |
2635 | 5.56k | g_free(st); |
2636 | 5.56k | } |
2637 | | /** |
2638 | | * fu_struct_efi_time_new_internal: (skip): |
2639 | | **/ |
2640 | | FuStructEfiTime * |
2641 | | fu_struct_efi_time_new_internal(void) |
2642 | 5.56k | { |
2643 | 5.56k | FuStructEfiTime *st = g_new0(FuStructEfiTime, 1); |
2644 | 5.56k | st->refcount = 1; |
2645 | 5.56k | return st; |
2646 | 5.56k | } |
2647 | | |
2648 | | /* getters */ |
2649 | | /** |
2650 | | * fu_struct_efi_time_get_year: (skip): |
2651 | | **/ |
2652 | | guint16 |
2653 | | fu_struct_efi_time_get_year(const FuStructEfiTime *st) |
2654 | 0 | { |
2655 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2656 | 0 | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
2657 | 0 | } |
2658 | | /** |
2659 | | * fu_struct_efi_time_get_month: (skip): |
2660 | | **/ |
2661 | | guint8 |
2662 | | fu_struct_efi_time_get_month(const FuStructEfiTime *st) |
2663 | 0 | { |
2664 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2665 | 0 | return st->buf->data[2]; |
2666 | 0 | } |
2667 | | /** |
2668 | | * fu_struct_efi_time_get_day: (skip): |
2669 | | **/ |
2670 | | guint8 |
2671 | | fu_struct_efi_time_get_day(const FuStructEfiTime *st) |
2672 | 0 | { |
2673 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2674 | 0 | return st->buf->data[3]; |
2675 | 0 | } |
2676 | | /** |
2677 | | * fu_struct_efi_time_get_hour: (skip): |
2678 | | **/ |
2679 | | guint8 |
2680 | | fu_struct_efi_time_get_hour(const FuStructEfiTime *st) |
2681 | 0 | { |
2682 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2683 | 0 | return st->buf->data[4]; |
2684 | 0 | } |
2685 | | /** |
2686 | | * fu_struct_efi_time_get_minute: (skip): |
2687 | | **/ |
2688 | | guint8 |
2689 | | fu_struct_efi_time_get_minute(const FuStructEfiTime *st) |
2690 | 0 | { |
2691 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2692 | 0 | return st->buf->data[5]; |
2693 | 0 | } |
2694 | | /** |
2695 | | * fu_struct_efi_time_get_second: (skip): |
2696 | | **/ |
2697 | | guint8 |
2698 | | fu_struct_efi_time_get_second(const FuStructEfiTime *st) |
2699 | 0 | { |
2700 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2701 | 0 | return st->buf->data[6]; |
2702 | 0 | } |
2703 | | /** |
2704 | | * fu_struct_efi_time_get_nanosecond: (skip): |
2705 | | **/ |
2706 | | guint32 |
2707 | | fu_struct_efi_time_get_nanosecond(const FuStructEfiTime *st) |
2708 | 0 | { |
2709 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2710 | 0 | return fu_memread_uint32(st->buf->data + 8, G_LITTLE_ENDIAN); |
2711 | 0 | } |
2712 | | /** |
2713 | | * fu_struct_efi_time_get_timezone: (skip): |
2714 | | **/ |
2715 | | guint16 |
2716 | | fu_struct_efi_time_get_timezone(const FuStructEfiTime *st) |
2717 | 0 | { |
2718 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2719 | 0 | return fu_memread_uint16(st->buf->data + 12, G_LITTLE_ENDIAN); |
2720 | 0 | } |
2721 | | /** |
2722 | | * fu_struct_efi_time_get_daylight: (skip): |
2723 | | **/ |
2724 | | guint8 |
2725 | | fu_struct_efi_time_get_daylight(const FuStructEfiTime *st) |
2726 | 0 | { |
2727 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2728 | 0 | return st->buf->data[14]; |
2729 | 0 | } |
2730 | | |
2731 | | /* setters */ |
2732 | | /** |
2733 | | * fu_struct_efi_time_set_year: (skip): |
2734 | | **/ |
2735 | | void |
2736 | | fu_struct_efi_time_set_year(FuStructEfiTime *st, guint16 value) |
2737 | 0 | { |
2738 | 0 | g_return_if_fail(st != NULL); |
2739 | 0 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2740 | 0 | } |
2741 | | /** |
2742 | | * fu_struct_efi_time_set_month: (skip): |
2743 | | **/ |
2744 | | void |
2745 | | fu_struct_efi_time_set_month(FuStructEfiTime *st, guint8 value) |
2746 | 0 | { |
2747 | 0 | g_return_if_fail(st != NULL); |
2748 | 0 | st->buf->data[2] = value; |
2749 | 0 | } |
2750 | | /** |
2751 | | * fu_struct_efi_time_set_day: (skip): |
2752 | | **/ |
2753 | | void |
2754 | | fu_struct_efi_time_set_day(FuStructEfiTime *st, guint8 value) |
2755 | 0 | { |
2756 | 0 | g_return_if_fail(st != NULL); |
2757 | 0 | st->buf->data[3] = value; |
2758 | 0 | } |
2759 | | /** |
2760 | | * fu_struct_efi_time_set_hour: (skip): |
2761 | | **/ |
2762 | | void |
2763 | | fu_struct_efi_time_set_hour(FuStructEfiTime *st, guint8 value) |
2764 | 0 | { |
2765 | 0 | g_return_if_fail(st != NULL); |
2766 | 0 | st->buf->data[4] = value; |
2767 | 0 | } |
2768 | | /** |
2769 | | * fu_struct_efi_time_set_minute: (skip): |
2770 | | **/ |
2771 | | void |
2772 | | fu_struct_efi_time_set_minute(FuStructEfiTime *st, guint8 value) |
2773 | 0 | { |
2774 | 0 | g_return_if_fail(st != NULL); |
2775 | 0 | st->buf->data[5] = value; |
2776 | 0 | } |
2777 | | /** |
2778 | | * fu_struct_efi_time_set_second: (skip): |
2779 | | **/ |
2780 | | void |
2781 | | fu_struct_efi_time_set_second(FuStructEfiTime *st, guint8 value) |
2782 | 0 | { |
2783 | 0 | g_return_if_fail(st != NULL); |
2784 | 0 | st->buf->data[6] = value; |
2785 | 0 | } |
2786 | | /** |
2787 | | * fu_struct_efi_time_set_nanosecond: (skip): |
2788 | | **/ |
2789 | | void |
2790 | | fu_struct_efi_time_set_nanosecond(FuStructEfiTime *st, guint32 value) |
2791 | 0 | { |
2792 | 0 | g_return_if_fail(st != NULL); |
2793 | 0 | fu_memwrite_uint32(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
2794 | 0 | } |
2795 | | /** |
2796 | | * fu_struct_efi_time_set_timezone: (skip): |
2797 | | **/ |
2798 | | void |
2799 | | fu_struct_efi_time_set_timezone(FuStructEfiTime *st, guint16 value) |
2800 | 0 | { |
2801 | 0 | g_return_if_fail(st != NULL); |
2802 | 0 | fu_memwrite_uint16(st->buf->data + 12, value, G_LITTLE_ENDIAN); |
2803 | 0 | } |
2804 | | /** |
2805 | | * fu_struct_efi_time_set_daylight: (skip): |
2806 | | **/ |
2807 | | void |
2808 | | fu_struct_efi_time_set_daylight(FuStructEfiTime *st, guint8 value) |
2809 | 0 | { |
2810 | 0 | g_return_if_fail(st != NULL); |
2811 | 0 | st->buf->data[14] = value; |
2812 | 0 | } |
2813 | | /** |
2814 | | * fu_struct_efi_time_new: (skip): |
2815 | | **/ |
2816 | | FuStructEfiTime * |
2817 | | fu_struct_efi_time_new(void) |
2818 | 525 | { |
2819 | 525 | FuStructEfiTime *st = fu_struct_efi_time_new_internal(); |
2820 | 525 | st->buf = g_byte_array_sized_new(16); |
2821 | 525 | fu_byte_array_set_size(st->buf, 16, 0x0); |
2822 | 525 | return st; |
2823 | 525 | } |
2824 | | /** |
2825 | | * fu_struct_efi_time_to_string: (skip): |
2826 | | **/ |
2827 | | gchar * |
2828 | | fu_struct_efi_time_to_string(const FuStructEfiTime *st) |
2829 | 0 | { |
2830 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiTime:\n"); |
2831 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2832 | 0 | g_string_append_printf(str, " year: 0x%x\n", |
2833 | 0 | (guint) fu_struct_efi_time_get_year(st)); |
2834 | 0 | g_string_append_printf(str, " month: 0x%x\n", |
2835 | 0 | (guint) fu_struct_efi_time_get_month(st)); |
2836 | 0 | g_string_append_printf(str, " day: 0x%x\n", |
2837 | 0 | (guint) fu_struct_efi_time_get_day(st)); |
2838 | 0 | g_string_append_printf(str, " hour: 0x%x\n", |
2839 | 0 | (guint) fu_struct_efi_time_get_hour(st)); |
2840 | 0 | g_string_append_printf(str, " minute: 0x%x\n", |
2841 | 0 | (guint) fu_struct_efi_time_get_minute(st)); |
2842 | 0 | g_string_append_printf(str, " second: 0x%x\n", |
2843 | 0 | (guint) fu_struct_efi_time_get_second(st)); |
2844 | 0 | g_string_append_printf(str, " nanosecond: 0x%x\n", |
2845 | 0 | (guint) fu_struct_efi_time_get_nanosecond(st)); |
2846 | 0 | g_string_append_printf(str, " timezone: 0x%x\n", |
2847 | 0 | (guint) fu_struct_efi_time_get_timezone(st)); |
2848 | 0 | g_string_append_printf(str, " daylight: 0x%x\n", |
2849 | 0 | (guint) fu_struct_efi_time_get_daylight(st)); |
2850 | 0 | if (str->len > 0) |
2851 | 0 | g_string_set_size(str, str->len - 1); |
2852 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
2853 | 0 | } |
2854 | | gboolean |
2855 | | fu_struct_efi_time_validate_internal(FuStructEfiTime *st, GError **error) |
2856 | 5.50k | { |
2857 | 5.50k | g_return_val_if_fail(st != NULL, FALSE); |
2858 | 5.50k | return TRUE; |
2859 | 5.50k | } |
2860 | | /** |
2861 | | * fu_struct_efi_win_certificate_ref: (skip): |
2862 | | **/ |
2863 | | FuStructEfiWinCertificate * |
2864 | | fu_struct_efi_win_certificate_ref(FuStructEfiWinCertificate *st) |
2865 | 0 | { |
2866 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2867 | 0 | st->refcount++; |
2868 | 0 | return st; |
2869 | 0 | } |
2870 | | /** |
2871 | | * fu_struct_efi_win_certificate_unref: (skip): |
2872 | | **/ |
2873 | | void |
2874 | | fu_struct_efi_win_certificate_unref(FuStructEfiWinCertificate *st) |
2875 | 0 | { |
2876 | 0 | g_return_if_fail(st != NULL); |
2877 | 0 | if (st->refcount == 0) { |
2878 | 0 | g_critical("FuStructEfiWinCertificate refcount already zero"); |
2879 | 0 | return; |
2880 | 0 | } |
2881 | 0 | if (--st->refcount > 0) |
2882 | 0 | return; |
2883 | 0 | if (st->buf != NULL) |
2884 | 0 | g_byte_array_unref(st->buf); |
2885 | 0 | g_free(st); |
2886 | 0 | } |
2887 | | /** |
2888 | | * fu_struct_efi_win_certificate_new_internal: (skip): |
2889 | | **/ |
2890 | | static FuStructEfiWinCertificate * |
2891 | | fu_struct_efi_win_certificate_new_internal(void) |
2892 | 0 | { |
2893 | 0 | FuStructEfiWinCertificate *st = g_new0(FuStructEfiWinCertificate, 1); |
2894 | 0 | st->refcount = 1; |
2895 | 0 | return st; |
2896 | 0 | } |
2897 | | |
2898 | | /* getters */ |
2899 | | /** |
2900 | | * fu_struct_efi_win_certificate_get_length: (skip): |
2901 | | **/ |
2902 | | guint32 |
2903 | | fu_struct_efi_win_certificate_get_length(const FuStructEfiWinCertificate *st) |
2904 | 0 | { |
2905 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2906 | 0 | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
2907 | 0 | } |
2908 | | /** |
2909 | | * fu_struct_efi_win_certificate_get_revision: (skip): |
2910 | | **/ |
2911 | | static guint16 |
2912 | | fu_struct_efi_win_certificate_get_revision(const FuStructEfiWinCertificate *st) |
2913 | 0 | { |
2914 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2915 | 0 | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
2916 | 0 | } |
2917 | | /** |
2918 | | * fu_struct_efi_win_certificate_get_certificate_type: (skip): |
2919 | | **/ |
2920 | | static guint16 |
2921 | | fu_struct_efi_win_certificate_get_certificate_type(const FuStructEfiWinCertificate *st) |
2922 | 0 | { |
2923 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
2924 | 0 | return fu_memread_uint16(st->buf->data + 6, G_LITTLE_ENDIAN); |
2925 | 0 | } |
2926 | | /** |
2927 | | * fu_struct_efi_win_certificate_get_guid: (skip): |
2928 | | **/ |
2929 | | static const fwupd_guid_t * |
2930 | | fu_struct_efi_win_certificate_get_guid(const FuStructEfiWinCertificate *st) |
2931 | 0 | { |
2932 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2933 | 0 | return (const fwupd_guid_t *) (st->buf->data + 8); |
2934 | 0 | } |
2935 | | |
2936 | | /* setters */ |
2937 | | /** |
2938 | | * fu_struct_efi_win_certificate_set_length: (skip): |
2939 | | **/ |
2940 | | void |
2941 | | fu_struct_efi_win_certificate_set_length(FuStructEfiWinCertificate *st, guint32 value) |
2942 | 0 | { |
2943 | 0 | g_return_if_fail(st != NULL); |
2944 | 0 | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2945 | 0 | } |
2946 | | /** |
2947 | | * fu_struct_efi_win_certificate_set_revision: (skip): |
2948 | | **/ |
2949 | | static void |
2950 | | fu_struct_efi_win_certificate_set_revision(FuStructEfiWinCertificate *st, guint16 value) |
2951 | 0 | { |
2952 | 0 | g_return_if_fail(st != NULL); |
2953 | 0 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
2954 | 0 | } |
2955 | | /** |
2956 | | * fu_struct_efi_win_certificate_set_certificate_type: (skip): |
2957 | | **/ |
2958 | | static void |
2959 | | fu_struct_efi_win_certificate_set_certificate_type(FuStructEfiWinCertificate *st, guint16 value) |
2960 | 0 | { |
2961 | 0 | g_return_if_fail(st != NULL); |
2962 | 0 | fu_memwrite_uint16(st->buf->data + 6, value, G_LITTLE_ENDIAN); |
2963 | 0 | } |
2964 | | /** |
2965 | | * fu_struct_efi_win_certificate_set_guid: (skip): |
2966 | | **/ |
2967 | | static void |
2968 | | fu_struct_efi_win_certificate_set_guid(FuStructEfiWinCertificate *st, const fwupd_guid_t *value) |
2969 | 0 | { |
2970 | 0 | g_return_if_fail(st != NULL); |
2971 | 0 | g_return_if_fail(value != NULL); |
2972 | 0 | memcpy(st->buf->data + 8, value, sizeof(*value)); /* nocheck:blocked */ |
2973 | 0 | } |
2974 | | /** |
2975 | | * fu_struct_efi_win_certificate_new: (skip): |
2976 | | **/ |
2977 | | static FuStructEfiWinCertificate * |
2978 | | fu_struct_efi_win_certificate_new(void) |
2979 | 0 | { |
2980 | 0 | FuStructEfiWinCertificate *st = fu_struct_efi_win_certificate_new_internal(); |
2981 | 0 | st->buf = g_byte_array_sized_new(24); |
2982 | 0 | fu_byte_array_set_size(st->buf, 24, 0x0); |
2983 | 0 | fu_struct_efi_win_certificate_set_length(st, 24); |
2984 | 0 | fu_struct_efi_win_certificate_set_revision(st, 0x0200); |
2985 | 0 | fu_struct_efi_win_certificate_set_certificate_type(st, 0x0EF1); |
2986 | 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"); |
2987 | 0 | return st; |
2988 | 0 | } |
2989 | | /** |
2990 | | * fu_struct_efi_win_certificate_to_string: (skip): |
2991 | | **/ |
2992 | | static gchar * |
2993 | | fu_struct_efi_win_certificate_to_string(const FuStructEfiWinCertificate *st) |
2994 | 0 | { |
2995 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiWinCertificate:\n"); |
2996 | 0 | g_return_val_if_fail(st != NULL, NULL); |
2997 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
2998 | 0 | (guint) fu_struct_efi_win_certificate_get_length(st)); |
2999 | 0 | g_string_append_printf(str, " revision: 0x%x\n", |
3000 | 0 | (guint) fu_struct_efi_win_certificate_get_revision(st)); |
3001 | 0 | g_string_append_printf(str, " certificate_type: 0x%x\n", |
3002 | 0 | (guint) fu_struct_efi_win_certificate_get_certificate_type(st)); |
3003 | 0 | { |
3004 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_win_certificate_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
3005 | 0 | g_string_append_printf(str, " guid: %s\n", tmp); |
3006 | 0 | } |
3007 | 0 | if (str->len > 0) |
3008 | 0 | g_string_set_size(str, str->len - 1); |
3009 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3010 | 0 | } |
3011 | | static gboolean |
3012 | | fu_struct_efi_win_certificate_validate_internal(FuStructEfiWinCertificate *st, GError **error) |
3013 | 0 | { |
3014 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3015 | 0 | if (fu_struct_efi_win_certificate_get_revision(st) != 0x0200) { |
3016 | 0 | g_set_error(error, |
3017 | 0 | FWUPD_ERROR, |
3018 | 0 | FWUPD_ERROR_INVALID_DATA, |
3019 | 0 | "constant FuStructEfiWinCertificate.revision was not valid, " |
3020 | 0 | "expected 0x%x and got 0x%x", |
3021 | 0 | (guint) 0x0200, |
3022 | 0 | (guint) fu_struct_efi_win_certificate_get_revision(st)); |
3023 | 0 | return FALSE; |
3024 | 0 | } |
3025 | 0 | if (fu_struct_efi_win_certificate_get_certificate_type(st) != 0x0EF1) { |
3026 | 0 | g_set_error(error, |
3027 | 0 | FWUPD_ERROR, |
3028 | 0 | FWUPD_ERROR_INVALID_DATA, |
3029 | 0 | "constant FuStructEfiWinCertificate.certificate_type was not valid, " |
3030 | 0 | "expected 0x%x and got 0x%x", |
3031 | 0 | (guint) 0x0EF1, |
3032 | 0 | (guint) fu_struct_efi_win_certificate_get_certificate_type(st)); |
3033 | 0 | return FALSE; |
3034 | 0 | } |
3035 | 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) { |
3036 | 0 | g_set_error_literal(error, |
3037 | 0 | FWUPD_ERROR, |
3038 | 0 | FWUPD_ERROR_INVALID_DATA, |
3039 | 0 | "constant FuStructEfiWinCertificate.guid was not valid"); |
3040 | 0 | return FALSE; |
3041 | 0 | } |
3042 | 0 | return TRUE; |
3043 | 0 | } |
3044 | | /** |
3045 | | * fu_struct_efi_variable_authentication2_ref: (skip): |
3046 | | **/ |
3047 | | FuStructEfiVariableAuthentication2 * |
3048 | | fu_struct_efi_variable_authentication2_ref(FuStructEfiVariableAuthentication2 *st) |
3049 | 0 | { |
3050 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3051 | 0 | st->refcount++; |
3052 | 0 | return st; |
3053 | 0 | } |
3054 | | /** |
3055 | | * fu_struct_efi_variable_authentication2_unref: (skip): |
3056 | | **/ |
3057 | | void |
3058 | | fu_struct_efi_variable_authentication2_unref(FuStructEfiVariableAuthentication2 *st) |
3059 | 0 | { |
3060 | 0 | g_return_if_fail(st != NULL); |
3061 | 0 | if (st->refcount == 0) { |
3062 | 0 | g_critical("FuStructEfiVariableAuthentication2 refcount already zero"); |
3063 | 0 | return; |
3064 | 0 | } |
3065 | 0 | if (--st->refcount > 0) |
3066 | 0 | return; |
3067 | 0 | if (st->buf != NULL) |
3068 | 0 | g_byte_array_unref(st->buf); |
3069 | 0 | g_free(st); |
3070 | 0 | } |
3071 | | /** |
3072 | | * fu_struct_efi_variable_authentication2_new_internal: (skip): |
3073 | | **/ |
3074 | | static FuStructEfiVariableAuthentication2 * |
3075 | | fu_struct_efi_variable_authentication2_new_internal(void) |
3076 | 0 | { |
3077 | 0 | FuStructEfiVariableAuthentication2 *st = g_new0(FuStructEfiVariableAuthentication2, 1); |
3078 | 0 | st->refcount = 1; |
3079 | 0 | return st; |
3080 | 0 | } |
3081 | | |
3082 | | /* getters */ |
3083 | | /** |
3084 | | * fu_struct_efi_variable_authentication2_get_timestamp: (skip): |
3085 | | **/ |
3086 | | FuStructEfiTime * |
3087 | | fu_struct_efi_variable_authentication2_get_timestamp(const FuStructEfiVariableAuthentication2 *st) |
3088 | 0 | { |
3089 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_time_new_internal(); |
3090 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3091 | 0 | st_tmp->buf = g_byte_array_new(); |
3092 | 0 | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, 16); |
3093 | 0 | return g_steal_pointer(&st_tmp); |
3094 | 0 | } |
3095 | | /** |
3096 | | * fu_struct_efi_variable_authentication2_get_auth_info: (skip): |
3097 | | **/ |
3098 | | FuStructEfiWinCertificate * |
3099 | | fu_struct_efi_variable_authentication2_get_auth_info(const FuStructEfiVariableAuthentication2 *st) |
3100 | 0 | { |
3101 | 0 | g_autoptr(FuStructEfiWinCertificate) st_tmp = fu_struct_efi_win_certificate_new_internal(); |
3102 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3103 | 0 | st_tmp->buf = g_byte_array_new(); |
3104 | 0 | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, 24); |
3105 | 0 | return g_steal_pointer(&st_tmp); |
3106 | 0 | } |
3107 | | |
3108 | | /* setters */ |
3109 | | /** |
3110 | | * fu_struct_efi_variable_authentication2_set_timestamp: (skip): |
3111 | | **/ |
3112 | | gboolean |
3113 | | fu_struct_efi_variable_authentication2_set_timestamp(FuStructEfiVariableAuthentication2 *st, const FuStructEfiTime *st_donor, GError **error) |
3114 | 0 | { |
3115 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3116 | 0 | g_return_val_if_fail(st_donor != NULL, FALSE); |
3117 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3118 | | |
3119 | 0 | if (st_donor->buf->len > FU_STRUCT_EFI_TIME_SIZE) { |
3120 | 0 | g_set_error(error, |
3121 | 0 | FWUPD_ERROR, |
3122 | 0 | FWUPD_ERROR_INVALID_DATA, |
3123 | 0 | "donor 'FuStructEfiTime' (0x%x bytes) does not fit in " |
3124 | 0 | "FuStructEfiVariableAuthentication2.timestamp (0x%x bytes)", |
3125 | 0 | (guint) st_donor->buf->len, |
3126 | 0 | (guint) FU_STRUCT_EFI_TIME_SIZE); |
3127 | 0 | return FALSE; |
3128 | 0 | } |
3129 | 0 | memcpy(st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, st_donor->buf->data, st_donor->buf->len); |
3130 | 0 | return TRUE; |
3131 | 0 | } |
3132 | | /** |
3133 | | * fu_struct_efi_variable_authentication2_set_auth_info: (skip): |
3134 | | **/ |
3135 | | gboolean |
3136 | | fu_struct_efi_variable_authentication2_set_auth_info(FuStructEfiVariableAuthentication2 *st, const FuStructEfiWinCertificate *st_donor, GError **error) |
3137 | 0 | { |
3138 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3139 | 0 | g_return_val_if_fail(st_donor != NULL, FALSE); |
3140 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3141 | | |
3142 | 0 | if (st_donor->buf->len > FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE) { |
3143 | 0 | g_set_error(error, |
3144 | 0 | FWUPD_ERROR, |
3145 | 0 | FWUPD_ERROR_INVALID_DATA, |
3146 | 0 | "donor 'FuStructEfiWinCertificate' (0x%x bytes) does not fit in " |
3147 | 0 | "FuStructEfiVariableAuthentication2.auth_info (0x%x bytes)", |
3148 | 0 | (guint) st_donor->buf->len, |
3149 | 0 | (guint) FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE); |
3150 | 0 | return FALSE; |
3151 | 0 | } |
3152 | 0 | memcpy(st->buf->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, st_donor->buf->data, st_donor->buf->len); |
3153 | 0 | return TRUE; |
3154 | 0 | } |
3155 | | /** |
3156 | | * fu_struct_efi_variable_authentication2_new: (skip): |
3157 | | **/ |
3158 | | FuStructEfiVariableAuthentication2 * |
3159 | | fu_struct_efi_variable_authentication2_new(void) |
3160 | 0 | { |
3161 | 0 | FuStructEfiVariableAuthentication2 *st = fu_struct_efi_variable_authentication2_new_internal(); |
3162 | 0 | st->buf = g_byte_array_sized_new(40); |
3163 | 0 | fu_byte_array_set_size(st->buf, 40, 0x0); |
3164 | 0 | { |
3165 | 0 | g_autoptr(FuStructEfiTime) st_donor = fu_struct_efi_time_new(); |
3166 | 0 | memcpy(st->buf->data + 0x0, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
3167 | 0 | } |
3168 | 0 | { |
3169 | 0 | g_autoptr(FuStructEfiWinCertificate) st_donor = fu_struct_efi_win_certificate_new(); |
3170 | 0 | memcpy(st->buf->data + 0x10, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
3171 | 0 | } |
3172 | 0 | return st; |
3173 | 0 | } |
3174 | | /** |
3175 | | * fu_struct_efi_variable_authentication2_to_string: (skip): |
3176 | | **/ |
3177 | | static gchar * |
3178 | | fu_struct_efi_variable_authentication2_to_string(const FuStructEfiVariableAuthentication2 *st) |
3179 | 0 | { |
3180 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVariableAuthentication2:\n"); |
3181 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3182 | 0 | { |
3183 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_variable_authentication2_get_timestamp(st); |
3184 | 0 | g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp); |
3185 | 0 | g_string_append_printf(str, " timestamp: %s\n", tmp); |
3186 | 0 | } |
3187 | 0 | { |
3188 | 0 | g_autoptr(FuStructEfiWinCertificate) st_tmp = fu_struct_efi_variable_authentication2_get_auth_info(st); |
3189 | 0 | g_autofree gchar *tmp = fu_struct_efi_win_certificate_to_string(st_tmp); |
3190 | 0 | g_string_append_printf(str, " auth_info: %s\n", tmp); |
3191 | 0 | } |
3192 | 0 | if (str->len > 0) |
3193 | 0 | g_string_set_size(str, str->len - 1); |
3194 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3195 | 0 | } |
3196 | | static gboolean |
3197 | | fu_struct_efi_variable_authentication2_validate_internal(FuStructEfiVariableAuthentication2 *st, GError **error) |
3198 | 0 | { |
3199 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3200 | 0 | { |
3201 | 0 | GByteArray buf_tmp = { |
3202 | 0 | .data = (guint8*) st->buf->data + 0x0, |
3203 | 0 | .len = 16, |
3204 | 0 | }; |
3205 | 0 | FuStructEfiTime st_tmp = { .buf = &buf_tmp }; |
3206 | 0 | if (!fu_struct_efi_time_validate_internal(&st_tmp, error)) |
3207 | 0 | return FALSE; |
3208 | 0 | } |
3209 | 0 | { |
3210 | 0 | GByteArray buf_tmp = { |
3211 | 0 | .data = (guint8*) st->buf->data + 0x10, |
3212 | 0 | .len = 24, |
3213 | 0 | }; |
3214 | 0 | FuStructEfiWinCertificate st_tmp = { .buf = &buf_tmp }; |
3215 | 0 | if (!fu_struct_efi_win_certificate_validate_internal(&st_tmp, error)) |
3216 | 0 | return FALSE; |
3217 | 0 | } |
3218 | 0 | return TRUE; |
3219 | 0 | } |
3220 | | /** |
3221 | | * fu_struct_efi_variable_authentication2_validate_stream: (skip): |
3222 | | **/ |
3223 | | gboolean |
3224 | | fu_struct_efi_variable_authentication2_validate_stream(GInputStream *stream, gsize offset, GError **error) |
3225 | 0 | { |
3226 | 0 | g_autoptr(FuStructEfiVariableAuthentication2) st = fu_struct_efi_variable_authentication2_new_internal(); |
3227 | 0 | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
3228 | 0 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3229 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error); |
3230 | 0 | if (st->buf == NULL) { |
3231 | 0 | g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40); |
3232 | 0 | return FALSE; |
3233 | 0 | } |
3234 | 0 | if (st->buf->len != 40) { |
3235 | 0 | g_set_error(error, |
3236 | 0 | FWUPD_ERROR, |
3237 | 0 | FWUPD_ERROR_INVALID_DATA, |
3238 | 0 | "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x", |
3239 | 0 | (guint) 40, |
3240 | 0 | (guint) st->buf->len); |
3241 | 0 | return FALSE; |
3242 | 0 | } |
3243 | 0 | return fu_struct_efi_variable_authentication2_validate_internal(st, error); |
3244 | 0 | } |
3245 | | static gboolean |
3246 | | fu_struct_efi_variable_authentication2_parse_internal(FuStructEfiVariableAuthentication2 *st, GError **error) |
3247 | 0 | { |
3248 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3249 | 0 | g_autofree gchar *str = fu_struct_efi_variable_authentication2_to_string(st); |
3250 | 0 | g_debug("%s", str); |
3251 | 0 | } |
3252 | 0 | if (!fu_struct_efi_variable_authentication2_validate_internal(st, error)) |
3253 | 0 | return FALSE; |
3254 | 0 | return TRUE; |
3255 | 0 | } |
3256 | | /** |
3257 | | * fu_struct_efi_variable_authentication2_parse_stream: (skip): |
3258 | | **/ |
3259 | | FuStructEfiVariableAuthentication2 * |
3260 | | fu_struct_efi_variable_authentication2_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3261 | 0 | { |
3262 | 0 | g_autoptr(FuStructEfiVariableAuthentication2) st = fu_struct_efi_variable_authentication2_new_internal(); |
3263 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error); |
3264 | 0 | if (st->buf == NULL) { |
3265 | 0 | g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40); |
3266 | 0 | return NULL; |
3267 | 0 | } |
3268 | 0 | if (st->buf->len != 40) { |
3269 | 0 | g_set_error(error, |
3270 | 0 | FWUPD_ERROR, |
3271 | 0 | FWUPD_ERROR_INVALID_DATA, |
3272 | 0 | "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x", |
3273 | 0 | (guint) 40, |
3274 | 0 | (guint) st->buf->len); |
3275 | 0 | return NULL; |
3276 | 0 | } |
3277 | 0 | if (!fu_struct_efi_variable_authentication2_parse_internal(st, error)) |
3278 | 0 | return NULL; |
3279 | 0 | return g_steal_pointer(&st); |
3280 | 0 | } |
3281 | | /** |
3282 | | * fu_struct_efi_signature_list_ref: (skip): |
3283 | | **/ |
3284 | | FuStructEfiSignatureList * |
3285 | | fu_struct_efi_signature_list_ref(FuStructEfiSignatureList *st) |
3286 | 0 | { |
3287 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3288 | 0 | st->refcount++; |
3289 | 0 | return st; |
3290 | 0 | } |
3291 | | /** |
3292 | | * fu_struct_efi_signature_list_unref: (skip): |
3293 | | **/ |
3294 | | void |
3295 | | fu_struct_efi_signature_list_unref(FuStructEfiSignatureList *st) |
3296 | 0 | { |
3297 | 0 | g_return_if_fail(st != NULL); |
3298 | 0 | if (st->refcount == 0) { |
3299 | 0 | g_critical("FuStructEfiSignatureList refcount already zero"); |
3300 | 0 | return; |
3301 | 0 | } |
3302 | 0 | if (--st->refcount > 0) |
3303 | 0 | return; |
3304 | 0 | if (st->buf != NULL) |
3305 | 0 | g_byte_array_unref(st->buf); |
3306 | 0 | g_free(st); |
3307 | 0 | } |
3308 | | /** |
3309 | | * fu_struct_efi_signature_list_new_internal: (skip): |
3310 | | **/ |
3311 | | static FuStructEfiSignatureList * |
3312 | | fu_struct_efi_signature_list_new_internal(void) |
3313 | 0 | { |
3314 | 0 | FuStructEfiSignatureList *st = g_new0(FuStructEfiSignatureList, 1); |
3315 | 0 | st->refcount = 1; |
3316 | 0 | return st; |
3317 | 0 | } |
3318 | | |
3319 | | /* getters */ |
3320 | | /** |
3321 | | * fu_struct_efi_signature_list_get_type: (skip): |
3322 | | **/ |
3323 | | const fwupd_guid_t * |
3324 | | fu_struct_efi_signature_list_get_type(const FuStructEfiSignatureList *st) |
3325 | 0 | { |
3326 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3327 | 0 | return (const fwupd_guid_t *) (st->buf->data + 0); |
3328 | 0 | } |
3329 | | /** |
3330 | | * fu_struct_efi_signature_list_get_list_size: (skip): |
3331 | | **/ |
3332 | | guint32 |
3333 | | fu_struct_efi_signature_list_get_list_size(const FuStructEfiSignatureList *st) |
3334 | 0 | { |
3335 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3336 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
3337 | 0 | } |
3338 | | /** |
3339 | | * fu_struct_efi_signature_list_get_header_size: (skip): |
3340 | | **/ |
3341 | | guint32 |
3342 | | fu_struct_efi_signature_list_get_header_size(const FuStructEfiSignatureList *st) |
3343 | 0 | { |
3344 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3345 | 0 | return fu_memread_uint32(st->buf->data + 20, G_LITTLE_ENDIAN); |
3346 | 0 | } |
3347 | | /** |
3348 | | * fu_struct_efi_signature_list_get_size: (skip): |
3349 | | **/ |
3350 | | guint32 |
3351 | | fu_struct_efi_signature_list_get_size(const FuStructEfiSignatureList *st) |
3352 | 0 | { |
3353 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3354 | 0 | return fu_memread_uint32(st->buf->data + 24, G_LITTLE_ENDIAN); |
3355 | 0 | } |
3356 | | |
3357 | | /* setters */ |
3358 | | /** |
3359 | | * fu_struct_efi_signature_list_set_type: (skip): |
3360 | | **/ |
3361 | | void |
3362 | | fu_struct_efi_signature_list_set_type(FuStructEfiSignatureList *st, const fwupd_guid_t *value) |
3363 | 0 | { |
3364 | 0 | g_return_if_fail(st != NULL); |
3365 | 0 | g_return_if_fail(value != NULL); |
3366 | 0 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
3367 | 0 | } |
3368 | | /** |
3369 | | * fu_struct_efi_signature_list_set_list_size: (skip): |
3370 | | **/ |
3371 | | void |
3372 | | fu_struct_efi_signature_list_set_list_size(FuStructEfiSignatureList *st, guint32 value) |
3373 | 0 | { |
3374 | 0 | g_return_if_fail(st != NULL); |
3375 | 0 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
3376 | 0 | } |
3377 | | /** |
3378 | | * fu_struct_efi_signature_list_set_header_size: (skip): |
3379 | | **/ |
3380 | | void |
3381 | | fu_struct_efi_signature_list_set_header_size(FuStructEfiSignatureList *st, guint32 value) |
3382 | 0 | { |
3383 | 0 | g_return_if_fail(st != NULL); |
3384 | 0 | fu_memwrite_uint32(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
3385 | 0 | } |
3386 | | /** |
3387 | | * fu_struct_efi_signature_list_set_size: (skip): |
3388 | | **/ |
3389 | | void |
3390 | | fu_struct_efi_signature_list_set_size(FuStructEfiSignatureList *st, guint32 value) |
3391 | 0 | { |
3392 | 0 | g_return_if_fail(st != NULL); |
3393 | 0 | fu_memwrite_uint32(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
3394 | 0 | } |
3395 | | /** |
3396 | | * fu_struct_efi_signature_list_new: (skip): |
3397 | | **/ |
3398 | | FuStructEfiSignatureList * |
3399 | | fu_struct_efi_signature_list_new(void) |
3400 | 0 | { |
3401 | 0 | FuStructEfiSignatureList *st = fu_struct_efi_signature_list_new_internal(); |
3402 | 0 | st->buf = g_byte_array_sized_new(28); |
3403 | 0 | fu_byte_array_set_size(st->buf, 28, 0x0); |
3404 | 0 | return st; |
3405 | 0 | } |
3406 | | /** |
3407 | | * fu_struct_efi_signature_list_to_string: (skip): |
3408 | | **/ |
3409 | | static gchar * |
3410 | | fu_struct_efi_signature_list_to_string(const FuStructEfiSignatureList *st) |
3411 | 0 | { |
3412 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiSignatureList:\n"); |
3413 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3414 | 0 | { |
3415 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_signature_list_get_type(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
3416 | 0 | g_string_append_printf(str, " type: %s\n", tmp); |
3417 | 0 | } |
3418 | 0 | g_string_append_printf(str, " list_size: 0x%x\n", |
3419 | 0 | (guint) fu_struct_efi_signature_list_get_list_size(st)); |
3420 | 0 | g_string_append_printf(str, " header_size: 0x%x\n", |
3421 | 0 | (guint) fu_struct_efi_signature_list_get_header_size(st)); |
3422 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
3423 | 0 | (guint) fu_struct_efi_signature_list_get_size(st)); |
3424 | 0 | if (str->len > 0) |
3425 | 0 | g_string_set_size(str, str->len - 1); |
3426 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3427 | 0 | } |
3428 | | static gboolean |
3429 | | fu_struct_efi_signature_list_validate_internal(FuStructEfiSignatureList *st, GError **error) |
3430 | 0 | { |
3431 | 0 | g_return_val_if_fail(st != NULL, FALSE); |
3432 | 0 | return TRUE; |
3433 | 0 | } |
3434 | | static gboolean |
3435 | | fu_struct_efi_signature_list_parse_internal(FuStructEfiSignatureList *st, GError **error) |
3436 | 0 | { |
3437 | 0 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3438 | 0 | g_autofree gchar *str = fu_struct_efi_signature_list_to_string(st); |
3439 | 0 | g_debug("%s", str); |
3440 | 0 | } |
3441 | 0 | if (!fu_struct_efi_signature_list_validate_internal(st, error)) |
3442 | 0 | return FALSE; |
3443 | 0 | return TRUE; |
3444 | 0 | } |
3445 | | /** |
3446 | | * fu_struct_efi_signature_list_parse_stream: (skip): |
3447 | | **/ |
3448 | | FuStructEfiSignatureList * |
3449 | | fu_struct_efi_signature_list_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3450 | 0 | { |
3451 | 0 | g_autoptr(FuStructEfiSignatureList) st = fu_struct_efi_signature_list_new_internal(); |
3452 | 0 | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
3453 | 0 | if (st->buf == NULL) { |
3454 | 0 | g_prefix_error(error, "FuStructEfiSignatureList failed read of 0x%x: ", (guint) 28); |
3455 | 0 | return NULL; |
3456 | 0 | } |
3457 | 0 | if (st->buf->len != 28) { |
3458 | 0 | g_set_error(error, |
3459 | 0 | FWUPD_ERROR, |
3460 | 0 | FWUPD_ERROR_INVALID_DATA, |
3461 | 0 | "FuStructEfiSignatureList requested 0x%x and got 0x%x", |
3462 | 0 | (guint) 28, |
3463 | 0 | (guint) st->buf->len); |
3464 | 0 | return NULL; |
3465 | 0 | } |
3466 | 0 | if (!fu_struct_efi_signature_list_parse_internal(st, error)) |
3467 | 0 | return NULL; |
3468 | 0 | return g_steal_pointer(&st); |
3469 | 0 | } |
3470 | | /** |
3471 | | * fu_struct_efi_load_option_ref: (skip): |
3472 | | **/ |
3473 | | FuStructEfiLoadOption * |
3474 | | fu_struct_efi_load_option_ref(FuStructEfiLoadOption *st) |
3475 | 0 | { |
3476 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3477 | 0 | st->refcount++; |
3478 | 0 | return st; |
3479 | 0 | } |
3480 | | /** |
3481 | | * fu_struct_efi_load_option_unref: (skip): |
3482 | | **/ |
3483 | | void |
3484 | | fu_struct_efi_load_option_unref(FuStructEfiLoadOption *st) |
3485 | 3.14k | { |
3486 | 3.14k | g_return_if_fail(st != NULL); |
3487 | 3.14k | if (st->refcount == 0) { |
3488 | 0 | g_critical("FuStructEfiLoadOption refcount already zero"); |
3489 | 0 | return; |
3490 | 0 | } |
3491 | 3.14k | if (--st->refcount > 0) |
3492 | 0 | return; |
3493 | 3.14k | if (st->buf != NULL) |
3494 | 2.24k | g_byte_array_unref(st->buf); |
3495 | 3.14k | g_free(st); |
3496 | 3.14k | } |
3497 | | /** |
3498 | | * fu_struct_efi_load_option_new_internal: (skip): |
3499 | | **/ |
3500 | | static FuStructEfiLoadOption * |
3501 | | fu_struct_efi_load_option_new_internal(void) |
3502 | 3.14k | { |
3503 | 3.14k | FuStructEfiLoadOption *st = g_new0(FuStructEfiLoadOption, 1); |
3504 | 3.14k | st->refcount = 1; |
3505 | 3.14k | return st; |
3506 | 3.14k | } |
3507 | | |
3508 | | /* getters */ |
3509 | | /** |
3510 | | * fu_struct_efi_load_option_get_attrs: (skip): |
3511 | | **/ |
3512 | | FuEfiLoadOptionAttrs |
3513 | | fu_struct_efi_load_option_get_attrs(const FuStructEfiLoadOption *st) |
3514 | 2.06k | { |
3515 | 2.06k | g_return_val_if_fail(st != NULL, 0x0); |
3516 | 2.06k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
3517 | 2.06k | } |
3518 | | /** |
3519 | | * fu_struct_efi_load_option_get_dp_size: (skip): |
3520 | | **/ |
3521 | | guint16 |
3522 | | fu_struct_efi_load_option_get_dp_size(const FuStructEfiLoadOption *st) |
3523 | 1.50k | { |
3524 | 1.50k | g_return_val_if_fail(st != NULL, 0x0); |
3525 | 1.50k | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
3526 | 1.50k | } |
3527 | | |
3528 | | /* setters */ |
3529 | | /** |
3530 | | * fu_struct_efi_load_option_set_attrs: (skip): |
3531 | | **/ |
3532 | | void |
3533 | | fu_struct_efi_load_option_set_attrs(FuStructEfiLoadOption *st, FuEfiLoadOptionAttrs value) |
3534 | 1.07k | { |
3535 | 1.07k | g_return_if_fail(st != NULL); |
3536 | 1.07k | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
3537 | 1.07k | } |
3538 | | /** |
3539 | | * fu_struct_efi_load_option_set_dp_size: (skip): |
3540 | | **/ |
3541 | | void |
3542 | | fu_struct_efi_load_option_set_dp_size(FuStructEfiLoadOption *st, guint16 value) |
3543 | 895 | { |
3544 | 895 | g_return_if_fail(st != NULL); |
3545 | 895 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
3546 | 895 | } |
3547 | | /** |
3548 | | * fu_struct_efi_load_option_new: (skip): |
3549 | | **/ |
3550 | | FuStructEfiLoadOption * |
3551 | | fu_struct_efi_load_option_new(void) |
3552 | 1.07k | { |
3553 | 1.07k | FuStructEfiLoadOption *st = fu_struct_efi_load_option_new_internal(); |
3554 | 1.07k | st->buf = g_byte_array_sized_new(6); |
3555 | 1.07k | fu_byte_array_set_size(st->buf, 6, 0x0); |
3556 | 1.07k | return st; |
3557 | 1.07k | } |
3558 | | /** |
3559 | | * fu_struct_efi_load_option_to_string: (skip): |
3560 | | **/ |
3561 | | static gchar * |
3562 | | fu_struct_efi_load_option_to_string(const FuStructEfiLoadOption *st) |
3563 | 0 | { |
3564 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiLoadOption:\n"); |
3565 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3566 | 0 | { |
3567 | 0 | const gchar *tmp = fu_efi_load_option_attrs_to_string(fu_struct_efi_load_option_get_attrs(st)); |
3568 | 0 | if (tmp != NULL) { |
3569 | 0 | g_string_append_printf(str, " attrs: 0x%x [%s]\n", (guint) fu_struct_efi_load_option_get_attrs(st), tmp); |
3570 | 0 | } else { |
3571 | 0 | g_string_append_printf(str, " attrs: 0x%x\n", (guint) fu_struct_efi_load_option_get_attrs(st)); |
3572 | 0 | } |
3573 | 0 | } |
3574 | 0 | g_string_append_printf(str, " dp_size: 0x%x\n", |
3575 | 0 | (guint) fu_struct_efi_load_option_get_dp_size(st)); |
3576 | 0 | if (str->len > 0) |
3577 | 0 | g_string_set_size(str, str->len - 1); |
3578 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3579 | 0 | } |
3580 | | static gboolean |
3581 | | fu_struct_efi_load_option_validate_internal(FuStructEfiLoadOption *st, GError **error) |
3582 | 2.06k | { |
3583 | 2.06k | g_return_val_if_fail(st != NULL, FALSE); |
3584 | 2.06k | return TRUE; |
3585 | 2.06k | } |
3586 | | static gboolean |
3587 | | fu_struct_efi_load_option_parse_internal(FuStructEfiLoadOption *st, GError **error) |
3588 | 2.06k | { |
3589 | 2.06k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3590 | 0 | g_autofree gchar *str = fu_struct_efi_load_option_to_string(st); |
3591 | 0 | g_debug("%s", str); |
3592 | 0 | } |
3593 | 2.06k | if (!fu_struct_efi_load_option_validate_internal(st, error)) |
3594 | 0 | return FALSE; |
3595 | 2.06k | return TRUE; |
3596 | 2.06k | } |
3597 | | /** |
3598 | | * fu_struct_efi_load_option_parse_stream: (skip): |
3599 | | **/ |
3600 | | FuStructEfiLoadOption * |
3601 | | fu_struct_efi_load_option_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3602 | 2.07k | { |
3603 | 2.07k | g_autoptr(FuStructEfiLoadOption) st = fu_struct_efi_load_option_new_internal(); |
3604 | 2.07k | st->buf = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error); |
3605 | 2.07k | if (st->buf == NULL) { |
3606 | 0 | g_prefix_error(error, "FuStructEfiLoadOption failed read of 0x%x: ", (guint) 6); |
3607 | 0 | return NULL; |
3608 | 0 | } |
3609 | 2.07k | if (st->buf->len != 6) { |
3610 | 9 | g_set_error(error, |
3611 | 9 | FWUPD_ERROR, |
3612 | 9 | FWUPD_ERROR_INVALID_DATA, |
3613 | 9 | "FuStructEfiLoadOption requested 0x%x and got 0x%x", |
3614 | 9 | (guint) 6, |
3615 | 9 | (guint) st->buf->len); |
3616 | 9 | return NULL; |
3617 | 9 | } |
3618 | 2.06k | if (!fu_struct_efi_load_option_parse_internal(st, error)) |
3619 | 0 | return NULL; |
3620 | 2.06k | return g_steal_pointer(&st); |
3621 | 2.06k | } |
3622 | | /** |
3623 | | * fu_struct_efi_device_path_ref: (skip): |
3624 | | **/ |
3625 | | FuStructEfiDevicePath * |
3626 | | fu_struct_efi_device_path_ref(FuStructEfiDevicePath *st) |
3627 | 0 | { |
3628 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3629 | 0 | st->refcount++; |
3630 | 0 | return st; |
3631 | 0 | } |
3632 | | /** |
3633 | | * fu_struct_efi_device_path_unref: (skip): |
3634 | | **/ |
3635 | | void |
3636 | | fu_struct_efi_device_path_unref(FuStructEfiDevicePath *st) |
3637 | 40.0k | { |
3638 | 40.0k | g_return_if_fail(st != NULL); |
3639 | 40.0k | if (st->refcount == 0) { |
3640 | 0 | g_critical("FuStructEfiDevicePath refcount already zero"); |
3641 | 0 | return; |
3642 | 0 | } |
3643 | 40.0k | if (--st->refcount > 0) |
3644 | 0 | return; |
3645 | 40.0k | if (st->buf != NULL) |
3646 | 36.7k | g_byte_array_unref(st->buf); |
3647 | 40.0k | g_free(st); |
3648 | 40.0k | } |
3649 | | /** |
3650 | | * fu_struct_efi_device_path_new_internal: (skip): |
3651 | | **/ |
3652 | | static FuStructEfiDevicePath * |
3653 | | fu_struct_efi_device_path_new_internal(void) |
3654 | 40.0k | { |
3655 | 40.0k | FuStructEfiDevicePath *st = g_new0(FuStructEfiDevicePath, 1); |
3656 | 40.0k | st->refcount = 1; |
3657 | 40.0k | return st; |
3658 | 40.0k | } |
3659 | | |
3660 | | /* getters */ |
3661 | | /** |
3662 | | * fu_struct_efi_device_path_get_type: (skip): |
3663 | | **/ |
3664 | | FuEfiDevicePathType |
3665 | | fu_struct_efi_device_path_get_type(const FuStructEfiDevicePath *st) |
3666 | 54.2k | { |
3667 | 54.2k | g_return_val_if_fail(st != NULL, 0x0); |
3668 | 54.2k | return st->buf->data[0]; |
3669 | 54.2k | } |
3670 | | /** |
3671 | | * fu_struct_efi_device_path_get_subtype: (skip): |
3672 | | **/ |
3673 | | guint8 |
3674 | | fu_struct_efi_device_path_get_subtype(const FuStructEfiDevicePath *st) |
3675 | 35.1k | { |
3676 | 35.1k | g_return_val_if_fail(st != NULL, 0x0); |
3677 | 35.1k | return st->buf->data[1]; |
3678 | 35.1k | } |
3679 | | /** |
3680 | | * fu_struct_efi_device_path_get_length: (skip): |
3681 | | **/ |
3682 | | guint16 |
3683 | | fu_struct_efi_device_path_get_length(const FuStructEfiDevicePath *st) |
3684 | 33.8k | { |
3685 | 33.8k | g_return_val_if_fail(st != NULL, 0x0); |
3686 | 33.8k | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3687 | 33.8k | } |
3688 | | |
3689 | | /* setters */ |
3690 | | /** |
3691 | | * fu_struct_efi_device_path_set_type: (skip): |
3692 | | **/ |
3693 | | void |
3694 | | fu_struct_efi_device_path_set_type(FuStructEfiDevicePath *st, FuEfiDevicePathType value) |
3695 | 4.19k | { |
3696 | 4.19k | g_return_if_fail(st != NULL); |
3697 | 4.19k | st->buf->data[0] = value; |
3698 | 4.19k | } |
3699 | | /** |
3700 | | * fu_struct_efi_device_path_set_subtype: (skip): |
3701 | | **/ |
3702 | | void |
3703 | | fu_struct_efi_device_path_set_subtype(FuStructEfiDevicePath *st, guint8 value) |
3704 | 8.56k | { |
3705 | 8.56k | g_return_if_fail(st != NULL); |
3706 | 8.56k | st->buf->data[1] = value; |
3707 | 8.56k | } |
3708 | | /** |
3709 | | * fu_struct_efi_device_path_set_length: (skip): |
3710 | | **/ |
3711 | | void |
3712 | | fu_struct_efi_device_path_set_length(FuStructEfiDevicePath *st, guint16 value) |
3713 | 7.67k | { |
3714 | 7.67k | g_return_if_fail(st != NULL); |
3715 | 7.67k | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
3716 | 7.67k | } |
3717 | | /** |
3718 | | * fu_struct_efi_device_path_new: (skip): |
3719 | | **/ |
3720 | | FuStructEfiDevicePath * |
3721 | | fu_struct_efi_device_path_new(void) |
3722 | 4.37k | { |
3723 | 4.37k | FuStructEfiDevicePath *st = fu_struct_efi_device_path_new_internal(); |
3724 | 4.37k | st->buf = g_byte_array_sized_new(4); |
3725 | 4.37k | fu_byte_array_set_size(st->buf, 4, 0x0); |
3726 | 4.37k | fu_struct_efi_device_path_set_subtype(st, 0xFF); |
3727 | 4.37k | fu_struct_efi_device_path_set_length(st, 4); |
3728 | 4.37k | return st; |
3729 | 4.37k | } |
3730 | | /** |
3731 | | * fu_struct_efi_device_path_to_string: (skip): |
3732 | | **/ |
3733 | | static gchar * |
3734 | | fu_struct_efi_device_path_to_string(const FuStructEfiDevicePath *st) |
3735 | 0 | { |
3736 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiDevicePath:\n"); |
3737 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3738 | 0 | { |
3739 | 0 | const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_device_path_get_type(st)); |
3740 | 0 | if (tmp != NULL) { |
3741 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_device_path_get_type(st), tmp); |
3742 | 0 | } else { |
3743 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_device_path_get_type(st)); |
3744 | 0 | } |
3745 | 0 | } |
3746 | 0 | g_string_append_printf(str, " subtype: 0x%x\n", |
3747 | 0 | (guint) fu_struct_efi_device_path_get_subtype(st)); |
3748 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
3749 | 0 | (guint) fu_struct_efi_device_path_get_length(st)); |
3750 | 0 | if (str->len > 0) |
3751 | 0 | g_string_set_size(str, str->len - 1); |
3752 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
3753 | 0 | } |
3754 | | static gboolean |
3755 | | fu_struct_efi_device_path_validate_internal(FuStructEfiDevicePath *st, GError **error) |
3756 | 35.6k | { |
3757 | 35.6k | g_return_val_if_fail(st != NULL, FALSE); |
3758 | 35.6k | return TRUE; |
3759 | 35.6k | } |
3760 | | static gboolean |
3761 | | fu_struct_efi_device_path_parse_internal(FuStructEfiDevicePath *st, GError **error) |
3762 | 35.6k | { |
3763 | 35.6k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
3764 | 0 | g_autofree gchar *str = fu_struct_efi_device_path_to_string(st); |
3765 | 0 | g_debug("%s", str); |
3766 | 0 | } |
3767 | 35.6k | if (!fu_struct_efi_device_path_validate_internal(st, error)) |
3768 | 0 | return FALSE; |
3769 | 35.6k | return TRUE; |
3770 | 35.6k | } |
3771 | | /** |
3772 | | * fu_struct_efi_device_path_parse_stream: (skip): |
3773 | | **/ |
3774 | | FuStructEfiDevicePath * |
3775 | | fu_struct_efi_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error) |
3776 | 35.6k | { |
3777 | 35.6k | g_autoptr(FuStructEfiDevicePath) st = fu_struct_efi_device_path_new_internal(); |
3778 | 35.6k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
3779 | 35.6k | if (st->buf == NULL) { |
3780 | 0 | g_prefix_error(error, "FuStructEfiDevicePath failed read of 0x%x: ", (guint) 4); |
3781 | 0 | return NULL; |
3782 | 0 | } |
3783 | 35.6k | if (st->buf->len != 4) { |
3784 | 33 | g_set_error(error, |
3785 | 33 | FWUPD_ERROR, |
3786 | 33 | FWUPD_ERROR_INVALID_DATA, |
3787 | 33 | "FuStructEfiDevicePath requested 0x%x and got 0x%x", |
3788 | 33 | (guint) 4, |
3789 | 33 | (guint) st->buf->len); |
3790 | 33 | return NULL; |
3791 | 33 | } |
3792 | 35.6k | if (!fu_struct_efi_device_path_parse_internal(st, error)) |
3793 | 0 | return NULL; |
3794 | 35.6k | return g_steal_pointer(&st); |
3795 | 35.6k | } |
3796 | | /** |
3797 | | * fu_struct_efi_hard_drive_device_path_ref: (skip): |
3798 | | **/ |
3799 | | FuStructEfiHardDriveDevicePath * |
3800 | | fu_struct_efi_hard_drive_device_path_ref(FuStructEfiHardDriveDevicePath *st) |
3801 | 0 | { |
3802 | 0 | g_return_val_if_fail(st != NULL, NULL); |
3803 | 0 | st->refcount++; |
3804 | 0 | return st; |
3805 | 0 | } |
3806 | | /** |
3807 | | * fu_struct_efi_hard_drive_device_path_unref: (skip): |
3808 | | **/ |
3809 | | void |
3810 | | fu_struct_efi_hard_drive_device_path_unref(FuStructEfiHardDriveDevicePath *st) |
3811 | 1.21k | { |
3812 | 1.21k | g_return_if_fail(st != NULL); |
3813 | 1.21k | if (st->refcount == 0) { |
3814 | 0 | g_critical("FuStructEfiHardDriveDevicePath refcount already zero"); |
3815 | 0 | return; |
3816 | 0 | } |
3817 | 1.21k | if (--st->refcount > 0) |
3818 | 0 | return; |
3819 | 1.21k | if (st->buf != NULL) |
3820 | 830 | g_byte_array_unref(st->buf); |
3821 | 1.21k | g_free(st); |
3822 | 1.21k | } |
3823 | | /** |
3824 | | * fu_struct_efi_hard_drive_device_path_new_internal: (skip): |
3825 | | **/ |
3826 | | static FuStructEfiHardDriveDevicePath * |
3827 | | fu_struct_efi_hard_drive_device_path_new_internal(void) |
3828 | 1.21k | { |
3829 | 1.21k | FuStructEfiHardDriveDevicePath *st = g_new0(FuStructEfiHardDriveDevicePath, 1); |
3830 | 1.21k | st->refcount = 1; |
3831 | 1.21k | return st; |
3832 | 1.21k | } |
3833 | | |
3834 | | /* getters */ |
3835 | | /** |
3836 | | * fu_struct_efi_hard_drive_device_path_get_type: (skip): |
3837 | | **/ |
3838 | | static FuEfiDevicePathType |
3839 | | fu_struct_efi_hard_drive_device_path_get_type(const FuStructEfiHardDriveDevicePath *st) |
3840 | 808 | { |
3841 | 808 | g_return_val_if_fail(st != NULL, 0x0); |
3842 | 808 | return st->buf->data[0]; |
3843 | 808 | } |
3844 | | /** |
3845 | | * fu_struct_efi_hard_drive_device_path_get_subtype: (skip): |
3846 | | **/ |
3847 | | FuEfiHardDriveDevicePathSubtype |
3848 | | fu_struct_efi_hard_drive_device_path_get_subtype(const FuStructEfiHardDriveDevicePath *st) |
3849 | 0 | { |
3850 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
3851 | 0 | return st->buf->data[1]; |
3852 | 0 | } |
3853 | | /** |
3854 | | * fu_struct_efi_hard_drive_device_path_get_length: (skip): |
3855 | | **/ |
3856 | | static guint16 |
3857 | | fu_struct_efi_hard_drive_device_path_get_length(const FuStructEfiHardDriveDevicePath *st) |
3858 | 826 | { |
3859 | 826 | g_return_val_if_fail(st != NULL, 0x0); |
3860 | 826 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3861 | 826 | } |
3862 | | /** |
3863 | | * fu_struct_efi_hard_drive_device_path_get_partition_number: (skip): |
3864 | | **/ |
3865 | | guint32 |
3866 | | fu_struct_efi_hard_drive_device_path_get_partition_number(const FuStructEfiHardDriveDevicePath *st) |
3867 | 790 | { |
3868 | 790 | g_return_val_if_fail(st != NULL, 0x0); |
3869 | 790 | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
3870 | 790 | } |
3871 | | /** |
3872 | | * fu_struct_efi_hard_drive_device_path_get_partition_start: (skip): |
3873 | | **/ |
3874 | | guint64 |
3875 | | fu_struct_efi_hard_drive_device_path_get_partition_start(const FuStructEfiHardDriveDevicePath *st) |
3876 | 790 | { |
3877 | 790 | g_return_val_if_fail(st != NULL, 0x0); |
3878 | 790 | return fu_memread_uint64(st->buf->data + 8, G_LITTLE_ENDIAN); |
3879 | 790 | } |
3880 | | /** |
3881 | | * fu_struct_efi_hard_drive_device_path_get_partition_size: (skip): |
3882 | | **/ |
3883 | | guint64 |
3884 | | fu_struct_efi_hard_drive_device_path_get_partition_size(const FuStructEfiHardDriveDevicePath *st) |
3885 | 790 | { |
3886 | 790 | g_return_val_if_fail(st != NULL, 0x0); |
3887 | 790 | return fu_memread_uint64(st->buf->data + 16, G_LITTLE_ENDIAN); |
3888 | 790 | } |
3889 | | /** |
3890 | | * fu_struct_efi_hard_drive_device_path_get_partition_signature: (skip): |
3891 | | **/ |
3892 | | const fwupd_guid_t * |
3893 | | fu_struct_efi_hard_drive_device_path_get_partition_signature(const FuStructEfiHardDriveDevicePath *st) |
3894 | 790 | { |
3895 | 790 | g_return_val_if_fail(st != NULL, NULL); |
3896 | 790 | return (const fwupd_guid_t *) (st->buf->data + 24); |
3897 | 790 | } |
3898 | | /** |
3899 | | * fu_struct_efi_hard_drive_device_path_get_partition_format: (skip): |
3900 | | **/ |
3901 | | FuEfiHardDriveDevicePathPartitionFormat |
3902 | | fu_struct_efi_hard_drive_device_path_get_partition_format(const FuStructEfiHardDriveDevicePath *st) |
3903 | 790 | { |
3904 | 790 | g_return_val_if_fail(st != NULL, 0x0); |
3905 | 790 | return st->buf->data[40]; |
3906 | 790 | } |
3907 | | /** |
3908 | | * fu_struct_efi_hard_drive_device_path_get_signature_type: (skip): |
3909 | | **/ |
3910 | | FuEfiHardDriveDevicePathSignatureType |
3911 | | fu_struct_efi_hard_drive_device_path_get_signature_type(const FuStructEfiHardDriveDevicePath *st) |
3912 | 790 | { |
3913 | 790 | g_return_val_if_fail(st != NULL, 0x0); |
3914 | 790 | return st->buf->data[41]; |
3915 | 790 | } |
3916 | | |
3917 | | /* setters */ |
3918 | | /** |
3919 | | * fu_struct_efi_hard_drive_device_path_set_type: (skip): |
3920 | | **/ |
3921 | | static void |
3922 | | fu_struct_efi_hard_drive_device_path_set_type(FuStructEfiHardDriveDevicePath *st, FuEfiDevicePathType value) |
3923 | 389 | { |
3924 | 389 | g_return_if_fail(st != NULL); |
3925 | 389 | st->buf->data[0] = value; |
3926 | 389 | } |
3927 | | /** |
3928 | | * fu_struct_efi_hard_drive_device_path_set_subtype: (skip): |
3929 | | **/ |
3930 | | void |
3931 | | fu_struct_efi_hard_drive_device_path_set_subtype(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSubtype value) |
3932 | 389 | { |
3933 | 389 | g_return_if_fail(st != NULL); |
3934 | 389 | st->buf->data[1] = value; |
3935 | 389 | } |
3936 | | /** |
3937 | | * fu_struct_efi_hard_drive_device_path_set_length: (skip): |
3938 | | **/ |
3939 | | static void |
3940 | | fu_struct_efi_hard_drive_device_path_set_length(FuStructEfiHardDriveDevicePath *st, guint16 value) |
3941 | 389 | { |
3942 | 389 | g_return_if_fail(st != NULL); |
3943 | 389 | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
3944 | 389 | } |
3945 | | /** |
3946 | | * fu_struct_efi_hard_drive_device_path_set_partition_number: (skip): |
3947 | | **/ |
3948 | | void |
3949 | | fu_struct_efi_hard_drive_device_path_set_partition_number(FuStructEfiHardDriveDevicePath *st, guint32 value) |
3950 | 389 | { |
3951 | 389 | g_return_if_fail(st != NULL); |
3952 | 389 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
3953 | 389 | } |
3954 | | /** |
3955 | | * fu_struct_efi_hard_drive_device_path_set_partition_start: (skip): |
3956 | | **/ |
3957 | | void |
3958 | | fu_struct_efi_hard_drive_device_path_set_partition_start(FuStructEfiHardDriveDevicePath *st, guint64 value) |
3959 | 389 | { |
3960 | 389 | g_return_if_fail(st != NULL); |
3961 | 389 | fu_memwrite_uint64(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
3962 | 389 | } |
3963 | | /** |
3964 | | * fu_struct_efi_hard_drive_device_path_set_partition_size: (skip): |
3965 | | **/ |
3966 | | void |
3967 | | fu_struct_efi_hard_drive_device_path_set_partition_size(FuStructEfiHardDriveDevicePath *st, guint64 value) |
3968 | 389 | { |
3969 | 389 | g_return_if_fail(st != NULL); |
3970 | 389 | fu_memwrite_uint64(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
3971 | 389 | } |
3972 | | /** |
3973 | | * fu_struct_efi_hard_drive_device_path_set_partition_signature: (skip): |
3974 | | **/ |
3975 | | void |
3976 | | fu_struct_efi_hard_drive_device_path_set_partition_signature(FuStructEfiHardDriveDevicePath *st, const fwupd_guid_t *value) |
3977 | 389 | { |
3978 | 389 | g_return_if_fail(st != NULL); |
3979 | 389 | g_return_if_fail(value != NULL); |
3980 | 389 | memcpy(st->buf->data + 24, value, sizeof(*value)); /* nocheck:blocked */ |
3981 | 389 | } |
3982 | | /** |
3983 | | * fu_struct_efi_hard_drive_device_path_set_partition_format: (skip): |
3984 | | **/ |
3985 | | void |
3986 | | fu_struct_efi_hard_drive_device_path_set_partition_format(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathPartitionFormat value) |
3987 | 778 | { |
3988 | 778 | g_return_if_fail(st != NULL); |
3989 | 778 | st->buf->data[40] = value; |
3990 | 778 | } |
3991 | | /** |
3992 | | * fu_struct_efi_hard_drive_device_path_set_signature_type: (skip): |
3993 | | **/ |
3994 | | void |
3995 | | fu_struct_efi_hard_drive_device_path_set_signature_type(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSignatureType value) |
3996 | 778 | { |
3997 | 778 | g_return_if_fail(st != NULL); |
3998 | 778 | st->buf->data[41] = value; |
3999 | 778 | } |
4000 | | /** |
4001 | | * fu_struct_efi_hard_drive_device_path_new: (skip): |
4002 | | **/ |
4003 | | FuStructEfiHardDriveDevicePath * |
4004 | | fu_struct_efi_hard_drive_device_path_new(void) |
4005 | 389 | { |
4006 | 389 | FuStructEfiHardDriveDevicePath *st = fu_struct_efi_hard_drive_device_path_new_internal(); |
4007 | 389 | st->buf = g_byte_array_sized_new(42); |
4008 | 389 | fu_byte_array_set_size(st->buf, 42, 0x0); |
4009 | 389 | fu_struct_efi_hard_drive_device_path_set_type(st, FU_EFI_DEVICE_PATH_TYPE_MEDIA); |
4010 | 389 | fu_struct_efi_hard_drive_device_path_set_subtype(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE); |
4011 | 389 | fu_struct_efi_hard_drive_device_path_set_length(st, 42); |
4012 | 389 | fu_struct_efi_hard_drive_device_path_set_partition_format(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE); |
4013 | 389 | fu_struct_efi_hard_drive_device_path_set_signature_type(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID); |
4014 | 389 | return st; |
4015 | 389 | } |
4016 | | /** |
4017 | | * fu_struct_efi_hard_drive_device_path_to_string: (skip): |
4018 | | **/ |
4019 | | static gchar * |
4020 | | fu_struct_efi_hard_drive_device_path_to_string(const FuStructEfiHardDriveDevicePath *st) |
4021 | 0 | { |
4022 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiHardDriveDevicePath:\n"); |
4023 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4024 | 0 | { |
4025 | 0 | const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_hard_drive_device_path_get_type(st)); |
4026 | 0 | if (tmp != NULL) { |
4027 | 0 | g_string_append_printf(str, " type: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_type(st), tmp); |
4028 | 0 | } else { |
4029 | 0 | g_string_append_printf(str, " type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_type(st)); |
4030 | 0 | } |
4031 | 0 | } |
4032 | 0 | { |
4033 | 0 | const gchar *tmp = fu_efi_hard_drive_device_path_subtype_to_string(fu_struct_efi_hard_drive_device_path_get_subtype(st)); |
4034 | 0 | if (tmp != NULL) { |
4035 | 0 | g_string_append_printf(str, " subtype: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st), tmp); |
4036 | 0 | } else { |
4037 | 0 | g_string_append_printf(str, " subtype: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st)); |
4038 | 0 | } |
4039 | 0 | } |
4040 | 0 | g_string_append_printf(str, " length: 0x%x\n", |
4041 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_length(st)); |
4042 | 0 | g_string_append_printf(str, " partition_number: 0x%x\n", |
4043 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_number(st)); |
4044 | 0 | g_string_append_printf(str, " partition_start: 0x%x\n", |
4045 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_start(st)); |
4046 | 0 | g_string_append_printf(str, " partition_size: 0x%x\n", |
4047 | 0 | (guint) fu_struct_efi_hard_drive_device_path_get_partition_size(st)); |
4048 | 0 | { |
4049 | 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); |
4050 | 0 | g_string_append_printf(str, " partition_signature: %s\n", tmp); |
4051 | 0 | } |
4052 | 0 | { |
4053 | 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)); |
4054 | 0 | if (tmp != NULL) { |
4055 | 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); |
4056 | 0 | } else { |
4057 | 0 | g_string_append_printf(str, " partition_format: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_partition_format(st)); |
4058 | 0 | } |
4059 | 0 | } |
4060 | 0 | { |
4061 | 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)); |
4062 | 0 | if (tmp != NULL) { |
4063 | 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); |
4064 | 0 | } else { |
4065 | 0 | g_string_append_printf(str, " signature_type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_signature_type(st)); |
4066 | 0 | } |
4067 | 0 | } |
4068 | 0 | if (str->len > 0) |
4069 | 0 | g_string_set_size(str, str->len - 1); |
4070 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4071 | 0 | } |
4072 | | static gboolean |
4073 | | fu_struct_efi_hard_drive_device_path_validate_internal(FuStructEfiHardDriveDevicePath *st, GError **error) |
4074 | 808 | { |
4075 | 808 | g_return_val_if_fail(st != NULL, FALSE); |
4076 | 808 | if (fu_struct_efi_hard_drive_device_path_get_type(st) != FU_EFI_DEVICE_PATH_TYPE_MEDIA) { |
4077 | 0 | g_set_error(error, |
4078 | 0 | FWUPD_ERROR, |
4079 | 0 | FWUPD_ERROR_INVALID_DATA, |
4080 | 0 | "constant FuStructEfiHardDriveDevicePath.type was not valid, " |
4081 | 0 | "expected 'FU_EFI_DEVICE_PATH_TYPE_MEDIA' and got 0x%x '%s'", |
4082 | 0 | fu_struct_efi_hard_drive_device_path_get_type(st), |
4083 | 0 | fu_efi_device_path_type_to_string(fu_struct_efi_hard_drive_device_path_get_type(st))); |
4084 | 0 | return FALSE; |
4085 | 0 | } |
4086 | 808 | if (fu_struct_efi_hard_drive_device_path_get_length(st) != 42) { |
4087 | 18 | g_set_error(error, |
4088 | 18 | FWUPD_ERROR, |
4089 | 18 | FWUPD_ERROR_INVALID_DATA, |
4090 | 18 | "constant FuStructEfiHardDriveDevicePath.length was not valid, " |
4091 | 18 | "expected 0x%x and got 0x%x", |
4092 | 18 | (guint) 42, |
4093 | 18 | (guint) fu_struct_efi_hard_drive_device_path_get_length(st)); |
4094 | 18 | return FALSE; |
4095 | 18 | } |
4096 | 790 | return TRUE; |
4097 | 808 | } |
4098 | | static gboolean |
4099 | | fu_struct_efi_hard_drive_device_path_parse_internal(FuStructEfiHardDriveDevicePath *st, GError **error) |
4100 | 808 | { |
4101 | 808 | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4102 | 0 | g_autofree gchar *str = fu_struct_efi_hard_drive_device_path_to_string(st); |
4103 | 0 | g_debug("%s", str); |
4104 | 0 | } |
4105 | 808 | if (!fu_struct_efi_hard_drive_device_path_validate_internal(st, error)) |
4106 | 18 | return FALSE; |
4107 | 790 | return TRUE; |
4108 | 808 | } |
4109 | | /** |
4110 | | * fu_struct_efi_hard_drive_device_path_parse_stream: (skip): |
4111 | | **/ |
4112 | | FuStructEfiHardDriveDevicePath * |
4113 | | fu_struct_efi_hard_drive_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4114 | 830 | { |
4115 | 830 | g_autoptr(FuStructEfiHardDriveDevicePath) st = fu_struct_efi_hard_drive_device_path_new_internal(); |
4116 | 830 | st->buf = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error); |
4117 | 830 | if (st->buf == NULL) { |
4118 | 0 | g_prefix_error(error, "FuStructEfiHardDriveDevicePath failed read of 0x%x: ", (guint) 42); |
4119 | 0 | return NULL; |
4120 | 0 | } |
4121 | 830 | if (st->buf->len != 42) { |
4122 | 22 | g_set_error(error, |
4123 | 22 | FWUPD_ERROR, |
4124 | 22 | FWUPD_ERROR_INVALID_DATA, |
4125 | 22 | "FuStructEfiHardDriveDevicePath requested 0x%x and got 0x%x", |
4126 | 22 | (guint) 42, |
4127 | 22 | (guint) st->buf->len); |
4128 | 22 | return NULL; |
4129 | 22 | } |
4130 | 808 | if (!fu_struct_efi_hard_drive_device_path_parse_internal(st, error)) |
4131 | 18 | return NULL; |
4132 | 790 | return g_steal_pointer(&st); |
4133 | 808 | } |
4134 | | /** |
4135 | | * fu_struct_efi_vss2_variable_store_header_ref: (skip): |
4136 | | **/ |
4137 | | FuStructEfiVss2VariableStoreHeader * |
4138 | | fu_struct_efi_vss2_variable_store_header_ref(FuStructEfiVss2VariableStoreHeader *st) |
4139 | 0 | { |
4140 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4141 | 0 | st->refcount++; |
4142 | 0 | return st; |
4143 | 0 | } |
4144 | | /** |
4145 | | * fu_struct_efi_vss2_variable_store_header_unref: (skip): |
4146 | | **/ |
4147 | | void |
4148 | | fu_struct_efi_vss2_variable_store_header_unref(FuStructEfiVss2VariableStoreHeader *st) |
4149 | 93.4k | { |
4150 | 93.4k | g_return_if_fail(st != NULL); |
4151 | 93.4k | if (st->refcount == 0) { |
4152 | 0 | g_critical("FuStructEfiVss2VariableStoreHeader refcount already zero"); |
4153 | 0 | return; |
4154 | 0 | } |
4155 | 93.4k | if (--st->refcount > 0) |
4156 | 0 | return; |
4157 | 93.4k | if (st->buf != NULL) |
4158 | 93.0k | g_byte_array_unref(st->buf); |
4159 | 93.4k | g_free(st); |
4160 | 93.4k | } |
4161 | | /** |
4162 | | * fu_struct_efi_vss2_variable_store_header_new_internal: (skip): |
4163 | | **/ |
4164 | | static FuStructEfiVss2VariableStoreHeader * |
4165 | | fu_struct_efi_vss2_variable_store_header_new_internal(void) |
4166 | 93.4k | { |
4167 | 93.4k | FuStructEfiVss2VariableStoreHeader *st = g_new0(FuStructEfiVss2VariableStoreHeader, 1); |
4168 | 93.4k | st->refcount = 1; |
4169 | 93.4k | return st; |
4170 | 93.4k | } |
4171 | | |
4172 | | /* getters */ |
4173 | | /** |
4174 | | * fu_struct_efi_vss2_variable_store_header_get_signature: (skip): |
4175 | | **/ |
4176 | | static const fwupd_guid_t * |
4177 | | fu_struct_efi_vss2_variable_store_header_get_signature(const FuStructEfiVss2VariableStoreHeader *st) |
4178 | 92.4k | { |
4179 | 92.4k | g_return_val_if_fail(st != NULL, NULL); |
4180 | 92.4k | return (const fwupd_guid_t *) (st->buf->data + 0); |
4181 | 92.4k | } |
4182 | | /** |
4183 | | * fu_struct_efi_vss2_variable_store_header_get_size: (skip): |
4184 | | **/ |
4185 | | guint32 |
4186 | | fu_struct_efi_vss2_variable_store_header_get_size(const FuStructEfiVss2VariableStoreHeader *st) |
4187 | 8.40k | { |
4188 | 8.40k | g_return_val_if_fail(st != NULL, 0x0); |
4189 | 8.40k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
4190 | 8.40k | } |
4191 | | /** |
4192 | | * fu_struct_efi_vss2_variable_store_header_get_format: (skip): |
4193 | | **/ |
4194 | | static FuEfiVariableStoreFormat |
4195 | | fu_struct_efi_vss2_variable_store_header_get_format(const FuStructEfiVss2VariableStoreHeader *st) |
4196 | 8.14k | { |
4197 | 8.14k | g_return_val_if_fail(st != NULL, 0x0); |
4198 | 8.14k | return st->buf->data[20]; |
4199 | 8.14k | } |
4200 | | /** |
4201 | | * fu_struct_efi_vss2_variable_store_header_get_state: (skip): |
4202 | | **/ |
4203 | | static FuEfiVariableStoreState |
4204 | | fu_struct_efi_vss2_variable_store_header_get_state(const FuStructEfiVss2VariableStoreHeader *st) |
4205 | 4.59k | { |
4206 | 4.59k | g_return_val_if_fail(st != NULL, 0x0); |
4207 | 4.59k | return st->buf->data[21]; |
4208 | 4.59k | } |
4209 | | |
4210 | | /* setters */ |
4211 | | /** |
4212 | | * fu_struct_efi_vss2_variable_store_header_set_signature: (skip): |
4213 | | **/ |
4214 | | static void |
4215 | | fu_struct_efi_vss2_variable_store_header_set_signature(FuStructEfiVss2VariableStoreHeader *st, const fwupd_guid_t *value) |
4216 | 466 | { |
4217 | 466 | g_return_if_fail(st != NULL); |
4218 | 466 | g_return_if_fail(value != NULL); |
4219 | 466 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
4220 | 466 | } |
4221 | | /** |
4222 | | * fu_struct_efi_vss2_variable_store_header_set_size: (skip): |
4223 | | **/ |
4224 | | void |
4225 | | fu_struct_efi_vss2_variable_store_header_set_size(FuStructEfiVss2VariableStoreHeader *st, guint32 value) |
4226 | 419 | { |
4227 | 419 | g_return_if_fail(st != NULL); |
4228 | 419 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
4229 | 419 | } |
4230 | | /** |
4231 | | * fu_struct_efi_vss2_variable_store_header_set_format: (skip): |
4232 | | **/ |
4233 | | static void |
4234 | | fu_struct_efi_vss2_variable_store_header_set_format(FuStructEfiVss2VariableStoreHeader *st, FuEfiVariableStoreFormat value) |
4235 | 466 | { |
4236 | 466 | g_return_if_fail(st != NULL); |
4237 | 466 | st->buf->data[20] = value; |
4238 | 466 | } |
4239 | | /** |
4240 | | * fu_struct_efi_vss2_variable_store_header_set_state: (skip): |
4241 | | **/ |
4242 | | static void |
4243 | | fu_struct_efi_vss2_variable_store_header_set_state(FuStructEfiVss2VariableStoreHeader *st, FuEfiVariableStoreState value) |
4244 | 466 | { |
4245 | 466 | g_return_if_fail(st != NULL); |
4246 | 466 | st->buf->data[21] = value; |
4247 | 466 | } |
4248 | | /** |
4249 | | * fu_struct_efi_vss2_variable_store_header_new: (skip): |
4250 | | **/ |
4251 | | FuStructEfiVss2VariableStoreHeader * |
4252 | | fu_struct_efi_vss2_variable_store_header_new(void) |
4253 | 466 | { |
4254 | 466 | FuStructEfiVss2VariableStoreHeader *st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4255 | 466 | st->buf = g_byte_array_sized_new(28); |
4256 | 466 | fu_byte_array_set_size(st->buf, 28, 0x0); |
4257 | 466 | 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"); |
4258 | 466 | fu_struct_efi_vss2_variable_store_header_set_format(st, FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED); |
4259 | 466 | fu_struct_efi_vss2_variable_store_header_set_state(st, FU_EFI_VARIABLE_STORE_STATE_HEALTHY); |
4260 | 466 | return st; |
4261 | 466 | } |
4262 | | /** |
4263 | | * fu_struct_efi_vss2_variable_store_header_to_string: (skip): |
4264 | | **/ |
4265 | | static gchar * |
4266 | | fu_struct_efi_vss2_variable_store_header_to_string(const FuStructEfiVss2VariableStoreHeader *st) |
4267 | 0 | { |
4268 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVss2VariableStoreHeader:\n"); |
4269 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4270 | 0 | { |
4271 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_vss2_variable_store_header_get_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4272 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
4273 | 0 | } |
4274 | 0 | g_string_append_printf(str, " size: 0x%x\n", |
4275 | 0 | (guint) fu_struct_efi_vss2_variable_store_header_get_size(st)); |
4276 | 0 | { |
4277 | 0 | const gchar *tmp = fu_efi_variable_store_format_to_string(fu_struct_efi_vss2_variable_store_header_get_format(st)); |
4278 | 0 | if (tmp != NULL) { |
4279 | 0 | g_string_append_printf(str, " format: 0x%x [%s]\n", (guint) fu_struct_efi_vss2_variable_store_header_get_format(st), tmp); |
4280 | 0 | } else { |
4281 | 0 | g_string_append_printf(str, " format: 0x%x\n", (guint) fu_struct_efi_vss2_variable_store_header_get_format(st)); |
4282 | 0 | } |
4283 | 0 | } |
4284 | 0 | { |
4285 | 0 | const gchar *tmp = fu_efi_variable_store_state_to_string(fu_struct_efi_vss2_variable_store_header_get_state(st)); |
4286 | 0 | if (tmp != NULL) { |
4287 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_vss2_variable_store_header_get_state(st), tmp); |
4288 | 0 | } else { |
4289 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_vss2_variable_store_header_get_state(st)); |
4290 | 0 | } |
4291 | 0 | } |
4292 | 0 | if (str->len > 0) |
4293 | 0 | g_string_set_size(str, str->len - 1); |
4294 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4295 | 0 | } |
4296 | | static gboolean |
4297 | | fu_struct_efi_vss2_variable_store_header_validate_internal(FuStructEfiVss2VariableStoreHeader *st, GError **error) |
4298 | 92.4k | { |
4299 | 92.4k | g_return_val_if_fail(st != NULL, FALSE); |
4300 | 92.4k | 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) { |
4301 | 86.9k | g_set_error_literal(error, |
4302 | 86.9k | FWUPD_ERROR, |
4303 | 86.9k | FWUPD_ERROR_INVALID_DATA, |
4304 | 86.9k | "constant FuStructEfiVss2VariableStoreHeader.signature was not valid"); |
4305 | 86.9k | return FALSE; |
4306 | 86.9k | } |
4307 | 5.50k | if (fu_struct_efi_vss2_variable_store_header_get_format(st) != FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) { |
4308 | 1.32k | g_set_error(error, |
4309 | 1.32k | FWUPD_ERROR, |
4310 | 1.32k | FWUPD_ERROR_INVALID_DATA, |
4311 | 1.32k | "constant FuStructEfiVss2VariableStoreHeader.format was not valid, " |
4312 | 1.32k | "expected 'FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED' and got 0x%x '%s'", |
4313 | 1.32k | fu_struct_efi_vss2_variable_store_header_get_format(st), |
4314 | 1.32k | fu_efi_variable_store_format_to_string(fu_struct_efi_vss2_variable_store_header_get_format(st))); |
4315 | 1.32k | return FALSE; |
4316 | 1.32k | } |
4317 | 4.18k | if (fu_struct_efi_vss2_variable_store_header_get_state(st) != FU_EFI_VARIABLE_STORE_STATE_HEALTHY) { |
4318 | 204 | g_set_error(error, |
4319 | 204 | FWUPD_ERROR, |
4320 | 204 | FWUPD_ERROR_INVALID_DATA, |
4321 | 204 | "constant FuStructEfiVss2VariableStoreHeader.state was not valid, " |
4322 | 204 | "expected 'FU_EFI_VARIABLE_STORE_STATE_HEALTHY' and got 0x%x '%s'", |
4323 | 204 | fu_struct_efi_vss2_variable_store_header_get_state(st), |
4324 | 204 | fu_efi_variable_store_state_to_string(fu_struct_efi_vss2_variable_store_header_get_state(st))); |
4325 | 204 | return FALSE; |
4326 | 204 | } |
4327 | 3.98k | return TRUE; |
4328 | 4.18k | } |
4329 | | /** |
4330 | | * fu_struct_efi_vss2_variable_store_header_validate_stream: (skip): |
4331 | | **/ |
4332 | | gboolean |
4333 | | fu_struct_efi_vss2_variable_store_header_validate_stream(GInputStream *stream, gsize offset, GError **error) |
4334 | 91.3k | { |
4335 | 91.3k | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4336 | 91.3k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
4337 | 91.3k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4338 | 91.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
4339 | 91.3k | if (st->buf == NULL) { |
4340 | 0 | g_prefix_error(error, "FuStructEfiVss2VariableStoreHeader failed read of 0x%x: ", (guint) 28); |
4341 | 0 | return FALSE; |
4342 | 0 | } |
4343 | 91.3k | if (st->buf->len != 28) { |
4344 | 543 | g_set_error(error, |
4345 | 543 | FWUPD_ERROR, |
4346 | 543 | FWUPD_ERROR_INVALID_DATA, |
4347 | 543 | "FuStructEfiVss2VariableStoreHeader requested 0x%x and got 0x%x", |
4348 | 543 | (guint) 28, |
4349 | 543 | (guint) st->buf->len); |
4350 | 543 | return FALSE; |
4351 | 543 | } |
4352 | 90.8k | return fu_struct_efi_vss2_variable_store_header_validate_internal(st, error); |
4353 | 91.3k | } |
4354 | | static gboolean |
4355 | | fu_struct_efi_vss2_variable_store_header_parse_internal(FuStructEfiVss2VariableStoreHeader *st, GError **error) |
4356 | 1.61k | { |
4357 | 1.61k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4358 | 0 | g_autofree gchar *str = fu_struct_efi_vss2_variable_store_header_to_string(st); |
4359 | 0 | g_debug("%s", str); |
4360 | 0 | } |
4361 | 1.61k | if (!fu_struct_efi_vss2_variable_store_header_validate_internal(st, error)) |
4362 | 0 | return FALSE; |
4363 | 1.61k | return TRUE; |
4364 | 1.61k | } |
4365 | | /** |
4366 | | * fu_struct_efi_vss2_variable_store_header_parse_stream: (skip): |
4367 | | **/ |
4368 | | FuStructEfiVss2VariableStoreHeader * |
4369 | | fu_struct_efi_vss2_variable_store_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4370 | 1.61k | { |
4371 | 1.61k | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4372 | 1.61k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
4373 | 1.61k | if (st->buf == NULL) { |
4374 | 0 | g_prefix_error(error, "FuStructEfiVss2VariableStoreHeader failed read of 0x%x: ", (guint) 28); |
4375 | 0 | return NULL; |
4376 | 0 | } |
4377 | 1.61k | if (st->buf->len != 28) { |
4378 | 0 | g_set_error(error, |
4379 | 0 | FWUPD_ERROR, |
4380 | 0 | FWUPD_ERROR_INVALID_DATA, |
4381 | 0 | "FuStructEfiVss2VariableStoreHeader requested 0x%x and got 0x%x", |
4382 | 0 | (guint) 28, |
4383 | 0 | (guint) st->buf->len); |
4384 | 0 | return NULL; |
4385 | 0 | } |
4386 | 1.61k | if (!fu_struct_efi_vss2_variable_store_header_parse_internal(st, error)) |
4387 | 0 | return NULL; |
4388 | 1.61k | return g_steal_pointer(&st); |
4389 | 1.61k | } |
4390 | | /** |
4391 | | * fu_struct_efi_vss_auth_variable_header_ref: (skip): |
4392 | | **/ |
4393 | | FuStructEfiVssAuthVariableHeader * |
4394 | | fu_struct_efi_vss_auth_variable_header_ref(FuStructEfiVssAuthVariableHeader *st) |
4395 | 0 | { |
4396 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4397 | 0 | st->refcount++; |
4398 | 0 | return st; |
4399 | 0 | } |
4400 | | /** |
4401 | | * fu_struct_efi_vss_auth_variable_header_unref: (skip): |
4402 | | **/ |
4403 | | void |
4404 | | fu_struct_efi_vss_auth_variable_header_unref(FuStructEfiVssAuthVariableHeader *st) |
4405 | 6.11k | { |
4406 | 6.11k | g_return_if_fail(st != NULL); |
4407 | 6.11k | if (st->refcount == 0) { |
4408 | 0 | g_critical("FuStructEfiVssAuthVariableHeader refcount already zero"); |
4409 | 0 | return; |
4410 | 0 | } |
4411 | 6.11k | if (--st->refcount > 0) |
4412 | 0 | return; |
4413 | 6.11k | if (st->buf != NULL) |
4414 | 5.59k | g_byte_array_unref(st->buf); |
4415 | 6.11k | g_free(st); |
4416 | 6.11k | } |
4417 | | /** |
4418 | | * fu_struct_efi_vss_auth_variable_header_new_internal: (skip): |
4419 | | **/ |
4420 | | static FuStructEfiVssAuthVariableHeader * |
4421 | | fu_struct_efi_vss_auth_variable_header_new_internal(void) |
4422 | 6.11k | { |
4423 | 6.11k | FuStructEfiVssAuthVariableHeader *st = g_new0(FuStructEfiVssAuthVariableHeader, 1); |
4424 | 6.11k | st->refcount = 1; |
4425 | 6.11k | return st; |
4426 | 6.11k | } |
4427 | | |
4428 | | /* getters */ |
4429 | | /** |
4430 | | * fu_struct_efi_vss_auth_variable_header_get_start_id: (skip): |
4431 | | **/ |
4432 | | guint16 |
4433 | | fu_struct_efi_vss_auth_variable_header_get_start_id(const FuStructEfiVssAuthVariableHeader *st) |
4434 | 11.0k | { |
4435 | 11.0k | g_return_val_if_fail(st != NULL, 0x0); |
4436 | 11.0k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
4437 | 11.0k | } |
4438 | | /** |
4439 | | * fu_struct_efi_vss_auth_variable_header_get_state: (skip): |
4440 | | **/ |
4441 | | FuEfiVariableState |
4442 | | fu_struct_efi_vss_auth_variable_header_get_state(const FuStructEfiVssAuthVariableHeader *st) |
4443 | 5.04k | { |
4444 | 5.04k | g_return_val_if_fail(st != NULL, 0x0); |
4445 | 5.04k | return st->buf->data[2]; |
4446 | 5.04k | } |
4447 | | /** |
4448 | | * fu_struct_efi_vss_auth_variable_header_get_attributes: (skip): |
4449 | | **/ |
4450 | | FuEfiVariableAttrs |
4451 | | fu_struct_efi_vss_auth_variable_header_get_attributes(const FuStructEfiVssAuthVariableHeader *st) |
4452 | 5.04k | { |
4453 | 5.04k | g_return_val_if_fail(st != NULL, 0x0); |
4454 | 5.04k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
4455 | 5.04k | } |
4456 | | /** |
4457 | | * fu_struct_efi_vss_auth_variable_header_get_monotonic_counter: (skip): |
4458 | | **/ |
4459 | | guint64 |
4460 | | fu_struct_efi_vss_auth_variable_header_get_monotonic_counter(const FuStructEfiVssAuthVariableHeader *st) |
4461 | 0 | { |
4462 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4463 | 0 | return fu_memread_uint64(st->buf->data + 8, G_LITTLE_ENDIAN); |
4464 | 0 | } |
4465 | | /** |
4466 | | * fu_struct_efi_vss_auth_variable_header_get_timestamp: (skip): |
4467 | | **/ |
4468 | | FuStructEfiTime * |
4469 | | fu_struct_efi_vss_auth_variable_header_get_timestamp(const FuStructEfiVssAuthVariableHeader *st) |
4470 | 5.04k | { |
4471 | 5.04k | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_time_new_internal(); |
4472 | 5.04k | g_return_val_if_fail(st != NULL, NULL); |
4473 | 5.04k | st_tmp->buf = g_byte_array_new(); |
4474 | 5.04k | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, 16); |
4475 | 5.04k | return g_steal_pointer(&st_tmp); |
4476 | 5.04k | } |
4477 | | /** |
4478 | | * fu_struct_efi_vss_auth_variable_header_get_pubkey_index: (skip): |
4479 | | **/ |
4480 | | guint32 |
4481 | | fu_struct_efi_vss_auth_variable_header_get_pubkey_index(const FuStructEfiVssAuthVariableHeader *st) |
4482 | 0 | { |
4483 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4484 | 0 | return fu_memread_uint32(st->buf->data + 32, G_LITTLE_ENDIAN); |
4485 | 0 | } |
4486 | | /** |
4487 | | * fu_struct_efi_vss_auth_variable_header_get_name_size: (skip): |
4488 | | **/ |
4489 | | guint32 |
4490 | | fu_struct_efi_vss_auth_variable_header_get_name_size(const FuStructEfiVssAuthVariableHeader *st) |
4491 | 9.95k | { |
4492 | 9.95k | g_return_val_if_fail(st != NULL, 0x0); |
4493 | 9.95k | return fu_memread_uint32(st->buf->data + 36, G_LITTLE_ENDIAN); |
4494 | 9.95k | } |
4495 | | /** |
4496 | | * fu_struct_efi_vss_auth_variable_header_get_data_size: (skip): |
4497 | | **/ |
4498 | | guint32 |
4499 | | fu_struct_efi_vss_auth_variable_header_get_data_size(const FuStructEfiVssAuthVariableHeader *st) |
4500 | 9.48k | { |
4501 | 9.48k | g_return_val_if_fail(st != NULL, 0x0); |
4502 | 9.48k | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
4503 | 9.48k | } |
4504 | | /** |
4505 | | * fu_struct_efi_vss_auth_variable_header_get_vendor_guid: (skip): |
4506 | | **/ |
4507 | | const fwupd_guid_t * |
4508 | | fu_struct_efi_vss_auth_variable_header_get_vendor_guid(const FuStructEfiVssAuthVariableHeader *st) |
4509 | 5.04k | { |
4510 | 5.04k | g_return_val_if_fail(st != NULL, NULL); |
4511 | 5.04k | return (const fwupd_guid_t *) (st->buf->data + 44); |
4512 | 5.04k | } |
4513 | | |
4514 | | /* setters */ |
4515 | | /** |
4516 | | * fu_struct_efi_vss_auth_variable_header_set_start_id: (skip): |
4517 | | **/ |
4518 | | void |
4519 | | fu_struct_efi_vss_auth_variable_header_set_start_id(FuStructEfiVssAuthVariableHeader *st, guint16 value) |
4520 | 525 | { |
4521 | 525 | g_return_if_fail(st != NULL); |
4522 | 525 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
4523 | 525 | } |
4524 | | /** |
4525 | | * fu_struct_efi_vss_auth_variable_header_set_state: (skip): |
4526 | | **/ |
4527 | | void |
4528 | | fu_struct_efi_vss_auth_variable_header_set_state(FuStructEfiVssAuthVariableHeader *st, FuEfiVariableState value) |
4529 | 525 | { |
4530 | 525 | g_return_if_fail(st != NULL); |
4531 | 525 | st->buf->data[2] = value; |
4532 | 525 | } |
4533 | | /** |
4534 | | * fu_struct_efi_vss_auth_variable_header_set_attributes: (skip): |
4535 | | **/ |
4536 | | void |
4537 | | fu_struct_efi_vss_auth_variable_header_set_attributes(FuStructEfiVssAuthVariableHeader *st, FuEfiVariableAttrs value) |
4538 | 525 | { |
4539 | 525 | g_return_if_fail(st != NULL); |
4540 | 525 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
4541 | 525 | } |
4542 | | /** |
4543 | | * fu_struct_efi_vss_auth_variable_header_set_monotonic_counter: (skip): |
4544 | | **/ |
4545 | | void |
4546 | | fu_struct_efi_vss_auth_variable_header_set_monotonic_counter(FuStructEfiVssAuthVariableHeader *st, guint64 value) |
4547 | 0 | { |
4548 | 0 | g_return_if_fail(st != NULL); |
4549 | 0 | fu_memwrite_uint64(st->buf->data + 8, value, G_LITTLE_ENDIAN); |
4550 | 0 | } |
4551 | | /** |
4552 | | * fu_struct_efi_vss_auth_variable_header_set_timestamp: (skip): |
4553 | | **/ |
4554 | | gboolean |
4555 | | fu_struct_efi_vss_auth_variable_header_set_timestamp(FuStructEfiVssAuthVariableHeader *st, const FuStructEfiTime *st_donor, GError **error) |
4556 | 525 | { |
4557 | 525 | g_return_val_if_fail(st != NULL, FALSE); |
4558 | 525 | g_return_val_if_fail(st_donor != NULL, FALSE); |
4559 | 525 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4560 | | |
4561 | 525 | if (st_donor->buf->len > FU_STRUCT_EFI_TIME_SIZE) { |
4562 | 0 | g_set_error(error, |
4563 | 0 | FWUPD_ERROR, |
4564 | 0 | FWUPD_ERROR_INVALID_DATA, |
4565 | 0 | "donor 'FuStructEfiTime' (0x%x bytes) does not fit in " |
4566 | 0 | "FuStructEfiVssAuthVariableHeader.timestamp (0x%x bytes)", |
4567 | 0 | (guint) st_donor->buf->len, |
4568 | 0 | (guint) FU_STRUCT_EFI_TIME_SIZE); |
4569 | 0 | return FALSE; |
4570 | 0 | } |
4571 | 525 | memcpy(st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, st_donor->buf->data, st_donor->buf->len); |
4572 | 525 | return TRUE; |
4573 | 525 | } |
4574 | | /** |
4575 | | * fu_struct_efi_vss_auth_variable_header_set_pubkey_index: (skip): |
4576 | | **/ |
4577 | | void |
4578 | | fu_struct_efi_vss_auth_variable_header_set_pubkey_index(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4579 | 0 | { |
4580 | 0 | g_return_if_fail(st != NULL); |
4581 | 0 | fu_memwrite_uint32(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
4582 | 0 | } |
4583 | | /** |
4584 | | * fu_struct_efi_vss_auth_variable_header_set_name_size: (skip): |
4585 | | **/ |
4586 | | void |
4587 | | fu_struct_efi_vss_auth_variable_header_set_name_size(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4588 | 525 | { |
4589 | 525 | g_return_if_fail(st != NULL); |
4590 | 525 | fu_memwrite_uint32(st->buf->data + 36, value, G_LITTLE_ENDIAN); |
4591 | 525 | } |
4592 | | /** |
4593 | | * fu_struct_efi_vss_auth_variable_header_set_data_size: (skip): |
4594 | | **/ |
4595 | | void |
4596 | | fu_struct_efi_vss_auth_variable_header_set_data_size(FuStructEfiVssAuthVariableHeader *st, guint32 value) |
4597 | 525 | { |
4598 | 525 | g_return_if_fail(st != NULL); |
4599 | 525 | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
4600 | 525 | } |
4601 | | /** |
4602 | | * fu_struct_efi_vss_auth_variable_header_set_vendor_guid: (skip): |
4603 | | **/ |
4604 | | void |
4605 | | fu_struct_efi_vss_auth_variable_header_set_vendor_guid(FuStructEfiVssAuthVariableHeader *st, const fwupd_guid_t *value) |
4606 | 525 | { |
4607 | 525 | g_return_if_fail(st != NULL); |
4608 | 525 | g_return_if_fail(value != NULL); |
4609 | 525 | memcpy(st->buf->data + 44, value, sizeof(*value)); /* nocheck:blocked */ |
4610 | 525 | } |
4611 | | /** |
4612 | | * fu_struct_efi_vss_auth_variable_header_new: (skip): |
4613 | | **/ |
4614 | | FuStructEfiVssAuthVariableHeader * |
4615 | | fu_struct_efi_vss_auth_variable_header_new(void) |
4616 | 525 | { |
4617 | 525 | FuStructEfiVssAuthVariableHeader *st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4618 | 525 | st->buf = g_byte_array_sized_new(60); |
4619 | 525 | fu_byte_array_set_size(st->buf, 60, 0x0); |
4620 | 525 | { |
4621 | 525 | g_autoptr(FuStructEfiTime) st_donor = fu_struct_efi_time_new(); |
4622 | 525 | memcpy(st->buf->data + 0x10, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
4623 | 525 | } |
4624 | 525 | fu_struct_efi_vss_auth_variable_header_set_start_id(st, 0x55AA); |
4625 | 525 | return st; |
4626 | 525 | } |
4627 | | /** |
4628 | | * fu_struct_efi_vss_auth_variable_header_to_string: (skip): |
4629 | | **/ |
4630 | | static gchar * |
4631 | | fu_struct_efi_vss_auth_variable_header_to_string(const FuStructEfiVssAuthVariableHeader *st) |
4632 | 0 | { |
4633 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiVssAuthVariableHeader:\n"); |
4634 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4635 | 0 | g_string_append_printf(str, " start_id: 0x%x\n", |
4636 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_start_id(st)); |
4637 | 0 | { |
4638 | 0 | const gchar *tmp = fu_efi_variable_state_to_string(fu_struct_efi_vss_auth_variable_header_get_state(st)); |
4639 | 0 | if (tmp != NULL) { |
4640 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_vss_auth_variable_header_get_state(st), tmp); |
4641 | 0 | } else { |
4642 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_vss_auth_variable_header_get_state(st)); |
4643 | 0 | } |
4644 | 0 | } |
4645 | 0 | { |
4646 | 0 | g_autofree gchar *tmp = fu_efi_variable_attrs_to_string(fu_struct_efi_vss_auth_variable_header_get_attributes(st)); |
4647 | 0 | if (tmp != NULL) { |
4648 | 0 | g_string_append_printf(str, " attributes: 0x%x [%s]\n", (guint) fu_struct_efi_vss_auth_variable_header_get_attributes(st), tmp); |
4649 | 0 | } else { |
4650 | 0 | g_string_append_printf(str, " attributes: 0x%x\n", (guint) fu_struct_efi_vss_auth_variable_header_get_attributes(st)); |
4651 | 0 | } |
4652 | 0 | } |
4653 | 0 | g_string_append_printf(str, " monotonic_counter: 0x%x\n", |
4654 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_monotonic_counter(st)); |
4655 | 0 | { |
4656 | 0 | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_vss_auth_variable_header_get_timestamp(st); |
4657 | 0 | g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp); |
4658 | 0 | g_string_append_printf(str, " timestamp: %s\n", tmp); |
4659 | 0 | } |
4660 | 0 | g_string_append_printf(str, " pubkey_index: 0x%x\n", |
4661 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_pubkey_index(st)); |
4662 | 0 | g_string_append_printf(str, " name_size: 0x%x\n", |
4663 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_name_size(st)); |
4664 | 0 | g_string_append_printf(str, " data_size: 0x%x\n", |
4665 | 0 | (guint) fu_struct_efi_vss_auth_variable_header_get_data_size(st)); |
4666 | 0 | { |
4667 | 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); |
4668 | 0 | g_string_append_printf(str, " vendor_guid: %s\n", tmp); |
4669 | 0 | } |
4670 | 0 | if (str->len > 0) |
4671 | 0 | g_string_set_size(str, str->len - 1); |
4672 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4673 | 0 | } |
4674 | | static gboolean |
4675 | | fu_struct_efi_vss_auth_variable_header_validate_internal(FuStructEfiVssAuthVariableHeader *st, GError **error) |
4676 | 5.50k | { |
4677 | 5.50k | g_return_val_if_fail(st != NULL, FALSE); |
4678 | 5.50k | { |
4679 | 5.50k | GByteArray buf_tmp = { |
4680 | 5.50k | .data = (guint8*) st->buf->data + 0x10, |
4681 | 5.50k | .len = 16, |
4682 | 5.50k | }; |
4683 | 5.50k | FuStructEfiTime st_tmp = { .buf = &buf_tmp }; |
4684 | 5.50k | if (!fu_struct_efi_time_validate_internal(&st_tmp, error)) |
4685 | 0 | return FALSE; |
4686 | 5.50k | } |
4687 | 5.50k | return TRUE; |
4688 | 5.50k | } |
4689 | | static gboolean |
4690 | | fu_struct_efi_vss_auth_variable_header_parse_internal(FuStructEfiVssAuthVariableHeader *st, GError **error) |
4691 | 5.50k | { |
4692 | 5.50k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4693 | 0 | g_autofree gchar *str = fu_struct_efi_vss_auth_variable_header_to_string(st); |
4694 | 0 | g_debug("%s", str); |
4695 | 0 | } |
4696 | 5.50k | if (!fu_struct_efi_vss_auth_variable_header_validate_internal(st, error)) |
4697 | 0 | return FALSE; |
4698 | 5.50k | return TRUE; |
4699 | 5.50k | } |
4700 | | /** |
4701 | | * fu_struct_efi_vss_auth_variable_header_parse_stream: (skip): |
4702 | | **/ |
4703 | | FuStructEfiVssAuthVariableHeader * |
4704 | | fu_struct_efi_vss_auth_variable_header_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4705 | 5.59k | { |
4706 | 5.59k | g_autoptr(FuStructEfiVssAuthVariableHeader) st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4707 | 5.59k | st->buf = fu_input_stream_read_byte_array(stream, offset, 60, NULL, error); |
4708 | 5.59k | if (st->buf == NULL) { |
4709 | 0 | g_prefix_error(error, "FuStructEfiVssAuthVariableHeader failed read of 0x%x: ", (guint) 60); |
4710 | 0 | return NULL; |
4711 | 0 | } |
4712 | 5.59k | if (st->buf->len != 60) { |
4713 | 93 | g_set_error(error, |
4714 | 93 | FWUPD_ERROR, |
4715 | 93 | FWUPD_ERROR_INVALID_DATA, |
4716 | 93 | "FuStructEfiVssAuthVariableHeader requested 0x%x and got 0x%x", |
4717 | 93 | (guint) 60, |
4718 | 93 | (guint) st->buf->len); |
4719 | 93 | return NULL; |
4720 | 93 | } |
4721 | 5.50k | if (!fu_struct_efi_vss_auth_variable_header_parse_internal(st, error)) |
4722 | 0 | return NULL; |
4723 | 5.50k | return g_steal_pointer(&st); |
4724 | 5.50k | } |
4725 | | /** |
4726 | | * fu_struct_efi_fault_tolerant_working_block_header64_ref: (skip): |
4727 | | **/ |
4728 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4729 | | fu_struct_efi_fault_tolerant_working_block_header64_ref(FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4730 | 0 | { |
4731 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4732 | 0 | st->refcount++; |
4733 | 0 | return st; |
4734 | 0 | } |
4735 | | /** |
4736 | | * fu_struct_efi_fault_tolerant_working_block_header64_unref: (skip): |
4737 | | **/ |
4738 | | void |
4739 | | fu_struct_efi_fault_tolerant_working_block_header64_unref(FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4740 | 97.8k | { |
4741 | 97.8k | g_return_if_fail(st != NULL); |
4742 | 97.8k | if (st->refcount == 0) { |
4743 | 0 | g_critical("FuStructEfiFaultTolerantWorkingBlockHeader64 refcount already zero"); |
4744 | 0 | return; |
4745 | 0 | } |
4746 | 97.8k | if (--st->refcount > 0) |
4747 | 0 | return; |
4748 | 97.8k | if (st->buf != NULL) |
4749 | 94.9k | g_byte_array_unref(st->buf); |
4750 | 97.8k | g_free(st); |
4751 | 97.8k | } |
4752 | | /** |
4753 | | * fu_struct_efi_fault_tolerant_working_block_header64_new_internal: (skip): |
4754 | | **/ |
4755 | | static FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4756 | | fu_struct_efi_fault_tolerant_working_block_header64_new_internal(void) |
4757 | 97.8k | { |
4758 | 97.8k | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = g_new0(FuStructEfiFaultTolerantWorkingBlockHeader64, 1); |
4759 | 97.8k | st->refcount = 1; |
4760 | 97.8k | return st; |
4761 | 97.8k | } |
4762 | | |
4763 | | /* getters */ |
4764 | | /** |
4765 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_signature: (skip): |
4766 | | **/ |
4767 | | static const fwupd_guid_t * |
4768 | | fu_struct_efi_fault_tolerant_working_block_header64_get_signature(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4769 | 94.2k | { |
4770 | 94.2k | g_return_val_if_fail(st != NULL, NULL); |
4771 | 94.2k | return (const fwupd_guid_t *) (st->buf->data + 0); |
4772 | 94.2k | } |
4773 | | /** |
4774 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_crc: (skip): |
4775 | | **/ |
4776 | | guint32 |
4777 | | fu_struct_efi_fault_tolerant_working_block_header64_get_crc(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4778 | 0 | { |
4779 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
4780 | 0 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
4781 | 0 | } |
4782 | | /** |
4783 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_state: (skip): |
4784 | | **/ |
4785 | | FuEfiVariableStoreState |
4786 | | fu_struct_efi_fault_tolerant_working_block_header64_get_state(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4787 | 3.23k | { |
4788 | 3.23k | g_return_val_if_fail(st != NULL, 0x0); |
4789 | 3.23k | return st->buf->data[20]; |
4790 | 3.23k | } |
4791 | | /** |
4792 | | * fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size: (skip): |
4793 | | **/ |
4794 | | guint64 |
4795 | | fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4796 | 8.52k | { |
4797 | 8.52k | g_return_val_if_fail(st != NULL, 0x0); |
4798 | 8.52k | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
4799 | 8.52k | } |
4800 | | |
4801 | | /* setters */ |
4802 | | /** |
4803 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_signature: (skip): |
4804 | | **/ |
4805 | | static void |
4806 | | fu_struct_efi_fault_tolerant_working_block_header64_set_signature(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, const fwupd_guid_t *value) |
4807 | 2.85k | { |
4808 | 2.85k | g_return_if_fail(st != NULL); |
4809 | 2.85k | g_return_if_fail(value != NULL); |
4810 | 2.85k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
4811 | 2.85k | } |
4812 | | /** |
4813 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_crc: (skip): |
4814 | | **/ |
4815 | | void |
4816 | | fu_struct_efi_fault_tolerant_working_block_header64_set_crc(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, guint32 value) |
4817 | 5.71k | { |
4818 | 5.71k | g_return_if_fail(st != NULL); |
4819 | 5.71k | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
4820 | 5.71k | } |
4821 | | /** |
4822 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_state: (skip): |
4823 | | **/ |
4824 | | void |
4825 | | fu_struct_efi_fault_tolerant_working_block_header64_set_state(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, FuEfiVariableStoreState value) |
4826 | 5.71k | { |
4827 | 5.71k | g_return_if_fail(st != NULL); |
4828 | 5.71k | st->buf->data[20] = value; |
4829 | 5.71k | } |
4830 | | /** |
4831 | | * fu_struct_efi_fault_tolerant_working_block_header64_set_write_queue_size: (skip): |
4832 | | **/ |
4833 | | void |
4834 | | fu_struct_efi_fault_tolerant_working_block_header64_set_write_queue_size(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, guint64 value) |
4835 | 2.85k | { |
4836 | 2.85k | g_return_if_fail(st != NULL); |
4837 | 2.85k | fu_memwrite_uint64(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
4838 | 2.85k | } |
4839 | | /** |
4840 | | * fu_struct_efi_fault_tolerant_working_block_header64_new: (skip): |
4841 | | **/ |
4842 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4843 | | fu_struct_efi_fault_tolerant_working_block_header64_new(void) |
4844 | 2.85k | { |
4845 | 2.85k | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4846 | 2.85k | st->buf = g_byte_array_sized_new(32); |
4847 | 2.85k | fu_byte_array_set_size(st->buf, 32, 0x0); |
4848 | 2.85k | 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"); |
4849 | 2.85k | fu_struct_efi_fault_tolerant_working_block_header64_set_crc(st, 0xFFFFFFFF); |
4850 | 2.85k | fu_struct_efi_fault_tolerant_working_block_header64_set_state(st, FU_EFI_VARIABLE_STORE_STATE_EMPTY); |
4851 | 2.85k | memcpy(st->buf->data + 0x15, "\xFF\xFF\xFF", 3); /* nocheck:blocked */ |
4852 | 2.85k | return st; |
4853 | 2.85k | } |
4854 | | /** |
4855 | | * fu_struct_efi_fault_tolerant_working_block_header64_to_string: (skip): |
4856 | | **/ |
4857 | | static gchar * |
4858 | | fu_struct_efi_fault_tolerant_working_block_header64_to_string(const FuStructEfiFaultTolerantWorkingBlockHeader64 *st) |
4859 | 0 | { |
4860 | 0 | g_autoptr(GString) str = g_string_new("FuStructEfiFaultTolerantWorkingBlockHeader64:\n"); |
4861 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4862 | 0 | { |
4863 | 0 | g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_fault_tolerant_working_block_header64_get_signature(st), FWUPD_GUID_FLAG_MIXED_ENDIAN); |
4864 | 0 | g_string_append_printf(str, " signature: %s\n", tmp); |
4865 | 0 | } |
4866 | 0 | g_string_append_printf(str, " crc: 0x%x\n", |
4867 | 0 | (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_crc(st)); |
4868 | 0 | { |
4869 | 0 | const gchar *tmp = fu_efi_variable_store_state_to_string(fu_struct_efi_fault_tolerant_working_block_header64_get_state(st)); |
4870 | 0 | if (tmp != NULL) { |
4871 | 0 | g_string_append_printf(str, " state: 0x%x [%s]\n", (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_state(st), tmp); |
4872 | 0 | } else { |
4873 | 0 | g_string_append_printf(str, " state: 0x%x\n", (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_state(st)); |
4874 | 0 | } |
4875 | 0 | } |
4876 | 0 | g_string_append_printf(str, " write_queue_size: 0x%x\n", |
4877 | 0 | (guint) fu_struct_efi_fault_tolerant_working_block_header64_get_write_queue_size(st)); |
4878 | 0 | if (str->len > 0) |
4879 | 0 | g_string_set_size(str, str->len - 1); |
4880 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
4881 | 0 | } |
4882 | | static gboolean |
4883 | | fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, GError **error) |
4884 | 94.2k | { |
4885 | 94.2k | g_return_val_if_fail(st != NULL, FALSE); |
4886 | 94.2k | if (memcmp(fu_struct_efi_fault_tolerant_working_block_header64_get_signature(st), "\x2b\x29\x58\x9e\x68\x7c\x7d\x49\xa0\xce\x65\x0\xfd\x9f\x1b\x95", 16) != 0) { |
4887 | 77.9k | g_set_error_literal(error, |
4888 | 77.9k | FWUPD_ERROR, |
4889 | 77.9k | FWUPD_ERROR_INVALID_DATA, |
4890 | 77.9k | "constant FuStructEfiFaultTolerantWorkingBlockHeader64.signature was not valid"); |
4891 | 77.9k | return FALSE; |
4892 | 77.9k | } |
4893 | 16.3k | return TRUE; |
4894 | 94.2k | } |
4895 | | /** |
4896 | | * fu_struct_efi_fault_tolerant_working_block_header64_validate_stream: (skip): |
4897 | | **/ |
4898 | | gboolean |
4899 | | fu_struct_efi_fault_tolerant_working_block_header64_validate_stream(GInputStream *stream, gsize offset, GError **error) |
4900 | 90.7k | { |
4901 | 90.7k | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4902 | 90.7k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
4903 | 90.7k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4904 | 90.7k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4905 | 90.7k | if (st->buf == NULL) { |
4906 | 0 | g_prefix_error(error, "FuStructEfiFaultTolerantWorkingBlockHeader64 failed read of 0x%x: ", (guint) 32); |
4907 | 0 | return FALSE; |
4908 | 0 | } |
4909 | 90.7k | if (st->buf->len != 32) { |
4910 | 692 | g_set_error(error, |
4911 | 692 | FWUPD_ERROR, |
4912 | 692 | FWUPD_ERROR_INVALID_DATA, |
4913 | 692 | "FuStructEfiFaultTolerantWorkingBlockHeader64 requested 0x%x and got 0x%x", |
4914 | 692 | (guint) 32, |
4915 | 692 | (guint) st->buf->len); |
4916 | 692 | return FALSE; |
4917 | 692 | } |
4918 | 90.0k | return fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error); |
4919 | 90.7k | } |
4920 | | static gboolean |
4921 | | fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, GError **error) |
4922 | 4.26k | { |
4923 | 4.26k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
4924 | 0 | g_autofree gchar *str = fu_struct_efi_fault_tolerant_working_block_header64_to_string(st); |
4925 | 0 | g_debug("%s", str); |
4926 | 0 | } |
4927 | 4.26k | if (!fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error)) |
4928 | 0 | return FALSE; |
4929 | 4.26k | return TRUE; |
4930 | 4.26k | } |
4931 | | /** |
4932 | | * fu_struct_efi_fault_tolerant_working_block_header64_parse_stream: (skip): |
4933 | | **/ |
4934 | | FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4935 | | fu_struct_efi_fault_tolerant_working_block_header64_parse_stream(GInputStream *stream, gsize offset, GError **error) |
4936 | 4.26k | { |
4937 | 4.26k | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4938 | 4.26k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4939 | 4.26k | if (st->buf == NULL) { |
4940 | 0 | g_prefix_error(error, "FuStructEfiFaultTolerantWorkingBlockHeader64 failed read of 0x%x: ", (guint) 32); |
4941 | 0 | return NULL; |
4942 | 0 | } |
4943 | 4.26k | if (st->buf->len != 32) { |
4944 | 0 | g_set_error(error, |
4945 | 0 | FWUPD_ERROR, |
4946 | 0 | FWUPD_ERROR_INVALID_DATA, |
4947 | 0 | "FuStructEfiFaultTolerantWorkingBlockHeader64 requested 0x%x and got 0x%x", |
4948 | 0 | (guint) 32, |
4949 | 0 | (guint) st->buf->len); |
4950 | 0 | return NULL; |
4951 | 0 | } |
4952 | 4.26k | if (!fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(st, error)) |
4953 | 0 | return NULL; |
4954 | 4.26k | return g_steal_pointer(&st); |
4955 | 4.26k | } |
4956 | | /** |
4957 | | * fu_struct_shim_hive_ref: (skip): |
4958 | | **/ |
4959 | | FuStructShimHive * |
4960 | | fu_struct_shim_hive_ref(FuStructShimHive *st) |
4961 | 0 | { |
4962 | 0 | g_return_val_if_fail(st != NULL, NULL); |
4963 | 0 | st->refcount++; |
4964 | 0 | return st; |
4965 | 0 | } |
4966 | | /** |
4967 | | * fu_struct_shim_hive_unref: (skip): |
4968 | | **/ |
4969 | | void |
4970 | | fu_struct_shim_hive_unref(FuStructShimHive *st) |
4971 | 1.66k | { |
4972 | 1.66k | g_return_if_fail(st != NULL); |
4973 | 1.66k | if (st->refcount == 0) { |
4974 | 0 | g_critical("FuStructShimHive refcount already zero"); |
4975 | 0 | return; |
4976 | 0 | } |
4977 | 1.66k | if (--st->refcount > 0) |
4978 | 0 | return; |
4979 | 1.66k | if (st->buf != NULL) |
4980 | 1.30k | g_byte_array_unref(st->buf); |
4981 | 1.66k | g_free(st); |
4982 | 1.66k | } |
4983 | | /** |
4984 | | * fu_struct_shim_hive_new_internal: (skip): |
4985 | | **/ |
4986 | | static FuStructShimHive * |
4987 | | fu_struct_shim_hive_new_internal(void) |
4988 | 1.66k | { |
4989 | 1.66k | FuStructShimHive *st = g_new0(FuStructShimHive, 1); |
4990 | 1.66k | st->refcount = 1; |
4991 | 1.66k | return st; |
4992 | 1.66k | } |
4993 | | |
4994 | | /* getters */ |
4995 | | /** |
4996 | | * fu_struct_shim_hive_get_magic: (skip): |
4997 | | **/ |
4998 | | static gchar * |
4999 | | fu_struct_shim_hive_get_magic(const FuStructShimHive *st) |
5000 | 397 | { |
5001 | 397 | g_return_val_if_fail(st != NULL, NULL); |
5002 | 397 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
5003 | 397 | } |
5004 | | /** |
5005 | | * fu_struct_shim_hive_get_header_version: (skip): |
5006 | | **/ |
5007 | | guint8 |
5008 | | fu_struct_shim_hive_get_header_version(const FuStructShimHive *st) |
5009 | 833 | { |
5010 | 833 | g_return_val_if_fail(st != NULL, 0x0); |
5011 | 833 | return st->buf->data[4]; |
5012 | 833 | } |
5013 | | /** |
5014 | | * fu_struct_shim_hive_get_items_count: (skip): |
5015 | | **/ |
5016 | | guint8 |
5017 | | fu_struct_shim_hive_get_items_count(const FuStructShimHive *st) |
5018 | 829 | { |
5019 | 829 | g_return_val_if_fail(st != NULL, 0x0); |
5020 | 829 | return st->buf->data[5]; |
5021 | 829 | } |
5022 | | /** |
5023 | | * fu_struct_shim_hive_get_items_offset: (skip): |
5024 | | **/ |
5025 | | guint8 |
5026 | | fu_struct_shim_hive_get_items_offset(const FuStructShimHive *st) |
5027 | 829 | { |
5028 | 829 | g_return_val_if_fail(st != NULL, 0x0); |
5029 | 829 | return st->buf->data[6]; |
5030 | 829 | } |
5031 | | /** |
5032 | | * fu_struct_shim_hive_get_crc32: (skip): |
5033 | | **/ |
5034 | | guint32 |
5035 | | fu_struct_shim_hive_get_crc32(const FuStructShimHive *st) |
5036 | 0 | { |
5037 | 0 | g_return_val_if_fail(st != NULL, 0x0); |
5038 | 0 | return fu_memread_uint32(st->buf->data + 7, G_LITTLE_ENDIAN); |
5039 | 0 | } |
5040 | | |
5041 | | /* setters */ |
5042 | | /** |
5043 | | * fu_struct_shim_hive_set_magic: (skip): |
5044 | | **/ |
5045 | | static gboolean |
5046 | | fu_struct_shim_hive_set_magic(FuStructShimHive *st, const gchar *value, GError **error) |
5047 | 360 | { |
5048 | 360 | gsize len; |
5049 | 360 | g_return_val_if_fail(st != NULL, FALSE); |
5050 | 360 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
5051 | 360 | if (value == NULL) { |
5052 | 0 | memset(st->buf->data + 0, 0x0, 4); |
5053 | 0 | return TRUE; |
5054 | 0 | } |
5055 | 360 | len = strlen(value); |
5056 | 360 | if (len > 4) { |
5057 | 0 | g_set_error(error, |
5058 | 0 | FWUPD_ERROR, |
5059 | 0 | FWUPD_ERROR_INVALID_DATA, |
5060 | 0 | "string '%s' (0x%x bytes) does not fit in FuStructShimHive.magic (0x%x bytes)", |
5061 | 0 | value, (guint) len, (guint) 4); |
5062 | 0 | return FALSE; |
5063 | 0 | } |
5064 | 360 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
5065 | 360 | } |
5066 | | /** |
5067 | | * fu_struct_shim_hive_set_header_version: (skip): |
5068 | | **/ |
5069 | | void |
5070 | | fu_struct_shim_hive_set_header_version(FuStructShimHive *st, guint8 value) |
5071 | 360 | { |
5072 | 360 | g_return_if_fail(st != NULL); |
5073 | 360 | st->buf->data[4] = value; |
5074 | 360 | } |
5075 | | /** |
5076 | | * fu_struct_shim_hive_set_items_count: (skip): |
5077 | | **/ |
5078 | | void |
5079 | | fu_struct_shim_hive_set_items_count(FuStructShimHive *st, guint8 value) |
5080 | 360 | { |
5081 | 360 | g_return_if_fail(st != NULL); |
5082 | 360 | st->buf->data[5] = value; |
5083 | 360 | } |
5084 | | /** |
5085 | | * fu_struct_shim_hive_set_items_offset: (skip): |
5086 | | **/ |
5087 | | void |
5088 | | fu_struct_shim_hive_set_items_offset(FuStructShimHive *st, guint8 value) |
5089 | 360 | { |
5090 | 360 | g_return_if_fail(st != NULL); |
5091 | 360 | st->buf->data[6] = value; |
5092 | 360 | } |
5093 | | /** |
5094 | | * fu_struct_shim_hive_set_crc32: (skip): |
5095 | | **/ |
5096 | | void |
5097 | | fu_struct_shim_hive_set_crc32(FuStructShimHive *st, guint32 value) |
5098 | 360 | { |
5099 | 360 | g_return_if_fail(st != NULL); |
5100 | 360 | fu_memwrite_uint32(st->buf->data + 7, value, G_LITTLE_ENDIAN); |
5101 | 360 | } |
5102 | | /** |
5103 | | * fu_struct_shim_hive_new: (skip): |
5104 | | **/ |
5105 | | FuStructShimHive * |
5106 | | fu_struct_shim_hive_new(void) |
5107 | 360 | { |
5108 | 360 | FuStructShimHive *st = fu_struct_shim_hive_new_internal(); |
5109 | 360 | st->buf = g_byte_array_sized_new(11); |
5110 | 360 | fu_byte_array_set_size(st->buf, 11, 0x0); |
5111 | 360 | fu_struct_shim_hive_set_magic(st, "HIVE", NULL); |
5112 | 360 | fu_struct_shim_hive_set_header_version(st, 0x1); |
5113 | 360 | return st; |
5114 | 360 | } |
5115 | | /** |
5116 | | * fu_struct_shim_hive_to_string: (skip): |
5117 | | **/ |
5118 | | static gchar * |
5119 | | fu_struct_shim_hive_to_string(const FuStructShimHive *st) |
5120 | 0 | { |
5121 | 0 | g_autoptr(GString) str = g_string_new("FuStructShimHive:\n"); |
5122 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5123 | 0 | { |
5124 | 0 | g_autofree gchar *tmp = fu_struct_shim_hive_get_magic(st); |
5125 | 0 | if (tmp != NULL) |
5126 | 0 | g_string_append_printf(str, " magic: %s\n", tmp); |
5127 | 0 | } |
5128 | 0 | g_string_append_printf(str, " header_version: 0x%x\n", |
5129 | 0 | (guint) fu_struct_shim_hive_get_header_version(st)); |
5130 | 0 | g_string_append_printf(str, " items_count: 0x%x\n", |
5131 | 0 | (guint) fu_struct_shim_hive_get_items_count(st)); |
5132 | 0 | g_string_append_printf(str, " items_offset: 0x%x\n", |
5133 | 0 | (guint) fu_struct_shim_hive_get_items_offset(st)); |
5134 | 0 | g_string_append_printf(str, " crc32: 0x%x\n", |
5135 | 0 | (guint) fu_struct_shim_hive_get_crc32(st)); |
5136 | 0 | if (str->len > 0) |
5137 | 0 | g_string_set_size(str, str->len - 1); |
5138 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
5139 | 0 | } |
5140 | | static gboolean |
5141 | | fu_struct_shim_hive_validate_internal(FuStructShimHive *st, GError **error) |
5142 | 1.22k | { |
5143 | 1.22k | g_return_val_if_fail(st != NULL, FALSE); |
5144 | 1.22k | if (strncmp((const gchar *) (st->buf->data + 0), "HIVE", 4) != 0) { |
5145 | 397 | g_autofree gchar *str = fu_struct_shim_hive_get_magic(st); |
5146 | 397 | g_set_error(error, |
5147 | 397 | FWUPD_ERROR, |
5148 | 397 | FWUPD_ERROR_INVALID_DATA, |
5149 | 397 | "constant FuStructShimHive.magic was not valid, " |
5150 | 397 | "expected 'HIVE' and got '%s'", |
5151 | 397 | str); |
5152 | 397 | return FALSE; |
5153 | 397 | } |
5154 | 831 | return TRUE; |
5155 | 1.22k | } |
5156 | | static gboolean |
5157 | | fu_struct_shim_hive_parse_internal(FuStructShimHive *st, GError **error) |
5158 | 1.22k | { |
5159 | 1.22k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
5160 | 0 | g_autofree gchar *str = fu_struct_shim_hive_to_string(st); |
5161 | 0 | g_debug("%s", str); |
5162 | 0 | } |
5163 | 1.22k | if (!fu_struct_shim_hive_validate_internal(st, error)) |
5164 | 397 | return FALSE; |
5165 | 831 | return TRUE; |
5166 | 1.22k | } |
5167 | | /** |
5168 | | * fu_struct_shim_hive_parse_stream: (skip): |
5169 | | **/ |
5170 | | FuStructShimHive * |
5171 | | fu_struct_shim_hive_parse_stream(GInputStream *stream, gsize offset, GError **error) |
5172 | 1.30k | { |
5173 | 1.30k | g_autoptr(FuStructShimHive) st = fu_struct_shim_hive_new_internal(); |
5174 | 1.30k | st->buf = fu_input_stream_read_byte_array(stream, offset, 11, NULL, error); |
5175 | 1.30k | if (st->buf == NULL) { |
5176 | 0 | g_prefix_error(error, "FuStructShimHive failed read of 0x%x: ", (guint) 11); |
5177 | 0 | return NULL; |
5178 | 0 | } |
5179 | 1.30k | if (st->buf->len != 11) { |
5180 | 74 | g_set_error(error, |
5181 | 74 | FWUPD_ERROR, |
5182 | 74 | FWUPD_ERROR_INVALID_DATA, |
5183 | 74 | "FuStructShimHive requested 0x%x and got 0x%x", |
5184 | 74 | (guint) 11, |
5185 | 74 | (guint) st->buf->len); |
5186 | 74 | return NULL; |
5187 | 74 | } |
5188 | 1.22k | if (!fu_struct_shim_hive_parse_internal(st, error)) |
5189 | 397 | return NULL; |
5190 | 831 | return g_steal_pointer(&st); |
5191 | 1.22k | } |
5192 | | /** |
5193 | | * fu_struct_shim_hive_item_ref: (skip): |
5194 | | **/ |
5195 | | FuStructShimHiveItem * |
5196 | | fu_struct_shim_hive_item_ref(FuStructShimHiveItem *st) |
5197 | 0 | { |
5198 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5199 | 0 | st->refcount++; |
5200 | 0 | return st; |
5201 | 0 | } |
5202 | | /** |
5203 | | * fu_struct_shim_hive_item_unref: (skip): |
5204 | | **/ |
5205 | | void |
5206 | | fu_struct_shim_hive_item_unref(FuStructShimHiveItem *st) |
5207 | 5.28k | { |
5208 | 5.28k | g_return_if_fail(st != NULL); |
5209 | 5.28k | if (st->refcount == 0) { |
5210 | 0 | g_critical("FuStructShimHiveItem refcount already zero"); |
5211 | 0 | return; |
5212 | 0 | } |
5213 | 5.28k | if (--st->refcount > 0) |
5214 | 0 | return; |
5215 | 5.28k | if (st->buf != NULL) |
5216 | 5.04k | g_byte_array_unref(st->buf); |
5217 | 5.28k | g_free(st); |
5218 | 5.28k | } |
5219 | | /** |
5220 | | * fu_struct_shim_hive_item_new_internal: (skip): |
5221 | | **/ |
5222 | | static FuStructShimHiveItem * |
5223 | | fu_struct_shim_hive_item_new_internal(void) |
5224 | 5.28k | { |
5225 | 5.28k | FuStructShimHiveItem *st = g_new0(FuStructShimHiveItem, 1); |
5226 | 5.28k | st->refcount = 1; |
5227 | 5.28k | return st; |
5228 | 5.28k | } |
5229 | | |
5230 | | /* getters */ |
5231 | | /** |
5232 | | * fu_struct_shim_hive_item_get_key_length: (skip): |
5233 | | **/ |
5234 | | guint8 |
5235 | | fu_struct_shim_hive_item_get_key_length(const FuStructShimHiveItem *st) |
5236 | 3.99k | { |
5237 | 3.99k | g_return_val_if_fail(st != NULL, 0x0); |
5238 | 3.99k | return st->buf->data[0]; |
5239 | 3.99k | } |
5240 | | /** |
5241 | | * fu_struct_shim_hive_item_get_value_length: (skip): |
5242 | | **/ |
5243 | | guint32 |
5244 | | fu_struct_shim_hive_item_get_value_length(const FuStructShimHiveItem *st) |
5245 | 3.89k | { |
5246 | 3.89k | g_return_val_if_fail(st != NULL, 0x0); |
5247 | 3.89k | return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN); |
5248 | 3.89k | } |
5249 | | |
5250 | | /* setters */ |
5251 | | /** |
5252 | | * fu_struct_shim_hive_item_set_key_length: (skip): |
5253 | | **/ |
5254 | | void |
5255 | | fu_struct_shim_hive_item_set_key_length(FuStructShimHiveItem *st, guint8 value) |
5256 | 1.02k | { |
5257 | 1.02k | g_return_if_fail(st != NULL); |
5258 | 1.02k | st->buf->data[0] = value; |
5259 | 1.02k | } |
5260 | | /** |
5261 | | * fu_struct_shim_hive_item_set_value_length: (skip): |
5262 | | **/ |
5263 | | void |
5264 | | fu_struct_shim_hive_item_set_value_length(FuStructShimHiveItem *st, guint32 value) |
5265 | 1.02k | { |
5266 | 1.02k | g_return_if_fail(st != NULL); |
5267 | 1.02k | fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN); |
5268 | 1.02k | } |
5269 | | /** |
5270 | | * fu_struct_shim_hive_item_new: (skip): |
5271 | | **/ |
5272 | | FuStructShimHiveItem * |
5273 | | fu_struct_shim_hive_item_new(void) |
5274 | 1.02k | { |
5275 | 1.02k | FuStructShimHiveItem *st = fu_struct_shim_hive_item_new_internal(); |
5276 | 1.02k | st->buf = g_byte_array_sized_new(5); |
5277 | 1.02k | fu_byte_array_set_size(st->buf, 5, 0x0); |
5278 | 1.02k | return st; |
5279 | 1.02k | } |
5280 | | /** |
5281 | | * fu_struct_shim_hive_item_to_string: (skip): |
5282 | | **/ |
5283 | | static gchar * |
5284 | | fu_struct_shim_hive_item_to_string(const FuStructShimHiveItem *st) |
5285 | 0 | { |
5286 | 0 | g_autoptr(GString) str = g_string_new("FuStructShimHiveItem:\n"); |
5287 | 0 | g_return_val_if_fail(st != NULL, NULL); |
5288 | 0 | g_string_append_printf(str, " key_length: 0x%x\n", |
5289 | 0 | (guint) fu_struct_shim_hive_item_get_key_length(st)); |
5290 | 0 | g_string_append_printf(str, " value_length: 0x%x\n", |
5291 | 0 | (guint) fu_struct_shim_hive_item_get_value_length(st)); |
5292 | 0 | if (str->len > 0) |
5293 | 0 | g_string_set_size(str, str->len - 1); |
5294 | 0 | return g_string_free(g_steal_pointer(&str), FALSE); |
5295 | 0 | } |
5296 | | static gboolean |
5297 | | fu_struct_shim_hive_item_validate_internal(FuStructShimHiveItem *st, GError **error) |
5298 | 3.99k | { |
5299 | 3.99k | g_return_val_if_fail(st != NULL, FALSE); |
5300 | 3.99k | return TRUE; |
5301 | 3.99k | } |
5302 | | static gboolean |
5303 | | fu_struct_shim_hive_item_parse_internal(FuStructShimHiveItem *st, GError **error) |
5304 | 3.99k | { |
5305 | 3.99k | if (g_getenv("FWUPD_VERBOSE") != NULL) { |
5306 | 0 | g_autofree gchar *str = fu_struct_shim_hive_item_to_string(st); |
5307 | 0 | g_debug("%s", str); |
5308 | 0 | } |
5309 | 3.99k | if (!fu_struct_shim_hive_item_validate_internal(st, error)) |
5310 | 0 | return FALSE; |
5311 | 3.99k | return TRUE; |
5312 | 3.99k | } |
5313 | | /** |
5314 | | * fu_struct_shim_hive_item_parse_stream: (skip): |
5315 | | **/ |
5316 | | FuStructShimHiveItem * |
5317 | | fu_struct_shim_hive_item_parse_stream(GInputStream *stream, gsize offset, GError **error) |
5318 | 4.26k | { |
5319 | 4.26k | g_autoptr(FuStructShimHiveItem) st = fu_struct_shim_hive_item_new_internal(); |
5320 | 4.26k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
5321 | 4.26k | if (st->buf == NULL) { |
5322 | 234 | g_prefix_error(error, "FuStructShimHiveItem failed read of 0x%x: ", (guint) 5); |
5323 | 234 | return NULL; |
5324 | 234 | } |
5325 | 4.02k | if (st->buf->len != 5) { |
5326 | 35 | g_set_error(error, |
5327 | 35 | FWUPD_ERROR, |
5328 | 35 | FWUPD_ERROR_INVALID_DATA, |
5329 | 35 | "FuStructShimHiveItem requested 0x%x and got 0x%x", |
5330 | 35 | (guint) 5, |
5331 | 35 | (guint) st->buf->len); |
5332 | 35 | return NULL; |
5333 | 35 | } |
5334 | 3.99k | if (!fu_struct_shim_hive_item_parse_internal(st, error)) |
5335 | 0 | return NULL; |
5336 | 3.99k | return g_steal_pointer(&st); |
5337 | 3.99k | } |