regedit: Read registry lines through a single function
Hugh McMaster
hugh.mcmaster at outlook.com
Mon May 1 07:54:31 CDT 2017
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
programs/regedit/regproc.c | 59 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 49 insertions(+), 10 deletions(-)
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 8dd18d2..a5dda02 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -141,6 +141,14 @@ static char* GetMultiByteStringN(const WCHAR* strW, int chars, DWORD* len)
return NULL;
}
+struct reg_info {
+ FILE *file;
+ BOOL is_unicode;
+};
+
+static char *get_lineA(FILE *fp);
+static WCHAR *get_lineW(FILE *fp);
+
/******************************************************************************
* Converts a hex representation of a DWORD into a DWORD.
*/
@@ -671,6 +679,23 @@ static enum reg_versions parse_file_header(WCHAR *s)
return REG_VERSION_INVALID;
}
+static WCHAR *get_line(struct reg_info *reg_info)
+{
+ WCHAR *line;
+
+ if (!reg_info->is_unicode)
+ {
+ char *lineA = get_lineA(reg_info->file);
+ line = GetWideString(lineA);
+ }
+ else
+ {
+ line = get_lineW(reg_info->file);
+ }
+
+ return line;
+}
+
static char *get_lineA(FILE *fp)
{
static size_t size;
@@ -742,13 +767,13 @@ static char *get_lineA(FILE *fp)
return NULL;
}
-static BOOL processRegLinesA(FILE *fp, char *two_chars)
+static BOOL processRegLinesA(struct reg_info *reg_info, char *two_chars)
{
char *line, *header;
WCHAR *lineW;
int reg_version;
- line = get_lineA(fp);
+ line = get_lineA(reg_info->file);
header = HeapAlloc(GetProcessHeap(), 0, strlen(line) + 3);
CHECK_ENOUGH_MEMORY(header);
@@ -766,10 +791,8 @@ static BOOL processRegLinesA(FILE *fp, char *two_chars)
return reg_version == REG_VERSION_FUZZY;
}
- while ((line = get_lineA(fp)))
+ while ((lineW = get_line(reg_info)))
{
- lineW = GetWideString(line);
-
if (reg_version == REG_VERSION_31)
processRegEntry31(lineW);
else
@@ -854,12 +877,12 @@ static WCHAR *get_lineW(FILE *fp)
return NULL;
}
-static BOOL processRegLinesW(FILE *fp)
+static BOOL processRegLinesW(struct reg_info *reg_info)
{
WCHAR *line;
int reg_version;
- line = get_lineW(fp);
+ line = get_line(reg_info);
reg_version = parse_file_header(line);
if (reg_version == REG_VERSION_FUZZY || reg_version == REG_VERSION_INVALID)
{
@@ -867,7 +890,7 @@ static BOOL processRegLinesW(FILE *fp)
return reg_version == REG_VERSION_FUZZY;
}
- while ((line = get_lineW(fp)))
+ while ((line = get_line(reg_info)))
processRegEntry(line, TRUE);
closeKey();
@@ -1348,14 +1371,30 @@ BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
BOOL import_registry_file(FILE* reg_file)
{
BYTE s[2];
+ struct reg_info *reg_info;
+ BOOL ret;
if (!reg_file || (fread(s, 2, 1, reg_file) != 1))
return FALSE;
+ reg_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*reg_info));
+ CHECK_ENOUGH_MEMORY(reg_info);
+
+ reg_info->file = reg_file;
+
if (s[0] == 0xff && s[1] == 0xfe)
- return processRegLinesW(reg_file);
+ {
+ reg_info->is_unicode = TRUE;
+ ret = processRegLinesW(reg_info);
+ }
else
- return processRegLinesA(reg_file, (char *)s);
+ {
+ reg_info->is_unicode = FALSE;
+ ret = processRegLinesA(reg_info, (char *)s);
+ }
+
+ HeapFree(GetProcessHeap(), 0, reg_info);
+ return ret;
}
/******************************************************************************
--
2.7.4
More information about the wine-patches
mailing list