#include #include "misc.h" #include "hook.h" #if 0 Check whether trampoline works correctly start: je lbl1 jmp lbl1 lbl1: --- hook() == LOOPS_INTO_OVERWRITTEN_CODE start: mov eax, 3 l: dec eax test eax, eax je l #endif static int test(int a, int b); static void normal(int a, int b, int c, int d, int e); static void normal2(int a, int b, int c, int d, int e); typedef void(*FUNCTYPE)(int a, int b, int c, int d, int e); static void hooked(int a, int b, int c, int d, int e); static FUNCTYPE original; int main(int argc, char** argv) { int r = 0; if((r = hook(normal2, 0, hooked, &original)) < 0) { printf("CAn't hook: %d\n", r); return 1; } printf("---\nDisass. trampoline/original\n"); disassemble_func(original, 10); original(3, 1, 1, 1, 1); //original(5, 1, 1, 1, 1); #if WINDOWS VirtualFree(original, 0, MEM_RELEASE); #endif (void)getc(stdin); } static int test(int a, int b) { if(a == 0) return 5; else if(a == 1) return b; return a; } static void normal(int a, int b, int c, int d, int e) { printf("Result: %d\n", a*b*c*d*e); } static void normal2(int a, int b, int c, int d, int e) { if(a == 3) return; printf("Result: %d\n", a*b*c*d*e); } static void hooked(int a, int b, int c, int d, int e) { original(1, b, c, d, e); }