2 * Registry processing routines. Routines, common for registry
3 * processing frontends.
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 Andriy Palamarchuk
7 * Copyright 2008 Alexander N. Sørnes <alex@thehandofagony.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include <wine/unicode.h>
35 #include <wine/debug.h>
38 #define REG_VAL_BUF_SIZE 4096
40 /* maximal number of characters in hexadecimal data line,
41 * including the indentation, but not including the '\' character
43 #define REG_FILE_HEX_LINE_LEN (2 + 25 * 3)
45 extern const WCHAR
* reg_class_namesW
[];
47 static HKEY reg_class_keys
[] = {
48 HKEY_LOCAL_MACHINE
, HKEY_USERS
, HKEY_CLASSES_ROOT
,
49 HKEY_CURRENT_CONFIG
, HKEY_CURRENT_USER
, HKEY_DYN_DATA
52 #define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
54 /******************************************************************************
55 * Allocates memory and converts input from multibyte to wide chars
56 * Returned string must be freed by the caller
58 static WCHAR
* GetWideString(const char* strA
)
63 int len
= MultiByteToWideChar(CP_ACP
, 0, strA
, -1, NULL
, 0);
65 strW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
66 CHECK_ENOUGH_MEMORY(strW
);
67 MultiByteToWideChar(CP_ACP
, 0, strA
, -1, strW
, len
);
73 /******************************************************************************
74 * Allocates memory and converts input from multibyte to wide chars
75 * Returned string must be freed by the caller
77 static WCHAR
* GetWideStringN(const char* strA
, int chars
, DWORD
*len
)
82 *len
= MultiByteToWideChar(CP_ACP
, 0, strA
, chars
, NULL
, 0);
84 strW
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(WCHAR
));
85 CHECK_ENOUGH_MEMORY(strW
);
86 MultiByteToWideChar(CP_ACP
, 0, strA
, chars
, strW
, *len
);
93 /******************************************************************************
94 * Allocates memory and converts input from wide chars to multibyte
95 * Returned string must be freed by the caller
97 char* GetMultiByteString(const WCHAR
* strW
)
102 int len
= WideCharToMultiByte(CP_ACP
, 0, strW
, -1, NULL
, 0, NULL
, NULL
);
104 strA
= HeapAlloc(GetProcessHeap(), 0, len
);
105 CHECK_ENOUGH_MEMORY(strA
);
106 WideCharToMultiByte(CP_ACP
, 0, strW
, -1, strA
, len
, NULL
, NULL
);
112 /******************************************************************************
113 * Allocates memory and converts input from wide chars to multibyte
114 * Returned string must be freed by the caller
116 static char* GetMultiByteStringN(const WCHAR
* strW
, int chars
, DWORD
* len
)
121 *len
= WideCharToMultiByte(CP_ACP
, 0, strW
, chars
, NULL
, 0, NULL
, NULL
);
123 strA
= HeapAlloc(GetProcessHeap(), 0, *len
);
124 CHECK_ENOUGH_MEMORY(strA
);
125 WideCharToMultiByte(CP_ACP
, 0, strW
, chars
, strA
, *len
, NULL
, NULL
);
132 static WCHAR
*(*get_line
)(FILE *);
134 /* parser definitions */
137 HEADER
, /* parsing the registry file version header */
138 PARSE_WIN31_LINE
, /* parsing a Windows 3.1 registry line */
139 LINE_START
, /* at the beginning of a registry line */
140 KEY_NAME
, /* parsing a key name */
141 DELETE_KEY
, /* deleting a registry key */
142 DEFAULT_VALUE_NAME
, /* parsing a default value name */
143 QUOTED_VALUE_NAME
, /* parsing a double-quoted value name */
144 DATA_START
, /* preparing for data parsing operations */
145 DELETE_VALUE
, /* deleting a registry value */
146 DATA_TYPE
, /* parsing the registry data type */
147 STRING_DATA
, /* parsing REG_SZ data */
148 DWORD_DATA
, /* parsing DWORD data */
149 HEX_DATA
, /* parsing REG_BINARY, REG_NONE, REG_EXPAND_SZ or REG_MULTI_SZ data */
150 EOL_BACKSLASH
, /* preparing to parse multiple lines of hex data */
151 HEX_MULTILINE
, /* parsing multiple lines of hex data */
152 UNKNOWN_DATA
, /* parsing an unhandled or invalid data type */
153 SET_VALUE
, /* adding a value to the registry */
159 FILE *file
; /* pointer to a registry file */
160 WCHAR two_wchars
[2]; /* first two characters from the encoding check */
161 BOOL is_unicode
; /* parsing Unicode or ASCII data */
162 short int reg_version
; /* registry file version */
163 HKEY hkey
; /* current registry key */
164 WCHAR
*key_name
; /* current key name */
165 WCHAR
*value_name
; /* value name */
166 DWORD parse_type
; /* generic data type for parsing */
167 DWORD data_type
; /* data type */
168 void *data
; /* value data */
169 DWORD data_size
; /* size of the data (in bytes) */
170 BOOL backslash
; /* TRUE if the current line contains a backslash */
171 enum parser_state state
; /* current parser state */
174 typedef WCHAR
*(*parser_state_func
)(struct parser
*parser
, WCHAR
*pos
);
176 /* parser state machine functions */
177 static WCHAR
*header_state(struct parser
*parser
, WCHAR
*pos
);
178 static WCHAR
*parse_win31_line_state(struct parser
*parser
, WCHAR
*pos
);
179 static WCHAR
*line_start_state(struct parser
*parser
, WCHAR
*pos
);
180 static WCHAR
*key_name_state(struct parser
*parser
, WCHAR
*pos
);
181 static WCHAR
*delete_key_state(struct parser
*parser
, WCHAR
*pos
);
182 static WCHAR
*default_value_name_state(struct parser
*parser
, WCHAR
*pos
);
183 static WCHAR
*quoted_value_name_state(struct parser
*parser
, WCHAR
*pos
);
184 static WCHAR
*data_start_state(struct parser
*parser
, WCHAR
*pos
);
185 static WCHAR
*delete_value_state(struct parser
*parser
, WCHAR
*pos
);
186 static WCHAR
*data_type_state(struct parser
*parser
, WCHAR
*pos
);
187 static WCHAR
*string_data_state(struct parser
*parser
, WCHAR
*pos
);
188 static WCHAR
*dword_data_state(struct parser
*parser
, WCHAR
*pos
);
189 static WCHAR
*hex_data_state(struct parser
*parser
, WCHAR
*pos
);
190 static WCHAR
*eol_backslash_state(struct parser
*parser
, WCHAR
*pos
);
191 static WCHAR
*hex_multiline_state(struct parser
*parser
, WCHAR
*pos
);
192 static WCHAR
*unknown_data_state(struct parser
*parser
, WCHAR
*pos
);
193 static WCHAR
*set_value_state(struct parser
*parser
, WCHAR
*pos
);
195 static const parser_state_func parser_funcs
[NB_PARSER_STATES
] =
197 header_state
, /* HEADER */
198 parse_win31_line_state
, /* PARSE_WIN31_LINE */
199 line_start_state
, /* LINE_START */
200 key_name_state
, /* KEY_NAME */
201 delete_key_state
, /* DELETE_KEY */
202 default_value_name_state
, /* DEFAULT_VALUE_NAME */
203 quoted_value_name_state
, /* QUOTED_VALUE_NAME */
204 data_start_state
, /* DATA_START */
205 delete_value_state
, /* DELETE_VALUE */
206 data_type_state
, /* DATA_TYPE */
207 string_data_state
, /* STRING_DATA */
208 dword_data_state
, /* DWORD_DATA */
209 hex_data_state
, /* HEX_DATA */
210 eol_backslash_state
, /* EOL_BACKSLASH */
211 hex_multiline_state
, /* HEX_MULTILINE */
212 unknown_data_state
, /* UNKNOWN_DATA */
213 set_value_state
, /* SET_VALUE */
216 /* set the new parser state and return the previous one */
217 static inline enum parser_state
set_state(struct parser
*parser
, enum parser_state state
)
219 enum parser_state ret
= parser
->state
;
220 parser
->state
= state
;
224 static void *resize_buffer(void *buf
, size_t count
)
229 new_buf
= HeapReAlloc(GetProcessHeap(), 0, buf
, count
);
231 new_buf
= HeapAlloc(GetProcessHeap(), 0, count
);
233 CHECK_ENOUGH_MEMORY(new_buf
);
237 /******************************************************************************
238 * Converts a hex representation of a DWORD into a DWORD.
240 static BOOL
convert_hex_to_dword(WCHAR
*str
, DWORD
*dw
)
245 while (*str
== ' ' || *str
== '\t') str
++;
246 if (!*str
) goto error
;
249 while (isxdigitW(*p
))
254 if (count
> 8) goto error
;
257 while (*p
== ' ' || *p
== '\t') p
++;
258 if (*p
&& *p
!= ';') goto error
;
261 *dw
= strtoulW(str
, &end
, 16);
268 /******************************************************************************
269 * Converts comma-separated hex data into a binary string and modifies
270 * the input parameter to skip the concatenating backslash, if found.
272 * Returns TRUE or FALSE to indicate whether parsing was successful.
274 static BOOL
convert_hex_csv_to_hex(struct parser
*parser
, WCHAR
**str
)
280 parser
->backslash
= FALSE
;
282 /* The worst case is 1 digit + 1 comma per byte */
283 size
= ((lstrlenW(*str
) + 1) / 2) + parser
->data_size
;
284 parser
->data
= resize_buffer(parser
->data
, size
);
287 d
= (BYTE
*)parser
->data
+ parser
->data_size
;
294 wc
= strtoulW(s
, &end
, 16);
295 if (wc
> 0xff) return FALSE
;
297 if (s
== end
&& wc
== 0)
299 while (*end
== ' ' || *end
== '\t') end
++;
302 parser
->backslash
= TRUE
;
306 else if (*end
== ';')
314 if (*end
&& *end
!= ',')
316 while (*end
== ' ' || *end
== '\t') end
++;
317 if (*end
&& *end
!= ';') return FALSE
;
328 /******************************************************************************
329 * Parses the data type of the registry value being imported and modifies
330 * the input parameter to skip the string representation of the data type.
332 * Returns TRUE or FALSE to indicate whether a data type was found.
334 static BOOL
parse_data_type(struct parser
*parser
, WCHAR
**line
)
336 struct data_type
{ const WCHAR
*tag
; int len
; int type
; int parse_type
; };
338 static const WCHAR quote
[] = {'"'};
339 static const WCHAR hex
[] = {'h','e','x',':'};
340 static const WCHAR dword
[] = {'d','w','o','r','d',':'};
341 static const WCHAR hexp
[] = {'h','e','x','('};
343 static const struct data_type data_types
[] = {
344 /* tag len type parse type */
345 { quote
, 1, REG_SZ
, REG_SZ
},
346 { hex
, 4, REG_BINARY
, REG_BINARY
},
347 { dword
, 6, REG_DWORD
, REG_DWORD
},
348 { hexp
, 4, -1, REG_BINARY
}, /* REG_NONE, REG_EXPAND_SZ, REG_MULTI_SZ */
352 const struct data_type
*ptr
;
354 for (ptr
= data_types
; ptr
->tag
; ptr
++)
356 if (strncmpW(ptr
->tag
, *line
, ptr
->len
))
359 parser
->parse_type
= ptr
->parse_type
;
360 parser
->data_type
= ptr
->parse_type
;
368 if (!**line
|| tolowerW((*line
)[1]) == 'x')
371 /* "hex(xx):" is special */
372 val
= wcstoul(*line
, &end
, 16);
373 if (*end
!= ')' || *(end
+ 1) != ':' || (val
== ~0u && errno
== ERANGE
))
376 parser
->data_type
= val
;
384 /******************************************************************************
385 * Replaces escape sequences with their character equivalents and
386 * null-terminates the string on the first non-escaped double quote.
388 * Assigns a pointer to the remaining unparsed data in the line.
389 * Returns TRUE or FALSE to indicate whether a closing double quote was found.
391 static BOOL
REGPROC_unescape_string(WCHAR
*str
, WCHAR
**unparsed
)
393 int str_idx
= 0; /* current character under analysis */
394 int val_idx
= 0; /* the last character of the unescaped string */
395 int len
= lstrlenW(str
);
398 for (str_idx
= 0; str_idx
< len
; str_idx
++, val_idx
++) {
399 if (str
[str_idx
] == '\\') {
401 switch (str
[str_idx
]) {
413 str
[val_idx
] = str
[str_idx
];
416 output_message(STRING_ESCAPE_SEQUENCE
, str
[str_idx
]);
417 str
[val_idx
] = str
[str_idx
];
420 } else if (str
[str_idx
] == '"') {
423 str
[val_idx
] = str
[str_idx
];
427 ret
= (str
[str_idx
] == '"');
428 *unparsed
= str
+ str_idx
+ 1;
433 static HKEY
parse_key_name(WCHAR
*key_name
, WCHAR
**key_path
)
437 if (!key_name
) return 0;
439 *key_path
= strchrW(key_name
, '\\');
440 if (*key_path
) (*key_path
)++;
442 for (i
= 0; i
< ARRAY_SIZE(reg_class_keys
); i
++)
444 int len
= lstrlenW(reg_class_namesW
[i
]);
445 if (!strncmpiW(key_name
, reg_class_namesW
[i
], len
) &&
446 (key_name
[len
] == 0 || key_name
[len
] == '\\'))
448 return reg_class_keys
[i
];
455 static void close_key(struct parser
*parser
)
459 HeapFree(GetProcessHeap(), 0, parser
->key_name
);
460 parser
->key_name
= NULL
;
462 RegCloseKey(parser
->hkey
);
467 /******************************************************************************
468 * Opens the registry key given by the input path.
469 * This key must be closed by calling close_key().
471 static LONG
open_key(struct parser
*parser
, WCHAR
*path
)
479 /* Get the registry class */
480 if (!path
|| !(key_class
= parse_key_name(path
, &key_path
)))
481 return ERROR_INVALID_PARAMETER
;
483 res
= RegCreateKeyExW(key_class
, key_path
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
484 KEY_ALL_ACCESS
, NULL
, &parser
->hkey
, NULL
);
486 if (res
== ERROR_SUCCESS
)
488 parser
->key_name
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(path
) + 1) * sizeof(WCHAR
));
489 CHECK_ENOUGH_MEMORY(parser
->key_name
);
490 lstrcpyW(parser
->key_name
, path
);
498 static void free_parser_data(struct parser
*parser
)
500 if (parser
->parse_type
== REG_DWORD
|| parser
->parse_type
== REG_BINARY
)
501 HeapFree(GetProcessHeap(), 0, parser
->data
);
504 parser
->data_size
= 0;
507 static void prepare_hex_string_data(struct parser
*parser
)
509 if (parser
->data_type
== REG_EXPAND_SZ
|| parser
->data_type
== REG_MULTI_SZ
)
511 BYTE
*data
= parser
->data
;
513 if (data
[parser
->data_size
- 1] != 0)
515 data
[parser
->data_size
] = 0;
519 if (!parser
->is_unicode
)
521 parser
->data
= GetWideStringN(parser
->data
, parser
->data_size
, &parser
->data_size
);
522 parser
->data_size
*= sizeof(WCHAR
);
523 HeapFree(GetProcessHeap(), 0, data
);
536 static enum reg_versions
parse_file_header(const WCHAR
*s
)
538 static const WCHAR header_31
[] = {'R','E','G','E','D','I','T',0};
539 static const WCHAR header_40
[] = {'R','E','G','E','D','I','T','4',0};
540 static const WCHAR header_50
[] = {'W','i','n','d','o','w','s',' ',
541 'R','e','g','i','s','t','r','y',' ','E','d','i','t','o','r',' ',
542 'V','e','r','s','i','o','n',' ','5','.','0','0',0};
544 while (*s
== ' ' || *s
== '\t') s
++;
546 if (!strcmpW(s
, header_31
))
547 return REG_VERSION_31
;
549 if (!strcmpW(s
, header_40
))
550 return REG_VERSION_40
;
552 if (!strcmpW(s
, header_50
))
553 return REG_VERSION_50
;
555 /* The Windows version accepts registry file headers beginning with "REGEDIT" and ending
556 * with other characters, as long as "REGEDIT" appears at the start of the line. For example,
557 * "REGEDIT 4", "REGEDIT9" and "REGEDIT4FOO" are all treated as valid file headers.
558 * In all such cases, however, the contents of the registry file are not imported.
560 if (!strncmpW(s
, header_31
, 7)) /* "REGEDIT" without NUL */
561 return REG_VERSION_FUZZY
;
563 return REG_VERSION_INVALID
;
566 /* handler for parser HEADER state */
567 static WCHAR
*header_state(struct parser
*parser
, WCHAR
*pos
)
569 WCHAR
*line
, *header
;
571 if (!(line
= get_line(parser
->file
)))
574 if (!parser
->is_unicode
)
576 header
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(line
) + 3) * sizeof(WCHAR
));
577 CHECK_ENOUGH_MEMORY(header
);
578 header
[0] = parser
->two_wchars
[0];
579 header
[1] = parser
->two_wchars
[1];
580 lstrcpyW(header
+ 2, line
);
581 parser
->reg_version
= parse_file_header(header
);
582 HeapFree(GetProcessHeap(), 0, header
);
584 else parser
->reg_version
= parse_file_header(line
);
586 switch (parser
->reg_version
)
589 set_state(parser
, PARSE_WIN31_LINE
);
593 set_state(parser
, LINE_START
);
596 get_line(NULL
); /* Reset static variables */
603 /* handler for parser PARSE_WIN31_LINE state */
604 static WCHAR
*parse_win31_line_state(struct parser
*parser
, WCHAR
*pos
)
607 static WCHAR hkcr
[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T'};
608 unsigned int key_end
= 0;
610 if (!(line
= get_line(parser
->file
)))
613 if (strncmpW(line
, hkcr
, ARRAY_SIZE(hkcr
)))
617 while (line
[key_end
] && !isspaceW(line
[key_end
])) key_end
++;
619 value
= line
+ key_end
;
620 while (*value
== ' ' || *value
== '\t') value
++;
622 if (*value
== '=') value
++;
623 if (*value
== ' ') value
++; /* at most one space is skipped */
627 if (open_key(parser
, line
) != ERROR_SUCCESS
)
629 output_message(STRING_OPEN_KEY_FAILED
, line
);
633 parser
->value_name
= NULL
;
634 parser
->data_type
= REG_SZ
;
635 parser
->data
= value
;
636 parser
->data_size
= (lstrlenW(value
) + 1) * sizeof(WCHAR
);
638 set_state(parser
, SET_VALUE
);
642 /* handler for parser LINE_START state */
643 static WCHAR
*line_start_state(struct parser
*parser
, WCHAR
*pos
)
647 if (!(line
= get_line(parser
->file
)))
650 for (p
= line
; *p
; p
++)
655 set_state(parser
, KEY_NAME
);
658 set_state(parser
, DEFAULT_VALUE_NAME
);
661 set_state(parser
, QUOTED_VALUE_NAME
);
674 /* handler for parser KEY_NAME state */
675 static WCHAR
*key_name_state(struct parser
*parser
, WCHAR
*pos
)
677 WCHAR
*p
= pos
, *key_end
;
679 if (*p
== ' ' || *p
== '\t' || !(key_end
= strrchrW(p
, ']')))
686 set_state(parser
, DELETE_KEY
);
689 else if (open_key(parser
, p
) != ERROR_SUCCESS
)
690 output_message(STRING_OPEN_KEY_FAILED
, p
);
693 set_state(parser
, LINE_START
);
697 /* handler for parser DELETE_KEY state */
698 static WCHAR
*delete_key_state(struct parser
*parser
, WCHAR
*pos
)
702 if (*p
== 'H' || *p
== 'h')
703 delete_registry_key(p
);
705 set_state(parser
, LINE_START
);
709 /* handler for parser DEFAULT_VALUE_NAME state */
710 static WCHAR
*default_value_name_state(struct parser
*parser
, WCHAR
*pos
)
712 parser
->value_name
= NULL
;
714 set_state(parser
, DATA_START
);
718 /* handler for parser QUOTED_VALUE_NAME state */
719 static WCHAR
*quoted_value_name_state(struct parser
*parser
, WCHAR
*pos
)
721 WCHAR
*val_name
= pos
, *p
;
723 if (parser
->value_name
)
725 HeapFree(GetProcessHeap(), 0, parser
->value_name
);
726 parser
->value_name
= NULL
;
729 if (!REGPROC_unescape_string(val_name
, &p
))
732 /* copy the value name in case we need to parse multiple lines and the buffer is overwritten */
733 parser
->value_name
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(val_name
) + 1) * sizeof(WCHAR
));
734 CHECK_ENOUGH_MEMORY(parser
->value_name
);
735 lstrcpyW(parser
->value_name
, val_name
);
737 set_state(parser
, DATA_START
);
741 set_state(parser
, LINE_START
);
745 /* handler for parser DATA_START state */
746 static WCHAR
*data_start_state(struct parser
*parser
, WCHAR
*pos
)
751 while (*p
== ' ' || *p
== '\t') p
++;
752 if (*p
!= '=') goto done
;
754 while (*p
== ' ' || *p
== '\t') p
++;
756 /* trim trailing whitespace */
758 while (len
> 0 && (p
[len
- 1] == ' ' || p
[len
- 1] == '\t')) len
--;
762 set_state(parser
, DELETE_VALUE
);
764 set_state(parser
, DATA_TYPE
);
768 set_state(parser
, LINE_START
);
772 /* handler for parser DELETE_VALUE state */
773 static WCHAR
*delete_value_state(struct parser
*parser
, WCHAR
*pos
)
777 while (*p
== ' ' || *p
== '\t') p
++;
778 if (*p
&& *p
!= ';') goto done
;
780 RegDeleteValueW(parser
->hkey
, parser
->value_name
);
783 set_state(parser
, LINE_START
);
787 /* handler for parser DATA_TYPE state */
788 static WCHAR
*data_type_state(struct parser
*parser
, WCHAR
*pos
)
792 if (!parse_data_type(parser
, &line
))
794 set_state(parser
, LINE_START
);
798 switch (parser
->parse_type
)
801 set_state(parser
, STRING_DATA
);
804 set_state(parser
, DWORD_DATA
);
806 case REG_BINARY
: /* all hex data types, including undefined */
807 set_state(parser
, HEX_DATA
);
810 set_state(parser
, UNKNOWN_DATA
);
816 /* handler for parser STRING_DATA state */
817 static WCHAR
*string_data_state(struct parser
*parser
, WCHAR
*pos
)
823 if (!REGPROC_unescape_string(parser
->data
, &line
))
826 while (*line
== ' ' || *line
== '\t') line
++;
827 if (*line
&& *line
!= ';') goto invalid
;
829 parser
->data_size
= (lstrlenW(parser
->data
) + 1) * sizeof(WCHAR
);
831 set_state(parser
, SET_VALUE
);
835 free_parser_data(parser
);
836 set_state(parser
, LINE_START
);
840 /* handler for parser DWORD_DATA state */
841 static WCHAR
*dword_data_state(struct parser
*parser
, WCHAR
*pos
)
845 parser
->data
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
));
846 CHECK_ENOUGH_MEMORY(parser
->data
);
848 if (!convert_hex_to_dword(line
, parser
->data
))
851 parser
->data_size
= sizeof(DWORD
);
853 set_state(parser
, SET_VALUE
);
857 free_parser_data(parser
);
858 set_state(parser
, LINE_START
);
862 /* handler for parser HEX_DATA state */
863 static WCHAR
*hex_data_state(struct parser
*parser
, WCHAR
*pos
)
867 if (!convert_hex_csv_to_hex(parser
, &line
))
870 if (parser
->backslash
)
872 set_state(parser
, EOL_BACKSLASH
);
876 prepare_hex_string_data(parser
);
878 set_state(parser
, SET_VALUE
);
882 free_parser_data(parser
);
883 set_state(parser
, LINE_START
);
887 /* handler for parser EOL_BACKSLASH state */
888 static WCHAR
*eol_backslash_state(struct parser
*parser
, WCHAR
*pos
)
892 while (*p
== ' ' || *p
== '\t') p
++;
893 if (*p
&& *p
!= ';') goto invalid
;
895 set_state(parser
, HEX_MULTILINE
);
899 free_parser_data(parser
);
900 set_state(parser
, LINE_START
);
904 /* handler for parser HEX_MULTILINE state */
905 static WCHAR
*hex_multiline_state(struct parser
*parser
, WCHAR
*pos
)
909 if (!(line
= get_line(parser
->file
)))
911 prepare_hex_string_data(parser
);
912 set_state(parser
, SET_VALUE
);
916 while (*line
== ' ' || *line
== '\t') line
++;
917 if (!*line
|| *line
== ';') return line
;
919 if (!isxdigitW(*line
)) goto invalid
;
921 set_state(parser
, HEX_DATA
);
925 free_parser_data(parser
);
926 set_state(parser
, LINE_START
);
930 /* handler for parser UNKNOWN_DATA state */
931 static WCHAR
*unknown_data_state(struct parser
*parser
, WCHAR
*pos
)
933 output_message(STRING_UNKNOWN_DATA_FORMAT
, parser
->data_type
);
935 set_state(parser
, LINE_START
);
939 /* handler for parser SET_VALUE state */
940 static WCHAR
*set_value_state(struct parser
*parser
, WCHAR
*pos
)
942 RegSetValueExW(parser
->hkey
, parser
->value_name
, 0, parser
->data_type
,
943 parser
->data
, parser
->data_size
);
945 free_parser_data(parser
);
947 if (parser
->reg_version
== REG_VERSION_31
)
948 set_state(parser
, PARSE_WIN31_LINE
);
950 set_state(parser
, LINE_START
);
955 static WCHAR
*get_lineA(FILE *fp
)
959 static char *buf
, *next
;
962 HeapFree(GetProcessHeap(), 0, lineW
);
964 if (!fp
) goto cleanup
;
968 size
= REG_VAL_BUF_SIZE
;
969 buf
= HeapAlloc(GetProcessHeap(), 0, size
);
970 CHECK_ENOUGH_MEMORY(buf
);
978 char *p
= strpbrk(line
, "\r\n");
983 memmove(buf
, next
, len
+ 1);
986 char *new_buf
= HeapReAlloc(GetProcessHeap(), 0, buf
, size
* 2);
987 CHECK_ENOUGH_MEMORY(new_buf
);
991 if (!(count
= fread(buf
+ len
, 1, size
- len
- 1, fp
)))
994 lineW
= GetWideString(buf
);
997 buf
[len
+ count
] = 0;
1003 if (*p
== '\r' && *(p
+ 1) == '\n') next
++;
1005 lineW
= GetWideString(line
);
1011 if (size
) HeapFree(GetProcessHeap(), 0, buf
);
1016 static WCHAR
*get_lineW(FILE *fp
)
1019 static WCHAR
*buf
, *next
;
1022 if (!fp
) goto cleanup
;
1026 size
= REG_VAL_BUF_SIZE
;
1027 buf
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
1028 CHECK_ENOUGH_MEMORY(buf
);
1036 static const WCHAR line_endings
[] = {'\r','\n',0};
1037 WCHAR
*p
= strpbrkW(line
, line_endings
);
1041 len
= strlenW(next
);
1042 memmove(buf
, next
, (len
+ 1) * sizeof(WCHAR
));
1045 WCHAR
*new_buf
= HeapReAlloc(GetProcessHeap(), 0, buf
, (size
* 2) * sizeof(WCHAR
));
1046 CHECK_ENOUGH_MEMORY(new_buf
);
1050 if (!(count
= fread(buf
+ len
, sizeof(WCHAR
), size
- len
- 1, fp
)))
1055 buf
[len
+ count
] = 0;
1061 if (*p
== '\r' && *(p
+ 1) == '\n') next
++;
1067 if (size
) HeapFree(GetProcessHeap(), 0, buf
);
1072 /******************************************************************************
1073 * Checks whether the buffer has enough room for the string or required size.
1074 * Resizes the buffer if necessary.
1077 * buffer - pointer to a buffer for string
1078 * len - current length of the buffer in characters.
1079 * required_len - length of the string to place to the buffer in characters.
1080 * The length does not include the terminating null character.
1082 static void REGPROC_resize_char_buffer(WCHAR
**buffer
, DWORD
*len
, DWORD required_len
)
1085 if (required_len
> *len
) {
1086 *len
= required_len
;
1088 *buffer
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(**buffer
));
1090 *buffer
= HeapReAlloc(GetProcessHeap(), 0, *buffer
, *len
* sizeof(**buffer
));
1091 CHECK_ENOUGH_MEMORY(*buffer
);
1095 /******************************************************************************
1096 * Prints string str to file
1098 static void REGPROC_export_string(WCHAR
**line_buf
, DWORD
*line_buf_size
, DWORD
*line_len
, WCHAR
*str
, DWORD str_len
)
1103 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, *line_len
+ str_len
+ 10);
1105 /* escaping characters */
1107 for (i
= 0; i
< str_len
; i
++) {
1112 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, *line_len
+ str_len
+ extra
);
1113 (*line_buf
)[pos
++] = '\\';
1114 (*line_buf
)[pos
++] = 'n';
1119 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, *line_len
+ str_len
+ extra
);
1120 (*line_buf
)[pos
++] = '\\';
1121 (*line_buf
)[pos
++] = 'r';
1127 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, *line_len
+ str_len
+ extra
);
1128 (*line_buf
)[pos
++] = '\\';
1132 (*line_buf
)[pos
++] = c
;
1136 (*line_buf
)[pos
] = '\0';
1140 static void REGPROC_export_binary(WCHAR
**line_buf
, DWORD
*line_buf_size
, DWORD
*line_len
, DWORD type
, BYTE
*value
, DWORD value_size
, BOOL unicode
)
1142 DWORD hex_pos
, data_pos
;
1143 const WCHAR
*hex_prefix
;
1144 const WCHAR hex
[] = {'h','e','x',':',0};
1146 const WCHAR concat
[] = {'\\','\r','\n',' ',' ',0};
1147 DWORD concat_prefix
, concat_len
;
1148 const WCHAR newline
[] = {'\r','\n',0};
1149 CHAR
* value_multibyte
= NULL
;
1151 if (type
== REG_BINARY
) {
1154 const WCHAR hex_format
[] = {'h','e','x','(','%','x',')',':',0};
1155 hex_prefix
= hex_buf
;
1156 sprintfW(hex_buf
, hex_format
, type
);
1157 if ((type
== REG_SZ
|| type
== REG_EXPAND_SZ
|| type
== REG_MULTI_SZ
) && !unicode
)
1159 value_multibyte
= GetMultiByteStringN((WCHAR
*)value
, value_size
/ sizeof(WCHAR
), &value_size
);
1160 value
= (BYTE
*)value_multibyte
;
1164 concat_len
= lstrlenW(concat
);
1167 hex_pos
= *line_len
;
1168 *line_len
+= lstrlenW(hex_prefix
);
1169 data_pos
= *line_len
;
1170 *line_len
+= value_size
* 3;
1171 /* - The 2 spaces that concat places at the start of the
1172 * line effectively reduce the space available for data.
1173 * - If the value name and hex prefix are very long
1174 * ( > REG_FILE_HEX_LINE_LEN) or *line_len divides
1175 * without a remainder then we may overestimate
1176 * the needed number of lines by one. But that's ok.
1177 * - The trailing '\r' takes the place of a comma so
1178 * we only need to add 1 for the trailing '\n'
1180 *line_len
+= *line_len
/ (REG_FILE_HEX_LINE_LEN
- concat_prefix
) * concat_len
+ 1;
1181 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, *line_len
);
1182 lstrcpyW(*line_buf
+ hex_pos
, hex_prefix
);
1185 const WCHAR format
[] = {'%','0','2','x',0};
1188 column
= data_pos
; /* no line wrap yet */
1192 sprintfW(*line_buf
+ data_pos
, format
, (unsigned int)value
[i
]);
1194 if (++i
== value_size
)
1197 (*line_buf
)[data_pos
++] = ',';
1201 if (column
>= REG_FILE_HEX_LINE_LEN
) {
1202 lstrcpyW(*line_buf
+ data_pos
, concat
);
1203 data_pos
+= concat_len
;
1204 column
= concat_prefix
;
1208 lstrcpyW(*line_buf
+ data_pos
, newline
);
1209 HeapFree(GetProcessHeap(), 0, value_multibyte
);
1212 /******************************************************************************
1213 * Writes the given line to a file, in multi-byte or wide characters
1215 static void REGPROC_write_line(FILE *file
, const WCHAR
* str
, BOOL unicode
)
1219 fwrite(str
, sizeof(WCHAR
), lstrlenW(str
), file
);
1222 char* strA
= GetMultiByteString(str
);
1224 HeapFree(GetProcessHeap(), 0, strA
);
1228 /******************************************************************************
1229 * Writes contents of the registry key to the specified file stream.
1232 * file - writable file stream to export registry branch to.
1233 * key - registry branch to export.
1234 * reg_key_name_buf - name of the key with registry class.
1235 * Is resized if necessary.
1236 * reg_key_name_size - length of the buffer for the registry class in characters.
1237 * val_name_buf - buffer for storing value name.
1238 * Is resized if necessary.
1239 * val_name_size - length of the buffer for storing value names in characters.
1240 * val_buf - buffer for storing values while extracting.
1241 * Is resized if necessary.
1242 * val_size - size of the buffer for storing values in bytes.
1244 static void export_hkey(FILE *file
, DWORD value_type
, BYTE
**val_buf
, DWORD
*val_size
,
1245 WCHAR
**line_buf
, DWORD
*line_buf_size
, BOOL unicode
)
1248 DWORD val_size1
= *val_size
;
1249 WCHAR
*wstr
= (WCHAR
*)*val_buf
;
1251 if (val_size1
< sizeof(WCHAR
) || val_size1
% sizeof(WCHAR
) ||
1252 wstr
[val_size1
/ sizeof(WCHAR
) - 1]) {
1253 REGPROC_export_binary(line_buf
, line_buf_size
, &line_len
, value_type
, *val_buf
, val_size1
, unicode
);
1255 const WCHAR start
[] = {'"',0};
1256 const WCHAR end
[] = {'"','\r','\n',0};
1259 len
= lstrlenW(start
);
1260 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, line_len
+ len
);
1261 lstrcpyW(*line_buf
+ line_len
, start
);
1264 REGPROC_export_string(line_buf
, line_buf_size
, &line_len
, wstr
, lstrlenW(wstr
));
1266 REGPROC_resize_char_buffer(line_buf
, line_buf_size
, line_len
+ lstrlenW(end
));
1267 lstrcpyW(*line_buf
+ line_len
, end
);
1269 REGPROC_write_line(file
, *line_buf
, unicode
);
1272 /******************************************************************************
1273 * Reads contents of the specified file into the registry.
1275 BOOL
import_registry_file(FILE *reg_file
)
1278 struct parser parser
;
1281 if (!reg_file
|| (fread(s
, 2, 1, reg_file
) != 1))
1284 parser
.is_unicode
= (s
[0] == 0xff && s
[1] == 0xfe);
1285 get_line
= parser
.is_unicode
? get_lineW
: get_lineA
;
1287 parser
.file
= reg_file
;
1288 parser
.two_wchars
[0] = s
[0];
1289 parser
.two_wchars
[1] = s
[1];
1290 parser
.reg_version
= -1;
1292 parser
.key_name
= NULL
;
1293 parser
.value_name
= NULL
;
1294 parser
.parse_type
= 0;
1295 parser
.data_type
= 0;
1297 parser
.data_size
= 0;
1298 parser
.backslash
= FALSE
;
1299 parser
.state
= HEADER
;
1301 pos
= parser
.two_wchars
;
1303 /* parser main loop */
1305 pos
= (parser_funcs
[parser
.state
])(&parser
, pos
);
1307 if (parser
.reg_version
== REG_VERSION_FUZZY
|| parser
.reg_version
== REG_VERSION_INVALID
)
1308 return parser
.reg_version
== REG_VERSION_FUZZY
;
1310 HeapFree(GetProcessHeap(), 0, parser
.value_name
);
1316 /******************************************************************************
1317 * Removes the registry key with all subkeys. Parses full key name.
1320 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
1321 * empty, points to register key class, does not exist.
1323 void delete_registry_key(WCHAR
*reg_key_name
)
1325 WCHAR
*key_name
= NULL
;
1328 if (!reg_key_name
|| !reg_key_name
[0])
1331 if (!(key_class
= parse_key_name(reg_key_name
, &key_name
)))
1333 if (key_name
) *(key_name
- 1) = 0;
1334 error_exit(STRING_INVALID_SYSTEM_KEY
, reg_key_name
);
1338 error_exit(STRING_DELETE_FAILED
, reg_key_name
);
1340 RegDeleteTreeW(key_class
, key_name
);
1343 static WCHAR
*REGPROC_escape_string(WCHAR
*str
, size_t str_len
, size_t *line_len
)
1345 size_t i
, escape_count
, pos
;
1348 for (i
= 0, escape_count
= 0; i
< str_len
; i
++)
1351 if (c
== '\r' || c
== '\n' || c
== '\\' || c
== '"' || c
== '\0')
1355 buf
= resize_buffer(NULL
, (str_len
+ escape_count
+ 1) * sizeof(WCHAR
));
1357 for (i
= 0, pos
= 0; i
< str_len
; i
++, pos
++)
1393 static size_t export_value_name(FILE *fp
, WCHAR
*name
, size_t len
, BOOL unicode
)
1395 static const WCHAR quoted_fmt
[] = {'"','%','s','"','=',0};
1396 static const WCHAR default_name
[] = {'@','=',0};
1401 WCHAR
*str
= REGPROC_escape_string(name
, len
, &line_len
);
1402 WCHAR
*buf
= resize_buffer(NULL
, (line_len
+ 4) * sizeof(WCHAR
));
1403 line_len
= sprintfW(buf
, quoted_fmt
, str
);
1404 REGPROC_write_line(fp
, buf
, unicode
);
1405 HeapFree(GetProcessHeap(), 0, buf
);
1406 HeapFree(GetProcessHeap(), 0, str
);
1410 line_len
= lstrlenW(default_name
);
1411 REGPROC_write_line(fp
, default_name
, unicode
);
1417 static void export_dword_data(WCHAR
**buf
, DWORD
*data
)
1419 static const WCHAR fmt
[] = {'d','w','o','r','d',':','%','0','8','x',0};
1421 *buf
= resize_buffer(NULL
, 15 * sizeof(WCHAR
));
1422 sprintfW(*buf
, fmt
, *data
);
1425 static size_t export_hex_data_type(FILE *fp
, DWORD type
, BOOL unicode
)
1427 static const WCHAR hex
[] = {'h','e','x',':',0};
1428 static const WCHAR hexp_fmt
[] = {'h','e','x','(','%','x',')',':',0};
1431 if (type
== REG_BINARY
)
1433 line_len
= lstrlenW(hex
);
1434 REGPROC_write_line(fp
, hex
, unicode
);
1438 WCHAR
*buf
= resize_buffer(NULL
, 15 * sizeof(WCHAR
));
1439 line_len
= sprintfW(buf
, hexp_fmt
, type
);
1440 REGPROC_write_line(fp
, buf
, unicode
);
1441 HeapFree(GetProcessHeap(), 0, buf
);
1447 #define MAX_HEX_CHARS 77
1449 static void export_hex_data(FILE *fp
, WCHAR
**buf
, DWORD type
, DWORD line_len
,
1450 void *data
, DWORD size
, BOOL unicode
)
1452 static const WCHAR fmt
[] = {'%','0','2','x',0};
1453 static const WCHAR hex_concat
[] = {'\\','\r','\n',' ',' ',0};
1454 size_t num_commas
, i
, pos
;
1456 line_len
+= export_hex_data_type(fp
, type
, unicode
);
1458 if (!unicode
&& (type
== REG_EXPAND_SZ
|| type
== REG_MULTI_SZ
))
1459 data
= GetMultiByteStringN(data
, size
/ sizeof(WCHAR
), &size
);
1461 num_commas
= size
- 1;
1462 *buf
= resize_buffer(NULL
, (size
* 3) * sizeof(WCHAR
));
1464 for (i
= 0, pos
= 0; i
< size
; i
++)
1466 pos
+= sprintfW(*buf
+ pos
, fmt
, ((BYTE
*)data
)[i
]);
1467 if (i
== num_commas
) break;
1468 (*buf
)[pos
++] = ',';
1472 if (line_len
>= MAX_HEX_CHARS
)
1474 REGPROC_write_line(fp
, *buf
, unicode
);
1475 REGPROC_write_line(fp
, hex_concat
, unicode
);
1482 static void export_data(FILE *fp
, DWORD type
, size_t line_len
, void *data
, size_t size
, BOOL unicode
)
1485 static const WCHAR newline
[] = {'\r','\n',0};
1490 export_dword_data(&buf
, data
);
1497 export_hex_data(fp
, &buf
, type
, line_len
, data
, size
, unicode
);
1501 REGPROC_write_line(fp
, buf
, unicode
);
1502 HeapFree(GetProcessHeap(), 0, buf
);
1503 REGPROC_write_line(fp
, newline
, unicode
);
1506 static WCHAR
*build_subkey_path(WCHAR
*path
, DWORD path_len
, WCHAR
*subkey_name
, DWORD subkey_len
)
1509 static const WCHAR fmt
[] = {'%','s','\\','%','s',0};
1511 subkey_path
= resize_buffer(NULL
, (path_len
+ subkey_len
+ 2) * sizeof(WCHAR
));
1512 sprintfW(subkey_path
, fmt
, path
, subkey_name
);
1517 static void export_key_name(FILE *fp
, WCHAR
*name
, BOOL unicode
)
1519 static const WCHAR fmt
[] = {'\r','\n','[','%','s',']','\r','\n',0};
1522 buf
= resize_buffer(NULL
, (lstrlenW(name
) + 7) * sizeof(WCHAR
));
1523 sprintfW(buf
, fmt
, name
);
1524 REGPROC_write_line(fp
, buf
, unicode
);
1525 HeapFree(GetProcessHeap(), 0, buf
);
1528 #define MAX_SUBKEY_LEN 257
1530 static int export_registry_data(FILE *fp
, HKEY key
, WCHAR
*path
, BOOL unicode
)
1533 DWORD line_buf_size
= KEY_MAX_LEN
+ REG_VAL_BUF_SIZE
;
1535 DWORD max_value_len
= 256, value_len
;
1536 DWORD max_data_bytes
= 2048, data_size
;
1538 DWORD i
, type
, path_len
;
1539 WCHAR
*value_name
, *subkey_name
, *subkey_path
;
1543 line_buf
= HeapAlloc(GetProcessHeap(), 0, line_buf_size
* sizeof(WCHAR
));
1544 CHECK_ENOUGH_MEMORY(line_buf
);
1546 export_key_name(fp
, path
, unicode
);
1548 value_name
= resize_buffer(NULL
, max_value_len
* sizeof(WCHAR
));
1549 data
= resize_buffer(NULL
, max_data_bytes
);
1554 value_len
= max_value_len
;
1555 data_size
= max_data_bytes
;
1556 rc
= RegEnumValueW(key
, i
, value_name
, &value_len
, NULL
, &type
, data
, &data_size
);
1557 if (rc
== ERROR_SUCCESS
)
1559 size_t line_len
= export_value_name(fp
, value_name
, value_len
, unicode
);
1561 export_data(fp
, type
, line_len
, data
, data_size
, unicode
);
1563 export_hkey(fp
, type
, &data
, &data_size
, &line_buf
, &line_buf_size
, unicode
);
1566 else if (rc
== ERROR_MORE_DATA
)
1568 if (data_size
> max_data_bytes
)
1570 max_data_bytes
*= 2;
1571 data
= resize_buffer(data
, max_data_bytes
);
1576 value_name
= resize_buffer(value_name
, max_value_len
* sizeof(WCHAR
));
1582 HeapFree(GetProcessHeap(), 0, data
);
1583 HeapFree(GetProcessHeap(), 0, value_name
);
1584 HeapFree(GetProcessHeap(), 0, line_buf
);
1586 subkey_name
= resize_buffer(NULL
, MAX_SUBKEY_LEN
* sizeof(WCHAR
));
1588 path_len
= lstrlenW(path
);
1593 subkey_len
= MAX_SUBKEY_LEN
;
1594 rc
= RegEnumKeyExW(key
, i
, subkey_name
, &subkey_len
, NULL
, NULL
, NULL
, NULL
);
1595 if (rc
== ERROR_SUCCESS
)
1597 subkey_path
= build_subkey_path(path
, path_len
, subkey_name
, subkey_len
);
1598 if (!RegOpenKeyExW(key
, subkey_name
, 0, KEY_READ
, &subkey
))
1600 export_registry_data(fp
, subkey
, subkey_path
, unicode
);
1601 RegCloseKey(subkey
);
1603 HeapFree(GetProcessHeap(), 0, subkey_path
);
1609 HeapFree(GetProcessHeap(), 0, subkey_name
);
1613 static FILE *REGPROC_open_export_file(WCHAR
*file_name
, BOOL unicode
)
1616 static const WCHAR hyphen
[] = {'-',0};
1618 if (!strcmpW(file_name
, hyphen
))
1621 _setmode(_fileno(file
), _O_BINARY
);
1625 static const WCHAR wb_mode
[] = {'w','b',0};
1627 file
= _wfopen(file_name
, wb_mode
);
1630 static const WCHAR regedit
[] = {'r','e','g','e','d','i','t',0};
1632 error_exit(STRING_CANNOT_OPEN_FILE
, file_name
);
1638 static const BYTE bom
[] = {0xff,0xfe};
1639 static const WCHAR header
[] = {'W','i','n','d','o','w','s',' ',
1640 'R','e','g','i','s','t','r','y',' ','E','d','i','t','o','r',' ',
1641 'V','e','r','s','i','o','n',' ','5','.','0','0','\r','\n'};
1643 fwrite(bom
, sizeof(BYTE
), ARRAY_SIZE(bom
), file
);
1644 fwrite(header
, sizeof(WCHAR
), ARRAY_SIZE(header
), file
);
1647 fputs("REGEDIT4\r\n", file
);
1652 static HKEY
open_export_key(HKEY key_class
, WCHAR
*subkey
, WCHAR
*path
)
1656 if (!RegOpenKeyExW(key_class
, subkey
, 0, KEY_READ
, &key
))
1659 output_message(STRING_OPEN_KEY_FAILED
, path
);
1663 static BOOL
export_key(WCHAR
*file_name
, WCHAR
*path
, BOOL unicode
)
1665 HKEY key_class
, key
;
1670 if (!(key_class
= parse_key_name(path
, &subkey
)))
1672 if (subkey
) *(subkey
- 1) = 0;
1673 output_message(STRING_INVALID_SYSTEM_KEY
, path
);
1677 if (!(key
= open_export_key(key_class
, subkey
, path
)))
1680 fp
= REGPROC_open_export_file(file_name
, unicode
);
1681 ret
= export_registry_data(fp
, key
, path
, unicode
);
1688 static BOOL
export_all(WCHAR
*file_name
, WCHAR
*path
, BOOL unicode
)
1692 HKEY classes
[] = {HKEY_LOCAL_MACHINE
, HKEY_USERS
}, key
;
1695 fp
= REGPROC_open_export_file(file_name
, unicode
);
1697 for (i
= 0; i
< ARRAY_SIZE(classes
); i
++)
1699 if (!(key
= open_export_key(classes
[i
], NULL
, path
)))
1705 class_name
= resize_buffer(NULL
, (lstrlenW(reg_class_namesW
[i
]) + 1) * sizeof(WCHAR
));
1706 lstrcpyW(class_name
, reg_class_namesW
[i
]);
1708 export_registry_data(fp
, classes
[i
], class_name
, unicode
);
1710 HeapFree(GetProcessHeap(), 0, class_name
);
1718 BOOL
export_registry_key(WCHAR
*file_name
, WCHAR
*path
, DWORD format
)
1720 BOOL unicode
= (format
== REG_FORMAT_5
);
1723 return export_key(file_name
, path
, unicode
);
1725 return export_all(file_name
, path
, unicode
);