report: GetCurrentSessionId get exception

c++ / delphi package - dll injection and api hooking
Post Reply
wd369
Posts: 3
Joined: Thu Dec 19, 2013 9:09 am

report: GetCurrentSessionId get exception

Post by wd369 »

I used MadCodeHook V3.1.6, licensed version, Link 32bit madCodeHook static library in WIN32 MFC APP on Windows 7 64 bits English OS.
run GetCurrentSessionId as this sequence case: GetCurrentSessionId _1, InitializeMadCHook(), HookAPI ..., FinalizeMadCHook(), GetCurrentSessionId _2.

The GetCurrentSessionId _2 got a 0xC0000005: Access violation writing location 0xffffffff.
if GetCurrentSessionId _2 run before FinalizeMadCHook(), then runs ok.
GetCurrentSessionId _1 always runs ok.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: report: GetCurrentSessionId get exception

Post by madshi »

You should never call any madCodeHook APIs outside of InitializeMadCHook()/FinalizeMadCHook(). Some of the APIs might succeed, some might silently fail, some might crash, if you call them before InitializeMadCHook() or after "FinalizeMadCHook()".

Or is there a specific situation where you can't avoid having to call some APIs after FinalizeMadCHook()? I don't see why that should happen.
wd369
Posts: 3
Joined: Thu Dec 19, 2013 9:09 am

Re: report: GetCurrentSessionId get exception

Post by wd369 »

thanks, I never paid that much attention to call any madCodeHook APIs must inside of InitializeMadCHook()/FinalizeMadCHook().
sometime I call some API e.g. GetCurrentSessionId directly without InitializeMadCHook() before, I should check that code now . :oops:
wd369
Posts: 3
Joined: Thu Dec 19, 2013 9:09 am

Re: report: GetCurrentSessionId get exception

Post by wd369 »

Hi Madshi, is enough using a pair of InitializeMadCHook on begin /FinalizeMadCHook on end for a multi-thread MS VC application or dll?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: report: GetCurrentSessionId get exception

Post by madshi »

Sorry for the late reply. Yes, one pair of InitializeMadCHook()/FinalizeMadCHook() is enough. Actually, please do not call it more than once.
Post Reply