I used Detours (http://research.microsoft.com/en-us/projects/detours/) under Windows, but now i using Linux Ubuntu and i want to Detour / Hook a function. I want to detour the function to mine, after that i want to call the original function. (I can hook the function, but i can't use the original after that).
So, i decided to write a detour function. First of all, I copied the function to another place, but I couldn't execute it. Can you help me, why I couldn't execute it? I got segmentation fault.
My code:
int (* h_Com_Printf)(const char *fmt, ...);
...
void *memBuffer;
int size = 0x4F; // size of the function
memBuffer = (void*)malloc(size);
memcpy(memBuffer, (void*)0x08060DEA, size); // copy the function
h_Com_Printf = (int (*)(const char *fmt, ...))memBuffer;
h_Com_Printf("print function: %d\n", 1); // segmentation fault HERE
Thanks!
Com_Printf in the "executable file" (IDA Pro): Image: http://kepfeltoltes.hu/150818/ida_printf_www.kepfeltoltes.hu_.png
Linux running in VirtualBox. (Can it be the problem?)