/src/libfwsi/libfwsi/libfwsi_extension_block_0xbeef0001_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Extension block 0xbeef0001 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_definitions.h" |
28 | | #include "libfwsi_extension_block_0xbeef0001_values.h" |
29 | | #include "libfwsi_libcerror.h" |
30 | | #include "libfwsi_libcnotify.h" |
31 | | |
32 | | /* Creates extension block 0xbeef0001 values |
33 | | * Make sure the value extension_block_0xbeef0001_values is referencing, is set to NULL |
34 | | * Returns 1 if successful or -1 on error |
35 | | */ |
36 | | int libfwsi_extension_block_0xbeef0001_values_initialize( |
37 | | libfwsi_extension_block_0xbeef0001_values_t **extension_block_0xbeef0001_values, |
38 | | libcerror_error_t **error ) |
39 | 0 | { |
40 | 0 | static char *function = "libfwsi_extension_block_0xbeef0001_values_initialize"; |
41 | |
|
42 | 0 | if( extension_block_0xbeef0001_values == NULL ) |
43 | 0 | { |
44 | 0 | libcerror_error_set( |
45 | 0 | error, |
46 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
47 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
48 | 0 | "%s: invalid extension block 0xbeef0001 values.", |
49 | 0 | function ); |
50 | |
|
51 | 0 | return( -1 ); |
52 | 0 | } |
53 | 0 | if( *extension_block_0xbeef0001_values != NULL ) |
54 | 0 | { |
55 | 0 | libcerror_error_set( |
56 | 0 | error, |
57 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
58 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
59 | 0 | "%s: invalid extension block 0xbeef0001 values value already set.", |
60 | 0 | function ); |
61 | |
|
62 | 0 | return( -1 ); |
63 | 0 | } |
64 | 0 | *extension_block_0xbeef0001_values = memory_allocate_structure( |
65 | 0 | libfwsi_extension_block_0xbeef0001_values_t ); |
66 | |
|
67 | 0 | if( *extension_block_0xbeef0001_values == NULL ) |
68 | 0 | { |
69 | 0 | libcerror_error_set( |
70 | 0 | error, |
71 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
72 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
73 | 0 | "%s: unable to create extension block 0xbeef0001 values.", |
74 | 0 | function ); |
75 | |
|
76 | 0 | goto on_error; |
77 | 0 | } |
78 | 0 | if( memory_set( |
79 | 0 | *extension_block_0xbeef0001_values, |
80 | 0 | 0, |
81 | 0 | sizeof( libfwsi_extension_block_0xbeef0001_values_t ) ) == NULL ) |
82 | 0 | { |
83 | 0 | libcerror_error_set( |
84 | 0 | error, |
85 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
86 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
87 | 0 | "%s: unable to clear extension block 0xbeef0001 values.", |
88 | 0 | function ); |
89 | |
|
90 | 0 | goto on_error; |
91 | 0 | } |
92 | 0 | return( 1 ); |
93 | | |
94 | 0 | on_error: |
95 | 0 | if( *extension_block_0xbeef0001_values != NULL ) |
96 | 0 | { |
97 | 0 | memory_free( |
98 | 0 | *extension_block_0xbeef0001_values ); |
99 | |
|
100 | 0 | *extension_block_0xbeef0001_values = NULL; |
101 | 0 | } |
102 | 0 | return( -1 ); |
103 | 0 | } |
104 | | |
105 | | /* Frees extension block 0xbeef0001 values |
106 | | * Returns 1 if successful or -1 on error |
107 | | */ |
108 | | int libfwsi_extension_block_0xbeef0001_values_free( |
109 | | libfwsi_extension_block_0xbeef0001_values_t **extension_block_0xbeef0001_values, |
110 | | libcerror_error_t **error ) |
111 | 0 | { |
112 | 0 | static char *function = "libfwsi_extension_block_0xbeef0001_values_free"; |
113 | |
|
114 | 0 | if( extension_block_0xbeef0001_values == NULL ) |
115 | 0 | { |
116 | 0 | libcerror_error_set( |
117 | 0 | error, |
118 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
119 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
120 | 0 | "%s: invalid extension block 0xbeef0001 values.", |
121 | 0 | function ); |
122 | |
|
123 | 0 | return( -1 ); |
124 | 0 | } |
125 | 0 | if( *extension_block_0xbeef0001_values != NULL ) |
126 | 0 | { |
127 | 0 | memory_free( |
128 | 0 | *extension_block_0xbeef0001_values ); |
129 | |
|
130 | 0 | *extension_block_0xbeef0001_values = NULL; |
131 | 0 | } |
132 | 0 | return( 1 ); |
133 | 0 | } |
134 | | |
135 | | /* Reads the extension block 0xbeef0001 values |
136 | | * Returns 1 if successful, 0 if not supported or -1 on error |
137 | | */ |
138 | | int libfwsi_extension_block_0xbeef0001_values_read_data( |
139 | | libfwsi_extension_block_0xbeef0001_values_t *extension_block_0xbeef0001_values, |
140 | | const uint8_t *data, |
141 | | size_t data_size, |
142 | | libcerror_error_t **error ) |
143 | 0 | { |
144 | 0 | static char *function = "libfwsi_extension_block_0xbeef0001_values_read_data"; |
145 | 0 | uint32_t signature = 0; |
146 | |
|
147 | | #if defined( HAVE_DEBUG_OUTPUT ) |
148 | | uint32_t value_32bit = 0; |
149 | | #endif |
150 | |
|
151 | 0 | if( extension_block_0xbeef0001_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 extension block 0xbeef0001 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 != 14 ) |
187 | 0 | { |
188 | 0 | return( 0 ); |
189 | 0 | } |
190 | | /* Do not try to parse unsupported extension block signatures |
191 | | */ |
192 | 0 | byte_stream_copy_to_uint32_little_endian( |
193 | 0 | &( data[ 4 ] ), |
194 | 0 | signature ); |
195 | |
|
196 | 0 | if( signature != 0xbeef0001 ) |
197 | 0 | { |
198 | 0 | return( 0 ); |
199 | 0 | } |
200 | | #if defined( HAVE_DEBUG_OUTPUT ) |
201 | | if( libcnotify_verbose != 0 ) |
202 | | { |
203 | | byte_stream_copy_to_uint16_little_endian( |
204 | | &( data[ 8 ] ), |
205 | | value_32bit ); |
206 | | libcnotify_printf( |
207 | | "%s: unknown1\t\t\t\t\t: 0x%08" PRIx32 "\n", |
208 | | function, |
209 | | value_32bit ); |
210 | | } |
211 | | #endif |
212 | 0 | return( 1 ); |
213 | 0 | } |
214 | | |