/src/libfwsi/libfwsi/libfwsi_game_folder_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Game folder (shell item) 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_game_folder_values.h" |
29 | | #include "libfwsi_libcerror.h" |
30 | | #include "libfwsi_libcnotify.h" |
31 | | #include "libfwsi_libfguid.h" |
32 | | |
33 | | /* Creates game folder values |
34 | | * Make sure the value game_folder_values is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libfwsi_game_folder_values_initialize( |
38 | | libfwsi_game_folder_values_t **game_folder_values, |
39 | | libcerror_error_t **error ) |
40 | 0 | { |
41 | 0 | static char *function = "libfwsi_game_folder_values_initialize"; |
42 | |
|
43 | 0 | if( game_folder_values == NULL ) |
44 | 0 | { |
45 | 0 | libcerror_error_set( |
46 | 0 | error, |
47 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
48 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
49 | 0 | "%s: invalid game folder values.", |
50 | 0 | function ); |
51 | |
|
52 | 0 | return( -1 ); |
53 | 0 | } |
54 | 0 | if( *game_folder_values != NULL ) |
55 | 0 | { |
56 | 0 | libcerror_error_set( |
57 | 0 | error, |
58 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
59 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
60 | 0 | "%s: invalid game folder values value already set.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 0 | *game_folder_values = memory_allocate_structure( |
66 | 0 | libfwsi_game_folder_values_t ); |
67 | |
|
68 | 0 | if( *game_folder_values == NULL ) |
69 | 0 | { |
70 | 0 | libcerror_error_set( |
71 | 0 | error, |
72 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
73 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
74 | 0 | "%s: unable to create game folder values.", |
75 | 0 | function ); |
76 | |
|
77 | 0 | goto on_error; |
78 | 0 | } |
79 | 0 | if( memory_set( |
80 | 0 | *game_folder_values, |
81 | 0 | 0, |
82 | 0 | sizeof( libfwsi_game_folder_values_t ) ) == NULL ) |
83 | 0 | { |
84 | 0 | libcerror_error_set( |
85 | 0 | error, |
86 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
87 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
88 | 0 | "%s: unable to clear game folder values.", |
89 | 0 | function ); |
90 | |
|
91 | 0 | goto on_error; |
92 | 0 | } |
93 | 0 | return( 1 ); |
94 | | |
95 | 0 | on_error: |
96 | 0 | if( *game_folder_values != NULL ) |
97 | 0 | { |
98 | 0 | memory_free( |
99 | 0 | *game_folder_values ); |
100 | |
|
101 | 0 | *game_folder_values = NULL; |
102 | 0 | } |
103 | 0 | return( -1 ); |
104 | 0 | } |
105 | | |
106 | | /* Frees game folder values |
107 | | * Returns 1 if successful or -1 on error |
108 | | */ |
109 | | int libfwsi_game_folder_values_free( |
110 | | libfwsi_game_folder_values_t **game_folder_values, |
111 | | libcerror_error_t **error ) |
112 | 0 | { |
113 | 0 | static char *function = "libfwsi_game_folder_values_free"; |
114 | |
|
115 | 0 | if( game_folder_values == 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 game folder values.", |
122 | 0 | function ); |
123 | |
|
124 | 0 | return( -1 ); |
125 | 0 | } |
126 | 0 | if( *game_folder_values != NULL ) |
127 | 0 | { |
128 | 0 | memory_free( |
129 | 0 | *game_folder_values ); |
130 | |
|
131 | 0 | *game_folder_values = NULL; |
132 | 0 | } |
133 | 0 | return( 1 ); |
134 | 0 | } |
135 | | |
136 | | /* Reads the game folder values |
137 | | * Returns 1 if successful, 0 if not supported or -1 on error |
138 | | */ |
139 | | int libfwsi_game_folder_values_read_data( |
140 | | libfwsi_game_folder_values_t *game_folder_values, |
141 | | const uint8_t *data, |
142 | | size_t data_size, |
143 | | libcerror_error_t **error ) |
144 | 0 | { |
145 | 0 | static char *function = "libfwsi_game_folder_values_read_data"; |
146 | |
|
147 | | #if defined( HAVE_DEBUG_OUTPUT ) |
148 | | uint64_t value_64bit = 0; |
149 | | #endif |
150 | |
|
151 | 0 | if( game_folder_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 game folder 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 < 32 ) |
187 | 0 | { |
188 | 0 | return( 0 ); |
189 | 0 | } |
190 | | /* Do not try to parse unsupported shell item signatures |
191 | | */ |
192 | 0 | if( memory_compare( |
193 | 0 | &( data[ 4 ] ), |
194 | 0 | "GFSI", |
195 | 0 | 4 ) != 0 ) |
196 | 0 | { |
197 | 0 | return( 0 ); |
198 | 0 | } |
199 | | #if defined( HAVE_DEBUG_OUTPUT ) |
200 | | if( libcnotify_verbose != 0 ) |
201 | | { |
202 | | libcnotify_printf( |
203 | | "%s: class type indicator\t\t\t: 0x%02" PRIx8 "\n", |
204 | | function, |
205 | | data[ 2 ] ); |
206 | | |
207 | | libcnotify_printf( |
208 | | "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", |
209 | | function, |
210 | | data[ 3 ] ); |
211 | | |
212 | | libcnotify_printf( |
213 | | "%s: signature\t\t\t\t: %c%c%c%c\n", |
214 | | function, |
215 | | data[ 4 ], |
216 | | data[ 5 ], |
217 | | data[ 6 ], |
218 | | data[ 7 ] ); |
219 | | |
220 | | if( libfwsi_debug_print_guid_value( |
221 | | function, |
222 | | "class identifier\t\t\t", |
223 | | &( data[ 8 ] ), |
224 | | 16, |
225 | | LIBFGUID_ENDIAN_LITTLE, |
226 | | LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, |
227 | | error ) != 1 ) |
228 | | { |
229 | | libcerror_error_set( |
230 | | error, |
231 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
232 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
233 | | "%s: unable to print GUID value.", |
234 | | function ); |
235 | | |
236 | | return( -1 ); |
237 | | } |
238 | | byte_stream_copy_to_uint64_little_endian( |
239 | | &( data[ 24 ] ), |
240 | | value_64bit ); |
241 | | libcnotify_printf( |
242 | | "%s: unknown2\t\t\t\t: 0x%08" PRIx64 "\n", |
243 | | function, |
244 | | value_64bit ); |
245 | | |
246 | | libcnotify_printf( |
247 | | "\n" ); |
248 | | } |
249 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
250 | | |
251 | 0 | return( 1 ); |
252 | 0 | } |
253 | | |