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*
43 #include <sys/types.h>
46 #ifdef HAVE_SYS_MMAN_H
47 # include <sys/mman.h>
54 #include "wine/winbase16.h"
55 #include "wine/server.h"
56 #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
;
951 if (nk
->SubBlockId
!= NT_REG_KEY_BLOCK_ID
) {
952 ERR("unknown node id 0x%04x, please report!\n", nk
->SubBlockId
);
956 if ((nk
->Type
!=NT_REG_ROOT_KEY_BLOCK_TYPE
) && (((nt_nk
*)(base
+nk
->parent_off
+4))->SubBlockId
!= NT_REG_KEY_BLOCK_ID
)) {
957 ERR("registry file corrupt!\n");
961 /* create the new key */
963 /* create new subkey name */
964 new_key_name
= _strdupnA(key_name
,strlen(key_name
)+nk
->name_len
+1);
965 if (strcmp(new_key_name
,"") != 0) strcat(new_key_name
,"\\");
966 strncat(new_key_name
,nk
->name
,nk
->name_len
);
968 /* write the key path (something like [Software\\Microsoft\\..]) only if:
969 1) key has some values
970 2) key has no values and no subkeys
972 if (nk
->nr_values
> 0) {
973 /* there are some values */
975 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
978 if ((nk
->nr_subkeys
== 0) && (nk
->nr_values
== 0)) {
979 /* no subkeys and no values */
981 _dump_strAtoW(new_key_name
,strlen(new_key_name
),f
,"[]");
985 /* loop trough the value list */
986 vl
= (DWORD
*)(base
+nk
->valuelist_off
+4);
987 for (n
=0; n
<nk
->nr_values
; n
++) {
988 nt_vk
* vk
= (nt_vk
*)(base
+vl
[n
]+4);
989 if (!_nt_dump_vk(new_key_name
, base
, vk
, f
)) {
994 } else new_key_name
= _strdupnA(key_name
,strlen(key_name
));
996 /* loop through the subkeys */
997 if (nk
->nr_subkeys
) {
998 nt_lf
*lf
= (nt_lf
*)(base
+nk
->lf_off
+4);
999 if (!_nt_dump_lf(new_key_name
, base
, nk
->nr_subkeys
, lf
, f
, level
-1)) {
1011 /**********************************************************************************
1012 * _set_registry_levels [Internal]
1014 * set level to 0 for loading system files
1015 * set level to 1 for loading user files
1017 static void _set_registry_levels(int level
,int saving
,int period
)
1019 SERVER_START_REQ( set_registry_levels
)
1021 req
->current
= level
;
1022 req
->saving
= saving
;
1023 req
->period
= period
;
1024 wine_server_call( req
);
1029 /* _save_at_exit [Internal] */
1030 static void _save_at_exit(HKEY hkey
,LPCSTR path
)
1032 LPCSTR confdir
= get_config_dir();
1034 SERVER_START_REQ( save_registry_atexit
)
1037 wine_server_add_data( req
, confdir
, strlen(confdir
) );
1038 wine_server_add_data( req
, path
, strlen(path
)+1 );
1039 wine_server_call( req
);
1044 /* configure save files and start the periodic saving timer [Internal] */
1045 static void _init_registry_saving( HKEY hkey_users_default
)
1050 all
= PROFILE_GetWineIniBool("registry","SaveOnlyUpdatedKeys",1);
1051 period
= PROFILE_GetWineIniInt("registry","PeriodicSave",0);
1053 /* set saving level (0 for saving everything, 1 for saving only modified keys) */
1054 _set_registry_levels(1,!all
,period
*1000);
1056 if (PROFILE_GetWineIniBool("registry","WritetoHomeRegistryFiles",1))
1058 _save_at_exit(HKEY_CURRENT_USER
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1059 _save_at_exit(HKEY_LOCAL_MACHINE
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1060 _save_at_exit(hkey_users_default
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1065 /******************************************************************************
1066 * _allocate_default_keys [Internal]
1067 * Registry initialisation, allocates some default keys.
1069 static void _allocate_default_keys(void) {
1075 RegCreateKeyA(HKEY_DYN_DATA
,"PerfStats\\StatData",&hkey
);
1078 /* This was an Open, but since it is called before the real registries
1079 are loaded, it was changed to a Create - MTB 980507*/
1080 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System",&hkey
);
1081 RegSetValueExA(hkey
,"Identifier",0,REG_SZ
,"SystemType WINE",strlen("SystemType WINE"));
1084 /* \\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion
1086 * CurrentBuildNumber
1088 * string RegisteredOwner
1089 * string RegisteredOrganization
1092 /* System\\CurrentControlSet\\Services\\SNMP\\Parameters\\RFC1156Agent
1094 * string SysLocation
1097 if (-1!=gethostname(buf
,200)) {
1098 RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",&hkey
);
1099 RegSetValueExA(hkey
,"ComputerName",0,REG_SZ
,buf
,strlen(buf
)+1);
1103 RegCreateKeyA(HKEY_USERS
,".Default",&hkey
);
1107 #define REG_DONTLOAD -1
1112 /* return the type of native registry [Internal] */
1113 static int _get_reg_type(void)
1115 char windir
[MAX_PATHNAME_LEN
];
1116 char tmp
[MAX_PATHNAME_LEN
];
1117 int ret
= REG_WIN31
;
1119 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1121 /* test %windir%/system32/config/system --> winnt */
1122 strcpy(tmp
, windir
);
1123 strncat(tmp
, "\\system32\\config\\system", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1124 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1129 /* test %windir%/system.dat --> win95 */
1130 strcpy(tmp
, windir
);
1131 strncat(tmp
, "\\system.dat", MAX_PATHNAME_LEN
- strlen(tmp
) - 1);
1132 if(GetFileAttributesA(tmp
) != (DWORD
)-1) {
1137 if ((ret
== REG_WINNT
) && (!PROFILE_GetWineIniString( "Wine", "Profile", "", tmp
, MAX_PATHNAME_LEN
))) {
1138 MESSAGE("When you are running with a native NT directory specify\n");
1139 MESSAGE("'Profile=<profiledirectory>' or disable loading of Windows\n");
1140 MESSAGE("registry (LoadWindowsRegistryFiles=N)\n");
1147 #define WINE_REG_VER_ERROR -1
1148 #define WINE_REG_VER_1 0
1149 #define WINE_REG_VER_2 1
1150 #define WINE_REG_VER_OLD 2
1151 #define WINE_REG_VER_UNKNOWN 3
1153 /* return the version of wine registry file [Internal] */
1154 static int _get_wine_registry_file_format_version(LPCSTR fn
)
1160 if ((f
=fopen(fn
,"rt")) == NULL
) {
1161 WARN("Couldn't open %s for reading: %s\n",fn
,strerror(errno
));
1162 return WINE_REG_VER_ERROR
;
1165 if (fgets(tmp
,50,f
) == NULL
) {
1166 WARN("Error reading %s: %s\n",fn
,strerror(errno
));
1168 return WINE_REG_VER_ERROR
;
1172 if (sscanf(tmp
,"WINE REGISTRY Version %d",&ver
) != 1) return WINE_REG_VER_UNKNOWN
;
1175 return WINE_REG_VER_1
;
1178 return WINE_REG_VER_2
;
1181 return WINE_REG_VER_UNKNOWN
;
1185 /* load the registry file in wine format [Internal] */
1186 static void load_wine_registry(HKEY hkey
,LPCSTR fn
)
1190 file_format
= _get_wine_registry_file_format_version(fn
);
1191 switch (file_format
) {
1193 case WINE_REG_VER_1
:
1194 WARN("Unable to load registry file %s: old format which is no longer supported.\n",fn
);
1197 case WINE_REG_VER_2
: {
1199 if ((file
= FILE_CreateFile( fn
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1200 FILE_ATTRIBUTE_NORMAL
, 0, TRUE
, DRIVE_UNKNOWN
)))
1202 SERVER_START_REQ( load_registry
)
1206 wine_server_call( req
);
1209 CloseHandle( file
);
1214 case WINE_REG_VER_UNKNOWN
:
1215 WARN("Unable to load registry file %s: unknown format.\n",fn
);
1218 case WINE_REG_VER_ERROR
:
1223 /* generate and return the name of the tmp file and associated stream [Internal] */
1224 static LPSTR
_get_tmp_fn(FILE **f
)
1231 sprintf(ret
,"/tmp/reg%lx%04x.tmp",(long)getpid(),count
++);
1232 if ((tmp_fd
= open(ret
,O_CREAT
| O_EXCL
| O_WRONLY
,0666)) != -1) break;
1233 if (errno
!= EEXIST
) {
1234 ERR("Unexpected error while open() call: %s\n",strerror(errno
));
1241 if ((*f
= fdopen(tmp_fd
,"w")) == NULL
) {
1242 ERR("Unexpected error while fdopen() call: %s\n",strerror(errno
));
1251 /* convert win95 native registry file to wine format [Internal] */
1252 static LPSTR
_convert_win95_registry_to_wine_format(LPCSTR fn
,int level
)
1256 DOS_FULL_NAME full_name
;
1263 _w95dke
*dke
, *root_dke
;
1265 if (!DOSFS_GetFullName( fn
, 0, &full_name
)) return NULL
;
1267 /* map the registry into the memory */
1268 if ((fd
= open(full_name
.long_name
, O_RDONLY
| O_NONBLOCK
)) == -1) return NULL
;
1269 if ((fstat(fd
, &st
) == -1)) goto error1
;
1270 if (!st
.st_size
) goto error1
;
1271 if ((base
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == MAP_FAILED
) goto error1
;
1273 /* control signature */
1274 if (*(LPDWORD
)base
!= W95_REG_CREG_ID
) {
1275 ERR("unable to load native win95 registry file %s: unknown signature.\n",fn
);
1280 /* load the header (rgkn) */
1281 rgkn
= (_w95rgkn
*)(creg
+ 1);
1282 if (rgkn
->id
!= W95_REG_RGKN_ID
) {
1283 ERR("second IFF header not RGKN, but %lx\n", rgkn
->id
);
1286 if (rgkn
->root_off
!= 0x20) {
1287 ERR("rgkn->root_off not 0x20, please report !\n");
1290 if (rgkn
->last_dke
> rgkn
->size
)
1292 ERR("registry file corrupt! last_dke > size!\n");
1295 /* verify last dke */
1296 dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->last_dke
);
1297 if (dke
->x1
!= 0x80000000)
1299 ERR("last dke invalid !\n");
1302 if (rgkn
->size
> creg
->rgdb_off
)
1304 ERR("registry file corrupt! rgkn size > rgdb_off !\n");
1307 root_dke
= (_w95dke
*)((char*)rgkn
+ rgkn
->root_off
);
1308 if ( (root_dke
->prevlvl
!= 0xffffffff) || (root_dke
->next
!= 0xffffffff) )
1310 ERR("registry file corrupt! invalid root dke !\n");
1314 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1315 fprintf(f
,"WINE REGISTRY Version 2");
1316 _w95_dump_dke("",creg
,rgkn
,root_dke
,f
,level
);
1321 ERR("Unable to load native win95 registry file %s.\n",fn
);
1322 ERR("Please report to a.mohr@mailto.de.\n");
1323 ERR("Make a backup of the file, run a good reg cleaner program and try again!\n");
1326 munmap(base
, st
.st_size
);
1332 /* convert winnt native registry file to wine format [Internal] */
1333 static LPSTR
_convert_winnt_registry_to_wine_format(LPCSTR fn
,int level
)
1337 DOS_FULL_NAME full_name
;
1344 nt_hbin_sub
*hbin_sub
;
1347 if (!DOSFS_GetFullName( fn
, 0, &full_name
)) return NULL
;
1349 /* map the registry into the memory */
1350 if ((fd
= open(full_name
.long_name
, O_RDONLY
| O_NONBLOCK
)) == -1) return NULL
;
1351 if ((fstat(fd
, &st
) == -1)) goto error1
;
1352 if (!st
.st_size
) goto error1
;
1353 if ((base
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0)) == MAP_FAILED
) goto error1
;
1355 /* control signature */
1356 if (*(LPDWORD
)base
!= NT_REG_HEADER_BLOCK_ID
) {
1357 ERR("unable to load native winnt registry file %s: unknown signature.\n",fn
);
1365 hbin
= (nt_hbin
*)((char*) base
+ 0x1000);
1366 if (hbin
->id
!= NT_REG_POOL_BLOCK_ID
) {
1367 ERR( "hbin block invalid\n");
1371 /* hbin_sub block */
1372 hbin_sub
= (nt_hbin_sub
*)&(hbin
->hbin_sub
);
1373 if ((hbin_sub
->data
[0] != 'n') || (hbin_sub
->data
[1] != 'k')) {
1374 ERR( "hbin_sub block invalid\n");
1379 nk
= (nt_nk
*)&(hbin_sub
->data
[0]);
1380 if (nk
->Type
!= NT_REG_ROOT_KEY_BLOCK_TYPE
) {
1381 ERR( "special nk block not found\n");
1385 if ( (ret
= _get_tmp_fn(&f
)) == NULL
) goto error
;
1386 fprintf(f
,"WINE REGISTRY Version 2");
1387 _nt_dump_nk("",(char*)base
+0x1000,nk
,f
,level
);
1391 munmap(base
,st
.st_size
);
1397 /* convert native registry to wine format and load it via server call [Internal] */
1398 static void _convert_and_load_native_registry(LPCSTR fn
,HKEY hkey
,int reg_type
,int level
)
1404 /* FIXME: following function doesn't really convert yet */
1405 tmp
= _convert_winnt_registry_to_wine_format(fn
,level
);
1408 tmp
= _convert_win95_registry_to_wine_format(fn
,level
);
1411 ERR("Don't know how to convert native 3.1 registry yet.\n");
1414 ERR("Unknown registry format parameter (%d)\n",reg_type
);
1419 load_wine_registry(hkey
,tmp
);
1420 TRACE("File %s successfully converted to %s and loaded to registry.\n",fn
,tmp
);
1423 else WARN("Unable to convert %s (doesn't exist?)\n",fn
);
1427 /* load all native windows registry files [Internal] */
1428 static void _load_windows_registry( HKEY hkey_users_default
)
1431 char windir
[MAX_PATHNAME_LEN
];
1432 char path
[MAX_PATHNAME_LEN
];
1434 GetWindowsDirectoryA(windir
,MAX_PATHNAME_LEN
);
1436 reg_type
= _get_reg_type();
1441 /* user specific ntuser.dat */
1442 if (PROFILE_GetWineIniString( "Wine", "Profile", "", path
, MAX_PATHNAME_LEN
)) {
1443 strcat(path
,"\\ntuser.dat");
1444 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WINNT
,1);
1447 /* default user.dat */
1448 if (hkey_users_default
) {
1449 strcpy(path
,windir
);
1450 strcat(path
,"\\system32\\config\\default");
1451 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WINNT
,1);
1456 * map HLM\System\ControlSet001 to HLM\System\CurrentControlSet
1459 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SYSTEM", &hkey
)) {
1460 strcpy(path
,windir
);
1461 strcat(path
,"\\system32\\config\\system");
1462 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1466 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
, "SOFTWARE", &hkey
)) {
1467 strcpy(path
,windir
);
1468 strcat(path
,"\\system32\\config\\software");
1469 _convert_and_load_native_registry(path
,hkey
,REG_WINNT
,1);
1473 strcpy(path
,windir
);
1474 strcat(path
,"\\system32\\config\\sam");
1475 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1477 strcpy(path
,windir
);
1478 strcat(path
,"\\system32\\config\\security");
1479 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WINNT
,0);
1481 /* this key is generated when the nt-core booted successfully */
1482 if (!RegCreateKeyA(HKEY_LOCAL_MACHINE
,"System\\Clone",&hkey
)) RegCloseKey(hkey
);
1487 _convert_and_load_native_registry("c:\\system.1st",HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1489 strcpy(path
,windir
);
1490 strcat(path
,"\\system.dat");
1491 _convert_and_load_native_registry(path
,HKEY_LOCAL_MACHINE
,REG_WIN95
,0);
1493 strcpy(path
,windir
);
1494 strcat(path
,"\\classes.dat");
1495 _convert_and_load_native_registry(path
,HKEY_CLASSES_ROOT
,REG_WIN95
,0);
1497 if (PROFILE_GetWineIniString("Wine","Profile","",path
,MAX_PATHNAME_LEN
)) {
1498 /* user specific user.dat */
1499 strncat(path
, "\\user.dat", MAX_PATHNAME_LEN
- strlen(path
) - 1);
1500 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1502 /* default user.dat */
1503 if (hkey_users_default
) {
1504 strcpy(path
,windir
);
1505 strcat(path
,"\\user.dat");
1506 _convert_and_load_native_registry(path
,hkey_users_default
,REG_WIN95
,1);
1509 strcpy(path
,windir
);
1510 strcat(path
,"\\user.dat");
1511 _convert_and_load_native_registry(path
,HKEY_CURRENT_USER
,REG_WIN95
,1);
1516 /* FIXME: here we should convert to *.reg file supported by server and call REQ_LOAD_REGISTRY, see REG_WIN95 case */
1521 TRACE("REG_DONTLOAD\n");
1525 ERR("switch: no match (%d)\n",reg_type
);
1531 /* load global registry files (stored in /etc/wine) [Internal] */
1532 static void _load_global_registry(void)
1536 /* Load the global HKU hive directly from sysconfdir */
1537 load_wine_registry( HKEY_USERS
, SAVE_GLOBAL_REGBRANCH_USER_DEFAULT
);
1539 /* Load the global machine defaults directly from sysconfdir */
1540 load_wine_registry( HKEY_LOCAL_MACHINE
, SAVE_GLOBAL_REGBRANCH_LOCAL_MACHINE
);
1543 /* load home registry files (stored in ~/.wine) [Internal] */
1544 static void _load_home_registry( HKEY hkey_users_default
)
1546 LPCSTR confdir
= get_config_dir();
1547 LPSTR tmp
= _xmalloc(strlen(confdir
)+20);
1549 strcpy(tmp
,confdir
);
1550 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_USER_DEFAULT
);
1551 load_wine_registry(hkey_users_default
,tmp
);
1553 strcpy(tmp
,confdir
);
1554 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_CURRENT_USER
);
1555 load_wine_registry(HKEY_CURRENT_USER
,tmp
);
1557 strcpy(tmp
,confdir
);
1558 strcat(tmp
,"/" SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE
);
1559 load_wine_registry(HKEY_LOCAL_MACHINE
,tmp
);
1564 /* load all registry (native and global and home) */
1565 void SHELL_LoadRegistry( void )
1567 HKEY hkey_users_default
;
1571 if (!CLIENT_IsBootThread()) return; /* already loaded */
1573 if (RegCreateKeyA(HKEY_USERS
,".Default",&hkey_users_default
))
1575 ERR("Cannot create HKEY_USERS/.Default\n" );
1579 _allocate_default_keys();
1580 _set_registry_levels(0,0,0);
1581 if (PROFILE_GetWineIniBool("Registry","LoadWindowsRegistryFiles",1))
1582 _load_windows_registry( hkey_users_default
);
1583 if (PROFILE_GetWineIniBool("Registry","LoadGlobalRegistryFiles",1))
1584 _load_global_registry();
1585 _set_registry_levels(1,0,0);
1586 if (PROFILE_GetWineIniBool("Registry","LoadHomeRegistryFiles",1))
1587 _load_home_registry( hkey_users_default
);
1588 _init_registry_saving( hkey_users_default
);
1589 RegCloseKey(hkey_users_default
);
1592 /***************************************************************************/
1594 /***************************************************************************/
1596 /******************************************************************************
1597 * RegFlushKey [ADVAPI32.@]
1598 * Immediately writes key to registry.
1599 * Only returns after data has been written to disk.
1601 * FIXME: does it really wait until data is written ?
1604 * hkey [I] Handle of key to write
1607 * Success: ERROR_SUCCESS
1608 * Failure: Error code
1610 DWORD WINAPI
RegFlushKey( HKEY hkey
)
1612 FIXME( "(%x): stub\n", hkey
);
1613 return ERROR_SUCCESS
;
1617 /******************************************************************************
1618 * RegUnLoadKeyA [ADVAPI32.@]
1620 LONG WINAPI
RegUnLoadKeyA( HKEY hkey
, LPCSTR lpSubKey
)
1622 FIXME("(%x,%s): stub\n",hkey
, debugstr_a(lpSubKey
));
1623 return ERROR_SUCCESS
;
1627 /******************************************************************************
1628 * RegReplaceKeyA [ADVAPI32.@]
1630 LONG WINAPI
RegReplaceKeyA( HKEY hkey
, LPCSTR lpSubKey
, LPCSTR lpNewFile
,
1633 FIXME("(%x,%s,%s,%s): stub\n", hkey
, debugstr_a(lpSubKey
),
1634 debugstr_a(lpNewFile
),debugstr_a(lpOldFile
));
1635 return ERROR_SUCCESS
;
1643 /* 16-bit functions */
1645 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
1646 * some programs. Do not remove those cases. -MM
1648 static inline void fix_win16_hkey( HKEY
*hkey
)
1650 if (*hkey
== 0 || *hkey
== 1) *hkey
= HKEY_CLASSES_ROOT
;
1653 /******************************************************************************
1654 * RegEnumKey [KERNEL.216]
1655 * RegEnumKey [SHELL.7]
1657 DWORD WINAPI
RegEnumKey16( HKEY hkey
, DWORD index
, LPSTR name
, DWORD name_len
)
1659 fix_win16_hkey( &hkey
);
1660 return RegEnumKeyA( hkey
, index
, name
, name_len
);
1663 /******************************************************************************
1664 * RegOpenKey [KERNEL.217]
1665 * RegOpenKey [SHELL.1]
1667 DWORD WINAPI
RegOpenKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1669 fix_win16_hkey( &hkey
);
1670 return RegOpenKeyA( hkey
, name
, retkey
);
1673 /******************************************************************************
1674 * RegCreateKey [KERNEL.218]
1675 * RegCreateKey [SHELL.2]
1677 DWORD WINAPI
RegCreateKey16( HKEY hkey
, LPCSTR name
, LPHKEY retkey
)
1679 fix_win16_hkey( &hkey
);
1680 return RegCreateKeyA( hkey
, name
, retkey
);
1683 /******************************************************************************
1684 * RegDeleteKey [KERNEL.219]
1685 * RegDeleteKey [SHELL.4]
1687 DWORD WINAPI
RegDeleteKey16( HKEY hkey
, LPCSTR name
)
1689 fix_win16_hkey( &hkey
);
1690 return RegDeleteKeyA( hkey
, name
);
1693 /******************************************************************************
1694 * RegCloseKey [KERNEL.220]
1695 * RegCloseKey [SHELL.3]
1697 DWORD WINAPI
RegCloseKey16( HKEY hkey
)
1699 fix_win16_hkey( &hkey
);
1700 return RegCloseKey( hkey
);
1703 /******************************************************************************
1704 * RegSetValue [KERNEL.221]
1705 * RegSetValue [SHELL.5]
1707 DWORD WINAPI
RegSetValue16( HKEY hkey
, LPCSTR name
, DWORD type
, LPCSTR data
, DWORD count
)
1709 fix_win16_hkey( &hkey
);
1710 return RegSetValueA( hkey
, name
, type
, data
, count
);
1713 /******************************************************************************
1714 * RegDeleteValue [KERNEL.222]
1716 DWORD WINAPI
RegDeleteValue16( HKEY hkey
, LPSTR name
)
1718 fix_win16_hkey( &hkey
);
1719 return RegDeleteValueA( hkey
, name
);
1722 /******************************************************************************
1723 * RegEnumValue [KERNEL.223]
1725 DWORD WINAPI
RegEnumValue16( HKEY hkey
, DWORD index
, LPSTR value
, LPDWORD val_count
,
1726 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
1728 fix_win16_hkey( &hkey
);
1729 return RegEnumValueA( hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
1732 /******************************************************************************
1733 * RegQueryValue [KERNEL.224]
1734 * RegQueryValue [SHELL.6]
1737 * Is this HACK still applicable?
1740 * The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just
1741 * mask out the high 16 bit. This (not so much incidently) hopefully fixes
1744 DWORD WINAPI
RegQueryValue16( HKEY hkey
, LPCSTR name
, LPSTR data
, LPDWORD count
)
1746 fix_win16_hkey( &hkey
);
1747 if (count
) *count
&= 0xffff;
1748 return RegQueryValueA( hkey
, name
, data
, count
);
1751 /******************************************************************************
1752 * RegQueryValueEx [KERNEL.225]
1754 DWORD WINAPI
RegQueryValueEx16( HKEY hkey
, LPCSTR name
, LPDWORD reserved
, LPDWORD type
,
1755 LPBYTE data
, LPDWORD count
)
1757 fix_win16_hkey( &hkey
);
1758 return RegQueryValueExA( hkey
, name
, reserved
, type
, data
, count
);
1761 /******************************************************************************
1762 * RegSetValueEx [KERNEL.226]
1764 DWORD WINAPI
RegSetValueEx16( HKEY hkey
, LPCSTR name
, DWORD reserved
, DWORD type
,
1765 CONST BYTE
*data
, DWORD count
)
1767 fix_win16_hkey( &hkey
);
1768 if (!count
&& (type
==REG_SZ
)) count
= strlen(data
);
1769 return RegSetValueExA( hkey
, name
, reserved
, type
, data
, count
);
1772 /******************************************************************************
1773 * RegFlushKey [KERNEL.227]
1775 DWORD WINAPI
RegFlushKey16( HKEY hkey
)
1777 fix_win16_hkey( &hkey
);
1778 return RegFlushKey( hkey
);