Coverage Report

Created: 2025-11-09 07:06

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