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
;
278 else if (dwParseType
== REG_DWORD
) /* Convert the dword types */
280 if (!convertHexToDWord(val_data
, &dwData
))
281 return ERROR_INVALID_DATA
;
282 lpbData
= (BYTE
*)&dwData
;
283 dwLen
= sizeof(dwData
);
285 else if (dwParseType
== REG_BINARY
) /* Convert the binary data */
287 lpbData
= convertHexCSVToHex(val_data
, &dwLen
);
289 return ERROR_INVALID_DATA
;
291 else /* unknown format */
293 fprintf(stderr
,"%s: ERROR, unknown data format\n", getAppName());
294 return ERROR_INVALID_DATA
;
304 if (dwParseType
== REG_BINARY
)
305 HeapFree(GetProcessHeap(), 0, lpbData
);
309 /******************************************************************************
310 * A helper function for processRegEntry() that opens the current key.
311 * That key must be closed by calling closeKey().
313 static LONG
openKey(LPSTR stdInput
)
321 if (stdInput
== NULL
)
322 return ERROR_INVALID_PARAMETER
;
324 /* Get the registry class */
325 if (!parseKeyName(stdInput
, &keyClass
, &keyPath
))
326 return ERROR_INVALID_PARAMETER
;
328 res
= RegCreateKeyEx(
329 keyClass
, /* Class */
330 keyPath
, /* Sub Key */
332 NULL
, /* object type */
333 REG_OPTION_NON_VOLATILE
, /* option, REG_OPTION_NON_VOLATILE ... */
334 KEY_ALL_ACCESS
, /* access mask, KEY_ALL_ACCESS */
335 NULL
, /* security attribute */
336 ¤tKeyHandle
, /* result */
337 &dwDisp
); /* disposition, REG_CREATED_NEW_KEY or
338 REG_OPENED_EXISTING_KEY */
340 if (res
== ERROR_SUCCESS
)
342 currentKeyName
= HeapAlloc(GetProcessHeap(), 0, strlen(stdInput
)+1);
343 CHECK_ENOUGH_MEMORY(currentKeyName
);
344 strcpy(currentKeyName
, stdInput
);
348 currentKeyHandle
= NULL
;
355 /******************************************************************************
356 * Close the currently opened key.
358 static void closeKey(void)
360 if (currentKeyHandle
)
362 HeapFree(GetProcessHeap(), 0, currentKeyName
);
363 RegCloseKey(currentKeyHandle
);
364 currentKeyHandle
= NULL
;
368 /******************************************************************************
369 * This function is a wrapper for the setValue function. It prepares the
370 * land and cleans the area once completed.
371 * Note: this function modifies the line parameter.
373 * line - registry file unwrapped line. Should have the registry value name and
374 * complete registry value data.
376 static void processSetValue(LPSTR line
)
378 LPSTR val_name
; /* registry value name */
379 LPSTR val_data
; /* registry value data */
381 int line_idx
= 0; /* current character under analysis */
385 if (line
[line_idx
] == '@' && line
[line_idx
+ 1] == '=') {
386 line
[line_idx
] = '\0';
389 } else if (line
[line_idx
] == '\"') {
391 val_name
= line
+ line_idx
;
393 if (line
[line_idx
] == '\\') /* skip escaped character */
397 if (line
[line_idx
] == '\"') {
398 line
[line_idx
] = '\0';
406 if (line
[line_idx
] != '=') {
407 line
[line_idx
] = '\"';
408 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
413 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
416 line_idx
++; /* skip the '=' character */
417 val_data
= line
+ line_idx
;
419 REGPROC_unescape_string(val_name
);
420 res
= setValue(val_name
, val_data
);
421 if ( res
!= ERROR_SUCCESS
)
422 fprintf(stderr
,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
429 /******************************************************************************
430 * This function receives the currently read entry and performs the
431 * corresponding action.
433 static void processRegEntry(LPSTR stdInput
)
436 * We encountered the end of the file, make sure we
437 * close the opened key and exit
439 if (stdInput
== NULL
) {
444 if ( stdInput
[0] == '[') /* We are reading a new key */
447 closeKey(); /* Close the previous key */
449 /* Get rid of the square brackets */
451 keyEnd
= strrchr(stdInput
, ']');
455 /* delete the key if we encounter '-' at the start of reg key */
456 if ( stdInput
[0] == '-')
457 delete_registry_key(stdInput
+1);
458 else if ( openKey(stdInput
) != ERROR_SUCCESS
)
459 fprintf(stderr
,"%s: setValue failed to open key %s\n",
460 getAppName(), stdInput
);
461 } else if( currentKeyHandle
&&
462 (( stdInput
[0] == '@') || /* reading a default @=data pair */
463 ( stdInput
[0] == '\"'))) /* reading a new value=data pair */
465 processSetValue(stdInput
);
468 /* Since we are assuming that the file format is valid we must be
469 * reading a blank line which indicates the end of this key processing
475 /******************************************************************************
476 * Processes a registry file.
477 * Correctly processes comments (in # form), line continuation.
480 * in - input stream to read from
482 void processRegLines(FILE *in
)
484 LPSTR line
= NULL
; /* line read from input stream */
485 ULONG lineSize
= REG_VAL_BUF_SIZE
;
488 line
= HeapAlloc(GetProcessHeap(), 0, lineSize
);
489 CHECK_ENOUGH_MEMORY(line
);
491 if (fread(uni
, 2, 1, in
) == 1) {
492 if (uni
[0] == 0xff && uni
[1] == 0xfe) {
493 printf("Trying to import from a unicode file: this isn't supported yet.\n"
494 "Please use export as Win 9x/NT4 files from native regedit\n");
497 fseek(in
, -2, SEEK_CUR
);
500 LPSTR s
; /* The pointer into line for where the current fgets should read */
503 size_t size_remaining
;
505 char *s_eol
; /* various local uses */
507 /* Do we need to expand the buffer ? */
508 assert (s
>= line
&& s
<= line
+ lineSize
);
509 size_remaining
= lineSize
- (s
-line
);
510 if (size_remaining
< 2) /* room for 1 character and the \0 */
513 size_t new_size
= lineSize
+ REG_VAL_BUF_SIZE
;
514 if (new_size
> lineSize
) /* no arithmetic overflow */
515 new_buffer
= HeapReAlloc (GetProcessHeap(), 0, line
, new_size
);
518 CHECK_ENOUGH_MEMORY(new_buffer
);
520 s
= line
+ lineSize
- size_remaining
;
522 size_remaining
= lineSize
- (s
-line
);
525 /* Get as much as possible into the buffer, terminated either by
526 * eof, error, eol or getting the maximum amount. Abort on error.
528 size_to_get
= (size_remaining
> INT_MAX
? INT_MAX
: size_remaining
);
529 if (NULL
== fgets (s
, size_to_get
, in
)) {
531 perror ("While reading input");
536 /* It is not clear to me from the definition that the
537 * contents of the buffer are well defined on detecting
538 * an eof without managing to read anything.
543 /* If we didn't read the eol nor the eof go around for the rest */
544 s_eol
= strchr (s
, '\n');
545 if (!feof (in
) && !s_eol
) {
546 s
= strchr (s
, '\0');
547 /* It should be s + size_to_get - 1 but this is safer */
551 /* If it is a comment line then discard it and go around again */
552 if (line
[0] == '#') {
557 /* Remove any line feed. Leave s_eol on the \0 */
560 if (s_eol
> line
&& *(s_eol
-1) == '\r')
563 s_eol
= strchr (s
, '\0');
565 /* If there is a concatenating \\ then go around again */
566 if (s_eol
> line
&& *(s_eol
-1) == '\\') {
569 /* The following error protection could be made more self-
570 * correcting but I thought it not worth trying.
572 if ((c
= fgetc (in
)) == EOF
|| c
!= ' ' ||
573 (c
= fgetc (in
)) == EOF
|| c
!= ' ')
574 fprintf(stderr
,"%s: ERROR - invalid continuation.\n",
579 break; /* That is the full virtual line */
582 processRegEntry(line
);
584 processRegEntry(NULL
);
586 HeapFree(GetProcessHeap(), 0, line
);
589 /****************************************************************************
590 * REGPROC_print_error
592 * Print the message for GetLastError
595 static void REGPROC_print_error(void)
601 error_code
= GetLastError ();
602 status
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
603 NULL
, error_code
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
605 fprintf(stderr
,"%s: Cannot display message for error %d, status %d\n",
606 getAppName(), error_code
, GetLastError());
610 LocalFree((HLOCAL
)lpMsgBuf
);
614 /******************************************************************************
615 * Checks whether the buffer has enough room for the string or required size.
616 * Resizes the buffer if necessary.
619 * buffer - pointer to a buffer for string
620 * len - current length of the buffer in characters.
621 * required_len - length of the string to place to the buffer in characters.
622 * The length does not include the terminating null character.
624 static void REGPROC_resize_char_buffer(CHAR
**buffer
, DWORD
*len
, DWORD required_len
)
627 if (required_len
> *len
) {
630 *buffer
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(**buffer
));
632 *buffer
= HeapReAlloc(GetProcessHeap(), 0, *buffer
, *len
* sizeof(**buffer
));
633 CHECK_ENOUGH_MEMORY(*buffer
);
637 /******************************************************************************
638 * Prints string str to file
640 static void REGPROC_export_string(FILE *file
, CHAR
*str
)
642 size_t len
= strlen(str
);
645 /* escaping characters */
646 for (i
= 0; i
< len
; i
++) {
665 /******************************************************************************
666 * Writes contents of the registry key to the specified file stream.
669 * file - writable file stream to export registry branch to.
670 * key - registry branch to export.
671 * reg_key_name_buf - name of the key with registry class.
672 * Is resized if necessary.
673 * reg_key_name_len - length of the buffer for the registry class in characters.
674 * val_name_buf - buffer for storing value name.
675 * Is resized if necessary.
676 * val_name_len - length of the buffer for storing value names in characters.
677 * val_buf - buffer for storing values while extracting.
678 * Is resized if necessary.
679 * val_size - size of the buffer for storing values in bytes.
681 static void export_hkey(FILE *file
, HKEY key
,
682 CHAR
**reg_key_name_buf
, DWORD
*reg_key_name_len
,
683 CHAR
**val_name_buf
, DWORD
*val_name_len
,
684 BYTE
**val_buf
, DWORD
*val_size
)
686 DWORD max_sub_key_len
;
687 DWORD max_val_name_len
;
694 /* get size information and resize the buffers if necessary */
695 if (RegQueryInfoKey(key
, NULL
, NULL
, NULL
, NULL
,
696 &max_sub_key_len
, NULL
,
697 NULL
, &max_val_name_len
, &max_val_size
, NULL
, NULL
698 ) != ERROR_SUCCESS
) {
699 REGPROC_print_error();
701 curr_len
= strlen(*reg_key_name_buf
);
702 REGPROC_resize_char_buffer(reg_key_name_buf
, reg_key_name_len
,
703 max_sub_key_len
+ curr_len
+ 1);
704 REGPROC_resize_char_buffer(val_name_buf
, val_name_len
,
706 if (max_val_size
> *val_size
) {
707 *val_size
= max_val_size
;
708 if (!*val_buf
) *val_buf
= HeapAlloc(GetProcessHeap(), 0, *val_size
);
709 else *val_buf
= HeapReAlloc(GetProcessHeap(), 0, *val_buf
, *val_size
);
710 CHECK_ENOUGH_MEMORY(val_buf
);
713 /* output data for the current key */
715 fputs(*reg_key_name_buf
, file
);
717 /* print all the values */
722 DWORD val_name_len1
= *val_name_len
;
723 DWORD val_size1
= *val_size
;
724 ret
= RegEnumValue(key
, i
, *val_name_buf
, &val_name_len1
, NULL
,
725 &value_type
, *val_buf
, &val_size1
);
726 if (ret
!= ERROR_SUCCESS
) {
728 if (ret
!= ERROR_NO_MORE_ITEMS
) {
729 REGPROC_print_error();
734 if ((*val_name_buf
)[0]) {
736 REGPROC_export_string(file
, *val_name_buf
);
742 switch (value_type
) {
746 REGPROC_export_string(file
, (char*) *val_buf
);
751 fprintf(file
, "dword:%08x\n", *((DWORD
*)*val_buf
));
755 fprintf(stderr
,"%s: warning - unsupported registry format '%d', "
757 getAppName(), value_type
);
758 fprintf(stderr
,"key name: \"%s\"\n", *reg_key_name_buf
);
759 fprintf(stderr
,"value name:\"%s\"\n\n", *val_name_buf
);
765 const CHAR
*hex_prefix
;
769 if (value_type
== REG_BINARY
) {
773 sprintf(buf
, "hex(%d):", value_type
);
776 /* position of where the next character will be printed */
777 /* NOTE: yes, strlen("hex:") is used even for hex(x): */
778 cur_pos
= strlen("\"\"=") + strlen("hex:") +
779 strlen(*val_name_buf
);
781 fputs(hex_prefix
, file
);
782 for (i1
= 0; i1
< val_size1
; i1
++) {
783 fprintf(file
, "%02x", (unsigned int)(*val_buf
)[i1
]);
784 if (i1
+ 1 < val_size1
) {
790 if (cur_pos
> REG_FILE_HEX_LINE_LEN
) {
791 fputs("\\\n ", file
);
804 (*reg_key_name_buf
)[curr_len
] = '\\';
806 DWORD buf_len
= *reg_key_name_len
- curr_len
;
808 ret
= RegEnumKeyEx(key
, i
, *reg_key_name_buf
+ curr_len
+ 1, &buf_len
,
809 NULL
, NULL
, NULL
, NULL
);
810 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_MORE_DATA
) {
812 if (ret
!= ERROR_NO_MORE_ITEMS
) {
813 REGPROC_print_error();
819 if (RegOpenKey(key
, *reg_key_name_buf
+ curr_len
+ 1,
820 &subkey
) == ERROR_SUCCESS
) {
821 export_hkey(file
, subkey
, reg_key_name_buf
, reg_key_name_len
,
822 val_name_buf
, val_name_len
, val_buf
, val_size
);
825 REGPROC_print_error();
829 (*reg_key_name_buf
)[curr_len
] = '\0';
832 /******************************************************************************
833 * Open file for export.
835 static FILE *REGPROC_open_export_file(CHAR
*file_name
)
839 if (strcmp(file_name
,"-")==0)
843 file
= fopen(file_name
, "w");
846 fprintf(stderr
,"%s: Can't open file \"%s\"\n", getAppName(), file_name
);
850 fputs("REGEDIT4\n", file
);
854 /******************************************************************************
855 * Writes contents of the registry key to the specified file stream.
858 * file_name - name of a file to export registry branch to.
859 * reg_key_name - registry branch to export. The whole registry is exported if
860 * reg_key_name is NULL or contains an empty string.
862 BOOL
export_registry_key(CHAR
*file_name
, CHAR
*reg_key_name
)
864 CHAR
*reg_key_name_buf
;
867 DWORD reg_key_name_len
= KEY_MAX_LEN
;
868 DWORD val_name_len
= KEY_MAX_LEN
;
869 DWORD val_size
= REG_VAL_BUF_SIZE
;
872 reg_key_name_buf
= HeapAlloc(GetProcessHeap(), 0,
873 reg_key_name_len
* sizeof(*reg_key_name_buf
));
874 val_name_buf
= HeapAlloc(GetProcessHeap(), 0,
875 val_name_len
* sizeof(*val_name_buf
));
876 val_buf
= HeapAlloc(GetProcessHeap(), 0, val_size
);
877 CHECK_ENOUGH_MEMORY(reg_key_name_buf
&& val_name_buf
&& val_buf
);
879 if (reg_key_name
&& reg_key_name
[0]) {
884 REGPROC_resize_char_buffer(®_key_name_buf
, ®_key_name_len
,
885 strlen(reg_key_name
));
886 strcpy(reg_key_name_buf
, reg_key_name
);
888 /* open the specified key */
889 if (!parseKeyName(reg_key_name
, ®_key_class
, &branch_name
)) {
890 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
891 getAppName(), reg_key_name
);
894 if (!branch_name
[0]) {
895 /* no branch - registry class is specified */
896 file
= REGPROC_open_export_file(file_name
);
897 export_hkey(file
, reg_key_class
,
898 ®_key_name_buf
, ®_key_name_len
,
899 &val_name_buf
, &val_name_len
,
900 &val_buf
, &val_size
);
901 } else if (RegOpenKey(reg_key_class
, branch_name
, &key
) == ERROR_SUCCESS
) {
902 file
= REGPROC_open_export_file(file_name
);
903 export_hkey(file
, key
,
904 ®_key_name_buf
, ®_key_name_len
,
905 &val_name_buf
, &val_name_len
,
906 &val_buf
, &val_size
);
909 fprintf(stderr
,"%s: Can't export. Registry key '%s' does not exist!\n",
910 getAppName(), reg_key_name
);
911 REGPROC_print_error();
916 /* export all registry classes */
917 file
= REGPROC_open_export_file(file_name
);
918 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
919 /* do not export HKEY_CLASSES_ROOT */
920 if (reg_class_keys
[i
] != HKEY_CLASSES_ROOT
&&
921 reg_class_keys
[i
] != HKEY_CURRENT_USER
&&
922 reg_class_keys
[i
] != HKEY_CURRENT_CONFIG
&&
923 reg_class_keys
[i
] != HKEY_DYN_DATA
) {
924 strcpy(reg_key_name_buf
, reg_class_names
[i
]);
925 export_hkey(file
, reg_class_keys
[i
],
926 ®_key_name_buf
, ®_key_name_len
,
927 &val_name_buf
, &val_name_len
,
928 &val_buf
, &val_size
);
936 HeapFree(GetProcessHeap(), 0, reg_key_name
);
937 HeapFree(GetProcessHeap(), 0, val_buf
);
941 /******************************************************************************
942 * Reads contents of the specified file into the registry.
944 BOOL
import_registry_file(LPTSTR filename
)
946 FILE* reg_file
= fopen(filename
, "r");
949 processRegLines(reg_file
);
955 /******************************************************************************
956 * Removes the registry key with all subkeys. Parses full key name.
959 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
960 * empty, points to register key class, does not exist.
962 void delete_registry_key(CHAR
*reg_key_name
)
967 if (!reg_key_name
|| !reg_key_name
[0])
970 if (!parseKeyName(reg_key_name
, &key_class
, &key_name
)) {
971 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
972 getAppName(), reg_key_name
);
976 fprintf(stderr
,"%s: Can't delete registry class '%s'\n",
977 getAppName(), reg_key_name
);
981 RegDeleteTreeA(key_class
, key_name
);