Coverage Report

Created: 2025-06-22 06:29

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