Skip to content

Commit 4fb7860

Browse files
committed
Common (Windows): uses RtlOpenCurrentUser directly
1 parent f188e95 commit 4fb7860

2 files changed

Lines changed: 6 additions & 17 deletions

File tree

src/common/windows/nt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,9 @@ NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(
12311231
_Out_ PULONG ResultLength
12321232
);
12331233

1234-
NTSYSAPI NTSTATUS NTAPI RtlFormatCurrentUserKeyPath(
1235-
_Out_ PUNICODE_STRING CurrentUserKeyPath
1234+
NTSYSAPI NTSTATUS NTAPI RtlOpenCurrentUser(
1235+
_In_ ACCESS_MASK DesiredAccess,
1236+
_Out_ PHANDLE CurrentUserKey
12361237
);
12371238

12381239
typedef struct _KEY_VALUE_PARTIAL_INFORMATION

src/common/windows/registry.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,15 @@ HANDLE ffRegGetRootKeyHandle(HKEY hKey)
4242
switch ((uintptr_t) hKey)
4343
{
4444
case (uintptr_t) HKEY_CURRENT_USER: {
45-
UNICODE_STRING path = {};
46-
NTSTATUS status = RtlFormatCurrentUserKeyPath(&path);
45+
NTSTATUS status = RtlOpenCurrentUser(KEY_READ, &result);
4746
if (!NT_SUCCESS(status))
4847
{
49-
FF_DEBUG("RtlFormatCurrentUserKeyPath() failed: %s", ffDebugNtStatus(status));
48+
FF_DEBUG("RtlOpenCurrentUser() failed: %s", ffDebugNtStatus(status));
5049
return NULL;
5150
}
52-
status = NtOpenKey(&result, KEY_READ, &(OBJECT_ATTRIBUTES) {
53-
.Length = sizeof(OBJECT_ATTRIBUTES),
54-
.RootDirectory = NULL,
55-
.ObjectName = &path,
56-
});
57-
if (!NT_SUCCESS(status))
58-
{
59-
FF_DEBUG("NtOpenKey(%ls) failed: %s (0x%08lx)", path.Buffer, ffDebugNtStatus(status), status);
60-
RtlFreeUnicodeString(&path);
61-
return NULL;
62-
}
63-
RtlFreeUnicodeString(&path);
6451
break;
6552
}
53+
6654
case (uintptr_t) HKEY_LOCAL_MACHINE: {
6755
UNICODE_STRING path = RTL_CONSTANT_STRING(L"\\Registry\\Machine");
6856
NTSTATUS status = NtOpenKey(&result, KEY_READ, &(OBJECT_ATTRIBUTES) {

0 commit comments

Comments
 (0)