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"
60 #include "wine/debug.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
64 /* FIXME: following defines should be configured global */
65 #define SAVE_GLOBAL_REGBRANCH_USER_DEFAULT ETCDIR"/wine.userreg"
66 #define SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE ETCDIR"/wine.systemreg"
68 /* relative in ~user/.wine/ : */
69 #define SAVE_LOCAL_REGBRANCH_CURRENT_USER "user.reg"
70 #define SAVE_LOCAL_REGBRANCH_USER_DEFAULT "userdef.reg"
71 #define SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE "system.reg"
73 /* _xmalloc [Internal] */
74 static void *_xmalloc( size_t size
)
78 res
= malloc (size
? size
: 1);
80 WARN("Virtual memory exhausted.\n");
86 /* _strdupnA [Internal] */
87 static LPSTR
_strdupnA(LPCSTR str
,size_t len
)
91 if (!str
) return NULL
;
92 ret
= _xmalloc( len
+ 1 );
93 memcpy( ret
, str
, len
);
98 /* convert ansi string to unicode [Internal] */
99 static LPWSTR
_strdupnAtoW(LPCSTR strA
,size_t lenA
)
104 if (!strA
) return NULL
;
105 lenW
= MultiByteToWideChar(CP_ACP
,0,strA
,lenA
,NULL
,0);
106 ret
= _xmalloc(lenW
*sizeof(WCHAR
)+sizeof(WCHAR
));
107 MultiByteToWideChar(CP_ACP
,0,strA
,lenA
,ret
,lenW
);
112 /* dump a Unicode string with proper escaping [Internal] */
113 /* FIXME: this code duplicates server/unicode.c */
114 static int _dump_strW(const WCHAR
*str
,size_t len
,FILE *f
,char escape
[2])
116 static const char escapes
[32] = ".......abtnvfr.............e....";
121 for (; len
; str
++, len
--)
123 if (pos
> buffer
+ sizeof(buffer
) - 8)
125 fwrite( buffer
, pos
- buffer
, 1, f
);
126 count
+= pos
- buffer
;
129 if (*str
> 127) /* hex escape */
131 if (len
> 1 && str
[1] < 128 && isxdigit((char)str
[1]))
132 pos
+= sprintf( pos
, "\\x%04x", *str
);
134 pos
+= sprintf( pos
, "\\x%x", *str
);
137 if (*str
< 32) /* octal or C escape */
139 if (!*str
&& len
== 1) continue; /* do not output terminating NULL */
140 if (escapes
[*str
] != '.')
141 pos
+= sprintf( pos
, "\\%c", escapes
[*str
] );
142 else if (len
> 1 && str
[1] >= '0' && str
[1] <= '7')
143 pos
+= sprintf( pos
, "\\%03o", *str
);
145 pos
+= sprintf( pos
, "\\%o", *str
);
148 if (*str
== '\\' || *str
== escape
[0] || *str
== escape
[1]) *pos
++ = '\\';
151 fwrite( buffer
, pos
- buffer
, 1, f
);
152 count
+= pos
- buffer
;
156 /* convert ansi string to unicode and dump with proper escaping [Internal] */
157 static int _dump_strAtoW(LPCSTR strA
,size_t len
,FILE *f
,char escape
[2])
162 if (strA
== NULL
) return 0;
163 strW
= _strdupnAtoW(strA
,len
);
164 ret
= _dump_strW(strW
,len
,f
,escape
);
170 /* FIXME: this code duplicates server/registry.c */
172 WCHAR
*nameW
; /* value name */
173 int type
; /* value type */
174 size_t len
; /* value data length in bytes */
175 void *data
; /* pointer to value data */
178 /* dump a value to a text file */
179 /* FIXME: this code duplicates server/registry.c */
180 static void _dump_value(struct key_value
*value
,FILE *f
)
184 if (value
->nameW
[0]) {
186 count
= 1 + _dump_strW(value
->nameW
,strlenW(value
->nameW
),f
,"\"\"");
187 count
+= fprintf( f
, "\"=" );
189 else count
= fprintf( f
, "@=" );
191 switch(value
->type
) {
195 if (value
->type
!= REG_SZ
) fprintf( f
, "str(%d):", value
->type
);
197 if (value
->data
) _dump_strW(value
->data
,value
->len
/sizeof(WCHAR
),f
,"\"\"");
201 if (value
->len
== sizeof(DWORD
)) {
203 memcpy( &dw
, value
->data
, sizeof(DWORD
) );
204 fprintf( f
, "dword:%08lx", dw
);
207 /* else fall through */
209 if (value
->type
== REG_BINARY
) count
+= fprintf( f
, "hex:" );
210 else count
+= fprintf( f
, "hex(%x):", value
->type
);
211 for (i
= 0; i
< value
->len
; i
++) {
212 count
+= fprintf( f
, "%02x", *((unsigned char *)value
->data
+ i
) );
213 if (i
< value
->len
-1) {
216 fprintf( f
, "\\\n " );
226 /******************************************************************/
227 /* WINDOWS 31 REGISTRY LOADER, supplied by Tor Sjøwall, tor@sn.no */
229 reghack - windows 3.11 registry data format demo program.
231 The reg.dat file has 3 parts, a header, a table of 8-byte entries that is
232 a combined hash table and tree description, and finally a text table.
234 The header is obvious from the struct header. The taboff1 and taboff2
235 fields are always 0x20, and their usage is unknown.
237 The 8-byte entry table has various entry types.
239 tabent[0] is a root index. The second word has the index of the root of
241 tabent[1..hashsize] is a hash table. The first word in the hash entry is
242 the index of the key/value that has that hash. Data with the same
243 hash value are on a circular list. The other three words in the
244 hash entry are always zero.
245 tabent[hashsize..tabcnt] is the tree structure. There are two kinds of
246 entry: dirent and keyent/valent. They are identified by context.
247 tabent[freeidx] is the first free entry. The first word in a free entry
248 is the index of the next free entry. The last has 0 as a link.
249 The other three words in the free list are probably irrelevant.
251 Entries in text table are preceded by a word at offset-2. This word
252 has the value (2*index)+1, where index is the referring keyent/valent
253 entry in the table. I have no suggestion for the 2* and the +1.
254 Following the word, there are N bytes of data, as per the keyent/valent
255 entry length. The offset of the keyent/valent entry is from the start
256 of the text table to the first data byte.
258 This information is not available from Microsoft. The data format is
259 deduced from the reg.dat file by me. Mistakes may
260 have been made. I claim no rights and give no guarantees for this program.
262 Tor Sjøwall, tor@sn.no
265 /* reg.dat header format */
267 char cookie
[8]; /* 'SHCC3.10' */
268 unsigned long taboff1
; /* offset of hash table (??) = 0x20 */
269 unsigned long taboff2
; /* offset of index table (??) = 0x20 */
270 unsigned long tabcnt
; /* number of entries in index table */
271 unsigned long textoff
; /* offset of text part */
272 unsigned long textsize
; /* byte size of text part */
273 unsigned short hashsize
; /* hash size */
274 unsigned short freeidx
; /* free index */
277 /* generic format of table entries */
279 unsigned short w0
, w1
, w2
, w3
;
282 /* directory tabent: */
284 unsigned short sibling_idx
; /* table index of sibling dirent */
285 unsigned short child_idx
; /* table index of child dirent */
286 unsigned short key_idx
; /* table index of key keyent */
287 unsigned short value_idx
; /* table index of value valent */
292 unsigned short hash_idx
; /* hash chain index for string */
293 unsigned short refcnt
; /* reference count */
294 unsigned short length
; /* length of string */
295 unsigned short string_off
; /* offset of string in text table */
300 unsigned short hash_idx
; /* hash chain index for string */
301 unsigned short refcnt
; /* reference count */
302 unsigned short length
; /* length of string */
303 unsigned short string_off
; /* offset of string in text table */
306 /* recursive helper function to display a directory tree [Internal] */
307 void _w31_dumptree(unsigned short idx
,unsigned char *txt
,struct _w31_tabent
*tab
,struct _w31_header
*head
,HKEY hkey
,time_t lastmodified
, int level
)
309 struct _w31_dirent
*dir
;
310 struct _w31_keyent
*key
;
311 struct _w31_valent
*val
;
313 static char tail
[400];
316 dir
=(struct _w31_dirent
*)&tab
[idx
];
319 key
= (struct _w31_keyent
*)&tab
[dir
->key_idx
];
321 memcpy(tail
,&txt
[key
->string_off
],key
->length
);
322 tail
[key
->length
]='\0';
323 /* all toplevel entries AND the entries in the
324 * toplevel subdirectory belong to \SOFTWARE\Classes
326 if (!level
&& !strcmp(tail
,".classes")) {
327 _w31_dumptree(dir
->child_idx
,txt
,tab
,head
,hkey
,lastmodified
,level
+1);
328 idx
=dir
->sibling_idx
;
331 if (subkey
) RegCloseKey( subkey
);
332 if (RegCreateKeyA( hkey
, tail
, &subkey
) != ERROR_SUCCESS
) subkey
= 0;
333 /* only add if leaf node or valued node */
334 if (dir
->value_idx
!=0||dir
->child_idx
==0) {
335 if (dir
->value_idx
) {
336 val
=(struct _w31_valent
*)&tab
[dir
->value_idx
];
337 memcpy(tail
,&txt
[val
->string_off
],val
->length
);
338 tail
[val
->length
]='\0';
339 RegSetValueA( subkey
, NULL
, REG_SZ
, tail
, 0 );
342 } else TRACE("strange: no directory key name, idx=%04x\n", idx
);
343 _w31_dumptree(dir
->child_idx
,txt
,tab
,head
,subkey
,lastmodified
,level
+1);
344 idx
=dir
->sibling_idx
;
346 if (subkey
) RegCloseKey( subkey
);
350 /******************************************************************************
351 * _w31_loadreg [Internal]
353 void _w31_loadreg(void)
356 struct _w31_header head
;
357 struct _w31_tabent
*tab
;
361 BY_HANDLE_FILE_INFORMATION hfinfo
;
366 hf
= OpenFile("reg.dat",&ofs
,OF_READ
);
367 if (hf
==HFILE_ERROR
) return;
369 /* read & dump header */
370 if (sizeof(head
)!=_lread(hf
,&head
,sizeof(head
))) {
371 ERR("reg.dat is too short.\n");
375 if (memcmp(head
.cookie
, "SHCC3.10", sizeof(head
.cookie
))!=0) {
376 ERR("reg.dat has bad signature.\n");
381 len
= head
.tabcnt
* sizeof(struct _w31_tabent
);
382 /* read and dump index table */
384 if (len
!=_lread(hf
,tab
,len
)) {
385 ERR("couldn't read %d bytes.\n",len
);
392 txt
= _xmalloc(head
.textsize
);
393 if (-1==_llseek(hf
,head
.textoff
,SEEK_SET
)) {
394 ERR("couldn't seek to textblock.\n");
400 if (head
.textsize
!=_lread(hf
,txt
,head
.textsize
)) {
401 ERR("textblock too short (%d instead of %ld).\n",len
,head
.textsize
);
408 if (!GetFileInformationByHandle(hf
,&hfinfo
)) {
409 ERR("GetFileInformationByHandle failed?.\n");
415 lastmodified
= DOSFS_FileTimeToUnixTime(&hfinfo
.ftLastWriteTime
,NULL
);
416 _w31_dumptree(tab
[0].w1
,txt
,tab
,&head
,HKEY_CLASSES_ROOT
,lastmodified
,0);
423 /***********************************************************************************/
424 /* windows 95 registry loader */
425 /***********************************************************************************/
427 /* SECTION 1: main header
431 #define W95_REG_CREG_ID 0x47455243
434 DWORD id
; /* "CREG" = W95_REG_CREG_ID */
435 DWORD version
; /* ???? 0x00010000 */
436 DWORD rgdb_off
; /* 0x08 Offset of 1st RGDB-block */
437 DWORD uk2
; /* 0x0c */
438 WORD rgdb_num
; /* 0x10 # of RGDB-blocks */
444 /* SECTION 2: Directory information (tree structure)
446 * once on offset 0x20
448 * structure: [rgkn][dke]* (repeat till last_dke is reached)
450 #define W95_REG_RGKN_ID 0x4e4b4752
453 DWORD id
; /*"RGKN" = W95_REG_RGKN_ID */
454 DWORD size
; /* Size of the RGKN-block */
455 DWORD root_off
; /* Rel. Offset of the root-record */
456 DWORD last_dke
; /* Offset to last DKE ? */
460 /* Disk Key Entry Structure
462 * the 1st entry in a "usual" registry file is a nul-entry with subkeys: the
463 * hive itself. It looks the same like other keys. Even the ID-number can
466 * The "hash"-value is a value representing the key's name. Windows will not
467 * search for the name, but for a matching hash-value. if it finds one, it
468 * will compare the actual string info, otherwise continue with the next key.
469 * To calculate the hash initialize a D-Word with 0 and add all ASCII-values
470 * of the string which are smaller than 0x80 (128) to this D-Word.
472 * If you want to modify key names, also modify the hash-values, since they
473 * cannot be found again (although they would be displayed in REGEDIT)
474 * End of list-pointers are filled with 0xFFFFFFFF
476 * Disk keys are layed out flat ... But, sometimes, nrLS and nrMS are both
477 * 0xFFFF, which means skipping over nextkeyoffset bytes (including this
478 * structure) and reading another RGDB_section.
480 * The last DKE (see field last_dke in _w95_rgkn) has only 3 DWORDs with
481 * 0x80000000 (EOL indicator ?) as x1, the hash value and 0xFFFFFFFF as x3.
482 * The remaining space between last_dke and the offset calculated from
483 * rgkn->size seems to be free for use for more dke:s.
484 * So it seems if more dke:s are added, they are added to that space and
485 * last_dke is grown, and in case that "free" space is out, the space
486 * gets grown and rgkn->size gets adjusted.
488 * there is a one to one relationship between dke and dkh
490 /* key struct, once per key */
492 DWORD x1
; /* Free entry indicator(?) */
493 DWORD hash
; /* sum of bytes of keyname */
494 DWORD x3
; /* Root key indicator? usually 0xFFFFFFFF */
495 DWORD prevlvl
; /* offset of previous key */
496 DWORD nextsub
; /* offset of child key */
497 DWORD next
; /* offset of sibling key */
498 WORD nrLS
; /* id inside the rgdb block */
499 WORD nrMS
; /* number of the rgdb block */
502 /* SECTION 3: key information, values and data
505 * section: [blocks]* (repeat creg->rgdb_num times)
506 * blocks: [rgdb] [subblocks]* (repeat till block size reached )
507 * subblocks: [dkh] [dkv]* (repeat dkh->values times )
509 * An interesting relationship exists in RGDB_section. The DWORD value
510 * at offset 0x10 equals the one at offset 0x04 minus the one at offset 0x08.
511 * I have no idea at the moment what this means. (Kevin Cozens)
514 /* block header, once per block */
515 #define W95_REG_RGDB_ID 0x42444752
518 DWORD id
; /* 0x00 'RGDB' = W95_REG_RGDB_ID */
519 DWORD size
; /* 0x04 */
520 DWORD uk1
; /* 0x08 */
521 DWORD uk2
; /* 0x0c */
522 DWORD uk3
; /* 0x10 */
523 DWORD uk4
; /* 0x14 */
524 DWORD uk5
; /* 0x18 */
525 DWORD uk6
; /* 0x1c */
529 /* Disk Key Header structure (RGDB part), once per key */
531 DWORD nextkeyoff
; /* 0x00 offset to next dkh */
532 WORD nrLS
; /* 0x04 id inside the rgdb block */
533 WORD nrMS
; /* 0x06 number of the rgdb block */
534 DWORD bytesused
; /* 0x08 */
535 WORD keynamelen
; /* 0x0c len of name */
536 WORD values
; /* 0x0e number of values */
537 DWORD xx1
; /* 0x10 */
538 char name
[1]; /* 0x14 */
539 /* dkv */ /* 0x14 + keynamelen */
542 /* Disk Key Value structure, once per value */
544 DWORD type
; /* 0x00 */
546 WORD valnamelen
; /* 0x08 length of name, 0 is default key */
547 WORD valdatalen
; /* 0x0A length of data */
548 char name
[1]; /* 0x0c */
549 /* raw data */ /* 0x0c + valnamelen */
552 /******************************************************************************
553 * _w95_lookup_dkh [Internal]
555 * seeks the dkh belonging to a dke
557 static _w95dkh
*_w95_lookup_dkh(_w95creg
*creg
,int nrLS
,int nrMS
)
563 /* get the beginning of the rgdb datastore */
564 rgdb
= (_w95rgdb
*)((char*)creg
+creg
->rgdb_off
);
566 /* check: requested block < last_block) */
567 if (creg
->rgdb_num
<= nrMS
) {
568 ERR("registry file corrupt! requested block no. beyond end.\n");
572 /* find the right block */
573 for(i
=0; i
<nrMS
;i
++) {
574 if(rgdb
->id
!= W95_REG_RGDB_ID
) { /* check the magic */
575 ERR("registry file corrupt! bad magic 0x%08lx\n", rgdb
->id
);
578 rgdb
= (_w95rgdb
*) ((char*)rgdb
+rgdb
->size
); /* find next block */
581 dkh
= (_w95dkh
*)(rgdb
+ 1); /* first sub block within the rgdb */
584 if(nrLS
==dkh
->nrLS
) return dkh
;
585 dkh
= (_w95dkh
*)((char*)dkh
+ dkh
->nextkeyoff
); /* find next subblock */
586 } while ((char *)dkh
< ((char*)rgdb
+rgdb
->size
));
592 /******************************************************************************
593 * _w95_dump_dkv [Internal]
595 static int _w95_dump_dkv(_w95dkh
*dkh
,int nrLS
,int nrMS
,FILE *f
)
600 /* first value block */
601 dkv
= (_w95dkv
*)((char*)dkh
+dkh
->keynamelen
+0x14);
603 /* loop through the values */
604 for (i
=0; i
< dkh
->values
; i
++) {
605 struct key_value value
;
608 value
.nameW
= _strdupnAtoW(dkv
->name
,dkv
->valnamelen
);
609 value
.type
= dkv
->type
;
610 value
.len
= dkv
->valdatalen
;
612 value
.data
= &(dkv
->name
[dkv
->valnamelen
]);
614 if ( (value
.type
==REG_SZ
) || (value
.type
==REG_EXPAND_SZ
) || (value
.type
==REG_MULTI_SZ
) ) {
615 pdata
= _strdupnAtoW(value
.data
,value
.len
);
618 if (pdata
!= NULL
) value
.data
= pdata
;
620 _dump_value(&value
,f
);
622 if (pdata
!= NULL
) free(pdata
);
625 dkv
= (_w95dkv
*)((char*)dkv
+dkv
->valnamelen
+dkv
->valdatalen
+0x0c);
630 /******************************************************************************
631 * _w95_dump_dke [Internal]
633 static int _w95_dump_dke(LPSTR key_name
,_w95creg
*creg
,_w95rgkn
*rgkn
,_w95dke
*dke
,FILE *f
,int level
)
636 LPSTR new_key_name
= NULL
;
638 /* special root key */
639 if (dke
->nrLS
== 0xffff || dke
->nrMS
==0xffff) /* eg. the root key has no name */
641 /* parse the one subkey */
642 if (dke
->nextsub
!= 0xffffffff) return _w95_dump_dke(key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->nextsub
),f
,level
);
643 /* has no sibling keys */
647 /* search subblock */
648 if (!(dkh
= _w95_lookup_dkh(creg
, dke
->nrLS
, dke
->nrMS
))) {
649 ERR("dke pointing to missing dkh !\n");
654 /* create new subkey name */
655 new_key_name
= _strdupnA(key_name
,strlen(key_name
)+dkh
->keynamelen
+1);
656 if (strcmp(new_key_name
,"") != 0) strcat(new_key_name
,"\\");
657 strncat(new_key_name
,dkh
->name
,dkh
->keynamelen
);
659 /* walk sibling keys */
660 if (dke
->next
!= 0xffffffff ) {
661 if (!_w95_dump_dke(key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->next
),f
,level
)) {
667 /* write the key path (something like [Software\\Microsoft\\..]) only if:
668 1) key has some values
669 2) key has no values and no subkeys
671 if (dkh
->values
> 0) {
672 /* there are some values */
674 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
676 if (!_w95_dump_dkv(dkh
, dke
->nrLS
, dke
->nrMS
,f
)) {
681 if ((dke
->nextsub
== 0xffffffff) && (dkh
->values
== 0)) {
682 /* no subkeys and no values */
684 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
687 } else new_key_name
= _strdupnA(key_name
,strlen(key_name
));
690 if (dke
->nextsub
!= 0xffffffff) {
691 if (!_w95_dump_dke(new_key_name
, creg
, rgkn
, (_w95dke
*)((char*)rgkn
+dke
->nextsub
),f
,level
-1)) {
700 /* end windows 95 loader */
702 /***********************************************************************************/
703 /* windows NT registry loader */
704 /***********************************************************************************/
706 /* NT REGISTRY LOADER */
708 #ifdef HAVE_SYS_MMAN_H
709 # include <sys/mman.h>
713 #define MAP_FAILED ((LPVOID)-1)
716 #define NT_REG_BLOCK_SIZE 0x1000
718 #define NT_REG_HEADER_BLOCK_ID 0x66676572 /* regf */
719 #define NT_REG_POOL_BLOCK_ID 0x6E696268 /* hbin */
720 #define NT_REG_KEY_BLOCK_ID 0x6b6e /* nk */
721 #define NT_REG_VALUE_BLOCK_ID 0x6b76 /* vk */
723 /* subblocks of nk */
724 #define NT_REG_HASH_BLOCK_ID 0x666c /* lf */
725 #define NT_REG_NOHASH_BLOCK_ID 0x696c /* li */
726 #define NT_REG_RI_BLOCK_ID 0x6972 /* ri */
728 #define NT_REG_KEY_BLOCK_TYPE 0x20
729 #define NT_REG_ROOT_KEY_BLOCK_TYPE 0x2c
732 DWORD id
; /* 0x66676572 'regf'*/
733 DWORD uk1
; /* 0x04 */
734 DWORD uk2
; /* 0x08 */
735 FILETIME DateModified
; /* 0x0c */
736 DWORD uk3
; /* 0x14 */
737 DWORD uk4
; /* 0x18 */
738 DWORD uk5
; /* 0x1c */
739 DWORD uk6
; /* 0x20 */
740 DWORD RootKeyBlock
; /* 0x24 */
741 DWORD BlockSize
; /* 0x28 */
743 DWORD Checksum
; /* at offset 0x1FC */
752 DWORD id
; /* 0x6E696268 'hbin' */
756 DWORD uk2
; /* 0x10 */
757 DWORD uk3
; /* 0x14 */
758 DWORD uk4
; /* 0x18 */
759 DWORD size
; /* 0x1C */
760 nt_hbin_sub hbin_sub
; /* 0x20 */
764 * the value_list consists of offsets to the values (vk)
767 WORD SubBlockId
; /* 0x00 0x6B6E */
768 WORD Type
; /* 0x02 for the root-key: 0x2C, otherwise 0x20*/
769 FILETIME writetime
; /* 0x04 */
770 DWORD uk1
; /* 0x0C */
771 DWORD parent_off
; /* 0x10 Offset of Owner/Parent key */
772 DWORD nr_subkeys
; /* 0x14 number of sub-Keys */
773 DWORD uk8
; /* 0x18 */
774 DWORD lf_off
; /* 0x1C Offset of the sub-key lf-Records */
775 DWORD uk2
; /* 0x20 */
776 DWORD nr_values
; /* 0x24 number of values */
777 DWORD valuelist_off
; /* 0x28 Offset of the Value-List */
778 DWORD off_sk
; /* 0x2c Offset of the sk-Record */
779 DWORD off_class
; /* 0x30 Offset of the Class-Name */
780 DWORD uk3
; /* 0x34 */
781 DWORD uk4
; /* 0x38 */
782 DWORD uk5
; /* 0x3c */
783 DWORD uk6
; /* 0x40 */
784 DWORD uk7
; /* 0x44 */
785 WORD name_len
; /* 0x48 name-length */
786 WORD class_len
; /* 0x4a class-name length */
787 char name
[1]; /* 0x4c key-name */
791 DWORD off_nk
; /* 0x00 */
792 DWORD name
; /* 0x04 */
796 WORD id
; /* 0x00 0x666c */
797 WORD nr_keys
; /* 0x06 */
798 hash_rec hash_rec
[1];
802 list of subkeys without hash
809 WORD id
; /* 0x00 0x696c */
815 this is a intermediate node
826 WORD id
; /* 0x00 0x6972 */
827 WORD nr_li
; /* 0x02 number off offsets */
828 DWORD off_li
[1]; /* 0x04 points to li */
832 WORD id
; /* 0x00 'vk' */
846 * 0 value is a default value
847 * 1 the value has a name
850 * len of the whole data block
852 * bytes including the terminating \0 = 2*(number_of_chars+1)
853 * - reg_dword, reg_binary:
854 * if highest bit of data_len is set data_off contains the value
856 static int _nt_dump_vk(LPSTR key_name
, char *base
, nt_vk
*vk
,FILE *f
)
858 BYTE
*pdata
= (BYTE
*)(base
+vk
->data_off
+4); /* start of data */
859 struct key_value value
;
861 if (vk
->id
!= NT_REG_VALUE_BLOCK_ID
) {
862 ERR("unknown block found (0x%04x), please report!\n", vk
->id
);
866 value
.nameW
= _strdupnAtoW(vk
->name
,vk
->nam_len
);
867 value
.type
= vk
->type
;
868 value
.len
= (vk
->data_len
& 0x7fffffff);
869 value
.data
= (vk
->data_len
& 0x80000000) ? (LPBYTE
)&(vk
->data_off
): pdata
;
871 _dump_value(&value
,f
);
877 /* it's called from _nt_dump_lf() */
878 static int _nt_dump_nk(LPSTR key_name
,char *base
,nt_nk
*nk
,FILE *f
,int level
);
883 * this structure contains the hash of a keyname and points to all
886 * exception: if the id is 'il' there are no hash values and every
889 static int _nt_dump_lf(LPSTR key_name
, char *base
, int subkeys
, nt_lf
*lf
, FILE *f
, int level
)
893 if (lf
->id
== NT_REG_HASH_BLOCK_ID
) {
894 if (subkeys
!= lf
->nr_keys
) goto error1
;
896 for (i
=0; i
<lf
->nr_keys
; i
++)
897 if (!_nt_dump_nk(key_name
, base
, (nt_nk
*)(base
+lf
->hash_rec
[i
].off_nk
+4), f
, level
)) goto error
;
898 } else if (lf
->id
== NT_REG_NOHASH_BLOCK_ID
) {
899 nt_li
* li
= (nt_li
*)lf
;
900 if (subkeys
!= li
->nr_keys
) goto error1
;
902 for (i
=0; i
<li
->nr_keys
; i
++)
903 if (!_nt_dump_nk(key_name
, base
, (nt_nk
*)(base
+li
->off_nk
[i
]+4), f
, level
)) goto error
;
904 } else if (lf
->id
== NT_REG_RI_BLOCK_ID
) { /* ri */
905 nt_ri
* ri
= (nt_ri
*)lf
;
908 /* count all subkeys */
909 for (i
=0; i
<ri
->nr_li
; i
++) {
910 nt_li
* li
= (nt_li
*)(base
+ri
->off_li
[i
]+4);
911 if(li
->id
!= NT_REG_NOHASH_BLOCK_ID
) goto error2
;
912 li_subkeys
+= li
->nr_keys
;
916 if (subkeys
!= li_subkeys
) goto error1
;
918 /* loop through the keys */
919 for (i
=0; i
<ri
->nr_li
; i
++) {
920 nt_li
*li
= (nt_li
*)(base
+ri
->off_li
[i
]+4);
921 if (!_nt_dump_lf(key_name
, base
, li
->nr_keys
, (nt_lf
*)li
, f
, level
)) goto error
;
928 if (lf
->id
== 0x686c)
929 FIXME("unknown Win XP node id 0x686c: do we need to add support for it ?\n");
931 ERR("unknown node id 0x%04x, please report!\n", lf
->id
);
935 ERR("registry file corrupt! (inconsistent number of subkeys)\n");
939 ERR("error reading lf block\n");
943 /* _nt_dump_nk [Internal] */
944 static int _nt_dump_nk(LPSTR key_name
,char *base
,nt_nk
*nk
,FILE *f
,int level
)
948 LPSTR new_key_name
= NULL
;
950 TRACE("%s\n", key_name
);
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
)
1052 all
= !PROFILE_GetWineIniBool("registry","SaveOnlyUpdatedKeys",1);
1053 PROFILE_GetWineIniString( "registry", "PeriodicSave", "", buffer
, sizeof(buffer
) );
1054 if (buffer
[0]) period
= atoi(buffer
);
1056 /* set saving level (0 for saving everything, 1 for saving only modified keys) */
1057 _set_registry_levels(1,!all
,period
*1000);
1059 if (PROFILE_GetWineIniBool("registry","WritetoHomeRegistryFiles",1))
1061 _save_at_exit(HKEY_CURRENT_USER
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1062 _save_at_exit(HKEY_LOCAL_MACHINE
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1063 _save_at_exit(hkey_users_default
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1068 /******************************************************************************
1069 * _allocate_default_keys [Internal]
1070 * Registry initialisation, allocates some default keys.
1072 static void _allocate_default_keys(void) {
1078 RegCreateKeyA(HKEY_DYN_DATA
,"PerfStats\\StatData",&hkey
);
1081 /* This was an Open, but since it is called before the real registries
1082 are loaded, it was changed to a Create - MTB 980507*/
1083 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System",&hkey
);
1084 RegSetValueExA(hkey
,"Identifier",0,REG_SZ
,"SystemType WINE",strlen("SystemType WINE"));
1087 /* \\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion
1089 * CurrentBuildNumber
1091 * string RegisteredOwner
1092 * string RegisteredOrganization
1095 /* System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent
1097 * string SysLocation
1100 if (-1!=gethostname(buf
,200)) {
1101 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",&hkey
);
1102 RegSetValueExA(hkey
,"ComputerName",0,REG_SZ
,buf
,strlen(buf
)+1);
1106 RegCreateKeyA(HKEY_USERS
,".Default",&hkey
);
1110 #define REG_DONTLOAD -1
1115 /* return the type of native registry [Internal] */
1116 static int _get_reg_type(void)
1118 char windir
[MAX_PATHNAME_LEN
];
1119 char tmp
[MAX_PATHNAME_LEN
];
1120 int ret
= REG_WIN31
;
1122 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1124 /* test %windir%/system32/config/system --> winnt */
1125 strcpy(tmp
, windir
);
1126 strncat(tmp
, "\\system32\\config\\system", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1127 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1132 /* test %windir%/system.dat --> win95 */
1133 strcpy(tmp
, windir
);
1134 strncat(tmp
, "\\system.dat", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1135 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1140 if ((ret
== REG_WINNT
) && (!PROFILE_GetWineIniString( "Wine", "Profile", "", tmp
, MAX_PATHNAME_LEN
))) {
1141 MESSAGE("When you are running with a native NT directory specify\n");
1142 MESSAGE("'Profile=<profiledirectory>' or disable loading of Windows\n");
1143 MESSAGE("registry (LoadWindowsRegistryFiles=N)\n");
1150 #define WINE_REG_VER_ERROR -1
1151 #define WINE_REG_VER_1 0
1152 #define WINE_REG_VER_2 1
1153 #define WINE_REG_VER_OLD 2
1154 #define WINE_REG_VER_UNKNOWN 3
1156 /* return the version of wine registry file [Internal] */
1157 static int _get_wine_registry_file_format_version(LPCSTR fn
)
1163 if ((f
=fopen(fn
,"rt")) == NULL
) {
1164 WARN("Couldn't open %s for reading: %s\n",fn
,strerror(errno
));
1165 return WINE_REG_VER_ERROR
;
1168 if (fgets(tmp
,50,f
) == NULL
) {
1169 WARN("Error reading %s: %s\n",fn
,strerror(errno
));
1171 return WINE_REG_VER_ERROR
;
1175 if (sscanf(tmp
,"WINE REGISTRY Version %d",&ver
) != 1) return WINE_REG_VER_UNKNOWN
;
1178 return WINE_REG_VER_1
;
1181 return WINE_REG_VER_2
;
1184 return WINE_REG_VER_UNKNOWN
;
1188 /* load the registry file in wine format [Internal] */
1189 static void load_wine_registry(HKEY hkey
,LPCSTR fn
)
1193 file_format
= _get_wine_registry_file_format_version(fn
);
1194 switch (file_format
) {
1196 case WINE_REG_VER_1
:
1197 WARN("Unable to load registry file %s: old format which is no longer supported.\n",fn
);
1200 case WINE_REG_VER_2
: {
1202 if ((file
= FILE_CreateFile( fn
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1203 FILE_ATTRIBUTE_NORMAL
, 0, TRUE
, DRIVE_UNKNOWN
)))
1205 SERVER_START_REQ( load_registry
)
1209 wine_server_call( req
);
1212 CloseHandle( file
);
1217 case WINE_REG_VER_UNKNOWN
:
1218 WARN("Unable to load registry file %s: unknown format.\n",fn
);
1221 case WINE_REG_VER_ERROR
:
1226 /* generate and return the name of the tmp file and associated stream [Internal] */
1227 static LPSTR
_get_tmp_fn(FILE **f
)
1234 sprintf(ret
,"/tmp/reg%lx%04x.tmp",(long)getpid(),count
++);
1235 if ((tmp_fd
= open(ret
,O_CREAT
| O_EXCL
| O_WRONLY
,0666)) != -1) break;
1236 if (errno
!= EEXIST
) {
1237 ERR("Unexpected error while open() call: %s\n",strerror(errno
));
1244 if ((*f
= fdopen(tmp_fd
,"w")) == NULL
) {
1245 ERR("Unexpected error while fdopen() call: %s\n",strerror(errno
));
1254 /* convert win95 native registry file to wine format [Internal] */
1255 static LPSTR
_convert_win95_registry_to_wine_format(LPCSTR fn
,int level
)
1259 DOS_FULL_NAME full_name
;
1266 _w95dke
*dke
, *root_dke
;
1268 if (!DOSFS_GetFullName( fn
, 0, &full_name
)) return NULL
;
1270 /* map the registry into the memory */
1271 if ((fd
= open(full_name
.long_name
, O_RDONLY
| O_NONBLOCK
)) == -1) return NULL
;
1272 if ((fstat(fd
, &st
) == -1)) goto error1
;
1273 if (!st
.st_size
) goto error1
;
1274 if ((base
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == MAP_FAILED
) goto error1
;
1276 /* control signature */
1277 if (*(LPDWORD
)base
!= W95_REG_CREG_ID
) {
1278 ERR("unable to load native win95 registry file %s: unknown signature.\n",fn
);
1283 /* load the header (rgkn) */
1284 rgkn
= (_w95rgkn
*)(creg
+ 1);
1285 if (rgkn
->id
!= W95_REG_RGKN_ID
) {
1286 ERR("second IFF header not RGKN, but %lx\n", rgkn
->id
);
1289 if (rgkn
->root_off
!= 0x20) {
1290 ERR("rgkn->root_off not 0x20, please report !\n");
1293 if (rgkn
->last_dke
> rgkn
->size
)
1295 ERR("registry file corrupt! last_dke > size!\n");
1298 /* verify last dke */
1299 dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->last_dke
);
1300 if (dke
->x1
!= 0x80000000)
1302 ERR("last dke invalid !\n");
1305 if (rgkn
->size
> creg
->rgdb_off
)
1307 ERR("registry file corrupt! rgkn size > rgdb_off !\n");
1310 root_dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->root_off
);
1311 if ( (root_dke
->prevlvl
!= 0xffffffff) || (root_dke
->next
!= 0xffffffff) )
1313 ERR("registry file corrupt! invalid root dke !\n");
1317 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1318 fprintf(f
,"WINE REGISTRY Version 2");
1319 _w95_dump_dke("",creg
,rgkn
,root_dke
,f
,level
);
1324 ERR("Unable to load native win95 registry file %s.\n",fn
);
1325 ERR("Please report this.\n");
1326 ERR("Make a backup of the file, run a good reg cleaner program and try again!\n");
1329 munmap(base
, st
.st_size
);
1335 /* convert winnt native registry file to wine format [Internal] */
1336 static LPSTR
_convert_winnt_registry_to_wine_format(LPCSTR fn
,int level
)
1346 nt_hbin_sub
*hbin_sub
;
1351 hFile
= CreateFileA( fn
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
1352 if ( hFile
== INVALID_HANDLE_VALUE
) return NULL
;
1353 hMapping
= CreateFileMappingA( hFile
, NULL
, PAGE_READONLY
|SEC_COMMIT
, 0, 0, NULL
);
1354 if (!hMapping
) goto error1
;
1355 base
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
1356 CloseHandle( hMapping
);
1357 if (!base
) goto error1
;
1359 /* control signature */
1360 if (*(LPDWORD
)base
!= NT_REG_HEADER_BLOCK_ID
) {
1361 ERR("unable to load native winnt registry file %s: unknown signature.\n",fn
);
1369 hbin
= (nt_hbin
*)((char*) base
+ 0x1000);
1370 if (hbin
->id
!= NT_REG_POOL_BLOCK_ID
) {
1371 ERR( "hbin block invalid\n");
1375 /* hbin_sub block */
1376 hbin_sub
= (nt_hbin_sub
*)&(hbin
->hbin_sub
);
1377 if ((hbin_sub
->data
[0] != 'n') || (hbin_sub
->data
[1] != 'k')) {
1378 ERR( "hbin_sub block invalid\n");
1383 nk
= (nt_nk
*)&(hbin_sub
->data
[0]);
1384 if (nk
->Type
!= NT_REG_ROOT_KEY_BLOCK_TYPE
) {
1385 ERR( "special nk block not found\n");
1389 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1390 fprintf(f
,"WINE REGISTRY Version 2");
1391 _nt_dump_nk("",(char*)base
+0x1000,nk
,f
,level
);
1395 UnmapViewOfFile( base
);
1401 /* convert native registry to wine format and load it via server call [Internal] */
1402 static void _convert_and_load_native_registry(LPCSTR fn
,HKEY hkey
,int reg_type
,int level
)
1408 /* FIXME: following function doesn't really convert yet */
1409 tmp
= _convert_winnt_registry_to_wine_format(fn
,level
);
1412 tmp
= _convert_win95_registry_to_wine_format(fn
,level
);
1415 ERR("Don't know how to convert native 3.1 registry yet.\n");
1418 ERR("Unknown registry format parameter (%d)\n",reg_type
);
1423 load_wine_registry(hkey
,tmp
);
1424 TRACE("File %s successfully converted to %s and loaded to registry.\n",fn
,tmp
);
1427 else WARN("Unable to convert %s (doesn't exist?)\n",fn
);
1431 /* load all native windows registry files [Internal] */
1432 static void _load_windows_registry( HKEY hkey_users_default
)
1435 char windir
[MAX_PATHNAME_LEN
];
1436 char path
[MAX_PATHNAME_LEN
];
1438 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1440 reg_type
= _get_reg_type();
1445 /* user specific ntuser.dat */
1446 if (PROFILE_GetWineIniString( "Wine", "Profile", "", path
, MAX_PATHNAME_LEN
)) {
1447 strcat(path
,"\\ntuser.dat");
1448 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WINNT
,1);
1451 /* default user.dat */
1452 if (hkey_users_default
) {
1453 strcpy(path
,windir
);
1454 strcat(path
,"\\system32\\config\\default");
1455 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WINNT
,1);
1460 * map HLM\System\ControlSet001 to HLM\System\CurrentControlSet
1463 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SYSTEM", &hkey
)) {
1464 strcpy(path
,windir
);
1465 strcat(path
,"\\system32\\config\\system");
1466 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1470 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE", &hkey
)) {
1471 strcpy(path
,windir
);
1472 strcat(path
,"\\system32\\config\\software");
1473 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1477 strcpy(path
,windir
);
1478 strcat(path
,"\\system32\\config\\sam");
1479 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1481 strcpy(path
,windir
);
1482 strcat(path
,"\\system32\\config\\security");
1483 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1485 /* this key is generated when the nt-core booted successfully */
1486 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\Clone",&hkey
)) RegCloseKey(hkey
);
1491 _convert_and_load_native_registry("c:\\system.1st",HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1493 strcpy(path
,windir
);
1494 strcat(path
,"\\system.dat");
1495 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1497 strcpy(path
,windir
);
1498 strcat(path
,"\\classes.dat");
1499 _convert_and_load_native_registry(path
,HKEY_CLASSES_ROOT
,REG_WIN95
,0);
1501 if (PROFILE_GetWineIniString("Wine","Profile","",path
,MAX_PATHNAME_LEN
)) {
1502 /* user specific user.dat */
1503 strncat(path
, "\\user.dat", MAX_PATHNAME_LEN
- strlen(path
) - 1);
1504 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1506 /* default user.dat */
1507 if (hkey_users_default
) {
1508 strcpy(path
,windir
);
1509 strcat(path
,"\\user.dat");
1510 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WIN95
,1);
1513 strcpy(path
,windir
);
1514 strcat(path
,"\\user.dat");
1515 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1520 /* FIXME: here we should convert to *.reg file supported by server and call REQ_LOAD_REGISTRY, see REG_WIN95 case */
1525 TRACE("REG_DONTLOAD\n");
1529 ERR("switch: no match (%d)\n",reg_type
);
1535 /* load global registry files (stored in /etc/wine) [Internal] */
1536 static void _load_global_registry(void)
1540 /* Load the global HKU hive directly from sysconfdir */
1541 load_wine_registry( HKEY_USERS
, SAVE_GLOBAL_REGBRANCH_USER_DEFAULT
);
1543 /* Load the global machine defaults directly from sysconfdir */
1544 load_wine_registry( HKEY_LOCAL_MACHINE
, SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE
);
1547 /* load home registry files (stored in ~/.wine) [Internal] */
1548 static void _load_home_registry( HKEY hkey_users_default
)
1550 LPCSTR confdir
= get_config_dir();
1551 LPSTR tmp
= _xmalloc(strlen(confdir
)+20);
1553 strcpy(tmp
,confdir
);
1554 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1555 load_wine_registry(hkey_users_default
,tmp
);
1557 strcpy(tmp
,confdir
);
1558 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1559 load_wine_registry(HKEY_CURRENT_USER
,tmp
);
1561 strcpy(tmp
,confdir
);
1562 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1563 load_wine_registry(HKEY_LOCAL_MACHINE
,tmp
);
1568 /* load all registry (native and global and home) */
1569 void SHELL_LoadRegistry( void )
1571 HKEY hkey_users_default
;
1575 if (!CLIENT_IsBootThread()) return; /* already loaded */
1577 if (RegCreateKeyA(HKEY_USERS
,".Default",&hkey_users_default
))
1579 ERR("Cannot create HKEY_USERS/.Default\n" );
1583 _allocate_default_keys();
1584 _set_registry_levels(0,0,0);
1585 if (PROFILE_GetWineIniBool("Registry","LoadWindowsRegistryFiles",1))
1586 _load_windows_registry( hkey_users_default
);
1587 if (PROFILE_GetWineIniBool("Registry","LoadGlobalRegistryFiles",1))
1588 _load_global_registry();
1589 _set_registry_levels(1,0,0);
1590 if (PROFILE_GetWineIniBool("Registry","LoadHomeRegistryFiles",1))
1591 _load_home_registry( hkey_users_default
);
1592 _init_registry_saving( hkey_users_default
);
1593 RegCloseKey(hkey_users_default
);
1596 /***************************************************************************/
1598 /***************************************************************************/
1600 /******************************************************************************
1601 * RegFlushKey [ADVAPI32.@]
1602 * Immediately writes key to registry.
1603 * Only returns after data has been written to disk.
1605 * FIXME: does it really wait until data is written ?
1608 * hkey [I] Handle of key to write
1611 * Success: ERROR_SUCCESS
1612 * Failure: Error code
1614 DWORD WINAPI
RegFlushKey( HKEY hkey
)
1616 FIXME( "(%x): stub\n", hkey
);
1617 return ERROR_SUCCESS
;
1621 /******************************************************************************
1622 * RegUnLoadKeyA [ADVAPI32.@]
1624 LONG WINAPI
RegUnLoadKeyA( HKEY hkey
, LPCSTR lpSubKey
)
1626 FIXME("(%x,%s): stub\n",hkey
, debugstr_a(lpSubKey
));
1627 return ERROR_SUCCESS
;
1631 /******************************************************************************
1632 * RegReplaceKeyA [ADVAPI32.@]
1634 LONG WINAPI
RegReplaceKeyA( HKEY hkey
, LPCSTR lpSubKey
, LPCSTR lpNewFile
,
1637 FIXME("(%x,%s,%s,%s): stub\n", hkey
, debugstr_a(lpSubKey
),
1638 debugstr_a(lpNewFile
),debugstr_a(lpOldFile
));
1639 return ERROR_SUCCESS
;
1647 /* 16-bit functions */
1649 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
1650 * some programs. Do not remove those cases. -MM
1652 static inline void fix_win16_hkey( HKEY
*hkey
)
1654 if (*hkey
== 0 || *hkey
== 1) *hkey
= HKEY_CLASSES_ROOT
;
1657 /******************************************************************************
1658 * RegEnumKey [KERNEL.216]
1659 * RegEnumKey [SHELL.7]
1661 DWORD WINAPI
RegEnumKey16( HKEY hkey
, DWORD index
, LPSTR name
, DWORD name_len
)
1663 fix_win16_hkey( &hkey
);
1664 return RegEnumKeyA( hkey
, index
, name
, name_len
);
1667 /******************************************************************************
1668 * RegOpenKey [KERNEL.217]
1669 * RegOpenKey [SHELL.1]
1671 DWORD WINAPI
RegOpenKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1673 fix_win16_hkey( &hkey
);
1674 return RegOpenKeyA( hkey
, name
, retkey
);
1677 /******************************************************************************
1678 * RegCreateKey [KERNEL.218]
1679 * RegCreateKey [SHELL.2]
1681 DWORD WINAPI
RegCreateKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1683 fix_win16_hkey( &hkey
);
1684 return RegCreateKeyA( hkey
, name
, retkey
);
1687 /******************************************************************************
1688 * RegDeleteKey [KERNEL.219]
1689 * RegDeleteKey [SHELL.4]
1691 DWORD WINAPI
RegDeleteKey16( HKEY hkey
, LPCSTR name
)
1693 fix_win16_hkey( &hkey
);
1694 return RegDeleteKeyA( hkey
, name
);
1697 /******************************************************************************
1698 * RegCloseKey [KERNEL.220]
1699 * RegCloseKey [SHELL.3]
1701 DWORD WINAPI
RegCloseKey16( HKEY hkey
)
1703 fix_win16_hkey( &hkey
);
1704 return RegCloseKey( hkey
);
1707 /******************************************************************************
1708 * RegSetValue [KERNEL.221]
1709 * RegSetValue [SHELL.5]
1711 DWORD WINAPI
RegSetValue16( HKEY hkey
, LPCSTR name
, DWORD type
, LPCSTR data
, DWORD count
)
1713 fix_win16_hkey( &hkey
);
1714 return RegSetValueA( hkey
, name
, type
, data
, count
);
1717 /******************************************************************************
1718 * RegDeleteValue [KERNEL.222]
1720 DWORD WINAPI
RegDeleteValue16( HKEY hkey
, LPSTR name
)
1722 fix_win16_hkey( &hkey
);
1723 return RegDeleteValueA( hkey
, name
);
1726 /******************************************************************************
1727 * RegEnumValue [KERNEL.223]
1729 DWORD WINAPI
RegEnumValue16( HKEY hkey
, DWORD index
, LPSTR value
, LPDWORD val_count
,
1730 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
1732 fix_win16_hkey( &hkey
);
1733 return RegEnumValueA( hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
1736 /******************************************************************************
1737 * RegQueryValue [KERNEL.224]
1738 * RegQueryValue [SHELL.6]
1741 * Is this HACK still applicable?
1744 * The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just
1745 * mask out the high 16 bit. This (not so much incidently) hopefully fixes
1748 DWORD WINAPI
RegQueryValue16( HKEY hkey
, LPCSTR name
, LPSTR data
, LPDWORD count
)
1750 fix_win16_hkey( &hkey
);
1751 if (count
) *count
&= 0xffff;
1752 return RegQueryValueA( hkey
, name
, data
, count
);
1755 /******************************************************************************
1756 * RegQueryValueEx [KERNEL.225]
1758 DWORD WINAPI
RegQueryValueEx16( HKEY hkey
, LPCSTR name
, LPDWORD reserved
, LPDWORD type
,
1759 LPBYTE data
, LPDWORD count
)
1761 fix_win16_hkey( &hkey
);
1762 return RegQueryValueExA( hkey
, name
, reserved
, type
, data
, count
);
1765 /******************************************************************************
1766 * RegSetValueEx [KERNEL.226]
1768 DWORD WINAPI
RegSetValueEx16( HKEY hkey
, LPCSTR name
, DWORD reserved
, DWORD type
,
1769 CONST BYTE
*data
, DWORD count
)
1771 fix_win16_hkey( &hkey
);
1772 if (!count
&& (type
==REG_SZ
)) count
= strlen(data
);
1773 return RegSetValueExA( hkey
, name
, reserved
, type
, data
, count
);
1776 /******************************************************************************
1777 * RegFlushKey [KERNEL.227]
1779 DWORD WINAPI
RegFlushKey16( HKEY hkey
)
1781 fix_win16_hkey( &hkey
);
1782 return RegFlushKey( hkey
);