Results 1 to 13 of 13
  1. #1
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow

    Some sort of hook

    After seeing BlackAngels little snippet on a simple keyboard hook I wanted to go a little more in depth with hooks so instead of a keyboard hook I tryed something else and it's been nothing but torture.
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    HHOOK Hook;
    HMODULE Mod;
    
    LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam)
    {
            if(code == HC_ACTION)
            {
                    PCWPSTRUCT info = (PCWPSTRUCT)lParam;
                    return CallNextHookEx(Hook,code,wParam,lParam);
            }
    }
    
    int main()
    {
        MSG msg;
        Mod = GetModuleHandle(NULL);
        if(!Mod)
        {
                return 0;
        }
        Hook = SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,Mod,0);
        if(!Hook)
        {
                 return 0;
        }
        GetMessage(&msg,0,0,0);
        cin.get();
    }
    Compiles fine. Everytime I run it it gives me an access violation error and every single program closes and explorer.exe closes. Slow moving trial and error.

    Not sure if i'm going in the right direction here but, I was trying to edit any messages that were being sent so that they could do something else. I'm in no hurry, this is all just for practice.

    Any help is appreciated, thanks.

  2. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Im not sure if you can hook CallWndProc... in fact I'm pretty sure that a lot of programs use that including the SetWindowsHook funchtion, but I'm not sure o_O... doesn't seem like a good idea.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  3. #3
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Code:
    HHOOK SetWindowsHookEx(      
        int idHook,
        HOOKPROC lpfn,
        HINSTANCE hMod,
        DWORD dwThreadId
    );
    Code:
    idHook
        [in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
    
        WH_CALLWNDPROC
            Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
    If I wasn't able to do that, why would MSDN include that?
    MSDN lied to me..

    SetWindowsHookEx Function()

  4. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Oh. my bad... hmmmm.. wonder what the problem. Maybe I can figure it out with zero understanding of Hooking =/

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #5
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by why06 View Post
    Oh. my bad... hmmmm.. wonder what the problem. Maybe I can figure it out with zero understanding of Hooking =/
    I also have zero understanding of hooking.
    I just find it weird how all my programs + explorer.exe close after access violation error.

  6. #6
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    add a 'return 0' at the very end of your callback.

    Also:
    The CallWndProc hook procedure can examine the message, but it cannot modify it. After the hook procedure returns control to the system, the message is passed to the window procedure.

  7. #7
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by B1ackAnge1 View Post
    add a 'return 0' at the very end of your callback.
    Tryed that already. Outcome stays the same.

    The CallWndProc hook procedure can examine the message, but it cannot modify it. After the hook procedure returns control to the system, the message is passed to the window procedure.
    Thanks, I think I found what i'm looking for but I'm still having trouble.
    GetMsgProc Function()

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    HHOOK Hook;
    
    HMODULE Mod;
    MSG *msg;
    
    
    LRESULT CALLBACK Proc(int code, WPARAM wParam, LPARAM lParam)
    {
            msg = (MSG*)lParam;
            
            if(msg)
            {
                   cout <<"Test";
            }
            
            return CallNextHookEx(Hook,code,wParam,lParam);
    }
    
    int main()
    {
        Mod = GetModuleHandle(NULL);
        if(!Mod)
        {
                return 0;
        }
        Hook = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)Proc,Mod,0);
        if(!Hook)
        {
                 return 0;
        }
        GetMessage(msg,0,0,0);
        
        cin.get();
    }
    Not sure if that's right but, GetMsgProc is called whenever GetMessage catches a message and the callback should output "Test" everytime it catches something but nothing happens. I'm testing by pressing any button on the keyboard, I think it should be sending WM_KEYDOWN or WM_SYSKEYDOWN. Correct me if i'm wrong.

  8. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Try using PeekMessage() instead of GetMessage(). GetMessage will freeze up until a message is sent. Also it requires you to do something with that message. So I imagine your freezing all the messages running through every application running on Windows.

    EDIT: Oh nvm.. guess you needed GetMsgProc... my bad. >_>
    Last edited by why06; 11-24-2009 at 04:11 PM.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  9. #9
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by why06 View Post
    Try using PeekMessage() instead of GetMessage(). GetMessage will freeze up until a message is sent. Also it requires you to do something with that message. So I imagine your freezing all the messages running through every application running on Windows.

    EDIT: Oh nvm.. guess you needed GetMsgProc... my bad. >_>
    Lolwhat?

    Even if GetMessage Freezes it's still getting any message sent. And once a message is sent GetMsgProc will be called and if my hook actually works it should output whatever.

  10. #10
    Azathoth69420's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    Did you escalate your privileges?

  11. #11
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by Azathoth69420 View Post
    Did you escalate your privileges?
    Keyboard hook worked fine without changing any privileges. I think i'm just doing something wrong...I just don't see it.

  12. #12
    Thats the way it is's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Posts
    95
    Reputation
    9
    Thanks
    11
    My Mood
    Tired
    Quote Originally Posted by B1ackAnge1 View Post
    add a 'return 0' at the very end of your callback.

    Also:
    for the record no return 0 is auto return 0 in most compilers it doesnt makes a difrend
    Cause There ain't no rest for the wicked

  13. #13
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    Quote Originally Posted by Thats the way it is View Post
    for the record no return 0 is auto return 0 in most compilers it doesnt makes a difrend
    Only in a few select situations and even then it's a nasty habit to just assume it'll return 0; It's right up there on the list of things to never do next to 'system("Pause")' or 'delete this'

Similar Threads

  1. i need some sort of tut
    By Sunday. in forum CrossFire Discussions
    Replies: 4
    Last Post: 01-12-2011, 09:03 AM
  2. some sort of AIM bot, I think
    By biggless in forum Other MMORPG Hacks
    Replies: 0
    Last Post: 12-09-2010, 12:45 PM
  3. some sort of pirate native
    By Decipher in forum Showroom
    Replies: 22
    Last Post: 10-22-2010, 05:24 PM
  4. proxy of some sort?
    By ledzepfan1 in forum Entertainment
    Replies: 15
    Last Post: 10-27-2007, 07:37 PM
  5. Some sort of riddle
    By System79 in forum Entertainment
    Replies: 10
    Last Post: 10-09-2006, 06:28 PM

Tags for this Thread