This code compiled and worked a few years ago. It doesn't work anymore, and I'm still using detours v2.1, I've only upgraded the compiler from (I believe) VS 2010 to now (2013 & 2015).
Note that I'm adding a hook at the middle of a function, not at the start.
This is what detour would do when it used to work:
1. adds a jmp to address 0x1000 [previously this was a mov ebx, 5]
2. mov eax, 1 // my code
3. mov ebx, 5
4. jump back at address 0x1004
Now what happens is
1. adds a jmp to address 0x1000, [ this still works]
2. mov eax, 1 // my code
3. jump back at address 0x1000
4. **Infinite loop.**
hook:
void __declspec(naked) New_Fn()
{
__asm MOV EAX, 1
JMP MidFun
}
DetourAttach(&(PVOID&)MidFun, New_Fn);
Any ideas?