tags:

views:

145

answers:

2

This one game I do scripting for uses a primary dll in which our scripts we write (creatively named "scripts.dll"

This scripts.dll, server-side, loads other plugins (.dlls as well).

Question: I need to override an existing function in scripts.dll in, for example, pluginA.dll to where the one in scripts.dll doesn't get called.

I had the idea of maybe grabbing the address of the one in scripts.dll and overwriting it with (memcpy()?) the address of my new function.

Oh and the functions are named the same.

+2  A: 

This is a fairly large topic that requires a long-winded answer, but, thankfully, it has been covered elsewhere in detail. This CodeProject article is a fairly decent read on the topic - it explains both the theory, and how to use the convenient Microsoft Detours library to do this very easily.

Pavel Minaev
Thanks, this should help me. :)
Zack
+1  A: 

First I would try to adjust the caller to get this specific function pointer from pluginA.dll, and not from scripts.dll, through GetProcAddress.

If that is not feasible, I would overwrite the start of the old function with a jump instruction to the new function. The jump instruction on x86 is "E9 XX XX XX XX"; notice that the target address is relative to the PC following the jump. If you don't have x86, the machine code will look different, of course.

Martin v. Löwis