Debian Codegraph @

hive.c

raw symbols SCIP
1 /* Hive.c
2 Hive file access, pretty lame and bugged but do the work O_o
3 Thanks to B.D. for file structure info
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 This program is released under the GPL with the additional exemption
20 that compiling, linking, and/or using OpenSSL is allowed.
21
22 Copyright (C) 2004-2006 Nicola Cuomo <[email protected]>
23 Improvments and some bugs fixes by Objectif Securité
24 <http://www.objectif-securite.ch>
25 */
26
27 #include <sys/param.h>
28 #include "hive.h"cxx . . $ `<file>/hive.h`/
29
30 #ifdef BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`!
31 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
32 #elif BYTE_ORDER == BIG_ENDIAN
33 #include <byteswap.h>
34 #else
35 #warning "Doesn't define a standard ENDIAN type"
36 #endif
37 #else
38 #warning "Doesn't define BYTE_ORDER"
39 #endif
40
41
42 nk_hdrcxx . . $ nk_hdr#* read_nkcxx . . $ read_nk(2316082a77336704).(nk_hdrcxx . . $ nk_hdr# *nk, struct hivecxx . . $ hive# *h, int offset ) {
43 memcpycxx . . $ memcpy(cc817cb175f282d).(nk, h->basecxx . . $ hive#base.+offset+4, sizeof(nk_hdrcxx . . $ nk_hdr#));
44 nk->key_namecxx . . $ _nk_hdr#key_name. = (h->basecxx . . $ hive#base.+offset+4+76);
45 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
46 #elif BYTE_ORDER == BIG_ENDIAN
47 nk->id = __bswap_16(nk->id);
48 nk->type = __bswap_16(nk->type);
49 nk->name_len = __bswap_16(nk->name_len);
50 nk->classname_len = __bswap_16(nk->classname_len);
51 nk->classname_off = __bswap_32(nk->classname_off);
52 nk->unk2 = __bswap_32(nk->unk2);
53 nk->lf_off = __bswap_32(nk->lf_off);
54 nk->value_cnt = __bswap_32(nk->value_cnt);
55 nk->value_off = __bswap_32(nk->value_off);
56 nk->subkey_num = __bswap_32(nk->subkey_num);
57 #endif
58 return nk;
59 }
60
61 lf_hdrcxx . . $ lf_hdr#* read_lfcxx . . $ read_lf(85bb1d927174c2d).(lf_hdrcxx . . $ lf_hdr# *lf, struct hivecxx . . $ hive# *h, int offset ) {
62 memcpycxx . . $ memcpy(cc817cb175f282d).(lf, h->basecxx . . $ hive#base.+offset+4, sizeof(lf_hdrcxx . . $ lf_hdr#));
63 lf->hrcxx . . $ _lf_hdr#hr. = (h->basecxx . . $ hive#base.+offset+4+4);
64 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
65 #elif BYTE_ORDER == BIG_ENDIAN
66 lf->id = __bswap_16(lf->id);
67 lf->key_num = __bswap_16(lf->key_num);
68 #endif
69 return lf;
70 }
71
72 vk_hdrcxx . . $ vk_hdr#* read_vkcxx . . $ read_vk(fd4df586ea07da97).(vk_hdrcxx . . $ vk_hdr# *vk, struct hivecxx . . $ hive# *h, int offset ) {
73 memcpycxx . . $ memcpy(cc817cb175f282d).(vk, h->basecxx . . $ hive#base.+offset+4, sizeof(vk_hdrcxx . . $ vk_hdr#));
74 vk->value_namecxx . . $ _vk_hdr#value_name. = (h->basecxx . . $ hive#base.+offset+4+20);
75 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
76 #elif BYTE_ORDER == BIG_ENDIAN
77 vk->id = __bswap_16(vk->id);
78 vk->name_len = __bswap_16(vk->name_len);
79 vk->flag = __bswap_16(vk->flag);
80 vk->data_len = __bswap_32(vk->data_len);
81 vk->data_off = __bswap_32(vk->data_off);
82 vk->data_type = __bswap_32(vk->data_type);
83 #endif
84 return vk;
85 }
86
87 int* read_valuelistcxx . . $ read_valuelist(2621c5b1afd2e82b).(int *value, struct hivecxx . . $ hive# *h, int offset, int size ){
88 memcpycxx . . $ memcpy(cc817cb175f282d).(value, h->basecxx . . $ hive#base.+offset+4, size*sizeof(int));
89 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
90 #elif BYTE_ORDER == BIG_ENDIAN
91 int i;
92 for (i=0; i<size; i++)
93 value[i] = __bswap_32(value[i]);
94 #endif
95 return value;
96 }
97
98 hashrecordcxx . . $ hashrecord#* read_hrcxx . . $ read_hr(9bbfcf56ed6c0170).(hashrecordcxx . . $ hashrecord# *hr, unsigned char *pos, int index ) {
99 pos+=(8*index);
100 memcpycxx . . $ memcpy(cc817cb175f282d).(hr, pos, sizeof(hashrecordcxx . . $ hashrecord#));
101 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
102 #elif BYTE_ORDER == BIG_ENDIAN
103 hr->nk_offset = __bswap_32(hr->nk_offset);
104 #endif
105 return hr;
106 }
107
108
109 unsigned char* read_datacxx . . $ read_data(c27d5f014b3fecf5).(struct hivecxx . . $ hive# *h, int offset ) {
110 return ( (unsigned char*) (h->basecxx . . $ hive#base. + offset + 4) );
111 }
112
113
114 void _RegCloseHivecxx . . $ _RegCloseHive(75e6f13f219d000f).( struct hivecxx . . $ hive# *h ) {
115 if( h->basecxx . . $ hive#base. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! )
116 freecxx . . $ free(5d22bdacc48458e8).( h->basecxx . . $ hive#base. );
117 return;
118 }
119
120 void _InitHivecxx . . $ _InitHive(75e6f13f219d000f).( struct hivecxx . . $ hive# *h ) {
121 h->basecxx . . $ hive#base. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
122 return;
123 }
124
125 int _RegOpenHivecxx . . $ _RegOpenHive(84cbfd8c19656c97).( unsigned char *filename, struct hivecxx . . $ hive# *h ) {
126 FILEcxx . . $ FILE# *hiveh;
127 unsigned long hsize;
128
129 /* Prova ad aprire l'hive */
130 if( ( hiveh = fopencxx . . $ fopen(82ec0787cd37e0a3).((char *) filename, "rb" ) ) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) {
131 if( fseekcxx . . $ fseek(543fae30d249f6b1).( hiveh, 0, SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:112:9`! ) == 0 ) {
132 hsize = ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).( hiveh );
133
134 /* Legge il file in memoria */
135 /* MMF ??? -_- */
136 h->basecxx . . $ hive#base. = (unsigned char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).( hsize );
137
138 fseekcxx . . $ fseek(543fae30d249f6b1).( hiveh, 0, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`! );
139
140 if( freadcxx . . $ fread(738fc8ac1d711e58).( (void *) h->basecxx . . $ hive#base., hsize, 1, hiveh ) == 1 ){
141 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
142 if( *((int*)h->basecxx . . $ hive#base.) == 0x66676572 ) {
143 fclosecxx . . $ fclose(89bc1efcdac0ca22).( hiveh );
144 return 0;
145 }
146 #elif BYTE_ORDER == BIG_ENDIAN
147 if( *((int*)h->base) == __bswap_32( 0x66676572)) {
148 fclose( hiveh );
149 return 0;
150 }
151 #endif
152 }
153 }
154 fclosecxx . . $ fclose(89bc1efcdac0ca22).( hiveh );
155 }
156 return -1;
157 }
158
159 int _RegOpenHiveBuffercxx . . $ _RegOpenHiveBuffer(94d6b6e0be58d039).( unsigned char *buffer, unsigned long size, struct hivecxx . . $ hive# *h ) {
160
161 h->basecxx . . $ hive#base. = (unsigned char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).( size );
162 memcpycxx . . $ memcpy(cc817cb175f282d).(h->basecxx . . $ hive#base., buffer, size);
163 #if BYTE_ORDERcxx . . $ `<external>/15855202785537844739/endian.h:30:10`! == LITTLE_ENDIANcxx . . $ `<external>/15855202785537844739/endian.h:27:10`!
164 if( *((int*)h->basecxx . . $ hive#base.) == 0x66676572 )
165 return 0;
166 #elif BYTE_ORDER == BIG_ENDIAN
167 if( *((int*)h->base) == __bswap_32( 0x66676572))
168 return 0;
169 #endif
170 return -1;
171 }
172
173 long parselfcxx . . $ parself(fede0aacf5ae7045).( struct hivecxx . . $ hive# *h, char *t, unsigned long off ) {
174 nk_hdrcxx . . $ nk_hdr# *n;
175 lf_hdrcxx . . $ lf_hdr# *l;
176 hashrecordcxx . . $ hashrecord# *hr;
177 long res;
178
179 int i;
180
181 hr = (hashrecordcxx . . $ hashrecord#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(hashrecordcxx . . $ hashrecord#));
182 n = (nk_hdrcxx . . $ nk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(nk_hdrcxx . . $ nk_hdr#));
183 l = (lf_hdrcxx . . $ lf_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(lf_hdrcxx . . $ lf_hdr#));
184 l = read_lfcxx . . $ read_lf(85bb1d927174c2d).(l, h, off );
185 #ifdef DEBUG
186 printf("off = %x, key_num = %d ", off, l->key_num);
187 #endif
188
189 for( i = 0; i < l->key_numcxx . . $ _lf_hdr#key_num.; i++ ){
190 hr = read_hrcxx . . $ read_hr(9bbfcf56ed6c0170).(hr, l->hrcxx . . $ _lf_hdr#hr., i);
191 n = read_nkcxx . . $ read_nk(2316082a77336704).(n, h, hr->nk_offsetcxx . . $ _hashrecord#nk_offset. + 0x1000 );
192 #ifdef DEBUG
193 printf("/ i=%d/%d, keyname = %x, nk_offset = %x\n", i, l->key_num, hr->keyname, hr->nk_offset);
194 printf("//t = %s, keyname = %s, len = %d\n", t, strndup(n->key_name, n->name_len), n->name_len);
195 #endif
196 if( !memcmpcxx . . $ memcmp(36f949851efa3055).( t, n->key_namecxx . . $ _nk_hdr#key_name., n->name_lencxx . . $ _nk_hdr#name_len. ) && (strlencxx . . $ strlen(751346f8406fd082).(t) == n->name_lencxx . . $ _nk_hdr#name_len.)) {
197 res = hr->nk_offsetcxx . . $ _hashrecord#nk_offset.;
198 freecxx . . $ free(5d22bdacc48458e8).(n);
199 freecxx . . $ free(5d22bdacc48458e8).(l);
200 return res;
201 }
202 }
203 freecxx . . $ free(5d22bdacc48458e8).(n);
204 freecxx . . $ free(5d22bdacc48458e8).(l);
205 return -1;
206 }
207
208 int _RegGetRootKeycxx . . $ _RegGetRootKey(3d851ed2cd37585f).(struct hivecxx . . $ hive# *h, char **root_key) {
209 nk_hdrcxx . . $ nk_hdr# *n;
210
211 n = (nk_hdrcxx . . $ nk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(nk_hdrcxx . . $ nk_hdr#));
212 n = read_nkcxx . . $ read_nk(2316082a77336704).(n, h, 0x1020);
213
214 #ifdef DEBUG
215 printf("id = %x type = %x name_len = %d\n", n->id, n->type, n->name_len);
216 #endif
217
218 if ( n->idcxx . . $ _nk_hdr#id. == NK_IDcxx . . $ `hive.h:36:9`! && n->typecxx . . $ _nk_hdr#type. == NK_ROOTcxx . . $ `hive.h:37:9`! ) {
219 *root_key = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(n->name_lencxx . . $ _nk_hdr#name_len.+1);
220 strncpycxx . . $ strncpy(255158a415b673b0).(*root_key, (char*)n->key_namecxx . . $ _nk_hdr#key_name., n->name_lencxx . . $ _nk_hdr#name_len.);
221 (*root_key)[n->name_lencxx . . $ _nk_hdr#name_len.] = 0;
222 freecxx . . $ free(5d22bdacc48458e8).(n);
223 return 0;
224 }
225 freecxx . . $ free(5d22bdacc48458e8).(n);
226 return -1;
227 }
228
229 int _RegOpenKeycxx . . $ _RegOpenKey(31ebb3f0ca3e6396).( struct hivecxx . . $ hive# *h, char *path, nk_hdrcxx . . $ nk_hdr# **nr ) {
230 nk_hdrcxx . . $ nk_hdr# *n;
231 char *t, *tpath;
232 unsigned long noff;
233
234 n = (nk_hdrcxx . . $ nk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(nk_hdrcxx . . $ nk_hdr#));
235 n = read_nkcxx . . $ read_nk(2316082a77336704).(n, h, 0x1020 );
236
237 #ifdef DEBUG
238 printf("id = %x type = %x\n", n->id, n->type);
239 #endif
240 if( n->idcxx . . $ _nk_hdr#id. == NK_IDcxx . . $ `hive.h:36:9`! && n->typecxx . . $ _nk_hdr#type. == NK_ROOTcxx . . $ `hive.h:37:9`! ) {
241 tpath = strdupcxx . . $ strdup(a8b8e32347182212).( path );
242 t = strtokcxx . . $ strtok(b7b3a83273496486).( tpath, "\\" );
243 #ifdef DEBUG
244 printf("1 %s\n", t);
245 #endif
246 if( !memcmpcxx . . $ memcmp(36f949851efa3055).( t, n->key_namecxx . . $ _nk_hdr#key_name., n->name_lencxx . . $ _nk_hdr#name_len. ) ) {
247 t = strtokcxx . . $ strtok(b7b3a83273496486).( NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "\\" );
248 #ifdef DEBUG
249 printf("2 %s %x %x\n", t, n->unk2, n->lf_off);
250 #endif
251 while( t != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) {
252 if( ( noff = parselfcxx . . $ parself(fede0aacf5ae7045).( h, t, n->lf_offcxx . . $ _nk_hdr#lf_off. + 0x1000 ) ) == -1 ){
253 freecxx . . $ free(5d22bdacc48458e8).(n);
254 return -1;
255 }
256 n = read_nkcxx . . $ read_nk(2316082a77336704).(n, h, noff + 0x1000 );
257 t = strtokcxx . . $ strtok(b7b3a83273496486).( NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "\\" );
258 #ifdef DEBUG
259 printf("t = %s, noff = %x\n", t, noff);
260 #endif
261 }
262 memcpycxx . . $ memcpy(cc817cb175f282d).(*nr, n, sizeof(nk_hdrcxx . . $ nk_hdr#));
263 freecxx . . $ free(5d22bdacc48458e8).(n);
264 return 0;
265 }
266 freecxx . . $ free(5d22bdacc48458e8).( tpath );
267 }
268 freecxx . . $ free(5d22bdacc48458e8).(n);
269 return -1;
270 }
271
272 int _RegQueryValuecxx . . $ _RegQueryValue(9d8dfe56b004a603).( struct hivecxx . . $ hive# *h, char *name, nk_hdrcxx . . $ nk_hdr# *nr, unsigned char **buff, int *len ) {
273 vk_hdrcxx . . $ vk_hdr# *v;
274 unsigned int i;
275 int *l;
276 #ifdef DEBUG
277 int j;
278 #endif
279
280 v = (vk_hdrcxx . . $ vk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(vk_hdrcxx . . $ vk_hdr#));
281 l = (int*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int)*nr->value_cntcxx . . $ _nk_hdr#value_cnt.);
282 l = read_valuelistcxx . . $ read_valuelist(2621c5b1afd2e82b).(l, h, nr->value_offcxx . . $ _nk_hdr#value_off. + 0x1000, nr->value_cntcxx . . $ _nk_hdr#value_cnt.);
283
284 *len = 0;
285
286 for( i = 0; i < nr->value_cntcxx . . $ _nk_hdr#value_cnt.; i++ ) {
287 v = read_vkcxx . . $ read_vk(fd4df586ea07da97).(v, h, l[i] + 0x1000 );
288 if( !memcmpcxx . . $ memcmp(36f949851efa3055).( name, v->value_namecxx . . $ _vk_hdr#value_name., strlencxx . . $ strlen(751346f8406fd082).( name ) ) || (name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && ( v->flagcxx . . $ _vk_hdr#flag. & 1 ) == 0 ) ) {
289 #ifdef DEBUG
290 printf("%s len=%x &off=%x off=%x type=%x\n", v->value_name, v->data_len&0x0000FFFF, &(v->data_off), v->data_off, v->data_type);
291 #endif
292 *len = v->data_lencxx . . $ _vk_hdr#data_len. & 0x0000FFFF;
293 if (*buff!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
294 freecxx . . $ free(5d22bdacc48458e8).(*buff);
295 *buff = (unsigned char*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((*len));
296 if ((*len)< 5 ) {
297 memcpycxx . . $ memcpy(cc817cb175f282d). (*buff, &(v->data_offcxx . . $ _vk_hdr#data_off.), (*len));
298 }
299 else
300 memcpycxx . . $ memcpy(cc817cb175f282d). (*buff, read_datacxx . . $ read_data(c27d5f014b3fecf5).( h, v->data_offcxx . . $ _vk_hdr#data_off. + 0x1000),(*len));
301 #ifdef DEBUG
302 printf("buff = ", (*len));
303 for (j=0; j<(*len); j++)
304 printf("%.2x", (*buff)[j]);
305 printf("\n");
306 #endif
307
308 freecxx . . $ free(5d22bdacc48458e8).(v);
309 return 0;
310 }
311 }
312 freecxx . . $ free(5d22bdacc48458e8).(v);
313 return -1;
314 }
315
316 int _RegEnumKeycxx . . $ _RegEnumKey(12b579c9edc383c3).( struct hivecxx . . $ hive# *h, nk_hdrcxx . . $ nk_hdr# *nr, int index, char *name, int *namelen ) {
317 lf_hdrcxx . . $ lf_hdr# *lf;
318 nk_hdrcxx . . $ nk_hdr# *nk;
319 hashrecordcxx . . $ hashrecord# *hr;
320
321 lf = (lf_hdrcxx . . $ lf_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(lf_hdrcxx . . $ lf_hdr#));
322 nk = (nk_hdrcxx . . $ nk_hdr#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(nk_hdrcxx . . $ nk_hdr#));
323 hr = (hashrecordcxx . . $ hashrecord#*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(hashrecordcxx . . $ hashrecord#));
324 #ifdef DEBUG
325 printf("subkey_num = %d\n", nr->subkey_num);
326 #endif
327
328 if( index < nr->subkey_numcxx . . $ _nk_hdr#subkey_num. ) {
329 lf = read_lfcxx . . $ read_lf(85bb1d927174c2d).(lf, h, nr->lf_offcxx . . $ _nk_hdr#lf_off. + 0x1000 );
330 hr = read_hrcxx . . $ read_hr(9bbfcf56ed6c0170).(hr, lf->hrcxx . . $ _lf_hdr#hr., index);
331 nk = read_nkcxx . . $ read_nk(2316082a77336704).(nk, h, hr->nk_offsetcxx . . $ _hashrecord#nk_offset. + 0x1000 );
332 memcpycxx . . $ memcpy(cc817cb175f282d).( name, nk->key_namecxx . . $ _nk_hdr#key_name., mincxx . . $ `hive.h:34:9`!( *namelen, nk->name_len ) );
333 name[ mincxx . . $ `hive.h:34:9`!( *namelen, nk->name_len ) ] = 0;
334 *namelen = nk->name_lencxx . . $ _nk_hdr#name_len.;
335 freecxx . . $ free(5d22bdacc48458e8).(lf);
336 return ( (index + 1) < nr->subkey_numcxx . . $ _nk_hdr#subkey_num. ) ? (index + 1) : -1;
337 }
338 freecxx . . $ free(5d22bdacc48458e8).(lf);
339 return -1;
340 }