Coverage Report

Created: 2026-06-15 06:54

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