/src/libwrc/libwrc/libwrc_string_table_resource.c
Line | Count | Source |
1 | | /* |
2 | | * String table (STRINGTABLE) resource functions |
3 | | * |
4 | | * Copyright (C) 2011-2025, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libwrc_definitions.h" |
27 | | #include "libwrc_libcdata.h" |
28 | | #include "libwrc_libcerror.h" |
29 | | #include "libwrc_libcnotify.h" |
30 | | #include "libwrc_libuna.h" |
31 | | #include "libwrc_string_table_resource.h" |
32 | | #include "libwrc_table_entry.h" |
33 | | |
34 | | /* Creates a string table resource |
35 | | * Make sure the value string_table_resource is referencing, is set to NULL |
36 | | * Returns 1 if successful or -1 on error |
37 | | */ |
38 | | int libwrc_string_table_resource_initialize( |
39 | | libwrc_string_table_resource_t **string_table_resource, |
40 | | libcerror_error_t **error ) |
41 | 197 | { |
42 | 197 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
43 | 197 | static char *function = "libwrc_string_table_resource_initialize"; |
44 | | |
45 | 197 | if( string_table_resource == NULL ) |
46 | 0 | { |
47 | 0 | libcerror_error_set( |
48 | 0 | error, |
49 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
50 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
51 | 0 | "%s: invalid string table resource.", |
52 | 0 | function ); |
53 | |
|
54 | 0 | return( -1 ); |
55 | 0 | } |
56 | 197 | if( *string_table_resource != NULL ) |
57 | 0 | { |
58 | 0 | libcerror_error_set( |
59 | 0 | error, |
60 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
61 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
62 | 0 | "%s: invalid string table resource value already set.", |
63 | 0 | function ); |
64 | |
|
65 | 0 | return( -1 ); |
66 | 0 | } |
67 | 197 | internal_string_table_resource = memory_allocate_structure( |
68 | 197 | libwrc_internal_string_table_resource_t ); |
69 | | |
70 | 197 | if( internal_string_table_resource == NULL ) |
71 | 0 | { |
72 | 0 | libcerror_error_set( |
73 | 0 | error, |
74 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
75 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
76 | 0 | "%s: unable to create string table resource.", |
77 | 0 | function ); |
78 | |
|
79 | 0 | goto on_error; |
80 | 0 | } |
81 | 197 | if( memory_set( |
82 | 197 | internal_string_table_resource, |
83 | 197 | 0, |
84 | 197 | sizeof( libwrc_internal_string_table_resource_t ) ) == NULL ) |
85 | 0 | { |
86 | 0 | libcerror_error_set( |
87 | 0 | error, |
88 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
89 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
90 | 0 | "%s: unable to clear string table resource.", |
91 | 0 | function ); |
92 | |
|
93 | 0 | memory_free( |
94 | 0 | internal_string_table_resource ); |
95 | |
|
96 | 0 | return( -1 ); |
97 | 0 | } |
98 | 197 | if( libcdata_array_initialize( |
99 | 197 | &( internal_string_table_resource->entries_array ), |
100 | 197 | 0, |
101 | 197 | error ) != 1 ) |
102 | 0 | { |
103 | 0 | libcerror_error_set( |
104 | 0 | error, |
105 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
106 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
107 | 0 | "%s: unable to create entries array.", |
108 | 0 | function ); |
109 | |
|
110 | 0 | goto on_error; |
111 | 0 | } |
112 | 197 | *string_table_resource = (libwrc_string_table_resource_t *) internal_string_table_resource; |
113 | | |
114 | 197 | return( 1 ); |
115 | | |
116 | 0 | on_error: |
117 | 0 | if( internal_string_table_resource != NULL ) |
118 | 0 | { |
119 | 0 | memory_free( |
120 | 0 | internal_string_table_resource ); |
121 | 0 | } |
122 | 0 | return( -1 ); |
123 | 197 | } |
124 | | |
125 | | /* Frees a string table resource |
126 | | * Returns 1 if successful or -1 on error |
127 | | */ |
128 | | int libwrc_string_table_resource_free( |
129 | | libwrc_string_table_resource_t **string_table_resource, |
130 | | libcerror_error_t **error ) |
131 | 197 | { |
132 | 197 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
133 | 197 | static char *function = "libwrc_string_table_resource_free"; |
134 | 197 | int result = 1; |
135 | | |
136 | 197 | if( string_table_resource == NULL ) |
137 | 0 | { |
138 | 0 | libcerror_error_set( |
139 | 0 | error, |
140 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
141 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
142 | 0 | "%s: invalid string table resource.", |
143 | 0 | function ); |
144 | |
|
145 | 0 | return( -1 ); |
146 | 0 | } |
147 | 197 | if( *string_table_resource != NULL ) |
148 | 197 | { |
149 | 197 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) *string_table_resource; |
150 | 197 | *string_table_resource = NULL; |
151 | | |
152 | 197 | if( libcdata_array_free( |
153 | 197 | &( internal_string_table_resource->entries_array ), |
154 | 197 | (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_table_entry_free, |
155 | 197 | error ) != 1 ) |
156 | 0 | { |
157 | 0 | libcerror_error_set( |
158 | 0 | error, |
159 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
160 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
161 | 0 | "%s: unable to free entries array.", |
162 | 0 | function ); |
163 | |
|
164 | 0 | result = -1; |
165 | 0 | } |
166 | 197 | memory_free( |
167 | 197 | internal_string_table_resource ); |
168 | 197 | } |
169 | 197 | return( result ); |
170 | 197 | } |
171 | | |
172 | | /* Reads the string table resource |
173 | | * Returns 1 if successful or -1 on error |
174 | | */ |
175 | | int libwrc_string_table_resource_read( |
176 | | libwrc_string_table_resource_t *string_table_resource, |
177 | | const uint8_t *data, |
178 | | size_t data_size, |
179 | | uint32_t base_identifier, |
180 | | libcerror_error_t **error ) |
181 | 197 | { |
182 | 197 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
183 | 197 | libwrc_table_entry_t *table_entry = NULL; |
184 | 197 | static char *function = "libwrc_string_table_resource_read"; |
185 | 197 | size_t data_offset = 0; |
186 | 197 | uint32_t string_size = 0; |
187 | 197 | int entry_index = 0; |
188 | 197 | int string_index = 0; |
189 | | |
190 | 197 | if( string_table_resource == NULL ) |
191 | 0 | { |
192 | 0 | libcerror_error_set( |
193 | 0 | error, |
194 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
195 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
196 | 0 | "%s: invalid string table resource.", |
197 | 0 | function ); |
198 | |
|
199 | 0 | return( -1 ); |
200 | 0 | } |
201 | 197 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
202 | | |
203 | 197 | if( data == NULL ) |
204 | 0 | { |
205 | 0 | libcerror_error_set( |
206 | 0 | error, |
207 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
208 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
209 | 0 | "%s: invalid data.", |
210 | 0 | function ); |
211 | |
|
212 | 0 | return( -1 ); |
213 | 0 | } |
214 | 197 | if( ( data_size < 2 ) |
215 | 196 | || ( data_size > (size_t) SSIZE_MAX ) ) |
216 | 1 | { |
217 | 1 | libcerror_error_set( |
218 | 1 | error, |
219 | 1 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
220 | 1 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
221 | 1 | "%s: invalid data size value out of bounds.", |
222 | 1 | function ); |
223 | | |
224 | 1 | return( -1 ); |
225 | 1 | } |
226 | | #if defined( HAVE_DEBUG_OUTPUT ) |
227 | | if( libcnotify_verbose != 0 ) |
228 | | { |
229 | | libcnotify_printf( |
230 | | "%s: data:\n", |
231 | | function ); |
232 | | libcnotify_print_data( |
233 | | data, |
234 | | data_size, |
235 | | 0 ); |
236 | | } |
237 | | #endif |
238 | 2.37M | while( data_offset < ( data_size - 2 ) ) |
239 | 2.37M | { |
240 | 2.37M | byte_stream_copy_to_uint16_little_endian( |
241 | 2.37M | &( data[ data_offset ] ), |
242 | 2.37M | string_size ); |
243 | | |
244 | 2.37M | data_offset += 2; |
245 | | |
246 | | #if defined( HAVE_DEBUG_OUTPUT ) |
247 | | if( libcnotify_verbose != 0 ) |
248 | | { |
249 | | libcnotify_printf( |
250 | | "%s: string: %02d length\t\t\t: %" PRIu32 "\n", |
251 | | function, |
252 | | string_index, |
253 | | string_size ); |
254 | | } |
255 | | #endif |
256 | 2.37M | if( string_size > 0 ) |
257 | 1.52M | { |
258 | 1.52M | if( string_size > ( ( data_size - data_offset ) / 2 ) ) |
259 | 90 | { |
260 | 90 | libcerror_error_set( |
261 | 90 | error, |
262 | 90 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
263 | 90 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
264 | 90 | "%s: invalid string size value out of bound.", |
265 | 90 | function ); |
266 | | |
267 | 90 | goto on_error; |
268 | 90 | } |
269 | 1.52M | string_size *= 2; |
270 | | |
271 | | #if defined( HAVE_DEBUG_OUTPUT ) |
272 | | if( libcnotify_verbose != 0 ) |
273 | | { |
274 | | libcnotify_printf( |
275 | | "%s: string: %02 data:\n", |
276 | | function, |
277 | | string_index ); |
278 | | libcnotify_print_data( |
279 | | &( data[ data_offset ] ), |
280 | | (size_t) string_size, |
281 | | 0 ); |
282 | | } |
283 | | #endif |
284 | 1.52M | if( libwrc_table_entry_initialize( |
285 | 1.52M | &table_entry, |
286 | 1.52M | error ) != 1 ) |
287 | 0 | { |
288 | 0 | libcerror_error_set( |
289 | 0 | error, |
290 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
291 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
292 | 0 | "%s: unable to create table entry.", |
293 | 0 | function ); |
294 | |
|
295 | 0 | goto on_error; |
296 | 0 | } |
297 | 1.52M | if( libwrc_table_entry_set_string( |
298 | 1.52M | table_entry, |
299 | 1.52M | &( data[ data_offset ] ), |
300 | 1.52M | (size_t) string_size, |
301 | 1.52M | LIBUNA_CODEPAGE_UTF16_LITTLE_ENDIAN, |
302 | 1.52M | error ) != 1 ) |
303 | 0 | { |
304 | 0 | libcerror_error_set( |
305 | 0 | error, |
306 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
307 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
308 | 0 | "%s: unable to set data of table entry.", |
309 | 0 | function ); |
310 | |
|
311 | 0 | goto on_error; |
312 | 0 | } |
313 | 1.52M | table_entry->identifier = ( ( base_identifier - 1 ) << 4 ) | (uint32_t) string_index; |
314 | | |
315 | 1.52M | if( libcdata_array_append_entry( |
316 | 1.52M | internal_string_table_resource->entries_array, |
317 | 1.52M | &entry_index, |
318 | 1.52M | (intptr_t *) table_entry, |
319 | 1.52M | error ) != 1 ) |
320 | 0 | { |
321 | 0 | libcerror_error_set( |
322 | 0 | error, |
323 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
324 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
325 | 0 | "%s: unable to append table entry to array.", |
326 | 0 | function ); |
327 | |
|
328 | 0 | goto on_error; |
329 | 0 | } |
330 | 1.52M | table_entry = NULL; |
331 | | |
332 | 1.52M | data_offset += (size_t) string_size; |
333 | 1.52M | } |
334 | | #if defined( HAVE_DEBUG_OUTPUT ) |
335 | | else if( libcnotify_verbose != 0 ) |
336 | | { |
337 | | libcnotify_printf( |
338 | | "\n" ); |
339 | | } |
340 | | #endif |
341 | 2.37M | string_index++; |
342 | 2.37M | } |
343 | 106 | return( 1 ); |
344 | | |
345 | 90 | on_error: |
346 | 90 | if( table_entry != NULL ) |
347 | 0 | { |
348 | 0 | libwrc_table_entry_free( |
349 | 0 | &table_entry, |
350 | 0 | NULL ); |
351 | 0 | } |
352 | 90 | libcdata_array_empty( |
353 | 90 | internal_string_table_resource->entries_array, |
354 | 90 | (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_table_entry_free, |
355 | 90 | error ); |
356 | | |
357 | 90 | return( -1 ); |
358 | 196 | } |
359 | | |
360 | | /* Retrieves the number of strings |
361 | | * Returns 1 if successful or -1 on error |
362 | | */ |
363 | | int libwrc_string_table_resource_get_number_of_strings( |
364 | | libwrc_string_table_resource_t *string_table_resource, |
365 | | int *number_of_strings, |
366 | | libcerror_error_t **error ) |
367 | 0 | { |
368 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
369 | 0 | static char *function = "libwrc_string_table_resource_get_number_of_strings"; |
370 | |
|
371 | 0 | if( string_table_resource == NULL ) |
372 | 0 | { |
373 | 0 | libcerror_error_set( |
374 | 0 | error, |
375 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
376 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
377 | 0 | "%s: invalid string table resource.", |
378 | 0 | function ); |
379 | |
|
380 | 0 | return( -1 ); |
381 | 0 | } |
382 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
383 | |
|
384 | 0 | if( libcdata_array_get_number_of_entries( |
385 | 0 | internal_string_table_resource->entries_array, |
386 | 0 | number_of_strings, |
387 | 0 | error ) != 1 ) |
388 | 0 | { |
389 | 0 | libcerror_error_set( |
390 | 0 | error, |
391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
392 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
393 | 0 | "%s: unable to retrieve number of entries from array.", |
394 | 0 | function ); |
395 | |
|
396 | 0 | return( -1 ); |
397 | 0 | } |
398 | 0 | return( 1 ); |
399 | 0 | } |
400 | | |
401 | | /* Retrieves a specific string identifier |
402 | | * Returns 1 if successful or -1 on error |
403 | | */ |
404 | | int libwrc_string_table_resource_get_identifier( |
405 | | libwrc_string_table_resource_t *string_table_resource, |
406 | | int string_index, |
407 | | uint32_t *string_identifier, |
408 | | libcerror_error_t **error ) |
409 | 0 | { |
410 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
411 | 0 | libwrc_table_entry_t *table_entry = NULL; |
412 | 0 | static char *function = "libwrc_string_table_resource_get_identifier"; |
413 | |
|
414 | 0 | if( string_table_resource == NULL ) |
415 | 0 | { |
416 | 0 | libcerror_error_set( |
417 | 0 | error, |
418 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
419 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
420 | 0 | "%s: invalid string table resource.", |
421 | 0 | function ); |
422 | |
|
423 | 0 | return( -1 ); |
424 | 0 | } |
425 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
426 | |
|
427 | 0 | if( string_identifier == NULL ) |
428 | 0 | { |
429 | 0 | libcerror_error_set( |
430 | 0 | error, |
431 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
432 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
433 | 0 | "%s: invalid string identifier.", |
434 | 0 | function ); |
435 | |
|
436 | 0 | return( -1 ); |
437 | 0 | } |
438 | 0 | if( libcdata_array_get_entry_by_index( |
439 | 0 | internal_string_table_resource->entries_array, |
440 | 0 | string_index, |
441 | 0 | (intptr_t **) &table_entry, |
442 | 0 | error ) != 1 ) |
443 | 0 | { |
444 | 0 | libcerror_error_set( |
445 | 0 | error, |
446 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
447 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
448 | 0 | "%s: unable to retrieve table entry: %d.", |
449 | 0 | function, |
450 | 0 | string_index ); |
451 | |
|
452 | 0 | return( -1 ); |
453 | 0 | } |
454 | 0 | if( table_entry == NULL ) |
455 | 0 | { |
456 | 0 | libcerror_error_set( |
457 | 0 | error, |
458 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
459 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
460 | 0 | "%s: missing table entry: %d.", |
461 | 0 | function, |
462 | 0 | string_index ); |
463 | |
|
464 | 0 | return( -1 ); |
465 | 0 | } |
466 | 0 | *string_identifier = table_entry->identifier; |
467 | |
|
468 | 0 | return( 1 ); |
469 | 0 | } |
470 | | |
471 | | /* Retrieves the string index for a specific identifier |
472 | | * Returns 1 if successful, 0 if no such string identifier or -1 on error |
473 | | */ |
474 | | int libwrc_string_table_resource_get_index_by_identifier( |
475 | | libwrc_string_table_resource_t *string_table_resource, |
476 | | uint32_t string_identifier, |
477 | | int *string_index, |
478 | | libcerror_error_t **error ) |
479 | 0 | { |
480 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
481 | 0 | libwrc_table_entry_t *table_entry = NULL; |
482 | 0 | static char *function = "libwrc_string_table_resource_get_index_by_identifier"; |
483 | 0 | int number_of_strings = 0; |
484 | 0 | int safe_string_index = 0; |
485 | |
|
486 | 0 | if( string_table_resource == NULL ) |
487 | 0 | { |
488 | 0 | libcerror_error_set( |
489 | 0 | error, |
490 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
491 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
492 | 0 | "%s: invalid string table resource.", |
493 | 0 | function ); |
494 | |
|
495 | 0 | return( -1 ); |
496 | 0 | } |
497 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
498 | |
|
499 | 0 | if( string_index == NULL ) |
500 | 0 | { |
501 | 0 | libcerror_error_set( |
502 | 0 | error, |
503 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
504 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
505 | 0 | "%s: invalid string index.", |
506 | 0 | function ); |
507 | |
|
508 | 0 | return( -1 ); |
509 | 0 | } |
510 | 0 | if( libcdata_array_get_number_of_entries( |
511 | 0 | internal_string_table_resource->entries_array, |
512 | 0 | &number_of_strings, |
513 | 0 | error ) != 1 ) |
514 | 0 | { |
515 | 0 | libcerror_error_set( |
516 | 0 | error, |
517 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
518 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
519 | 0 | "%s: unable to retrieve number of entries from array.", |
520 | 0 | function ); |
521 | |
|
522 | 0 | return( -1 ); |
523 | 0 | } |
524 | 0 | for( safe_string_index = 0; |
525 | 0 | safe_string_index < number_of_strings; |
526 | 0 | safe_string_index++ ) |
527 | 0 | { |
528 | 0 | if( libcdata_array_get_entry_by_index( |
529 | 0 | internal_string_table_resource->entries_array, |
530 | 0 | safe_string_index, |
531 | 0 | (intptr_t **) &table_entry, |
532 | 0 | error ) != 1 ) |
533 | 0 | { |
534 | 0 | libcerror_error_set( |
535 | 0 | error, |
536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
537 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
538 | 0 | "%s: unable to retrieve table entry: %d.", |
539 | 0 | function, |
540 | 0 | safe_string_index ); |
541 | |
|
542 | 0 | return( -1 ); |
543 | 0 | } |
544 | 0 | if( table_entry == NULL ) |
545 | 0 | { |
546 | 0 | libcerror_error_set( |
547 | 0 | error, |
548 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
549 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
550 | 0 | "%s: missing table entry: %d.", |
551 | 0 | function, |
552 | 0 | safe_string_index ); |
553 | |
|
554 | 0 | return( -1 ); |
555 | 0 | } |
556 | 0 | if( string_identifier == table_entry->identifier ) |
557 | 0 | { |
558 | 0 | *string_index = safe_string_index; |
559 | |
|
560 | 0 | return( 1 ); |
561 | 0 | } |
562 | 0 | } |
563 | 0 | return( 0 ); |
564 | 0 | } |
565 | | |
566 | | /* Retrieves the size of a specific UTF-8 formatted string string |
567 | | * Returns 1 if successful or -1 on error |
568 | | */ |
569 | | int libwrc_string_table_resource_get_utf8_string_size( |
570 | | libwrc_string_table_resource_t *string_table_resource, |
571 | | int string_index, |
572 | | size_t *utf8_string_size, |
573 | | libcerror_error_t **error ) |
574 | 0 | { |
575 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
576 | 0 | libwrc_table_entry_t *table_entry = NULL; |
577 | 0 | static char *function = "libwrc_string_table_resource_get_utf8_string_size"; |
578 | |
|
579 | 0 | if( string_table_resource == NULL ) |
580 | 0 | { |
581 | 0 | libcerror_error_set( |
582 | 0 | error, |
583 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
584 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
585 | 0 | "%s: invalid string table resource.", |
586 | 0 | function ); |
587 | |
|
588 | 0 | return( -1 ); |
589 | 0 | } |
590 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
591 | |
|
592 | 0 | if( libcdata_array_get_entry_by_index( |
593 | 0 | internal_string_table_resource->entries_array, |
594 | 0 | string_index, |
595 | 0 | (intptr_t **) &table_entry, |
596 | 0 | error ) != 1 ) |
597 | 0 | { |
598 | 0 | libcerror_error_set( |
599 | 0 | error, |
600 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
601 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
602 | 0 | "%s: unable to retrieve table entry: %d.", |
603 | 0 | function, |
604 | 0 | string_index ); |
605 | |
|
606 | 0 | return( -1 ); |
607 | 0 | } |
608 | 0 | if( libwrc_table_entry_get_utf8_string_size( |
609 | 0 | table_entry, |
610 | 0 | utf8_string_size, |
611 | 0 | error ) != 1 ) |
612 | 0 | { |
613 | 0 | libcerror_error_set( |
614 | 0 | error, |
615 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
616 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
617 | 0 | "%s: unable to retrieve UTF-8 string size of table entry: %d.", |
618 | 0 | function, |
619 | 0 | string_index ); |
620 | |
|
621 | 0 | return( -1 ); |
622 | 0 | } |
623 | 0 | return( 1 ); |
624 | 0 | } |
625 | | |
626 | | /* Retrieves a specific UTF-8 formatted string string |
627 | | * Returns 1 if successful or -1 on error |
628 | | */ |
629 | | int libwrc_string_table_resource_get_utf8_string( |
630 | | libwrc_string_table_resource_t *string_table_resource, |
631 | | int string_index, |
632 | | uint8_t *utf8_string, |
633 | | size_t utf8_string_size, |
634 | | libcerror_error_t **error ) |
635 | 0 | { |
636 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
637 | 0 | libwrc_table_entry_t *table_entry = NULL; |
638 | 0 | static char *function = "libwrc_string_table_resource_get_utf8_string"; |
639 | |
|
640 | 0 | if( string_table_resource == NULL ) |
641 | 0 | { |
642 | 0 | libcerror_error_set( |
643 | 0 | error, |
644 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
645 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
646 | 0 | "%s: invalid string table resource.", |
647 | 0 | function ); |
648 | |
|
649 | 0 | return( -1 ); |
650 | 0 | } |
651 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
652 | |
|
653 | 0 | if( libcdata_array_get_entry_by_index( |
654 | 0 | internal_string_table_resource->entries_array, |
655 | 0 | string_index, |
656 | 0 | (intptr_t **) &table_entry, |
657 | 0 | error ) != 1 ) |
658 | 0 | { |
659 | 0 | libcerror_error_set( |
660 | 0 | error, |
661 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
662 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
663 | 0 | "%s: unable to retrieve table entry: %d.", |
664 | 0 | function, |
665 | 0 | string_index ); |
666 | |
|
667 | 0 | return( -1 ); |
668 | 0 | } |
669 | 0 | if( libwrc_table_entry_get_utf8_string( |
670 | 0 | table_entry, |
671 | 0 | utf8_string, |
672 | 0 | utf8_string_size, |
673 | 0 | error ) != 1 ) |
674 | 0 | { |
675 | 0 | libcerror_error_set( |
676 | 0 | error, |
677 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
678 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
679 | 0 | "%s: unable to copy table entry: %d to UTF-8 string.", |
680 | 0 | function, |
681 | 0 | string_index ); |
682 | |
|
683 | 0 | return( -1 ); |
684 | 0 | } |
685 | 0 | return( 1 ); |
686 | 0 | } |
687 | | |
688 | | /* Retrieves the size of a specific UTF-16 formatted string string |
689 | | * Returns 1 if successful or -1 on error |
690 | | */ |
691 | | int libwrc_string_table_resource_get_utf16_string_size( |
692 | | libwrc_string_table_resource_t *string_table_resource, |
693 | | int string_index, |
694 | | size_t *utf16_string_size, |
695 | | libcerror_error_t **error ) |
696 | 0 | { |
697 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
698 | 0 | libwrc_table_entry_t *table_entry = NULL; |
699 | 0 | static char *function = "libwrc_string_table_resource_get_utf16_string_size"; |
700 | |
|
701 | 0 | if( string_table_resource == NULL ) |
702 | 0 | { |
703 | 0 | libcerror_error_set( |
704 | 0 | error, |
705 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
706 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
707 | 0 | "%s: invalid string table resource.", |
708 | 0 | function ); |
709 | |
|
710 | 0 | return( -1 ); |
711 | 0 | } |
712 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
713 | |
|
714 | 0 | if( libcdata_array_get_entry_by_index( |
715 | 0 | internal_string_table_resource->entries_array, |
716 | 0 | string_index, |
717 | 0 | (intptr_t **) &table_entry, |
718 | 0 | error ) != 1 ) |
719 | 0 | { |
720 | 0 | libcerror_error_set( |
721 | 0 | error, |
722 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
723 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
724 | 0 | "%s: unable to retrieve table entry: %d.", |
725 | 0 | function, |
726 | 0 | string_index ); |
727 | |
|
728 | 0 | return( -1 ); |
729 | 0 | } |
730 | 0 | if( libwrc_table_entry_get_utf16_string_size( |
731 | 0 | table_entry, |
732 | 0 | utf16_string_size, |
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_GET_FAILED, |
739 | 0 | "%s: unable to retrieve UTF-16 string size of table entry: %d.", |
740 | 0 | function, |
741 | 0 | string_index ); |
742 | |
|
743 | 0 | return( -1 ); |
744 | 0 | } |
745 | 0 | return( 1 ); |
746 | 0 | } |
747 | | |
748 | | /* Retrieves a specific UTF-16 formatted string string |
749 | | * Returns 1 if successful or -1 on error |
750 | | */ |
751 | | int libwrc_string_table_resource_get_utf16_string( |
752 | | libwrc_string_table_resource_t *string_table_resource, |
753 | | int string_index, |
754 | | uint16_t *utf16_string, |
755 | | size_t utf16_string_size, |
756 | | libcerror_error_t **error ) |
757 | 0 | { |
758 | 0 | libwrc_internal_string_table_resource_t *internal_string_table_resource = NULL; |
759 | 0 | libwrc_table_entry_t *table_entry = NULL; |
760 | 0 | static char *function = "libwrc_string_table_resource_get_utf16_string"; |
761 | |
|
762 | 0 | if( string_table_resource == NULL ) |
763 | 0 | { |
764 | 0 | libcerror_error_set( |
765 | 0 | error, |
766 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
767 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
768 | 0 | "%s: invalid string table resource.", |
769 | 0 | function ); |
770 | |
|
771 | 0 | return( -1 ); |
772 | 0 | } |
773 | 0 | internal_string_table_resource = (libwrc_internal_string_table_resource_t *) string_table_resource; |
774 | |
|
775 | 0 | if( libcdata_array_get_entry_by_index( |
776 | 0 | internal_string_table_resource->entries_array, |
777 | 0 | string_index, |
778 | 0 | (intptr_t **) &table_entry, |
779 | 0 | error ) != 1 ) |
780 | 0 | { |
781 | 0 | libcerror_error_set( |
782 | 0 | error, |
783 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
784 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
785 | 0 | "%s: unable to retrieve table entry: %d.", |
786 | 0 | function, |
787 | 0 | string_index ); |
788 | |
|
789 | 0 | return( -1 ); |
790 | 0 | } |
791 | 0 | if( libwrc_table_entry_get_utf16_string( |
792 | 0 | table_entry, |
793 | 0 | utf16_string, |
794 | 0 | utf16_string_size, |
795 | 0 | error ) != 1 ) |
796 | 0 | { |
797 | 0 | libcerror_error_set( |
798 | 0 | error, |
799 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
800 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
801 | 0 | "%s: unable to copy table entry: %d to UTF-16 string.", |
802 | 0 | function, |
803 | 0 | string_index ); |
804 | |
|
805 | 0 | return( -1 ); |
806 | 0 | } |
807 | 0 | return( 1 ); |
808 | 0 | } |
809 | | |