Thomas Faller : reg: Implement binary data add operation.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Sep 7 09:20:13 CDT 2015
Module: wine
Branch: master
Commit: 5c9526cb6c6151d0f9093c1ac6bb3b7333c64feb
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5c9526cb6c6151d0f9093c1ac6bb3b7333c64feb
Author: Thomas Faller <tfaller1 at gmx.de>
Date: Sun Sep 6 16:07:18 2015 +0200
reg: Implement binary data add operation.
---
programs/reg/reg.c | 43 +++++++++++++++++++++++++++++++++++++++++++
programs/reg/tests/reg.c | 6 +++---
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 4ec25bc..e4d121c 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -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};
diff --git a/programs/reg/tests/reg.c b/programs/reg/tests/reg.c
index dbfce89..2880d37 100644
--- a/programs/reg/tests/reg.c
+++ b/programs/reg/tests/reg.c
@@ -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);
More information about the wine-cvs
mailing list