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