From 4fb7860a8e0c7a61e54702c0eb4179e0f17a0e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 22 Mar 2026 19:52:41 +0800 Subject: [PATCH] Common (Windows): uses `RtlOpenCurrentUser` directly --- src/common/windows/nt.h | 5 +++-- src/common/windows/registry.c | 18 +++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/common/windows/nt.h b/src/common/windows/nt.h index f855f90cd..f7acbf61f 100644 --- a/src/common/windows/nt.h +++ b/src/common/windows/nt.h @@ -1231,8 +1231,9 @@ NTSYSAPI NTSTATUS NTAPI NtQueryValueKey( _Out_ PULONG ResultLength ); -NTSYSAPI NTSTATUS NTAPI RtlFormatCurrentUserKeyPath( - _Out_ PUNICODE_STRING CurrentUserKeyPath +NTSYSAPI NTSTATUS NTAPI RtlOpenCurrentUser( + _In_ ACCESS_MASK DesiredAccess, + _Out_ PHANDLE CurrentUserKey ); typedef struct _KEY_VALUE_PARTIAL_INFORMATION diff --git a/src/common/windows/registry.c b/src/common/windows/registry.c index 52e5dca63..f57535c73 100644 --- a/src/common/windows/registry.c +++ b/src/common/windows/registry.c @@ -42,27 +42,15 @@ HANDLE ffRegGetRootKeyHandle(HKEY hKey) switch ((uintptr_t) hKey) { case (uintptr_t) HKEY_CURRENT_USER: { - UNICODE_STRING path = {}; - NTSTATUS status = RtlFormatCurrentUserKeyPath(&path); + NTSTATUS status = RtlOpenCurrentUser(KEY_READ, &result); if (!NT_SUCCESS(status)) { - FF_DEBUG("RtlFormatCurrentUserKeyPath() failed: %s", ffDebugNtStatus(status)); + FF_DEBUG("RtlOpenCurrentUser() failed: %s", ffDebugNtStatus(status)); return NULL; } - status = NtOpenKey(&result, KEY_READ, &(OBJECT_ATTRIBUTES) { - .Length = sizeof(OBJECT_ATTRIBUTES), - .RootDirectory = NULL, - .ObjectName = &path, - }); - if (!NT_SUCCESS(status)) - { - FF_DEBUG("NtOpenKey(%ls) failed: %s (0x%08lx)", path.Buffer, ffDebugNtStatus(status), status); - RtlFreeUnicodeString(&path); - return NULL; - } - RtlFreeUnicodeString(&path); break; } + case (uintptr_t) HKEY_LOCAL_MACHINE: { UNICODE_STRING path = RTL_CONSTANT_STRING(L"\\Registry\\Machine"); NTSTATUS status = NtOpenKey(&result, KEY_READ, &(OBJECT_ATTRIBUTES) {