Skip to content

Commit

Permalink
Fea #83, Windows XP添加动态DLL TLS兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed May 25, 2024
1 parent 1f01599 commit 532d525
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ indent_size = 4
[*.{vcxproj,xml,nuspec,targets}]
indent_style = space
indent_size = 2

[*.cmd]
charset = unset
4 changes: 2 additions & 2 deletions .github/workflows/Build&Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ jobs:
$RunFaild = 0
&vstest.console src\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin32.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full /Diag:TestResults\Win32.log"
&vstest.console src\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin32.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full" "/Diag:TestResults\Win32.log"
if($lastexitcode -ne 0)
{
$RunFaild = 1
}
&vstest.console src\x64\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin64.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full /Diag:TestResults\Win64.log"
&vstest.console src\x64\Release\YY-Thunks.UnitTest.dll "/logger:trx;LogFileName=UnitTestWin64.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full" "/Diag:TestResults\Win64.log"
if($lastexitcode -ne 0)
{
$RunFaild = 1
Expand Down
3 changes: 2 additions & 1 deletion NuGet/build/native/YY-Thunks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<MinimumRequiredVersion Condition=" '%(Link.MinimumRequiredVersion)' == '' and '$(PlatformShortName)'=='x86' and '$(YY_Thunks_File)'=='YY_Thunks_for_WinXP.obj' ">5.01</MinimumRequiredVersion>
<MinimumRequiredVersion Condition=" '%(Link.MinimumRequiredVersion)' == '' and '$(PlatformShortName)'=='x64' and '$(YY_Thunks_File)'=='YY_Thunks_for_WinXP.obj' ">5.02</MinimumRequiredVersion>
<AdditionalDependencies>$(MSBuildThisFileDirectory)objs\$(PlatformShortName)\$(YY_Thunks_File);%(AdditionalDependencies)</AdditionalDependencies>
<EntryPointSymbol Condition="'$(ConfigurationType)'=='DynamicLibrary' and ('$(YY_Thunks_File)'=='YY_Thunks_for_WinXP.obj' or '$(YY_Thunks_File)'=='YY_Thunks_for_Win2K.obj')">DllMainCRTStartupForYY_Thunks</EntryPointSymbol>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -21,4 +22,4 @@
<Target Name="YY_Thunks_Update_MinimumRequiredVersion" Condition="'$(YY_Thunks_File)'=='YY_Thunks_for_Win2K.obj' and Exists('$(MSBuildThisFileDirectory)objs\$(PlatformShortName)\$(YY_Thunks_File)') and ('$(ConfigurationType)' == 'Application' Or '$(ConfigurationType)' == 'DynamicLibrary') " AfterTargets="AfterLink">
<Exec Command="%22$(MSBuildThisFileDirectory)Bin\MinimumRequiredVersionHelper.exe%22 %22$(TargetPath)%22 /MinimumRequiredVersion:5.0"/>
</Target>
</Project>
</Project>
21 changes: 18 additions & 3 deletions ReadMe.md → Readme.ocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![nuget](https://img.shields.io/nuget/vpre/YY-Thunks)](https://www.nuget.org/packages/YY-Thunks)
[![Build&Test](https://github.com/Chuyu-Team/YY-Thunks/actions/workflows/Build&Test.yml/badge.svg)](https://github.com/Chuyu-Team/YY-Thunks/actions/workflows/Build&Test.yml)

- [英语](Readme.md)

## 1. 关于 YY-Thunks

众所周知,从 Windows 的每次更新又会新增大量 API,这使得兼容不同版本的 Windows
Expand All @@ -22,8 +24,20 @@ YY-Thunks(鸭船),存在的目的就是抹平不同系统的差异,编
### 1.1. 原理

使用 `LoadLibrary` 以及 `GetProcAddress` 动态加载 API,不存在时做出补偿措施,
最大限度模拟原始 API 行为,让你的程序正常运行。

最大限度模拟原始 API 行为,让你的程序正常运行。大概就像下面这个`GetTickCount64`函数:

```cpp
// 注意:Windows XP 不支持 GetTickCount64
ULONGLONG WINAPI GetTickCount64(VOID)
{
if (auto const _pfnGetTickCount64 = try_get_GetTickCount64())
{
return _pfnGetTickCount64();
}
// Fallback
return GetTickCount();
}
```
### 1.2. 亮点
* 更快!更安全!`鸭船`内建2级缓存以及按需加载机制,同时自动加密所有函数指针,
Expand Down Expand Up @@ -57,7 +71,8 @@ YY-Thunks(鸭船),存在的目的就是抹平不同系统的差异,编
2. 【链接器】-【输入】-【附加依赖项】,添加
`objs\$(PlatformShortName)\YY_Thunks_for_WinXP.obj`。
3. 【链接器】-【系统】-【所需的最低版本】,根据实际情况填写 `5.01`(WinXP 32位) 或者 `5.02`(WinXP x64、2003)。
4. 重新编译代码。
4. 如果是编译DLL,那么【链接器】-【高级】-【自定义入口点】更改为`DllMainCRTStartupForYY_Thunks`(不这样做XP下使用thread_local可能崩溃!)
5. 重新编译代码。
> 温馨提示:如果需要兼容 Vista,【所需的最低版本】无需修改,但是【附加依赖项】请选择
`objs\$(PlatformShortName)\YY_Thunks_for_Vista.obj`。
Expand Down
12 changes: 6 additions & 6 deletions src/Build.cmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@echo off
@echo off
setlocal

::需要设置LibMaker.exe路径到环境变量Path。
::如果你需要LibMaker.exe,请自行到 初雨开源项目交流QQ群(633710173)群文件中下载。
::需要设置LibMaker.exe路径到环境变量Path。
::如果你需要LibMaker.exe,请自行到 初雨开源项目交流QQ群(633710173)群文件中下载。

pushd "%~dp0.."

Expand All @@ -12,7 +12,7 @@ if "%Platform%"=="" set Platform=x86

md "objs\\%Platform%"

::先生成 YY_Thunks_List.hpp
::先生成 YY_Thunks_List.hpp
msbuild "%~dp0YY-Thunks.UnitTest\YY-Thunks.UnitTest.vcxproj" -t:Build_YY_Thunks_List_hpp

call:Build%Platform%
Expand All @@ -26,8 +26,8 @@ goto:eof
:BuildObj
cl /O1 /Os /Oi /GS- /std:c++17 /arch:IA32 /Z7 /MT /Fo"objs\\%Platform%\\%1" /Zl /c /D "NDEBUG" /D "YY_Thunks_Support_Version=%2" "%~dp0Thunks\YY_Thunks.cpp"

::进行函数名称进行修正 __imp__%s_%u -> __imp__%s@%u
LibMaker.exe FixObj "%~dp0..\\objs\\%Platform%\\%1" /WeakExternFix:__security_cookie=%PointType% /WeakExternFix:__YY_Thunks_Process_Terminating=4 /WeakExternFix:__acrt_atexit_table=%PointType%
::进行函数名称进行修正 __imp__%s_%u -> __imp__%s@%u
LibMaker.exe FixObj "%~dp0..\\objs\\%Platform%\\%1" /WeakExternFix:__security_cookie=%PointType% /WeakExternFix:__YY_Thunks_Process_Terminating=4 /WeakExternFix:__acrt_atexit_table=%PointType% /WeakExternFix:__pfnDllMainCRTStartupForYY_Thunks=%PointType%

LibMaker.exe AppendWeak /MACHINE:%Platform% /DEF:"%~dp0def\\%Platform%\\PSAPI2Kernel32.def" /OUT:"%~dp0..\\objs\\%Platform%\\%1"

Expand Down
Loading

0 comments on commit 532d525

Please sign in to comment.