/src/libregf/libregf/libregf_hive_bin_cell.c
Line | Count | Source |
1 | | /* |
2 | | * Hive bin cell functions |
3 | | * |
4 | | * Copyright (C) 2009-2026, 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 "libregf_hive_bin_cell.h" |
28 | | #include "libregf_libcerror.h" |
29 | | |
30 | | /* Creates a hive bin cell |
31 | | * Make sure the value hive_bin_cell is referencing, is set to NULL |
32 | | * Returns 1 if successful or -1 on error |
33 | | */ |
34 | | int libregf_hive_bin_cell_initialize( |
35 | | libregf_hive_bin_cell_t **hive_bin_cell, |
36 | | libcerror_error_t **error ) |
37 | 99.4k | { |
38 | 99.4k | static char *function = "libregf_hive_bin_cell_initialize"; |
39 | | |
40 | 99.4k | if( hive_bin_cell == NULL ) |
41 | 0 | { |
42 | 0 | libcerror_error_set( |
43 | 0 | error, |
44 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
45 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
46 | 0 | "%s: invalid hive bin cell.", |
47 | 0 | function ); |
48 | |
|
49 | 0 | return( -1 ); |
50 | 0 | } |
51 | 99.4k | if( *hive_bin_cell != NULL ) |
52 | 0 | { |
53 | 0 | libcerror_error_set( |
54 | 0 | error, |
55 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
56 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
57 | 0 | "%s: invalid hive bin cell value already set.", |
58 | 0 | function ); |
59 | |
|
60 | 0 | return( -1 ); |
61 | 0 | } |
62 | 99.4k | *hive_bin_cell = memory_allocate_structure( |
63 | 99.4k | libregf_hive_bin_cell_t ); |
64 | | |
65 | 99.4k | if( *hive_bin_cell == NULL ) |
66 | 0 | { |
67 | 0 | libcerror_error_set( |
68 | 0 | error, |
69 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
70 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
71 | 0 | "%s: unable to create hive bin cell.", |
72 | 0 | function ); |
73 | |
|
74 | 0 | goto on_error; |
75 | 0 | } |
76 | 99.4k | if( memory_set( |
77 | 99.4k | *hive_bin_cell, |
78 | 99.4k | 0, |
79 | 99.4k | sizeof( libregf_hive_bin_cell_t ) ) == NULL ) |
80 | 0 | { |
81 | 0 | libcerror_error_set( |
82 | 0 | error, |
83 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
84 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
85 | 0 | "%s: unable to clear hive bin cell.", |
86 | 0 | function ); |
87 | |
|
88 | 0 | goto on_error; |
89 | 0 | } |
90 | 99.4k | return( 1 ); |
91 | | |
92 | 0 | on_error: |
93 | 0 | if( *hive_bin_cell != NULL ) |
94 | 0 | { |
95 | 0 | memory_free( |
96 | 0 | *hive_bin_cell ); |
97 | |
|
98 | 0 | *hive_bin_cell = NULL; |
99 | 0 | } |
100 | 0 | return( -1 ); |
101 | 99.4k | } |
102 | | |
103 | | /* Frees a hive bin cell |
104 | | * Returns 1 if successful or -1 on error |
105 | | */ |
106 | | int libregf_hive_bin_cell_free( |
107 | | libregf_hive_bin_cell_t **hive_bin_cell, |
108 | | libcerror_error_t **error ) |
109 | 99.4k | { |
110 | 99.4k | static char *function = "libregf_hive_bin_cell_free"; |
111 | | |
112 | 99.4k | if( hive_bin_cell == NULL ) |
113 | 0 | { |
114 | 0 | libcerror_error_set( |
115 | 0 | error, |
116 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
117 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
118 | 0 | "%s: invalid hive bin cell.", |
119 | 0 | function ); |
120 | |
|
121 | 0 | return( -1 ); |
122 | 0 | } |
123 | 99.4k | if( *hive_bin_cell != NULL ) |
124 | 99.4k | { |
125 | | /* The hive bin cell data is referenced |
126 | | * and maintained by the hive bin |
127 | | */ |
128 | 99.4k | memory_free( |
129 | 99.4k | *hive_bin_cell ); |
130 | | |
131 | | *hive_bin_cell = NULL; |
132 | 99.4k | } |
133 | 99.4k | return( 1 ); |
134 | 99.4k | } |
135 | | |