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
|
|
|
*/
|
|
|
|
|
2017-06-21 14:18:53 +02:00
|
|
|
#include <errno.h>
|
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"
|
|
|
|
|
|
|
|
#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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
static WCHAR *(*get_line)(FILE *);
|
|
|
|
|
|
|
|
/* parser definitions */
|
|
|
|
enum parser_state
|
|
|
|
{
|
|
|
|
HEADER, /* parsing the registry file version header */
|
|
|
|
PARSE_WIN31_LINE, /* parsing a Windows 3.1 registry line */
|
|
|
|
LINE_START, /* at the beginning of a registry line */
|
2017-06-15 14:00:55 +02:00
|
|
|
KEY_NAME, /* parsing a key name */
|
|
|
|
DELETE_KEY, /* deleting a registry key */
|
2017-06-15 14:01:26 +02:00
|
|
|
DEFAULT_VALUE_NAME, /* parsing a default value name */
|
|
|
|
QUOTED_VALUE_NAME, /* parsing a double-quoted value name */
|
|
|
|
DATA_START, /* preparing for data parsing operations */
|
|
|
|
DELETE_VALUE, /* deleting a registry value */
|
2017-06-15 14:01:47 +02:00
|
|
|
DATA_TYPE, /* parsing the registry data type */
|
|
|
|
STRING_DATA, /* parsing REG_SZ data */
|
|
|
|
DWORD_DATA, /* parsing DWORD data */
|
|
|
|
HEX_DATA, /* parsing REG_BINARY, REG_NONE, REG_EXPAND_SZ or REG_MULTI_SZ data */
|
2017-06-30 15:42:55 +02:00
|
|
|
EOL_BACKSLASH, /* preparing to parse multiple lines of hex data */
|
|
|
|
HEX_MULTILINE, /* parsing multiple lines of hex data */
|
2017-06-15 14:01:47 +02:00
|
|
|
UNKNOWN_DATA, /* parsing an unhandled or invalid data type */
|
2017-06-15 14:00:31 +02:00
|
|
|
SET_VALUE, /* adding a value to the registry */
|
|
|
|
NB_PARSER_STATES
|
|
|
|
};
|
|
|
|
|
|
|
|
struct parser
|
|
|
|
{
|
|
|
|
FILE *file; /* pointer to a registry file */
|
|
|
|
WCHAR two_wchars[2]; /* first two characters from the encoding check */
|
|
|
|
BOOL is_unicode; /* parsing Unicode or ASCII data */
|
|
|
|
short int reg_version; /* registry file version */
|
2017-06-15 14:01:47 +02:00
|
|
|
HKEY hkey; /* current registry key */
|
|
|
|
WCHAR *key_name; /* current key name */
|
2017-06-15 14:00:31 +02:00
|
|
|
WCHAR *value_name; /* value name */
|
2017-06-20 15:25:32 +02:00
|
|
|
DWORD parse_type; /* generic data type for parsing */
|
2017-06-15 14:00:31 +02:00
|
|
|
DWORD data_type; /* data type */
|
|
|
|
void *data; /* value data */
|
|
|
|
DWORD data_size; /* size of the data (in bytes) */
|
2017-06-30 15:42:55 +02:00
|
|
|
BOOL backslash; /* TRUE if the current line contains a backslash */
|
2017-06-15 14:00:31 +02:00
|
|
|
enum parser_state state; /* current parser state */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef WCHAR *(*parser_state_func)(struct parser *parser, WCHAR *pos);
|
|
|
|
|
|
|
|
/* parser state machine functions */
|
|
|
|
static WCHAR *header_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *parse_win31_line_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *line_start_state(struct parser *parser, WCHAR *pos);
|
2017-06-15 14:00:55 +02:00
|
|
|
static WCHAR *key_name_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *delete_key_state(struct parser *parser, WCHAR *pos);
|
2017-06-15 14:01:26 +02:00
|
|
|
static WCHAR *default_value_name_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *quoted_value_name_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *data_start_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *delete_value_state(struct parser *parser, WCHAR *pos);
|
2017-06-15 14:01:47 +02:00
|
|
|
static WCHAR *data_type_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *string_data_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *dword_data_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *hex_data_state(struct parser *parser, WCHAR *pos);
|
2017-06-30 15:42:55 +02:00
|
|
|
static WCHAR *eol_backslash_state(struct parser *parser, WCHAR *pos);
|
|
|
|
static WCHAR *hex_multiline_state(struct parser *parser, WCHAR *pos);
|
2017-06-15 14:01:47 +02:00
|
|
|
static WCHAR *unknown_data_state(struct parser *parser, WCHAR *pos);
|
2017-06-15 14:00:31 +02:00
|
|
|
static WCHAR *set_value_state(struct parser *parser, WCHAR *pos);
|
|
|
|
|
|
|
|
static const parser_state_func parser_funcs[NB_PARSER_STATES] =
|
|
|
|
{
|
|
|
|
header_state, /* HEADER */
|
|
|
|
parse_win31_line_state, /* PARSE_WIN31_LINE */
|
|
|
|
line_start_state, /* LINE_START */
|
2017-06-15 14:00:55 +02:00
|
|
|
key_name_state, /* KEY_NAME */
|
|
|
|
delete_key_state, /* DELETE_KEY */
|
2017-06-15 14:01:26 +02:00
|
|
|
default_value_name_state, /* DEFAULT_VALUE_NAME */
|
|
|
|
quoted_value_name_state, /* QUOTED_VALUE_NAME */
|
|
|
|
data_start_state, /* DATA_START */
|
|
|
|
delete_value_state, /* DELETE_VALUE */
|
2017-06-15 14:01:47 +02:00
|
|
|
data_type_state, /* DATA_TYPE */
|
|
|
|
string_data_state, /* STRING_DATA */
|
|
|
|
dword_data_state, /* DWORD_DATA */
|
|
|
|
hex_data_state, /* HEX_DATA */
|
2017-06-30 15:42:55 +02:00
|
|
|
eol_backslash_state, /* EOL_BACKSLASH */
|
|
|
|
hex_multiline_state, /* HEX_MULTILINE */
|
2017-06-15 14:01:47 +02:00
|
|
|
unknown_data_state, /* UNKNOWN_DATA */
|
2017-06-15 14:00:31 +02:00
|
|
|
set_value_state, /* SET_VALUE */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* set the new parser state and return the previous one */
|
|
|
|
static inline enum parser_state set_state(struct parser *parser, enum parser_state state)
|
|
|
|
{
|
|
|
|
enum parser_state ret = parser->state;
|
|
|
|
parser->state = state;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
static void *resize_buffer(void *buf, size_t count)
|
|
|
|
{
|
|
|
|
void *new_buf;
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, count);
|
|
|
|
else
|
|
|
|
new_buf = HeapAlloc(GetProcessHeap(), 0, count);
|
|
|
|
|
|
|
|
CHECK_ENOUGH_MEMORY(new_buf);
|
|
|
|
return new_buf;
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Converts a hex representation of a DWORD into a DWORD.
|
|
|
|
*/
|
2017-06-15 14:01:47 +02:00
|
|
|
static BOOL convert_hex_to_dword(WCHAR *str, DWORD *dw)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2017-04-11 15:11:54 +02:00
|
|
|
WCHAR *p, *end;
|
|
|
|
int count = 0;
|
2008-07-09 20:59:01 +02:00
|
|
|
|
2017-04-11 15:11:54 +02:00
|
|
|
while (*str == ' ' || *str == '\t') str++;
|
|
|
|
if (!*str) goto error;
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
while (isxdigitW(*p))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
p++;
|
2007-06-14 11:46:29 +02:00
|
|
|
}
|
2017-04-11 15:11:54 +02:00
|
|
|
if (count > 8) goto error;
|
|
|
|
|
|
|
|
end = p;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
if (*p && *p != ';') goto error;
|
|
|
|
|
|
|
|
*end = 0;
|
|
|
|
*dw = strtoulW(str, &end, 16);
|
2007-06-14 11:46:29 +02:00
|
|
|
return TRUE;
|
2017-04-11 15:11:54 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
return FALSE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2017-06-30 15:42:55 +02:00
|
|
|
* Converts comma-separated hex data into a binary string and modifies
|
|
|
|
* the input parameter to skip the concatenating backslash, if found.
|
|
|
|
*
|
|
|
|
* Returns TRUE or FALSE to indicate whether parsing was successful.
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2017-06-30 15:42:55 +02:00
|
|
|
static BOOL convert_hex_csv_to_hex(struct parser *parser, WCHAR **str)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2017-06-30 15:42:55 +02:00
|
|
|
size_t size;
|
|
|
|
BYTE *d;
|
2008-08-27 23:29:08 +02:00
|
|
|
WCHAR *s;
|
2017-06-30 15:42:55 +02:00
|
|
|
|
|
|
|
parser->backslash = FALSE;
|
2007-06-14 11:46:29 +02:00
|
|
|
|
|
|
|
/* The worst case is 1 digit + 1 comma per byte */
|
2017-06-30 15:42:55 +02:00
|
|
|
size = ((lstrlenW(*str) + 1) / 2) + parser->data_size;
|
|
|
|
parser->data = resize_buffer(parser->data, size);
|
|
|
|
|
|
|
|
s = *str;
|
|
|
|
d = (BYTE *)parser->data + parser->data_size;
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
{
|
2008-08-27 23:29:08 +02:00
|
|
|
WCHAR *end;
|
2017-06-30 15:42:55 +02:00
|
|
|
unsigned long wc;
|
|
|
|
|
|
|
|
wc = strtoulW(s, &end, 16);
|
|
|
|
if (wc > 0xff) return FALSE;
|
|
|
|
|
|
|
|
if (s == end && wc == 0)
|
|
|
|
{
|
|
|
|
while (*end == ' ' || *end == '\t') end++;
|
|
|
|
if (*end == '\\')
|
|
|
|
{
|
|
|
|
parser->backslash = TRUE;
|
|
|
|
*str = end + 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
*d++ = wc;
|
|
|
|
parser->data_size++;
|
|
|
|
|
|
|
|
if (*end && *end != ',')
|
|
|
|
{
|
|
|
|
while (*end == ' ' || *end == '\t') end++;
|
|
|
|
if (*end && *end != ';') return FALSE;
|
|
|
|
return TRUE;
|
2007-06-14 11:46:29 +02:00
|
|
|
}
|
2017-06-30 15:42:55 +02:00
|
|
|
|
2008-01-07 19:56:15 +01:00
|
|
|
if (*end) end++;
|
|
|
|
s = end;
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
return TRUE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2017-06-15 14:01:47 +02:00
|
|
|
* Parses the data type of the registry value being imported and modifies
|
|
|
|
* the input parameter to skip the string representation of the data type.
|
2002-04-12 01:58:40 +02:00
|
|
|
*
|
2017-06-15 14:01:47 +02:00
|
|
|
* Returns TRUE or FALSE to indicate whether a data type was found.
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2017-06-15 14:01:47 +02:00
|
|
|
static BOOL parse_data_type(struct parser *parser, WCHAR **line)
|
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 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
|
|
|
|
2017-03-29 07:25:31 +02:00
|
|
|
static const struct data_type data_types[] = {
|
|
|
|
/* tag len type parse type */
|
|
|
|
{ quote, 1, REG_SZ, REG_SZ },
|
|
|
|
{ hex, 4, REG_BINARY, REG_BINARY },
|
|
|
|
{ dword, 6, REG_DWORD, REG_DWORD },
|
|
|
|
{ hexp, 4, -1, REG_BINARY }, /* REG_NONE, REG_EXPAND_SZ, REG_MULTI_SZ */
|
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
};
|
2002-04-12 01:58:40 +02:00
|
|
|
|
|
|
|
const struct data_type *ptr;
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
for (ptr = data_types; ptr->tag; ptr++)
|
|
|
|
{
|
|
|
|
if (strncmpW(ptr->tag, *line, ptr->len))
|
2002-04-12 01:58:40 +02:00
|
|
|
continue;
|
|
|
|
|
2017-06-20 15:25:32 +02:00
|
|
|
parser->parse_type = ptr->parse_type;
|
2017-06-15 14:01:47 +02:00
|
|
|
parser->data_type = ptr->parse_type;
|
|
|
|
*line += ptr->len;
|
|
|
|
|
|
|
|
if (ptr->type == -1)
|
|
|
|
{
|
|
|
|
WCHAR *end;
|
|
|
|
DWORD val;
|
2008-07-09 20:59:01 +02:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/* "hex(xx):" is special */
|
2017-06-21 14:18:53 +02:00
|
|
|
val = wcstoul(*line, &end, 16);
|
|
|
|
if (!**line || *end != ')' || *(end + 1) != ':' || (val == ~0u && errno == ERANGE))
|
2017-06-15 14:01:47 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
parser->data_type = val;
|
|
|
|
*line = end + 2;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2017-06-15 14:01:47 +02:00
|
|
|
return TRUE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2017-06-15 14:01:47 +02:00
|
|
|
return FALSE;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2017-04-25 15:31:10 +02:00
|
|
|
* Replaces escape sequences with their character equivalents and
|
|
|
|
* null-terminates the string on the first non-escaped double quote.
|
|
|
|
*
|
|
|
|
* Assigns a pointer to the remaining unparsed data in the line.
|
|
|
|
* Returns TRUE or FALSE to indicate whether a closing double quote was found.
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2017-04-25 15:31:10 +02:00
|
|
|
static BOOL REGPROC_unescape_string(WCHAR *str, WCHAR **unparsed)
|
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);
|
2017-04-25 15:31:10 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
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;
|
|
|
|
}
|
2017-04-25 15:31:10 +02:00
|
|
|
} else if (str[str_idx] == '"') {
|
|
|
|
break;
|
2002-04-12 01:58:40 +02:00
|
|
|
} else {
|
|
|
|
str[val_idx] = str[str_idx];
|
|
|
|
}
|
|
|
|
}
|
2017-04-25 15:31:10 +02:00
|
|
|
|
|
|
|
ret = (str[str_idx] == '"');
|
|
|
|
*unparsed = str + str_idx + 1;
|
2002-04-12 01:58:40 +02:00
|
|
|
str[val_idx] = '\0';
|
2017-04-25 15:31:10 +02:00
|
|
|
return ret;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
static HKEY parse_key_name(WCHAR *key_name, WCHAR **key_path)
|
2008-07-07 23:12:21 +02:00
|
|
|
{
|
2017-04-25 15:30:56 +02:00
|
|
|
unsigned int i;
|
2008-07-07 23:12:21 +02:00
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
if (!key_name) return 0;
|
2008-07-07 23:12:21 +02:00
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
*key_path = strchrW(key_name, '\\');
|
|
|
|
if (*key_path) (*key_path)++;
|
2008-07-07 23:12:21 +02:00
|
|
|
|
2017-04-25 15:30:56 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(reg_class_keys); i++)
|
2008-07-07 23:12:21 +02:00
|
|
|
{
|
2017-04-25 15:30:56 +02:00
|
|
|
int len = lstrlenW(reg_class_namesW[i]);
|
2017-06-16 15:06:31 +02:00
|
|
|
if (!strncmpiW(key_name, reg_class_namesW[i], len) &&
|
2017-06-15 14:00:55 +02:00
|
|
|
(key_name[len] == 0 || key_name[len] == '\\'))
|
2017-04-25 15:30:56 +02:00
|
|
|
{
|
|
|
|
return reg_class_keys[i];
|
2008-07-07 23:12:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 15:30:56 +02:00
|
|
|
return 0;
|
2008-07-07 23:12:21 +02:00
|
|
|
}
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
static void close_key(struct parser *parser)
|
2017-06-15 14:00:55 +02:00
|
|
|
{
|
2017-06-15 14:01:47 +02:00
|
|
|
if (parser->hkey)
|
2017-06-15 14:00:55 +02:00
|
|
|
{
|
2017-06-15 14:01:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, parser->key_name);
|
|
|
|
parser->key_name = NULL;
|
2017-06-15 14:00:55 +02:00
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
RegCloseKey(parser->hkey);
|
|
|
|
parser->hkey = NULL;
|
2017-06-15 14:00:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
2017-06-15 14:00:55 +02:00
|
|
|
* Opens the registry key given by the input path.
|
|
|
|
* This key must be closed by calling close_key().
|
2002-04-12 01:58:40 +02:00
|
|
|
*/
|
2017-06-15 14:01:47 +02:00
|
|
|
static LONG open_key(struct parser *parser, WCHAR *path)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2017-06-15 14:00:55 +02:00
|
|
|
HKEY key_class;
|
|
|
|
WCHAR *key_path;
|
2007-06-14 11:46:46 +02:00
|
|
|
LONG res;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
close_key(parser);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2007-06-14 11:42:41 +02:00
|
|
|
/* Get the registry class */
|
2017-06-15 14:01:47 +02:00
|
|
|
if (!path || !(key_class = parse_key_name(path, &key_path)))
|
2007-06-14 11:42:41 +02:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2003-12-08 23:48:07 +01:00
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
res = RegCreateKeyExW(key_class, key_path, 0, NULL, REG_OPTION_NON_VOLATILE,
|
2017-06-15 14:01:47 +02:00
|
|
|
KEY_ALL_ACCESS, NULL, &parser->hkey, NULL);
|
2007-06-14 11:42:41 +02:00
|
|
|
|
2007-06-14 11:46:46 +02:00
|
|
|
if (res == ERROR_SUCCESS)
|
2016-07-15 09:50:16 +02:00
|
|
|
{
|
2017-06-15 14:01:47 +02:00
|
|
|
parser->key_name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(path) + 1) * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(parser->key_name);
|
|
|
|
lstrcpyW(parser->key_name, path);
|
2016-07-15 09:50:16 +02:00
|
|
|
}
|
2007-06-15 18:59:55 +02:00
|
|
|
else
|
2017-06-15 14:01:47 +02:00
|
|
|
parser->hkey = 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
|
|
|
}
|
|
|
|
|
2017-03-22 12:53:53 +01:00
|
|
|
enum reg_versions {
|
|
|
|
REG_VERSION_31,
|
|
|
|
REG_VERSION_40,
|
|
|
|
REG_VERSION_50,
|
2017-03-22 12:54:28 +01:00
|
|
|
REG_VERSION_FUZZY,
|
2017-03-22 12:53:53 +01:00
|
|
|
REG_VERSION_INVALID
|
|
|
|
};
|
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
static enum reg_versions parse_file_header(const WCHAR *s)
|
2017-03-22 12:53:53 +01:00
|
|
|
{
|
|
|
|
static const WCHAR header_31[] = {'R','E','G','E','D','I','T',0};
|
|
|
|
static const WCHAR header_40[] = {'R','E','G','E','D','I','T','4',0};
|
|
|
|
static const WCHAR header_50[] = {'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',0};
|
|
|
|
|
2017-07-04 14:46:09 +02:00
|
|
|
while (*s == ' ' || *s == '\t') s++;
|
2017-01-30 05:09:27 +01:00
|
|
|
|
2017-03-22 12:53:53 +01:00
|
|
|
if (!strcmpW(s, header_31))
|
|
|
|
return REG_VERSION_31;
|
|
|
|
|
|
|
|
if (!strcmpW(s, header_40))
|
|
|
|
return REG_VERSION_40;
|
|
|
|
|
|
|
|
if (!strcmpW(s, header_50))
|
|
|
|
return REG_VERSION_50;
|
|
|
|
|
2017-03-22 12:54:28 +01:00
|
|
|
/* The Windows version accepts registry file headers beginning with "REGEDIT" and ending
|
|
|
|
* with other characters, as long as "REGEDIT" appears at the start of the line. For example,
|
|
|
|
* "REGEDIT 4", "REGEDIT9" and "REGEDIT4FOO" are all treated as valid file headers.
|
|
|
|
* In all such cases, however, the contents of the registry file are not imported.
|
|
|
|
*/
|
|
|
|
if (!strncmpW(s, header_31, 7)) /* "REGEDIT" without NUL */
|
|
|
|
return REG_VERSION_FUZZY;
|
|
|
|
|
2017-03-22 12:53:53 +01:00
|
|
|
return REG_VERSION_INVALID;
|
|
|
|
}
|
2017-01-30 05:09:27 +01:00
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
/* handler for parser HEADER state */
|
|
|
|
static WCHAR *header_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line, *header;
|
|
|
|
|
|
|
|
if (!(line = get_line(parser->file)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!parser->is_unicode)
|
|
|
|
{
|
|
|
|
header = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(line) + 3) * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(header);
|
|
|
|
header[0] = parser->two_wchars[0];
|
|
|
|
header[1] = parser->two_wchars[1];
|
|
|
|
lstrcpyW(header + 2, line);
|
|
|
|
parser->reg_version = parse_file_header(header);
|
|
|
|
HeapFree(GetProcessHeap(), 0, header);
|
|
|
|
}
|
|
|
|
else parser->reg_version = parse_file_header(line);
|
|
|
|
|
|
|
|
switch (parser->reg_version)
|
|
|
|
{
|
|
|
|
case REG_VERSION_31:
|
|
|
|
set_state(parser, PARSE_WIN31_LINE);
|
|
|
|
break;
|
|
|
|
case REG_VERSION_40:
|
|
|
|
case REG_VERSION_50:
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
get_line(NULL); /* Reset static variables */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser PARSE_WIN31_LINE state */
|
|
|
|
static WCHAR *parse_win31_line_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line, *value;
|
|
|
|
static WCHAR hkcr[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T'};
|
|
|
|
unsigned int key_end = 0;
|
|
|
|
|
|
|
|
if (!(line = get_line(parser->file)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (strncmpW(line, hkcr, ARRAY_SIZE(hkcr)))
|
2017-06-30 15:42:43 +02:00
|
|
|
return line;
|
2017-06-15 14:00:31 +02:00
|
|
|
|
|
|
|
/* get key name */
|
|
|
|
while (line[key_end] && !isspaceW(line[key_end])) key_end++;
|
|
|
|
|
|
|
|
value = line + key_end;
|
|
|
|
while (*value == ' ' || *value == '\t') value++;
|
|
|
|
|
|
|
|
if (*value == '=') value++;
|
|
|
|
if (*value == ' ') value++; /* at most one space is skipped */
|
|
|
|
|
|
|
|
line[key_end] = 0;
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
if (open_key(parser, line) != ERROR_SUCCESS)
|
2017-06-15 14:00:31 +02:00
|
|
|
{
|
|
|
|
output_message(STRING_OPEN_KEY_FAILED, line);
|
2017-06-30 15:42:43 +02:00
|
|
|
return line;
|
2017-06-15 14:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parser->value_name = NULL;
|
|
|
|
parser->data_type = REG_SZ;
|
|
|
|
parser->data = value;
|
|
|
|
parser->data_size = (lstrlenW(value) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
set_state(parser, SET_VALUE);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser LINE_START state */
|
|
|
|
static WCHAR *line_start_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line, *p;
|
|
|
|
|
|
|
|
if (!(line = get_line(parser->file)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (p = line; *p; p++)
|
|
|
|
{
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case '[':
|
2017-06-15 14:00:55 +02:00
|
|
|
set_state(parser, KEY_NAME);
|
|
|
|
return p + 1;
|
2017-06-15 14:00:31 +02:00
|
|
|
case '@':
|
2017-06-15 14:01:26 +02:00
|
|
|
set_state(parser, DEFAULT_VALUE_NAME);
|
2017-06-15 14:00:55 +02:00
|
|
|
return p;
|
2017-06-15 14:01:26 +02:00
|
|
|
case '"':
|
|
|
|
set_state(parser, QUOTED_VALUE_NAME);
|
|
|
|
return p + 1;
|
2017-06-15 14:00:31 +02:00
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
/* handler for parser KEY_NAME state */
|
|
|
|
static WCHAR *key_name_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *p = pos, *key_end;
|
|
|
|
|
|
|
|
if (*p == ' ' || *p == '\t' || !(key_end = strrchrW(p, ']')))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
*key_end = 0;
|
|
|
|
|
|
|
|
if (*p == '-')
|
|
|
|
{
|
|
|
|
set_state(parser, DELETE_KEY);
|
|
|
|
return p + 1;
|
|
|
|
}
|
2017-06-15 14:01:47 +02:00
|
|
|
else if (open_key(parser, p) != ERROR_SUCCESS)
|
2017-06-15 14:00:55 +02:00
|
|
|
output_message(STRING_OPEN_KEY_FAILED, p);
|
|
|
|
|
|
|
|
done:
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser DELETE_KEY state */
|
|
|
|
static WCHAR *delete_key_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *p = pos;
|
|
|
|
|
2017-06-16 15:06:41 +02:00
|
|
|
if (*p == 'H' || *p == 'h')
|
2017-06-15 14:00:55 +02:00
|
|
|
delete_registry_key(p);
|
|
|
|
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:01:26 +02:00
|
|
|
/* handler for parser DEFAULT_VALUE_NAME state */
|
|
|
|
static WCHAR *default_value_name_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
parser->value_name = NULL;
|
|
|
|
|
|
|
|
set_state(parser, DATA_START);
|
|
|
|
return pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser QUOTED_VALUE_NAME state */
|
|
|
|
static WCHAR *quoted_value_name_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *val_name = pos, *p;
|
|
|
|
|
|
|
|
if (parser->value_name)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, parser->value_name);
|
|
|
|
parser->value_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!REGPROC_unescape_string(val_name, &p))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
/* copy the value name in case we need to parse multiple lines and the buffer is overwritten */
|
|
|
|
parser->value_name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(val_name) + 1) * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(parser->value_name);
|
|
|
|
lstrcpyW(parser->value_name, val_name);
|
|
|
|
|
|
|
|
set_state(parser, DATA_START);
|
|
|
|
return p;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser DATA_START state */
|
|
|
|
static WCHAR *data_start_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *p = pos;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
if (*p != '=') goto done;
|
|
|
|
p++;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
|
|
|
|
/* trim trailing whitespace */
|
|
|
|
len = strlenW(p);
|
|
|
|
while (len > 0 && (p[len - 1] == ' ' || p[len - 1] == '\t')) len--;
|
|
|
|
p[len] = 0;
|
|
|
|
|
|
|
|
if (*p == '-')
|
|
|
|
set_state(parser, DELETE_VALUE);
|
2017-06-15 14:01:47 +02:00
|
|
|
else
|
|
|
|
set_state(parser, DATA_TYPE);
|
|
|
|
return p;
|
2017-06-15 14:01:26 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser DELETE_VALUE state */
|
|
|
|
static WCHAR *delete_value_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *p = pos + 1;
|
|
|
|
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
if (*p && *p != ';') goto done;
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
RegDeleteValueW(parser->hkey, parser->value_name);
|
2017-06-15 14:01:26 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
/* handler for parser DATA_TYPE state */
|
|
|
|
static WCHAR *data_type_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line = pos;
|
|
|
|
|
|
|
|
if (!parse_data_type(parser, &line))
|
|
|
|
{
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2017-06-20 15:25:32 +02:00
|
|
|
switch (parser->parse_type)
|
2017-06-15 14:01:47 +02:00
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
set_state(parser, STRING_DATA);
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
set_state(parser, DWORD_DATA);
|
|
|
|
break;
|
2017-06-20 15:25:32 +02:00
|
|
|
case REG_BINARY: /* all hex data types, including undefined */
|
2017-06-15 14:01:47 +02:00
|
|
|
set_state(parser, HEX_DATA);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
set_state(parser, UNKNOWN_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser STRING_DATA state */
|
|
|
|
static WCHAR *string_data_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line;
|
|
|
|
|
|
|
|
parser->data = pos;
|
|
|
|
|
|
|
|
if (!REGPROC_unescape_string(parser->data, &line))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
while (*line == ' ' || *line == '\t') line++;
|
|
|
|
if (*line && *line != ';') goto invalid;
|
|
|
|
|
|
|
|
parser->data_size = (lstrlenW(parser->data) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
set_state(parser, SET_VALUE);
|
|
|
|
return line;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-26 15:47:16 +02:00
|
|
|
parser->data = NULL;
|
|
|
|
parser->data_size = 0;
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser DWORD_DATA state */
|
|
|
|
static WCHAR *dword_data_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line = pos;
|
|
|
|
|
|
|
|
parser->data = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
|
|
|
|
CHECK_ENOUGH_MEMORY(parser->data);
|
|
|
|
|
|
|
|
if (!convert_hex_to_dword(line, parser->data))
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
parser->data_size = sizeof(DWORD);
|
|
|
|
|
|
|
|
set_state(parser, SET_VALUE);
|
|
|
|
return line;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
HeapFree(GetProcessHeap(), 0, parser->data);
|
|
|
|
parser->data = NULL;
|
2017-06-26 15:47:16 +02:00
|
|
|
parser->data_size = 0;
|
2017-06-15 14:01:47 +02:00
|
|
|
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser HEX_DATA state */
|
|
|
|
static WCHAR *hex_data_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line = pos;
|
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
if (!convert_hex_csv_to_hex(parser, &line))
|
2017-06-15 14:01:47 +02:00
|
|
|
goto invalid;
|
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
if (parser->backslash)
|
|
|
|
{
|
|
|
|
set_state(parser, EOL_BACKSLASH);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
if (!parser->is_unicode && (parser->data_type == REG_EXPAND_SZ || parser->data_type == REG_MULTI_SZ))
|
|
|
|
{
|
|
|
|
void *tmp = parser->data;
|
|
|
|
|
|
|
|
parser->data = GetWideStringN(parser->data, parser->data_size, &parser->data_size);
|
|
|
|
parser->data_size *= sizeof(WCHAR);
|
|
|
|
HeapFree(GetProcessHeap(), 0, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_state(parser, SET_VALUE);
|
|
|
|
return line;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-26 15:47:16 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, parser->data);
|
|
|
|
parser->data = NULL;
|
|
|
|
parser->data_size = 0;
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2017-06-30 15:42:55 +02:00
|
|
|
/* handler for parser EOL_BACKSLASH state */
|
|
|
|
static WCHAR *eol_backslash_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *p = pos;
|
|
|
|
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
if (*p && *p != ';') goto invalid;
|
|
|
|
|
|
|
|
set_state(parser, HEX_MULTILINE);
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
HeapFree(GetProcessHeap(), 0, parser->data);
|
|
|
|
parser->data = NULL;
|
|
|
|
parser->data_size = 0;
|
|
|
|
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handler for parser HEX_MULTILINE state */
|
|
|
|
static WCHAR *hex_multiline_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
WCHAR *line;
|
|
|
|
|
|
|
|
if (!(line = get_line(parser->file)))
|
|
|
|
{
|
|
|
|
set_state(parser, SET_VALUE);
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*line == ' ' || *line == '\t') line++;
|
|
|
|
if (*line == ';') return line;
|
|
|
|
|
|
|
|
set_state(parser, HEX_DATA);
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
/* handler for parser UNKNOWN_DATA state */
|
|
|
|
static WCHAR *unknown_data_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
|
|
|
output_message(STRING_UNKNOWN_DATA_FORMAT, parser->data_type);
|
|
|
|
|
|
|
|
set_state(parser, LINE_START);
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
/* handler for parser SET_VALUE state */
|
|
|
|
static WCHAR *set_value_state(struct parser *parser, WCHAR *pos)
|
|
|
|
{
|
2017-06-15 14:01:47 +02:00
|
|
|
RegSetValueExW(parser->hkey, parser->value_name, 0, parser->data_type,
|
2017-06-15 14:00:31 +02:00
|
|
|
parser->data, parser->data_size);
|
|
|
|
|
2017-06-20 15:25:32 +02:00
|
|
|
if (parser->parse_type == REG_DWORD || parser->parse_type == REG_BINARY)
|
2017-06-16 15:06:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, parser->data);
|
2017-06-26 15:47:16 +02:00
|
|
|
|
|
|
|
parser->data = NULL;
|
|
|
|
parser->data_size = 0;
|
2017-06-16 15:06:23 +02:00
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
if (parser->reg_version == REG_VERSION_31)
|
|
|
|
set_state(parser, PARSE_WIN31_LINE);
|
|
|
|
else
|
|
|
|
set_state(parser, LINE_START);
|
2017-06-15 14:00:31 +02:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2017-05-03 13:28:26 +02:00
|
|
|
static WCHAR *get_lineA(FILE *fp)
|
2002-04-12 01:58:40 +02:00
|
|
|
{
|
2017-05-03 13:28:26 +02:00
|
|
|
static WCHAR *lineW;
|
2017-03-22 12:54:05 +01:00
|
|
|
static size_t size;
|
|
|
|
static char *buf, *next;
|
|
|
|
char *line;
|
2002-04-12 01:58:40 +02:00
|
|
|
|
2017-05-03 13:28:26 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lineW);
|
|
|
|
|
2017-05-03 13:28:14 +02:00
|
|
|
if (!fp) goto cleanup;
|
2016-07-21 07:48:30 +02:00
|
|
|
|
2017-03-22 12:54:05 +01:00
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
size = REG_VAL_BUF_SIZE;
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
CHECK_ENOUGH_MEMORY(buf);
|
|
|
|
*buf = 0;
|
|
|
|
next = buf;
|
|
|
|
}
|
|
|
|
line = next;
|
2009-06-16 15:46:33 +02:00
|
|
|
|
2017-03-22 12:54:05 +01:00
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
char *p = strpbrk(line, "\r\n");
|
|
|
|
if (!p)
|
2009-06-16 15:46:33 +02:00
|
|
|
{
|
2017-03-22 12:54:05 +01:00
|
|
|
size_t len, count;
|
|
|
|
len = strlen(next);
|
|
|
|
memmove(buf, next, len + 1);
|
|
|
|
if (size - len < 3)
|
|
|
|
{
|
|
|
|
char *new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, size * 2);
|
|
|
|
CHECK_ENOUGH_MEMORY(new_buf);
|
|
|
|
buf = new_buf;
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
if (!(count = fread(buf + len, 1, size - len - 1, fp)))
|
|
|
|
{
|
|
|
|
next = NULL;
|
2017-05-03 13:28:26 +02:00
|
|
|
lineW = GetWideString(buf);
|
|
|
|
return lineW;
|
2017-03-22 12:54:05 +01:00
|
|
|
}
|
|
|
|
buf[len + count] = 0;
|
|
|
|
next = buf;
|
2016-07-21 07:48:30 +02:00
|
|
|
line = buf;
|
2017-03-22 12:54:05 +01:00
|
|
|
continue;
|
2009-06-16 15:46:33 +02:00
|
|
|
}
|
2017-03-22 12:54:05 +01:00
|
|
|
next = p + 1;
|
|
|
|
if (*p == '\r' && *(p + 1) == '\n') next++;
|
|
|
|
*p = 0;
|
|
|
|
if (*line == ';' || *line == '#')
|
2016-07-21 07:48:30 +02:00
|
|
|
{
|
2017-03-22 12:54:05 +01:00
|
|
|
line = next;
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-03 13:28:26 +02:00
|
|
|
lineW = GetWideString(line);
|
|
|
|
return lineW;
|
2017-03-22 12:54:05 +01:00
|
|
|
}
|
2017-05-03 13:28:14 +02:00
|
|
|
|
|
|
|
cleanup:
|
2017-05-03 13:28:26 +02:00
|
|
|
lineW = NULL;
|
2017-05-03 13:28:14 +02:00
|
|
|
if (size) HeapFree(GetProcessHeap(), 0, buf);
|
2017-03-22 12:54:05 +01:00
|
|
|
size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-21 22:12:02 +02:00
|
|
|
|
2017-03-16 13:05:00 +01:00
|
|
|
static WCHAR *get_lineW(FILE *fp)
|
2008-07-09 23:39:08 +02:00
|
|
|
{
|
2017-03-16 13:05:00 +01:00
|
|
|
static size_t size;
|
|
|
|
static WCHAR *buf, *next;
|
|
|
|
WCHAR *line;
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2017-05-03 13:28:14 +02:00
|
|
|
if (!fp) goto cleanup;
|
2017-03-22 12:53:53 +01:00
|
|
|
|
2017-03-16 13:05:00 +01:00
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
size = REG_VAL_BUF_SIZE;
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(buf);
|
|
|
|
*buf = 0;
|
|
|
|
next = buf;
|
|
|
|
}
|
|
|
|
line = next;
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2017-03-16 13:05:00 +01:00
|
|
|
while (next)
|
|
|
|
{
|
|
|
|
static const WCHAR line_endings[] = {'\r','\n',0};
|
|
|
|
WCHAR *p = strpbrkW(line, line_endings);
|
|
|
|
if (!p)
|
2008-07-09 23:39:08 +02:00
|
|
|
{
|
2017-03-16 13:05:00 +01:00
|
|
|
size_t len, count;
|
|
|
|
len = strlenW(next);
|
|
|
|
memmove(buf, next, (len + 1) * sizeof(WCHAR));
|
|
|
|
if (size - len < 3)
|
|
|
|
{
|
|
|
|
WCHAR *new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, (size * 2) * sizeof(WCHAR));
|
|
|
|
CHECK_ENOUGH_MEMORY(new_buf);
|
|
|
|
buf = new_buf;
|
|
|
|
size *= 2;
|
|
|
|
}
|
|
|
|
if (!(count = fread(buf + len, sizeof(WCHAR), size - len - 1, fp)))
|
|
|
|
{
|
|
|
|
next = NULL;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
buf[len + count] = 0;
|
|
|
|
next = buf;
|
2009-03-08 16:45:54 +01:00
|
|
|
line = buf;
|
2017-03-16 13:05:00 +01:00
|
|
|
continue;
|
2008-07-09 23:39:08 +02:00
|
|
|
}
|
2017-03-16 13:05:00 +01:00
|
|
|
next = p + 1;
|
|
|
|
if (*p == '\r' && *(p + 1) == '\n') next++;
|
|
|
|
*p = 0;
|
|
|
|
if (*line == ';' || *line == '#')
|
2008-07-09 23:39:08 +02:00
|
|
|
{
|
2017-03-16 13:05:00 +01:00
|
|
|
line = next;
|
|
|
|
continue;
|
2008-07-09 23:39:08 +02:00
|
|
|
}
|
2017-03-16 13:05:00 +01:00
|
|
|
return line;
|
2008-07-09 23:39:08 +02:00
|
|
|
}
|
2017-05-03 13:28:14 +02:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (size) HeapFree(GetProcessHeap(), 0, buf);
|
2017-03-16 13:05:00 +01:00
|
|
|
size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-07-09 23:39:08 +02:00
|
|
|
|
2002-04-12 01:58:40 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* 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;
|
|
|
|
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
|
2016-08-11 06:48:42 +02:00
|
|
|
) != ERROR_SUCCESS)
|
|
|
|
return;
|
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;
|
2016-08-11 06:48:42 +02:00
|
|
|
for (;;) {
|
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);
|
2016-08-11 06:48:42 +02:00
|
|
|
} else if (ret == ERROR_SUCCESS) {
|
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
|
|
|
|
2017-06-16 15:06:11 +02:00
|
|
|
case REG_NONE:
|
2008-11-20 20:43:25 +01:00
|
|
|
case REG_EXPAND_SZ:
|
2002-06-28 19:33:09 +02:00
|
|
|
case REG_MULTI_SZ:
|
2008-11-20 20:43:25 +01:00
|
|
|
case REG_BINARY:
|
2017-06-16 15:06:11 +02:00
|
|
|
default:
|
2008-11-20 20:43:25 +01:00
|
|
|
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
|
|
|
}
|
2016-08-11 06:48:42 +02:00
|
|
|
else break;
|
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;
|
|
|
|
(*reg_key_name_buf)[curr_len] = '\\';
|
2016-08-11 06:48:42 +02:00
|
|
|
for (;;) {
|
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);
|
2016-08-11 06:48:42 +02:00
|
|
|
} else if (ret == ERROR_SUCCESS) {
|
2002-04-12 01:58:40 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-08-11 06:48:42 +02:00
|
|
|
else break;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
2016-08-11 06:48:42 +02:00
|
|
|
else break;
|
2002-04-12 01:58:40 +02:00
|
|
|
}
|
|
|
|
(*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 */
|
2017-06-15 14:00:55 +02:00
|
|
|
if (!(reg_key_class = parse_key_name(reg_key_name, &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);
|
|
|
|
}
|
2017-05-18 16:08:56 +02:00
|
|
|
if (!branch_name || !*branch_name) {
|
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.
|
|
|
|
*/
|
2017-06-15 14:00:31 +02:00
|
|
|
BOOL import_registry_file(FILE *reg_file)
|
2003-08-07 05:10:13 +02:00
|
|
|
{
|
2017-03-22 12:54:16 +01:00
|
|
|
BYTE s[2];
|
2017-06-15 14:00:31 +02:00
|
|
|
struct parser parser;
|
|
|
|
WCHAR *pos;
|
2017-03-22 12:54:16 +01:00
|
|
|
|
|
|
|
if (!reg_file || (fread(s, 2, 1, reg_file) != 1))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
parser.is_unicode = (s[0] == 0xff && s[1] == 0xfe);
|
|
|
|
get_line = parser.is_unicode ? get_lineW : get_lineA;
|
2017-05-05 11:42:21 +02:00
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
parser.file = reg_file;
|
|
|
|
parser.two_wchars[0] = s[0];
|
|
|
|
parser.two_wchars[1] = s[1];
|
|
|
|
parser.reg_version = -1;
|
2017-06-15 14:01:47 +02:00
|
|
|
parser.hkey = NULL;
|
|
|
|
parser.key_name = NULL;
|
2017-06-15 14:00:31 +02:00
|
|
|
parser.value_name = NULL;
|
2017-06-20 15:25:32 +02:00
|
|
|
parser.parse_type = 0;
|
2017-06-15 14:00:31 +02:00
|
|
|
parser.data_type = 0;
|
|
|
|
parser.data = NULL;
|
|
|
|
parser.data_size = 0;
|
2017-06-30 15:42:55 +02:00
|
|
|
parser.backslash = FALSE;
|
2017-06-15 14:00:31 +02:00
|
|
|
parser.state = HEADER;
|
2017-05-05 11:42:21 +02:00
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
pos = parser.two_wchars;
|
2017-05-05 11:42:21 +02:00
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
/* parser main loop */
|
|
|
|
while (pos)
|
|
|
|
pos = (parser_funcs[parser.state])(&parser, pos);
|
2017-05-05 11:42:21 +02:00
|
|
|
|
2017-06-15 14:00:31 +02:00
|
|
|
if (parser.reg_version == REG_VERSION_FUZZY || parser.reg_version == REG_VERSION_INVALID)
|
|
|
|
return parser.reg_version == REG_VERSION_FUZZY;
|
2017-05-05 11:42:33 +02:00
|
|
|
|
2017-06-15 14:01:26 +02:00
|
|
|
if (parser.value_name)
|
|
|
|
HeapFree(GetProcessHeap(), 0, parser.value_name);
|
|
|
|
|
2017-06-15 14:01:47 +02:00
|
|
|
close_key(&parser);
|
|
|
|
|
2017-05-05 11:42:33 +02:00
|
|
|
return TRUE;
|
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;
|
|
|
|
|
2017-06-15 14:00:55 +02:00
|
|
|
if (!(key_class = parse_key_name(reg_key_name, &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);
|
|
|
|
}
|