reg-Implement_Query: Updated patchset.

This commit is contained in:
Sebastian Lackner 2016-03-27 18:53:12 +02:00
parent e83d9c4233
commit 0a391faaba
3 changed files with 63 additions and 58 deletions

View File

@ -5820,8 +5820,8 @@ if test "$enable_reg_Implement_Query" -eq 1; then
patch_apply reg-Implement_Query/0001-reg-Query-all-values-and-subkeys-in-a-specified-key.patch
patch_apply reg-Implement_Query/0002-reg-Add-support-for-querying-the-registry-with-the-v.patch
(
echo '+ { "Hugh McMaster", "reg: Query all values and subkeys in a specified key.", 1 },';
echo '+ { "Hugh McMaster", "reg: Add support for querying the registry with the /v and /ve switches.", 1 },';
echo '+ { "Hugh McMaster", "reg: Query all values and subkeys in a specified key.", 2 },';
echo '+ { "Hugh McMaster", "reg: Add support for querying the registry with the /v and /ve switches.", 2 },';
) >> "$patchlist"
fi

View File

@ -1,20 +1,20 @@
From 52a65aa581b8bdcc972efcb8f8a9320481124812 Mon Sep 17 00:00:00 2001
From 47f219c26491fdffccf4b74e319daf80baf06de6 Mon Sep 17 00:00:00 2001
From: Hugh McMaster <hugh.mcmaster@outlook.com>
Date: Thu, 17 Mar 2016 16:10:25 +1100
Subject: reg: Query all values and subkeys in a specified key
Subject: reg: Query all values and subkeys in a specified key (v2)
Displays all values and subkeys in a specified key. Recursion is supported.
Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
---
programs/reg/reg.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 286 insertions(+), 8 deletions(-)
programs/reg/reg.c | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 291 insertions(+), 7 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 9dbce32..75c5292 100644
index b2066e0..ab04ee9 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -546,14 +546,292 @@ static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
@@ -536,14 +536,298 @@ static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
return 0;
}
@ -22,8 +22,7 @@ index 9dbce32..75c5292 100644
- BOOL subkey)
+static WCHAR *reg_data_to_wchar(DWORD type, const BYTE *src, DWORD size_bytes)
{
+ WCHAR *buffer = NULL, *ptr = NULL;
+ WCHAR hex_fmt[] = {'%','0','2','x',0};
+ WCHAR *buffer = NULL;
+ int i;
+
+ switch (type)
@ -35,24 +34,31 @@ index 9dbce32..75c5292 100644
+ strcpyW(buffer, (WCHAR *)src);
+ break;
+ case REG_BINARY:
+ {
+ WCHAR *ptr;
+ WCHAR fmt[] = {'%','0','2','x',0};
+
+ buffer = HeapAlloc(GetProcessHeap(), 0, (size_bytes * 2 + 1) * sizeof(WCHAR));
+ ptr = buffer;
+ for (i = 0; i < size_bytes; i++)
+ ptr += sprintfW(ptr, hex_fmt, src[i]);
+ ptr += sprintfW(ptr, fmt, src[i]);
+ break;
+ }
+ case REG_DWORD:
+ /* case REG_DWORD_LITTLE_ENDIAN: */
+ case REG_DWORD_BIG_ENDIAN:
+ {
+ DWORD value = 0;
+ const int zero_x_dword = 10;
+ WCHAR zero_x[] = {'0','x',0};
+
+ buffer = HeapAlloc(GetProcessHeap(), 0, (zero_x_dword + 1) * sizeof(WCHAR));
+ strcpyW(buffer, zero_x);
+ ptr = buffer + 2;
+ WCHAR fmt[] = {'0','x','%','x',0};
+
+ for (i = size_bytes; i-- > 0;)
+ ptr += sprintfW(ptr, hex_fmt, src[i]);
+ {
+ value <<= 8;
+ value |= src[i];
+ }
+ buffer = HeapAlloc(GetProcessHeap(), 0, (zero_x_dword + 1) * sizeof(WCHAR));
+ sprintfW(buffer, fmt, value);;
+ break;
+ }
+ case REG_MULTI_SZ:
@ -102,7 +108,6 @@ index 9dbce32..75c5292 100644
+ if (type == type_rels[i].type)
+ return type_rels[i].name;
+ }
+
+ return NULL;
+}
+
@ -127,12 +132,12 @@ index 9dbce32..75c5292 100644
+ output_string(newlineW);
+}
+
+static WCHAR *build_subkey_path(WCHAR *path, WCHAR *subkey_name, DWORD len)
+static WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
+{
+ WCHAR *subkey_path;
+ WCHAR fmt[] = {'%','s','\\','%','s',0};
+
+ subkey_path = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
+ subkey_path = HeapAlloc(GetProcessHeap(), 0, (path_len + subkey_len + 2) * sizeof(WCHAR));
+ if (!subkey_path)
+ {
+ ERR("Failed to allocate memory for subkey_path\n");
@ -142,13 +147,13 @@ index 9dbce32..75c5292 100644
+ return subkey_path;
+}
+
+static int query_all(HKEY key, WCHAR *path, DWORD path_len, BOOL recurse)
+static int query_all(HKEY key, WCHAR *path, BOOL recurse)
+{
+ LONG rc;
+ DWORD num_subkeys, max_subkey_len, subkey_len, subkey_path_len;
+ DWORD num_subkeys, max_subkey_len, subkey_len;
+ DWORD num_values, max_value_len, value_len;
+ DWORD max_data_bytes, data_size;
+ DWORD type;
+ DWORD type, path_len;
+ WCHAR *value_name, *subkey_name, *subkey_path;
+ WCHAR fmt[] = {'%','1','\n',0};
+ WCHAR fmt_path[] = {'%','1','\\','%','2','\n',0};
@ -166,8 +171,6 @@ index 9dbce32..75c5292 100644
+ }
+
+ max_value_len++;
+ max_subkey_len++;
+
+ value_name = HeapAlloc(GetProcessHeap(), 0, max_value_len * sizeof(WCHAR));
+ if (!value_name)
+ {
@ -200,6 +203,7 @@ index 9dbce32..75c5292 100644
+ if (num_values || recurse)
+ output_string(newlineW);
+
+ max_subkey_len++;
+ subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR));
+ if (!subkey_name)
+ {
@ -207,6 +211,8 @@ index 9dbce32..75c5292 100644
+ return 1;
+ }
+
+ path_len = strlenW(path);
+
+ for (i = 0; i < num_subkeys; i++)
+ {
+ subkey_len = max_subkey_len;
@ -215,10 +221,9 @@ index 9dbce32..75c5292 100644
+ {
+ if (recurse)
+ {
+ subkey_path_len = path_len + subkey_len + 1;
+ subkey_path = build_subkey_path(path, subkey_name, subkey_path_len);
+ subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len);
+ RegOpenKeyExW(key, subkey_name, 0, KEY_READ, &subkey);
+ query_all(subkey, subkey_path, subkey_path_len, recurse);
+ query_all(subkey, subkey_path, recurse);
+ RegCloseKey(subkey);
+ HeapFree(GetProcessHeap(), 0, subkey_path);
+ }
@ -226,13 +231,16 @@ index 9dbce32..75c5292 100644
+ }
+ }
+
+ if (num_subkeys && !recurse)
+ output_string(newlineW);
+
+ HeapFree(GetProcessHeap(), 0, subkey_name);
+ return 0;
+}
+
+static WCHAR *get_long_path(HKEY root, WCHAR *path)
+{
+ int i, len;
+ DWORD i, len;
+ WCHAR *long_path;
+ WCHAR fmt[] = {'%','s','\\','%','s',0};
+
@ -262,10 +270,8 @@ index 9dbce32..75c5292 100644
+ WCHAR *p, *path;
+ HKEY root, key;
static const WCHAR stubW[] = {'S','T','U','B',' ','Q','U','E','R','Y',' ',
- '-',' ','%','1',' ','%','2',' ','%','3','!','d','!',' ','%','4','!','d','!','\n',0};
'-',' ','%','1',' ','%','2',' ','%','3','!','d','!',' ','%','4','!','d','!','\n',0};
- output_string(stubW, key_name, value_name, value_empty, subkey);
+ '-',' ','%','1',' ','%','2',' ','%','3','!','d','!',' ','%','4','!','d','!','\n',0};
+ DWORD path_len;
+ int ret;
+
+ if (!sane_path(key_name))
@ -294,7 +300,6 @@ index 9dbce32..75c5292 100644
+ }
+
+ path = get_long_path(root, p);
+ path_len = strlenW(path);
+
+ if (value_name || value_empty)
+ {
@ -302,7 +307,7 @@ index 9dbce32..75c5292 100644
+ return 1;
+ }
+
+ ret = query_all(key, path, path_len, recurse);
+ ret = query_all(key, path, recurse);
+
+ HeapFree(GetProcessHeap(), 0, path);
+ RegCloseKey(key);
@ -312,7 +317,7 @@ index 9dbce32..75c5292 100644
}
int wmain(int argc, WCHAR *argvW[])
@@ -677,7 +955,7 @@ int wmain(int argc, WCHAR *argvW[])
@@ -667,7 +951,7 @@ int wmain(int argc, WCHAR *argvW[])
else if (!lstrcmpiW(argvW[1], queryW))
{
WCHAR *key_name, *value_name = NULL;
@ -321,7 +326,7 @@ index 9dbce32..75c5292 100644
if (argc < 3)
{
@@ -705,9 +983,9 @@ int wmain(int argc, WCHAR *argvW[])
@@ -695,9 +979,9 @@ int wmain(int argc, WCHAR *argvW[])
else if (!lstrcmpiW(argvW[i], slashVEW))
value_empty = TRUE;
else if (!lstrcmpiW(argvW[i], slashSW))

View File

@ -1,8 +1,8 @@
From bf459e7bcaca10acae3f07756d4e63812e7da0c0 Mon Sep 17 00:00:00 2001
From 26a2b604e32ae517aed24313ddba4eaccd4e1e23 Mon Sep 17 00:00:00 2001
From: Hugh McMaster <hugh.mcmaster@outlook.com>
Date: Fri, 18 Mar 2016 15:50:31 +1100
Date: Sun, 27 Mar 2016 22:19:17 +1100
Subject: reg: Add support for querying the registry with the /v and /ve
switches
switches (v2)
Recursion is supported.
@ -12,21 +12,21 @@ Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
1 file changed, 80 insertions(+), 8 deletions(-)
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 75c5292..3722841 100644
index ab04ee9..8dd7e50 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -756,6 +756,83 @@ static int query_all(HKEY key, WCHAR *path, DWORD path_len, BOOL recurse)
@@ -754,6 +754,83 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
return 0;
}
+static int num_values_found = 0;
+
+static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, DWORD path_len, BOOL recurse)
+static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse)
+{
+ LONG rc;
+ DWORD num_subkeys, max_subkey_len, subkey_len, subkey_path_len;
+ DWORD num_subkeys, max_subkey_len, subkey_len;
+ DWORD max_data_bytes, data_size;
+ DWORD type;
+ DWORD type, path_len;
+ BYTE *data;
+ WCHAR fmt[] = {'%','1','\n',0};
+ WCHAR newlineW[] = {'\n',0};
@ -42,8 +42,6 @@ index 75c5292..3722841 100644
+ return 1;
+ }
+
+ max_subkey_len++;
+
+ data = HeapAlloc(GetProcessHeap(), 0, max_data_bytes);
+ if (!data)
+ {
@ -70,6 +68,7 @@ index 75c5292..3722841 100644
+ return 0;
+ }
+
+ max_subkey_len++;
+ subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR));
+ if (!subkey_name)
+ {
@ -77,16 +76,17 @@ index 75c5292..3722841 100644
+ return 1;
+ }
+
+ path_len = strlenW(path);
+
+ for (i = 0; i < num_subkeys; i++)
+ {
+ subkey_len = max_subkey_len;
+ rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
+ if (rc == ERROR_SUCCESS)
+ {
+ subkey_path_len = path_len + subkey_len + 1;
+ subkey_path = build_subkey_path(path, subkey_name, subkey_path_len);
+ subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len);
+ RegOpenKeyExW(key, subkey_name, 0, KEY_READ, &subkey);
+ query_value(subkey, value_name, subkey_path, subkey_path_len, recurse);
+ query_value(subkey, value_name, subkey_path, recurse);
+ RegCloseKey(subkey);
+ HeapFree(GetProcessHeap(), 0, subkey_path);
+ }
@ -98,18 +98,18 @@ index 75c5292..3722841 100644
+
static WCHAR *get_long_path(HKEY root, WCHAR *path)
{
int i, len;
@@ -787,8 +864,6 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL
DWORD i, len;
@@ -785,8 +862,6 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL
{
WCHAR *p, *path;
HKEY root, key;
- static const WCHAR stubW[] = {'S','T','U','B',' ','Q','U','E','R','Y',' ',
- '-',' ','%','1',' ','%','2',' ','%','3','!','d','!',' ','%','4','!','d','!','\n',0};
DWORD path_len;
- '-',' ','%','1',' ','%','2',' ','%','3','!','d','!',' ','%','4','!','d','!','\n',0};
int ret;
@@ -821,12 +896,9 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL
path_len = strlenW(path);
if (!sane_path(key_name))
@@ -817,12 +892,9 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL
path = get_long_path(root, p);
if (value_name || value_empty)
- {
@ -117,10 +117,10 @@ index 75c5292..3722841 100644
- return 1;
- }
-
- ret = query_all(key, path, path_len, recurse);
+ ret = query_value(key, value_name, path, path_len, recurse);
- ret = query_all(key, path, recurse);
+ ret = query_value(key, value_name, path, recurse);
+ else
+ ret = query_all(key, path, path_len, recurse);
+ ret = query_all(key, path, recurse);
HeapFree(GetProcessHeap(), 0, path);
RegCloseKey(key);