Coverage Report

Created: 2026-03-11 07:30

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