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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define REG_VAL_BUF_SIZE 4096
37 /* Delimiters used to parse the "value" to query queryValue*/
38 #define QUERY_VALUE_MAX_ARGS 1
40 /* maximal number of characters in hexadecimal data line,
41 not including '\' character */
42 #define REG_FILE_HEX_LINE_LEN 76
44 /* Globals used by the api setValue, queryValue */
45 static LPSTR currentKeyName
= NULL
;
46 static HKEY currentKeyClass
= 0;
47 static HKEY currentKeyHandle
= 0;
48 static BOOL bTheKeyIsOpen
= FALSE
;
50 static const CHAR
*app_name
= "UNKNOWN";
52 static const CHAR
*reg_class_names
[] = {
53 "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT",
54 "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA"
57 #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0]))
59 static HKEY reg_class_keys
[REG_CLASS_NUMBER
] = {
60 HKEY_LOCAL_MACHINE
, HKEY_USERS
, HKEY_CLASSES_ROOT
,
61 HKEY_CURRENT_CONFIG
, HKEY_CURRENT_USER
, HKEY_DYN_DATA
65 #define NOT_ENOUGH_MEMORY 1
68 /* processing macros */
70 /* common check of memory allocation results */
71 #define CHECK_ENOUGH_MEMORY(p) \
74 fprintf(stderr,"%s: file %s, line %d: Not enough memory", \
75 getAppName(), __FILE__, __LINE__); \
76 exit(NOT_ENOUGH_MEMORY); \
79 /******************************************************************************
80 * This is a replacement for strsep which is not portable (missing on Solaris).
84 char* getToken(char** str
, const char* delims
)
95 if (strchr(delims
,**str
)!=NULL
) {
102 /* There is no other token */
108 /******************************************************************************
109 * Copies file name from command line string to the buffer.
110 * Rewinds the command line string pointer to the next non-space character
111 * after the file name.
112 * Buffer contains an empty string if no filename was found;
115 * command_line - command line current position pointer
116 * where *s[0] is the first symbol of the file name.
117 * file_name - buffer to write the file name to.
119 void get_file_name(CHAR
**command_line
, CHAR
*file_name
)
121 CHAR
*s
= *command_line
;
122 int pos
= 0; /* position of pointer "s" in *command_line */
134 fprintf(stderr
,"%s: Unexpected end of file name!\n",
142 while(s
[0] && !isspace(s
[0])) {
147 memcpy(file_name
, *command_line
, pos
* sizeof((*command_line
)[0]));
148 /* remove the last backslash */
149 if (file_name
[pos
- 1] == '\\') {
150 file_name
[pos
- 1] = '\0';
152 file_name
[pos
] = '\0';
159 while(s
[0] && isspace(s
[0])) {
163 (*command_line
) += pos
;
167 /******************************************************************************
168 * Converts a hex representation of a DWORD into a DWORD.
170 DWORD
convertHexToDWord(char *str
, BYTE
*buf
)
177 sscanf(xbuf
,"%08lx",&dw
);
178 memcpy(buf
,&dw
,sizeof(DWORD
));
179 return sizeof(DWORD
);
182 /******************************************************************************
183 * Converts a hex buffer into a hex comma separated values
185 char* convertHexToHexCSV(BYTE
*buf
, ULONG bufLen
)
193 str
= HeapAlloc(GetProcessHeap(), 0, (bufLen
+1)*2);
194 memset(str
, 0, (bufLen
+1)*2);
195 ptrStr
= str
; /* Pointer to result */
196 ptrBuf
= buf
; /* Pointer to current */
198 while (current
< bufLen
) {
199 BYTE bCur
= ptrBuf
[current
++];
202 sprintf(res
, "%02x", (unsigned int)*&bCur
);
207 /* Get rid of the last comma */
208 str
[strlen(str
)-1] = '\0';
212 /******************************************************************************
213 * Converts a hex buffer into a DWORD string
215 char* convertHexToDWORDStr(BYTE
*buf
, ULONG bufLen
)
220 if ( bufLen
!= sizeof(DWORD
) ) return NULL
;
222 str
= HeapAlloc(GetProcessHeap(), 0, (bufLen
*2)+1);
224 memcpy(&dw
,buf
,sizeof(DWORD
));
225 sprintf(str
, "%08lx", dw
);
227 /* Get rid of the last comma */
231 /******************************************************************************
232 * Converts a hex comma separated values list into a hex list.
233 * The Hex input string must be in exactly the correct form.
235 DWORD
convertHexCSVToHex(char *str
, BYTE
*buf
, ULONG bufLen
)
237 char *s
= str
; /* Pointer to current */
238 char *b
= (char*) buf
; /* Pointer to result */
240 ULONG strLen
= strlen(str
);
244 memset(buf
, 0, bufLen
);
247 * warn the user if we are here with a string longer than 2 bytes that does
248 * not contains ",". It is more likely because the data is invalid.
250 if ( ( strLen
> 2) && ( strchr(str
, ',') == NULL
) )
251 fprintf(stderr
,"%s: WARNING converting CSV hex stream with no comma, "
252 "input data seems invalid.\n", getAppName());
253 if (strLen
> 3*bufLen
)
254 fprintf(stderr
,"%s: ERROR converting CSV hex stream. Too long\n",
257 while (strPos
< strLen
) {
261 memcpy(xbuf
,s
,2); xbuf
[2]='\0';
262 sscanf(xbuf
,"%02x",&wc
);
263 if (byteCount
< bufLen
)
264 *b
++ =(unsigned char)wc
;
274 /******************************************************************************
275 * This function returns the HKEY associated with the data type encoded in the
276 * value. It modifies the input parameter (key value) in order to skip this
277 * "now useless" data type information.
279 * Note: Updated based on the algorithm used in 'server/registry.c'
281 DWORD
getDataType(LPSTR
*lpValue
, DWORD
* parse_type
)
283 struct data_type
{ const char *tag
; int len
; int type
; int parse_type
; };
285 static const struct data_type data_types
[] = { /* actual type */ /* type to assume for parsing */
286 { "\"", 1, REG_SZ
, REG_SZ
},
287 { "str:\"", 5, REG_SZ
, REG_SZ
},
288 { "str(2):\"", 8, REG_EXPAND_SZ
, REG_SZ
},
289 { "hex:", 4, REG_BINARY
, REG_BINARY
},
290 { "dword:", 6, REG_DWORD
, REG_DWORD
},
291 { "hex(", 4, -1, REG_BINARY
},
295 const struct data_type
*ptr
;
298 for (ptr
= data_types
; ptr
->tag
; ptr
++) {
299 if (memcmp( ptr
->tag
, *lpValue
, ptr
->len
))
303 *parse_type
= ptr
->parse_type
;
308 /* "hex(xx):" is special */
309 type
= (int)strtoul( *lpValue
, &end
, 16 );
310 if (**lpValue
=='\0' || *end
!=')' || *(end
+1)!=':') {
318 return (**lpValue
=='\0'?REG_SZ
:REG_NONE
);
321 /******************************************************************************
322 * Returns an allocated buffer with a cleaned copy (removed the surrounding
323 * dbl quotes) of the passed value.
325 LPSTR
getArg( LPSTR arg
)
334 * Get rid of surrounding quotes
338 if( arg
[len
-1] == '\"' ) arg
[len
-1] = '\0';
339 if( arg
[0] == '\"' ) arg
++;
341 tmp
= HeapAlloc(GetProcessHeap(), 0, strlen(arg
)+1);
347 /******************************************************************************
348 * Replaces escape sequences with the characters.
350 static void REGPROC_unescape_string(LPSTR str
)
352 int str_idx
= 0; /* current character under analysis */
353 int val_idx
= 0; /* the last character of the unescaped string */
354 int len
= strlen(str
);
355 for (str_idx
= 0; str_idx
< len
; str_idx
++, val_idx
++) {
356 if (str
[str_idx
] == '\\') {
358 switch (str
[str_idx
]) {
364 str
[val_idx
] = str
[str_idx
];
367 fprintf(stderr
,"Warning! Unrecognized escape sequence: \\%c'\n",
369 str
[val_idx
] = str
[str_idx
];
373 str
[val_idx
] = str
[str_idx
];
379 /******************************************************************************
380 * Sets the value with name val_name to the data in val_data for the currently
384 * val_name - name of the registry value
385 * val_data - registry value data
387 HRESULT
setValue(LPSTR val_name
, LPSTR val_data
)
390 DWORD dwDataType
, dwParseType
= REG_BINARY
;
392 BYTE convert
[KEY_MAX_LEN
];
393 BYTE
*bBigBuffer
= 0;
396 if ( (val_name
== NULL
) || (val_data
== NULL
) )
397 return ERROR_INVALID_PARAMETER
;
399 /* Get the data type stored into the value field */
400 dwDataType
= getDataType(&val_data
, &dwParseType
);
402 if ( dwParseType
== REG_SZ
) /* no conversion for string */
404 dwLen
= strlen(val_data
);
405 if (dwLen
>0 && val_data
[dwLen
-1]=='"')
408 val_data
[dwLen
]='\0';
411 REGPROC_unescape_string(val_data
);
412 lpbData
= (LPBYTE
)val_data
;
413 } else if (dwParseType
== REG_DWORD
) /* Convert the dword types */
415 dwLen
= convertHexToDWord(val_data
, convert
);
417 } else /* Convert the hexadecimal types */
419 int b_len
= strlen (val_data
)+2/3;
420 if (b_len
> KEY_MAX_LEN
) {
421 bBigBuffer
= HeapAlloc (GetProcessHeap(), 0, b_len
);
422 CHECK_ENOUGH_MEMORY(bBigBuffer
);
423 dwLen
= convertHexCSVToHex(val_data
, bBigBuffer
, b_len
);
424 lpbData
= bBigBuffer
;
426 dwLen
= convertHexCSVToHex(val_data
, convert
, KEY_MAX_LEN
);
431 hRes
= RegSetValueExA(
440 HeapFree (GetProcessHeap(), 0, bBigBuffer
);
445 /******************************************************************************
448 HRESULT
openKey( LPSTR stdInput
)
454 if (stdInput
== NULL
)
455 return ERROR_INVALID_PARAMETER
;
457 /* Get the registry class */
458 currentKeyClass
= getRegClass(stdInput
); /* Sets global variable */
459 if (currentKeyClass
== (HKEY
)ERROR_INVALID_PARAMETER
)
460 return (HRESULT
)ERROR_INVALID_PARAMETER
;
462 /* Get the key name */
463 currentKeyName
= getRegKeyName(stdInput
); /* Sets global variable */
464 if (currentKeyName
== NULL
)
465 return ERROR_INVALID_PARAMETER
;
467 hRes
= RegCreateKeyExA(
468 currentKeyClass
, /* Class */
469 currentKeyName
, /* Sub Key */
471 NULL
, /* object type */
472 REG_OPTION_NON_VOLATILE
, /* option, REG_OPTION_NON_VOLATILE ... */
473 KEY_ALL_ACCESS
, /* access mask, KEY_ALL_ACCESS */
474 NULL
, /* security attribute */
475 ¤tKeyHandle
, /* result */
476 &dwDisp
); /* disposition, REG_CREATED_NEW_KEY or
477 REG_OPENED_EXISTING_KEY */
479 if (hRes
== ERROR_SUCCESS
)
480 bTheKeyIsOpen
= TRUE
;
486 /******************************************************************************
487 * Extracts from [HKEY\some\key\path] or HKEY\some\key\path types of line
488 * the key name (what starts after the first '\')
490 LPSTR
getRegKeyName(LPSTR lpLine
)
493 char lpLineCopy
[KEY_MAX_LEN
];
498 strcpy(lpLineCopy
, lpLine
);
500 keyNameBeg
= strchr(lpLineCopy
, '\\'); /* The key name start by '\' */
504 keyNameBeg
++; /* is not part of the name */
505 keyNameEnd
= strchr(lpLineCopy
, ']');
507 *keyNameEnd
= '\0'; /* remove ']' from the key name */
510 keyNameBeg
= lpLineCopy
+ strlen(lpLineCopy
); /* branch - empty string */
512 currentKeyName
= HeapAlloc(GetProcessHeap(), 0, strlen(keyNameBeg
) + 1);
513 CHECK_ENOUGH_MEMORY(currentKeyName
);
514 strcpy(currentKeyName
, keyNameBeg
);
515 return currentKeyName
;
518 /******************************************************************************
519 * Extracts from [HKEY\some\key\path] or HKEY\some\key\path types of line
520 * the key class (what ends before the first '\')
522 HKEY
getRegClass(LPSTR lpClass
)
528 char lpClassCopy
[KEY_MAX_LEN
];
531 return (HKEY
)ERROR_INVALID_PARAMETER
;
533 lstrcpynA(lpClassCopy
, lpClass
, KEY_MAX_LEN
);
535 classNameEnd
= strchr(lpClassCopy
, '\\'); /* The class name ends by '\' */
536 if (!classNameEnd
) /* or the whole string */
538 classNameEnd
= lpClassCopy
+ strlen(lpClassCopy
);
539 if (classNameEnd
[-1] == ']')
544 *classNameEnd
= '\0'; /* Isolate the class name */
545 if (lpClassCopy
[0] == '[') {
546 classNameBeg
= lpClassCopy
+ 1;
548 classNameBeg
= lpClassCopy
;
551 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
552 if (!strcmp(classNameBeg
, reg_class_names
[i
])) {
553 return reg_class_keys
[i
];
556 return (HKEY
)ERROR_INVALID_PARAMETER
;
559 /******************************************************************************
560 * Close the currently opened key.
564 RegCloseKey(currentKeyHandle
);
566 HeapFree(GetProcessHeap(), 0, currentKeyName
); /* Allocated by getKeyName */
568 bTheKeyIsOpen
= FALSE
;
570 currentKeyName
= NULL
;
572 currentKeyHandle
= 0;
575 /******************************************************************************
576 * This function is the main entry point to the setValue type of action. It
577 * receives the currently read line and dispatch the work depending on the
580 void doSetValue(LPSTR stdInput
)
583 * We encountered the end of the file, make sure we
584 * close the opened key and exit
586 if (stdInput
== NULL
) {
587 if (bTheKeyIsOpen
!= FALSE
)
593 if ( stdInput
[0] == '[') /* We are reading a new key */
595 if ( bTheKeyIsOpen
!= FALSE
)
596 closeKey(); /* Close the previous key before */
598 if ( openKey(stdInput
) != ERROR_SUCCESS
)
599 fprintf(stderr
,"%s: setValue failed to open key %s\n",
600 getAppName(), stdInput
);
601 } else if( ( bTheKeyIsOpen
) &&
602 (( stdInput
[0] == '@') || /* reading a default @=data pair */
603 ( stdInput
[0] == '\"'))) /* reading a new value=data pair */
605 processSetValue(stdInput
);
606 } else /* since we are assuming that the */
607 { /* file format is valid we must */
608 if ( bTheKeyIsOpen
) /* be reading a blank line which */
609 closeKey(); /* indicate end of this key processing */
613 /******************************************************************************
614 * This function is the main entry point to the queryValue type of action. It
615 * receives the currently read line and dispatch the work depending on the
618 void doQueryValue(LPSTR stdInput
)
621 * We encountered the end of the file, make sure we
622 * close the opened key and exit
624 if (stdInput
== NULL
) {
625 if (bTheKeyIsOpen
!= FALSE
)
631 if ( stdInput
[0] == '[') /* We are reading a new key */
633 if ( bTheKeyIsOpen
!= FALSE
)
634 closeKey(); /* Close the previous key before */
636 if ( openKey(stdInput
) != ERROR_SUCCESS
)
637 fprintf(stderr
,"%s: queryValue failed to open key %s\n",
638 getAppName(), stdInput
);
639 } else if( ( bTheKeyIsOpen
) &&
640 (( stdInput
[0] == '@') || /* reading a default @=data pair */
641 ( stdInput
[0] == '\"'))) /* reading a new value=data pair */
643 processQueryValue(stdInput
);
644 } else /* since we are assuming that the */
645 { /* file format is valid we must */
646 if ( bTheKeyIsOpen
) /* be reading a blank line which */
647 closeKey(); /* indicate end of this key processing */
651 /******************************************************************************
652 * This function is the main entry point to the deleteValue type of action. It
653 * receives the currently read line and dispatch the work depending on the
656 void doDeleteValue(LPSTR line
)
658 fprintf(stderr
,"%s: deleteValue not yet implemented\n", getAppName());
661 /******************************************************************************
662 * This function is the main entry point to the deleteKey type of action. It
663 * receives the currently read line and dispatch the work depending on the
666 void doDeleteKey(LPSTR line
)
668 fprintf(stderr
,"%s: deleteKey not yet implemented\n", getAppName());
671 /******************************************************************************
672 * This function is the main entry point to the createKey type of action. It
673 * receives the currently read line and dispatch the work depending on the
676 void doCreateKey(LPSTR line
)
678 fprintf(stderr
,"%s: createKey not yet implemented\n", getAppName());
681 /******************************************************************************
682 * This function is a wrapper for the setValue function. It prepares the
683 * land and clean the area once completed.
684 * Note: this function modifies the line parameter.
686 * line - registry file unwrapped line. Should have the registry value name and
687 * complete registry value data.
689 void processSetValue(LPSTR line
)
691 LPSTR val_name
; /* registry value name */
692 LPSTR val_data
; /* registry value data */
694 int line_idx
= 0; /* current character under analysis */
698 if (line
[line_idx
] == '@' && line
[line_idx
+ 1] == '=') {
699 line
[line_idx
] = '\0';
702 } else if (line
[line_idx
] == '\"') {
704 val_name
= line
+ line_idx
;
706 if (line
[line_idx
] == '\\') /* skip escaped character */
710 if (line
[line_idx
] == '\"') {
711 line
[line_idx
] = '\0';
719 if (line
[line_idx
] != '=') {
720 line
[line_idx
] = '\"';
721 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
726 fprintf(stderr
,"Warning! unrecognized line:\n%s\n", line
);
729 line_idx
++; /* skip the '=' character */
730 val_data
= line
+ line_idx
;
732 REGPROC_unescape_string(val_name
);
733 hRes
= setValue(val_name
, val_data
);
734 if ( hRes
!= ERROR_SUCCESS
)
735 fprintf(stderr
,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
742 /******************************************************************************
743 * This function is a wrapper for the queryValue function. It prepares the
744 * land and clean the area once completed.
746 void processQueryValue(LPSTR cmdline
)
748 fprintf(stderr
,"ERROR!!! - temporary disabled");
751 LPSTR argv
[QUERY_VALUE_MAX_ARGS
];/* args storage */
752 LPSTR token
= NULL
; /* current token analyzed */
753 ULONG argCounter
= 0; /* counter of args */
756 LPSTR keyValue
= NULL
;
760 * Init storage and parse the line
762 for (counter
=0; counter
<QUERY_VALUE_MAX_ARGS
; counter
++)
765 while( (token
= getToken(&cmdline
, queryValueDelim
[argCounter
])) != NULL
) {
766 argv
[argCounter
++] = getArg(token
);
768 if (argCounter
== QUERY_VALUE_MAX_ARGS
)
769 break; /* Stop processing args no matter what */
772 /* The value we look for is the first token on the line */
773 if ( argv
[0] == NULL
)
774 return; /* SHOULD NOT HAPPEN */
778 if( (keyValue
[0] == '@') && (strlen(keyValue
) == 1) ) {
779 LONG lLen
= KEY_MAX_LEN
;
780 CHAR
* lpsData
=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,KEY_MAX_LEN
);
782 * We need to query the key default value
784 hRes
= RegQueryValue(
790 if (hRes
==ERROR_MORE_DATA
) {
791 lpsData
=HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,lpsData
,lLen
);
792 hRes
= RegQueryValue(currentKeyHandle
,currentKeyName
,(LPBYTE
)lpsData
,&lLen
);
795 if (hRes
== ERROR_SUCCESS
) {
796 lpsRes
= HeapAlloc( GetProcessHeap(), 0, lLen
);
797 lstrcpynA(lpsRes
, lpsData
, lLen
);
800 DWORD dwLen
= KEY_MAX_LEN
;
801 BYTE
* lpbData
=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,KEY_MAX_LEN
);
804 * We need to query a specific value for the key
806 hRes
= RegQueryValueEx(
814 if (hRes
==ERROR_MORE_DATA
) {
815 lpbData
=HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,lpbData
,dwLen
);
816 hRes
= RegQueryValueEx(currentKeyHandle
,keyValue
,NULL
,&dwType
,(LPBYTE
)lpbData
,&dwLen
);
819 if (hRes
== ERROR_SUCCESS
) {
821 * Convert the returned data to a displayable format
825 case REG_EXPAND_SZ
: {
826 lpsRes
= HeapAlloc( GetProcessHeap(), 0, dwLen
);
827 lstrcpynA(lpsRes
, lpbData
, dwLen
);
831 lpsRes
= convertHexToDWORDStr(lpbData
, dwLen
);
835 lpsRes
= convertHexToHexCSV(lpbData
, dwLen
);
841 HeapFree(GetProcessHeap(), 0, lpbData
);
845 if ( hRes
== ERROR_SUCCESS
)
847 "%s: Value \"%s\" = \"%s\" in key [%s]\n",
854 fprintf(stderr
,"%s: ERROR Value \"%s\" not found for key \"%s\".\n",
862 for (counter
=0; counter
<argCounter
; counter
++)
863 if (argv
[counter
] != NULL
)
864 HeapFree(GetProcessHeap(), 0, argv
[counter
]);
867 HeapFree(GetProcessHeap(), 0, lpsRes
);
871 /******************************************************************************
872 * Calls command for each line of a registry file.
873 * Correctly processes comments (in # form), line continuation.
876 * in - input stream to read from
877 * command - command to be called for each line
879 void processRegLines(FILE *in
, CommandAPI command
)
881 LPSTR line
= NULL
; /* line read from input stream */
882 ULONG lineSize
= REG_VAL_BUF_SIZE
;
884 line
= HeapAlloc(GetProcessHeap(), 0, lineSize
);
885 CHECK_ENOUGH_MEMORY(line
);
888 LPSTR s
; /* The pointer into line for where the current fgets should read */
891 size_t size_remaining
;
893 char *s_eol
; /* various local uses */
895 /* Do we need to expand the buffer ? */
896 assert (s
>= line
&& s
<= line
+ lineSize
);
897 size_remaining
= lineSize
- (s
-line
);
898 if (size_remaining
< 2) /* room for 1 character and the \0 */
901 size_t new_size
= lineSize
+ REG_VAL_BUF_SIZE
;
902 if (new_size
> lineSize
) /* no arithmetic overflow */
903 new_buffer
= HeapReAlloc (GetProcessHeap(), 0, line
, new_size
);
906 CHECK_ENOUGH_MEMORY(new_buffer
);
908 s
= line
+ lineSize
- size_remaining
;
910 size_remaining
= lineSize
- (s
-line
);
913 /* Get as much as possible into the buffer, terminated either by
914 * eof, error, eol or getting the maximum amount. Abort on error.
916 size_to_get
= (size_remaining
> INT_MAX
? INT_MAX
: size_remaining
);
917 if (NULL
== fgets (s
, size_to_get
, in
)) {
919 perror ("While reading input");
924 /* It is not clear to me from the definition that the
925 * contents of the buffer are well defined on detecting
926 * an eof without managing to read anything.
931 /* If we didn't read the eol nor the eof go around for the rest */
932 s_eol
= strchr (s
, '\n');
933 if (!feof (in
) && !s_eol
) {
934 s
= strchr (s
, '\0');
935 /* It should be s + size_to_get - 1 but this is safer */
939 /* If it is a comment line then discard it and go around again */
940 if (line
[0] == '#') {
945 /* Remove any line feed. Leave s_eol on the \0 */
948 if (s_eol
> line
&& *(s_eol
-1) == '\r')
951 s_eol
= strchr (s
, '\0');
953 /* If there is a concatenating \\ then go around again */
954 if (s_eol
> line
&& *(s_eol
-1) == '\\') {
957 /* The following error protection could be made more self-
958 * correcting but I thought it not worth trying.
960 if ((c
= fgetc (in
)) == EOF
|| c
!= ' ' ||
961 (c
= fgetc (in
)) == EOF
|| c
!= ' ')
962 fprintf(stderr
,"%s: ERROR - invalid continuation.\n",
967 break; /* That is the full virtual line */
974 HeapFree(GetProcessHeap(), 0, line
);
977 /******************************************************************************
978 * This function is the main entry point to the registerDLL action. It
979 * receives the currently read line, then loads and registers the requested DLLs
981 void doRegisterDLL(LPSTR stdInput
)
986 /* Check for valid input */
987 if (stdInput
== NULL
)
990 /* Load and register the library, then free it */
991 theLib
= LoadLibraryA(stdInput
);
993 FARPROC lpfnDLLRegProc
= GetProcAddress(theLib
, "DllRegisterServer");
995 retVal
= (*lpfnDLLRegProc
)();
997 fprintf(stderr
,"%s: Couldn't find DllRegisterServer proc in '%s'.\n",
998 getAppName(), stdInput
);
1001 fprintf(stderr
,"%s: DLLRegisterServer error 0x%x in '%s'.\n",
1002 getAppName(), retVal
, stdInput
);
1004 FreeLibrary(theLib
);
1006 fprintf(stderr
,"%s: Could not load DLL '%s'.\n", getAppName(), stdInput
);
1010 /******************************************************************************
1011 * This function is the main entry point to the unregisterDLL action. It
1012 * receives the currently read line, then loads and unregisters the requested DLLs
1014 void doUnregisterDLL(LPSTR stdInput
)
1019 /* Check for valid input */
1020 if (stdInput
== NULL
)
1023 /* Load and unregister the library, then free it */
1024 theLib
= LoadLibraryA(stdInput
);
1026 FARPROC lpfnDLLRegProc
= GetProcAddress(theLib
, "DllUnregisterServer");
1028 retVal
= (*lpfnDLLRegProc
)();
1030 fprintf(stderr
,"%s: Couldn't find DllUnregisterServer proc in '%s'.\n",
1031 getAppName(), stdInput
);
1034 fprintf(stderr
,"%s: DLLUnregisterServer error 0x%x in '%s'.\n",
1035 getAppName(), retVal
, stdInput
);
1037 FreeLibrary(theLib
);
1039 fprintf(stderr
,"%s: Could not load DLL '%s'.\n", getAppName(), stdInput
);
1043 /****************************************************************************
1044 * REGPROC_print_error
1046 * Print the message for GetLastError
1049 static void REGPROC_print_error(void)
1055 error_code
= GetLastError ();
1056 status
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1057 NULL
, error_code
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
1059 fprintf(stderr
,"%s: Cannot display message for error %ld, status %ld\n",
1060 getAppName(), error_code
, GetLastError());
1064 LocalFree((HLOCAL
)lpMsgBuf
);
1068 /******************************************************************************
1069 * Checks whether the buffer has enough room for the string or required size.
1070 * Resizes the buffer if necessary.
1073 * buffer - pointer to a buffer for string
1074 * len - current length of the buffer in characters.
1075 * required_len - length of the string to place to the buffer in characters.
1076 * The length does not include the terminating null character.
1078 static void REGPROC_resize_char_buffer(CHAR
**buffer
, DWORD
*len
, DWORD required_len
)
1081 if (required_len
> *len
) {
1082 *len
= required_len
;
1084 *buffer
= HeapAlloc(GetProcessHeap(), 0, *len
* sizeof(**buffer
));
1086 *buffer
= HeapReAlloc(GetProcessHeap(), 0, *buffer
, *len
* sizeof(**buffer
));
1087 CHECK_ENOUGH_MEMORY(*buffer
);
1091 /******************************************************************************
1092 * Prints string str to file
1094 static void REGPROC_export_string(FILE *file
, CHAR
*str
)
1096 size_t len
= strlen(str
);
1099 /* escaping characters */
1100 for (i
= 0; i
< len
; i
++) {
1104 fputs("\\\\", file
);
1107 fputs("\\\"", file
);
1110 fputs("\\\n", file
);
1119 /******************************************************************************
1120 * Writes contents of the registry key to the specified file stream.
1123 * file - writable file stream to export registry branch to.
1124 * key - registry branch to export.
1125 * reg_key_name_buf - name of the key with registry class.
1126 * Is resized if necessary.
1127 * reg_key_name_len - length of the buffer for the registry class in characters.
1128 * val_name_buf - buffer for storing value name.
1129 * Is resized if necessary.
1130 * val_name_len - length of the buffer for storing value names in characters.
1131 * val_buf - buffer for storing values while extracting.
1132 * Is resized if necessary.
1133 * val_size - size of the buffer for storing values in bytes.
1135 static void export_hkey(FILE *file
, HKEY key
,
1136 CHAR
**reg_key_name_buf
, DWORD
*reg_key_name_len
,
1137 CHAR
**val_name_buf
, DWORD
*val_name_len
,
1138 BYTE
**val_buf
, DWORD
*val_size
)
1140 DWORD max_sub_key_len
;
1141 DWORD max_val_name_len
;
1148 /* get size information and resize the buffers if necessary */
1149 if (RegQueryInfoKey(key
, NULL
, NULL
, NULL
, NULL
,
1150 &max_sub_key_len
, NULL
,
1151 NULL
, &max_val_name_len
, &max_val_size
, NULL
, NULL
1152 ) != ERROR_SUCCESS
) {
1153 REGPROC_print_error();
1155 curr_len
= strlen(*reg_key_name_buf
);
1156 REGPROC_resize_char_buffer(reg_key_name_buf
, reg_key_name_len
,
1157 max_sub_key_len
+ curr_len
+ 1);
1158 REGPROC_resize_char_buffer(val_name_buf
, val_name_len
,
1160 if (max_val_size
> *val_size
) {
1161 *val_size
= max_val_size
;
1162 if (!*val_buf
) *val_buf
= HeapAlloc(GetProcessHeap(), 0, *val_size
);
1163 else *val_buf
= HeapReAlloc(GetProcessHeap(), 0, *val_buf
, *val_size
);
1164 CHECK_ENOUGH_MEMORY(val_buf
);
1167 /* output data for the current key */
1169 fputs(*reg_key_name_buf
, file
);
1171 /* print all the values */
1176 DWORD val_name_len1
= *val_name_len
;
1177 DWORD val_size1
= *val_size
;
1178 ret
= RegEnumValueA(key
, i
, *val_name_buf
, &val_name_len1
, NULL
,
1179 &value_type
, *val_buf
, &val_size1
);
1180 if (ret
!= ERROR_SUCCESS
) {
1182 if (ret
!= ERROR_NO_MORE_ITEMS
) {
1183 REGPROC_print_error();
1188 if ((*val_name_buf
)[0]) {
1190 REGPROC_export_string(file
, *val_name_buf
);
1196 switch (value_type
) {
1200 REGPROC_export_string(file
, (char*) *val_buf
);
1201 fputs("\"\n", file
);
1205 fprintf(file
, "dword:%08lx\n", *((DWORD
*)*val_buf
));
1209 fprintf(stderr
,"%s: warning - unsupported registry format '%ld', "
1210 "treat as binary\n",
1211 getAppName(), value_type
);
1212 fprintf(stderr
,"key name: \"%s\"\n", *reg_key_name_buf
);
1213 fprintf(stderr
,"value name:\"%s\"\n\n", *val_name_buf
);
1219 const CHAR
*hex_prefix
;
1223 if (value_type
== REG_BINARY
) {
1224 hex_prefix
= "hex:";
1227 sprintf(buf
, "hex(%ld):", value_type
);
1230 /* position of where the next character will be printed */
1231 /* NOTE: yes, strlen("hex:") is used even for hex(x): */
1232 cur_pos
= strlen("\"\"=") + strlen("hex:") +
1233 strlen(*val_name_buf
);
1235 fputs(hex_prefix
, file
);
1236 for (i1
= 0; i1
< val_size1
; i1
++) {
1237 fprintf(file
, "%02x", (unsigned int)(*val_buf
)[i1
]);
1238 if (i1
+ 1 < val_size1
) {
1244 if (cur_pos
> REG_FILE_HEX_LINE_LEN
) {
1245 fputs("\\\n ", file
);
1258 (*reg_key_name_buf
)[curr_len
] = '\\';
1260 DWORD buf_len
= *reg_key_name_len
- curr_len
;
1262 ret
= RegEnumKeyExA(key
, i
, *reg_key_name_buf
+ curr_len
+ 1, &buf_len
,
1263 NULL
, NULL
, NULL
, NULL
);
1264 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_MORE_DATA
) {
1266 if (ret
!= ERROR_NO_MORE_ITEMS
) {
1267 REGPROC_print_error();
1273 if (RegOpenKeyA(key
, *reg_key_name_buf
+ curr_len
+ 1,
1274 &subkey
) == ERROR_SUCCESS
) {
1275 export_hkey(file
, subkey
, reg_key_name_buf
, reg_key_name_len
,
1276 val_name_buf
, val_name_len
, val_buf
, val_size
);
1277 RegCloseKey(subkey
);
1279 REGPROC_print_error();
1283 (*reg_key_name_buf
)[curr_len
] = '\0';
1286 /******************************************************************************
1287 * Open file for export.
1289 static FILE *REGPROC_open_export_file(const TCHAR
*file_name
)
1291 FILE *file
= _tfopen(file_name
, _T("w"));
1294 /* fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), file_name);*/
1297 fputs("REGEDIT4\n", file
);
1301 /******************************************************************************
1302 * Writes contents of the registry key to the specified file stream.
1305 * file_name - name of a file to export registry branch to.
1306 * reg_key_name - registry branch to export. The whole registry is exported if
1307 * reg_key_name is NULL or contains an empty string.
1309 BOOL
export_registry_key(const TCHAR
*file_name
, CHAR
*reg_key_name
)
1313 CHAR
*reg_key_name_buf
;
1316 DWORD reg_key_name_len
= KEY_MAX_LEN
;
1317 DWORD val_name_len
= KEY_MAX_LEN
;
1318 DWORD val_size
= REG_VAL_BUF_SIZE
;
1321 reg_key_name_buf
= HeapAlloc(GetProcessHeap(), 0,
1322 reg_key_name_len
* sizeof(*reg_key_name_buf
));
1323 val_name_buf
= HeapAlloc(GetProcessHeap(), 0,
1324 val_name_len
* sizeof(*val_name_buf
));
1325 val_buf
= HeapAlloc(GetProcessHeap(), 0, val_size
);
1326 CHECK_ENOUGH_MEMORY(reg_key_name_buf
&& val_name_buf
&& val_buf
);
1328 if (reg_key_name
&& reg_key_name
[0]) {
1332 REGPROC_resize_char_buffer(®_key_name_buf
, ®_key_name_len
,
1333 strlen(reg_key_name
));
1334 strcpy(reg_key_name_buf
, reg_key_name
);
1336 /* open the specified key */
1337 reg_key_class
= getRegClass(reg_key_name
);
1338 if (reg_key_class
== (HKEY
)ERROR_INVALID_PARAMETER
) {
1339 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
1340 getAppName(), reg_key_name
);
1343 branch_name
= getRegKeyName(reg_key_name
);
1344 CHECK_ENOUGH_MEMORY(branch_name
);
1345 if (!branch_name
[0]) {
1346 /* no branch - registry class is specified */
1347 file
= REGPROC_open_export_file(file_name
);
1348 export_hkey(file
, reg_key_class
,
1349 ®_key_name_buf
, ®_key_name_len
,
1350 &val_name_buf
, &val_name_len
,
1351 &val_buf
, &val_size
);
1352 } else if (RegOpenKeyA(reg_key_class
, branch_name
, &key
) == ERROR_SUCCESS
) {
1353 file
= REGPROC_open_export_file(file_name
);
1354 export_hkey(file
, key
,
1355 ®_key_name_buf
, ®_key_name_len
,
1356 &val_name_buf
, &val_name_len
,
1357 &val_buf
, &val_size
);
1360 fprintf(stderr
,"%s: Can't export. Registry key '%s' does not exist!\n",
1361 getAppName(), reg_key_name
);
1362 REGPROC_print_error();
1364 HeapFree(GetProcessHeap(), 0, branch_name
);
1368 /* export all registry classes */
1369 file
= REGPROC_open_export_file(file_name
);
1370 for (i
= 0; i
< REG_CLASS_NUMBER
; i
++) {
1371 /* do not export HKEY_CLASSES_ROOT */
1372 if (reg_class_keys
[i
] != HKEY_CLASSES_ROOT
&&
1373 reg_class_keys
[i
] != HKEY_CURRENT_USER
&&
1374 reg_class_keys
[i
] != HKEY_CURRENT_CONFIG
&&
1375 reg_class_keys
[i
] != HKEY_DYN_DATA
) {
1376 strcpy(reg_key_name_buf
, reg_class_names
[i
]);
1377 export_hkey(file
, reg_class_keys
[i
],
1378 ®_key_name_buf
, ®_key_name_len
,
1379 &val_name_buf
, &val_name_len
,
1380 &val_buf
, &val_size
);
1388 HeapFree(GetProcessHeap(), 0, val_buf
);
1392 /******************************************************************************
1393 * Reads contents of the specified file into the registry.
1395 BOOL
import_registry_file(LPTSTR filename
)
1397 FILE* reg_file
= _tfopen(filename
, _T("r"));
1400 processRegLines(reg_file
, doSetValue
);
1406 /******************************************************************************
1407 * Recursive function which removes the registry key with all subkeys.
1409 static void delete_branch(HKEY key
,
1410 CHAR
**reg_key_name_buf
, DWORD
*reg_key_name_len
)
1413 DWORD max_sub_key_len
;
1419 if (RegOpenKeyA(key
, *reg_key_name_buf
, &branch_key
) != ERROR_SUCCESS
) {
1420 REGPROC_print_error();
1423 /* get size information and resize the buffers if necessary */
1424 if (RegQueryInfoKey(branch_key
, NULL
, NULL
, NULL
,
1425 &subkeys
, &max_sub_key_len
,
1426 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
1427 ) != ERROR_SUCCESS
) {
1428 REGPROC_print_error();
1430 curr_len
= strlen(*reg_key_name_buf
);
1431 REGPROC_resize_char_buffer(reg_key_name_buf
, reg_key_name_len
,
1432 max_sub_key_len
+ curr_len
+ 1);
1434 (*reg_key_name_buf
)[curr_len
] = '\\';
1435 for (i
= subkeys
- 1; i
>= 0; i
--) {
1436 DWORD buf_len
= *reg_key_name_len
- curr_len
;
1438 ret
= RegEnumKeyExA(branch_key
, i
, *reg_key_name_buf
+ curr_len
+ 1,
1439 &buf_len
, NULL
, NULL
, NULL
, NULL
);
1440 if (ret
!= ERROR_SUCCESS
&&
1441 ret
!= ERROR_MORE_DATA
&&
1442 ret
!= ERROR_NO_MORE_ITEMS
) {
1443 REGPROC_print_error();
1445 delete_branch(key
, reg_key_name_buf
, reg_key_name_len
);
1448 (*reg_key_name_buf
)[curr_len
] = '\0';
1449 RegCloseKey(branch_key
);
1450 RegDeleteKeyA(key
, *reg_key_name_buf
);
1453 /******************************************************************************
1454 * Removes the registry key with all subkeys. Parses full key name.
1457 * reg_key_name - full name of registry branch to delete. Ignored if is NULL,
1458 * empty, points to register key class, does not exist.
1460 void delete_registry_key(CHAR
*reg_key_name
)
1463 DWORD branch_name_len
;
1467 if (!reg_key_name
|| !reg_key_name
[0])
1469 /* open the specified key */
1470 reg_key_class
= getRegClass(reg_key_name
);
1471 if (reg_key_class
== (HKEY
)ERROR_INVALID_PARAMETER
) {
1472 fprintf(stderr
,"%s: Incorrect registry class specification in '%s'\n",
1473 getAppName(), reg_key_name
);
1476 branch_name
= getRegKeyName(reg_key_name
);
1477 CHECK_ENOUGH_MEMORY(branch_name
);
1478 branch_name_len
= strlen(branch_name
);
1479 if (!branch_name
[0]) {
1480 fprintf(stderr
,"%s: Can't delete registry class '%s'\n",
1481 getAppName(), reg_key_name
);
1484 if (RegOpenKeyA(reg_key_class
, branch_name
, &branch_key
) == ERROR_SUCCESS
) {
1485 /* check whether the key exists */
1486 RegCloseKey(branch_key
);
1487 delete_branch(reg_key_class
, &branch_name
, &branch_name_len
);
1489 HeapFree(GetProcessHeap(), 0, branch_name
);
1492 /******************************************************************************
1493 * Sets the application name. Then application name is used in the error
1496 void setAppName(const CHAR
*name
)
1501 const CHAR
*getAppName(void)
1506 LONG
RegDeleteKeyRecursive(HKEY hKey
, LPCTSTR lpSubKey
)
1509 HKEY hSubKey
= NULL
;
1510 DWORD dwIndex
, cbName
;
1511 TCHAR szSubKey
[256];
1514 lResult
= RegOpenKeyEx(hKey
, lpSubKey
, 0, KEY_ALL_ACCESS
, &hSubKey
);
1515 if (lResult
== ERROR_SUCCESS
)
1520 cbName
= sizeof(szSubKey
) / sizeof(szSubKey
[0]);
1521 lResult
= RegEnumKeyEx(hSubKey
, dwIndex
++, szSubKey
, &cbName
, NULL
, NULL
, NULL
, &ft
);
1522 if (lResult
== ERROR_SUCCESS
)
1523 RegDeleteKeyRecursive(hSubKey
, szSubKey
);
1525 while(lResult
== ERROR_SUCCESS
);
1527 RegCloseKey(hSubKey
);
1530 return RegDeleteKey(hKey
, lpSubKey
);
1533 LONG
RegCopyKey(HKEY hDestKey
, LPCTSTR lpDestSubKey
, HKEY hSrcKey
, LPCTSTR lpSrcSubKey
)
1536 DWORD dwDisposition
;
1537 HKEY hDestSubKey
= NULL
;
1538 HKEY hSrcSubKey
= NULL
;
1539 DWORD dwIndex
, dwType
, cbName
, cbData
;
1540 TCHAR szSubKey
[256];
1541 TCHAR szValueName
[256];
1542 BYTE szValueData
[512];
1546 /* open the source subkey, if specified */
1549 lResult
= RegOpenKeyEx(hSrcKey
, lpSrcSubKey
, 0, KEY_ALL_ACCESS
, &hSrcSubKey
);
1552 hSrcKey
= hSrcSubKey
;
1555 /* create the destination subkey */
1556 lResult
= RegCreateKeyEx(hDestKey
, lpDestSubKey
, 0, NULL
, 0, KEY_WRITE
, NULL
,
1557 &hDestSubKey
, &dwDisposition
);
1561 /* copy all subkeys */
1565 cbName
= sizeof(szSubKey
) / sizeof(szSubKey
[0]);
1566 lResult
= RegEnumKeyEx(hSrcKey
, dwIndex
++, szSubKey
, &cbName
, NULL
, NULL
, NULL
, &ft
);
1567 if (lResult
== ERROR_SUCCESS
)
1569 lResult
= RegCopyKey(hDestSubKey
, szSubKey
, hSrcKey
, szSubKey
);
1574 while(lResult
== ERROR_SUCCESS
);
1576 /* copy all subvalues */
1580 cbName
= sizeof(szValueName
) / sizeof(szValueName
[0]);
1581 cbData
= sizeof(szValueData
) / sizeof(szValueData
[0]);
1582 lResult
= RegEnumValue(hSrcKey
, dwIndex
++, szValueName
, &cbName
, NULL
, &dwType
, szValueData
, &cbData
);
1583 if (lResult
== ERROR_SUCCESS
)
1585 lResult
= RegSetValueEx(hDestSubKey
, szValueName
, 0, dwType
, szValueData
, cbData
);
1590 while(lResult
== ERROR_SUCCESS
);
1592 lResult
= ERROR_SUCCESS
;
1596 RegCloseKey(hSrcSubKey
);
1598 RegCloseKey(hDestSubKey
);
1599 if (lResult
!= ERROR_SUCCESS
)
1600 RegDeleteKeyRecursive(hDestKey
, lpDestSubKey
);
1605 LONG
RegMoveKey(HKEY hDestKey
, LPCTSTR lpDestSubKey
, HKEY hSrcKey
, LPCTSTR lpSrcSubKey
)
1610 return ERROR_INVALID_FUNCTION
;
1612 lResult
= RegCopyKey(hDestKey
, lpDestSubKey
, hSrcKey
, lpSrcSubKey
);
1613 if (lResult
== ERROR_SUCCESS
)
1614 RegDeleteKeyRecursive(hSrcKey
, lpSrcSubKey
);
1619 LONG
RegRenameKey(HKEY hKey
, LPCTSTR lpSubKey
, LPCTSTR lpNewName
)
1624 s
= _tcsrchr(lpSubKey
, '\\');
1628 lpNewSubKey
= (LPTSTR
) alloca((s
- lpSubKey
+ _tcslen(lpNewName
) + 1) * sizeof(TCHAR
));
1629 memcpy(lpNewSubKey
, lpSubKey
, (s
- lpSubKey
) * sizeof(TCHAR
));
1630 _tcscpy(lpNewSubKey
+ (s
- lpSubKey
), lpNewName
);
1631 lpNewName
= lpNewSubKey
;
1633 return RegMoveKey(hKey
, lpNewName
, hKey
, lpSubKey
);
1636 LONG
RegRenameValue(HKEY hKey
, LPCTSTR lpSubKey
, LPCTSTR lpDestValue
, LPCTSTR lpSrcValue
)
1639 HKEY hSubKey
= NULL
;
1640 DWORD dwType
, cbData
;
1645 lResult
= RegOpenKey(hKey
, lpSubKey
, &hSubKey
);
1646 if (lResult
!= ERROR_SUCCESS
)
1651 cbData
= sizeof(data
);
1652 lResult
= RegQueryValueEx(hKey
, lpSrcValue
, NULL
, &dwType
, data
, &cbData
);
1653 if (lResult
!= ERROR_SUCCESS
)
1656 lResult
= RegSetValueEx(hKey
, lpDestValue
, 0, dwType
, data
, cbData
);
1657 if (lResult
!= ERROR_SUCCESS
)
1660 RegDeleteValue(hKey
, lpSrcValue
);
1664 RegCloseKey(hSubKey
);
1668 LONG
RegQueryStringValue(HKEY hKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPTSTR pszBuffer
, DWORD dwBufferLen
)
1671 HKEY hSubKey
= NULL
;
1672 DWORD cbData
, dwType
;
1676 lResult
= RegOpenKey(hKey
, lpSubKey
, &hSubKey
);
1677 if (lResult
!= ERROR_SUCCESS
)
1682 cbData
= (dwBufferLen
- 1) * sizeof(*pszBuffer
);
1683 lResult
= RegQueryValueEx(hKey
, lpValueName
, NULL
, &dwType
, (LPBYTE
) pszBuffer
, &cbData
);
1684 if (lResult
!= ERROR_SUCCESS
)
1686 if (dwType
!= REG_SZ
)
1692 pszBuffer
[cbData
/ sizeof(*pszBuffer
)] = '\0';
1695 if (lResult
!= ERROR_SUCCESS
)
1696 pszBuffer
[0] = '\0';
1698 RegCloseKey(hSubKey
);
1702 /******************************************************************************
1703 * Key naming and parsing
1706 BOOL
RegKeyGetName(LPTSTR pszDest
, size_t iDestLength
, HKEY hRootKey
, LPCTSTR lpSubKey
)
1710 if (hRootKey
== HKEY_CLASSES_ROOT
)
1711 pszRootKey
= TEXT("HKEY_CLASSES_ROOT");
1712 else if (hRootKey
== HKEY_CURRENT_USER
)
1713 pszRootKey
= TEXT("HKEY_CURRENT_USER");
1714 else if (hRootKey
== HKEY_LOCAL_MACHINE
)
1715 pszRootKey
= TEXT("HKEY_LOCAL_MACHINE");
1716 else if (hRootKey
== HKEY_USERS
)
1717 pszRootKey
= TEXT("HKEY_USERS");
1718 else if (hRootKey
== HKEY_CURRENT_CONFIG
)
1719 pszRootKey
= TEXT("HKEY_CURRENT_CONFIG");
1720 else if (hRootKey
== HKEY_DYN_DATA
)
1721 pszRootKey
= TEXT("HKEY_DYN_DATA");
1726 _sntprintf(pszDest
, iDestLength
, TEXT("%s\\%s"), pszRootKey
, lpSubKey
);
1728 _sntprintf(pszDest
, iDestLength
, TEXT("%s"), pszRootKey
);