Coverage Report

Created: 2026-04-28 06:49

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