Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ - overriding a function imported from a DLL?

I'm trying to override a specific function in kernel32.dll. Is it somehow possible to redefine that function in a static library and force the executable to use the one in the static library? I guess the different linkage could become a problem.

It would be possible to override it with my own custom DLL. However the problem is that the DLL itself needs to link to kernel32.dll, so it ignores my definition of that function.

EDIT: I got it working with my own DLL. When building it, link time code generation needs to be disabled. What about linking the overridden function statically though?

like image 611
NFRCR Avatar asked Mar 11 '26 23:03

NFRCR


1 Answers

If I understand you correctly, you want custom behavior for a Windows API function in kernel32.dll. If so, you need to hook into the Windows API. One way to do this is to use Detours. Haven't tried it myself but here's a link to a CodeProject article - http://www.codeproject.com/Articles/30140/API-Hooking-with-MS-Detours.

like image 84
Ilian Avatar answered Mar 14 '26 13:03

Ilian