/src/libfwsi/libfwsi/libfwsi_extension_block_0xbeef0014_values.c
Line | Count | Source |
1 | | /* |
2 | | * Extension block 0xbeef0014 values functions |
3 | | * |
4 | | * Copyright (C) 2010-2026, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libfwsi_debug.h" |
28 | | #include "libfwsi_definitions.h" |
29 | | #include "libfwsi_extension_block_0xbeef0014_values.h" |
30 | | #include "libfwsi_libcerror.h" |
31 | | #include "libfwsi_libcnotify.h" |
32 | | #include "libfwsi_libfguid.h" |
33 | | |
34 | | static const uint8_t curi_class_identifier[ 16 ] = { |
35 | | 0x13, 0xce, 0x2f, 0xdf, 0xec, 0x25, 0xbb, 0x45, 0x9d, 0x4c, 0xce, 0xcd, 0x47, 0xc2, 0x43, 0x0c }; |
36 | | |
37 | | /* Creates extension block 0xbeef0014 values |
38 | | * Make sure the value extension_block_0xbeef0014_values is referencing, is set to NULL |
39 | | * Returns 1 if successful or -1 on error |
40 | | */ |
41 | | int libfwsi_extension_block_0xbeef0014_values_initialize( |
42 | | libfwsi_extension_block_0xbeef0014_values_t **extension_block_0xbeef0014_values, |
43 | | libcerror_error_t **error ) |
44 | 0 | { |
45 | 0 | static char *function = "libfwsi_extension_block_0xbeef0014_values_initialize"; |
46 | |
|
47 | 0 | if( extension_block_0xbeef0014_values == NULL ) |
48 | 0 | { |
49 | 0 | libcerror_error_set( |
50 | 0 | error, |
51 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
52 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
53 | 0 | "%s: invalid extension block 0xbeef0014 values.", |
54 | 0 | function ); |
55 | |
|
56 | 0 | return( -1 ); |
57 | 0 | } |
58 | 0 | if( *extension_block_0xbeef0014_values != NULL ) |
59 | 0 | { |
60 | 0 | libcerror_error_set( |
61 | 0 | error, |
62 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
63 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
64 | 0 | "%s: invalid extension block 0xbeef0014 values value already set.", |
65 | 0 | function ); |
66 | |
|
67 | 0 | return( -1 ); |
68 | 0 | } |
69 | 0 | *extension_block_0xbeef0014_values = memory_allocate_structure( |
70 | 0 | libfwsi_extension_block_0xbeef0014_values_t ); |
71 | |
|
72 | 0 | if( *extension_block_0xbeef0014_values == NULL ) |
73 | 0 | { |
74 | 0 | libcerror_error_set( |
75 | 0 | error, |
76 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
77 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
78 | 0 | "%s: unable to create extension block 0xbeef0014 values.", |
79 | 0 | function ); |
80 | |
|
81 | 0 | goto on_error; |
82 | 0 | } |
83 | 0 | if( memory_set( |
84 | 0 | *extension_block_0xbeef0014_values, |
85 | 0 | 0, |
86 | 0 | sizeof( libfwsi_extension_block_0xbeef0014_values_t ) ) == NULL ) |
87 | 0 | { |
88 | 0 | libcerror_error_set( |
89 | 0 | error, |
90 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
91 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
92 | 0 | "%s: unable to clear extension block 0xbeef0014 values.", |
93 | 0 | function ); |
94 | |
|
95 | 0 | goto on_error; |
96 | 0 | } |
97 | 0 | return( 1 ); |
98 | | |
99 | 0 | on_error: |
100 | 0 | if( *extension_block_0xbeef0014_values != NULL ) |
101 | 0 | { |
102 | 0 | memory_free( |
103 | 0 | *extension_block_0xbeef0014_values ); |
104 | |
|
105 | 0 | *extension_block_0xbeef0014_values = NULL; |
106 | 0 | } |
107 | 0 | return( -1 ); |
108 | 0 | } |
109 | | |
110 | | /* Frees extension block 0xbeef0014 values |
111 | | * Returns 1 if successful or -1 on error |
112 | | */ |
113 | | int libfwsi_extension_block_0xbeef0014_values_free( |
114 | | libfwsi_extension_block_0xbeef0014_values_t **extension_block_0xbeef0014_values, |
115 | | libcerror_error_t **error ) |
116 | 0 | { |
117 | 0 | static char *function = "libfwsi_extension_block_0xbeef0014_values_free"; |
118 | |
|
119 | 0 | if( extension_block_0xbeef0014_values == NULL ) |
120 | 0 | { |
121 | 0 | libcerror_error_set( |
122 | 0 | error, |
123 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
124 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
125 | 0 | "%s: invalid extension block 0xbeef0014 values.", |
126 | 0 | function ); |
127 | |
|
128 | 0 | return( -1 ); |
129 | 0 | } |
130 | 0 | if( *extension_block_0xbeef0014_values != NULL ) |
131 | 0 | { |
132 | 0 | memory_free( |
133 | 0 | *extension_block_0xbeef0014_values ); |
134 | |
|
135 | 0 | *extension_block_0xbeef0014_values = NULL; |
136 | 0 | } |
137 | 0 | return( 1 ); |
138 | 0 | } |
139 | | |
140 | | /* Reads the extension block 0xbeef0014 values |
141 | | * Returns 1 if successful, 0 if not supported or -1 on error |
142 | | */ |
143 | | int libfwsi_extension_block_0xbeef0014_values_read_data( |
144 | | libfwsi_extension_block_0xbeef0014_values_t *extension_block_0xbeef0014_values, |
145 | | const uint8_t *data, |
146 | | size_t data_size, |
147 | | libcerror_error_t **error ) |
148 | 0 | { |
149 | 0 | static char *function = "libfwsi_extension_block_0xbeef0014_values_read_data"; |
150 | 0 | size_t data_offset = 0; |
151 | 0 | uint32_t number_of_properties = 0; |
152 | 0 | uint32_t property_index = 0; |
153 | 0 | uint32_t property_size = 0; |
154 | 0 | uint32_t signature = 0; |
155 | 0 | int result = 0; |
156 | |
|
157 | | #if defined( HAVE_DEBUG_OUTPUT ) |
158 | | uint32_t value_32bit = 0; |
159 | | #endif |
160 | |
|
161 | 0 | if( extension_block_0xbeef0014_values == NULL ) |
162 | 0 | { |
163 | 0 | libcerror_error_set( |
164 | 0 | error, |
165 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
166 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
167 | 0 | "%s: invalid extension block 0xbeef0014 values.", |
168 | 0 | function ); |
169 | |
|
170 | 0 | return( -1 ); |
171 | 0 | } |
172 | 0 | if( data == NULL ) |
173 | 0 | { |
174 | 0 | libcerror_error_set( |
175 | 0 | error, |
176 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
177 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
178 | 0 | "%s: invalid data.", |
179 | 0 | function ); |
180 | |
|
181 | 0 | return( -1 ); |
182 | 0 | } |
183 | 0 | if( data_size > (size_t) SSIZE_MAX ) |
184 | 0 | { |
185 | 0 | libcerror_error_set( |
186 | 0 | error, |
187 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
188 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
189 | 0 | "%s: data size exceeds maximum.", |
190 | 0 | function ); |
191 | |
|
192 | 0 | return( -1 ); |
193 | 0 | } |
194 | | /* Do not try to parse unsupported data sizes |
195 | | */ |
196 | 0 | if( data_size < 26 ) |
197 | 0 | { |
198 | 0 | return( 0 ); |
199 | 0 | } |
200 | | /* Do not try to parse unsupported extension block signatures |
201 | | */ |
202 | 0 | byte_stream_copy_to_uint32_little_endian( |
203 | 0 | &( data[ 4 ] ), |
204 | 0 | signature ); |
205 | |
|
206 | 0 | if( signature != 0xbeef0014 ) |
207 | 0 | { |
208 | 0 | return( 0 ); |
209 | 0 | } |
210 | | #if defined( HAVE_DEBUG_OUTPUT ) |
211 | | if( libcnotify_verbose != 0 ) |
212 | | { |
213 | | if( libfwsi_debug_print_guid_value( |
214 | | function, |
215 | | "class identifier\t\t", |
216 | | &( data[ 8 ] ), |
217 | | 16, |
218 | | LIBFGUID_ENDIAN_LITTLE, |
219 | | LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE, |
220 | | error ) != 1 ) |
221 | | { |
222 | | libcerror_error_set( |
223 | | error, |
224 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
225 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
226 | | "%s: unable to print GUID value.", |
227 | | function ); |
228 | | |
229 | | return( -1 ); |
230 | | } |
231 | | } |
232 | | #endif |
233 | 0 | result = memory_compare( |
234 | 0 | &( data[ 8 ] ), |
235 | 0 | curi_class_identifier, |
236 | 0 | 16 ); |
237 | |
|
238 | 0 | data_offset = 24; |
239 | |
|
240 | 0 | if( result == 0 ) |
241 | 0 | { |
242 | 0 | if( data_size < 58 ) |
243 | 0 | { |
244 | 0 | return( 0 ); |
245 | 0 | } |
246 | | #if defined( HAVE_DEBUG_OUTPUT ) |
247 | | if( libcnotify_verbose != 0 ) |
248 | | { |
249 | | byte_stream_copy_to_uint32_little_endian( |
250 | | &( data[ data_offset ] ), |
251 | | value_32bit ); |
252 | | |
253 | | libcnotify_printf( |
254 | | "%s: data size\t\t\t: %" PRIu32 "\n", |
255 | | function, |
256 | | value_32bit ); |
257 | | } |
258 | | #endif |
259 | 0 | data_offset += 4; |
260 | |
|
261 | | #if defined( HAVE_DEBUG_OUTPUT ) |
262 | | if( libcnotify_verbose != 0 ) |
263 | | { |
264 | | libcnotify_printf( |
265 | | "%s: unknown1:\n", |
266 | | function ); |
267 | | libcnotify_print_data( |
268 | | &( data[ data_offset ] ), |
269 | | 8, |
270 | | 0 ); |
271 | | } |
272 | | #endif |
273 | 0 | data_offset += 8; |
274 | |
|
275 | | #if defined( HAVE_DEBUG_OUTPUT ) |
276 | | if( libcnotify_verbose != 0 ) |
277 | | { |
278 | | byte_stream_copy_to_uint32_little_endian( |
279 | | &( data[ data_offset ] ), |
280 | | value_32bit ); |
281 | | |
282 | | libcnotify_printf( |
283 | | "%s: unknown2\t\t\t: 0x%08" PRIx32 "\n", |
284 | | function, |
285 | | value_32bit ); |
286 | | } |
287 | | #endif |
288 | 0 | data_offset += 4; |
289 | |
|
290 | | #if defined( HAVE_DEBUG_OUTPUT ) |
291 | | if( libcnotify_verbose != 0 ) |
292 | | { |
293 | | libcnotify_printf( |
294 | | "%s: unknown3:\n", |
295 | | function ); |
296 | | libcnotify_print_data( |
297 | | &( data[ data_offset ] ), |
298 | | 12, |
299 | | 0 ); |
300 | | } |
301 | | #endif |
302 | 0 | data_offset += 12; |
303 | | |
304 | | /* Property table |
305 | | */ |
306 | 0 | byte_stream_copy_to_uint32_little_endian( |
307 | 0 | &( data[ data_offset ] ), |
308 | 0 | number_of_properties ); |
309 | |
|
310 | | #if defined( HAVE_DEBUG_OUTPUT ) |
311 | | if( libcnotify_verbose != 0 ) |
312 | | { |
313 | | libcnotify_printf( |
314 | | "%s: number of properties\t: %" PRIu32 "\n", |
315 | | function, |
316 | | number_of_properties ); |
317 | | } |
318 | | #endif |
319 | 0 | data_offset += 4; |
320 | |
|
321 | 0 | for( property_index = 0; |
322 | 0 | property_index < number_of_properties; |
323 | 0 | property_index++ ) |
324 | 0 | { |
325 | 0 | if( data_offset > ( data_size - 8 ) ) |
326 | 0 | { |
327 | 0 | return( 0 ); |
328 | 0 | } |
329 | | #if defined( HAVE_DEBUG_OUTPUT ) |
330 | | if( libcnotify_verbose != 0 ) |
331 | | { |
332 | | byte_stream_copy_to_uint32_little_endian( |
333 | | &( data[ data_offset ] ), |
334 | | value_32bit ); |
335 | | libcnotify_printf( |
336 | | "%s: property: %" PRIu32 " type\t\t: %" PRIu32 "\n", |
337 | | function, |
338 | | property_index, |
339 | | value_32bit ); |
340 | | } |
341 | | #endif |
342 | 0 | data_offset += 4; |
343 | |
|
344 | 0 | byte_stream_copy_to_uint32_little_endian( |
345 | 0 | &( data[ data_offset ] ), |
346 | 0 | property_size ); |
347 | |
|
348 | | #if defined( HAVE_DEBUG_OUTPUT ) |
349 | | if( libcnotify_verbose != 0 ) |
350 | | { |
351 | | libcnotify_printf( |
352 | | "%s: property: %" PRIu32 " size\t\t: %" PRIu32 "\n", |
353 | | function, |
354 | | property_index, |
355 | | property_size ); |
356 | | } |
357 | | #endif |
358 | 0 | data_offset += 4; |
359 | |
|
360 | 0 | if( ( property_size > data_size ) |
361 | 0 | || ( data_offset > ( data_size - property_size ) ) ) |
362 | 0 | { |
363 | 0 | return( 0 ); |
364 | 0 | } |
365 | | #if defined( HAVE_DEBUG_OUTPUT ) |
366 | | if( libcnotify_verbose != 0 ) |
367 | | { |
368 | | libcnotify_printf( |
369 | | "%s: property: %" PRIu32 " data:\n", |
370 | | function, |
371 | | property_index ); |
372 | | libcnotify_print_data( |
373 | | &( data[ data_offset ] ), |
374 | | property_size, |
375 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
376 | | } |
377 | | #endif |
378 | 0 | data_offset += property_size; |
379 | 0 | } |
380 | 0 | } |
381 | | #if defined( HAVE_DEBUG_OUTPUT ) |
382 | | if( libcnotify_verbose != 0 ) |
383 | | { |
384 | | libcnotify_printf( |
385 | | "\n" ); |
386 | | } |
387 | | #endif |
388 | 0 | return( 1 ); |
389 | 0 | } |
390 | | |