Coverage Report

Created: 2025-07-01 07:09

/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.91k
{
91
3.91k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_NONE)
92
0
        return "none";
93
3.91k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY)
94
2.51k
        return "legacy";
95
1.40k
    if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_TIANO)
96
1.40k
        return "tiano";
97
0
    return NULL;
98
1.40k
}
99
100
const gchar *
101
fu_efi_section_type_to_string(FuEfiSectionType val)
102
32.6k
{
103
32.6k
    if (val == FU_EFI_SECTION_TYPE_COMPRESSION)
104
0
        return "compression";
105
32.6k
    if (val == FU_EFI_SECTION_TYPE_GUID_DEFINED)
106
37
        return "guid-defined";
107
32.5k
    if (val == FU_EFI_SECTION_TYPE_DISPOSABLE)
108
379
        return "disposable";
109
32.2k
    if (val == FU_EFI_SECTION_TYPE_PE32)
110
711
        return "pe32";
111
31.4k
    if (val == FU_EFI_SECTION_TYPE_PIC)
112
840
        return "pic";
113
30.6k
    if (val == FU_EFI_SECTION_TYPE_TE)
114
675
        return "te";
115
29.9k
    if (val == FU_EFI_SECTION_TYPE_DXE_DEPEX)
116
401
        return "dxe-depex";
117
29.5k
    if (val == FU_EFI_SECTION_TYPE_VERSION)
118
0
        return "version";
119
29.5k
    if (val == FU_EFI_SECTION_TYPE_USER_INTERFACE)
120
0
        return "user-interface";
121
29.5k
    if (val == FU_EFI_SECTION_TYPE_COMPATIBILITY16)
122
3.14k
        return "compatibility16";
123
26.4k
    if (val == FU_EFI_SECTION_TYPE_VOLUME_IMAGE)
124
0
        return "volume-image";
125
26.4k
    if (val == FU_EFI_SECTION_TYPE_FREEFORM_SUBTYPE_GUID)
126
0
        return "freeform-subtype-guid";
127
26.4k
    if (val == FU_EFI_SECTION_TYPE_RAW)
128
7.31k
        return "raw";
129
19.1k
    if (val == FU_EFI_SECTION_TYPE_PEI_DEPEX)
130
1.60k
        return "pei-depex";
131
17.5k
    if (val == FU_EFI_SECTION_TYPE_MM_DEPEX)
132
319
        return "mm-depex";
133
17.1k
    if (val == FU_EFI_SECTION_TYPE_PHOENIX_SECTION_POSTCODE)
134
1.18k
        return "phoenix-section-postcode";
135
15.9k
    if (val == FU_EFI_SECTION_TYPE_INSYDE_SECTION_POSTCODE)
136
341
        return "insyde-section-postcode";
137
15.6k
    return NULL;
138
15.9k
}
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
31.9k
{
287
31.9k
    g_return_val_if_fail(st != NULL, NULL);
288
31.9k
    return (const fwupd_guid_t *) (st->data + 0);
289
31.9k
}
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
32.1k
{
296
32.1k
    g_return_val_if_fail(st != NULL, 0x0);
297
32.1k
    return st->data[16];
298
32.1k
}
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
771
{
305
771
    g_return_val_if_fail(st != NULL, 0x0);
306
771
    return st->data[17];
307
771
}
308
/**
309
 * fu_struct_efi_file_get_type: (skip):
310
 **/
311
FuEfiFileType
312
fu_struct_efi_file_get_type(const FuStructEfiFile *st)
313
31.9k
{
314
31.9k
    g_return_val_if_fail(st != NULL, 0x0);
315
31.9k
    return st->data[18];
316
31.9k
}
317
/**
318
 * fu_struct_efi_file_get_attrs: (skip):
319
 **/
320
guint8
321
fu_struct_efi_file_get_attrs(const FuStructEfiFile *st)
322
31.9k
{
323
31.9k
    g_return_val_if_fail(st != NULL, 0x0);
324
31.9k
    return st->data[19];
325
31.9k
}
326
/**
327
 * fu_struct_efi_file_get_size: (skip):
328
 **/
329
guint32
330
fu_struct_efi_file_get_size(const FuStructEfiFile *st)
331
32.0k
{
332
32.0k
    g_return_val_if_fail(st != NULL, 0x0);
333
32.0k
    return fu_memread_uint24(st->data + 20, G_LITTLE_ENDIAN);
334
32.0k
}
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.72k
{
352
6.72k
    g_return_if_fail(st != NULL);
353
6.72k
    g_return_if_fail(value != NULL);
354
6.72k
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
355
6.72k
}
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
13.4k
{
362
13.4k
    g_return_if_fail(st != NULL);
363
13.4k
    st->data[16] = value;
364
13.4k
}
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.72k
{
371
6.72k
    g_return_if_fail(st != NULL);
372
6.72k
    st->data[17] = value;
373
6.72k
}
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.72k
{
380
6.72k
    g_return_if_fail(st != NULL);
381
6.72k
    st->data[18] = value;
382
6.72k
}
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.72k
{
389
6.72k
    g_return_if_fail(st != NULL);
390
6.72k
    st->data[19] = value;
391
6.72k
}
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.72k
{
398
6.72k
    g_return_if_fail(st != NULL);
399
6.72k
    fu_memwrite_uint24(st->data + 20, value, G_LITTLE_ENDIAN);
400
6.72k
}
401
/**
402
 * fu_struct_efi_file_set_state: (skip):
403
 **/
404
void
405
fu_struct_efi_file_set_state(FuStructEfiFile *st, guint8 value)
406
7.11k
{
407
7.11k
    g_return_if_fail(st != NULL);
408
7.11k
    st->data[23] = value;
409
7.11k
}
410
/**
411
 * fu_struct_efi_file_new: (skip):
412
 **/
413
FuStructEfiFile *
414
fu_struct_efi_file_new(void)
415
7.11k
{
416
7.11k
    FuStructEfiFile *st = g_byte_array_sized_new(24);
417
7.11k
    fu_byte_array_set_size(st, 24, 0x0);
418
7.11k
    fu_struct_efi_file_set_state(st, 0xF8);
419
7.11k
    return st;
420
7.11k
}
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
32.2k
{
458
32.2k
    g_return_val_if_fail(st != NULL, FALSE);
459
32.2k
    return TRUE;
460
32.2k
}
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(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
31.9k
{
481
31.9k
    if (!fu_struct_efi_file_validate_internal(st, error))
482
0
        return FALSE;
483
31.9k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
484
0
        g_autofree gchar *str = fu_struct_efi_file_to_string(st);
485
0
        g_debug("%s", str);
486
0
    }
487
31.9k
    return TRUE;
488
31.9k
}
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
32.0k
{
495
32.0k
    g_autoptr(GByteArray) st = NULL;
496
32.0k
    st = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error);
497
32.0k
    if (st == NULL) {
498
0
        g_prefix_error(error, "FuStructEfiFile failed read of 0x%x: ", (guint) 24);
499
0
        return NULL;
500
0
    }
501
32.0k
    if (st->len != 24) {
502
95
        g_set_error(error,
503
95
                    FWUPD_ERROR,
504
95
                    FWUPD_ERROR_INVALID_DATA,
505
95
                    "FuStructEfiFile requested 0x%x and got 0x%x",
506
95
                    (guint) 24,
507
95
                    (guint) st->len);
508
95
        return NULL;
509
95
    }
510
31.9k
    if (!fu_struct_efi_file_parse_internal(st, error))
511
0
        return NULL;
512
31.9k
    return g_steal_pointer(&st);
513
31.9k
}
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
242
{
521
242
    g_return_val_if_fail(st != NULL, 0x0);
522
242
    return fu_memread_uint64(st->data + 24, G_LITTLE_ENDIAN);
523
242
}
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
242
{
543
242
    g_return_val_if_fail(st != NULL, FALSE);
544
242
    {
545
242
        GByteArray st_tmp = {
546
242
            .data = (guint8*) st->data + 0x0,
547
242
            .len = 24,
548
242
        };
549
242
        if (!fu_struct_efi_file_validate_internal(&st_tmp, error))
550
0
            return FALSE;
551
242
    }
552
242
    return TRUE;
553
242
}
554
static gboolean
555
fu_struct_efi_file2_parse_internal(FuStructEfiFile2 *st, GError **error)
556
242
{
557
242
    if (!fu_struct_efi_file2_validate_internal(st, error))
558
0
        return FALSE;
559
242
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
560
0
        g_autofree gchar *str = fu_struct_efi_file2_to_string(st);
561
0
        g_debug("%s", str);
562
0
    }
563
242
    return TRUE;
564
242
}
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
253
{
571
253
    g_autoptr(GByteArray) st = NULL;
572
253
    st = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error);
573
253
    if (st == NULL) {
574
0
        g_prefix_error(error, "FuStructEfiFile2 failed read of 0x%x: ", (guint) 32);
575
0
        return NULL;
576
0
    }
577
253
    if (st->len != 32) {
578
11
        g_set_error(error,
579
11
                    FWUPD_ERROR,
580
11
                    FWUPD_ERROR_INVALID_DATA,
581
11
                    "FuStructEfiFile2 requested 0x%x and got 0x%x",
582
11
                    (guint) 32,
583
11
                    (guint) st->len);
584
11
        return NULL;
585
11
    }
586
242
    if (!fu_struct_efi_file2_parse_internal(st, error))
587
0
        return NULL;
588
242
    return g_steal_pointer(&st);
589
242
}
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.43k
{
606
3.43k
    g_return_val_if_fail(st != NULL, 0x0);
607
3.43k
    return st->data[4];
608
3.43k
}
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.43k
{
636
3.43k
    g_return_val_if_fail(st != NULL, FALSE);
637
3.43k
    return TRUE;
638
3.43k
}
639
static gboolean
640
fu_struct_efi_section_compression_parse_internal(FuStructEfiSectionCompression *st, GError **error)
641
3.43k
{
642
3.43k
    if (!fu_struct_efi_section_compression_validate_internal(st, error))
643
0
        return FALSE;
644
3.43k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
645
0
        g_autofree gchar *str = fu_struct_efi_section_compression_to_string(st);
646
0
        g_debug("%s", str);
647
0
    }
648
3.43k
    return TRUE;
649
3.43k
}
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.46k
{
656
3.46k
    g_autoptr(GByteArray) st = NULL;
657
3.46k
    st = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error);
658
3.46k
    if (st == NULL) {
659
10
        g_prefix_error(error, "FuStructEfiSectionCompression failed read of 0x%x: ", (guint) 5);
660
10
        return NULL;
661
10
    }
662
3.45k
    if (st->len != 5) {
663
17
        g_set_error(error,
664
17
                    FWUPD_ERROR,
665
17
                    FWUPD_ERROR_INVALID_DATA,
666
17
                    "FuStructEfiSectionCompression requested 0x%x and got 0x%x",
667
17
                    (guint) 5,
668
17
                    (guint) st->len);
669
17
        return NULL;
670
17
    }
671
3.43k
    if (!fu_struct_efi_section_compression_parse_internal(st, error))
672
0
        return NULL;
673
3.43k
    return g_steal_pointer(&st);
674
3.43k
}
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.65k
{
682
3.65k
    g_return_val_if_fail(st != NULL, 0x0);
683
3.65k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
684
3.65k
}
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.54k
{
691
3.54k
    g_return_val_if_fail(st != NULL, 0x0);
692
3.54k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
693
3.54k
}
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.65k
{
715
3.65k
    g_return_val_if_fail(st != NULL, FALSE);
716
3.65k
    return TRUE;
717
3.65k
}
718
static gboolean
719
fu_struct_efi_lz77_decompressor_header_parse_internal(FuStructEfiLz77DecompressorHeader *st, GError **error)
720
3.65k
{
721
3.65k
    if (!fu_struct_efi_lz77_decompressor_header_validate_internal(st, error))
722
0
        return FALSE;
723
3.65k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
724
0
        g_autofree gchar *str = fu_struct_efi_lz77_decompressor_header_to_string(st);
725
0
        g_debug("%s", str);
726
0
    }
727
3.65k
    return TRUE;
728
3.65k
}
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.69k
{
735
3.69k
    g_autoptr(GByteArray) st = NULL;
736
3.69k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
737
3.69k
    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.69k
    if (st->len != 8) {
742
36
        g_set_error(error,
743
36
                    FWUPD_ERROR,
744
36
                    FWUPD_ERROR_INVALID_DATA,
745
36
                    "FuStructEfiLz77DecompressorHeader requested 0x%x and got 0x%x",
746
36
                    (guint) 8,
747
36
                    (guint) st->len);
748
36
        return NULL;
749
36
    }
750
3.65k
    if (!fu_struct_efi_lz77_decompressor_header_parse_internal(st, error))
751
0
        return NULL;
752
3.65k
    return g_steal_pointer(&st);
753
3.65k
}
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.5k
{
761
95.5k
    g_return_val_if_fail(st != NULL, 0x0);
762
95.5k
    return fu_memread_uint24(st->data + 0, G_LITTLE_ENDIAN);
763
95.5k
}
764
/**
765
 * fu_struct_efi_section_get_type: (skip):
766
 **/
767
FuEfiSectionType
768
fu_struct_efi_section_get_type(const FuStructEfiSection *st)
769
47.5k
{
770
47.5k
    g_return_val_if_fail(st != NULL, 0x0);
771
47.5k
    return st->data[3];
772
47.5k
}
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.89k
{
781
7.89k
    g_return_if_fail(st != NULL);
782
7.89k
    fu_memwrite_uint24(st->data + 0, value, G_LITTLE_ENDIAN);
783
7.89k
}
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.89k
{
790
7.89k
    g_return_if_fail(st != NULL);
791
7.89k
    st->data[3] = value;
792
7.89k
}
793
/**
794
 * fu_struct_efi_section_new: (skip):
795
 **/
796
FuStructEfiSection *
797
fu_struct_efi_section_new(void)
798
8.24k
{
799
8.24k
    FuStructEfiSection *st = g_byte_array_sized_new(4);
800
8.24k
    fu_byte_array_set_size(st, 4, 0x0);
801
8.24k
    return st;
802
8.24k
}
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.6k
{
828
49.6k
    g_return_val_if_fail(st != NULL, FALSE);
829
49.6k
    return TRUE;
830
49.6k
}
831
static gboolean
832
fu_struct_efi_section_parse_internal(FuStructEfiSection *st, GError **error)
833
48.4k
{
834
48.4k
    if (!fu_struct_efi_section_validate_internal(st, error))
835
0
        return FALSE;
836
48.4k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
837
0
        g_autofree gchar *str = fu_struct_efi_section_to_string(st);
838
0
        g_debug("%s", str);
839
0
    }
840
48.4k
    return TRUE;
841
48.4k
}
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.6k
{
848
48.6k
    g_autoptr(GByteArray) st = NULL;
849
48.6k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
850
48.6k
    if (st == NULL) {
851
126
        g_prefix_error(error, "FuStructEfiSection failed read of 0x%x: ", (guint) 4);
852
126
        return NULL;
853
126
    }
854
48.4k
    if (st->len != 4) {
855
73
        g_set_error(error,
856
73
                    FWUPD_ERROR,
857
73
                    FWUPD_ERROR_INVALID_DATA,
858
73
                    "FuStructEfiSection requested 0x%x and got 0x%x",
859
73
                    (guint) 4,
860
73
                    (guint) st->len);
861
73
        return NULL;
862
73
    }
863
48.4k
    if (!fu_struct_efi_section_parse_internal(st, error))
864
0
        return NULL;
865
48.4k
    return g_steal_pointer(&st);
866
48.4k
}
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.28k
{
874
1.28k
    g_return_val_if_fail(st != NULL, 0x0);
875
1.28k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
876
1.28k
}
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.28k
{
896
1.28k
    g_return_val_if_fail(st != NULL, FALSE);
897
1.28k
    {
898
1.28k
        GByteArray st_tmp = {
899
1.28k
            .data = (guint8*) st->data + 0x0,
900
1.28k
            .len = 4,
901
1.28k
        };
902
1.28k
        if (!fu_struct_efi_section_validate_internal(&st_tmp, error))
903
0
            return FALSE;
904
1.28k
    }
905
1.28k
    return TRUE;
906
1.28k
}
907
static gboolean
908
fu_struct_efi_section2_parse_internal(FuStructEfiSection2 *st, GError **error)
909
1.28k
{
910
1.28k
    if (!fu_struct_efi_section2_validate_internal(st, error))
911
0
        return FALSE;
912
1.28k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
913
0
        g_autofree gchar *str = fu_struct_efi_section2_to_string(st);
914
0
        g_debug("%s", str);
915
0
    }
916
1.28k
    return TRUE;
917
1.28k
}
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.30k
{
924
1.30k
    g_autoptr(GByteArray) st = NULL;
925
1.30k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
926
1.30k
    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.30k
    if (st->len != 8) {
931
23
        g_set_error(error,
932
23
                    FWUPD_ERROR,
933
23
                    FWUPD_ERROR_INVALID_DATA,
934
23
                    "FuStructEfiSection2 requested 0x%x and got 0x%x",
935
23
                    (guint) 8,
936
23
                    (guint) st->len);
937
23
        return NULL;
938
23
    }
939
1.28k
    if (!fu_struct_efi_section2_parse_internal(st, error))
940
0
        return NULL;
941
1.28k
    return g_steal_pointer(&st);
942
1.28k
}
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
302
{
950
302
    g_return_val_if_fail(st != NULL, NULL);
951
302
    return (const fwupd_guid_t *) (st->data + 0);
952
302
}
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
302
{
974
302
    g_return_val_if_fail(st != NULL, FALSE);
975
302
    return TRUE;
976
302
}
977
static gboolean
978
fu_struct_efi_section_freeform_subtype_guid_parse_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error)
979
302
{
980
302
    if (!fu_struct_efi_section_freeform_subtype_guid_validate_internal(st, error))
981
0
        return FALSE;
982
302
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
983
0
        g_autofree gchar *str = fu_struct_efi_section_freeform_subtype_guid_to_string(st);
984
0
        g_debug("%s", str);
985
0
    }
986
302
    return TRUE;
987
302
}
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
323
{
994
323
    g_autoptr(GByteArray) st = NULL;
995
323
    st = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error);
996
323
    if (st == NULL) {
997
3
        g_prefix_error(error, "FuStructEfiSectionFreeformSubtypeGuid failed read of 0x%x: ", (guint) 16);
998
3
        return NULL;
999
3
    }
1000
320
    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
302
    if (!fu_struct_efi_section_freeform_subtype_guid_parse_internal(st, error))
1010
0
        return NULL;
1011
302
    return g_steal_pointer(&st);
1012
302
}
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.27k
{
1020
7.27k
    g_return_val_if_fail(st != NULL, NULL);
1021
7.27k
    return (const fwupd_guid_t *) (st->data + 0);
1022
7.27k
}
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.5k
{
1029
14.5k
    g_return_val_if_fail(st != NULL, 0x0);
1030
14.5k
    return fu_memread_uint16(st->data + 16, G_LITTLE_ENDIAN);
1031
14.5k
}
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.69k
{
1049
1.69k
    g_return_if_fail(st != NULL);
1050
1.69k
    g_return_if_fail(value != NULL);
1051
1.69k
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
1052
1.69k
}
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.69k
{
1059
1.69k
    g_return_if_fail(st != NULL);
1060
1.69k
    fu_memwrite_uint16(st->data + 16, value, G_LITTLE_ENDIAN);
1061
1.69k
}
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.69k
{
1077
1.69k
    FuStructEfiSectionGuidDefined *st = g_byte_array_sized_new(20);
1078
1.69k
    fu_byte_array_set_size(st, 20, 0x0);
1079
1.69k
    return st;
1080
1.69k
}
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.27k
{
1104
7.27k
    g_return_val_if_fail(st != NULL, FALSE);
1105
7.27k
    return TRUE;
1106
7.27k
}
1107
static gboolean
1108
fu_struct_efi_section_guid_defined_parse_internal(FuStructEfiSectionGuidDefined *st, GError **error)
1109
7.27k
{
1110
7.27k
    if (!fu_struct_efi_section_guid_defined_validate_internal(st, error))
1111
0
        return FALSE;
1112
7.27k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1113
0
        g_autofree gchar *str = fu_struct_efi_section_guid_defined_to_string(st);
1114
0
        g_debug("%s", str);
1115
0
    }
1116
7.27k
    return TRUE;
1117
7.27k
}
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.29k
{
1124
7.29k
    g_autoptr(GByteArray) st = NULL;
1125
7.29k
    st = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error);
1126
7.29k
    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.29k
    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.27k
    if (!fu_struct_efi_section_guid_defined_parse_internal(st, error))
1140
0
        return NULL;
1141
7.27k
    return g_steal_pointer(&st);
1142
7.27k
}
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.78k
{
1159
9.78k
    g_return_val_if_fail(st != NULL, NULL);
1160
9.78k
    return (const fwupd_guid_t *) (st->data + 16);
1161
9.78k
}
1162
/**
1163
 * fu_struct_efi_volume_get_length: (skip):
1164
 **/
1165
guint64
1166
fu_struct_efi_volume_get_length(const FuStructEfiVolume *st)
1167
9.78k
{
1168
9.78k
    g_return_val_if_fail(st != NULL, 0x0);
1169
9.78k
    return fu_memread_uint64(st->data + 32, G_LITTLE_ENDIAN);
1170
9.78k
}
1171
/**
1172
 * fu_struct_efi_volume_get_signature: (skip):
1173
 **/
1174
static guint32
1175
fu_struct_efi_volume_get_signature(const FuStructEfiVolume *st)
1176
11.2M
{
1177
11.2M
    g_return_val_if_fail(st != NULL, 0x0);
1178
11.2M
    return fu_memread_uint32(st->data + 40, G_LITTLE_ENDIAN);
1179
11.2M
}
1180
/**
1181
 * fu_struct_efi_volume_get_attrs: (skip):
1182
 **/
1183
guint32
1184
fu_struct_efi_volume_get_attrs(const FuStructEfiVolume *st)
1185
9.75k
{
1186
9.75k
    g_return_val_if_fail(st != NULL, 0x0);
1187
9.75k
    return fu_memread_uint32(st->data + 44, G_LITTLE_ENDIAN);
1188
9.75k
}
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
9.26k
{
1195
9.26k
    g_return_val_if_fail(st != NULL, 0x0);
1196
9.26k
    return fu_memread_uint16(st->data + 48, G_LITTLE_ENDIAN);
1197
9.26k
}
1198
/**
1199
 * fu_struct_efi_volume_get_checksum: (skip):
1200
 **/
1201
guint16
1202
fu_struct_efi_volume_get_checksum(const FuStructEfiVolume *st)
1203
633
{
1204
633
    g_return_val_if_fail(st != NULL, 0x0);
1205
633
    return fu_memread_uint16(st->data + 50, G_LITTLE_ENDIAN);
1206
633
}
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
7.22k
{
1213
7.22k
    g_return_val_if_fail(st != NULL, 0x0);
1214
7.22k
    return fu_memread_uint16(st->data + 52, G_LITTLE_ENDIAN);
1215
7.22k
}
1216
/**
1217
 * fu_struct_efi_volume_get_revision: (skip):
1218
 **/
1219
static guint8
1220
fu_struct_efi_volume_get_revision(const FuStructEfiVolume *st)
1221
20.7k
{
1222
20.7k
    g_return_val_if_fail(st != NULL, 0x0);
1223
20.7k
    return st->data[55];
1224
20.7k
}
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.37k
{
1243
2.37k
    g_return_if_fail(st != NULL);
1244
2.37k
    g_return_if_fail(value != NULL);
1245
2.37k
    memcpy(st->data + 16, value, sizeof(*value)); /* nocheck:blocked */
1246
2.37k
}
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.37k
{
1253
2.37k
    g_return_if_fail(st != NULL);
1254
2.37k
    fu_memwrite_uint64(st->data + 32, value, G_LITTLE_ENDIAN);
1255
2.37k
}
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.53k
{
1262
2.53k
    g_return_if_fail(st != NULL);
1263
2.53k
    fu_memwrite_uint32(st->data + 40, value, G_LITTLE_ENDIAN);
1264
2.53k
}
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.37k
{
1271
2.37k
    g_return_if_fail(st != NULL);
1272
2.37k
    fu_memwrite_uint32(st->data + 44, value, G_LITTLE_ENDIAN);
1273
2.37k
}
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.37k
{
1280
2.37k
    g_return_if_fail(st != NULL);
1281
2.37k
    fu_memwrite_uint16(st->data + 48, value, G_LITTLE_ENDIAN);
1282
2.37k
}
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.37k
{
1289
2.37k
    g_return_if_fail(st != NULL);
1290
2.37k
    fu_memwrite_uint16(st->data + 50, value, G_LITTLE_ENDIAN);
1291
2.37k
}
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.53k
{
1307
2.53k
    g_return_if_fail(st != NULL);
1308
2.53k
    st->data[55] = value;
1309
2.53k
}
1310
/**
1311
 * fu_struct_efi_volume_new: (skip):
1312
 **/
1313
FuStructEfiVolume *
1314
fu_struct_efi_volume_new(void)
1315
2.53k
{
1316
2.53k
    FuStructEfiVolume *st = g_byte_array_sized_new(56);
1317
2.53k
    fu_byte_array_set_size(st, 56, 0x0);
1318
2.53k
    fu_struct_efi_volume_set_signature(st, 0x4856465F);
1319
2.53k
    fu_struct_efi_volume_set_revision(st, 0x02);
1320
2.53k
    return st;
1321
2.53k
}
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
11.2M
{
1355
11.2M
    g_return_val_if_fail(st != NULL, FALSE);
1356
11.2M
    if (fu_struct_efi_volume_get_signature(st) != 0x4856465F) {
1357
11.2M
        g_set_error_literal(error,
1358
11.2M
                            FWUPD_ERROR,
1359
11.2M
                            FWUPD_ERROR_INVALID_DATA,
1360
11.2M
                            "constant FuStructEfiVolume.signature was not valid");
1361
11.2M
        return FALSE;
1362
11.2M
    }
1363
20.7k
    if (fu_struct_efi_volume_get_revision(st) != 0x02) {
1364
1.14k
        g_set_error_literal(error,
1365
1.14k
                            FWUPD_ERROR,
1366
1.14k
                            FWUPD_ERROR_INVALID_DATA,
1367
1.14k
                            "constant FuStructEfiVolume.revision was not valid");
1368
1.14k
        return FALSE;
1369
1.14k
    }
1370
19.5k
    return TRUE;
1371
20.7k
}
1372
/**
1373
 * fu_struct_efi_volume_validate_stream: (skip):
1374
 **/
1375
gboolean
1376
fu_struct_efi_volume_validate_stream(GInputStream *stream, gsize offset, GError **error)
1377
11.2M
{
1378
11.2M
    g_autoptr(GByteArray) st = NULL;
1379
11.2M
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
1380
11.2M
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
1381
11.2M
    st = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error);
1382
11.2M
    if (st == NULL) {
1383
2
        g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56);
1384
2
        return FALSE;
1385
2
    }
1386
11.2M
    if (st->len != 56) {
1387
8.22k
        g_set_error(error,
1388
8.22k
                    FWUPD_ERROR,
1389
8.22k
                    FWUPD_ERROR_INVALID_DATA,
1390
8.22k
                    "FuStructEfiVolume requested 0x%x and got 0x%x",
1391
8.22k
                    (guint) 56,
1392
8.22k
                    (guint) st->len);
1393
8.22k
        return FALSE;
1394
8.22k
    }
1395
11.2M
    return fu_struct_efi_volume_validate_internal(st, error);
1396
11.2M
}
1397
static gboolean
1398
fu_struct_efi_volume_parse_internal(FuStructEfiVolume *st, GError **error)
1399
9.78k
{
1400
9.78k
    if (!fu_struct_efi_volume_validate_internal(st, error))
1401
0
        return FALSE;
1402
9.78k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1403
0
        g_autofree gchar *str = fu_struct_efi_volume_to_string(st);
1404
0
        g_debug("%s", str);
1405
0
    }
1406
9.78k
    return TRUE;
1407
9.78k
}
1408
/**
1409
 * fu_struct_efi_volume_parse_stream: (skip):
1410
 **/
1411
FuStructEfiVolume *
1412
fu_struct_efi_volume_parse_stream(GInputStream *stream, gsize offset, GError **error)
1413
9.78k
{
1414
9.78k
    g_autoptr(GByteArray) st = NULL;
1415
9.78k
    st = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error);
1416
9.78k
    if (st == NULL) {
1417
0
        g_prefix_error(error, "FuStructEfiVolume failed read of 0x%x: ", (guint) 56);
1418
0
        return NULL;
1419
0
    }
1420
9.78k
    if (st->len != 56) {
1421
0
        g_set_error(error,
1422
0
                    FWUPD_ERROR,
1423
0
                    FWUPD_ERROR_INVALID_DATA,
1424
0
                    "FuStructEfiVolume requested 0x%x and got 0x%x",
1425
0
                    (guint) 56,
1426
0
                    (guint) st->len);
1427
0
        return NULL;
1428
0
    }
1429
9.78k
    if (!fu_struct_efi_volume_parse_internal(st, error))
1430
0
        return NULL;
1431
9.78k
    return g_steal_pointer(&st);
1432
9.78k
}
1433
/* getters */
1434
/**
1435
 * fu_struct_efi_volume_ext_header_get_fv_name: (skip):
1436
 **/
1437
const fwupd_guid_t *
1438
fu_struct_efi_volume_ext_header_get_fv_name(const FuStructEfiVolumeExtHeader *st)
1439
0
{
1440
0
    g_return_val_if_fail(st != NULL, NULL);
1441
0
    return (const fwupd_guid_t *) (st->data + 0);
1442
0
}
1443
/**
1444
 * fu_struct_efi_volume_ext_header_get_size: (skip):
1445
 **/
1446
guint32
1447
fu_struct_efi_volume_ext_header_get_size(const FuStructEfiVolumeExtHeader *st)
1448
362
{
1449
362
    g_return_val_if_fail(st != NULL, 0x0);
1450
362
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
1451
362
}
1452
1453
/* setters */
1454
/**
1455
 * fu_struct_efi_volume_ext_header_to_string: (skip):
1456
 **/
1457
static gchar *
1458
fu_struct_efi_volume_ext_header_to_string(const FuStructEfiVolumeExtHeader *st)
1459
0
{
1460
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtHeader:\n");
1461
0
    g_return_val_if_fail(st != NULL, NULL);
1462
0
    {
1463
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_volume_ext_header_get_fv_name(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
1464
0
        g_string_append_printf(str, "  fv_name: %s\n", tmp);
1465
0
    }
1466
0
    g_string_append_printf(str, "  size: 0x%x\n",
1467
0
                           (guint) fu_struct_efi_volume_ext_header_get_size(st));
1468
0
    if (str->len > 0)
1469
0
        g_string_set_size(str, str->len - 1);
1470
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1471
0
}
1472
static gboolean
1473
fu_struct_efi_volume_ext_header_validate_internal(FuStructEfiVolumeExtHeader *st, GError **error)
1474
362
{
1475
362
    g_return_val_if_fail(st != NULL, FALSE);
1476
362
    return TRUE;
1477
362
}
1478
static gboolean
1479
fu_struct_efi_volume_ext_header_parse_internal(FuStructEfiVolumeExtHeader *st, GError **error)
1480
362
{
1481
362
    if (!fu_struct_efi_volume_ext_header_validate_internal(st, error))
1482
0
        return FALSE;
1483
362
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1484
0
        g_autofree gchar *str = fu_struct_efi_volume_ext_header_to_string(st);
1485
0
        g_debug("%s", str);
1486
0
    }
1487
362
    return TRUE;
1488
362
}
1489
/**
1490
 * fu_struct_efi_volume_ext_header_parse_stream: (skip):
1491
 **/
1492
FuStructEfiVolumeExtHeader *
1493
fu_struct_efi_volume_ext_header_parse_stream(GInputStream *stream, gsize offset, GError **error)
1494
428
{
1495
428
    g_autoptr(GByteArray) st = NULL;
1496
428
    st = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error);
1497
428
    if (st == NULL) {
1498
54
        g_prefix_error(error, "FuStructEfiVolumeExtHeader failed read of 0x%x: ", (guint) 20);
1499
54
        return NULL;
1500
54
    }
1501
374
    if (st->len != 20) {
1502
12
        g_set_error(error,
1503
12
                    FWUPD_ERROR,
1504
12
                    FWUPD_ERROR_INVALID_DATA,
1505
12
                    "FuStructEfiVolumeExtHeader requested 0x%x and got 0x%x",
1506
12
                    (guint) 20,
1507
12
                    (guint) st->len);
1508
12
        return NULL;
1509
12
    }
1510
362
    if (!fu_struct_efi_volume_ext_header_parse_internal(st, error))
1511
0
        return NULL;
1512
362
    return g_steal_pointer(&st);
1513
362
}
1514
/* getters */
1515
/**
1516
 * fu_struct_efi_volume_ext_entry_get_size: (skip):
1517
 **/
1518
guint16
1519
fu_struct_efi_volume_ext_entry_get_size(const FuStructEfiVolumeExtEntry *st)
1520
10.0k
{
1521
10.0k
    g_return_val_if_fail(st != NULL, 0x0);
1522
10.0k
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
1523
10.0k
}
1524
/**
1525
 * fu_struct_efi_volume_ext_entry_get_type: (skip):
1526
 **/
1527
FuEfiVolumeExtEntryType
1528
fu_struct_efi_volume_ext_entry_get_type(const FuStructEfiVolumeExtEntry *st)
1529
0
{
1530
0
    g_return_val_if_fail(st != NULL, 0x0);
1531
0
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
1532
0
}
1533
1534
/* setters */
1535
/**
1536
 * fu_struct_efi_volume_ext_entry_to_string: (skip):
1537
 **/
1538
static gchar *
1539
fu_struct_efi_volume_ext_entry_to_string(const FuStructEfiVolumeExtEntry *st)
1540
0
{
1541
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeExtEntry:\n");
1542
0
    g_return_val_if_fail(st != NULL, NULL);
1543
0
    g_string_append_printf(str, "  size: 0x%x\n",
1544
0
                           (guint) fu_struct_efi_volume_ext_entry_get_size(st));
1545
0
    {
1546
0
        const gchar *tmp = fu_efi_volume_ext_entry_type_to_string(fu_struct_efi_volume_ext_entry_get_type(st));
1547
0
        if (tmp != NULL) {
1548
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st), tmp);
1549
0
        } else {
1550
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_volume_ext_entry_get_type(st));
1551
0
        }
1552
0
    }
1553
0
    if (str->len > 0)
1554
0
        g_string_set_size(str, str->len - 1);
1555
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1556
0
}
1557
static gboolean
1558
fu_struct_efi_volume_ext_entry_validate_internal(FuStructEfiVolumeExtEntry *st, GError **error)
1559
3.38k
{
1560
3.38k
    g_return_val_if_fail(st != NULL, FALSE);
1561
3.38k
    return TRUE;
1562
3.38k
}
1563
static gboolean
1564
fu_struct_efi_volume_ext_entry_parse_internal(FuStructEfiVolumeExtEntry *st, GError **error)
1565
3.38k
{
1566
3.38k
    if (!fu_struct_efi_volume_ext_entry_validate_internal(st, error))
1567
0
        return FALSE;
1568
3.38k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1569
0
        g_autofree gchar *str = fu_struct_efi_volume_ext_entry_to_string(st);
1570
0
        g_debug("%s", str);
1571
0
    }
1572
3.38k
    return TRUE;
1573
3.38k
}
1574
/**
1575
 * fu_struct_efi_volume_ext_entry_parse_stream: (skip):
1576
 **/
1577
FuStructEfiVolumeExtEntry *
1578
fu_struct_efi_volume_ext_entry_parse_stream(GInputStream *stream, gsize offset, GError **error)
1579
3.56k
{
1580
3.56k
    g_autoptr(GByteArray) st = NULL;
1581
3.56k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
1582
3.56k
    if (st == NULL) {
1583
157
        g_prefix_error(error, "FuStructEfiVolumeExtEntry failed read of 0x%x: ", (guint) 4);
1584
157
        return NULL;
1585
157
    }
1586
3.40k
    if (st->len != 4) {
1587
22
        g_set_error(error,
1588
22
                    FWUPD_ERROR,
1589
22
                    FWUPD_ERROR_INVALID_DATA,
1590
22
                    "FuStructEfiVolumeExtEntry requested 0x%x and got 0x%x",
1591
22
                    (guint) 4,
1592
22
                    (guint) st->len);
1593
22
        return NULL;
1594
22
    }
1595
3.38k
    if (!fu_struct_efi_volume_ext_entry_parse_internal(st, error))
1596
0
        return NULL;
1597
3.38k
    return g_steal_pointer(&st);
1598
3.38k
}
1599
/* getters */
1600
/**
1601
 * fu_struct_efi_volume_block_map_get_num_blocks: (skip):
1602
 **/
1603
guint32
1604
fu_struct_efi_volume_block_map_get_num_blocks(const FuStructEfiVolumeBlockMap *st)
1605
331k
{
1606
331k
    g_return_val_if_fail(st != NULL, 0x0);
1607
331k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
1608
331k
}
1609
/**
1610
 * fu_struct_efi_volume_block_map_get_length: (skip):
1611
 **/
1612
guint32
1613
fu_struct_efi_volume_block_map_get_length(const FuStructEfiVolumeBlockMap *st)
1614
331k
{
1615
331k
    g_return_val_if_fail(st != NULL, 0x0);
1616
331k
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
1617
331k
}
1618
1619
/* setters */
1620
/**
1621
 * fu_struct_efi_volume_block_map_set_num_blocks: (skip):
1622
 **/
1623
void
1624
fu_struct_efi_volume_block_map_set_num_blocks(FuStructEfiVolumeBlockMap *st, guint32 value)
1625
4.74k
{
1626
4.74k
    g_return_if_fail(st != NULL);
1627
4.74k
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
1628
4.74k
}
1629
/**
1630
 * fu_struct_efi_volume_block_map_set_length: (skip):
1631
 **/
1632
void
1633
fu_struct_efi_volume_block_map_set_length(FuStructEfiVolumeBlockMap *st, guint32 value)
1634
4.74k
{
1635
4.74k
    g_return_if_fail(st != NULL);
1636
4.74k
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
1637
4.74k
}
1638
/**
1639
 * fu_struct_efi_volume_block_map_new: (skip):
1640
 **/
1641
FuStructEfiVolumeBlockMap *
1642
fu_struct_efi_volume_block_map_new(void)
1643
2.53k
{
1644
2.53k
    FuStructEfiVolumeBlockMap *st = g_byte_array_sized_new(8);
1645
2.53k
    fu_byte_array_set_size(st, 8, 0x0);
1646
2.53k
    return st;
1647
2.53k
}
1648
/**
1649
 * fu_struct_efi_volume_block_map_to_string: (skip):
1650
 **/
1651
static gchar *
1652
fu_struct_efi_volume_block_map_to_string(const FuStructEfiVolumeBlockMap *st)
1653
0
{
1654
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVolumeBlockMap:\n");
1655
0
    g_return_val_if_fail(st != NULL, NULL);
1656
0
    g_string_append_printf(str, "  num_blocks: 0x%x\n",
1657
0
                           (guint) fu_struct_efi_volume_block_map_get_num_blocks(st));
1658
0
    g_string_append_printf(str, "  length: 0x%x\n",
1659
0
                           (guint) fu_struct_efi_volume_block_map_get_length(st));
1660
0
    if (str->len > 0)
1661
0
        g_string_set_size(str, str->len - 1);
1662
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1663
0
}
1664
static gboolean
1665
fu_struct_efi_volume_block_map_validate_internal(FuStructEfiVolumeBlockMap *st, GError **error)
1666
331k
{
1667
331k
    g_return_val_if_fail(st != NULL, FALSE);
1668
331k
    return TRUE;
1669
331k
}
1670
static gboolean
1671
fu_struct_efi_volume_block_map_parse_internal(FuStructEfiVolumeBlockMap *st, GError **error)
1672
331k
{
1673
331k
    if (!fu_struct_efi_volume_block_map_validate_internal(st, error))
1674
0
        return FALSE;
1675
331k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1676
0
        g_autofree gchar *str = fu_struct_efi_volume_block_map_to_string(st);
1677
0
        g_debug("%s", str);
1678
0
    }
1679
331k
    return TRUE;
1680
331k
}
1681
/**
1682
 * fu_struct_efi_volume_block_map_parse_stream: (skip):
1683
 **/
1684
FuStructEfiVolumeBlockMap *
1685
fu_struct_efi_volume_block_map_parse_stream(GInputStream *stream, gsize offset, GError **error)
1686
331k
{
1687
331k
    g_autoptr(GByteArray) st = NULL;
1688
331k
    st = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error);
1689
331k
    if (st == NULL) {
1690
0
        g_prefix_error(error, "FuStructEfiVolumeBlockMap failed read of 0x%x: ", (guint) 8);
1691
0
        return NULL;
1692
0
    }
1693
331k
    if (st->len != 8) {
1694
127
        g_set_error(error,
1695
127
                    FWUPD_ERROR,
1696
127
                    FWUPD_ERROR_INVALID_DATA,
1697
127
                    "FuStructEfiVolumeBlockMap requested 0x%x and got 0x%x",
1698
127
                    (guint) 8,
1699
127
                    (guint) st->len);
1700
127
        return NULL;
1701
127
    }
1702
331k
    if (!fu_struct_efi_volume_block_map_parse_internal(st, error))
1703
0
        return NULL;
1704
331k
    return g_steal_pointer(&st);
1705
331k
}
1706
/* getters */
1707
/**
1708
 * fu_struct_efi_time_get_year: (skip):
1709
 **/
1710
guint16
1711
fu_struct_efi_time_get_year(const FuStructEfiTime *st)
1712
0
{
1713
0
    g_return_val_if_fail(st != NULL, 0x0);
1714
0
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
1715
0
}
1716
/**
1717
 * fu_struct_efi_time_get_month: (skip):
1718
 **/
1719
guint8
1720
fu_struct_efi_time_get_month(const FuStructEfiTime *st)
1721
0
{
1722
0
    g_return_val_if_fail(st != NULL, 0x0);
1723
0
    return st->data[2];
1724
0
}
1725
/**
1726
 * fu_struct_efi_time_get_day: (skip):
1727
 **/
1728
guint8
1729
fu_struct_efi_time_get_day(const FuStructEfiTime *st)
1730
0
{
1731
0
    g_return_val_if_fail(st != NULL, 0x0);
1732
0
    return st->data[3];
1733
0
}
1734
/**
1735
 * fu_struct_efi_time_get_hour: (skip):
1736
 **/
1737
guint8
1738
fu_struct_efi_time_get_hour(const FuStructEfiTime *st)
1739
0
{
1740
0
    g_return_val_if_fail(st != NULL, 0x0);
1741
0
    return st->data[4];
1742
0
}
1743
/**
1744
 * fu_struct_efi_time_get_minute: (skip):
1745
 **/
1746
guint8
1747
fu_struct_efi_time_get_minute(const FuStructEfiTime *st)
1748
0
{
1749
0
    g_return_val_if_fail(st != NULL, 0x0);
1750
0
    return st->data[5];
1751
0
}
1752
/**
1753
 * fu_struct_efi_time_get_second: (skip):
1754
 **/
1755
guint8
1756
fu_struct_efi_time_get_second(const FuStructEfiTime *st)
1757
0
{
1758
0
    g_return_val_if_fail(st != NULL, 0x0);
1759
0
    return st->data[6];
1760
0
}
1761
/**
1762
 * fu_struct_efi_time_get_nanosecond: (skip):
1763
 **/
1764
guint32
1765
fu_struct_efi_time_get_nanosecond(const FuStructEfiTime *st)
1766
0
{
1767
0
    g_return_val_if_fail(st != NULL, 0x0);
1768
0
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
1769
0
}
1770
/**
1771
 * fu_struct_efi_time_get_timezone: (skip):
1772
 **/
1773
guint16
1774
fu_struct_efi_time_get_timezone(const FuStructEfiTime *st)
1775
0
{
1776
0
    g_return_val_if_fail(st != NULL, 0x0);
1777
0
    return fu_memread_uint16(st->data + 12, G_LITTLE_ENDIAN);
1778
0
}
1779
/**
1780
 * fu_struct_efi_time_get_daylight: (skip):
1781
 **/
1782
guint8
1783
fu_struct_efi_time_get_daylight(const FuStructEfiTime *st)
1784
0
{
1785
0
    g_return_val_if_fail(st != NULL, 0x0);
1786
0
    return st->data[14];
1787
0
}
1788
1789
/* setters */
1790
/**
1791
 * fu_struct_efi_time_new: (skip):
1792
 **/
1793
static FuStructEfiTime *
1794
fu_struct_efi_time_new(void)
1795
0
{
1796
0
    FuStructEfiTime *st = g_byte_array_sized_new(16);
1797
0
    fu_byte_array_set_size(st, 16, 0x0);
1798
0
    return st;
1799
0
}
1800
/**
1801
 * fu_struct_efi_time_to_string: (skip):
1802
 **/
1803
static gchar *
1804
fu_struct_efi_time_to_string(const FuStructEfiTime *st)
1805
0
{
1806
0
    g_autoptr(GString) str = g_string_new("FuStructEfiTime:\n");
1807
0
    g_return_val_if_fail(st != NULL, NULL);
1808
0
    g_string_append_printf(str, "  year: 0x%x\n",
1809
0
                           (guint) fu_struct_efi_time_get_year(st));
1810
0
    g_string_append_printf(str, "  month: 0x%x\n",
1811
0
                           (guint) fu_struct_efi_time_get_month(st));
1812
0
    g_string_append_printf(str, "  day: 0x%x\n",
1813
0
                           (guint) fu_struct_efi_time_get_day(st));
1814
0
    g_string_append_printf(str, "  hour: 0x%x\n",
1815
0
                           (guint) fu_struct_efi_time_get_hour(st));
1816
0
    g_string_append_printf(str, "  minute: 0x%x\n",
1817
0
                           (guint) fu_struct_efi_time_get_minute(st));
1818
0
    g_string_append_printf(str, "  second: 0x%x\n",
1819
0
                           (guint) fu_struct_efi_time_get_second(st));
1820
0
    g_string_append_printf(str, "  nanosecond: 0x%x\n",
1821
0
                           (guint) fu_struct_efi_time_get_nanosecond(st));
1822
0
    g_string_append_printf(str, "  timezone: 0x%x\n",
1823
0
                           (guint) fu_struct_efi_time_get_timezone(st));
1824
0
    g_string_append_printf(str, "  daylight: 0x%x\n",
1825
0
                           (guint) fu_struct_efi_time_get_daylight(st));
1826
0
    if (str->len > 0)
1827
0
        g_string_set_size(str, str->len - 1);
1828
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1829
0
}
1830
static gboolean
1831
fu_struct_efi_time_validate_internal(FuStructEfiTime *st, GError **error)
1832
0
{
1833
0
    g_return_val_if_fail(st != NULL, FALSE);
1834
0
    return TRUE;
1835
0
}
1836
/* getters */
1837
/**
1838
 * fu_struct_efi_win_certificate_get_length: (skip):
1839
 **/
1840
guint32
1841
fu_struct_efi_win_certificate_get_length(const FuStructEfiWinCertificate *st)
1842
0
{
1843
0
    g_return_val_if_fail(st != NULL, 0x0);
1844
0
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
1845
0
}
1846
/**
1847
 * fu_struct_efi_win_certificate_get_revision: (skip):
1848
 **/
1849
static guint16
1850
fu_struct_efi_win_certificate_get_revision(const FuStructEfiWinCertificate *st)
1851
0
{
1852
0
    g_return_val_if_fail(st != NULL, 0x0);
1853
0
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
1854
0
}
1855
/**
1856
 * fu_struct_efi_win_certificate_get_certificate_type: (skip):
1857
 **/
1858
static guint16
1859
fu_struct_efi_win_certificate_get_certificate_type(const FuStructEfiWinCertificate *st)
1860
0
{
1861
0
    g_return_val_if_fail(st != NULL, 0x0);
1862
0
    return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN);
1863
0
}
1864
/**
1865
 * fu_struct_efi_win_certificate_get_guid: (skip):
1866
 **/
1867
static const fwupd_guid_t *
1868
fu_struct_efi_win_certificate_get_guid(const FuStructEfiWinCertificate *st)
1869
0
{
1870
0
    g_return_val_if_fail(st != NULL, NULL);
1871
0
    return (const fwupd_guid_t *) (st->data + 8);
1872
0
}
1873
1874
/* setters */
1875
/**
1876
 * fu_struct_efi_win_certificate_set_length: (skip):
1877
 **/
1878
void
1879
fu_struct_efi_win_certificate_set_length(FuStructEfiWinCertificate *st, guint32 value)
1880
0
{
1881
0
    g_return_if_fail(st != NULL);
1882
0
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
1883
0
}
1884
/**
1885
 * fu_struct_efi_win_certificate_set_revision: (skip):
1886
 **/
1887
static void
1888
fu_struct_efi_win_certificate_set_revision(FuStructEfiWinCertificate *st, guint16 value)
1889
0
{
1890
0
    g_return_if_fail(st != NULL);
1891
0
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
1892
0
}
1893
/**
1894
 * fu_struct_efi_win_certificate_set_certificate_type: (skip):
1895
 **/
1896
static void
1897
fu_struct_efi_win_certificate_set_certificate_type(FuStructEfiWinCertificate *st, guint16 value)
1898
0
{
1899
0
    g_return_if_fail(st != NULL);
1900
0
    fu_memwrite_uint16(st->data + 6, value, G_LITTLE_ENDIAN);
1901
0
}
1902
/**
1903
 * fu_struct_efi_win_certificate_set_guid: (skip):
1904
 **/
1905
static void
1906
fu_struct_efi_win_certificate_set_guid(FuStructEfiWinCertificate *st, const fwupd_guid_t *value)
1907
0
{
1908
0
    g_return_if_fail(st != NULL);
1909
0
    g_return_if_fail(value != NULL);
1910
0
    memcpy(st->data + 8, value, sizeof(*value)); /* nocheck:blocked */
1911
0
}
1912
/**
1913
 * fu_struct_efi_win_certificate_new: (skip):
1914
 **/
1915
static FuStructEfiWinCertificate *
1916
fu_struct_efi_win_certificate_new(void)
1917
0
{
1918
0
    FuStructEfiWinCertificate *st = g_byte_array_sized_new(24);
1919
0
    fu_byte_array_set_size(st, 24, 0x0);
1920
0
    fu_struct_efi_win_certificate_set_length(st, 24);
1921
0
    fu_struct_efi_win_certificate_set_revision(st, 0x0200);
1922
0
    fu_struct_efi_win_certificate_set_certificate_type(st, 0x0EF1);
1923
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");
1924
0
    return st;
1925
0
}
1926
/**
1927
 * fu_struct_efi_win_certificate_to_string: (skip):
1928
 **/
1929
static gchar *
1930
fu_struct_efi_win_certificate_to_string(const FuStructEfiWinCertificate *st)
1931
0
{
1932
0
    g_autoptr(GString) str = g_string_new("FuStructEfiWinCertificate:\n");
1933
0
    g_return_val_if_fail(st != NULL, NULL);
1934
0
    g_string_append_printf(str, "  length: 0x%x\n",
1935
0
                           (guint) fu_struct_efi_win_certificate_get_length(st));
1936
0
    if (str->len > 0)
1937
0
        g_string_set_size(str, str->len - 1);
1938
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1939
0
}
1940
static gboolean
1941
fu_struct_efi_win_certificate_validate_internal(FuStructEfiWinCertificate *st, GError **error)
1942
0
{
1943
0
    g_return_val_if_fail(st != NULL, FALSE);
1944
0
    if (fu_struct_efi_win_certificate_get_revision(st) != 0x0200) {
1945
0
        g_set_error_literal(error,
1946
0
                            FWUPD_ERROR,
1947
0
                            FWUPD_ERROR_INVALID_DATA,
1948
0
                            "constant FuStructEfiWinCertificate.revision was not valid");
1949
0
        return FALSE;
1950
0
    }
1951
0
    if (fu_struct_efi_win_certificate_get_certificate_type(st) != 0x0EF1) {
1952
0
        g_set_error_literal(error,
1953
0
                            FWUPD_ERROR,
1954
0
                            FWUPD_ERROR_INVALID_DATA,
1955
0
                            "constant FuStructEfiWinCertificate.certificate_type was not valid");
1956
0
        return FALSE;
1957
0
    }
1958
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) {
1959
0
        g_set_error_literal(error,
1960
0
                            FWUPD_ERROR,
1961
0
                            FWUPD_ERROR_INVALID_DATA,
1962
0
                            "constant FuStructEfiWinCertificate.guid was not valid");
1963
0
        return FALSE;
1964
0
    }
1965
0
    return TRUE;
1966
0
}
1967
/* getters */
1968
/**
1969
 * fu_struct_efi_variable_authentication2_get_timestamp: (skip):
1970
 **/
1971
FuStructEfiTime *
1972
fu_struct_efi_variable_authentication2_get_timestamp(const FuStructEfiVariableAuthentication2 *st)
1973
0
{
1974
0
    g_autoptr(GByteArray) buf = g_byte_array_new();
1975
0
    g_return_val_if_fail(st != NULL, NULL);
1976
0
    g_byte_array_append(buf, st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, 16);
1977
0
    return g_steal_pointer(&buf);
1978
0
}
1979
/**
1980
 * fu_struct_efi_variable_authentication2_get_auth_info: (skip):
1981
 **/
1982
FuStructEfiWinCertificate *
1983
fu_struct_efi_variable_authentication2_get_auth_info(const FuStructEfiVariableAuthentication2 *st)
1984
0
{
1985
0
    g_autoptr(GByteArray) buf = g_byte_array_new();
1986
0
    g_return_val_if_fail(st != NULL, NULL);
1987
0
    g_byte_array_append(buf, st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, 24);
1988
0
    return g_steal_pointer(&buf);
1989
0
}
1990
1991
/* setters */
1992
/**
1993
 * fu_struct_efi_variable_authentication2_set_timestamp: (skip):
1994
 **/
1995
gboolean
1996
fu_struct_efi_variable_authentication2_set_timestamp(FuStructEfiVariableAuthentication2 *st, const FuStructEfiTime *st_donor, GError **error)
1997
0
{
1998
0
    g_return_val_if_fail(st != NULL, FALSE);
1999
0
    g_return_val_if_fail(st_donor != NULL, FALSE);
2000
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2001
2002
0
    if (st_donor->len > FU_STRUCT_EFI_TIME_SIZE) {
2003
0
        g_set_error(error,
2004
0
                    FWUPD_ERROR,
2005
0
                    FWUPD_ERROR_INVALID_DATA,
2006
0
                    "donor 'FuStructEfiTime' (0x%x bytes) does not fit in "
2007
0
                    "FuStructEfiVariableAuthentication2.timestamp (0x%x bytes)",
2008
0
                    (guint) st_donor->len,
2009
0
                    (guint) FU_STRUCT_EFI_TIME_SIZE);
2010
0
        return FALSE;
2011
0
    }
2012
0
    memcpy(st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_TIMESTAMP, st_donor->data, st_donor->len);
2013
0
    return TRUE;
2014
0
}
2015
/**
2016
 * fu_struct_efi_variable_authentication2_set_auth_info: (skip):
2017
 **/
2018
gboolean
2019
fu_struct_efi_variable_authentication2_set_auth_info(FuStructEfiVariableAuthentication2 *st, const FuStructEfiWinCertificate *st_donor, GError **error)
2020
0
{
2021
0
    g_return_val_if_fail(st != NULL, FALSE);
2022
0
    g_return_val_if_fail(st_donor != NULL, FALSE);
2023
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2024
2025
0
    if (st_donor->len > FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE) {
2026
0
        g_set_error(error,
2027
0
                    FWUPD_ERROR,
2028
0
                    FWUPD_ERROR_INVALID_DATA,
2029
0
                    "donor 'FuStructEfiWinCertificate' (0x%x bytes) does not fit in "
2030
0
                    "FuStructEfiVariableAuthentication2.auth_info (0x%x bytes)",
2031
0
                    (guint) st_donor->len,
2032
0
                    (guint) FU_STRUCT_EFI_WIN_CERTIFICATE_SIZE);
2033
0
        return FALSE;
2034
0
    }
2035
0
    memcpy(st->data + FU_STRUCT_EFI_VARIABLE_AUTHENTICATION2_OFFSET_AUTH_INFO, st_donor->data, st_donor->len);
2036
0
    return TRUE;
2037
0
}
2038
/**
2039
 * fu_struct_efi_variable_authentication2_new: (skip):
2040
 **/
2041
FuStructEfiVariableAuthentication2 *
2042
fu_struct_efi_variable_authentication2_new(void)
2043
0
{
2044
0
    FuStructEfiVariableAuthentication2 *st = g_byte_array_sized_new(40);
2045
0
    fu_byte_array_set_size(st, 40, 0x0);
2046
0
    {
2047
0
        g_autoptr(GByteArray) st_donor = fu_struct_efi_time_new();
2048
0
        memcpy(st->data + 0x0, st_donor->data, st_donor->len); /* nocheck:blocked */
2049
0
    }
2050
0
    {
2051
0
        g_autoptr(GByteArray) st_donor = fu_struct_efi_win_certificate_new();
2052
0
        memcpy(st->data + 0x10, st_donor->data, st_donor->len); /* nocheck:blocked */
2053
0
    }
2054
0
    return st;
2055
0
}
2056
/**
2057
 * fu_struct_efi_variable_authentication2_to_string: (skip):
2058
 **/
2059
static gchar *
2060
fu_struct_efi_variable_authentication2_to_string(const FuStructEfiVariableAuthentication2 *st)
2061
0
{
2062
0
    g_autoptr(GString) str = g_string_new("FuStructEfiVariableAuthentication2:\n");
2063
0
    g_return_val_if_fail(st != NULL, NULL);
2064
0
    {
2065
0
        g_autoptr(GByteArray) st_tmp = fu_struct_efi_variable_authentication2_get_timestamp(st);
2066
0
        g_autofree gchar *tmp = fu_struct_efi_time_to_string(st_tmp);
2067
0
        g_string_append_printf(str, "  timestamp: %s\n", tmp);
2068
0
    }
2069
0
    {
2070
0
        g_autoptr(GByteArray) st_tmp = fu_struct_efi_variable_authentication2_get_auth_info(st);
2071
0
        g_autofree gchar *tmp = fu_struct_efi_win_certificate_to_string(st_tmp);
2072
0
        g_string_append_printf(str, "  auth_info: %s\n", tmp);
2073
0
    }
2074
0
    if (str->len > 0)
2075
0
        g_string_set_size(str, str->len - 1);
2076
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2077
0
}
2078
static gboolean
2079
fu_struct_efi_variable_authentication2_validate_internal(FuStructEfiVariableAuthentication2 *st, GError **error)
2080
0
{
2081
0
    g_return_val_if_fail(st != NULL, FALSE);
2082
0
    {
2083
0
        GByteArray st_tmp = {
2084
0
            .data = (guint8*) st->data + 0x0,
2085
0
            .len = 16,
2086
0
        };
2087
0
        if (!fu_struct_efi_time_validate_internal(&st_tmp, error))
2088
0
            return FALSE;
2089
0
    }
2090
0
    {
2091
0
        GByteArray st_tmp = {
2092
0
            .data = (guint8*) st->data + 0x10,
2093
0
            .len = 24,
2094
0
        };
2095
0
        if (!fu_struct_efi_win_certificate_validate_internal(&st_tmp, error))
2096
0
            return FALSE;
2097
0
    }
2098
0
    return TRUE;
2099
0
}
2100
/**
2101
 * fu_struct_efi_variable_authentication2_validate_stream: (skip):
2102
 **/
2103
gboolean
2104
fu_struct_efi_variable_authentication2_validate_stream(GInputStream *stream, gsize offset, GError **error)
2105
0
{
2106
0
    g_autoptr(GByteArray) st = NULL;
2107
0
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
2108
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2109
0
    st = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error);
2110
0
    if (st == NULL) {
2111
0
        g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40);
2112
0
        return FALSE;
2113
0
    }
2114
0
    if (st->len != 40) {
2115
0
        g_set_error(error,
2116
0
                    FWUPD_ERROR,
2117
0
                    FWUPD_ERROR_INVALID_DATA,
2118
0
                    "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x",
2119
0
                    (guint) 40,
2120
0
                    (guint) st->len);
2121
0
        return FALSE;
2122
0
    }
2123
0
    return fu_struct_efi_variable_authentication2_validate_internal(st, error);
2124
0
}
2125
static gboolean
2126
fu_struct_efi_variable_authentication2_parse_internal(FuStructEfiVariableAuthentication2 *st, GError **error)
2127
0
{
2128
0
    if (!fu_struct_efi_variable_authentication2_validate_internal(st, error))
2129
0
        return FALSE;
2130
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2131
0
        g_autofree gchar *str = fu_struct_efi_variable_authentication2_to_string(st);
2132
0
        g_debug("%s", str);
2133
0
    }
2134
0
    return TRUE;
2135
0
}
2136
/**
2137
 * fu_struct_efi_variable_authentication2_parse_stream: (skip):
2138
 **/
2139
FuStructEfiVariableAuthentication2 *
2140
fu_struct_efi_variable_authentication2_parse_stream(GInputStream *stream, gsize offset, GError **error)
2141
0
{
2142
0
    g_autoptr(GByteArray) st = NULL;
2143
0
    st = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error);
2144
0
    if (st == NULL) {
2145
0
        g_prefix_error(error, "FuStructEfiVariableAuthentication2 failed read of 0x%x: ", (guint) 40);
2146
0
        return NULL;
2147
0
    }
2148
0
    if (st->len != 40) {
2149
0
        g_set_error(error,
2150
0
                    FWUPD_ERROR,
2151
0
                    FWUPD_ERROR_INVALID_DATA,
2152
0
                    "FuStructEfiVariableAuthentication2 requested 0x%x and got 0x%x",
2153
0
                    (guint) 40,
2154
0
                    (guint) st->len);
2155
0
        return NULL;
2156
0
    }
2157
0
    if (!fu_struct_efi_variable_authentication2_parse_internal(st, error))
2158
0
        return NULL;
2159
0
    return g_steal_pointer(&st);
2160
0
}
2161
/* getters */
2162
/**
2163
 * fu_struct_efi_signature_list_get_type: (skip):
2164
 **/
2165
const fwupd_guid_t *
2166
fu_struct_efi_signature_list_get_type(const FuStructEfiSignatureList *st)
2167
0
{
2168
0
    g_return_val_if_fail(st != NULL, NULL);
2169
0
    return (const fwupd_guid_t *) (st->data + 0);
2170
0
}
2171
/**
2172
 * fu_struct_efi_signature_list_get_list_size: (skip):
2173
 **/
2174
guint32
2175
fu_struct_efi_signature_list_get_list_size(const FuStructEfiSignatureList *st)
2176
0
{
2177
0
    g_return_val_if_fail(st != NULL, 0x0);
2178
0
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
2179
0
}
2180
/**
2181
 * fu_struct_efi_signature_list_get_header_size: (skip):
2182
 **/
2183
guint32
2184
fu_struct_efi_signature_list_get_header_size(const FuStructEfiSignatureList *st)
2185
0
{
2186
0
    g_return_val_if_fail(st != NULL, 0x0);
2187
0
    return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN);
2188
0
}
2189
/**
2190
 * fu_struct_efi_signature_list_get_size: (skip):
2191
 **/
2192
guint32
2193
fu_struct_efi_signature_list_get_size(const FuStructEfiSignatureList *st)
2194
0
{
2195
0
    g_return_val_if_fail(st != NULL, 0x0);
2196
0
    return fu_memread_uint32(st->data + 24, G_LITTLE_ENDIAN);
2197
0
}
2198
2199
/* setters */
2200
/**
2201
 * fu_struct_efi_signature_list_set_type: (skip):
2202
 **/
2203
void
2204
fu_struct_efi_signature_list_set_type(FuStructEfiSignatureList *st, const fwupd_guid_t *value)
2205
0
{
2206
0
    g_return_if_fail(st != NULL);
2207
0
    g_return_if_fail(value != NULL);
2208
0
    memcpy(st->data + 0, value, sizeof(*value)); /* nocheck:blocked */
2209
0
}
2210
/**
2211
 * fu_struct_efi_signature_list_set_list_size: (skip):
2212
 **/
2213
void
2214
fu_struct_efi_signature_list_set_list_size(FuStructEfiSignatureList *st, guint32 value)
2215
0
{
2216
0
    g_return_if_fail(st != NULL);
2217
0
    fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN);
2218
0
}
2219
/**
2220
 * fu_struct_efi_signature_list_set_header_size: (skip):
2221
 **/
2222
void
2223
fu_struct_efi_signature_list_set_header_size(FuStructEfiSignatureList *st, guint32 value)
2224
0
{
2225
0
    g_return_if_fail(st != NULL);
2226
0
    fu_memwrite_uint32(st->data + 20, value, G_LITTLE_ENDIAN);
2227
0
}
2228
/**
2229
 * fu_struct_efi_signature_list_set_size: (skip):
2230
 **/
2231
void
2232
fu_struct_efi_signature_list_set_size(FuStructEfiSignatureList *st, guint32 value)
2233
0
{
2234
0
    g_return_if_fail(st != NULL);
2235
0
    fu_memwrite_uint32(st->data + 24, value, G_LITTLE_ENDIAN);
2236
0
}
2237
/**
2238
 * fu_struct_efi_signature_list_new: (skip):
2239
 **/
2240
FuStructEfiSignatureList *
2241
fu_struct_efi_signature_list_new(void)
2242
0
{
2243
0
    FuStructEfiSignatureList *st = g_byte_array_sized_new(28);
2244
0
    fu_byte_array_set_size(st, 28, 0x0);
2245
0
    return st;
2246
0
}
2247
/**
2248
 * fu_struct_efi_signature_list_to_string: (skip):
2249
 **/
2250
static gchar *
2251
fu_struct_efi_signature_list_to_string(const FuStructEfiSignatureList *st)
2252
0
{
2253
0
    g_autoptr(GString) str = g_string_new("FuStructEfiSignatureList:\n");
2254
0
    g_return_val_if_fail(st != NULL, NULL);
2255
0
    {
2256
0
        g_autofree gchar *tmp = fwupd_guid_to_string(fu_struct_efi_signature_list_get_type(st), FWUPD_GUID_FLAG_MIXED_ENDIAN);
2257
0
        g_string_append_printf(str, "  type: %s\n", tmp);
2258
0
    }
2259
0
    g_string_append_printf(str, "  list_size: 0x%x\n",
2260
0
                           (guint) fu_struct_efi_signature_list_get_list_size(st));
2261
0
    g_string_append_printf(str, "  header_size: 0x%x\n",
2262
0
                           (guint) fu_struct_efi_signature_list_get_header_size(st));
2263
0
    g_string_append_printf(str, "  size: 0x%x\n",
2264
0
                           (guint) fu_struct_efi_signature_list_get_size(st));
2265
0
    if (str->len > 0)
2266
0
        g_string_set_size(str, str->len - 1);
2267
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2268
0
}
2269
static gboolean
2270
fu_struct_efi_signature_list_validate_internal(FuStructEfiSignatureList *st, GError **error)
2271
0
{
2272
0
    g_return_val_if_fail(st != NULL, FALSE);
2273
0
    return TRUE;
2274
0
}
2275
static gboolean
2276
fu_struct_efi_signature_list_parse_internal(FuStructEfiSignatureList *st, GError **error)
2277
0
{
2278
0
    if (!fu_struct_efi_signature_list_validate_internal(st, error))
2279
0
        return FALSE;
2280
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2281
0
        g_autofree gchar *str = fu_struct_efi_signature_list_to_string(st);
2282
0
        g_debug("%s", str);
2283
0
    }
2284
0
    return TRUE;
2285
0
}
2286
/**
2287
 * fu_struct_efi_signature_list_parse_stream: (skip):
2288
 **/
2289
FuStructEfiSignatureList *
2290
fu_struct_efi_signature_list_parse_stream(GInputStream *stream, gsize offset, GError **error)
2291
0
{
2292
0
    g_autoptr(GByteArray) st = NULL;
2293
0
    st = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error);
2294
0
    if (st == NULL) {
2295
0
        g_prefix_error(error, "FuStructEfiSignatureList failed read of 0x%x: ", (guint) 28);
2296
0
        return NULL;
2297
0
    }
2298
0
    if (st->len != 28) {
2299
0
        g_set_error(error,
2300
0
                    FWUPD_ERROR,
2301
0
                    FWUPD_ERROR_INVALID_DATA,
2302
0
                    "FuStructEfiSignatureList requested 0x%x and got 0x%x",
2303
0
                    (guint) 28,
2304
0
                    (guint) st->len);
2305
0
        return NULL;
2306
0
    }
2307
0
    if (!fu_struct_efi_signature_list_parse_internal(st, error))
2308
0
        return NULL;
2309
0
    return g_steal_pointer(&st);
2310
0
}
2311
/* getters */
2312
/**
2313
 * fu_struct_efi_load_option_get_attrs: (skip):
2314
 **/
2315
FuEfiLoadOptionAttrs
2316
fu_struct_efi_load_option_get_attrs(const FuStructEfiLoadOption *st)
2317
2.21k
{
2318
2.21k
    g_return_val_if_fail(st != NULL, 0x0);
2319
2.21k
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
2320
2.21k
}
2321
/**
2322
 * fu_struct_efi_load_option_get_dp_size: (skip):
2323
 **/
2324
guint16
2325
fu_struct_efi_load_option_get_dp_size(const FuStructEfiLoadOption *st)
2326
1.63k
{
2327
1.63k
    g_return_val_if_fail(st != NULL, 0x0);
2328
1.63k
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
2329
1.63k
}
2330
2331
/* setters */
2332
/**
2333
 * fu_struct_efi_load_option_set_attrs: (skip):
2334
 **/
2335
void
2336
fu_struct_efi_load_option_set_attrs(FuStructEfiLoadOption *st, FuEfiLoadOptionAttrs value)
2337
1.24k
{
2338
1.24k
    g_return_if_fail(st != NULL);
2339
1.24k
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
2340
1.24k
}
2341
/**
2342
 * fu_struct_efi_load_option_set_dp_size: (skip):
2343
 **/
2344
void
2345
fu_struct_efi_load_option_set_dp_size(FuStructEfiLoadOption *st, guint16 value)
2346
795
{
2347
795
    g_return_if_fail(st != NULL);
2348
795
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
2349
795
}
2350
/**
2351
 * fu_struct_efi_load_option_new: (skip):
2352
 **/
2353
FuStructEfiLoadOption *
2354
fu_struct_efi_load_option_new(void)
2355
1.24k
{
2356
1.24k
    FuStructEfiLoadOption *st = g_byte_array_sized_new(6);
2357
1.24k
    fu_byte_array_set_size(st, 6, 0x0);
2358
1.24k
    return st;
2359
1.24k
}
2360
/**
2361
 * fu_struct_efi_load_option_to_string: (skip):
2362
 **/
2363
static gchar *
2364
fu_struct_efi_load_option_to_string(const FuStructEfiLoadOption *st)
2365
0
{
2366
0
    g_autoptr(GString) str = g_string_new("FuStructEfiLoadOption:\n");
2367
0
    g_return_val_if_fail(st != NULL, NULL);
2368
0
    {
2369
0
        const gchar *tmp = fu_efi_load_option_attrs_to_string(fu_struct_efi_load_option_get_attrs(st));
2370
0
        if (tmp != NULL) {
2371
0
            g_string_append_printf(str, "  attrs: 0x%x [%s]\n", (guint) fu_struct_efi_load_option_get_attrs(st), tmp);
2372
0
        } else {
2373
0
            g_string_append_printf(str, "  attrs: 0x%x\n", (guint) fu_struct_efi_load_option_get_attrs(st));
2374
0
        }
2375
0
    }
2376
0
    g_string_append_printf(str, "  dp_size: 0x%x\n",
2377
0
                           (guint) fu_struct_efi_load_option_get_dp_size(st));
2378
0
    if (str->len > 0)
2379
0
        g_string_set_size(str, str->len - 1);
2380
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2381
0
}
2382
static gboolean
2383
fu_struct_efi_load_option_validate_internal(FuStructEfiLoadOption *st, GError **error)
2384
2.21k
{
2385
2.21k
    g_return_val_if_fail(st != NULL, FALSE);
2386
2.21k
    return TRUE;
2387
2.21k
}
2388
static gboolean
2389
fu_struct_efi_load_option_parse_internal(FuStructEfiLoadOption *st, GError **error)
2390
2.21k
{
2391
2.21k
    if (!fu_struct_efi_load_option_validate_internal(st, error))
2392
0
        return FALSE;
2393
2.21k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2394
0
        g_autofree gchar *str = fu_struct_efi_load_option_to_string(st);
2395
0
        g_debug("%s", str);
2396
0
    }
2397
2.21k
    return TRUE;
2398
2.21k
}
2399
/**
2400
 * fu_struct_efi_load_option_parse_stream: (skip):
2401
 **/
2402
FuStructEfiLoadOption *
2403
fu_struct_efi_load_option_parse_stream(GInputStream *stream, gsize offset, GError **error)
2404
2.22k
{
2405
2.22k
    g_autoptr(GByteArray) st = NULL;
2406
2.22k
    st = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error);
2407
2.22k
    if (st == NULL) {
2408
0
        g_prefix_error(error, "FuStructEfiLoadOption failed read of 0x%x: ", (guint) 6);
2409
0
        return NULL;
2410
0
    }
2411
2.22k
    if (st->len != 6) {
2412
16
        g_set_error(error,
2413
16
                    FWUPD_ERROR,
2414
16
                    FWUPD_ERROR_INVALID_DATA,
2415
16
                    "FuStructEfiLoadOption requested 0x%x and got 0x%x",
2416
16
                    (guint) 6,
2417
16
                    (guint) st->len);
2418
16
        return NULL;
2419
16
    }
2420
2.21k
    if (!fu_struct_efi_load_option_parse_internal(st, error))
2421
0
        return NULL;
2422
2.21k
    return g_steal_pointer(&st);
2423
2.21k
}
2424
/* getters */
2425
/**
2426
 * fu_struct_efi_device_path_get_type: (skip):
2427
 **/
2428
FuEfiDevicePathType
2429
fu_struct_efi_device_path_get_type(const FuStructEfiDevicePath *st)
2430
110k
{
2431
110k
    g_return_val_if_fail(st != NULL, 0x0);
2432
110k
    return st->data[0];
2433
110k
}
2434
/**
2435
 * fu_struct_efi_device_path_get_subtype: (skip):
2436
 **/
2437
guint8
2438
fu_struct_efi_device_path_get_subtype(const FuStructEfiDevicePath *st)
2439
54.0k
{
2440
54.0k
    g_return_val_if_fail(st != NULL, 0x0);
2441
54.0k
    return st->data[1];
2442
54.0k
}
2443
/**
2444
 * fu_struct_efi_device_path_get_length: (skip):
2445
 **/
2446
guint16
2447
fu_struct_efi_device_path_get_length(const FuStructEfiDevicePath *st)
2448
57.0k
{
2449
57.0k
    g_return_val_if_fail(st != NULL, 0x0);
2450
57.0k
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
2451
57.0k
}
2452
2453
/* setters */
2454
/**
2455
 * fu_struct_efi_device_path_set_type: (skip):
2456
 **/
2457
void
2458
fu_struct_efi_device_path_set_type(FuStructEfiDevicePath *st, FuEfiDevicePathType value)
2459
7.34k
{
2460
7.34k
    g_return_if_fail(st != NULL);
2461
7.34k
    st->data[0] = value;
2462
7.34k
}
2463
/**
2464
 * fu_struct_efi_device_path_set_subtype: (skip):
2465
 **/
2466
void
2467
fu_struct_efi_device_path_set_subtype(FuStructEfiDevicePath *st, guint8 value)
2468
15.1k
{
2469
15.1k
    g_return_if_fail(st != NULL);
2470
15.1k
    st->data[1] = value;
2471
15.1k
}
2472
/**
2473
 * fu_struct_efi_device_path_set_length: (skip):
2474
 **/
2475
void
2476
fu_struct_efi_device_path_set_length(FuStructEfiDevicePath *st, guint16 value)
2477
14.3k
{
2478
14.3k
    g_return_if_fail(st != NULL);
2479
14.3k
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
2480
14.3k
}
2481
/**
2482
 * fu_struct_efi_device_path_new: (skip):
2483
 **/
2484
FuStructEfiDevicePath *
2485
fu_struct_efi_device_path_new(void)
2486
7.80k
{
2487
7.80k
    FuStructEfiDevicePath *st = g_byte_array_sized_new(4);
2488
7.80k
    fu_byte_array_set_size(st, 4, 0x0);
2489
7.80k
    fu_struct_efi_device_path_set_subtype(st, 0xFF);
2490
7.80k
    fu_struct_efi_device_path_set_length(st, 4);
2491
7.80k
    return st;
2492
7.80k
}
2493
/**
2494
 * fu_struct_efi_device_path_to_string: (skip):
2495
 **/
2496
static gchar *
2497
fu_struct_efi_device_path_to_string(const FuStructEfiDevicePath *st)
2498
0
{
2499
0
    g_autoptr(GString) str = g_string_new("FuStructEfiDevicePath:\n");
2500
0
    g_return_val_if_fail(st != NULL, NULL);
2501
0
    {
2502
0
        const gchar *tmp = fu_efi_device_path_type_to_string(fu_struct_efi_device_path_get_type(st));
2503
0
        if (tmp != NULL) {
2504
0
            g_string_append_printf(str, "  type: 0x%x [%s]\n", (guint) fu_struct_efi_device_path_get_type(st), tmp);
2505
0
        } else {
2506
0
            g_string_append_printf(str, "  type: 0x%x\n", (guint) fu_struct_efi_device_path_get_type(st));
2507
0
        }
2508
0
    }
2509
0
    g_string_append_printf(str, "  subtype: 0x%x\n",
2510
0
                           (guint) fu_struct_efi_device_path_get_subtype(st));
2511
0
    g_string_append_printf(str, "  length: 0x%x\n",
2512
0
                           (guint) fu_struct_efi_device_path_get_length(st));
2513
0
    if (str->len > 0)
2514
0
        g_string_set_size(str, str->len - 1);
2515
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2516
0
}
2517
static gboolean
2518
fu_struct_efi_device_path_validate_internal(FuStructEfiDevicePath *st, GError **error)
2519
56.6k
{
2520
56.6k
    g_return_val_if_fail(st != NULL, FALSE);
2521
56.6k
    return TRUE;
2522
56.6k
}
2523
static gboolean
2524
fu_struct_efi_device_path_parse_internal(FuStructEfiDevicePath *st, GError **error)
2525
56.6k
{
2526
56.6k
    if (!fu_struct_efi_device_path_validate_internal(st, error))
2527
0
        return FALSE;
2528
56.6k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2529
0
        g_autofree gchar *str = fu_struct_efi_device_path_to_string(st);
2530
0
        g_debug("%s", str);
2531
0
    }
2532
56.6k
    return TRUE;
2533
56.6k
}
2534
/**
2535
 * fu_struct_efi_device_path_parse_stream: (skip):
2536
 **/
2537
FuStructEfiDevicePath *
2538
fu_struct_efi_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error)
2539
56.6k
{
2540
56.6k
    g_autoptr(GByteArray) st = NULL;
2541
56.6k
    st = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error);
2542
56.6k
    if (st == NULL) {
2543
0
        g_prefix_error(error, "FuStructEfiDevicePath failed read of 0x%x: ", (guint) 4);
2544
0
        return NULL;
2545
0
    }
2546
56.6k
    if (st->len != 4) {
2547
49
        g_set_error(error,
2548
49
                    FWUPD_ERROR,
2549
49
                    FWUPD_ERROR_INVALID_DATA,
2550
49
                    "FuStructEfiDevicePath requested 0x%x and got 0x%x",
2551
49
                    (guint) 4,
2552
49
                    (guint) st->len);
2553
49
        return NULL;
2554
49
    }
2555
56.6k
    if (!fu_struct_efi_device_path_parse_internal(st, error))
2556
0
        return NULL;
2557
56.6k
    return g_steal_pointer(&st);
2558
56.6k
}
2559
/* getters */
2560
/**
2561
 * fu_struct_efi_hard_drive_device_path_get_type: (skip):
2562
 **/
2563
static FuEfiDevicePathType
2564
fu_struct_efi_hard_drive_device_path_get_type(const FuStructEfiHardDriveDevicePath *st)
2565
645
{
2566
645
    g_return_val_if_fail(st != NULL, 0x0);
2567
645
    return st->data[0];
2568
645
}
2569
/**
2570
 * fu_struct_efi_hard_drive_device_path_get_subtype: (skip):
2571
 **/
2572
FuEfiHardDriveDevicePathSubtype
2573
fu_struct_efi_hard_drive_device_path_get_subtype(const FuStructEfiHardDriveDevicePath *st)
2574
0
{
2575
0
    g_return_val_if_fail(st != NULL, 0x0);
2576
0
    return st->data[1];
2577
0
}
2578
/**
2579
 * fu_struct_efi_hard_drive_device_path_get_length: (skip):
2580
 **/
2581
static guint16
2582
fu_struct_efi_hard_drive_device_path_get_length(const FuStructEfiHardDriveDevicePath *st)
2583
645
{
2584
645
    g_return_val_if_fail(st != NULL, 0x0);
2585
645
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
2586
645
}
2587
/**
2588
 * fu_struct_efi_hard_drive_device_path_get_partition_number: (skip):
2589
 **/
2590
guint32
2591
fu_struct_efi_hard_drive_device_path_get_partition_number(const FuStructEfiHardDriveDevicePath *st)
2592
628
{
2593
628
    g_return_val_if_fail(st != NULL, 0x0);
2594
628
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
2595
628
}
2596
/**
2597
 * fu_struct_efi_hard_drive_device_path_get_partition_start: (skip):
2598
 **/
2599
guint64
2600
fu_struct_efi_hard_drive_device_path_get_partition_start(const FuStructEfiHardDriveDevicePath *st)
2601
628
{
2602
628
    g_return_val_if_fail(st != NULL, 0x0);
2603
628
    return fu_memread_uint64(st->data + 8, G_LITTLE_ENDIAN);
2604
628
}
2605
/**
2606
 * fu_struct_efi_hard_drive_device_path_get_partition_size: (skip):
2607
 **/
2608
guint64
2609
fu_struct_efi_hard_drive_device_path_get_partition_size(const FuStructEfiHardDriveDevicePath *st)
2610
628
{
2611
628
    g_return_val_if_fail(st != NULL, 0x0);
2612
628
    return fu_memread_uint64(st->data + 16, G_LITTLE_ENDIAN);
2613
628
}
2614
/**
2615
 * fu_struct_efi_hard_drive_device_path_get_partition_signature: (skip):
2616
 **/
2617
const fwupd_guid_t *
2618
fu_struct_efi_hard_drive_device_path_get_partition_signature(const FuStructEfiHardDriveDevicePath *st)
2619
628
{
2620
628
    g_return_val_if_fail(st != NULL, NULL);
2621
628
    return (const fwupd_guid_t *) (st->data + 24);
2622
628
}
2623
/**
2624
 * fu_struct_efi_hard_drive_device_path_get_partition_format: (skip):
2625
 **/
2626
FuEfiHardDriveDevicePathPartitionFormat
2627
fu_struct_efi_hard_drive_device_path_get_partition_format(const FuStructEfiHardDriveDevicePath *st)
2628
628
{
2629
628
    g_return_val_if_fail(st != NULL, 0x0);
2630
628
    return st->data[40];
2631
628
}
2632
/**
2633
 * fu_struct_efi_hard_drive_device_path_get_signature_type: (skip):
2634
 **/
2635
FuEfiHardDriveDevicePathSignatureType
2636
fu_struct_efi_hard_drive_device_path_get_signature_type(const FuStructEfiHardDriveDevicePath *st)
2637
628
{
2638
628
    g_return_val_if_fail(st != NULL, 0x0);
2639
628
    return st->data[41];
2640
628
}
2641
2642
/* setters */
2643
/**
2644
 * fu_struct_efi_hard_drive_device_path_set_type: (skip):
2645
 **/
2646
static void
2647
fu_struct_efi_hard_drive_device_path_set_type(FuStructEfiHardDriveDevicePath *st, FuEfiDevicePathType value)
2648
395
{
2649
395
    g_return_if_fail(st != NULL);
2650
395
    st->data[0] = value;
2651
395
}
2652
/**
2653
 * fu_struct_efi_hard_drive_device_path_set_subtype: (skip):
2654
 **/
2655
void
2656
fu_struct_efi_hard_drive_device_path_set_subtype(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSubtype value)
2657
395
{
2658
395
    g_return_if_fail(st != NULL);
2659
395
    st->data[1] = value;
2660
395
}
2661
/**
2662
 * fu_struct_efi_hard_drive_device_path_set_length: (skip):
2663
 **/
2664
static void
2665
fu_struct_efi_hard_drive_device_path_set_length(FuStructEfiHardDriveDevicePath *st, guint16 value)
2666
395
{
2667
395
    g_return_if_fail(st != NULL);
2668
395
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
2669
395
}
2670
/**
2671
 * fu_struct_efi_hard_drive_device_path_set_partition_number: (skip):
2672
 **/
2673
void
2674
fu_struct_efi_hard_drive_device_path_set_partition_number(FuStructEfiHardDriveDevicePath *st, guint32 value)
2675
395
{
2676
395
    g_return_if_fail(st != NULL);
2677
395
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
2678
395
}
2679
/**
2680
 * fu_struct_efi_hard_drive_device_path_set_partition_start: (skip):
2681
 **/
2682
void
2683
fu_struct_efi_hard_drive_device_path_set_partition_start(FuStructEfiHardDriveDevicePath *st, guint64 value)
2684
395
{
2685
395
    g_return_if_fail(st != NULL);
2686
395
    fu_memwrite_uint64(st->data + 8, value, G_LITTLE_ENDIAN);
2687
395
}
2688
/**
2689
 * fu_struct_efi_hard_drive_device_path_set_partition_size: (skip):
2690
 **/
2691
void
2692
fu_struct_efi_hard_drive_device_path_set_partition_size(FuStructEfiHardDriveDevicePath *st, guint64 value)
2693
395
{
2694
395
    g_return_if_fail(st != NULL);
2695
395
    fu_memwrite_uint64(st->data + 16, value, G_LITTLE_ENDIAN);
2696
395
}
2697
/**
2698
 * fu_struct_efi_hard_drive_device_path_set_partition_signature: (skip):
2699
 **/
2700
void
2701
fu_struct_efi_hard_drive_device_path_set_partition_signature(FuStructEfiHardDriveDevicePath *st, const fwupd_guid_t *value)
2702
395
{
2703
395
    g_return_if_fail(st != NULL);
2704
395
    g_return_if_fail(value != NULL);
2705
395
    memcpy(st->data + 24, value, sizeof(*value)); /* nocheck:blocked */
2706
395
}
2707
/**
2708
 * fu_struct_efi_hard_drive_device_path_set_partition_format: (skip):
2709
 **/
2710
void
2711
fu_struct_efi_hard_drive_device_path_set_partition_format(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathPartitionFormat value)
2712
790
{
2713
790
    g_return_if_fail(st != NULL);
2714
790
    st->data[40] = value;
2715
790
}
2716
/**
2717
 * fu_struct_efi_hard_drive_device_path_set_signature_type: (skip):
2718
 **/
2719
void
2720
fu_struct_efi_hard_drive_device_path_set_signature_type(FuStructEfiHardDriveDevicePath *st, FuEfiHardDriveDevicePathSignatureType value)
2721
790
{
2722
790
    g_return_if_fail(st != NULL);
2723
790
    st->data[41] = value;
2724
790
}
2725
/**
2726
 * fu_struct_efi_hard_drive_device_path_new: (skip):
2727
 **/
2728
FuStructEfiHardDriveDevicePath *
2729
fu_struct_efi_hard_drive_device_path_new(void)
2730
395
{
2731
395
    FuStructEfiHardDriveDevicePath *st = g_byte_array_sized_new(42);
2732
395
    fu_byte_array_set_size(st, 42, 0x0);
2733
395
    fu_struct_efi_hard_drive_device_path_set_type(st, FU_EFI_DEVICE_PATH_TYPE_MEDIA);
2734
395
    fu_struct_efi_hard_drive_device_path_set_subtype(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE_HARD_DRIVE);
2735
395
    fu_struct_efi_hard_drive_device_path_set_length(st, 42);
2736
395
    fu_struct_efi_hard_drive_device_path_set_partition_format(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_PARTITION_FORMAT_GUID_PARTITION_TABLE);
2737
395
    fu_struct_efi_hard_drive_device_path_set_signature_type(st, FU_EFI_HARD_DRIVE_DEVICE_PATH_SIGNATURE_TYPE_GUID);
2738
395
    return st;
2739
395
}
2740
/**
2741
 * fu_struct_efi_hard_drive_device_path_to_string: (skip):
2742
 **/
2743
static gchar *
2744
fu_struct_efi_hard_drive_device_path_to_string(const FuStructEfiHardDriveDevicePath *st)
2745
0
{
2746
0
    g_autoptr(GString) str = g_string_new("FuStructEfiHardDriveDevicePath:\n");
2747
0
    g_return_val_if_fail(st != NULL, NULL);
2748
0
    {
2749
0
        const gchar *tmp = fu_efi_hard_drive_device_path_subtype_to_string(fu_struct_efi_hard_drive_device_path_get_subtype(st));
2750
0
        if (tmp != NULL) {
2751
0
            g_string_append_printf(str, "  subtype: 0x%x [%s]\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st), tmp);
2752
0
        } else {
2753
0
            g_string_append_printf(str, "  subtype: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_subtype(st));
2754
0
        }
2755
0
    }
2756
0
    g_string_append_printf(str, "  partition_number: 0x%x\n",
2757
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_number(st));
2758
0
    g_string_append_printf(str, "  partition_start: 0x%x\n",
2759
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_start(st));
2760
0
    g_string_append_printf(str, "  partition_size: 0x%x\n",
2761
0
                           (guint) fu_struct_efi_hard_drive_device_path_get_partition_size(st));
2762
0
    {
2763
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);
2764
0
        g_string_append_printf(str, "  partition_signature: %s\n", tmp);
2765
0
    }
2766
0
    {
2767
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));
2768
0
        if (tmp != NULL) {
2769
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);
2770
0
        } else {
2771
0
            g_string_append_printf(str, "  partition_format: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_partition_format(st));
2772
0
        }
2773
0
    }
2774
0
    {
2775
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));
2776
0
        if (tmp != NULL) {
2777
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);
2778
0
        } else {
2779
0
            g_string_append_printf(str, "  signature_type: 0x%x\n", (guint) fu_struct_efi_hard_drive_device_path_get_signature_type(st));
2780
0
        }
2781
0
    }
2782
0
    if (str->len > 0)
2783
0
        g_string_set_size(str, str->len - 1);
2784
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2785
0
}
2786
static gboolean
2787
fu_struct_efi_hard_drive_device_path_validate_internal(FuStructEfiHardDriveDevicePath *st, GError **error)
2788
645
{
2789
645
    g_return_val_if_fail(st != NULL, FALSE);
2790
645
    if (fu_struct_efi_hard_drive_device_path_get_type(st) != FU_EFI_DEVICE_PATH_TYPE_MEDIA) {
2791
0
        g_set_error_literal(error,
2792
0
                            FWUPD_ERROR,
2793
0
                            FWUPD_ERROR_INVALID_DATA,
2794
0
                            "constant FuStructEfiHardDriveDevicePath.type was not valid");
2795
0
        return FALSE;
2796
0
    }
2797
645
    if (fu_struct_efi_hard_drive_device_path_get_length(st) != 42) {
2798
17
        g_set_error_literal(error,
2799
17
                            FWUPD_ERROR,
2800
17
                            FWUPD_ERROR_INVALID_DATA,
2801
17
                            "constant FuStructEfiHardDriveDevicePath.length was not valid");
2802
17
        return FALSE;
2803
17
    }
2804
628
    return TRUE;
2805
645
}
2806
static gboolean
2807
fu_struct_efi_hard_drive_device_path_parse_internal(FuStructEfiHardDriveDevicePath *st, GError **error)
2808
645
{
2809
645
    if (!fu_struct_efi_hard_drive_device_path_validate_internal(st, error))
2810
17
        return FALSE;
2811
628
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2812
0
        g_autofree gchar *str = fu_struct_efi_hard_drive_device_path_to_string(st);
2813
0
        g_debug("%s", str);
2814
0
    }
2815
628
    return TRUE;
2816
645
}
2817
/**
2818
 * fu_struct_efi_hard_drive_device_path_parse_stream: (skip):
2819
 **/
2820
FuStructEfiHardDriveDevicePath *
2821
fu_struct_efi_hard_drive_device_path_parse_stream(GInputStream *stream, gsize offset, GError **error)
2822
665
{
2823
665
    g_autoptr(GByteArray) st = NULL;
2824
665
    st = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error);
2825
665
    if (st == NULL) {
2826
0
        g_prefix_error(error, "FuStructEfiHardDriveDevicePath failed read of 0x%x: ", (guint) 42);
2827
0
        return NULL;
2828
0
    }
2829
665
    if (st->len != 42) {
2830
20
        g_set_error(error,
2831
20
                    FWUPD_ERROR,
2832
20
                    FWUPD_ERROR_INVALID_DATA,
2833
20
                    "FuStructEfiHardDriveDevicePath requested 0x%x and got 0x%x",
2834
20
                    (guint) 42,
2835
20
                    (guint) st->len);
2836
20
        return NULL;
2837
20
    }
2838
645
    if (!fu_struct_efi_hard_drive_device_path_parse_internal(st, error))
2839
17
        return NULL;
2840
628
    return g_steal_pointer(&st);
2841
645
}
2842
/* getters */
2843
/**
2844
 * fu_struct_shim_hive_get_header_version: (skip):
2845
 **/
2846
guint8
2847
fu_struct_shim_hive_get_header_version(const FuStructShimHive *st)
2848
970
{
2849
970
    g_return_val_if_fail(st != NULL, 0x0);
2850
970
    return st->data[4];
2851
970
}
2852
/**
2853
 * fu_struct_shim_hive_get_items_count: (skip):
2854
 **/
2855
guint8
2856
fu_struct_shim_hive_get_items_count(const FuStructShimHive *st)
2857
968
{
2858
968
    g_return_val_if_fail(st != NULL, 0x0);
2859
968
    return st->data[5];
2860
968
}
2861
/**
2862
 * fu_struct_shim_hive_get_items_offset: (skip):
2863
 **/
2864
guint8
2865
fu_struct_shim_hive_get_items_offset(const FuStructShimHive *st)
2866
968
{
2867
968
    g_return_val_if_fail(st != NULL, 0x0);
2868
968
    return st->data[6];
2869
968
}
2870
/**
2871
 * fu_struct_shim_hive_get_crc32: (skip):
2872
 **/
2873
guint32
2874
fu_struct_shim_hive_get_crc32(const FuStructShimHive *st)
2875
0
{
2876
0
    g_return_val_if_fail(st != NULL, 0x0);
2877
0
    return fu_memread_uint32(st->data + 7, G_LITTLE_ENDIAN);
2878
0
}
2879
2880
/* setters */
2881
/**
2882
 * fu_struct_shim_hive_set_magic: (skip):
2883
 **/
2884
static gboolean
2885
fu_struct_shim_hive_set_magic(FuStructShimHive *st, const gchar *value, GError **error)
2886
373
{
2887
373
    gsize len;
2888
373
    g_return_val_if_fail(st != NULL, FALSE);
2889
373
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
2890
373
    if (value == NULL) {
2891
0
        memset(st->data + 0, 0x0, 4);
2892
0
        return TRUE;
2893
0
    }
2894
373
    len = strlen(value);
2895
373
    if (len > 4) {
2896
0
        g_set_error(error,
2897
0
                    FWUPD_ERROR,
2898
0
                    FWUPD_ERROR_INVALID_DATA,
2899
0
                    "string '%s' (0x%x bytes) does not fit in FuStructShimHive.magic (0x%x bytes)",
2900
0
                    value, (guint) len, (guint) 4);
2901
0
        return FALSE;
2902
0
    }
2903
373
    return fu_memcpy_safe(st->data, st->len, 0, (const guint8 *)value, len, 0x0, len, error);
2904
373
}
2905
/**
2906
 * fu_struct_shim_hive_set_header_version: (skip):
2907
 **/
2908
void
2909
fu_struct_shim_hive_set_header_version(FuStructShimHive *st, guint8 value)
2910
373
{
2911
373
    g_return_if_fail(st != NULL);
2912
373
    st->data[4] = value;
2913
373
}
2914
/**
2915
 * fu_struct_shim_hive_set_items_count: (skip):
2916
 **/
2917
void
2918
fu_struct_shim_hive_set_items_count(FuStructShimHive *st, guint8 value)
2919
373
{
2920
373
    g_return_if_fail(st != NULL);
2921
373
    st->data[5] = value;
2922
373
}
2923
/**
2924
 * fu_struct_shim_hive_set_items_offset: (skip):
2925
 **/
2926
void
2927
fu_struct_shim_hive_set_items_offset(FuStructShimHive *st, guint8 value)
2928
373
{
2929
373
    g_return_if_fail(st != NULL);
2930
373
    st->data[6] = value;
2931
373
}
2932
/**
2933
 * fu_struct_shim_hive_set_crc32: (skip):
2934
 **/
2935
void
2936
fu_struct_shim_hive_set_crc32(FuStructShimHive *st, guint32 value)
2937
373
{
2938
373
    g_return_if_fail(st != NULL);
2939
373
    fu_memwrite_uint32(st->data + 7, value, G_LITTLE_ENDIAN);
2940
373
}
2941
/**
2942
 * fu_struct_shim_hive_new: (skip):
2943
 **/
2944
FuStructShimHive *
2945
fu_struct_shim_hive_new(void)
2946
373
{
2947
373
    FuStructShimHive *st = g_byte_array_sized_new(11);
2948
373
    fu_byte_array_set_size(st, 11, 0x0);
2949
373
    fu_struct_shim_hive_set_magic(st, "HIVE", NULL);
2950
373
    fu_struct_shim_hive_set_header_version(st, 0x1);
2951
373
    return st;
2952
373
}
2953
/**
2954
 * fu_struct_shim_hive_to_string: (skip):
2955
 **/
2956
static gchar *
2957
fu_struct_shim_hive_to_string(const FuStructShimHive *st)
2958
0
{
2959
0
    g_autoptr(GString) str = g_string_new("FuStructShimHive:\n");
2960
0
    g_return_val_if_fail(st != NULL, NULL);
2961
0
    g_string_append_printf(str, "  header_version: 0x%x\n",
2962
0
                           (guint) fu_struct_shim_hive_get_header_version(st));
2963
0
    g_string_append_printf(str, "  items_count: 0x%x\n",
2964
0
                           (guint) fu_struct_shim_hive_get_items_count(st));
2965
0
    g_string_append_printf(str, "  items_offset: 0x%x\n",
2966
0
                           (guint) fu_struct_shim_hive_get_items_offset(st));
2967
0
    g_string_append_printf(str, "  crc32: 0x%x\n",
2968
0
                           (guint) fu_struct_shim_hive_get_crc32(st));
2969
0
    if (str->len > 0)
2970
0
        g_string_set_size(str, str->len - 1);
2971
0
    return g_string_free(g_steal_pointer(&str), FALSE);
2972
0
}
2973
static gboolean
2974
fu_struct_shim_hive_validate_internal(FuStructShimHive *st, GError **error)
2975
1.36k
{
2976
1.36k
    g_return_val_if_fail(st != NULL, FALSE);
2977
1.36k
    if (strncmp((const gchar *) (st->data + 0), "HIVE", 4) != 0) {
2978
400
        g_set_error_literal(error,
2979
400
                            FWUPD_ERROR,
2980
400
                            FWUPD_ERROR_INVALID_DATA,
2981
400
                            "constant FuStructShimHive.magic was not valid");
2982
400
        return FALSE;
2983
400
    }
2984
969
    return TRUE;
2985
1.36k
}
2986
static gboolean
2987
fu_struct_shim_hive_parse_internal(FuStructShimHive *st, GError **error)
2988
1.36k
{
2989
1.36k
    if (!fu_struct_shim_hive_validate_internal(st, error))
2990
400
        return FALSE;
2991
969
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
2992
0
        g_autofree gchar *str = fu_struct_shim_hive_to_string(st);
2993
0
        g_debug("%s", str);
2994
0
    }
2995
969
    return TRUE;
2996
1.36k
}
2997
/**
2998
 * fu_struct_shim_hive_parse_stream: (skip):
2999
 **/
3000
FuStructShimHive *
3001
fu_struct_shim_hive_parse_stream(GInputStream *stream, gsize offset, GError **error)
3002
1.46k
{
3003
1.46k
    g_autoptr(GByteArray) st = NULL;
3004
1.46k
    st = fu_input_stream_read_byte_array(stream, offset, 11, NULL, error);
3005
1.46k
    if (st == NULL) {
3006
0
        g_prefix_error(error, "FuStructShimHive failed read of 0x%x: ", (guint) 11);
3007
0
        return NULL;
3008
0
    }
3009
1.46k
    if (st->len != 11) {
3010
94
        g_set_error(error,
3011
94
                    FWUPD_ERROR,
3012
94
                    FWUPD_ERROR_INVALID_DATA,
3013
94
                    "FuStructShimHive requested 0x%x and got 0x%x",
3014
94
                    (guint) 11,
3015
94
                    (guint) st->len);
3016
94
        return NULL;
3017
94
    }
3018
1.36k
    if (!fu_struct_shim_hive_parse_internal(st, error))
3019
400
        return NULL;
3020
969
    return g_steal_pointer(&st);
3021
1.36k
}
3022
/* getters */
3023
/**
3024
 * fu_struct_shim_hive_item_get_key_length: (skip):
3025
 **/
3026
guint8
3027
fu_struct_shim_hive_item_get_key_length(const FuStructShimHiveItem *st)
3028
4.64k
{
3029
4.64k
    g_return_val_if_fail(st != NULL, 0x0);
3030
4.64k
    return st->data[0];
3031
4.64k
}
3032
/**
3033
 * fu_struct_shim_hive_item_get_value_length: (skip):
3034
 **/
3035
guint32
3036
fu_struct_shim_hive_item_get_value_length(const FuStructShimHiveItem *st)
3037
4.52k
{
3038
4.52k
    g_return_val_if_fail(st != NULL, 0x0);
3039
4.52k
    return fu_memread_uint32(st->data + 1, G_LITTLE_ENDIAN);
3040
4.52k
}
3041
3042
/* setters */
3043
/**
3044
 * fu_struct_shim_hive_item_set_key_length: (skip):
3045
 **/
3046
void
3047
fu_struct_shim_hive_item_set_key_length(FuStructShimHiveItem *st, guint8 value)
3048
920
{
3049
920
    g_return_if_fail(st != NULL);
3050
920
    st->data[0] = value;
3051
920
}
3052
/**
3053
 * fu_struct_shim_hive_item_set_value_length: (skip):
3054
 **/
3055
void
3056
fu_struct_shim_hive_item_set_value_length(FuStructShimHiveItem *st, guint32 value)
3057
920
{
3058
920
    g_return_if_fail(st != NULL);
3059
920
    fu_memwrite_uint32(st->data + 1, value, G_LITTLE_ENDIAN);
3060
920
}
3061
/**
3062
 * fu_struct_shim_hive_item_new: (skip):
3063
 **/
3064
FuStructShimHiveItem *
3065
fu_struct_shim_hive_item_new(void)
3066
920
{
3067
920
    FuStructShimHiveItem *st = g_byte_array_sized_new(5);
3068
920
    fu_byte_array_set_size(st, 5, 0x0);
3069
920
    return st;
3070
920
}
3071
/**
3072
 * fu_struct_shim_hive_item_to_string: (skip):
3073
 **/
3074
static gchar *
3075
fu_struct_shim_hive_item_to_string(const FuStructShimHiveItem *st)
3076
0
{
3077
0
    g_autoptr(GString) str = g_string_new("FuStructShimHiveItem:\n");
3078
0
    g_return_val_if_fail(st != NULL, NULL);
3079
0
    g_string_append_printf(str, "  key_length: 0x%x\n",
3080
0
                           (guint) fu_struct_shim_hive_item_get_key_length(st));
3081
0
    g_string_append_printf(str, "  value_length: 0x%x\n",
3082
0
                           (guint) fu_struct_shim_hive_item_get_value_length(st));
3083
0
    if (str->len > 0)
3084
0
        g_string_set_size(str, str->len - 1);
3085
0
    return g_string_free(g_steal_pointer(&str), FALSE);
3086
0
}
3087
static gboolean
3088
fu_struct_shim_hive_item_validate_internal(FuStructShimHiveItem *st, GError **error)
3089
4.64k
{
3090
4.64k
    g_return_val_if_fail(st != NULL, FALSE);
3091
4.64k
    return TRUE;
3092
4.64k
}
3093
static gboolean
3094
fu_struct_shim_hive_item_parse_internal(FuStructShimHiveItem *st, GError **error)
3095
4.64k
{
3096
4.64k
    if (!fu_struct_shim_hive_item_validate_internal(st, error))
3097
0
        return FALSE;
3098
4.64k
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
3099
0
        g_autofree gchar *str = fu_struct_shim_hive_item_to_string(st);
3100
0
        g_debug("%s", str);
3101
0
    }
3102
4.64k
    return TRUE;
3103
4.64k
}
3104
/**
3105
 * fu_struct_shim_hive_item_parse_stream: (skip):
3106
 **/
3107
FuStructShimHiveItem *
3108
fu_struct_shim_hive_item_parse_stream(GInputStream *stream, gsize offset, GError **error)
3109
5.01k
{
3110
5.01k
    g_autoptr(GByteArray) st = NULL;
3111
5.01k
    st = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error);
3112
5.01k
    if (st == NULL) {
3113
161
        g_prefix_error(error, "FuStructShimHiveItem failed read of 0x%x: ", (guint) 5);
3114
161
        return NULL;
3115
161
    }
3116
4.84k
    if (st->len != 5) {
3117
209
        g_set_error(error,
3118
209
                    FWUPD_ERROR,
3119
209
                    FWUPD_ERROR_INVALID_DATA,
3120
209
                    "FuStructShimHiveItem requested 0x%x and got 0x%x",
3121
209
                    (guint) 5,
3122
209
                    (guint) st->len);
3123
209
        return NULL;
3124
209
    }
3125
4.64k
    if (!fu_struct_shim_hive_item_parse_internal(st, error))
3126
0
        return NULL;
3127
4.64k
    return g_steal_pointer(&st);
3128
4.64k
}