Commit 5c9526cb authored by Thomas Faller's avatar Thomas Faller Committed by Alexandre Julliard

reg: Implement binary data add operation.

parent ffb4d151
......@@ -158,6 +158,19 @@ static DWORD wchar_get_type(const WCHAR *type_name)
return ~0u;
}
/* hexchar_to_byte from programs/regedit/hexedit.c */
static inline BYTE hexchar_to_byte(WCHAR ch)
{
if (ch >= '0' && ch <= '9')
return ch - '0';
else if (ch >= 'a' && ch <= 'f')
return ch - 'a' + 10;
else if (ch >= 'A' && ch <= 'F')
return ch - 'A' + 10;
else
return -1;
}
static LPBYTE get_regdata(LPWSTR data, DWORD reg_type, WCHAR separator, DWORD *reg_count)
{
LPBYTE out_data = NULL;
......@@ -187,6 +200,36 @@ static LPBYTE get_regdata(LPWSTR data, DWORD reg_type, WCHAR separator, DWORD *r
((LPDWORD)out_data)[0] = val;
break;
}
case REG_BINARY:
{
static const WCHAR nohex[] = {'E','r','r','o','r',':',' ','/','d',' ','r','e','q','u','i','r','e','s',' ','h','e','x',' ','d','a','t','a','.','\n',0};
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);
if(datalen % 2)
{
hex1 = hexchar_to_byte(data[i++]);
if(hex1 == 0xFF)
goto no_hex_data;
out_data[destByteIndex++] = hex1;
}
for(;i + 1 < datalen;i += 2)
{
hex0 = hexchar_to_byte(data[i]);
hex1 = hexchar_to_byte(data[i + 1]);
if(hex0 == 0xFF || hex1 == 0xFF)
goto no_hex_data;
out_data[destByteIndex++] = (hex0 << 4) | hex1;
}
break;
no_hex_data:
/* cleanup, print error */
HeapFree(GetProcessHeap(), 0, out_data);
reg_printfW(nohex);
out_data = NULL;
break;
}
default:
{
static const WCHAR unhandled[] = {'U','n','h','a','n','d','l','e','d',' ','T','y','p','e',' ','0','x','%','x',' ',' ','d','a','t','a',' ','%','s','\n',0};
......
......@@ -214,7 +214,7 @@ static void test_add(void)
run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_BINARY /d deadbeef /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
dword = 0xefbeadde;
verify_reg(hkey, "", REG_BINARY, &dword, sizeof(DWORD), TODO_REG_SIZE);
verify_reg(hkey, "", REG_BINARY, &dword, sizeof(DWORD), 0);
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin1 /f /d 0xDeAdBeEf", &r);
todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
......@@ -235,8 +235,8 @@ static void test_add(void)
err = RegQueryValueExA(hkey, "bin4", NULL, &type, (void *) (buffer+12), &size);
ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
ok(type == REG_BINARY, "got wrong type %u\n", type);
todo_wine ok(size == 6, "got wrong size %u\n", size);
todo_wine ok(memcmp(buffer, buffer+12, 6) == 0 ||
ok(size == 6, "got wrong size %u\n", size);
ok(memcmp(buffer, buffer+12, 6) == 0 ||
broken(memcmp(buffer+6, buffer+12, 6) == 0 /* WinXP */), "got wrong data\n");
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin5 /d \"\" /f", &r);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment