2 * Registry processing routines. Routines, common for registry
3 * processing frontends.
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define REG_VAL_BUF_SIZE 4096
33 /* maximal number of characters in hexadecimal data line,
34 not including '\' character */
35 #define REG_FILE_HEX_LINE_LEN 76
37 static const CHAR
*reg_class_names
[] = {
38 "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
39 "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
42 #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
44 static HKEY reg_class_keys
[REG_CLASS_NUMBER
] = {
45 HKEY_LOCAL_MACHINE
, HKEY_USERS
, HKEY_CLASSES_ROOT
,
46 HKEY_CURRENT_CONFIG
, HKEY_CURRENT_USER
, HKEY_DYN_DATA
50 #define NOT_ENOUGH_MEMORY 1
53 /* processing macros */
55 /* common check of memory allocation results */
56 #define CHECK_ENOUGH_MEMORY(p) \
59 fprintf(stderr,"%s: file %s, line %d: Not enough memory\n", \
60 getAppName(), __FILE__, __LINE__); \
61 exit(NOT_ENOUGH_MEMORY); \
64 /******************************************************************************
65 * Converts a hex representation of a DWORD into a DWORD.
67 static BOOL
convertHexToDWord(char* str
, DWORD
*dw
)
70 if (strlen(str
) > 8 || sscanf(str
, "%x%c", dw
, &dummy
) != 1) {
71 fprintf(stderr
,"%s: ERROR, invalid hex value\n", getAppName());
77 /******************************************************************************
78 * Converts a hex comma separated values list into a binary string.
80 static BYTE
* convertHexCSVToHex(char *str
, DWORD
*size
)
85 /* The worst case is 1 digit + 1 comma per byte */
86 *size
=(strlen(str
)+1)/2;
87 data
=HeapAlloc(GetProcessHeap(), 0, *size
);
88 CHECK_ENOUGH_MEMORY(data
);
97 wc
= strtoul(s
,&end
,16);
98 if (end
== s
|| wc
> 0xff || (*end
&& *end
!= ',')) {
99 fprintf(stderr
,"%s: ERROR converting CSV hex stream. Invalid value at '%s'\n",
101 HeapFree(GetProcessHeap(), 0, data
);
113 /******************************************************************************
114 * This function returns the HKEY associated with the data type encoded in the
115 * value. It modifies the input parameter (key value) in order to skip this
116 * "now useless" data type information.
118 * Note: Updated based on the algorithm used in 'server/registry.c'
120 static DWORD
getDataType(LPSTR
*lpValue
, DWORD
* parse_type
)
122 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
124 static const struct data_type data_types
[] = { /* actual type */ /* type to assume for parsing */
125 { "\"", 1, REG_SZ
, REG_SZ
},
126 { "str:\"", 5, REG_SZ
, REG_SZ
},
127 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
128 { "hex:", 4, REG_BINARY
, REG_BINARY
},
129 { "dword:", 6, REG_DWORD
, REG_DWORD
},
130 { "hex(", 4, -1, REG_BINARY
},
134 const struct data_type
*ptr
;
137 for (ptr
= data_types
; ptr
->tag
; ptr
++) {
138 if (memcmp( ptr
->tag
, *lpValue
, ptr
->len
))
142 *parse_type
= ptr
->parse_type
;
147 /* "hex(xx):" is special */
148 type
= (int)strtoul( *lpValue
, &end
, 16 );
149 if (**lpValue
=='\0' || *end
!=')' || *(end
+1)!=':') {
157 *parse_type
=REG_NONE
;
161 /******************************************************************************
162 * Replaces escape sequences with the characters.
164 static void REGPROC_unescape_string(LPSTR str
)
166 int str_idx
= 0; /* current character under analysis */
167 int val_idx
= 0; /* the last character of the unescaped string */
168 int len
= strlen(str
);
169 for (str_idx
= 0; str_idx
< len
; str_idx
++, val_idx
++) {
170 if (str
[str_idx
] == '\\') {
172 switch (str
[str_idx
]) {
178 str
[val_idx
] = str
[str_idx
];
181 fprintf(stderr
,"Warning! Unrecognized escape sequence: \\%c'\n",
183 str
[val_idx
] = str
[str_idx
];
187 str
[val_idx
] = str
[str_idx
];
193 /******************************************************************************
194 * Parses HKEY_SOME_ROOT\some\key\path to get the root key handle and
195 * extract the key path (what comes after the first '\').
197 static BOOL
parseKeyName(LPSTR lpKeyName
, HKEY
*hKey
, LPSTR
*lpKeyPath
)
202 if (lpKeyName
== NULL
)
205 lpSlash
= strchr(lpKeyName
, '\\');
208 len
= lpSlash
-lpKeyName
;
212 len
= strlen(lpKeyName
);
213 lpSlash
= lpKeyName
+len
;
216 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
217 if (strncmp(lpKeyName
, reg_class_names
[i
], len
) == 0 &&
218 len
== strlen(reg_class_names
[i
])) {
219 *hKey
= reg_class_keys
[i
];
226 if (*lpSlash
!= '\0')
228 *lpKeyPath
= lpSlash
;
232 /* Globals used by the setValue() & co */
233 static LPSTR currentKeyName
;
234 static HKEY currentKeyHandle
= NULL
;
236 /******************************************************************************
237 * Sets the value with name val_name to the data in val_data for the currently
241 * val_name - name of the registry value
242 * val_data - registry value data
244 static LONG
setValue(LPSTR val_name
, LPSTR val_data
)
247 DWORD dwDataType
, dwParseType
;
251 if ( (val_name
== NULL
) || (val_data
== NULL
) )
252 return ERROR_INVALID_PARAMETER
;
254 if (strcmp(val_data
, "-") == 0)
256 res
=RegDeleteValue(currentKeyHandle
,val_name
);
257 return (res
== ERROR_FILE_NOT_FOUND
? ERROR_SUCCESS
: res
);
260 /* Get the data type stored into the value field */
261 dwDataType
= getDataType(&val_data
, &dwParseType
);
263 if (dwParseType
== REG_SZ
) /* no conversion for string */
265 REGPROC_unescape_string(val_data
);
266 /* Compute dwLen after REGPROC_unescape_string because it may
267 * have changed the string length and we don't want to store
268 * the extra garbage in the registry.
270 dwLen
= strlen(val_data
);
271 if (dwLen
>0 && val_data
[dwLen
-1]=='"')
274 val_data
[dwLen
]='\0';
276 lpbData
= (BYTE
*) val_data
;
277 dwLen
++; /* include terminating null */
279 else if (dwParseType
== REG_DWORD
) /* Convert the dword types */
281 if (!convertHexToDWord(val_data
, &dwData
))
282 return ERROR_INVALID_DATA
;
283 lpbData
= (BYTE
*)&dwData
;
284 dwLen
= sizeof(dwData
);
286 else if (dwParseType
== REG_BINARY
) /* Convert the binary data */
288 lpbData
= convertHexCSVToHex(val_data
, &dwLen
);
290 return ERROR_INVALID_DATA
;
292 else /* unknown format */
294 fprintf(stderr
,"%s: ERROR, unknown data format\n", getAppName());
295 return ERROR_INVALID_DATA
;
305 if (dwParseType
== REG_BINARY
)
306 HeapFree(GetProcessHeap(), 0, lpbData
);
310 /******************************************************************************
311 * A helper function for processRegEntry() that opens the current key.
312 * That key must be closed by calling closeKey().
314 static LONG
openKey(LPSTR stdInput
)
322 if (stdInput
== NULL
)
323 return ERROR_INVALID_PARAMETER
;
325 /* Get the registry class */
326 if (!parseKeyName(stdInput
, &keyClass
, &keyPath
))
327 return ERROR_INVALID_PARAMETER
;
329 res
= RegCreateKeyEx(
330 keyClass
, /* Class */
331 keyPath
, /* Sub Key */
333 NULL
, /* object type */
334 REG_OPTION_NON_VOLATILE
, /* option, REG_OPTION_NON_VOLATILE ... */
335 KEY_ALL_ACCESS
, /* access mask, KEY_ALL_ACCESS */
336 NULL
, /* security attribute */
337 ¤tKeyHandle
, /* result */
338 &dwDisp
); /* disposition, REG_CREATED_NEW_KEY or
339 REG_OPENED_EXISTING_KEY */
341 if (res
== ERROR_SUCCESS
)
343 currentKeyName
= HeapAlloc(GetProcessHeap(), 0, strlen(stdInput
)+1);
344 CHECK_ENOUGH_MEMORY(currentKeyName
);
345 strcpy(currentKeyName
, stdInput
);
349 currentKeyHandle
= NULL
;
356 /******************************************************************************
357 * Close the currently opened key.
359 static void closeKey(void)
361 if (currentKeyHandle
)
363 HeapFree(GetProcessHeap(), 0, currentKeyName
);
364 RegCloseKey(currentKeyHandle
);
365 currentKeyHandle
= NULL
;
369 /******************************************************************************
370 * This function is a wrapper for the setValue function. It prepares the
371 * land and cleans the area once completed.
372 * Note: this function modifies the line parameter.
374 * line - registry file unwrapped line. Should have the registry value name and
375 * complete registry value data.
377 static void processSetValue(LPSTR line
)
379 LPSTR val_name
; /* registry value name */
380 LPSTR val_data
; /* registry value data */
382 int line_idx
= 0; /* current character under analysis */
386 if (line
[line_idx
] == '@' && line
[line_idx
+ 1] == '=') {
387 line
[line_idx
] = '\0';
390 } else if (line
[line_idx
] == '\"') {
392 val_name
= line
+ line_idx
;
394 if (line
[line_idx
] == '\\') /* skip escaped character */
398 if (line
[line_idx
] == '\"') {
399 line
[line_idx
] = '\0';
407 if (line
[line_idx
] != '=') {
408 line
[line_idx
] = '\"';
409 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
414 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
417 line_idx
++; /* skip the '=' character */
418 val_data
= line
+ line_idx
;
420 REGPROC_unescape_string(val_name
);
421 res
= setValue(val_name
, val_data
);
422 if ( res
!= ERROR_SUCCESS
)
423 fprintf(stderr
,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
430 /******************************************************************************
431 * This function receives the currently read entry and performs the
432 * corresponding action.
434 static void processRegEntry(LPSTR stdInput
)
437 * We encountered the end of the file, make sure we
438 * close the opened key and exit
440 if (stdInput
== NULL
) {
445 if ( stdInput
[0] == '[') /* We are reading a new key */
448 closeKey(); /* Close the previous key */
450 /* Get rid of the square brackets */
452 keyEnd
= strrchr(stdInput
, ']');
456 /* delete the key if we encounter '-' at the start of reg key */
457 if ( stdInput
[0] == '-')
458 delete_registry_key(stdInput
+1);
459 else if ( openKey(stdInput
) != ERROR_SUCCESS
)
460 fprintf(stderr
,"%s: setValue failed to open key %s\n",
461 getAppName(), stdInput
);
462 } else if( currentKeyHandle
&&
463 (( stdInput
[0] == '@') || /* reading a default @=data pair */
464 ( stdInput
[0] == '\"'))) /* reading a new value=data pair */
466 processSetValue(stdInput
);
469 /* Since we are assuming that the file format is valid we must be
470 * reading a blank line which indicates the end of this key processing
476 /******************************************************************************
477 * Processes a registry file.
478 * Correctly processes comments (in # form), line continuation.
481 * in - input stream to read from
483 void processRegLines(FILE *in
)
485 LPSTR line
= NULL
; /* line read from input stream */
486 ULONG lineSize
= REG_VAL_BUF_SIZE
;
487 BOOL unicode_check
= TRUE
;
489 line
= HeapAlloc(GetProcessHeap(), 0, lineSize
);
490 CHECK_ENOUGH_MEMORY(line
);
493 LPSTR s
; /* The pointer into line for where the current fgets should read */
497 size_t size_remaining
;
499 char *s_eol
; /* various local uses */
501 /* Do we need to expand the buffer ? */
502 assert (s
>= line
&& s
<= line
+ lineSize
);
503 size_remaining
= lineSize
- (s
-line
);
504 if (size_remaining
< 2) /* room for 1 character and the \0 */
507 size_t new_size
= lineSize
+ REG_VAL_BUF_SIZE
;
508 if (new_size
> lineSize
) /* no arithmetic overflow */
509 new_buffer
= HeapReAlloc (GetProcessHeap(), 0, line
, new_size
);
512 CHECK_ENOUGH_MEMORY(new_buffer
);
514 s
= line
+ lineSize
- size_remaining
;
516 size_remaining
= lineSize
- (s
-line
);
519 /* Get as much as possible into the buffer, terminated either by
520 * eof, error, eol or getting the maximum amount. Abort on error.
522 size_to_get
= (size_remaining
> INT_MAX
? INT_MAX
: size_remaining
);
526 if (fread( s
, 2, 1, in
) == 1)
528 if ((BYTE
)s
[0] == 0xff && (BYTE
)s
[1] == 0xfe)
530 printf("Trying to import from a unicode file: this isn't supported yet.\n"
531 "Please use export as Win 9x/NT4 files from native regedit\n");
532 HeapFree(GetProcessHeap(), 0, line
);
537 unicode_check
= FALSE
;
538 check
= fgets (&s
[2], size_to_get
-2, in
);
543 unicode_check
= FALSE
;
548 check
= fgets (s
, size_to_get
, in
);
552 perror ("While reading input");
557 /* It is not clear to me from the definition that the
558 * contents of the buffer are well defined on detecting
559 * an eof without managing to read anything.
564 /* If we didn't read the eol nor the eof go around for the rest */
565 s_eol
= strchr (s
, '\n');
566 if (!feof (in
) && !s_eol
) {
567 s
= strchr (s
, '\0');
568 /* It should be s + size_to_get - 1 but this is safer */
572 /* If it is a comment line then discard it and go around again */
573 if (line
[0] == '#') {
578 /* Remove any line feed. Leave s_eol on the \0 */
581 if (s_eol
> line
&& *(s_eol
-1) == '\r')
584 s_eol
= strchr (s
, '\0');
586 /* If there is a concatenating \\ then go around again */
587 if (s_eol
> line
&& *(s_eol
-1) == '\\') {
590 /* The following error protection could be made more self-
591 * correcting but I thought it not worth trying.
593 if ((c
= fgetc (in
)) == EOF
|| c
!= ' ' ||
594 (c
= fgetc (in
)) == EOF
|| c
!= ' ')
595 fprintf(stderr
,"%s: ERROR - invalid continuation.\n",
600 break; /* That is the full virtual line */
603 processRegEntry(line
);
605 processRegEntry(NULL
);
607 HeapFree(GetProcessHeap(), 0, line
);
610 /****************************************************************************
611 * REGPROC_print_error
613 * Print the message for GetLastError
616 static void REGPROC_print_error(void)
622 error_code
= GetLastError ();
623 status
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
624 NULL
, error_code
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
626 fprintf(stderr
,"%s: Cannot display message for error %d, status %d\n",
627 getAppName(), error_code
, GetLastError());
631 LocalFree((HLOCAL
)lpMsgBuf
);
635 /******************************************************************************
636 * Checks whether the buffer has enough room for the string or required size.
637 * Resizes the buffer if necessary.
640 * buffer - pointer to a buffer for string
641 * len - current length of the buffer in characters.
642 * required_len - length of the string to place to the buffer in characters.
643 * The length does not include the terminating null character.
645 static void REGPROC_resize_char_buffer(CHAR
**buffer
, DWORD
*len
, DWORD required_len
)
648 if (required_len
> *len
) {
651 *buffer
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(**buffer
));
653 *buffer
= HeapReAlloc(GetProcessHeap(), 0, *buffer
, *len
* sizeof(**buffer
));
654 CHECK_ENOUGH_MEMORY(*buffer
);
658 /******************************************************************************
659 * Prints string str to file
661 static void REGPROC_export_string(FILE *file
, CHAR
*str
)
663 size_t len
= strlen(str
);
666 /* escaping characters */
667 for (i
= 0; i
< len
; i
++) {
686 /******************************************************************************
687 * Writes contents of the registry key to the specified file stream.
690 * file - writable file stream to export registry branch to.
691 * key - registry branch to export.
692 * reg_key_name_buf - name of the key with registry class.
693 * Is resized if necessary.
694 * reg_key_name_len - length of the buffer for the registry class in characters.
695 * val_name_buf - buffer for storing value name.
696 * Is resized if necessary.
697 * val_name_len - length of the buffer for storing value names in characters.
698 * val_buf - buffer for storing values while extracting.
699 * Is resized if necessary.
700 * val_size - size of the buffer for storing values in bytes.
702 static void export_hkey(FILE *file
, HKEY key
,
703 CHAR
**reg_key_name_buf
, DWORD
*reg_key_name_len
,
704 CHAR
**val_name_buf
, DWORD
*val_name_len
,
705 BYTE
**val_buf
, DWORD
*val_size
)
707 DWORD max_sub_key_len
;
708 DWORD max_val_name_len
;
715 /* get size information and resize the buffers if necessary */
716 if (RegQueryInfoKey(key
, NULL
, NULL
, NULL
, NULL
,
717 &max_sub_key_len
, NULL
,
718 NULL
, &max_val_name_len
, &max_val_size
, NULL
, NULL
719 ) != ERROR_SUCCESS
) {
720 REGPROC_print_error();
722 curr_len
= strlen(*reg_key_name_buf
);
723 REGPROC_resize_char_buffer(reg_key_name_buf
, reg_key_name_len
,
724 max_sub_key_len
+ curr_len
+ 1);
725 REGPROC_resize_char_buffer(val_name_buf
, val_name_len
,
727 if (max_val_size
> *val_size
) {
728 *val_size
= max_val_size
;
729 if (!*val_buf
) *val_buf
= HeapAlloc(GetProcessHeap(), 0, *val_size
);
730 else *val_buf
= HeapReAlloc(GetProcessHeap(), 0, *val_buf
, *val_size
);
731 CHECK_ENOUGH_MEMORY(val_buf
);
734 /* output data for the current key */
736 fputs(*reg_key_name_buf
, file
);
738 /* print all the values */
743 DWORD val_name_len1
= *val_name_len
;
744 DWORD val_size1
= *val_size
;
745 ret
= RegEnumValue(key
, i
, *val_name_buf
, &val_name_len1
, NULL
,
746 &value_type
, *val_buf
, &val_size1
);
747 if (ret
!= ERROR_SUCCESS
) {
749 if (ret
!= ERROR_NO_MORE_ITEMS
) {
750 REGPROC_print_error();
755 if ((*val_name_buf
)[0]) {
757 REGPROC_export_string(file
, *val_name_buf
);
763 switch (value_type
) {
767 REGPROC_export_string(file
, (char*) *val_buf
);
772 fprintf(file
, "dword:%08x\n", *((DWORD
*)*val_buf
));
776 fprintf(stderr
,"%s: warning - unsupported registry format '%d', "
778 getAppName(), value_type
);
779 fprintf(stderr
,"key name: \"%s\"\n", *reg_key_name_buf
);
780 fprintf(stderr
,"value name:\"%s\"\n\n", *val_name_buf
);
786 const CHAR
*hex_prefix
;
790 if (value_type
== REG_BINARY
) {
794 sprintf(buf
, "hex(%d):", value_type
);
797 /* position of where the next character will be printed */
798 /* NOTE: yes, strlen("hex:") is used even for hex(x): */
799 cur_pos
= strlen("\"\"=") + strlen("hex:") +
800 strlen(*val_name_buf
);
802 fputs(hex_prefix
, file
);
803 for (i1
= 0; i1
< val_size1
; i1
++) {
804 fprintf(file
, "%02x", (unsigned int)(*val_buf
)[i1
]);
805 if (i1
+ 1 < val_size1
) {
811 if (cur_pos
> REG_FILE_HEX_LINE_LEN
) {
812 fputs("\\\n ", file
);
825 (*reg_key_name_buf
)[curr_len
] = '\\';
827 DWORD buf_len
= *reg_key_name_len
- curr_len
;
829 ret
= RegEnumKeyEx(key
, i
, *reg_key_name_buf
+ curr_len
+ 1, &buf_len
,
830 NULL
, NULL
, NULL
, NULL
);
831 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_MORE_DATA
) {
833 if (ret
!= ERROR_NO_MORE_ITEMS
) {
834 REGPROC_print_error();
840 if (RegOpenKey(key
, *reg_key_name_buf
+ curr_len
+ 1,
841 &subkey
) == ERROR_SUCCESS
) {
842 export_hkey(file
, subkey
, reg_key_name_buf
, reg_key_name_len
,
843 val_name_buf
, val_name_len
, val_buf
, val_size
);
846 REGPROC_print_error();
850 (*reg_key_name_buf
)[curr_len
] = '\0';
853 /******************************************************************************
854 * Open file for export.
856 static FILE *REGPROC_open_export_file(CHAR
*file_name
)
860 if (strcmp(file_name
,"-")==0)
864 file
= fopen(file_name
, "w");
867 fprintf(stderr
,"%s: Can't open file \"%s\"\n", getAppName(), file_name
);
871 fputs("REGEDIT4\n", file
);
875 /******************************************************************************
876 * Writes contents of the registry key to the specified file stream.
879 * file_name - name of a file to export registry branch to.
880 * reg_key_name - registry branch to export. The whole registry is exported if
881 * reg_key_name is NULL or contains an empty string.
883 BOOL
export_registry_key(CHAR
*file_name
, CHAR
*reg_key_name
)
885 CHAR
*reg_key_name_buf
;
888 DWORD reg_key_name_len
= KEY_MAX_LEN
;
889 DWORD val_name_len
= KEY_MAX_LEN
;
890 DWORD val_size
= REG_VAL_BUF_SIZE
;
893 reg_key_name_buf
= HeapAlloc(GetProcessHeap(), 0,
894 reg_key_name_len
* sizeof(*reg_key_name_buf
));
895 val_name_buf
= HeapAlloc(GetProcessHeap(), 0,
896 val_name_len
* sizeof(*val_name_buf
));
897 val_buf
= HeapAlloc(GetProcessHeap(), 0, val_size
);
898 CHECK_ENOUGH_MEMORY(reg_key_name_buf
&& val_name_buf
&& val_buf
);
900 if (reg_key_name
&& reg_key_name
[0]) {
905 REGPROC_resize_char_buffer(®_key_name_buf
, ®_key_name_len
,
906 strlen(reg_key_name
));
907 strcpy(reg_key_name_buf
, reg_key_name
);
909 /* open the specified key */
910 if (!parseKeyName(reg_key_name
, ®_key_class
, &branch_name
)) {
911 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
912 getAppName(), reg_key_name
);
915 if (!branch_name
[0]) {
916 /* no branch - registry class is specified */
917 file
= REGPROC_open_export_file(file_name
);
918 export_hkey(file
, reg_key_class
,
919 ®_key_name_buf
, ®_key_name_len
,
920 &val_name_buf
, &val_name_len
,
921 &val_buf
, &val_size
);
922 } else if (RegOpenKey(reg_key_class
, branch_name
, &key
) == ERROR_SUCCESS
) {
923 file
= REGPROC_open_export_file(file_name
);
924 export_hkey(file
, key
,
925 ®_key_name_buf
, ®_key_name_len
,
926 &val_name_buf
, &val_name_len
,
927 &val_buf
, &val_size
);
930 fprintf(stderr
,"%s: Can't export. Registry key '%s' does not exist!\n",
931 getAppName(), reg_key_name
);
932 REGPROC_print_error();
937 /* export all registry classes */
938 file
= REGPROC_open_export_file(file_name
);
939 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
940 /* do not export HKEY_CLASSES_ROOT */
941 if (reg_class_keys
[i
] != HKEY_CLASSES_ROOT
&&
942 reg_class_keys
[i
] != HKEY_CURRENT_USER
&&
943 reg_class_keys
[i
] != HKEY_CURRENT_CONFIG
&&
944 reg_class_keys
[i
] != HKEY_DYN_DATA
) {
945 strcpy(reg_key_name_buf
, reg_class_names
[i
]);
946 export_hkey(file
, reg_class_keys
[i
],
947 ®_key_name_buf
, ®_key_name_len
,
948 &val_name_buf
, &val_name_len
,
949 &val_buf
, &val_size
);
957 HeapFree(GetProcessHeap(), 0, reg_key_name
);
958 HeapFree(GetProcessHeap(), 0, val_buf
);
962 /******************************************************************************
963 * Reads contents of the specified file into the registry.
965 BOOL
import_registry_file(LPTSTR filename
)
967 FILE* reg_file
= fopen(filename
, "r");
970 processRegLines(reg_file
);
976 /******************************************************************************
977 * Removes the registry key with all subkeys. Parses full key name.
980 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
981 * empty, points to register key class, does not exist.
983 void delete_registry_key(CHAR
*reg_key_name
)
988 if (!reg_key_name
|| !reg_key_name
[0])
991 if (!parseKeyName(reg_key_name
, &key_class
, &key_name
)) {
992 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
993 getAppName(), reg_key_name
);
997 fprintf(stderr
,"%s: Can't delete registry class '%s'\n",
998 getAppName(), reg_key_name
);
1002 RegDeleteTreeA(key_class
, key_name
);