Coverage Report

Created: 2026-12-01 06:28

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