Coverage Report

Created: 2025-10-14 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwsi/libfwsi/libfwsi_delegate_folder_values.c
Line
Count
Source
1
/*
2
 * Delegate folder (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_delegate_folder_values.h"
30
#include "libfwsi_libcerror.h"
31
#include "libfwsi_libcnotify.h"
32
#include "libfwsi_libfguid.h"
33
#include "libfwsi_libuna.h"
34
#include "libfwsi_shell_folder_identifier.h"
35
36
const uint8_t libfwsi_delegate_class_identifier[ 16 ] = {
37
  0x74, 0x1a, 0x59, 0x5e, 0x96, 0xdf, 0xd3, 0x48, 0x8d, 0x67, 0x17, 0x33, 0xbc, 0xee, 0x28, 0xba };
38
39
/* Creates delegate folder values
40
 * Make sure the value delegate_folder_values is referencing, is set to NULL
41
 * Returns 1 if successful or -1 on error
42
 */
43
int libfwsi_delegate_folder_values_initialize(
44
     libfwsi_delegate_folder_values_t **delegate_folder_values,
45
     libcerror_error_t **error )
46
0
{
47
0
  static char *function = "libfwsi_delegate_folder_values_initialize";
48
49
0
  if( delegate_folder_values == NULL )
50
0
  {
51
0
    libcerror_error_set(
52
0
     error,
53
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
54
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
55
0
     "%s: invalid delegate folder values.",
56
0
     function );
57
58
0
    return( -1 );
59
0
  }
60
0
  if( *delegate_folder_values != NULL )
61
0
  {
62
0
    libcerror_error_set(
63
0
     error,
64
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
65
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
66
0
     "%s: invalid delegate folder values value already set.",
67
0
     function );
68
69
0
    return( -1 );
70
0
  }
71
0
  *delegate_folder_values = memory_allocate_structure(
72
0
                             libfwsi_delegate_folder_values_t );
73
74
0
  if( *delegate_folder_values == NULL )
75
0
  {
76
0
    libcerror_error_set(
77
0
     error,
78
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
79
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
80
0
     "%s: unable to create delegate folder values.",
81
0
     function );
82
83
0
    goto on_error;
84
0
  }
85
0
  if( memory_set(
86
0
       *delegate_folder_values,
87
0
       0,
88
0
       sizeof( libfwsi_delegate_folder_values_t ) ) == NULL )
89
0
  {
90
0
    libcerror_error_set(
91
0
     error,
92
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
93
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
94
0
     "%s: unable to clear delegate folder values.",
95
0
     function );
96
97
0
    goto on_error;
98
0
  }
99
0
  return( 1 );
100
101
0
on_error:
102
0
  if( *delegate_folder_values != NULL )
103
0
  {
104
0
    memory_free(
105
0
     *delegate_folder_values );
106
107
0
    *delegate_folder_values = NULL;
108
0
  }
109
0
  return( -1 );
110
0
}
111
112
/* Frees delegate folder values
113
 * Returns 1 if successful or -1 on error
114
 */
115
int libfwsi_delegate_folder_values_free(
116
     libfwsi_delegate_folder_values_t **delegate_folder_values,
117
     libcerror_error_t **error )
118
0
{
119
0
  static char *function = "libfwsi_delegate_folder_values_free";
120
121
0
  if( delegate_folder_values == NULL )
122
0
  {
123
0
    libcerror_error_set(
124
0
     error,
125
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
126
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
127
0
     "%s: invalid delegate folder values.",
128
0
     function );
129
130
0
    return( -1 );
131
0
  }
132
0
  if( *delegate_folder_values != NULL )
133
0
  {
134
0
    memory_free(
135
0
     *delegate_folder_values );
136
137
0
    *delegate_folder_values = NULL;
138
0
  }
139
0
  return( 1 );
140
0
}
141
142
/* Reads the delegate folder values
143
 * Returns 1 if successful, 0 if not supported or -1 on error
144
 */
145
int libfwsi_delegate_folder_values_read_data(
146
     libfwsi_delegate_folder_values_t *delegate_folder_values,
147
     const uint8_t *data,
148
     size_t data_size,
149
     libcerror_error_t **error )
150
0
{
151
0
  static char *function    = "libfwsi_delegate_folder_values_read_data";
152
0
  uint16_t inner_data_size = 0;
153
154
0
  if( delegate_folder_values == NULL )
155
0
  {
156
0
    libcerror_error_set(
157
0
     error,
158
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
159
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
160
0
     "%s: invalid delegate folder values.",
161
0
     function );
162
163
0
    return( -1 );
164
0
  }
165
0
  if( data == NULL )
166
0
  {
167
0
    libcerror_error_set(
168
0
     error,
169
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
170
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
171
0
     "%s: invalid data.",
172
0
     function );
173
174
0
    return( -1 );
175
0
  }
176
0
  if( data_size > (size_t) SSIZE_MAX )
177
0
  {
178
0
    libcerror_error_set(
179
0
     error,
180
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
181
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
182
0
     "%s: data size exceeds maximum.",
183
0
     function );
184
185
0
    return( -1 );
186
0
  }
187
  /* Do not try to parse unsupported data sizes
188
   */
189
0
  if( data_size < 38 )
190
0
  {
191
0
    return( 0 );
192
0
  }
193
  /* Do not try to parse unsupported data
194
   */
195
0
  if( memory_compare(
196
0
       &( data[ data_size - 32 ] ),
197
0
       libfwsi_delegate_class_identifier,
198
0
       16 ) != 0 )
199
0
  {
200
0
    return( 0 );
201
0
  }
202
0
  byte_stream_copy_to_uint16_little_endian(
203
0
   &( data[ 4 ] ),
204
0
   inner_data_size );
205
206
#if defined( HAVE_DEBUG_OUTPUT )
207
  if( libcnotify_verbose != 0 )
208
  {
209
    libcnotify_printf(
210
     "%s: class type indicator\t\t: 0x%02" PRIx8 "\n",
211
     function,
212
     data[ 2 ] );
213
214
    libcnotify_printf(
215
     "%s: unknown1\t\t\t: 0x%02" PRIx8 "\n",
216
     function,
217
     data[ 3 ] );
218
219
    libcnotify_printf(
220
     "%s: inner data size\t\t: %" PRIu16 "\n",
221
     function,
222
     inner_data_size );
223
  }
224
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
225
226
0
  if( inner_data_size > ( data_size - 38 ) )
227
0
  {
228
0
    libcerror_error_set(
229
0
     error,
230
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
231
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
232
0
     "%s: invalid inner data size value out of bounds.",
233
0
     function );
234
235
0
    return( -1 );
236
0
  }
237
0
  delegate_folder_values->inner_data      = &( data[ 6 ] );
238
0
  delegate_folder_values->inner_data_size = inner_data_size;
239
240
0
  if( memory_copy(
241
0
       delegate_folder_values->identifier,
242
0
       &( data[ data_size - 16 ] ),
243
0
       16 ) == NULL )
244
0
  {
245
0
    libcerror_error_set(
246
0
     error,
247
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
248
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
249
0
     "%s: unable to delegate folder identifier.",
250
0
     function );
251
252
0
    return( -1 );
253
0
  }
254
#if defined( HAVE_DEBUG_OUTPUT )
255
  if( libcnotify_verbose != 0 )
256
  {
257
    libcnotify_printf(
258
     "%s: inner data:\n",
259
     function );
260
    libcnotify_print_data(
261
     delegate_folder_values->inner_data,
262
     delegate_folder_values->inner_data_size,
263
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
264
265
    if( inner_data_size < ( data_size - 38 ) )
266
    {
267
      libcnotify_printf(
268
       "%s: trailing data:\n",
269
       function );
270
      libcnotify_print_data(
271
       &( data[ 4 + inner_data_size ] ),
272
       data_size - ( inner_data_size + 38 ),
273
       LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
274
    }
275
    if( libfwsi_debug_print_guid_value(
276
         function,
277
         "delegate class identifier\t",
278
         &( data[ data_size - 32 ] ),
279
         16,
280
         LIBFGUID_ENDIAN_LITTLE,
281
         LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
282
         error ) != 1 )
283
    {
284
      libcerror_error_set(
285
       error,
286
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
287
       LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
288
       "%s: unable to print GUID value.",
289
       function );
290
291
      return( -1 );
292
    }
293
    if( libfwsi_debug_print_guid_value(
294
         function,
295
         "delegate folder identifier\t",
296
         delegate_folder_values->identifier,
297
         16,
298
         LIBFGUID_ENDIAN_LITTLE,
299
         LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES,
300
         error ) != 1 )
301
    {
302
      libcerror_error_set(
303
       error,
304
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
305
       LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
306
       "%s: unable to print GUID value.",
307
       function );
308
309
      return( -1 );
310
    }
311
    libcnotify_printf(
312
     "%s: delegate folder name\t\t: %s\n",
313
     function,
314
     libfwsi_shell_folder_identifier_get_name(
315
      delegate_folder_values->identifier ) );
316
317
    libcnotify_printf(
318
     "\n" );
319
  }
320
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
321
322
0
  return( 1 );
323
0
}
324