Detours

Detours is a library that allows you to hook functions and instrument arbitrary win32 function by proxying them and re-writing the function.

Detours works by using a jmp instruction to redirect code execution.

Detours has a whitepaper which goes into further detail.

This uses a trampoline function which is a like a proxy and setups everything properly.

With hooking, we can: look at values that the function uses, make it return a certain value, or execute someone etc.

Example

To demonstrate, lets try hooking a simple message box function.

We will inject a dll into the process that uses the message box, our dll will look like this.

First, we make a pointer to the original MessageBox

Then, we create the "hooking function", which is the function that will replace the original message box.

Then, when our dll gets attached, we will being hooking with this code.

And when our dll gets detached, we will unhook the code.

For our injector, we can use a simple dll injector or use Process hacker to inject a dll. Our next step is to then inject our dll into the target process with the messagebox function and resume execution by entering a key to get through getchar().

When injected, this DLL will change the message that the messagebox popups during execution.

Last updated

Was this helpful?