Coverage Report

Created: 2025-06-24 07:14

/src/libfwsi/libfwsi/libfwsi_web_site_values.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Web site (shell item) values 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 <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libfwsi_debug.h"
28
#include "libfwsi_definitions.h"
29
#include "libfwsi_libcerror.h"
30
#include "libfwsi_libcnotify.h"
31
#include "libfwsi_libuna.h"
32
#include "libfwsi_web_site_values.h"
33
34
/* Creates web site values
35
 * Make sure the value web_site_values is referencing, is set to NULL
36
 * Returns 1 if successful or -1 on error
37
 */
38
int libfwsi_web_site_values_initialize(
39
     libfwsi_web_site_values_t **web_site_values,
40
     libcerror_error_t **error )
41
0
{
42
0
  static char *function = "libfwsi_web_site_values_initialize";
43
44
0
  if( web_site_values == NULL )
45
0
  {
46
0
    libcerror_error_set(
47
0
     error,
48
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
49
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
50
0
     "%s: invalid web site values.",
51
0
     function );
52
53
0
    return( -1 );
54
0
  }
55
0
  if( *web_site_values != NULL )
56
0
  {
57
0
    libcerror_error_set(
58
0
     error,
59
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
60
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
61
0
     "%s: invalid web site values value already set.",
62
0
     function );
63
64
0
    return( -1 );
65
0
  }
66
0
  *web_site_values = memory_allocate_structure(
67
0
                      libfwsi_web_site_values_t );
68
69
0
  if( *web_site_values == NULL )
70
0
  {
71
0
    libcerror_error_set(
72
0
     error,
73
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
74
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
75
0
     "%s: unable to create web site values.",
76
0
     function );
77
78
0
    goto on_error;
79
0
  }
80
0
  if( memory_set(
81
0
       *web_site_values,
82
0
       0,
83
0
       sizeof( libfwsi_web_site_values_t ) ) == NULL )
84
0
  {
85
0
    libcerror_error_set(
86
0
     error,
87
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
88
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
89
0
     "%s: unable to clear web site values.",
90
0
     function );
91
92
0
    goto on_error;
93
0
  }
94
0
  return( 1 );
95
96
0
on_error:
97
0
  if( *web_site_values != NULL )
98
0
  {
99
0
    memory_free(
100
0
     *web_site_values );
101
102
0
    *web_site_values = NULL;
103
0
  }
104
0
  return( -1 );
105
0
}
106
107
/* Frees web site values
108
 * Returns 1 if successful or -1 on error
109
 */
110
int libfwsi_web_site_values_free(
111
     libfwsi_web_site_values_t **web_site_values,
112
     libcerror_error_t **error )
113
0
{
114
0
  static char *function = "libfwsi_web_site_values_free";
115
116
0
  if( web_site_values == NULL )
117
0
  {
118
0
    libcerror_error_set(
119
0
     error,
120
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
121
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
122
0
     "%s: invalid web site values.",
123
0
     function );
124
125
0
    return( -1 );
126
0
  }
127
0
  if( *web_site_values != NULL )
128
0
  {
129
0
    if( ( *web_site_values )->location != NULL )
130
0
    {
131
0
      memory_free(
132
0
       ( *web_site_values )->location );
133
0
    }
134
0
    memory_free(
135
0
     *web_site_values );
136
137
0
    *web_site_values = NULL;
138
0
  }
139
0
  return( 1 );
140
0
}
141
142
/* Reads the web site values
143
 * Returns 1 if successful, 0 if not supported or -1 on error
144
 */
145
int libfwsi_web_site_values_read_data(
146
     libfwsi_web_site_values_t *web_site_values,
147
     const uint8_t *data,
148
     size_t data_size,
149
     libcerror_error_t **error )
150
0
{
151
0
  static char *function     = "libfwsi_web_site_values_read_data";
152
0
  size_t data_offset        = 0;
153
0
  uint32_t string_data_size = 0;
154
155
#if defined( HAVE_DEBUG_OUTPUT )
156
  uint32_t value_32bit      = 0;
157
  uint16_t value_16bit      = 0;
158
#endif
159
160
0
  if( web_site_values == NULL )
161
0
  {
162
0
    libcerror_error_set(
163
0
     error,
164
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
165
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
166
0
     "%s: invalid web site values.",
167
0
     function );
168
169
0
    return( -1 );
170
0
  }
171
0
  if( data == NULL )
172
0
  {
173
0
    libcerror_error_set(
174
0
     error,
175
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
176
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
177
0
     "%s: invalid data.",
178
0
     function );
179
180
0
    return( -1 );
181
0
  }
182
0
  if( data_size > (size_t) SSIZE_MAX )
183
0
  {
184
0
    libcerror_error_set(
185
0
     error,
186
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
187
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
188
0
     "%s: data size exceeds maximum.",
189
0
     function );
190
191
0
    return( -1 );
192
0
  }
193
  /* Do not try to parse unsupported data sizes
194
   */
195
0
  if( data_size < 24 )
196
0
  {
197
0
    return( 0 );
198
0
  }
199
  /* Do not try to parse unsupported data
200
   */
201
0
  if( ( data[ 4 ] != 0x00 )
202
0
   || ( data[ 5 ] != 0xb0 )
203
0
   || ( data[ 6 ] != 0x01 )
204
0
   || ( data[ 7 ] != 0xc0 ) )
205
0
  {
206
0
    return( 0 );
207
0
  }
208
0
  byte_stream_copy_to_uint32_little_endian(
209
0
   &( data[ 20 ] ),
210
0
   string_data_size );
211
212
#if defined( HAVE_DEBUG_OUTPUT )
213
  if( libcnotify_verbose != 0 )
214
  {
215
    byte_stream_copy_to_uint16_little_endian(
216
     &( data[ 2 ] ),
217
     value_16bit );
218
    libcnotify_printf(
219
     "%s: unknown1\t\t\t\t: 0x%04" PRIx16 "\n",
220
     function,
221
     value_16bit );
222
223
    byte_stream_copy_to_uint32_little_endian(
224
     &( data[ 4 ] ),
225
     value_32bit );
226
    libcnotify_printf(
227
     "%s: signature\t\t\t\t: 0x%08" PRIx32 "\n",
228
     function,
229
     value_32bit );
230
231
    byte_stream_copy_to_uint32_little_endian(
232
     &( data[ 8 ] ),
233
     value_32bit );
234
    libcnotify_printf(
235
     "%s: data size\t\t\t\t: %" PRIu32 "\n",
236
     function,
237
     value_32bit );
238
239
    byte_stream_copy_to_uint32_little_endian(
240
     &( data[ 12 ] ),
241
     value_32bit );
242
    libcnotify_printf(
243
     "%s: unknown2\t\t\t\t: 0x%08" PRIx32 "\n",
244
     function,
245
     value_32bit );
246
247
    byte_stream_copy_to_uint32_little_endian(
248
     &( data[ 16 ] ),
249
     value_32bit );
250
    libcnotify_printf(
251
     "%s: unknown3\t\t\t\t: 0x%08" PRIx32 "\n",
252
     function,
253
     value_32bit );
254
255
    libcnotify_printf(
256
     "%s: string1 data size\t\t\t: %" PRIu32 "\n",
257
     function,
258
     string_data_size );
259
  }
260
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
261
262
0
  data_offset = 24;
263
264
0
  if( ( string_data_size > data_size )
265
0
   || ( data_offset > ( data_size - string_data_size ) ) )
266
0
  {
267
0
    libcerror_error_set(
268
0
     error,
269
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
270
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
271
0
     "%s: invalid string1 data size value out of bounds.",
272
0
     function );
273
274
0
    goto on_error;
275
0
  }
276
#if defined( HAVE_DEBUG_OUTPUT )
277
  if( libcnotify_verbose != 0 )
278
  {
279
    libcnotify_printf(
280
     "%s: string1 data:\n",
281
     function );
282
    libcnotify_print_data(
283
     &( data[ data_offset ] ),
284
     string_data_size,
285
     0 );
286
  }
287
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
288
289
0
  data_offset += string_data_size;
290
291
0
  if( data_offset > ( data_size - 20 ) )
292
0
  {
293
0
    libcerror_error_set(
294
0
     error,
295
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
296
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
297
0
     "%s: invalid data size value out of bounds.",
298
0
     function );
299
300
0
    goto on_error;
301
0
  }
302
0
  byte_stream_copy_to_uint32_little_endian(
303
0
   &( data[ data_offset + 16 ] ),
304
0
   string_data_size );
305
306
#if defined( HAVE_DEBUG_OUTPUT )
307
  if( libcnotify_verbose != 0 )
308
  {
309
    byte_stream_copy_to_uint32_little_endian(
310
     &( data[ data_offset ] ),
311
     value_32bit );
312
    libcnotify_printf(
313
     "%s: unknown4\t\t\t\t: 0x%08" PRIx32 "\n",
314
     function,
315
     value_32bit );
316
317
    byte_stream_copy_to_uint32_little_endian(
318
     &( data[ data_offset + 4 ] ),
319
     value_32bit );
320
    libcnotify_printf(
321
     "%s: unknown5\t\t\t\t: 0x%08" PRIx32 "\n",
322
     function,
323
     value_32bit );
324
325
    byte_stream_copy_to_uint32_little_endian(
326
     &( data[ data_offset + 8 ] ),
327
     value_32bit );
328
    libcnotify_printf(
329
     "%s: unknown6\t\t\t\t: 0x%08" PRIx32 "\n",
330
     function,
331
     value_32bit );
332
333
    byte_stream_copy_to_uint32_little_endian(
334
     &( data[ data_offset + 12 ] ),
335
     value_32bit );
336
    libcnotify_printf(
337
     "%s: unknown7\t\t\t\t: 0x%08" PRIx32 "\n",
338
     function,
339
     value_32bit );
340
341
    libcnotify_printf(
342
     "%s: string2 data size\t\t\t: %" PRIu32 "\n",
343
     function,
344
     string_data_size );
345
  }
346
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
347
348
0
  data_offset += 20;
349
350
0
  if( ( string_data_size > data_size )
351
0
   || ( data_offset > ( data_size - string_data_size ) ) )
352
0
  {
353
0
    libcerror_error_set(
354
0
     error,
355
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
356
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
357
0
     "%s: invalid string2 data size value out of bounds.",
358
0
     function );
359
360
0
    goto on_error;
361
0
  }
362
#if defined( HAVE_DEBUG_OUTPUT )
363
  if( libcnotify_verbose != 0 )
364
  {
365
    libcnotify_printf(
366
     "%s: string2 data:\n",
367
     function );
368
    libcnotify_print_data(
369
     &( data[ data_offset ] ),
370
     string_data_size,
371
     0 );
372
  }
373
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
374
375
0
  data_offset += string_data_size;
376
377
0
  if( data_offset > ( data_size - 12 ) )
378
0
  {
379
0
    libcerror_error_set(
380
0
     error,
381
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
382
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
383
0
     "%s: invalid data size value out of bounds.",
384
0
     function );
385
386
0
    goto on_error;
387
0
  }
388
#if defined( HAVE_DEBUG_OUTPUT )
389
  if( libcnotify_verbose != 0 )
390
  {
391
    byte_stream_copy_to_uint32_little_endian(
392
     &( data[ data_offset ] ),
393
     value_32bit );
394
    libcnotify_printf(
395
     "%s: unknown8\t\t\t\t: 0x%08" PRIx32 "\n",
396
     function,
397
     value_32bit );
398
399
    byte_stream_copy_to_uint32_little_endian(
400
     &( data[ data_offset + 4 ] ),
401
     value_32bit );
402
    libcnotify_printf(
403
     "%s: unknown9\t\t\t\t: 0x%08" PRIx32 "\n",
404
     function,
405
     value_32bit );
406
407
    byte_stream_copy_to_uint16_little_endian(
408
     &( data[ data_offset + 8 ] ),
409
     value_16bit );
410
    libcnotify_printf(
411
     "%s: unknown10\t\t\t\t: 0x%04" PRIx16 "\n",
412
     function,
413
     value_16bit );
414
415
    byte_stream_copy_to_uint16_little_endian(
416
     &( data[ data_offset + 10 ] ),
417
     value_16bit );
418
    libcnotify_printf(
419
     "%s: unknown11\t\t\t\t: 0x%04" PRIx16 "\n",
420
     function,
421
     value_16bit );
422
  }
423
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
424
425
0
  data_offset += 12;
426
427
#if defined( HAVE_DEBUG_OUTPUT )
428
  if( libcnotify_verbose != 0 )
429
  {
430
    if( data_offset < data_size )
431
    {
432
      libcnotify_printf(
433
       "%s: trailing data:\n",
434
       function );
435
      libcnotify_print_data(
436
       &( data[ data_offset ] ),
437
       data_size - data_offset,
438
       LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
439
    }
440
    else
441
    {
442
      libcnotify_printf(
443
       "\n" );
444
    }
445
  }
446
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
447
448
0
  return( 1 );
449
450
0
on_error:
451
0
  if( web_site_values->location != NULL )
452
0
  {
453
0
    memory_free(
454
0
     web_site_values->location );
455
456
0
    web_site_values->location = NULL;
457
0
  }
458
0
  web_site_values->location_size = 0;
459
460
0
  return( -1 );
461
0
}
462