Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

low level Hooker

I want to make a hook that will act like "event" (and not with agly GetAsyncKeyState) in C# (I want to do it in C++). so, I've made a dll with this content: http://pastebin.com/yEHJKSS7 .

well, it doesn't call to Handler Function.

by the way, here's how I used the dll:

void KeysHandler(int vkKey, int flags)
{
    if(vkKey == VK_ESCAPE)
        exit(0);
    File << vkKey << endl << flags << endl;
}

int main
{
    SetHandler(HandlerFunc);
    //sleep here
}

edit: now I saw how I can "debug" in the dll, here are the findings: the SetWindowsHookEx returns 255 - i think it's starnge because it worth to char exactly - I'm going to check in the documentation what does it mean.

edit: 255 is valid return value :O only NULL (0) is error.

I have no idea what's the problem.

edit: well, now my friend brought me a hooker that worked for him. and guess... it didn't work.

I decided it's very strange so I did GetLastError and got 127 - procedure haven't found. I don't see any reason my procedure won't be found, help please :(

like image 381
Ohad Avatar asked Nov 15 '22 08:11

Ohad


1 Answers

Is your main really only calling SetHandler followed by sleep?

You need a MessageLoop in order for any events to be called.

like image 145
AShelly Avatar answered Dec 06 '22 07:12

AShelly