/src/libfwsi/libfwsi/libfwsi_uri_sub_values.c
Line | Count | Source |
1 | | /* |
2 | | * URI sub (shell item) values functions |
3 | | * |
4 | | * Copyright (C) 2010-2025, 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_libcerror.h" |
29 | | #include "libfwsi_libcnotify.h" |
30 | | #include "libfwsi_libfdatetime.h" |
31 | | #include "libfwsi_uri_sub_values.h" |
32 | | |
33 | | /* Creates URI sub values |
34 | | * Make sure the value uri_sub_values is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libfwsi_uri_sub_values_initialize( |
38 | | libfwsi_uri_sub_values_t **uri_sub_values, |
39 | | libcerror_error_t **error ) |
40 | 0 | { |
41 | 0 | static char *function = "libfwsi_uri_sub_values_initialize"; |
42 | |
|
43 | 0 | if( uri_sub_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 URI sub values.", |
50 | 0 | function ); |
51 | |
|
52 | 0 | return( -1 ); |
53 | 0 | } |
54 | 0 | if( *uri_sub_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 URI sub values value already set.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 0 | *uri_sub_values = memory_allocate_structure( |
66 | 0 | libfwsi_uri_sub_values_t ); |
67 | |
|
68 | 0 | if( *uri_sub_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 URI sub values.", |
75 | 0 | function ); |
76 | |
|
77 | 0 | goto on_error; |
78 | 0 | } |
79 | 0 | if( memory_set( |
80 | 0 | *uri_sub_values, |
81 | 0 | 0, |
82 | 0 | sizeof( libfwsi_uri_sub_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 URI sub values.", |
89 | 0 | function ); |
90 | |
|
91 | 0 | goto on_error; |
92 | 0 | } |
93 | 0 | return( 1 ); |
94 | | |
95 | 0 | on_error: |
96 | 0 | if( *uri_sub_values != NULL ) |
97 | 0 | { |
98 | 0 | memory_free( |
99 | 0 | *uri_sub_values ); |
100 | |
|
101 | 0 | *uri_sub_values = NULL; |
102 | 0 | } |
103 | 0 | return( -1 ); |
104 | 0 | } |
105 | | |
106 | | /* Frees URI sub values |
107 | | * Returns 1 if successful or -1 on error |
108 | | */ |
109 | | int libfwsi_uri_sub_values_free( |
110 | | libfwsi_uri_sub_values_t **uri_sub_values, |
111 | | libcerror_error_t **error ) |
112 | 0 | { |
113 | 0 | static char *function = "libfwsi_uri_sub_values_free"; |
114 | |
|
115 | 0 | if( uri_sub_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 URI sub values.", |
122 | 0 | function ); |
123 | |
|
124 | 0 | return( -1 ); |
125 | 0 | } |
126 | 0 | if( *uri_sub_values != NULL ) |
127 | 0 | { |
128 | 0 | memory_free( |
129 | 0 | *uri_sub_values ); |
130 | |
|
131 | 0 | *uri_sub_values = NULL; |
132 | 0 | } |
133 | 0 | return( 1 ); |
134 | 0 | } |
135 | | |
136 | | /* Reads the URI sub values |
137 | | * Returns 1 if successful, 0 if not supported or -1 on error |
138 | | */ |
139 | | int libfwsi_uri_sub_values_read_data( |
140 | | libfwsi_uri_sub_values_t *uri_sub_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_uri_sub_values_read_data"; |
147 | |
|
148 | | #if defined( HAVE_DEBUG_OUTPUT ) |
149 | | uint32_t value_32bit = 0; |
150 | | uint16_t value_16bit = 0; |
151 | | #endif |
152 | |
|
153 | 0 | if( uri_sub_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 URI sub 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 < 38 ) |
189 | 0 | { |
190 | 0 | return( 0 ); |
191 | 0 | } |
192 | | #if defined( HAVE_DEBUG_OUTPUT ) |
193 | | if( libcnotify_verbose != 0 ) |
194 | | { |
195 | | libcnotify_printf( |
196 | | "%s: class type indicator\t\t\t: 0x%02" PRIx8 "\n", |
197 | | function, |
198 | | data[ 2 ] ); |
199 | | |
200 | | libcnotify_printf( |
201 | | "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", |
202 | | function, |
203 | | data[ 3 ] ); |
204 | | |
205 | | byte_stream_copy_to_uint16_little_endian( |
206 | | &( data[ 4 ] ), |
207 | | value_16bit ); |
208 | | libcnotify_printf( |
209 | | "%s: unknown2\t\t\t\t: 0x%04" PRIx16 "\n", |
210 | | function, |
211 | | value_16bit ); |
212 | | |
213 | | byte_stream_copy_to_uint16_little_endian( |
214 | | &( data[ 6 ] ), |
215 | | value_16bit ); |
216 | | libcnotify_printf( |
217 | | "%s: unknown3\t\t\t\t: 0x%04" PRIx16 "\n", |
218 | | function, |
219 | | value_16bit ); |
220 | | |
221 | | byte_stream_copy_to_uint16_little_endian( |
222 | | &( data[ 8 ] ), |
223 | | value_16bit ); |
224 | | libcnotify_printf( |
225 | | "%s: unknown4\t\t\t\t: 0x%04" PRIx16 "\n", |
226 | | function, |
227 | | value_16bit ); |
228 | | |
229 | | byte_stream_copy_to_uint32_little_endian( |
230 | | &( data[ 10 ] ), |
231 | | value_32bit ); |
232 | | libcnotify_printf( |
233 | | "%s: unknown5\t\t\t\t: 0x%08" PRIx32 "\n", |
234 | | function, |
235 | | value_32bit ); |
236 | | |
237 | | byte_stream_copy_to_uint32_little_endian( |
238 | | &( data[ 14 ] ), |
239 | | value_32bit ); |
240 | | libcnotify_printf( |
241 | | "%s: unknown6\t\t\t\t: 0x%08" PRIx32 "\n", |
242 | | function, |
243 | | value_32bit ); |
244 | | |
245 | | byte_stream_copy_to_uint32_little_endian( |
246 | | &( data[ 18 ] ), |
247 | | value_32bit ); |
248 | | libcnotify_printf( |
249 | | "%s: unknown7\t\t\t\t: 0x%08" PRIx32 "\n", |
250 | | function, |
251 | | value_32bit ); |
252 | | |
253 | | if( libfwsi_debug_print_filetime_value( |
254 | | function, |
255 | | "unknown8 time\t\t\t\t", |
256 | | &( data[ 22 ] ), |
257 | | 8, |
258 | | LIBFDATETIME_ENDIAN_LITTLE, |
259 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS, |
260 | | error ) != 1 ) |
261 | | { |
262 | | libcerror_error_set( |
263 | | error, |
264 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
265 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
266 | | "%s: unable to print FILETIME value.", |
267 | | function ); |
268 | | |
269 | | return( -1 ); |
270 | | } |
271 | | byte_stream_copy_to_uint32_little_endian( |
272 | | &( data[ 30 ] ), |
273 | | value_32bit ); |
274 | | libcnotify_printf( |
275 | | "%s: unknown9\t\t\t\t: 0x%08" PRIx32 "\n", |
276 | | function, |
277 | | value_32bit ); |
278 | | |
279 | | byte_stream_copy_to_uint32_little_endian( |
280 | | &( data[ 34 ] ), |
281 | | value_32bit ); |
282 | | libcnotify_printf( |
283 | | "%s: unknown10\t\t\t\t: 0x%08" PRIx32 "\n", |
284 | | function, |
285 | | value_32bit ); |
286 | | |
287 | | libcnotify_printf( |
288 | | "%s: unknown11:\n", |
289 | | function ); |
290 | | libcnotify_print_data( |
291 | | &( data[ 38 ] ), |
292 | | data_size - 38, |
293 | | 0 ); |
294 | | } |
295 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
296 | | |
297 | 0 | return( 1 ); |
298 | 0 | } |
299 | | |