Skip to content

Commit

Permalink
Update detours
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiyansKing committed Jan 26, 2023
1 parent e1af016 commit 2f458cf
Show file tree
Hide file tree
Showing 43 changed files with 13,822 additions and 228 deletions.
5 changes: 3 additions & 2 deletions D3D11Engine/CGameManager.h
Expand Up @@ -9,15 +9,16 @@ class CGameManager {

/** Hooks the functions of this Class */
static void Hook() {
//XHook(HookedFunctions::OriginalFunctions.original_CGameManagerExitGame, GothicMemoryLocations::CGameManager::ExitGame, CGameManager::hooked_ExitGame);
//DetourAttach( &reinterpret_cast<PVOID&>(HookedFunctions::OriginalFunctions.original_CGameManagerExitGame), hooked_ExitGame );
}

/*
static int __fastcall hooked_ExitGame( void* thisptr, void* unknwn ) {
HookedFunctions::OriginalFunctions.original_CGameManagerExitGame( thisptr );
Engine::OnShutDown();
return 1;
}

*/
};
20 changes: 16 additions & 4 deletions D3D11Engine/D3D11Engine.vcxproj
Expand Up @@ -66,7 +66,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_AVX|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -113,7 +113,7 @@
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Launcher|Win32'">
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -628,6 +628,8 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<ClInclude Include="D3D7\MyDirect3DVertexBuffer7.h" />
<ClInclude Include="D3D7\MyDirectDraw.h" />
<ClInclude Include="D3D7\MyDirectDrawSurface7.h" />
<ClInclude Include="Detours\detours.h" />
<ClInclude Include="Detours\detver.h" />
<ClInclude Include="EditorLinePrimitive.h" />
<ClInclude Include="Engine.h" />
<ClInclude Include="GFSDK_SSAO.h" />
Expand Down Expand Up @@ -874,6 +876,16 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release_NoOpt_Spacer|Win32'">../pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release_NoOpt_G1|Win32'">../pch.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="Detours\creatwth.cpp" />
<ClCompile Include="Detours\detours.cpp" />
<ClCompile Include="Detours\disasm.cpp" />
<ClCompile Include="Detours\disolarm.cpp" />
<ClCompile Include="Detours\disolarm64.cpp" />
<ClCompile Include="Detours\disolia64.cpp" />
<ClCompile Include="Detours\disolx64.cpp" />
<ClCompile Include="Detours\disolx86.cpp" />
<ClCompile Include="Detours\image.cpp" />
<ClCompile Include="Detours\modules.cpp" />
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="EditorLinePrimitive.cpp" />
<ClCompile Include="Engine.cpp" />
Expand Down Expand Up @@ -979,7 +991,7 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\fx11_desktop_2019.2022.8.18.1\build\native\fx11_desktop_2019.targets" Condition="Exists('..\packages\fx11_desktop_2019.2022.8.18.1\build\native\fx11_desktop_2019.targets')" />
<Import Project="..\packages\fx11_desktop_2019.2022.8.18.1\build\native\fx11_desktop_2019.targets" Condition="Exists('..\packages\fx11_desktop_2019.2022.8.18.1\build\native\fx11_desktop_2019.targets')" />
<Import Project="..\packages\directxmesh_desktop_2019.2022.10.18.1\build\native\directxmesh_desktop_2019.targets" Condition="Exists('..\packages\directxmesh_desktop_2019.2022.10.18.1\build\native\directxmesh_desktop_2019.targets')" />
<Import Project="..\packages\directxmath.2022.12.12.1\build\native\directxmath.targets" Condition="Exists('..\packages\directxmath.2022.12.12.1\build\native\directxmath.targets')" />
<Import Project="..\packages\directxtk_desktop_2019.2022.10.18.2\build\native\directxtk_desktop_2019.targets" Condition="Exists('..\packages\directxtk_desktop_2019.2022.10.18.2\build\native\directxtk_desktop_2019.targets')" />
Expand All @@ -1000,4 +1012,4 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<directxtk-LibPath>$(directxtk-LibPath)\..\Release</directxtk-LibPath>
<fx11-LibPath>$(fx11-LibPath)\..\Release</fx11-LibPath>
</PropertyGroup>
</Project>
</Project>
39 changes: 39 additions & 0 deletions D3D11Engine/D3D11Engine.vcxproj.filters
Expand Up @@ -70,6 +70,9 @@
<Filter Include="Engine\D3D11\Engine">
<UniqueIdentifier>{ec0d93fb-3577-4853-a58f-8654d872352e}</UniqueIdentifier>
</Filter>
<Filter Include="Detours">
<UniqueIdentifier>{cc76209d-e83c-4217-9632-b333a4ee7d49}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
Expand Down Expand Up @@ -728,6 +731,12 @@
<ClInclude Include="D3D7\Conversions.h">
<Filter>D3D7</Filter>
</ClInclude>
<ClInclude Include="Detours\detours.h">
<Filter>Detours</Filter>
</ClInclude>
<ClInclude Include="Detours\detver.h">
<Filter>Detours</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down Expand Up @@ -956,6 +965,36 @@
<ClCompile Include="zBinkPlayer.cpp">
<Filter>ZenGin\Classes</Filter>
</ClCompile>
<ClCompile Include="Detours\creatwth.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\detours.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disasm.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disolarm.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disolarm64.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disolia64.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disolx64.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\disolx86.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\image.cpp">
<Filter>Detours</Filter>
</ClCompile>
<ClCompile Include="Detours\modules.cpp">
<Filter>Detours</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="ddraw.def">
Expand Down
16 changes: 12 additions & 4 deletions D3D11Engine/DLLMain.cpp
Expand Up @@ -3,7 +3,7 @@
#include "ddraw.h"
#include "D3D7/MyDirectDraw.h"
#include "Logger.h"
#include "detours.h"
#include "Detours/detours.h"
#include "DbgHelp.h"
#include "BaseAntTweakBar.h"
#include "HookedFunctions.h"
Expand Down Expand Up @@ -32,7 +32,7 @@ typedef HRESULT( WINAPI* DirectDrawCreateEx_type )(GUID FAR*, LPVOID*, REFIID, I

#if defined(BUILD_GOTHIC_2_6_fix)
using WinMainFunc = decltype(&WinMain);
WinMainFunc originalWinMain;
WinMainFunc originalWinMain = reinterpret_cast<WinMainFunc>(GothicMemoryLocations::Functions::WinMain);
#endif

bool FeatureLevel10Compatibility = false;
Expand Down Expand Up @@ -217,21 +217,28 @@ int WINAPI hooked_WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR l
// Remove automatic volume change of sounds regarding whether the camera is indoor or outdoor
// TODO: Implement!
if ( !GMPModeActive ) {
XHook( GothicMemoryLocations::zCActiveSnd::AutoCalcObstruction, HookedFunctionInfo::hooked_zCActiveSndAutoCalcObstruction );
DetourAttach( &reinterpret_cast<PVOID&>(HookedFunctions::OriginalFunctions.original_zCActiveSndAutoCalcObstruction), HookedFunctionInfo::hooked_zCActiveSndAutoCalcObstruction );
}
return originalWinMain( hInstance, hPrevInstance, lpCmdLine, nShowCmd );
}
#endif

BOOL WINAPI DllMain( HINSTANCE hInst, DWORD reason, LPVOID ) {
if ( DetourIsHelperProcess() ) {
return TRUE;
}

if ( reason == DLL_PROCESS_ATTACH ) {
DetourRestoreAfterWith();
DetourTransactionBegin();

//DebugWrite_i("DDRAW Proxy DLL starting.\n", 0);
hLThis = hInst;

Engine::PassThrough = false;

#if defined(BUILD_GOTHIC_2_6_fix)
XHook( originalWinMain, GothicMemoryLocations::Functions::WinMain, hooked_WinMain );
DetourAttach( &reinterpret_cast<PVOID&>(originalWinMain), hooked_WinMain );
#endif

//_CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
Expand All @@ -258,6 +265,7 @@ BOOL WINAPI DllMain( HINSTANCE hInst, DWORD reason, LPVOID ) {
EnableCrashingOnCrashes();
//SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
}
DetourTransactionCommit();

char infoBuf[MAX_PATH];
GetSystemDirectoryA( infoBuf, MAX_PATH );
Expand Down
118 changes: 118 additions & 0 deletions D3D11Engine/Detours/CREDITS.md
@@ -0,0 +1,118 @@
# Detours Contributor Credits

The following individuals have helped identify specific bugs and improvements
in Detours. The entire Detours community has benefited from their help.

* Jay Krell: Identified error in DetourFindPayload that caused a
incorrect failure when pcbData is NULL. (Build_342)

* Jay Krell: Identified issue with VirtualSize == 0 files created in
NT 3.1 images. (Build_339)

* Igor Odnovorov: Identified an issue with the placement of the trampoline
region when a function is detoured twice and the second
trampoline region is outside of the +/- 2GB range of
the target. (Build_337)

* Jay Krell: Identified need for some programs to enumerate the
address of IAT entries. (Build_336)

* Calvin Hsia: Identified need for some program to change the excluded
system region. (Build_336)

* Adam Smith: Identified error in failure handling when VirtualProect
cannot make pages executable because the Prohibit
Dynamic Code Generation mitigation policy has been
applied to a process. (Build_335)

* Ben Faull: Identified fix to detour_alloc_region_from_lo and
detour_alloc_region_from_hi that preserves ASLR entropy.
(Build_334)

* Shaoxiang Su: Reported errors building with Visual Studio 2015.
(Build_332)

* Jay Krell: Identified and resolved significant gaps in the X86, X64
and IA64 disassemblers for instruction found in code,
but seldom found in function prologues. (Build_331)

* Allan Murphy: Identify error in rep and jmp ds: encodings. (Build_331)

* Philip Bacon: Identified incorrect entry point return for pure
resource-only binaries. (Build_330)

* Jay Krell: Identified failure in DetourAttachEx to update nAlign.
(Build_330)

* Sumit Sarin: Helped debug error with packed binaries.
(Build_329)

* Nitya Kumar Sharma: Reported bug in DetourAfterWithDll for 32/64 agnostic
EXEs.
(Build_327)

* Richard Black: Identified a large number of typos in documentation.
(Build_326)

* Michael Bilodeau: Identified bug in DetourUpdateProcessWithDll when the
target process contains a Detours payload *after* all
valid PE binaries.
(Build_324)

* Meera Jindal: Reported bug in identification of target address in
DetourCopyInstruction for jmp[] and call[] on x86 & x64,
the ff15 and ff25 opcodes.
(Build_323)

* Ken Johnson: Assistance with SAL 2.0 annotations.
(Build_319)

* Nick Wood: Identified bug in DetourFindFunction on ARM.
(Build_314)

* Mark Russinovich: Helped debug DetourCreateProcessWithDllEx.
(Build_314)

* John Lin: Implementation idea for DetoursCreateProcessWithDllEx.
(Build_314)

* Andrew Zawadowskiy Reported an improper memory page permissions
vulnerability in Detours 2.1. (Vulnerability does not
exist in versions later than Detours 2.1.)
(Build_223)

* Nightxie: Identified bug in detour_alloc_round_up_to_region.
(Build_310)

* Diana Milirud: Identified bug in B* instructions on ARM.
(Build_309)

* Juan Carlos Identified correct MSIL entry point for unsigned MSIL.
Luciani: (Build_308)

* Lee Hunt Suggested improvements in algorithm for allocation of
Lawrence Landauer trampoline regions on x64 to avoid collisions with
Joe Laughlin: system DLLs.
(Build_307)

* Tyler Sims Identified bug in handling of "anycpu" MSIL binaries
Darren Kennedy: on x64.
(Build_307)

* Andre Vachon: Help with optimized binaries.
(Build 301)

* Chris Mann: Identified fix not forward ported from 2.2 to 3.0.
(Build_301)

* Mark Irving: Identified bug with EXEs missing second import table.
(Build_300)

* Ben Schwarz: Identified bug in handling of multi-byte NOPs.
(Build_300)

* Aaron Giles Coded initial ARM/Thumb2 disassembler.
Jared Henderson: (Build_300)

* Doug Brubacher: Coded initial x86 disassembler.
(Build_100)
23 changes: 23 additions & 0 deletions D3D11Engine/Detours/LICENSE.md
@@ -0,0 +1,23 @@
# Copyright (c) Microsoft Corporation

All rights reserved.

# MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit 2f458cf

Please sign in to comment.