Coverage Report

Created: 2026-03-05 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfwsi/libfwsi/libfwsi_extension_block_0xbeef0003_values.c
Line
Count
Source
1
/*
2
 * Extension block 0xbeef0003 values functions
3
 *
4
 * Copyright (C) 2010-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 <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_extension_block_0xbeef0003_values.h"
30
#include "libfwsi_libcerror.h"
31
#include "libfwsi_libcnotify.h"
32
#include "libfwsi_libfguid.h"
33
#include "libfwsi_shell_folder_identifier.h"
34
35
/* Creates extension block 0xbeef0003 values
36
 * Make sure the value extension_block_0xbeef0003_values is referencing, is set to NULL
37
 * Returns 1 if successful or -1 on error
38
 */
39
int libfwsi_extension_block_0xbeef0003_values_initialize(
40
     libfwsi_extension_block_0xbeef0003_values_t **extension_block_0xbeef0003_values,
41
     libcerror_error_t **error )
42
0
{
43
0
  static char *function = "libfwsi_extension_block_0xbeef0003_values_initialize";
44
45
0
  if( extension_block_0xbeef0003_values == 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 extension block 0xbeef0003 values.",
52
0
     function );
53
54
0
    return( -1 );
55
0
  }
56
0
  if( *extension_block_0xbeef0003_values != 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 extension block 0xbeef0003 values value already set.",
63
0
     function );
64
65
0
    return( -1 );
66
0
  }
67
0
  *extension_block_0xbeef0003_values = memory_allocate_structure(
68
0
                                        libfwsi_extension_block_0xbeef0003_values_t );
69
70
0
  if( *extension_block_0xbeef0003_values == 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 extension block 0xbeef0003 values.",
77
0
     function );
78
79
0
    goto on_error;
80
0
  }
81
0
  if( memory_set(
82
0
       *extension_block_0xbeef0003_values,
83
0
       0,
84
0
       sizeof( libfwsi_extension_block_0xbeef0003_values_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 extension block 0xbeef0003 values.",
91
0
     function );
92
93
0
    goto on_error;
94
0
  }
95
0
  return( 1 );
96
97
0
on_error:
98
0
  if( *extension_block_0xbeef0003_values != NULL )
99
0
  {
100
0
    memory_free(
101
0
     *extension_block_0xbeef0003_values );
102
103
0
    *extension_block_0xbeef0003_values = NULL;
104
0
  }
105
0
  return( -1 );
106
0
}
107
108
/* Frees extension block 0xbeef0003 values
109
 * Returns 1 if successful or -1 on error
110
 */
111
int libfwsi_extension_block_0xbeef0003_values_free(
112
     libfwsi_extension_block_0xbeef0003_values_t **extension_block_0xbeef0003_values,
113
     libcerror_error_t **error )
114
0
{
115
0
  static char *function = "libfwsi_extension_block_0xbeef0003_values_free";
116
117
0
  if( extension_block_0xbeef0003_values == NULL )
118
0
  {
119
0
    libcerror_error_set(
120
0
     error,
121
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
122
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
123
0
     "%s: invalid extension block 0xbeef0003 values.",
124
0
     function );
125
126
0
    return( -1 );
127
0
  }
128
0
  if( *extension_block_0xbeef0003_values != NULL )
129
0
  {
130
0
    memory_free(
131
0
     *extension_block_0xbeef0003_values );
132
133
0
    *extension_block_0xbeef0003_values = NULL;
134
0
  }
135
0
  return( 1 );
136
0
}
137
138
/* Reads the extension block 0xbeef0003 values
139
 * Returns 1 if successful, 0 if not supported or -1 on error
140
 */
141
int libfwsi_extension_block_0xbeef0003_values_read_data(
142
     libfwsi_extension_block_0xbeef0003_values_t *extension_block_0xbeef0003_values,
143
     const uint8_t *data,
144
     size_t data_size,
145
     libcerror_error_t **error )
146
0
{
147
0
  static char *function = "libfwsi_extension_block_0xbeef0003_values_read_data";
148
0
  uint32_t signature    = 0;
149
150
0
  if( extension_block_0xbeef0003_values == NULL )
151
0
  {
152
0
    libcerror_error_set(
153
0
     error,
154
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
155
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
156
0
     "%s: invalid extension block 0xbeef0003 values.",
157
0
     function );
158
159
0
    return( -1 );
160
0
  }
161
0
  if( data == NULL )
162
0
  {
163
0
    libcerror_error_set(
164
0
     error,
165
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
166
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
167
0
     "%s: invalid data.",
168
0
     function );
169
170
0
    return( -1 );
171
0
  }
172
0
  if( data_size > (size_t) SSIZE_MAX )
173
0
  {
174
0
    libcerror_error_set(
175
0
     error,
176
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
177
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
178
0
     "%s: data size exceeds maximum.",
179
0
     function );
180
181
0
    return( -1 );
182
0
  }
183
  /* Do not try to parse unsupported data sizes
184
   */
185
0
  if( data_size != 26 )
186
0
  {
187
0
    return( 0 );
188
0
  }
189
  /* Do not try to parse unsupported extension block signatures
190
   */
191
0
  byte_stream_copy_to_uint32_little_endian(
192
0
   &( data[ 4 ] ),
193
0
   signature );
194
195
0
  if( signature != 0xbeef0003 )
196
0
  {
197
0
    return( 0 );
198
0
  }
199
#if defined( HAVE_DEBUG_OUTPUT )
200
  if( libcnotify_verbose != 0 )
201
  {
202
    if( libfwsi_debug_print_guid_value(
203
         function,
204
         "shell folder identifier\t",
205
         &( data[ 8 ] ),
206
         16,
207
         LIBFGUID_ENDIAN_LITTLE,
208
         LIBFGUID_STRING_FORMAT_FLAG_USE_LOWER_CASE,
209
         error ) != 1 )
210
    {
211
      libcerror_error_set(
212
       error,
213
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
214
       LIBCERROR_RUNTIME_ERROR_PRINT_FAILED,
215
       "%s: unable to print GUID value.",
216
       function );
217
218
      return( -1 );
219
    }
220
    libcnotify_printf(
221
     "%s: shell folder name\t: %s\n",
222
     function,
223
     libfwsi_shell_folder_identifier_get_name(
224
      &( data[ 8 ] ) ) );
225
226
    libcnotify_printf(
227
     "\n" );
228
  }
229
#endif
230
0
  return( 1 );
231
0
}
232