[REG] Sync with Wine Staging 2.16. CORE-13762

39e0e81 reg: Null-terminate incomplete REG_EXPAND_SZ and REG_MULTI_SZ Unicode data.
82fc4c8 reg: Close any open registry keys before starting the key deletion process.
5de883c reg: Use the correct return codes during the import operation.
56e58e4 reg: Delete registry keys via the state machine.
d90f2a5 reg: Delete registry values via the state machine.
db98cc4 reg: Handle unknown registry data types in the state machine.
32d5368 reg: Import hex data via the state machine.
f1874c1 reg: Import REG_DWORD data via the state machine.
038f1c6 reg: Parse data types and import REG_SZ data via the state machine.
0565934 reg: Parse key names and value names in the state machine.
3e87a70 reg: Introduce a partial state machine for importing Windows 3.1 registry data.
aa386af reg: Add initial support for the import operation.
f2fbbec reg: Rename reg.h to resource.h.
c6c95a0 reg: Compile with msvcrt.
8c253c4 reg: Make some variables 'static const'.
337e0f4 reg: Avoid an uninitialized variable warning.
8abec73 reg: Dynamically allocate memory for the value name buffer when deleting all registry values in a specified key.
e7ea838 reg: Use a helper function to resize a memory buffer.
a1bc33a reg: Use a helper function to free allocated memory.
a6e28cc reg: Use a helper function to allocate memory and die on failure.
90da210 reg: Account for sizeof(WCHAR) when resizing the value name buffer during the query operation.
fb22f6c reg: Avoid using RegQueryInfoKey() to enumerate subkeys and values in the query operation.

svn path=/trunk/; revision=75958
This commit is contained in:
Amine Khaldi 2017-09-24 11:33:04 +00:00
parent 3826e0eec9
commit 044cf8a897
30 changed files with 1380 additions and 182 deletions

View file

@ -2,7 +2,7 @@
remove_definitions(-D_WIN32_WINNT=0x502)
add_definitions(-D_WIN32_WINNT=0x600)
add_executable(reg reg.c reg.rc)
add_executable(reg import.c reg.c reg.rc)
set_module_type(reg win32cui UNICODE)
target_link_libraries(reg wine)
add_importlibs(reg advapi32 advapi32_vista user32 msvcrt kernel32 ntdll)

File diff suppressed because it is too large Load diff

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -38,4 +38,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -39,4 +39,8 @@ STRINGTABLE
STRING_REG_HELP, "Tastați «REG /?» pentru mai multe informații.\n"
STRING_FUNC_HELP, "Tastați «REG %1 /?» pentru mai multe informații.\n"
STRING_VALUE_NOT_SET, "(valoare nealocată)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Введите ""REG /?"" для получения справки по использованию..\n"
STRING_FUNC_HELP, "Введите ""REG %1 /?"" для получения справки по использованию..\n"
STRING_VALUE_NOT_SET, "(значение не указано)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -37,4 +37,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -35,4 +35,8 @@ STRINGTABLE
STRING_REG_HELP, "Yardım için ""REG /?"" yazınız.\n"
STRING_FUNC_HELP, "Yardım için ""REG %1 /?"" yazınız.\n"
STRING_VALUE_NOT_SET, "(Değer belirlenmemiş.)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -33,4 +33,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -35,4 +35,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -35,4 +35,8 @@ STRINGTABLE
STRING_REG_HELP, "Type ""REG /?"" for help.\n"
STRING_FUNC_HELP, "Type ""REG %1 /?"" for help.\n"
STRING_VALUE_NOT_SET, "(value not set)"
STRING_IMPORT_USAGE, "REG IMPORT file.reg\n"
STRING_FILE_NOT_FOUND, "reg: The file '%1' was not found.\n"
STRING_OPEN_KEY_FAILED, "reg: Unable to open the registry key '%1'.\n"
STRING_ESCAPE_SEQUENCE, "reg: Unrecognized escape sequence [\\%1!c!]\n"
}

View file

@ -25,11 +25,8 @@
#include <shlwapi.h>
#include <wine/unicode.h>
#include <wine/debug.h>
#include <errno.h>
#include "reg.h"
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
WINE_DEFAULT_DEBUG_CHANNEL(reg);
static const WCHAR short_hklm[] = {'H','K','L','M',0};
@ -84,6 +81,40 @@ type_rels[] =
{REG_MULTI_SZ, type_multi_sz},
};
void *heap_xalloc(size_t size)
{
void *buf = HeapAlloc(GetProcessHeap(), 0, size);
if (!buf)
{
ERR("Out of memory!\n");
exit(1);
}
return buf;
}
void *heap_xrealloc(void *buf, size_t size)
{
void *new_buf;
if (buf)
new_buf = HeapReAlloc(GetProcessHeap(), 0, buf, size);
else
new_buf = HeapAlloc(GetProcessHeap(), 0, size);
if (!new_buf)
{
ERR("Out of memory!\n");
exit(1);
}
return new_buf;
}
BOOL heap_free(void *buf)
{
return HeapFree(GetProcessHeap(), 0, buf);
}
static void output_writeconsole(const WCHAR *str, DWORD wlen)
{
DWORD count, ret;
@ -99,12 +130,11 @@ static void output_writeconsole(const WCHAR *str, DWORD wlen)
* one in that case.
*/
len = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, NULL, 0, NULL, NULL);
msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
if (!msgA) return;
msgA = heap_xalloc(len);
WideCharToMultiByte(GetConsoleOutputCP(), 0, str, wlen, msgA, len, NULL, NULL);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
HeapFree(GetProcessHeap(), 0, msgA);
heap_free(msgA);
}
}
@ -125,7 +155,7 @@ static void output_formatstring(const WCHAR *fmt, __ms_va_list va_args)
LocalFree(str);
}
static void __cdecl output_message(unsigned int id, ...)
void __cdecl output_message(unsigned int id, ...)
{
WCHAR fmt[1024];
__ms_va_list va_args;
@ -188,7 +218,7 @@ static inline BOOL path_rootname_cmp(const WCHAR *input_path, const WCHAR *rootk
(input_path[length] == 0 || input_path[length] == '\\'));
}
static HKEY path_get_rootkey(const WCHAR *path)
HKEY path_get_rootkey(const WCHAR *path)
{
DWORD i;
@ -246,7 +276,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
case REG_EXPAND_SZ:
{
*reg_count = (lstrlenW(data) + 1) * sizeof(WCHAR);
out_data = HeapAlloc(GetProcessHeap(),0,*reg_count);
out_data = heap_xalloc(*reg_count);
lstrcpyW((LPWSTR)out_data,data);
break;
}
@ -256,13 +286,13 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
{
LPWSTR rest;
unsigned long val;
val = strtoulW(data, &rest, (tolowerW(data[1]) == 'x') ? 16 : 10);
if (*rest || data[0] == '-' || (val == ~0u && errno == ERANGE) || val > ~0u) {
val = wcstoul(data, &rest, (tolowerW(data[1]) == 'x') ? 16 : 10);
if (*rest || data[0] == '-' || (val == ~0u && errno == ERANGE)) {
output_message(STRING_MISSING_INTEGER);
break;
}
*reg_count = sizeof(DWORD);
out_data = HeapAlloc(GetProcessHeap(),0,*reg_count);
out_data = heap_xalloc(*reg_count);
((LPDWORD)out_data)[0] = val;
break;
}
@ -271,7 +301,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
BYTE hex0, hex1;
int i = 0, destByteIndex = 0, datalen = lstrlenW(data);
*reg_count = ((datalen + datalen % 2) / 2) * sizeof(BYTE);
out_data = HeapAlloc(GetProcessHeap(), 0, *reg_count);
out_data = heap_xalloc(*reg_count);
if(datalen % 2)
{
hex1 = hexchar_to_byte(data[i++]);
@ -290,7 +320,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
break;
no_hex_data:
/* cleanup, print error */
HeapFree(GetProcessHeap(), 0, out_data);
heap_free(out_data);
output_message(STRING_MISSING_HEXDATA);
out_data = NULL;
break;
@ -298,7 +328,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
case REG_MULTI_SZ:
{
int i, destindex, len = strlenW(data);
WCHAR *buffer = HeapAlloc(GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
WCHAR *buffer = heap_xalloc((len + 2) * sizeof(WCHAR));
for (i = 0, destindex = 0; i < len; i++, destindex++)
{
@ -314,7 +344,7 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW
if (destindex && !buffer[destindex - 1] && (!buffer[destindex] || destindex == 1))
{
HeapFree(GetProcessHeap(), 0, buffer);
heap_free(buffer);
output_message(STRING_INVALID_STRING);
return NULL;
}
@ -402,7 +432,7 @@ static int reg_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
}
RegSetValueExW(key, value_name, 0, reg_type, reg_data, reg_count);
HeapFree(GetProcessHeap(),0,reg_data);
heap_free(reg_data);
}
RegCloseKey(key);
@ -454,40 +484,35 @@ static int reg_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name
if (value_all)
{
LPWSTR szValue;
DWORD maxValue;
DWORD count;
DWORD max_value_len = 256, value_len;
WCHAR *value_name;
LONG rc;
rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, &maxValue, NULL, NULL, NULL);
if (rc != ERROR_SUCCESS)
{
RegCloseKey(key);
output_message(STRING_GENERAL_FAILURE);
return 1;
}
maxValue++;
szValue = HeapAlloc(GetProcessHeap(),0,maxValue*sizeof(WCHAR));
value_name = heap_xalloc(max_value_len * sizeof(WCHAR));
while (1)
{
count = maxValue;
rc = RegEnumValueW(key, 0, szValue, &count, NULL, NULL, NULL, NULL);
value_len = max_value_len;
rc = RegEnumValueW(key, 0, value_name, &value_len, NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS)
{
rc = RegDeleteValueW(key, szValue);
rc = RegDeleteValueW(key, value_name);
if (rc != ERROR_SUCCESS)
{
HeapFree(GetProcessHeap(), 0, szValue);
heap_free(value_name);
RegCloseKey(key);
output_message(STRING_VALUEALL_FAILED, key_name);
return 1;
}
}
else if (rc == ERROR_MORE_DATA)
{
max_value_len *= 2;
value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR));
}
else break;
}
HeapFree(GetProcessHeap(), 0, szValue);
heap_free(value_name);
}
else if (value_name || value_empty)
{
@ -513,16 +538,16 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
{
case REG_SZ:
case REG_EXPAND_SZ:
buffer = HeapAlloc(GetProcessHeap(), 0, size_bytes);
buffer = heap_xalloc(size_bytes);
strcpyW(buffer, (WCHAR *)src);
break;
case REG_NONE:
case REG_BINARY:
{
WCHAR *ptr;
WCHAR fmt[] = {'%','0','2','X',0};
static const WCHAR fmt[] = {'%','0','2','X',0};
buffer = HeapAlloc(GetProcessHeap(), 0, (size_bytes * 2 + 1) * sizeof(WCHAR));
buffer = heap_xalloc((size_bytes * 2 + 1) * sizeof(WCHAR));
ptr = buffer;
for (i = 0; i < size_bytes; i++)
ptr += sprintfW(ptr, fmt, src[i]);
@ -533,9 +558,9 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
case REG_DWORD_BIG_ENDIAN:
{
const int zero_x_dword = 10;
WCHAR fmt[] = {'0','x','%','x',0};
static const WCHAR fmt[] = {'0','x','%','x',0};
buffer = HeapAlloc(GetProcessHeap(), 0, (zero_x_dword + 1) * sizeof(WCHAR));
buffer = heap_xalloc((zero_x_dword + 1) * sizeof(WCHAR));
sprintfW(buffer, fmt, *(DWORD *)src);
break;
}
@ -548,13 +573,13 @@ static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
if (size_bytes <= two_wchars)
{
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
buffer = heap_xalloc(sizeof(WCHAR));
*buffer = 0;
return buffer;
}
tmp_size = size_bytes - two_wchars; /* exclude both null terminators */
buffer = HeapAlloc(GetProcessHeap(), 0, tmp_size * 2 + sizeof(WCHAR));
buffer = heap_xalloc(tmp_size * 2 + sizeof(WCHAR));
len = tmp_size / sizeof(WCHAR);
for (i = 0, destindex = 0; i < len; i++, destindex++)
@ -588,10 +613,10 @@ static const WCHAR *reg_type_to_wchar(DWORD type)
static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD data_size)
{
WCHAR fmt[] = {' ',' ',' ',' ','%','1',0};
static const WCHAR fmt[] = {' ',' ',' ',' ','%','1',0};
static const WCHAR newlineW[] = {'\n',0};
WCHAR defval[32];
WCHAR *reg_data;
WCHAR newlineW[] = {'\n',0};
if (value_name && value_name[0])
output_string(fmt, value_name);
@ -606,7 +631,7 @@ static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD
{
reg_data = reg_data_to_wchar(type, data, data_size);
output_string(fmt, reg_data);
HeapFree(GetProcessHeap(), 0, reg_data);
heap_free(reg_data);
}
else
{
@ -619,25 +644,23 @@ static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD
static WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
{
WCHAR *subkey_path;
WCHAR fmt[] = {'%','s','\\','%','s',0};
static const WCHAR fmt[] = {'%','s','\\','%','s',0};
subkey_path = HeapAlloc(GetProcessHeap(), 0, (path_len + subkey_len + 2) * sizeof(WCHAR));
if (!subkey_path)
{
ERR("Failed to allocate memory for subkey_path\n");
return NULL;
}
subkey_path = heap_xalloc((path_len + subkey_len + 2) * sizeof(WCHAR));
sprintfW(subkey_path, fmt, path, subkey_name);
return subkey_path;
}
static unsigned int num_values_found = 0;
#define MAX_SUBKEY_LEN 257
static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
{
LONG rc;
DWORD num_subkeys, max_subkey_len, subkey_len;
DWORD max_data_bytes, data_size;
DWORD max_data_bytes = 2048, data_size;
DWORD subkey_len;
DWORD type, path_len, i;
BYTE *data;
WCHAR fmt[] = {'%','1','\n',0};
@ -645,23 +668,20 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
WCHAR *subkey_name, *subkey_path;
HKEY subkey;
rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, &num_subkeys, &max_subkey_len,
NULL, NULL, NULL, &max_data_bytes, NULL, NULL);
if (rc)
data = heap_xalloc(max_data_bytes);
for (;;)
{
ERR("RegQueryInfoKey failed: %d\n", rc);
return 1;
data_size = max_data_bytes;
rc = RegQueryValueExW(key, value_name, NULL, &type, data, &data_size);
if (rc == ERROR_MORE_DATA)
{
max_data_bytes = data_size;
data = heap_xrealloc(data, max_data_bytes);
}
else break;
}
data = HeapAlloc(GetProcessHeap(), 0, max_data_bytes);
if (!data)
{
ERR("Failed to allocate memory for data\n");
return 1;
}
data_size = max_data_bytes;
rc = RegQueryValueExW(key, value_name, NULL, &type, data, &data_size);
if (rc == ERROR_SUCCESS)
{
output_string(fmt, path);
@ -670,7 +690,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
num_values_found++;
}
HeapFree(GetProcessHeap(), 0, data);
heap_free(data);
if (!recurse)
{
@ -687,19 +707,14 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
return 0;
}
max_subkey_len++;
subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR));
if (!subkey_name)
{
ERR("Failed to allocate memory for subkey_name\n");
return 1;
}
subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = strlenW(path);
for (i = 0; i < num_subkeys; i++)
i = 0;
for (;;)
{
subkey_len = max_subkey_len;
subkey_len = MAX_SUBKEY_LEN;
rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS)
{
@ -709,20 +724,22 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
query_value(subkey, value_name, subkey_path, recurse);
RegCloseKey(subkey);
}
HeapFree(GetProcessHeap(), 0, subkey_path);
heap_free(subkey_path);
i++;
}
else break;
}
HeapFree(GetProcessHeap(), 0, subkey_name);
heap_free(subkey_name);
return 0;
}
static int query_all(HKEY key, WCHAR *path, BOOL recurse)
{
LONG rc;
DWORD num_subkeys, max_subkey_len, subkey_len;
DWORD num_values, max_value_len, value_len;
DWORD max_data_bytes, data_size;
DWORD max_value_len = 256, value_len;
DWORD max_data_bytes = 2048, data_size;
DWORD subkey_len;
DWORD i, type, path_len;
WCHAR fmt[] = {'%','1','\n',0};
WCHAR fmt_path[] = {'%','1','\\','%','2','\n',0};
@ -731,60 +748,52 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
BYTE *data;
HKEY subkey;
rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, &num_subkeys, &max_subkey_len, NULL,
&num_values, &max_value_len, &max_data_bytes, NULL, NULL);
if (rc)
{
ERR("RegQueryInfoKey failed: %d\n", rc);
return 1;
}
output_string(fmt, path);
max_value_len++;
value_name = HeapAlloc(GetProcessHeap(), 0, max_value_len * sizeof(WCHAR));
if (!value_name)
{
ERR("Failed to allocate memory for value_name\n");
return 1;
}
value_name = heap_xalloc(max_value_len * sizeof(WCHAR));
data = heap_xalloc(max_data_bytes);
data = HeapAlloc(GetProcessHeap(), 0, max_data_bytes);
if (!data)
{
HeapFree(GetProcessHeap(), 0, value_name);
ERR("Failed to allocate memory for data\n");
return 1;
}
for (i = 0; i < num_values; i++)
i = 0;
for (;;)
{
value_len = max_value_len;
data_size = max_data_bytes;
rc = RegEnumValueW(key, i, value_name, &value_len, NULL, &type, data, &data_size);
if (rc == ERROR_SUCCESS)
{
output_value(value_name, type, data, data_size);
i++;
}
else if (rc == ERROR_MORE_DATA)
{
if (data_size > max_data_bytes)
{
max_data_bytes = data_size;
data = heap_xrealloc(data, max_data_bytes);
}
else
{
max_value_len *= 2;
value_name = heap_xrealloc(value_name, max_value_len * sizeof(WCHAR));
}
}
else break;
}
HeapFree(GetProcessHeap(), 0, data);
HeapFree(GetProcessHeap(), 0, value_name);
heap_free(data);
heap_free(value_name);
if (num_values || recurse)
if (i || recurse)
output_string(newlineW);
max_subkey_len++;
subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR));
if (!subkey_name)
{
ERR("Failed to allocate memory for subkey_name\n");
return 1;
}
subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = strlenW(path);
for (i = 0; i < num_subkeys; i++)
i = 0;
for (;;)
{
subkey_len = max_subkey_len;
subkey_len = MAX_SUBKEY_LEN;
rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
if (rc == ERROR_SUCCESS)
{
@ -796,15 +805,17 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
query_all(subkey, subkey_path, recurse);
RegCloseKey(subkey);
}
HeapFree(GetProcessHeap(), 0, subkey_path);
heap_free(subkey_path);
}
else output_string(fmt_path, path, subkey_name);
i++;
}
else break;
}
HeapFree(GetProcessHeap(), 0, subkey_name);
heap_free(subkey_name);
if (num_subkeys && !recurse)
if (i && !recurse)
output_string(newlineW);
return 0;
@ -855,13 +866,13 @@ static WCHAR *get_long_key(HKEY root, WCHAR *path)
if (!path)
{
long_key = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
long_key = heap_xalloc((len + 1) * sizeof(WCHAR));
strcpyW(long_key, root_rels[i].long_name);
return long_key;
}
len += strlenW(path) + 1; /* add one for the backslash */
long_key = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
long_key = heap_xalloc((len + 1) * sizeof(WCHAR));
sprintfW(long_key, fmt, root_rels[i].long_name, path);
return long_key;
}
@ -900,32 +911,38 @@ static BOOL is_help_switch(const WCHAR *s)
enum operations {
REG_ADD,
REG_DELETE,
REG_IMPORT,
REG_QUERY,
REG_INVALID
};
static const WCHAR addW[] = {'a','d','d',0};
static const WCHAR deleteW[] = {'d','e','l','e','t','e',0};
static const WCHAR queryW[] = {'q','u','e','r','y',0};
static enum operations get_operation(const WCHAR *str, int *op_help)
{
if (!lstrcmpiW(str, addW))
{
*op_help = STRING_ADD_USAGE;
return REG_ADD;
}
struct op_info { const WCHAR *op; int id; int help_id; };
if (!lstrcmpiW(str, deleteW))
{
*op_help = STRING_DELETE_USAGE;
return REG_DELETE;
}
static const WCHAR add[] = {'a','d','d',0};
static const WCHAR delete[] = {'d','e','l','e','t','e',0};
static const WCHAR import[] = {'i','m','p','o','r','t',0};
static const WCHAR query[] = {'q','u','e','r','y',0};
if (!lstrcmpiW(str, queryW))
static const struct op_info op_array[] =
{
*op_help = STRING_QUERY_USAGE;
return REG_QUERY;
{ add, REG_ADD, STRING_ADD_USAGE },
{ delete, REG_DELETE, STRING_DELETE_USAGE },
{ import, REG_IMPORT, STRING_IMPORT_USAGE },
{ query, REG_QUERY, STRING_QUERY_USAGE },
{ NULL, -1, 0 }
};
const struct op_info *ptr;
for (ptr = op_array; ptr->op; ptr++)
{
if (!lstrcmpiW(str, ptr->op))
{
*op_help = ptr->help_id;
return ptr->id;
}
}
return REG_INVALID;
@ -966,7 +983,7 @@ int wmain(int argc, WCHAR *argvW[])
if (argc > 2)
show_op_help = is_help_switch(argvW[2]);
if (argc == 2 || (show_op_help && argc > 3))
if (argc == 2 || ((show_op_help || op == REG_IMPORT) && argc > 3))
{
output_message(STRING_INVALID_SYNTAX);
output_message(STRING_FUNC_HELP, struprW(argvW[1]));
@ -978,6 +995,9 @@ int wmain(int argc, WCHAR *argvW[])
return 0;
}
if (op == REG_IMPORT)
return reg_import(argvW[2]);
if (!parse_registry_key(argvW[2], &root, &path, &key_name))
return 1;
@ -1061,7 +1081,7 @@ int wmain(int argc, WCHAR *argvW[])
ret = reg_add(root, path, value_name, value_empty, type, separator, data, force);
else if (op == REG_DELETE)
ret = reg_delete(root, path, key_name, value_name, value_empty, value_all, force);
else if (op == REG_QUERY)
else
ret = reg_query(root, path, key_name, value_name, value_empty, recurse);
return ret;
}

View file

@ -1,7 +1,5 @@
/*
* REG.EXE - Wine-compatible reg program.
*
* Copyright 2008 Andrew Riedi
* Copyright 2017 Hugh McMaster
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,39 +16,21 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#pragma once
#ifndef __REG_H__
#define __REG_H__
//#include <windef.h>
#include "resource.h"
/* Translation IDs. */
#define STRING_USAGE 101
#define STRING_ADD_USAGE 102
#define STRING_DELETE_USAGE 103
#define STRING_QUERY_USAGE 104
#define STRING_SUCCESS 105
#define STRING_INVALID_KEY 106
#define STRING_INVALID_CMDLINE 107
#define STRING_NO_REMOTE 108
#define STRING_CANNOT_FIND 109
#define STRING_UNSUPPORTED_TYPE 110
#define STRING_MISSING_INTEGER 111
#define STRING_MISSING_HEXDATA 112
#define STRING_UNHANDLED_TYPE 113
#define STRING_OVERWRITE_VALUE 114
#define STRING_YESNO 115
#define STRING_YES 116
#define STRING_NO 117
#define STRING_CANCELLED 118
#define STRING_DEFAULT_VALUE 119
#define STRING_DELETE_VALUE 120
#define STRING_DELETE_VALUEALL 121
#define STRING_DELETE_SUBKEY 122
#define STRING_INVALID_STRING 123
#define STRING_VALUEALL_FAILED 124
#define STRING_GENERAL_FAILURE 125
#define STRING_MATCHES_FOUND 126
#define STRING_INVALID_SYNTAX 127
#define STRING_INVALID_OPTION 128
#define STRING_REG_HELP 129
#define STRING_FUNC_HELP 130
#define STRING_VALUE_NOT_SET 131
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
/* reg.c */
void *heap_xalloc(size_t size);
void *heap_xrealloc(void *buf, size_t size);
BOOL heap_free(void *buf);
void __cdecl output_message(unsigned int id, ...);
HKEY path_get_rootkey(const WCHAR *path);
/* import.c */
int reg_import(const WCHAR *filename);
#endif /* __REG_H__ */

View file

@ -0,0 +1,60 @@
/*
* REG.EXE - Wine-compatible reg program.
*
* Copyright 2008 Andrew Riedi
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#pragma once
//#include <windef.h>
/* Translation IDs. */
#define STRING_USAGE 101
#define STRING_ADD_USAGE 102
#define STRING_DELETE_USAGE 103
#define STRING_QUERY_USAGE 104
#define STRING_SUCCESS 105
#define STRING_INVALID_KEY 106
#define STRING_INVALID_CMDLINE 107
#define STRING_NO_REMOTE 108
#define STRING_CANNOT_FIND 109
#define STRING_UNSUPPORTED_TYPE 110
#define STRING_MISSING_INTEGER 111
#define STRING_MISSING_HEXDATA 112
#define STRING_UNHANDLED_TYPE 113
#define STRING_OVERWRITE_VALUE 114
#define STRING_YESNO 115
#define STRING_YES 116
#define STRING_NO 117
#define STRING_CANCELLED 118
#define STRING_DEFAULT_VALUE 119
#define STRING_DELETE_VALUE 120
#define STRING_DELETE_VALUEALL 121
#define STRING_DELETE_SUBKEY 122
#define STRING_INVALID_STRING 123
#define STRING_VALUEALL_FAILED 124
#define STRING_GENERAL_FAILURE 125
#define STRING_MATCHES_FOUND 126
#define STRING_INVALID_SYNTAX 127
#define STRING_INVALID_OPTION 128
#define STRING_REG_HELP 129
#define STRING_FUNC_HELP 130
#define STRING_VALUE_NOT_SET 131
#define STRING_IMPORT_USAGE 132
#define STRING_FILE_NOT_FOUND 133
#define STRING_OPEN_KEY_FAILED 134
#define STRING_ESCAPE_SEQUENCE 135

View file

@ -227,7 +227,7 @@ reactos/win32ss/printing/monitors/localmon/ui/ # Synced to WineStaging-2.9 (kno
ReactOS shares the following programs with Winehq.
reactos/base/applications/cmdutils/cscript # Synced to WineStaging-2.9
reactos/base/applications/cmdutils/reg # Synced to WineStaging-2.9
reactos/base/applications/cmdutils/reg # Synced to WineStaging-2.16
reactos/base/applications/cmdutils/schtasks # Synced to WineStaging-2.9
reactos/base/applications/cmdutils/taskkill # Synced to WineStaging-2.9
reactos/base/applications/cmdutils/wmic # Synced to WineStaging-2.9