4 * Copyright 1996 Marcus Meissner
5 * Copyright 1998 Matthew Becker
6 * Copyright 1999 Sylvain St-Germain
8 * December 21, 1997 - Kevin Cozens
9 * Fixed bugs in the _w95_loadreg() function. Added extra information
10 * regarding the format of the Windows '95 registry files.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * When changing this file, please re-run the regtest program to ensure
28 * the conditions are handled properly.
33 * Time for RegEnumKey*, RegQueryInfoKey*
37 #include "wine/port.h"
44 #include <sys/types.h>
47 #ifdef HAVE_SYS_MMAN_H
48 # include <sys/mman.h>
55 #include "wine/winbase16.h"
56 #include "wine/server.h"
57 #include "wine/unicode.h"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
65 /* FIXME: following defines should be configured global */
66 #define SAVE_GLOBAL_REGBRANCH_USER_DEFAULT ETCDIR"/wine.userreg"
67 #define SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE ETCDIR"/wine.systemreg"
69 /* relative in ~user/.wine/ : */
70 #define SAVE_LOCAL_REGBRANCH_CURRENT_USER "user.reg"
71 #define SAVE_LOCAL_REGBRANCH_USER_DEFAULT "userdef.reg"
72 #define SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE "system.reg"
74 /* _xmalloc [Internal] */
75 static void *_xmalloc( size_t size
)
79 res
= malloc (size
? size
: 1);
81 WARN("Virtual memory exhausted.\n");
87 /* _strdupnA [Internal] */
88 static LPSTR
_strdupnA(LPCSTR str
,size_t len
)
92 if (!str
) return NULL
;
93 ret
= _xmalloc( len
+ 1 );
94 memcpy( ret
, str
, len
);
99 /* convert ansi string to unicode [Internal] */
100 static LPWSTR
_strdupnAtoW(LPCSTR strA
,size_t lenA
)
105 if (!strA
) return NULL
;
106 lenW
= MultiByteToWideChar(CP_ACP
,0,strA
,lenA
,NULL
,0);
107 ret
= _xmalloc(lenW
*sizeof(WCHAR
)+sizeof(WCHAR
));
108 MultiByteToWideChar(CP_ACP
,0,strA
,lenA
,ret
,lenW
);
113 /* dump a Unicode string with proper escaping [Internal] */
114 /* FIXME: this code duplicates server/unicode.c */
115 static int _dump_strW(const WCHAR
*str
,size_t len
,FILE *f
,char escape
[2])
117 static const char escapes
[32] = ".......abtnvfr.............e....";
122 for (; len
; str
++, len
--)
124 if (pos
> buffer
+ sizeof(buffer
) - 8)
126 fwrite( buffer
, pos
- buffer
, 1, f
);
127 count
+= pos
- buffer
;
130 if (*str
> 127) /* hex escape */
132 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
133 pos
+= sprintf( pos
, "\\x%04x", *str
);
135 pos
+= sprintf( pos
, "\\x%x", *str
);
138 if (*str
< 32) /* octal or C escape */
140 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
141 if (escapes
[*str
] != '.')
142 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
143 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
144 pos
+= sprintf( pos
, "\\%03o", *str
);
146 pos
+= sprintf( pos
, "\\%o", *str
);
149 if (*str
== '\\' || *str
== escape
[0] || *str
== escape
[1]) *pos
++ = '\\';
152 fwrite( buffer
, pos
- buffer
, 1, f
);
153 count
+= pos
- buffer
;
157 /* convert ansi string to unicode and dump with proper escaping [Internal] */
158 static int _dump_strAtoW(LPCSTR strA
,size_t len
,FILE *f
,char escape
[2])
163 if (strA
== NULL
) return 0;
164 strW
= _strdupnAtoW(strA
,len
);
165 ret
= _dump_strW(strW
,len
,f
,escape
);
171 /* FIXME: this code duplicates server/registry.c */
173 WCHAR
*nameW
; /* value name */
174 int type
; /* value type */
175 size_t len
; /* value data length in bytes */
176 void *data
; /* pointer to value data */
179 /* dump a value to a text file */
180 /* FIXME: this code duplicates server/registry.c */
181 static void _dump_value(struct key_value
*value
,FILE *f
)
185 if (value
->nameW
[0]) {
187 count
= 1 + _dump_strW(value
->nameW
,strlenW(value
->nameW
),f
,"\"\"");
188 count
+= fprintf( f
, "\"=" );
190 else count
= fprintf( f
, "@=" );
192 switch(value
->type
) {
196 if (value
->type
!= REG_SZ
) fprintf( f
, "str(%d):", value
->type
);
198 if (value
->data
) _dump_strW(value
->data
,value
->len
/sizeof(WCHAR
),f
,"\"\"");
202 if (value
->len
== sizeof(DWORD
)) {
204 memcpy( &dw
, value
->data
, sizeof(DWORD
) );
205 fprintf( f
, "dword:%08lx", dw
);
208 /* else fall through */
210 if (value
->type
== REG_BINARY
) count
+= fprintf( f
, "hex:" );
211 else count
+= fprintf( f
, "hex(%x):", value
->type
);
212 for (i
= 0; i
< value
->len
; i
++) {
213 count
+= fprintf( f
, "%02x", *((unsigned char *)value
->data
+ i
) );
214 if (i
< value
->len
-1) {
217 fprintf( f
, "\\\n " );
227 /******************************************************************/
228 /* WINDOWS 31 REGISTRY LOADER, supplied by Tor Sjøwall, tor@sn.no */
230 reghack - windows 3.11 registry data format demo program.
232 The reg.dat file has 3 parts, a header, a table of 8-byte entries that is
233 a combined hash table and tree description, and finally a text table.
235 The header is obvious from the struct header. The taboff1 and taboff2
236 fields are always 0x20, and their usage is unknown.
238 The 8-byte entry table has various entry types.
240 tabent[0] is a root index. The second word has the index of the root of
242 tabent[1..hashsize] is a hash table. The first word in the hash entry is
243 the index of the key/value that has that hash. Data with the same
244 hash value are on a circular list. The other three words in the
245 hash entry are always zero.
246 tabent[hashsize..tabcnt] is the tree structure. There are two kinds of
247 entry: dirent and keyent/valent. They are identified by context.
248 tabent[freeidx] is the first free entry. The first word in a free entry
249 is the index of the next free entry. The last has 0 as a link.
250 The other three words in the free list are probably irrelevant.
252 Entries in text table are preceded by a word at offset-2. This word
253 has the value (2*index)+1, where index is the referring keyent/valent
254 entry in the table. I have no suggestion for the 2* and the +1.
255 Following the word, there are N bytes of data, as per the keyent/valent
256 entry length. The offset of the keyent/valent entry is from the start
257 of the text table to the first data byte.
259 This information is not available from Microsoft. The data format is
260 deduced from the reg.dat file by me. Mistakes may
261 have been made. I claim no rights and give no guarantees for this program.
263 Tor Sjøwall, tor@sn.no
266 /* reg.dat header format */
268 char cookie
[8]; /* 'SHCC3.10' */
269 unsigned long taboff1
; /* offset of hash table (??) = 0x20 */
270 unsigned long taboff2
; /* offset of index table (??) = 0x20 */
271 unsigned long tabcnt
; /* number of entries in index table */
272 unsigned long textoff
; /* offset of text part */
273 unsigned long textsize
; /* byte size of text part */
274 unsigned short hashsize
; /* hash size */
275 unsigned short freeidx
; /* free index */
278 /* generic format of table entries */
280 unsigned short w0
, w1
, w2
, w3
;
283 /* directory tabent: */
285 unsigned short sibling_idx
; /* table index of sibling dirent */
286 unsigned short child_idx
; /* table index of child dirent */
287 unsigned short key_idx
; /* table index of key keyent */
288 unsigned short value_idx
; /* table index of value valent */
293 unsigned short hash_idx
; /* hash chain index for string */
294 unsigned short refcnt
; /* reference count */
295 unsigned short length
; /* length of string */
296 unsigned short string_off
; /* offset of string in text table */
301 unsigned short hash_idx
; /* hash chain index for string */
302 unsigned short refcnt
; /* reference count */
303 unsigned short length
; /* length of string */
304 unsigned short string_off
; /* offset of string in text table */
307 /* recursive helper function to display a directory tree [Internal] */
308 void _w31_dumptree(unsigned short idx
,unsigned char *txt
,struct _w31_tabent
*tab
,struct _w31_header
*head
,HKEY hkey
,time_t lastmodified
, int level
)
310 struct _w31_dirent
*dir
;
311 struct _w31_keyent
*key
;
312 struct _w31_valent
*val
;
314 static char tail
[400];
317 dir
=(struct _w31_dirent
*)&tab
[idx
];
320 key
= (struct _w31_keyent
*)&tab
[dir
->key_idx
];
322 memcpy(tail
,&txt
[key
->string_off
],key
->length
);
323 tail
[key
->length
]='\0';
324 /* all toplevel entries AND the entries in the
325 * toplevel subdirectory belong to \SOFTWARE\Classes
327 if (!level
&& !strcmp(tail
,".classes")) {
328 _w31_dumptree(dir
->child_idx
,txt
,tab
,head
,hkey
,lastmodified
,level
+1);
329 idx
=dir
->sibling_idx
;
332 if (subkey
) RegCloseKey( subkey
);
333 if (RegCreateKeyA( hkey
, tail
, &subkey
) != ERROR_SUCCESS
) subkey
= 0;
334 /* only add if leaf node or valued node */
335 if (dir
->value_idx
!=0||dir
->child_idx
==0) {
336 if (dir
->value_idx
) {
337 val
=(struct _w31_valent
*)&tab
[dir
->value_idx
];
338 memcpy(tail
,&txt
[val
->string_off
],val
->length
);
339 tail
[val
->length
]='\0';
340 RegSetValueA( subkey
, NULL
, REG_SZ
, tail
, 0 );
343 } else TRACE("strange: no directory key name, idx=%04x\n", idx
);
344 _w31_dumptree(dir
->child_idx
,txt
,tab
,head
,subkey
,lastmodified
,level
+1);
345 idx
=dir
->sibling_idx
;
347 if (subkey
) RegCloseKey( subkey
);
351 /******************************************************************************
352 * _w31_loadreg [Internal]
354 void _w31_loadreg(void)
357 struct _w31_header head
;
358 struct _w31_tabent
*tab
;
362 BY_HANDLE_FILE_INFORMATION hfinfo
;
367 hf
= OpenFile("reg.dat",&ofs
,OF_READ
);
368 if (hf
==HFILE_ERROR
) return;
370 /* read & dump header */
371 if (sizeof(head
)!=_lread(hf
,&head
,sizeof(head
))) {
372 ERR("reg.dat is too short.\n");
376 if (memcmp(head
.cookie
, "SHCC3.10", sizeof(head
.cookie
))!=0) {
377 ERR("reg.dat has bad signature.\n");
382 len
= head
.tabcnt
* sizeof(struct _w31_tabent
);
383 /* read and dump index table */
385 if (len
!=_lread(hf
,tab
,len
)) {
386 ERR("couldn't read %d bytes.\n",len
);
393 txt
= _xmalloc(head
.textsize
);
394 if (-1==_llseek(hf
,head
.textoff
,SEEK_SET
)) {
395 ERR("couldn't seek to textblock.\n");
401 if (head
.textsize
!=_lread(hf
,txt
,head
.textsize
)) {
402 ERR("textblock too short (%d instead of %ld).\n",len
,head
.textsize
);
409 if (!GetFileInformationByHandle(hf
,&hfinfo
)) {
410 ERR("GetFileInformationByHandle failed?.\n");
416 lastmodified
= DOSFS_FileTimeToUnixTime(&hfinfo
.ftLastWriteTime
,NULL
);
417 _w31_dumptree(tab
[0].w1
,txt
,tab
,&head
,HKEY_CLASSES_ROOT
,lastmodified
,0);
424 /***********************************************************************************/
425 /* windows 95 registry loader */
426 /***********************************************************************************/
428 /* SECTION 1: main header
432 #define W95_REG_CREG_ID 0x47455243
435 DWORD id
; /* "CREG" = W95_REG_CREG_ID */
436 DWORD version
; /* ???? 0x00010000 */
437 DWORD rgdb_off
; /* 0x08 Offset of 1st RGDB-block */
438 DWORD uk2
; /* 0x0c */
439 WORD rgdb_num
; /* 0x10 # of RGDB-blocks */
445 /* SECTION 2: Directory information (tree structure)
447 * once on offset 0x20
449 * structure: [rgkn][dke]* (repeat till last_dke is reached)
451 #define W95_REG_RGKN_ID 0x4e4b4752
454 DWORD id
; /*"RGKN" = W95_REG_RGKN_ID */
455 DWORD size
; /* Size of the RGKN-block */
456 DWORD root_off
; /* Rel. Offset of the root-record */
457 DWORD last_dke
; /* Offset to last DKE ? */
461 /* Disk Key Entry Structure
463 * the 1st entry in a "usual" registry file is a nul-entry with subkeys: the
464 * hive itself. It looks the same like other keys. Even the ID-number can
467 * The "hash"-value is a value representing the key's name. Windows will not
468 * search for the name, but for a matching hash-value. if it finds one, it
469 * will compare the actual string info, otherwise continue with the next key.
470 * To calculate the hash initialize a D-Word with 0 and add all ASCII-values
471 * of the string which are smaller than 0x80 (128) to this D-Word.
473 * If you want to modify key names, also modify the hash-values, since they
474 * cannot be found again (although they would be displayed in REGEDIT)
475 * End of list-pointers are filled with 0xFFFFFFFF
477 * Disk keys are layed out flat ... But, sometimes, nrLS and nrMS are both
478 * 0xFFFF, which means skipping over nextkeyoffset bytes (including this
479 * structure) and reading another RGDB_section.
481 * The last DKE (see field last_dke in _w95_rgkn) has only 3 DWORDs with
482 * 0x80000000 (EOL indicator ?) as x1, the hash value and 0xFFFFFFFF as x3.
483 * The remaining space between last_dke and the offset calculated from
484 * rgkn->size seems to be free for use for more dke:s.
485 * So it seems if more dke:s are added, they are added to that space and
486 * last_dke is grown, and in case that "free" space is out, the space
487 * gets grown and rgkn->size gets adjusted.
489 * there is a one to one relationship between dke and dkh
491 /* key struct, once per key */
493 DWORD x1
; /* Free entry indicator(?) */
494 DWORD hash
; /* sum of bytes of keyname */
495 DWORD x3
; /* Root key indicator? usually 0xFFFFFFFF */
496 DWORD prevlvl
; /* offset of previous key */
497 DWORD nextsub
; /* offset of child key */
498 DWORD next
; /* offset of sibling key */
499 WORD nrLS
; /* id inside the rgdb block */
500 WORD nrMS
; /* number of the rgdb block */
503 /* SECTION 3: key information, values and data
506 * section: [blocks]* (repeat creg->rgdb_num times)
507 * blocks: [rgdb] [subblocks]* (repeat till block size reached )
508 * subblocks: [dkh] [dkv]* (repeat dkh->values times )
510 * An interesting relationship exists in RGDB_section. The DWORD value
511 * at offset 0x10 equals the one at offset 0x04 minus the one at offset 0x08.
512 * I have no idea at the moment what this means. (Kevin Cozens)
515 /* block header, once per block */
516 #define W95_REG_RGDB_ID 0x42444752
519 DWORD id
; /* 0x00 'RGDB' = W95_REG_RGDB_ID */
520 DWORD size
; /* 0x04 */
521 DWORD uk1
; /* 0x08 */
522 DWORD uk2
; /* 0x0c */
523 DWORD uk3
; /* 0x10 */
524 DWORD uk4
; /* 0x14 */
525 DWORD uk5
; /* 0x18 */
526 DWORD uk6
; /* 0x1c */
530 /* Disk Key Header structure (RGDB part), once per key */
532 DWORD nextkeyoff
; /* 0x00 offset to next dkh */
533 WORD nrLS
; /* 0x04 id inside the rgdb block */
534 WORD nrMS
; /* 0x06 number of the rgdb block */
535 DWORD bytesused
; /* 0x08 */
536 WORD keynamelen
; /* 0x0c len of name */
537 WORD values
; /* 0x0e number of values */
538 DWORD xx1
; /* 0x10 */
539 char name
[1]; /* 0x14 */
540 /* dkv */ /* 0x14 + keynamelen */
543 /* Disk Key Value structure, once per value */
545 DWORD type
; /* 0x00 */
547 WORD valnamelen
; /* 0x08 length of name, 0 is default key */
548 WORD valdatalen
; /* 0x0A length of data */
549 char name
[1]; /* 0x0c */
550 /* raw data */ /* 0x0c + valnamelen */
553 /******************************************************************************
554 * _w95_lookup_dkh [Internal]
556 * seeks the dkh belonging to a dke
558 static _w95dkh
*_w95_lookup_dkh(_w95creg
*creg
,int nrLS
,int nrMS
)
564 /* get the beginning of the rgdb datastore */
565 rgdb
= (_w95rgdb
*)((char*)creg
+creg
->rgdb_off
);
567 /* check: requested block < last_block) */
568 if (creg
->rgdb_num
<= nrMS
) {
569 ERR("registry file corrupt! requested block no. beyond end.\n");
573 /* find the right block */
574 for(i
=0; i
<nrMS
;i
++) {
575 if(rgdb
->id
!= W95_REG_RGDB_ID
) { /* check the magic */
576 ERR("registry file corrupt! bad magic 0x%08lx\n", rgdb
->id
);
579 rgdb
= (_w95rgdb
*) ((char*)rgdb
+rgdb
->size
); /* find next block */
582 dkh
= (_w95dkh
*)(rgdb
+ 1); /* first sub block within the rgdb */
585 if(nrLS
==dkh
->nrLS
) return dkh
;
586 dkh
= (_w95dkh
*)((char*)dkh
+ dkh
->nextkeyoff
); /* find next subblock */
587 } while ((char *)dkh
< ((char*)rgdb
+rgdb
->size
));
593 /******************************************************************************
594 * _w95_dump_dkv [Internal]
596 static int _w95_dump_dkv(_w95dkh
*dkh
,int nrLS
,int nrMS
,FILE *f
)
601 /* first value block */
602 dkv
= (_w95dkv
*)((char*)dkh
+dkh
->keynamelen
+0x14);
604 /* loop through the values */
605 for (i
=0; i
< dkh
->values
; i
++) {
606 struct key_value value
;
609 value
.nameW
= _strdupnAtoW(dkv
->name
,dkv
->valnamelen
);
610 value
.type
= dkv
->type
;
611 value
.len
= dkv
->valdatalen
;
613 value
.data
= &(dkv
->name
[dkv
->valnamelen
]);
615 if ( (value
.type
==REG_SZ
) || (value
.type
==REG_EXPAND_SZ
) || (value
.type
==REG_MULTI_SZ
) ) {
616 pdata
= _strdupnAtoW(value
.data
,value
.len
);
619 if (pdata
!= NULL
) value
.data
= pdata
;
621 _dump_value(&value
,f
);
623 if (pdata
!= NULL
) free(pdata
);
626 dkv
= (_w95dkv
*)((char*)dkv
+dkv
->valnamelen
+dkv
->valdatalen
+0x0c);
631 /******************************************************************************
632 * _w95_dump_dke [Internal]
634 static int _w95_dump_dke(LPSTR key_name
,_w95creg
*creg
,_w95rgkn
*rgkn
,_w95dke
*dke
,FILE *f
,int level
)
637 LPSTR new_key_name
= NULL
;
639 /* special root key */
640 if (dke
->nrLS
== 0xffff || dke
->nrMS
==0xffff) /* eg. the root key has no name */
642 /* parse the one subkey */
643 if (dke
->nextsub
!= 0xffffffff) return _w95_dump_dke(key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->nextsub
),f
,level
);
644 /* has no sibling keys */
648 /* search subblock */
649 if (!(dkh
= _w95_lookup_dkh(creg
, dke
->nrLS
, dke
->nrMS
))) {
650 ERR("dke pointing to missing dkh !\n");
655 /* create new subkey name */
656 new_key_name
= _strdupnA(key_name
,strlen(key_name
)+dkh
->keynamelen
+1);
657 if (strcmp(new_key_name
,"") != 0) strcat(new_key_name
,"\\");
658 strncat(new_key_name
,dkh
->name
,dkh
->keynamelen
);
660 /* walk sibling keys */
661 if (dke
->next
!= 0xffffffff ) {
662 if (!_w95_dump_dke(key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->next
),f
,level
)) {
668 /* write the key path (something like [Software\\Microsoft\\..]) only if:
669 1) key has some values
670 2) key has no values and no subkeys
672 if (dkh
->values
> 0) {
673 /* there are some values */
675 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
677 if (!_w95_dump_dkv(dkh
, dke
->nrLS
, dke
->nrMS
,f
)) {
682 if ((dke
->nextsub
== 0xffffffff) && (dkh
->values
== 0)) {
683 /* no subkeys and no values */
685 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
688 } else new_key_name
= _strdupnA(key_name
,strlen(key_name
));
691 if (dke
->nextsub
!= 0xffffffff) {
692 if (!_w95_dump_dke(new_key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->nextsub
),f
,level
-1)) {
701 /* end windows 95 loader */
703 /***********************************************************************************/
704 /* windows NT registry loader */
705 /***********************************************************************************/
707 /* NT REGISTRY LOADER */
709 #ifdef HAVE_SYS_MMAN_H
710 # include <sys/mman.h>
714 #define MAP_FAILED ((LPVOID)-1)
717 #define NT_REG_BLOCK_SIZE 0x1000
719 #define NT_REG_HEADER_BLOCK_ID 0x66676572 /* regf */
720 #define NT_REG_POOL_BLOCK_ID 0x6E696268 /* hbin */
721 #define NT_REG_KEY_BLOCK_ID 0x6b6e /* nk */
722 #define NT_REG_VALUE_BLOCK_ID 0x6b76 /* vk */
724 /* subblocks of nk */
725 #define NT_REG_HASH_BLOCK_ID 0x666c /* lf */
726 #define NT_REG_NOHASH_BLOCK_ID 0x696c /* li */
727 #define NT_REG_RI_BLOCK_ID 0x6972 /* ri */
729 #define NT_REG_KEY_BLOCK_TYPE 0x20
730 #define NT_REG_ROOT_KEY_BLOCK_TYPE 0x2c
733 DWORD id
; /* 0x66676572 'regf'*/
734 DWORD uk1
; /* 0x04 */
735 DWORD uk2
; /* 0x08 */
736 FILETIME DateModified
; /* 0x0c */
737 DWORD uk3
; /* 0x14 */
738 DWORD uk4
; /* 0x18 */
739 DWORD uk5
; /* 0x1c */
740 DWORD uk6
; /* 0x20 */
741 DWORD RootKeyBlock
; /* 0x24 */
742 DWORD BlockSize
; /* 0x28 */
744 DWORD Checksum
; /* at offset 0x1FC */
753 DWORD id
; /* 0x6E696268 'hbin' */
757 DWORD uk2
; /* 0x10 */
758 DWORD uk3
; /* 0x14 */
759 DWORD uk4
; /* 0x18 */
760 DWORD size
; /* 0x1C */
761 nt_hbin_sub hbin_sub
; /* 0x20 */
765 * the value_list consists of offsets to the values (vk)
768 WORD SubBlockId
; /* 0x00 0x6B6E */
769 WORD Type
; /* 0x02 for the root-key: 0x2C, otherwise 0x20*/
770 FILETIME writetime
; /* 0x04 */
771 DWORD uk1
; /* 0x0C */
772 DWORD parent_off
; /* 0x10 Offset of Owner/Parent key */
773 DWORD nr_subkeys
; /* 0x14 number of sub-Keys */
774 DWORD uk8
; /* 0x18 */
775 DWORD lf_off
; /* 0x1C Offset of the sub-key lf-Records */
776 DWORD uk2
; /* 0x20 */
777 DWORD nr_values
; /* 0x24 number of values */
778 DWORD valuelist_off
; /* 0x28 Offset of the Value-List */
779 DWORD off_sk
; /* 0x2c Offset of the sk-Record */
780 DWORD off_class
; /* 0x30 Offset of the Class-Name */
781 DWORD uk3
; /* 0x34 */
782 DWORD uk4
; /* 0x38 */
783 DWORD uk5
; /* 0x3c */
784 DWORD uk6
; /* 0x40 */
785 DWORD uk7
; /* 0x44 */
786 WORD name_len
; /* 0x48 name-length */
787 WORD class_len
; /* 0x4a class-name length */
788 char name
[1]; /* 0x4c key-name */
792 DWORD off_nk
; /* 0x00 */
793 DWORD name
; /* 0x04 */
797 WORD id
; /* 0x00 0x666c */
798 WORD nr_keys
; /* 0x06 */
799 hash_rec hash_rec
[1];
803 list of subkeys without hash
810 WORD id
; /* 0x00 0x696c */
816 this is a intermediate node
827 WORD id
; /* 0x00 0x6972 */
828 WORD nr_li
; /* 0x02 number off offsets */
829 DWORD off_li
[1]; /* 0x04 points to li */
833 WORD id
; /* 0x00 'vk' */
847 * 0 value is a default value
848 * 1 the value has a name
851 * len of the whole data block
853 * bytes including the terminating \0 = 2*(number_of_chars+1)
854 * - reg_dword, reg_binary:
855 * if highest bit of data_len is set data_off contains the value
857 static int _nt_dump_vk(LPSTR key_name
, char *base
, nt_vk
*vk
,FILE *f
)
859 BYTE
*pdata
= (BYTE
*)(base
+vk
->data_off
+4); /* start of data */
860 struct key_value value
;
862 if (vk
->id
!= NT_REG_VALUE_BLOCK_ID
) {
863 ERR("unknown block found (0x%04x), please report!\n", vk
->id
);
867 value
.nameW
= _strdupnAtoW(vk
->name
,vk
->nam_len
);
868 value
.type
= vk
->type
;
869 value
.len
= (vk
->data_len
& 0x7fffffff);
870 value
.data
= (vk
->data_len
& 0x80000000) ? (LPBYTE
)&(vk
->data_off
): pdata
;
872 _dump_value(&value
,f
);
878 /* it's called from _nt_dump_lf() */
879 static int _nt_dump_nk(LPSTR key_name
,char *base
,nt_nk
*nk
,FILE *f
,int level
);
884 * this structure contains the hash of a keyname and points to all
887 * exception: if the id is 'il' there are no hash values and every
890 static int _nt_dump_lf(LPSTR key_name
, char *base
, int subkeys
, nt_lf
*lf
, FILE *f
, int level
)
894 if (lf
->id
== NT_REG_HASH_BLOCK_ID
) {
895 if (subkeys
!= lf
->nr_keys
) goto error1
;
897 for (i
=0; i
<lf
->nr_keys
; i
++)
898 if (!_nt_dump_nk(key_name
, base
, (nt_nk
*)(base
+lf
->hash_rec
[i
].off_nk
+4), f
, level
)) goto error
;
899 } else if (lf
->id
== NT_REG_NOHASH_BLOCK_ID
) {
900 nt_li
* li
= (nt_li
*)lf
;
901 if (subkeys
!= li
->nr_keys
) goto error1
;
903 for (i
=0; i
<li
->nr_keys
; i
++)
904 if (!_nt_dump_nk(key_name
, base
, (nt_nk
*)(base
+li
->off_nk
[i
]+4), f
, level
)) goto error
;
905 } else if (lf
->id
== NT_REG_RI_BLOCK_ID
) { /* ri */
906 nt_ri
* ri
= (nt_ri
*)lf
;
909 /* count all subkeys */
910 for (i
=0; i
<ri
->nr_li
; i
++) {
911 nt_li
* li
= (nt_li
*)(base
+ri
->off_li
[i
]+4);
912 if(li
->id
!= NT_REG_NOHASH_BLOCK_ID
) goto error2
;
913 li_subkeys
+= li
->nr_keys
;
917 if (subkeys
!= li_subkeys
) goto error1
;
919 /* loop through the keys */
920 for (i
=0; i
<ri
->nr_li
; i
++) {
921 nt_li
*li
= (nt_li
*)(base
+ri
->off_li
[i
]+4);
922 if (!_nt_dump_lf(key_name
, base
, li
->nr_keys
, (nt_lf
*)li
, f
, level
)) goto error
;
929 if (lf
->id
== 0x686c)
930 FIXME("unknown Win XP node id 0x686c: do we need to add support for it ?\n");
932 ERR("unknown node id 0x%04x, please report!\n", lf
->id
);
936 ERR("registry file corrupt! (inconsistent number of subkeys)\n");
940 ERR("error reading lf block\n");
944 /* _nt_dump_nk [Internal] */
945 static int _nt_dump_nk(LPSTR key_name
,char *base
,nt_nk
*nk
,FILE *f
,int level
)
949 LPSTR new_key_name
= NULL
;
952 if (nk
->SubBlockId
!= NT_REG_KEY_BLOCK_ID
) {
953 ERR("unknown node id 0x%04x, please report!\n", nk
->SubBlockId
);
957 if ((nk
->Type
!=NT_REG_ROOT_KEY_BLOCK_TYPE
) && (((nt_nk
*)(base
+nk
->parent_off
+4))->SubBlockId
!= NT_REG_KEY_BLOCK_ID
)) {
958 ERR("registry file corrupt!\n");
962 /* create the new key */
964 /* create new subkey name */
965 new_key_name
= _strdupnA(key_name
,strlen(key_name
)+nk
->name_len
+1);
966 if (strcmp(new_key_name
,"") != 0) strcat(new_key_name
,"\\");
967 strncat(new_key_name
,nk
->name
,nk
->name_len
);
969 /* write the key path (something like [Software\\Microsoft\\..]) only if:
970 1) key has some values
971 2) key has no values and no subkeys
973 if (nk
->nr_values
> 0) {
974 /* there are some values */
976 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
979 if ((nk
->nr_subkeys
== 0) && (nk
->nr_values
== 0)) {
980 /* no subkeys and no values */
982 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
986 /* loop trough the value list */
987 vl
= (DWORD
*)(base
+nk
->valuelist_off
+4);
988 for (n
=0; n
<nk
->nr_values
; n
++) {
989 nt_vk
* vk
= (nt_vk
*)(base
+vl
[n
]+4);
990 if (!_nt_dump_vk(new_key_name
, base
, vk
, f
)) {
995 } else new_key_name
= _strdupnA(key_name
,strlen(key_name
));
997 /* loop through the subkeys */
998 if (nk
->nr_subkeys
) {
999 nt_lf
*lf
= (nt_lf
*)(base
+nk
->lf_off
+4);
1000 if (!_nt_dump_lf(new_key_name
, base
, nk
->nr_subkeys
, lf
, f
, level
-1)) {
1012 /**********************************************************************************
1013 * _set_registry_levels [Internal]
1015 * set level to 0 for loading system files
1016 * set level to 1 for loading user files
1018 static void _set_registry_levels(int level
,int saving
,int period
)
1020 SERVER_START_REQ( set_registry_levels
)
1022 req
->current
= level
;
1023 req
->saving
= saving
;
1024 req
->period
= period
;
1025 wine_server_call( req
);
1030 /* _save_at_exit [Internal] */
1031 static void _save_at_exit(HKEY hkey
,LPCSTR path
)
1033 LPCSTR confdir
= get_config_dir();
1035 SERVER_START_REQ( save_registry_atexit
)
1038 wine_server_add_data( req
, confdir
, strlen(confdir
) );
1039 wine_server_add_data( req
, path
, strlen(path
)+1 );
1040 wine_server_call( req
);
1045 /* configure save files and start the periodic saving timer [Internal] */
1046 static void _init_registry_saving( HKEY hkey_users_default
)
1051 all
= PROFILE_GetWineIniBool("registry","SaveOnlyUpdatedKeys",1);
1052 period
= PROFILE_GetWineIniInt("registry","PeriodicSave",0);
1054 /* set saving level (0 for saving everything, 1 for saving only modified keys) */
1055 _set_registry_levels(1,!all
,period
*1000);
1057 if (PROFILE_GetWineIniBool("registry","WritetoHomeRegistryFiles",1))
1059 _save_at_exit(HKEY_CURRENT_USER
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1060 _save_at_exit(HKEY_LOCAL_MACHINE
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1061 _save_at_exit(hkey_users_default
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1066 /******************************************************************************
1067 * _allocate_default_keys [Internal]
1068 * Registry initialisation, allocates some default keys.
1070 static void _allocate_default_keys(void) {
1076 RegCreateKeyA(HKEY_DYN_DATA
,"PerfStats\\StatData",&hkey
);
1079 /* This was an Open, but since it is called before the real registries
1080 are loaded, it was changed to a Create - MTB 980507*/
1081 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System",&hkey
);
1082 RegSetValueExA(hkey
,"Identifier",0,REG_SZ
,"SystemType WINE",strlen("SystemType WINE"));
1085 /* \\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion
1087 * CurrentBuildNumber
1089 * string RegisteredOwner
1090 * string RegisteredOrganization
1093 /* System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent
1095 * string SysLocation
1098 if (-1!=gethostname(buf
,200)) {
1099 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",&hkey
);
1100 RegSetValueExA(hkey
,"ComputerName",0,REG_SZ
,buf
,strlen(buf
)+1);
1104 RegCreateKeyA(HKEY_USERS
,".Default",&hkey
);
1108 #define REG_DONTLOAD -1
1113 /* return the type of native registry [Internal] */
1114 static int _get_reg_type(void)
1116 char windir
[MAX_PATHNAME_LEN
];
1117 char tmp
[MAX_PATHNAME_LEN
];
1118 int ret
= REG_WIN31
;
1120 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1122 /* test %windir%/system32/config/system --> winnt */
1123 strcpy(tmp
, windir
);
1124 strncat(tmp
, "\\system32\\config\\system", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1125 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1130 /* test %windir%/system.dat --> win95 */
1131 strcpy(tmp
, windir
);
1132 strncat(tmp
, "\\system.dat", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1133 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1138 if ((ret
== REG_WINNT
) && (!PROFILE_GetWineIniString( "Wine", "Profile", "", tmp
, MAX_PATHNAME_LEN
))) {
1139 MESSAGE("When you are running with a native NT directory specify\n");
1140 MESSAGE("'Profile=<profiledirectory>' or disable loading of Windows\n");
1141 MESSAGE("registry (LoadWindowsRegistryFiles=N)\n");
1148 #define WINE_REG_VER_ERROR -1
1149 #define WINE_REG_VER_1 0
1150 #define WINE_REG_VER_2 1
1151 #define WINE_REG_VER_OLD 2
1152 #define WINE_REG_VER_UNKNOWN 3
1154 /* return the version of wine registry file [Internal] */
1155 static int _get_wine_registry_file_format_version(LPCSTR fn
)
1161 if ((f
=fopen(fn
,"rt")) == NULL
) {
1162 WARN("Couldn't open %s for reading: %s\n",fn
,strerror(errno
));
1163 return WINE_REG_VER_ERROR
;
1166 if (fgets(tmp
,50,f
) == NULL
) {
1167 WARN("Error reading %s: %s\n",fn
,strerror(errno
));
1169 return WINE_REG_VER_ERROR
;
1173 if (sscanf(tmp
,"WINE REGISTRY Version %d",&ver
) != 1) return WINE_REG_VER_UNKNOWN
;
1176 return WINE_REG_VER_1
;
1179 return WINE_REG_VER_2
;
1182 return WINE_REG_VER_UNKNOWN
;
1186 /* load the registry file in wine format [Internal] */
1187 static void load_wine_registry(HKEY hkey
,LPCSTR fn
)
1191 file_format
= _get_wine_registry_file_format_version(fn
);
1192 switch (file_format
) {
1194 case WINE_REG_VER_1
:
1195 WARN("Unable to load registry file %s: old format which is no longer supported.\n",fn
);
1198 case WINE_REG_VER_2
: {
1200 if ((file
= FILE_CreateFile( fn
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1201 FILE_ATTRIBUTE_NORMAL
, 0, TRUE
, DRIVE_UNKNOWN
)))
1203 SERVER_START_REQ( load_registry
)
1207 wine_server_call( req
);
1210 CloseHandle( file
);
1215 case WINE_REG_VER_UNKNOWN
:
1216 WARN("Unable to load registry file %s: unknown format.\n",fn
);
1219 case WINE_REG_VER_ERROR
:
1224 /* generate and return the name of the tmp file and associated stream [Internal] */
1225 static LPSTR
_get_tmp_fn(FILE **f
)
1232 sprintf(ret
,"/tmp/reg%lx%04x.tmp",(long)getpid(),count
++);
1233 if ((tmp_fd
= open(ret
,O_CREAT
| O_EXCL
| O_WRONLY
,0666)) != -1) break;
1234 if (errno
!= EEXIST
) {
1235 ERR("Unexpected error while open() call: %s\n",strerror(errno
));
1242 if ((*f
= fdopen(tmp_fd
,"w")) == NULL
) {
1243 ERR("Unexpected error while fdopen() call: %s\n",strerror(errno
));
1252 /* convert win95 native registry file to wine format [Internal] */
1253 static LPSTR
_convert_win95_registry_to_wine_format(LPCSTR fn
,int level
)
1257 DOS_FULL_NAME full_name
;
1264 _w95dke
*dke
, *root_dke
;
1266 if (!DOSFS_GetFullName( fn
, 0, &full_name
)) return NULL
;
1268 /* map the registry into the memory */
1269 if ((fd
= open(full_name
.long_name
, O_RDONLY
| O_NONBLOCK
)) == -1) return NULL
;
1270 if ((fstat(fd
, &st
) == -1)) goto error1
;
1271 if (!st
.st_size
) goto error1
;
1272 if ((base
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == MAP_FAILED
) goto error1
;
1274 /* control signature */
1275 if (*(LPDWORD
)base
!= W95_REG_CREG_ID
) {
1276 ERR("unable to load native win95 registry file %s: unknown signature.\n",fn
);
1281 /* load the header (rgkn) */
1282 rgkn
= (_w95rgkn
*)(creg
+ 1);
1283 if (rgkn
->id
!= W95_REG_RGKN_ID
) {
1284 ERR("second IFF header not RGKN, but %lx\n", rgkn
->id
);
1287 if (rgkn
->root_off
!= 0x20) {
1288 ERR("rgkn->root_off not 0x20, please report !\n");
1291 if (rgkn
->last_dke
> rgkn
->size
)
1293 ERR("registry file corrupt! last_dke > size!\n");
1296 /* verify last dke */
1297 dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->last_dke
);
1298 if (dke
->x1
!= 0x80000000)
1300 ERR("last dke invalid !\n");
1303 if (rgkn
->size
> creg
->rgdb_off
)
1305 ERR("registry file corrupt! rgkn size > rgdb_off !\n");
1308 root_dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->root_off
);
1309 if ( (root_dke
->prevlvl
!= 0xffffffff) || (root_dke
->next
!= 0xffffffff) )
1311 ERR("registry file corrupt! invalid root dke !\n");
1315 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1316 fprintf(f
,"WINE REGISTRY Version 2");
1317 _w95_dump_dke("",creg
,rgkn
,root_dke
,f
,level
);
1322 ERR("Unable to load native win95 registry file %s.\n",fn
);
1323 ERR("Please report to a.mohr@mailto.de.\n");
1324 ERR("Make a backup of the file, run a good reg cleaner program and try again!\n");
1327 munmap(base
, st
.st_size
);
1333 /* convert winnt native registry file to wine format [Internal] */
1334 static LPSTR
_convert_winnt_registry_to_wine_format(LPCSTR fn
,int level
)
1338 DOS_FULL_NAME full_name
;
1345 nt_hbin_sub
*hbin_sub
;
1348 if (!DOSFS_GetFullName( fn
, 0, &full_name
)) return NULL
;
1350 /* map the registry into the memory */
1351 if ((fd
= open(full_name
.long_name
, O_RDONLY
| O_NONBLOCK
)) == -1) return NULL
;
1352 if ((fstat(fd
, &st
) == -1)) goto error1
;
1353 if (!st
.st_size
) goto error1
;
1354 if ((base
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == MAP_FAILED
) goto error1
;
1356 /* control signature */
1357 if (*(LPDWORD
)base
!= NT_REG_HEADER_BLOCK_ID
) {
1358 ERR("unable to load native winnt registry file %s: unknown signature.\n",fn
);
1366 hbin
= (nt_hbin
*)((char*) base
+ 0x1000);
1367 if (hbin
->id
!= NT_REG_POOL_BLOCK_ID
) {
1368 ERR( "hbin block invalid\n");
1372 /* hbin_sub block */
1373 hbin_sub
= (nt_hbin_sub
*)&(hbin
->hbin_sub
);
1374 if ((hbin_sub
->data
[0] != 'n') || (hbin_sub
->data
[1] != 'k')) {
1375 ERR( "hbin_sub block invalid\n");
1380 nk
= (nt_nk
*)&(hbin_sub
->data
[0]);
1381 if (nk
->Type
!= NT_REG_ROOT_KEY_BLOCK_TYPE
) {
1382 ERR( "special nk block not found\n");
1386 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1387 fprintf(f
,"WINE REGISTRY Version 2");
1388 _nt_dump_nk("",(char*)base
+0x1000,nk
,f
,level
);
1392 munmap(base
,st
.st_size
);
1398 /* convert native registry to wine format and load it via server call [Internal] */
1399 static void _convert_and_load_native_registry(LPCSTR fn
,HKEY hkey
,int reg_type
,int level
)
1405 /* FIXME: following function doesn't really convert yet */
1406 tmp
= _convert_winnt_registry_to_wine_format(fn
,level
);
1409 tmp
= _convert_win95_registry_to_wine_format(fn
,level
);
1412 ERR("Don't know how to convert native 3.1 registry yet.\n");
1415 ERR("Unknown registry format parameter (%d)\n",reg_type
);
1420 load_wine_registry(hkey
,tmp
);
1421 TRACE("File %s successfully converted to %s and loaded to registry.\n",fn
,tmp
);
1424 else WARN("Unable to convert %s (doesn't exist?)\n",fn
);
1428 /* load all native windows registry files [Internal] */
1429 static void _load_windows_registry( HKEY hkey_users_default
)
1432 char windir
[MAX_PATHNAME_LEN
];
1433 char path
[MAX_PATHNAME_LEN
];
1435 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1437 reg_type
= _get_reg_type();
1442 /* user specific ntuser.dat */
1443 if (PROFILE_GetWineIniString( "Wine", "Profile", "", path
, MAX_PATHNAME_LEN
)) {
1444 strcat(path
,"\\ntuser.dat");
1445 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WINNT
,1);
1448 /* default user.dat */
1449 if (hkey_users_default
) {
1450 strcpy(path
,windir
);
1451 strcat(path
,"\\system32\\config\\default");
1452 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WINNT
,1);
1457 * map HLM\System\ControlSet001 to HLM\System\CurrentControlSet
1460 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SYSTEM", &hkey
)) {
1461 strcpy(path
,windir
);
1462 strcat(path
,"\\system32\\config\\system");
1463 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1467 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE", &hkey
)) {
1468 strcpy(path
,windir
);
1469 strcat(path
,"\\system32\\config\\software");
1470 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1474 strcpy(path
,windir
);
1475 strcat(path
,"\\system32\\config\\sam");
1476 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1478 strcpy(path
,windir
);
1479 strcat(path
,"\\system32\\config\\security");
1480 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1482 /* this key is generated when the nt-core booted successfully */
1483 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\Clone",&hkey
)) RegCloseKey(hkey
);
1488 _convert_and_load_native_registry("c:\\system.1st",HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1490 strcpy(path
,windir
);
1491 strcat(path
,"\\system.dat");
1492 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1494 strcpy(path
,windir
);
1495 strcat(path
,"\\classes.dat");
1496 _convert_and_load_native_registry(path
,HKEY_CLASSES_ROOT
,REG_WIN95
,0);
1498 if (PROFILE_GetWineIniString("Wine","Profile","",path
,MAX_PATHNAME_LEN
)) {
1499 /* user specific user.dat */
1500 strncat(path
, "\\user.dat", MAX_PATHNAME_LEN
- strlen(path
) - 1);
1501 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1503 /* default user.dat */
1504 if (hkey_users_default
) {
1505 strcpy(path
,windir
);
1506 strcat(path
,"\\user.dat");
1507 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WIN95
,1);
1510 strcpy(path
,windir
);
1511 strcat(path
,"\\user.dat");
1512 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1517 /* FIXME: here we should convert to *.reg file supported by server and call REQ_LOAD_REGISTRY, see REG_WIN95 case */
1522 TRACE("REG_DONTLOAD\n");
1526 ERR("switch: no match (%d)\n",reg_type
);
1532 /* load global registry files (stored in /etc/wine) [Internal] */
1533 static void _load_global_registry(void)
1537 /* Load the global HKU hive directly from sysconfdir */
1538 load_wine_registry( HKEY_USERS
, SAVE_GLOBAL_REGBRANCH_USER_DEFAULT
);
1540 /* Load the global machine defaults directly from sysconfdir */
1541 load_wine_registry( HKEY_LOCAL_MACHINE
, SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE
);
1544 /* load home registry files (stored in ~/.wine) [Internal] */
1545 static void _load_home_registry( HKEY hkey_users_default
)
1547 LPCSTR confdir
= get_config_dir();
1548 LPSTR tmp
= _xmalloc(strlen(confdir
)+20);
1550 strcpy(tmp
,confdir
);
1551 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1552 load_wine_registry(hkey_users_default
,tmp
);
1554 strcpy(tmp
,confdir
);
1555 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1556 load_wine_registry(HKEY_CURRENT_USER
,tmp
);
1558 strcpy(tmp
,confdir
);
1559 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1560 load_wine_registry(HKEY_LOCAL_MACHINE
,tmp
);
1565 /* load all registry (native and global and home) */
1566 void SHELL_LoadRegistry( void )
1568 HKEY hkey_users_default
;
1572 if (!CLIENT_IsBootThread()) return; /* already loaded */
1574 if (RegCreateKeyA(HKEY_USERS
,".Default",&hkey_users_default
))
1576 ERR("Cannot create HKEY_USERS/.Default\n" );
1580 _allocate_default_keys();
1581 _set_registry_levels(0,0,0);
1582 if (PROFILE_GetWineIniBool("Registry","LoadWindowsRegistryFiles",1))
1583 _load_windows_registry( hkey_users_default
);
1584 if (PROFILE_GetWineIniBool("Registry","LoadGlobalRegistryFiles",1))
1585 _load_global_registry();
1586 _set_registry_levels(1,0,0);
1587 if (PROFILE_GetWineIniBool("Registry","LoadHomeRegistryFiles",1))
1588 _load_home_registry( hkey_users_default
);
1589 _init_registry_saving( hkey_users_default
);
1590 RegCloseKey(hkey_users_default
);
1593 /***************************************************************************/
1595 /***************************************************************************/
1597 /******************************************************************************
1598 * RegFlushKey [ADVAPI32.@]
1599 * Immediately writes key to registry.
1600 * Only returns after data has been written to disk.
1602 * FIXME: does it really wait until data is written ?
1605 * hkey [I] Handle of key to write
1608 * Success: ERROR_SUCCESS
1609 * Failure: Error code
1611 DWORD WINAPI
RegFlushKey( HKEY hkey
)
1613 FIXME( "(%x): stub\n", hkey
);
1614 return ERROR_SUCCESS
;
1618 /******************************************************************************
1619 * RegUnLoadKeyA [ADVAPI32.@]
1621 LONG WINAPI
RegUnLoadKeyA( HKEY hkey
, LPCSTR lpSubKey
)
1623 FIXME("(%x,%s): stub\n",hkey
, debugstr_a(lpSubKey
));
1624 return ERROR_SUCCESS
;
1628 /******************************************************************************
1629 * RegReplaceKeyA [ADVAPI32.@]
1631 LONG WINAPI
RegReplaceKeyA( HKEY hkey
, LPCSTR lpSubKey
, LPCSTR lpNewFile
,
1634 FIXME("(%x,%s,%s,%s): stub\n", hkey
, debugstr_a(lpSubKey
),
1635 debugstr_a(lpNewFile
),debugstr_a(lpOldFile
));
1636 return ERROR_SUCCESS
;
1644 /* 16-bit functions */
1646 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
1647 * some programs. Do not remove those cases. -MM
1649 static inline void fix_win16_hkey( HKEY
*hkey
)
1651 if (*hkey
== 0 || *hkey
== 1) *hkey
= HKEY_CLASSES_ROOT
;
1654 /******************************************************************************
1655 * RegEnumKey [KERNEL.216]
1656 * RegEnumKey [SHELL.7]
1658 DWORD WINAPI
RegEnumKey16( HKEY hkey
, DWORD index
, LPSTR name
, DWORD name_len
)
1660 fix_win16_hkey( &hkey
);
1661 return RegEnumKeyA( hkey
, index
, name
, name_len
);
1664 /******************************************************************************
1665 * RegOpenKey [KERNEL.217]
1666 * RegOpenKey [SHELL.1]
1668 DWORD WINAPI
RegOpenKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1670 fix_win16_hkey( &hkey
);
1671 return RegOpenKeyA( hkey
, name
, retkey
);
1674 /******************************************************************************
1675 * RegCreateKey [KERNEL.218]
1676 * RegCreateKey [SHELL.2]
1678 DWORD WINAPI
RegCreateKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1680 fix_win16_hkey( &hkey
);
1681 return RegCreateKeyA( hkey
, name
, retkey
);
1684 /******************************************************************************
1685 * RegDeleteKey [KERNEL.219]
1686 * RegDeleteKey [SHELL.4]
1688 DWORD WINAPI
RegDeleteKey16( HKEY hkey
, LPCSTR name
)
1690 fix_win16_hkey( &hkey
);
1691 return RegDeleteKeyA( hkey
, name
);
1694 /******************************************************************************
1695 * RegCloseKey [KERNEL.220]
1696 * RegCloseKey [SHELL.3]
1698 DWORD WINAPI
RegCloseKey16( HKEY hkey
)
1700 fix_win16_hkey( &hkey
);
1701 return RegCloseKey( hkey
);
1704 /******************************************************************************
1705 * RegSetValue [KERNEL.221]
1706 * RegSetValue [SHELL.5]
1708 DWORD WINAPI
RegSetValue16( HKEY hkey
, LPCSTR name
, DWORD type
, LPCSTR data
, DWORD count
)
1710 fix_win16_hkey( &hkey
);
1711 return RegSetValueA( hkey
, name
, type
, data
, count
);
1714 /******************************************************************************
1715 * RegDeleteValue [KERNEL.222]
1717 DWORD WINAPI
RegDeleteValue16( HKEY hkey
, LPSTR name
)
1719 fix_win16_hkey( &hkey
);
1720 return RegDeleteValueA( hkey
, name
);
1723 /******************************************************************************
1724 * RegEnumValue [KERNEL.223]
1726 DWORD WINAPI
RegEnumValue16( HKEY hkey
, DWORD index
, LPSTR value
, LPDWORD val_count
,
1727 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
1729 fix_win16_hkey( &hkey
);
1730 return RegEnumValueA( hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
1733 /******************************************************************************
1734 * RegQueryValue [KERNEL.224]
1735 * RegQueryValue [SHELL.6]
1738 * Is this HACK still applicable?
1741 * The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just
1742 * mask out the high 16 bit. This (not so much incidently) hopefully fixes
1745 DWORD WINAPI
RegQueryValue16( HKEY hkey
, LPCSTR name
, LPSTR data
, LPDWORD count
)
1747 fix_win16_hkey( &hkey
);
1748 if (count
) *count
&= 0xffff;
1749 return RegQueryValueA( hkey
, name
, data
, count
);
1752 /******************************************************************************
1753 * RegQueryValueEx [KERNEL.225]
1755 DWORD WINAPI
RegQueryValueEx16( HKEY hkey
, LPCSTR name
, LPDWORD reserved
, LPDWORD type
,
1756 LPBYTE data
, LPDWORD count
)
1758 fix_win16_hkey( &hkey
);
1759 return RegQueryValueExA( hkey
, name
, reserved
, type
, data
, count
);
1762 /******************************************************************************
1763 * RegSetValueEx [KERNEL.226]
1765 DWORD WINAPI
RegSetValueEx16( HKEY hkey
, LPCSTR name
, DWORD reserved
, DWORD type
,
1766 CONST BYTE
*data
, DWORD count
)
1768 fix_win16_hkey( &hkey
);
1769 if (!count
&& (type
==REG_SZ
)) count
= strlen(data
);
1770 return RegSetValueExA( hkey
, name
, reserved
, type
, data
, count
);
1773 /******************************************************************************
1774 * RegFlushKey [KERNEL.227]
1776 DWORD WINAPI
RegFlushKey16( HKEY hkey
)
1778 fix_win16_hkey( &hkey
);
1779 return RegFlushKey( hkey
);