Coverage Report

Created: 2025-08-28 07:10

/src/libfwsi/libfwsi/libfwsi_extension_block_0xbeef0013_values.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Extension block 0xbeef0013 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_extension_block_0xbeef0013_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 0xbeef0013 values
36
 * Make sure the value extension_block_0xbeef0013_values is referencing, is set to NULL
37
 * Returns 1 if successful or -1 on error
38
 */
39
int libfwsi_extension_block_0xbeef0013_values_initialize(
40
     libfwsi_extension_block_0xbeef0013_values_t **extension_block_0xbeef0013_values,
41
     libcerror_error_t **error )
42
0
{
43
0
  static char *function = "libfwsi_extension_block_0xbeef0013_values_initialize";
44
45
0
  if( extension_block_0xbeef0013_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 0xbeef0013 values.",
52
0
     function );
53
54
0
    return( -1 );
55
0
  }
56
0
  if( *extension_block_0xbeef0013_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 0xbeef0013 values value already set.",
63
0
     function );
64
65
0
    return( -1 );
66
0
  }
67
0
  *extension_block_0xbeef0013_values = memory_allocate_structure(
68
0
                                        libfwsi_extension_block_0xbeef0013_values_t );
69
70
0
  if( *extension_block_0xbeef0013_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 0xbeef0013 values.",
77
0
     function );
78
79
0
    goto on_error;
80
0
  }
81
0
  if( memory_set(
82
0
       *extension_block_0xbeef0013_values,
83
0
       0,
84
0
       sizeof( libfwsi_extension_block_0xbeef0013_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 0xbeef0013 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_0xbeef0013_values != NULL )
99
0
  {
100
0
    memory_free(
101
0
     *extension_block_0xbeef0013_values );
102
103
0
    *extension_block_0xbeef0013_values = NULL;
104
0
  }
105
0
  return( -1 );
106
0
}
107
108
/* Frees extension block 0xbeef0013 values
109
 * Returns 1 if successful or -1 on error
110
 */
111
int libfwsi_extension_block_0xbeef0013_values_free(
112
     libfwsi_extension_block_0xbeef0013_values_t **extension_block_0xbeef0013_values,
113
     libcerror_error_t **error )
114
0
{
115
0
  static char *function = "libfwsi_extension_block_0xbeef0013_values_free";
116
117
0
  if( extension_block_0xbeef0013_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 0xbeef0013 values.",
124
0
     function );
125
126
0
    return( -1 );
127
0
  }
128
0
  if( *extension_block_0xbeef0013_values != NULL )
129
0
  {
130
0
    memory_free(
131
0
     *extension_block_0xbeef0013_values );
132
133
0
    *extension_block_0xbeef0013_values = NULL;
134
0
  }
135
0
  return( 1 );
136
0
}
137
138
/* Reads the extension block 0xbeef0013 values
139
 * Returns 1 if successful, 0 if not supported or -1 on error
140
 */
141
int libfwsi_extension_block_0xbeef0013_values_read_data(
142
     libfwsi_extension_block_0xbeef0013_values_t *extension_block_0xbeef0013_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_0xbeef0013_values_read_data";
148
0
  uint32_t signature    = 0;
149
150
#if defined( HAVE_DEBUG_OUTPUT )
151
  uint32_t value_32bit  = 0;
152
#endif
153
154
0
  if( extension_block_0xbeef0013_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 extension block 0xbeef0013 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 != 42 )
190
0
  {
191
0
    return( 0 );
192
0
  }
193
  /* Do not try to parse unsupported extension block signatures
194
   */
195
0
  byte_stream_copy_to_uint32_little_endian(
196
0
   &( data[ 4 ] ),
197
0
   signature );
198
199
0
  if( signature != 0xbeef0013 )
200
0
  {
201
0
    return( 0 );
202
0
  }
203
#if defined( HAVE_DEBUG_OUTPUT )
204
  if( libcnotify_verbose != 0 )
205
  {
206
    byte_stream_copy_to_uint32_little_endian(
207
     &( data[ 8 ] ),
208
     value_32bit );
209
    libcnotify_printf(
210
     "%s: unknown1\t\t: 0x%08" PRIx32 "\n",
211
     function,
212
     value_32bit );
213
214
    libcnotify_printf(
215
     "%s: unknown2:\n",
216
     function );
217
    libcnotify_print_data(
218
     &( data[ 12 ] ),
219
     24,
220
     0 );
221
222
    byte_stream_copy_to_uint32_little_endian(
223
     &( data[ 36 ] ),
224
     value_32bit );
225
    libcnotify_printf(
226
     "%s: unknown3\t\t: 0x%08" PRIx32 "\n",
227
     function,
228
     value_32bit );
229
230
    libcnotify_printf(
231
     "\n" );
232
  }
233
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
234
235
0
  return( 1 );
236
0
}
237