Coverage Report

Created: 2025-07-01 07:09

/work/fu-pefile-struct.c
Line
Count
Source (jump to first uncovered line)
1
/* auto-generated, do not modify */
2
#include "config.h"
3
4
#include "fu-pefile-struct.h"
5
#include "fu-byte-array.h"
6
#include "fu-mem-private.h"
7
#include "fu-string.h"
8
9
#ifdef G_LOG_DOMAIN
10
  #undef G_LOG_DOMAIN
11
#endif
12
0
#define G_LOG_DOMAIN "FuStruct"
13
14
static const gchar *
15
fu_pe_coff_machine_to_string(FuPeCoffMachine val)
16
0
{
17
0
    if (val == FU_PE_COFF_MACHINE_UNKNOWN)
18
0
        return "unknown";
19
0
    if (val == FU_PE_COFF_MACHINE_ALPHA)
20
0
        return "alpha";
21
0
    if (val == FU_PE_COFF_MACHINE_ALPHA64)
22
0
        return "alpha64";
23
0
    if (val == FU_PE_COFF_MACHINE_AM33)
24
0
        return "am33";
25
0
    if (val == FU_PE_COFF_MACHINE_AMD64)
26
0
        return "amd64";
27
0
    if (val == FU_PE_COFF_MACHINE_ARM)
28
0
        return "arm";
29
0
    if (val == FU_PE_COFF_MACHINE_ARM64)
30
0
        return "arm64";
31
0
    if (val == FU_PE_COFF_MACHINE_ARMNT)
32
0
        return "armnt";
33
0
    if (val == FU_PE_COFF_MACHINE_EBC)
34
0
        return "ebc";
35
0
    if (val == FU_PE_COFF_MACHINE_I386)
36
0
        return "i386";
37
0
    if (val == FU_PE_COFF_MACHINE_IA64)
38
0
        return "ia64";
39
0
    if (val == FU_PE_COFF_MACHINE_LOONGARCH32)
40
0
        return "loongarch32";
41
0
    if (val == FU_PE_COFF_MACHINE_LOONGARCH64)
42
0
        return "loongarch64";
43
0
    if (val == FU_PE_COFF_MACHINE_M32R)
44
0
        return "m32r";
45
0
    if (val == FU_PE_COFF_MACHINE_MIPS16)
46
0
        return "mips16";
47
0
    if (val == FU_PE_COFF_MACHINE_MIPSFPU)
48
0
        return "mipsfpu";
49
0
    if (val == FU_PE_COFF_MACHINE_MIPSFPU16)
50
0
        return "mipsfpu16";
51
0
    if (val == FU_PE_COFF_MACHINE_POWERPC)
52
0
        return "powerpc";
53
0
    if (val == FU_PE_COFF_MACHINE_POWERPCFP)
54
0
        return "powerpcfp";
55
0
    if (val == FU_PE_COFF_MACHINE_R4000)
56
0
        return "r4000";
57
0
    if (val == FU_PE_COFF_MACHINE_RISCV32)
58
0
        return "riscv32";
59
0
    if (val == FU_PE_COFF_MACHINE_RISCV64)
60
0
        return "riscv64";
61
0
    if (val == FU_PE_COFF_MACHINE_RISCV128)
62
0
        return "riscv128";
63
0
    if (val == FU_PE_COFF_MACHINE_SH3)
64
0
        return "sh3";
65
0
    if (val == FU_PE_COFF_MACHINE_SH3DSP)
66
0
        return "sh3dsp";
67
0
    if (val == FU_PE_COFF_MACHINE_SH4)
68
0
        return "sh4";
69
0
    if (val == FU_PE_COFF_MACHINE_SH5)
70
0
        return "sh5";
71
0
    if (val == FU_PE_COFF_MACHINE_THUMB)
72
0
        return "thumb";
73
0
    if (val == FU_PE_COFF_MACHINE_WCEMIPSV2)
74
0
        return "wcemipsv2";
75
0
    return NULL;
76
0
}
77
78
static const gchar *
79
fu_pe_coff_magic_to_string(FuPeCoffMagic val)
80
0
{
81
0
    if (val == FU_PE_COFF_MAGIC_PE32)
82
0
        return "pe32";
83
0
    if (val == FU_PE_COFF_MAGIC_PE32_PLUS)
84
0
        return "pe32-plus";
85
0
    return NULL;
86
0
}
87
88
const gchar *
89
fu_coff_subsystem_to_string(FuCoffSubsystem val)
90
0
{
91
0
    if (val == FU_COFF_SUBSYSTEM_UNKNOWN)
92
0
        return "unknown";
93
0
    if (val == FU_COFF_SUBSYSTEM_NATIVE)
94
0
        return "native";
95
0
    if (val == FU_COFF_SUBSYSTEM_WINDOWS_GUI)
96
0
        return "windows-gui";
97
0
    if (val == FU_COFF_SUBSYSTEM_WINDOWS_CUI)
98
0
        return "windows-cui";
99
0
    if (val == FU_COFF_SUBSYSTEM_OS2_CUI)
100
0
        return "os2-cui";
101
0
    if (val == FU_COFF_SUBSYSTEM_POSIX_CUI)
102
0
        return "posix-cui";
103
0
    if (val == FU_COFF_SUBSYSTEM_NATIVE_WINDOWS)
104
0
        return "native-windows";
105
0
    if (val == FU_COFF_SUBSYSTEM_WINDOWS_CE_GUI)
106
0
        return "windows-ce-gui";
107
0
    if (val == FU_COFF_SUBSYSTEM_EFI_APPLICATION)
108
0
        return "efi-application";
109
0
    if (val == FU_COFF_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)
110
0
        return "efi-boot-service-driver";
111
0
    if (val == FU_COFF_SUBSYSTEM_EFI_RUNTIME_DRIVER)
112
0
        return "efi-runtime-driver";
113
0
    if (val == FU_COFF_SUBSYSTEM_EFI_ROM)
114
0
        return "efi-rom";
115
0
    if (val == FU_COFF_SUBSYSTEM_XBOX)
116
0
        return "xbox";
117
0
    if (val == FU_COFF_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
118
0
        return "windows-boot-application";
119
0
    return NULL;
120
0
}
121
/* getters */
122
/**
123
 * fu_struct_pe_dos_header_get_magic: (skip):
124
 **/
125
static guint16
126
fu_struct_pe_dos_header_get_magic(const FuStructPeDosHeader *st)
127
0
{
128
0
    g_return_val_if_fail(st != NULL, 0x0);
129
0
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
130
0
}
131
/**
132
 * fu_struct_pe_dos_header_get_cblp: (skip):
133
 **/
134
guint16
135
fu_struct_pe_dos_header_get_cblp(const FuStructPeDosHeader *st)
136
0
{
137
0
    g_return_val_if_fail(st != NULL, 0x0);
138
0
    return fu_memread_uint16(st->data + 2, G_LITTLE_ENDIAN);
139
0
}
140
/**
141
 * fu_struct_pe_dos_header_get_cp: (skip):
142
 **/
143
guint16
144
fu_struct_pe_dos_header_get_cp(const FuStructPeDosHeader *st)
145
0
{
146
0
    g_return_val_if_fail(st != NULL, 0x0);
147
0
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
148
0
}
149
/**
150
 * fu_struct_pe_dos_header_get_crlc: (skip):
151
 **/
152
guint16
153
fu_struct_pe_dos_header_get_crlc(const FuStructPeDosHeader *st)
154
0
{
155
0
    g_return_val_if_fail(st != NULL, 0x0);
156
0
    return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN);
157
0
}
158
/**
159
 * fu_struct_pe_dos_header_get_cparhdr: (skip):
160
 **/
161
guint16
162
fu_struct_pe_dos_header_get_cparhdr(const FuStructPeDosHeader *st)
163
0
{
164
0
    g_return_val_if_fail(st != NULL, 0x0);
165
0
    return fu_memread_uint16(st->data + 8, G_LITTLE_ENDIAN);
166
0
}
167
/**
168
 * fu_struct_pe_dos_header_get_minalloc: (skip):
169
 **/
170
guint16
171
fu_struct_pe_dos_header_get_minalloc(const FuStructPeDosHeader *st)
172
0
{
173
0
    g_return_val_if_fail(st != NULL, 0x0);
174
0
    return fu_memread_uint16(st->data + 10, G_LITTLE_ENDIAN);
175
0
}
176
/**
177
 * fu_struct_pe_dos_header_get_maxalloc: (skip):
178
 **/
179
guint16
180
fu_struct_pe_dos_header_get_maxalloc(const FuStructPeDosHeader *st)
181
0
{
182
0
    g_return_val_if_fail(st != NULL, 0x0);
183
0
    return fu_memread_uint16(st->data + 12, G_LITTLE_ENDIAN);
184
0
}
185
/**
186
 * fu_struct_pe_dos_header_get_sp: (skip):
187
 **/
188
guint16
189
fu_struct_pe_dos_header_get_sp(const FuStructPeDosHeader *st)
190
0
{
191
0
    g_return_val_if_fail(st != NULL, 0x0);
192
0
    return fu_memread_uint16(st->data + 16, G_LITTLE_ENDIAN);
193
0
}
194
/**
195
 * fu_struct_pe_dos_header_get_lfarlc: (skip):
196
 **/
197
guint16
198
fu_struct_pe_dos_header_get_lfarlc(const FuStructPeDosHeader *st)
199
0
{
200
0
    g_return_val_if_fail(st != NULL, 0x0);
201
0
    return fu_memread_uint16(st->data + 24, G_LITTLE_ENDIAN);
202
0
}
203
/**
204
 * fu_struct_pe_dos_header_get_lfanew: (skip):
205
 **/
206
guint32
207
fu_struct_pe_dos_header_get_lfanew(const FuStructPeDosHeader *st)
208
0
{
209
0
    g_return_val_if_fail(st != NULL, 0x0);
210
0
    return fu_memread_uint32(st->data + 60, G_LITTLE_ENDIAN);
211
0
}
212
213
/* setters */
214
/**
215
 * fu_struct_pe_dos_header_set_magic: (skip):
216
 **/
217
static void
218
fu_struct_pe_dos_header_set_magic(FuStructPeDosHeader *st, guint16 value)
219
0
{
220
0
    g_return_if_fail(st != NULL);
221
0
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
222
0
}
223
/**
224
 * fu_struct_pe_dos_header_set_cblp: (skip):
225
 **/
226
void
227
fu_struct_pe_dos_header_set_cblp(FuStructPeDosHeader *st, guint16 value)
228
0
{
229
0
    g_return_if_fail(st != NULL);
230
0
    fu_memwrite_uint16(st->data + 2, value, G_LITTLE_ENDIAN);
231
0
}
232
/**
233
 * fu_struct_pe_dos_header_set_cp: (skip):
234
 **/
235
void
236
fu_struct_pe_dos_header_set_cp(FuStructPeDosHeader *st, guint16 value)
237
0
{
238
0
    g_return_if_fail(st != NULL);
239
0
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
240
0
}
241
/**
242
 * fu_struct_pe_dos_header_set_crlc: (skip):
243
 **/
244
void
245
fu_struct_pe_dos_header_set_crlc(FuStructPeDosHeader *st, guint16 value)
246
0
{
247
0
    g_return_if_fail(st != NULL);
248
0
    fu_memwrite_uint16(st->data + 6, value, G_LITTLE_ENDIAN);
249
0
}
250
/**
251
 * fu_struct_pe_dos_header_set_cparhdr: (skip):
252
 **/
253
void
254
fu_struct_pe_dos_header_set_cparhdr(FuStructPeDosHeader *st, guint16 value)
255
0
{
256
0
    g_return_if_fail(st != NULL);
257
0
    fu_memwrite_uint16(st->data + 8, value, G_LITTLE_ENDIAN);
258
0
}
259
/**
260
 * fu_struct_pe_dos_header_set_minalloc: (skip):
261
 **/
262
void
263
fu_struct_pe_dos_header_set_minalloc(FuStructPeDosHeader *st, guint16 value)
264
0
{
265
0
    g_return_if_fail(st != NULL);
266
0
    fu_memwrite_uint16(st->data + 10, value, G_LITTLE_ENDIAN);
267
0
}
268
/**
269
 * fu_struct_pe_dos_header_set_maxalloc: (skip):
270
 **/
271
void
272
fu_struct_pe_dos_header_set_maxalloc(FuStructPeDosHeader *st, guint16 value)
273
0
{
274
0
    g_return_if_fail(st != NULL);
275
0
    fu_memwrite_uint16(st->data + 12, value, G_LITTLE_ENDIAN);
276
0
}
277
/**
278
 * fu_struct_pe_dos_header_set_sp: (skip):
279
 **/
280
void
281
fu_struct_pe_dos_header_set_sp(FuStructPeDosHeader *st, guint16 value)
282
0
{
283
0
    g_return_if_fail(st != NULL);
284
0
    fu_memwrite_uint16(st->data + 16, value, G_LITTLE_ENDIAN);
285
0
}
286
/**
287
 * fu_struct_pe_dos_header_set_lfarlc: (skip):
288
 **/
289
void
290
fu_struct_pe_dos_header_set_lfarlc(FuStructPeDosHeader *st, guint16 value)
291
0
{
292
0
    g_return_if_fail(st != NULL);
293
0
    fu_memwrite_uint16(st->data + 24, value, G_LITTLE_ENDIAN);
294
0
}
295
/**
296
 * fu_struct_pe_dos_header_set_lfanew: (skip):
297
 **/
298
void
299
fu_struct_pe_dos_header_set_lfanew(FuStructPeDosHeader *st, guint32 value)
300
0
{
301
0
    g_return_if_fail(st != NULL);
302
0
    fu_memwrite_uint32(st->data + 60, value, G_LITTLE_ENDIAN);
303
0
}
304
/**
305
 * fu_struct_pe_dos_header_new: (skip):
306
 **/
307
FuStructPeDosHeader *
308
fu_struct_pe_dos_header_new(void)
309
0
{
310
0
    FuStructPeDosHeader *st = g_byte_array_sized_new(128);
311
0
    fu_byte_array_set_size(st, 128, 0x0);
312
0
    fu_struct_pe_dos_header_set_magic(st, 0x5A4D);
313
0
    fu_struct_pe_dos_header_set_cblp(st, 0x90);
314
0
    fu_struct_pe_dos_header_set_cp(st, 0x3);
315
0
    fu_struct_pe_dos_header_set_cparhdr(st, 0x4);
316
0
    fu_struct_pe_dos_header_set_maxalloc(st, 0xFFFF);
317
0
    fu_struct_pe_dos_header_set_sp(st, 0xB8);
318
0
    fu_struct_pe_dos_header_set_lfarlc(st, 0x40);
319
0
    fu_struct_pe_dos_header_set_lfanew(st, 0x80);
320
0
    return st;
321
0
}
322
/**
323
 * fu_struct_pe_dos_header_to_string: (skip):
324
 **/
325
static gchar *
326
fu_struct_pe_dos_header_to_string(const FuStructPeDosHeader *st)
327
0
{
328
0
    g_autoptr(GString) str = g_string_new("FuStructPeDosHeader:\n");
329
0
    g_return_val_if_fail(st != NULL, NULL);
330
0
    g_string_append_printf(str, "  cblp: 0x%x\n",
331
0
                           (guint) fu_struct_pe_dos_header_get_cblp(st));
332
0
    g_string_append_printf(str, "  cp: 0x%x\n",
333
0
                           (guint) fu_struct_pe_dos_header_get_cp(st));
334
0
    g_string_append_printf(str, "  crlc: 0x%x\n",
335
0
                           (guint) fu_struct_pe_dos_header_get_crlc(st));
336
0
    g_string_append_printf(str, "  cparhdr: 0x%x\n",
337
0
                           (guint) fu_struct_pe_dos_header_get_cparhdr(st));
338
0
    g_string_append_printf(str, "  minalloc: 0x%x\n",
339
0
                           (guint) fu_struct_pe_dos_header_get_minalloc(st));
340
0
    g_string_append_printf(str, "  maxalloc: 0x%x\n",
341
0
                           (guint) fu_struct_pe_dos_header_get_maxalloc(st));
342
0
    g_string_append_printf(str, "  sp: 0x%x\n",
343
0
                           (guint) fu_struct_pe_dos_header_get_sp(st));
344
0
    g_string_append_printf(str, "  lfarlc: 0x%x\n",
345
0
                           (guint) fu_struct_pe_dos_header_get_lfarlc(st));
346
0
    g_string_append_printf(str, "  lfanew: 0x%x\n",
347
0
                           (guint) fu_struct_pe_dos_header_get_lfanew(st));
348
0
    if (str->len > 0)
349
0
        g_string_set_size(str, str->len - 1);
350
0
    return g_string_free(g_steal_pointer(&str), FALSE);
351
0
}
352
static gboolean
353
fu_struct_pe_dos_header_validate_internal(FuStructPeDosHeader *st, GError **error)
354
0
{
355
0
    g_return_val_if_fail(st != NULL, FALSE);
356
0
    if (fu_struct_pe_dos_header_get_magic(st) != 0x5A4D) {
357
0
        g_set_error_literal(error,
358
0
                            FWUPD_ERROR,
359
0
                            FWUPD_ERROR_INVALID_DATA,
360
0
                            "constant FuStructPeDosHeader.magic was not valid");
361
0
        return FALSE;
362
0
    }
363
0
    return TRUE;
364
0
}
365
/**
366
 * fu_struct_pe_dos_header_validate_stream: (skip):
367
 **/
368
gboolean
369
fu_struct_pe_dos_header_validate_stream(GInputStream *stream, gsize offset, GError **error)
370
0
{
371
0
    g_autoptr(GByteArray) st = NULL;
372
0
    g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE);
373
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
374
0
    st = fu_input_stream_read_byte_array(stream, offset, 128, NULL, error);
375
0
    if (st == NULL) {
376
0
        g_prefix_error(error, "FuStructPeDosHeader failed read of 0x%x: ", (guint) 128);
377
0
        return FALSE;
378
0
    }
379
0
    if (st->len != 128) {
380
0
        g_set_error(error,
381
0
                    FWUPD_ERROR,
382
0
                    FWUPD_ERROR_INVALID_DATA,
383
0
                    "FuStructPeDosHeader requested 0x%x and got 0x%x",
384
0
                    (guint) 128,
385
0
                    (guint) st->len);
386
0
        return FALSE;
387
0
    }
388
0
    return fu_struct_pe_dos_header_validate_internal(st, error);
389
0
}
390
static gboolean
391
fu_struct_pe_dos_header_parse_internal(FuStructPeDosHeader *st, GError **error)
392
0
{
393
0
    if (!fu_struct_pe_dos_header_validate_internal(st, error))
394
0
        return FALSE;
395
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
396
0
        g_autofree gchar *str = fu_struct_pe_dos_header_to_string(st);
397
0
        g_debug("%s", str);
398
0
    }
399
0
    return TRUE;
400
0
}
401
/**
402
 * fu_struct_pe_dos_header_parse_stream: (skip):
403
 **/
404
FuStructPeDosHeader *
405
fu_struct_pe_dos_header_parse_stream(GInputStream *stream, gsize offset, GError **error)
406
0
{
407
0
    g_autoptr(GByteArray) st = NULL;
408
0
    st = fu_input_stream_read_byte_array(stream, offset, 128, NULL, error);
409
0
    if (st == NULL) {
410
0
        g_prefix_error(error, "FuStructPeDosHeader failed read of 0x%x: ", (guint) 128);
411
0
        return NULL;
412
0
    }
413
0
    if (st->len != 128) {
414
0
        g_set_error(error,
415
0
                    FWUPD_ERROR,
416
0
                    FWUPD_ERROR_INVALID_DATA,
417
0
                    "FuStructPeDosHeader requested 0x%x and got 0x%x",
418
0
                    (guint) 128,
419
0
                    (guint) st->len);
420
0
        return NULL;
421
0
    }
422
0
    if (!fu_struct_pe_dos_header_parse_internal(st, error))
423
0
        return NULL;
424
0
    return g_steal_pointer(&st);
425
0
}
426
/* getters */
427
/**
428
 * fu_struct_pe_coff_file_header_get_signature: (skip):
429
 **/
430
static guint32
431
fu_struct_pe_coff_file_header_get_signature(const FuStructPeCoffFileHeader *st)
432
0
{
433
0
    g_return_val_if_fail(st != NULL, 0x0);
434
0
    return fu_memread_uint32(st->data + 0, G_LITTLE_ENDIAN);
435
0
}
436
/**
437
 * fu_struct_pe_coff_file_header_get_machine: (skip):
438
 **/
439
FuPeCoffMachine
440
fu_struct_pe_coff_file_header_get_machine(const FuStructPeCoffFileHeader *st)
441
0
{
442
0
    g_return_val_if_fail(st != NULL, 0x0);
443
0
    return fu_memread_uint16(st->data + 4, G_LITTLE_ENDIAN);
444
0
}
445
/**
446
 * fu_struct_pe_coff_file_header_get_number_of_sections: (skip):
447
 **/
448
guint16
449
fu_struct_pe_coff_file_header_get_number_of_sections(const FuStructPeCoffFileHeader *st)
450
0
{
451
0
    g_return_val_if_fail(st != NULL, 0x0);
452
0
    return fu_memread_uint16(st->data + 6, G_LITTLE_ENDIAN);
453
0
}
454
/**
455
 * fu_struct_pe_coff_file_header_get_pointer_to_symbol_table: (skip):
456
 **/
457
guint32
458
fu_struct_pe_coff_file_header_get_pointer_to_symbol_table(const FuStructPeCoffFileHeader *st)
459
0
{
460
0
    g_return_val_if_fail(st != NULL, 0x0);
461
0
    return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN);
462
0
}
463
/**
464
 * fu_struct_pe_coff_file_header_get_number_of_symbols: (skip):
465
 **/
466
guint32
467
fu_struct_pe_coff_file_header_get_number_of_symbols(const FuStructPeCoffFileHeader *st)
468
0
{
469
0
    g_return_val_if_fail(st != NULL, 0x0);
470
0
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
471
0
}
472
/**
473
 * fu_struct_pe_coff_file_header_get_size_of_optional_header: (skip):
474
 **/
475
guint16
476
fu_struct_pe_coff_file_header_get_size_of_optional_header(const FuStructPeCoffFileHeader *st)
477
0
{
478
0
    g_return_val_if_fail(st != NULL, 0x0);
479
0
    return fu_memread_uint16(st->data + 20, G_LITTLE_ENDIAN);
480
0
}
481
/**
482
 * fu_struct_pe_coff_file_header_get_characteristics: (skip):
483
 **/
484
guint16
485
fu_struct_pe_coff_file_header_get_characteristics(const FuStructPeCoffFileHeader *st)
486
0
{
487
0
    g_return_val_if_fail(st != NULL, 0x0);
488
0
    return fu_memread_uint16(st->data + 22, G_LITTLE_ENDIAN);
489
0
}
490
491
/* setters */
492
/**
493
 * fu_struct_pe_coff_file_header_set_signature: (skip):
494
 **/
495
static void
496
fu_struct_pe_coff_file_header_set_signature(FuStructPeCoffFileHeader *st, guint32 value)
497
0
{
498
0
    g_return_if_fail(st != NULL);
499
0
    fu_memwrite_uint32(st->data + 0, value, G_LITTLE_ENDIAN);
500
0
}
501
/**
502
 * fu_struct_pe_coff_file_header_set_machine: (skip):
503
 **/
504
void
505
fu_struct_pe_coff_file_header_set_machine(FuStructPeCoffFileHeader *st, FuPeCoffMachine value)
506
0
{
507
0
    g_return_if_fail(st != NULL);
508
0
    fu_memwrite_uint16(st->data + 4, value, G_LITTLE_ENDIAN);
509
0
}
510
/**
511
 * fu_struct_pe_coff_file_header_set_number_of_sections: (skip):
512
 **/
513
void
514
fu_struct_pe_coff_file_header_set_number_of_sections(FuStructPeCoffFileHeader *st, guint16 value)
515
0
{
516
0
    g_return_if_fail(st != NULL);
517
0
    fu_memwrite_uint16(st->data + 6, value, G_LITTLE_ENDIAN);
518
0
}
519
/**
520
 * fu_struct_pe_coff_file_header_set_pointer_to_symbol_table: (skip):
521
 **/
522
void
523
fu_struct_pe_coff_file_header_set_pointer_to_symbol_table(FuStructPeCoffFileHeader *st, guint32 value)
524
0
{
525
0
    g_return_if_fail(st != NULL);
526
0
    fu_memwrite_uint32(st->data + 12, value, G_LITTLE_ENDIAN);
527
0
}
528
/**
529
 * fu_struct_pe_coff_file_header_set_number_of_symbols: (skip):
530
 **/
531
void
532
fu_struct_pe_coff_file_header_set_number_of_symbols(FuStructPeCoffFileHeader *st, guint32 value)
533
0
{
534
0
    g_return_if_fail(st != NULL);
535
0
    fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN);
536
0
}
537
/**
538
 * fu_struct_pe_coff_file_header_set_size_of_optional_header: (skip):
539
 **/
540
void
541
fu_struct_pe_coff_file_header_set_size_of_optional_header(FuStructPeCoffFileHeader *st, guint16 value)
542
0
{
543
0
    g_return_if_fail(st != NULL);
544
0
    fu_memwrite_uint16(st->data + 20, value, G_LITTLE_ENDIAN);
545
0
}
546
/**
547
 * fu_struct_pe_coff_file_header_set_characteristics: (skip):
548
 **/
549
void
550
fu_struct_pe_coff_file_header_set_characteristics(FuStructPeCoffFileHeader *st, guint16 value)
551
0
{
552
0
    g_return_if_fail(st != NULL);
553
0
    fu_memwrite_uint16(st->data + 22, value, G_LITTLE_ENDIAN);
554
0
}
555
/**
556
 * fu_struct_pe_coff_file_header_new: (skip):
557
 **/
558
FuStructPeCoffFileHeader *
559
fu_struct_pe_coff_file_header_new(void)
560
0
{
561
0
    FuStructPeCoffFileHeader *st = g_byte_array_sized_new(24);
562
0
    fu_byte_array_set_size(st, 24, 0x0);
563
0
    fu_struct_pe_coff_file_header_set_signature(st, 0x4550);
564
0
    fu_struct_pe_coff_file_header_set_machine(st, FU_PE_COFF_MACHINE_AMD64);
565
0
    fu_struct_pe_coff_file_header_set_size_of_optional_header(st, 0xf0);
566
0
    fu_struct_pe_coff_file_header_set_characteristics(st, 0x2022);
567
0
    return st;
568
0
}
569
/**
570
 * fu_struct_pe_coff_file_header_to_string: (skip):
571
 **/
572
static gchar *
573
fu_struct_pe_coff_file_header_to_string(const FuStructPeCoffFileHeader *st)
574
0
{
575
0
    g_autoptr(GString) str = g_string_new("FuStructPeCoffFileHeader:\n");
576
0
    g_return_val_if_fail(st != NULL, NULL);
577
0
    {
578
0
        const gchar *tmp = fu_pe_coff_machine_to_string(fu_struct_pe_coff_file_header_get_machine(st));
579
0
        if (tmp != NULL) {
580
0
            g_string_append_printf(str, "  machine: 0x%x [%s]\n", (guint) fu_struct_pe_coff_file_header_get_machine(st), tmp);
581
0
        } else {
582
0
            g_string_append_printf(str, "  machine: 0x%x\n", (guint) fu_struct_pe_coff_file_header_get_machine(st));
583
0
        }
584
0
    }
585
0
    g_string_append_printf(str, "  number_of_sections: 0x%x\n",
586
0
                           (guint) fu_struct_pe_coff_file_header_get_number_of_sections(st));
587
0
    g_string_append_printf(str, "  pointer_to_symbol_table: 0x%x\n",
588
0
                           (guint) fu_struct_pe_coff_file_header_get_pointer_to_symbol_table(st));
589
0
    g_string_append_printf(str, "  number_of_symbols: 0x%x\n",
590
0
                           (guint) fu_struct_pe_coff_file_header_get_number_of_symbols(st));
591
0
    g_string_append_printf(str, "  size_of_optional_header: 0x%x\n",
592
0
                           (guint) fu_struct_pe_coff_file_header_get_size_of_optional_header(st));
593
0
    g_string_append_printf(str, "  characteristics: 0x%x\n",
594
0
                           (guint) fu_struct_pe_coff_file_header_get_characteristics(st));
595
0
    if (str->len > 0)
596
0
        g_string_set_size(str, str->len - 1);
597
0
    return g_string_free(g_steal_pointer(&str), FALSE);
598
0
}
599
static gboolean
600
fu_struct_pe_coff_file_header_validate_internal(FuStructPeCoffFileHeader *st, GError **error)
601
0
{
602
0
    g_return_val_if_fail(st != NULL, FALSE);
603
0
    if (fu_struct_pe_coff_file_header_get_signature(st) != 0x4550) {
604
0
        g_set_error_literal(error,
605
0
                            FWUPD_ERROR,
606
0
                            FWUPD_ERROR_INVALID_DATA,
607
0
                            "constant FuStructPeCoffFileHeader.signature was not valid");
608
0
        return FALSE;
609
0
    }
610
0
    return TRUE;
611
0
}
612
static gboolean
613
fu_struct_pe_coff_file_header_parse_internal(FuStructPeCoffFileHeader *st, GError **error)
614
0
{
615
0
    if (!fu_struct_pe_coff_file_header_validate_internal(st, error))
616
0
        return FALSE;
617
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
618
0
        g_autofree gchar *str = fu_struct_pe_coff_file_header_to_string(st);
619
0
        g_debug("%s", str);
620
0
    }
621
0
    return TRUE;
622
0
}
623
/**
624
 * fu_struct_pe_coff_file_header_parse_stream: (skip):
625
 **/
626
FuStructPeCoffFileHeader *
627
fu_struct_pe_coff_file_header_parse_stream(GInputStream *stream, gsize offset, GError **error)
628
0
{
629
0
    g_autoptr(GByteArray) st = NULL;
630
0
    st = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error);
631
0
    if (st == NULL) {
632
0
        g_prefix_error(error, "FuStructPeCoffFileHeader failed read of 0x%x: ", (guint) 24);
633
0
        return NULL;
634
0
    }
635
0
    if (st->len != 24) {
636
0
        g_set_error(error,
637
0
                    FWUPD_ERROR,
638
0
                    FWUPD_ERROR_INVALID_DATA,
639
0
                    "FuStructPeCoffFileHeader requested 0x%x and got 0x%x",
640
0
                    (guint) 24,
641
0
                    (guint) st->len);
642
0
        return NULL;
643
0
    }
644
0
    if (!fu_struct_pe_coff_file_header_parse_internal(st, error))
645
0
        return NULL;
646
0
    return g_steal_pointer(&st);
647
0
}
648
/* getters */
649
/**
650
 * fu_struct_pe_coff_optional_header64_get_magic: (skip):
651
 **/
652
FuPeCoffMagic
653
fu_struct_pe_coff_optional_header64_get_magic(const FuStructPeCoffOptionalHeader64 *st)
654
0
{
655
0
    g_return_val_if_fail(st != NULL, 0x0);
656
0
    return fu_memread_uint16(st->data + 0, G_LITTLE_ENDIAN);
657
0
}
658
/**
659
 * fu_struct_pe_coff_optional_header64_get_major_linker_version: (skip):
660
 **/
661
guint8
662
fu_struct_pe_coff_optional_header64_get_major_linker_version(const FuStructPeCoffOptionalHeader64 *st)
663
0
{
664
0
    g_return_val_if_fail(st != NULL, 0x0);
665
0
    return st->data[2];
666
0
}
667
/**
668
 * fu_struct_pe_coff_optional_header64_get_minor_linker_version: (skip):
669
 **/
670
guint8
671
fu_struct_pe_coff_optional_header64_get_minor_linker_version(const FuStructPeCoffOptionalHeader64 *st)
672
0
{
673
0
    g_return_val_if_fail(st != NULL, 0x0);
674
0
    return st->data[3];
675
0
}
676
/**
677
 * fu_struct_pe_coff_optional_header64_get_size_of_code: (skip):
678
 **/
679
guint32
680
fu_struct_pe_coff_optional_header64_get_size_of_code(const FuStructPeCoffOptionalHeader64 *st)
681
0
{
682
0
    g_return_val_if_fail(st != NULL, 0x0);
683
0
    return fu_memread_uint32(st->data + 4, G_LITTLE_ENDIAN);
684
0
}
685
/**
686
 * fu_struct_pe_coff_optional_header64_get_size_of_initialized_data: (skip):
687
 **/
688
guint32
689
fu_struct_pe_coff_optional_header64_get_size_of_initialized_data(const FuStructPeCoffOptionalHeader64 *st)
690
0
{
691
0
    g_return_val_if_fail(st != NULL, 0x0);
692
0
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
693
0
}
694
/**
695
 * fu_struct_pe_coff_optional_header64_get_size_of_uninitialized_data: (skip):
696
 **/
697
guint32
698
fu_struct_pe_coff_optional_header64_get_size_of_uninitialized_data(const FuStructPeCoffOptionalHeader64 *st)
699
0
{
700
0
    g_return_val_if_fail(st != NULL, 0x0);
701
0
    return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN);
702
0
}
703
/**
704
 * fu_struct_pe_coff_optional_header64_get_addressofentrypoint: (skip):
705
 **/
706
guint32
707
fu_struct_pe_coff_optional_header64_get_addressofentrypoint(const FuStructPeCoffOptionalHeader64 *st)
708
0
{
709
0
    g_return_val_if_fail(st != NULL, 0x0);
710
0
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
711
0
}
712
/**
713
 * fu_struct_pe_coff_optional_header64_get_base_of_code: (skip):
714
 **/
715
guint32
716
fu_struct_pe_coff_optional_header64_get_base_of_code(const FuStructPeCoffOptionalHeader64 *st)
717
0
{
718
0
    g_return_val_if_fail(st != NULL, 0x0);
719
0
    return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN);
720
0
}
721
/**
722
 * fu_struct_pe_coff_optional_header64_get_image_base: (skip):
723
 **/
724
guint64
725
fu_struct_pe_coff_optional_header64_get_image_base(const FuStructPeCoffOptionalHeader64 *st)
726
0
{
727
0
    g_return_val_if_fail(st != NULL, 0x0);
728
0
    return fu_memread_uint64(st->data + 24, G_LITTLE_ENDIAN);
729
0
}
730
/**
731
 * fu_struct_pe_coff_optional_header64_get_section_alignment: (skip):
732
 **/
733
guint32
734
fu_struct_pe_coff_optional_header64_get_section_alignment(const FuStructPeCoffOptionalHeader64 *st)
735
0
{
736
0
    g_return_val_if_fail(st != NULL, 0x0);
737
0
    return fu_memread_uint32(st->data + 32, G_LITTLE_ENDIAN);
738
0
}
739
/**
740
 * fu_struct_pe_coff_optional_header64_get_file_alignment: (skip):
741
 **/
742
guint32
743
fu_struct_pe_coff_optional_header64_get_file_alignment(const FuStructPeCoffOptionalHeader64 *st)
744
0
{
745
0
    g_return_val_if_fail(st != NULL, 0x0);
746
0
    return fu_memread_uint32(st->data + 36, G_LITTLE_ENDIAN);
747
0
}
748
/**
749
 * fu_struct_pe_coff_optional_header64_get_size_of_image: (skip):
750
 **/
751
guint32
752
fu_struct_pe_coff_optional_header64_get_size_of_image(const FuStructPeCoffOptionalHeader64 *st)
753
0
{
754
0
    g_return_val_if_fail(st != NULL, 0x0);
755
0
    return fu_memread_uint32(st->data + 56, G_LITTLE_ENDIAN);
756
0
}
757
/**
758
 * fu_struct_pe_coff_optional_header64_get_size_of_headers: (skip):
759
 **/
760
guint32
761
fu_struct_pe_coff_optional_header64_get_size_of_headers(const FuStructPeCoffOptionalHeader64 *st)
762
0
{
763
0
    g_return_val_if_fail(st != NULL, 0x0);
764
0
    return fu_memread_uint32(st->data + 60, G_LITTLE_ENDIAN);
765
0
}
766
/**
767
 * fu_struct_pe_coff_optional_header64_get_checksum: (skip):
768
 **/
769
guint32
770
fu_struct_pe_coff_optional_header64_get_checksum(const FuStructPeCoffOptionalHeader64 *st)
771
0
{
772
0
    g_return_val_if_fail(st != NULL, 0x0);
773
0
    return fu_memread_uint32(st->data + 64, G_LITTLE_ENDIAN);
774
0
}
775
/**
776
 * fu_struct_pe_coff_optional_header64_get_subsystem: (skip):
777
 **/
778
FuCoffSubsystem
779
fu_struct_pe_coff_optional_header64_get_subsystem(const FuStructPeCoffOptionalHeader64 *st)
780
0
{
781
0
    g_return_val_if_fail(st != NULL, 0x0);
782
0
    return fu_memread_uint16(st->data + 68, G_LITTLE_ENDIAN);
783
0
}
784
/**
785
 * fu_struct_pe_coff_optional_header64_get_loader_flags: (skip):
786
 **/
787
guint32
788
fu_struct_pe_coff_optional_header64_get_loader_flags(const FuStructPeCoffOptionalHeader64 *st)
789
0
{
790
0
    g_return_val_if_fail(st != NULL, 0x0);
791
0
    return fu_memread_uint32(st->data + 104, G_LITTLE_ENDIAN);
792
0
}
793
/**
794
 * fu_struct_pe_coff_optional_header64_get_number_of_rva_and_sizes: (skip):
795
 **/
796
guint32
797
fu_struct_pe_coff_optional_header64_get_number_of_rva_and_sizes(const FuStructPeCoffOptionalHeader64 *st)
798
0
{
799
0
    g_return_val_if_fail(st != NULL, 0x0);
800
0
    return fu_memread_uint32(st->data + 108, G_LITTLE_ENDIAN);
801
0
}
802
/**
803
 * fu_struct_pe_coff_optional_header64_get_certificate_table: (skip):
804
 **/
805
guint32
806
fu_struct_pe_coff_optional_header64_get_certificate_table(const FuStructPeCoffOptionalHeader64 *st)
807
0
{
808
0
    g_return_val_if_fail(st != NULL, 0x0);
809
0
    return fu_memread_uint32(st->data + 144, G_LITTLE_ENDIAN);
810
0
}
811
/**
812
 * fu_struct_pe_coff_optional_header64_get_size_of_certificate_table: (skip):
813
 **/
814
guint32
815
fu_struct_pe_coff_optional_header64_get_size_of_certificate_table(const FuStructPeCoffOptionalHeader64 *st)
816
0
{
817
0
    g_return_val_if_fail(st != NULL, 0x0);
818
0
    return fu_memread_uint32(st->data + 148, G_LITTLE_ENDIAN);
819
0
}
820
/**
821
 * fu_struct_pe_coff_optional_header64_get_debug_table: (skip):
822
 **/
823
guint32
824
fu_struct_pe_coff_optional_header64_get_debug_table(const FuStructPeCoffOptionalHeader64 *st)
825
0
{
826
0
    g_return_val_if_fail(st != NULL, 0x0);
827
0
    return fu_memread_uint32(st->data + 152, G_LITTLE_ENDIAN);
828
0
}
829
/**
830
 * fu_struct_pe_coff_optional_header64_get_size_of_debug_table: (skip):
831
 **/
832
guint32
833
fu_struct_pe_coff_optional_header64_get_size_of_debug_table(const FuStructPeCoffOptionalHeader64 *st)
834
0
{
835
0
    g_return_val_if_fail(st != NULL, 0x0);
836
0
    return fu_memread_uint32(st->data + 156, G_LITTLE_ENDIAN);
837
0
}
838
839
/* setters */
840
/**
841
 * fu_struct_pe_coff_optional_header64_set_magic: (skip):
842
 **/
843
void
844
fu_struct_pe_coff_optional_header64_set_magic(FuStructPeCoffOptionalHeader64 *st, FuPeCoffMagic value)
845
0
{
846
0
    g_return_if_fail(st != NULL);
847
0
    fu_memwrite_uint16(st->data + 0, value, G_LITTLE_ENDIAN);
848
0
}
849
/**
850
 * fu_struct_pe_coff_optional_header64_set_major_linker_version: (skip):
851
 **/
852
void
853
fu_struct_pe_coff_optional_header64_set_major_linker_version(FuStructPeCoffOptionalHeader64 *st, guint8 value)
854
0
{
855
0
    g_return_if_fail(st != NULL);
856
0
    st->data[2] = value;
857
0
}
858
/**
859
 * fu_struct_pe_coff_optional_header64_set_minor_linker_version: (skip):
860
 **/
861
void
862
fu_struct_pe_coff_optional_header64_set_minor_linker_version(FuStructPeCoffOptionalHeader64 *st, guint8 value)
863
0
{
864
0
    g_return_if_fail(st != NULL);
865
0
    st->data[3] = value;
866
0
}
867
/**
868
 * fu_struct_pe_coff_optional_header64_set_size_of_code: (skip):
869
 **/
870
void
871
fu_struct_pe_coff_optional_header64_set_size_of_code(FuStructPeCoffOptionalHeader64 *st, guint32 value)
872
0
{
873
0
    g_return_if_fail(st != NULL);
874
0
    fu_memwrite_uint32(st->data + 4, value, G_LITTLE_ENDIAN);
875
0
}
876
/**
877
 * fu_struct_pe_coff_optional_header64_set_size_of_initialized_data: (skip):
878
 **/
879
void
880
fu_struct_pe_coff_optional_header64_set_size_of_initialized_data(FuStructPeCoffOptionalHeader64 *st, guint32 value)
881
0
{
882
0
    g_return_if_fail(st != NULL);
883
0
    fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN);
884
0
}
885
/**
886
 * fu_struct_pe_coff_optional_header64_set_size_of_uninitialized_data: (skip):
887
 **/
888
void
889
fu_struct_pe_coff_optional_header64_set_size_of_uninitialized_data(FuStructPeCoffOptionalHeader64 *st, guint32 value)
890
0
{
891
0
    g_return_if_fail(st != NULL);
892
0
    fu_memwrite_uint32(st->data + 12, value, G_LITTLE_ENDIAN);
893
0
}
894
/**
895
 * fu_struct_pe_coff_optional_header64_set_addressofentrypoint: (skip):
896
 **/
897
void
898
fu_struct_pe_coff_optional_header64_set_addressofentrypoint(FuStructPeCoffOptionalHeader64 *st, guint32 value)
899
0
{
900
0
    g_return_if_fail(st != NULL);
901
0
    fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN);
902
0
}
903
/**
904
 * fu_struct_pe_coff_optional_header64_set_base_of_code: (skip):
905
 **/
906
void
907
fu_struct_pe_coff_optional_header64_set_base_of_code(FuStructPeCoffOptionalHeader64 *st, guint32 value)
908
0
{
909
0
    g_return_if_fail(st != NULL);
910
0
    fu_memwrite_uint32(st->data + 20, value, G_LITTLE_ENDIAN);
911
0
}
912
/**
913
 * fu_struct_pe_coff_optional_header64_set_image_base: (skip):
914
 **/
915
void
916
fu_struct_pe_coff_optional_header64_set_image_base(FuStructPeCoffOptionalHeader64 *st, guint64 value)
917
0
{
918
0
    g_return_if_fail(st != NULL);
919
0
    fu_memwrite_uint64(st->data + 24, value, G_LITTLE_ENDIAN);
920
0
}
921
/**
922
 * fu_struct_pe_coff_optional_header64_set_section_alignment: (skip):
923
 **/
924
void
925
fu_struct_pe_coff_optional_header64_set_section_alignment(FuStructPeCoffOptionalHeader64 *st, guint32 value)
926
0
{
927
0
    g_return_if_fail(st != NULL);
928
0
    fu_memwrite_uint32(st->data + 32, value, G_LITTLE_ENDIAN);
929
0
}
930
/**
931
 * fu_struct_pe_coff_optional_header64_set_file_alignment: (skip):
932
 **/
933
void
934
fu_struct_pe_coff_optional_header64_set_file_alignment(FuStructPeCoffOptionalHeader64 *st, guint32 value)
935
0
{
936
0
    g_return_if_fail(st != NULL);
937
0
    fu_memwrite_uint32(st->data + 36, value, G_LITTLE_ENDIAN);
938
0
}
939
/**
940
 * fu_struct_pe_coff_optional_header64_set_size_of_image: (skip):
941
 **/
942
void
943
fu_struct_pe_coff_optional_header64_set_size_of_image(FuStructPeCoffOptionalHeader64 *st, guint32 value)
944
0
{
945
0
    g_return_if_fail(st != NULL);
946
0
    fu_memwrite_uint32(st->data + 56, value, G_LITTLE_ENDIAN);
947
0
}
948
/**
949
 * fu_struct_pe_coff_optional_header64_set_size_of_headers: (skip):
950
 **/
951
void
952
fu_struct_pe_coff_optional_header64_set_size_of_headers(FuStructPeCoffOptionalHeader64 *st, guint32 value)
953
0
{
954
0
    g_return_if_fail(st != NULL);
955
0
    fu_memwrite_uint32(st->data + 60, value, G_LITTLE_ENDIAN);
956
0
}
957
/**
958
 * fu_struct_pe_coff_optional_header64_set_checksum: (skip):
959
 **/
960
void
961
fu_struct_pe_coff_optional_header64_set_checksum(FuStructPeCoffOptionalHeader64 *st, guint32 value)
962
0
{
963
0
    g_return_if_fail(st != NULL);
964
0
    fu_memwrite_uint32(st->data + 64, value, G_LITTLE_ENDIAN);
965
0
}
966
/**
967
 * fu_struct_pe_coff_optional_header64_set_subsystem: (skip):
968
 **/
969
void
970
fu_struct_pe_coff_optional_header64_set_subsystem(FuStructPeCoffOptionalHeader64 *st, FuCoffSubsystem value)
971
0
{
972
0
    g_return_if_fail(st != NULL);
973
0
    fu_memwrite_uint16(st->data + 68, value, G_LITTLE_ENDIAN);
974
0
}
975
/**
976
 * fu_struct_pe_coff_optional_header64_set_loader_flags: (skip):
977
 **/
978
void
979
fu_struct_pe_coff_optional_header64_set_loader_flags(FuStructPeCoffOptionalHeader64 *st, guint32 value)
980
0
{
981
0
    g_return_if_fail(st != NULL);
982
0
    fu_memwrite_uint32(st->data + 104, value, G_LITTLE_ENDIAN);
983
0
}
984
/**
985
 * fu_struct_pe_coff_optional_header64_set_number_of_rva_and_sizes: (skip):
986
 **/
987
void
988
fu_struct_pe_coff_optional_header64_set_number_of_rva_and_sizes(FuStructPeCoffOptionalHeader64 *st, guint32 value)
989
0
{
990
0
    g_return_if_fail(st != NULL);
991
0
    fu_memwrite_uint32(st->data + 108, value, G_LITTLE_ENDIAN);
992
0
}
993
/**
994
 * fu_struct_pe_coff_optional_header64_set_certificate_table: (skip):
995
 **/
996
void
997
fu_struct_pe_coff_optional_header64_set_certificate_table(FuStructPeCoffOptionalHeader64 *st, guint32 value)
998
0
{
999
0
    g_return_if_fail(st != NULL);
1000
0
    fu_memwrite_uint32(st->data + 144, value, G_LITTLE_ENDIAN);
1001
0
}
1002
/**
1003
 * fu_struct_pe_coff_optional_header64_set_size_of_certificate_table: (skip):
1004
 **/
1005
void
1006
fu_struct_pe_coff_optional_header64_set_size_of_certificate_table(FuStructPeCoffOptionalHeader64 *st, guint32 value)
1007
0
{
1008
0
    g_return_if_fail(st != NULL);
1009
0
    fu_memwrite_uint32(st->data + 148, value, G_LITTLE_ENDIAN);
1010
0
}
1011
/**
1012
 * fu_struct_pe_coff_optional_header64_set_debug_table: (skip):
1013
 **/
1014
void
1015
fu_struct_pe_coff_optional_header64_set_debug_table(FuStructPeCoffOptionalHeader64 *st, guint32 value)
1016
0
{
1017
0
    g_return_if_fail(st != NULL);
1018
0
    fu_memwrite_uint32(st->data + 152, value, G_LITTLE_ENDIAN);
1019
0
}
1020
/**
1021
 * fu_struct_pe_coff_optional_header64_set_size_of_debug_table: (skip):
1022
 **/
1023
void
1024
fu_struct_pe_coff_optional_header64_set_size_of_debug_table(FuStructPeCoffOptionalHeader64 *st, guint32 value)
1025
0
{
1026
0
    g_return_if_fail(st != NULL);
1027
0
    fu_memwrite_uint32(st->data + 156, value, G_LITTLE_ENDIAN);
1028
0
}
1029
/**
1030
 * fu_struct_pe_coff_optional_header64_new: (skip):
1031
 **/
1032
FuStructPeCoffOptionalHeader64 *
1033
fu_struct_pe_coff_optional_header64_new(void)
1034
0
{
1035
0
    FuStructPeCoffOptionalHeader64 *st = g_byte_array_sized_new(176);
1036
0
    fu_byte_array_set_size(st, 176, 0x0);
1037
0
    fu_struct_pe_coff_optional_header64_set_magic(st, FU_PE_COFF_MAGIC_PE32_PLUS);
1038
0
    fu_struct_pe_coff_optional_header64_set_major_linker_version(st, 0x0e);
1039
0
    fu_struct_pe_coff_optional_header64_set_minor_linker_version(st, 0x0e);
1040
0
    fu_struct_pe_coff_optional_header64_set_section_alignment(st, 0x200);
1041
0
    fu_struct_pe_coff_optional_header64_set_file_alignment(st, 0x200);
1042
0
    fu_struct_pe_coff_optional_header64_set_subsystem(st, FU_COFF_SUBSYSTEM_EFI_APPLICATION);
1043
0
    return st;
1044
0
}
1045
/**
1046
 * fu_struct_pe_coff_optional_header64_to_string: (skip):
1047
 **/
1048
static gchar *
1049
fu_struct_pe_coff_optional_header64_to_string(const FuStructPeCoffOptionalHeader64 *st)
1050
0
{
1051
0
    g_autoptr(GString) str = g_string_new("FuStructPeCoffOptionalHeader64:\n");
1052
0
    g_return_val_if_fail(st != NULL, NULL);
1053
0
    {
1054
0
        const gchar *tmp = fu_pe_coff_magic_to_string(fu_struct_pe_coff_optional_header64_get_magic(st));
1055
0
        if (tmp != NULL) {
1056
0
            g_string_append_printf(str, "  magic: 0x%x [%s]\n", (guint) fu_struct_pe_coff_optional_header64_get_magic(st), tmp);
1057
0
        } else {
1058
0
            g_string_append_printf(str, "  magic: 0x%x\n", (guint) fu_struct_pe_coff_optional_header64_get_magic(st));
1059
0
        }
1060
0
    }
1061
0
    g_string_append_printf(str, "  major_linker_version: 0x%x\n",
1062
0
                           (guint) fu_struct_pe_coff_optional_header64_get_major_linker_version(st));
1063
0
    g_string_append_printf(str, "  minor_linker_version: 0x%x\n",
1064
0
                           (guint) fu_struct_pe_coff_optional_header64_get_minor_linker_version(st));
1065
0
    g_string_append_printf(str, "  size_of_code: 0x%x\n",
1066
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_code(st));
1067
0
    g_string_append_printf(str, "  size_of_initialized_data: 0x%x\n",
1068
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_initialized_data(st));
1069
0
    g_string_append_printf(str, "  size_of_uninitialized_data: 0x%x\n",
1070
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_uninitialized_data(st));
1071
0
    g_string_append_printf(str, "  addressofentrypoint: 0x%x\n",
1072
0
                           (guint) fu_struct_pe_coff_optional_header64_get_addressofentrypoint(st));
1073
0
    g_string_append_printf(str, "  base_of_code: 0x%x\n",
1074
0
                           (guint) fu_struct_pe_coff_optional_header64_get_base_of_code(st));
1075
0
    g_string_append_printf(str, "  image_base: 0x%x\n",
1076
0
                           (guint) fu_struct_pe_coff_optional_header64_get_image_base(st));
1077
0
    g_string_append_printf(str, "  section_alignment: 0x%x\n",
1078
0
                           (guint) fu_struct_pe_coff_optional_header64_get_section_alignment(st));
1079
0
    g_string_append_printf(str, "  file_alignment: 0x%x\n",
1080
0
                           (guint) fu_struct_pe_coff_optional_header64_get_file_alignment(st));
1081
0
    g_string_append_printf(str, "  size_of_image: 0x%x\n",
1082
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_image(st));
1083
0
    g_string_append_printf(str, "  size_of_headers: 0x%x\n",
1084
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_headers(st));
1085
0
    g_string_append_printf(str, "  checksum: 0x%x\n",
1086
0
                           (guint) fu_struct_pe_coff_optional_header64_get_checksum(st));
1087
0
    {
1088
0
        const gchar *tmp = fu_coff_subsystem_to_string(fu_struct_pe_coff_optional_header64_get_subsystem(st));
1089
0
        if (tmp != NULL) {
1090
0
            g_string_append_printf(str, "  subsystem: 0x%x [%s]\n", (guint) fu_struct_pe_coff_optional_header64_get_subsystem(st), tmp);
1091
0
        } else {
1092
0
            g_string_append_printf(str, "  subsystem: 0x%x\n", (guint) fu_struct_pe_coff_optional_header64_get_subsystem(st));
1093
0
        }
1094
0
    }
1095
0
    g_string_append_printf(str, "  loader_flags: 0x%x\n",
1096
0
                           (guint) fu_struct_pe_coff_optional_header64_get_loader_flags(st));
1097
0
    g_string_append_printf(str, "  number_of_rva_and_sizes: 0x%x\n",
1098
0
                           (guint) fu_struct_pe_coff_optional_header64_get_number_of_rva_and_sizes(st));
1099
0
    g_string_append_printf(str, "  certificate_table: 0x%x\n",
1100
0
                           (guint) fu_struct_pe_coff_optional_header64_get_certificate_table(st));
1101
0
    g_string_append_printf(str, "  size_of_certificate_table: 0x%x\n",
1102
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_certificate_table(st));
1103
0
    g_string_append_printf(str, "  debug_table: 0x%x\n",
1104
0
                           (guint) fu_struct_pe_coff_optional_header64_get_debug_table(st));
1105
0
    g_string_append_printf(str, "  size_of_debug_table: 0x%x\n",
1106
0
                           (guint) fu_struct_pe_coff_optional_header64_get_size_of_debug_table(st));
1107
0
    if (str->len > 0)
1108
0
        g_string_set_size(str, str->len - 1);
1109
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1110
0
}
1111
static gboolean
1112
fu_struct_pe_coff_optional_header64_validate_internal(FuStructPeCoffOptionalHeader64 *st, GError **error)
1113
0
{
1114
0
    g_return_val_if_fail(st != NULL, FALSE);
1115
0
    return TRUE;
1116
0
}
1117
static gboolean
1118
fu_struct_pe_coff_optional_header64_parse_internal(FuStructPeCoffOptionalHeader64 *st, GError **error)
1119
0
{
1120
0
    if (!fu_struct_pe_coff_optional_header64_validate_internal(st, error))
1121
0
        return FALSE;
1122
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1123
0
        g_autofree gchar *str = fu_struct_pe_coff_optional_header64_to_string(st);
1124
0
        g_debug("%s", str);
1125
0
    }
1126
0
    return TRUE;
1127
0
}
1128
/**
1129
 * fu_struct_pe_coff_optional_header64_parse_stream: (skip):
1130
 **/
1131
FuStructPeCoffOptionalHeader64 *
1132
fu_struct_pe_coff_optional_header64_parse_stream(GInputStream *stream, gsize offset, GError **error)
1133
0
{
1134
0
    g_autoptr(GByteArray) st = NULL;
1135
0
    st = fu_input_stream_read_byte_array(stream, offset, 176, NULL, error);
1136
0
    if (st == NULL) {
1137
0
        g_prefix_error(error, "FuStructPeCoffOptionalHeader64 failed read of 0x%x: ", (guint) 176);
1138
0
        return NULL;
1139
0
    }
1140
0
    if (st->len != 176) {
1141
0
        g_set_error(error,
1142
0
                    FWUPD_ERROR,
1143
0
                    FWUPD_ERROR_INVALID_DATA,
1144
0
                    "FuStructPeCoffOptionalHeader64 requested 0x%x and got 0x%x",
1145
0
                    (guint) 176,
1146
0
                    (guint) st->len);
1147
0
        return NULL;
1148
0
    }
1149
0
    if (!fu_struct_pe_coff_optional_header64_parse_internal(st, error))
1150
0
        return NULL;
1151
0
    return g_steal_pointer(&st);
1152
0
}
1153
/* getters */
1154
1155
/* setters */
1156
/* getters */
1157
/**
1158
 * fu_struct_pe_coff_section_get_name: (skip):
1159
 **/
1160
gchar *
1161
fu_struct_pe_coff_section_get_name(const FuStructPeCoffSection *st)
1162
0
{
1163
0
    g_return_val_if_fail(st != NULL, NULL);
1164
0
    return fu_memstrsafe(st->data, st->len, 0, 8, NULL);
1165
0
}
1166
/**
1167
 * fu_struct_pe_coff_section_get_virtual_size: (skip):
1168
 **/
1169
guint32
1170
fu_struct_pe_coff_section_get_virtual_size(const FuStructPeCoffSection *st)
1171
0
{
1172
0
    g_return_val_if_fail(st != NULL, 0x0);
1173
0
    return fu_memread_uint32(st->data + 8, G_LITTLE_ENDIAN);
1174
0
}
1175
/**
1176
 * fu_struct_pe_coff_section_get_virtual_address: (skip):
1177
 **/
1178
guint32
1179
fu_struct_pe_coff_section_get_virtual_address(const FuStructPeCoffSection *st)
1180
0
{
1181
0
    g_return_val_if_fail(st != NULL, 0x0);
1182
0
    return fu_memread_uint32(st->data + 12, G_LITTLE_ENDIAN);
1183
0
}
1184
/**
1185
 * fu_struct_pe_coff_section_get_size_of_raw_data: (skip):
1186
 **/
1187
guint32
1188
fu_struct_pe_coff_section_get_size_of_raw_data(const FuStructPeCoffSection *st)
1189
0
{
1190
0
    g_return_val_if_fail(st != NULL, 0x0);
1191
0
    return fu_memread_uint32(st->data + 16, G_LITTLE_ENDIAN);
1192
0
}
1193
/**
1194
 * fu_struct_pe_coff_section_get_pointer_to_raw_data: (skip):
1195
 **/
1196
guint32
1197
fu_struct_pe_coff_section_get_pointer_to_raw_data(const FuStructPeCoffSection *st)
1198
0
{
1199
0
    g_return_val_if_fail(st != NULL, 0x0);
1200
0
    return fu_memread_uint32(st->data + 20, G_LITTLE_ENDIAN);
1201
0
}
1202
/**
1203
 * fu_struct_pe_coff_section_get_characteristics: (skip):
1204
 **/
1205
guint32
1206
fu_struct_pe_coff_section_get_characteristics(const FuStructPeCoffSection *st)
1207
0
{
1208
0
    g_return_val_if_fail(st != NULL, 0x0);
1209
0
    return fu_memread_uint32(st->data + 36, G_LITTLE_ENDIAN);
1210
0
}
1211
1212
/* setters */
1213
/**
1214
 * fu_struct_pe_coff_section_set_name: (skip):
1215
 **/
1216
gboolean
1217
fu_struct_pe_coff_section_set_name(FuStructPeCoffSection *st, const gchar *value, GError **error)
1218
0
{
1219
0
    gsize len;
1220
0
    g_return_val_if_fail(st != NULL, FALSE);
1221
0
    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
1222
0
    if (value == NULL) {
1223
0
        memset(st->data + 0, 0x0, 8);
1224
0
        return TRUE;
1225
0
    }
1226
0
    len = strlen(value);
1227
0
    if (len > 8) {
1228
0
        g_set_error(error,
1229
0
                    FWUPD_ERROR,
1230
0
                    FWUPD_ERROR_INVALID_DATA,
1231
0
                    "string '%s' (0x%x bytes) does not fit in FuStructPeCoffSection.name (0x%x bytes)",
1232
0
                    value, (guint) len, (guint) 8);
1233
0
        return FALSE;
1234
0
    }
1235
0
    return fu_memcpy_safe(st->data, st->len, 0, (const guint8 *)value, len, 0x0, len, error);
1236
0
}
1237
/**
1238
 * fu_struct_pe_coff_section_set_virtual_size: (skip):
1239
 **/
1240
void
1241
fu_struct_pe_coff_section_set_virtual_size(FuStructPeCoffSection *st, guint32 value)
1242
0
{
1243
0
    g_return_if_fail(st != NULL);
1244
0
    fu_memwrite_uint32(st->data + 8, value, G_LITTLE_ENDIAN);
1245
0
}
1246
/**
1247
 * fu_struct_pe_coff_section_set_virtual_address: (skip):
1248
 **/
1249
void
1250
fu_struct_pe_coff_section_set_virtual_address(FuStructPeCoffSection *st, guint32 value)
1251
0
{
1252
0
    g_return_if_fail(st != NULL);
1253
0
    fu_memwrite_uint32(st->data + 12, value, G_LITTLE_ENDIAN);
1254
0
}
1255
/**
1256
 * fu_struct_pe_coff_section_set_size_of_raw_data: (skip):
1257
 **/
1258
void
1259
fu_struct_pe_coff_section_set_size_of_raw_data(FuStructPeCoffSection *st, guint32 value)
1260
0
{
1261
0
    g_return_if_fail(st != NULL);
1262
0
    fu_memwrite_uint32(st->data + 16, value, G_LITTLE_ENDIAN);
1263
0
}
1264
/**
1265
 * fu_struct_pe_coff_section_set_pointer_to_raw_data: (skip):
1266
 **/
1267
void
1268
fu_struct_pe_coff_section_set_pointer_to_raw_data(FuStructPeCoffSection *st, guint32 value)
1269
0
{
1270
0
    g_return_if_fail(st != NULL);
1271
0
    fu_memwrite_uint32(st->data + 20, value, G_LITTLE_ENDIAN);
1272
0
}
1273
/**
1274
 * fu_struct_pe_coff_section_set_characteristics: (skip):
1275
 **/
1276
void
1277
fu_struct_pe_coff_section_set_characteristics(FuStructPeCoffSection *st, guint32 value)
1278
0
{
1279
0
    g_return_if_fail(st != NULL);
1280
0
    fu_memwrite_uint32(st->data + 36, value, G_LITTLE_ENDIAN);
1281
0
}
1282
/**
1283
 * fu_struct_pe_coff_section_new: (skip):
1284
 **/
1285
FuStructPeCoffSection *
1286
fu_struct_pe_coff_section_new(void)
1287
0
{
1288
0
    FuStructPeCoffSection *st = g_byte_array_sized_new(40);
1289
0
    fu_byte_array_set_size(st, 40, 0x0);
1290
0
    return st;
1291
0
}
1292
/**
1293
 * fu_struct_pe_coff_section_to_string: (skip):
1294
 **/
1295
static gchar *
1296
fu_struct_pe_coff_section_to_string(const FuStructPeCoffSection *st)
1297
0
{
1298
0
    g_autoptr(GString) str = g_string_new("FuStructPeCoffSection:\n");
1299
0
    g_return_val_if_fail(st != NULL, NULL);
1300
0
    {
1301
0
        g_autofree gchar *tmp = fu_struct_pe_coff_section_get_name(st);
1302
0
        if (tmp != NULL)
1303
0
            g_string_append_printf(str, "  name: %s\n", tmp);
1304
0
    }
1305
0
    g_string_append_printf(str, "  virtual_size: 0x%x\n",
1306
0
                           (guint) fu_struct_pe_coff_section_get_virtual_size(st));
1307
0
    g_string_append_printf(str, "  virtual_address: 0x%x\n",
1308
0
                           (guint) fu_struct_pe_coff_section_get_virtual_address(st));
1309
0
    g_string_append_printf(str, "  size_of_raw_data: 0x%x\n",
1310
0
                           (guint) fu_struct_pe_coff_section_get_size_of_raw_data(st));
1311
0
    g_string_append_printf(str, "  pointer_to_raw_data: 0x%x\n",
1312
0
                           (guint) fu_struct_pe_coff_section_get_pointer_to_raw_data(st));
1313
0
    g_string_append_printf(str, "  characteristics: 0x%x\n",
1314
0
                           (guint) fu_struct_pe_coff_section_get_characteristics(st));
1315
0
    if (str->len > 0)
1316
0
        g_string_set_size(str, str->len - 1);
1317
0
    return g_string_free(g_steal_pointer(&str), FALSE);
1318
0
}
1319
static gboolean
1320
fu_struct_pe_coff_section_validate_internal(FuStructPeCoffSection *st, GError **error)
1321
0
{
1322
0
    g_return_val_if_fail(st != NULL, FALSE);
1323
0
    return TRUE;
1324
0
}
1325
static gboolean
1326
fu_struct_pe_coff_section_parse_internal(FuStructPeCoffSection *st, GError **error)
1327
0
{
1328
0
    if (!fu_struct_pe_coff_section_validate_internal(st, error))
1329
0
        return FALSE;
1330
0
    if (g_getenv("FWUPD_VERBOSE") != NULL) {
1331
0
        g_autofree gchar *str = fu_struct_pe_coff_section_to_string(st);
1332
0
        g_debug("%s", str);
1333
0
    }
1334
0
    return TRUE;
1335
0
}
1336
/**
1337
 * fu_struct_pe_coff_section_parse_stream: (skip):
1338
 **/
1339
FuStructPeCoffSection *
1340
fu_struct_pe_coff_section_parse_stream(GInputStream *stream, gsize offset, GError **error)
1341
0
{
1342
0
    g_autoptr(GByteArray) st = NULL;
1343
0
    st = fu_input_stream_read_byte_array(stream, offset, 40, NULL, error);
1344
0
    if (st == NULL) {
1345
0
        g_prefix_error(error, "FuStructPeCoffSection failed read of 0x%x: ", (guint) 40);
1346
0
        return NULL;
1347
0
    }
1348
0
    if (st->len != 40) {
1349
0
        g_set_error(error,
1350
0
                    FWUPD_ERROR,
1351
0
                    FWUPD_ERROR_INVALID_DATA,
1352
0
                    "FuStructPeCoffSection requested 0x%x and got 0x%x",
1353
0
                    (guint) 40,
1354
0
                    (guint) st->len);
1355
0
        return NULL;
1356
0
    }
1357
0
    if (!fu_struct_pe_coff_section_parse_internal(st, error))
1358
0
        return NULL;
1359
0
    return g_steal_pointer(&st);
1360
0
}