📄 reg.c
字号:
if(CurrentTest > 7)
ok(!1, "Invalid Test Specified!\n");
CurrentTest++;
if(ValName)
pRtlFreeHeap(GetProcessHeap(), 0, ValName);
if(ValData)
pRtlFreeHeap(GetProcessHeap(), 0, ValData);
return ret;
}
static void test_RtlQueryRegistryValues(void)
{
/*
******************************
* QueryTable Flags *
******************************
*RTL_QUERY_REGISTRY_SUBKEY * Name is the name of a subkey relative to Path
*RTL_QUERY_REGISTRY_TOPKEY * Resets location to original RelativeTo and Path
*RTL_QUERY_REGISTRY_REQUIRED * Key required. returns STATUS_OBJECT_NAME_NOT_FOUND if not present
*RTL_QUERY_REGISTRY_NOVALUE * We just want a call-back
*RTL_QUERY_REGISTRY_NOEXPAND * Don't expand the variables!
*RTL_QUERY_REGISTRY_DIRECT * Results of query will be stored in EntryContext(QueryRoutine ignored)
*RTL_QUERY_REGISTRY_DELETE * Delete value key after query
******************************
**Test layout(numbered according to CurrentTest value)**
0)NOVALUE Just make sure call-back works
1)Null Name See if QueryRoutine is called for every value in current key
2)SUBKEY See if we can use SUBKEY to change the current path on the fly
3)REQUIRED Test for value that's not there
4)NOEXPAND See if it will return multiple strings(no expand should split strings up)
5)DIRECT Make it store data directly in EntryContext and not call QueryRoutine
6)DefaultType Test return values when key isn't present
7)DefaultValue Test Default Value returned with key isn't present(and no REQUIRED flag set)
8)DefaultLength Test Default Length with DefaultType = REG_SZ
9)DefaultLength Test Default Length with DefaultType = REG_MULTI_SZ
10)DefaultLength Test Default Length with DefaultType = REG_EXPAND_SZ
11)DefaultData Test whether DefaultData is used while DefaltType = REG_NONE(shouldn't be)
12)Delete Try to delete value key
*/
NTSTATUS status;
ULONG RelativeTo;
PRTL_QUERY_REGISTRY_TABLE QueryTable = NULL;
RelativeTo = RTL_REGISTRY_ABSOLUTE;/*Only using absolute - no need to test all relativeto variables*/
QueryTable = (PRTL_QUERY_REGISTRY_TABLE)pRtlAllocateHeap(GetProcessHeap(), 0, sizeof(RTL_QUERY_REGISTRY_TABLE)*26);
pRtlZeroMemory( QueryTable, sizeof(RTL_QUERY_REGISTRY_TABLE) * 26);
QueryTable[0].QueryRoutine = QueryRoutine;
QueryTable[0].Flags = RTL_QUERY_REGISTRY_NOVALUE;
QueryTable[0].Name = NULL;
QueryTable[0].EntryContext = NULL;
QueryTable[0].DefaultType = REG_BINARY;
QueryTable[0].DefaultData = NULL;
QueryTable[0].DefaultLength = 100;
QueryTable[1].QueryRoutine = QueryRoutine;
QueryTable[1].Flags = RTL_QUERY_REGISTRY_DELETE;
QueryTable[1].Name = L"multisztest";
QueryTable[1].EntryContext = 0;
QueryTable[1].DefaultType = REG_NONE;
QueryTable[1].DefaultData = NULL;
QueryTable[1].DefaultLength = 0;
QueryTable[2].QueryRoutine = QueryRoutine;
QueryTable[2].Flags = 0;
QueryTable[2].Name = NULL;
QueryTable[2].EntryContext = 0;
QueryTable[2].DefaultType = REG_NONE;
QueryTable[2].DefaultData = NULL;
QueryTable[2].DefaultLength = 0;
status = pRtlQueryRegistryValues(RelativeTo, winetestpath.Buffer, QueryTable, 0, 0);
ok(status == STATUS_SUCCESS, "RtlQueryRegistryValues return: 0x%08lx\n", status);
pRtlFreeHeap(GetProcessHeap(), 0, QueryTable);
}
static void test_NtCreateKey(void)
{
/*Create WineTest*/
OBJECT_ATTRIBUTES attr;
HANDLE key;
ACCESS_MASK am = GENERIC_ALL;
NTSTATUS status;
InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0);
status = pNtCreateKey(&key, am, &attr, 0, 0, 0, 0);
ok(status == STATUS_SUCCESS, "NtCreateKey Failed: 0x%08lx\n", status);
pNtClose(key);
}
static void test_NtSetValueKey(void)
{
HANDLE key;
NTSTATUS status;
OBJECT_ATTRIBUTES attr;
ACCESS_MASK am = KEY_WRITE;
UNICODE_STRING ValName;
UNICODE_STRING ValNameMultiSz;
DWORD data = 711;
static const WCHAR DataMultiSz[] = {'T','e','s','t','V','a','l','u','e','1',0,
'T','e','s','t','V','a','l','u','e','2',0,
'T','e','s','t','V','a','l','u','e','3',0,0,
'T','e','s','t','V','a','l','u','e','5',0,0,0};
pRtlCreateUnicodeStringFromAsciiz(&ValName, "deletetest");
InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0);
status = pNtOpenKey(&key, am, &attr);
ok(status == STATUS_SUCCESS, "NtOpenKey Failed: 0x%08lx\n", status);
status = pNtSetValueKey(key, &ValName, 0, REG_DWORD, &data, sizeof(data));
ok(status == STATUS_SUCCESS, "NtSetValueKey Failed: 0x%08lx\n", status);
pRtlFreeUnicodeString(&ValName);
pRtlCreateUnicodeStringFromAsciiz(&ValNameMultiSz, "multisztest");
status = pNtSetValueKey(key, &ValNameMultiSz, 0, REG_MULTI_SZ, (PVOID)DataMultiSz, sizeof(DataMultiSz));
ok(status == STATUS_SUCCESS, "NtSetValueKey Failed: 0x%08lx\n", status);
pRtlFreeUnicodeString(&ValNameMultiSz);
pNtClose(key);
}
static void test_RtlOpenCurrentUser(void)
{
NTSTATUS status;
HANDLE handle;
status=pRtlOpenCurrentUser(KEY_READ, &handle);
ok(status == STATUS_SUCCESS, "RtlOpenCurrentUser Failed: 0x%08lx\n", status);
pNtClose(handle);
}
static void test_RtlCheckRegistryKey(void)
{
NTSTATUS status;
status = pRtlCheckRegistryKey(RTL_REGISTRY_ABSOLUTE, winetestpath.Buffer);
ok(status == STATUS_SUCCESS, "RtlCheckRegistryKey with RTL_REGISTRY_ABSOLUTE: 0x%08lx\n", status);
status = pRtlCheckRegistryKey((RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL), winetestpath.Buffer);
ok(status == STATUS_SUCCESS, "RtlCheckRegistryKey with RTL_REGISTRY_ABSOLUTE and RTL_REGISTRY_OPTIONAL: 0x%08lx\n", status);
}
static void test_RtlQueryRegistryDelete(void)
{
HANDLE key;
NTSTATUS status;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING ValNameMultiSz;
WCHAR sBuf[255];
DWORD ValueSize;
InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0);
status = pNtOpenKey(&key, KEY_READ, &attr);
ok(status == STATUS_SUCCESS, "NtOpenKey Failed: 0x%08lx\n", status);
pRtlCreateUnicodeStringFromAsciiz(&ValNameMultiSz, "multisztest");
status = pNtQueryValueKey(key, &ValNameMultiSz, 0, (void*)sBuf, sizeof(sBuf), &ValueSize);
ok(status == STATUS_OBJECT_NAME_NOT_FOUND, "NtOpenKey returns: 0x%08lx instead of STATUS_OBJECT_NAME_NOT_FOUND\n", status);
pRtlFreeUnicodeString(&ValNameMultiSz);
pNtClose(key);
}
static void test_NtDeleteKey(void)
{
NTSTATUS status;
HANDLE hkey;
OBJECT_ATTRIBUTES attr;
ACCESS_MASK am = KEY_ALL_ACCESS;
InitializeObjectAttributes(&attr, &winetestpath, 0, 0, 0);
status = pNtOpenKey(&hkey, am, &attr);
status = pNtDeleteKey(hkey);
ok(status == STATUS_SUCCESS, "NtDeleteKey Failed: 0x%08lx\n", status);
pNtClose(hkey);
}
START_TEST(reg)
{
static const WCHAR winetest[] = {'\\','W','i','n','e','T','e','s','t','\\',0};
if(!InitFunctionPtrs())
return;
pRtlFormatCurrentUserKeyPath(&winetestpath);
winetestpath.Buffer = (PWSTR)pRtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, winetestpath.Buffer,
winetestpath.MaximumLength + sizeof(winetest)*sizeof(WCHAR));
winetestpath.MaximumLength = winetestpath.MaximumLength + sizeof(winetest)*sizeof(WCHAR);
pRtlAppendUnicodeToString(&winetestpath, winetest);
test_NtCreateKey();
test_NtSetValueKey();
test_RtlCheckRegistryKey();
test_RtlOpenCurrentUser();
test_RtlQueryRegistryValues();
test_RtlQueryRegistryDelete();
test_NtDeleteKey();
pRtlFreeUnicodeString(&winetestpath);
FreeLibrary(hntdll);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -