I'm wondering what hippomocks does to intercept the exit
call function for example as shown in the below code:
MockRepository mocks;
mocks.ExpectCallFunc(exit).With(2).Throw(std::exception());
The code which does the interception is in hippomocks.h
. It modifies the memory protection flags to allow writing to the address of the provided function pointer, then writes a jump instruction in place of the initial bytes of the function. When the hook is no longer needed, the original bytes are restored. This is the same approach used, for example, by the Microsoft Detours library.