Coverage Report

Created: 2025-10-14 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwsi/libfwsi/libfwsi_cdburn_values.c
Line
Count
Source
1
/*
2
 * CD burn (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_cdburn_values.h"
28
#include "libfwsi_libcerror.h"
29
#include "libfwsi_libcnotify.h"
30
31
/* Creates CD burn values
32
 * Make sure the value cdburn_values is referencing, is set to NULL
33
 * Returns 1 if successful or -1 on error
34
 */
35
int libfwsi_cdburn_values_initialize(
36
     libfwsi_cdburn_values_t **cdburn_values,
37
     libcerror_error_t **error )
38
0
{
39
0
  static char *function = "libfwsi_cdburn_values_initialize";
40
41
0
  if( cdburn_values == NULL )
42
0
  {
43
0
    libcerror_error_set(
44
0
     error,
45
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
46
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
47
0
     "%s: invalid CD burn values.",
48
0
     function );
49
50
0
    return( -1 );
51
0
  }
52
0
  if( *cdburn_values != NULL )
53
0
  {
54
0
    libcerror_error_set(
55
0
     error,
56
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
57
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
58
0
     "%s: invalid CD burn values value already set.",
59
0
     function );
60
61
0
    return( -1 );
62
0
  }
63
0
  *cdburn_values = memory_allocate_structure(
64
0
                    libfwsi_cdburn_values_t );
65
66
0
  if( *cdburn_values == NULL )
67
0
  {
68
0
    libcerror_error_set(
69
0
     error,
70
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
71
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
72
0
     "%s: unable to create CD burn values.",
73
0
     function );
74
75
0
    goto on_error;
76
0
  }
77
0
  if( memory_set(
78
0
       *cdburn_values,
79
0
       0,
80
0
       sizeof( libfwsi_cdburn_values_t ) ) == NULL )
81
0
  {
82
0
    libcerror_error_set(
83
0
     error,
84
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
85
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
86
0
     "%s: unable to clear CD burn values.",
87
0
     function );
88
89
0
    goto on_error;
90
0
  }
91
0
  return( 1 );
92
93
0
on_error:
94
0
  if( *cdburn_values != NULL )
95
0
  {
96
0
    memory_free(
97
0
     *cdburn_values );
98
99
0
    *cdburn_values = NULL;
100
0
  }
101
0
  return( -1 );
102
0
}
103
104
/* Frees CD burn values
105
 * Returns 1 if successful or -1 on error
106
 */
107
int libfwsi_cdburn_values_free(
108
     libfwsi_cdburn_values_t **cdburn_values,
109
     libcerror_error_t **error )
110
0
{
111
0
  static char *function = "libfwsi_cdburn_values_free";
112
113
0
  if( cdburn_values == NULL )
114
0
  {
115
0
    libcerror_error_set(
116
0
     error,
117
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
118
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
119
0
     "%s: invalid CD burn values.",
120
0
     function );
121
122
0
    return( -1 );
123
0
  }
124
0
  if( *cdburn_values != NULL )
125
0
  {
126
0
    memory_free(
127
0
     *cdburn_values );
128
129
0
    *cdburn_values = NULL;
130
0
  }
131
0
  return( 1 );
132
0
}
133
134
/* Reads the CD burn values
135
 * Returns 1 if successful, 0 if not supported or -1 on error
136
 */
137
int libfwsi_cdburn_values_read_data(
138
     libfwsi_cdburn_values_t *cdburn_values,
139
     const uint8_t *data,
140
     size_t data_size,
141
     libcerror_error_t **error )
142
0
{
143
0
  static char *function = "libfwsi_cdburn_values_read_data";
144
0
  size_t data_offset    = 0;
145
0
  uint32_t unknown2     = 0;
146
147
#if defined( HAVE_DEBUG_OUTPUT )
148
  uint32_t value_32bit  = 0;
149
#endif
150
151
0
  if( cdburn_values == NULL )
152
0
  {
153
0
    libcerror_error_set(
154
0
     error,
155
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
156
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
157
0
     "%s: invalid CD burn values.",
158
0
     function );
159
160
0
    return( -1 );
161
0
  }
162
0
  if( data == NULL )
163
0
  {
164
0
    libcerror_error_set(
165
0
     error,
166
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
167
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
168
0
     "%s: invalid data.",
169
0
     function );
170
171
0
    return( -1 );
172
0
  }
173
0
  if( data_size > (size_t) SSIZE_MAX )
174
0
  {
175
0
    libcerror_error_set(
176
0
     error,
177
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
178
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
179
0
     "%s: data size exceeds maximum.",
180
0
     function );
181
182
0
    return( -1 );
183
0
  }
184
  /* Do not try to parse unsupported data sizes
185
   */
186
0
  if( data_size < 18 )
187
0
  {
188
0
    return( 0 );
189
0
  }
190
  /* Do not try to parse unsupported shell item signatures
191
   */
192
0
  if( memory_compare(
193
0
       &( data[ 4 ] ),
194
0
       "AugM",
195
0
       4 ) != 0 )
196
0
  {
197
0
    return( 0 );
198
0
  }
199
0
  byte_stream_copy_to_uint32_little_endian(
200
0
   &( data[ 8 ] ),
201
0
   unknown2 );
202
203
#if defined( HAVE_DEBUG_OUTPUT )
204
  if( libcnotify_verbose != 0 )
205
  {
206
    libcnotify_printf(
207
     "%s: class type indicator\t\t\t: 0x%02" PRIx8 "\n",
208
     function,
209
     data[ 2 ] );
210
211
    libcnotify_printf(
212
     "%s: unknown1\t\t\t\t\t: 0x%02" PRIx8 "\n",
213
     function,
214
     data[ 3 ] );
215
216
    libcnotify_printf(
217
     "%s: signature\t\t\t\t\t: %c%c%c%c\n",
218
     function,
219
     data[ 4 ],
220
     data[ 5 ],
221
     data[ 6 ],
222
     data[ 7 ] );
223
224
    libcnotify_printf(
225
     "%s: unknown2\t\t\t\t\t: 0x%08" PRIx32 "\n",
226
     function,
227
     unknown2 );
228
229
    byte_stream_copy_to_uint32_little_endian(
230
     &( data[ 12 ] ),
231
     value_32bit );
232
    libcnotify_printf(
233
     "%s: unknown3\t\t\t\t\t: 0x%08" PRIx32 "\n",
234
     function,
235
     value_32bit );
236
237
    if( ( unknown2 == 4 )
238
     && ( data_size >= 22 ) )
239
    {
240
      byte_stream_copy_to_uint32_little_endian(
241
       &( data[ 16 ] ),
242
       value_32bit );
243
      libcnotify_printf(
244
       "%s: unknown4\t\t\t\t\t: 0x%08" PRIx32 "\n",
245
       function,
246
       value_32bit );
247
    }
248
  }
249
#endif
250
  /* Do not try to parse unsupported unknown2 values
251
   */
252
0
  if( unknown2 == 2 )
253
0
  {
254
0
    data_offset = 16;
255
0
  }
256
0
  else if( unknown2 == 4 )
257
0
  {
258
0
    data_offset = 20;
259
0
  }
260
0
  if( data_offset > 0 )
261
0
  {
262
/* TODO parse sub shell item list */
263
0
  }
264
#if defined( HAVE_DEBUG_OUTPUT )
265
  if( libcnotify_verbose != 0 )
266
  {
267
    libcnotify_printf(
268
     "\n" );
269
  }
270
#endif
271
0
  return( 1 );
272
0
}
273