This article is written in follow-up to Specific's "Hook process functions via dll injection Cpp". His article detailed how to hook functions using an injected DLL. Expanding on this concept, i'll detail how you can trampoline over the CALL or JMP instruction which forwards flow to the hook function; effectively rendering the HOOK void/useless. This method works well with any application that attempts to spy on or intercept specific functions, e.g. WPE, TrainerSpy, etc. The code is in ASM but generic enough to be ported to any other language with minimal fuss.
What we're going to do is disable TrainerSpy (XP) by invoking trampolined function calls. For those of you unfamiliar with TrainerSpy (or variants thereof), it's basically a tool that people (read: lamers) use to intercept function calls to kernel32.WriteProcessMemory() in trainers (or any application that calls WPM for that matter). It logs several paramters of the WPM() but most importantly, address of and bytes written to address. If I spend a few hours reversing a game, the last thing I want is some lamer to just spy on my addresses and release his own with my options. So let's disable that.
Before I get into the code, i'll quickly gloss over some ASM fundamentals. Open kernel32.dll in OllyDbg or IDA (or any other decent dissasembler/debugger) and find the function WriteProcessMemory (ctrl+N to bring up referenced API list).
First few lines of WPM();
What TrainerSpy does is;
By placing JMP instruction at the start of the function, it directs flow to the hook.Function, where it can log or modify parameters. To bypass this HOOK, we simply emulate the first three instructions then jump into the function 5 bytes, pseudo;
Some may ask, what exactly is this and why is it there? It's a procedural stack frame and indicates the start of most (most, not all) functions. Above and beyond helping us identify where functions start, it's imperative for arranging local storage on the stack.
Ok so, enough talking, here's the code;
The following snippet uses a custom function of mine to load a function address and store it into the supplied variable for later use within the MACRO trampCALL:
What the code does it load the address of WriteProcessMemory+5 and save it in pWriteProcessMemory. Then it prepares a call to WPM as per normal setting up the parameters. The macro trampCALL pWriteProcessMemory emulates the first 3 instructions and prepares the stack for the trampoline, finally jumping to WPM+5 and returning to EIP.

