Coverage Report

Created: 2025-07-11 06:31

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