issue with Steam and wglSwapBuffers

c++ / delphi package - dll injection and api hooking
Post Reply
musikit
Posts: 30
Joined: Fri Oct 06, 2006 9:00 pm

issue with Steam and wglSwapBuffers

Post by musikit »

I know I've reported this before with madcodehook v2 however, after fully upgrading to madcodehook v3, and completing all our testing, there is still an issue with Steam and madcodehook and hooking the function "wglSwapBuffers" causing a stack overflow.

I have no clue who's "bug" it is. I know previously we have tracked it down to the fact that there is a difference between a 6 byte jump (madcodehook) and a 5 byte jump (steam).

Just an interoperability FYI. The best game to test this with is Counter-Strike 1.6.

We have worked around this ourselves by implementing our own 5 byte function hook for this function because if this is a bug on Steam's side we will never expect a bug fix for this, and if this is a madcodehook bug we don't have the resources to fund madshi for a fix and we know this is a low priority.
aiwnjoo
Posts: 52
Joined: Tue Mar 06, 2007 1:06 pm

Post by aiwnjoo »

Maybe your detouring? or hooking GetProcAddress which could cause a recursive stack overflow like this. Its more likely a Steam issue that MAD.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I'm considering offering an alternative hooking mode which (on a minor performance cost) uses a 5 byte JMP + 6 byte JMP. This might work around the problem. However, it's really low priority right now, since I'm mainly working on madExcept now...
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

P.S: Not sure if you alreay tried this, but newer madCodeHook versions have this new API:

Code: Select all

// restores the original code of the API/function (only first 6 bytes)
// the original code is read from the dll file on harddisk
// you can use this function e.g. to remove the hook of another hook library
// don't use this to uninstall your own hooks, use UnhookCode for that purpose
function RestoreCode (code: pointer) : bool; stdcall;
You could try calling this on wglSwapBuffers before installing your own API hook. That would remove Steam's API hook. Maybe doing so works around the problem?
softtouch
Posts: 111
Joined: Sat Jun 20, 2009 10:08 am
Contact:

Post by softtouch »

madshi wrote:P.S: Not sure if you alreay tried this, but newer madCodeHook versions have this new API:

Code: Select all

// restores the original code of the API/function (only first 6 bytes)
// the original code is read from the dll file on harddisk
// you can use this function e.g. to remove the hook of another hook library
// don't use this to uninstall your own hooks, use UnhookCode for that purpose
function RestoreCode (code: pointer) : bool; stdcall;
You could try calling this on wglSwapBuffers before installing your own API hook. That would remove Steam's API hook. Maybe doing so works around the problem?
What is the parameter for RestoreCode??? What do I have to provide there?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Just the API address.
softtouch
Posts: 111
Joined: Sat Jun 20, 2009 10:08 am
Contact:

Post by softtouch »

madshi wrote:Just the API address.
Thanks Mathias,

do you mean just the address I get via GetProcAddress, even its hooked?
How does the RestoreCode know what api it is?

Like:

lib:=LoadLibrary('ws2_32.dll');
p:=GetprocAddress(lib,'connect');
RestoreCode(p);
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You need to provide RestoreCode with the address of the original API. Depending on which API hooking method was used, GetProcAddress may return the address of the original API or not. E.g. when the export table was patched, GetProcAddress will return the address of the hook callback function and not the original API address. But then RestoreCode does not uninstall import or export table patches, anyway, so it's not much of a problem. The purpose of RestoreCode is *not* to unhook all kinds of API hooks. The purpose of RestoreCode is more limited/specific. RestoreCode does just what it claims to do, namely restoring the original API code of any given API. The only reason why I implemented RestoreCode is a situation like the topic of this thread, namely where multiple hooking libraries collide and installing madCodeHook API hooks results in stability issues. RestoreCode *may* help in this situation - or not, depending on how the other API hooking library behaves.
softtouch
Posts: 111
Joined: Sat Jun 20, 2009 10:08 am
Contact:

Post by softtouch »

Ah, I see. But I might anyway be able to use it for my purpose.
I [...] . This works so far, but is sure not the right way to do... then I saw RestoreCode and thought "thats it!"...
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Yes, RestoreCode works quite similar to what you're describing. However, I may modify RestoreCode to not allow removal of madCodeHook API hooks, just to be safe, because that's not the purpose of RestoreCode...
Post Reply