Skip to content

Commit

Permalink
尝试在 C# 劫持函数
Browse files Browse the repository at this point in the history
替换 Detours 依赖包
  • Loading branch information
wherewhere committed Jul 3, 2024
1 parent d81281d commit 6be6fa7
Show file tree
Hide file tree
Showing 9 changed files with 1,606 additions and 14 deletions.
8 changes: 5 additions & 3 deletions CoreAppUWP.WinRT/CoreAppUWP.WinRT.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<ModuleDefinitionFile>CoreAppUWP.WinRT.def</ModuleDefinitionFile>
<AdditionalLibraryDirectories Condition="'$(PlatformTarget)'=='ARM64'">Detours\ARM64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformTarget)'=='x86'">..\packages\Detours.Win32Metadata.4.0.1.16\static\win-x86\native;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformTarget)'=='x64'">..\packages\Detours.Win32Metadata.4.0.1.16\static\win-x64\native;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformTarget)'=='ARM64'">..\packages\Detours.Win32Metadata.4.0.1.16\static\win-arm64\native;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>detours.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
Expand All @@ -112,6 +115,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="detours.h" />
<ClInclude Include="HookRegistry.h">
<DependentUpon>HookRegistry.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -148,14 +152,12 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Detours.4.0.1\build\native\Detours.targets" Condition="Exists('..\packages\Detours.4.0.1\build\native\Detours.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Detours.4.0.1\build\native\Detours.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Detours.4.0.1\build\native\Detours.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
Expand Down
Binary file removed CoreAppUWP.WinRT/Detours/ARM64/detours.lib
Binary file not shown.
Binary file removed CoreAppUWP.WinRT/Detours/ARM64/detours.pdb
Binary file not shown.
13 changes: 3 additions & 10 deletions CoreAppUWP.WinRT/HookRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ namespace winrt::CoreAppUWP::WinRT::implementation

LSTATUS APIENTRY HookRegistry::OverrideRegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
{
LSTATUS result;
if (lpValueName != NULL && !_wcsicmp(lpValueName, L"EnableUWPWindow"))
{
bool isRealKey = false;
Expand All @@ -111,6 +110,7 @@ namespace winrt::CoreAppUWP::WinRT::implementation

if (isXamlKey)
{
LSTATUS result;
if (isRealKey)
{
// real key
Expand Down Expand Up @@ -162,17 +162,10 @@ namespace winrt::CoreAppUWP::WinRT::implementation
}
}
}
}
else
{
result = BaseRegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
return result;
}
}
else
{
result = BaseRegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
}

return result;
return BaseRegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
}
}
Loading

0 comments on commit 6be6fa7

Please sign in to comment.