Coverage Report

Created: 2026-07-16 07:10

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