/src/libmsiecf/libfvalue/libfvalue_string.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * String value 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 <memory.h>  | 
24  |  | #include <types.h>  | 
25  |  |  | 
26  |  | #include "libfvalue_codepage.h"  | 
27  |  | #include "libfvalue_definitions.h"  | 
28  |  | #include "libfvalue_libcerror.h"  | 
29  |  | #include "libfvalue_libcnotify.h"  | 
30  |  | #include "libfvalue_libuna.h"  | 
31  |  | #include "libfvalue_split_utf16_string.h"  | 
32  |  | #include "libfvalue_split_utf8_string.h"  | 
33  |  | #include "libfvalue_string.h"  | 
34  |  | #include "libfvalue_types.h"  | 
35  |  |  | 
36  |  | /* Creates a string  | 
37  |  |  * Make sure the value string is referencing, is set to NULL  | 
38  |  |  * Returns 1 if successful or -1 on error  | 
39  |  |  */  | 
40  |  | int libfvalue_string_initialize(  | 
41  |  |      libfvalue_string_t **string,  | 
42  |  |      libcerror_error_t **error )  | 
43  | 0  | { | 
44  | 0  |   static char *function = "libfvalue_string_initialize";  | 
45  |  | 
  | 
46  | 0  |   if( string == 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 string.",  | 
53  | 0  |      function );  | 
54  |  | 
  | 
55  | 0  |     return( -1 );  | 
56  | 0  |   }  | 
57  | 0  |   if( *string != 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 string value already set.",  | 
64  | 0  |      function );  | 
65  |  | 
  | 
66  | 0  |     return( -1 );  | 
67  | 0  |   }  | 
68  | 0  |   *string = memory_allocate_structure(  | 
69  | 0  |              libfvalue_string_t );  | 
70  |  | 
  | 
71  | 0  |   if( *string == 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 string.",  | 
78  | 0  |      function );  | 
79  |  | 
  | 
80  | 0  |     goto on_error;  | 
81  | 0  |   }  | 
82  | 0  |   if( memory_set(  | 
83  | 0  |        *string,  | 
84  | 0  |        0,  | 
85  | 0  |        sizeof( libfvalue_string_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 string.",  | 
92  | 0  |      function );  | 
93  |  | 
  | 
94  | 0  |     goto on_error;  | 
95  | 0  |   }  | 
96  | 0  |   ( *string )->codepage = LIBFVALUE_CODEPAGE_UTF8;  | 
97  |  | 
  | 
98  | 0  |   return( 1 );  | 
99  |  |  | 
100  | 0  | on_error:  | 
101  | 0  |   if( *string != NULL )  | 
102  | 0  |   { | 
103  | 0  |     memory_free(  | 
104  | 0  |      *string );  | 
105  |  | 
  | 
106  | 0  |     *string = NULL;  | 
107  | 0  |   }  | 
108  | 0  |   return( -1 );  | 
109  | 0  | }  | 
110  |  |  | 
111  |  | /* Frees a string  | 
112  |  |  * Returns 1 if successful or -1 on error  | 
113  |  |  */  | 
114  |  | int libfvalue_string_free(  | 
115  |  |      libfvalue_string_t **string,  | 
116  |  |      libcerror_error_t **error )  | 
117  | 0  | { | 
118  | 0  |   static char *function = "libfvalue_string_free";  | 
119  |  | 
  | 
120  | 0  |   if( string == NULL )  | 
121  | 0  |   { | 
122  | 0  |     libcerror_error_set(  | 
123  | 0  |      error,  | 
124  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
125  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
126  | 0  |      "%s: invalid string.",  | 
127  | 0  |      function );  | 
128  |  | 
  | 
129  | 0  |     return( -1 );  | 
130  | 0  |   }  | 
131  | 0  |   if( *string != NULL )  | 
132  | 0  |   { | 
133  | 0  |     if( ( *string )->data != NULL )  | 
134  | 0  |     { | 
135  | 0  |       if( ( ( *string )->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
136  | 0  |       { | 
137  | 0  |         memory_free(  | 
138  | 0  |          ( *string )->data );  | 
139  | 0  |       }  | 
140  | 0  |     }  | 
141  | 0  |     memory_free(  | 
142  | 0  |      *string );  | 
143  |  | 
  | 
144  | 0  |     *string = NULL;  | 
145  | 0  |   }  | 
146  | 0  |   return( 1 );  | 
147  | 0  | }  | 
148  |  |  | 
149  |  | /* Clones a string  | 
150  |  |  * Returns 1 if successful or -1 on error  | 
151  |  |  */  | 
152  |  | int libfvalue_string_clone(  | 
153  |  |      libfvalue_string_t **destination_string,  | 
154  |  |      libfvalue_string_t *source_string,  | 
155  |  |      libcerror_error_t **error )  | 
156  | 0  | { | 
157  | 0  |   static char *function = "libfvalue_string_clone";  | 
158  |  | 
  | 
159  | 0  |   if( destination_string == NULL )  | 
160  | 0  |   { | 
161  | 0  |     libcerror_error_set(  | 
162  | 0  |      error,  | 
163  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
164  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
165  | 0  |      "%s: invalid destination string.",  | 
166  | 0  |      function );  | 
167  |  | 
  | 
168  | 0  |     return( -1 );  | 
169  | 0  |   }  | 
170  | 0  |   if( *destination_string != NULL )  | 
171  | 0  |   { | 
172  | 0  |     libcerror_error_set(  | 
173  | 0  |      error,  | 
174  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
175  | 0  |      LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,  | 
176  | 0  |      "%s: destination string already set.",  | 
177  | 0  |      function );  | 
178  |  | 
  | 
179  | 0  |     return( -1 );  | 
180  | 0  |   }  | 
181  | 0  |   if( source_string == NULL )  | 
182  | 0  |   { | 
183  | 0  |     *destination_string = NULL;  | 
184  |  | 
  | 
185  | 0  |     return( 1 );  | 
186  | 0  |   }  | 
187  | 0  |   *destination_string = memory_allocate_structure(  | 
188  | 0  |                          libfvalue_string_t );  | 
189  |  | 
  | 
190  | 0  |   if( *destination_string == NULL )  | 
191  | 0  |   { | 
192  | 0  |     libcerror_error_set(  | 
193  | 0  |      error,  | 
194  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
195  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
196  | 0  |      "%s: unable to create destination string.",  | 
197  | 0  |      function );  | 
198  |  | 
  | 
199  | 0  |     goto on_error;  | 
200  | 0  |   }  | 
201  | 0  |   if( memory_set(  | 
202  | 0  |        *destination_string,  | 
203  | 0  |        0,  | 
204  | 0  |        sizeof( libfvalue_string_t ) ) == NULL )  | 
205  | 0  |   { | 
206  | 0  |     libcerror_error_set(  | 
207  | 0  |      error,  | 
208  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
209  | 0  |      LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
210  | 0  |      "%s: unable to clear destination string.",  | 
211  | 0  |      function );  | 
212  |  | 
  | 
213  | 0  |     memory_free(  | 
214  | 0  |      *destination_string );  | 
215  |  | 
  | 
216  | 0  |     *destination_string = NULL;  | 
217  |  | 
  | 
218  | 0  |     return( -1 );  | 
219  | 0  |   }  | 
220  | 0  |   if( ( source_string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) == 0 )  | 
221  | 0  |   { | 
222  | 0  |     ( *destination_string )->data      = source_string->data;  | 
223  | 0  |     ( *destination_string )->data_size = source_string->data_size;  | 
224  | 0  |   }  | 
225  | 0  |   else  | 
226  | 0  |   { | 
227  | 0  |     ( *destination_string )->data = (uint8_t *) memory_allocate(  | 
228  | 0  |                                                  sizeof( uint8_t ) * source_string->data_size );  | 
229  |  | 
  | 
230  | 0  |     if( ( *destination_string )->data == NULL )  | 
231  | 0  |     { | 
232  | 0  |       libcerror_error_set(  | 
233  | 0  |        error,  | 
234  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
235  | 0  |        LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
236  | 0  |        "%s: unable to create destination string data.",  | 
237  | 0  |        function );  | 
238  |  | 
  | 
239  | 0  |       goto on_error;  | 
240  | 0  |     }  | 
241  | 0  |     ( *destination_string )->data_size = source_string->data_size;  | 
242  |  | 
  | 
243  | 0  |     ( *destination_string )->flags |= LIBFVALUE_VALUE_FLAG_DATA_MANAGED;  | 
244  |  | 
  | 
245  | 0  |     if( memory_copy(  | 
246  | 0  |          ( *destination_string )->data,  | 
247  | 0  |          source_string->data,  | 
248  | 0  |          sizeof( uint8_t ) * source_string->data_size ) == NULL )  | 
249  | 0  |     { | 
250  | 0  |       libcerror_error_set(  | 
251  | 0  |        error,  | 
252  | 0  |        LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
253  | 0  |        LIBCERROR_MEMORY_ERROR_COPY_FAILED,  | 
254  | 0  |        "%s: unable to copy string data.",  | 
255  | 0  |        function );  | 
256  |  | 
  | 
257  | 0  |       goto on_error;  | 
258  | 0  |     }  | 
259  | 0  |   }  | 
260  | 0  |   ( *destination_string )->codepage = source_string->codepage;  | 
261  |  | 
  | 
262  | 0  |   return( 1 );  | 
263  |  |  | 
264  | 0  | on_error:  | 
265  | 0  |   if( *destination_string != NULL )  | 
266  | 0  |   { | 
267  | 0  |     if( ( ( *destination_string )->data != NULL )  | 
268  | 0  |      && ( ( *destination_string )->data != source_string->data ) )  | 
269  | 0  |     { | 
270  | 0  |       memory_free(  | 
271  | 0  |        ( *destination_string )->data );  | 
272  | 0  |     }  | 
273  | 0  |     memory_free(  | 
274  | 0  |      *destination_string );  | 
275  |  | 
  | 
276  | 0  |     *destination_string = NULL;  | 
277  | 0  |   }  | 
278  | 0  |   return( -1 );  | 
279  | 0  | }  | 
280  |  |  | 
281  |  | /* Copies the string from a byte stream  | 
282  |  |  * Returns 1 if successful or -1 on error  | 
283  |  |  */  | 
284  |  | int libfvalue_string_copy_from_byte_stream(  | 
285  |  |      libfvalue_string_t *string,  | 
286  |  |      const uint8_t *byte_stream,  | 
287  |  |      size_t byte_stream_size,  | 
288  |  |      int encoding,  | 
289  |  |      libcerror_error_t **error )  | 
290  | 0  | { | 
291  | 0  |   static char *function = "libfvalue_string_copy_from_byte_stream";  | 
292  |  | 
  | 
293  | 0  |   if( string == NULL )  | 
294  | 0  |   { | 
295  | 0  |     libcerror_error_set(  | 
296  | 0  |      error,  | 
297  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
298  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
299  | 0  |      "%s: invalid string.",  | 
300  | 0  |      function );  | 
301  |  | 
  | 
302  | 0  |     return( -1 );  | 
303  | 0  |   }  | 
304  | 0  |   if( byte_stream == NULL )  | 
305  | 0  |   { | 
306  | 0  |     libcerror_error_set(  | 
307  | 0  |      error,  | 
308  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
309  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
310  | 0  |      "%s: invalid byte stream.",  | 
311  | 0  |      function );  | 
312  |  | 
  | 
313  | 0  |     return( -1 );  | 
314  | 0  |   }  | 
315  | 0  |   if( byte_stream_size > (size_t) SSIZE_MAX )  | 
316  | 0  |   { | 
317  | 0  |     libcerror_error_set(  | 
318  | 0  |      error,  | 
319  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
320  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
321  | 0  |      "%s: invalid byte stream size value exceeds maximum.",  | 
322  | 0  |      function );  | 
323  |  | 
  | 
324  | 0  |     return( -1 );  | 
325  | 0  |   }  | 
326  | 0  |   if( ( encoding != LIBFVALUE_CODEPAGE_ASCII )  | 
327  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_1 )  | 
328  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_2 )  | 
329  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_3 )  | 
330  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_4 )  | 
331  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_5 )  | 
332  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_6 )  | 
333  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_7 )  | 
334  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_8 )  | 
335  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_9 )  | 
336  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_10 )  | 
337  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_11 )  | 
338  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_13 )  | 
339  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_14 )  | 
340  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_15 )  | 
341  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_ISO_8859_16 )  | 
342  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_KOI8_R )  | 
343  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_KOI8_U )  | 
344  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
345  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN )  | 
346  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
347  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN )  | 
348  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF7 )  | 
349  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_UTF8 )  | 
350  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_SCSU )  | 
351  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_874 )  | 
352  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_932 )  | 
353  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_936 )  | 
354  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_949 )  | 
355  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_950 )  | 
356  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1250 )  | 
357  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1251 )  | 
358  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1252 )  | 
359  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1253 )  | 
360  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1254 )  | 
361  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1255 )  | 
362  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1256 )  | 
363  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1257 )  | 
364  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_WINDOWS_1258 )  | 
365  | 0  |    && ( encoding != LIBFVALUE_CODEPAGE_1200_MIXED ) )  | 
366  | 0  |   { | 
367  | 0  |     libcerror_error_set(  | 
368  | 0  |      error,  | 
369  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
370  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
371  | 0  |      "%s: unsupported encoding.",  | 
372  | 0  |      function );  | 
373  |  | 
  | 
374  | 0  |     return( -1 );  | 
375  | 0  |   }  | 
376  | 0  |   if( string->data != NULL )  | 
377  | 0  |   { | 
378  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
379  | 0  |     { | 
380  | 0  |       memory_free(  | 
381  | 0  |        string->data );  | 
382  |  | 
  | 
383  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
384  | 0  |     }  | 
385  | 0  |     string->data      = NULL;  | 
386  | 0  |     string->data_size = 0;  | 
387  | 0  |   }  | 
388  | 0  |   string->data_size = byte_stream_size;  | 
389  |  | 
  | 
390  | 0  |   string->data = (uint8_t *) memory_allocate(  | 
391  | 0  |                               sizeof( uint8_t ) * string->data_size );  | 
392  |  | 
  | 
393  | 0  |   if( string->data == NULL )  | 
394  | 0  |   { | 
395  | 0  |     libcerror_error_set(  | 
396  | 0  |      error,  | 
397  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
398  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
399  | 0  |      "%s: unable to create string data.",  | 
400  | 0  |      function );  | 
401  |  | 
  | 
402  | 0  |     goto on_error;  | 
403  | 0  |   }  | 
404  | 0  |   string->flags |= LIBFVALUE_VALUE_FLAG_DATA_MANAGED;  | 
405  |  | 
  | 
406  | 0  |   if( memory_copy(  | 
407  | 0  |        string->data,  | 
408  | 0  |        byte_stream,  | 
409  | 0  |        sizeof( uint8_t ) * string->data_size ) == NULL )  | 
410  | 0  |   { | 
411  | 0  |     libcerror_error_set(  | 
412  | 0  |      error,  | 
413  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
414  | 0  |      LIBCERROR_MEMORY_ERROR_COPY_FAILED,  | 
415  | 0  |      "%s: unable to copy byte stream.",  | 
416  | 0  |      function );  | 
417  |  | 
  | 
418  | 0  |     goto on_error;  | 
419  | 0  |   }  | 
420  | 0  |   string->codepage = encoding;  | 
421  |  | 
  | 
422  | 0  |   return( 1 );  | 
423  |  |  | 
424  | 0  | on_error:  | 
425  | 0  |   if( string->data != NULL )  | 
426  | 0  |   { | 
427  | 0  |     memory_free(  | 
428  | 0  |      string->data );  | 
429  |  | 
  | 
430  | 0  |     string->data = NULL;  | 
431  | 0  |   }  | 
432  | 0  |   string->data_size = 0;  | 
433  |  | 
  | 
434  | 0  |   return( -1 );  | 
435  | 0  | }  | 
436  |  |  | 
437  |  | /* Copies the string from an UTF-8 encoded string  | 
438  |  |  * Returns 1 if successful or -1 on error  | 
439  |  |  */  | 
440  |  | int libfvalue_string_copy_from_utf8_string_with_index(  | 
441  |  |      libfvalue_string_t *string,  | 
442  |  |      const uint8_t *utf8_string,  | 
443  |  |      size_t utf8_string_size,  | 
444  |  |      size_t *utf8_string_index,  | 
445  |  |      uint32_t string_format_flags,  | 
446  |  |      libcerror_error_t **error )  | 
447  | 0  | { | 
448  | 0  |   static char *function         = "libfvalue_string_copy_from_utf8_string_with_index";  | 
449  | 0  |   size_t safe_utf8_string_index = 0;  | 
450  | 0  |   size_t value_data_size        = 0;  | 
451  | 0  |   int byte_order                = 0;  | 
452  |  | 
  | 
453  | 0  |   if( string == NULL )  | 
454  | 0  |   { | 
455  | 0  |     libcerror_error_set(  | 
456  | 0  |      error,  | 
457  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
458  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
459  | 0  |      "%s: invalid string.",  | 
460  | 0  |      function );  | 
461  |  | 
  | 
462  | 0  |     return( -1 );  | 
463  | 0  |   }  | 
464  | 0  |   if( utf8_string_size > (size_t) SSIZE_MAX )  | 
465  | 0  |   { | 
466  | 0  |     libcerror_error_set(  | 
467  | 0  |      error,  | 
468  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
469  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
470  | 0  |      "%s: invalid UTF-8 string size value exceeds maximum.",  | 
471  | 0  |      function );  | 
472  |  | 
  | 
473  | 0  |     return( -1 );  | 
474  | 0  |   }  | 
475  | 0  |   if( utf8_string_index == NULL )  | 
476  | 0  |   { | 
477  | 0  |     libcerror_error_set(  | 
478  | 0  |      error,  | 
479  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
480  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
481  | 0  |      "%s: invalid UTF-8 string index.",  | 
482  | 0  |      function );  | 
483  |  | 
  | 
484  | 0  |     return( -1 );  | 
485  | 0  |   }  | 
486  | 0  |   if( *utf8_string_index >= utf8_string_size )  | 
487  | 0  |   { | 
488  | 0  |     libcerror_error_set(  | 
489  | 0  |      error,  | 
490  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
491  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
492  | 0  |      "%s: UTF-8 string is too small.",  | 
493  | 0  |      function );  | 
494  |  | 
  | 
495  | 0  |     return( -1 );  | 
496  | 0  |   }  | 
497  | 0  |   if( string_format_flags != 0 )  | 
498  | 0  |   { | 
499  | 0  |     libcerror_error_set(  | 
500  | 0  |      error,  | 
501  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
502  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
503  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
504  | 0  |      function,  | 
505  | 0  |      string_format_flags );  | 
506  |  | 
  | 
507  | 0  |     return( -1 );  | 
508  | 0  |   }  | 
509  | 0  |   safe_utf8_string_index = *utf8_string_index;  | 
510  |  | 
  | 
511  | 0  |   switch( string->codepage )  | 
512  | 0  |   { | 
513  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
514  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
515  | 0  |       libcerror_error_set(  | 
516  | 0  |        error,  | 
517  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
518  | 0  |        LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
519  | 0  |        "%s: unsupported encoding.",  | 
520  | 0  |        function );  | 
521  |  | 
  | 
522  | 0  |       goto on_error;  | 
523  |  |  | 
524  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
525  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
526  | 0  |       if( libuna_utf16_stream_size_from_utf8(  | 
527  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
528  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
529  | 0  |            &value_data_size,  | 
530  | 0  |            error ) != 1 )  | 
531  | 0  |       { | 
532  | 0  |         libcerror_error_set(  | 
533  | 0  |          error,  | 
534  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
535  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
536  | 0  |          "%s: unable to determine UTF-16 stream size of UTF-8 string.",  | 
537  | 0  |          function );  | 
538  |  | 
  | 
539  | 0  |         goto on_error;  | 
540  | 0  |       }  | 
541  | 0  |       break;  | 
542  |  |  | 
543  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
544  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
545  | 0  |       if( libuna_utf32_stream_size_from_utf8(  | 
546  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
547  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
548  | 0  |            &value_data_size,  | 
549  | 0  |            error ) != 1 )  | 
550  | 0  |       { | 
551  | 0  |         libcerror_error_set(  | 
552  | 0  |          error,  | 
553  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
554  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
555  | 0  |          "%s: unable to determine UTF-32 stream size of UTF-8 string.",  | 
556  | 0  |          function );  | 
557  |  | 
  | 
558  | 0  |         goto on_error;  | 
559  | 0  |       }  | 
560  | 0  |       break;  | 
561  |  |  | 
562  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
563  | 0  |       if( libuna_utf7_stream_size_from_utf8(  | 
564  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
565  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
566  | 0  |            &value_data_size,  | 
567  | 0  |            error ) != 1 )  | 
568  | 0  |       { | 
569  | 0  |         libcerror_error_set(  | 
570  | 0  |          error,  | 
571  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
572  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
573  | 0  |          "%s: unable to determine UTF-7 stream size of UTF-8 string.",  | 
574  | 0  |          function );  | 
575  |  | 
  | 
576  | 0  |         goto on_error;  | 
577  | 0  |       }  | 
578  | 0  |       break;  | 
579  |  |  | 
580  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
581  | 0  |       if( libuna_utf8_stream_size_from_utf8(  | 
582  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
583  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
584  | 0  |            &value_data_size,  | 
585  | 0  |            error ) != 1 )  | 
586  | 0  |       { | 
587  | 0  |         libcerror_error_set(  | 
588  | 0  |          error,  | 
589  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
590  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
591  | 0  |          "%s: unable to determine UTF-8 stream size of UTF-8 string.",  | 
592  | 0  |          function );  | 
593  |  | 
  | 
594  | 0  |         goto on_error;  | 
595  | 0  |       }  | 
596  | 0  |       break;  | 
597  |  |  | 
598  | 0  |     default:  | 
599  | 0  |       if( libuna_byte_stream_size_from_utf8(  | 
600  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
601  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
602  | 0  |            string->codepage,  | 
603  | 0  |            &value_data_size,  | 
604  | 0  |            error ) != 1 )  | 
605  | 0  |       { | 
606  | 0  |         libcerror_error_set(  | 
607  | 0  |          error,  | 
608  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
609  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
610  | 0  |          "%s: unable to determine byte stream size of UTF-8 string.",  | 
611  | 0  |          function );  | 
612  |  | 
  | 
613  | 0  |         goto on_error;  | 
614  | 0  |       }  | 
615  | 0  |       break;  | 
616  |  | 
  | 
617  | 0  |   }  | 
618  | 0  |   if( string->data != NULL )  | 
619  | 0  |   { | 
620  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
621  | 0  |     { | 
622  | 0  |       memory_free(  | 
623  | 0  |        string->data );  | 
624  |  | 
  | 
625  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
626  | 0  |     }  | 
627  | 0  |     string->data      = NULL;  | 
628  | 0  |     string->data_size = 0;  | 
629  | 0  |   }  | 
630  | 0  |   string->data_size = value_data_size;  | 
631  |  | 
  | 
632  | 0  |   string->data = (uint8_t *) memory_allocate(  | 
633  | 0  |                               sizeof( uint8_t ) * string->data_size );  | 
634  |  | 
  | 
635  | 0  |   if( string->data == NULL )  | 
636  | 0  |   { | 
637  | 0  |     libcerror_error_set(  | 
638  | 0  |      error,  | 
639  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
640  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
641  | 0  |      "%s: unable to create string data.",  | 
642  | 0  |      function );  | 
643  |  | 
  | 
644  | 0  |     goto on_error;  | 
645  | 0  |   }  | 
646  | 0  |   string->flags |= LIBFVALUE_VALUE_FLAG_DATA_MANAGED;  | 
647  |  | 
  | 
648  | 0  |   switch( string->codepage )  | 
649  | 0  |   { | 
650  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
651  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
652  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
653  | 0  |       { | 
654  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
655  | 0  |       }  | 
656  | 0  |       else  | 
657  | 0  |       { | 
658  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
659  | 0  |       }  | 
660  | 0  |       if( libuna_utf16_stream_copy_from_utf8(  | 
661  | 0  |            string->data,  | 
662  | 0  |            string->data_size,  | 
663  | 0  |            byte_order,  | 
664  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
665  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
666  | 0  |            error ) != 1 )  | 
667  | 0  |       { | 
668  | 0  |         libcerror_error_set(  | 
669  | 0  |          error,  | 
670  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
671  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
672  | 0  |          "%s: unable to copy UTF-16 stream from UTF-8 string.",  | 
673  | 0  |          function );  | 
674  |  | 
  | 
675  | 0  |         goto on_error;  | 
676  | 0  |       }  | 
677  | 0  |       break;  | 
678  |  |  | 
679  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
680  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
681  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
682  | 0  |       { | 
683  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
684  | 0  |       }  | 
685  | 0  |       else  | 
686  | 0  |       { | 
687  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
688  | 0  |       }  | 
689  | 0  |       if( libuna_utf32_stream_copy_from_utf8(  | 
690  | 0  |            string->data,  | 
691  | 0  |            string->data_size,  | 
692  | 0  |            byte_order,  | 
693  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
694  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
695  | 0  |            error ) != 1 )  | 
696  | 0  |       { | 
697  | 0  |         libcerror_error_set(  | 
698  | 0  |          error,  | 
699  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
700  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
701  | 0  |          "%s: unable to copy UTF-32 stream from UTF-8 string.",  | 
702  | 0  |          function );  | 
703  |  | 
  | 
704  | 0  |         goto on_error;  | 
705  | 0  |       }  | 
706  | 0  |       break;  | 
707  |  |  | 
708  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
709  | 0  |       if( libuna_utf7_stream_copy_from_utf8(  | 
710  | 0  |            string->data,  | 
711  | 0  |            string->data_size,  | 
712  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
713  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
714  | 0  |            error ) != 1 )  | 
715  | 0  |       { | 
716  | 0  |         libcerror_error_set(  | 
717  | 0  |          error,  | 
718  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
719  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
720  | 0  |          "%s: unable to copy UTF-7 stream from UTF-8 string.",  | 
721  | 0  |          function );  | 
722  |  | 
  | 
723  | 0  |         goto on_error;  | 
724  | 0  |       }  | 
725  | 0  |       break;  | 
726  |  |  | 
727  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
728  | 0  |       if( libuna_utf8_stream_copy_from_utf8(  | 
729  | 0  |            string->data,  | 
730  | 0  |            string->data_size,  | 
731  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
732  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
733  | 0  |            error ) != 1 )  | 
734  | 0  |       { | 
735  | 0  |         libcerror_error_set(  | 
736  | 0  |          error,  | 
737  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
738  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
739  | 0  |          "%s: unable to copy UTF-8 stream from UTF-8 string.",  | 
740  | 0  |          function );  | 
741  |  | 
  | 
742  | 0  |         goto on_error;  | 
743  | 0  |       }  | 
744  | 0  |       break;  | 
745  |  |  | 
746  | 0  |     default:  | 
747  | 0  |       if( libuna_byte_stream_copy_from_utf8(  | 
748  | 0  |            string->data,  | 
749  | 0  |            string->data_size,  | 
750  | 0  |            string->codepage,  | 
751  | 0  |            &( utf8_string[ safe_utf8_string_index ] ),  | 
752  | 0  |            utf8_string_size - safe_utf8_string_index,  | 
753  | 0  |            error ) != 1 )  | 
754  | 0  |       { | 
755  | 0  |         libcerror_error_set(  | 
756  | 0  |          error,  | 
757  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
758  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
759  | 0  |          "%s: unable to copy byte stream from UTF-8 string.",  | 
760  | 0  |          function );  | 
761  |  | 
  | 
762  | 0  |         goto on_error;  | 
763  | 0  |       }  | 
764  | 0  |       break;  | 
765  | 0  |   }  | 
766  | 0  |   *utf8_string_index = utf8_string_size;  | 
767  |  | 
  | 
768  | 0  |   return( 1 );  | 
769  |  |  | 
770  | 0  | on_error:  | 
771  | 0  |   if( string->data != NULL )  | 
772  | 0  |   { | 
773  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
774  | 0  |     { | 
775  | 0  |       memory_free(  | 
776  | 0  |        string->data );  | 
777  |  | 
  | 
778  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
779  | 0  |     }  | 
780  | 0  |     string->data      = NULL;  | 
781  | 0  |     string->data_size = 0;  | 
782  | 0  |   }  | 
783  | 0  |   return( -1 );  | 
784  | 0  | }  | 
785  |  |  | 
786  |  | /* Retrieves the size of an UTF-8 encoded string of the string  | 
787  |  |  * Returns 1 if successful or -1 on error  | 
788  |  |  */  | 
789  |  | int libfvalue_string_get_utf8_string_size(  | 
790  |  |      libfvalue_string_t *string,  | 
791  |  |      size_t *utf8_string_size,  | 
792  |  |      uint32_t string_format_flags,  | 
793  |  |      libcerror_error_t **error )  | 
794  | 0  | { | 
795  | 0  |   static char *function = "libfvalue_string_get_utf8_string_size";  | 
796  | 0  |   int byte_order        = 0;  | 
797  | 0  |   int result            = 0;  | 
798  |  | 
  | 
799  | 0  |   if( string == NULL )  | 
800  | 0  |   { | 
801  | 0  |     libcerror_error_set(  | 
802  | 0  |      error,  | 
803  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
804  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
805  | 0  |      "%s: invalid string.",  | 
806  | 0  |      function );  | 
807  |  | 
  | 
808  | 0  |     return( -1 );  | 
809  | 0  |   }  | 
810  | 0  |   if( string_format_flags != 0 )  | 
811  | 0  |   { | 
812  | 0  |     libcerror_error_set(  | 
813  | 0  |      error,  | 
814  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
815  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
816  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
817  | 0  |      function,  | 
818  | 0  |      string_format_flags );  | 
819  |  | 
  | 
820  | 0  |     return( -1 );  | 
821  | 0  |   }  | 
822  | 0  |   if( ( string->data == NULL )  | 
823  | 0  |    || ( string->data_size == 0 ) )  | 
824  | 0  |   { | 
825  | 0  |     if( utf8_string_size == NULL )  | 
826  | 0  |     { | 
827  | 0  |       libcerror_error_set(  | 
828  | 0  |        error,  | 
829  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
830  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
831  | 0  |        "%s: invalid UTF-8 string size.",  | 
832  | 0  |        function );  | 
833  |  | 
  | 
834  | 0  |       return( -1 );  | 
835  | 0  |     }  | 
836  | 0  |     *utf8_string_size = 1;  | 
837  | 0  |   }  | 
838  | 0  |   else switch( string->codepage )  | 
839  | 0  |   { | 
840  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
841  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
842  | 0  |       { | 
843  | 0  |         result = libuna_utf8_string_size_from_utf16_stream(  | 
844  | 0  |                   string->data,  | 
845  | 0  |                   string->data_size,  | 
846  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
847  | 0  |                   utf8_string_size,  | 
848  | 0  |                   error );  | 
849  |  | 
  | 
850  | 0  |         if( result != 1 )  | 
851  | 0  |         { | 
852  | 0  |           libcerror_error_set(  | 
853  | 0  |            error,  | 
854  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
855  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
856  | 0  |            "%s: unable to determine UTF-8 string size of UTF-16 stream.",  | 
857  | 0  |            function );  | 
858  |  | 
  | 
859  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
860  |  |           if( ( error != NULL )  | 
861  |  |            && ( *error != NULL ) )  | 
862  |  |           { | 
863  |  |             libcnotify_print_error_backtrace(  | 
864  |  |              *error );  | 
865  |  |           }  | 
866  |  | #endif  | 
867  | 0  |           libcerror_error_free(  | 
868  | 0  |            error );  | 
869  | 0  |         }  | 
870  | 0  |       }  | 
871  | 0  |       if( result != 1 )  | 
872  | 0  |       { | 
873  | 0  |         if( libuna_utf8_string_size_from_byte_stream(  | 
874  | 0  |              string->data,  | 
875  | 0  |              string->data_size,  | 
876  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
877  | 0  |              utf8_string_size,  | 
878  | 0  |              error ) != 1 )  | 
879  | 0  |         { | 
880  | 0  |           libcerror_error_set(  | 
881  | 0  |            error,  | 
882  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
883  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
884  | 0  |            "%s: unable to determine UTF-8 string size of byte stream.",  | 
885  | 0  |            function );  | 
886  |  | 
  | 
887  | 0  |           return( -1 );  | 
888  | 0  |         }  | 
889  | 0  |       }  | 
890  | 0  |       break;  | 
891  |  |  | 
892  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
893  | 0  |       if( libuna_utf8_string_size_from_scsu_stream(  | 
894  | 0  |            string->data,  | 
895  | 0  |            string->data_size,  | 
896  | 0  |            utf8_string_size,  | 
897  | 0  |            error ) != 1 )  | 
898  | 0  |       { | 
899  | 0  |         libcerror_error_set(  | 
900  | 0  |          error,  | 
901  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
902  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
903  | 0  |          "%s: unable to determine UTF-8 string size of SCSU stream.",  | 
904  | 0  |          function );  | 
905  |  | 
  | 
906  | 0  |         return( -1 );  | 
907  | 0  |       }  | 
908  | 0  |       break;  | 
909  |  |  | 
910  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
911  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
912  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
913  | 0  |       { | 
914  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
915  | 0  |       }  | 
916  | 0  |       else  | 
917  | 0  |       { | 
918  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
919  | 0  |       }  | 
920  | 0  |       if( libuna_utf8_string_size_from_utf16_stream(  | 
921  | 0  |            string->data,  | 
922  | 0  |            string->data_size,  | 
923  | 0  |            byte_order,  | 
924  | 0  |            utf8_string_size,  | 
925  | 0  |            error ) != 1 )  | 
926  | 0  |       { | 
927  | 0  |         libcerror_error_set(  | 
928  | 0  |          error,  | 
929  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
930  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
931  | 0  |          "%s: unable to determine UTF-8 string size of UTF-16 stream.",  | 
932  | 0  |          function );  | 
933  |  | 
  | 
934  | 0  |         return( -1 );  | 
935  | 0  |       }  | 
936  | 0  |       break;  | 
937  |  |  | 
938  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
939  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
940  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
941  | 0  |       { | 
942  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
943  | 0  |       }  | 
944  | 0  |       else  | 
945  | 0  |       { | 
946  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
947  | 0  |       }  | 
948  | 0  |       if( libuna_utf8_string_size_from_utf32_stream(  | 
949  | 0  |            string->data,  | 
950  | 0  |            string->data_size,  | 
951  | 0  |            byte_order,  | 
952  | 0  |            utf8_string_size,  | 
953  | 0  |            error ) != 1 )  | 
954  | 0  |       { | 
955  | 0  |         libcerror_error_set(  | 
956  | 0  |          error,  | 
957  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
958  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
959  | 0  |          "%s: unable to determine UTF-8 string size of UTF-32 stream.",  | 
960  | 0  |          function );  | 
961  |  | 
  | 
962  | 0  |         return( -1 );  | 
963  | 0  |       }  | 
964  | 0  |       break;  | 
965  |  |  | 
966  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
967  | 0  |       if( libuna_utf8_string_size_from_utf7_stream(  | 
968  | 0  |            string->data,  | 
969  | 0  |            string->data_size,  | 
970  | 0  |            utf8_string_size,  | 
971  | 0  |            error ) != 1 )  | 
972  | 0  |       { | 
973  | 0  |         libcerror_error_set(  | 
974  | 0  |          error,  | 
975  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
976  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
977  | 0  |          "%s: unable to determine UTF-8 string size of UTF-7 stream.",  | 
978  | 0  |          function );  | 
979  |  | 
  | 
980  | 0  |         return( -1 );  | 
981  | 0  |       }  | 
982  | 0  |       break;  | 
983  |  |  | 
984  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
985  | 0  |       if( libuna_utf8_string_size_from_utf8_stream(  | 
986  | 0  |            string->data,  | 
987  | 0  |            string->data_size,  | 
988  | 0  |            utf8_string_size,  | 
989  | 0  |            error ) != 1 )  | 
990  | 0  |       { | 
991  | 0  |         libcerror_error_set(  | 
992  | 0  |          error,  | 
993  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
994  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
995  | 0  |          "%s: unable to determine UTF-8 string size of UTF-8 stream.",  | 
996  | 0  |          function );  | 
997  |  | 
  | 
998  | 0  |         return( -1 );  | 
999  | 0  |       }  | 
1000  | 0  |       break;  | 
1001  |  |  | 
1002  | 0  |     default:  | 
1003  | 0  |       if( libuna_utf8_string_size_from_byte_stream(  | 
1004  | 0  |            string->data,  | 
1005  | 0  |            string->data_size,  | 
1006  | 0  |            string->codepage,  | 
1007  | 0  |            utf8_string_size,  | 
1008  | 0  |            error ) != 1 )  | 
1009  | 0  |       { | 
1010  | 0  |         libcerror_error_set(  | 
1011  | 0  |          error,  | 
1012  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1013  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1014  | 0  |          "%s: unable to determine UTF-8 string size of byte stream.",  | 
1015  | 0  |          function );  | 
1016  |  | 
  | 
1017  | 0  |         return( -1 );  | 
1018  | 0  |       }  | 
1019  | 0  |       break;  | 
1020  | 0  |   }  | 
1021  | 0  |   return( 1 );  | 
1022  | 0  | }  | 
1023  |  |  | 
1024  |  | /* Copies the string to an UTF-8 encoded string  | 
1025  |  |  * Returns 1 if successful or -1 on error  | 
1026  |  |  */  | 
1027  |  | int libfvalue_string_copy_to_utf8_string_with_index(  | 
1028  |  |      libfvalue_string_t *string,  | 
1029  |  |      uint8_t *utf8_string,  | 
1030  |  |      size_t utf8_string_size,  | 
1031  |  |      size_t *utf8_string_index,  | 
1032  |  |      uint32_t string_format_flags,  | 
1033  |  |      libcerror_error_t **error )  | 
1034  | 0  | { | 
1035  | 0  |   static char *function = "libfvalue_string_copy_to_utf8_string_with_index";  | 
1036  | 0  |   int byte_order        = 0;  | 
1037  | 0  |   int result            = 0;  | 
1038  |  | 
  | 
1039  | 0  |   if( string == NULL )  | 
1040  | 0  |   { | 
1041  | 0  |     libcerror_error_set(  | 
1042  | 0  |      error,  | 
1043  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1044  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1045  | 0  |      "%s: invalid string.",  | 
1046  | 0  |      function );  | 
1047  |  | 
  | 
1048  | 0  |     return( -1 );  | 
1049  | 0  |   }  | 
1050  | 0  |   if( string_format_flags != 0 )  | 
1051  | 0  |   { | 
1052  | 0  |     libcerror_error_set(  | 
1053  | 0  |      error,  | 
1054  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1055  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
1056  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
1057  | 0  |      function,  | 
1058  | 0  |      string_format_flags );  | 
1059  |  | 
  | 
1060  | 0  |     return( -1 );  | 
1061  | 0  |   }  | 
1062  | 0  |   if( ( string->data == NULL )  | 
1063  | 0  |    || ( string->data_size == 0 ) )  | 
1064  | 0  |   { | 
1065  | 0  |     if( utf8_string == NULL )  | 
1066  | 0  |     { | 
1067  | 0  |       libcerror_error_set(  | 
1068  | 0  |        error,  | 
1069  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1070  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1071  | 0  |        "%s: invalid UTF-8 string.",  | 
1072  | 0  |        function );  | 
1073  |  | 
  | 
1074  | 0  |       return( -1 );  | 
1075  | 0  |     }  | 
1076  | 0  |     if( utf8_string_size > (size_t) SSIZE_MAX )  | 
1077  | 0  |     { | 
1078  | 0  |       libcerror_error_set(  | 
1079  | 0  |        error,  | 
1080  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1081  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
1082  | 0  |        "%s: invalid UTF-8 string size value exceeds maximum.",  | 
1083  | 0  |        function );  | 
1084  |  | 
  | 
1085  | 0  |       return( -1 );  | 
1086  | 0  |     }  | 
1087  | 0  |     if( utf8_string_index == NULL )  | 
1088  | 0  |     { | 
1089  | 0  |       libcerror_error_set(  | 
1090  | 0  |        error,  | 
1091  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1092  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1093  | 0  |        "%s: invalid UTF-8 string index.",  | 
1094  | 0  |        function );  | 
1095  |  | 
  | 
1096  | 0  |       return( -1 );  | 
1097  | 0  |     }  | 
1098  | 0  |     if( *utf8_string_index >= utf8_string_size )  | 
1099  | 0  |     { | 
1100  | 0  |       libcerror_error_set(  | 
1101  | 0  |        error,  | 
1102  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1103  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
1104  | 0  |        "%s: UTF-8 string is too small.",  | 
1105  | 0  |        function );  | 
1106  |  | 
  | 
1107  | 0  |       return( -1 );  | 
1108  | 0  |     }  | 
1109  | 0  |     utf8_string[ *utf8_string_index ] = 0;  | 
1110  |  | 
  | 
1111  | 0  |     *utf8_string_index += 1;  | 
1112  | 0  |   }  | 
1113  | 0  |   else switch( string->codepage )  | 
1114  | 0  |   { | 
1115  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
1116  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
1117  | 0  |       { | 
1118  | 0  |         result = libuna_utf8_string_with_index_copy_from_utf16_stream(  | 
1119  | 0  |                   utf8_string,  | 
1120  | 0  |                   utf8_string_size,  | 
1121  | 0  |                   utf8_string_index,  | 
1122  | 0  |                   string->data,  | 
1123  | 0  |                   string->data_size,  | 
1124  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
1125  | 0  |                   error );  | 
1126  |  | 
  | 
1127  | 0  |         if( result != 1 )  | 
1128  | 0  |         { | 
1129  | 0  |           libcerror_error_set(  | 
1130  | 0  |            error,  | 
1131  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1132  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1133  | 0  |            "%s: unable to copy UTF-16 stream to UTF-8 string.",  | 
1134  | 0  |            function );  | 
1135  |  | 
  | 
1136  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
1137  |  |           if( ( error != NULL )  | 
1138  |  |            && ( *error != NULL ) )  | 
1139  |  |           { | 
1140  |  |             libcnotify_print_error_backtrace(  | 
1141  |  |              *error );  | 
1142  |  |           }  | 
1143  |  | #endif  | 
1144  | 0  |           libcerror_error_free(  | 
1145  | 0  |            error );  | 
1146  | 0  |         }  | 
1147  | 0  |       }  | 
1148  | 0  |       if( result != 1 )  | 
1149  | 0  |       { | 
1150  | 0  |         if( libuna_utf8_string_with_index_copy_from_byte_stream(  | 
1151  | 0  |              utf8_string,  | 
1152  | 0  |              utf8_string_size,  | 
1153  | 0  |              utf8_string_index,  | 
1154  | 0  |              string->data,  | 
1155  | 0  |              string->data_size,  | 
1156  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
1157  | 0  |              error ) != 1 )  | 
1158  | 0  |         { | 
1159  | 0  |           libcerror_error_set(  | 
1160  | 0  |            error,  | 
1161  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1162  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1163  | 0  |            "%s: unable to copy byte stream to UTF-8 string.",  | 
1164  | 0  |            function );  | 
1165  |  | 
  | 
1166  | 0  |           return( -1 );  | 
1167  | 0  |         }  | 
1168  | 0  |       }  | 
1169  | 0  |       break;  | 
1170  |  |  | 
1171  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
1172  | 0  |       if( libuna_utf8_string_with_index_copy_from_scsu_stream(  | 
1173  | 0  |            utf8_string,  | 
1174  | 0  |            utf8_string_size,  | 
1175  | 0  |            utf8_string_index,  | 
1176  | 0  |            string->data,  | 
1177  | 0  |            string->data_size,  | 
1178  | 0  |            error ) != 1 )  | 
1179  | 0  |       { | 
1180  | 0  |         libcerror_error_set(  | 
1181  | 0  |          error,  | 
1182  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1183  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1184  | 0  |          "%s: unable to copy SCSU stream to UTF-8 string.",  | 
1185  | 0  |          function );  | 
1186  |  | 
  | 
1187  | 0  |         return( -1 );  | 
1188  | 0  |       }  | 
1189  | 0  |       break;  | 
1190  |  |  | 
1191  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
1192  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
1193  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
1194  | 0  |       { | 
1195  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1196  | 0  |       }  | 
1197  | 0  |       else  | 
1198  | 0  |       { | 
1199  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1200  | 0  |       }  | 
1201  | 0  |       if( libuna_utf8_string_with_index_copy_from_utf16_stream(  | 
1202  | 0  |            utf8_string,  | 
1203  | 0  |            utf8_string_size,  | 
1204  | 0  |            utf8_string_index,  | 
1205  | 0  |            string->data,  | 
1206  | 0  |            string->data_size,  | 
1207  | 0  |            byte_order,  | 
1208  | 0  |            error ) != 1 )  | 
1209  | 0  |       { | 
1210  | 0  |         libcerror_error_set(  | 
1211  | 0  |          error,  | 
1212  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1213  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1214  | 0  |          "%s: unable to copy UTF-16 stream to UTF-8 string.",  | 
1215  | 0  |          function );  | 
1216  |  | 
  | 
1217  | 0  |         return( -1 );  | 
1218  | 0  |       }  | 
1219  | 0  |       break;  | 
1220  |  |  | 
1221  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
1222  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
1223  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
1224  | 0  |       { | 
1225  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1226  | 0  |       }  | 
1227  | 0  |       else  | 
1228  | 0  |       { | 
1229  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1230  | 0  |       }  | 
1231  | 0  |       if( libuna_utf8_string_with_index_copy_from_utf32_stream(  | 
1232  | 0  |            utf8_string,  | 
1233  | 0  |            utf8_string_size,  | 
1234  | 0  |            utf8_string_index,  | 
1235  | 0  |            string->data,  | 
1236  | 0  |            string->data_size,  | 
1237  | 0  |            byte_order,  | 
1238  | 0  |            error ) != 1 )  | 
1239  | 0  |       { | 
1240  | 0  |         libcerror_error_set(  | 
1241  | 0  |          error,  | 
1242  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1243  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1244  | 0  |          "%s: unable to copy UTF-32 stream to UTF-8 string.",  | 
1245  | 0  |          function );  | 
1246  |  | 
  | 
1247  | 0  |         return( -1 );  | 
1248  | 0  |       }  | 
1249  | 0  |       break;  | 
1250  |  |  | 
1251  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
1252  | 0  |       if( libuna_utf8_string_with_index_copy_from_utf7_stream(  | 
1253  | 0  |            utf8_string,  | 
1254  | 0  |            utf8_string_size,  | 
1255  | 0  |            utf8_string_index,  | 
1256  | 0  |            string->data,  | 
1257  | 0  |            string->data_size,  | 
1258  | 0  |            error ) != 1 )  | 
1259  | 0  |       { | 
1260  | 0  |         libcerror_error_set(  | 
1261  | 0  |          error,  | 
1262  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1263  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1264  | 0  |          "%s: unable to copy UTF-7 stream to UTF-8 string.",  | 
1265  | 0  |          function );  | 
1266  |  | 
  | 
1267  | 0  |         return( -1 );  | 
1268  | 0  |       }  | 
1269  | 0  |       break;  | 
1270  |  |  | 
1271  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
1272  | 0  |       if( libuna_utf8_string_with_index_copy_from_utf8_stream(  | 
1273  | 0  |            utf8_string,  | 
1274  | 0  |            utf8_string_size,  | 
1275  | 0  |            utf8_string_index,  | 
1276  | 0  |            string->data,  | 
1277  | 0  |            string->data_size,  | 
1278  | 0  |            error ) != 1 )  | 
1279  | 0  |       { | 
1280  | 0  |         libcerror_error_set(  | 
1281  | 0  |          error,  | 
1282  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1283  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1284  | 0  |          "%s: unable to copy UTF-8 stream to UTF-8 string.",  | 
1285  | 0  |          function );  | 
1286  |  | 
  | 
1287  | 0  |         return( -1 );  | 
1288  | 0  |       }  | 
1289  | 0  |       break;  | 
1290  |  |  | 
1291  | 0  |     default:  | 
1292  | 0  |       if( libuna_utf8_string_with_index_copy_from_byte_stream(  | 
1293  | 0  |            utf8_string,  | 
1294  | 0  |            utf8_string_size,  | 
1295  | 0  |            utf8_string_index,  | 
1296  | 0  |            string->data,  | 
1297  | 0  |            string->data_size,  | 
1298  | 0  |            string->codepage,  | 
1299  | 0  |            error ) != 1 )  | 
1300  | 0  |       { | 
1301  | 0  |         libcerror_error_set(  | 
1302  | 0  |          error,  | 
1303  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1304  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1305  | 0  |          "%s: unable to copy byte stream to UTF-8 string.",  | 
1306  | 0  |          function );  | 
1307  |  | 
  | 
1308  | 0  |         return( -1 );  | 
1309  | 0  |       }  | 
1310  | 0  |       break;  | 
1311  | 0  |   }  | 
1312  | 0  |   return( 1 );  | 
1313  | 0  | }  | 
1314  |  |  | 
1315  |  | /* Copies the string from an UTF-16 encoded string  | 
1316  |  |  * Returns 1 if successful or -1 on error  | 
1317  |  |  */  | 
1318  |  | int libfvalue_string_copy_from_utf16_string_with_index(  | 
1319  |  |      libfvalue_string_t *string,  | 
1320  |  |      const uint16_t *utf16_string,  | 
1321  |  |      size_t utf16_string_size,  | 
1322  |  |      size_t *utf16_string_index,  | 
1323  |  |      uint32_t string_format_flags,  | 
1324  |  |      libcerror_error_t **error )  | 
1325  | 0  | { | 
1326  | 0  |   static char *function          = "libfvalue_string_copy_from_utf16_string_with_index";  | 
1327  | 0  |   size_t safe_utf16_string_index = 0;  | 
1328  | 0  |   size_t value_data_size         = 0;  | 
1329  | 0  |   int byte_order                 = 0;  | 
1330  |  | 
  | 
1331  | 0  |   if( string == NULL )  | 
1332  | 0  |   { | 
1333  | 0  |     libcerror_error_set(  | 
1334  | 0  |      error,  | 
1335  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1336  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1337  | 0  |      "%s: invalid string.",  | 
1338  | 0  |      function );  | 
1339  |  | 
  | 
1340  | 0  |     return( -1 );  | 
1341  | 0  |   }  | 
1342  | 0  |   if( utf16_string_size > (size_t) SSIZE_MAX )  | 
1343  | 0  |   { | 
1344  | 0  |     libcerror_error_set(  | 
1345  | 0  |      error,  | 
1346  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1347  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
1348  | 0  |      "%s: invalid UTF-16 string size value exceeds maximum.",  | 
1349  | 0  |      function );  | 
1350  |  | 
  | 
1351  | 0  |     return( -1 );  | 
1352  | 0  |   }  | 
1353  | 0  |   if( utf16_string_index == NULL )  | 
1354  | 0  |   { | 
1355  | 0  |     libcerror_error_set(  | 
1356  | 0  |      error,  | 
1357  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1358  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1359  | 0  |      "%s: invalid UTF-16 string index.",  | 
1360  | 0  |      function );  | 
1361  |  | 
  | 
1362  | 0  |     return( -1 );  | 
1363  | 0  |   }  | 
1364  | 0  |   if( *utf16_string_index >= utf16_string_size )  | 
1365  | 0  |   { | 
1366  | 0  |     libcerror_error_set(  | 
1367  | 0  |      error,  | 
1368  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1369  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
1370  | 0  |      "%s: UTF-16 string is too small.",  | 
1371  | 0  |      function );  | 
1372  |  | 
  | 
1373  | 0  |     return( -1 );  | 
1374  | 0  |   }  | 
1375  | 0  |   if( string_format_flags != 0 )  | 
1376  | 0  |   { | 
1377  | 0  |     libcerror_error_set(  | 
1378  | 0  |      error,  | 
1379  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1380  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
1381  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
1382  | 0  |      function,  | 
1383  | 0  |      string_format_flags );  | 
1384  |  | 
  | 
1385  | 0  |     return( -1 );  | 
1386  | 0  |   }  | 
1387  | 0  |   safe_utf16_string_index = *utf16_string_index;  | 
1388  |  | 
  | 
1389  | 0  |   switch( string->codepage )  | 
1390  | 0  |   { | 
1391  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
1392  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
1393  | 0  |       libcerror_error_set(  | 
1394  | 0  |        error,  | 
1395  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1396  | 0  |        LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
1397  | 0  |        "%s: unsupported encoding.",  | 
1398  | 0  |        function );  | 
1399  |  | 
  | 
1400  | 0  |       goto on_error;  | 
1401  |  |  | 
1402  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
1403  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
1404  | 0  |       if( libuna_utf16_stream_size_from_utf16(  | 
1405  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1406  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1407  | 0  |            &value_data_size,  | 
1408  | 0  |            error ) != 1 )  | 
1409  | 0  |       { | 
1410  | 0  |         libcerror_error_set(  | 
1411  | 0  |          error,  | 
1412  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1413  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1414  | 0  |          "%s: unable to determine UTF-16 stream size of UTF-16 string.",  | 
1415  | 0  |          function );  | 
1416  |  | 
  | 
1417  | 0  |         goto on_error;  | 
1418  | 0  |       }  | 
1419  | 0  |       break;  | 
1420  |  |  | 
1421  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
1422  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
1423  | 0  |       if( libuna_utf32_stream_size_from_utf16(  | 
1424  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1425  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1426  | 0  |            &value_data_size,  | 
1427  | 0  |            error ) != 1 )  | 
1428  | 0  |       { | 
1429  | 0  |         libcerror_error_set(  | 
1430  | 0  |          error,  | 
1431  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1432  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1433  | 0  |          "%s: unable to determine UTF-32 stream size of UTF-16 string.",  | 
1434  | 0  |          function );  | 
1435  |  | 
  | 
1436  | 0  |         goto on_error;  | 
1437  | 0  |       }  | 
1438  | 0  |       break;  | 
1439  |  |  | 
1440  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
1441  | 0  |       if( libuna_utf7_stream_size_from_utf16(  | 
1442  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1443  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1444  | 0  |            &value_data_size,  | 
1445  | 0  |            error ) != 1 )  | 
1446  | 0  |       { | 
1447  | 0  |         libcerror_error_set(  | 
1448  | 0  |          error,  | 
1449  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1450  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1451  | 0  |          "%s: unable to determine UTF-7 stream size of UTF-16 string.",  | 
1452  | 0  |          function );  | 
1453  |  | 
  | 
1454  | 0  |         goto on_error;  | 
1455  | 0  |       }  | 
1456  | 0  |       break;  | 
1457  |  |  | 
1458  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
1459  | 0  |       if( libuna_utf8_stream_size_from_utf16(  | 
1460  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1461  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1462  | 0  |            &value_data_size,  | 
1463  | 0  |            error ) != 1 )  | 
1464  | 0  |       { | 
1465  | 0  |         libcerror_error_set(  | 
1466  | 0  |          error,  | 
1467  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1468  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1469  | 0  |          "%s: unable to determine UTF-8 stream size of UTF-16 string.",  | 
1470  | 0  |          function );  | 
1471  |  | 
  | 
1472  | 0  |         goto on_error;  | 
1473  | 0  |       }  | 
1474  | 0  |       break;  | 
1475  |  |  | 
1476  | 0  |     default:  | 
1477  | 0  |       if( libuna_byte_stream_size_from_utf16(  | 
1478  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1479  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1480  | 0  |            string->codepage,  | 
1481  | 0  |            &value_data_size,  | 
1482  | 0  |            error ) != 1 )  | 
1483  | 0  |       { | 
1484  | 0  |         libcerror_error_set(  | 
1485  | 0  |          error,  | 
1486  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1487  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1488  | 0  |          "%s: unable to determine byte stream size of UTF-16 string.",  | 
1489  | 0  |          function );  | 
1490  |  | 
  | 
1491  | 0  |         goto on_error;  | 
1492  | 0  |       }  | 
1493  | 0  |       break;  | 
1494  |  | 
  | 
1495  | 0  |   }  | 
1496  | 0  |   if( string->data != NULL )  | 
1497  | 0  |   { | 
1498  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
1499  | 0  |     { | 
1500  | 0  |       memory_free(  | 
1501  | 0  |        string->data );  | 
1502  |  | 
  | 
1503  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
1504  | 0  |     }  | 
1505  | 0  |     string->data      = NULL;  | 
1506  | 0  |     string->data_size = 0;  | 
1507  | 0  |   }  | 
1508  | 0  |   string->data_size = value_data_size;  | 
1509  |  | 
  | 
1510  | 0  |   string->data = (uint8_t *) memory_allocate(  | 
1511  | 0  |                               sizeof( uint8_t ) * string->data_size );  | 
1512  |  | 
  | 
1513  | 0  |   if( string->data == NULL )  | 
1514  | 0  |   { | 
1515  | 0  |     libcerror_error_set(  | 
1516  | 0  |      error,  | 
1517  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
1518  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
1519  | 0  |      "%s: unable to create string data.",  | 
1520  | 0  |      function );  | 
1521  |  | 
  | 
1522  | 0  |     goto on_error;  | 
1523  | 0  |   }  | 
1524  | 0  |   string->flags |= LIBFVALUE_VALUE_FLAG_DATA_MANAGED;  | 
1525  |  | 
  | 
1526  | 0  |   switch( string->codepage )  | 
1527  | 0  |   { | 
1528  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
1529  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
1530  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
1531  | 0  |       { | 
1532  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1533  | 0  |       }  | 
1534  | 0  |       else  | 
1535  | 0  |       { | 
1536  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1537  | 0  |       }  | 
1538  | 0  |       if( libuna_utf16_stream_copy_from_utf16(  | 
1539  | 0  |            string->data,  | 
1540  | 0  |            string->data_size,  | 
1541  | 0  |            byte_order,  | 
1542  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1543  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1544  | 0  |            error ) != 1 )  | 
1545  | 0  |       { | 
1546  | 0  |         libcerror_error_set(  | 
1547  | 0  |          error,  | 
1548  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1549  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1550  | 0  |          "%s: unable to copy UTF-16 stream from UTF-16 string.",  | 
1551  | 0  |          function );  | 
1552  |  | 
  | 
1553  | 0  |         goto on_error;  | 
1554  | 0  |       }  | 
1555  | 0  |       break;  | 
1556  |  |  | 
1557  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
1558  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
1559  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
1560  | 0  |       { | 
1561  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1562  | 0  |       }  | 
1563  | 0  |       else  | 
1564  | 0  |       { | 
1565  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1566  | 0  |       }  | 
1567  | 0  |       if( libuna_utf32_stream_copy_from_utf16(  | 
1568  | 0  |            string->data,  | 
1569  | 0  |            string->data_size,  | 
1570  | 0  |            byte_order,  | 
1571  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1572  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1573  | 0  |            error ) != 1 )  | 
1574  | 0  |       { | 
1575  | 0  |         libcerror_error_set(  | 
1576  | 0  |          error,  | 
1577  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1578  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1579  | 0  |          "%s: unable to copy UTF-32 stream from UTF-16 string.",  | 
1580  | 0  |          function );  | 
1581  |  | 
  | 
1582  | 0  |         goto on_error;  | 
1583  | 0  |       }  | 
1584  | 0  |       break;  | 
1585  |  |  | 
1586  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
1587  | 0  |       if( libuna_utf7_stream_copy_from_utf16(  | 
1588  | 0  |            string->data,  | 
1589  | 0  |            string->data_size,  | 
1590  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1591  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1592  | 0  |            error ) != 1 )  | 
1593  | 0  |       { | 
1594  | 0  |         libcerror_error_set(  | 
1595  | 0  |          error,  | 
1596  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1597  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1598  | 0  |          "%s: unable to copy UTF-7 stream from UTF-16 string.",  | 
1599  | 0  |          function );  | 
1600  |  | 
  | 
1601  | 0  |         goto on_error;  | 
1602  | 0  |       }  | 
1603  | 0  |       break;  | 
1604  |  |  | 
1605  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
1606  | 0  |       if( libuna_utf8_stream_copy_from_utf16(  | 
1607  | 0  |            string->data,  | 
1608  | 0  |            string->data_size,  | 
1609  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1610  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1611  | 0  |            error ) != 1 )  | 
1612  | 0  |       { | 
1613  | 0  |         libcerror_error_set(  | 
1614  | 0  |          error,  | 
1615  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1616  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1617  | 0  |          "%s: unable to copy UTF-8 stream from UTF-16 string.",  | 
1618  | 0  |          function );  | 
1619  |  | 
  | 
1620  | 0  |         goto on_error;  | 
1621  | 0  |       }  | 
1622  | 0  |       break;  | 
1623  |  |  | 
1624  | 0  |     default:  | 
1625  | 0  |       if( libuna_byte_stream_copy_from_utf16(  | 
1626  | 0  |            string->data,  | 
1627  | 0  |            string->data_size,  | 
1628  | 0  |            string->codepage,  | 
1629  | 0  |            &( utf16_string[ safe_utf16_string_index ] ),  | 
1630  | 0  |            utf16_string_size - safe_utf16_string_index,  | 
1631  | 0  |            error ) != 1 )  | 
1632  | 0  |       { | 
1633  | 0  |         libcerror_error_set(  | 
1634  | 0  |          error,  | 
1635  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1636  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
1637  | 0  |          "%s: unable to copy byte stream from UTF-16 string.",  | 
1638  | 0  |          function );  | 
1639  |  | 
  | 
1640  | 0  |         goto on_error;  | 
1641  | 0  |       }  | 
1642  | 0  |       break;  | 
1643  | 0  |   }  | 
1644  | 0  |   *utf16_string_index = utf16_string_size;  | 
1645  |  | 
  | 
1646  | 0  |   return( 1 );  | 
1647  |  |  | 
1648  | 0  | on_error:  | 
1649  | 0  |   if( string->data != NULL )  | 
1650  | 0  |   { | 
1651  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
1652  | 0  |     { | 
1653  | 0  |       memory_free(  | 
1654  | 0  |        string->data );  | 
1655  |  | 
  | 
1656  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
1657  | 0  |     }  | 
1658  | 0  |     string->data      = NULL;  | 
1659  | 0  |     string->data_size = 0;  | 
1660  | 0  |   }  | 
1661  | 0  |   return( -1 );  | 
1662  | 0  | }  | 
1663  |  |  | 
1664  |  | /* Retrieves the size of an UTF-16 encoded string of the string  | 
1665  |  |  * Returns 1 if successful or -1 on error  | 
1666  |  |  */  | 
1667  |  | int libfvalue_string_get_utf16_string_size(  | 
1668  |  |      libfvalue_string_t *string,  | 
1669  |  |      size_t *utf16_string_size,  | 
1670  |  |      uint32_t string_format_flags,  | 
1671  |  |      libcerror_error_t **error )  | 
1672  | 0  | { | 
1673  | 0  |   static char *function = "libfvalue_string_get_utf16_string_size";  | 
1674  | 0  |   int byte_order        = 0;  | 
1675  | 0  |   int result            = 0;  | 
1676  |  | 
  | 
1677  | 0  |   if( string == NULL )  | 
1678  | 0  |   { | 
1679  | 0  |     libcerror_error_set(  | 
1680  | 0  |      error,  | 
1681  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1682  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1683  | 0  |      "%s: invalid string.",  | 
1684  | 0  |      function );  | 
1685  |  | 
  | 
1686  | 0  |     return( -1 );  | 
1687  | 0  |   }  | 
1688  | 0  |   if( string_format_flags != 0 )  | 
1689  | 0  |   { | 
1690  | 0  |     libcerror_error_set(  | 
1691  | 0  |      error,  | 
1692  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1693  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
1694  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
1695  | 0  |      function,  | 
1696  | 0  |      string_format_flags );  | 
1697  |  | 
  | 
1698  | 0  |     return( -1 );  | 
1699  | 0  |   }  | 
1700  | 0  |   if( ( string->data == NULL )  | 
1701  | 0  |    || ( string->data_size == 0 ) )  | 
1702  | 0  |   { | 
1703  | 0  |     if( utf16_string_size == NULL )  | 
1704  | 0  |     { | 
1705  | 0  |       libcerror_error_set(  | 
1706  | 0  |        error,  | 
1707  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1708  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1709  | 0  |        "%s: invalid UTF-16 string size.",  | 
1710  | 0  |        function );  | 
1711  |  | 
  | 
1712  | 0  |       return( -1 );  | 
1713  | 0  |     }  | 
1714  | 0  |     *utf16_string_size = 1;  | 
1715  | 0  |   }  | 
1716  | 0  |   else switch( string->codepage )  | 
1717  | 0  |   { | 
1718  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
1719  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
1720  | 0  |       { | 
1721  | 0  |         result = libuna_utf16_string_size_from_utf16_stream(  | 
1722  | 0  |                   string->data,  | 
1723  | 0  |                   string->data_size,  | 
1724  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
1725  | 0  |                   utf16_string_size,  | 
1726  | 0  |                   error );  | 
1727  |  | 
  | 
1728  | 0  |         if( result != 1 )  | 
1729  | 0  |         { | 
1730  | 0  |           libcerror_error_set(  | 
1731  | 0  |            error,  | 
1732  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1733  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1734  | 0  |            "%s: unable to determine UTF-16 string size of UTF-16 stream.",  | 
1735  | 0  |            function );  | 
1736  |  | 
  | 
1737  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
1738  |  |           if( ( error != NULL )  | 
1739  |  |            && ( *error != NULL ) )  | 
1740  |  |           { | 
1741  |  |             libcnotify_print_error_backtrace(  | 
1742  |  |              *error );  | 
1743  |  |           }  | 
1744  |  | #endif  | 
1745  | 0  |           libcerror_error_free(  | 
1746  | 0  |            error );  | 
1747  | 0  |         }  | 
1748  | 0  |       }  | 
1749  | 0  |       if( result != 1 )  | 
1750  | 0  |       { | 
1751  | 0  |         if( libuna_utf16_string_size_from_byte_stream(  | 
1752  | 0  |              string->data,  | 
1753  | 0  |              string->data_size,  | 
1754  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
1755  | 0  |              utf16_string_size,  | 
1756  | 0  |              error ) != 1 )  | 
1757  | 0  |         { | 
1758  | 0  |           libcerror_error_set(  | 
1759  | 0  |            error,  | 
1760  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1761  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1762  | 0  |            "%s: unable to determine UTF-16 string size of byte stream.",  | 
1763  | 0  |            function );  | 
1764  |  | 
  | 
1765  | 0  |           return( -1 );  | 
1766  | 0  |         }  | 
1767  | 0  |       }  | 
1768  | 0  |       break;  | 
1769  |  |  | 
1770  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
1771  | 0  |       if( libuna_utf16_string_size_from_scsu_stream(  | 
1772  | 0  |            string->data,  | 
1773  | 0  |            string->data_size,  | 
1774  | 0  |            utf16_string_size,  | 
1775  | 0  |            error ) != 1 )  | 
1776  | 0  |       { | 
1777  | 0  |         libcerror_error_set(  | 
1778  | 0  |          error,  | 
1779  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1780  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1781  | 0  |          "%s: unable to determine UTF-16 string size of SCSU stream.",  | 
1782  | 0  |          function );  | 
1783  |  | 
  | 
1784  | 0  |         return( -1 );  | 
1785  | 0  |       }  | 
1786  | 0  |       break;  | 
1787  |  |  | 
1788  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
1789  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
1790  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
1791  | 0  |       { | 
1792  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1793  | 0  |       }  | 
1794  | 0  |       else  | 
1795  | 0  |       { | 
1796  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1797  | 0  |       }  | 
1798  | 0  |       if( libuna_utf16_string_size_from_utf16_stream(  | 
1799  | 0  |            string->data,  | 
1800  | 0  |            string->data_size,  | 
1801  | 0  |            byte_order,  | 
1802  | 0  |            utf16_string_size,  | 
1803  | 0  |            error ) != 1 )  | 
1804  | 0  |       { | 
1805  | 0  |         libcerror_error_set(  | 
1806  | 0  |          error,  | 
1807  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1808  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1809  | 0  |          "%s: unable to determine UTF-16 string size of UTF-16 stream.",  | 
1810  | 0  |          function );  | 
1811  |  | 
  | 
1812  | 0  |         return( -1 );  | 
1813  | 0  |       }  | 
1814  | 0  |       break;  | 
1815  |  |  | 
1816  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
1817  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
1818  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
1819  | 0  |       { | 
1820  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
1821  | 0  |       }  | 
1822  | 0  |       else  | 
1823  | 0  |       { | 
1824  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
1825  | 0  |       }  | 
1826  | 0  |       if( libuna_utf16_string_size_from_utf32_stream(  | 
1827  | 0  |            string->data,  | 
1828  | 0  |            string->data_size,  | 
1829  | 0  |            byte_order,  | 
1830  | 0  |            utf16_string_size,  | 
1831  | 0  |            error ) != 1 )  | 
1832  | 0  |       { | 
1833  | 0  |         libcerror_error_set(  | 
1834  | 0  |          error,  | 
1835  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1836  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1837  | 0  |          "%s: unable to determine UTF-16 string size of UTF-32 stream.",  | 
1838  | 0  |          function );  | 
1839  |  | 
  | 
1840  | 0  |         return( -1 );  | 
1841  | 0  |       }  | 
1842  | 0  |       break;  | 
1843  |  |  | 
1844  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
1845  | 0  |       if( libuna_utf16_string_size_from_utf7_stream(  | 
1846  | 0  |            string->data,  | 
1847  | 0  |            string->data_size,  | 
1848  | 0  |            utf16_string_size,  | 
1849  | 0  |            error ) != 1 )  | 
1850  | 0  |       { | 
1851  | 0  |         libcerror_error_set(  | 
1852  | 0  |          error,  | 
1853  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1854  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1855  | 0  |          "%s: unable to determine UTF-16 string size of UTF-7 stream.",  | 
1856  | 0  |          function );  | 
1857  |  | 
  | 
1858  | 0  |         return( -1 );  | 
1859  | 0  |       }  | 
1860  | 0  |       break;  | 
1861  |  |  | 
1862  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
1863  | 0  |       if( libuna_utf16_string_size_from_utf8_stream(  | 
1864  | 0  |            string->data,  | 
1865  | 0  |            string->data_size,  | 
1866  | 0  |            utf16_string_size,  | 
1867  | 0  |            error ) != 1 )  | 
1868  | 0  |       { | 
1869  | 0  |         libcerror_error_set(  | 
1870  | 0  |          error,  | 
1871  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1872  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1873  | 0  |          "%s: unable to determine UTF-16 string size of UTF-8 stream.",  | 
1874  | 0  |          function );  | 
1875  |  | 
  | 
1876  | 0  |         return( -1 );  | 
1877  | 0  |       }  | 
1878  | 0  |       break;  | 
1879  |  |  | 
1880  | 0  |     default:  | 
1881  | 0  |       if( libuna_utf16_string_size_from_byte_stream(  | 
1882  | 0  |            string->data,  | 
1883  | 0  |            string->data_size,  | 
1884  | 0  |            string->codepage,  | 
1885  | 0  |            utf16_string_size,  | 
1886  | 0  |            error ) != 1 )  | 
1887  | 0  |       { | 
1888  | 0  |         libcerror_error_set(  | 
1889  | 0  |          error,  | 
1890  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1891  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1892  | 0  |          "%s: unable to determine UTF-16 string size of byte stream.",  | 
1893  | 0  |          function );  | 
1894  |  | 
  | 
1895  | 0  |         return( -1 );  | 
1896  | 0  |       }  | 
1897  | 0  |       break;  | 
1898  | 0  |   }  | 
1899  | 0  |   return( 1 );  | 
1900  | 0  | }  | 
1901  |  |  | 
1902  |  | /* Copies the string to an UTF-16 encoded string  | 
1903  |  |  * Returns 1 if successful or -1 on error  | 
1904  |  |  */  | 
1905  |  | int libfvalue_string_copy_to_utf16_string_with_index(  | 
1906  |  |      libfvalue_string_t *string,  | 
1907  |  |      uint16_t *utf16_string,  | 
1908  |  |      size_t utf16_string_size,  | 
1909  |  |      size_t *utf16_string_index,  | 
1910  |  |      uint32_t string_format_flags,  | 
1911  |  |      libcerror_error_t **error )  | 
1912  | 0  | { | 
1913  | 0  |   static char *function = "libfvalue_string_copy_to_utf16_string_with_index";  | 
1914  | 0  |   int byte_order        = 0;  | 
1915  | 0  |   int result            = 0;  | 
1916  |  | 
  | 
1917  | 0  |   if( string == NULL )  | 
1918  | 0  |   { | 
1919  | 0  |     libcerror_error_set(  | 
1920  | 0  |      error,  | 
1921  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1922  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1923  | 0  |      "%s: invalid string.",  | 
1924  | 0  |      function );  | 
1925  |  | 
  | 
1926  | 0  |     return( -1 );  | 
1927  | 0  |   }  | 
1928  | 0  |   if( string_format_flags != 0 )  | 
1929  | 0  |   { | 
1930  | 0  |     libcerror_error_set(  | 
1931  | 0  |      error,  | 
1932  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1933  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
1934  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
1935  | 0  |      function,  | 
1936  | 0  |      string_format_flags );  | 
1937  |  | 
  | 
1938  | 0  |     return( -1 );  | 
1939  | 0  |   }  | 
1940  | 0  |   if( ( string->data == NULL )  | 
1941  | 0  |    || ( string->data_size == 0 ) )  | 
1942  | 0  |   { | 
1943  | 0  |     if( utf16_string == NULL )  | 
1944  | 0  |     { | 
1945  | 0  |       libcerror_error_set(  | 
1946  | 0  |        error,  | 
1947  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1948  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1949  | 0  |        "%s: invalid UTF-16 string.",  | 
1950  | 0  |        function );  | 
1951  |  | 
  | 
1952  | 0  |       return( -1 );  | 
1953  | 0  |     }  | 
1954  | 0  |     if( utf16_string_size > (size_t) SSIZE_MAX )  | 
1955  | 0  |     { | 
1956  | 0  |       libcerror_error_set(  | 
1957  | 0  |        error,  | 
1958  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1959  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
1960  | 0  |        "%s: invalid UTF-16 string size value exceeds maximum.",  | 
1961  | 0  |        function );  | 
1962  |  | 
  | 
1963  | 0  |       return( -1 );  | 
1964  | 0  |     }  | 
1965  | 0  |     if( utf16_string_index == NULL )  | 
1966  | 0  |     { | 
1967  | 0  |       libcerror_error_set(  | 
1968  | 0  |        error,  | 
1969  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1970  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
1971  | 0  |        "%s: invalid UTF-16 string index.",  | 
1972  | 0  |        function );  | 
1973  |  | 
  | 
1974  | 0  |       return( -1 );  | 
1975  | 0  |     }  | 
1976  | 0  |     if( *utf16_string_index >= utf16_string_size )  | 
1977  | 0  |     { | 
1978  | 0  |       libcerror_error_set(  | 
1979  | 0  |        error,  | 
1980  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
1981  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
1982  | 0  |        "%s: UTF-16 string is too small.",  | 
1983  | 0  |        function );  | 
1984  |  | 
  | 
1985  | 0  |       return( -1 );  | 
1986  | 0  |     }  | 
1987  | 0  |     utf16_string[ *utf16_string_index ] = 0;  | 
1988  |  | 
  | 
1989  | 0  |     *utf16_string_index += 1;  | 
1990  | 0  |   }  | 
1991  | 0  |   else switch( string->codepage )  | 
1992  | 0  |   { | 
1993  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
1994  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
1995  | 0  |       { | 
1996  | 0  |         result = libuna_utf16_string_with_index_copy_from_utf16_stream(  | 
1997  | 0  |                   utf16_string,  | 
1998  | 0  |                   utf16_string_size,  | 
1999  | 0  |                   utf16_string_index,  | 
2000  | 0  |                   string->data,  | 
2001  | 0  |                   string->data_size,  | 
2002  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
2003  | 0  |                   error );  | 
2004  |  | 
  | 
2005  | 0  |         if( result != 1 )  | 
2006  | 0  |         { | 
2007  | 0  |           libcerror_error_set(  | 
2008  | 0  |            error,  | 
2009  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2010  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2011  | 0  |            "%s: unable to copy UTF-16 stream to UTF-16 string.",  | 
2012  | 0  |            function );  | 
2013  |  | 
  | 
2014  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
2015  |  |           if( ( error != NULL )  | 
2016  |  |            && ( *error != NULL ) )  | 
2017  |  |           { | 
2018  |  |             libcnotify_print_error_backtrace(  | 
2019  |  |              *error );  | 
2020  |  |           }  | 
2021  |  | #endif  | 
2022  | 0  |           libcerror_error_free(  | 
2023  | 0  |            error );  | 
2024  | 0  |         }  | 
2025  | 0  |       }  | 
2026  | 0  |       if( result != 1 )  | 
2027  | 0  |       { | 
2028  | 0  |         if( libuna_utf16_string_with_index_copy_from_byte_stream(  | 
2029  | 0  |              utf16_string,  | 
2030  | 0  |              utf16_string_size,  | 
2031  | 0  |              utf16_string_index,  | 
2032  | 0  |              string->data,  | 
2033  | 0  |              string->data_size,  | 
2034  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
2035  | 0  |              error ) != 1 )  | 
2036  | 0  |         { | 
2037  | 0  |           libcerror_error_set(  | 
2038  | 0  |            error,  | 
2039  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2040  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2041  | 0  |            "%s: unable to copy byte stream to UTF-16 string.",  | 
2042  | 0  |            function );  | 
2043  |  | 
  | 
2044  | 0  |           return( -1 );  | 
2045  | 0  |         }  | 
2046  | 0  |       }  | 
2047  | 0  |       break;  | 
2048  |  |  | 
2049  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
2050  | 0  |       if( libuna_utf16_string_with_index_copy_from_scsu_stream(  | 
2051  | 0  |            utf16_string,  | 
2052  | 0  |            utf16_string_size,  | 
2053  | 0  |            utf16_string_index,  | 
2054  | 0  |            string->data,  | 
2055  | 0  |            string->data_size,  | 
2056  | 0  |            error ) != 1 )  | 
2057  | 0  |       { | 
2058  | 0  |         libcerror_error_set(  | 
2059  | 0  |          error,  | 
2060  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2061  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2062  | 0  |          "%s: unable to copy SCSU stream to UTF-16 string.",  | 
2063  | 0  |          function );  | 
2064  |  | 
  | 
2065  | 0  |         return( -1 );  | 
2066  | 0  |       }  | 
2067  | 0  |       break;  | 
2068  |  |  | 
2069  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
2070  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
2071  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
2072  | 0  |       { | 
2073  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2074  | 0  |       }  | 
2075  | 0  |       else  | 
2076  | 0  |       { | 
2077  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2078  | 0  |       }  | 
2079  | 0  |       if( libuna_utf16_string_with_index_copy_from_utf16_stream(  | 
2080  | 0  |            utf16_string,  | 
2081  | 0  |            utf16_string_size,  | 
2082  | 0  |            utf16_string_index,  | 
2083  | 0  |            string->data,  | 
2084  | 0  |            string->data_size,  | 
2085  | 0  |            byte_order,  | 
2086  | 0  |            error ) != 1 )  | 
2087  | 0  |       { | 
2088  | 0  |         libcerror_error_set(  | 
2089  | 0  |          error,  | 
2090  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2091  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2092  | 0  |          "%s: unable to copy UTF-16 stream to UTF-16 string.",  | 
2093  | 0  |          function );  | 
2094  |  | 
  | 
2095  | 0  |         return( -1 );  | 
2096  | 0  |       }  | 
2097  | 0  |       break;  | 
2098  |  |  | 
2099  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
2100  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
2101  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
2102  | 0  |       { | 
2103  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2104  | 0  |       }  | 
2105  | 0  |       else  | 
2106  | 0  |       { | 
2107  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2108  | 0  |       }  | 
2109  | 0  |       if( libuna_utf16_string_with_index_copy_from_utf32_stream(  | 
2110  | 0  |            utf16_string,  | 
2111  | 0  |            utf16_string_size,  | 
2112  | 0  |            utf16_string_index,  | 
2113  | 0  |            string->data,  | 
2114  | 0  |            string->data_size,  | 
2115  | 0  |            byte_order,  | 
2116  | 0  |            error ) != 1 )  | 
2117  | 0  |       { | 
2118  | 0  |         libcerror_error_set(  | 
2119  | 0  |          error,  | 
2120  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2121  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2122  | 0  |          "%s: unable to copy UTF-32 stream to UTF-16 string.",  | 
2123  | 0  |          function );  | 
2124  |  | 
  | 
2125  | 0  |         return( -1 );  | 
2126  | 0  |       }  | 
2127  | 0  |       break;  | 
2128  |  |  | 
2129  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
2130  | 0  |       if( libuna_utf16_string_with_index_copy_from_utf7_stream(  | 
2131  | 0  |            utf16_string,  | 
2132  | 0  |            utf16_string_size,  | 
2133  | 0  |            utf16_string_index,  | 
2134  | 0  |            string->data,  | 
2135  | 0  |            string->data_size,  | 
2136  | 0  |            error ) != 1 )  | 
2137  | 0  |       { | 
2138  | 0  |         libcerror_error_set(  | 
2139  | 0  |          error,  | 
2140  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2141  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2142  | 0  |          "%s: unable to copy UTF-7 stream to UTF-16 string.",  | 
2143  | 0  |          function );  | 
2144  |  | 
  | 
2145  | 0  |         return( -1 );  | 
2146  | 0  |       }  | 
2147  | 0  |       break;  | 
2148  |  |  | 
2149  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
2150  | 0  |       if( libuna_utf16_string_with_index_copy_from_utf8_stream(  | 
2151  | 0  |            utf16_string,  | 
2152  | 0  |            utf16_string_size,  | 
2153  | 0  |            utf16_string_index,  | 
2154  | 0  |            string->data,  | 
2155  | 0  |            string->data_size,  | 
2156  | 0  |            error ) != 1 )  | 
2157  | 0  |       { | 
2158  | 0  |         libcerror_error_set(  | 
2159  | 0  |          error,  | 
2160  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2161  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2162  | 0  |          "%s: unable to copy UTF-8 stream to UTF-16 string.",  | 
2163  | 0  |          function );  | 
2164  |  | 
  | 
2165  | 0  |         return( -1 );  | 
2166  | 0  |       }  | 
2167  | 0  |       break;  | 
2168  |  |  | 
2169  | 0  |     default:  | 
2170  | 0  |       if( libuna_utf16_string_with_index_copy_from_byte_stream(  | 
2171  | 0  |            utf16_string,  | 
2172  | 0  |            utf16_string_size,  | 
2173  | 0  |            utf16_string_index,  | 
2174  | 0  |            string->data,  | 
2175  | 0  |            string->data_size,  | 
2176  | 0  |            string->codepage,  | 
2177  | 0  |            error ) != 1 )  | 
2178  | 0  |       { | 
2179  | 0  |         libcerror_error_set(  | 
2180  | 0  |          error,  | 
2181  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2182  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2183  | 0  |          "%s: unable to copy byte stream to UTF-16 string.",  | 
2184  | 0  |          function );  | 
2185  |  | 
  | 
2186  | 0  |         return( -1 );  | 
2187  | 0  |       }  | 
2188  | 0  |       break;  | 
2189  | 0  |   }  | 
2190  | 0  |   return( 1 );  | 
2191  | 0  | }  | 
2192  |  |  | 
2193  |  | /* Copies the string from an UTF-32 encoded string  | 
2194  |  |  * Returns 1 if successful or -1 on error  | 
2195  |  |  */  | 
2196  |  | int libfvalue_string_copy_from_utf32_string_with_index(  | 
2197  |  |      libfvalue_string_t *string,  | 
2198  |  |      const uint32_t *utf32_string,  | 
2199  |  |      size_t utf32_string_size,  | 
2200  |  |      size_t *utf32_string_index,  | 
2201  |  |      uint32_t string_format_flags,  | 
2202  |  |      libcerror_error_t **error )  | 
2203  | 0  | { | 
2204  | 0  |   static char *function          = "libfvalue_string_copy_from_utf32_string_with_index";  | 
2205  | 0  |   size_t safe_utf32_string_index = 0;  | 
2206  | 0  |   size_t value_data_size         = 0;  | 
2207  | 0  |   int byte_order                 = 0;  | 
2208  |  | 
  | 
2209  | 0  |   if( string == NULL )  | 
2210  | 0  |   { | 
2211  | 0  |     libcerror_error_set(  | 
2212  | 0  |      error,  | 
2213  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2214  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2215  | 0  |      "%s: invalid string.",  | 
2216  | 0  |      function );  | 
2217  |  | 
  | 
2218  | 0  |     return( -1 );  | 
2219  | 0  |   }  | 
2220  | 0  |   if( utf32_string_size > (size_t) SSIZE_MAX )  | 
2221  | 0  |   { | 
2222  | 0  |     libcerror_error_set(  | 
2223  | 0  |      error,  | 
2224  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2225  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
2226  | 0  |      "%s: invalid UTF-32 string size value exceeds maximum.",  | 
2227  | 0  |      function );  | 
2228  |  | 
  | 
2229  | 0  |     return( -1 );  | 
2230  | 0  |   }  | 
2231  | 0  |   if( utf32_string_index == NULL )  | 
2232  | 0  |   { | 
2233  | 0  |     libcerror_error_set(  | 
2234  | 0  |      error,  | 
2235  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2236  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2237  | 0  |      "%s: invalid UTF-32 string index.",  | 
2238  | 0  |      function );  | 
2239  |  | 
  | 
2240  | 0  |     return( -1 );  | 
2241  | 0  |   }  | 
2242  | 0  |   if( *utf32_string_index >= utf32_string_size )  | 
2243  | 0  |   { | 
2244  | 0  |     libcerror_error_set(  | 
2245  | 0  |      error,  | 
2246  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2247  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
2248  | 0  |      "%s: UTF-32 string is too small.",  | 
2249  | 0  |      function );  | 
2250  |  | 
  | 
2251  | 0  |     return( -1 );  | 
2252  | 0  |   }  | 
2253  | 0  |   if( string_format_flags != 0 )  | 
2254  | 0  |   { | 
2255  | 0  |     libcerror_error_set(  | 
2256  | 0  |      error,  | 
2257  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2258  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
2259  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
2260  | 0  |      function,  | 
2261  | 0  |      string_format_flags );  | 
2262  |  | 
  | 
2263  | 0  |     return( -1 );  | 
2264  | 0  |   }  | 
2265  | 0  |   safe_utf32_string_index = *utf32_string_index;  | 
2266  |  | 
  | 
2267  | 0  |   switch( string->codepage )  | 
2268  | 0  |   { | 
2269  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
2270  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
2271  | 0  |       libcerror_error_set(  | 
2272  | 0  |        error,  | 
2273  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2274  | 0  |        LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
2275  | 0  |        "%s: unsupported encoding.",  | 
2276  | 0  |        function );  | 
2277  |  | 
  | 
2278  | 0  |       goto on_error;  | 
2279  |  |  | 
2280  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
2281  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
2282  | 0  |       if( libuna_utf16_stream_size_from_utf32(  | 
2283  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2284  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2285  | 0  |            &value_data_size,  | 
2286  | 0  |            error ) != 1 )  | 
2287  | 0  |       { | 
2288  | 0  |         libcerror_error_set(  | 
2289  | 0  |          error,  | 
2290  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2291  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2292  | 0  |          "%s: unable to determine UTF-16 stream size of UTF-32 string.",  | 
2293  | 0  |          function );  | 
2294  |  | 
  | 
2295  | 0  |         goto on_error;  | 
2296  | 0  |       }  | 
2297  | 0  |       break;  | 
2298  |  |  | 
2299  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
2300  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
2301  | 0  |       if( libuna_utf32_stream_size_from_utf32(  | 
2302  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2303  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2304  | 0  |            &value_data_size,  | 
2305  | 0  |            error ) != 1 )  | 
2306  | 0  |       { | 
2307  | 0  |         libcerror_error_set(  | 
2308  | 0  |          error,  | 
2309  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2310  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2311  | 0  |          "%s: unable to determine UTF-32 stream size of UTF-32 string.",  | 
2312  | 0  |          function );  | 
2313  |  | 
  | 
2314  | 0  |         goto on_error;  | 
2315  | 0  |       }  | 
2316  | 0  |       break;  | 
2317  |  |  | 
2318  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
2319  | 0  |       if( libuna_utf7_stream_size_from_utf32(  | 
2320  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2321  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2322  | 0  |            &value_data_size,  | 
2323  | 0  |            error ) != 1 )  | 
2324  | 0  |       { | 
2325  | 0  |         libcerror_error_set(  | 
2326  | 0  |          error,  | 
2327  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2328  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2329  | 0  |          "%s: unable to determine UTF-7 stream size of UTF-32 string.",  | 
2330  | 0  |          function );  | 
2331  |  | 
  | 
2332  | 0  |         goto on_error;  | 
2333  | 0  |       }  | 
2334  | 0  |       break;  | 
2335  |  |  | 
2336  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
2337  | 0  |       if( libuna_utf8_stream_size_from_utf32(  | 
2338  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2339  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2340  | 0  |            &value_data_size,  | 
2341  | 0  |            error ) != 1 )  | 
2342  | 0  |       { | 
2343  | 0  |         libcerror_error_set(  | 
2344  | 0  |          error,  | 
2345  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2346  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2347  | 0  |          "%s: unable to determine UTF-8 stream size of UTF-32 string.",  | 
2348  | 0  |          function );  | 
2349  |  | 
  | 
2350  | 0  |         goto on_error;  | 
2351  | 0  |       }  | 
2352  | 0  |       break;  | 
2353  |  |  | 
2354  | 0  |     default:  | 
2355  | 0  |       if( libuna_byte_stream_size_from_utf32(  | 
2356  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2357  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2358  | 0  |            string->codepage,  | 
2359  | 0  |            &value_data_size,  | 
2360  | 0  |            error ) != 1 )  | 
2361  | 0  |       { | 
2362  | 0  |         libcerror_error_set(  | 
2363  | 0  |          error,  | 
2364  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2365  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2366  | 0  |          "%s: unable to determine byte stream size of UTF-32 string.",  | 
2367  | 0  |          function );  | 
2368  |  | 
  | 
2369  | 0  |         goto on_error;  | 
2370  | 0  |       }  | 
2371  | 0  |       break;  | 
2372  |  | 
  | 
2373  | 0  |   }  | 
2374  | 0  |   if( string->data != NULL )  | 
2375  | 0  |   { | 
2376  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
2377  | 0  |     { | 
2378  | 0  |       memory_free(  | 
2379  | 0  |        string->data );  | 
2380  |  | 
  | 
2381  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
2382  | 0  |     }  | 
2383  | 0  |     string->data      = NULL;  | 
2384  | 0  |     string->data_size = 0;  | 
2385  | 0  |   }  | 
2386  | 0  |   string->data_size = value_data_size;  | 
2387  |  | 
  | 
2388  | 0  |   string->data = (uint8_t *) memory_allocate(  | 
2389  | 0  |                               sizeof( uint8_t ) * string->data_size );  | 
2390  |  | 
  | 
2391  | 0  |   if( string->data == NULL )  | 
2392  | 0  |   { | 
2393  | 0  |     libcerror_error_set(  | 
2394  | 0  |      error,  | 
2395  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
2396  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
2397  | 0  |      "%s: unable to create string data.",  | 
2398  | 0  |      function );  | 
2399  |  | 
  | 
2400  | 0  |     goto on_error;  | 
2401  | 0  |   }  | 
2402  | 0  |   string->flags |= LIBFVALUE_VALUE_FLAG_DATA_MANAGED;  | 
2403  |  | 
  | 
2404  | 0  |   switch( string->codepage )  | 
2405  | 0  |   { | 
2406  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
2407  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
2408  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
2409  | 0  |       { | 
2410  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2411  | 0  |       }  | 
2412  | 0  |       else  | 
2413  | 0  |       { | 
2414  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2415  | 0  |       }  | 
2416  | 0  |       if( libuna_utf16_stream_copy_from_utf32(  | 
2417  | 0  |            string->data,  | 
2418  | 0  |            string->data_size,  | 
2419  | 0  |            byte_order,  | 
2420  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2421  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2422  | 0  |            error ) != 1 )  | 
2423  | 0  |       { | 
2424  | 0  |         libcerror_error_set(  | 
2425  | 0  |          error,  | 
2426  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2427  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2428  | 0  |          "%s: unable to copy UTF-16 stream from UTF-32 string.",  | 
2429  | 0  |          function );  | 
2430  |  | 
  | 
2431  | 0  |         goto on_error;  | 
2432  | 0  |       }  | 
2433  | 0  |       break;  | 
2434  |  |  | 
2435  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
2436  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
2437  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
2438  | 0  |       { | 
2439  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2440  | 0  |       }  | 
2441  | 0  |       else  | 
2442  | 0  |       { | 
2443  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2444  | 0  |       }  | 
2445  | 0  |       if( libuna_utf32_stream_copy_from_utf32(  | 
2446  | 0  |            string->data,  | 
2447  | 0  |            string->data_size,  | 
2448  | 0  |            byte_order,  | 
2449  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2450  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2451  | 0  |            error ) != 1 )  | 
2452  | 0  |       { | 
2453  | 0  |         libcerror_error_set(  | 
2454  | 0  |          error,  | 
2455  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2456  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2457  | 0  |          "%s: unable to copy UTF-32 stream from UTF-32 string.",  | 
2458  | 0  |          function );  | 
2459  |  | 
  | 
2460  | 0  |         goto on_error;  | 
2461  | 0  |       }  | 
2462  | 0  |       break;  | 
2463  |  |  | 
2464  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
2465  | 0  |       if( libuna_utf7_stream_copy_from_utf32(  | 
2466  | 0  |            string->data,  | 
2467  | 0  |            string->data_size,  | 
2468  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2469  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2470  | 0  |            error ) != 1 )  | 
2471  | 0  |       { | 
2472  | 0  |         libcerror_error_set(  | 
2473  | 0  |          error,  | 
2474  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2475  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2476  | 0  |          "%s: unable to copy UTF-7 stream from UTF-32 string.",  | 
2477  | 0  |          function );  | 
2478  |  | 
  | 
2479  | 0  |         goto on_error;  | 
2480  | 0  |       }  | 
2481  | 0  |       break;  | 
2482  |  |  | 
2483  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
2484  | 0  |       if( libuna_utf8_stream_copy_from_utf32(  | 
2485  | 0  |            string->data,  | 
2486  | 0  |            string->data_size,  | 
2487  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2488  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2489  | 0  |            error ) != 1 )  | 
2490  | 0  |       { | 
2491  | 0  |         libcerror_error_set(  | 
2492  | 0  |          error,  | 
2493  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2494  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2495  | 0  |          "%s: unable to copy UTF-8 stream from UTF-32 string.",  | 
2496  | 0  |          function );  | 
2497  |  | 
  | 
2498  | 0  |         goto on_error;  | 
2499  | 0  |       }  | 
2500  | 0  |       break;  | 
2501  |  |  | 
2502  | 0  |     default:  | 
2503  | 0  |       if( libuna_byte_stream_copy_from_utf32(  | 
2504  | 0  |            string->data,  | 
2505  | 0  |            string->data_size,  | 
2506  | 0  |            string->codepage,  | 
2507  | 0  |            &( utf32_string[ safe_utf32_string_index ] ),  | 
2508  | 0  |            utf32_string_size - safe_utf32_string_index,  | 
2509  | 0  |            error ) != 1 )  | 
2510  | 0  |       { | 
2511  | 0  |         libcerror_error_set(  | 
2512  | 0  |          error,  | 
2513  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2514  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2515  | 0  |          "%s: unable to copy byte stream from UTF-32 string.",  | 
2516  | 0  |          function );  | 
2517  |  | 
  | 
2518  | 0  |         goto on_error;  | 
2519  | 0  |       }  | 
2520  | 0  |       break;  | 
2521  | 0  |   }  | 
2522  | 0  |   *utf32_string_index = utf32_string_size;  | 
2523  |  | 
  | 
2524  | 0  |   return( 1 );  | 
2525  |  |  | 
2526  | 0  | on_error:  | 
2527  | 0  |   if( string->data != NULL )  | 
2528  | 0  |   { | 
2529  | 0  |     if( ( string->flags & LIBFVALUE_VALUE_FLAG_DATA_MANAGED ) != 0 )  | 
2530  | 0  |     { | 
2531  | 0  |       memory_free(  | 
2532  | 0  |        string->data );  | 
2533  |  | 
  | 
2534  | 0  |       string->flags &= ~( LIBFVALUE_VALUE_FLAG_DATA_MANAGED );  | 
2535  | 0  |     }  | 
2536  | 0  |     string->data      = NULL;  | 
2537  | 0  |     string->data_size = 0;  | 
2538  | 0  |   }  | 
2539  | 0  |   return( -1 );  | 
2540  | 0  | }  | 
2541  |  |  | 
2542  |  | /* Retrieves the size of an UTF-32 encoded string of the string  | 
2543  |  |  * Returns 1 if successful or -1 on error  | 
2544  |  |  */  | 
2545  |  | int libfvalue_string_get_utf32_string_size(  | 
2546  |  |      libfvalue_string_t *string,  | 
2547  |  |      size_t *utf32_string_size,  | 
2548  |  |      uint32_t string_format_flags,  | 
2549  |  |      libcerror_error_t **error )  | 
2550  | 0  | { | 
2551  | 0  |   static char *function = "libfvalue_string_get_utf32_string_size";  | 
2552  | 0  |   int byte_order        = 0;  | 
2553  | 0  |   int result            = 0;  | 
2554  |  | 
  | 
2555  | 0  |   if( string == NULL )  | 
2556  | 0  |   { | 
2557  | 0  |     libcerror_error_set(  | 
2558  | 0  |      error,  | 
2559  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2560  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2561  | 0  |      "%s: invalid string.",  | 
2562  | 0  |      function );  | 
2563  |  | 
  | 
2564  | 0  |     return( -1 );  | 
2565  | 0  |   }  | 
2566  | 0  |   if( string_format_flags != 0 )  | 
2567  | 0  |   { | 
2568  | 0  |     libcerror_error_set(  | 
2569  | 0  |      error,  | 
2570  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2571  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
2572  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
2573  | 0  |      function,  | 
2574  | 0  |      string_format_flags );  | 
2575  |  | 
  | 
2576  | 0  |     return( -1 );  | 
2577  | 0  |   }  | 
2578  | 0  |   if( ( string->data == NULL )  | 
2579  | 0  |    || ( string->data_size == 0 ) )  | 
2580  | 0  |   { | 
2581  | 0  |     if( utf32_string_size == NULL )  | 
2582  | 0  |     { | 
2583  | 0  |       libcerror_error_set(  | 
2584  | 0  |        error,  | 
2585  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2586  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2587  | 0  |        "%s: invalid UTF-32 string size.",  | 
2588  | 0  |        function );  | 
2589  |  | 
  | 
2590  | 0  |       return( -1 );  | 
2591  | 0  |     }  | 
2592  | 0  |     *utf32_string_size = 1;  | 
2593  | 0  |   }  | 
2594  | 0  |   else switch( string->codepage )  | 
2595  | 0  |   { | 
2596  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
2597  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
2598  | 0  |       { | 
2599  | 0  |         result = libuna_utf32_string_size_from_utf16_stream(  | 
2600  | 0  |                   string->data,  | 
2601  | 0  |                   string->data_size,  | 
2602  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
2603  | 0  |                   utf32_string_size,  | 
2604  | 0  |                   error );  | 
2605  |  | 
  | 
2606  | 0  |         if( result != 1 )  | 
2607  | 0  |         { | 
2608  | 0  |           libcerror_error_set(  | 
2609  | 0  |            error,  | 
2610  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2611  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2612  | 0  |            "%s: unable to determine UTF-32 string size of UTF-16 stream.",  | 
2613  | 0  |            function );  | 
2614  |  | 
  | 
2615  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
2616  |  |           if( ( error != NULL )  | 
2617  |  |            && ( *error != NULL ) )  | 
2618  |  |           { | 
2619  |  |             libcnotify_print_error_backtrace(  | 
2620  |  |              *error );  | 
2621  |  |           }  | 
2622  |  | #endif  | 
2623  | 0  |           libcerror_error_free(  | 
2624  | 0  |            error );  | 
2625  | 0  |         }  | 
2626  | 0  |       }  | 
2627  | 0  |       if( result != 1 )  | 
2628  | 0  |       { | 
2629  | 0  |         if( libuna_utf32_string_size_from_byte_stream(  | 
2630  | 0  |              string->data,  | 
2631  | 0  |              string->data_size,  | 
2632  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
2633  | 0  |              utf32_string_size,  | 
2634  | 0  |              error ) != 1 )  | 
2635  | 0  |         { | 
2636  | 0  |           libcerror_error_set(  | 
2637  | 0  |            error,  | 
2638  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2639  | 0  |            LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2640  | 0  |            "%s: unable to determine UTF-32 string size of byte stream.",  | 
2641  | 0  |            function );  | 
2642  |  | 
  | 
2643  | 0  |           return( -1 );  | 
2644  | 0  |         }  | 
2645  | 0  |       }  | 
2646  | 0  |       break;  | 
2647  |  |  | 
2648  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
2649  | 0  |       if( libuna_utf32_string_size_from_scsu_stream(  | 
2650  | 0  |            string->data,  | 
2651  | 0  |            string->data_size,  | 
2652  | 0  |            utf32_string_size,  | 
2653  | 0  |            error ) != 1 )  | 
2654  | 0  |       { | 
2655  | 0  |         libcerror_error_set(  | 
2656  | 0  |          error,  | 
2657  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2658  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2659  | 0  |          "%s: unable to determine UTF-32 string size of SCSU stream.",  | 
2660  | 0  |          function );  | 
2661  |  | 
  | 
2662  | 0  |         return( -1 );  | 
2663  | 0  |       }  | 
2664  | 0  |       break;  | 
2665  |  |  | 
2666  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
2667  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
2668  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
2669  | 0  |       { | 
2670  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2671  | 0  |       }  | 
2672  | 0  |       else  | 
2673  | 0  |       { | 
2674  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2675  | 0  |       }  | 
2676  | 0  |       if( libuna_utf32_string_size_from_utf16_stream(  | 
2677  | 0  |            string->data,  | 
2678  | 0  |            string->data_size,  | 
2679  | 0  |            byte_order,  | 
2680  | 0  |            utf32_string_size,  | 
2681  | 0  |            error ) != 1 )  | 
2682  | 0  |       { | 
2683  | 0  |         libcerror_error_set(  | 
2684  | 0  |          error,  | 
2685  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2686  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2687  | 0  |          "%s: unable to determine UTF-32 string size of UTF-16 stream.",  | 
2688  | 0  |          function );  | 
2689  |  | 
  | 
2690  | 0  |         return( -1 );  | 
2691  | 0  |       }  | 
2692  | 0  |       break;  | 
2693  |  |  | 
2694  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
2695  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
2696  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
2697  | 0  |       { | 
2698  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2699  | 0  |       }  | 
2700  | 0  |       else  | 
2701  | 0  |       { | 
2702  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2703  | 0  |       }  | 
2704  | 0  |       if( libuna_utf32_string_size_from_utf32_stream(  | 
2705  | 0  |            string->data,  | 
2706  | 0  |            string->data_size,  | 
2707  | 0  |            byte_order,  | 
2708  | 0  |            utf32_string_size,  | 
2709  | 0  |            error ) != 1 )  | 
2710  | 0  |       { | 
2711  | 0  |         libcerror_error_set(  | 
2712  | 0  |          error,  | 
2713  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2714  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2715  | 0  |          "%s: unable to determine UTF-32 string size of UTF-32 stream.",  | 
2716  | 0  |          function );  | 
2717  |  | 
  | 
2718  | 0  |         return( -1 );  | 
2719  | 0  |       }  | 
2720  | 0  |       break;  | 
2721  |  |  | 
2722  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
2723  | 0  |       if( libuna_utf32_string_size_from_utf7_stream(  | 
2724  | 0  |            string->data,  | 
2725  | 0  |            string->data_size,  | 
2726  | 0  |            utf32_string_size,  | 
2727  | 0  |            error ) != 1 )  | 
2728  | 0  |       { | 
2729  | 0  |         libcerror_error_set(  | 
2730  | 0  |          error,  | 
2731  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2732  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2733  | 0  |          "%s: unable to determine UTF-32 string size of UTF-7 stream.",  | 
2734  | 0  |          function );  | 
2735  |  | 
  | 
2736  | 0  |         return( -1 );  | 
2737  | 0  |       }  | 
2738  | 0  |       break;  | 
2739  |  |  | 
2740  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
2741  | 0  |       if( libuna_utf32_string_size_from_utf8_stream(  | 
2742  | 0  |            string->data,  | 
2743  | 0  |            string->data_size,  | 
2744  | 0  |            utf32_string_size,  | 
2745  | 0  |            error ) != 1 )  | 
2746  | 0  |       { | 
2747  | 0  |         libcerror_error_set(  | 
2748  | 0  |          error,  | 
2749  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2750  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2751  | 0  |          "%s: unable to determine UTF-32 string size of UTF-8 stream.",  | 
2752  | 0  |          function );  | 
2753  |  | 
  | 
2754  | 0  |         return( -1 );  | 
2755  | 0  |       }  | 
2756  | 0  |       break;  | 
2757  |  |  | 
2758  | 0  |     default:  | 
2759  | 0  |       if( libuna_utf32_string_size_from_byte_stream(  | 
2760  | 0  |            string->data,  | 
2761  | 0  |            string->data_size,  | 
2762  | 0  |            string->codepage,  | 
2763  | 0  |            utf32_string_size,  | 
2764  | 0  |            error ) != 1 )  | 
2765  | 0  |       { | 
2766  | 0  |         libcerror_error_set(  | 
2767  | 0  |          error,  | 
2768  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2769  | 0  |          LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2770  | 0  |          "%s: unable to determine UTF-32 string size of byte stream.",  | 
2771  | 0  |          function );  | 
2772  |  | 
  | 
2773  | 0  |         return( -1 );  | 
2774  | 0  |       }  | 
2775  | 0  |       break;  | 
2776  | 0  |   }  | 
2777  | 0  |   return( 1 );  | 
2778  | 0  | }  | 
2779  |  |  | 
2780  |  | /* Copies the string to an UTF-32 encoded string  | 
2781  |  |  * Returns 1 if successful or -1 on error  | 
2782  |  |  */  | 
2783  |  | int libfvalue_string_copy_to_utf32_string_with_index(  | 
2784  |  |      libfvalue_string_t *string,  | 
2785  |  |      uint32_t *utf32_string,  | 
2786  |  |      size_t utf32_string_size,  | 
2787  |  |      size_t *utf32_string_index,  | 
2788  |  |      uint32_t string_format_flags,  | 
2789  |  |      libcerror_error_t **error )  | 
2790  | 0  | { | 
2791  | 0  |   static char *function = "libfvalue_string_copy_to_utf32_string_with_index";  | 
2792  | 0  |   int byte_order        = 0;  | 
2793  | 0  |   int result            = 0;  | 
2794  |  | 
  | 
2795  | 0  |   if( string == NULL )  | 
2796  | 0  |   { | 
2797  | 0  |     libcerror_error_set(  | 
2798  | 0  |      error,  | 
2799  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2800  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2801  | 0  |      "%s: invalid string.",  | 
2802  | 0  |      function );  | 
2803  |  | 
  | 
2804  | 0  |     return( -1 );  | 
2805  | 0  |   }  | 
2806  | 0  |   if( string_format_flags != 0 )  | 
2807  | 0  |   { | 
2808  | 0  |     libcerror_error_set(  | 
2809  | 0  |      error,  | 
2810  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2811  | 0  |      LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,  | 
2812  | 0  |      "%s: unsupported string format flags: 0x%08" PRIx32 ".",  | 
2813  | 0  |      function,  | 
2814  | 0  |      string_format_flags );  | 
2815  |  | 
  | 
2816  | 0  |     return( -1 );  | 
2817  | 0  |   }  | 
2818  | 0  |   if( ( string->data == NULL )  | 
2819  | 0  |    || ( string->data_size == 0 ) )  | 
2820  | 0  |   { | 
2821  | 0  |     if( utf32_string == NULL )  | 
2822  | 0  |     { | 
2823  | 0  |       libcerror_error_set(  | 
2824  | 0  |        error,  | 
2825  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2826  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2827  | 0  |        "%s: invalid UTF-32 string.",  | 
2828  | 0  |        function );  | 
2829  |  | 
  | 
2830  | 0  |       return( -1 );  | 
2831  | 0  |     }  | 
2832  | 0  |     if( utf32_string_size > (size_t) SSIZE_MAX )  | 
2833  | 0  |     { | 
2834  | 0  |       libcerror_error_set(  | 
2835  | 0  |        error,  | 
2836  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2837  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,  | 
2838  | 0  |        "%s: invalid UTF-32 string size value exceeds maximum.",  | 
2839  | 0  |        function );  | 
2840  |  | 
  | 
2841  | 0  |       return( -1 );  | 
2842  | 0  |     }  | 
2843  | 0  |     if( utf32_string_index == NULL )  | 
2844  | 0  |     { | 
2845  | 0  |       libcerror_error_set(  | 
2846  | 0  |        error,  | 
2847  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2848  | 0  |        LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
2849  | 0  |        "%s: invalid UTF-32 string index.",  | 
2850  | 0  |        function );  | 
2851  |  | 
  | 
2852  | 0  |       return( -1 );  | 
2853  | 0  |     }  | 
2854  | 0  |     if( *utf32_string_index >= utf32_string_size )  | 
2855  | 0  |     { | 
2856  | 0  |       libcerror_error_set(  | 
2857  | 0  |        error,  | 
2858  | 0  |        LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
2859  | 0  |        LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,  | 
2860  | 0  |        "%s: UTF-32 string is too small.",  | 
2861  | 0  |        function );  | 
2862  |  | 
  | 
2863  | 0  |       return( -1 );  | 
2864  | 0  |     }  | 
2865  | 0  |     utf32_string[ *utf32_string_index ] = 0;  | 
2866  |  | 
  | 
2867  | 0  |     *utf32_string_index += 1;  | 
2868  | 0  |   }  | 
2869  | 0  |   else switch( string->codepage )  | 
2870  | 0  |   { | 
2871  | 0  |     case LIBFVALUE_CODEPAGE_1200_MIXED:  | 
2872  | 0  |       if( ( string->data_size % 2 ) == 0 )  | 
2873  | 0  |       { | 
2874  | 0  |         result = libuna_utf32_string_with_index_copy_from_utf16_stream(  | 
2875  | 0  |                   utf32_string,  | 
2876  | 0  |                   utf32_string_size,  | 
2877  | 0  |                   utf32_string_index,  | 
2878  | 0  |                   string->data,  | 
2879  | 0  |                   string->data_size,  | 
2880  | 0  |                   LIBFVALUE_ENDIAN_LITTLE,  | 
2881  | 0  |                   error );  | 
2882  |  | 
  | 
2883  | 0  |         if( result != 1 )  | 
2884  | 0  |         { | 
2885  | 0  |           libcerror_error_set(  | 
2886  | 0  |            error,  | 
2887  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2888  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2889  | 0  |            "%s: unable to copy UTF-32 stream to UTF-16 string.",  | 
2890  | 0  |            function );  | 
2891  |  | 
  | 
2892  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
2893  |  |           if( ( error != NULL )  | 
2894  |  |            && ( *error != NULL ) )  | 
2895  |  |           { | 
2896  |  |             libcnotify_print_error_backtrace(  | 
2897  |  |              *error );  | 
2898  |  |           }  | 
2899  |  | #endif  | 
2900  | 0  |           libcerror_error_free(  | 
2901  | 0  |            error );  | 
2902  | 0  |         }  | 
2903  | 0  |       }  | 
2904  | 0  |       if( result != 1 )  | 
2905  | 0  |       { | 
2906  | 0  |         if( libuna_utf32_string_with_index_copy_from_byte_stream(  | 
2907  | 0  |              utf32_string,  | 
2908  | 0  |              utf32_string_size,  | 
2909  | 0  |              utf32_string_index,  | 
2910  | 0  |              string->data,  | 
2911  | 0  |              string->data_size,  | 
2912  | 0  |              LIBUNA_CODEPAGE_ASCII,  | 
2913  | 0  |              error ) != 1 )  | 
2914  | 0  |         { | 
2915  | 0  |           libcerror_error_set(  | 
2916  | 0  |            error,  | 
2917  | 0  |            LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2918  | 0  |            LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2919  | 0  |            "%s: unable to copy byte stream to UTF-32 string.",  | 
2920  | 0  |            function );  | 
2921  |  | 
  | 
2922  | 0  |           return( -1 );  | 
2923  | 0  |         }  | 
2924  | 0  |       }  | 
2925  | 0  |       break;  | 
2926  |  |  | 
2927  | 0  |     case LIBFVALUE_CODEPAGE_SCSU:  | 
2928  | 0  |       if( libuna_utf32_string_with_index_copy_from_scsu_stream(  | 
2929  | 0  |            utf32_string,  | 
2930  | 0  |            utf32_string_size,  | 
2931  | 0  |            utf32_string_index,  | 
2932  | 0  |            string->data,  | 
2933  | 0  |            string->data_size,  | 
2934  | 0  |            error ) != 1 )  | 
2935  | 0  |       { | 
2936  | 0  |         libcerror_error_set(  | 
2937  | 0  |          error,  | 
2938  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2939  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2940  | 0  |          "%s: unable to copy SCSU stream to UTF-32 string.",  | 
2941  | 0  |          function );  | 
2942  |  | 
  | 
2943  | 0  |         return( -1 );  | 
2944  | 0  |       }  | 
2945  | 0  |       break;  | 
2946  |  |  | 
2947  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN:  | 
2948  | 0  |     case LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN:  | 
2949  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF16_BIG_ENDIAN )  | 
2950  | 0  |       { | 
2951  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2952  | 0  |       }  | 
2953  | 0  |       else  | 
2954  | 0  |       { | 
2955  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2956  | 0  |       }  | 
2957  | 0  |       if( libuna_utf32_string_with_index_copy_from_utf16_stream(  | 
2958  | 0  |            utf32_string,  | 
2959  | 0  |            utf32_string_size,  | 
2960  | 0  |            utf32_string_index,  | 
2961  | 0  |            string->data,  | 
2962  | 0  |            string->data_size,  | 
2963  | 0  |            byte_order,  | 
2964  | 0  |            error ) != 1 )  | 
2965  | 0  |       { | 
2966  | 0  |         libcerror_error_set(  | 
2967  | 0  |          error,  | 
2968  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2969  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
2970  | 0  |          "%s: unable to copy UTF-16 stream to UTF-32 string.",  | 
2971  | 0  |          function );  | 
2972  |  | 
  | 
2973  | 0  |         return( -1 );  | 
2974  | 0  |       }  | 
2975  | 0  |       break;  | 
2976  |  |  | 
2977  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN:  | 
2978  | 0  |     case LIBFVALUE_CODEPAGE_UTF32_LITTLE_ENDIAN:  | 
2979  | 0  |       if( string->codepage == LIBFVALUE_CODEPAGE_UTF32_BIG_ENDIAN )  | 
2980  | 0  |       { | 
2981  | 0  |         byte_order = LIBFVALUE_ENDIAN_BIG;  | 
2982  | 0  |       }  | 
2983  | 0  |       else  | 
2984  | 0  |       { | 
2985  | 0  |         byte_order = LIBFVALUE_ENDIAN_LITTLE;  | 
2986  | 0  |       }  | 
2987  | 0  |       if( libuna_utf32_string_with_index_copy_from_utf32_stream(  | 
2988  | 0  |            utf32_string,  | 
2989  | 0  |            utf32_string_size,  | 
2990  | 0  |            utf32_string_index,  | 
2991  | 0  |            string->data,  | 
2992  | 0  |            string->data_size,  | 
2993  | 0  |            byte_order,  | 
2994  | 0  |            error ) != 1 )  | 
2995  | 0  |       { | 
2996  | 0  |         libcerror_error_set(  | 
2997  | 0  |          error,  | 
2998  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2999  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
3000  | 0  |          "%s: unable to copy UTF-32 stream to UTF-32 string.",  | 
3001  | 0  |          function );  | 
3002  |  | 
  | 
3003  | 0  |         return( -1 );  | 
3004  | 0  |       }  | 
3005  | 0  |       break;  | 
3006  |  |  | 
3007  | 0  |     case LIBFVALUE_CODEPAGE_UTF7:  | 
3008  | 0  |       if( libuna_utf32_string_with_index_copy_from_utf7_stream(  | 
3009  | 0  |            utf32_string,  | 
3010  | 0  |            utf32_string_size,  | 
3011  | 0  |            utf32_string_index,  | 
3012  | 0  |            string->data,  | 
3013  | 0  |            string->data_size,  | 
3014  | 0  |            error ) != 1 )  | 
3015  | 0  |       { | 
3016  | 0  |         libcerror_error_set(  | 
3017  | 0  |          error,  | 
3018  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
3019  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
3020  | 0  |          "%s: unable to copy UTF-7 stream to UTF-32 string.",  | 
3021  | 0  |          function );  | 
3022  |  | 
  | 
3023  | 0  |         return( -1 );  | 
3024  | 0  |       }  | 
3025  | 0  |       break;  | 
3026  |  |  | 
3027  | 0  |     case LIBFVALUE_CODEPAGE_UTF8:  | 
3028  | 0  |       if( libuna_utf32_string_with_index_copy_from_utf8_stream(  | 
3029  | 0  |            utf32_string,  | 
3030  | 0  |            utf32_string_size,  | 
3031  | 0  |            utf32_string_index,  | 
3032  | 0  |            string->data,  | 
3033  | 0  |            string->data_size,  | 
3034  | 0  |            error ) != 1 )  | 
3035  | 0  |       { | 
3036  | 0  |         libcerror_error_set(  | 
3037  | 0  |          error,  | 
3038  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
3039  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
3040  | 0  |          "%s: unable to copy UTF-8 stream to UTF-32 string.",  | 
3041  | 0  |          function );  | 
3042  |  | 
  | 
3043  | 0  |         return( -1 );  | 
3044  | 0  |       }  | 
3045  | 0  |       break;  | 
3046  |  |  | 
3047  | 0  |     default:  | 
3048  | 0  |       if( libuna_utf32_string_with_index_copy_from_byte_stream(  | 
3049  | 0  |            utf32_string,  | 
3050  | 0  |            utf32_string_size,  | 
3051  | 0  |            utf32_string_index,  | 
3052  | 0  |            string->data,  | 
3053  | 0  |            string->data_size,  | 
3054  | 0  |            string->codepage,  | 
3055  | 0  |            error ) != 1 )  | 
3056  | 0  |       { | 
3057  | 0  |         libcerror_error_set(  | 
3058  | 0  |          error,  | 
3059  | 0  |          LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
3060  | 0  |          LIBCERROR_RUNTIME_ERROR_COPY_FAILED,  | 
3061  | 0  |          "%s: unable to copy byte stream to UTF-32 string.",  | 
3062  | 0  |          function );  | 
3063  |  | 
  | 
3064  | 0  |         return( -1 );  | 
3065  | 0  |       }  | 
3066  | 0  |       break;  | 
3067  | 0  |   }  | 
3068  | 0  |   return( 1 );  | 
3069  | 0  | }  | 
3070  |  |  |