diff --git a/dll/advapi32/winreg.cpp b/dll/advapi32/winreg.cpp index 2ec1eb6..10003c8 100644 --- a/dll/advapi32/winreg.cpp +++ b/dll/advapi32/winreg.cpp @@ -6,6 +6,7 @@ #include "handles.h" #include "strutil.h" +#include #include #include #include @@ -115,12 +116,8 @@ Pin handleDataFromHKeyLocked(HKEY hKey) { bool isPredefinedKeyHandle(HKEY hKey) { uintptr_t raw = reinterpret_cast(hKey); - for (const auto &kPredefinedKeyInfo : kPredefinedKeyInfos) { - if (kPredefinedKeyInfo.value == raw) { - return true; - } - } - return false; + return std::any_of(std::begin(kPredefinedKeyInfos), std::end(kPredefinedKeyInfos), + [raw](const PredefinedKeyInfo &info) { return info.value == raw; }); } } // namespace diff --git a/dll/kernel32/handleapi.cpp b/dll/kernel32/handleapi.cpp index 92f52d8..53a6e3f 100644 --- a/dll/kernel32/handleapi.cpp +++ b/dll/kernel32/handleapi.cpp @@ -37,22 +37,22 @@ BOOL WIN_FUNC DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, return FALSE; } + auto &handles = wibo::handles(); if (isPseudoCurrentProcessHandle(hSourceHandle)) { auto po = make_pin(getpid(), -1); - auto handle = wibo::handles().alloc(std::move(po), 0, 0); + auto handle = handles.alloc(std::move(po), 0, 0); DEBUG_LOG("DuplicateHandle: created process handle for current process -> %p\n", handle); *lpTargetHandle = handle; return TRUE; } else if (isPseudoCurrentThreadHandle(hSourceHandle)) { auto th = make_pin(pthread_self()); - auto handle = wibo::handles().alloc(std::move(th), 0, 0); + auto handle = handles.alloc(std::move(th), 0, 0); DEBUG_LOG("DuplicateHandle: created thread handle for current thread -> %p\n", handle); *lpTargetHandle = handle; return TRUE; } - if (!wibo::handles().duplicateTo(hSourceHandle, wibo::handles(), *lpTargetHandle, dwDesiredAccess, bInheritHandle, - dwOptions)) { + if (!handles.duplicateTo(hSourceHandle, handles, *lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions)) { wibo::lastError = ERROR_INVALID_HANDLE; return FALSE; } diff --git a/src/handles.cpp b/src/handles.cpp index ab953aa..3e880e7 100644 --- a/src/handles.cpp +++ b/src/handles.cpp @@ -187,7 +187,7 @@ bool Handles::duplicateTo(HANDLE src, Handles &dst, HANDLE &out, uint32_t desire uint32_t effAccess = (options & DUPLICATE_SAME_ACCESS) ? meta.grantedAccess : (desiredAccess & meta.grantedAccess); const uint32_t flags = (inherit ? HANDLE_FLAG_INHERIT : 0); - // Reuse the same handle if duplicating within the same table and no changes + // Reuse the same handle if duplicating with DUPLICATE_CLOSE_SOURCE within the same table and no changes if (&dst == this && closeSource && effAccess == meta.grantedAccess && flags == meta.flags) { out = src; return true;