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.92k | { |
93 | 3.92k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_NONE) |
94 | 0 | return "none"; |
95 | 3.92k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_LEGACY) |
96 | 2.46k | return "legacy"; |
97 | 1.46k | if (val == FU_EFI_LZ77_DECOMPRESSOR_VERSION_TIANO) |
98 | 1.46k | return "tiano"; |
99 | 0 | return NULL; |
100 | 1.46k | } |
101 | | |
102 | | const gchar * |
103 | | fu_efi_section_type_to_string(FuEfiSectionType val) |
104 | 32.1k | { |
105 | 32.1k | if (val == FU_EFI_SECTION_TYPE_COMPRESSION) |
106 | 0 | return "compression"; |
107 | 32.1k | if (val == FU_EFI_SECTION_TYPE_GUID_DEFINED) |
108 | 102 | return "guid-defined"; |
109 | 32.0k | if (val == FU_EFI_SECTION_TYPE_DISPOSABLE) |
110 | 386 | return "disposable"; |
111 | 31.7k | if (val == FU_EFI_SECTION_TYPE_PE32) |
112 | 624 | return "pe32"; |
113 | 31.0k | if (val == FU_EFI_SECTION_TYPE_PIC) |
114 | 770 | return "pic"; |
115 | 30.3k | if (val == FU_EFI_SECTION_TYPE_TE) |
116 | 656 | return "te"; |
117 | 29.6k | if (val == FU_EFI_SECTION_TYPE_DXE_DEPEX) |
118 | 317 | return "dxe-depex"; |
119 | 29.3k | if (val == FU_EFI_SECTION_TYPE_VERSION) |
120 | 0 | return "version"; |
121 | 29.3k | if (val == FU_EFI_SECTION_TYPE_USER_INTERFACE) |
122 | 0 | return "user-interface"; |
123 | 29.3k | if (val == FU_EFI_SECTION_TYPE_COMPATIBILITY16) |
124 | 2.48k | return "compatibility16"; |
125 | 26.8k | if (val == FU_EFI_SECTION_TYPE_VOLUME_IMAGE) |
126 | 0 | return "volume-image"; |
127 | 26.8k | if (val == FU_EFI_SECTION_TYPE_FREEFORM_SUBTYPE_GUID) |
128 | 0 | return "freeform-subtype-guid"; |
129 | 26.8k | if (val == FU_EFI_SECTION_TYPE_RAW) |
130 | 7.40k | return "raw"; |
131 | 19.4k | if (val == FU_EFI_SECTION_TYPE_PEI_DEPEX) |
132 | 1.19k | return "pei-depex"; |
133 | 18.2k | if (val == FU_EFI_SECTION_TYPE_MM_DEPEX) |
134 | 332 | return "mm-depex"; |
135 | 17.9k | if (val == FU_EFI_SECTION_TYPE_PHOENIX_SECTION_POSTCODE) |
136 | 2.01k | return "phoenix-section-postcode"; |
137 | 15.9k | if (val == FU_EFI_SECTION_TYPE_INSYDE_SECTION_POSTCODE) |
138 | 283 | return "insyde-section-postcode"; |
139 | 15.6k | return NULL; |
140 | 15.9k | } |
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 | 16 | { |
286 | 16 | if (val == FU_EFI_VARIABLE_STORE_STATE_UNSET) |
287 | 2 | 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 | 43 | { |
309 | 43 | if (val == FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) |
310 | 0 | return "formatted"; |
311 | 43 | return NULL; |
312 | 43 | } |
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 | 40.6k | { |
435 | 40.6k | g_return_if_fail(st != NULL); |
436 | 40.6k | if (st->refcount == 0) { |
437 | 0 | g_critical("FuStructEfiFile refcount already zero"); |
438 | 0 | return; |
439 | 0 | } |
440 | 40.6k | if (--st->refcount > 0) |
441 | 0 | return; |
442 | 40.6k | if (st->buf != NULL) |
443 | 32.7k | g_byte_array_unref(st->buf); |
444 | 40.6k | g_free(st); |
445 | 40.6k | } |
446 | | static FuStructEfiFile * |
447 | | fu_struct_efi_file_new_internal(void) |
448 | 40.4k | { |
449 | 40.4k | FuStructEfiFile *st = g_new0(FuStructEfiFile, 1); |
450 | 40.4k | st->refcount = 1; |
451 | 40.4k | return st; |
452 | 40.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 | 32.0k | { |
461 | 32.0k | g_return_val_if_fail(st != NULL, NULL); |
462 | 32.0k | return (const fwupd_guid_t *) (st->buf->data + 0); |
463 | 32.0k | } |
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 | 32.1k | { |
470 | 32.1k | g_return_val_if_fail(st != NULL, 0x0); |
471 | 32.1k | return st->buf->data[16]; |
472 | 32.1k | } |
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 | 804 | { |
479 | 804 | g_return_val_if_fail(st != NULL, 0x0); |
480 | 804 | return st->buf->data[17]; |
481 | 804 | } |
482 | | /** |
483 | | * fu_struct_efi_file_get_type: (skip): |
484 | | **/ |
485 | | FuEfiFileType |
486 | | fu_struct_efi_file_get_type(const FuStructEfiFile *st) |
487 | 32.0k | { |
488 | 32.0k | g_return_val_if_fail(st != NULL, 0x0); |
489 | 32.0k | return st->buf->data[18]; |
490 | 32.0k | } |
491 | | /** |
492 | | * fu_struct_efi_file_get_attrs: (skip): |
493 | | **/ |
494 | | guint8 |
495 | | fu_struct_efi_file_get_attrs(const FuStructEfiFile *st) |
496 | 32.0k | { |
497 | 32.0k | g_return_val_if_fail(st != NULL, 0x0); |
498 | 32.0k | return st->buf->data[19]; |
499 | 32.0k | } |
500 | | /** |
501 | | * fu_struct_efi_file_get_size: (skip): |
502 | | **/ |
503 | | guint32 |
504 | | fu_struct_efi_file_get_size(const FuStructEfiFile *st) |
505 | 32.1k | { |
506 | 32.1k | g_return_val_if_fail(st != NULL, 0x0); |
507 | 32.1k | return fu_memread_uint24(st->buf->data + 20, G_LITTLE_ENDIAN); |
508 | 32.1k | } |
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 | 7.92k | { |
526 | 7.92k | g_return_if_fail(st != NULL); |
527 | 7.92k | g_return_if_fail(value != NULL); |
528 | 7.92k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
529 | 7.92k | } |
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 | 15.8k | { |
536 | 15.8k | g_return_if_fail(st != NULL); |
537 | 15.8k | st->buf->data[16] = value; |
538 | 15.8k | } |
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 | 7.92k | { |
545 | 7.92k | g_return_if_fail(st != NULL); |
546 | 7.92k | st->buf->data[17] = value; |
547 | 7.92k | } |
548 | | /** |
549 | | * fu_struct_efi_file_set_type: (skip): |
550 | | **/ |
551 | | void |
552 | | fu_struct_efi_file_set_type(FuStructEfiFile *st, FuEfiFileType value) |
553 | 7.92k | { |
554 | 7.92k | g_return_if_fail(st != NULL); |
555 | 7.92k | st->buf->data[18] = value; |
556 | 7.92k | } |
557 | | /** |
558 | | * fu_struct_efi_file_set_attrs: (skip): |
559 | | **/ |
560 | | void |
561 | | fu_struct_efi_file_set_attrs(FuStructEfiFile *st, guint8 value) |
562 | 7.92k | { |
563 | 7.92k | g_return_if_fail(st != NULL); |
564 | 7.92k | st->buf->data[19] = value; |
565 | 7.92k | } |
566 | | /** |
567 | | * fu_struct_efi_file_set_size: (skip): |
568 | | **/ |
569 | | void |
570 | | fu_struct_efi_file_set_size(FuStructEfiFile *st, guint32 value) |
571 | 7.92k | { |
572 | 7.92k | g_return_if_fail(st != NULL); |
573 | 7.92k | fu_memwrite_uint24(st->buf->data + 20, value, G_LITTLE_ENDIAN); |
574 | 7.92k | } |
575 | | /** |
576 | | * fu_struct_efi_file_set_state: (skip): |
577 | | **/ |
578 | | void |
579 | | fu_struct_efi_file_set_state(FuStructEfiFile *st, guint8 value) |
580 | 8.32k | { |
581 | 8.32k | g_return_if_fail(st != NULL); |
582 | 8.32k | st->buf->data[23] = value; |
583 | 8.32k | } |
584 | | /** |
585 | | * fu_struct_efi_file_new: (skip): |
586 | | **/ |
587 | | FuStructEfiFile * |
588 | | fu_struct_efi_file_new(void) |
589 | 8.32k | { |
590 | 8.32k | FuStructEfiFile *st = fu_struct_efi_file_new_internal(); |
591 | 8.32k | st->buf = g_byte_array_sized_new(24); |
592 | 8.32k | fu_byte_array_set_size(st->buf, 24, 0x0); |
593 | 8.32k | fu_struct_efi_file_set_state(st, 0xF8); |
594 | 8.32k | return st; |
595 | 8.32k | } |
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 | 32.2k | { |
633 | 32.2k | g_return_val_if_fail(st != NULL, FALSE); |
634 | 32.2k | return TRUE; |
635 | 32.2k | } |
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 | 32.0k | { |
657 | 32.0k | 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 | 32.0k | if (!fu_struct_efi_file_validate_internal(st, error)) |
662 | 0 | return FALSE; |
663 | 32.0k | return TRUE; |
664 | 32.0k | } |
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 | 32.1k | { |
671 | 32.1k | g_autoptr(FuStructEfiFile) st = fu_struct_efi_file_new_internal(); |
672 | 32.1k | st->buf = fu_input_stream_read_byte_array(stream, offset, 24, NULL, error); |
673 | 32.1k | 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 | 32.1k | if (st->buf->len != 24) { |
678 | 96 | g_set_error(error, |
679 | 96 | FWUPD_ERROR, |
680 | 96 | FWUPD_ERROR_INVALID_DATA, |
681 | 96 | "FuStructEfiFile requested 0x%x and got 0x%x", |
682 | 96 | (guint) 24, |
683 | 96 | (guint) st->buf->len); |
684 | 96 | return NULL; |
685 | 96 | } |
686 | 32.0k | if (!fu_struct_efi_file_parse_internal(st, error)) |
687 | 0 | return NULL; |
688 | 32.0k | return g_steal_pointer(&st); |
689 | 32.0k | } |
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 | 6 | { |
706 | 6 | g_return_if_fail(st != NULL); |
707 | 6 | if (st->refcount == 0) { |
708 | 0 | g_critical("FuStructEfiFile2 refcount already zero"); |
709 | 0 | return; |
710 | 0 | } |
711 | 6 | if (--st->refcount > 0) |
712 | 0 | return; |
713 | 6 | if (st->buf != NULL) |
714 | 6 | g_byte_array_unref(st->buf); |
715 | 6 | g_free(st); |
716 | 6 | } |
717 | | static FuStructEfiFile2 * |
718 | | fu_struct_efi_file2_new_internal(void) |
719 | 189 | { |
720 | 189 | FuStructEfiFile2 *st = g_new0(FuStructEfiFile2, 1); |
721 | 189 | st->refcount = 1; |
722 | 189 | return st; |
723 | 189 | } |
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 | 183 | { |
732 | 183 | g_return_val_if_fail(st != NULL, 0x0); |
733 | 183 | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
734 | 183 | } |
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 | 183 | { |
754 | 183 | g_return_val_if_fail(st != NULL, FALSE); |
755 | 183 | { |
756 | 183 | GByteArray buf_tmp = { |
757 | 183 | .data = (guint8*) st->buf->data + 0x0, |
758 | 183 | .len = 24, |
759 | 183 | }; |
760 | 183 | FuStructEfiFile st_tmp = { .buf = &buf_tmp }; |
761 | 183 | if (!fu_struct_efi_file_validate_internal(&st_tmp, error)) |
762 | 0 | return FALSE; |
763 | 183 | } |
764 | 183 | return TRUE; |
765 | 183 | } |
766 | | static gboolean |
767 | | fu_struct_efi_file2_parse_internal(FuStructEfiFile2 *st, GError **error) |
768 | 183 | { |
769 | 183 | 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 | 183 | if (!fu_struct_efi_file2_validate_internal(st, error)) |
774 | 0 | return FALSE; |
775 | 183 | return TRUE; |
776 | 183 | } |
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 | 189 | { |
783 | 189 | g_autoptr(FuStructEfiFile2) st = fu_struct_efi_file2_new_internal(); |
784 | 189 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
785 | 189 | 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 | 189 | if (st->buf->len != 32) { |
790 | 6 | g_set_error(error, |
791 | 6 | FWUPD_ERROR, |
792 | 6 | FWUPD_ERROR_INVALID_DATA, |
793 | 6 | "FuStructEfiFile2 requested 0x%x and got 0x%x", |
794 | 6 | (guint) 32, |
795 | 6 | (guint) st->buf->len); |
796 | 6 | return NULL; |
797 | 6 | } |
798 | 183 | if (!fu_struct_efi_file2_parse_internal(st, error)) |
799 | 0 | return NULL; |
800 | 183 | return g_steal_pointer(&st); |
801 | 183 | } |
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.62k | { |
818 | 3.62k | g_return_if_fail(st != NULL); |
819 | 3.62k | if (st->refcount == 0) { |
820 | 0 | g_critical("FuStructEfiSectionCompression refcount already zero"); |
821 | 0 | return; |
822 | 0 | } |
823 | 3.62k | if (--st->refcount > 0) |
824 | 0 | return; |
825 | 3.62k | if (st->buf != NULL) |
826 | 3.61k | g_byte_array_unref(st->buf); |
827 | 3.62k | g_free(st); |
828 | 3.62k | } |
829 | | static FuStructEfiSectionCompression * |
830 | | fu_struct_efi_section_compression_new_internal(void) |
831 | 3.62k | { |
832 | 3.62k | FuStructEfiSectionCompression *st = g_new0(FuStructEfiSectionCompression, 1); |
833 | 3.62k | st->refcount = 1; |
834 | 3.62k | return st; |
835 | 3.62k | } |
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.60k | { |
853 | 3.60k | g_return_val_if_fail(st != NULL, 0x0); |
854 | 3.60k | return st->buf->data[4]; |
855 | 3.60k | } |
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.60k | { |
883 | 3.60k | g_return_val_if_fail(st != NULL, FALSE); |
884 | 3.60k | return TRUE; |
885 | 3.60k | } |
886 | | static gboolean |
887 | | fu_struct_efi_section_compression_parse_internal(FuStructEfiSectionCompression *st, GError **error) |
888 | 3.60k | { |
889 | 3.60k | 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.60k | if (!fu_struct_efi_section_compression_validate_internal(st, error)) |
894 | 0 | return FALSE; |
895 | 3.60k | return TRUE; |
896 | 3.60k | } |
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.62k | { |
903 | 3.62k | g_autoptr(FuStructEfiSectionCompression) st = fu_struct_efi_section_compression_new_internal(); |
904 | 3.62k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
905 | 3.62k | 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.61k | if (st->buf->len != 5) { |
910 | 13 | g_set_error(error, |
911 | 13 | FWUPD_ERROR, |
912 | 13 | FWUPD_ERROR_INVALID_DATA, |
913 | 13 | "FuStructEfiSectionCompression requested 0x%x and got 0x%x", |
914 | 13 | (guint) 5, |
915 | 13 | (guint) st->buf->len); |
916 | 13 | return NULL; |
917 | 13 | } |
918 | 3.60k | if (!fu_struct_efi_section_compression_parse_internal(st, error)) |
919 | 0 | return NULL; |
920 | 3.60k | return g_steal_pointer(&st); |
921 | 3.60k | } |
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.44k | { |
938 | 3.44k | g_return_if_fail(st != NULL); |
939 | 3.44k | if (st->refcount == 0) { |
940 | 0 | g_critical("FuStructEfiLz77DecompressorHeader refcount already zero"); |
941 | 0 | return; |
942 | 0 | } |
943 | 3.44k | if (--st->refcount > 0) |
944 | 0 | return; |
945 | 3.44k | if (st->buf != NULL) |
946 | 3.44k | g_byte_array_unref(st->buf); |
947 | 3.44k | g_free(st); |
948 | 3.44k | } |
949 | | static FuStructEfiLz77DecompressorHeader * |
950 | | fu_struct_efi_lz77_decompressor_header_new_internal(void) |
951 | 3.44k | { |
952 | 3.44k | FuStructEfiLz77DecompressorHeader *st = g_new0(FuStructEfiLz77DecompressorHeader, 1); |
953 | 3.44k | st->refcount = 1; |
954 | 3.44k | return st; |
955 | 3.44k | } |
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.41k | { |
964 | 3.41k | g_return_val_if_fail(st != NULL, 0x0); |
965 | 3.41k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
966 | 3.41k | } |
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.31k | { |
973 | 3.31k | g_return_val_if_fail(st != NULL, 0x0); |
974 | 3.31k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
975 | 3.31k | } |
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.41k | { |
997 | 3.41k | g_return_val_if_fail(st != NULL, FALSE); |
998 | 3.41k | return TRUE; |
999 | 3.41k | } |
1000 | | static gboolean |
1001 | | fu_struct_efi_lz77_decompressor_header_parse_internal(FuStructEfiLz77DecompressorHeader *st, GError **error) |
1002 | 3.41k | { |
1003 | 3.41k | 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.41k | if (!fu_struct_efi_lz77_decompressor_header_validate_internal(st, error)) |
1008 | 0 | return FALSE; |
1009 | 3.41k | return TRUE; |
1010 | 3.41k | } |
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.44k | { |
1017 | 3.44k | g_autoptr(FuStructEfiLz77DecompressorHeader) st = fu_struct_efi_lz77_decompressor_header_new_internal(); |
1018 | 3.44k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1019 | 3.44k | 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.44k | if (st->buf->len != 8) { |
1024 | 26 | g_set_error(error, |
1025 | 26 | FWUPD_ERROR, |
1026 | 26 | FWUPD_ERROR_INVALID_DATA, |
1027 | 26 | "FuStructEfiLz77DecompressorHeader requested 0x%x and got 0x%x", |
1028 | 26 | (guint) 8, |
1029 | 26 | (guint) st->buf->len); |
1030 | 26 | return NULL; |
1031 | 26 | } |
1032 | 3.41k | if (!fu_struct_efi_lz77_decompressor_header_parse_internal(st, error)) |
1033 | 0 | return NULL; |
1034 | 3.41k | return g_steal_pointer(&st); |
1035 | 3.41k | } |
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 | 58.1k | { |
1052 | 58.1k | g_return_if_fail(st != NULL); |
1053 | 58.1k | if (st->refcount == 0) { |
1054 | 0 | g_critical("FuStructEfiSection refcount already zero"); |
1055 | 0 | return; |
1056 | 0 | } |
1057 | 58.1k | if (--st->refcount > 0) |
1058 | 0 | return; |
1059 | 58.1k | if (st->buf != NULL) |
1060 | 48.9k | g_byte_array_unref(st->buf); |
1061 | 58.1k | g_free(st); |
1062 | 58.1k | } |
1063 | | static FuStructEfiSection * |
1064 | | fu_struct_efi_section_new_internal(void) |
1065 | 58.1k | { |
1066 | 58.1k | FuStructEfiSection *st = g_new0(FuStructEfiSection, 1); |
1067 | 58.1k | st->refcount = 1; |
1068 | 58.1k | return st; |
1069 | 58.1k | } |
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 | 95.7k | { |
1078 | 95.7k | g_return_val_if_fail(st != NULL, 0x0); |
1079 | 95.7k | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1080 | 95.7k | } |
1081 | | /** |
1082 | | * fu_struct_efi_section_get_type: (skip): |
1083 | | **/ |
1084 | | FuEfiSectionType |
1085 | | fu_struct_efi_section_get_type(const FuStructEfiSection *st) |
1086 | 47.2k | { |
1087 | 47.2k | g_return_val_if_fail(st != NULL, 0x0); |
1088 | 47.2k | return st->buf->data[3]; |
1089 | 47.2k | } |
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 | 8.96k | { |
1098 | 8.96k | g_return_if_fail(st != NULL); |
1099 | 8.96k | fu_memwrite_uint24(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
1100 | 8.96k | } |
1101 | | /** |
1102 | | * fu_struct_efi_section_set_type: (skip): |
1103 | | **/ |
1104 | | void |
1105 | | fu_struct_efi_section_set_type(FuStructEfiSection *st, FuEfiSectionType value) |
1106 | 8.96k | { |
1107 | 8.96k | g_return_if_fail(st != NULL); |
1108 | 8.96k | st->buf->data[3] = value; |
1109 | 8.96k | } |
1110 | | /** |
1111 | | * fu_struct_efi_section_new: (skip): |
1112 | | **/ |
1113 | | FuStructEfiSection * |
1114 | | fu_struct_efi_section_new(void) |
1115 | 9.31k | { |
1116 | 9.31k | FuStructEfiSection *st = fu_struct_efi_section_new_internal(); |
1117 | 9.31k | st->buf = g_byte_array_sized_new(4); |
1118 | 9.31k | fu_byte_array_set_size(st->buf, 4, 0x0); |
1119 | 9.31k | return st; |
1120 | 9.31k | } |
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 | 48.5k | { |
1146 | 48.5k | g_return_val_if_fail(st != NULL, FALSE); |
1147 | 48.5k | return TRUE; |
1148 | 48.5k | } |
1149 | | static gboolean |
1150 | | fu_struct_efi_section_parse_internal(FuStructEfiSection *st, GError **error) |
1151 | 48.5k | { |
1152 | 48.5k | 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 | 48.5k | if (!fu_struct_efi_section_validate_internal(st, error)) |
1157 | 0 | return FALSE; |
1158 | 48.5k | return TRUE; |
1159 | 48.5k | } |
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 | 48.8k | { |
1166 | 48.8k | g_autoptr(FuStructEfiSection) st = fu_struct_efi_section_new_internal(); |
1167 | 48.8k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
1168 | 48.8k | if (st->buf == NULL) { |
1169 | 222 | g_prefix_error(error, "FuStructEfiSection failed read of 0x%x: ", (guint) 4); |
1170 | 222 | return NULL; |
1171 | 222 | } |
1172 | 48.5k | if (st->buf->len != 4) { |
1173 | 56 | g_set_error(error, |
1174 | 56 | FWUPD_ERROR, |
1175 | 56 | FWUPD_ERROR_INVALID_DATA, |
1176 | 56 | "FuStructEfiSection requested 0x%x and got 0x%x", |
1177 | 56 | (guint) 4, |
1178 | 56 | (guint) st->buf->len); |
1179 | 56 | return NULL; |
1180 | 56 | } |
1181 | 48.5k | if (!fu_struct_efi_section_parse_internal(st, error)) |
1182 | 0 | return NULL; |
1183 | 48.5k | return g_steal_pointer(&st); |
1184 | 48.5k | } |
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.32k | { |
1201 | 1.32k | g_return_if_fail(st != NULL); |
1202 | 1.32k | if (st->refcount == 0) { |
1203 | 0 | g_critical("FuStructEfiSection2 refcount already zero"); |
1204 | 0 | return; |
1205 | 0 | } |
1206 | 1.32k | if (--st->refcount > 0) |
1207 | 0 | return; |
1208 | 1.32k | if (st->buf != NULL) |
1209 | 1.32k | g_byte_array_unref(st->buf); |
1210 | 1.32k | g_free(st); |
1211 | 1.32k | } |
1212 | | static FuStructEfiSection2 * |
1213 | | fu_struct_efi_section2_new_internal(void) |
1214 | 1.32k | { |
1215 | 1.32k | FuStructEfiSection2 *st = g_new0(FuStructEfiSection2, 1); |
1216 | 1.32k | st->refcount = 1; |
1217 | 1.32k | return st; |
1218 | 1.32k | } |
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.29k | { |
1227 | 1.29k | g_return_val_if_fail(st != NULL, 0x0); |
1228 | 1.29k | return fu_memread_uint24(st->buf->data + 0, G_LITTLE_ENDIAN); |
1229 | 1.29k | } |
1230 | | /** |
1231 | | * fu_struct_efi_section2_get_type: (skip): |
1232 | | **/ |
1233 | | FuEfiSectionType |
1234 | | fu_struct_efi_section2_get_type(const FuStructEfiSection2 *st) |
1235 | 1.29k | { |
1236 | 1.29k | g_return_val_if_fail(st != NULL, 0x0); |
1237 | 1.29k | return st->buf->data[3]; |
1238 | 1.29k | } |
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.29k | { |
1245 | 1.29k | g_return_val_if_fail(st != NULL, 0x0); |
1246 | 1.29k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
1247 | 1.29k | } |
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.29k | { |
1275 | 1.29k | g_return_val_if_fail(st != NULL, FALSE); |
1276 | 1.29k | 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.29k | return TRUE; |
1287 | 1.29k | } |
1288 | | static gboolean |
1289 | | fu_struct_efi_section2_parse_internal(FuStructEfiSection2 *st, GError **error) |
1290 | 1.29k | { |
1291 | 1.29k | 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.29k | if (!fu_struct_efi_section2_validate_internal(st, error)) |
1296 | 0 | return FALSE; |
1297 | 1.29k | return TRUE; |
1298 | 1.29k | } |
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.32k | { |
1305 | 1.32k | g_autoptr(FuStructEfiSection2) st = fu_struct_efi_section2_new_internal(); |
1306 | 1.32k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
1307 | 1.32k | 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.32k | if (st->buf->len != 8) { |
1312 | 21 | g_set_error(error, |
1313 | 21 | FWUPD_ERROR, |
1314 | 21 | FWUPD_ERROR_INVALID_DATA, |
1315 | 21 | "FuStructEfiSection2 requested 0x%x and got 0x%x", |
1316 | 21 | (guint) 8, |
1317 | 21 | (guint) st->buf->len); |
1318 | 21 | return NULL; |
1319 | 21 | } |
1320 | 1.29k | if (!fu_struct_efi_section2_parse_internal(st, error)) |
1321 | 0 | return NULL; |
1322 | 1.29k | return g_steal_pointer(&st); |
1323 | 1.29k | } |
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 | 346 | { |
1340 | 346 | g_return_if_fail(st != NULL); |
1341 | 346 | if (st->refcount == 0) { |
1342 | 0 | g_critical("FuStructEfiSectionFreeformSubtypeGuid refcount already zero"); |
1343 | 0 | return; |
1344 | 0 | } |
1345 | 346 | if (--st->refcount > 0) |
1346 | 0 | return; |
1347 | 346 | if (st->buf != NULL) |
1348 | 344 | g_byte_array_unref(st->buf); |
1349 | 346 | g_free(st); |
1350 | 346 | } |
1351 | | static FuStructEfiSectionFreeformSubtypeGuid * |
1352 | | fu_struct_efi_section_freeform_subtype_guid_new_internal(void) |
1353 | 346 | { |
1354 | 346 | FuStructEfiSectionFreeformSubtypeGuid *st = g_new0(FuStructEfiSectionFreeformSubtypeGuid, 1); |
1355 | 346 | st->refcount = 1; |
1356 | 346 | return st; |
1357 | 346 | } |
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 | 327 | { |
1366 | 327 | g_return_val_if_fail(st != NULL, NULL); |
1367 | 327 | return (const fwupd_guid_t *) (st->buf->data + 0); |
1368 | 327 | } |
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 | 327 | { |
1390 | 327 | g_return_val_if_fail(st != NULL, FALSE); |
1391 | 327 | return TRUE; |
1392 | 327 | } |
1393 | | static gboolean |
1394 | | fu_struct_efi_section_freeform_subtype_guid_parse_internal(FuStructEfiSectionFreeformSubtypeGuid *st, GError **error) |
1395 | 327 | { |
1396 | 327 | 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 | 327 | if (!fu_struct_efi_section_freeform_subtype_guid_validate_internal(st, error)) |
1401 | 0 | return FALSE; |
1402 | 327 | return TRUE; |
1403 | 327 | } |
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 | 346 | { |
1410 | 346 | g_autoptr(FuStructEfiSectionFreeformSubtypeGuid) st = fu_struct_efi_section_freeform_subtype_guid_new_internal(); |
1411 | 346 | st->buf = fu_input_stream_read_byte_array(stream, offset, 16, NULL, error); |
1412 | 346 | 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 | 344 | if (st->buf->len != 16) { |
1417 | 17 | g_set_error(error, |
1418 | 17 | FWUPD_ERROR, |
1419 | 17 | FWUPD_ERROR_INVALID_DATA, |
1420 | 17 | "FuStructEfiSectionFreeformSubtypeGuid requested 0x%x and got 0x%x", |
1421 | 17 | (guint) 16, |
1422 | 17 | (guint) st->buf->len); |
1423 | 17 | return NULL; |
1424 | 17 | } |
1425 | 327 | if (!fu_struct_efi_section_freeform_subtype_guid_parse_internal(st, error)) |
1426 | 0 | return NULL; |
1427 | 327 | return g_steal_pointer(&st); |
1428 | 327 | } |
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 | 10.0k | { |
1445 | 10.0k | g_return_if_fail(st != NULL); |
1446 | 10.0k | if (st->refcount == 0) { |
1447 | 0 | g_critical("FuStructEfiSectionGuidDefined refcount already zero"); |
1448 | 0 | return; |
1449 | 0 | } |
1450 | 10.0k | if (--st->refcount > 0) |
1451 | 0 | return; |
1452 | 10.0k | if (st->buf != NULL) |
1453 | 10.0k | g_byte_array_unref(st->buf); |
1454 | 10.0k | g_free(st); |
1455 | 10.0k | } |
1456 | | static FuStructEfiSectionGuidDefined * |
1457 | | fu_struct_efi_section_guid_defined_new_internal(void) |
1458 | 10.0k | { |
1459 | 10.0k | FuStructEfiSectionGuidDefined *st = g_new0(FuStructEfiSectionGuidDefined, 1); |
1460 | 10.0k | st->refcount = 1; |
1461 | 10.0k | return st; |
1462 | 10.0k | } |
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.89k | { |
1471 | 7.89k | g_return_val_if_fail(st != NULL, NULL); |
1472 | 7.89k | return (const fwupd_guid_t *) (st->buf->data + 0); |
1473 | 7.89k | } |
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 | 15.7k | { |
1480 | 15.7k | g_return_val_if_fail(st != NULL, 0x0); |
1481 | 15.7k | return fu_memread_uint16(st->buf->data + 16, G_LITTLE_ENDIAN); |
1482 | 15.7k | } |
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 | 2.09k | { |
1500 | 2.09k | g_return_if_fail(st != NULL); |
1501 | 2.09k | g_return_if_fail(value != NULL); |
1502 | 2.09k | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
1503 | 2.09k | } |
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 | 2.09k | { |
1510 | 2.09k | g_return_if_fail(st != NULL); |
1511 | 2.09k | fu_memwrite_uint16(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
1512 | 2.09k | } |
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 | 2.09k | { |
1528 | 2.09k | FuStructEfiSectionGuidDefined *st = fu_struct_efi_section_guid_defined_new_internal(); |
1529 | 2.09k | st->buf = g_byte_array_sized_new(20); |
1530 | 2.09k | fu_byte_array_set_size(st->buf, 20, 0x0); |
1531 | 2.09k | return st; |
1532 | 2.09k | } |
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.89k | { |
1556 | 7.89k | g_return_val_if_fail(st != NULL, FALSE); |
1557 | 7.89k | return TRUE; |
1558 | 7.89k | } |
1559 | | static gboolean |
1560 | | fu_struct_efi_section_guid_defined_parse_internal(FuStructEfiSectionGuidDefined *st, GError **error) |
1561 | 7.89k | { |
1562 | 7.89k | 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.89k | if (!fu_struct_efi_section_guid_defined_validate_internal(st, error)) |
1567 | 0 | return FALSE; |
1568 | 7.89k | return TRUE; |
1569 | 7.89k | } |
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.91k | { |
1576 | 7.91k | g_autoptr(FuStructEfiSectionGuidDefined) st = fu_struct_efi_section_guid_defined_new_internal(); |
1577 | 7.91k | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
1578 | 7.91k | 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.91k | 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.89k | if (!fu_struct_efi_section_guid_defined_parse_internal(st, error)) |
1592 | 0 | return NULL; |
1593 | 7.89k | return g_steal_pointer(&st); |
1594 | 7.89k | } |
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 | 157k | { |
1611 | 157k | g_return_if_fail(st != NULL); |
1612 | 157k | if (st->refcount == 0) { |
1613 | 0 | g_critical("FuStructEfiVolume refcount already zero"); |
1614 | 0 | return; |
1615 | 0 | } |
1616 | 157k | if (--st->refcount > 0) |
1617 | 0 | return; |
1618 | 157k | if (st->buf != NULL) |
1619 | 153k | g_byte_array_unref(st->buf); |
1620 | 157k | g_free(st); |
1621 | 157k | } |
1622 | | static FuStructEfiVolume * |
1623 | | fu_struct_efi_volume_new_internal(void) |
1624 | 157k | { |
1625 | 157k | FuStructEfiVolume *st = g_new0(FuStructEfiVolume, 1); |
1626 | 157k | st->refcount = 1; |
1627 | 157k | return st; |
1628 | 157k | } |
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 | 11.1k | { |
1646 | 11.1k | g_return_val_if_fail(st != NULL, NULL); |
1647 | 11.1k | return (const fwupd_guid_t *) (st->buf->data + 16); |
1648 | 11.1k | } |
1649 | | /** |
1650 | | * fu_struct_efi_volume_get_length: (skip): |
1651 | | **/ |
1652 | | guint64 |
1653 | | fu_struct_efi_volume_get_length(const FuStructEfiVolume *st) |
1654 | 11.1k | { |
1655 | 11.1k | g_return_val_if_fail(st != NULL, 0x0); |
1656 | 11.1k | return fu_memread_uint64(st->buf->data + 32, G_LITTLE_ENDIAN); |
1657 | 11.1k | } |
1658 | | /** |
1659 | | * fu_struct_efi_volume_get_signature: (skip): |
1660 | | **/ |
1661 | | static guint32 |
1662 | | fu_struct_efi_volume_get_signature(const FuStructEfiVolume *st) |
1663 | 270k | { |
1664 | 270k | g_return_val_if_fail(st != NULL, 0x0); |
1665 | 270k | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
1666 | 270k | } |
1667 | | /** |
1668 | | * fu_struct_efi_volume_get_attrs: (skip): |
1669 | | **/ |
1670 | | guint32 |
1671 | | fu_struct_efi_volume_get_attrs(const FuStructEfiVolume *st) |
1672 | 8.96k | { |
1673 | 8.96k | g_return_val_if_fail(st != NULL, 0x0); |
1674 | 8.96k | return fu_memread_uint32(st->buf->data + 44, G_LITTLE_ENDIAN); |
1675 | 8.96k | } |
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.87k | { |
1682 | 8.87k | g_return_val_if_fail(st != NULL, 0x0); |
1683 | 8.87k | return fu_memread_uint16(st->buf->data + 48, G_LITTLE_ENDIAN); |
1684 | 8.87k | } |
1685 | | /** |
1686 | | * fu_struct_efi_volume_get_checksum: (skip): |
1687 | | **/ |
1688 | | guint16 |
1689 | | fu_struct_efi_volume_get_checksum(const FuStructEfiVolume *st) |
1690 | 432 | { |
1691 | 432 | g_return_val_if_fail(st != NULL, 0x0); |
1692 | 432 | return fu_memread_uint16(st->buf->data + 50, G_LITTLE_ENDIAN); |
1693 | 432 | } |
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 | 8.50k | { |
1700 | 8.50k | g_return_val_if_fail(st != NULL, 0x0); |
1701 | 8.50k | return fu_memread_uint16(st->buf->data + 52, G_LITTLE_ENDIAN); |
1702 | 8.50k | } |
1703 | | /** |
1704 | | * fu_struct_efi_volume_get_revision: (skip): |
1705 | | **/ |
1706 | | static guint8 |
1707 | | fu_struct_efi_volume_get_revision(const FuStructEfiVolume *st) |
1708 | 22.6k | { |
1709 | 22.6k | g_return_val_if_fail(st != NULL, 0x0); |
1710 | 22.6k | return st->buf->data[55]; |
1711 | 22.6k | } |
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 | 3.49k | { |
1730 | 3.49k | g_return_if_fail(st != NULL); |
1731 | 3.49k | g_return_if_fail(value != NULL); |
1732 | 3.49k | memcpy(st->buf->data + 16, value, sizeof(*value)); /* nocheck:blocked */ |
1733 | 3.49k | } |
1734 | | /** |
1735 | | * fu_struct_efi_volume_set_length: (skip): |
1736 | | **/ |
1737 | | void |
1738 | | fu_struct_efi_volume_set_length(FuStructEfiVolume *st, guint64 value) |
1739 | 3.49k | { |
1740 | 3.49k | g_return_if_fail(st != NULL); |
1741 | 3.49k | fu_memwrite_uint64(st->buf->data + 32, value, G_LITTLE_ENDIAN); |
1742 | 3.49k | } |
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.72k | { |
1749 | 3.72k | g_return_if_fail(st != NULL); |
1750 | 3.72k | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
1751 | 3.72k | } |
1752 | | /** |
1753 | | * fu_struct_efi_volume_set_attrs: (skip): |
1754 | | **/ |
1755 | | void |
1756 | | fu_struct_efi_volume_set_attrs(FuStructEfiVolume *st, guint32 value) |
1757 | 3.49k | { |
1758 | 3.49k | g_return_if_fail(st != NULL); |
1759 | 3.49k | fu_memwrite_uint32(st->buf->data + 44, value, G_LITTLE_ENDIAN); |
1760 | 3.49k | } |
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 | 3.49k | { |
1767 | 3.49k | g_return_if_fail(st != NULL); |
1768 | 3.49k | fu_memwrite_uint16(st->buf->data + 48, value, G_LITTLE_ENDIAN); |
1769 | 3.49k | } |
1770 | | /** |
1771 | | * fu_struct_efi_volume_set_checksum: (skip): |
1772 | | **/ |
1773 | | void |
1774 | | fu_struct_efi_volume_set_checksum(FuStructEfiVolume *st, guint16 value) |
1775 | 3.49k | { |
1776 | 3.49k | g_return_if_fail(st != NULL); |
1777 | 3.49k | fu_memwrite_uint16(st->buf->data + 50, value, G_LITTLE_ENDIAN); |
1778 | 3.49k | } |
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.72k | { |
1794 | 3.72k | g_return_if_fail(st != NULL); |
1795 | 3.72k | st->buf->data[55] = value; |
1796 | 3.72k | } |
1797 | | /** |
1798 | | * fu_struct_efi_volume_new: (skip): |
1799 | | **/ |
1800 | | FuStructEfiVolume * |
1801 | | fu_struct_efi_volume_new(void) |
1802 | 3.72k | { |
1803 | 3.72k | FuStructEfiVolume *st = fu_struct_efi_volume_new_internal(); |
1804 | 3.72k | st->buf = g_byte_array_sized_new(56); |
1805 | 3.72k | fu_byte_array_set_size(st->buf, 56, 0x0); |
1806 | 3.72k | fu_struct_efi_volume_set_signature(st, 0x4856465F); |
1807 | 3.72k | fu_struct_efi_volume_set_revision(st, 0x02); |
1808 | 3.72k | return st; |
1809 | 3.72k | } |
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 | 146k | { |
1843 | 146k | g_return_val_if_fail(st != NULL, FALSE); |
1844 | 146k | if (fu_struct_efi_volume_get_signature(st) != 0x4856465F) { |
1845 | 123k | g_set_error(error, |
1846 | 123k | FWUPD_ERROR, |
1847 | 123k | FWUPD_ERROR_INVALID_DATA, |
1848 | 123k | "constant FuStructEfiVolume.signature was not valid, " |
1849 | 123k | "expected 0x%x and got 0x%x", |
1850 | 123k | (guint) 0x4856465F, |
1851 | 123k | (guint) fu_struct_efi_volume_get_signature(st)); |
1852 | 123k | return FALSE; |
1853 | 123k | } |
1854 | 22.6k | if (fu_struct_efi_volume_get_revision(st) != 0x02) { |
1855 | 305 | g_set_error_literal(error, |
1856 | 305 | FWUPD_ERROR, |
1857 | 305 | FWUPD_ERROR_INVALID_DATA, |
1858 | 305 | "constant FuStructEfiVolume.revision was not valid"); |
1859 | 305 | return FALSE; |
1860 | 305 | } |
1861 | 22.3k | return TRUE; |
1862 | 22.6k | } |
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 | 142k | { |
1869 | 142k | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
1870 | 142k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
1871 | 142k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
1872 | 142k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
1873 | 142k | 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 | 142k | if (st->buf->len != 56) { |
1878 | 6.92k | g_set_error(error, |
1879 | 6.92k | FWUPD_ERROR, |
1880 | 6.92k | FWUPD_ERROR_INVALID_DATA, |
1881 | 6.92k | "FuStructEfiVolume requested 0x%x and got 0x%x", |
1882 | 6.92k | (guint) 56, |
1883 | 6.92k | (guint) st->buf->len); |
1884 | 6.92k | return FALSE; |
1885 | 6.92k | } |
1886 | 135k | return fu_struct_efi_volume_validate_internal(st, error); |
1887 | 142k | } |
1888 | | static gboolean |
1889 | | fu_struct_efi_volume_parse_internal(FuStructEfiVolume *st, GError **error) |
1890 | 11.1k | { |
1891 | 11.1k | 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 | 11.1k | if (!fu_struct_efi_volume_validate_internal(st, error)) |
1896 | 0 | return FALSE; |
1897 | 11.1k | return TRUE; |
1898 | 11.1k | } |
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 | 11.1k | { |
1905 | 11.1k | g_autoptr(FuStructEfiVolume) st = fu_struct_efi_volume_new_internal(); |
1906 | 11.1k | st->buf = fu_input_stream_read_byte_array(stream, offset, 56, NULL, error); |
1907 | 11.1k | 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 | 11.1k | 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 | 11.1k | if (!fu_struct_efi_volume_parse_internal(st, error)) |
1921 | 0 | return NULL; |
1922 | 11.1k | return g_steal_pointer(&st); |
1923 | 11.1k | } |
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 | 265 | { |
1940 | 265 | g_return_if_fail(st != NULL); |
1941 | 265 | if (st->refcount == 0) { |
1942 | 0 | g_critical("FuStructEfiVolumeExtHeader refcount already zero"); |
1943 | 0 | return; |
1944 | 0 | } |
1945 | 265 | if (--st->refcount > 0) |
1946 | 0 | return; |
1947 | 265 | if (st->buf != NULL) |
1948 | 224 | g_byte_array_unref(st->buf); |
1949 | 265 | g_free(st); |
1950 | 265 | } |
1951 | | static FuStructEfiVolumeExtHeader * |
1952 | | fu_struct_efi_volume_ext_header_new_internal(void) |
1953 | 265 | { |
1954 | 265 | FuStructEfiVolumeExtHeader *st = g_new0(FuStructEfiVolumeExtHeader, 1); |
1955 | 265 | st->refcount = 1; |
1956 | 265 | return st; |
1957 | 265 | } |
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 | 217 | { |
1975 | 217 | g_return_val_if_fail(st != NULL, 0x0); |
1976 | 217 | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
1977 | 217 | } |
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 | 217 | { |
2001 | 217 | g_return_val_if_fail(st != NULL, FALSE); |
2002 | 217 | return TRUE; |
2003 | 217 | } |
2004 | | static gboolean |
2005 | | fu_struct_efi_volume_ext_header_parse_internal(FuStructEfiVolumeExtHeader *st, GError **error) |
2006 | 217 | { |
2007 | 217 | 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 | 217 | if (!fu_struct_efi_volume_ext_header_validate_internal(st, error)) |
2012 | 0 | return FALSE; |
2013 | 217 | return TRUE; |
2014 | 217 | } |
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 | 265 | { |
2021 | 265 | g_autoptr(FuStructEfiVolumeExtHeader) st = fu_struct_efi_volume_ext_header_new_internal(); |
2022 | 265 | st->buf = fu_input_stream_read_byte_array(stream, offset, 20, NULL, error); |
2023 | 265 | 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 | 224 | if (st->buf->len != 20) { |
2028 | 7 | g_set_error(error, |
2029 | 7 | FWUPD_ERROR, |
2030 | 7 | FWUPD_ERROR_INVALID_DATA, |
2031 | 7 | "FuStructEfiVolumeExtHeader requested 0x%x and got 0x%x", |
2032 | 7 | (guint) 20, |
2033 | 7 | (guint) st->buf->len); |
2034 | 7 | return NULL; |
2035 | 7 | } |
2036 | 217 | if (!fu_struct_efi_volume_ext_header_parse_internal(st, error)) |
2037 | 0 | return NULL; |
2038 | 217 | return g_steal_pointer(&st); |
2039 | 217 | } |
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.86k | { |
2056 | 1.86k | g_return_if_fail(st != NULL); |
2057 | 1.86k | if (st->refcount == 0) { |
2058 | 0 | g_critical("FuStructEfiVolumeExtEntry refcount already zero"); |
2059 | 0 | return; |
2060 | 0 | } |
2061 | 1.86k | if (--st->refcount > 0) |
2062 | 0 | return; |
2063 | 1.86k | if (st->buf != NULL) |
2064 | 1.79k | g_byte_array_unref(st->buf); |
2065 | 1.86k | g_free(st); |
2066 | 1.86k | } |
2067 | | static FuStructEfiVolumeExtEntry * |
2068 | | fu_struct_efi_volume_ext_entry_new_internal(void) |
2069 | 1.86k | { |
2070 | 1.86k | FuStructEfiVolumeExtEntry *st = g_new0(FuStructEfiVolumeExtEntry, 1); |
2071 | 1.86k | st->refcount = 1; |
2072 | 1.86k | return st; |
2073 | 1.86k | } |
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 | 5.28k | { |
2082 | 5.28k | g_return_val_if_fail(st != NULL, 0x0); |
2083 | 5.28k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
2084 | 5.28k | } |
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.77k | { |
2121 | 1.77k | g_return_val_if_fail(st != NULL, FALSE); |
2122 | 1.77k | return TRUE; |
2123 | 1.77k | } |
2124 | | static gboolean |
2125 | | fu_struct_efi_volume_ext_entry_parse_internal(FuStructEfiVolumeExtEntry *st, GError **error) |
2126 | 1.77k | { |
2127 | 1.77k | 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.77k | if (!fu_struct_efi_volume_ext_entry_validate_internal(st, error)) |
2132 | 0 | return FALSE; |
2133 | 1.77k | return TRUE; |
2134 | 1.77k | } |
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.86k | { |
2141 | 1.86k | g_autoptr(FuStructEfiVolumeExtEntry) st = fu_struct_efi_volume_ext_entry_new_internal(); |
2142 | 1.86k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
2143 | 1.86k | if (st->buf == NULL) { |
2144 | 68 | g_prefix_error(error, "FuStructEfiVolumeExtEntry failed read of 0x%x: ", (guint) 4); |
2145 | 68 | return NULL; |
2146 | 68 | } |
2147 | 1.79k | if (st->buf->len != 4) { |
2148 | 20 | g_set_error(error, |
2149 | 20 | FWUPD_ERROR, |
2150 | 20 | FWUPD_ERROR_INVALID_DATA, |
2151 | 20 | "FuStructEfiVolumeExtEntry requested 0x%x and got 0x%x", |
2152 | 20 | (guint) 4, |
2153 | 20 | (guint) st->buf->len); |
2154 | 20 | return NULL; |
2155 | 20 | } |
2156 | 1.77k | if (!fu_struct_efi_volume_ext_entry_parse_internal(st, error)) |
2157 | 0 | return NULL; |
2158 | 1.77k | return g_steal_pointer(&st); |
2159 | 1.77k | } |
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 | 486k | { |
2176 | 486k | g_return_if_fail(st != NULL); |
2177 | 486k | if (st->refcount == 0) { |
2178 | 0 | g_critical("FuStructEfiVolumeBlockMap refcount already zero"); |
2179 | 0 | return; |
2180 | 0 | } |
2181 | 486k | if (--st->refcount > 0) |
2182 | 0 | return; |
2183 | 486k | if (st->buf != NULL) |
2184 | 486k | g_byte_array_unref(st->buf); |
2185 | 486k | g_free(st); |
2186 | 486k | } |
2187 | | static FuStructEfiVolumeBlockMap * |
2188 | | fu_struct_efi_volume_block_map_new_internal(void) |
2189 | 486k | { |
2190 | 486k | FuStructEfiVolumeBlockMap *st = g_new0(FuStructEfiVolumeBlockMap, 1); |
2191 | 486k | st->refcount = 1; |
2192 | 486k | return st; |
2193 | 486k | } |
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 | 482k | { |
2202 | 482k | g_return_val_if_fail(st != NULL, 0x0); |
2203 | 482k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
2204 | 482k | } |
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 | 482k | { |
2211 | 482k | g_return_val_if_fail(st != NULL, 0x0); |
2212 | 482k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
2213 | 482k | } |
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 | 6.99k | { |
2222 | 6.99k | g_return_if_fail(st != NULL); |
2223 | 6.99k | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
2224 | 6.99k | } |
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 | 6.99k | { |
2231 | 6.99k | g_return_if_fail(st != NULL); |
2232 | 6.99k | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
2233 | 6.99k | } |
2234 | | /** |
2235 | | * fu_struct_efi_volume_block_map_new: (skip): |
2236 | | **/ |
2237 | | FuStructEfiVolumeBlockMap * |
2238 | | fu_struct_efi_volume_block_map_new(void) |
2239 | 3.72k | { |
2240 | 3.72k | FuStructEfiVolumeBlockMap *st = fu_struct_efi_volume_block_map_new_internal(); |
2241 | 3.72k | st->buf = g_byte_array_sized_new(8); |
2242 | 3.72k | fu_byte_array_set_size(st->buf, 8, 0x0); |
2243 | 3.72k | return st; |
2244 | 3.72k | } |
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 | 482k | { |
2264 | 482k | g_return_val_if_fail(st != NULL, FALSE); |
2265 | 482k | return TRUE; |
2266 | 482k | } |
2267 | | static gboolean |
2268 | | fu_struct_efi_volume_block_map_parse_internal(FuStructEfiVolumeBlockMap *st, GError **error) |
2269 | 482k | { |
2270 | 482k | 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 | 482k | if (!fu_struct_efi_volume_block_map_validate_internal(st, error)) |
2275 | 0 | return FALSE; |
2276 | 482k | return TRUE; |
2277 | 482k | } |
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 | 482k | { |
2284 | 482k | g_autoptr(FuStructEfiVolumeBlockMap) st = fu_struct_efi_volume_block_map_new_internal(); |
2285 | 482k | st->buf = fu_input_stream_read_byte_array(stream, offset, 8, NULL, error); |
2286 | 482k | 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 | 482k | if (st->buf->len != 8) { |
2291 | 537 | g_set_error(error, |
2292 | 537 | FWUPD_ERROR, |
2293 | 537 | FWUPD_ERROR_INVALID_DATA, |
2294 | 537 | "FuStructEfiVolumeBlockMap requested 0x%x and got 0x%x", |
2295 | 537 | (guint) 8, |
2296 | 537 | (guint) st->buf->len); |
2297 | 537 | return NULL; |
2298 | 537 | } |
2299 | 482k | if (!fu_struct_efi_volume_block_map_parse_internal(st, error)) |
2300 | 0 | return NULL; |
2301 | 482k | return g_steal_pointer(&st); |
2302 | 482k | } |
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.62k | { |
2319 | 3.62k | g_return_if_fail(st != NULL); |
2320 | 3.62k | if (st->refcount == 0) { |
2321 | 0 | g_critical("FuStructEfiTime refcount already zero"); |
2322 | 0 | return; |
2323 | 0 | } |
2324 | 3.62k | if (--st->refcount > 0) |
2325 | 0 | return; |
2326 | 3.62k | if (st->buf != NULL) |
2327 | 3.62k | g_byte_array_unref(st->buf); |
2328 | 3.62k | g_free(st); |
2329 | 3.62k | } |
2330 | | static FuStructEfiTime * |
2331 | | fu_struct_efi_time_new_internal(void) |
2332 | 3.62k | { |
2333 | 3.62k | FuStructEfiTime *st = g_new0(FuStructEfiTime, 1); |
2334 | 3.62k | st->refcount = 1; |
2335 | 3.62k | return st; |
2336 | 3.62k | } |
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 | 483 | { |
2509 | 483 | FuStructEfiTime *st = fu_struct_efi_time_new_internal(); |
2510 | 483 | st->buf = g_byte_array_sized_new(16); |
2511 | 483 | fu_byte_array_set_size(st->buf, 16, 0x0); |
2512 | 483 | return st; |
2513 | 483 | } |
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.23k | { |
2547 | 3.23k | g_return_val_if_fail(st != NULL, FALSE); |
2548 | 3.23k | return TRUE; |
2549 | 3.23k | } |
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.28k | { |
3159 | 3.28k | g_return_if_fail(st != NULL); |
3160 | 3.28k | if (st->refcount == 0) { |
3161 | 0 | g_critical("FuStructEfiLoadOption refcount already zero"); |
3162 | 0 | return; |
3163 | 0 | } |
3164 | 3.28k | if (--st->refcount > 0) |
3165 | 0 | return; |
3166 | 3.28k | if (st->buf != NULL) |
3167 | 2.50k | g_byte_array_unref(st->buf); |
3168 | 3.28k | g_free(st); |
3169 | 3.28k | } |
3170 | | static FuStructEfiLoadOption * |
3171 | | fu_struct_efi_load_option_new_internal(void) |
3172 | 3.28k | { |
3173 | 3.28k | FuStructEfiLoadOption *st = g_new0(FuStructEfiLoadOption, 1); |
3174 | 3.28k | st->refcount = 1; |
3175 | 3.28k | return st; |
3176 | 3.28k | } |
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.09k | { |
3185 | 2.09k | g_return_val_if_fail(st != NULL, 0x0); |
3186 | 2.09k | return fu_memread_uint32(st->buf->data + 0, G_LITTLE_ENDIAN); |
3187 | 2.09k | } |
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.59k | { |
3194 | 1.59k | g_return_val_if_fail(st != NULL, 0x0); |
3195 | 1.59k | return fu_memread_uint16(st->buf->data + 4, G_LITTLE_ENDIAN); |
3196 | 1.59k | } |
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.18k | { |
3205 | 1.18k | g_return_if_fail(st != NULL); |
3206 | 1.18k | fu_memwrite_uint32(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
3207 | 1.18k | } |
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 | 781 | { |
3214 | 781 | g_return_if_fail(st != NULL); |
3215 | 781 | fu_memwrite_uint16(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
3216 | 781 | } |
3217 | | /** |
3218 | | * fu_struct_efi_load_option_new: (skip): |
3219 | | **/ |
3220 | | FuStructEfiLoadOption * |
3221 | | fu_struct_efi_load_option_new(void) |
3222 | 1.18k | { |
3223 | 1.18k | FuStructEfiLoadOption *st = fu_struct_efi_load_option_new_internal(); |
3224 | 1.18k | st->buf = g_byte_array_sized_new(6); |
3225 | 1.18k | fu_byte_array_set_size(st->buf, 6, 0x0); |
3226 | 1.18k | return st; |
3227 | 1.18k | } |
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.09k | { |
3253 | 2.09k | g_return_val_if_fail(st != NULL, FALSE); |
3254 | 2.09k | return TRUE; |
3255 | 2.09k | } |
3256 | | static gboolean |
3257 | | fu_struct_efi_load_option_parse_internal(FuStructEfiLoadOption *st, GError **error) |
3258 | 2.09k | { |
3259 | 2.09k | 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.09k | if (!fu_struct_efi_load_option_validate_internal(st, error)) |
3264 | 0 | return FALSE; |
3265 | 2.09k | return TRUE; |
3266 | 2.09k | } |
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.10k | { |
3273 | 2.10k | g_autoptr(FuStructEfiLoadOption) st = fu_struct_efi_load_option_new_internal(); |
3274 | 2.10k | st->buf = fu_input_stream_read_byte_array(stream, offset, 6, NULL, error); |
3275 | 2.10k | 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.10k | if (st->buf->len != 6) { |
3280 | 8 | g_set_error(error, |
3281 | 8 | FWUPD_ERROR, |
3282 | 8 | FWUPD_ERROR_INVALID_DATA, |
3283 | 8 | "FuStructEfiLoadOption requested 0x%x and got 0x%x", |
3284 | 8 | (guint) 6, |
3285 | 8 | (guint) st->buf->len); |
3286 | 8 | return NULL; |
3287 | 8 | } |
3288 | 2.09k | if (!fu_struct_efi_load_option_parse_internal(st, error)) |
3289 | 0 | return NULL; |
3290 | 2.09k | return g_steal_pointer(&st); |
3291 | 2.09k | } |
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 | 59.5k | { |
3308 | 59.5k | g_return_if_fail(st != NULL); |
3309 | 59.5k | if (st->refcount == 0) { |
3310 | 0 | g_critical("FuStructEfiDevicePath refcount already zero"); |
3311 | 0 | return; |
3312 | 0 | } |
3313 | 59.5k | if (--st->refcount > 0) |
3314 | 0 | return; |
3315 | 59.5k | if (st->buf != NULL) |
3316 | 52.5k | g_byte_array_unref(st->buf); |
3317 | 59.5k | g_free(st); |
3318 | 59.5k | } |
3319 | | static FuStructEfiDevicePath * |
3320 | | fu_struct_efi_device_path_new_internal(void) |
3321 | 59.5k | { |
3322 | 59.5k | FuStructEfiDevicePath *st = g_new0(FuStructEfiDevicePath, 1); |
3323 | 59.5k | st->refcount = 1; |
3324 | 59.5k | return st; |
3325 | 59.5k | } |
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 | 99.3k | { |
3334 | 99.3k | g_return_val_if_fail(st != NULL, 0x0); |
3335 | 99.3k | return st->buf->data[0]; |
3336 | 99.3k | } |
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 | 47.4k | { |
3343 | 47.4k | g_return_val_if_fail(st != NULL, 0x0); |
3344 | 47.4k | return st->buf->data[1]; |
3345 | 47.4k | } |
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 | 51.1k | { |
3352 | 51.1k | g_return_val_if_fail(st != NULL, 0x0); |
3353 | 51.1k | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3354 | 51.1k | } |
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.73k | { |
3363 | 7.73k | g_return_if_fail(st != NULL); |
3364 | 7.73k | st->buf->data[0] = value; |
3365 | 7.73k | } |
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.8k | { |
3372 | 15.8k | g_return_if_fail(st != NULL); |
3373 | 15.8k | st->buf->data[1] = value; |
3374 | 15.8k | } |
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 | 15.0k | { |
3381 | 15.0k | g_return_if_fail(st != NULL); |
3382 | 15.0k | fu_memwrite_uint16(st->buf->data + 2, value, G_LITTLE_ENDIAN); |
3383 | 15.0k | } |
3384 | | /** |
3385 | | * fu_struct_efi_device_path_new: (skip): |
3386 | | **/ |
3387 | | FuStructEfiDevicePath * |
3388 | | fu_struct_efi_device_path_new(void) |
3389 | 8.13k | { |
3390 | 8.13k | FuStructEfiDevicePath *st = fu_struct_efi_device_path_new_internal(); |
3391 | 8.13k | st->buf = g_byte_array_sized_new(4); |
3392 | 8.13k | fu_byte_array_set_size(st->buf, 4, 0x0); |
3393 | 8.13k | fu_struct_efi_device_path_set_subtype(st, 0xFF); |
3394 | 8.13k | fu_struct_efi_device_path_set_length(st, 4); |
3395 | 8.13k | return st; |
3396 | 8.13k | } |
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 | 51.3k | { |
3424 | 51.3k | g_return_val_if_fail(st != NULL, FALSE); |
3425 | 51.3k | return TRUE; |
3426 | 51.3k | } |
3427 | | static gboolean |
3428 | | fu_struct_efi_device_path_parse_internal(FuStructEfiDevicePath *st, GError **error) |
3429 | 51.3k | { |
3430 | 51.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 | 51.3k | if (!fu_struct_efi_device_path_validate_internal(st, error)) |
3435 | 0 | return FALSE; |
3436 | 51.3k | return TRUE; |
3437 | 51.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 | 51.3k | { |
3444 | 51.3k | g_autoptr(FuStructEfiDevicePath) st = fu_struct_efi_device_path_new_internal(); |
3445 | 51.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 4, NULL, error); |
3446 | 51.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 | 51.3k | if (st->buf->len != 4) { |
3451 | 45 | g_set_error(error, |
3452 | 45 | FWUPD_ERROR, |
3453 | 45 | FWUPD_ERROR_INVALID_DATA, |
3454 | 45 | "FuStructEfiDevicePath requested 0x%x and got 0x%x", |
3455 | 45 | (guint) 4, |
3456 | 45 | (guint) st->buf->len); |
3457 | 45 | return NULL; |
3458 | 45 | } |
3459 | 51.3k | if (!fu_struct_efi_device_path_parse_internal(st, error)) |
3460 | 0 | return NULL; |
3461 | 51.3k | return g_steal_pointer(&st); |
3462 | 51.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.03k | { |
3479 | 1.03k | g_return_if_fail(st != NULL); |
3480 | 1.03k | if (st->refcount == 0) { |
3481 | 0 | g_critical("FuStructEfiHardDriveDevicePath refcount already zero"); |
3482 | 0 | return; |
3483 | 0 | } |
3484 | 1.03k | if (--st->refcount > 0) |
3485 | 0 | return; |
3486 | 1.03k | if (st->buf != NULL) |
3487 | 650 | g_byte_array_unref(st->buf); |
3488 | 1.03k | g_free(st); |
3489 | 1.03k | } |
3490 | | static FuStructEfiHardDriveDevicePath * |
3491 | | fu_struct_efi_hard_drive_device_path_new_internal(void) |
3492 | 1.03k | { |
3493 | 1.03k | FuStructEfiHardDriveDevicePath *st = g_new0(FuStructEfiHardDriveDevicePath, 1); |
3494 | 1.03k | st->refcount = 1; |
3495 | 1.03k | return st; |
3496 | 1.03k | } |
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 | 636 | { |
3505 | 636 | g_return_val_if_fail(st != NULL, 0x0); |
3506 | 636 | return st->buf->data[0]; |
3507 | 636 | } |
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 | 656 | { |
3523 | 656 | g_return_val_if_fail(st != NULL, 0x0); |
3524 | 656 | return fu_memread_uint16(st->buf->data + 2, G_LITTLE_ENDIAN); |
3525 | 656 | } |
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 | 636 | { |
3729 | 636 | g_return_val_if_fail(st != NULL, FALSE); |
3730 | 636 | 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 | 636 | if (fu_struct_efi_hard_drive_device_path_get_length(st) != 42) { |
3740 | 20 | g_set_error(error, |
3741 | 20 | FWUPD_ERROR, |
3742 | 20 | FWUPD_ERROR_INVALID_DATA, |
3743 | 20 | "constant FuStructEfiHardDriveDevicePath.length was not valid, " |
3744 | 20 | "expected 0x%x and got 0x%x", |
3745 | 20 | (guint) 42, |
3746 | 20 | (guint) fu_struct_efi_hard_drive_device_path_get_length(st)); |
3747 | 20 | return FALSE; |
3748 | 20 | } |
3749 | 616 | return TRUE; |
3750 | 636 | } |
3751 | | static gboolean |
3752 | | fu_struct_efi_hard_drive_device_path_parse_internal(FuStructEfiHardDriveDevicePath *st, GError **error) |
3753 | 636 | { |
3754 | 636 | 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 | 636 | if (!fu_struct_efi_hard_drive_device_path_validate_internal(st, error)) |
3759 | 20 | return FALSE; |
3760 | 616 | return TRUE; |
3761 | 636 | } |
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 | 650 | { |
3768 | 650 | g_autoptr(FuStructEfiHardDriveDevicePath) st = fu_struct_efi_hard_drive_device_path_new_internal(); |
3769 | 650 | st->buf = fu_input_stream_read_byte_array(stream, offset, 42, NULL, error); |
3770 | 650 | 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 | 650 | if (st->buf->len != 42) { |
3775 | 14 | g_set_error(error, |
3776 | 14 | FWUPD_ERROR, |
3777 | 14 | FWUPD_ERROR_INVALID_DATA, |
3778 | 14 | "FuStructEfiHardDriveDevicePath requested 0x%x and got 0x%x", |
3779 | 14 | (guint) 42, |
3780 | 14 | (guint) st->buf->len); |
3781 | 14 | return NULL; |
3782 | 14 | } |
3783 | 636 | if (!fu_struct_efi_hard_drive_device_path_parse_internal(st, error)) |
3784 | 20 | return NULL; |
3785 | 616 | return g_steal_pointer(&st); |
3786 | 636 | } |
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 | 33.5k | { |
3803 | 33.5k | g_return_if_fail(st != NULL); |
3804 | 33.5k | if (st->refcount == 0) { |
3805 | 0 | g_critical("FuStructEfiVss2VariableStoreHeader refcount already zero"); |
3806 | 0 | return; |
3807 | 0 | } |
3808 | 33.5k | if (--st->refcount > 0) |
3809 | 0 | return; |
3810 | 33.5k | if (st->buf != NULL) |
3811 | 33.3k | g_byte_array_unref(st->buf); |
3812 | 33.5k | g_free(st); |
3813 | 33.5k | } |
3814 | | static FuStructEfiVss2VariableStoreHeader * |
3815 | | fu_struct_efi_vss2_variable_store_header_new_internal(void) |
3816 | 33.5k | { |
3817 | 33.5k | FuStructEfiVss2VariableStoreHeader *st = g_new0(FuStructEfiVss2VariableStoreHeader, 1); |
3818 | 33.5k | st->refcount = 1; |
3819 | 33.5k | return st; |
3820 | 33.5k | } |
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 | 33.1k | { |
3829 | 33.1k | g_return_val_if_fail(st != NULL, NULL); |
3830 | 33.1k | return (const fwupd_guid_t *) (st->buf->data + 0); |
3831 | 33.1k | } |
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 | 5.08k | { |
3838 | 5.08k | g_return_val_if_fail(st != NULL, 0x0); |
3839 | 5.08k | return fu_memread_uint32(st->buf->data + 16, G_LITTLE_ENDIAN); |
3840 | 5.08k | } |
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.40k | { |
3847 | 2.40k | g_return_val_if_fail(st != NULL, 0x0); |
3848 | 2.40k | return st->buf->data[20]; |
3849 | 2.40k | } |
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.33k | { |
3856 | 2.33k | g_return_val_if_fail(st != NULL, 0x0); |
3857 | 2.33k | return st->buf->data[21]; |
3858 | 2.33k | } |
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 | 270 | { |
3867 | 270 | g_return_if_fail(st != NULL); |
3868 | 270 | g_return_if_fail(value != NULL); |
3869 | 270 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
3870 | 270 | } |
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 | 213 | { |
3877 | 213 | g_return_if_fail(st != NULL); |
3878 | 213 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
3879 | 213 | } |
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 | 270 | { |
3886 | 270 | g_return_if_fail(st != NULL); |
3887 | 270 | st->buf->data[20] = value; |
3888 | 270 | } |
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 | 270 | { |
3895 | 270 | g_return_if_fail(st != NULL); |
3896 | 270 | st->buf->data[21] = value; |
3897 | 270 | } |
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 | 270 | { |
3904 | 270 | FuStructEfiVss2VariableStoreHeader *st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
3905 | 270 | st->buf = g_byte_array_sized_new(28); |
3906 | 270 | fu_byte_array_set_size(st->buf, 28, 0x0); |
3907 | 270 | 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 | 270 | fu_struct_efi_vss2_variable_store_header_set_format(st, FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED); |
3909 | 270 | fu_struct_efi_vss2_variable_store_header_set_state(st, FU_EFI_VARIABLE_STORE_STATE_HEALTHY); |
3910 | 270 | return st; |
3911 | 270 | } |
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 | 33.1k | { |
3929 | 33.1k | g_return_val_if_fail(st != NULL, FALSE); |
3930 | 33.1k | 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 | 30.8k | g_set_error_literal(error, |
3932 | 30.8k | FWUPD_ERROR, |
3933 | 30.8k | FWUPD_ERROR_INVALID_DATA, |
3934 | 30.8k | "constant FuStructEfiVss2VariableStoreHeader.signature was not valid"); |
3935 | 30.8k | return FALSE; |
3936 | 30.8k | } |
3937 | 2.35k | if (fu_struct_efi_vss2_variable_store_header_get_format(st) != FU_EFI_VARIABLE_STORE_FORMAT_FORMATTED) { |
3938 | 43 | g_set_error(error, |
3939 | 43 | FWUPD_ERROR, |
3940 | 43 | FWUPD_ERROR_INVALID_DATA, |
3941 | 43 | "constant FuStructEfiVss2VariableStoreHeader.format was not valid, " |
3942 | 43 | "expected 'FuEfiVariableStoreFormat' and got '%s'", |
3943 | 43 | fu_efi_variable_store_format_to_string(fu_struct_efi_vss2_variable_store_header_get_format(st))); |
3944 | 43 | return FALSE; |
3945 | 43 | } |
3946 | 2.31k | if (fu_struct_efi_vss2_variable_store_header_get_state(st) != FU_EFI_VARIABLE_STORE_STATE_HEALTHY) { |
3947 | 16 | g_set_error(error, |
3948 | 16 | FWUPD_ERROR, |
3949 | 16 | FWUPD_ERROR_INVALID_DATA, |
3950 | 16 | "constant FuStructEfiVss2VariableStoreHeader.state was not valid, " |
3951 | 16 | "expected 'FuEfiVariableStoreState' and got '%s'", |
3952 | 16 | fu_efi_variable_store_state_to_string(fu_struct_efi_vss2_variable_store_header_get_state(st))); |
3953 | 16 | return FALSE; |
3954 | 16 | } |
3955 | 2.30k | return TRUE; |
3956 | 2.31k | } |
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 | 32.3k | { |
3963 | 32.3k | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
3964 | 32.3k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
3965 | 32.3k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
3966 | 32.3k | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
3967 | 32.3k | 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 | 32.3k | if (st->buf->len != 28) { |
3972 | 97 | g_set_error(error, |
3973 | 97 | FWUPD_ERROR, |
3974 | 97 | FWUPD_ERROR_INVALID_DATA, |
3975 | 97 | "FuStructEfiVss2VariableStoreHeader requested 0x%x and got 0x%x", |
3976 | 97 | (guint) 28, |
3977 | 97 | (guint) st->buf->len); |
3978 | 97 | return FALSE; |
3979 | 97 | } |
3980 | 32.2k | return fu_struct_efi_vss2_variable_store_header_validate_internal(st, error); |
3981 | 32.3k | } |
3982 | | static gboolean |
3983 | | fu_struct_efi_vss2_variable_store_header_parse_internal(FuStructEfiVss2VariableStoreHeader *st, GError **error) |
3984 | 979 | { |
3985 | 979 | 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 | 979 | if (!fu_struct_efi_vss2_variable_store_header_validate_internal(st, error)) |
3990 | 0 | return FALSE; |
3991 | 979 | return TRUE; |
3992 | 979 | } |
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 | 979 | { |
3999 | 979 | g_autoptr(FuStructEfiVss2VariableStoreHeader) st = fu_struct_efi_vss2_variable_store_header_new_internal(); |
4000 | 979 | st->buf = fu_input_stream_read_byte_array(stream, offset, 28, NULL, error); |
4001 | 979 | 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 | 979 | 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 | 979 | if (!fu_struct_efi_vss2_variable_store_header_parse_internal(st, error)) |
4015 | 0 | return NULL; |
4016 | 979 | return g_steal_pointer(&st); |
4017 | 979 | } |
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.77k | { |
4034 | 3.77k | g_return_if_fail(st != NULL); |
4035 | 3.77k | if (st->refcount == 0) { |
4036 | 0 | g_critical("FuStructEfiVssAuthVariableHeader refcount already zero"); |
4037 | 0 | return; |
4038 | 0 | } |
4039 | 3.77k | if (--st->refcount > 0) |
4040 | 0 | return; |
4041 | 3.77k | if (st->buf != NULL) |
4042 | 3.29k | g_byte_array_unref(st->buf); |
4043 | 3.77k | g_free(st); |
4044 | 3.77k | } |
4045 | | static FuStructEfiVssAuthVariableHeader * |
4046 | | fu_struct_efi_vss_auth_variable_header_new_internal(void) |
4047 | 3.77k | { |
4048 | 3.77k | FuStructEfiVssAuthVariableHeader *st = g_new0(FuStructEfiVssAuthVariableHeader, 1); |
4049 | 3.77k | st->refcount = 1; |
4050 | 3.77k | return st; |
4051 | 3.77k | } |
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.51k | { |
4060 | 6.51k | g_return_val_if_fail(st != NULL, 0x0); |
4061 | 6.51k | return fu_memread_uint16(st->buf->data + 0, G_LITTLE_ENDIAN); |
4062 | 6.51k | } |
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 | 3.14k | { |
4069 | 3.14k | g_return_val_if_fail(st != NULL, 0x0); |
4070 | 3.14k | return st->buf->data[2]; |
4071 | 3.14k | } |
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 | 3.14k | { |
4078 | 3.14k | g_return_val_if_fail(st != NULL, 0x0); |
4079 | 3.14k | return fu_memread_uint32(st->buf->data + 4, G_LITTLE_ENDIAN); |
4080 | 3.14k | } |
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 | 3.14k | { |
4096 | 3.14k | g_autoptr(FuStructEfiTime) st_tmp = fu_struct_efi_time_new_internal(); |
4097 | 3.14k | g_return_val_if_fail(st != NULL, NULL); |
4098 | 3.14k | st_tmp->buf = g_byte_array_new(); |
4099 | 3.14k | g_byte_array_append(st_tmp->buf, st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, 16); |
4100 | 3.14k | return g_steal_pointer(&st_tmp); |
4101 | 3.14k | } |
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 | 6.20k | { |
4117 | 6.20k | g_return_val_if_fail(st != NULL, 0x0); |
4118 | 6.20k | return fu_memread_uint32(st->buf->data + 36, G_LITTLE_ENDIAN); |
4119 | 6.20k | } |
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.87k | { |
4126 | 5.87k | g_return_val_if_fail(st != NULL, 0x0); |
4127 | 5.87k | return fu_memread_uint32(st->buf->data + 40, G_LITTLE_ENDIAN); |
4128 | 5.87k | } |
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 | 3.14k | { |
4135 | 3.14k | g_return_val_if_fail(st != NULL, NULL); |
4136 | 3.14k | return (const fwupd_guid_t *) (st->buf->data + 44); |
4137 | 3.14k | } |
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 | 483 | { |
4146 | 483 | g_return_if_fail(st != NULL); |
4147 | 483 | fu_memwrite_uint16(st->buf->data + 0, value, G_LITTLE_ENDIAN); |
4148 | 483 | } |
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 | 483 | { |
4155 | 483 | g_return_if_fail(st != NULL); |
4156 | 483 | st->buf->data[2] = value; |
4157 | 483 | } |
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 | 483 | { |
4164 | 483 | g_return_if_fail(st != NULL); |
4165 | 483 | fu_memwrite_uint32(st->buf->data + 4, value, G_LITTLE_ENDIAN); |
4166 | 483 | } |
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 | 483 | { |
4182 | 483 | g_return_val_if_fail(st != NULL, FALSE); |
4183 | 483 | g_return_val_if_fail(st_donor != NULL, FALSE); |
4184 | 483 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4185 | | |
4186 | 483 | 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 | 483 | memcpy(st->buf->data + FU_STRUCT_EFI_VSS_AUTH_VARIABLE_HEADER_OFFSET_TIMESTAMP, st_donor->buf->data, st_donor->buf->len); |
4197 | 483 | return TRUE; |
4198 | 483 | } |
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 | 483 | { |
4214 | 483 | g_return_if_fail(st != NULL); |
4215 | 483 | fu_memwrite_uint32(st->buf->data + 36, value, G_LITTLE_ENDIAN); |
4216 | 483 | } |
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 | 483 | { |
4223 | 483 | g_return_if_fail(st != NULL); |
4224 | 483 | fu_memwrite_uint32(st->buf->data + 40, value, G_LITTLE_ENDIAN); |
4225 | 483 | } |
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 | 483 | { |
4232 | 483 | g_return_if_fail(st != NULL); |
4233 | 483 | g_return_if_fail(value != NULL); |
4234 | 483 | memcpy(st->buf->data + 44, value, sizeof(*value)); /* nocheck:blocked */ |
4235 | 483 | } |
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 | 483 | { |
4242 | 483 | FuStructEfiVssAuthVariableHeader *st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4243 | 483 | st->buf = g_byte_array_sized_new(60); |
4244 | 483 | fu_byte_array_set_size(st->buf, 60, 0x0); |
4245 | 483 | { |
4246 | 483 | g_autoptr(FuStructEfiTime) st_donor = fu_struct_efi_time_new(); |
4247 | 483 | memcpy(st->buf->data + 0x10, st_donor->buf->data, st_donor->buf->len); /* nocheck:blocked */ |
4248 | 483 | } |
4249 | 483 | fu_struct_efi_vss_auth_variable_header_set_start_id(st, 0x55AA); |
4250 | 483 | return st; |
4251 | 483 | } |
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.23k | { |
4302 | 3.23k | g_return_val_if_fail(st != NULL, FALSE); |
4303 | 3.23k | { |
4304 | 3.23k | GByteArray buf_tmp = { |
4305 | 3.23k | .data = (guint8*) st->buf->data + 0x10, |
4306 | 3.23k | .len = 16, |
4307 | 3.23k | }; |
4308 | 3.23k | FuStructEfiTime st_tmp = { .buf = &buf_tmp }; |
4309 | 3.23k | if (!fu_struct_efi_time_validate_internal(&st_tmp, error)) |
4310 | 0 | return FALSE; |
4311 | 3.23k | } |
4312 | 3.23k | return TRUE; |
4313 | 3.23k | } |
4314 | | static gboolean |
4315 | | fu_struct_efi_vss_auth_variable_header_parse_internal(FuStructEfiVssAuthVariableHeader *st, GError **error) |
4316 | 3.23k | { |
4317 | 3.23k | 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.23k | if (!fu_struct_efi_vss_auth_variable_header_validate_internal(st, error)) |
4322 | 0 | return FALSE; |
4323 | 3.23k | return TRUE; |
4324 | 3.23k | } |
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.29k | { |
4331 | 3.29k | g_autoptr(FuStructEfiVssAuthVariableHeader) st = fu_struct_efi_vss_auth_variable_header_new_internal(); |
4332 | 3.29k | st->buf = fu_input_stream_read_byte_array(stream, offset, 60, NULL, error); |
4333 | 3.29k | 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.29k | if (st->buf->len != 60) { |
4338 | 58 | g_set_error(error, |
4339 | 58 | FWUPD_ERROR, |
4340 | 58 | FWUPD_ERROR_INVALID_DATA, |
4341 | 58 | "FuStructEfiVssAuthVariableHeader requested 0x%x and got 0x%x", |
4342 | 58 | (guint) 60, |
4343 | 58 | (guint) st->buf->len); |
4344 | 58 | return NULL; |
4345 | 58 | } |
4346 | 3.23k | if (!fu_struct_efi_vss_auth_variable_header_parse_internal(st, error)) |
4347 | 0 | return NULL; |
4348 | 3.23k | return g_steal_pointer(&st); |
4349 | 3.23k | } |
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 | 32.4k | { |
4366 | 32.4k | g_return_if_fail(st != NULL); |
4367 | 32.4k | if (st->refcount == 0) { |
4368 | 0 | g_critical("FuStructEfiFaultTolerantWorkingBlockHeader64 refcount already zero"); |
4369 | 0 | return; |
4370 | 0 | } |
4371 | 32.4k | if (--st->refcount > 0) |
4372 | 0 | return; |
4373 | 32.4k | if (st->buf != NULL) |
4374 | 32.2k | g_byte_array_unref(st->buf); |
4375 | 32.4k | g_free(st); |
4376 | 32.4k | } |
4377 | | static FuStructEfiFaultTolerantWorkingBlockHeader64 * |
4378 | | fu_struct_efi_fault_tolerant_working_block_header64_new_internal(void) |
4379 | 32.4k | { |
4380 | 32.4k | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = g_new0(FuStructEfiFaultTolerantWorkingBlockHeader64, 1); |
4381 | 32.4k | st->refcount = 1; |
4382 | 32.4k | return st; |
4383 | 32.4k | } |
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 | 32.0k | { |
4392 | 32.0k | g_return_val_if_fail(st != NULL, NULL); |
4393 | 32.0k | return (const fwupd_guid_t *) (st->buf->data + 0); |
4394 | 32.0k | } |
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 | 133 | { |
4410 | 133 | g_return_val_if_fail(st != NULL, 0x0); |
4411 | 133 | return st->buf->data[20]; |
4412 | 133 | } |
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 | 630 | { |
4419 | 630 | g_return_val_if_fail(st != NULL, 0x0); |
4420 | 630 | return fu_memread_uint64(st->buf->data + 24, G_LITTLE_ENDIAN); |
4421 | 630 | } |
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 | 112 | { |
4430 | 112 | g_return_if_fail(st != NULL); |
4431 | 112 | g_return_if_fail(value != NULL); |
4432 | 112 | memcpy(st->buf->data + 0, value, sizeof(*value)); /* nocheck:blocked */ |
4433 | 112 | } |
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 | 224 | { |
4440 | 224 | g_return_if_fail(st != NULL); |
4441 | 224 | fu_memwrite_uint32(st->buf->data + 16, value, G_LITTLE_ENDIAN); |
4442 | 224 | } |
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 | 224 | { |
4449 | 224 | g_return_if_fail(st != NULL); |
4450 | 224 | st->buf->data[20] = value; |
4451 | 224 | } |
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 | 112 | { |
4458 | 112 | g_return_if_fail(st != NULL); |
4459 | 112 | fu_memwrite_uint64(st->buf->data + 24, value, G_LITTLE_ENDIAN); |
4460 | 112 | } |
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 | 112 | { |
4467 | 112 | FuStructEfiFaultTolerantWorkingBlockHeader64 *st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4468 | 112 | st->buf = g_byte_array_sized_new(32); |
4469 | 112 | fu_byte_array_set_size(st->buf, 32, 0x0); |
4470 | 112 | 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 | 112 | fu_struct_efi_fault_tolerant_working_block_header64_set_crc(st, 0xFFFFFFFF); |
4472 | 112 | fu_struct_efi_fault_tolerant_working_block_header64_set_state(st, FU_EFI_VARIABLE_STORE_STATE_EMPTY); |
4473 | 112 | memcpy(st->buf->data + 0x15, "\xFF\xFF\xFF", 3); /* nocheck:blocked */ |
4474 | 112 | return st; |
4475 | 112 | } |
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 | 32.0k | { |
4503 | 32.0k | g_return_val_if_fail(st != NULL, FALSE); |
4504 | 32.0k | 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 | 30.7k | g_set_error_literal(error, |
4506 | 30.7k | FWUPD_ERROR, |
4507 | 30.7k | FWUPD_ERROR_INVALID_DATA, |
4508 | 30.7k | "constant FuStructEfiFaultTolerantWorkingBlockHeader64.signature was not valid"); |
4509 | 30.7k | return FALSE; |
4510 | 30.7k | } |
4511 | 1.26k | return TRUE; |
4512 | 32.0k | } |
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 | 31.9k | { |
4519 | 31.9k | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4520 | 31.9k | g_return_val_if_fail(G_IS_INPUT_STREAM(stream), FALSE); |
4521 | 31.9k | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4522 | 31.9k | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4523 | 31.9k | 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 | 31.9k | if (st->buf->len != 32) { |
4528 | 247 | g_set_error(error, |
4529 | 247 | FWUPD_ERROR, |
4530 | 247 | FWUPD_ERROR_INVALID_DATA, |
4531 | 247 | "FuStructEfiFaultTolerantWorkingBlockHeader64 requested 0x%x and got 0x%x", |
4532 | 247 | (guint) 32, |
4533 | 247 | (guint) st->buf->len); |
4534 | 247 | return FALSE; |
4535 | 247 | } |
4536 | 31.7k | return fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error); |
4537 | 31.9k | } |
4538 | | static gboolean |
4539 | | fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(FuStructEfiFaultTolerantWorkingBlockHeader64 *st, GError **error) |
4540 | 315 | { |
4541 | 315 | 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 | 315 | if (!fu_struct_efi_fault_tolerant_working_block_header64_validate_internal(st, error)) |
4546 | 0 | return FALSE; |
4547 | 315 | return TRUE; |
4548 | 315 | } |
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 | 315 | { |
4555 | 315 | g_autoptr(FuStructEfiFaultTolerantWorkingBlockHeader64) st = fu_struct_efi_fault_tolerant_working_block_header64_new_internal(); |
4556 | 315 | st->buf = fu_input_stream_read_byte_array(stream, offset, 32, NULL, error); |
4557 | 315 | 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 | 315 | 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 | 315 | if (!fu_struct_efi_fault_tolerant_working_block_header64_parse_internal(st, error)) |
4571 | 0 | return NULL; |
4572 | 315 | return g_steal_pointer(&st); |
4573 | 315 | } |
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.77k | { |
4590 | 1.77k | g_return_if_fail(st != NULL); |
4591 | 1.77k | if (st->refcount == 0) { |
4592 | 0 | g_critical("FuStructShimHive refcount already zero"); |
4593 | 0 | return; |
4594 | 0 | } |
4595 | 1.77k | if (--st->refcount > 0) |
4596 | 0 | return; |
4597 | 1.77k | if (st->buf != NULL) |
4598 | 1.40k | g_byte_array_unref(st->buf); |
4599 | 1.77k | g_free(st); |
4600 | 1.77k | } |
4601 | | static FuStructShimHive * |
4602 | | fu_struct_shim_hive_new_internal(void) |
4603 | 1.77k | { |
4604 | 1.77k | FuStructShimHive *st = g_new0(FuStructShimHive, 1); |
4605 | 1.77k | st->refcount = 1; |
4606 | 1.77k | return st; |
4607 | 1.77k | } |
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 | 423 | { |
4616 | 423 | g_return_val_if_fail(st != NULL, NULL); |
4617 | 423 | return fu_memstrsafe(st->buf->data, st->buf->len, 0, 4, NULL); |
4618 | 423 | } |
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 | 902 | { |
4625 | 902 | g_return_val_if_fail(st != NULL, 0x0); |
4626 | 902 | return st->buf->data[4]; |
4627 | 902 | } |
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 | 900 | { |
4634 | 900 | g_return_val_if_fail(st != NULL, 0x0); |
4635 | 900 | return st->buf->data[5]; |
4636 | 900 | } |
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 | 900 | { |
4643 | 900 | g_return_val_if_fail(st != NULL, 0x0); |
4644 | 900 | return st->buf->data[6]; |
4645 | 900 | } |
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 | 365 | { |
4663 | 365 | gsize len; |
4664 | 365 | g_return_val_if_fail(st != NULL, FALSE); |
4665 | 365 | g_return_val_if_fail(error == NULL || *error == NULL, FALSE); |
4666 | 365 | if (value == NULL) { |
4667 | 0 | memset(st->buf->data + 0, 0x0, 4); |
4668 | 0 | return TRUE; |
4669 | 0 | } |
4670 | 365 | len = strlen(value); |
4671 | 365 | 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 | 365 | return fu_memcpy_safe(st->buf->data, st->buf->len, 0, (const guint8 *)value, len, 0x0, len, error); |
4680 | 365 | } |
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 | 365 | { |
4687 | 365 | g_return_if_fail(st != NULL); |
4688 | 365 | st->buf->data[4] = value; |
4689 | 365 | } |
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 | 365 | { |
4696 | 365 | g_return_if_fail(st != NULL); |
4697 | 365 | st->buf->data[5] = value; |
4698 | 365 | } |
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 | 365 | { |
4705 | 365 | g_return_if_fail(st != NULL); |
4706 | 365 | st->buf->data[6] = value; |
4707 | 365 | } |
4708 | | /** |
4709 | | * fu_struct_shim_hive_set_crc32: (skip): |
4710 | | **/ |
4711 | | void |
4712 | | fu_struct_shim_hive_set_crc32(FuStructShimHive *st, guint32 value) |
4713 | 365 | { |
4714 | 365 | g_return_if_fail(st != NULL); |
4715 | 365 | fu_memwrite_uint32(st->buf->data + 7, value, G_LITTLE_ENDIAN); |
4716 | 365 | } |
4717 | | /** |
4718 | | * fu_struct_shim_hive_new: (skip): |
4719 | | **/ |
4720 | | FuStructShimHive * |
4721 | | fu_struct_shim_hive_new(void) |
4722 | 365 | { |
4723 | 365 | FuStructShimHive *st = fu_struct_shim_hive_new_internal(); |
4724 | 365 | st->buf = g_byte_array_sized_new(11); |
4725 | 365 | fu_byte_array_set_size(st->buf, 11, 0x0); |
4726 | 365 | fu_struct_shim_hive_set_magic(st, "HIVE", NULL); |
4727 | 365 | fu_struct_shim_hive_set_header_version(st, 0x1); |
4728 | 365 | return st; |
4729 | 365 | } |
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.32k | { |
4753 | 1.32k | g_return_val_if_fail(st != NULL, FALSE); |
4754 | 1.32k | if (strncmp((const gchar *) (st->buf->data + 0), "HIVE", 4) != 0) { |
4755 | 423 | g_autofree gchar *str = fu_struct_shim_hive_get_magic(st); |
4756 | 423 | g_set_error(error, |
4757 | 423 | FWUPD_ERROR, |
4758 | 423 | FWUPD_ERROR_INVALID_DATA, |
4759 | 423 | "constant FuStructShimHive.magic was not valid, " |
4760 | 423 | "expected 'HIVE' and got '%s'", |
4761 | 423 | str); |
4762 | 423 | return FALSE; |
4763 | 423 | } |
4764 | 901 | return TRUE; |
4765 | 1.32k | } |
4766 | | static gboolean |
4767 | | fu_struct_shim_hive_parse_internal(FuStructShimHive *st, GError **error) |
4768 | 1.32k | { |
4769 | 1.32k | 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.32k | if (!fu_struct_shim_hive_validate_internal(st, error)) |
4774 | 423 | return FALSE; |
4775 | 901 | return TRUE; |
4776 | 1.32k | } |
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.40k | { |
4783 | 1.40k | g_autoptr(FuStructShimHive) st = fu_struct_shim_hive_new_internal(); |
4784 | 1.40k | st->buf = fu_input_stream_read_byte_array(stream, offset, 11, NULL, error); |
4785 | 1.40k | 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.40k | if (st->buf->len != 11) { |
4790 | 81 | g_set_error(error, |
4791 | 81 | FWUPD_ERROR, |
4792 | 81 | FWUPD_ERROR_INVALID_DATA, |
4793 | 81 | "FuStructShimHive requested 0x%x and got 0x%x", |
4794 | 81 | (guint) 11, |
4795 | 81 | (guint) st->buf->len); |
4796 | 81 | return NULL; |
4797 | 81 | } |
4798 | 1.32k | if (!fu_struct_shim_hive_parse_internal(st, error)) |
4799 | 423 | return NULL; |
4800 | 901 | return g_steal_pointer(&st); |
4801 | 1.32k | } |
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.17k | { |
4818 | 6.17k | g_return_if_fail(st != NULL); |
4819 | 6.17k | if (st->refcount == 0) { |
4820 | 0 | g_critical("FuStructShimHiveItem refcount already zero"); |
4821 | 0 | return; |
4822 | 0 | } |
4823 | 6.17k | if (--st->refcount > 0) |
4824 | 0 | return; |
4825 | 6.17k | if (st->buf != NULL) |
4826 | 6.01k | g_byte_array_unref(st->buf); |
4827 | 6.17k | g_free(st); |
4828 | 6.17k | } |
4829 | | static FuStructShimHiveItem * |
4830 | | fu_struct_shim_hive_item_new_internal(void) |
4831 | 6.17k | { |
4832 | 6.17k | FuStructShimHiveItem *st = g_new0(FuStructShimHiveItem, 1); |
4833 | 6.17k | st->refcount = 1; |
4834 | 6.17k | return st; |
4835 | 6.17k | } |
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 | 4.92k | { |
4844 | 4.92k | g_return_val_if_fail(st != NULL, 0x0); |
4845 | 4.92k | return st->buf->data[0]; |
4846 | 4.92k | } |
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.78k | { |
4853 | 4.78k | g_return_val_if_fail(st != NULL, 0x0); |
4854 | 4.78k | return fu_memread_uint32(st->buf->data + 1, G_LITTLE_ENDIAN); |
4855 | 4.78k | } |
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 | 972 | { |
4864 | 972 | g_return_if_fail(st != NULL); |
4865 | 972 | st->buf->data[0] = value; |
4866 | 972 | } |
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 | 972 | { |
4873 | 972 | g_return_if_fail(st != NULL); |
4874 | 972 | fu_memwrite_uint32(st->buf->data + 1, value, G_LITTLE_ENDIAN); |
4875 | 972 | } |
4876 | | /** |
4877 | | * fu_struct_shim_hive_item_new: (skip): |
4878 | | **/ |
4879 | | FuStructShimHiveItem * |
4880 | | fu_struct_shim_hive_item_new(void) |
4881 | 972 | { |
4882 | 972 | FuStructShimHiveItem *st = fu_struct_shim_hive_item_new_internal(); |
4883 | 972 | st->buf = g_byte_array_sized_new(5); |
4884 | 972 | fu_byte_array_set_size(st->buf, 5, 0x0); |
4885 | 972 | return st; |
4886 | 972 | } |
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 | 4.92k | { |
4906 | 4.92k | g_return_val_if_fail(st != NULL, FALSE); |
4907 | 4.92k | return TRUE; |
4908 | 4.92k | } |
4909 | | static gboolean |
4910 | | fu_struct_shim_hive_item_parse_internal(FuStructShimHiveItem *st, GError **error) |
4911 | 4.92k | { |
4912 | 4.92k | 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 | 4.92k | if (!fu_struct_shim_hive_item_validate_internal(st, error)) |
4917 | 0 | return FALSE; |
4918 | 4.92k | return TRUE; |
4919 | 4.92k | } |
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.20k | { |
4926 | 5.20k | g_autoptr(FuStructShimHiveItem) st = fu_struct_shim_hive_item_new_internal(); |
4927 | 5.20k | st->buf = fu_input_stream_read_byte_array(stream, offset, 5, NULL, error); |
4928 | 5.20k | if (st->buf == NULL) { |
4929 | 160 | g_prefix_error(error, "FuStructShimHiveItem failed read of 0x%x: ", (guint) 5); |
4930 | 160 | return NULL; |
4931 | 160 | } |
4932 | 5.04k | if (st->buf->len != 5) { |
4933 | 118 | g_set_error(error, |
4934 | 118 | FWUPD_ERROR, |
4935 | 118 | FWUPD_ERROR_INVALID_DATA, |
4936 | 118 | "FuStructShimHiveItem requested 0x%x and got 0x%x", |
4937 | 118 | (guint) 5, |
4938 | 118 | (guint) st->buf->len); |
4939 | 118 | return NULL; |
4940 | 118 | } |
4941 | 4.92k | if (!fu_struct_shim_hive_item_parse_internal(st, error)) |
4942 | 0 | return NULL; |
4943 | 4.92k | return g_steal_pointer(&st); |
4944 | 4.92k | } |