From b039048ea9ff63731c6aa6a1f129303e07417a41 Mon Sep 17 00:00:00 2001 From: mingkuang Date: Sun, 1 Oct 2023 19:50:37 +0800 Subject: [PATCH] =?UTF-8?q?Fea=20#29=EF=BC=8CFindFirstFileEx=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0Windows=20XP=E3=80=81Vista=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=20FIND=5FFIRST=5FEX=5FLARGE=5FFETCH=E3=80=81FindExInfoStandard?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThunksList.md | 1 + src/Thunks/api-ms-win-core-file.hpp | 78 +++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/ThunksList.md b/ThunksList.md index 98e2e7f..aa94114 100644 --- a/ThunksList.md +++ b/ThunksList.md @@ -292,6 +292,7 @@ | RtlCaptureStackBackTrace | 调用ntdll.RtlCaptureStackBackTrace。 | SetFileCompletionNotificationModes | 不存在时,什么也不做。 | GetQueuedCompletionStatusEx | 不存在时,调用 GetQueuedCompletionStatus,注意:丢失可警报状态支持。 +| FindFirstFileEx(W/A) | Windows XP、Vista兼容 FIND_FIRST_EX_LARGE_FETCH、FindExInfoStandard参数。 ## mfplat.dll | 函数 | Fallback diff --git a/src/Thunks/api-ms-win-core-file.hpp b/src/Thunks/api-ms-win-core-file.hpp index dfb5ae2..027304f 100644 --- a/src/Thunks/api-ms-win-core-file.hpp +++ b/src/Thunks/api-ms-win-core-file.hpp @@ -1222,6 +1222,84 @@ namespace YY } #endif +#if (YY_Thunks_Support_Version < NTDDI_WIN7) + + // 最低受支持的客户端 Windows XP [桌面应用 |UWP 应用] + // 最低受支持的服务器 Windows Server 2003[桌面应用 | UWP 应用] + __DEFINE_THUNK( + kernel32, + 24, + HANDLE, + WINAPI, + FindFirstFileExW, + _In_ LPCWSTR lpFileName, + _In_ FINDEX_INFO_LEVELS fInfoLevelId, + _Out_writes_bytes_(sizeof(WIN32_FIND_DATAW)) LPVOID lpFindFileData, + _In_ FINDEX_SEARCH_OPS fSearchOp, + _Reserved_ LPVOID lpSearchFilter, + _In_ DWORD dwAdditionalFlags + ) + { + if (const auto _pfnFindFirstFileExW = try_get_FindFirstFileExW()) + { + const auto _uMajorVersion = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock->OSMajorVersion; + const auto _uMinorVersion = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock->OSMinorVersion; + + if (internal::MakeVersion(_uMajorVersion, _uMinorVersion) < internal::MakeVersion(6, 1)) + { + // dwAdditionalFlags : Windows 7开始才支持 FIND_FIRST_EX_LARGE_FETCH + dwAdditionalFlags &= (FIND_FIRST_EX_CASE_SENSITIVE | FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY); + + // Windows 7开始才支持 FindExInfoBasic + fInfoLevelId = FindExInfoStandard; + } + + + return _pfnFindFirstFileExW(lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags); + } + + return FindFirstFileW(lpFileName, (WIN32_FIND_DATAW*)lpFindFileData); + } +#endif + +#if (YY_Thunks_Support_Version < NTDDI_WIN7) + + // 最低受支持的客户端 Windows XP [桌面应用 |UWP 应用] + // 最低受支持的服务器 Windows Server 2003[桌面应用 | UWP 应用] + __DEFINE_THUNK( + kernel32, + 24, + HANDLE, + WINAPI, + FindFirstFileExA, + _In_ LPCSTR lpFileName, + _In_ FINDEX_INFO_LEVELS fInfoLevelId, + _Out_writes_bytes_(sizeof(WIN32_FIND_DATAA)) LPVOID lpFindFileData, + _In_ FINDEX_SEARCH_OPS fSearchOp, + _Reserved_ LPVOID lpSearchFilter, + _In_ DWORD dwAdditionalFlags + ) + { + if (const auto _pfnFindFirstFileExA = try_get_FindFirstFileExA()) + { + const auto _uMajorVersion = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock->OSMajorVersion; + const auto _uMinorVersion = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock->OSMinorVersion; + + if (internal::MakeVersion(_uMajorVersion, _uMinorVersion) < internal::MakeVersion(6, 1)) + { + // dwAdditionalFlags : Windows 7开始才支持 FIND_FIRST_EX_LARGE_FETCH + dwAdditionalFlags &= (FIND_FIRST_EX_CASE_SENSITIVE | FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY); + + // Windows 7开始才支持 FindExInfoBasic + fInfoLevelId = FindExInfoStandard; + } + + return _pfnFindFirstFileExA(lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags); + } + + return FindFirstFileA(lpFileName, (WIN32_FIND_DATAA*)lpFindFileData); + } +#endif }//namespace Thunks } //namespace YY \ No newline at end of file