Hooking CGInputCtrl_OnMouseMoveRel menu

User Tag List

Results 1 to 15 of 15
  1. #1
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hooking CGInputCtrl_OnMouseMoveRel

    Hello everybody!

    Im trying to get friend with hooking functions from WoW. Or to be more precise (cause hooking isnt a problem any more ) creating prototypes of the functions. I want to take CGInputCtrl_onMouseMoveRel (Offset: 0x57FFB0 3.2.2a) as a first example. I took IDA and found the following:
    Code:
    .text:0057FFB0 sub_57FFB0      proc near               ; CODE XREF: .text:0049AA3Cp
    .text:0057FFB0
    .text:0057FFB0 var_18          = dword ptr -18h
    .text:0057FFB0 var_14          = dword ptr -14h
    .text:0057FFB0 var_C           = dword ptr -0Ch
    .text:0057FFB0 arg_0           = dword ptr  8
    So what i think now:
    The function has 1 Argument, which may be CGInputCtrl* this. So it may look like:
    RETURNTYPE CGInputCtrl::OnMouseMoveRel();

    Now we have to go to the returntype. That to be honest is a bit more a problem for me. From what i have learned the returnvalue is put in eax so i try to take a look on eax at the end:
    Code:
    .text:00580093                 pop     edi
    .text:00580094                 pop     esi
    .text:00580095                 pop     ebp
    .text:00580096                 retn    4
    .text:00580096 sub_57FFB0      endp
    So for me this looks like there is no returnvalue so i think it may be like this:
    void CGInputCtrl::OnMouseMoveRel().

    Now my questions:
    Would you agree with what i have found there?

    Greetings
    Cromon

    Hooking CGInputCtrl_OnMouseMoveRel
  2. #2
    kynox's Avatar Member
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're partly right, it has one argument indeed, but the argument isn't the CGInputControl class; it's a float as verified by this line:
    .text:00580048 fld [ebp+arg_0]
    You can also tell that it is of the "thiscall" calling convention as verified by the preservation of ecx:
    .text:0057FFC6 mov esi, ecx
    So in summary, the proper prototype is:
    void (__thiscall * CGInputControl__OnMouseMoveRel)(void *this, float floatArg)

  3. #3
    ggg898's Avatar Member
    Reputation
    10
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @kynox,

    I wonder if theres a easy general way to see if a function is thiscall or stdcall, since both passes arguments i registers?

    thanks

  4. #4
    kynox's Avatar Member
    Reputation
    830
    Join Date
    Dec 2006
    Posts
    888
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Err, read my second point.

  5. #5
    ggg898's Avatar Member
    Reputation
    10
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondered if that was in general. thanks.

  6. #6
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Kynox!

    Thanks for that! To pratice a bit i just took the next function in the list, CGInputCtrl_ToggleControlBit.

    So, im trying the same approach:
    Code:
    .text:00581230 arg_0           = dword ptr  8
    .text:00581230 arg_4           = dword ptr  0Ch
    .text:00581230 arg_8           = dword ptr  10h
    .text:00581230 arg_C           = dword ptr  14h
    4 arguments, type may be figured out when looking whats done with'em later.

    Then we find mov esi, ecx before anything is made on ecx so this again may be __thiscall, so far:
    T CGInputCtrl::ToggleControlBit((4byte)arg1, (4byte)arg2, (4byte)arg3, (4byte)arg4);

    The last "chunk" looks as following:
    Code:
    .text:00581289 loc_581289:                             ; CODE XREF: CGInputCtrl__ToggleControlBit+2Aj
    .text:00581289                 pop     edi
    .text:0058128A                 pop     esi
    .text:0058128B                 pop     ebx
    .text:0058128C                 pop     ebp
    .text:0058128D                 retn    10h
    So this looks for me again like no returnvalue, so
    void CGInputCtrl::ToggleControlBit(a0, a1, a2, a3);

    for the types i cant really figure out what they should but they are compared [ebp + argX], 0 i guess it may be a numerical type like float or int. From the context i would say these are integers
    Code:
    void CGInputCtrl::ToggleControlBit(int, int, int, int)
    Will test that as soon as i can. Maybe you see a major error.

    Greetings

  7. #7
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ggg898 View Post
    @kynox,

    I wonder if theres a easy general way to see if a function is thiscall or stdcall, since both passes arguments i registers?

    thanks
    __stdcall doesn't pass arguments in registers... Wtf are you talking about?

  8. #8
    ggg898's Avatar Member
    Reputation
    10
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Cypher, i dunno. Im sick and am taking antibiotics, it might even make me more stupid than usual.

    What ive been wondering is how do you know if it is thiscall or fastcall, since both passes stuff in ecx. Its no actual problem, just curious.
    Last edited by ggg898; 11-27-2009 at 06:15 AM.

  9. #9
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ggg898 View Post
    @Cypher, i dunno. Im sick and am taking antibiotics, it might even make me more stupid than usual.

    What ive been wondering is how do you know if it is thiscall or fastcall, since both passes stuff in ecx. Its no actual problem, just curious.
    MSDN to the rescue!

    WHOOSH!

    __fastcall (C++)
    __thiscall (C++)

    Read those two pages. The answer should be obvious.

    EDIT:

    By the way, no, antibiotics wouldn't cause such a side effect under usual circumstances.

  10. #10
    ggg898's Avatar Member
    Reputation
    10
    Join Date
    Jan 2009
    Posts
    39
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    EDIT:

    By the way, no, antibiotics wouldn't cause such a side effect under usual circumstances.
    Damn, I was really hoping that was it.

  11. #11
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is pretty helpfull, started to learn reversing with this:

    x86 Disassembly/Calling Conventions - Wikibooks, collection of open-content textbooks
    Hey, it compiles! Ship it!

  12. #12
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yes, that looks interesting, that helps a lot reversing!

    Now im facing a final problem:
    Detouring __thiscall. I googled a lot and found several sometimes strange methods to detour __thiscall functions. Sadly every of these methodes result in a ACCES_VIOLATION. Anybody has a hint how i manage that __thiscall?

    Greetings
    Cromon

  13. #13
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Detouring a __thiscall function is no different to detouring any other type of function. Just ensure that you preserve the correct registers and perform any necessary stack cleanup.

    In the case of __thiscall you need to preserve the value of ECX, and pop the appropriate amount of bytes off the stack if you return without calling the trampoline.

  14. #14
    Cromon's Avatar Legendary


    Reputation
    840
    Join Date
    Mar 2008
    Posts
    714
    Thanks G/R
    0/7
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oukey, i will try that. I wanted to make it pretty much like that:
    hook the function
    call the original using __asm
    return without returnvalue (its void)

    Should i write the hook as __declspec(naked) to prevent ECX getting manipulated on any way during the prolog?

  15. #15
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Though, it may not matter. I'd do it to be on the safe side since it won't hurt performance or anything.

Similar Threads

  1. Hooking up unused instances
    By iindigo in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 09-22-2007, 08:13 PM
  2. Need Help....Hooking Signals
    By shindaustin in forum World of Warcraft Emulator Servers
    Replies: 19
    Last Post: 09-03-2007, 04:44 PM
  3. Hooking Signals
    By Banksey in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 08-31-2007, 01:26 AM
  4. Music ya dj hook ya up with some beats.
    By DJ Zodiac in forum Community Chat
    Replies: 1
    Last Post: 07-27-2007, 03:45 AM
  5. Hook a brother up..
    By HaSh in forum World of Warcraft General
    Replies: 0
    Last Post: 01-21-2007, 03:36 PM
All times are GMT -5. The time now is 02:07 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search