stevemk14ebr / PolyHook

x86/x64 C++ Hooking Library
MIT License
882 stars 168 forks source link

VEH::HARDWARE_BP hook gets called once #27

Closed diejozef closed 7 years ago

diejozef commented 7 years ago

When I try to hook a function through your HWBP method, it gets called only once / hook setup. Used your example:

typedef int(__stdcall* tVEH)(int intparam);
tVEH oVEHTest;
__declspec(noinline) int __stdcall VEHTest(int param)
{
    printf("original called.\n");
    return 3;
}

std::shared_ptr<PLH::VEHHook> VEHHook_Ex;
__declspec(noinline) int __stdcall hkVEHTest(int param)
{
    auto ProtectionObject = VEHHook_Ex->GetProtectionObject();
    printf("hook called.\n");
    return oVEHTest(param) + 1;
}
SECTION("Hardware Type Breakpoint")
{
    VEHHook_Ex->SetupHook((BYTE*)&VEHTest, (BYTE*)&hkVEHTest, PLH::VEHHook::VEHMethod::HARDWARE_BP);
    REQUIRE(VEHHook_Ex->Hook());
    oVEHTest = VEHHook_Ex->GetOriginal<tVEH>();
    VEHTest(0);
    VEHTest(1);
    VEHTest(2);

    VEHHook_Ex->UnHook();
}

Output: Image