Mercurial > mplayer.hg
annotate loader/registry.c @ 4800:e47b32c0eca8
discovered what appears to be another valid FLI frame magic number
author | melanson |
---|---|
date | Fri, 22 Feb 2002 03:41:19 +0000 |
parents | a1d27234018f |
children | 174e2a58b4cd |
rev | line source |
---|---|
3465 | 1 #include "config.h" |
1 | 2 |
3 #include <stdio.h> | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
4 #include <stdlib.h> |
1 | 5 #include <fcntl.h> |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
6 #include <unistd.h> |
1 | 7 #include <pwd.h> |
8 #include <sys/types.h> | |
9 | |
10 #include <wine/winbase.h> | |
11 #include <wine/winreg.h> | |
12 #include <wine/winnt.h> | |
13 #include <wine/winerror.h> | |
14 | |
3465 | 15 #include "ext.h" |
16 #include "registry.h" | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
17 |
128 | 18 //#undef TRACE |
19 //#define TRACE printf | |
3128 | 20 |
4384 | 21 extern char *get_path ( char * ); |
3134 | 22 |
4384 | 23 // ...can be set before init_registry() call |
24 char* regpathname = NULL; | |
3134 | 25 |
4384 | 26 static char* localregpathname = NULL; |
3134 | 27 |
28 typedef struct reg_handle_s | |
29 { | |
30 int handle; | |
31 char* name; | |
32 struct reg_handle_s* next; | |
33 struct reg_handle_s* prev; | |
34 } reg_handle_t; | |
35 | |
1 | 36 struct reg_value |
37 { | |
38 int type; | |
39 char* name; | |
40 int len; | |
41 char* value; | |
42 }; | |
43 | |
3134 | 44 static struct reg_value* regs = NULL; |
45 static int reg_size; | |
46 static reg_handle_t* head = NULL; | |
1 | 47 |
48 #define DIR -25 | |
49 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
50 static void create_registry(void); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
51 static void open_registry(void); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
52 static void save_registry(void); |
3128 | 53 static void init_registry(void); |
1 | 54 |
55 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
56 static void create_registry(void){ |
1 | 57 if(regs) |
58 { | |
59 printf("Logic error: create_registry() called with existing registry\n"); | |
60 save_registry(); | |
61 return; | |
3128 | 62 } |
1 | 63 regs=(struct reg_value*)malloc(3*sizeof(struct reg_value)); |
64 regs[0].type=regs[1].type=DIR; | |
65 regs[0].name=(char*)malloc(5); | |
66 strcpy(regs[0].name, "HKLM"); | |
67 regs[1].name=(char*)malloc(5); | |
68 strcpy(regs[1].name, "HKCU"); | |
69 regs[0].value=regs[1].value=NULL; | |
70 regs[0].len=regs[1].len=0; | |
71 reg_size=2; | |
3134 | 72 head = 0; |
1 | 73 save_registry(); |
74 } | |
3134 | 75 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
76 static void open_registry(void) |
1 | 77 { |
78 int fd; | |
79 int i; | |
3128 | 80 unsigned int len; |
1 | 81 if(regs) |
82 { | |
83 printf("Multiple open_registry(>\n"); | |
84 return; | |
85 } | |
3134 | 86 fd = open(localregpathname, O_RDONLY); |
3128 | 87 if (fd == -1) |
1 | 88 { |
89 printf("Creating new registry\n"); | |
90 create_registry(); | |
91 return; | |
3128 | 92 } |
1 | 93 read(fd, ®_size, 4); |
94 regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value)); | |
3134 | 95 head = 0; |
1 | 96 for(i=0; i<reg_size; i++) |
97 { | |
98 read(fd,®s[i].type,4); | |
99 read(fd,&len,4); | |
100 regs[i].name=(char*)malloc(len+1); | |
101 if(regs[i].name==0) | |
102 { | |
103 reg_size=i+1; | |
104 goto error; | |
105 } | |
106 read(fd, regs[i].name, len); | |
107 regs[i].name[len]=0; | |
108 read(fd,®s[i].len,4); | |
109 regs[i].value=(char*)malloc(regs[i].len+1); | |
110 if(regs[i].value==0) | |
111 { | |
3134 | 112 free(regs[i].name); |
1 | 113 reg_size=i+1; |
114 goto error; | |
115 } | |
116 read(fd, regs[i].value, regs[i].len); | |
117 regs[i].value[regs[i].len]=0; | |
118 } | |
119 error: | |
120 close(fd); | |
121 return; | |
122 } | |
123 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
124 static void save_registry(void) |
1 | 125 { |
3128 | 126 int fd, i; |
127 if (!regs) | |
128 init_registry(); | |
3134 | 129 fd = open(localregpathname, O_WRONLY | O_CREAT, 00666); |
3128 | 130 if (fd == -1) |
1 | 131 { |
3128 | 132 printf("Failed to open registry file '%s' for writing.\n", |
3134 | 133 localregpathname); |
3128 | 134 return; |
1 | 135 } |
136 write(fd, ®_size, 4); | |
137 for(i=0; i<reg_size; i++) | |
138 { | |
3128 | 139 unsigned len=strlen(regs[i].name); |
1 | 140 write(fd, ®s[i].type, 4); |
141 write(fd, &len, 4); | |
142 write(fd, regs[i].name, len); | |
143 write(fd, ®s[i].len, 4); | |
144 write(fd, regs[i].value, regs[i].len); | |
145 } | |
146 close(fd); | |
147 } | |
3134 | 148 |
149 void free_registry(void) | |
150 { | |
151 reg_handle_t* t = head; | |
152 while (t) | |
153 { | |
154 reg_handle_t* f = t; | |
155 if (t->name) | |
156 free(t->name); | |
157 t=t->prev; | |
158 free(f); | |
159 } | |
160 head = 0; | |
161 if (regs) | |
162 { | |
163 int i; | |
164 for(i=0; i<reg_size; i++) | |
165 { | |
166 free(regs[i].name); | |
167 free(regs[i].value); | |
168 } | |
169 free(regs); | |
170 regs = 0; | |
171 } | |
3465 | 172 |
173 if (localregpathname && localregpathname != regpathname) | |
3134 | 174 free(localregpathname); |
3465 | 175 localregpathname = 0; |
3134 | 176 } |
177 | |
178 | |
1 | 179 static reg_handle_t* find_handle_by_name(const char* name) |
180 { | |
181 reg_handle_t* t; | |
182 for(t=head; t; t=t->prev) | |
183 { | |
184 if(!strcmp(t->name, name)) | |
185 { | |
186 return t; | |
187 } | |
188 } | |
189 return 0; | |
190 } | |
191 static struct reg_value* find_value_by_name(const char* name) | |
192 { | |
193 int i; | |
194 for(i=0; i<reg_size; i++) | |
195 if(!strcmp(regs[i].name, name)) | |
196 return regs+i; | |
197 return 0; | |
198 } | |
199 static reg_handle_t* find_handle(int handle) | |
200 { | |
201 reg_handle_t* t; | |
202 for(t=head; t; t=t->prev) | |
203 { | |
204 if(t->handle==handle) | |
205 { | |
206 return t; | |
207 } | |
208 } | |
209 return 0; | |
3128 | 210 } |
1 | 211 static int generate_handle() |
212 { | |
213 static int zz=249; | |
214 zz++; | |
215 while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER)) | |
216 zz++; | |
217 return zz; | |
218 } | |
219 | |
220 static reg_handle_t* insert_handle(long handle, const char* name) | |
221 { | |
222 reg_handle_t* t; | |
223 t=(reg_handle_t*)malloc(sizeof(reg_handle_t)); | |
224 if(head==0) | |
225 { | |
226 t->prev=0; | |
227 } | |
228 else | |
229 { | |
230 head->next=t; | |
231 t->prev=head; | |
232 } | |
233 t->next=0; | |
234 t->name=(char*)malloc(strlen(name)+1); | |
235 strcpy(t->name, name); | |
236 t->handle=handle; | |
237 head=t; | |
238 return t; | |
239 } | |
240 static char* build_keyname(long key, const char* subkey) | |
241 { | |
242 char* full_name; | |
243 reg_handle_t* t; | |
244 if((t=find_handle(key))==0) | |
245 { | |
246 TRACE("Invalid key\n"); | |
247 return NULL; | |
248 } | |
249 if(subkey==NULL) | |
250 subkey="<default>"; | |
251 full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); | |
252 strcpy(full_name, t->name); | |
253 strcat(full_name, "\\"); | |
254 strcat(full_name, subkey); | |
255 return full_name; | |
256 } | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
257 static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len) |
1 | 258 { |
259 reg_handle_t* t; | |
260 struct reg_value* v; | |
261 char* fullname; | |
262 if((fullname=build_keyname(handle, name))==NULL) | |
263 { | |
264 TRACE("Invalid handle\n"); | |
265 return NULL; | |
266 } | |
267 | |
268 if((v=find_value_by_name(fullname))==0) | |
269 //creating new value in registry | |
270 { | |
271 if(regs==0) | |
272 create_registry(); | |
273 regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1)); | |
3134 | 274 //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1)); |
1 | 275 v=regs+reg_size; |
276 reg_size++; | |
277 } | |
278 else | |
279 //replacing old one | |
280 { | |
3134 | 281 free(v->value); |
282 free(v->name); | |
1 | 283 } |
284 v->type=type; | |
285 v->len=len; | |
286 v->value=(char*)malloc(len); | |
287 memcpy(v->value, value, len); | |
288 v->name=(char*)malloc(strlen(fullname)+1); | |
289 strcpy(v->name, fullname); | |
3134 | 290 free(fullname); |
1 | 291 save_registry(); |
292 return v; | |
293 } | |
294 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
340
diff
changeset
|
295 static void init_registry(void) |
1 | 296 { |
3128 | 297 TRACE("Initializing registry\n"); |
298 // can't be free-ed - it's static and probably thread | |
299 // unsafe structure which is stored in glibc | |
300 | |
3465 | 301 #ifdef MPLAYER |
302 regpathname = get_path("registry"); | |
303 localregpathname = regpathname; | |
3128 | 304 #else |
3465 | 305 // regpathname is an external pointer |
306 // | |
307 // registry.c is holding it's own internal pointer | |
308 // localregpathname - which is being allocate/deallocated | |
309 | |
3134 | 310 if (localregpathname == 0) |
3128 | 311 { |
3134 | 312 const char* pthn = regpathname; |
313 if (!regpathname) | |
314 { | |
3465 | 315 // avifile - for now reading data from user's home |
3134 | 316 struct passwd* pwent; |
317 pwent = getpwuid(geteuid()); | |
318 pthn = pwent->pw_dir; | |
319 } | |
320 | |
321 localregpathname = (char*)malloc(strlen(pthn)+20); | |
322 strcpy(localregpathname, pthn); | |
323 strcat(localregpathname, "/.registry"); | |
3128 | 324 } |
340 | 325 #endif |
3128 | 326 |
1 | 327 open_registry(); |
328 insert_handle(HKEY_LOCAL_MACHINE, "HKLM"); | |
329 insert_handle(HKEY_CURRENT_USER, "HKCU"); | |
330 } | |
3128 | 331 |
1 | 332 static reg_handle_t* find_handle_2(long key, const char* subkey) |
333 { | |
334 char* full_name; | |
335 reg_handle_t* t; | |
336 if((t=find_handle(key))==0) | |
337 { | |
338 TRACE("Invalid key\n"); | |
339 return (reg_handle_t*)-1; | |
340 } | |
341 if(subkey==NULL) | |
342 return t; | |
343 full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10); | |
344 strcpy(full_name, t->name); | |
345 strcat(full_name, "\\"); | |
346 strcat(full_name, subkey); | |
347 t=find_handle_by_name(full_name); | |
348 free(full_name); | |
349 return t; | |
350 } | |
351 | |
352 long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey) | |
353 { | |
354 char* full_name; | |
355 reg_handle_t* t; | |
356 struct reg_value* v; | |
357 TRACE("Opening key %s\n", subkey); | |
3128 | 358 |
1 | 359 if(!regs) |
360 init_registry() | |
3128 | 361 ; |
1 | 362 /* t=find_handle_2(key, subkey); |
3128 | 363 |
1 | 364 if(t==0) |
365 return -1; | |
366 | |
367 if(t==(reg_handle_t*)-1) | |
368 return -1; | |
3128 | 369 */ |
370 full_name=build_keyname(key, subkey); | |
1 | 371 if(!full_name) |
372 return -1; | |
3128 | 373 TRACE("Opening key Fullname %s\n", full_name); |
374 v=find_value_by_name(full_name); | |
1 | 375 |
376 t=insert_handle(generate_handle(), full_name); | |
377 *newkey=t->handle; | |
378 free(full_name); | |
3128 | 379 |
1 | 380 return 0; |
3128 | 381 } |
1 | 382 long RegCloseKey(long key) |
383 { | |
384 reg_handle_t *handle; | |
385 if(key==HKEY_LOCAL_MACHINE) | |
386 return 0; | |
387 if(key==HKEY_CURRENT_USER) | |
388 return 0; | |
389 handle=find_handle(key); | |
390 if(handle==0) | |
391 return 0; | |
392 if(handle->prev) | |
393 handle->prev->next=handle->next; | |
394 if(handle->next) | |
395 handle->next->prev=handle->prev; | |
396 if(handle->name) | |
397 free(handle->name); | |
398 if(handle==head) | |
399 head=head->prev; | |
400 free(handle); | |
401 return 1; | |
3128 | 402 } |
403 | |
1 | 404 long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count) |
405 { | |
406 struct reg_value* t; | |
407 char* c; | |
408 TRACE("Querying value %s\n", value); | |
409 if(!regs) | |
3465 | 410 init_registry(); |
411 | |
3128 | 412 c=build_keyname(key, value); |
1 | 413 if(c==NULL) |
3134 | 414 return 1; |
415 t=find_value_by_name(c); | |
416 free(c); | |
417 if(t==0) | |
1 | 418 return 2; |
419 if(type) | |
420 *type=t->type; | |
421 if(data) | |
422 { | |
423 memcpy(data, t->value, (t->len<*count)?t->len:*count); | |
424 TRACE("returning %d bytes: %d\n", t->len, *(int*)data); | |
3128 | 425 } |
1 | 426 if(*count<t->len) |
427 { | |
428 *count=t->len; | |
429 return ERROR_MORE_DATA; | |
430 } | |
431 else | |
432 { | |
433 *count=t->len; | |
434 } | |
435 return 0; | |
3128 | 436 } |
1 | 437 long RegCreateKeyExA(long key, const char* name, long reserved, |
3128 | 438 void* classs, long options, long security, |
439 void* sec_attr, int* newkey, int* status) | |
1 | 440 { |
441 reg_handle_t* t; | |
442 char* fullname; | |
443 struct reg_value* v; | |
444 // TRACE("Creating/Opening key %s\n", name); | |
445 TRACE("Creating/Opening key %s\n", name); | |
446 if(!regs) | |
3465 | 447 init_registry(); |
448 | |
1 | 449 fullname=build_keyname(key, name); |
450 if(fullname==NULL) | |
451 return 1; | |
452 v=find_value_by_name(fullname); | |
453 if(v==0) | |
454 { | |
455 int qw=45708; | |
456 v=insert_reg_value(key, name, DIR, &qw, 4); | |
128 | 457 if (status) *status=REG_CREATED_NEW_KEY; |
1 | 458 // return 0; |
459 } | |
460 | |
461 t=insert_handle(generate_handle(), fullname); | |
462 *newkey=t->handle; | |
463 free(fullname); | |
464 return 0; | |
465 } | |
1416 | 466 |
3128 | 467 /* |
468 LONG RegEnumValue( | |
469 HKEY hKey, // handle to key to query | |
470 DWORD dwIndex, // index of value to query | |
471 LPTSTR lpValueName, // address of buffer for value string | |
472 LPDWORD lpcbValueName, // address for size of value buffer | |
473 LPDWORD lpReserved, // reserved | |
474 LPDWORD lpType, // address of buffer for type code | |
475 LPBYTE lpData, // address of buffer for value data | |
476 LPDWORD lpcbData // address for size of data buffer | |
477 ); | |
478 */ | |
479 | |
1416 | 480 long RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count, |
481 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count) | |
482 { | |
3128 | 483 // currenly just made to support MSZH & ZLIB |
484 //printf("Reg Enum 0x%x %d %s %d data: %p %d %d >%s<\n", hkey, index, | |
485 // value, *val_count, data, *count, reg_size, data); | |
486 reg_handle_t* t = find_handle(hkey); | |
487 if (t && index < 10) | |
1416 | 488 { |
3128 | 489 struct reg_value* v=find_value_by_name(t->name); |
490 if (v) | |
1416 | 491 { |
3128 | 492 memcpy(data, v->value, (v->len < *count) ? v->len : *count); |
493 if(*count < v->len) | |
494 *count = v->len; | |
495 if (type) | |
1416 | 496 *type = v->type; |
497 //printf("Found handle %s\n", v->name); | |
3128 | 498 return 0; |
1416 | 499 } |
500 } | |
3128 | 501 return ERROR_NO_MORE_ITEMS; |
1416 | 502 } |
503 | |
1 | 504 long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size) |
505 { | |
506 struct reg_value* t; | |
507 char* c; | |
508 TRACE("Request to set value %s\n", name); | |
509 if(!regs) | |
3465 | 510 init_registry(); |
511 | |
1 | 512 c=build_keyname(key, name); |
513 if(c==NULL) | |
514 return 1; | |
515 insert_reg_value(key, name, v2, data, size); | |
516 free(c); | |
517 return 0; | |
3128 | 518 } |
3465 | 519 |
520 long RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName, | |
521 LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass, | |
522 LPFILETIME lpftLastWriteTime) | |
523 { | |
524 return ERROR_NO_MORE_ITEMS; | |
525 } |