/src/libevtx/libfwevt/libfwevt_xml_template_value.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Binary XML template value functions |
3 | | * |
4 | | * Copyright (C) 2011-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 <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libfwevt_libcerror.h" |
27 | | #include "libfwevt_types.h" |
28 | | #include "libfwevt_xml_template_value.h" |
29 | | |
30 | | /* Creates a binary XML template value |
31 | | * Make sure the value xml_template_value is referencing, is set to NULL |
32 | | * Returns 1 if successful or -1 on error |
33 | | */ |
34 | | int libfwevt_xml_template_value_initialize( |
35 | | libfwevt_xml_template_value_t **xml_template_value, |
36 | | libcerror_error_t **error ) |
37 | 3.77M | { |
38 | 3.77M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
39 | 3.77M | static char *function = "libfwevt_xml_template_value_initialize"; |
40 | | |
41 | 3.77M | if( xml_template_value == 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 binary XML template value.", |
48 | 0 | function ); |
49 | |
|
50 | 0 | return( -1 ); |
51 | 0 | } |
52 | 3.77M | if( *xml_template_value != 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 binary XML template value value already set.", |
59 | 0 | function ); |
60 | |
|
61 | 0 | return( -1 ); |
62 | 0 | } |
63 | 3.77M | internal_xml_template_value = memory_allocate_structure( |
64 | 3.77M | libfwevt_internal_xml_template_value_t ); |
65 | | |
66 | 3.77M | if( internal_xml_template_value == 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 binary XML template value.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | goto on_error; |
76 | 0 | } |
77 | 3.77M | if( memory_set( |
78 | 3.77M | internal_xml_template_value, |
79 | 3.77M | 0, |
80 | 3.77M | sizeof( libfwevt_internal_xml_template_value_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 binary XML template value.", |
87 | 0 | function ); |
88 | | |
89 | |
|
90 | 0 | goto on_error; |
91 | 0 | } |
92 | 3.77M | *xml_template_value = (libfwevt_xml_template_value_t *) internal_xml_template_value; |
93 | | |
94 | 3.77M | return( 1 ); |
95 | | |
96 | 0 | on_error: |
97 | 0 | if( internal_xml_template_value != NULL ) |
98 | 0 | { |
99 | 0 | memory_free( |
100 | 0 | internal_xml_template_value ); |
101 | 0 | } |
102 | 0 | return( -1 ); |
103 | 3.77M | } |
104 | | |
105 | | /* Frees a binary XML template value |
106 | | * Returns 1 if successful or -1 on error |
107 | | */ |
108 | | int libfwevt_xml_template_value_free( |
109 | | libfwevt_xml_template_value_t **xml_template_value, |
110 | | libcerror_error_t **error ) |
111 | 3.77M | { |
112 | 3.77M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
113 | 3.77M | static char *function = "libfwevt_xml_template_value_free"; |
114 | | |
115 | 3.77M | if( xml_template_value == NULL ) |
116 | 0 | { |
117 | 0 | libcerror_error_set( |
118 | 0 | error, |
119 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
120 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
121 | 0 | "%s: invalid binary XML template value.", |
122 | 0 | function ); |
123 | |
|
124 | 0 | return( -1 ); |
125 | 0 | } |
126 | 3.77M | if( *xml_template_value != NULL ) |
127 | 3.77M | { |
128 | 3.77M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) *xml_template_value; |
129 | 3.77M | *xml_template_value = NULL; |
130 | | |
131 | 3.77M | memory_free( |
132 | 3.77M | internal_xml_template_value ); |
133 | 3.77M | } |
134 | 3.77M | return( 1 ); |
135 | 3.77M | } |
136 | | |
137 | | /* Retrieves the type |
138 | | * Returns 1 if successful or -1 on error |
139 | | */ |
140 | | int libfwevt_xml_template_value_get_type( |
141 | | libfwevt_xml_template_value_t *xml_template_value, |
142 | | uint8_t *type, |
143 | | libcerror_error_t **error ) |
144 | 1.17M | { |
145 | 1.17M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
146 | 1.17M | static char *function = "libfwevt_xml_template_value_get_type"; |
147 | | |
148 | 1.17M | if( xml_template_value == NULL ) |
149 | 0 | { |
150 | 0 | libcerror_error_set( |
151 | 0 | error, |
152 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
153 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
154 | 0 | "%s: invalid binary XML template value.", |
155 | 0 | function ); |
156 | |
|
157 | 0 | return( -1 ); |
158 | 0 | } |
159 | 1.17M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
160 | | |
161 | 1.17M | if( type == 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 type.", |
168 | 0 | function ); |
169 | |
|
170 | 0 | return( -1 ); |
171 | 0 | } |
172 | 1.17M | *type = internal_xml_template_value->type; |
173 | | |
174 | 1.17M | return( 1 ); |
175 | 1.17M | } |
176 | | |
177 | | /* Sets the type |
178 | | * Returns 1 if successful or -1 on error |
179 | | */ |
180 | | int libfwevt_xml_template_value_set_type( |
181 | | libfwevt_xml_template_value_t *xml_template_value, |
182 | | uint8_t type, |
183 | | libcerror_error_t **error ) |
184 | 3.77M | { |
185 | 3.77M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
186 | 3.77M | static char *function = "libfwevt_xml_template_value_set_type"; |
187 | | |
188 | 3.77M | if( xml_template_value == NULL ) |
189 | 0 | { |
190 | 0 | libcerror_error_set( |
191 | 0 | error, |
192 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
193 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
194 | 0 | "%s: invalid binary XML template value.", |
195 | 0 | function ); |
196 | |
|
197 | 0 | return( -1 ); |
198 | 0 | } |
199 | 3.77M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
200 | | |
201 | 3.77M | internal_xml_template_value->type = type; |
202 | | |
203 | 3.77M | return( 1 ); |
204 | 3.77M | } |
205 | | |
206 | | /* Retrieves the offset |
207 | | * Returns 1 if successful or -1 on error |
208 | | */ |
209 | | int libfwevt_xml_template_value_get_offset( |
210 | | libfwevt_xml_template_value_t *xml_template_value, |
211 | | size_t *offset, |
212 | | libcerror_error_t **error ) |
213 | 1.17M | { |
214 | 1.17M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
215 | 1.17M | static char *function = "libfwevt_xml_template_value_get_offset"; |
216 | | |
217 | 1.17M | if( xml_template_value == NULL ) |
218 | 0 | { |
219 | 0 | libcerror_error_set( |
220 | 0 | error, |
221 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
222 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
223 | 0 | "%s: invalid binary XML template value.", |
224 | 0 | function ); |
225 | |
|
226 | 0 | return( -1 ); |
227 | 0 | } |
228 | 1.17M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
229 | | |
230 | 1.17M | if( offset == NULL ) |
231 | 0 | { |
232 | 0 | libcerror_error_set( |
233 | 0 | error, |
234 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
235 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
236 | 0 | "%s: invalid offset.", |
237 | 0 | function ); |
238 | |
|
239 | 0 | return( -1 ); |
240 | 0 | } |
241 | 1.17M | *offset = internal_xml_template_value->offset; |
242 | | |
243 | 1.17M | return( 1 ); |
244 | 1.17M | } |
245 | | |
246 | | /* Sets the offset |
247 | | * Returns 1 if successful or -1 on error |
248 | | */ |
249 | | int libfwevt_xml_template_value_set_offset( |
250 | | libfwevt_xml_template_value_t *xml_template_value, |
251 | | size_t offset, |
252 | | libcerror_error_t **error ) |
253 | 777k | { |
254 | 777k | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
255 | 777k | static char *function = "libfwevt_xml_template_value_set_offset"; |
256 | | |
257 | 777k | if( xml_template_value == NULL ) |
258 | 0 | { |
259 | 0 | libcerror_error_set( |
260 | 0 | error, |
261 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
262 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
263 | 0 | "%s: invalid binary XML template value.", |
264 | 0 | function ); |
265 | |
|
266 | 0 | return( -1 ); |
267 | 0 | } |
268 | 777k | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
269 | | |
270 | 777k | internal_xml_template_value->offset = offset; |
271 | | |
272 | 777k | return( 1 ); |
273 | 777k | } |
274 | | |
275 | | /* Retrieves the size |
276 | | * Returns 1 if successful or -1 on error |
277 | | */ |
278 | | int libfwevt_xml_template_value_get_size( |
279 | | libfwevt_xml_template_value_t *xml_template_value, |
280 | | uint16_t *size, |
281 | | libcerror_error_t **error ) |
282 | 3.21M | { |
283 | 3.21M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
284 | 3.21M | static char *function = "libfwevt_xml_template_value_get_size"; |
285 | | |
286 | 3.21M | if( xml_template_value == NULL ) |
287 | 0 | { |
288 | 0 | libcerror_error_set( |
289 | 0 | error, |
290 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
291 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
292 | 0 | "%s: invalid binary XML template value.", |
293 | 0 | function ); |
294 | |
|
295 | 0 | return( -1 ); |
296 | 0 | } |
297 | 3.21M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
298 | | |
299 | 3.21M | if( size == NULL ) |
300 | 0 | { |
301 | 0 | libcerror_error_set( |
302 | 0 | error, |
303 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
304 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
305 | 0 | "%s: invalid size.", |
306 | 0 | function ); |
307 | |
|
308 | 0 | return( -1 ); |
309 | 0 | } |
310 | 3.21M | *size = internal_xml_template_value->size; |
311 | | |
312 | 3.21M | return( 1 ); |
313 | 3.21M | } |
314 | | |
315 | | /* Sets the size |
316 | | * Returns 1 if successful or -1 on error |
317 | | */ |
318 | | int libfwevt_xml_template_value_set_size( |
319 | | libfwevt_xml_template_value_t *xml_template_value, |
320 | | uint16_t size, |
321 | | libcerror_error_t **error ) |
322 | 3.77M | { |
323 | 3.77M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
324 | 3.77M | static char *function = "libfwevt_xml_template_value_set_size"; |
325 | | |
326 | 3.77M | if( xml_template_value == NULL ) |
327 | 0 | { |
328 | 0 | libcerror_error_set( |
329 | 0 | error, |
330 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
331 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
332 | 0 | "%s: invalid binary XML template value.", |
333 | 0 | function ); |
334 | |
|
335 | 0 | return( -1 ); |
336 | 0 | } |
337 | 3.77M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
338 | | |
339 | 3.77M | internal_xml_template_value->size = size; |
340 | | |
341 | 3.77M | return( 1 ); |
342 | 3.77M | } |
343 | | |
344 | | /* Retrieves the flags |
345 | | * Returns 1 if successful or -1 on error |
346 | | */ |
347 | | int libfwevt_xml_template_value_get_flags( |
348 | | libfwevt_xml_template_value_t *xml_template_value, |
349 | | uint8_t *flags, |
350 | | libcerror_error_t **error ) |
351 | 1.17M | { |
352 | 1.17M | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
353 | 1.17M | static char *function = "libfwevt_xml_template_value_get_flags"; |
354 | | |
355 | 1.17M | if( xml_template_value == NULL ) |
356 | 0 | { |
357 | 0 | libcerror_error_set( |
358 | 0 | error, |
359 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
360 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
361 | 0 | "%s: invalid binary XML template value.", |
362 | 0 | function ); |
363 | |
|
364 | 0 | return( -1 ); |
365 | 0 | } |
366 | 1.17M | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
367 | | |
368 | 1.17M | if( flags == NULL ) |
369 | 0 | { |
370 | 0 | libcerror_error_set( |
371 | 0 | error, |
372 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
373 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
374 | 0 | "%s: invalid flags.", |
375 | 0 | function ); |
376 | |
|
377 | 0 | return( -1 ); |
378 | 0 | } |
379 | 1.17M | *flags = internal_xml_template_value->flags; |
380 | | |
381 | 1.17M | return( 1 ); |
382 | 1.17M | } |
383 | | |
384 | | /* Sets the flags |
385 | | * Returns 1 if successful or -1 on error |
386 | | */ |
387 | | int libfwevt_xml_template_value_set_flags( |
388 | | libfwevt_xml_template_value_t *xml_template_value, |
389 | | uint8_t flags, |
390 | | libcerror_error_t **error ) |
391 | 1.68k | { |
392 | 1.68k | libfwevt_internal_xml_template_value_t *internal_xml_template_value = NULL; |
393 | 1.68k | static char *function = "libfwevt_xml_template_value_set_flags"; |
394 | | |
395 | 1.68k | if( xml_template_value == NULL ) |
396 | 0 | { |
397 | 0 | libcerror_error_set( |
398 | 0 | error, |
399 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
400 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
401 | 0 | "%s: invalid binary XML template value.", |
402 | 0 | function ); |
403 | |
|
404 | 0 | return( -1 ); |
405 | 0 | } |
406 | 1.68k | internal_xml_template_value = (libfwevt_internal_xml_template_value_t *) xml_template_value; |
407 | | |
408 | 1.68k | internal_xml_template_value->flags = flags; |
409 | | |
410 | 1.68k | return( 1 ); |
411 | 1.68k | } |
412 | | |