/src/libwrc/libwrc/libwrc_message_table_resource.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Message table (MESSAGETABLE) resource functions |
3 | | * |
4 | | * Copyright (C) 2011-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 <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libwrc_definitions.h" |
28 | | #include "libwrc_libcdata.h" |
29 | | #include "libwrc_libcerror.h" |
30 | | #include "libwrc_libcnotify.h" |
31 | | #include "libwrc_libuna.h" |
32 | | #include "libwrc_message_table_resource.h" |
33 | | #include "libwrc_table_entry.h" |
34 | | |
35 | | #include "wrc_message_table_resource.h" |
36 | | |
37 | | /* Creates a message table resource |
38 | | * Make sure the value message_table_resource is referencing, is set to NULL |
39 | | * Returns 1 if successful or -1 on error |
40 | | */ |
41 | | int libwrc_message_table_resource_initialize( |
42 | | libwrc_message_table_resource_t **message_table_resource, |
43 | | libcerror_error_t **error ) |
44 | 354 | { |
45 | 354 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
46 | 354 | static char *function = "libwrc_message_table_resource_initialize"; |
47 | | |
48 | 354 | if( message_table_resource == NULL ) |
49 | 0 | { |
50 | 0 | libcerror_error_set( |
51 | 0 | error, |
52 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
53 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
54 | 0 | "%s: invalid message table resource.", |
55 | 0 | function ); |
56 | |
|
57 | 0 | return( -1 ); |
58 | 0 | } |
59 | 354 | if( *message_table_resource != NULL ) |
60 | 0 | { |
61 | 0 | libcerror_error_set( |
62 | 0 | error, |
63 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
64 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
65 | 0 | "%s: invalid message table resource value already set.", |
66 | 0 | function ); |
67 | |
|
68 | 0 | return( -1 ); |
69 | 0 | } |
70 | 354 | internal_message_table_resource = memory_allocate_structure( |
71 | 354 | libwrc_internal_message_table_resource_t ); |
72 | | |
73 | 354 | if( internal_message_table_resource == NULL ) |
74 | 0 | { |
75 | 0 | libcerror_error_set( |
76 | 0 | error, |
77 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
78 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
79 | 0 | "%s: unable to create message table resource.", |
80 | 0 | function ); |
81 | |
|
82 | 0 | goto on_error; |
83 | 0 | } |
84 | 354 | if( memory_set( |
85 | 354 | internal_message_table_resource, |
86 | 354 | 0, |
87 | 354 | sizeof( libwrc_internal_message_table_resource_t ) ) == NULL ) |
88 | 0 | { |
89 | 0 | libcerror_error_set( |
90 | 0 | error, |
91 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
92 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
93 | 0 | "%s: unable to clear message table resource.", |
94 | 0 | function ); |
95 | |
|
96 | 0 | memory_free( |
97 | 0 | internal_message_table_resource ); |
98 | |
|
99 | 0 | return( -1 ); |
100 | 0 | } |
101 | 354 | if( libcdata_array_initialize( |
102 | 354 | &( internal_message_table_resource->entries_array ), |
103 | 354 | 0, |
104 | 354 | error ) != 1 ) |
105 | 0 | { |
106 | 0 | libcerror_error_set( |
107 | 0 | error, |
108 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
109 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
110 | 0 | "%s: unable to create entries array.", |
111 | 0 | function ); |
112 | |
|
113 | 0 | goto on_error; |
114 | 0 | } |
115 | 354 | *message_table_resource = (libwrc_message_table_resource_t *) internal_message_table_resource; |
116 | | |
117 | 354 | return( 1 ); |
118 | | |
119 | 0 | on_error: |
120 | 0 | if( internal_message_table_resource != NULL ) |
121 | 0 | { |
122 | 0 | memory_free( |
123 | 0 | internal_message_table_resource ); |
124 | 0 | } |
125 | 0 | return( -1 ); |
126 | 354 | } |
127 | | |
128 | | /* Frees a message table resource |
129 | | * Returns 1 if successful or -1 on error |
130 | | */ |
131 | | int libwrc_message_table_resource_free( |
132 | | libwrc_message_table_resource_t **message_table_resource, |
133 | | libcerror_error_t **error ) |
134 | 354 | { |
135 | 354 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
136 | 354 | static char *function = "libwrc_message_table_resource_free"; |
137 | 354 | int result = 1; |
138 | | |
139 | 354 | if( message_table_resource == NULL ) |
140 | 0 | { |
141 | 0 | libcerror_error_set( |
142 | 0 | error, |
143 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
144 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
145 | 0 | "%s: invalid message table resource.", |
146 | 0 | function ); |
147 | |
|
148 | 0 | return( -1 ); |
149 | 0 | } |
150 | 354 | if( *message_table_resource != NULL ) |
151 | 354 | { |
152 | 354 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) *message_table_resource; |
153 | 354 | *message_table_resource = NULL; |
154 | | |
155 | 354 | if( libcdata_array_free( |
156 | 354 | &( internal_message_table_resource->entries_array ), |
157 | 354 | (int (*)(intptr_t **, libcerror_error_t **)) &libwrc_table_entry_free, |
158 | 354 | error ) != 1 ) |
159 | 0 | { |
160 | 0 | libcerror_error_set( |
161 | 0 | error, |
162 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
163 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
164 | 0 | "%s: unable to free entries array.", |
165 | 0 | function ); |
166 | |
|
167 | 0 | result = -1; |
168 | 0 | } |
169 | 354 | memory_free( |
170 | 354 | internal_message_table_resource ); |
171 | 354 | } |
172 | 354 | return( result ); |
173 | 354 | } |
174 | | |
175 | | /* Reads the message table resource |
176 | | * Returns 1 if successful or -1 on error |
177 | | */ |
178 | | int libwrc_message_table_resource_read( |
179 | | libwrc_message_table_resource_t *message_table_resource, |
180 | | const uint8_t *data, |
181 | | size_t data_size, |
182 | | int ascii_codepage, |
183 | | libcerror_error_t **error ) |
184 | 354 | { |
185 | 354 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
186 | 354 | libwrc_table_entry_t *table_entry = NULL; |
187 | 354 | static char *function = "libwrc_message_table_resource_read"; |
188 | 354 | size_t data_offset = 0; |
189 | 354 | uint32_t first_message_identifier = 0; |
190 | 354 | uint32_t last_message_identifier = 0; |
191 | 354 | uint32_t message_string_offset = 0; |
192 | 354 | uint16_t message_entry_descriptor_index = 0; |
193 | 354 | uint16_t message_string_flags = 0; |
194 | 354 | uint16_t message_string_size = 0; |
195 | 354 | uint16_t number_of_message_entry_descriptors = 0; |
196 | 354 | uint16_t string_size = 0; |
197 | 354 | int entry_index = 0; |
198 | 354 | int value_encoding = 0; |
199 | | |
200 | 354 | if( message_table_resource == NULL ) |
201 | 0 | { |
202 | 0 | libcerror_error_set( |
203 | 0 | error, |
204 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
205 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
206 | 0 | "%s: invalid message table resource.", |
207 | 0 | function ); |
208 | |
|
209 | 0 | return( -1 ); |
210 | 0 | } |
211 | 354 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
212 | | |
213 | 354 | if( data == NULL ) |
214 | 0 | { |
215 | 0 | libcerror_error_set( |
216 | 0 | error, |
217 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
218 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
219 | 0 | "%s: invalid data.", |
220 | 0 | function ); |
221 | |
|
222 | 0 | return( -1 ); |
223 | 0 | } |
224 | 354 | if( ( data_size < 4 ) |
225 | 354 | || ( data_size > (size_t) SSIZE_MAX ) ) |
226 | 2 | { |
227 | 2 | libcerror_error_set( |
228 | 2 | error, |
229 | 2 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
230 | 2 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
231 | 2 | "%s: invalid data size value out of bounds.", |
232 | 2 | function ); |
233 | | |
234 | 2 | return( -1 ); |
235 | 2 | } |
236 | | #if defined( HAVE_DEBUG_OUTPUT ) |
237 | | if( libcnotify_verbose != 0 ) |
238 | | { |
239 | | libcnotify_printf( |
240 | | "%s: data:\n", |
241 | | function ); |
242 | | libcnotify_print_data( |
243 | | data, |
244 | | data_size, |
245 | | 0 ); |
246 | | } |
247 | | #endif |
248 | 352 | byte_stream_copy_to_uint32_little_endian( |
249 | 352 | data, |
250 | 352 | number_of_message_entry_descriptors ); |
251 | | |
252 | | #if defined( HAVE_DEBUG_OUTPUT ) |
253 | | if( libcnotify_verbose != 0 ) |
254 | | { |
255 | | libcnotify_printf( |
256 | | "%s: number of message entry descriptors\t: %" PRIu32 "\n", |
257 | | function, |
258 | | number_of_message_entry_descriptors ); |
259 | | |
260 | | libcnotify_printf( |
261 | | "\n" ); |
262 | | } |
263 | | #endif |
264 | 352 | data_offset += 4; |
265 | | |
266 | 352 | if( number_of_message_entry_descriptors > ( ( data_size - data_offset ) / sizeof( wrc_message_table_entry_descriptor_t ) ) ) |
267 | 25 | { |
268 | 25 | libcerror_error_set( |
269 | 25 | error, |
270 | 25 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
271 | 25 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
272 | 25 | "%s: invalid number of message entry descriptors value out of bounds.", |
273 | 25 | function ); |
274 | | |
275 | 25 | goto on_error; |
276 | 25 | } |
277 | 327 | for( message_entry_descriptor_index = 0; |
278 | 973 | message_entry_descriptor_index < number_of_message_entry_descriptors; |
279 | 646 | message_entry_descriptor_index++ ) |
280 | 943 | { |
281 | | #if defined( HAVE_DEBUG_OUTPUT ) |
282 | | if( libcnotify_verbose != 0 ) |
283 | | { |
284 | | libcnotify_printf( |
285 | | "%s: message entry descriptor: %03d\n", |
286 | | function, |
287 | | message_entry_descriptor_index ); |
288 | | libcnotify_print_data( |
289 | | &( data[ data_offset ] ), |
290 | | sizeof( wrc_message_table_entry_descriptor_t ), |
291 | | 0 ); |
292 | | } |
293 | | #endif |
294 | 943 | byte_stream_copy_to_uint32_little_endian( |
295 | 943 | ( (wrc_message_table_entry_descriptor_t *) &( data[ data_offset ] ) )->first_identifier, |
296 | 943 | first_message_identifier ); |
297 | | |
298 | 943 | byte_stream_copy_to_uint32_little_endian( |
299 | 943 | ( (wrc_message_table_entry_descriptor_t *) &( data[ data_offset ] ) )->last_identifier, |
300 | 943 | last_message_identifier ); |
301 | | |
302 | 943 | byte_stream_copy_to_uint32_little_endian( |
303 | 943 | ( (wrc_message_table_entry_descriptor_t *) &( data[ data_offset ] ) )->offset, |
304 | 943 | message_string_offset ); |
305 | | |
306 | | #if defined( HAVE_DEBUG_OUTPUT ) |
307 | | if( libcnotify_verbose != 0 ) |
308 | | { |
309 | | libcnotify_printf( |
310 | | "%s: first message identifier\t\t: 0x%08" PRIx32 "\n", |
311 | | function, |
312 | | first_message_identifier ); |
313 | | |
314 | | libcnotify_printf( |
315 | | "%s: last message identifier\t\t: 0x%08" PRIx32 "\n", |
316 | | function, |
317 | | last_message_identifier ); |
318 | | |
319 | | libcnotify_printf( |
320 | | "%s: first message string offset\t\t: 0x%08" PRIx32 "\n", |
321 | | function, |
322 | | message_string_offset ); |
323 | | |
324 | | libcnotify_printf( |
325 | | "\n" ); |
326 | | } |
327 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
328 | | |
329 | 943 | data_offset += sizeof( wrc_message_table_entry_descriptor_t ); |
330 | | |
331 | 943 | if( first_message_identifier > last_message_identifier ) |
332 | 25 | { |
333 | 25 | libcerror_error_set( |
334 | 25 | error, |
335 | 25 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
336 | 25 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
337 | 25 | "%s: first message identifier exceeds last.", |
338 | 25 | function ); |
339 | | |
340 | 25 | goto on_error; |
341 | 25 | } |
342 | 470k | while( first_message_identifier <= last_message_identifier ) |
343 | 469k | { |
344 | 469k | if( ( message_string_offset < data_offset ) |
345 | 469k | || ( message_string_offset >= ( data_size - sizeof( wrc_message_table_string_t ) ) ) ) |
346 | 205 | { |
347 | 205 | libcerror_error_set( |
348 | 205 | error, |
349 | 205 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
350 | 205 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
351 | 205 | "%s: invalid message table string offset value out of bounds.", |
352 | 205 | function ); |
353 | | |
354 | 205 | goto on_error; |
355 | 205 | } |
356 | | #if defined( HAVE_DEBUG_OUTPUT ) |
357 | | if( libcnotify_verbose != 0 ) |
358 | | { |
359 | | libcnotify_printf( |
360 | | "%s: message string: 0x%08" PRIx32 "\n", |
361 | | function, |
362 | | first_message_identifier ); |
363 | | libcnotify_print_data( |
364 | | &( data[ message_string_offset ] ), |
365 | | sizeof( wrc_message_table_string_t ), |
366 | | 0 ); |
367 | | } |
368 | | #endif |
369 | 469k | byte_stream_copy_to_uint16_little_endian( |
370 | 469k | ( (wrc_message_table_string_t *) &( data[ message_string_offset ] ) )->size, |
371 | 469k | message_string_size ); |
372 | | |
373 | 469k | byte_stream_copy_to_uint16_little_endian( |
374 | 469k | ( (wrc_message_table_string_t *) &( data[ message_string_offset ] ) )->flags, |
375 | 469k | message_string_flags ); |
376 | | |
377 | | #if defined( HAVE_DEBUG_OUTPUT ) |
378 | | if( libcnotify_verbose != 0 ) |
379 | | { |
380 | | libcnotify_printf( |
381 | | "%s: message string: 0x%08" PRIx32 " size\t: %" PRIu16 "\n", |
382 | | function, |
383 | | first_message_identifier, |
384 | | message_string_size ); |
385 | | |
386 | | libcnotify_printf( |
387 | | "%s: message string: 0x%08" PRIx32 " flags\t: 0x%04" PRIx16 "\n", |
388 | | function, |
389 | | first_message_identifier, |
390 | | message_string_flags ); |
391 | | } |
392 | | #endif |
393 | 469k | if( ( message_string_size < sizeof( wrc_message_table_string_t ) ) |
394 | 469k | || ( message_string_size > ( data_size - message_string_offset ) ) ) |
395 | 54 | { |
396 | 54 | libcerror_error_set( |
397 | 54 | error, |
398 | 54 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
399 | 54 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
400 | 54 | "%s: invalid message string size value out of bounds.", |
401 | 54 | function ); |
402 | | |
403 | 54 | goto on_error; |
404 | 54 | } |
405 | 469k | message_string_offset += sizeof( wrc_message_table_string_t ); |
406 | 469k | message_string_size -= sizeof( wrc_message_table_string_t ); |
407 | | |
408 | 469k | if( message_string_size > 0 ) |
409 | 467k | { |
410 | | #if defined( HAVE_DEBUG_OUTPUT ) |
411 | | if( libcnotify_verbose != 0 ) |
412 | | { |
413 | | libcnotify_printf( |
414 | | "%s: message string: 0x%08" PRIx32 " data:\n", |
415 | | function, |
416 | | first_message_identifier ); |
417 | | libcnotify_print_data( |
418 | | &( data[ message_string_offset ] ), |
419 | | (size_t) message_string_size, |
420 | | 0 ); |
421 | | } |
422 | | #endif |
423 | | /* Strip off trailing 0-byte values |
424 | | */ |
425 | 467k | string_size = message_string_size; |
426 | | |
427 | 467k | if( ( message_string_flags & 0x0001 ) == 0 ) |
428 | 466k | { |
429 | 911k | while( string_size > 0 ) |
430 | 473k | { |
431 | 473k | string_size -= 1; |
432 | | |
433 | 473k | if( data[ message_string_offset + string_size ] != 0 ) |
434 | 28.4k | { |
435 | 28.4k | break; |
436 | 28.4k | } |
437 | 473k | } |
438 | 466k | string_size += 1; |
439 | 466k | } |
440 | 1.11k | else |
441 | 1.11k | { |
442 | 1.11k | if( ( message_string_size % 2 ) != 0 ) |
443 | 13 | { |
444 | 13 | libcerror_error_set( |
445 | 13 | error, |
446 | 13 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
447 | 13 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
448 | 13 | "%s: invalid message string: 0x%08" PRIx32 " size value not a multitude of 2.", |
449 | 13 | function, |
450 | 13 | first_message_identifier ); |
451 | | |
452 | 13 | goto on_error; |
453 | 13 | } |
454 | 1.91k | while( string_size > 1 ) |
455 | 1.64k | { |
456 | 1.64k | string_size -= 2; |
457 | | |
458 | 1.64k | if( ( data[ message_string_offset + string_size ] != 0 ) |
459 | 1.64k | || ( data[ message_string_offset + string_size + 1 ] != 0 ) ) |
460 | 825 | { |
461 | 825 | break; |
462 | 825 | } |
463 | 1.64k | } |
464 | 1.10k | string_size += 2; |
465 | 1.10k | } |
466 | 467k | if( libwrc_table_entry_initialize( |
467 | 467k | &table_entry, |
468 | 467k | error ) != 1 ) |
469 | 0 | { |
470 | 0 | libcerror_error_set( |
471 | 0 | error, |
472 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
473 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
474 | 0 | "%s: unable to create table entry.", |
475 | 0 | function ); |
476 | |
|
477 | 0 | goto on_error; |
478 | 0 | } |
479 | 467k | if( ( message_string_flags & 0x0001 ) == 0 ) |
480 | 466k | { |
481 | 466k | value_encoding = ascii_codepage; |
482 | 466k | } |
483 | 1.10k | else |
484 | 1.10k | { |
485 | 1.10k | value_encoding = LIBUNA_CODEPAGE_UTF16_LITTLE_ENDIAN; |
486 | 1.10k | } |
487 | 467k | if( libwrc_table_entry_set_string( |
488 | 467k | table_entry, |
489 | 467k | &( data[ message_string_offset ] ), |
490 | 467k | (size_t) string_size, |
491 | 467k | value_encoding, |
492 | 467k | error ) != 1 ) |
493 | 0 | { |
494 | 0 | libcerror_error_set( |
495 | 0 | error, |
496 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
497 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
498 | 0 | "%s: unable to set data of table entry.", |
499 | 0 | function ); |
500 | |
|
501 | 0 | goto on_error; |
502 | 0 | } |
503 | 467k | table_entry->identifier = first_message_identifier; |
504 | | |
505 | 467k | if( libcdata_array_append_entry( |
506 | 467k | internal_message_table_resource->entries_array, |
507 | 467k | &entry_index, |
508 | 467k | (intptr_t *) table_entry, |
509 | 467k | error ) != 1 ) |
510 | 0 | { |
511 | 0 | libcerror_error_set( |
512 | 0 | error, |
513 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
514 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
515 | 0 | "%s: unable to append table entry to array.", |
516 | 0 | function ); |
517 | |
|
518 | 0 | goto on_error; |
519 | 0 | } |
520 | 467k | table_entry = NULL; |
521 | | |
522 | 467k | message_string_offset += message_string_size; |
523 | 467k | } |
524 | | #if defined( HAVE_DEBUG_OUTPUT ) |
525 | | else if( libcnotify_verbose != 0 ) |
526 | | { |
527 | | libcnotify_printf( |
528 | | "\n" ); |
529 | | } |
530 | | #endif |
531 | 469k | first_message_identifier++; |
532 | 469k | } |
533 | 918 | } |
534 | 30 | return( 1 ); |
535 | | |
536 | 322 | on_error: |
537 | 322 | if( table_entry != NULL ) |
538 | 0 | { |
539 | 0 | libwrc_table_entry_free( |
540 | 0 | &table_entry, |
541 | 0 | NULL ); |
542 | 0 | } |
543 | 322 | return( -1 ); |
544 | 327 | } |
545 | | |
546 | | /* Retrieves the number of messages |
547 | | * Returns 1 if successful or -1 on error |
548 | | */ |
549 | | int libwrc_message_table_resource_get_number_of_messages( |
550 | | libwrc_message_table_resource_t *message_table_resource, |
551 | | int *number_of_messages, |
552 | | libcerror_error_t **error ) |
553 | 0 | { |
554 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
555 | 0 | static char *function = "libwrc_message_table_resource_get_number_of_messages"; |
556 | |
|
557 | 0 | if( message_table_resource == NULL ) |
558 | 0 | { |
559 | 0 | libcerror_error_set( |
560 | 0 | error, |
561 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
562 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
563 | 0 | "%s: invalid message table resource.", |
564 | 0 | function ); |
565 | |
|
566 | 0 | return( -1 ); |
567 | 0 | } |
568 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
569 | |
|
570 | 0 | if( libcdata_array_get_number_of_entries( |
571 | 0 | internal_message_table_resource->entries_array, |
572 | 0 | number_of_messages, |
573 | 0 | error ) != 1 ) |
574 | 0 | { |
575 | 0 | libcerror_error_set( |
576 | 0 | error, |
577 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
578 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
579 | 0 | "%s: unable to retrieve number of entries from array.", |
580 | 0 | function ); |
581 | |
|
582 | 0 | return( -1 ); |
583 | 0 | } |
584 | 0 | return( 1 ); |
585 | 0 | } |
586 | | |
587 | | /* Retrieves a specific message identifier |
588 | | * Returns 1 if successful or -1 on error |
589 | | */ |
590 | | int libwrc_message_table_resource_get_identifier( |
591 | | libwrc_message_table_resource_t *message_table_resource, |
592 | | int message_index, |
593 | | uint32_t *message_identifier, |
594 | | libcerror_error_t **error ) |
595 | 0 | { |
596 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
597 | 0 | libwrc_table_entry_t *table_entry = NULL; |
598 | 0 | static char *function = "libwrc_message_table_resource_get_identifier"; |
599 | |
|
600 | 0 | if( message_table_resource == NULL ) |
601 | 0 | { |
602 | 0 | libcerror_error_set( |
603 | 0 | error, |
604 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
605 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
606 | 0 | "%s: invalid message table resource.", |
607 | 0 | function ); |
608 | |
|
609 | 0 | return( -1 ); |
610 | 0 | } |
611 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
612 | |
|
613 | 0 | if( message_identifier == NULL ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
618 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
619 | 0 | "%s: invalid message identifier.", |
620 | 0 | function ); |
621 | |
|
622 | 0 | return( -1 ); |
623 | 0 | } |
624 | 0 | if( libcdata_array_get_entry_by_index( |
625 | 0 | internal_message_table_resource->entries_array, |
626 | 0 | message_index, |
627 | 0 | (intptr_t **) &table_entry, |
628 | 0 | error ) != 1 ) |
629 | 0 | { |
630 | 0 | libcerror_error_set( |
631 | 0 | error, |
632 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
633 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
634 | 0 | "%s: unable to retrieve table entry: %d.", |
635 | 0 | function, |
636 | 0 | message_index ); |
637 | |
|
638 | 0 | return( -1 ); |
639 | 0 | } |
640 | 0 | if( table_entry == NULL ) |
641 | 0 | { |
642 | 0 | libcerror_error_set( |
643 | 0 | error, |
644 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
645 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
646 | 0 | "%s: missing table entry: %d.", |
647 | 0 | function, |
648 | 0 | message_index ); |
649 | |
|
650 | 0 | return( -1 ); |
651 | 0 | } |
652 | 0 | *message_identifier = table_entry->identifier; |
653 | |
|
654 | 0 | return( 1 ); |
655 | 0 | } |
656 | | |
657 | | /* Retrieves the message index for a specific identifier |
658 | | * Returns 1 if successful, 0 if no such message identifier or -1 on error |
659 | | */ |
660 | | int libwrc_message_table_resource_get_index_by_identifier( |
661 | | libwrc_message_table_resource_t *message_table_resource, |
662 | | uint32_t message_identifier, |
663 | | int *message_index, |
664 | | libcerror_error_t **error ) |
665 | 0 | { |
666 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
667 | 0 | libwrc_table_entry_t *table_entry = NULL; |
668 | 0 | static char *function = "libwrc_message_table_resource_get_index_by_identifier"; |
669 | 0 | int number_of_messages = 0; |
670 | 0 | int safe_message_index = 0; |
671 | |
|
672 | 0 | if( message_table_resource == NULL ) |
673 | 0 | { |
674 | 0 | libcerror_error_set( |
675 | 0 | error, |
676 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
677 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
678 | 0 | "%s: invalid message table resource.", |
679 | 0 | function ); |
680 | |
|
681 | 0 | return( -1 ); |
682 | 0 | } |
683 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
684 | |
|
685 | 0 | if( message_index == NULL ) |
686 | 0 | { |
687 | 0 | libcerror_error_set( |
688 | 0 | error, |
689 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
690 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
691 | 0 | "%s: invalid message index.", |
692 | 0 | function ); |
693 | |
|
694 | 0 | return( -1 ); |
695 | 0 | } |
696 | 0 | if( libcdata_array_get_number_of_entries( |
697 | 0 | internal_message_table_resource->entries_array, |
698 | 0 | &number_of_messages, |
699 | 0 | error ) != 1 ) |
700 | 0 | { |
701 | 0 | libcerror_error_set( |
702 | 0 | error, |
703 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
704 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
705 | 0 | "%s: unable to retrieve number of entries from array.", |
706 | 0 | function ); |
707 | |
|
708 | 0 | return( -1 ); |
709 | 0 | } |
710 | 0 | for( safe_message_index = 0; |
711 | 0 | safe_message_index < number_of_messages; |
712 | 0 | safe_message_index++ ) |
713 | 0 | { |
714 | 0 | if( libcdata_array_get_entry_by_index( |
715 | 0 | internal_message_table_resource->entries_array, |
716 | 0 | safe_message_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 | safe_message_index ); |
727 | |
|
728 | 0 | return( -1 ); |
729 | 0 | } |
730 | 0 | if( table_entry == NULL ) |
731 | 0 | { |
732 | 0 | libcerror_error_set( |
733 | 0 | error, |
734 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
735 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
736 | 0 | "%s: missing table entry: %d.", |
737 | 0 | function, |
738 | 0 | safe_message_index ); |
739 | |
|
740 | 0 | return( -1 ); |
741 | 0 | } |
742 | 0 | if( message_identifier == table_entry->identifier ) |
743 | 0 | { |
744 | 0 | *message_index = safe_message_index; |
745 | |
|
746 | 0 | return( 1 ); |
747 | 0 | } |
748 | 0 | } |
749 | 0 | return( 0 ); |
750 | 0 | } |
751 | | |
752 | | /* Retrieves the size of a specific UTF-8 formatted message string |
753 | | * Returns 1 if successful or -1 on error |
754 | | */ |
755 | | int libwrc_message_table_resource_get_utf8_string_size( |
756 | | libwrc_message_table_resource_t *message_table_resource, |
757 | | int message_index, |
758 | | size_t *utf8_string_size, |
759 | | libcerror_error_t **error ) |
760 | 0 | { |
761 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
762 | 0 | libwrc_table_entry_t *table_entry = NULL; |
763 | 0 | static char *function = "libwrc_message_table_resource_get_utf8_string_size"; |
764 | |
|
765 | 0 | if( message_table_resource == NULL ) |
766 | 0 | { |
767 | 0 | libcerror_error_set( |
768 | 0 | error, |
769 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
770 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
771 | 0 | "%s: invalid message table resource.", |
772 | 0 | function ); |
773 | |
|
774 | 0 | return( -1 ); |
775 | 0 | } |
776 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
777 | |
|
778 | 0 | if( libcdata_array_get_entry_by_index( |
779 | 0 | internal_message_table_resource->entries_array, |
780 | 0 | message_index, |
781 | 0 | (intptr_t **) &table_entry, |
782 | 0 | error ) != 1 ) |
783 | 0 | { |
784 | 0 | libcerror_error_set( |
785 | 0 | error, |
786 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
787 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
788 | 0 | "%s: unable to retrieve table entry: %d.", |
789 | 0 | function, |
790 | 0 | message_index ); |
791 | |
|
792 | 0 | return( -1 ); |
793 | 0 | } |
794 | 0 | if( libwrc_table_entry_get_utf8_string_size( |
795 | 0 | table_entry, |
796 | 0 | utf8_string_size, |
797 | 0 | error ) != 1 ) |
798 | 0 | { |
799 | 0 | libcerror_error_set( |
800 | 0 | error, |
801 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
802 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
803 | 0 | "%s: unable to retrieve UTF-8 string size of table entry: %d.", |
804 | 0 | function, |
805 | 0 | message_index ); |
806 | |
|
807 | 0 | return( -1 ); |
808 | 0 | } |
809 | 0 | return( 1 ); |
810 | 0 | } |
811 | | |
812 | | /* Retrieves a specific UTF-8 formatted message string |
813 | | * Returns 1 if successful or -1 on error |
814 | | */ |
815 | | int libwrc_message_table_resource_get_utf8_string( |
816 | | libwrc_message_table_resource_t *message_table_resource, |
817 | | int message_index, |
818 | | uint8_t *utf8_string, |
819 | | size_t utf8_string_size, |
820 | | libcerror_error_t **error ) |
821 | 0 | { |
822 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
823 | 0 | libwrc_table_entry_t *table_entry = NULL; |
824 | 0 | static char *function = "libwrc_message_table_resource_get_utf8_string"; |
825 | |
|
826 | 0 | if( message_table_resource == NULL ) |
827 | 0 | { |
828 | 0 | libcerror_error_set( |
829 | 0 | error, |
830 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
831 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
832 | 0 | "%s: invalid message table resource.", |
833 | 0 | function ); |
834 | |
|
835 | 0 | return( -1 ); |
836 | 0 | } |
837 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
838 | |
|
839 | 0 | if( libcdata_array_get_entry_by_index( |
840 | 0 | internal_message_table_resource->entries_array, |
841 | 0 | message_index, |
842 | 0 | (intptr_t **) &table_entry, |
843 | 0 | error ) != 1 ) |
844 | 0 | { |
845 | 0 | libcerror_error_set( |
846 | 0 | error, |
847 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
848 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
849 | 0 | "%s: unable to retrieve table entry: %d.", |
850 | 0 | function, |
851 | 0 | message_index ); |
852 | |
|
853 | 0 | return( -1 ); |
854 | 0 | } |
855 | 0 | if( libwrc_table_entry_get_utf8_string( |
856 | 0 | table_entry, |
857 | 0 | utf8_string, |
858 | 0 | utf8_string_size, |
859 | 0 | error ) != 1 ) |
860 | 0 | { |
861 | 0 | libcerror_error_set( |
862 | 0 | error, |
863 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
864 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
865 | 0 | "%s: unable to copy table entry: %d to UTF-8 string.", |
866 | 0 | function, |
867 | 0 | message_index ); |
868 | |
|
869 | 0 | return( -1 ); |
870 | 0 | } |
871 | 0 | return( 1 ); |
872 | 0 | } |
873 | | |
874 | | /* Retrieves the size of a specific UTF-16 formatted message string |
875 | | * Returns 1 if successful or -1 on error |
876 | | */ |
877 | | int libwrc_message_table_resource_get_utf16_string_size( |
878 | | libwrc_message_table_resource_t *message_table_resource, |
879 | | int message_index, |
880 | | size_t *utf16_string_size, |
881 | | libcerror_error_t **error ) |
882 | 0 | { |
883 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
884 | 0 | libwrc_table_entry_t *table_entry = NULL; |
885 | 0 | static char *function = "libwrc_message_table_resource_get_utf16_string_size"; |
886 | |
|
887 | 0 | if( message_table_resource == NULL ) |
888 | 0 | { |
889 | 0 | libcerror_error_set( |
890 | 0 | error, |
891 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
892 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
893 | 0 | "%s: invalid message table resource.", |
894 | 0 | function ); |
895 | |
|
896 | 0 | return( -1 ); |
897 | 0 | } |
898 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
899 | |
|
900 | 0 | if( libcdata_array_get_entry_by_index( |
901 | 0 | internal_message_table_resource->entries_array, |
902 | 0 | message_index, |
903 | 0 | (intptr_t **) &table_entry, |
904 | 0 | error ) != 1 ) |
905 | 0 | { |
906 | 0 | libcerror_error_set( |
907 | 0 | error, |
908 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
909 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
910 | 0 | "%s: unable to retrieve table entry: %d.", |
911 | 0 | function, |
912 | 0 | message_index ); |
913 | |
|
914 | 0 | return( -1 ); |
915 | 0 | } |
916 | 0 | if( libwrc_table_entry_get_utf16_string_size( |
917 | 0 | table_entry, |
918 | 0 | utf16_string_size, |
919 | 0 | error ) != 1 ) |
920 | 0 | { |
921 | 0 | libcerror_error_set( |
922 | 0 | error, |
923 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
924 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
925 | 0 | "%s: unable to retrieve UTF-16 string size of table entry: %d.", |
926 | 0 | function, |
927 | 0 | message_index ); |
928 | |
|
929 | 0 | return( -1 ); |
930 | 0 | } |
931 | 0 | return( 1 ); |
932 | 0 | } |
933 | | |
934 | | /* Retrieves a specific UTF-16 formatted message string |
935 | | * Returns 1 if successful or -1 on error |
936 | | */ |
937 | | int libwrc_message_table_resource_get_utf16_string( |
938 | | libwrc_message_table_resource_t *message_table_resource, |
939 | | int message_index, |
940 | | uint16_t *utf16_string, |
941 | | size_t utf16_string_size, |
942 | | libcerror_error_t **error ) |
943 | 0 | { |
944 | 0 | libwrc_internal_message_table_resource_t *internal_message_table_resource = NULL; |
945 | 0 | libwrc_table_entry_t *table_entry = NULL; |
946 | 0 | static char *function = "libwrc_message_table_resource_get_utf16_string"; |
947 | |
|
948 | 0 | if( message_table_resource == NULL ) |
949 | 0 | { |
950 | 0 | libcerror_error_set( |
951 | 0 | error, |
952 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
953 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
954 | 0 | "%s: invalid message table resource.", |
955 | 0 | function ); |
956 | |
|
957 | 0 | return( -1 ); |
958 | 0 | } |
959 | 0 | internal_message_table_resource = (libwrc_internal_message_table_resource_t *) message_table_resource; |
960 | |
|
961 | 0 | if( libcdata_array_get_entry_by_index( |
962 | 0 | internal_message_table_resource->entries_array, |
963 | 0 | message_index, |
964 | 0 | (intptr_t **) &table_entry, |
965 | 0 | error ) != 1 ) |
966 | 0 | { |
967 | 0 | libcerror_error_set( |
968 | 0 | error, |
969 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
970 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
971 | 0 | "%s: unable to retrieve table entry: %d.", |
972 | 0 | function, |
973 | 0 | message_index ); |
974 | |
|
975 | 0 | return( -1 ); |
976 | 0 | } |
977 | 0 | if( libwrc_table_entry_get_utf16_string( |
978 | 0 | table_entry, |
979 | 0 | utf16_string, |
980 | 0 | utf16_string_size, |
981 | 0 | error ) != 1 ) |
982 | 0 | { |
983 | 0 | libcerror_error_set( |
984 | 0 | error, |
985 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
986 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
987 | 0 | "%s: unable to copy table entry: %d to UTF-16 string.", |
988 | 0 | function, |
989 | 0 | message_index ); |
990 | |
|
991 | 0 | return( -1 ); |
992 | 0 | } |
993 | 0 | return( 1 ); |
994 | 0 | } |
995 | | |