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