/src/libfwsi/libfwsi/libfwsi_extension_block_0xbeef0027_values.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Extension block 0xbeef0027 values functions  | 
3  |  |  *  | 
4  |  |  * Copyright (C) 2010-2024, 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_0xbeef0027_values.h"  | 
30  |  | #include "libfwsi_libcerror.h"  | 
31  |  | #include "libfwsi_libcnotify.h"  | 
32  |  |  | 
33  |  | /* Creates extension block 0xbeef0027 values  | 
34  |  |  * Make sure the value extension_block_0xbeef0027_values is referencing, is set to NULL  | 
35  |  |  * Returns 1 if successful or -1 on error  | 
36  |  |  */  | 
37  |  | int libfwsi_extension_block_0xbeef0027_values_initialize(  | 
38  |  |      libfwsi_extension_block_0xbeef0027_values_t **extension_block_0xbeef0027_values,  | 
39  |  |      libcerror_error_t **error )  | 
40  | 0  | { | 
41  | 0  |   static char *function = "libfwsi_extension_block_0xbeef0027_values_initialize";  | 
42  |  | 
  | 
43  | 0  |   if( extension_block_0xbeef0027_values == NULL )  | 
44  | 0  |   { | 
45  | 0  |     libcerror_error_set(  | 
46  | 0  |      error,  | 
47  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
48  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
49  | 0  |      "%s: invalid extension block 0xbeef0027 values.",  | 
50  | 0  |      function );  | 
51  |  | 
  | 
52  | 0  |     return( -1 );  | 
53  | 0  |   }  | 
54  | 0  |   if( *extension_block_0xbeef0027_values != NULL )  | 
55  | 0  |   { | 
56  | 0  |     libcerror_error_set(  | 
57  | 0  |      error,  | 
58  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
59  | 0  |      LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,  | 
60  | 0  |      "%s: invalid extension block 0xbeef0027 values value already set.",  | 
61  | 0  |      function );  | 
62  |  | 
  | 
63  | 0  |     return( -1 );  | 
64  | 0  |   }  | 
65  | 0  |   *extension_block_0xbeef0027_values = memory_allocate_structure(  | 
66  | 0  |                                         libfwsi_extension_block_0xbeef0027_values_t );  | 
67  |  | 
  | 
68  | 0  |   if( *extension_block_0xbeef0027_values == NULL )  | 
69  | 0  |   { | 
70  | 0  |     libcerror_error_set(  | 
71  | 0  |      error,  | 
72  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
73  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
74  | 0  |      "%s: unable to create extension block 0xbeef0027 values.",  | 
75  | 0  |      function );  | 
76  |  | 
  | 
77  | 0  |     goto on_error;  | 
78  | 0  |   }  | 
79  | 0  |   if( memory_set(  | 
80  | 0  |        *extension_block_0xbeef0027_values,  | 
81  | 0  |        0,  | 
82  | 0  |        sizeof( libfwsi_extension_block_0xbeef0027_values_t ) ) == NULL )  | 
83  | 0  |   { | 
84  | 0  |     libcerror_error_set(  | 
85  | 0  |      error,  | 
86  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
87  | 0  |      LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
88  | 0  |      "%s: unable to clear extension block 0xbeef0027 values.",  | 
89  | 0  |      function );  | 
90  |  | 
  | 
91  | 0  |     goto on_error;  | 
92  | 0  |   }  | 
93  | 0  |   return( 1 );  | 
94  |  |  | 
95  | 0  | on_error:  | 
96  | 0  |   if( *extension_block_0xbeef0027_values != NULL )  | 
97  | 0  |   { | 
98  | 0  |     memory_free(  | 
99  | 0  |      *extension_block_0xbeef0027_values );  | 
100  |  | 
  | 
101  | 0  |     *extension_block_0xbeef0027_values = NULL;  | 
102  | 0  |   }  | 
103  | 0  |   return( -1 );  | 
104  | 0  | }  | 
105  |  |  | 
106  |  | /* Frees extension block 0xbeef0027 values  | 
107  |  |  * Returns 1 if successful or -1 on error  | 
108  |  |  */  | 
109  |  | int libfwsi_extension_block_0xbeef0027_values_free(  | 
110  |  |      libfwsi_extension_block_0xbeef0027_values_t **extension_block_0xbeef0027_values,  | 
111  |  |      libcerror_error_t **error )  | 
112  | 0  | { | 
113  | 0  |   static char *function = "libfwsi_extension_block_0xbeef0027_values_free";  | 
114  |  | 
  | 
115  | 0  |   if( extension_block_0xbeef0027_values == NULL )  | 
116  | 0  |   { | 
117  | 0  |     libcerror_error_set(  | 
118  | 0  |      error,  | 
119  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
120  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
121  | 0  |      "%s: invalid extension block 0xbeef0027 values.",  | 
122  | 0  |      function );  | 
123  |  | 
  | 
124  | 0  |     return( -1 );  | 
125  | 0  |   }  | 
126  | 0  |   if( *extension_block_0xbeef0027_values != NULL )  | 
127  | 0  |   { | 
128  | 0  |     memory_free(  | 
129  | 0  |      *extension_block_0xbeef0027_values );  | 
130  |  | 
  | 
131  | 0  |     *extension_block_0xbeef0027_values = NULL;  | 
132  | 0  |   }  | 
133  | 0  |   return( 1 );  | 
134  | 0  | }  | 
135  |  |  | 
136  |  | /* Reads the extension block 0xbeef0027 values  | 
137  |  |  * Returns 1 if successful, 0 if not supported or -1 on error  | 
138  |  |  */  | 
139  |  | int libfwsi_extension_block_0xbeef0027_values_read_data(  | 
140  |  |      libfwsi_extension_block_0xbeef0027_values_t *extension_block_0xbeef0027_values,  | 
141  |  |      const uint8_t *data,  | 
142  |  |      size_t data_size,  | 
143  |  |      int ascii_codepage,  | 
144  |  |      libcerror_error_t **error )  | 
145  | 0  | { | 
146  | 0  |   static char *function        = "libfwsi_extension_block_0xbeef0027_values_read_data";  | 
147  | 0  |   uint32_t signature           = 0;  | 
148  |  | 
  | 
149  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
150  |  |   uint32_t property_store_size = 0;  | 
151  |  | #endif  | 
152  |  | 
  | 
153  | 0  |   if( extension_block_0xbeef0027_values == NULL )  | 
154  | 0  |   { | 
155  | 0  |     libcerror_error_set(  | 
156  | 0  |      error,  | 
157  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
158  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
159  | 0  |      "%s: invalid extension block 0xbeef0027 values.",  | 
160  | 0  |      function );  | 
161  |  | 
  | 
162  | 0  |     return( -1 );  | 
163  | 0  |   }  | 
164  | 0  |   if( data == NULL )  | 
165  | 0  |   { | 
166  | 0  |     libcerror_error_set(  | 
167  | 0  |      error,  | 
168  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
169  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
170  | 0  |      "%s: invalid data.",  | 
171  | 0  |      function );  | 
172  |  | 
  | 
173  | 0  |     return( -1 );  | 
174  | 0  |   }  | 
175  | 0  |   if( data_size > (size_t) SSIZE_MAX )  | 
176  | 0  |   { | 
177  | 0  |     libcerror_error_set(  | 
178  | 0  |      error,  | 
179  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
180  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
181  | 0  |      "%s: data size exceeds maximum.",  | 
182  | 0  |      function );  | 
183  |  | 
  | 
184  | 0  |     return( -1 );  | 
185  | 0  |   }  | 
186  |  |   /* Do not try to parse unsupported data sizes  | 
187  |  |    */  | 
188  | 0  |   if( data_size < 12 )  | 
189  | 0  |   { | 
190  | 0  |     return( 0 );  | 
191  | 0  |   }  | 
192  |  |   /* Do not try to parse unsupported extension block signatures  | 
193  |  |    */  | 
194  | 0  |   byte_stream_copy_to_uint32_little_endian(  | 
195  | 0  |    &( data[ 4 ] ),  | 
196  | 0  |    signature );  | 
197  |  | 
  | 
198  | 0  |   if( signature != 0xbeef0027 )  | 
199  | 0  |   { | 
200  | 0  |     return( 0 );  | 
201  | 0  |   }  | 
202  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
203  |  |   if( libcnotify_verbose != 0 )  | 
204  |  |   { | 
205  |  |     if( libfwsi_debug_print_property_store_value(  | 
206  |  |          &( data[ 8 ] ),  | 
207  |  |          data_size - 8 - 2,  | 
208  |  |          ascii_codepage,  | 
209  |  |          error ) != 1 )  | 
210  |  |     { | 
211  |  |       libcerror_error_set(  | 
212  |  |        error,  | 
213  |  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
214  |  |        LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,  | 
215  |  |        "%s: unable to print property store value.",  | 
216  |  |        function );  | 
217  |  |  | 
218  |  |       return( -1 );  | 
219  |  |     }  | 
220  |  |   }  | 
221  |  | #endif /* defined( HAVE_DEBUG_OUTPUT ) */  | 
222  |  |  | 
223  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
224  |  |   if( libcnotify_verbose != 0 )  | 
225  |  |   { | 
226  |  |     byte_stream_copy_to_uint32_little_endian(  | 
227  |  |      &( data[ 8 ] ),  | 
228  |  |      property_store_size );  | 
229  |  |  | 
230  |  |     if( property_store_size < ( data_size - 8 ) )  | 
231  |  |     { | 
232  |  |       libcnotify_printf(  | 
233  |  |        "%s: trailing data:\n",  | 
234  |  |        function );  | 
235  |  |       libcnotify_print_data(  | 
236  |  |        &( data[ 8 + property_store_size ] ),  | 
237  |  |        data_size - 8 - property_store_size - 2,  | 
238  |  |        LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );  | 
239  |  |     }  | 
240  |  |     else  | 
241  |  |     { | 
242  |  |       libcnotify_printf(  | 
243  |  |        "\n" );  | 
244  |  |     }  | 
245  |  |   }  | 
246  |  | #endif /* defined( HAVE_DEBUG_OUTPUT ) */  | 
247  |  |  | 
248  | 0  |   return( 1 );  | 
249  | 0  | }  | 
250  |  |  |