Hooking Rule #7

c++ / delphi package - dll injection and api hooking
Post Reply
jossanjo
Posts: 18
Joined: Thu Jul 15, 2004 9:30 am

Hooking Rule #7

Post by jossanjo »

Hi Mathias,

I have noticed a strange behavour when I using GetClassNameW in a DLL that is injected in the window process (I am using your inject method). As soon as I call GetClassNameW in there I get an "Invalid access to memory location" error. However - if I use the non-wide version (GetClassName) everything works fine. Also if I use the GetClassNameW in a normal stand alone exe-application it works fine:

var wclassnameBuffer : array [0..255] of widechar;
if GetClassNameW(winHandle), wclassnameBuffer, SizeOf(wclassnameBuffer)) > 0

I've read your hooking rule #7 about beeing careful when using Unicode in callback functions in the hooking world but you also state that "It only applies to wide hook callbacks in winNT" - but as far as I understand I don't have any wide hook callbacks. But maybe there is something more in this rule I don't know/understand.

Do you have any idea why I get this error?

Kind Regards
Thomas
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Hmmmm... Not sure what this could be. You could try allocating the buffer for the class name instead of using a local wide char array. Maybe the stack is so full, that the local array is too much? Just guessing. If that doesn't help, post the full crashing hook callback function, please.
uall
Posts: 254
Joined: Sun Feb 20, 2005 1:24 pm

Post by uall »

yes, you should post the complete callback

in the most forums i noticed that some guys create threads and post
"why does this crash, i do it exactly this way <code>"

but they dont post the complete source and the error isnt in the lines which they posted

i mean:
if GetClassNameW(winHandle), wclassnameBuffer, SizeOf(wclassnameBuffer)) > 0
is NEVER the line u use! because, delphi doesnt compile it, because
"GetClassNameW(winHandle)" isnt a valid call ;)
Post Reply