Beispiel #1
0
void DetourNtdllForModule(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetNtdllModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"ntdll", base, module))
  {
    DetourFunc(process,
               base,
               "NtMapViewOfSection",
               GetNtMapViewOfSectionDetour(),
               NtMapViewOfSectionDetour);
    DetourFunc(process,
               base,
               "NtUnmapViewOfSection",
               GetNtUnmapViewOfSectionDetour(),
               NtUnmapViewOfSectionDetour);
    DetourFunc(
      process, base, "LdrLoadDll", GetLdrLoadDllDetour(), LdrLoadDllDetour);
    DetourFunc(process,
               base,
               "LdrUnloadDll",
               GetLdrUnloadDllDetour(),
               LdrUnloadDllDetour);
  }
}
Beispiel #2
0
void UndetourD3D9(bool remove)
{
  auto& module = GetD3D9Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"D3D9", module))
  {
    UndetourFunc(
      L"IDirect3DDevice9::AddRef", GetIDirect3DDevice9AddRefDetour(), remove);
    UndetourFunc(
      L"IDirect3DDevice9::Release", GetIDirect3DDevice9ReleaseDetour(), remove);
    UndetourFunc(
      L"IDirect3DDevice9::Present", GetIDirect3DDevice9PresentDetour(), remove);
    UndetourFunc(
      L"IDirect3DDevice9::Reset", GetIDirect3DDevice9ResetDetour(), remove);
    UndetourFunc(L"IDirect3DDevice9::EndScene",
                 GetIDirect3DDevice9EndSceneDetour(),
                 remove);
    UndetourFunc(L"IDirect3DDevice9Ex::PresentEx",
                 GetIDirect3DDevice9ExPresentExDetour(),
                 remove);
    UndetourFunc(L"IDirect3DDevice9Ex::ResetEx",
                 GetIDirect3DDevice9ExResetExDetour(),
                 remove);
    UndetourFunc(L"IDirect3DSwapChain9::Present",
                 GetIDirect3DSwapChain9PresentDetour(),
                 remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #3
0
void InitializeRawInput()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(L"USER32",
                                    DetourUser32ForRawInput,
                                    UndetourUser32ForRawInput,
                                    GetUser32Module);
}
Beispiel #4
0
void UndetourOpenGL32(bool remove)
{
  auto& module = GetOpenGL32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"OpenGL32", module))
  {
    UndetourFunc(L"wglSwapBuffers", GetWglSwapBuffersDetour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #5
0
void InitializeException()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(L"NTDLL",
                                    DetourNtdllForException,
                                    UndetourNtdllForException,
                                    GetNtdllModule);
  helper.InitializeSupportForModule(L"KERNELBASE",
                                    DetourKernelBaseForException,
                                    UndetourNtdllForException,
                                    GetKernelBaseModule);
}
Beispiel #6
0
void UndetourUser32ForWindow(bool remove)
{
  auto& module = GetUser32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"user32", module))
  {
    UndetourFunc(
      L"GetForegroundWindow", GetGetForegroundWindowDetour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #7
0
void UndetourKernelBaseForException(bool remove)
{
  auto& module = GetKernelBaseModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"kernelbase", module))
  {
    UndetourFunc(L"SetUnhandledExceptionFilter",
                 GetSetUnhandledExceptionFilterDetour(),
                 remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #8
0
void UndetourNtdllForException(bool remove)
{
  auto& module = GetNtdllModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"ntdll", module))
  {
    UndetourFunc(L"RtlAddVectoredExceptionHandler",
                 GetRtlAddVectoredExceptionHandlerDetour(),
                 remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #9
0
void DetourUser32ForWindow(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetUser32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"user32", base, module))
  {
    DetourFunc(process,
               base,
               "GetForegroundWindow",
               GetGetForegroundWindowDetour(),
               GetForegroundWindowDetour);
  }
}
Beispiel #10
0
void DetourKernelBaseForException(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetKernelBaseModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"kernelbase", base, module))
  {
    DetourFunc(process,
               base,
               "SetUnhandledExceptionFilter",
               GetSetUnhandledExceptionFilterDetour(),
               SetUnhandledExceptionFilterDetour);
  }
}
Beispiel #11
0
void DetourNtdllForException(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetNtdllModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"ntdll", base, module))
  {
    DetourFunc(process,
               base,
               "RtlAddVectoredExceptionHandler",
               GetRtlAddVectoredExceptionHandlerDetour(),
               RtlAddVectoredExceptionHandlerDetour);
  }
}
Beispiel #12
0
void DetourOpenGL32(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetOpenGL32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"OpenGL32", base, module))
  {
    DetourFunc(process,
               base,
               "wglSwapBuffers",
               GetWglSwapBuffersDetour(),
               WglSwapBuffersDetour);
  }
}
Beispiel #13
0
void UndetourD3D101(bool remove)
{
  auto& module = GetD3D10Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"D3D10_1", module))
  {
    UndetourFunc(L"D3D10CreateDeviceAndSwapChain1",
                 GetD3D10CreateDeviceAndSwapChain1Detour(),
                 remove);
    UndetourFunc(L"D3D10CreateDevice1", GetD3D10CreateDevice1Detour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #14
0
void UndetourUser32ForRawInput(bool remove)
{
  auto& module = GetUser32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"user32", module))
  {
    UndetourFunc(L"GetRawInputBuffer", GetGetRawInputBufferDetour(), remove);
    UndetourFunc(L"GetRawInputData", GetGetRawInputDataDetour(), remove);
    UndetourFunc(
      L"RegisterRawInputDevices", GetRegisterRawInputDevicesDetour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #15
0
void UndetourNtdllForModule(bool remove)
{
  auto& module = GetNtdllModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"ntdll", module))
  {
    UndetourFunc(L"NtMapViewOfSection", GetNtMapViewOfSectionDetour(), remove);
    UndetourFunc(
      L"NtUnmapViewOfSection", GetNtUnmapViewOfSectionDetour(), remove);
    UndetourFunc(L"LdrLoadDll", GetLdrLoadDllDetour(), remove);
    UndetourFunc(L"LdrUnloadDll", GetLdrUnloadDllDetour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #16
0
void UndetourDXGI(bool remove)
{
  auto& module = GetDXGIModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonUndetourModule(L"DXGI", module))
  {
    UndetourFunc(
      L"IDXGISwapChain::Present", GetIDXGISwapChainPresentDetour(), remove);
    UndetourFunc(L"IDXGISwapChain::ResizeBuffers",
                 GetIDXGISwapChainResizeBuffersDetour(),
                 remove);
    UndetourFunc(
      L"IDXGISwapChain::Present1", GetIDXGISwapChain1Present1Detour(), remove);

    module = std::make_pair(nullptr, 0);
  }
}
Beispiel #17
0
void DetourD3D101(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetD3D101Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"D3D10_1", base, module))
  {
    DetourFunc(process,
               base,
               "D3D10CreateDevice1",
               GetD3D10CreateDevice1Detour(),
               D3D10CreateDevice1Detour);
    DetourFunc(process,
               base,
               "D3D10CreateDeviceAndSwapChain1",
               GetD3D10CreateDeviceAndSwapChain1Detour(),
               D3D10CreateDeviceAndSwapChain1Detour);
  }
}
Beispiel #18
0
void DetourDXGI(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetDXGIModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"DXGI", base, module))
  {
    auto& render_helper = GetRenderHelperInterface();
    auto const render_offsets = render_helper.GetRenderOffsets();
    auto const dxgi_offsets = &render_offsets->dxgi_offsets_;
    auto const offset_base = reinterpret_cast<std::uint8_t*>(base);

    if (!dxgi_offsets->present_)
    {
      HADESMEM_DETAIL_TRACE_FORMAT_A(
        "WARNING! No DXGI offsets. Skipping hooks.");
      return;
    }

    auto const present_fn = offset_base + dxgi_offsets->present_;
    DetourFunc(process,
               "IDXGISwapChain::Present",
               GetIDXGISwapChainPresentDetour(),
               reinterpret_cast<IDXGISwapChain_Present_Fn>(present_fn),
               IDXGISwapChain_Present_Detour);

    auto const resize_buffers_fn = offset_base + dxgi_offsets->resize_buffers_;
    DetourFunc(
      process,
      "IDXGISwapChain::ResizeBuffers",
      GetIDXGISwapChainResizeBuffersDetour(),
      reinterpret_cast<IDXGISwapChain_ResizeBuffers_Fn>(resize_buffers_fn),
      IDXGISwapChain_ResizeBuffers_Detour);

    auto const present_1_fn = offset_base + dxgi_offsets->present_1_;
    DetourFunc(process,
               "IDXGISwapChain1::Present1",
               GetIDXGISwapChain1Present1Detour(),
               reinterpret_cast<IDXGISwapChain1_Present1_Fn>(present_1_fn),
               IDXGISwapChain1_Present1_Detour);
  }
}
Beispiel #19
0
void DetourUser32ForRawInput(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetUser32Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"user32", base, module))
  {
    DetourFunc(process,
               base,
               "GetRawInputBuffer",
               GetGetRawInputBufferDetour(),
               GetRawInputBufferDetour);
    DetourFunc(process,
               base,
               "GetRawInputData",
               GetGetRawInputDataDetour(),
               GetRawInputDataDetour);
    DetourFunc(process,
               base,
               "RegisterRawInputDevices",
               GetRegisterRawInputDevicesDetour(),
               RegisterRawInputDevicesDetour);
  }
}
Beispiel #20
0
void InitializeWindow()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"USER32", DetourUser32ForWindow, UndetourUser32ForWindow, GetUser32Module);
}
Beispiel #21
0
void DetourD3D9(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetD3D9Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"D3D9", base, module))
  {
    auto& render_helper = GetRenderHelperInterface();
    auto const render_offsets = render_helper.GetRenderOffsets();
    auto const d3d9_offsets = &render_offsets->d3d9_offsets_;
    auto const offset_base = reinterpret_cast<std::uint8_t*>(base);

    if (!d3d9_offsets->add_ref_)
    {
      HADESMEM_DETAIL_TRACE_FORMAT_A(
        "WARNING! No D3D9 offsets. Skipping hooks.");
      return;
    }

    auto const add_ref_fn = offset_base + d3d9_offsets->add_ref_;
    DetourFunc(process,
               "IDirect3DDevice9::AddRef",
               GetIDirect3DDevice9AddRefDetour(),
               reinterpret_cast<IDirect3DDevice9_AddRef_Fn>(add_ref_fn),
               IDirect3DDevice9_AddRef_Detour);

    auto const release_fn = offset_base + d3d9_offsets->release_;
    DetourFunc(process,
               "IDirect3DDevice9::Release",
               GetIDirect3DDevice9ReleaseDetour(),
               reinterpret_cast<IDirect3DDevice9_Release_Fn>(release_fn),
               IDirect3DDevice9_Release_Detour);

    auto const present_fn = offset_base + d3d9_offsets->present_;
    DetourFunc(process,
               "IDirect3DDevice9::Present",
               GetIDirect3DDevice9PresentDetour(),
               reinterpret_cast<IDirect3DDevice9_Present_Fn>(present_fn),
               IDirect3DDevice9_Present_Detour);

    auto const reset_fn = offset_base + d3d9_offsets->reset_;
    DetourFunc(process,
               "IDirect3DDevice9::Reset",
               GetIDirect3DDevice9ResetDetour(),
               reinterpret_cast<IDirect3DDevice9_Reset_Fn>(reset_fn),
               IDirect3DDevice9_Reset_Detour);

    auto const end_scene_fn = offset_base + d3d9_offsets->end_scene_;
    DetourFunc(process,
               "IDirect3DDevice9::EndScene",
               GetIDirect3DDevice9EndSceneDetour(),
               reinterpret_cast<IDirect3DDevice9_EndScene_Fn>(end_scene_fn),
               IDirect3DDevice9_EndScene_Detour);

    auto const present_ex_fn = offset_base + d3d9_offsets->present_ex_;
    DetourFunc(process,
               "IDirect3DDevice9Ex::PresentEx",
               GetIDirect3DDevice9ExPresentExDetour(),
               reinterpret_cast<IDirect3DDevice9Ex_PresentEx_Fn>(present_ex_fn),
               IDirect3DDevice9Ex_PresentEx_Detour);

    auto const reset_ex_fn = offset_base + d3d9_offsets->reset_ex_;
    DetourFunc(process,
               "IDirect3DDevice9Ex::ResetEx",
               GetIDirect3DDevice9ExResetExDetour(),
               reinterpret_cast<IDirect3DDevice9Ex_ResetEx_Fn>(reset_ex_fn),
               IDirect3DDevice9Ex_ResetEx_Detour);

    auto const swap_chain_present_fn =
      offset_base + d3d9_offsets->swap_chain_present_;
    DetourFunc(
      process,
      "IDirect3DSwapChain9::Present",
      GetIDirect3DSwapChain9PresentDetour(),
      reinterpret_cast<IDirect3DSwapChain9_Present_Fn>(swap_chain_present_fn),
      IDirect3DSwapChain9_Present_Detour);
  }
}
Beispiel #22
0
void InitializeD3D11()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"D3D11", DetourD3D11, UndetourD3D11, GetD3D11Module);
}
Beispiel #23
0
void InitializeD3D9()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"D3D9", DetourD3D9, UndetourD3D9, GetD3D9Module, false);
}
Beispiel #24
0
void InitializeModule()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"NTDLL", DetourNtdllForModule, UndetourNtdllForModule, GetNtdllModule);
}
Beispiel #25
0
void InitializeDXGI()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"DXGI", &DetourDXGI, &UndetourDXGI, &GetDXGIModule);
}
Beispiel #26
0
void InitializeOpenGL32()
{
  auto& helper = GetHelperInterface();
  helper.InitializeSupportForModule(
    L"OPENGL32", DetourOpenGL32, UndetourOpenGL32, GetOpenGL32Module);
}