2002-04-12 01:58:40 +02:00
|
|
|
/*
|
|
|
|
* Registry processing routines. Routines, common for registry
|
|
|
|
* processing frontends.
|
|
|
|
*
|
|
|
|
* Copyright 1999 Sylvain St-Germain
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
2008-09-14 02:21:23 +02:00
|
|
|
* Copyright 2008 Alexander N. Sørnes <alex@thehandofagony.com>
|
2002-04-12 01:58:40 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
|
|
|
|
2002-06-21 22:12:02 +02:00
|
|
|
#include <limits.h>
|
2002-04-12 01:58:40 +02:00
|
|
|
#include <stdio.h>
|
2012-01-23 12:02:39 +01:00
|
|
|
#include <stdlib.h>
|
2011-03-04 15:00:51 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
2002-04-12 01:58:40 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winnt.h>
|
|
|
|
#include <winreg.h>
|
2002-06-21 22:12:02 +02:00
|
|
|
#include <assert.h>
|
2008-07-09 20:59:01 +02:00
|
|
|
#include <wine/unicode.h>
|
2016-07-15 09:49:58 +02:00
|
|
|
#include <wine/debug.h>
|
2002-04-12 01:58:40 +02:00
|
|
|
#include "regproc.h"
|
|
|
|
|
2016-07-15 09:49:58 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(regedit);
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
#define REG_VAL_BUF_SIZE 4096
|
|
|
|
|
|
|
|
/* maximal number of characters in hexadecimal data line,
|
2008-11-12 11:31:40 +01:00
|
|
|
* including the indentation, but not including the '\' character
|
|
|
|
*/
|
|
|
|
#define REG_FILE_HEX_LINE_LEN (2 + 25 * 3)
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2008-08-10 13:52:44 +02:00
|
|
|
extern const WCHAR* reg_class_namesW[];
|
|
|
|
|
2011-01-21 11:58:31 +01:00
|
|
|
static HKEY reg_class_keys[] = {
|
2003-12-08 23:48:07 +01:00
|
|
|
HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT,
|
2004-07-08 22:14:10 +02:00
|
|
|
HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA
|
2003-12-08 23:48:07 +01:00
|
|
|
};
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2016-07-21 07:48:43 +02:00
|
|
|
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
|
2011-01-21 11:58:31 +01:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/* return values */
|
|
|
|
#define NOT_ENOUGH_MEMORY 1
|
2002-06-21 22:12:02 +02:00
|
|
|
#define IO_ERROR 2
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
/* processing macros */
|
|
|
|
|
|
|
|
/* common check of memory allocation results */
|
|
|
|
#define CHECK_ENOUGH_MEMORY(p) \
|
2003-12-08 23:48:07 +01:00
|
|
|
if (!(p)) \
|
|
|
|
{ \
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_OUT_OF_MEMORY, __FILE__, __LINE__); \
|
2003-12-08 23:48:07 +01:00
|
|
|
exit(NOT_ENOUGH_MEMORY); \
|
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2008-07-09 18:18:14 +02:00
|
|
|
/******************************************************************************
|
2008-11-17 15:02:01 +01:00
|
|
|
* Allocates memory and converts input from multibyte to wide chars
|
2008-07-09 18:18:14 +02:00
|
|
|
* Returned string must be freed by the caller
|
|
|
|
*/
|
2016-07-06 17:05:17 +02:00
|
|
|
static WCHAR* GetWideString(const char* strA)
|
2008-07-09 18:18:14 +02:00
|
|
|
{
|
2008-08-30 01:23:09 +02:00
|
|
|
if(strA)
|
|
|
|
{
|
2008-11-12 11:10:00 +01:00
|
|
|
WCHAR* strW;
|
2008-08-30 01:23:09 +02:00
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, strA, -1, NULL, 0);
|
|
|
|
|
|
|
|
strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(strW);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, strA, -1, strW, len);
|
|
|
|
return strW;
|
|
|
|
}
|
|
|
|
return NULL;
|
2008-07-09 18:18:14 +02:00
|
|
|
}
|
|
|
|
|
2008-09-09 21:48:33 +02:00
|
|
|
/******************************************************************************
|
2008-11-17 15:02:01 +01:00
|
|
|
* Allocates memory and converts input from multibyte to wide chars
|
2008-09-09 21:48:33 +02:00
|
|
|
* Returned string must be freed by the caller
|
|
|
|
*/
|
2009-01-26 12:53:12 +01:00
|
|
|
static WCHAR* GetWideStringN(const char* strA, int chars, DWORD *len)
|
2008-09-09 21:48:33 +02:00
|
|
|
{
|
|
|
|
if(strA)
|
|
|
|
{
|
2008-11-12 11:10:00 +01:00
|
|
|
WCHAR* strW;
|
2008-09-09 21:48:33 +02:00
|
|
|
*len = MultiByteToWideChar(CP_ACP, 0, strA, chars, NULL, 0);
|
|
|
|
|
|
|
|
strW = HeapAlloc(GetProcessHeap(), 0, *len * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(strW);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, strA, chars, strW, *len);
|
|
|
|
return strW;
|
|
|
|
}
|
|
|
|
*len = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-07 23:12:21 +02:00
|
|
|
/******************************************************************************
|
2008-11-17 15:02:01 +01:00
|
|
|
* Allocates memory and converts input from wide chars to multibyte
|
2008-07-07 23:12:21 +02:00
|
|
|
* Returned string must be freed by the caller
|
|
|
|
*/
|
2008-07-10 17:49:36 +02:00
|
|
|
char* GetMultiByteString(const WCHAR* strW)
|
2008-07-07 23:12:21 +02:00
|
|
|
{
|
2008-08-30 01:23:09 +02:00
|
|
|
if(strW)
|
|
|
|
{
|
2008-11-12 11:10:00 +01:00
|
|
|
char* strA;
|
2008-08-30 01:23:09 +02:00
|
|
|
int len = WideCharToMultiByte(CP_ACP, 0, strW, -1, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
strA = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
CHECK_ENOUGH_MEMORY(strA);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, len, NULL, NULL);
|
|
|
|
return strA;
|
|
|
|
}
|
|
|
|
return NULL;
|
2008-07-07 23:12:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-08 21:44:08 +02:00
|
|
|
/******************************************************************************
|
2008-11-17 15:02:01 +01:00
|
|
|
* Allocates memory and converts input from wide chars to multibyte
|
2008-09-08 21:44:08 +02:00
|
|
|
* Returned string must be freed by the caller
|
|
|
|
*/
|
2009-01-26 12:53:12 +01:00
|
|
|
static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
|
2008-09-08 21:44:08 +02:00
|
|
|
{
|
|
|
|
if(strW)
|
|
|
|
{
|
2008-11-12 11:10:00 +01:00
|
|
|
char* strA;
|
2008-09-08 21:44:08 +02:00
|
|
|
*len = WideCharToMultiByte(CP_ACP, 0, strW, chars, NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
strA = HeapAlloc(GetProcessHeap(), 0, *len);
|
|
|
|
CHECK_ENOUGH_MEMORY(strA);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, strW, chars, strA, *len, NULL, NULL);
|
|
|
|
return strA;
|
|
|
|
}
|
|
|
|
*len = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Converts a hex representation of a DWORD into a DWORD.
|
|
|
|
*/
|
2008-07-09 20:59:01 +02:00
|
|
|
static BOOL convertHexToDWord(WCHAR* str, DWORD *dw)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-07-09 20:59:01 +02:00
|
|
|
char buf[9];
|
2007-06-14 11:46:29 +02:00
|
|
|
char dummy;
|
2008-07-09 20:59:01 +02:00
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, str, -1, buf, 9, NULL, NULL);
|
|
|
|
if (lstrlenW(str) > 8 || sscanf(buf, "%x%c", dw, &dummy) != 1) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_INVALID_HEX);
|
2007-06-14 11:46:29 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2007-06-14 11:46:29 +02:00
|
|
|
* Converts a hex comma separated values list into a binary string.
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2008-08-27 23:29:08 +02:00
|
|
|
static BYTE* convertHexCSVToHex(WCHAR *str, DWORD *size)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-08-27 23:29:08 +02:00
|
|
|
WCHAR *s;
|
2007-06-14 11:46:29 +02:00
|
|
|
BYTE *d, *data;
|
|
|
|
|
|
|
|
/* The worst case is 1 digit + 1 comma per byte */
|
2008-08-27 23:29:08 +02:00
|
|
|
*size=(lstrlenW(str)+1)/2;
|
2007-06-14 11:46:29 +02:00
|
|
|
data=HeapAlloc(GetProcessHeap(), 0, *size);
|
|
|
|
CHECK_ENOUGH_MEMORY(data);
|
|
|
|
|
2008-08-27 23:29:08 +02:00
|
|
|
s = str;
|
2007-06-14 11:46:29 +02:00
|
|
|
d = data;
|
|
|
|
*size=0;
|
|
|
|
while (*s != '\0') {
|
2003-12-08 23:48:07 +01:00
|
|
|
UINT wc;
|
2008-08-27 23:29:08 +02:00
|
|
|
WCHAR *end;
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2008-08-27 23:29:08 +02:00
|
|
|
wc = strtoulW(s,&end,16);
|
2008-01-07 19:56:15 +01:00
|
|
|
if (end == s || wc > 0xff || (*end && *end != ',')) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_CSV_HEX_ERROR, s);
|
2007-06-14 11:46:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*d++ =(BYTE)wc;
|
|
|
|
(*size)++;
|
2008-01-07 19:56:15 +01:00
|
|
|
if (*end) end++;
|
|
|
|
s = end;
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
|
2007-06-14 11:46:29 +02:00
|
|
|
return data;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* This function returns the HKEY associated with the data type encoded in the
|
|
|
|
* value. It modifies the input parameter (key value) in order to skip this
|
2002-04-12 01:58:40 +02:00
|
|
|
* "now useless" data type information.
|
|
|
|
*
|
|
|
|
* Note: Updated based on the algorithm used in 'server/registry.c'
|
|
|
|
*/
|
2008-07-09 20:59:01 +02:00
|
|
|
static DWORD getDataType(LPWSTR *lpValue, DWORD* parse_type)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-07-09 20:59:01 +02:00
|
|
|
struct data_type { const WCHAR *tag; int len; int type; int parse_type; };
|
|
|
|
|
|
|
|
static const WCHAR quote[] = {'"'};
|
|
|
|
static const WCHAR str[] = {'s','t','r',':','"'};
|
|
|
|
static const WCHAR str2[] = {'s','t','r','(','2',')',':','"'};
|
|
|
|
static const WCHAR hex[] = {'h','e','x',':'};
|
|
|
|
static const WCHAR dword[] = {'d','w','o','r','d',':'};
|
|
|
|
static const WCHAR hexp[] = {'h','e','x','('};
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
static const struct data_type data_types[] = { /* actual type */ /* type to assume for parsing */
|
2008-07-09 20:59:01 +02:00
|
|
|
{ quote, 1, REG_SZ, REG_SZ },
|
|
|
|
{ str, 5, REG_SZ, REG_SZ },
|
|
|
|
{ str2, 8, REG_EXPAND_SZ, REG_SZ },
|
|
|
|
{ hex, 4, REG_BINARY, REG_BINARY },
|
|
|
|
{ dword, 6, REG_DWORD, REG_DWORD },
|
|
|
|
{ hexp, 4, -1, REG_BINARY },
|
2003-12-08 23:48:07 +01:00
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
};
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
const struct data_type *ptr;
|
|
|
|
int type;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
for (ptr = data_types; ptr->tag; ptr++) {
|
2008-07-09 20:59:01 +02:00
|
|
|
if (strncmpW( ptr->tag, *lpValue, ptr->len ))
|
2002-04-12 01:58:40 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Found! */
|
|
|
|
*parse_type = ptr->parse_type;
|
|
|
|
type=ptr->type;
|
|
|
|
*lpValue+=ptr->len;
|
|
|
|
if (type == -1) {
|
2008-07-09 20:59:01 +02:00
|
|
|
WCHAR* end;
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/* "hex(xx):" is special */
|
2008-07-09 20:59:01 +02:00
|
|
|
type = (int)strtoulW( *lpValue , &end, 16 );
|
2002-04-12 01:58:40 +02:00
|
|
|
if (**lpValue=='\0' || *end!=')' || *(end+1)!=':') {
|
|
|
|
type=REG_NONE;
|
|
|
|
} else {
|
2008-07-09 20:59:01 +02:00
|
|
|
*lpValue = end + 2;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2007-06-14 11:43:58 +02:00
|
|
|
*parse_type=REG_NONE;
|
|
|
|
return REG_NONE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Replaces escape sequences with the characters.
|
|
|
|
*/
|
2014-10-29 03:30:13 +01:00
|
|
|
static int REGPROC_unescape_string(WCHAR* str)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
|
|
|
int str_idx = 0; /* current character under analysis */
|
|
|
|
int val_idx = 0; /* the last character of the unescaped string */
|
2008-07-09 20:02:02 +02:00
|
|
|
int len = lstrlenW(str);
|
2003-12-08 23:48:07 +01:00
|
|
|
for (str_idx = 0; str_idx < len; str_idx++, val_idx++) {
|
|
|
|
if (str[str_idx] == '\\') {
|
2002-04-12 01:58:40 +02:00
|
|
|
str_idx++;
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (str[str_idx]) {
|
2002-04-12 01:58:40 +02:00
|
|
|
case 'n':
|
|
|
|
str[val_idx] = '\n';
|
|
|
|
break;
|
2014-10-30 02:55:08 +01:00
|
|
|
case 'r':
|
|
|
|
str[val_idx] = '\r';
|
|
|
|
break;
|
2014-10-29 03:30:13 +01:00
|
|
|
case '0':
|
|
|
|
str[val_idx] = '\0';
|
|
|
|
break;
|
2002-04-12 01:58:40 +02:00
|
|
|
case '\\':
|
|
|
|
case '"':
|
|
|
|
str[val_idx] = str[str_idx];
|
|
|
|
break;
|
|
|
|
default:
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_ESCAPE_SEQUENCE, str[str_idx]);
|
2002-04-12 01:58:40 +02:00
|
|
|
str[val_idx] = str[str_idx];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str[val_idx] = str[str_idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str[val_idx] = '\0';
|
2014-10-29 03:30:13 +01:00
|
|
|
return val_idx;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
2008-09-08 21:44:08 +02:00
|
|
|
static BOOL parseKeyName(LPWSTR lpKeyName, HKEY *hKey, LPWSTR *lpKeyPath)
|
2008-07-07 23:12:21 +02:00
|
|
|
{
|
|
|
|
WCHAR* lpSlash = NULL;
|
|
|
|
unsigned int i, len;
|
|
|
|
|
|
|
|
if (lpKeyName == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for(i = 0; *(lpKeyName+i) != 0; i++)
|
|
|
|
{
|
|
|
|
if(*(lpKeyName+i) == '\\')
|
|
|
|
{
|
|
|
|
lpSlash = lpKeyName+i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpSlash)
|
|
|
|
{
|
|
|
|
len = lpSlash-lpKeyName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = lstrlenW(lpKeyName);
|
|
|
|
lpSlash = lpKeyName+len;
|
|
|
|
}
|
|
|
|
*hKey = NULL;
|
|
|
|
|
2016-07-21 07:48:43 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++) {
|
2014-11-19 08:55:58 +01:00
|
|
|
if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], -1) == CSTR_EQUAL &&
|
2008-07-07 23:12:21 +02:00
|
|
|
len == lstrlenW(reg_class_namesW[i])) {
|
|
|
|
*hKey = reg_class_keys[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*hKey == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
if (*lpSlash != '\0')
|
|
|
|
lpSlash++;
|
|
|
|
*lpKeyPath = lpSlash;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-15 18:59:55 +02:00
|
|
|
/* Globals used by the setValue() & co */
|
2016-07-15 09:50:16 +02:00
|
|
|
static WCHAR *currentKeyName;
|
2007-06-15 18:59:55 +02:00
|
|
|
static HKEY currentKeyHandle = NULL;
|
|
|
|
|
2016-07-21 12:57:01 +02:00
|
|
|
/* Registry data types */
|
|
|
|
static const WCHAR type_none[] = {'R','E','G','_','N','O','N','E',0};
|
|
|
|
static const WCHAR type_sz[] = {'R','E','G','_','S','Z',0};
|
|
|
|
static const WCHAR type_expand_sz[] = {'R','E','G','_','E','X','P','A','N','D','_','S','Z',0};
|
|
|
|
static const WCHAR type_binary[] = {'R','E','G','_','B','I','N','A','R','Y',0};
|
|
|
|
static const WCHAR type_dword[] = {'R','E','G','_','D','W','O','R','D',0};
|
|
|
|
static const WCHAR type_dword_le[] = {'R','E','G','_','D','W','O','R','D','_','L','I','T','T','L','E','_','E','N','D','I','A','N',0};
|
|
|
|
static const WCHAR type_dword_be[] = {'R','E','G','_','D','W','O','R','D','_','B','I','G','_','E','N','D','I','A','N',0};
|
|
|
|
static const WCHAR type_multi_sz[] = {'R','E','G','_','M','U','L','T','I','_','S','Z',0};
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
const WCHAR *name;
|
|
|
|
}
|
|
|
|
type_rels[] =
|
|
|
|
{
|
|
|
|
{REG_NONE, type_none},
|
|
|
|
{REG_SZ, type_sz},
|
|
|
|
{REG_EXPAND_SZ, type_expand_sz},
|
|
|
|
{REG_BINARY, type_binary},
|
|
|
|
{REG_DWORD, type_dword},
|
|
|
|
{REG_DWORD_LITTLE_ENDIAN, type_dword_le},
|
|
|
|
{REG_DWORD_BIG_ENDIAN, type_dword_be},
|
|
|
|
{REG_MULTI_SZ, type_multi_sz},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WCHAR *reg_type_to_wchar(DWORD type)
|
|
|
|
{
|
|
|
|
int i, array_size = ARRAY_SIZE(type_rels);
|
|
|
|
|
|
|
|
for (i = 0; i < array_size; i++)
|
|
|
|
{
|
|
|
|
if (type == type_rels[i].type)
|
|
|
|
return type_rels[i].name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* Sets the value with name val_name to the data in val_data for the currently
|
2002-04-12 01:58:40 +02:00
|
|
|
* opened key.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* val_name - name of the registry value
|
|
|
|
* val_data - registry value data
|
|
|
|
*/
|
2008-09-09 21:48:33 +02:00
|
|
|
static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2007-06-14 11:46:46 +02:00
|
|
|
LONG res;
|
2007-06-14 11:46:29 +02:00
|
|
|
DWORD dwDataType, dwParseType;
|
2003-12-08 23:48:07 +01:00
|
|
|
LPBYTE lpbData;
|
2007-06-14 11:46:29 +02:00
|
|
|
DWORD dwData, dwLen;
|
2008-07-09 20:59:01 +02:00
|
|
|
WCHAR del[] = {'-',0};
|
2003-12-08 23:48:07 +01:00
|
|
|
|
|
|
|
if ( (val_name == NULL) || (val_data == NULL) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2008-07-09 20:59:01 +02:00
|
|
|
if (lstrcmpW(val_data, del) == 0)
|
2007-06-14 11:47:50 +02:00
|
|
|
{
|
2008-07-09 20:02:02 +02:00
|
|
|
res=RegDeleteValueW(currentKeyHandle,val_name);
|
2007-06-14 11:47:50 +02:00
|
|
|
return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res);
|
|
|
|
}
|
2006-07-28 19:38:44 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
/* Get the data type stored into the value field */
|
|
|
|
dwDataType = getDataType(&val_data, &dwParseType);
|
|
|
|
|
2007-06-14 11:43:58 +02:00
|
|
|
if (dwParseType == REG_SZ) /* no conversion for string */
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2014-10-29 03:30:13 +01:00
|
|
|
dwLen = REGPROC_unescape_string(val_data);
|
|
|
|
if(!dwLen || val_data[dwLen-1] != '"')
|
2010-08-05 18:57:55 +02:00
|
|
|
return ERROR_INVALID_DATA;
|
2014-10-29 03:30:13 +01:00
|
|
|
val_data[dwLen-1] = '\0'; /* remove last quotes */
|
2008-07-09 20:59:01 +02:00
|
|
|
lpbData = (BYTE*) val_data;
|
2008-07-09 20:02:02 +02:00
|
|
|
dwLen = dwLen * sizeof(WCHAR); /* size is in bytes */
|
2007-06-14 11:43:58 +02:00
|
|
|
}
|
|
|
|
else if (dwParseType == REG_DWORD) /* Convert the dword types */
|
2002-06-21 22:12:02 +02:00
|
|
|
{
|
2007-06-14 11:46:29 +02:00
|
|
|
if (!convertHexToDWord(val_data, &dwData))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
lpbData = (BYTE*)&dwData;
|
|
|
|
dwLen = sizeof(dwData);
|
2007-06-14 11:43:58 +02:00
|
|
|
}
|
|
|
|
else if (dwParseType == REG_BINARY) /* Convert the binary data */
|
2002-06-21 22:12:02 +02:00
|
|
|
{
|
2007-06-14 11:46:29 +02:00
|
|
|
lpbData = convertHexCSVToHex(val_data, &dwLen);
|
|
|
|
if (!lpbData)
|
|
|
|
return ERROR_INVALID_DATA;
|
2008-09-09 21:48:33 +02:00
|
|
|
|
2009-01-18 09:29:09 +01:00
|
|
|
if((dwDataType == REG_MULTI_SZ || dwDataType == REG_EXPAND_SZ) && !is_unicode)
|
2008-09-09 21:48:33 +02:00
|
|
|
{
|
|
|
|
LPBYTE tmp = lpbData;
|
|
|
|
lpbData = (LPBYTE)GetWideStringN((char*)lpbData, dwLen, &dwLen);
|
|
|
|
dwLen *= sizeof(WCHAR);
|
|
|
|
HeapFree(GetProcessHeap(), 0, tmp);
|
|
|
|
}
|
2002-06-21 22:12:02 +02:00
|
|
|
}
|
2007-06-14 11:43:58 +02:00
|
|
|
else /* unknown format */
|
|
|
|
{
|
2016-07-21 12:57:01 +02:00
|
|
|
output_message(STRING_UNKNOWN_DATA_FORMAT, reg_type_to_wchar(dwDataType));
|
2007-06-14 11:43:58 +02:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2008-07-09 20:02:02 +02:00
|
|
|
res = RegSetValueExW(
|
2003-12-08 23:48:07 +01:00
|
|
|
currentKeyHandle,
|
|
|
|
val_name,
|
|
|
|
0, /* Reserved */
|
|
|
|
dwDataType,
|
|
|
|
lpbData,
|
|
|
|
dwLen);
|
2008-07-09 20:59:01 +02:00
|
|
|
if (dwParseType == REG_BINARY)
|
2007-06-14 11:46:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpbData);
|
2007-06-14 11:46:46 +02:00
|
|
|
return res;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2007-06-15 18:59:55 +02:00
|
|
|
* A helper function for processRegEntry() that opens the current key.
|
|
|
|
* That key must be closed by calling closeKey().
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2008-07-09 21:42:20 +02:00
|
|
|
static LONG openKeyW(WCHAR* stdInput)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2007-06-15 18:59:55 +02:00
|
|
|
HKEY keyClass;
|
2008-07-09 21:42:20 +02:00
|
|
|
WCHAR* keyPath;
|
2007-06-14 11:46:46 +02:00
|
|
|
DWORD dwDisp;
|
|
|
|
LONG res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-06-14 11:42:41 +02:00
|
|
|
/* Sanity checks */
|
|
|
|
if (stdInput == NULL)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-06-14 11:42:41 +02:00
|
|
|
/* Get the registry class */
|
2008-09-08 21:44:08 +02:00
|
|
|
if (!parseKeyName(stdInput, &keyClass, &keyPath))
|
2007-06-14 11:42:41 +02:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2008-07-09 21:42:20 +02:00
|
|
|
res = RegCreateKeyExW(
|
2007-06-15 18:59:55 +02:00
|
|
|
keyClass, /* Class */
|
|
|
|
keyPath, /* Sub Key */
|
2007-06-14 11:42:41 +02:00
|
|
|
0, /* MUST BE 0 */
|
|
|
|
NULL, /* object type */
|
|
|
|
REG_OPTION_NON_VOLATILE, /* option, REG_OPTION_NON_VOLATILE ... */
|
|
|
|
KEY_ALL_ACCESS, /* access mask, KEY_ALL_ACCESS */
|
|
|
|
NULL, /* security attribute */
|
|
|
|
¤tKeyHandle, /* result */
|
|
|
|
&dwDisp); /* disposition, REG_CREATED_NEW_KEY or
|
|
|
|
REG_OPENED_EXISTING_KEY */
|
|
|
|
|
2007-06-14 11:46:46 +02:00
|
|
|
if (res == ERROR_SUCCESS)
|
2016-07-15 09:50:16 +02:00
|
|
|
{
|
|
|
|
currentKeyName = HeapAlloc(GetProcessHeap(), 0, (strlenW(stdInput) + 1) * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(currentKeyName);
|
|
|
|
strcpyW(currentKeyName, stdInput);
|
|
|
|
}
|
2007-06-15 18:59:55 +02:00
|
|
|
else
|
|
|
|
currentKeyHandle = NULL;
|
2007-06-14 11:42:41 +02:00
|
|
|
|
2007-06-14 11:46:46 +02:00
|
|
|
return res;
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Close the currently opened key.
|
|
|
|
*/
|
2007-06-14 11:42:41 +02:00
|
|
|
static void closeKey(void)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2007-06-15 18:59:55 +02:00
|
|
|
if (currentKeyHandle)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, currentKeyName);
|
|
|
|
RegCloseKey(currentKeyHandle);
|
|
|
|
currentKeyHandle = NULL;
|
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* This function is a wrapper for the setValue function. It prepares the
|
2007-12-07 01:03:54 +01:00
|
|
|
* land and cleans the area once completed.
|
2002-04-12 01:58:40 +02:00
|
|
|
* Note: this function modifies the line parameter.
|
|
|
|
*
|
|
|
|
* line - registry file unwrapped line. Should have the registry value name and
|
|
|
|
* complete registry value data.
|
|
|
|
*/
|
2008-09-09 21:48:33 +02:00
|
|
|
static void processSetValue(WCHAR* line, BOOL is_unicode)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-07-09 22:41:26 +02:00
|
|
|
WCHAR* val_name; /* registry value name */
|
|
|
|
WCHAR* val_data; /* registry value data */
|
2003-12-08 23:48:07 +01:00
|
|
|
int line_idx = 0; /* current character under analysis */
|
2007-06-14 11:46:46 +02:00
|
|
|
LONG res;
|
2003-12-08 23:48:07 +01:00
|
|
|
|
|
|
|
/* get value name */
|
2008-09-26 07:31:24 +02:00
|
|
|
while ( isspaceW(line[line_idx]) ) line_idx++;
|
2003-12-08 23:48:07 +01:00
|
|
|
if (line[line_idx] == '@' && line[line_idx + 1] == '=') {
|
|
|
|
line[line_idx] = '\0';
|
|
|
|
val_name = line;
|
|
|
|
line_idx++;
|
|
|
|
} else if (line[line_idx] == '\"') {
|
|
|
|
line_idx++;
|
|
|
|
val_name = line + line_idx;
|
2010-08-05 18:57:55 +02:00
|
|
|
while (line[line_idx]) {
|
2003-12-08 23:48:07 +01:00
|
|
|
if (line[line_idx] == '\\') /* skip escaped character */
|
|
|
|
{
|
|
|
|
line_idx += 2;
|
|
|
|
} else {
|
|
|
|
if (line[line_idx] == '\"') {
|
|
|
|
line[line_idx] = '\0';
|
|
|
|
line_idx++;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
line_idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-26 07:31:24 +02:00
|
|
|
while ( isspaceW(line[line_idx]) ) line_idx++;
|
2010-08-05 18:57:55 +02:00
|
|
|
if (!line[line_idx]) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_UNEXPECTED_EOL, line);
|
2010-08-05 18:57:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
if (line[line_idx] != '=') {
|
|
|
|
line[line_idx] = '\"';
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_UNRECOGNIZED_LINE, line);
|
2003-12-08 23:48:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_UNRECOGNIZED_LINE, line);
|
2003-12-08 23:48:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
line_idx++; /* skip the '=' character */
|
2008-09-26 07:31:24 +02:00
|
|
|
|
|
|
|
while ( isspaceW(line[line_idx]) ) line_idx++;
|
2003-12-08 23:48:07 +01:00
|
|
|
val_data = line + line_idx;
|
2008-09-26 07:31:24 +02:00
|
|
|
/* trim trailing blanks */
|
|
|
|
line_idx = strlenW(val_data);
|
|
|
|
while (line_idx > 0 && isspaceW(val_data[line_idx-1])) line_idx--;
|
|
|
|
val_data[line_idx] = '\0';
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2008-07-09 22:41:26 +02:00
|
|
|
REGPROC_unescape_string(val_name);
|
2008-09-09 21:48:33 +02:00
|
|
|
res = setValue(val_name, val_data, is_unicode);
|
2007-06-14 11:46:46 +02:00
|
|
|
if ( res != ERROR_SUCCESS )
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_SETVALUE_FAILED, val_name, currentKeyName);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2007-06-14 11:42:41 +02:00
|
|
|
* This function receives the currently read entry and performs the
|
|
|
|
* corresponding action.
|
2008-09-09 21:48:33 +02:00
|
|
|
* isUnicode affects parsing of REG_MULTI_SZ values
|
2007-06-14 11:42:41 +02:00
|
|
|
*/
|
2008-09-09 21:48:33 +02:00
|
|
|
static void processRegEntry(WCHAR* stdInput, BOOL isUnicode)
|
2007-06-14 11:42:41 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We encountered the end of the file, make sure we
|
|
|
|
* close the opened key and exit
|
|
|
|
*/
|
|
|
|
if (stdInput == NULL) {
|
2007-06-15 18:59:55 +02:00
|
|
|
closeKey();
|
2007-06-14 11:42:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( stdInput[0] == '[') /* We are reading a new key */
|
|
|
|
{
|
2008-07-09 22:41:26 +02:00
|
|
|
WCHAR* keyEnd;
|
2007-06-15 18:59:55 +02:00
|
|
|
closeKey(); /* Close the previous key */
|
2007-06-14 11:42:41 +02:00
|
|
|
|
2007-06-15 18:58:42 +02:00
|
|
|
/* Get rid of the square brackets */
|
|
|
|
stdInput++;
|
2008-07-09 22:41:26 +02:00
|
|
|
keyEnd = strrchrW(stdInput, ']');
|
2007-06-15 18:58:42 +02:00
|
|
|
if (keyEnd)
|
|
|
|
*keyEnd='\0';
|
|
|
|
|
2007-06-14 11:42:41 +02:00
|
|
|
/* delete the key if we encounter '-' at the start of reg key */
|
2016-07-15 09:49:48 +02:00
|
|
|
if (stdInput[0] == '-')
|
2008-07-09 22:41:26 +02:00
|
|
|
delete_registry_key(stdInput + 1);
|
2016-07-15 09:49:48 +02:00
|
|
|
else if (openKeyW(stdInput) != ERROR_SUCCESS)
|
|
|
|
output_message(STRING_OPEN_KEY_FAILED, stdInput);
|
2007-06-15 18:59:55 +02:00
|
|
|
} else if( currentKeyHandle &&
|
2007-06-14 11:42:41 +02:00
|
|
|
(( stdInput[0] == '@') || /* reading a default @=data pair */
|
|
|
|
( stdInput[0] == '\"'))) /* reading a new value=data pair */
|
|
|
|
{
|
2008-09-09 21:48:33 +02:00
|
|
|
processSetValue(stdInput, isUnicode);
|
2007-06-15 18:59:55 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
/* Since we are assuming that the file format is valid we must be
|
|
|
|
* reading a blank line which indicates the end of this key processing
|
|
|
|
*/
|
|
|
|
closeKey();
|
2007-06-14 11:42:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Processes a registry file.
|
2012-04-27 06:40:47 +02:00
|
|
|
* Correctly processes comments (in # and ; form), line continuation.
|
2002-04-12 01:58:40 +02:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* in - input stream to read from
|
2009-06-16 15:46:33 +02:00
|
|
|
* first_chars - beginning of stream, read due to Unicode check
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2009-06-16 15:46:33 +02:00
|
|
|
static void processRegLinesA(FILE *in, char* first_chars)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2016-07-21 07:48:30 +02:00
|
|
|
char *buf = NULL; /* the line read from the input stream */
|
|
|
|
unsigned long line_size = REG_VAL_BUF_SIZE;
|
|
|
|
size_t chars_in_buf = -1;
|
|
|
|
char *s; /* A pointer to buf for fread */
|
|
|
|
char *line; /* The start of the current line */
|
|
|
|
WCHAR *lineW;
|
|
|
|
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, line_size);
|
|
|
|
CHECK_ENOUGH_MEMORY(buf);
|
|
|
|
s = buf;
|
|
|
|
line = buf;
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2009-06-16 15:46:33 +02:00
|
|
|
memcpy(line, first_chars, 2);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
if (first_chars)
|
|
|
|
s += 2;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
while (!feof(in)) {
|
2016-07-21 07:48:30 +02:00
|
|
|
size_t size_remaining;
|
|
|
|
int size_to_get;
|
|
|
|
char *s_eol = NULL; /* various local uses */
|
2009-06-16 15:46:33 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* Do we need to expand the buffer? */
|
|
|
|
assert(s >= buf && s <= buf + line_size);
|
|
|
|
size_remaining = line_size - (s - buf);
|
|
|
|
if (size_remaining < 3) /* we need at least 3 bytes of room for \r\n\0 */
|
2009-06-16 15:46:33 +02:00
|
|
|
{
|
2016-07-21 07:48:30 +02:00
|
|
|
char *new_buffer;
|
|
|
|
size_t new_size = line_size + REG_VAL_BUF_SIZE;
|
|
|
|
if (new_size > line_size) /* no arithmetic overflow */
|
|
|
|
new_buffer = HeapReAlloc(GetProcessHeap(), 0, buf, new_size);
|
|
|
|
else
|
|
|
|
new_buffer = NULL;
|
|
|
|
CHECK_ENOUGH_MEMORY(new_buffer);
|
|
|
|
buf = new_buffer;
|
|
|
|
line = buf;
|
|
|
|
s = buf + line_size - size_remaining;
|
|
|
|
line_size = new_size;
|
|
|
|
size_remaining = line_size - (s - buf);
|
2009-06-16 15:46:33 +02:00
|
|
|
}
|
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* Get as much as possible into the buffer, terminating on EOF,
|
|
|
|
* error or once we have read the maximum amount. Abort on error.
|
|
|
|
*/
|
|
|
|
size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);
|
2002-06-21 22:12:02 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
chars_in_buf = fread(s, 1, size_to_get - 1, in);
|
|
|
|
s[chars_in_buf] = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
if (chars_in_buf == 0) {
|
|
|
|
if (ferror(in)) {
|
|
|
|
perror("While reading input");
|
|
|
|
exit(IO_ERROR);
|
|
|
|
} else {
|
|
|
|
assert(feof(in));
|
|
|
|
*s = '\0';
|
2002-06-21 22:12:02 +02:00
|
|
|
}
|
2016-07-21 07:48:30 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* If we didn't read the end-of-line sequence or EOF, go around again */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
s_eol = strpbrk(line, "\r\n");
|
|
|
|
if (!s_eol) {
|
|
|
|
/* Move the stub of the line to the start of the buffer so
|
|
|
|
* we get the maximum space to read into, and so we don't
|
|
|
|
* have to recalculate 'line' if the buffer expands */
|
|
|
|
MoveMemory(buf, line, strlen(line) + 1);
|
|
|
|
line = buf;
|
|
|
|
s = strchr(line, '\0');
|
|
|
|
break;
|
2002-06-21 22:12:02 +02:00
|
|
|
}
|
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* If we find a comment line, discard it and go around again */
|
2012-04-27 06:40:47 +02:00
|
|
|
if (line [0] == '#' || line [0] == ';') {
|
2016-07-21 07:48:30 +02:00
|
|
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
|
|
|
line = s_eol + 2;
|
|
|
|
else
|
|
|
|
line = s_eol + 1;
|
2002-04-12 01:58:40 +02:00
|
|
|
continue;
|
2002-06-21 22:12:02 +02:00
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* If there is a concatenating '\\', go around again */
|
|
|
|
if (*(s_eol - 1) == '\\') {
|
|
|
|
char *next_line = s_eol + 1;
|
|
|
|
|
|
|
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
|
|
|
next_line++;
|
|
|
|
|
|
|
|
while (*(next_line + 1) == ' ' || *(next_line + 1) == '\t')
|
|
|
|
next_line++;
|
|
|
|
|
|
|
|
MoveMemory(s_eol - 1, next_line, chars_in_buf - (next_line - s) + 1);
|
|
|
|
chars_in_buf -= next_line - s_eol + 1;
|
|
|
|
s_eol = 0;
|
2002-06-21 22:12:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
/* Remove any line feed. Leave s_eol on the last \0 */
|
|
|
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
|
|
|
*s_eol++ = '\0';
|
|
|
|
*s_eol = '\0';
|
2008-07-09 22:41:26 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
lineW = GetWideString(line);
|
|
|
|
processRegEntry(lineW, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lineW);
|
|
|
|
line = s_eol + 1;
|
|
|
|
s_eol = 0;
|
|
|
|
continue; /* That is the full virtual line */
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-09 21:48:33 +02:00
|
|
|
processRegEntry(NULL, FALSE);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2016-07-21 07:48:30 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
2009-01-26 12:53:12 +01:00
|
|
|
static void processRegLinesW(FILE *in)
|
2008-07-09 23:39:08 +02:00
|
|
|
{
|
|
|
|
WCHAR* buf = NULL; /* line read from input stream */
|
|
|
|
ULONG lineSize = REG_VAL_BUF_SIZE;
|
2008-07-13 13:58:40 +02:00
|
|
|
size_t CharsInBuf = -1;
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2009-03-08 16:45:54 +01:00
|
|
|
WCHAR* s; /* The pointer into buf for where the current fgets should read */
|
|
|
|
WCHAR* line; /* The start of the current line */
|
2008-07-09 23:39:08 +02:00
|
|
|
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, lineSize * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(buf);
|
|
|
|
|
|
|
|
s = buf;
|
2009-03-08 16:45:54 +01:00
|
|
|
line = buf;
|
2008-07-09 23:39:08 +02:00
|
|
|
|
|
|
|
while(!feof(in)) {
|
|
|
|
size_t size_remaining;
|
|
|
|
int size_to_get;
|
|
|
|
WCHAR *s_eol = NULL; /* various local uses */
|
|
|
|
|
|
|
|
/* Do we need to expand the buffer ? */
|
|
|
|
assert (s >= buf && s <= buf + lineSize);
|
|
|
|
size_remaining = lineSize - (s-buf);
|
|
|
|
if (size_remaining < 2) /* room for 1 character and the \0 */
|
|
|
|
{
|
|
|
|
WCHAR *new_buffer;
|
|
|
|
size_t new_size = lineSize + (REG_VAL_BUF_SIZE / sizeof(WCHAR));
|
|
|
|
if (new_size > lineSize) /* no arithmetic overflow */
|
|
|
|
new_buffer = HeapReAlloc (GetProcessHeap(), 0, buf, new_size * sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
new_buffer = NULL;
|
|
|
|
CHECK_ENOUGH_MEMORY(new_buffer);
|
|
|
|
buf = new_buffer;
|
2009-03-08 16:45:54 +01:00
|
|
|
line = buf;
|
2008-07-09 23:39:08 +02:00
|
|
|
s = buf + lineSize - size_remaining;
|
|
|
|
lineSize = new_size;
|
|
|
|
size_remaining = lineSize - (s-buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get as much as possible into the buffer, terminated either by
|
2008-07-11 13:21:17 +02:00
|
|
|
* eof, error or getting the maximum amount. Abort on error.
|
2008-07-09 23:39:08 +02:00
|
|
|
*/
|
|
|
|
size_to_get = (size_remaining > INT_MAX ? INT_MAX : size_remaining);
|
|
|
|
|
2008-07-13 13:58:40 +02:00
|
|
|
CharsInBuf = fread(s, sizeof(WCHAR), size_to_get - 1, in);
|
|
|
|
s[CharsInBuf] = 0;
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2008-07-13 13:58:40 +02:00
|
|
|
if (CharsInBuf == 0) {
|
2008-07-09 23:39:08 +02:00
|
|
|
if (ferror(in)) {
|
|
|
|
perror ("While reading input");
|
|
|
|
exit (IO_ERROR);
|
|
|
|
} else {
|
|
|
|
assert (feof(in));
|
|
|
|
*s = '\0';
|
|
|
|
/* It is not clear to me from the definition that the
|
|
|
|
* contents of the buffer are well defined on detecting
|
|
|
|
* an eof without managing to read anything.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we didn't read the eol nor the eof go around for the rest */
|
|
|
|
while(1)
|
|
|
|
{
|
2010-07-30 23:02:36 +02:00
|
|
|
const WCHAR line_endings[] = {'\r','\n',0};
|
|
|
|
s_eol = strpbrkW(line, line_endings);
|
2009-03-08 16:45:54 +01:00
|
|
|
|
|
|
|
if(!s_eol) {
|
|
|
|
/* Move the stub of the line to the start of the buffer so
|
|
|
|
* we get the maximum space to read into, and so we don't
|
|
|
|
* have to recalculate 'line' if the buffer expands */
|
|
|
|
MoveMemory(buf, line, (strlenW(line)+1) * sizeof(WCHAR));
|
|
|
|
line = buf;
|
|
|
|
s = strchrW(line, '\0');
|
2008-07-11 13:21:17 +02:00
|
|
|
break;
|
2009-03-08 16:45:54 +01:00
|
|
|
}
|
2008-07-11 13:21:17 +02:00
|
|
|
|
2008-07-09 23:39:08 +02:00
|
|
|
/* If it is a comment line then discard it and go around again */
|
2012-04-27 06:40:47 +02:00
|
|
|
if (*line == '#' || *line == ';') {
|
2010-07-30 23:02:36 +02:00
|
|
|
if (*s_eol == '\r' && *(s_eol+1) == '\n')
|
|
|
|
line = s_eol + 2;
|
|
|
|
else
|
|
|
|
line = s_eol + 1;
|
2008-07-09 23:39:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-13 13:58:40 +02:00
|
|
|
/* If there is a concatenating \\ then go around again */
|
2010-07-30 23:02:36 +02:00
|
|
|
if (*(s_eol-1) == '\\') {
|
|
|
|
WCHAR* NextLine = s_eol + 1;
|
2008-07-13 13:58:40 +02:00
|
|
|
|
2010-07-30 23:02:36 +02:00
|
|
|
if(*s_eol == '\r' && *(s_eol+1) == '\n')
|
2008-07-13 13:58:40 +02:00
|
|
|
NextLine++;
|
|
|
|
|
2010-07-30 23:02:36 +02:00
|
|
|
while(*(NextLine+1) == ' ' || *(NextLine+1) == '\t')
|
|
|
|
NextLine++;
|
2008-07-13 13:58:40 +02:00
|
|
|
|
2009-03-08 16:45:54 +01:00
|
|
|
MoveMemory(s_eol - 1, NextLine, (CharsInBuf - (NextLine - s) + 1)*sizeof(WCHAR));
|
2008-07-13 13:58:40 +02:00
|
|
|
CharsInBuf -= NextLine - s_eol + 1;
|
|
|
|
s_eol = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-30 23:02:36 +02:00
|
|
|
/* Remove any line feed. Leave s_eol on the last \0 */
|
|
|
|
if (*s_eol == '\r' && *(s_eol + 1) == '\n')
|
|
|
|
*s_eol++ = '\0';
|
|
|
|
*s_eol = '\0';
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2009-03-08 16:45:54 +01:00
|
|
|
processRegEntry(line, TRUE);
|
|
|
|
line = s_eol + 1;
|
2008-07-09 23:39:08 +02:00
|
|
|
s_eol = 0;
|
|
|
|
continue; /* That is the full virtual line */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 21:48:33 +02:00
|
|
|
processRegEntry(NULL, TRUE);
|
2008-07-09 23:39:08 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* REGPROC_print_error
|
|
|
|
*
|
|
|
|
* Print the message for GetLastError
|
|
|
|
*/
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static void REGPROC_print_error(void)
|
2003-12-08 23:48:07 +01:00
|
|
|
{
|
2016-07-15 09:49:58 +02:00
|
|
|
WCHAR *str;
|
|
|
|
DWORD error_code, len;
|
|
|
|
|
|
|
|
error_code = GetLastError();
|
|
|
|
len = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, error_code, 0, (WCHAR *)&str, 0, NULL);
|
|
|
|
if (len == 0 && GetLastError() != NO_ERROR) {
|
|
|
|
WINE_FIXME("FormatMessage failed: le=%u, previous=%u\n", GetLastError(), error_code);
|
2002-04-12 01:58:40 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-07-15 09:49:58 +02:00
|
|
|
output_writeconsole(str, len);
|
|
|
|
LocalFree(str);
|
2002-04-12 01:58:40 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Checks whether the buffer has enough room for the string or required size.
|
|
|
|
* Resizes the buffer if necessary.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* buffer - pointer to a buffer for string
|
|
|
|
* len - current length of the buffer in characters.
|
|
|
|
* required_len - length of the string to place to the buffer in characters.
|
|
|
|
* The length does not include the terminating null character.
|
|
|
|
*/
|
2008-09-08 21:44:08 +02:00
|
|
|
static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD required_len)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
|
|
|
required_len++;
|
2003-12-08 23:48:07 +01:00
|
|
|
if (required_len > *len) {
|
2002-04-12 01:58:40 +02:00
|
|
|
*len = required_len;
|
2003-11-21 00:43:12 +01:00
|
|
|
if (!*buffer)
|
|
|
|
*buffer = HeapAlloc(GetProcessHeap(), 0, *len * sizeof(**buffer));
|
2003-12-08 23:48:07 +01:00
|
|
|
else
|
2003-11-21 00:43:12 +01:00
|
|
|
*buffer = HeapReAlloc(GetProcessHeap(), 0, *buffer, *len * sizeof(**buffer));
|
2002-04-12 01:58:40 +02:00
|
|
|
CHECK_ENOUGH_MEMORY(*buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 11:06:32 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Same as REGPROC_resize_char_buffer() but on a regular buffer.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* buffer - pointer to a buffer
|
|
|
|
* len - current size of the buffer in bytes
|
|
|
|
* required_size - size of the data to place in the buffer in bytes
|
|
|
|
*/
|
|
|
|
static void REGPROC_resize_binary_buffer(BYTE **buffer, DWORD *size, DWORD required_size)
|
|
|
|
{
|
|
|
|
if (required_size > *size) {
|
|
|
|
*size = required_size;
|
|
|
|
if (!*buffer)
|
|
|
|
*buffer = HeapAlloc(GetProcessHeap(), 0, *size);
|
|
|
|
else
|
|
|
|
*buffer = HeapReAlloc(GetProcessHeap(), 0, *buffer, *size);
|
|
|
|
CHECK_ENOUGH_MEMORY(*buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
2002-06-28 19:33:09 +02:00
|
|
|
* Prints string str to file
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2008-11-20 20:45:25 +01:00
|
|
|
static void REGPROC_export_string(WCHAR **line_buf, DWORD *line_buf_size, DWORD *line_len, WCHAR *str, DWORD str_len)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-11-12 11:29:09 +01:00
|
|
|
DWORD i, pos;
|
2008-09-12 00:54:02 +02:00
|
|
|
DWORD extra = 0;
|
|
|
|
|
2008-11-20 20:45:25 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + 10);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
/* escaping characters */
|
2008-11-12 11:29:09 +01:00
|
|
|
pos = *line_len;
|
2008-11-20 20:45:25 +01:00
|
|
|
for (i = 0; i < str_len; i++) {
|
2008-09-12 00:54:02 +02:00
|
|
|
WCHAR c = str[i];
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (c) {
|
2008-11-12 11:29:09 +01:00
|
|
|
case '\n':
|
2008-09-12 00:54:02 +02:00
|
|
|
extra++;
|
2008-11-20 20:45:25 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra);
|
2008-11-12 11:29:09 +01:00
|
|
|
(*line_buf)[pos++] = '\\';
|
|
|
|
(*line_buf)[pos++] = 'n';
|
2002-04-12 01:58:40 +02:00
|
|
|
break;
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2014-10-30 02:55:08 +01:00
|
|
|
case '\r':
|
|
|
|
extra++;
|
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra);
|
|
|
|
(*line_buf)[pos++] = '\\';
|
|
|
|
(*line_buf)[pos++] = 'r';
|
|
|
|
break;
|
|
|
|
|
2008-11-12 11:29:09 +01:00
|
|
|
case '\\':
|
|
|
|
case '"':
|
2008-09-12 00:54:02 +02:00
|
|
|
extra++;
|
2008-11-20 20:45:25 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra);
|
2008-11-12 11:29:09 +01:00
|
|
|
(*line_buf)[pos++] = '\\';
|
|
|
|
/* Fall through */
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
default:
|
2008-11-12 11:29:09 +01:00
|
|
|
(*line_buf)[pos++] = c;
|
2002-04-12 01:58:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-12 11:29:09 +01:00
|
|
|
(*line_buf)[pos] = '\0';
|
|
|
|
*line_len = pos;
|
2008-09-12 00:54:02 +02:00
|
|
|
}
|
|
|
|
|
2008-11-20 20:43:25 +01:00
|
|
|
static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD *line_len, DWORD type, BYTE *value, DWORD value_size, BOOL unicode)
|
|
|
|
{
|
2008-11-23 20:54:45 +01:00
|
|
|
DWORD hex_pos, data_pos;
|
2008-11-20 20:43:25 +01:00
|
|
|
const WCHAR *hex_prefix;
|
|
|
|
const WCHAR hex[] = {'h','e','x',':',0};
|
|
|
|
WCHAR hex_buf[17];
|
2011-03-04 15:00:51 +01:00
|
|
|
const WCHAR concat[] = {'\\','\r','\n',' ',' ',0};
|
2008-11-20 20:43:25 +01:00
|
|
|
DWORD concat_prefix, concat_len;
|
2011-03-04 15:00:51 +01:00
|
|
|
const WCHAR newline[] = {'\r','\n',0};
|
2008-11-20 20:43:25 +01:00
|
|
|
CHAR* value_multibyte = NULL;
|
|
|
|
|
|
|
|
if (type == REG_BINARY) {
|
|
|
|
hex_prefix = hex;
|
|
|
|
} else {
|
2012-05-17 02:39:19 +02:00
|
|
|
const WCHAR hex_format[] = {'h','e','x','(','%','x',')',':',0};
|
2008-11-20 20:43:25 +01:00
|
|
|
hex_prefix = hex_buf;
|
2008-11-20 20:45:12 +01:00
|
|
|
sprintfW(hex_buf, hex_format, type);
|
2008-11-20 20:43:25 +01:00
|
|
|
if ((type == REG_SZ || type == REG_EXPAND_SZ || type == REG_MULTI_SZ) && !unicode)
|
|
|
|
{
|
|
|
|
value_multibyte = GetMultiByteStringN((WCHAR*)value, value_size / sizeof(WCHAR), &value_size);
|
|
|
|
value = (BYTE*)value_multibyte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
concat_len = lstrlenW(concat);
|
|
|
|
concat_prefix = 2;
|
|
|
|
|
|
|
|
hex_pos = *line_len;
|
|
|
|
*line_len += lstrlenW(hex_prefix);
|
|
|
|
data_pos = *line_len;
|
|
|
|
*line_len += value_size * 3;
|
|
|
|
/* - The 2 spaces that concat places at the start of the
|
|
|
|
* line effectively reduce the space available for data.
|
|
|
|
* - If the value name and hex prefix are very long
|
2012-04-12 16:10:59 +02:00
|
|
|
* ( > REG_FILE_HEX_LINE_LEN) or *line_len divides
|
|
|
|
* without a remainder then we may overestimate
|
2008-11-20 20:43:25 +01:00
|
|
|
* the needed number of lines by one. But that's ok.
|
2012-04-12 16:10:59 +02:00
|
|
|
* - The trailing '\r' takes the place of a comma so
|
|
|
|
* we only need to add 1 for the trailing '\n'
|
2008-11-20 20:43:25 +01:00
|
|
|
*/
|
2012-04-12 16:10:59 +02:00
|
|
|
*line_len += *line_len / (REG_FILE_HEX_LINE_LEN - concat_prefix) * concat_len + 1;
|
2008-11-20 20:43:25 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len);
|
|
|
|
lstrcpyW(*line_buf + hex_pos, hex_prefix);
|
2008-11-23 20:54:45 +01:00
|
|
|
if (value_size)
|
2008-11-20 20:43:25 +01:00
|
|
|
{
|
2008-11-23 20:54:45 +01:00
|
|
|
const WCHAR format[] = {'%','0','2','x',0};
|
|
|
|
DWORD i, column;
|
2008-11-20 20:43:25 +01:00
|
|
|
|
2008-11-23 20:54:45 +01:00
|
|
|
column = data_pos; /* no line wrap yet */
|
|
|
|
i = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
sprintfW(*line_buf + data_pos, format, (unsigned int)value[i]);
|
|
|
|
data_pos += 2;
|
|
|
|
if (++i == value_size)
|
|
|
|
break;
|
2008-11-20 20:43:25 +01:00
|
|
|
|
2008-11-23 20:54:45 +01:00
|
|
|
(*line_buf)[data_pos++] = ',';
|
|
|
|
column += 3;
|
|
|
|
|
|
|
|
/* wrap the line */
|
|
|
|
if (column >= REG_FILE_HEX_LINE_LEN) {
|
|
|
|
lstrcpyW(*line_buf + data_pos, concat);
|
|
|
|
data_pos += concat_len;
|
|
|
|
column = concat_prefix;
|
|
|
|
}
|
2008-11-20 20:43:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lstrcpyW(*line_buf + data_pos, newline);
|
2008-11-25 10:12:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, value_multibyte);
|
2008-11-20 20:43:25 +01:00
|
|
|
}
|
|
|
|
|
2008-09-12 00:54:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Writes the given line to a file, in multi-byte or wide characters
|
|
|
|
*/
|
2008-09-14 02:21:23 +02:00
|
|
|
static void REGPROC_write_line(FILE *file, const WCHAR* str, BOOL unicode)
|
2008-09-12 00:54:02 +02:00
|
|
|
{
|
2008-09-14 02:21:23 +02:00
|
|
|
if(unicode)
|
|
|
|
{
|
|
|
|
fwrite(str, sizeof(WCHAR), lstrlenW(str), file);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
char* strA = GetMultiByteString(str);
|
2008-09-22 15:34:41 +02:00
|
|
|
fputs(strA, file);
|
2008-09-14 02:21:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, strA);
|
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Writes contents of the registry key to the specified file stream.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* file - writable file stream to export registry branch to.
|
|
|
|
* key - registry branch to export.
|
|
|
|
* reg_key_name_buf - name of the key with registry class.
|
|
|
|
* Is resized if necessary.
|
2008-11-12 11:28:49 +01:00
|
|
|
* reg_key_name_size - length of the buffer for the registry class in characters.
|
2002-04-12 01:58:40 +02:00
|
|
|
* val_name_buf - buffer for storing value name.
|
|
|
|
* Is resized if necessary.
|
2008-11-12 11:28:49 +01:00
|
|
|
* val_name_size - length of the buffer for storing value names in characters.
|
2002-04-12 01:58:40 +02:00
|
|
|
* val_buf - buffer for storing values while extracting.
|
|
|
|
* Is resized if necessary.
|
|
|
|
* val_size - size of the buffer for storing values in bytes.
|
|
|
|
*/
|
2005-06-04 12:01:25 +02:00
|
|
|
static void export_hkey(FILE *file, HKEY key,
|
2008-11-12 11:28:49 +01:00
|
|
|
WCHAR **reg_key_name_buf, DWORD *reg_key_name_size,
|
|
|
|
WCHAR **val_name_buf, DWORD *val_name_size,
|
2008-09-12 00:54:02 +02:00
|
|
|
BYTE **val_buf, DWORD *val_size,
|
2008-09-14 02:21:23 +02:00
|
|
|
WCHAR **line_buf, DWORD *line_buf_size,
|
|
|
|
BOOL unicode)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
|
|
|
DWORD max_sub_key_len;
|
|
|
|
DWORD max_val_name_len;
|
|
|
|
DWORD max_val_size;
|
|
|
|
DWORD curr_len;
|
|
|
|
DWORD i;
|
|
|
|
BOOL more_data;
|
|
|
|
LONG ret;
|
2011-03-04 15:00:51 +01:00
|
|
|
WCHAR key_format[] = {'\r','\n','[','%','s',']','\r','\n',0};
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
/* get size information and resize the buffers if necessary */
|
2008-09-08 21:44:08 +02:00
|
|
|
if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL,
|
2002-04-12 01:58:40 +02:00
|
|
|
&max_sub_key_len, NULL,
|
|
|
|
NULL, &max_val_name_len, &max_val_size, NULL, NULL
|
2003-12-08 23:48:07 +01:00
|
|
|
) != ERROR_SUCCESS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
REGPROC_print_error();
|
|
|
|
}
|
2008-09-08 21:44:08 +02:00
|
|
|
curr_len = strlenW(*reg_key_name_buf);
|
2008-11-12 11:28:49 +01:00
|
|
|
REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size,
|
2002-04-12 01:58:40 +02:00
|
|
|
max_sub_key_len + curr_len + 1);
|
2008-11-12 11:28:49 +01:00
|
|
|
REGPROC_resize_char_buffer(val_name_buf, val_name_size,
|
2002-04-12 01:58:40 +02:00
|
|
|
max_val_name_len);
|
2008-12-01 11:06:32 +01:00
|
|
|
REGPROC_resize_binary_buffer(val_buf, val_size, max_val_size);
|
2008-09-12 00:54:02 +02:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, lstrlenW(*reg_key_name_buf) + 4);
|
2002-04-12 01:58:40 +02:00
|
|
|
/* output data for the current key */
|
2008-11-20 20:45:12 +01:00
|
|
|
sprintfW(*line_buf, key_format, *reg_key_name_buf);
|
2008-09-14 02:21:23 +02:00
|
|
|
REGPROC_write_line(file, *line_buf, unicode);
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/* print all the values */
|
|
|
|
i = 0;
|
|
|
|
more_data = TRUE;
|
2003-12-08 23:48:07 +01:00
|
|
|
while(more_data) {
|
2002-04-12 01:58:40 +02:00
|
|
|
DWORD value_type;
|
2008-11-12 11:28:49 +01:00
|
|
|
DWORD val_name_size1 = *val_name_size;
|
2002-04-12 01:58:40 +02:00
|
|
|
DWORD val_size1 = *val_size;
|
2008-11-12 11:28:49 +01:00
|
|
|
ret = RegEnumValueW(key, i, *val_name_buf, &val_name_size1, NULL,
|
2002-04-12 01:58:40 +02:00
|
|
|
&value_type, *val_buf, &val_size1);
|
2008-12-01 11:06:32 +01:00
|
|
|
if (ret == ERROR_MORE_DATA) {
|
|
|
|
/* Increase the size of the buffers and retry */
|
|
|
|
REGPROC_resize_char_buffer(val_name_buf, val_name_size, val_name_size1);
|
|
|
|
REGPROC_resize_binary_buffer(val_buf, val_size, val_size1);
|
|
|
|
} else if (ret != ERROR_SUCCESS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
more_data = FALSE;
|
2003-12-08 23:48:07 +01:00
|
|
|
if (ret != ERROR_NO_MORE_ITEMS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
REGPROC_print_error();
|
|
|
|
}
|
|
|
|
} else {
|
2008-11-12 11:29:51 +01:00
|
|
|
DWORD line_len;
|
2002-04-12 01:58:40 +02:00
|
|
|
i++;
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
if ((*val_name_buf)[0]) {
|
2008-09-12 00:54:02 +02:00
|
|
|
const WCHAR val_start[] = {'"','%','s','"','=',0};
|
|
|
|
|
2010-06-07 23:07:48 +02:00
|
|
|
line_len = 0;
|
|
|
|
REGPROC_export_string(line_buf, line_buf_size, &line_len, *val_name_buf, lstrlenW(*val_name_buf));
|
|
|
|
REGPROC_resize_char_buffer(val_name_buf, val_name_size, lstrlenW(*line_buf) + 1);
|
|
|
|
lstrcpyW(*val_name_buf, *line_buf);
|
|
|
|
|
2008-11-12 11:29:51 +01:00
|
|
|
line_len = 3 + lstrlenW(*val_name_buf);
|
2008-11-12 11:15:26 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len);
|
2008-11-20 20:45:12 +01:00
|
|
|
sprintfW(*line_buf, val_start, *val_name_buf);
|
2002-04-12 01:58:40 +02:00
|
|
|
} else {
|
2008-09-12 00:54:02 +02:00
|
|
|
const WCHAR std_val[] = {'@','=',0};
|
2008-11-12 11:29:51 +01:00
|
|
|
line_len = 2;
|
2008-11-12 11:15:26 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len);
|
2008-09-12 00:54:02 +02:00
|
|
|
lstrcpyW(*line_buf, std_val);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
switch (value_type) {
|
2002-04-12 01:58:40 +02:00
|
|
|
case REG_SZ:
|
2008-09-12 00:54:02 +02:00
|
|
|
{
|
2008-11-20 20:43:25 +01:00
|
|
|
WCHAR* wstr = (WCHAR*)*val_buf;
|
|
|
|
|
|
|
|
if (val_size1 < sizeof(WCHAR) || val_size1 % sizeof(WCHAR) ||
|
|
|
|
wstr[val_size1 / sizeof(WCHAR) - 1]) {
|
|
|
|
REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode);
|
|
|
|
} else {
|
|
|
|
const WCHAR start[] = {'"',0};
|
2011-03-04 15:00:51 +01:00
|
|
|
const WCHAR end[] = {'"','\r','\n',0};
|
2008-11-20 20:43:25 +01:00
|
|
|
DWORD len;
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2008-11-20 20:43:25 +01:00
|
|
|
len = lstrlenW(start);
|
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len + len);
|
|
|
|
lstrcpyW(*line_buf + line_len, start);
|
|
|
|
line_len += len;
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2014-10-25 02:01:02 +02:00
|
|
|
REGPROC_export_string(line_buf, line_buf_size, &line_len, wstr, lstrlenW(wstr));
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2008-11-20 20:43:25 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len + lstrlenW(end));
|
|
|
|
lstrcpyW(*line_buf + line_len, end);
|
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
break;
|
2008-09-12 00:54:02 +02:00
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
case REG_DWORD:
|
2008-09-12 00:54:02 +02:00
|
|
|
{
|
2011-03-04 15:00:51 +01:00
|
|
|
WCHAR format[] = {'d','w','o','r','d',':','%','0','8','x','\r','\n',0};
|
2008-09-12 00:54:02 +02:00
|
|
|
|
2008-11-12 11:29:51 +01:00
|
|
|
REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len + 15);
|
2008-11-20 20:45:12 +01:00
|
|
|
sprintfW(*line_buf + line_len, format, *((DWORD *)*val_buf));
|
2002-04-12 01:58:40 +02:00
|
|
|
break;
|
2008-09-12 00:54:02 +02:00
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
default:
|
2008-09-21 23:26:32 +02:00
|
|
|
{
|
2016-07-21 12:57:01 +02:00
|
|
|
output_message(STRING_UNSUPPORTED_TYPE, reg_type_to_wchar(value_type), *reg_key_name_buf);
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_EXPORT_AS_BINARY, *val_name_buf);
|
2008-09-21 23:26:32 +02:00
|
|
|
}
|
2002-06-28 19:33:09 +02:00
|
|
|
/* falls through */
|
2008-11-20 20:43:25 +01:00
|
|
|
case REG_EXPAND_SZ:
|
2002-06-28 19:33:09 +02:00
|
|
|
case REG_MULTI_SZ:
|
|
|
|
/* falls through */
|
2008-11-20 20:43:25 +01:00
|
|
|
case REG_BINARY:
|
|
|
|
REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2008-09-14 02:21:23 +02:00
|
|
|
REGPROC_write_line(file, *line_buf, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
i = 0;
|
|
|
|
more_data = TRUE;
|
|
|
|
(*reg_key_name_buf)[curr_len] = '\\';
|
2003-12-08 23:48:07 +01:00
|
|
|
while(more_data) {
|
2008-11-12 11:28:49 +01:00
|
|
|
DWORD buf_size = *reg_key_name_size - curr_len - 1;
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2008-11-12 11:28:49 +01:00
|
|
|
ret = RegEnumKeyExW(key, i, *reg_key_name_buf + curr_len + 1, &buf_size,
|
2002-04-12 01:58:40 +02:00
|
|
|
NULL, NULL, NULL, NULL);
|
2008-12-01 11:06:32 +01:00
|
|
|
if (ret == ERROR_MORE_DATA) {
|
|
|
|
/* Increase the size of the buffer and retry */
|
|
|
|
REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size, curr_len + 1 + buf_size);
|
|
|
|
} else if (ret != ERROR_SUCCESS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
more_data = FALSE;
|
2003-12-08 23:48:07 +01:00
|
|
|
if (ret != ERROR_NO_MORE_ITEMS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
REGPROC_print_error();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HKEY subkey;
|
|
|
|
|
|
|
|
i++;
|
2008-09-08 21:44:08 +02:00
|
|
|
if (RegOpenKeyW(key, *reg_key_name_buf + curr_len + 1,
|
2003-12-08 23:48:07 +01:00
|
|
|
&subkey) == ERROR_SUCCESS) {
|
2008-11-12 11:28:49 +01:00
|
|
|
export_hkey(file, subkey, reg_key_name_buf, reg_key_name_size,
|
|
|
|
val_name_buf, val_name_size, val_buf, val_size,
|
2008-09-14 02:21:23 +02:00
|
|
|
line_buf, line_buf_size, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
RegCloseKey(subkey);
|
|
|
|
} else {
|
|
|
|
REGPROC_print_error();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*reg_key_name_buf)[curr_len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2011-03-04 15:00:51 +01:00
|
|
|
* Open file in binary mode for export.
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2008-09-14 02:21:23 +02:00
|
|
|
static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2007-10-09 21:04:36 +02:00
|
|
|
FILE *file;
|
2008-09-08 21:44:08 +02:00
|
|
|
WCHAR dash = '-';
|
2007-10-09 21:04:36 +02:00
|
|
|
|
2011-03-04 15:00:51 +01:00
|
|
|
if (strncmpW(file_name,&dash,1)==0) {
|
2007-10-09 21:04:36 +02:00
|
|
|
file=stdout;
|
2011-03-04 15:00:51 +01:00
|
|
|
_setmode(_fileno(file), _O_BINARY);
|
|
|
|
} else
|
2007-10-09 21:04:36 +02:00
|
|
|
{
|
2016-07-15 09:50:06 +02:00
|
|
|
WCHAR wb_mode[] = {'w','b',0};
|
|
|
|
WCHAR regedit[] = {'r','e','g','e','d','i','t',0};
|
|
|
|
|
|
|
|
file = _wfopen(file_name, wb_mode);
|
2007-10-09 21:04:36 +02:00
|
|
|
if (!file) {
|
2016-07-15 09:50:06 +02:00
|
|
|
_wperror(regedit);
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_CANNOT_OPEN_FILE, file_name);
|
2007-10-09 21:04:36 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2008-09-14 02:21:23 +02:00
|
|
|
if(unicode)
|
|
|
|
{
|
|
|
|
const BYTE unicode_seq[] = {0xff,0xfe};
|
2011-03-04 15:00:51 +01:00
|
|
|
const WCHAR header[] = {'W','i','n','d','o','w','s',' ','R','e','g','i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s','i','o','n',' ','5','.','0','0','\r','\n'};
|
2008-09-14 02:21:23 +02:00
|
|
|
fwrite(unicode_seq, sizeof(BYTE), sizeof(unicode_seq)/sizeof(unicode_seq[0]), file);
|
|
|
|
fwrite(header, sizeof(WCHAR), sizeof(header)/sizeof(header[0]), file);
|
|
|
|
} else
|
|
|
|
{
|
2011-03-04 15:00:51 +01:00
|
|
|
fputs("REGEDIT4\r\n", file);
|
2008-09-14 02:21:23 +02:00
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Writes contents of the registry key to the specified file stream.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* file_name - name of a file to export registry branch to.
|
|
|
|
* reg_key_name - registry branch to export. The whole registry is exported if
|
|
|
|
* reg_key_name is NULL or contains an empty string.
|
|
|
|
*/
|
2008-09-14 02:21:23 +02:00
|
|
|
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2008-09-08 21:44:08 +02:00
|
|
|
WCHAR *reg_key_name_buf;
|
|
|
|
WCHAR *val_name_buf;
|
2002-04-12 01:58:40 +02:00
|
|
|
BYTE *val_buf;
|
2008-09-12 00:54:02 +02:00
|
|
|
WCHAR *line_buf;
|
2008-11-12 11:28:49 +01:00
|
|
|
DWORD reg_key_name_size = KEY_MAX_LEN;
|
|
|
|
DWORD val_name_size = KEY_MAX_LEN;
|
2002-04-12 01:58:40 +02:00
|
|
|
DWORD val_size = REG_VAL_BUF_SIZE;
|
2008-09-12 00:54:02 +02:00
|
|
|
DWORD line_buf_size = KEY_MAX_LEN + REG_VAL_BUF_SIZE;
|
2002-04-12 01:58:40 +02:00
|
|
|
FILE *file = NULL;
|
2008-09-14 02:21:23 +02:00
|
|
|
BOOL unicode = (format == REG_FORMAT_5);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
reg_key_name_buf = HeapAlloc(GetProcessHeap(), 0,
|
2008-11-12 11:28:49 +01:00
|
|
|
reg_key_name_size * sizeof(*reg_key_name_buf));
|
2002-04-12 01:58:40 +02:00
|
|
|
val_name_buf = HeapAlloc(GetProcessHeap(), 0,
|
2008-11-12 11:28:49 +01:00
|
|
|
val_name_size * sizeof(*val_name_buf));
|
2002-04-12 01:58:40 +02:00
|
|
|
val_buf = HeapAlloc(GetProcessHeap(), 0, val_size);
|
2008-11-20 20:41:04 +01:00
|
|
|
line_buf = HeapAlloc(GetProcessHeap(), 0, line_buf_size * sizeof(*line_buf));
|
2008-11-12 11:10:29 +01:00
|
|
|
CHECK_ENOUGH_MEMORY(reg_key_name_buf && val_name_buf && val_buf && line_buf);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
if (reg_key_name && reg_key_name[0]) {
|
2007-06-15 18:59:55 +02:00
|
|
|
HKEY reg_key_class;
|
2008-09-08 21:44:08 +02:00
|
|
|
WCHAR *branch_name = NULL;
|
2002-04-12 01:58:40 +02:00
|
|
|
HKEY key;
|
|
|
|
|
2008-11-12 11:28:49 +01:00
|
|
|
REGPROC_resize_char_buffer(®_key_name_buf, ®_key_name_size,
|
2008-09-08 21:44:08 +02:00
|
|
|
lstrlenW(reg_key_name));
|
|
|
|
lstrcpyW(reg_key_name_buf, reg_key_name);
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
/* open the specified key */
|
2007-06-15 18:59:55 +02:00
|
|
|
if (!parseKeyName(reg_key_name, ®_key_class, &branch_name)) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_INCORRECT_REG_CLASS, reg_key_name);
|
2002-04-12 01:58:40 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
if (!branch_name[0]) {
|
2002-04-12 01:58:40 +02:00
|
|
|
/* no branch - registry class is specified */
|
2008-09-14 02:21:23 +02:00
|
|
|
file = REGPROC_open_export_file(file_name, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
export_hkey(file, reg_key_class,
|
2008-11-12 11:28:49 +01:00
|
|
|
®_key_name_buf, ®_key_name_size,
|
|
|
|
&val_name_buf, &val_name_size,
|
2008-09-14 02:21:23 +02:00
|
|
|
&val_buf, &val_size, &line_buf,
|
|
|
|
&line_buf_size, unicode);
|
2008-09-08 21:44:08 +02:00
|
|
|
} else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS) {
|
2008-09-14 02:21:23 +02:00
|
|
|
file = REGPROC_open_export_file(file_name, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
export_hkey(file, key,
|
2008-11-12 11:28:49 +01:00
|
|
|
®_key_name_buf, ®_key_name_size,
|
|
|
|
&val_name_buf, &val_name_size,
|
2008-09-14 02:21:23 +02:00
|
|
|
&val_buf, &val_size, &line_buf,
|
|
|
|
&line_buf_size, unicode);
|
2002-04-12 01:58:40 +02:00
|
|
|
RegCloseKey(key);
|
|
|
|
} else {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_REG_KEY_NOT_FOUND, reg_key_name);
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
/* export all registry classes */
|
2008-09-14 02:21:23 +02:00
|
|
|
file = REGPROC_open_export_file(file_name, unicode);
|
2016-07-21 07:48:43 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++) {
|
2002-06-28 19:33:09 +02:00
|
|
|
/* do not export HKEY_CLASSES_ROOT */
|
|
|
|
if (reg_class_keys[i] != HKEY_CLASSES_ROOT &&
|
2003-12-08 23:48:07 +01:00
|
|
|
reg_class_keys[i] != HKEY_CURRENT_USER &&
|
2004-07-08 22:14:10 +02:00
|
|
|
reg_class_keys[i] != HKEY_CURRENT_CONFIG &&
|
|
|
|
reg_class_keys[i] != HKEY_DYN_DATA) {
|
2008-09-08 21:44:08 +02:00
|
|
|
lstrcpyW(reg_key_name_buf, reg_class_namesW[i]);
|
2002-06-28 19:33:09 +02:00
|
|
|
export_hkey(file, reg_class_keys[i],
|
2008-11-12 11:28:49 +01:00
|
|
|
®_key_name_buf, ®_key_name_size,
|
|
|
|
&val_name_buf, &val_name_size,
|
2008-09-14 02:21:23 +02:00
|
|
|
&val_buf, &val_size, &line_buf,
|
|
|
|
&line_buf_size, unicode);
|
2002-06-28 19:33:09 +02:00
|
|
|
}
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:48:07 +01:00
|
|
|
if (file) {
|
2002-04-12 01:58:40 +02:00
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, reg_key_name);
|
2008-09-03 17:44:48 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, val_name_buf);
|
2002-04-12 01:58:40 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, val_buf);
|
2008-09-12 00:54:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, line_buf);
|
2003-08-07 05:10:13 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Reads contents of the specified file into the registry.
|
|
|
|
*/
|
2008-07-09 23:39:08 +02:00
|
|
|
BOOL import_registry_file(FILE* reg_file)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2008-07-09 23:39:08 +02:00
|
|
|
if (reg_file)
|
|
|
|
{
|
|
|
|
BYTE s[2];
|
|
|
|
if (fread( s, 2, 1, reg_file) == 1)
|
|
|
|
{
|
|
|
|
if (s[0] == 0xff && s[1] == 0xfe)
|
|
|
|
{
|
|
|
|
processRegLinesW(reg_file);
|
|
|
|
} else
|
|
|
|
{
|
2009-06-16 15:46:33 +02:00
|
|
|
processRegLinesA(reg_file, (char*)s);
|
2008-07-09 23:39:08 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-07 05:10:13 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Removes the registry key with all subkeys. Parses full key name.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* reg_key_name - full name of registry branch to delete. Ignored if is NULL,
|
|
|
|
* empty, points to register key class, does not exist.
|
|
|
|
*/
|
2008-07-09 18:18:14 +02:00
|
|
|
void delete_registry_key(WCHAR *reg_key_name)
|
2008-07-07 23:12:21 +02:00
|
|
|
{
|
|
|
|
WCHAR *key_name = NULL;
|
|
|
|
HKEY key_class;
|
|
|
|
|
|
|
|
if (!reg_key_name || !reg_key_name[0])
|
|
|
|
return;
|
|
|
|
|
2008-09-08 21:44:08 +02:00
|
|
|
if (!parseKeyName(reg_key_name, &key_class, &key_name)) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_INCORRECT_REG_CLASS, reg_key_name);
|
2008-07-07 23:12:21 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!*key_name) {
|
2016-07-15 09:49:48 +02:00
|
|
|
output_message(STRING_DELETE_REG_CLASS_FAILED, reg_key_name);
|
2008-07-07 23:12:21 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegDeleteTreeW(key_class, key_name);
|
|
|
|
}
|