I'm using the latest vcpkg port of PolyHook2 (polyhook2[core,detours,exception,inlinentd,pe,virtuals]:x64-windows -> 2023-05-16#1). My dependencies asmjit, asmtk and zydis are also up-to-date. I noticed when I'm hooking the QueryPerformanceCounter function, the process crashes. My reproduction code is as follows:
#include <iostream>
#include <polyhook2/Detour/NatDetour.hpp>
#include <Windows.h>
using namespace std::chrono_literals;
using tQueryPerformanceCounter = BOOL(WINAPI*)(LARGE_INTEGER* lp_performance_count);
tQueryPerformanceCounter oQueryPerformanceCounter;
auto called_count = 0;
BOOL WINAPI hQueryPerformanceCounter(LARGE_INTEGER* performance_count)
{
called_count++;
return oQueryPerformanceCounter(performance_count);
}
int main()
{
oQueryPerformanceCounter = QueryPerformanceCounter;
PLH::NatDetour hook(reinterpret_cast<uint64_t>(oQueryPerformanceCounter),
reinterpret_cast<uint64_t>(hQueryPerformanceCounter),
reinterpret_cast<uint64_t*>(&oQueryPerformanceCounter));
const auto successfully_hooked = hook.hook();
std::cout << "Successfully hooked: " << successfully_hooked << std::endl;
for (auto index = 0; index < 5; index++)
{
std::cout << "Called count: " << called_count << std::endl;
std::this_thread::sleep_for(1000ms);
} // Exception thrown at 0x00007FFCC43A6E10 (kernel32.dll) in PolyHookQueryPerformanceCounterHookingTest.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
hook.unHook();
return EXIT_SUCCESS;
}
I expect this code to run successfully and return with EXIT_SUCCESS but it doesn't.
Other types of hooks generally seem to work fine.
When I compile and run this example in x86, it also works and produces a reasonable output of:
Successfully hooked: 1
Called count: 0
Called count: 3
Called count: 6
Called count: 9
Called count: 12
Any idea how this issue is caused in x64? Can I maybe use a different detours scheme? When using the Microsoft Detours library, the QueryPerformanceCounter hook works fine in x64 so it's not generally problematic to hook e.g. QueryPerformanceCounter. It would be great to be able to fully switch over to PolyHook2.
Hello,
I'm using the latest vcpkg port of
PolyHook2
(polyhook2[core,detours,exception,inlinentd,pe,virtuals]:x64-windows -> 2023-05-16#1
). My dependenciesasmjit
,asmtk
andzydis
are also up-to-date. I noticed when I'm hooking theQueryPerformanceCounter
function, the process crashes. My reproduction code is as follows:ErrorLog output:
I expect this code to run successfully and return with![image](https://github.com/stevemk14ebr/PolyHook_2_0/assets/7620135/d0e01a70-4f65-4d06-97e3-7540bf19acd4)
EXIT_SUCCESS
but it doesn't.Other types of hooks generally seem to work fine.
When I compile and run this example in x86, it also works and produces a reasonable output of:
Any idea how this issue is caused in x64? Can I maybe use a different detours scheme? When using the
Microsoft Detours
library, theQueryPerformanceCounter
hook works fine in x64 so it's not generally problematic to hook e.g.QueryPerformanceCounter
. It would be great to be able to fully switch over toPolyHook2
.