/src/libevt/libevt/libevt_strings_array.c
Line | Count | Source |
1 | | /* |
2 | | * Strings array functions |
3 | | * |
4 | | * Copyright (C) 2011-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 <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libevt_libcerror.h" |
27 | | #include "libevt_libcnotify.h" |
28 | | #include "libevt_libuna.h" |
29 | | #include "libevt_strings_array.h" |
30 | | |
31 | | /* Creates a strings array |
32 | | * Make sure the value strings_array is referencing, is set to NULL |
33 | | * Returns 1 if successful or -1 on error |
34 | | */ |
35 | | int libevt_strings_array_initialize( |
36 | | libevt_strings_array_t **strings_array, |
37 | | libcerror_error_t **error ) |
38 | 46.3k | { |
39 | 46.3k | static char *function = "libevt_strings_array_initialize"; |
40 | | |
41 | 46.3k | if( strings_array == NULL ) |
42 | 0 | { |
43 | 0 | libcerror_error_set( |
44 | 0 | error, |
45 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
46 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
47 | 0 | "%s: invalid strings array.", |
48 | 0 | function ); |
49 | |
|
50 | 0 | return( -1 ); |
51 | 0 | } |
52 | 46.3k | if( *strings_array != NULL ) |
53 | 0 | { |
54 | 0 | libcerror_error_set( |
55 | 0 | error, |
56 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
57 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
58 | 0 | "%s: invalid strings array value already set.", |
59 | 0 | function ); |
60 | |
|
61 | 0 | return( -1 ); |
62 | 0 | } |
63 | 46.3k | *strings_array = memory_allocate_structure( |
64 | 46.3k | libevt_strings_array_t ); |
65 | | |
66 | 46.3k | if( *strings_array == NULL ) |
67 | 0 | { |
68 | 0 | libcerror_error_set( |
69 | 0 | error, |
70 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
71 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
72 | 0 | "%s: unable to create strings array.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | goto on_error; |
76 | 0 | } |
77 | 46.3k | if( memory_set( |
78 | 46.3k | *strings_array, |
79 | 46.3k | 0, |
80 | 46.3k | sizeof( libevt_strings_array_t ) ) == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
85 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
86 | 0 | "%s: unable to clear strings array.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | goto on_error; |
90 | 0 | } |
91 | 46.3k | return( 1 ); |
92 | | |
93 | 0 | on_error: |
94 | 0 | if( *strings_array != NULL ) |
95 | 0 | { |
96 | 0 | memory_free( |
97 | 0 | *strings_array ); |
98 | |
|
99 | 0 | *strings_array = NULL; |
100 | 0 | } |
101 | 0 | return( -1 ); |
102 | 46.3k | } |
103 | | |
104 | | /* Frees a strings array |
105 | | * Returns 1 if successful or -1 on error |
106 | | */ |
107 | | int libevt_strings_array_free( |
108 | | libevt_strings_array_t **strings_array, |
109 | | libcerror_error_t **error ) |
110 | 46.3k | { |
111 | 46.3k | static char *function = "libevt_strings_array_free"; |
112 | | |
113 | 46.3k | if( strings_array == NULL ) |
114 | 0 | { |
115 | 0 | libcerror_error_set( |
116 | 0 | error, |
117 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
118 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
119 | 0 | "%s: invalid strings array.", |
120 | 0 | function ); |
121 | |
|
122 | 0 | return( -1 ); |
123 | 0 | } |
124 | 46.3k | if( *strings_array != NULL ) |
125 | 46.3k | { |
126 | 46.3k | if( ( *strings_array )->string_sizes != NULL ) |
127 | 43.3k | { |
128 | 43.3k | memory_free( |
129 | 43.3k | ( *strings_array )->string_sizes ); |
130 | 43.3k | } |
131 | 46.3k | if( ( *strings_array )->strings != NULL ) |
132 | 43.3k | { |
133 | 43.3k | memory_free( |
134 | 43.3k | ( *strings_array )->strings ); |
135 | 43.3k | } |
136 | 46.3k | if( ( *strings_array )->strings_data != NULL ) |
137 | 43.3k | { |
138 | 43.3k | memory_free( |
139 | 43.3k | ( *strings_array )->strings_data ); |
140 | 43.3k | } |
141 | 46.3k | memory_free( |
142 | 46.3k | *strings_array ); |
143 | | |
144 | 46.3k | *strings_array = NULL; |
145 | 46.3k | } |
146 | 46.3k | return( 1 ); |
147 | 46.3k | } |
148 | | |
149 | | /* Reads the strings array data |
150 | | * Returns 1 if successful or -1 on error |
151 | | */ |
152 | | int libevt_strings_array_read_data( |
153 | | libevt_strings_array_t *strings_array, |
154 | | const uint8_t *data, |
155 | | size_t data_size, |
156 | | libcerror_error_t **error ) |
157 | 46.3k | { |
158 | 46.3k | static char *function = "libevt_strings_array_read_data"; |
159 | 46.3k | size_t data_offset = 0; |
160 | 46.3k | size_t string_offset = 0; |
161 | 46.3k | int number_of_strings = 0; |
162 | 46.3k | int string_index = 0; |
163 | | |
164 | 46.3k | if( strings_array == 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 strings array.", |
171 | 0 | function ); |
172 | |
|
173 | 0 | return( -1 ); |
174 | 0 | } |
175 | 46.3k | if( strings_array->strings_data != NULL ) |
176 | 0 | { |
177 | 0 | libcerror_error_set( |
178 | 0 | error, |
179 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
180 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
181 | 0 | "%s: invalid strings array - strings data value already set.", |
182 | 0 | function ); |
183 | |
|
184 | 0 | return( -1 ); |
185 | 0 | } |
186 | 46.3k | if( data == NULL ) |
187 | 0 | { |
188 | 0 | libcerror_error_set( |
189 | 0 | error, |
190 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
191 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
192 | 0 | "%s: invalid data.", |
193 | 0 | function ); |
194 | |
|
195 | 0 | return( -1 ); |
196 | 0 | } |
197 | 46.3k | if( ( data_size < 2 ) |
198 | 44.6k | || ( data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
199 | 1.74k | { |
200 | 1.74k | libcerror_error_set( |
201 | 1.74k | error, |
202 | 1.74k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
203 | 1.74k | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
204 | 1.74k | "%s: invalid data size value out of bounds.", |
205 | 1.74k | function ); |
206 | | |
207 | 1.74k | return( -1 ); |
208 | 1.74k | } |
209 | 44.6k | if( ( data_size % 2 ) != 0 ) |
210 | 1.28k | { |
211 | 1.28k | libcerror_error_set( |
212 | 1.28k | error, |
213 | 1.28k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
214 | 1.28k | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
215 | 1.28k | "%s: invalid data size - value must be a multitude of 2.", |
216 | 1.28k | function ); |
217 | | |
218 | 1.28k | return( -1 ); |
219 | 1.28k | } |
220 | | #if defined( HAVE_DEBUG_OUTPUT ) |
221 | | if( libcnotify_verbose != 0 ) |
222 | | { |
223 | | libcnotify_printf( |
224 | | "%s: strings array data:\n", |
225 | | function ); |
226 | | libcnotify_print_data( |
227 | | data, |
228 | | data_size, |
229 | | 0 ); |
230 | | } |
231 | | #endif |
232 | 43.3k | for( data_offset = 0; |
233 | 10.0M | data_offset < data_size; |
234 | 9.97M | data_offset += 2 ) |
235 | 9.97M | { |
236 | 9.97M | if( ( data[ data_offset ] == 0 ) |
237 | 4.36M | && ( data[ data_offset + 1 ] == 0 ) ) |
238 | 3.16M | { |
239 | 3.16M | number_of_strings++; |
240 | 3.16M | } |
241 | 9.97M | } |
242 | | #if defined( HAVE_DEBUG_OUTPUT ) |
243 | | if( libcnotify_verbose != 0 ) |
244 | | { |
245 | | libcnotify_printf( |
246 | | "%s: number of strings\t\t\t: %d\n", |
247 | | function, |
248 | | number_of_strings ); |
249 | | |
250 | | libcnotify_printf( |
251 | | "\n" ); |
252 | | } |
253 | | #endif |
254 | 43.3k | strings_array->strings_data = (uint8_t *) memory_allocate( |
255 | 43.3k | sizeof( uint8_t ) * data_size ); |
256 | | |
257 | 43.3k | if( strings_array->strings_data == NULL ) |
258 | 0 | { |
259 | 0 | libcerror_error_set( |
260 | 0 | error, |
261 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
262 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
263 | 0 | "%s: unable to create strings data.", |
264 | 0 | function ); |
265 | |
|
266 | 0 | goto on_error; |
267 | 0 | } |
268 | 43.3k | if( memory_copy( |
269 | 43.3k | strings_array->strings_data, |
270 | 43.3k | data, |
271 | 43.3k | sizeof( uint8_t ) * data_size ) == NULL ) |
272 | 0 | { |
273 | 0 | libcerror_error_set( |
274 | 0 | error, |
275 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
276 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
277 | 0 | "%s: unable to copy strings data.", |
278 | 0 | function ); |
279 | |
|
280 | 0 | goto on_error; |
281 | 0 | } |
282 | 43.3k | strings_array->strings_data_size = data_size; |
283 | | |
284 | 43.3k | strings_array->strings = (uint8_t **) memory_allocate( |
285 | 43.3k | sizeof( uint8_t* ) * number_of_strings ); |
286 | | |
287 | 43.3k | if( strings_array->strings == NULL ) |
288 | 0 | { |
289 | 0 | libcerror_error_set( |
290 | 0 | error, |
291 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
292 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
293 | 0 | "%s: unable to create strings.", |
294 | 0 | function ); |
295 | |
|
296 | 0 | goto on_error; |
297 | 0 | } |
298 | 43.3k | if( memory_set( |
299 | 43.3k | strings_array->strings, |
300 | 43.3k | 0, |
301 | 43.3k | sizeof( uint8_t* ) * number_of_strings ) == NULL ) |
302 | 0 | { |
303 | 0 | libcerror_error_set( |
304 | 0 | error, |
305 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
306 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
307 | 0 | "%s: unable to clear strings.", |
308 | 0 | function ); |
309 | |
|
310 | 0 | goto on_error; |
311 | 0 | } |
312 | 43.3k | strings_array->string_sizes = (size_t *) memory_allocate( |
313 | 43.3k | sizeof( size_t ) * number_of_strings ); |
314 | | |
315 | 43.3k | if( strings_array->string_sizes == NULL ) |
316 | 0 | { |
317 | 0 | libcerror_error_set( |
318 | 0 | error, |
319 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
320 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
321 | 0 | "%s: unable to create string sizes.", |
322 | 0 | function ); |
323 | |
|
324 | 0 | goto on_error; |
325 | 0 | } |
326 | 43.3k | if( memory_set( |
327 | 43.3k | strings_array->string_sizes, |
328 | 43.3k | 0, |
329 | 43.3k | sizeof( uint8_t* ) * number_of_strings ) == NULL ) |
330 | 0 | { |
331 | 0 | libcerror_error_set( |
332 | 0 | error, |
333 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
334 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
335 | 0 | "%s: unable to clear string sizes.", |
336 | 0 | function ); |
337 | |
|
338 | 0 | goto on_error; |
339 | 0 | } |
340 | 43.3k | for( data_offset = 0; |
341 | 10.0M | data_offset < strings_array->strings_data_size; |
342 | 9.97M | data_offset += 2 ) |
343 | 9.97M | { |
344 | 9.97M | if( ( strings_array->strings_data[ data_offset ] == 0 ) |
345 | 4.36M | && ( strings_array->strings_data[ data_offset + 1 ] == 0 ) ) |
346 | 3.16M | { |
347 | 3.16M | strings_array->strings[ string_index ] = &( strings_array->strings_data[ string_offset ] ); |
348 | 3.16M | strings_array->string_sizes[ string_index ] = ( data_offset + 2 ) - string_offset; |
349 | | |
350 | | #if defined( HAVE_DEBUG_OUTPUT ) |
351 | | if( libcnotify_verbose != 0 ) |
352 | | { |
353 | | libcnotify_printf( |
354 | | "%s: string: %d data:\n", |
355 | | function, |
356 | | string_index ); |
357 | | libcnotify_print_data( |
358 | | strings_array->strings[ string_index ], |
359 | | strings_array->string_sizes[ string_index ], |
360 | | 0 ); |
361 | | } |
362 | | #endif |
363 | 3.16M | string_offset = data_offset + 2; |
364 | | |
365 | 3.16M | string_index++; |
366 | 3.16M | } |
367 | 9.97M | } |
368 | 43.3k | strings_array->number_of_strings = number_of_strings; |
369 | | |
370 | 43.3k | return( 1 ); |
371 | | |
372 | 0 | on_error: |
373 | 0 | if( strings_array->string_sizes != NULL ) |
374 | 0 | { |
375 | 0 | memory_free( |
376 | 0 | strings_array->string_sizes ); |
377 | |
|
378 | 0 | strings_array->string_sizes = NULL; |
379 | 0 | } |
380 | 0 | if( strings_array->strings != NULL ) |
381 | 0 | { |
382 | 0 | memory_free( |
383 | 0 | strings_array->strings ); |
384 | |
|
385 | 0 | strings_array->strings = NULL; |
386 | 0 | } |
387 | 0 | if( strings_array->strings_data != NULL ) |
388 | 0 | { |
389 | 0 | memory_free( |
390 | 0 | strings_array->strings_data ); |
391 | |
|
392 | 0 | strings_array->strings_data = NULL; |
393 | 0 | } |
394 | 0 | strings_array->strings_data_size = 0; |
395 | |
|
396 | 0 | return( -1 ); |
397 | 43.3k | } |
398 | | |
399 | | /* Retrieves the number of strings |
400 | | * Returns 1 if successful or -1 on error |
401 | | */ |
402 | | int libevt_strings_array_get_number_of_strings( |
403 | | libevt_strings_array_t *strings_array, |
404 | | int *number_of_strings, |
405 | | libcerror_error_t **error ) |
406 | 0 | { |
407 | 0 | static char *function = "libevt_strings_array_get_number_of_strings"; |
408 | |
|
409 | 0 | if( strings_array == NULL ) |
410 | 0 | { |
411 | 0 | libcerror_error_set( |
412 | 0 | error, |
413 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
414 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
415 | 0 | "%s: invalid strings array.", |
416 | 0 | function ); |
417 | |
|
418 | 0 | return( -1 ); |
419 | 0 | } |
420 | 0 | if( number_of_strings == NULL ) |
421 | 0 | { |
422 | 0 | libcerror_error_set( |
423 | 0 | error, |
424 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
425 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
426 | 0 | "%s: invalid number of strings.", |
427 | 0 | function ); |
428 | |
|
429 | 0 | return( -1 ); |
430 | 0 | } |
431 | 0 | *number_of_strings = strings_array->number_of_strings; |
432 | |
|
433 | 0 | return( 1 ); |
434 | 0 | } |
435 | | |
436 | | /* Retrieves the size of a specific UTF-8 encoded string |
437 | | * The returned size includes the end of string character |
438 | | * Returns 1 if successful or -1 on error |
439 | | */ |
440 | | int libevt_strings_array_get_utf8_string_size( |
441 | | libevt_strings_array_t *strings_array, |
442 | | int string_index, |
443 | | size_t *utf8_string_size, |
444 | | libcerror_error_t **error ) |
445 | 0 | { |
446 | 0 | static char *function = "libevt_strings_array_get_utf8_string_size"; |
447 | |
|
448 | 0 | if( strings_array == NULL ) |
449 | 0 | { |
450 | 0 | libcerror_error_set( |
451 | 0 | error, |
452 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
453 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
454 | 0 | "%s: invalid record values.", |
455 | 0 | function ); |
456 | |
|
457 | 0 | return( -1 ); |
458 | 0 | } |
459 | 0 | if( strings_array->strings == NULL ) |
460 | 0 | { |
461 | 0 | libcerror_error_set( |
462 | 0 | error, |
463 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
464 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
465 | 0 | "%s: invalid string index value out of bounds.", |
466 | 0 | function ); |
467 | |
|
468 | 0 | return( -1 ); |
469 | 0 | } |
470 | 0 | if( ( string_index < 0 ) |
471 | 0 | || ( string_index >= strings_array->number_of_strings ) ) |
472 | 0 | { |
473 | 0 | libcerror_error_set( |
474 | 0 | error, |
475 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
476 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
477 | 0 | "%s: invalid strings index value out of bounds.", |
478 | 0 | function ); |
479 | |
|
480 | 0 | return( -1 ); |
481 | 0 | } |
482 | 0 | if( libuna_utf8_string_size_from_utf16_stream( |
483 | 0 | strings_array->strings[ string_index ], |
484 | 0 | strings_array->string_sizes[ string_index ], |
485 | 0 | LIBUNA_ENDIAN_LITTLE, |
486 | 0 | utf8_string_size, |
487 | 0 | error ) != 1 ) |
488 | 0 | { |
489 | 0 | libcerror_error_set( |
490 | 0 | error, |
491 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
492 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
493 | 0 | "%s: unable to determine size of UTF-8 string: %d.", |
494 | 0 | function, |
495 | 0 | string_index ); |
496 | |
|
497 | 0 | return( -1 ); |
498 | 0 | } |
499 | 0 | return( 1 ); |
500 | 0 | } |
501 | | |
502 | | /* Retrieves a specific UTF-8 encoded string |
503 | | * The size should include the end of string character |
504 | | * Returns 1 if successful or -1 on error |
505 | | */ |
506 | | int libevt_strings_array_get_utf8_string( |
507 | | libevt_strings_array_t *strings_array, |
508 | | int string_index, |
509 | | uint8_t *utf8_string, |
510 | | size_t utf8_string_size, |
511 | | libcerror_error_t **error ) |
512 | 0 | { |
513 | 0 | static char *function = "libevt_values_record_get_utf8_string"; |
514 | |
|
515 | 0 | if( strings_array == NULL ) |
516 | 0 | { |
517 | 0 | libcerror_error_set( |
518 | 0 | error, |
519 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
520 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
521 | 0 | "%s: invalid record values.", |
522 | 0 | function ); |
523 | |
|
524 | 0 | return( -1 ); |
525 | 0 | } |
526 | 0 | if( strings_array->strings == NULL ) |
527 | 0 | { |
528 | 0 | libcerror_error_set( |
529 | 0 | error, |
530 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
531 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
532 | 0 | "%s: invalid string index value out of bounds.", |
533 | 0 | function ); |
534 | |
|
535 | 0 | return( -1 ); |
536 | 0 | } |
537 | 0 | if( ( string_index < 0 ) |
538 | 0 | || ( string_index >= strings_array->number_of_strings ) ) |
539 | 0 | { |
540 | 0 | libcerror_error_set( |
541 | 0 | error, |
542 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
543 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
544 | 0 | "%s: invalid strings index value out of bounds.", |
545 | 0 | function ); |
546 | |
|
547 | 0 | return( -1 ); |
548 | 0 | } |
549 | 0 | if( libuna_utf8_string_copy_from_utf16_stream( |
550 | 0 | (libuna_utf8_character_t *) utf8_string, |
551 | 0 | utf8_string_size, |
552 | 0 | strings_array->strings[ string_index ], |
553 | 0 | strings_array->string_sizes[ string_index ], |
554 | 0 | LIBUNA_ENDIAN_LITTLE, |
555 | 0 | error ) != 1 ) |
556 | 0 | { |
557 | 0 | libcerror_error_set( |
558 | 0 | error, |
559 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
560 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
561 | 0 | "%s: unable to set UTF-8 string: %d.", |
562 | 0 | function, |
563 | 0 | string_index ); |
564 | |
|
565 | 0 | return( -1 ); |
566 | 0 | } |
567 | 0 | return( 1 ); |
568 | 0 | } |
569 | | |
570 | | /* Retrieves the size of a specific UTF-16 encoded string |
571 | | * The returned size includes the end of string character |
572 | | * Returns 1 if successful or -1 on error |
573 | | */ |
574 | | int libevt_strings_array_get_utf16_string_size( |
575 | | libevt_strings_array_t *strings_array, |
576 | | int string_index, |
577 | | size_t *utf16_string_size, |
578 | | libcerror_error_t **error ) |
579 | 0 | { |
580 | 0 | static char *function = "libevt_strings_array_get_utf16_string_size"; |
581 | |
|
582 | 0 | if( strings_array == NULL ) |
583 | 0 | { |
584 | 0 | libcerror_error_set( |
585 | 0 | error, |
586 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
587 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
588 | 0 | "%s: invalid record values.", |
589 | 0 | function ); |
590 | |
|
591 | 0 | return( -1 ); |
592 | 0 | } |
593 | 0 | if( strings_array->strings == NULL ) |
594 | 0 | { |
595 | 0 | libcerror_error_set( |
596 | 0 | error, |
597 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
598 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
599 | 0 | "%s: invalid string index value out of bounds.", |
600 | 0 | function ); |
601 | |
|
602 | 0 | return( -1 ); |
603 | 0 | } |
604 | 0 | if( ( string_index < 0 ) |
605 | 0 | || ( string_index >= strings_array->number_of_strings ) ) |
606 | 0 | { |
607 | 0 | libcerror_error_set( |
608 | 0 | error, |
609 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
610 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
611 | 0 | "%s: invalid strings index value out of bounds.", |
612 | 0 | function ); |
613 | |
|
614 | 0 | return( -1 ); |
615 | 0 | } |
616 | 0 | if( libuna_utf16_string_size_from_utf16_stream( |
617 | 0 | strings_array->strings[ string_index ], |
618 | 0 | strings_array->string_sizes[ string_index ], |
619 | 0 | LIBUNA_ENDIAN_LITTLE, |
620 | 0 | utf16_string_size, |
621 | 0 | error ) != 1 ) |
622 | 0 | { |
623 | 0 | libcerror_error_set( |
624 | 0 | error, |
625 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
626 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
627 | 0 | "%s: unable to determine size of UTF-16 string: %d.", |
628 | 0 | function, |
629 | 0 | string_index ); |
630 | |
|
631 | 0 | return( -1 ); |
632 | 0 | } |
633 | 0 | return( 1 ); |
634 | 0 | } |
635 | | |
636 | | /* Retrieves a specific UTF-16 encoded string |
637 | | * The size should include the end of string character |
638 | | * Returns 1 if successful or -1 on error |
639 | | */ |
640 | | int libevt_strings_array_get_utf16_string( |
641 | | libevt_strings_array_t *strings_array, |
642 | | int string_index, |
643 | | uint16_t *utf16_string, |
644 | | size_t utf16_string_size, |
645 | | libcerror_error_t **error ) |
646 | 0 | { |
647 | 0 | static char *function = "libevt_values_record_get_utf16_string"; |
648 | |
|
649 | 0 | if( strings_array == NULL ) |
650 | 0 | { |
651 | 0 | libcerror_error_set( |
652 | 0 | error, |
653 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
654 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
655 | 0 | "%s: invalid record values.", |
656 | 0 | function ); |
657 | |
|
658 | 0 | return( -1 ); |
659 | 0 | } |
660 | 0 | if( strings_array->strings == NULL ) |
661 | 0 | { |
662 | 0 | libcerror_error_set( |
663 | 0 | error, |
664 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
665 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
666 | 0 | "%s: invalid string index value out of bounds.", |
667 | 0 | function ); |
668 | |
|
669 | 0 | return( -1 ); |
670 | 0 | } |
671 | 0 | if( ( string_index < 0 ) |
672 | 0 | || ( string_index >= strings_array->number_of_strings ) ) |
673 | 0 | { |
674 | 0 | libcerror_error_set( |
675 | 0 | error, |
676 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
677 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
678 | 0 | "%s: invalid strings index value out of bounds.", |
679 | 0 | function ); |
680 | |
|
681 | 0 | return( -1 ); |
682 | 0 | } |
683 | 0 | if( libuna_utf16_string_copy_from_utf16_stream( |
684 | 0 | (libuna_utf16_character_t *) utf16_string, |
685 | 0 | utf16_string_size, |
686 | 0 | strings_array->strings[ string_index ], |
687 | 0 | strings_array->string_sizes[ string_index ], |
688 | 0 | LIBUNA_ENDIAN_LITTLE, |
689 | 0 | error ) != 1 ) |
690 | 0 | { |
691 | 0 | libcerror_error_set( |
692 | 0 | error, |
693 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
694 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
695 | 0 | "%s: unable to set UTF-16 string: %d.", |
696 | 0 | function, |
697 | 0 | string_index ); |
698 | |
|
699 | 0 | return( -1 ); |
700 | 0 | } |
701 | 0 | return( 1 ); |
702 | 0 | } |
703 | | |