Coverage Report

Created: 2025-08-26 06:55

/work/fu-efi-struct.c
Line
Count
Source (jump to first uncovered line)
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include "fu-efi-struct.h"
5
#include "fu-byte-array.h"
6
#include "fu-mem-private.h"
7
#include "fu-string.h"
8
9
#ifdef G_LOG_DOMAIN
10
  #undef G_LOG_DOMAIN
11
#endif
12
0
#define G_LOG_DOMAIN "FuStruct"
13
14
const gchar *
15
fu_efi_signature_kind_to_string(FuEfiSignatureKind val)
16
0
{
17
0
    if (val == FU_EFI_SIGNATURE_KIND_UNKNOWN)
18
0
        return "unknown";
19
0
    if (val == FU_EFI_SIGNATURE_KIND_SHA256)
20
0
        return "sha256";
21
0
    if (val == FU_EFI_SIGNATURE_KIND_X509)
22
0
        return "x509";
23
0
    return NULL;
24
0
}
25
FuEfiSignatureKind
26
fu_efi_signature_kind_from_string(const gchar *val)
27
0
{
28
0
    if (g_strcmp0(val, "unknown") == 0)
29
0
        return FU_EFI_SIGNATURE_KIND_UNKNOWN;
30
0
    if (g_strcmp0(val, "sha256") == 0)
31
0
        return FU_EFI_SIGNATURE_KIND_SHA256;
32
0
    if (g_strcmp0(val, "x509") == 0)
33
0
        return FU_EFI_SIGNATURE_KIND_X509;
34
0
    return FU_EFI_SIGNATURE_KIND_UNKNOWN;
35
0
}
36
37
38
const gchar *
39
fu_efi_file_type_to_string(FuEfiFileType val)
40
0
{
41
0
    if (val == FU_EFI_FILE_TYPE_ALL)
42
0
        return "all";
43
0
    if (val == FU_EFI_FILE_TYPE_RAW)
44
0
        return "raw";
45
0
    if (val == FU_EFI_FILE_TYPE_FREEFORM)
46
0
        return "freeform";
47
0
    if (val == FU_EFI_FILE_TYPE_SECURITY_CORE)
48
0
        return "security-core";
49
0
    if (val == FU_EFI_FILE_TYPE_PEI_CORE)
50
0
        return "pei-core";
51
0
    if (val == FU_EFI_FILE_TYPE_DXE_CORE)
52
0
        return "dxe-core";
53
0
    if (val == FU_EFI_FILE_TYPE_PEIM)
54
0
        return "peim";
55
0
    if (val == FU_EFI_FILE_TYPE_DRIVER)
56
0
        return "driver";
57
0
    if (val == FU_EFI_FILE_TYPE_COMBINED_PEIM_DRIVER)
58
0
        return "combined-peim-driver";
59
0
    if (val == FU_EFI_FILE_TYPE_APPLICATION)
60
0
        return "application";
61
0
    if (val == FU_EFI_FILE_TYPE_MM)
62
0
        return "mm";
63
0
    if (val == FU_EFI_FILE_TYPE_FIRMWARE_VOLUME_IMAGE)
64
0
        return "firmware-volume-image";
65
0
    if (val == FU_EFI_FILE_TYPE_COMBINED_MM_DXE)
66
0
        return "combined-mm-dxe";
67
0
    if (val == FU_EFI_FILE_TYPE_MM_CORE)
68
0
        return "mm-core";
69
0
    if (val == FU_EFI_FILE_TYPE_MM_STANDALONE)
70
0
        return "mm-standalone";
71
0
    if (val == FU_EFI_FILE_TYPE_MM_CORE_STANDALONE)
72
0
        return "mm-core-standalone";
73
0
    if (val == FU_EFI_FILE_TYPE_FFS_PAD)
74
0
        return "ffs-pad";
75
0
    return NULL;
76
0
}
77
78
static const gchar *
79
fu_efi_compression_type_to_string(FuEfiCompressionType val)
80
0
{
81
0
    if (val == FU_EFI_COMPRESSION_TYPE_NOT_COMPRESSED)
82
0
        return "not-compressed";
83
0
    if (val == FU_EFI_COMPRESSION_TYPE_STANDARD_COMPRESSION)
84
0
        return "standard-compression";
85
0
    return NULL;
86
0
}
87
88
const gchar *
89
fu_efi_lz77_decompressor_version_to_string(FuEfiLz77DecompressorVersion val)
90
3.72k
{
91
3.72k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_NONE)
92
0
        return "none";
93
3.72k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY)
94
2.41k
        return "legacy";
95
1.30k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_TIANO)
96
1.30k
        return "tiano";
97
0
    return NULL;
98
1.30k
}
99
100
const gchar *
101
fu_efi_section_type_to_string(FuEfiSectionType val)
102
32.5k
{
103
32.5k
    if (val == FU_EFI_SECTION_TYPE_COMPRESSION)
104
0
        return "compression";
105
32.5k
    if (val == FU_EFI_SECTION_TYPE_GUID_DEFINED)
106
22
        return "guid-defined";
107
32.5k
    if (val == FU_EFI_SECTION_TYPE_DISPOSABLE)
108
468
        return "disposable";
109
32.0k
    if (val == FU_EFI_SECTION_TYPE_PE32)
110
706
        return "pe32";
111
31.3k
    if (val == FU_EFI_SECTION_TYPE_PIC)
112
798
        return "pic";
113
30.5k
    if (val == FU_EFI_SECTION_TYPE_TE)
114
572
        return "te";
115
29.9k
    if (val == FU_EFI_SECTION_TYPE_DXE_DEPEX)
116
307
        return "dxe-depex";
117
29.6k
    if (val == FU_EFI_SECTION_TYPE_VERSION)
118
0
        return "version";
119
29.6k
    if (val == FU_EFI_SECTION_TYPE_USER_INTERFACE)
120
0
        return "user-interface";
121
29.6k
    if (val == FU_EFI_SECTION_TYPE_COMPATIBILITY16)
122
2.98k
        return "compatibility16";
123
26.6k
    if (val == FU_EFI_SECTION_TYPE_VOLUME_IMAGE)
124
0
        return "volume-image";
125
26.6k
    if (val == FU_EFI_SECTION_TYPE_FREEFORM_SUBTYPE_GUID)
126
0
        return "freeform-subtype-guid";
127
26.6k
    if (val == FU_EFI_SECTION_TYPE_RAW)
128
6.85k
        return "raw";
129
19.8k
    if (val == FU_EFI_SECTION_TYPE_PEI_DEPEX)
130
1.56k
        return "pei-depex";
131
18.2k
    if (val == FU_EFI_SECTION_TYPE_MM_DEPEX)
132
337
        return "mm-depex";
133
17.9k
    if (val == FU_EFI_SECTION_TYPE_PHOENIX_SECTION_POSTCODE)
134
1.62k
        return "phoenix-section-postcode";
135
16.2k
    if (val == FU_EFI_SECTION_TYPE_INSYDE_SECTION_POSTCODE)
136
269
        return "insyde-section-postcode";
137
16.0k
    return NULL;
138
16.2k
}
139
140
const gchar *
141
fu_efi_volume_ext_entry_type_to_string(FuEfiVolumeExtEntryType val)
142
0
{
143
0
    if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_OEM)
144
0
        return "oem";
145
0
    if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_GUID)
146
0
        return "guid";
147
0
    if (val == FU_EFI_VOLUME_EXT_ENTRY_TYPE_SIZE)
148
0
        return "size";
149
0
    return NULL;
150
0
}
151
152
static const gchar *
153
fu_efi_load_option_attrs_to_string(FuEfiLoadOptionAttrs val)
154
0
{
155
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_ACTIVE)
156
0
        return "active";
157
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_FORCE_RECONNECT)
158
0
        return "force-reconnect";
159
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_HIDDEN)
160
0
        return "hidden";
161
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_CATEGORY)
162
0
        return "category";
163
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_CATEGORY_BOOT)
164
0
        return "category-boot";
165
0
    if (val == FU_EFI_LOAD_OPTION_ATTRS_CATEGORY_AP)
166
0
        return "category-ap";
167
0
    return NULL;
168
0
}
169
170
const gchar *
171
fu_efi_load_option_kind_to_string(FuEfiLoadOptionKind val)
172
0
{
173
0
    if (val == FU_EFI_LOAD_OPTION_KIND_UNKNOWN)
174
0
        return "unknown";
175
0
    if (val == FU_EFI_LOAD_OPTION_KIND_PATH)
176
0
        return "path";
177
0
    if (val == FU_EFI_LOAD_OPTION_KIND_HIVE)
178
0
        return "hive";
179
0
    if (val == FU_EFI_LOAD_OPTION_KIND_DATA)
180
0
        return "data";
181
0
    return NULL;
182
0
}
183
FuEfiLoadOptionKind
184
fu_efi_load_option_kind_from_string(const gchar *val)
185
0
{
186
0
    if (g_strcmp0(val, "unknown") == 0)
187
0
        return FU_EFI_LOAD_OPTION_KIND_UNKNOWN;
188
0
    if (g_strcmp0(val, "path") == 0)
189
0
        return FU_EFI_LOAD_OPTION_KIND_PATH;
190
0
    if (g_strcmp0(val, "hive") == 0)
191
0
        return FU_EFI_LOAD_OPTION_KIND_HIVE;
192
0
    if (g_strcmp0(val, "data") == 0)
193
0
        return FU_EFI_LOAD_OPTION_KIND_DATA;
194
0
    return FU_EFI_LOAD_OPTION_KIND_UNKNOWN;
195
0
}
196
197
static const gchar *
198
fu_efi_device_path_type_to_string(FuEfiDevicePathType val)
199
0
{
200
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_HARDWARE)
201
0
        return "hardware";
202
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_ACPI)
203
0
        return "acpi";
204
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_MESSAGE)
205
0
        return "message";
206
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_MEDIA)
207
0
        return "media";
208
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_BIOS_BOOT)
209
0
        return "bios-boot";
210
0
    if (val == FU_EFI_DEVICE_PATH_TYPE_END)
211
0
        return "end";
212
0
    return NULL;
213
0
}
214
215
static const gchar *
216
fu_efi_hard_drive_device_path_subtype_to_string(FuEfiHardDriveDevicePathSubtype val)
217
0
{
218
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE)
219
0
        return "hard-drive";
220
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_CDROM)
221
0
        return "cdrom";
222
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_VENDOR)
223
0
        return "vendor";
224
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_FILE_PATH)
225
0
        return "file-path";
226
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_MEDIA_PROTOCOL)
227
0
        return "media-protocol";
228
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_PIWG_FIRMWARE_FILE)
229
0
        return "piwg-firmware-file";
230
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_PIWG_FIRMWARE_VOLUME)
231
0
        return "piwg-firmware-volume";
232
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_RELATIVE_OFFSET_RANGE)
233
0
        return "relative-offset-range";
234
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_RAM_DISK_DEVICE_PATH)
235
0
        return "ram-disk-device-path";
236
0
    return NULL;
237
0
}
238
239
const gchar *
240
fu_efi_hard_drive_device_path_partition_format_to_string(FuEfiHardDriveDevicePathPartitionFormat val)
241
0
{
242
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR)
243
0
        return "legacy-mbr";
244
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE)
245
0
        return "guid-partition-table";
246
0
    return NULL;
247
0
}
248
FuEfiHardDriveDevicePathPartitionFormat
249
fu_efi_hard_drive_device_path_partition_format_from_string(const gchar *val)
250
0
{
251
0
    if (g_strcmp0(val, "legacy-mbr") == 0)
252
0
        return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR;
253
0
    if (g_strcmp0(val, "guid-partition-table") == 0)
254
0
        return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE;
255
0
    return FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_LEGACY_MBR;
256
0
}
257
258
const gchar *
259
fu_efi_hard_drive_device_path_signature_type_to_string(FuEfiHardDriveDevicePathSignatureType val)
260
0
{
261
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE)
262
0
        return "none";
263
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_ADDR1B8)
264
0
        return "addr1b8";
265
0
    if (val == FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID)
266
0
        return "guid";
267
0
    return NULL;
268
0
}
269
FuEfiHardDriveDevicePathSignatureType
270
fu_efi_hard_drive_device_path_signature_type_from_string(const gchar *val)
271
0
{
272
0
    if (g_strcmp0(val, "none") == 0)
273
0
        return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE;
274
0
    if (g_strcmp0(val, "addr1b8") == 0)
275
0
        return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_ADDR1B8;
276
0
    if (g_strcmp0(val, "guid") == 0)
277
0
        return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID;
278
0
    return FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_NONE;
279
0
}
280
/* getters */
281
/**
282
 * fu_struct_efi_file_get_name: (skip):
283
 **/
284
const fwupd_guid_t *
285
fu_struct_efi_file_get_name(const FuStructEfiFile *st)
286
30.2k
{
287
30.2k
    g_return_val_if_fail(st != NULL, NULL);
288
30.2k
    return (const fwupd_guid_t *) (st->data + 0);
289
30.2k
}
290
/**
291
 * fu_struct_efi_file_get_hdr_checksum: (skip):
292
 **/
293
guint8
294
fu_struct_efi_file_get_hdr_checksum(const FuStructEfiFile *st)
295
30.3k
{
296
30.3k
    g_return_val_if_fail(st != NULL, 0x0);
297
30.3k
    return st->data[16];
298
30.3k
}
299
/**
300
 * fu_struct_efi_file_get_data_checksum: (skip):
301
 **/
302
guint8
303
fu_struct_efi_file_get_data_checksum(const FuStructEfiFile *st)
304
731
{
305
731
    g_return_val_if_fail(st != NULL, 0x0);
306
731
    return st->data[17];
307
731
}
308
/**
309
 * fu_struct_efi_file_get_type: (skip):
310
 **/
311
FuEfiFileType
312
fu_struct_efi_file_get_type(const FuStructEfiFile *st)
313
30.2k
{
314
30.2k
    g_return_val_if_fail(st != NULL, 0x0);
315
30.2k
    return st->data[18];
316
30.2k
}
317
/**
318
 * fu_struct_efi_file_get_attrs: (skip):
319
 **/
320
guint8
321
fu_struct_efi_file_get_attrs(const FuStructEfiFile *st)
322
30.2k
{
323
30.2k
    g_return_val_if_fail(st != NULL, 0x0);
324
30.2k
    return st->data[19];
325
30.2k
}
326
/**
327
 * fu_struct_efi_file_get_size: (skip):
328
 **/
329
guint32
330
fu_struct_efi_file_get_size(const FuStructEfiFile *st)
331
30.3k
{
332
30.3k
    g_return_val_if_fail(st != NULL, 0x0);
333
30.3k
    return fu_memread_uint24(st->data + 20, G_LITTLE_ENDIAN);
334
30.3k
}
335
/**
336
 * fu_struct_efi_file_get_state: (skip):
337
 **/
338
guint8
339
fu_struct_efi_file_get_state(const FuStructEfiFile *st)
340
0
{
341
0
    g_return_val_if_fail(st != NULL, 0x0);
342
0
    return st->data[23];
343
0
}
344
345
/* setters */
346
/**
347
 * fu_struct_efi_file_set_name: (skip):
348
 **/
349
void
350
fu_struct_efi_file_set_name(FuStructEfiFile *st, const fwupd_guid_t *value)
351
6.32k
{
352
6.32k
    g_return_if_fail(st != NULL);
353
6.32k
    g_return_if_fail(value != NULL);
354
6.32k
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
355
6.32k
}
356
/**
357
 * fu_struct_efi_file_set_hdr_checksum: (skip):
358
 **/
359
void
360
fu_struct_efi_file_set_hdr_checksum(FuStructEfiFile *st, guint8 value)
361
12.6k
{
362
12.6k
    g_return_if_fail(st != NULL);
363
12.6k
    st->data[16] = value;
364
12.6k
}
365
/**
366
 * fu_struct_efi_file_set_data_checksum: (skip):
367
 **/
368
void
369
fu_struct_efi_file_set_data_checksum(FuStructEfiFile *st, guint8 value)
370
6.32k
{
371
6.32k
    g_return_if_fail(st != NULL);
372
6.32k
    st->data[17] = value;
373
6.32k
}
374
/**
375
 * fu_struct_efi_file_set_type: (skip):
376
 **/
377
void
378
fu_struct_efi_file_set_type(FuStructEfiFile *st, FuEfiFileType value)
379
6.32k
{
380
6.32k
    g_return_if_fail(st != NULL);
381
6.32k
    st->data[18] = value;
382
6.32k
}
383
/**
384
 * fu_struct_efi_file_set_attrs: (skip):
385
 **/
386
void
387
fu_struct_efi_file_set_attrs(FuStructEfiFile *st, guint8 value)
388
6.32k
{
389
6.32k
    g_return_if_fail(st != NULL);
390
6.32k
    st->data[19] = value;
391
6.32k
}
392
/**
393
 * fu_struct_efi_file_set_size: (skip):
394
 **/
395
void
396
fu_struct_efi_file_set_size(FuStructEfiFile *st, guint32 value)
397
6.32k
{
398
6.32k
    g_return_if_fail(st != NULL);
399
6.32k
    fu_memwrite_uint24(st->data + 20, value, G_LITTLE_ENDIAN);
400
6.32k
}
401
/**
402
 * fu_struct_efi_file_set_state: (skip):
403
 **/
404
void
405
fu_struct_efi_file_set_state(FuStructEfiFile *st, guint8 value)
406
6.74k
{
407
6.74k
    g_return_if_fail(st != NULL);
408
6.74k
    st->data[23] = value;
409
6.74k
}
410
/**
411
 * fu_struct_efi_file_new: (skip):
412
 **/
413
FuStructEfiFile *
414
fu_struct_efi_file_new(void)
415
6.74k
{
416
6.74k
    FuStructEfiFile *st = g_byte_array_sized_new(24);
417
6.74k
    fu_byte_array_set_size(st, 24, 0x0);
418
6.74k
    fu_struct_efi_file_set_state(st, 0xF8);
419
6.74k
    return st;
420
6.74k
}
421
/**
422
 * fu_struct_efi_file_to_string: (skip):
423
 **/
424
static gchar *
425
fu_struct_efi_file_to_string(const FuStructEfiFile *st)
426
0
{
427
0
    g_autoptr(GString) str = g_string_new("FuStructEfiFile:\n");
428
0
    g_return_val_if_fail(st != NULL, NULL);
429
0
    {
430
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_file_get_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
431
0
        g_string_append_printf(str, "  name: %s\n", tmp);
432
0
    }
433
0
    g_string_append_printf(str, "  hdr_checksum: 0x%x\n",
434
0
                           (guint) fu_struct_efi_file_get_hdr_checksum(st));
435
0
    g_string_append_printf(str, "  data_checksum: 0x%x\n",
436
0
                           (guint) fu_struct_efi_file_get_data_checksum(st));
437
0
    {
438
0
        const gchar *tmp = fu_efi_file_type_to_string(fu_struct_efi_file_get_type(st));
439
0
        if (tmp != NULL) {
440
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_file_get_type(st), tmp);
441
0
        } else {
442
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_file_get_type(st));
443
0
        }
444
0
    }
445
0
    g_string_append_printf(str, "  attrs: 0x%x\n",
446
0
                           (guint) fu_struct_efi_file_get_attrs(st));
447
0
    g_string_append_printf(str, "  size: 0x%x\n",
448
0
                           (guint) fu_struct_efi_file_get_size(st));
449
0
    g_string_append_printf(str, "  state: 0x%x\n",
450
0
                           (guint) fu_struct_efi_file_get_state(st));
451
0
    if (str->len > 0)
452
0
        g_string_set_size(str, str->len - 1);
453
0
    return g_string_free(g_steal_pointer(&str), FALSE);
454
0
}
455
static gboolean
456
fu_struct_efi_file_validate_internal(FuStructEfiFile *st, GError **error)
457
30.4k
{
458
30.4k
    g_return_val_if_fail(st != NULL, FALSE);
459
30.4k
    return TRUE;
460
30.4k
}
461
/**
462
 * fu_struct_efi_file_validate: (skip):
463
 **/
464
gboolean
465
fu_struct_efi_file_validate(const guint8 *buf, gsize bufsz, gsize offset, GError **error)
466
0
{
467
0
    GByteArray st = {.data = (guint8 *) buf + offset, .len = bufsz - offset, };
468
0
    g_return_val_if_fail(buf != NULL, FALSE);
469
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
470
0
    if (!fu_memchk_read(bufsz, offset, 24, error)) {
471
0
        g_prefix_error_literal(error, "invalid struct FuStructEfiFile: ");
472
0
        return FALSE;
473
0
    }
474
0
    if (!fu_struct_efi_file_validate_internal(&st, error))
475
0
        return FALSE;
476
0
    return TRUE;
477
0
}
478
static gboolean
479
fu_struct_efi_file_parse_internal(FuStructEfiFile *st, GError **error)
480
30.2k
{
481
30.2k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
482
0
        g_autofree gchar *str = fu_struct_efi_file_to_string(st);
483
0
        g_debug("%s", str);
484
0
    }
485
30.2k
    if (!fu_struct_efi_file_validate_internal(st, error))
486
0
        return FALSE;
487
30.2k
    return TRUE;
488
30.2k
}
489
/**
490
 * fu_struct_efi_file_parse_stream: (skip):
491
 **/
492
FuStructEfiFile *
493
fu_struct_efi_file_parse_stream(GInputStream *stream, gsize offset, GError **error)
494
30.3k
{
495
30.3k
    g_autoptr(GByteArray) st = NULL;
496
30.3k
    st = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error);
497
30.3k
    if (st == NULL) {
498
0
        g_prefix_error(error, "FuStructEfiFile failed read of 0x%x: ", (guint) 24);
499
0
        return NULL;
500
0
    }
501
30.3k
    if (st->len != 24) {
502
87
        g_set_error(error,
503
87
                    FWUPD_ERROR,
504
87
                    FWUPD_ERROR_INVALID_DATA,
505
87
                    "FuStructEfiFile requested 0x%x and got 0x%x",
506
87
                    (guint) 24,
507
87
                    (guint) st->len);
508
87
        return NULL;
509
87
    }
510
30.2k
    if (!fu_struct_efi_file_parse_internal(st, error))
511
0
        return NULL;
512
30.2k
    return g_steal_pointer(&st);
513
30.2k
}
514
/* getters */
515
/**
516
 * fu_struct_efi_file2_get_extended_size: (skip):
517
 **/
518
guint64
519
fu_struct_efi_file2_get_extended_size(const FuStructEfiFile2 *st)
520
227
{
521
227
    g_return_val_if_fail(st != NULL, 0x0);
522
227
    return fu_memread_uint64(st->data + 24, G_LITTLE_ENDIAN);
523
227
}
524
525
/* setters */
526
/**
527
 * fu_struct_efi_file2_to_string: (skip):
528
 **/
529
static gchar *
530
fu_struct_efi_file2_to_string(const FuStructEfiFile2 *st)
531
0
{
532
0
    g_autoptr(GString) str = g_string_new("FuStructEfiFile2:\n");
533
0
    g_return_val_if_fail(st != NULL, NULL);
534
0
    g_string_append_printf(str, "  extended_size: 0x%x\n",
535
0
                           (guint) fu_struct_efi_file2_get_extended_size(st));
536
0
    if (str->len > 0)
537
0
        g_string_set_size(str, str->len - 1);
538
0
    return g_string_free(g_steal_pointer(&str), FALSE);
539
0
}
540
static gboolean
541
fu_struct_efi_file2_validate_internal(FuStructEfiFile2 *st, GError **error)
542
227
{
543
227
    g_return_val_if_fail(st != NULL, FALSE);
544
227
    {
545
227
        GByteArray st_tmp = {
546
227
            .data = (guint8*) st->data + 0x0,
547
227
            .len = 24,
548
227
        };
549
227
        if (!fu_struct_efi_file_validate_internal(&st_tmp, error))
550
0
            return FALSE;
551
227
    }
552
227
    return TRUE;
553
227
}
554
static gboolean
555
fu_struct_efi_file2_parse_internal(FuStructEfiFile2 *st, GError **error)
556
227
{
557
227
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
558
0
        g_autofree gchar *str = fu_struct_efi_file2_to_string(st);
559
0
        g_debug("%s", str);
560
0
    }
561
227
    if (!fu_struct_efi_file2_validate_internal(st, error))
562
0
        return FALSE;
563
227
    return TRUE;
564
227
}
565
/**
566
 * fu_struct_efi_file2_parse_stream: (skip):
567
 **/
568
FuStructEfiFile2 *
569
fu_struct_efi_file2_parse_stream(GInputStream *stream, gsize offset, GError **error)
570
236
{
571
236
    g_autoptr(GByteArray) st = NULL;
572
236
    st = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
573
236
    if (st == NULL) {
574
0
        g_prefix_error(error, "FuStructEfiFile2 failed read of 0x%x: ", (guint) 32);
575
0
        return NULL;
576
0
    }
577
236
    if (st->len != 32) {
578
9
        g_set_error(error,
579
9
                    FWUPD_ERROR,
580
9
                    FWUPD_ERROR_INVALID_DATA,
581
9
                    "FuStructEfiFile2 requested 0x%x and got 0x%x",
582
9
                    (guint) 32,
583
9
                    (guint) st->len);
584
9
        return NULL;
585
9
    }
586
227
    if (!fu_struct_efi_file2_parse_internal(st, error))
587
0
        return NULL;
588
227
    return g_steal_pointer(&st);
589
227
}
590
/* getters */
591
/**
592
 * fu_struct_efi_section_compression_get_uncompressed_length: (skip):
593
 **/
594
guint32
595
fu_struct_efi_section_compression_get_uncompressed_length(const FuStructEfiSectionCompression *st)
596
0
{
597
0
    g_return_val_if_fail(st != NULL, 0x0);
598
0
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
599
0
}
600
/**
601
 * fu_struct_efi_section_compression_get_compression_type: (skip):
602
 **/
603
FuEfiCompressionType
604
fu_struct_efi_section_compression_get_compression_type(const FuStructEfiSectionCompression *st)
605
3.67k
{
606
3.67k
    g_return_val_if_fail(st != NULL, 0x0);
607
3.67k
    return st->data[4];
608
3.67k
}
609
610
/* setters */
611
/**
612
 * fu_struct_efi_section_compression_to_string: (skip):
613
 **/
614
static gchar *
615
fu_struct_efi_section_compression_to_string(const FuStructEfiSectionCompression *st)
616
0
{
617
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSectionCompression:\n");
618
0
    g_return_val_if_fail(st != NULL, NULL);
619
0
    g_string_append_printf(str, "  uncompressed_length: 0x%x\n",
620
0
                           (guint) fu_struct_efi_section_compression_get_uncompressed_length(st));
621
0
    {
622
0
        const gchar *tmp = fu_efi_compression_type_to_string(fu_struct_efi_section_compression_get_compression_type(st));
623
0
        if (tmp != NULL) {
624
0
            g_string_append_printf(str, "  compression_type: 0x%x [%s]\n", (guint) fu_struct_efi_section_compression_get_compression_type(st), tmp);
625
0
        } else {
626
0
            g_string_append_printf(str, "  compression_type: 0x%x\n", (guint) fu_struct_efi_section_compression_get_compression_type(st));
627
0
        }
628
0
    }
629
0
    if (str->len > 0)
630
0
        g_string_set_size(str, str->len - 1);
631
0
    return g_string_free(g_steal_pointer(&str), FALSE);
632
0
}
633
static gboolean
634
fu_struct_efi_section_compression_validate_internal(FuStructEfiSectionCompression *st, GError **error)
635
3.67k
{
636
3.67k
    g_return_val_if_fail(st != NULL, FALSE);
637
3.67k
    return TRUE;
638
3.67k
}
639
static gboolean
640
fu_struct_efi_section_compression_parse_internal(FuStructEfiSectionCompression *st, GError **error)
641
3.67k
{
642
3.67k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
643
0
        g_autofree gchar *str = fu_struct_efi_section_compression_to_string(st);
644
0
        g_debug("%s", str);
645
0
    }
646
3.67k
    if (!fu_struct_efi_section_compression_validate_internal(st, error))
647
0
        return FALSE;
648
3.67k
    return TRUE;
649
3.67k
}
650
/**
651
 * fu_struct_efi_section_compression_parse_stream: (skip):
652
 **/
653
FuStructEfiSectionCompression *
654
fu_struct_efi_section_compression_parse_stream(GInputStream *stream, gsize offset, GError **error)
655
3.69k
{
656
3.69k
    g_autoptr(GByteArray) st = NULL;
657
3.69k
    st = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error);
658
3.69k
    if (st == NULL) {
659
9
        g_prefix_error(error, "FuStructEfiSectionCompression failed read of 0x%x: ", (guint) 5);
660
9
        return NULL;
661
9
    }
662
3.69k
    if (st->len != 5) {
663
11
        g_set_error(error,
664
11
                    FWUPD_ERROR,
665
11
                    FWUPD_ERROR_INVALID_DATA,
666
11
                    "FuStructEfiSectionCompression requested 0x%x and got 0x%x",
667
11
                    (guint) 5,
668
11
                    (guint) st->len);
669
11
        return NULL;
670
11
    }
671
3.67k
    if (!fu_struct_efi_section_compression_parse_internal(st, error))
672
0
        return NULL;
673
3.67k
    return g_steal_pointer(&st);
674
3.67k
}
675
/* getters */
676
/**
677
 * fu_struct_efi_lz77_decompressor_header_get_src_size: (skip):
678
 **/
679
guint32
680
fu_struct_efi_lz77_decompressor_header_get_src_size(const FuStructEfiLz77DecompressorHeader *st)
681
3.41k
{
682
3.41k
    g_return_val_if_fail(st != NULL, 0x0);
683
3.41k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
684
3.41k
}
685
/**
686
 * fu_struct_efi_lz77_decompressor_header_get_dst_size: (skip):
687
 **/
688
guint32
689
fu_struct_efi_lz77_decompressor_header_get_dst_size(const FuStructEfiLz77DecompressorHeader *st)
690
3.35k
{
691
3.35k
    g_return_val_if_fail(st != NULL, 0x0);
692
3.35k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
693
3.35k
}
694
695
/* setters */
696
/**
697
 * fu_struct_efi_lz77_decompressor_header_to_string: (skip):
698
 **/
699
static gchar *
700
fu_struct_efi_lz77_decompressor_header_to_string(const FuStructEfiLz77DecompressorHeader *st)
701
0
{
702
0
    g_autoptr(GString) str = g_string_new("FuStructEfiLz77DecompressorHeader:\n");
703
0
    g_return_val_if_fail(st != NULL, NULL);
704
0
    g_string_append_printf(str, "  src_size: 0x%x\n",
705
0
                           (guint) fu_struct_efi_lz77_decompressor_header_get_src_size(st));
706
0
    g_string_append_printf(str, "  dst_size: 0x%x\n",
707
0
                           (guint) fu_struct_efi_lz77_decompressor_header_get_dst_size(st));
708
0
    if (str->len > 0)
709
0
        g_string_set_size(str, str->len - 1);
710
0
    return g_string_free(g_steal_pointer(&str), FALSE);
711
0
}
712
static gboolean
713
fu_struct_efi_lz77_decompressor_header_validate_internal(FuStructEfiLz77DecompressorHeader *st, GError **error)
714
3.41k
{
715
3.41k
    g_return_val_if_fail(st != NULL, FALSE);
716
3.41k
    return TRUE;
717
3.41k
}
718
static gboolean
719
fu_struct_efi_lz77_decompressor_header_parse_internal(FuStructEfiLz77DecompressorHeader *st, GError **error)
720
3.41k
{
721
3.41k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
722
0
        g_autofree gchar *str = fu_struct_efi_lz77_decompressor_header_to_string(st);
723
0
        g_debug("%s", str);
724
0
    }
725
3.41k
    if (!fu_struct_efi_lz77_decompressor_header_validate_internal(st, error))
726
0
        return FALSE;
727
3.41k
    return TRUE;
728
3.41k
}
729
/**
730
 * fu_struct_efi_lz77_decompressor_header_parse_stream: (skip):
731
 **/
732
FuStructEfiLz77DecompressorHeader *
733
fu_struct_efi_lz77_decompressor_header_parse_stream(GInputStream *stream, gsize offset, GError **error)
734
3.44k
{
735
3.44k
    g_autoptr(GByteArray) st = NULL;
736
3.44k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
737
3.44k
    if (st == NULL) {
738
1
        g_prefix_error(error, "FuStructEfiLz77DecompressorHeader failed read of 0x%x: ", (guint) 8);
739
1
        return NULL;
740
1
    }
741
3.44k
    if (st->len != 8) {
742
26
        g_set_error(error,
743
26
                    FWUPD_ERROR,
744
26
                    FWUPD_ERROR_INVALID_DATA,
745
26
                    "FuStructEfiLz77DecompressorHeader requested 0x%x and got 0x%x",
746
26
                    (guint) 8,
747
26
                    (guint) st->len);
748
26
        return NULL;
749
26
    }
750
3.41k
    if (!fu_struct_efi_lz77_decompressor_header_parse_internal(st, error))
751
0
        return NULL;
752
3.41k
    return g_steal_pointer(&st);
753
3.41k
}
754
/* getters */
755
/**
756
 * fu_struct_efi_section_get_size: (skip):
757
 **/
758
guint32
759
fu_struct_efi_section_get_size(const FuStructEfiSection *st)
760
95.1k
{
761
95.1k
    g_return_val_if_fail(st != NULL, 0x0);
762
95.1k
    return fu_memread_uint24(st->data + 0, G_LITTLE_ENDIAN);
763
95.1k
}
764
/**
765
 * fu_struct_efi_section_get_type: (skip):
766
 **/
767
FuEfiSectionType
768
fu_struct_efi_section_get_type(const FuStructEfiSection *st)
769
47.3k
{
770
47.3k
    g_return_val_if_fail(st != NULL, 0x0);
771
47.3k
    return st->data[3];
772
47.3k
}
773
774
/* setters */
775
/**
776
 * fu_struct_efi_section_set_size: (skip):
777
 **/
778
void
779
fu_struct_efi_section_set_size(FuStructEfiSection *st, guint32 value)
780
7.38k
{
781
7.38k
    g_return_if_fail(st != NULL);
782
7.38k
    fu_memwrite_uint24(st->data + 0, value, G_LITTLE_ENDIAN);
783
7.38k
}
784
/**
785
 * fu_struct_efi_section_set_type: (skip):
786
 **/
787
void
788
fu_struct_efi_section_set_type(FuStructEfiSection *st, FuEfiSectionType value)
789
7.38k
{
790
7.38k
    g_return_if_fail(st != NULL);
791
7.38k
    st->data[3] = value;
792
7.38k
}
793
/**
794
 * fu_struct_efi_section_new: (skip):
795
 **/
796
FuStructEfiSection *
797
fu_struct_efi_section_new(void)
798
7.76k
{
799
7.76k
    FuStructEfiSection *st = g_byte_array_sized_new(4);
800
7.76k
    fu_byte_array_set_size(st, 4, 0x0);
801
7.76k
    return st;
802
7.76k
}
803
/**
804
 * fu_struct_efi_section_to_string: (skip):
805
 **/
806
static gchar *
807
fu_struct_efi_section_to_string(const FuStructEfiSection *st)
808
0
{
809
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSection:\n");
810
0
    g_return_val_if_fail(st != NULL, NULL);
811
0
    g_string_append_printf(str, "  size: 0x%x\n",
812
0
                           (guint) fu_struct_efi_section_get_size(st));
813
0
    {
814
0
        const gchar *tmp = fu_efi_section_type_to_string(fu_struct_efi_section_get_type(st));
815
0
        if (tmp != NULL) {
816
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_section_get_type(st), tmp);
817
0
        } else {
818
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_section_get_type(st));
819
0
        }
820
0
    }
821
0
    if (str->len > 0)
822
0
        g_string_set_size(str, str->len - 1);
823
0
    return g_string_free(g_steal_pointer(&str), FALSE);
824
0
}
825
static gboolean
826
fu_struct_efi_section_validate_internal(FuStructEfiSection *st, GError **error)
827
49.3k
{
828
49.3k
    g_return_val_if_fail(st != NULL, FALSE);
829
49.3k
    return TRUE;
830
49.3k
}
831
static gboolean
832
fu_struct_efi_section_parse_internal(FuStructEfiSection *st, GError **error)
833
48.1k
{
834
48.1k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
835
0
        g_autofree gchar *str = fu_struct_efi_section_to_string(st);
836
0
        g_debug("%s", str);
837
0
    }
838
48.1k
    if (!fu_struct_efi_section_validate_internal(st, error))
839
0
        return FALSE;
840
48.1k
    return TRUE;
841
48.1k
}
842
/**
843
 * fu_struct_efi_section_parse_stream: (skip):
844
 **/
845
FuStructEfiSection *
846
fu_struct_efi_section_parse_stream(GInputStream *stream, gsize offset, GError **error)
847
48.3k
{
848
48.3k
    g_autoptr(GByteArray) st = NULL;
849
48.3k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
850
48.3k
    if (st == NULL) {
851
129
        g_prefix_error(error, "FuStructEfiSection failed read of 0x%x: ", (guint) 4);
852
129
        return NULL;
853
129
    }
854
48.2k
    if (st->len != 4) {
855
68
        g_set_error(error,
856
68
                    FWUPD_ERROR,
857
68
                    FWUPD_ERROR_INVALID_DATA,
858
68
                    "FuStructEfiSection requested 0x%x and got 0x%x",
859
68
                    (guint) 4,
860
68
                    (guint) st->len);
861
68
        return NULL;
862
68
    }
863
48.1k
    if (!fu_struct_efi_section_parse_internal(st, error))
864
0
        return NULL;
865
48.1k
    return g_steal_pointer(&st);
866
48.1k
}
867
/* getters */
868
/**
869
 * fu_struct_efi_section2_get_extended_size: (skip):
870
 **/
871
guint32
872
fu_struct_efi_section2_get_extended_size(const FuStructEfiSection2 *st)
873
1.19k
{
874
1.19k
    g_return_val_if_fail(st != NULL, 0x0);
875
1.19k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
876
1.19k
}
877
878
/* setters */
879
/**
880
 * fu_struct_efi_section2_to_string: (skip):
881
 **/
882
static gchar *
883
fu_struct_efi_section2_to_string(const FuStructEfiSection2 *st)
884
0
{
885
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSection2:\n");
886
0
    g_return_val_if_fail(st != NULL, NULL);
887
0
    g_string_append_printf(str, "  extended_size: 0x%x\n",
888
0
                           (guint) fu_struct_efi_section2_get_extended_size(st));
889
0
    if (str->len > 0)
890
0
        g_string_set_size(str, str->len - 1);
891
0
    return g_string_free(g_steal_pointer(&str), FALSE);
892
0
}
893
static gboolean
894
fu_struct_efi_section2_validate_internal(FuStructEfiSection2 *st, GError **error)
895
1.19k
{
896
1.19k
    g_return_val_if_fail(st != NULL, FALSE);
897
1.19k
    {
898
1.19k
        GByteArray st_tmp = {
899
1.19k
            .data = (guint8*) st->data + 0x0,
900
1.19k
            .len = 4,
901
1.19k
        };
902
1.19k
        if (!fu_struct_efi_section_validate_internal(&st_tmp, error))
903
0
            return FALSE;
904
1.19k
    }
905
1.19k
    return TRUE;
906
1.19k
}
907
static gboolean
908
fu_struct_efi_section2_parse_internal(FuStructEfiSection2 *st, GError **error)
909
1.19k
{
910
1.19k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
911
0
        g_autofree gchar *str = fu_struct_efi_section2_to_string(st);
912
0
        g_debug("%s", str);
913
0
    }
914
1.19k
    if (!fu_struct_efi_section2_validate_internal(st, error))
915
0
        return FALSE;
916
1.19k
    return TRUE;
917
1.19k
}
918
/**
919
 * fu_struct_efi_section2_parse_stream: (skip):
920
 **/
921
FuStructEfiSection2 *
922
fu_struct_efi_section2_parse_stream(GInputStream *stream, gsize offset, GError **error)
923
1.21k
{
924
1.21k
    g_autoptr(GByteArray) st = NULL;
925
1.21k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
926
1.21k
    if (st == NULL) {
927
0
        g_prefix_error(error, "FuStructEfiSection2 failed read of 0x%x: ", (guint) 8);
928
0
        return NULL;
929
0
    }
930
1.21k
    if (st->len != 8) {
931
21
        g_set_error(error,
932
21
                    FWUPD_ERROR,
933
21
                    FWUPD_ERROR_INVALID_DATA,
934
21
                    "FuStructEfiSection2 requested 0x%x and got 0x%x",
935
21
                    (guint) 8,
936
21
                    (guint) st->len);
937
21
        return NULL;
938
21
    }
939
1.19k
    if (!fu_struct_efi_section2_parse_internal(st, error))
940
0
        return NULL;
941
1.19k
    return g_steal_pointer(&st);
942
1.19k
}
943
/* getters */
944
/**
945
 * fu_struct_efi_section_freeform_subtype_guid_get_guid: (skip):
946
 **/
947
const fwupd_guid_t *
948
fu_struct_efi_section_freeform_subtype_guid_get_guid(const FuStructEfiSectionFreeformSubtypeGuid *st)
949
314
{
950
314
    g_return_val_if_fail(st != NULL, NULL);
951
314
    return (const fwupd_guid_t *) (st->data + 0);
952
314
}
953
954
/* setters */
955
/**
956
 * fu_struct_efi_section_freeform_subtype_guid_to_string: (skip):
957
 **/
958
static gchar *
959
fu_struct_efi_section_freeform_subtype_guid_to_string(const FuStructEfiSectionFreeformSubtypeGuid *st)
960
0
{
961
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSectionFreeformSubtypeGuid:\n");
962
0
    g_return_val_if_fail(st != NULL, NULL);
963
0
    {
964
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_freeform_subtype_guid_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
965
0
        g_string_append_printf(str, "  guid: %s\n", tmp);
966
0
    }
967
0
    if (str->len > 0)
968
0
        g_string_set_size(str, str->len - 1);
969
0
    return g_string_free(g_steal_pointer(&str), FALSE);
970
0
}
971
static gboolean
972
fu_struct_efi_section_freeform_subtype_guid_validate_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error)
973
314
{
974
314
    g_return_val_if_fail(st != NULL, FALSE);
975
314
    return TRUE;
976
314
}
977
static gboolean
978
fu_struct_efi_section_freeform_subtype_guid_parse_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error)
979
314
{
980
314
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
981
0
        g_autofree gchar *str = fu_struct_efi_section_freeform_subtype_guid_to_string(st);
982
0
        g_debug("%s", str);
983
0
    }
984
314
    if (!fu_struct_efi_section_freeform_subtype_guid_validate_internal(st, error))
985
0
        return FALSE;
986
314
    return TRUE;
987
314
}
988
/**
989
 * fu_struct_efi_section_freeform_subtype_guid_parse_stream: (skip):
990
 **/
991
FuStructEfiSectionFreeformSubtypeGuid *
992
fu_struct_efi_section_freeform_subtype_guid_parse_stream(GInputStream *stream, gsize offset, GError **error)
993
336
{
994
336
    g_autoptr(GByteArray) st = NULL;
995
336
    st = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error);
996
336
    if (st == NULL) {
997
4
        g_prefix_error(error, "FuStructEfiSectionFreeformSubtypeGuid failed read of 0x%x: ", (guint) 16);
998
4
        return NULL;
999
4
    }
1000
332
    if (st->len != 16) {
1001
18
        g_set_error(error,
1002
18
                    FWUPD_ERROR,
1003
18
                    FWUPD_ERROR_INVALID_DATA,
1004
18
                    "FuStructEfiSectionFreeformSubtypeGuid requested 0x%x and got 0x%x",
1005
18
                    (guint) 16,
1006
18
                    (guint) st->len);
1007
18
        return NULL;
1008
18
    }
1009
314
    if (!fu_struct_efi_section_freeform_subtype_guid_parse_internal(st, error))
1010
0
        return NULL;
1011
314
    return g_steal_pointer(&st);
1012
314
}
1013
/* getters */
1014
/**
1015
 * fu_struct_efi_section_guid_defined_get_name: (skip):
1016
 **/
1017
const fwupd_guid_t *
1018
fu_struct_efi_section_guid_defined_get_name(const FuStructEfiSectionGuidDefined *st)
1019
7.03k
{
1020
7.03k
    g_return_val_if_fail(st != NULL, NULL);
1021
7.03k
    return (const fwupd_guid_t *) (st->data + 0);
1022
7.03k
}
1023
/**
1024
 * fu_struct_efi_section_guid_defined_get_offset: (skip):
1025
 **/
1026
guint16
1027
fu_struct_efi_section_guid_defined_get_offset(const FuStructEfiSectionGuidDefined *st)
1028
14.0k
{
1029
14.0k
    g_return_val_if_fail(st != NULL, 0x0);
1030
14.0k
    return fu_memread_uint16(st->data + 16, G_LITTLE_ENDIAN);
1031
14.0k
}
1032
/**
1033
 * fu_struct_efi_section_guid_defined_get_attr: (skip):
1034
 **/
1035
guint16
1036
fu_struct_efi_section_guid_defined_get_attr(const FuStructEfiSectionGuidDefined *st)
1037
0
{
1038
0
    g_return_val_if_fail(st != NULL, 0x0);
1039
0
    return fu_memread_uint16(st->data + 18, G_LITTLE_ENDIAN);
1040
0
}
1041
1042
/* setters */
1043
/**
1044
 * fu_struct_efi_section_guid_defined_set_name: (skip):
1045
 **/
1046
void
1047
fu_struct_efi_section_guid_defined_set_name(FuStructEfiSectionGuidDefined *st, const fwupd_guid_t *value)
1048
1.59k
{
1049
1.59k
    g_return_if_fail(st != NULL);
1050
1.59k
    g_return_if_fail(value != NULL);
1051
1.59k
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
1052
1.59k
}
1053
/**
1054
 * fu_struct_efi_section_guid_defined_set_offset: (skip):
1055
 **/
1056
void
1057
fu_struct_efi_section_guid_defined_set_offset(FuStructEfiSectionGuidDefined *st, guint16 value)
1058
1.59k
{
1059
1.59k
    g_return_if_fail(st != NULL);
1060
1.59k
    fu_memwrite_uint16(st->data + 16, value, G_LITTLE_ENDIAN);
1061
1.59k
}
1062
/**
1063
 * fu_struct_efi_section_guid_defined_set_attr: (skip):
1064
 **/
1065
void
1066
fu_struct_efi_section_guid_defined_set_attr(FuStructEfiSectionGuidDefined *st, guint16 value)
1067
0
{
1068
0
    g_return_if_fail(st != NULL);
1069
0
    fu_memwrite_uint16(st->data + 18, value, G_LITTLE_ENDIAN);
1070
0
}
1071
/**
1072
 * fu_struct_efi_section_guid_defined_new: (skip):
1073
 **/
1074
FuStructEfiSectionGuidDefined *
1075
fu_struct_efi_section_guid_defined_new(void)
1076
1.59k
{
1077
1.59k
    FuStructEfiSectionGuidDefined *st = g_byte_array_sized_new(20);
1078
1.59k
    fu_byte_array_set_size(st, 20, 0x0);
1079
1.59k
    return st;
1080
1.59k
}
1081
/**
1082
 * fu_struct_efi_section_guid_defined_to_string: (skip):
1083
 **/
1084
static gchar *
1085
fu_struct_efi_section_guid_defined_to_string(const FuStructEfiSectionGuidDefined *st)
1086
0
{
1087
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSectionGuidDefined:\n");
1088
0
    g_return_val_if_fail(st != NULL, NULL);
1089
0
    {
1090
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_section_guid_defined_get_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
1091
0
        g_string_append_printf(str, "  name: %s\n", tmp);
1092
0
    }
1093
0
    g_string_append_printf(str, "  offset: 0x%x\n",
1094
0
                           (guint) fu_struct_efi_section_guid_defined_get_offset(st));
1095
0
    g_string_append_printf(str, "  attr: 0x%x\n",
1096
0
                           (guint) fu_struct_efi_section_guid_defined_get_attr(st));
1097
0
    if (str->len > 0)
1098
0
        g_string_set_size(str, str->len - 1);
1099
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1100
0
}
1101
static gboolean
1102
fu_struct_efi_section_guid_defined_validate_internal(FuStructEfiSectionGuidDefined *st, GError **error)
1103
7.03k
{
1104
7.03k
    g_return_val_if_fail(st != NULL, FALSE);
1105
7.03k
    return TRUE;
1106
7.03k
}
1107
static gboolean
1108
fu_struct_efi_section_guid_defined_parse_internal(FuStructEfiSectionGuidDefined *st, GError **error)
1109
7.03k
{
1110
7.03k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1111
0
        g_autofree gchar *str = fu_struct_efi_section_guid_defined_to_string(st);
1112
0
        g_debug("%s", str);
1113
0
    }
1114
7.03k
    if (!fu_struct_efi_section_guid_defined_validate_internal(st, error))
1115
0
        return FALSE;
1116
7.03k
    return TRUE;
1117
7.03k
}
1118
/**
1119
 * fu_struct_efi_section_guid_defined_parse_stream: (skip):
1120
 **/
1121
FuStructEfiSectionGuidDefined *
1122
fu_struct_efi_section_guid_defined_parse_stream(GInputStream *stream, gsize offset, GError **error)
1123
7.06k
{
1124
7.06k
    g_autoptr(GByteArray) st = NULL;
1125
7.06k
    st = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error);
1126
7.06k
    if (st == NULL) {
1127
2
        g_prefix_error(error, "FuStructEfiSectionGuidDefined failed read of 0x%x: ", (guint) 20);
1128
2
        return NULL;
1129
2
    }
1130
7.06k
    if (st->len != 20) {
1131
21
        g_set_error(error,
1132
21
                    FWUPD_ERROR,
1133
21
                    FWUPD_ERROR_INVALID_DATA,
1134
21
                    "FuStructEfiSectionGuidDefined requested 0x%x and got 0x%x",
1135
21
                    (guint) 20,
1136
21
                    (guint) st->len);
1137
21
        return NULL;
1138
21
    }
1139
7.03k
    if (!fu_struct_efi_section_guid_defined_parse_internal(st, error))
1140
0
        return NULL;
1141
7.03k
    return g_steal_pointer(&st);
1142
7.03k
}
1143
/* getters */
1144
/**
1145
 * fu_struct_efi_volume_get_zero_vector: (skip):
1146
 **/
1147
const fwupd_guid_t *
1148
fu_struct_efi_volume_get_zero_vector(const FuStructEfiVolume *st)
1149
0
{
1150
0
    g_return_val_if_fail(st != NULL, NULL);
1151
0
    return (const fwupd_guid_t *) (st->data + 0);
1152
0
}
1153
/**
1154
 * fu_struct_efi_volume_get_guid: (skip):
1155
 **/
1156
const fwupd_guid_t *
1157
fu_struct_efi_volume_get_guid(const FuStructEfiVolume *st)
1158
9.25k
{
1159
9.25k
    g_return_val_if_fail(st != NULL, NULL);
1160
9.25k
    return (const fwupd_guid_t *) (st->data + 16);
1161
9.25k
}
1162
/**
1163
 * fu_struct_efi_volume_get_length: (skip):
1164
 **/
1165
guint64
1166
fu_struct_efi_volume_get_length(const FuStructEfiVolume *st)
1167
9.25k
{
1168
9.25k
    g_return_val_if_fail(st != NULL, 0x0);
1169
9.25k
    return fu_memread_uint64(st->data + 32, G_LITTLE_ENDIAN);
1170
9.25k
}
1171
/**
1172
 * fu_struct_efi_volume_get_signature: (skip):
1173
 **/
1174
static guint32
1175
fu_struct_efi_volume_get_signature(const FuStructEfiVolume *st)
1176
8.21M
{
1177
8.21M
    g_return_val_if_fail(st != NULL, 0x0);
1178
8.21M
    return fu_memread_uint32(st->data + 40, G_LITTLE_ENDIAN);
1179
8.21M
}
1180
/**
1181
 * fu_struct_efi_volume_get_attrs: (skip):
1182
 **/
1183
guint32
1184
fu_struct_efi_volume_get_attrs(const FuStructEfiVolume *st)
1185
9.22k
{
1186
9.22k
    g_return_val_if_fail(st != NULL, 0x0);
1187
9.22k
    return fu_memread_uint32(st->data + 44, G_LITTLE_ENDIAN);
1188
9.22k
}
1189
/**
1190
 * fu_struct_efi_volume_get_hdr_len: (skip):
1191
 **/
1192
guint16
1193
fu_struct_efi_volume_get_hdr_len(const FuStructEfiVolume *st)
1194
8.79k
{
1195
8.79k
    g_return_val_if_fail(st != NULL, 0x0);
1196
8.79k
    return fu_memread_uint16(st->data + 48, G_LITTLE_ENDIAN);
1197
8.79k
}
1198
/**
1199
 * fu_struct_efi_volume_get_checksum: (skip):
1200
 **/
1201
guint16
1202
fu_struct_efi_volume_get_checksum(const FuStructEfiVolume *st)
1203
608
{
1204
608
    g_return_val_if_fail(st != NULL, 0x0);
1205
608
    return fu_memread_uint16(st->data + 50, G_LITTLE_ENDIAN);
1206
608
}
1207
/**
1208
 * fu_struct_efi_volume_get_ext_hdr: (skip):
1209
 **/
1210
guint16
1211
fu_struct_efi_volume_get_ext_hdr(const FuStructEfiVolume *st)
1212
6.80k
{
1213
6.80k
    g_return_val_if_fail(st != NULL, 0x0);
1214
6.80k
    return fu_memread_uint16(st->data + 52, G_LITTLE_ENDIAN);
1215
6.80k
}
1216
/**
1217
 * fu_struct_efi_volume_get_revision: (skip):
1218
 **/
1219
static guint8
1220
fu_struct_efi_volume_get_revision(const FuStructEfiVolume *st)
1221
19.3k
{
1222
19.3k
    g_return_val_if_fail(st != NULL, 0x0);
1223
19.3k
    return st->data[55];
1224
19.3k
}
1225
1226
/* setters */
1227
/**
1228
 * fu_struct_efi_volume_set_zero_vector: (skip):
1229
 **/
1230
void
1231
fu_struct_efi_volume_set_zero_vector(FuStructEfiVolume *st, const fwupd_guid_t *value)
1232
0
{
1233
0
    g_return_if_fail(st != NULL);
1234
0
    g_return_if_fail(value != NULL);
1235
0
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
1236
0
}
1237
/**
1238
 * fu_struct_efi_volume_set_guid: (skip):
1239
 **/
1240
void
1241
fu_struct_efi_volume_set_guid(FuStructEfiVolume *st, const fwupd_guid_t *value)
1242
2.16k
{
1243
2.16k
    g_return_if_fail(st != NULL);
1244
2.16k
    g_return_if_fail(value != NULL);
1245
2.16k
    memcpy(st->data + 16, value, sizeof(*value)); /* nocheck:blocked */
1246
2.16k
}
1247
/**
1248
 * fu_struct_efi_volume_set_length: (skip):
1249
 **/
1250
void
1251
fu_struct_efi_volume_set_length(FuStructEfiVolume *st, guint64 value)
1252
2.16k
{
1253
2.16k
    g_return_if_fail(st != NULL);
1254
2.16k
    fu_memwrite_uint64(st->data + 32, value, G_LITTLE_ENDIAN);
1255
2.16k
}
1256
/**
1257
 * fu_struct_efi_volume_set_signature: (skip):
1258
 **/
1259
static void
1260
fu_struct_efi_volume_set_signature(FuStructEfiVolume *st, guint32 value)
1261
2.31k
{
1262
2.31k
    g_return_if_fail(st != NULL);
1263
2.31k
    fu_memwrite_uint32(st->data + 40, value, G_LITTLE_ENDIAN);
1264
2.31k
}
1265
/**
1266
 * fu_struct_efi_volume_set_attrs: (skip):
1267
 **/
1268
void
1269
fu_struct_efi_volume_set_attrs(FuStructEfiVolume *st, guint32 value)
1270
2.16k
{
1271
2.16k
    g_return_if_fail(st != NULL);
1272
2.16k
    fu_memwrite_uint32(st->data + 44, value, G_LITTLE_ENDIAN);
1273
2.16k
}
1274
/**
1275
 * fu_struct_efi_volume_set_hdr_len: (skip):
1276
 **/
1277
void
1278
fu_struct_efi_volume_set_hdr_len(FuStructEfiVolume *st, guint16 value)
1279
2.16k
{
1280
2.16k
    g_return_if_fail(st != NULL);
1281
2.16k
    fu_memwrite_uint16(st->data + 48, value, G_LITTLE_ENDIAN);
1282
2.16k
}
1283
/**
1284
 * fu_struct_efi_volume_set_checksum: (skip):
1285
 **/
1286
void
1287
fu_struct_efi_volume_set_checksum(FuStructEfiVolume *st, guint16 value)
1288
2.16k
{
1289
2.16k
    g_return_if_fail(st != NULL);
1290
2.16k
    fu_memwrite_uint16(st->data + 50, value, G_LITTLE_ENDIAN);
1291
2.16k
}
1292
/**
1293
 * fu_struct_efi_volume_set_ext_hdr: (skip):
1294
 **/
1295
void
1296
fu_struct_efi_volume_set_ext_hdr(FuStructEfiVolume *st, guint16 value)
1297
0
{
1298
0
    g_return_if_fail(st != NULL);
1299
0
    fu_memwrite_uint16(st->data + 52, value, G_LITTLE_ENDIAN);
1300
0
}
1301
/**
1302
 * fu_struct_efi_volume_set_revision: (skip):
1303
 **/
1304
static void
1305
fu_struct_efi_volume_set_revision(FuStructEfiVolume *st, guint8 value)
1306
2.31k
{
1307
2.31k
    g_return_if_fail(st != NULL);
1308
2.31k
    st->data[55] = value;
1309
2.31k
}
1310
/**
1311
 * fu_struct_efi_volume_new: (skip):
1312
 **/
1313
FuStructEfiVolume *
1314
fu_struct_efi_volume_new(void)
1315
2.31k
{
1316
2.31k
    FuStructEfiVolume *st = g_byte_array_sized_new(56);
1317
2.31k
    fu_byte_array_set_size(st, 56, 0x0);
1318
2.31k
    fu_struct_efi_volume_set_signature(st, 0x4856465F);
1319
2.31k
    fu_struct_efi_volume_set_revision(st, 0x02);
1320
2.31k
    return st;
1321
2.31k
}
1322
/**
1323
 * fu_struct_efi_volume_to_string: (skip):
1324
 **/
1325
static gchar *
1326
fu_struct_efi_volume_to_string(const FuStructEfiVolume *st)
1327
0
{
1328
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolume:\n");
1329
0
    g_return_val_if_fail(st != NULL, NULL);
1330
0
    {
1331
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_zero_vector(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
1332
0
        g_string_append_printf(str, "  zero_vector: %s\n", tmp);
1333
0
    }
1334
0
    {
1335
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_get_guid(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
1336
0
        g_string_append_printf(str, "  guid: %s\n", tmp);
1337
0
    }
1338
0
    g_string_append_printf(str, "  length: 0x%x\n",
1339
0
                           (guint) fu_struct_efi_volume_get_length(st));
1340
0
    g_string_append_printf(str, "  attrs: 0x%x\n",
1341
0
                           (guint) fu_struct_efi_volume_get_attrs(st));
1342
0
    g_string_append_printf(str, "  hdr_len: 0x%x\n",
1343
0
                           (guint) fu_struct_efi_volume_get_hdr_len(st));
1344
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
1345
0
                           (guint) fu_struct_efi_volume_get_checksum(st));
1346
0
    g_string_append_printf(str, "  ext_hdr: 0x%x\n",
1347
0
                           (guint) fu_struct_efi_volume_get_ext_hdr(st));
1348
0
    if (str->len > 0)
1349
0
        g_string_set_size(str, str->len - 1);
1350
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1351
0
}
1352
static gboolean
1353
fu_struct_efi_volume_validate_internal(FuStructEfiVolume *st, GError **error)
1354
4.11M
{
1355
4.11M
    g_return_val_if_fail(st != NULL, FALSE);
1356
4.11M
    if (fu_struct_efi_volume_get_signature(st) != 0x4856465F) {
1357
4.09M
        g_set_error(error,
1358
4.09M
                    FWUPD_ERROR,
1359
4.09M
                    FWUPD_ERROR_INVALID_DATA,
1360
4.09M
                    "constant FuStructEfiVolume.signature was not valid, "
1361
4.09M
                    "expected 0x%x and got 0x%x",
1362
4.09M
                    (guint) 0x4856465F,
1363
4.09M
                    (guint) fu_struct_efi_volume_get_signature(st));
1364
4.09M
        return FALSE;
1365
4.09M
    }
1366
19.3k
    if (fu_struct_efi_volume_get_revision(st) != 0x02) {
1367
865
        g_set_error_literal(error,
1368
865
                            FWUPD_ERROR,
1369
865
                            FWUPD_ERROR_INVALID_DATA,
1370
865
                            "constant FuStructEfiVolume.revision was not valid");
1371
865
        return FALSE;
1372
865
    }
1373
18.5k
    return TRUE;
1374
19.3k
}
1375
/**
1376
 * fu_struct_efi_volume_validate_stream: (skip):
1377
 **/
1378
gboolean
1379
fu_struct_efi_volume_validate_stream(GInputStream *stream, gsize offset, GError **error)
1380
4.11M
{
1381
4.11M
    g_autoptr(GByteArray) st = NULL;
1382
4.11M
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
1383
4.11M
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
1384
4.11M
    st = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error);
1385
4.11M
    if (st == NULL) {
1386
2
        g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56);
1387
2
        return FALSE;
1388
2
    }
1389
4.11M
    if (st->len != 56) {
1390
7.37k
        g_set_error(error,
1391
7.37k
                    FWUPD_ERROR,
1392
7.37k
                    FWUPD_ERROR_INVALID_DATA,
1393
7.37k
                    "FuStructEfiVolume requested 0x%x and got 0x%x",
1394
7.37k
                    (guint) 56,
1395
7.37k
                    (guint) st->len);
1396
7.37k
        return FALSE;
1397
7.37k
    }
1398
4.10M
    return fu_struct_efi_volume_validate_internal(st, error);
1399
4.11M
}
1400
static gboolean
1401
fu_struct_efi_volume_parse_internal(FuStructEfiVolume *st, GError **error)
1402
9.25k
{
1403
9.25k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1404
0
        g_autofree gchar *str = fu_struct_efi_volume_to_string(st);
1405
0
        g_debug("%s", str);
1406
0
    }
1407
9.25k
    if (!fu_struct_efi_volume_validate_internal(st, error))
1408
0
        return FALSE;
1409
9.25k
    return TRUE;
1410
9.25k
}
1411
/**
1412
 * fu_struct_efi_volume_parse_stream: (skip):
1413
 **/
1414
FuStructEfiVolume *
1415
fu_struct_efi_volume_parse_stream(GInputStream *stream, gsize offset, GError **error)
1416
9.25k
{
1417
9.25k
    g_autoptr(GByteArray) st = NULL;
1418
9.25k
    st = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error);
1419
9.25k
    if (st == NULL) {
1420
0
        g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56);
1421
0
        return NULL;
1422
0
    }
1423
9.25k
    if (st->len != 56) {
1424
0
        g_set_error(error,
1425
0
                    FWUPD_ERROR,
1426
0
                    FWUPD_ERROR_INVALID_DATA,
1427
0
                    "FuStructEfiVolume requested 0x%x and got 0x%x",
1428
0
                    (guint) 56,
1429
0
                    (guint) st->len);
1430
0
        return NULL;
1431
0
    }
1432
9.25k
    if (!fu_struct_efi_volume_parse_internal(st, error))
1433
0
        return NULL;
1434
9.25k
    return g_steal_pointer(&st);
1435
9.25k
}
1436
/* getters */
1437
/**
1438
 * fu_struct_efi_volume_ext_header_get_fv_name: (skip):
1439
 **/
1440
const fwupd_guid_t *
1441
fu_struct_efi_volume_ext_header_get_fv_name(const FuStructEfiVolumeExtHeader *st)
1442
0
{
1443
0
    g_return_val_if_fail(st != NULL, NULL);
1444
0
    return (const fwupd_guid_t *) (st->data + 0);
1445
0
}
1446
/**
1447
 * fu_struct_efi_volume_ext_header_get_size: (skip):
1448
 **/
1449
guint32
1450
fu_struct_efi_volume_ext_header_get_size(const FuStructEfiVolumeExtHeader *st)
1451
368
{
1452
368
    g_return_val_if_fail(st != NULL, 0x0);
1453
368
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
1454
368
}
1455
1456
/* setters */
1457
/**
1458
 * fu_struct_efi_volume_ext_header_to_string: (skip):
1459
 **/
1460
static gchar *
1461
fu_struct_efi_volume_ext_header_to_string(const FuStructEfiVolumeExtHeader *st)
1462
0
{
1463
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtHeader:\n");
1464
0
    g_return_val_if_fail(st != NULL, NULL);
1465
0
    {
1466
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_ext_header_get_fv_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
1467
0
        g_string_append_printf(str, "  fv_name: %s\n", tmp);
1468
0
    }
1469
0
    g_string_append_printf(str, "  size: 0x%x\n",
1470
0
                           (guint) fu_struct_efi_volume_ext_header_get_size(st));
1471
0
    if (str->len > 0)
1472
0
        g_string_set_size(str, str->len - 1);
1473
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1474
0
}
1475
static gboolean
1476
fu_struct_efi_volume_ext_header_validate_internal(FuStructEfiVolumeExtHeader *st, GError **error)
1477
368
{
1478
368
    g_return_val_if_fail(st != NULL, FALSE);
1479
368
    return TRUE;
1480
368
}
1481
static gboolean
1482
fu_struct_efi_volume_ext_header_parse_internal(FuStructEfiVolumeExtHeader *st, GError **error)
1483
368
{
1484
368
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1485
0
        g_autofree gchar *str = fu_struct_efi_volume_ext_header_to_string(st);
1486
0
        g_debug("%s", str);
1487
0
    }
1488
368
    if (!fu_struct_efi_volume_ext_header_validate_internal(st, error))
1489
0
        return FALSE;
1490
368
    return TRUE;
1491
368
}
1492
/**
1493
 * fu_struct_efi_volume_ext_header_parse_stream: (skip):
1494
 **/
1495
FuStructEfiVolumeExtHeader *
1496
fu_struct_efi_volume_ext_header_parse_stream(GInputStream *stream, gsize offset, GError **error)
1497
420
{
1498
420
    g_autoptr(GByteArray) st = NULL;
1499
420
    st = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error);
1500
420
    if (st == NULL) {
1501
44
        g_prefix_error(error, "FuStructEfiVolumeExtHeader failed read of 0x%x: ", (guint) 20);
1502
44
        return NULL;
1503
44
    }
1504
376
    if (st->len != 20) {
1505
8
        g_set_error(error,
1506
8
                    FWUPD_ERROR,
1507
8
                    FWUPD_ERROR_INVALID_DATA,
1508
8
                    "FuStructEfiVolumeExtHeader requested 0x%x and got 0x%x",
1509
8
                    (guint) 20,
1510
8
                    (guint) st->len);
1511
8
        return NULL;
1512
8
    }
1513
368
    if (!fu_struct_efi_volume_ext_header_parse_internal(st, error))
1514
0
        return NULL;
1515
368
    return g_steal_pointer(&st);
1516
368
}
1517
/* getters */
1518
/**
1519
 * fu_struct_efi_volume_ext_entry_get_size: (skip):
1520
 **/
1521
guint16
1522
fu_struct_efi_volume_ext_entry_get_size(const FuStructEfiVolumeExtEntry *st)
1523
9.98k
{
1524
9.98k
    g_return_val_if_fail(st != NULL, 0x0);
1525
9.98k
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
1526
9.98k
}
1527
/**
1528
 * fu_struct_efi_volume_ext_entry_get_type: (skip):
1529
 **/
1530
FuEfiVolumeExtEntryType
1531
fu_struct_efi_volume_ext_entry_get_type(const FuStructEfiVolumeExtEntry *st)
1532
0
{
1533
0
    g_return_val_if_fail(st != NULL, 0x0);
1534
0
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
1535
0
}
1536
1537
/* setters */
1538
/**
1539
 * fu_struct_efi_volume_ext_entry_to_string: (skip):
1540
 **/
1541
static gchar *
1542
fu_struct_efi_volume_ext_entry_to_string(const FuStructEfiVolumeExtEntry *st)
1543
0
{
1544
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtEntry:\n");
1545
0
    g_return_val_if_fail(st != NULL, NULL);
1546
0
    g_string_append_printf(str, "  size: 0x%x\n",
1547
0
                           (guint) fu_struct_efi_volume_ext_entry_get_size(st));
1548
0
    {
1549
0
        const gchar *tmp = fu_efi_volume_ext_entry_type_to_string(fu_struct_efi_volume_ext_entry_get_type(st));
1550
0
        if (tmp != NULL) {
1551
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st), tmp);
1552
0
        } else {
1553
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st));
1554
0
        }
1555
0
    }
1556
0
    if (str->len > 0)
1557
0
        g_string_set_size(str, str->len - 1);
1558
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1559
0
}
1560
static gboolean
1561
fu_struct_efi_volume_ext_entry_validate_internal(FuStructEfiVolumeExtEntry *st, GError **error)
1562
3.36k
{
1563
3.36k
    g_return_val_if_fail(st != NULL, FALSE);
1564
3.36k
    return TRUE;
1565
3.36k
}
1566
static gboolean
1567
fu_struct_efi_volume_ext_entry_parse_internal(FuStructEfiVolumeExtEntry *st, GError **error)
1568
3.36k
{
1569
3.36k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1570
0
        g_autofree gchar *str = fu_struct_efi_volume_ext_entry_to_string(st);
1571
0
        g_debug("%s", str);
1572
0
    }
1573
3.36k
    if (!fu_struct_efi_volume_ext_entry_validate_internal(st, error))
1574
0
        return FALSE;
1575
3.36k
    return TRUE;
1576
3.36k
}
1577
/**
1578
 * fu_struct_efi_volume_ext_entry_parse_stream: (skip):
1579
 **/
1580
FuStructEfiVolumeExtEntry *
1581
fu_struct_efi_volume_ext_entry_parse_stream(GInputStream *stream, gsize offset, GError **error)
1582
3.54k
{
1583
3.54k
    g_autoptr(GByteArray) st = NULL;
1584
3.54k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
1585
3.54k
    if (st == NULL) {
1586
157
        g_prefix_error(error, "FuStructEfiVolumeExtEntry failed read of 0x%x: ", (guint) 4);
1587
157
        return NULL;
1588
157
    }
1589
3.38k
    if (st->len != 4) {
1590
25
        g_set_error(error,
1591
25
                    FWUPD_ERROR,
1592
25
                    FWUPD_ERROR_INVALID_DATA,
1593
25
                    "FuStructEfiVolumeExtEntry requested 0x%x and got 0x%x",
1594
25
                    (guint) 4,
1595
25
                    (guint) st->len);
1596
25
        return NULL;
1597
25
    }
1598
3.36k
    if (!fu_struct_efi_volume_ext_entry_parse_internal(st, error))
1599
0
        return NULL;
1600
3.36k
    return g_steal_pointer(&st);
1601
3.36k
}
1602
/* getters */
1603
/**
1604
 * fu_struct_efi_volume_block_map_get_num_blocks: (skip):
1605
 **/
1606
guint32
1607
fu_struct_efi_volume_block_map_get_num_blocks(const FuStructEfiVolumeBlockMap *st)
1608
359k
{
1609
359k
    g_return_val_if_fail(st != NULL, 0x0);
1610
359k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
1611
359k
}
1612
/**
1613
 * fu_struct_efi_volume_block_map_get_length: (skip):
1614
 **/
1615
guint32
1616
fu_struct_efi_volume_block_map_get_length(const FuStructEfiVolumeBlockMap *st)
1617
359k
{
1618
359k
    g_return_val_if_fail(st != NULL, 0x0);
1619
359k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
1620
359k
}
1621
1622
/* setters */
1623
/**
1624
 * fu_struct_efi_volume_block_map_set_num_blocks: (skip):
1625
 **/
1626
void
1627
fu_struct_efi_volume_block_map_set_num_blocks(FuStructEfiVolumeBlockMap *st, guint32 value)
1628
4.32k
{
1629
4.32k
    g_return_if_fail(st != NULL);
1630
4.32k
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
1631
4.32k
}
1632
/**
1633
 * fu_struct_efi_volume_block_map_set_length: (skip):
1634
 **/
1635
void
1636
fu_struct_efi_volume_block_map_set_length(FuStructEfiVolumeBlockMap *st, guint32 value)
1637
4.32k
{
1638
4.32k
    g_return_if_fail(st != NULL);
1639
4.32k
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
1640
4.32k
}
1641
/**
1642
 * fu_struct_efi_volume_block_map_new: (skip):
1643
 **/
1644
FuStructEfiVolumeBlockMap *
1645
fu_struct_efi_volume_block_map_new(void)
1646
2.31k
{
1647
2.31k
    FuStructEfiVolumeBlockMap *st = g_byte_array_sized_new(8);
1648
2.31k
    fu_byte_array_set_size(st, 8, 0x0);
1649
2.31k
    return st;
1650
2.31k
}
1651
/**
1652
 * fu_struct_efi_volume_block_map_to_string: (skip):
1653
 **/
1654
static gchar *
1655
fu_struct_efi_volume_block_map_to_string(const FuStructEfiVolumeBlockMap *st)
1656
0
{
1657
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeBlockMap:\n");
1658
0
    g_return_val_if_fail(st != NULL, NULL);
1659
0
    g_string_append_printf(str, "  num_blocks: 0x%x\n",
1660
0
                           (guint) fu_struct_efi_volume_block_map_get_num_blocks(st));
1661
0
    g_string_append_printf(str, "  length: 0x%x\n",
1662
0
                           (guint) fu_struct_efi_volume_block_map_get_length(st));
1663
0
    if (str->len > 0)
1664
0
        g_string_set_size(str, str->len - 1);
1665
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1666
0
}
1667
static gboolean
1668
fu_struct_efi_volume_block_map_validate_internal(FuStructEfiVolumeBlockMap *st, GError **error)
1669
359k
{
1670
359k
    g_return_val_if_fail(st != NULL, FALSE);
1671
359k
    return TRUE;
1672
359k
}
1673
static gboolean
1674
fu_struct_efi_volume_block_map_parse_internal(FuStructEfiVolumeBlockMap *st, GError **error)
1675
359k
{
1676
359k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1677
0
        g_autofree gchar *str = fu_struct_efi_volume_block_map_to_string(st);
1678
0
        g_debug("%s", str);
1679
0
    }
1680
359k
    if (!fu_struct_efi_volume_block_map_validate_internal(st, error))
1681
0
        return FALSE;
1682
359k
    return TRUE;
1683
359k
}
1684
/**
1685
 * fu_struct_efi_volume_block_map_parse_stream: (skip):
1686
 **/
1687
FuStructEfiVolumeBlockMap *
1688
fu_struct_efi_volume_block_map_parse_stream(GInputStream *stream, gsize offset, GError **error)
1689
359k
{
1690
359k
    g_autoptr(GByteArray) st = NULL;
1691
359k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
1692
359k
    if (st == NULL) {
1693
0
        g_prefix_error(error, "FuStructEfiVolumeBlockMap failed read of 0x%x: ", (guint) 8);
1694
0
        return NULL;
1695
0
    }
1696
359k
    if (st->len != 8) {
1697
119
        g_set_error(error,
1698
119
                    FWUPD_ERROR,
1699
119
                    FWUPD_ERROR_INVALID_DATA,
1700
119
                    "FuStructEfiVolumeBlockMap requested 0x%x and got 0x%x",
1701
119
                    (guint) 8,
1702
119
                    (guint) st->len);
1703
119
        return NULL;
1704
119
    }
1705
359k
    if (!fu_struct_efi_volume_block_map_parse_internal(st, error))
1706
0
        return NULL;
1707
359k
    return g_steal_pointer(&st);
1708
359k
}
1709
/* getters */
1710
/**
1711
 * fu_struct_efi_time_get_year: (skip):
1712
 **/
1713
guint16
1714
fu_struct_efi_time_get_year(const FuStructEfiTime *st)
1715
0
{
1716
0
    g_return_val_if_fail(st != NULL, 0x0);
1717
0
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
1718
0
}
1719
/**
1720
 * fu_struct_efi_time_get_month: (skip):
1721
 **/
1722
guint8
1723
fu_struct_efi_time_get_month(const FuStructEfiTime *st)
1724
0
{
1725
0
    g_return_val_if_fail(st != NULL, 0x0);
1726
0
    return st->data[2];
1727
0
}
1728
/**
1729
 * fu_struct_efi_time_get_day: (skip):
1730
 **/
1731
guint8
1732
fu_struct_efi_time_get_day(const FuStructEfiTime *st)
1733
0
{
1734
0
    g_return_val_if_fail(st != NULL, 0x0);
1735
0
    return st->data[3];
1736
0
}
1737
/**
1738
 * fu_struct_efi_time_get_hour: (skip):
1739
 **/
1740
guint8
1741
fu_struct_efi_time_get_hour(const FuStructEfiTime *st)
1742
0
{
1743
0
    g_return_val_if_fail(st != NULL, 0x0);
1744
0
    return st->data[4];
1745
0
}
1746
/**
1747
 * fu_struct_efi_time_get_minute: (skip):
1748
 **/
1749
guint8
1750
fu_struct_efi_time_get_minute(const FuStructEfiTime *st)
1751
0
{
1752
0
    g_return_val_if_fail(st != NULL, 0x0);
1753
0
    return st->data[5];
1754
0
}
1755
/**
1756
 * fu_struct_efi_time_get_second: (skip):
1757
 **/
1758
guint8
1759
fu_struct_efi_time_get_second(const FuStructEfiTime *st)
1760
0
{
1761
0
    g_return_val_if_fail(st != NULL, 0x0);
1762
0
    return st->data[6];
1763
0
}
1764
/**
1765
 * fu_struct_efi_time_get_nanosecond: (skip):
1766
 **/
1767
guint32
1768
fu_struct_efi_time_get_nanosecond(const FuStructEfiTime *st)
1769
0
{
1770
0
    g_return_val_if_fail(st != NULL, 0x0);
1771
0
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
1772
0
}
1773
/**
1774
 * fu_struct_efi_time_get_timezone: (skip):
1775
 **/
1776
guint16
1777
fu_struct_efi_time_get_timezone(const FuStructEfiTime *st)
1778
0
{
1779
0
    g_return_val_if_fail(st != NULL, 0x0);
1780
0
    return fu_memread_uint16(st->data + 12, G_LITTLE_ENDIAN);
1781
0
}
1782
/**
1783
 * fu_struct_efi_time_get_daylight: (skip):
1784
 **/
1785
guint8
1786
fu_struct_efi_time_get_daylight(const FuStructEfiTime *st)
1787
0
{
1788
0
    g_return_val_if_fail(st != NULL, 0x0);
1789
0
    return st->data[14];
1790
0
}
1791
1792
/* setters */
1793
/**
1794
 * fu_struct_efi_time_new: (skip):
1795
 **/
1796
static FuStructEfiTime *
1797
fu_struct_efi_time_new(void)
1798
0
{
1799
0
    FuStructEfiTime *st = g_byte_array_sized_new(16);
1800
0
    fu_byte_array_set_size(st, 16, 0x0);
1801
0
    return st;
1802
0
}
1803
/**
1804
 * fu_struct_efi_time_to_string: (skip):
1805
 **/
1806
static gchar *
1807
fu_struct_efi_time_to_string(const FuStructEfiTime *st)
1808
0
{
1809
0
    g_autoptr(GString) str = g_string_new("FuStructEfiTime:\n");
1810
0
    g_return_val_if_fail(st != NULL, NULL);
1811
0
    g_string_append_printf(str, "  year: 0x%x\n",
1812
0
                           (guint) fu_struct_efi_time_get_year(st));
1813
0
    g_string_append_printf(str, "  month: 0x%x\n",
1814
0
                           (guint) fu_struct_efi_time_get_month(st));
1815
0
    g_string_append_printf(str, "  day: 0x%x\n",
1816
0
                           (guint) fu_struct_efi_time_get_day(st));
1817
0
    g_string_append_printf(str, "  hour: 0x%x\n",
1818
0
                           (guint) fu_struct_efi_time_get_hour(st));
1819
0
    g_string_append_printf(str, "  minute: 0x%x\n",
1820
0
                           (guint) fu_struct_efi_time_get_minute(st));
1821
0
    g_string_append_printf(str, "  second: 0x%x\n",
1822
0
                           (guint) fu_struct_efi_time_get_second(st));
1823
0
    g_string_append_printf(str, "  nanosecond: 0x%x\n",
1824
0
                           (guint) fu_struct_efi_time_get_nanosecond(st));
1825
0
    g_string_append_printf(str, "  timezone: 0x%x\n",
1826
0
                           (guint) fu_struct_efi_time_get_timezone(st));
1827
0
    g_string_append_printf(str, "  daylight: 0x%x\n",
1828
0
                           (guint) fu_struct_efi_time_get_daylight(st));
1829
0
    if (str->len > 0)
1830
0
        g_string_set_size(str, str->len - 1);
1831
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1832
0
}
1833
static gboolean
1834
fu_struct_efi_time_validate_internal(FuStructEfiTime *st, GError **error)
1835
0
{
1836
0
    g_return_val_if_fail(st != NULL, FALSE);
1837
0
    return TRUE;
1838
0
}
1839
/* getters */
1840
/**
1841
 * fu_struct_efi_win_certificate_get_length: (skip):
1842
 **/
1843
guint32
1844
fu_struct_efi_win_certificate_get_length(const FuStructEfiWinCertificate *st)
1845
0
{
1846
0
    g_return_val_if_fail(st != NULL, 0x0);
1847
0
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
1848
0
}
1849
/**
1850
 * fu_struct_efi_win_certificate_get_revision: (skip):
1851
 **/
1852
static guint16
1853
fu_struct_efi_win_certificate_get_revision(const FuStructEfiWinCertificate *st)
1854
0
{
1855
0
    g_return_val_if_fail(st != NULL, 0x0);
1856
0
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
1857
0
}
1858
/**
1859
 * fu_struct_efi_win_certificate_get_certificate_type: (skip):
1860
 **/
1861
static guint16
1862
fu_struct_efi_win_certificate_get_certificate_type(const FuStructEfiWinCertificate *st)
1863
0
{
1864
0
    g_return_val_if_fail(st != NULL, 0x0);
1865
0
    return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN);
1866
0
}
1867
/**
1868
 * fu_struct_efi_win_certificate_get_guid: (skip):
1869
 **/
1870
static const fwupd_guid_t *
1871
fu_struct_efi_win_certificate_get_guid(const FuStructEfiWinCertificate *st)
1872
0
{
1873
0
    g_return_val_if_fail(st != NULL, NULL);
1874
0
    return (const fwupd_guid_t *) (st->data + 8);
1875
0
}
1876
1877
/* setters */
1878
/**
1879
 * fu_struct_efi_win_certificate_set_length: (skip):
1880
 **/
1881
void
1882
fu_struct_efi_win_certificate_set_length(FuStructEfiWinCertificate *st, guint32 value)
1883
0
{
1884
0
    g_return_if_fail(st != NULL);
1885
0
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
1886
0
}
1887
/**
1888
 * fu_struct_efi_win_certificate_set_revision: (skip):
1889
 **/
1890
static void
1891
fu_struct_efi_win_certificate_set_revision(FuStructEfiWinCertificate *st, guint16 value)
1892
0
{
1893
0
    g_return_if_fail(st != NULL);
1894
0
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
1895
0
}
1896
/**
1897
 * fu_struct_efi_win_certificate_set_certificate_type: (skip):
1898
 **/
1899
static void
1900
fu_struct_efi_win_certificate_set_certificate_type(FuStructEfiWinCertificate *st, guint16 value)
1901
0
{
1902
0
    g_return_if_fail(st != NULL);
1903
0
    fu_memwrite_uint16(st->data + 6, value, G_LITTLE_ENDIAN);
1904
0
}
1905
/**
1906
 * fu_struct_efi_win_certificate_set_guid: (skip):
1907
 **/
1908
static void
1909
fu_struct_efi_win_certificate_set_guid(FuStructEfiWinCertificate *st, const fwupd_guid_t *value)
1910
0
{
1911
0
    g_return_if_fail(st != NULL);
1912
0
    g_return_if_fail(value != NULL);
1913
0
    memcpy(st->data + 8, value, sizeof(*value)); /* nocheck:blocked */
1914
0
}
1915
/**
1916
 * fu_struct_efi_win_certificate_new: (skip):
1917
 **/
1918
static FuStructEfiWinCertificate *
1919
fu_struct_efi_win_certificate_new(void)
1920
0
{
1921
0
    FuStructEfiWinCertificate *st = g_byte_array_sized_new(24);
1922
0
    fu_byte_array_set_size(st, 24, 0x0);
1923
0
    fu_struct_efi_win_certificate_set_length(st, 24);
1924
0
    fu_struct_efi_win_certificate_set_revision(st, 0x0200);
1925
0
    fu_struct_efi_win_certificate_set_certificate_type(st, 0x0EF1);
1926
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");
1927
0
    return st;
1928
0
}
1929
/**
1930
 * fu_struct_efi_win_certificate_to_string: (skip):
1931
 **/
1932
static gchar *
1933
fu_struct_efi_win_certificate_to_string(const FuStructEfiWinCertificate *st)
1934
0
{
1935
0
    g_autoptr(GString) str = g_string_new("FuStructEfiWinCertificate:\n");
1936
0
    g_return_val_if_fail(st != NULL, NULL);
1937
0
    g_string_append_printf(str, "  length: 0x%x\n",
1938
0
                           (guint) fu_struct_efi_win_certificate_get_length(st));
1939
0
    if (str->len > 0)
1940
0
        g_string_set_size(str, str->len - 1);
1941
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1942
0
}
1943
static gboolean
1944
fu_struct_efi_win_certificate_validate_internal(FuStructEfiWinCertificate *st, GError **error)
1945
0
{
1946
0
    g_return_val_if_fail(st != NULL, FALSE);
1947
0
    if (fu_struct_efi_win_certificate_get_revision(st) != 0x0200) {
1948
0
        g_set_error(error,
1949
0
                    FWUPD_ERROR,
1950
0
                    FWUPD_ERROR_INVALID_DATA,
1951
0
                    "constant FuStructEfiWinCertificate.revision was not valid, "
1952
0
                    "expected 0x%x and got 0x%x",
1953
0
                    (guint) 0x0200,
1954
0
                    (guint) fu_struct_efi_win_certificate_get_revision(st));
1955
0
        return FALSE;
1956
0
    }
1957
0
    if (fu_struct_efi_win_certificate_get_certificate_type(st) != 0x0EF1) {
1958
0
        g_set_error(error,
1959
0
                    FWUPD_ERROR,
1960
0
                    FWUPD_ERROR_INVALID_DATA,
1961
0
                    "constant FuStructEfiWinCertificate.certificate_type was not valid, "
1962
0
                    "expected 0x%x and got 0x%x",
1963
0
                    (guint) 0x0EF1,
1964
0
                    (guint) fu_struct_efi_win_certificate_get_certificate_type(st));
1965
0
        return FALSE;
1966
0
    }
1967
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) {
1968
0
        g_set_error_literal(error,
1969
0
                            FWUPD_ERROR,
1970
0
                            FWUPD_ERROR_INVALID_DATA,
1971
0
                            "constant FuStructEfiWinCertificate.guid was not valid");
1972
0
        return FALSE;
1973
0
    }
1974
0
    return TRUE;
1975
0
}
1976
/* getters */
1977
/**
1978
 * fu_struct_efi_variable_authentication2_get_timestamp: (skip):
1979
 **/
1980
FuStructEfiTime *
1981
fu_struct_efi_variable_authentication2_get_timestamp(const FuStructEfiVariableAuthentication2 *st)
1982
0
{
1983
0
    g_autoptr(GByteArray) buf = g_byte_array_new();
1984
0
    g_return_val_if_fail(st != NULL, NULL);
1985
0
    g_byte_array_append(buf, st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, 16);
1986
0
    return g_steal_pointer(&buf);
1987
0
}
1988
/**
1989
 * fu_struct_efi_variable_authentication2_get_auth_info: (skip):
1990
 **/
1991
FuStructEfiWinCertificate *
1992
fu_struct_efi_variable_authentication2_get_auth_info(const FuStructEfiVariableAuthentication2 *st)
1993
0
{
1994
0
    g_autoptr(GByteArray) buf = g_byte_array_new();
1995
0
    g_return_val_if_fail(st != NULL, NULL);
1996
0
    g_byte_array_append(buf, st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, 24);
1997
0
    return g_steal_pointer(&buf);
1998
0
}
1999
2000
/* setters */
2001
/**
2002
 * fu_struct_efi_variable_authentication2_set_timestamp: (skip):
2003
 **/
2004
gboolean
2005
fu_struct_efi_variable_authentication2_set_timestamp(FuStructEfiVariableAuthentication2 *st, const FuStructEfiTime *st_donor, GError **error)
2006
0
{
2007
0
    g_return_val_if_fail(st != NULL, FALSE);
2008
0
    g_return_val_if_fail(st_donor != NULL, FALSE);
2009
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2010
2011
0
    if (st_donor->len > FU_STRUCT_EFI_TIME_SIZE) {
2012
0
        g_set_error(error,
2013
0
                    FWUPD_ERROR,
2014
0
                    FWUPD_ERROR_INVALID_DATA,
2015
0
                    "donor 'FuStructEfiTime' (0x%x bytes) does not fit in "
2016
0
                    "FuStructEfiVariableAuthentication2.timestamp (0x%x bytes)",
2017
0
                    (guint) st_donor->len,
2018
0
                    (guint) FU_STRUCT_EFI_TIME_SIZE);
2019
0
        return FALSE;
2020
0
    }
2021
0
    memcpy(st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, st_donor->data, st_donor->len);
2022
0
    return TRUE;
2023
0
}
2024
/**
2025
 * fu_struct_efi_variable_authentication2_set_auth_info: (skip):
2026
 **/
2027
gboolean
2028
fu_struct_efi_variable_authentication2_set_auth_info(FuStructEfiVariableAuthentication2 *st, const FuStructEfiWinCertificate *st_donor, GError **error)
2029
0
{
2030
0
    g_return_val_if_fail(st != NULL, FALSE);
2031
0
    g_return_val_if_fail(st_donor != NULL, FALSE);
2032
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2033
2034
0
    if (st_donor->len > FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE) {
2035
0
        g_set_error(error,
2036
0
                    FWUPD_ERROR,
2037
0
                    FWUPD_ERROR_INVALID_DATA,
2038
0
                    "donor 'FuStructEfiWinCertificate' (0x%x bytes) does not fit in "
2039
0
                    "FuStructEfiVariableAuthentication2.auth_info (0x%x bytes)",
2040
0
                    (guint) st_donor->len,
2041
0
                    (guint) FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE);
2042
0
        return FALSE;
2043
0
    }
2044
0
    memcpy(st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, st_donor->data, st_donor->len);
2045
0
    return TRUE;
2046
0
}
2047
/**
2048
 * fu_struct_efi_variable_authentication2_new: (skip):
2049
 **/
2050
FuStructEfiVariableAuthentication2 *
2051
fu_struct_efi_variable_authentication2_new(void)
2052
0
{
2053
0
    FuStructEfiVariableAuthentication2 *st = g_byte_array_sized_new(40);
2054
0
    fu_byte_array_set_size(st, 40, 0x0);
2055
0
    {
2056
0
        g_autoptr(GByteArray) st_donor = fu_struct_efi_time_new();
2057
0
        memcpy(st->data + 0x0, st_donor->data, st_donor->len); /* nocheck:blocked */
2058
0
    }
2059
0
    {
2060
0
        g_autoptr(GByteArray) st_donor = fu_struct_efi_win_certificate_new();
2061
0
        memcpy(st->data + 0x10, st_donor->data, st_donor->len); /* nocheck:blocked */
2062
0
    }
2063
0
    return st;
2064
0
}
2065
/**
2066
 * fu_struct_efi_variable_authentication2_to_string: (skip):
2067
 **/
2068
static gchar *
2069
fu_struct_efi_variable_authentication2_to_string(const FuStructEfiVariableAuthentication2 *st)
2070
0
{
2071
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVariableAuthentication2:\n");
2072
0
    g_return_val_if_fail(st != NULL, NULL);
2073
0
    {
2074
0
        g_autoptr(GByteArray) st_tmp = fu_struct_efi_variable_authentication2_get_timestamp(st);
2075
0
        g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp);
2076
0
        g_string_append_printf(str, "  timestamp: %s\n", tmp);
2077
0
    }
2078
0
    {
2079
0
        g_autoptr(GByteArray) st_tmp = fu_struct_efi_variable_authentication2_get_auth_info(st);
2080
0
        g_autofree gchar *tmp = fu_struct_efi_win_certificate_to_string(st_tmp);
2081
0
        g_string_append_printf(str, "  auth_info: %s\n", tmp);
2082
0
    }
2083
0
    if (str->len > 0)
2084
0
        g_string_set_size(str, str->len - 1);
2085
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2086
0
}
2087
static gboolean
2088
fu_struct_efi_variable_authentication2_validate_internal(FuStructEfiVariableAuthentication2 *st, GError **error)
2089
0
{
2090
0
    g_return_val_if_fail(st != NULL, FALSE);
2091
0
    {
2092
0
        GByteArray st_tmp = {
2093
0
            .data = (guint8*) st->data + 0x0,
2094
0
            .len = 16,
2095
0
        };
2096
0
        if (!fu_struct_efi_time_validate_internal(&st_tmp, error))
2097
0
            return FALSE;
2098
0
    }
2099
0
    {
2100
0
        GByteArray st_tmp = {
2101
0
            .data = (guint8*) st->data + 0x10,
2102
0
            .len = 24,
2103
0
        };
2104
0
        if (!fu_struct_efi_win_certificate_validate_internal(&st_tmp, error))
2105
0
            return FALSE;
2106
0
    }
2107
0
    return TRUE;
2108
0
}
2109
/**
2110
 * fu_struct_efi_variable_authentication2_validate_stream: (skip):
2111
 **/
2112
gboolean
2113
fu_struct_efi_variable_authentication2_validate_stream(GInputStream *stream, gsize offset, GError **error)
2114
0
{
2115
0
    g_autoptr(GByteArray) st = NULL;
2116
0
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
2117
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2118
0
    st = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error);
2119
0
    if (st == NULL) {
2120
0
        g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40);
2121
0
        return FALSE;
2122
0
    }
2123
0
    if (st->len != 40) {
2124
0
        g_set_error(error,
2125
0
                    FWUPD_ERROR,
2126
0
                    FWUPD_ERROR_INVALID_DATA,
2127
0
                    "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x",
2128
0
                    (guint) 40,
2129
0
                    (guint) st->len);
2130
0
        return FALSE;
2131
0
    }
2132
0
    return fu_struct_efi_variable_authentication2_validate_internal(st, error);
2133
0
}
2134
static gboolean
2135
fu_struct_efi_variable_authentication2_parse_internal(FuStructEfiVariableAuthentication2 *st, GError **error)
2136
0
{
2137
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2138
0
        g_autofree gchar *str = fu_struct_efi_variable_authentication2_to_string(st);
2139
0
        g_debug("%s", str);
2140
0
    }
2141
0
    if (!fu_struct_efi_variable_authentication2_validate_internal(st, error))
2142
0
        return FALSE;
2143
0
    return TRUE;
2144
0
}
2145
/**
2146
 * fu_struct_efi_variable_authentication2_parse_stream: (skip):
2147
 **/
2148
FuStructEfiVariableAuthentication2 *
2149
fu_struct_efi_variable_authentication2_parse_stream(GInputStream *stream, gsize offset, GError **error)
2150
0
{
2151
0
    g_autoptr(GByteArray) st = NULL;
2152
0
    st = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error);
2153
0
    if (st == NULL) {
2154
0
        g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40);
2155
0
        return NULL;
2156
0
    }
2157
0
    if (st->len != 40) {
2158
0
        g_set_error(error,
2159
0
                    FWUPD_ERROR,
2160
0
                    FWUPD_ERROR_INVALID_DATA,
2161
0
                    "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x",
2162
0
                    (guint) 40,
2163
0
                    (guint) st->len);
2164
0
        return NULL;
2165
0
    }
2166
0
    if (!fu_struct_efi_variable_authentication2_parse_internal(st, error))
2167
0
        return NULL;
2168
0
    return g_steal_pointer(&st);
2169
0
}
2170
/* getters */
2171
/**
2172
 * fu_struct_efi_signature_list_get_type: (skip):
2173
 **/
2174
const fwupd_guid_t *
2175
fu_struct_efi_signature_list_get_type(const FuStructEfiSignatureList *st)
2176
0
{
2177
0
    g_return_val_if_fail(st != NULL, NULL);
2178
0
    return (const fwupd_guid_t *) (st->data + 0);
2179
0
}
2180
/**
2181
 * fu_struct_efi_signature_list_get_list_size: (skip):
2182
 **/
2183
guint32
2184
fu_struct_efi_signature_list_get_list_size(const FuStructEfiSignatureList *st)
2185
0
{
2186
0
    g_return_val_if_fail(st != NULL, 0x0);
2187
0
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
2188
0
}
2189
/**
2190
 * fu_struct_efi_signature_list_get_header_size: (skip):
2191
 **/
2192
guint32
2193
fu_struct_efi_signature_list_get_header_size(const FuStructEfiSignatureList *st)
2194
0
{
2195
0
    g_return_val_if_fail(st != NULL, 0x0);
2196
0
    return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN);
2197
0
}
2198
/**
2199
 * fu_struct_efi_signature_list_get_size: (skip):
2200
 **/
2201
guint32
2202
fu_struct_efi_signature_list_get_size(const FuStructEfiSignatureList *st)
2203
0
{
2204
0
    g_return_val_if_fail(st != NULL, 0x0);
2205
0
    return fu_memread_uint32(st->data + 24, G_LITTLE_ENDIAN);
2206
0
}
2207
2208
/* setters */
2209
/**
2210
 * fu_struct_efi_signature_list_set_type: (skip):
2211
 **/
2212
void
2213
fu_struct_efi_signature_list_set_type(FuStructEfiSignatureList *st, const fwupd_guid_t *value)
2214
0
{
2215
0
    g_return_if_fail(st != NULL);
2216
0
    g_return_if_fail(value != NULL);
2217
0
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
2218
0
}
2219
/**
2220
 * fu_struct_efi_signature_list_set_list_size: (skip):
2221
 **/
2222
void
2223
fu_struct_efi_signature_list_set_list_size(FuStructEfiSignatureList *st, guint32 value)
2224
0
{
2225
0
    g_return_if_fail(st != NULL);
2226
0
    fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN);
2227
0
}
2228
/**
2229
 * fu_struct_efi_signature_list_set_header_size: (skip):
2230
 **/
2231
void
2232
fu_struct_efi_signature_list_set_header_size(FuStructEfiSignatureList *st, guint32 value)
2233
0
{
2234
0
    g_return_if_fail(st != NULL);
2235
0
    fu_memwrite_uint32(st->data + 20, value, G_LITTLE_ENDIAN);
2236
0
}
2237
/**
2238
 * fu_struct_efi_signature_list_set_size: (skip):
2239
 **/
2240
void
2241
fu_struct_efi_signature_list_set_size(FuStructEfiSignatureList *st, guint32 value)
2242
0
{
2243
0
    g_return_if_fail(st != NULL);
2244
0
    fu_memwrite_uint32(st->data + 24, value, G_LITTLE_ENDIAN);
2245
0
}
2246
/**
2247
 * fu_struct_efi_signature_list_new: (skip):
2248
 **/
2249
FuStructEfiSignatureList *
2250
fu_struct_efi_signature_list_new(void)
2251
0
{
2252
0
    FuStructEfiSignatureList *st = g_byte_array_sized_new(28);
2253
0
    fu_byte_array_set_size(st, 28, 0x0);
2254
0
    return st;
2255
0
}
2256
/**
2257
 * fu_struct_efi_signature_list_to_string: (skip):
2258
 **/
2259
static gchar *
2260
fu_struct_efi_signature_list_to_string(const FuStructEfiSignatureList *st)
2261
0
{
2262
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSignatureList:\n");
2263
0
    g_return_val_if_fail(st != NULL, NULL);
2264
0
    {
2265
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_signature_list_get_type(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
2266
0
        g_string_append_printf(str, "  type: %s\n", tmp);
2267
0
    }
2268
0
    g_string_append_printf(str, "  list_size: 0x%x\n",
2269
0
                           (guint) fu_struct_efi_signature_list_get_list_size(st));
2270
0
    g_string_append_printf(str, "  header_size: 0x%x\n",
2271
0
                           (guint) fu_struct_efi_signature_list_get_header_size(st));
2272
0
    g_string_append_printf(str, "  size: 0x%x\n",
2273
0
                           (guint) fu_struct_efi_signature_list_get_size(st));
2274
0
    if (str->len > 0)
2275
0
        g_string_set_size(str, str->len - 1);
2276
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2277
0
}
2278
static gboolean
2279
fu_struct_efi_signature_list_validate_internal(FuStructEfiSignatureList *st, GError **error)
2280
0
{
2281
0
    g_return_val_if_fail(st != NULL, FALSE);
2282
0
    return TRUE;
2283
0
}
2284
static gboolean
2285
fu_struct_efi_signature_list_parse_internal(FuStructEfiSignatureList *st, GError **error)
2286
0
{
2287
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2288
0
        g_autofree gchar *str = fu_struct_efi_signature_list_to_string(st);
2289
0
        g_debug("%s", str);
2290
0
    }
2291
0
    if (!fu_struct_efi_signature_list_validate_internal(st, error))
2292
0
        return FALSE;
2293
0
    return TRUE;
2294
0
}
2295
/**
2296
 * fu_struct_efi_signature_list_parse_stream: (skip):
2297
 **/
2298
FuStructEfiSignatureList *
2299
fu_struct_efi_signature_list_parse_stream(GInputStream *stream, gsize offset, GError **error)
2300
0
{
2301
0
    g_autoptr(GByteArray) st = NULL;
2302
0
    st = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
2303
0
    if (st == NULL) {
2304
0
        g_prefix_error(error, "FuStructEfiSignatureList failed read of 0x%x: ", (guint) 28);
2305
0
        return NULL;
2306
0
    }
2307
0
    if (st->len != 28) {
2308
0
        g_set_error(error,
2309
0
                    FWUPD_ERROR,
2310
0
                    FWUPD_ERROR_INVALID_DATA,
2311
0
                    "FuStructEfiSignatureList requested 0x%x and got 0x%x",
2312
0
                    (guint) 28,
2313
0
                    (guint) st->len);
2314
0
        return NULL;
2315
0
    }
2316
0
    if (!fu_struct_efi_signature_list_parse_internal(st, error))
2317
0
        return NULL;
2318
0
    return g_steal_pointer(&st);
2319
0
}
2320
/* getters */
2321
/**
2322
 * fu_struct_efi_load_option_get_attrs: (skip):
2323
 **/
2324
FuEfiLoadOptionAttrs
2325
fu_struct_efi_load_option_get_attrs(const FuStructEfiLoadOption *st)
2326
2.17k
{
2327
2.17k
    g_return_val_if_fail(st != NULL, 0x0);
2328
2.17k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
2329
2.17k
}
2330
/**
2331
 * fu_struct_efi_load_option_get_dp_size: (skip):
2332
 **/
2333
guint16
2334
fu_struct_efi_load_option_get_dp_size(const FuStructEfiLoadOption *st)
2335
1.68k
{
2336
1.68k
    g_return_val_if_fail(st != NULL, 0x0);
2337
1.68k
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
2338
1.68k
}
2339
2340
/* setters */
2341
/**
2342
 * fu_struct_efi_load_option_set_attrs: (skip):
2343
 **/
2344
void
2345
fu_struct_efi_load_option_set_attrs(FuStructEfiLoadOption *st, FuEfiLoadOptionAttrs value)
2346
1.27k
{
2347
1.27k
    g_return_if_fail(st != NULL);
2348
1.27k
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
2349
1.27k
}
2350
/**
2351
 * fu_struct_efi_load_option_set_dp_size: (skip):
2352
 **/
2353
void
2354
fu_struct_efi_load_option_set_dp_size(FuStructEfiLoadOption *st, guint16 value)
2355
798
{
2356
798
    g_return_if_fail(st != NULL);
2357
798
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
2358
798
}
2359
/**
2360
 * fu_struct_efi_load_option_new: (skip):
2361
 **/
2362
FuStructEfiLoadOption *
2363
fu_struct_efi_load_option_new(void)
2364
1.27k
{
2365
1.27k
    FuStructEfiLoadOption *st = g_byte_array_sized_new(6);
2366
1.27k
    fu_byte_array_set_size(st, 6, 0x0);
2367
1.27k
    return st;
2368
1.27k
}
2369
/**
2370
 * fu_struct_efi_load_option_to_string: (skip):
2371
 **/
2372
static gchar *
2373
fu_struct_efi_load_option_to_string(const FuStructEfiLoadOption *st)
2374
0
{
2375
0
    g_autoptr(GString) str = g_string_new("FuStructEfiLoadOption:\n");
2376
0
    g_return_val_if_fail(st != NULL, NULL);
2377
0
    {
2378
0
        const gchar *tmp = fu_efi_load_option_attrs_to_string(fu_struct_efi_load_option_get_attrs(st));
2379
0
        if (tmp != NULL) {
2380
0
            g_string_append_printf(str, "  attrs: 0x%x [%s]\n", (guint) fu_struct_efi_load_option_get_attrs(st), tmp);
2381
0
        } else {
2382
0
            g_string_append_printf(str, "  attrs: 0x%x\n", (guint) fu_struct_efi_load_option_get_attrs(st));
2383
0
        }
2384
0
    }
2385
0
    g_string_append_printf(str, "  dp_size: 0x%x\n",
2386
0
                           (guint) fu_struct_efi_load_option_get_dp_size(st));
2387
0
    if (str->len > 0)
2388
0
        g_string_set_size(str, str->len - 1);
2389
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2390
0
}
2391
static gboolean
2392
fu_struct_efi_load_option_validate_internal(FuStructEfiLoadOption *st, GError **error)
2393
2.17k
{
2394
2.17k
    g_return_val_if_fail(st != NULL, FALSE);
2395
2.17k
    return TRUE;
2396
2.17k
}
2397
static gboolean
2398
fu_struct_efi_load_option_parse_internal(FuStructEfiLoadOption *st, GError **error)
2399
2.17k
{
2400
2.17k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2401
0
        g_autofree gchar *str = fu_struct_efi_load_option_to_string(st);
2402
0
        g_debug("%s", str);
2403
0
    }
2404
2.17k
    if (!fu_struct_efi_load_option_validate_internal(st, error))
2405
0
        return FALSE;
2406
2.17k
    return TRUE;
2407
2.17k
}
2408
/**
2409
 * fu_struct_efi_load_option_parse_stream: (skip):
2410
 **/
2411
FuStructEfiLoadOption *
2412
fu_struct_efi_load_option_parse_stream(GInputStream *stream, gsize offset, GError **error)
2413
2.18k
{
2414
2.18k
    g_autoptr(GByteArray) st = NULL;
2415
2.18k
    st = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error);
2416
2.18k
    if (st == NULL) {
2417
0
        g_prefix_error(error, "FuStructEfiLoadOption failed read of 0x%x: ", (guint) 6);
2418
0
        return NULL;
2419
0
    }
2420
2.18k
    if (st->len != 6) {
2421
11
        g_set_error(error,
2422
11
                    FWUPD_ERROR,
2423
11
                    FWUPD_ERROR_INVALID_DATA,
2424
11
                    "FuStructEfiLoadOption requested 0x%x and got 0x%x",
2425
11
                    (guint) 6,
2426
11
                    (guint) st->len);
2427
11
        return NULL;
2428
11
    }
2429
2.17k
    if (!fu_struct_efi_load_option_parse_internal(st, error))
2430
0
        return NULL;
2431
2.17k
    return g_steal_pointer(&st);
2432
2.17k
}
2433
/* getters */
2434
/**
2435
 * fu_struct_efi_device_path_get_type: (skip):
2436
 **/
2437
FuEfiDevicePathType
2438
fu_struct_efi_device_path_get_type(const FuStructEfiDevicePath *st)
2439
100k
{
2440
100k
    g_return_val_if_fail(st != NULL, 0x0);
2441
100k
    return st->data[0];
2442
100k
}
2443
/**
2444
 * fu_struct_efi_device_path_get_subtype: (skip):
2445
 **/
2446
guint8
2447
fu_struct_efi_device_path_get_subtype(const FuStructEfiDevicePath *st)
2448
46.5k
{
2449
46.5k
    g_return_val_if_fail(st != NULL, 0x0);
2450
46.5k
    return st->data[1];
2451
46.5k
}
2452
/**
2453
 * fu_struct_efi_device_path_get_length: (skip):
2454
 **/
2455
guint16
2456
fu_struct_efi_device_path_get_length(const FuStructEfiDevicePath *st)
2457
52.3k
{
2458
52.3k
    g_return_val_if_fail(st != NULL, 0x0);
2459
52.3k
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
2460
52.3k
}
2461
2462
/* setters */
2463
/**
2464
 * fu_struct_efi_device_path_set_type: (skip):
2465
 **/
2466
void
2467
fu_struct_efi_device_path_set_type(FuStructEfiDevicePath *st, FuEfiDevicePathType value)
2468
8.01k
{
2469
8.01k
    g_return_if_fail(st != NULL);
2470
8.01k
    st->data[0] = value;
2471
8.01k
}
2472
/**
2473
 * fu_struct_efi_device_path_set_subtype: (skip):
2474
 **/
2475
void
2476
fu_struct_efi_device_path_set_subtype(FuStructEfiDevicePath *st, guint8 value)
2477
16.5k
{
2478
16.5k
    g_return_if_fail(st != NULL);
2479
16.5k
    st->data[1] = value;
2480
16.5k
}
2481
/**
2482
 * fu_struct_efi_device_path_set_length: (skip):
2483
 **/
2484
void
2485
fu_struct_efi_device_path_set_length(FuStructEfiDevicePath *st, guint16 value)
2486
15.7k
{
2487
15.7k
    g_return_if_fail(st != NULL);
2488
15.7k
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
2489
15.7k
}
2490
/**
2491
 * fu_struct_efi_device_path_new: (skip):
2492
 **/
2493
FuStructEfiDevicePath *
2494
fu_struct_efi_device_path_new(void)
2495
8.49k
{
2496
8.49k
    FuStructEfiDevicePath *st = g_byte_array_sized_new(4);
2497
8.49k
    fu_byte_array_set_size(st, 4, 0x0);
2498
8.49k
    fu_struct_efi_device_path_set_subtype(st, 0xFF);
2499
8.49k
    fu_struct_efi_device_path_set_length(st, 4);
2500
8.49k
    return st;
2501
8.49k
}
2502
/**
2503
 * fu_struct_efi_device_path_to_string: (skip):
2504
 **/
2505
static gchar *
2506
fu_struct_efi_device_path_to_string(const FuStructEfiDevicePath *st)
2507
0
{
2508
0
    g_autoptr(GString) str = g_string_new("FuStructEfiDevicePath:\n");
2509
0
    g_return_val_if_fail(st != NULL, NULL);
2510
0
    {
2511
0
        const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_device_path_get_type(st));
2512
0
        if (tmp != NULL) {
2513
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_device_path_get_type(st), tmp);
2514
0
        } else {
2515
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_device_path_get_type(st));
2516
0
        }
2517
0
    }
2518
0
    g_string_append_printf(str, "  subtype: 0x%x\n",
2519
0
                           (guint) fu_struct_efi_device_path_get_subtype(st));
2520
0
    g_string_append_printf(str, "  length: 0x%x\n",
2521
0
                           (guint) fu_struct_efi_device_path_get_length(st));
2522
0
    if (str->len > 0)
2523
0
        g_string_set_size(str, str->len - 1);
2524
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2525
0
}
2526
static gboolean
2527
fu_struct_efi_device_path_validate_internal(FuStructEfiDevicePath *st, GError **error)
2528
51.9k
{
2529
51.9k
    g_return_val_if_fail(st != NULL, FALSE);
2530
51.9k
    return TRUE;
2531
51.9k
}
2532
static gboolean
2533
fu_struct_efi_device_path_parse_internal(FuStructEfiDevicePath *st, GError **error)
2534
51.9k
{
2535
51.9k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2536
0
        g_autofree gchar *str = fu_struct_efi_device_path_to_string(st);
2537
0
        g_debug("%s", str);
2538
0
    }
2539
51.9k
    if (!fu_struct_efi_device_path_validate_internal(st, error))
2540
0
        return FALSE;
2541
51.9k
    return TRUE;
2542
51.9k
}
2543
/**
2544
 * fu_struct_efi_device_path_parse_stream: (skip):
2545
 **/
2546
FuStructEfiDevicePath *
2547
fu_struct_efi_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error)
2548
51.9k
{
2549
51.9k
    g_autoptr(GByteArray) st = NULL;
2550
51.9k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
2551
51.9k
    if (st == NULL) {
2552
0
        g_prefix_error(error, "FuStructEfiDevicePath failed read of 0x%x: ", (guint) 4);
2553
0
        return NULL;
2554
0
    }
2555
51.9k
    if (st->len != 4) {
2556
48
        g_set_error(error,
2557
48
                    FWUPD_ERROR,
2558
48
                    FWUPD_ERROR_INVALID_DATA,
2559
48
                    "FuStructEfiDevicePath requested 0x%x and got 0x%x",
2560
48
                    (guint) 4,
2561
48
                    (guint) st->len);
2562
48
        return NULL;
2563
48
    }
2564
51.9k
    if (!fu_struct_efi_device_path_parse_internal(st, error))
2565
0
        return NULL;
2566
51.9k
    return g_steal_pointer(&st);
2567
51.9k
}
2568
/* getters */
2569
/**
2570
 * fu_struct_efi_hard_drive_device_path_get_type: (skip):
2571
 **/
2572
static FuEfiDevicePathType
2573
fu_struct_efi_hard_drive_device_path_get_type(const FuStructEfiHardDriveDevicePath *st)
2574
635
{
2575
635
    g_return_val_if_fail(st != NULL, 0x0);
2576
635
    return st->data[0];
2577
635
}
2578
/**
2579
 * fu_struct_efi_hard_drive_device_path_get_subtype: (skip):
2580
 **/
2581
FuEfiHardDriveDevicePathSubtype
2582
fu_struct_efi_hard_drive_device_path_get_subtype(const FuStructEfiHardDriveDevicePath *st)
2583
0
{
2584
0
    g_return_val_if_fail(st != NULL, 0x0);
2585
0
    return st->data[1];
2586
0
}
2587
/**
2588
 * fu_struct_efi_hard_drive_device_path_get_length: (skip):
2589
 **/
2590
static guint16
2591
fu_struct_efi_hard_drive_device_path_get_length(const FuStructEfiHardDriveDevicePath *st)
2592
653
{
2593
653
    g_return_val_if_fail(st != NULL, 0x0);
2594
653
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
2595
653
}
2596
/**
2597
 * fu_struct_efi_hard_drive_device_path_get_partition_number: (skip):
2598
 **/
2599
guint32
2600
fu_struct_efi_hard_drive_device_path_get_partition_number(const FuStructEfiHardDriveDevicePath *st)
2601
617
{
2602
617
    g_return_val_if_fail(st != NULL, 0x0);
2603
617
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
2604
617
}
2605
/**
2606
 * fu_struct_efi_hard_drive_device_path_get_partition_start: (skip):
2607
 **/
2608
guint64
2609
fu_struct_efi_hard_drive_device_path_get_partition_start(const FuStructEfiHardDriveDevicePath *st)
2610
617
{
2611
617
    g_return_val_if_fail(st != NULL, 0x0);
2612
617
    return fu_memread_uint64(st->data + 8, G_LITTLE_ENDIAN);
2613
617
}
2614
/**
2615
 * fu_struct_efi_hard_drive_device_path_get_partition_size: (skip):
2616
 **/
2617
guint64
2618
fu_struct_efi_hard_drive_device_path_get_partition_size(const FuStructEfiHardDriveDevicePath *st)
2619
617
{
2620
617
    g_return_val_if_fail(st != NULL, 0x0);
2621
617
    return fu_memread_uint64(st->data + 16, G_LITTLE_ENDIAN);
2622
617
}
2623
/**
2624
 * fu_struct_efi_hard_drive_device_path_get_partition_signature: (skip):
2625
 **/
2626
const fwupd_guid_t *
2627
fu_struct_efi_hard_drive_device_path_get_partition_signature(const FuStructEfiHardDriveDevicePath *st)
2628
617
{
2629
617
    g_return_val_if_fail(st != NULL, NULL);
2630
617
    return (const fwupd_guid_t *) (st->data + 24);
2631
617
}
2632
/**
2633
 * fu_struct_efi_hard_drive_device_path_get_partition_format: (skip):
2634
 **/
2635
FuEfiHardDriveDevicePathPartitionFormat
2636
fu_struct_efi_hard_drive_device_path_get_partition_format(const FuStructEfiHardDriveDevicePath *st)
2637
617
{
2638
617
    g_return_val_if_fail(st != NULL, 0x0);
2639
617
    return st->data[40];
2640
617
}
2641
/**
2642
 * fu_struct_efi_hard_drive_device_path_get_signature_type: (skip):
2643
 **/
2644
FuEfiHardDriveDevicePathSignatureType
2645
fu_struct_efi_hard_drive_device_path_get_signature_type(const FuStructEfiHardDriveDevicePath *st)
2646
617
{
2647
617
    g_return_val_if_fail(st != NULL, 0x0);
2648
617
    return st->data[41];
2649
617
}
2650
2651
/* setters */
2652
/**
2653
 * fu_struct_efi_hard_drive_device_path_set_type: (skip):
2654
 **/
2655
static void
2656
fu_struct_efi_hard_drive_device_path_set_type(FuStructEfiHardDriveDevicePath *st, FuEfiDevicePathType value)
2657
386
{
2658
386
    g_return_if_fail(st != NULL);
2659
386
    st->data[0] = value;
2660
386
}
2661
/**
2662
 * fu_struct_efi_hard_drive_device_path_set_subtype: (skip):
2663
 **/
2664
void
2665
fu_struct_efi_hard_drive_device_path_set_subtype(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSubtype value)
2666
386
{
2667
386
    g_return_if_fail(st != NULL);
2668
386
    st->data[1] = value;
2669
386
}
2670
/**
2671
 * fu_struct_efi_hard_drive_device_path_set_length: (skip):
2672
 **/
2673
static void
2674
fu_struct_efi_hard_drive_device_path_set_length(FuStructEfiHardDriveDevicePath *st, guint16 value)
2675
386
{
2676
386
    g_return_if_fail(st != NULL);
2677
386
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
2678
386
}
2679
/**
2680
 * fu_struct_efi_hard_drive_device_path_set_partition_number: (skip):
2681
 **/
2682
void
2683
fu_struct_efi_hard_drive_device_path_set_partition_number(FuStructEfiHardDriveDevicePath *st, guint32 value)
2684
386
{
2685
386
    g_return_if_fail(st != NULL);
2686
386
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
2687
386
}
2688
/**
2689
 * fu_struct_efi_hard_drive_device_path_set_partition_start: (skip):
2690
 **/
2691
void
2692
fu_struct_efi_hard_drive_device_path_set_partition_start(FuStructEfiHardDriveDevicePath *st, guint64 value)
2693
386
{
2694
386
    g_return_if_fail(st != NULL);
2695
386
    fu_memwrite_uint64(st->data + 8, value, G_LITTLE_ENDIAN);
2696
386
}
2697
/**
2698
 * fu_struct_efi_hard_drive_device_path_set_partition_size: (skip):
2699
 **/
2700
void
2701
fu_struct_efi_hard_drive_device_path_set_partition_size(FuStructEfiHardDriveDevicePath *st, guint64 value)
2702
386
{
2703
386
    g_return_if_fail(st != NULL);
2704
386
    fu_memwrite_uint64(st->data + 16, value, G_LITTLE_ENDIAN);
2705
386
}
2706
/**
2707
 * fu_struct_efi_hard_drive_device_path_set_partition_signature: (skip):
2708
 **/
2709
void
2710
fu_struct_efi_hard_drive_device_path_set_partition_signature(FuStructEfiHardDriveDevicePath *st, const fwupd_guid_t *value)
2711
386
{
2712
386
    g_return_if_fail(st != NULL);
2713
386
    g_return_if_fail(value != NULL);
2714
386
    memcpy(st->data + 24, value, sizeof(*value)); /* nocheck:blocked */
2715
386
}
2716
/**
2717
 * fu_struct_efi_hard_drive_device_path_set_partition_format: (skip):
2718
 **/
2719
void
2720
fu_struct_efi_hard_drive_device_path_set_partition_format(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathPartitionFormat value)
2721
772
{
2722
772
    g_return_if_fail(st != NULL);
2723
772
    st->data[40] = value;
2724
772
}
2725
/**
2726
 * fu_struct_efi_hard_drive_device_path_set_signature_type: (skip):
2727
 **/
2728
void
2729
fu_struct_efi_hard_drive_device_path_set_signature_type(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSignatureType value)
2730
772
{
2731
772
    g_return_if_fail(st != NULL);
2732
772
    st->data[41] = value;
2733
772
}
2734
/**
2735
 * fu_struct_efi_hard_drive_device_path_new: (skip):
2736
 **/
2737
FuStructEfiHardDriveDevicePath *
2738
fu_struct_efi_hard_drive_device_path_new(void)
2739
386
{
2740
386
    FuStructEfiHardDriveDevicePath *st = g_byte_array_sized_new(42);
2741
386
    fu_byte_array_set_size(st, 42, 0x0);
2742
386
    fu_struct_efi_hard_drive_device_path_set_type(st, FU_EFI_DEVICE_PATH_TYPE_MEDIA);
2743
386
    fu_struct_efi_hard_drive_device_path_set_subtype(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE);
2744
386
    fu_struct_efi_hard_drive_device_path_set_length(st, 42);
2745
386
    fu_struct_efi_hard_drive_device_path_set_partition_format(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE);
2746
386
    fu_struct_efi_hard_drive_device_path_set_signature_type(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID);
2747
386
    return st;
2748
386
}
2749
/**
2750
 * fu_struct_efi_hard_drive_device_path_to_string: (skip):
2751
 **/
2752
static gchar *
2753
fu_struct_efi_hard_drive_device_path_to_string(const FuStructEfiHardDriveDevicePath *st)
2754
0
{
2755
0
    g_autoptr(GString) str = g_string_new("FuStructEfiHardDriveDevicePath:\n");
2756
0
    g_return_val_if_fail(st != NULL, NULL);
2757
0
    {
2758
0
        const gchar *tmp = fu_efi_hard_drive_device_path_subtype_to_string(fu_struct_efi_hard_drive_device_path_get_subtype(st));
2759
0
        if (tmp != NULL) {
2760
0
            g_string_append_printf(str, "  subtype: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st), tmp);
2761
0
        } else {
2762
0
            g_string_append_printf(str, "  subtype: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st));
2763
0
        }
2764
0
    }
2765
0
    g_string_append_printf(str, "  partition_number: 0x%x\n",
2766
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_number(st));
2767
0
    g_string_append_printf(str, "  partition_start: 0x%x\n",
2768
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_start(st));
2769
0
    g_string_append_printf(str, "  partition_size: 0x%x\n",
2770
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_size(st));
2771
0
    {
2772
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);
2773
0
        g_string_append_printf(str, "  partition_signature: %s\n", tmp);
2774
0
    }
2775
0
    {
2776
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));
2777
0
        if (tmp != NULL) {
2778
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);
2779
0
        } else {
2780
0
            g_string_append_printf(str, "  partition_format: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_partition_format(st));
2781
0
        }
2782
0
    }
2783
0
    {
2784
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));
2785
0
        if (tmp != NULL) {
2786
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);
2787
0
        } else {
2788
0
            g_string_append_printf(str, "  signature_type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_signature_type(st));
2789
0
        }
2790
0
    }
2791
0
    if (str->len > 0)
2792
0
        g_string_set_size(str, str->len - 1);
2793
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2794
0
}
2795
static gboolean
2796
fu_struct_efi_hard_drive_device_path_validate_internal(FuStructEfiHardDriveDevicePath *st, GError **error)
2797
635
{
2798
635
    g_return_val_if_fail(st != NULL, FALSE);
2799
635
    if (fu_struct_efi_hard_drive_device_path_get_type(st) != FU_EFI_DEVICE_PATH_TYPE_MEDIA) {
2800
0
        g_set_error_literal(error,
2801
0
                            FWUPD_ERROR,
2802
0
                            FWUPD_ERROR_INVALID_DATA,
2803
0
                            "constant FuStructEfiHardDriveDevicePath.type was not valid");
2804
0
        return FALSE;
2805
0
    }
2806
635
    if (fu_struct_efi_hard_drive_device_path_get_length(st) != 42) {
2807
18
        g_set_error(error,
2808
18
                    FWUPD_ERROR,
2809
18
                    FWUPD_ERROR_INVALID_DATA,
2810
18
                    "constant FuStructEfiHardDriveDevicePath.length was not valid, "
2811
18
                    "expected 0x%x and got 0x%x",
2812
18
                    (guint) 42,
2813
18
                    (guint) fu_struct_efi_hard_drive_device_path_get_length(st));
2814
18
        return FALSE;
2815
18
    }
2816
617
    return TRUE;
2817
635
}
2818
static gboolean
2819
fu_struct_efi_hard_drive_device_path_parse_internal(FuStructEfiHardDriveDevicePath *st, GError **error)
2820
635
{
2821
635
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2822
0
        g_autofree gchar *str = fu_struct_efi_hard_drive_device_path_to_string(st);
2823
0
        g_debug("%s", str);
2824
0
    }
2825
635
    if (!fu_struct_efi_hard_drive_device_path_validate_internal(st, error))
2826
18
        return FALSE;
2827
617
    return TRUE;
2828
635
}
2829
/**
2830
 * fu_struct_efi_hard_drive_device_path_parse_stream: (skip):
2831
 **/
2832
FuStructEfiHardDriveDevicePath *
2833
fu_struct_efi_hard_drive_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error)
2834
655
{
2835
655
    g_autoptr(GByteArray) st = NULL;
2836
655
    st = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error);
2837
655
    if (st == NULL) {
2838
0
        g_prefix_error(error, "FuStructEfiHardDriveDevicePath failed read of 0x%x: ", (guint) 42);
2839
0
        return NULL;
2840
0
    }
2841
655
    if (st->len != 42) {
2842
20
        g_set_error(error,
2843
20
                    FWUPD_ERROR,
2844
20
                    FWUPD_ERROR_INVALID_DATA,
2845
20
                    "FuStructEfiHardDriveDevicePath requested 0x%x and got 0x%x",
2846
20
                    (guint) 42,
2847
20
                    (guint) st->len);
2848
20
        return NULL;
2849
20
    }
2850
635
    if (!fu_struct_efi_hard_drive_device_path_parse_internal(st, error))
2851
18
        return NULL;
2852
617
    return g_steal_pointer(&st);
2853
635
}
2854
/* getters */
2855
/**
2856
 * fu_struct_shim_hive_get_magic: (skip):
2857
 **/
2858
static gchar *
2859
fu_struct_shim_hive_get_magic(const FuStructShimHive *st)
2860
429
{
2861
429
    g_return_val_if_fail(st != NULL, NULL);
2862
429
    return fu_memstrsafe(st->data, st->len, 0, 4, NULL);
2863
429
}
2864
/**
2865
 * fu_struct_shim_hive_get_header_version: (skip):
2866
 **/
2867
guint8
2868
fu_struct_shim_hive_get_header_version(const FuStructShimHive *st)
2869
987
{
2870
987
    g_return_val_if_fail(st != NULL, 0x0);
2871
987
    return st->data[4];
2872
987
}
2873
/**
2874
 * fu_struct_shim_hive_get_items_count: (skip):
2875
 **/
2876
guint8
2877
fu_struct_shim_hive_get_items_count(const FuStructShimHive *st)
2878
983
{
2879
983
    g_return_val_if_fail(st != NULL, 0x0);
2880
983
    return st->data[5];
2881
983
}
2882
/**
2883
 * fu_struct_shim_hive_get_items_offset: (skip):
2884
 **/
2885
guint8
2886
fu_struct_shim_hive_get_items_offset(const FuStructShimHive *st)
2887
983
{
2888
983
    g_return_val_if_fail(st != NULL, 0x0);
2889
983
    return st->data[6];
2890
983
}
2891
/**
2892
 * fu_struct_shim_hive_get_crc32: (skip):
2893
 **/
2894
guint32
2895
fu_struct_shim_hive_get_crc32(const FuStructShimHive *st)
2896
0
{
2897
0
    g_return_val_if_fail(st != NULL, 0x0);
2898
0
    return fu_memread_uint32(st->data + 7, G_LITTLE_ENDIAN);
2899
0
}
2900
2901
/* setters */
2902
/**
2903
 * fu_struct_shim_hive_set_magic: (skip):
2904
 **/
2905
static gboolean
2906
fu_struct_shim_hive_set_magic(FuStructShimHive *st, const gchar *value, GError **error)
2907
395
{
2908
395
    gsize len;
2909
395
    g_return_val_if_fail(st != NULL, FALSE);
2910
395
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2911
395
    if (value == NULL) {
2912
0
        memset(st->data + 0, 0x0, 4);
2913
0
        return TRUE;
2914
0
    }
2915
395
    len = strlen(value);
2916
395
    if (len > 4) {
2917
0
        g_set_error(error,
2918
0
                    FWUPD_ERROR,
2919
0
                    FWUPD_ERROR_INVALID_DATA,
2920
0
                    "string '%s' (0x%x bytes) does not fit in FuStructShimHive.magic (0x%x bytes)",
2921
0
                    value, (guint) len, (guint) 4);
2922
0
        return FALSE;
2923
0
    }
2924
395
    return fu_memcpy_safe(st->data, st->len, 0, (const guint8 *)value, len, 0x0, len, error);
2925
395
}
2926
/**
2927
 * fu_struct_shim_hive_set_header_version: (skip):
2928
 **/
2929
void
2930
fu_struct_shim_hive_set_header_version(FuStructShimHive *st, guint8 value)
2931
395
{
2932
395
    g_return_if_fail(st != NULL);
2933
395
    st->data[4] = value;
2934
395
}
2935
/**
2936
 * fu_struct_shim_hive_set_items_count: (skip):
2937
 **/
2938
void
2939
fu_struct_shim_hive_set_items_count(FuStructShimHive *st, guint8 value)
2940
395
{
2941
395
    g_return_if_fail(st != NULL);
2942
395
    st->data[5] = value;
2943
395
}
2944
/**
2945
 * fu_struct_shim_hive_set_items_offset: (skip):
2946
 **/
2947
void
2948
fu_struct_shim_hive_set_items_offset(FuStructShimHive *st, guint8 value)
2949
395
{
2950
395
    g_return_if_fail(st != NULL);
2951
395
    st->data[6] = value;
2952
395
}
2953
/**
2954
 * fu_struct_shim_hive_set_crc32: (skip):
2955
 **/
2956
void
2957
fu_struct_shim_hive_set_crc32(FuStructShimHive *st, guint32 value)
2958
395
{
2959
395
    g_return_if_fail(st != NULL);
2960
395
    fu_memwrite_uint32(st->data + 7, value, G_LITTLE_ENDIAN);
2961
395
}
2962
/**
2963
 * fu_struct_shim_hive_new: (skip):
2964
 **/
2965
FuStructShimHive *
2966
fu_struct_shim_hive_new(void)
2967
395
{
2968
395
    FuStructShimHive *st = g_byte_array_sized_new(11);
2969
395
    fu_byte_array_set_size(st, 11, 0x0);
2970
395
    fu_struct_shim_hive_set_magic(st, "HIVE", NULL);
2971
395
    fu_struct_shim_hive_set_header_version(st, 0x1);
2972
395
    return st;
2973
395
}
2974
/**
2975
 * fu_struct_shim_hive_to_string: (skip):
2976
 **/
2977
static gchar *
2978
fu_struct_shim_hive_to_string(const FuStructShimHive *st)
2979
0
{
2980
0
    g_autoptr(GString) str = g_string_new("FuStructShimHive:\n");
2981
0
    g_return_val_if_fail(st != NULL, NULL);
2982
0
    g_string_append_printf(str, "  header_version: 0x%x\n",
2983
0
                           (guint) fu_struct_shim_hive_get_header_version(st));
2984
0
    g_string_append_printf(str, "  items_count: 0x%x\n",
2985
0
                           (guint) fu_struct_shim_hive_get_items_count(st));
2986
0
    g_string_append_printf(str, "  items_offset: 0x%x\n",
2987
0
                           (guint) fu_struct_shim_hive_get_items_offset(st));
2988
0
    g_string_append_printf(str, "  crc32: 0x%x\n",
2989
0
                           (guint) fu_struct_shim_hive_get_crc32(st));
2990
0
    if (str->len > 0)
2991
0
        g_string_set_size(str, str->len - 1);
2992
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2993
0
}
2994
static gboolean
2995
fu_struct_shim_hive_validate_internal(FuStructShimHive *st, GError **error)
2996
1.41k
{
2997
1.41k
    g_return_val_if_fail(st != NULL, FALSE);
2998
1.41k
    if (strncmp((const gchar *) (st->data + 0), "HIVE", 4) != 0) {
2999
429
        g_autofree gchar *str = fu_struct_shim_hive_get_magic(st);
3000
429
        g_set_error(error,
3001
429
                    FWUPD_ERROR,
3002
429
                    FWUPD_ERROR_INVALID_DATA,
3003
429
                    "constant FuStructShimHive.magic was not valid, "
3004
429
                    "expected 'HIVE' and got '%s'",
3005
429
                    str);
3006
429
        return FALSE;
3007
429
    }
3008
985
    return TRUE;
3009
1.41k
}
3010
static gboolean
3011
fu_struct_shim_hive_parse_internal(FuStructShimHive *st, GError **error)
3012
1.41k
{
3013
1.41k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
3014
0
        g_autofree gchar *str = fu_struct_shim_hive_to_string(st);
3015
0
        g_debug("%s", str);
3016
0
    }
3017
1.41k
    if (!fu_struct_shim_hive_validate_internal(st, error))
3018
429
        return FALSE;
3019
985
    return TRUE;
3020
1.41k
}
3021
/**
3022
 * fu_struct_shim_hive_parse_stream: (skip):
3023
 **/
3024
FuStructShimHive *
3025
fu_struct_shim_hive_parse_stream(GInputStream *stream, gsize offset, GError **error)
3026
1.49k
{
3027
1.49k
    g_autoptr(GByteArray) st = NULL;
3028
1.49k
    st = fu_input_stream_read_byte_array(stream, offset, 11, NULL, error);
3029
1.49k
    if (st == NULL) {
3030
0
        g_prefix_error(error, "FuStructShimHive failed read of 0x%x: ", (guint) 11);
3031
0
        return NULL;
3032
0
    }
3033
1.49k
    if (st->len != 11) {
3034
85
        g_set_error(error,
3035
85
                    FWUPD_ERROR,
3036
85
                    FWUPD_ERROR_INVALID_DATA,
3037
85
                    "FuStructShimHive requested 0x%x and got 0x%x",
3038
85
                    (guint) 11,
3039
85
                    (guint) st->len);
3040
85
        return NULL;
3041
85
    }
3042
1.41k
    if (!fu_struct_shim_hive_parse_internal(st, error))
3043
429
        return NULL;
3044
985
    return g_steal_pointer(&st);
3045
1.41k
}
3046
/* getters */
3047
/**
3048
 * fu_struct_shim_hive_item_get_key_length: (skip):
3049
 **/
3050
guint8
3051
fu_struct_shim_hive_item_get_key_length(const FuStructShimHiveItem *st)
3052
4.63k
{
3053
4.63k
    g_return_val_if_fail(st != NULL, 0x0);
3054
4.63k
    return st->data[0];
3055
4.63k
}
3056
/**
3057
 * fu_struct_shim_hive_item_get_value_length: (skip):
3058
 **/
3059
guint32
3060
fu_struct_shim_hive_item_get_value_length(const FuStructShimHiveItem *st)
3061
4.52k
{
3062
4.52k
    g_return_val_if_fail(st != NULL, 0x0);
3063
4.52k
    return fu_memread_uint32(st->data + 1, G_LITTLE_ENDIAN);
3064
4.52k
}
3065
3066
/* setters */
3067
/**
3068
 * fu_struct_shim_hive_item_set_key_length: (skip):
3069
 **/
3070
void
3071
fu_struct_shim_hive_item_set_key_length(FuStructShimHiveItem *st, guint8 value)
3072
1.10k
{
3073
1.10k
    g_return_if_fail(st != NULL);
3074
1.10k
    st->data[0] = value;
3075
1.10k
}
3076
/**
3077
 * fu_struct_shim_hive_item_set_value_length: (skip):
3078
 **/
3079
void
3080
fu_struct_shim_hive_item_set_value_length(FuStructShimHiveItem *st, guint32 value)
3081
1.10k
{
3082
1.10k
    g_return_if_fail(st != NULL);
3083
1.10k
    fu_memwrite_uint32(st->data + 1, value, G_LITTLE_ENDIAN);
3084
1.10k
}
3085
/**
3086
 * fu_struct_shim_hive_item_new: (skip):
3087
 **/
3088
FuStructShimHiveItem *
3089
fu_struct_shim_hive_item_new(void)
3090
1.10k
{
3091
1.10k
    FuStructShimHiveItem *st = g_byte_array_sized_new(5);
3092
1.10k
    fu_byte_array_set_size(st, 5, 0x0);
3093
1.10k
    return st;
3094
1.10k
}
3095
/**
3096
 * fu_struct_shim_hive_item_to_string: (skip):
3097
 **/
3098
static gchar *
3099
fu_struct_shim_hive_item_to_string(const FuStructShimHiveItem *st)
3100
0
{
3101
0
    g_autoptr(GString) str = g_string_new("FuStructShimHiveItem:\n");
3102
0
    g_return_val_if_fail(st != NULL, NULL);
3103
0
    g_string_append_printf(str, "  key_length: 0x%x\n",
3104
0
                           (guint) fu_struct_shim_hive_item_get_key_length(st));
3105
0
    g_string_append_printf(str, "  value_length: 0x%x\n",
3106
0
                           (guint) fu_struct_shim_hive_item_get_value_length(st));
3107
0
    if (str->len > 0)
3108
0
        g_string_set_size(str, str->len - 1);
3109
0
    return g_string_free(g_steal_pointer(&str), FALSE);
3110
0
}
3111
static gboolean
3112
fu_struct_shim_hive_item_validate_internal(FuStructShimHiveItem *st, GError **error)
3113
4.63k
{
3114
4.63k
    g_return_val_if_fail(st != NULL, FALSE);
3115
4.63k
    return TRUE;
3116
4.63k
}
3117
static gboolean
3118
fu_struct_shim_hive_item_parse_internal(FuStructShimHiveItem *st, GError **error)
3119
4.63k
{
3120
4.63k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
3121
0
        g_autofree gchar *str = fu_struct_shim_hive_item_to_string(st);
3122
0
        g_debug("%s", str);
3123
0
    }
3124
4.63k
    if (!fu_struct_shim_hive_item_validate_internal(st, error))
3125
0
        return FALSE;
3126
4.63k
    return TRUE;
3127
4.63k
}
3128
/**
3129
 * fu_struct_shim_hive_item_parse_stream: (skip):
3130
 **/
3131
FuStructShimHiveItem *
3132
fu_struct_shim_hive_item_parse_stream(GInputStream *stream, gsize offset, GError **error)
3133
4.99k
{
3134
4.99k
    g_autoptr(GByteArray) st = NULL;
3135
4.99k
    st = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error);
3136
4.99k
    if (st == NULL) {
3137
187
        g_prefix_error(error, "FuStructShimHiveItem failed read of 0x%x: ", (guint) 5);
3138
187
        return NULL;
3139
187
    }
3140
4.81k
    if (st->len != 5) {
3141
180
        g_set_error(error,
3142
180
                    FWUPD_ERROR,
3143
180
                    FWUPD_ERROR_INVALID_DATA,
3144
180
                    "FuStructShimHiveItem requested 0x%x and got 0x%x",
3145
180
                    (guint) 5,
3146
180
                    (guint) st->len);
3147
180
        return NULL;
3148
180
    }
3149
4.63k
    if (!fu_struct_shim_hive_item_parse_internal(st, error))
3150
0
        return NULL;
3151
4.63k
    return g_steal_pointer(&st);
3152
4.63k
}