Skip to content

Commit

Permalink
Opt, 统一废除WinSDK的NTDDI版本号,改用YY-Thunks自建版本号,便于未来细分行为
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jun 29, 2024
1 parent e5afe74 commit 545348f
Show file tree
Hide file tree
Showing 91 changed files with 20,280 additions and 20,224 deletions.
2 changes: 1 addition & 1 deletion ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
## dwrite.dll
| 函数 | Fallback
| ---- | -----------
| DWriteCreateFactory | 不存在时,返回 `E_NOINTERFACE`
| DWriteCreateFactory | 不存在时,返回 `E_NOINTERFACE`</br>此外NT6或者更高版本提供IDWriteFactory3模拟。

## dxgi.dll
| 函数 | Fallback
Expand Down
41 changes: 20 additions & 21 deletions src/Build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ goto:eof
:BuildObj
echo BuildObj %1 %2 %3

cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Support_Version=%2" "%~dp0Thunks\YY_Thunks.cpp"
cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Target=%2" "%~dp0Thunks\YY_Thunks.cpp"
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

::生成weak符号,一些非必须符号安排为weak可以避免链接失败
Expand All @@ -52,7 +52,7 @@ echo BuildLib %1 %2 %3

md "Lib\\%1\\%Platform%"

cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Support_Version=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp"
cl /O1 /Os /Oi /GS- /std:c++17 /execution-charset:utf-8 /arch:IA32 /Z7 /MT /Fo"Lib\\%1\\%Platform%\\YY_Thunks_for_%1.obj" /Zl /c /D "__APPLY_CHROMIUM_WORKAROUNDS" /D "__USING_NTDLL_LIB" /D "NDEBUG" /D "YY_Thunks_Target=%2" /D "__FALLBACK_PREFIX=YY_Thunks_" "%~dp0Thunks\YY_Thunks.cpp"

if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

Expand Down Expand Up @@ -95,72 +95,71 @@ goto:eof

:Buildx86
set PointType=4
call:BuildX 5.0.2195.0 YY_Thunks_for_Win2K.obj NTDDI_WIN2K PSAPI2Kernel32.def+esent.def
call:BuildX 5.0.2195.0 YY_Thunks_for_Win2K.obj __WindowsNT5 PSAPI2Kernel32.def+esent.def
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 5.1.2600.0 YY_Thunks_for_WinXP.obj NTDDI_WINXP PSAPI2Kernel32.def+esent.def
call:BuildX 5.1.2600.0 YY_Thunks_for_WinXP.obj __WindowsNT5_1 PSAPI2Kernel32.def+esent.def
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.0.6000.0 YY_Thunks_for_Vista.obj NTDDI_WIN6 PSAPI2Kernel32.def
call:BuildX 6.0.6000.0 YY_Thunks_for_Vista.obj __WindowsNT6 PSAPI2Kernel32.def
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.1.7600.0 YY_Thunks_for_Win7.obj NTDDI_WIN7
call:BuildX 6.1.7600.0 YY_Thunks_for_Win7.obj __WindowsNT6_1
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj NTDDI_WIN8
call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj __WindowsNT6_2
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj NTDDI_WIN10
call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj __WindowsNT10_10240
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj NTDDI_WIN10_VB
call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj __WindowsNT10_19041
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

goto:eof


:Buildx64
set PointType=8
call:BuildX 5.2.3790.1180 YY_Thunks_for_WinXP.obj NTDDI_WS03SP1 PSAPI2Kernel32.def+esent.def
call:BuildX 5.2.3790.1830 YY_Thunks_for_WinXP.obj __WindowsNT5_2_SP1 PSAPI2Kernel32.def+esent.def
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.0.6000.0 YY_Thunks_for_Vista.obj NTDDI_WIN6 PSAPI2Kernel32.def
call:BuildX 6.0.6000.0 YY_Thunks_for_Vista.obj __WindowsNT6 PSAPI2Kernel32.def
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.1.7600.0 YY_Thunks_for_Win7.obj NTDDI_WIN7
call:BuildX 6.1.7600.0 YY_Thunks_for_Win7.obj __WindowsNT6_1
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj NTDDI_WIN8
call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj __WindowsNT6_2
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj NTDDI_WIN10
call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj __WindowsNT10_10240
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj NTDDI_WIN10_VB
call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj __WindowsNT10_19041
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

goto:eof

:Buildarm
set PointType=4
call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj NTDDI_WIN8
call:BuildX 6.2.9200.0 YY_Thunks_for_Win8.obj __WindowsNT6_2
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj NTDDI_WIN10
call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj __WindowsNT10_10240
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj NTDDI_WIN10_VB
call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj __WindowsNT10_19041
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

goto:eof

:Buildarm64
set PointType=8
; NTDDI_WIN10_RS3 = 16299
call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj NTDDI_WIN10_RS3
call:BuildX 10.0.10240.0 YY_Thunks_for_Win10.0.10240.obj __WindowsNT10_16299
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj NTDDI_WIN10_VB
call:BuildX 10.0.19041.0 YY_Thunks_for_Win10.0.19041.obj __WindowsNT10_19041
if %ErrorLevel% NEQ 0 exit /b %ErrorLevel%

goto:eof
79 changes: 79 additions & 0 deletions src/Shared/SharedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,82 @@
using _Type = std::underlying_type<_ENUM>::type; \
return (_Type)_eLeft & (_Type)_eRight; \
}

#define __Version(Major, Minor, Build, Revision) (Major * 0x1000000000000ull + Minor * 0x100000000ull + Build * 0x10000ull + Revision)

// 版本号参考来源:
// https://github.com/MouriNaruto/MouriDocs/tree/main/docs/18

// Windows 2000 RTM x86
#define __WindowsNT5 __Version(5, 0, 2195, 0)

// Windows XP RTM x86
#define __WindowsNT5_1 __Version(5, 1, 2600, 0)

#define __WindowsNT5_1_SP1 __Version(5, 1, 2600, 1106)

#define __WindowsNT5_1_SP2 __Version(5, 1, 2600, 2180)

#define __WindowsNT5_1_SP3 __Version(5, 1, 2600, 5512)

// Windows 2003 RTM x86
#define __WindowsNT5_2 __Version(5, 2, 3790, 0)

// Windows XP RTM x64,Windows 2003 SP1
#define __WindowsNT5_2_SP1 __Version(5, 2, 3790, 1830)

// Windows Vista RTM, Windows Server 2008 RTM
#define __WindowsNT6 __Version(6, 0, 6000, 0)

#define __WindowsNT6_SP1 __Version(6, 0, 6001, 0)

#define __WindowsNT6_SP2 __Version(6, 0, 6002, 0)

// Windows 7 RTM, Windows Server 2008 R2 RTM
#define __WindowsNT6_1 __Version(6, 1, 7600, 0)

#define __WindowsNT6_1_SP1 __Version(6, 1, 7601, 0)

// Windows 8 RTM, Windows Server 2012 RTM
#define __WindowsNT6_2 __Version(6, 2, 9200, 0)

// Windows 8.1 RTM, Windows Server 2012 R2 RTM
#define __WindowsNT6_3 __Version(6, 3, 9600, 0)

// Windows 10 1507
#define __WindowsNT10_10240 __Version(10, 0, 10240, 0)

// Windows 10 1607(RS1)
#define __WindowsNT10_14393 __Version(10, 0, 14393, 0)

// Windows 10 1703(RS2)
#define __WindowsNT10_15063 __Version(10, 0, 15063, 0)

// Windows 10 1709(RS3),注意ARM64从这个版本开始才支持。
#define __WindowsNT10_16299 __Version(10, 0, 16299, 0)

// Windows 10 2004(VB)
#define __WindowsNT10_19041 __Version(10, 0, 19041, 0)

// Windows Server 2022(FE)
#define __WindowsNT10_20348 __Version(10, 0, 20348, 0)

#if defined(_M_IX86)
#define __WindowsMinTarget __WindowsNT5
#elif defined(_M_AMD64)
#define __WindowsMinTarget __WindowsNT5_2_SP1
#elif defined(_M_ARM)
#define __WindowsMinTarget __WindowsNT6_2
#elif defined(_M_ARM64)
#define __WindowsMinTarget __WindowsNT10_16299
#endif

#ifndef YY_Thunks_Target
#define YY_Thunks_Target __WindowsMinTarget
#endif

// 输错了版本号?
#if YY_Thunks_Target < __WindowsMinTarget
#undef YY_Thunks_Target
#define YY_Thunks_Target __WindowsMinTarget
#endif
28 changes: 14 additions & 14 deletions src/Thunks/BCryptPrimitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ extern "C" BOOL WINAPI ProcessPrng(

namespace YY::Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_WIN8)
#if (YY_Thunks_Target < __WindowsNT6_2)

// 用户反馈Windows 7也会报告此API不存在。
__DEFINE_THUNK(
bcryptprimitives,
8,
BOOL,
WINAPI,
ProcessPrng,
// 用户反馈Windows 7也会报告此API不存在。
__DEFINE_THUNK(
bcryptprimitives,
8,
BOOL,
WINAPI,
ProcessPrng,
_Out_writes_bytes_(_cbBuffer) PUCHAR _pbBuffer,
_In_ ULONG _cbBuffer
)
{
if (auto _pfnProcessPrng = try_get_ProcessPrng())
{
return _pfnProcessPrng(_pbBuffer, _cbBuffer);
}
{
if (auto _pfnProcessPrng = try_get_ProcessPrng())
{
return _pfnProcessPrng(_pbBuffer, _cbBuffer);
}

const auto _pfnRtlGenRandom = try_get_SystemFunction036();
if (!_pfnRtlGenRandom)
Expand All @@ -32,6 +32,6 @@ namespace YY::Thunks
}

return _pfnRtlGenRandom(_pbBuffer, _cbBuffer);
}
}
#endif
} // namespace YY::Thunks
16 changes: 8 additions & 8 deletions src/Thunks/CfgMgr32.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)
#include <cfgmgr32.h>
#include <SetupAPI.h>
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7) && !defined(__Comment_Lib_setupapi)
#if (YY_Thunks_Target < __WindowsNT6_1) && !defined(__Comment_Lib_setupapi)
#define __Comment_Lib_setupapi
#pragma comment(lib, "SetupAPI.Lib")
#endif

#if (YY_Thunks_Support_Version < NTDDI_WIN7) && __YY_Thunks_libs && !defined(__Comment_Lib_cfgmgr32)
#if (YY_Thunks_Target < __WindowsNT6_1) && __YY_Thunks_libs && !defined(__Comment_Lib_cfgmgr32)
#define __Comment_Lib_cfgmgr32
#pragma comment(lib, "cfgmgr32.Lib")
#endif
Expand All @@ -18,7 +18,7 @@ namespace YY::Thunks::Fallback
{
namespace
{
#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)
struct DevNodeTempPropertyBufffer
{
wchar_t szId[39];
Expand Down Expand Up @@ -251,7 +251,7 @@ namespace YY::Thunks::Fallback

namespace YY::Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)

// Windows 7 RTM 导出
// Windows Vista有这个函数但是没有导出
Expand Down Expand Up @@ -311,7 +311,7 @@ namespace YY::Thunks
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)

// Windows 7 RTM 导出
// Windows Vista有这个函数但是没有导出
Expand Down Expand Up @@ -360,7 +360,7 @@ namespace YY::Thunks
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)

// 最低受支持的客户端 在 Microsoft Windows Vista 和更高版本的 Windows 中可用。
// 实际Windows Vista RTM根本就没有这个接口
Expand Down Expand Up @@ -388,7 +388,7 @@ namespace YY::Thunks
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN7)
#if (YY_Thunks_Target < __WindowsNT6_1)

// 最低受支持的客户端 在 Microsoft Windows Vista 和更高版本的 Windows 中可用。
// 实际Windows Vista RTM根本就没有这个接口
Expand Down
Loading

0 comments on commit 545348f

Please sign in to comment.