I’m doing some exercises and I came across a problem. I have got DLL file which will be injected into exe file. I have to override one function from that exe, by my function from DLL file. I can’t interfere in exe file, but in DLL I can. I got address of function which I have to replace (got it by GetProcAddress() function ) and now I have to redirect this address to my function. What I want to achievie is when exe will call function, he will call not his internal function, but my func, from dll. I hope that I made my myself clear. That’s how head of function looks like:
int ( func )( float, int );
I tried to do it like that:
typedef int ( *func_ptr )( float, int );
func_ptr myFunction;
myFunction = (*func_ptr)GetProcAddress(hModule, func_name);
*myFunction = newFunction;
You might want to have a look at Detours: http://research.microsoft.com/en-us/projects/detours/
Or manually patch the target function with a jump to your replacement.