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