__thiscall convention question, whilst injected. menu

User Tag List

Results 1 to 11 of 11
  1. #1
    lweid's Avatar Corporal
    Reputation
    1
    Join Date
    Mar 2011
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    __thiscall convention question, whilst injected.

    So thanks to alot of you on this forum, I have been able to write alot of different tools and also learn a great deal. To name a few _Mike, amadmonk, and icefire32 (Ende) calling a function that does not use the _thiscall convention is easy to set up with a typedef and a function pointer.

    I can easily reverse a function that uses _thiscall, and then I know to retrieve the (hidden) so to speak*this pointer that is passed when invoking a member function.

    However what I do not understand is, what would a typedef look like for this kind of function, would I need to include *this as an argument? Also, how can I feed it a valid class pointer?

    Thanks

    __thiscall convention question, whilst injected.
  2. #2
    namreeb's Avatar Legendary

    Reputation
    658
    Join Date
    Sep 2008
    Posts
    1,023
    Thanks G/R
    7/215
    Trade Feedback
    0 (0%)
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    In C# it looks something like this:

    Code:
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            private delegate IntPtr SendGameDataDelegate(IntPtr thisPtr, IntPtr bufferPtr, bool boolean);
    Where the 'thisPtr' variable corresponds to the ECX register. The other two parameters are normal.

  3. #3
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can just use normal member function syntax.

    Code:
    class Obj
    {
    public:
        int Foo(int i) { return i; }
    }
     
    // could use __thiscall to make it explicit
    typedef void (__thiscall Obj::*FooPtr)(int);
     
    int main(int argc, char* argv[])
    {
        Obj obj;
        FooPtr ptr = &Obj::Foo;
     
        int i = (obj.*ptr)(5);
       assert(i == 5);
     
        // or with pObj as synonym for the this ptr: 
        Obj* pObj = &obj;
        i = (pObj->*ptr)(5);
     
       assert(i == 5);
    }
    This works as long as WoW's compiler uses the same calling conventions as yours.
    They use some version (together with runtime version 8.0) of MS' compiler, so you will be perfectly fine with using visual studio.
    Just remember, GCC uses a different thiscall calling convention (http://www.mmowned.com/forums/world-...n32-mingw.html).

    Edit: code format is ****ed up...
    Last edited by Bananenbrot; 04-10-2011 at 04:49 AM.

  4. #4
    lweid's Avatar Corporal
    Reputation
    1
    Join Date
    Mar 2011
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help namreeb much appreciated

    Bananenbrot you too, Im not sure if you were just trying to paint me a clear picture to help me understand better (which you did ) however correct me if im wrong here maybe im just retarted, but my function would need the address of an actual WoW subroutine yes? And it would also then need to use the ECX register for the *this pointer to the object. Unless of course you guys are somehow "emulating" the object based off alot of analysis or something.

    My typedef in cpp looks like this -

    typedef DWORD(__thiscall *mfunc)(Obj *pThis, DWORD a1, DWORD a2);
    and then since im injected, I set it manually like this -

    mfunc funct=(mfunc)((DWORD)GetModuleHandle(NULL)+import[13]);
    // import[13] is the offset of this subroutine

    so what I dont understand here is, should I be using some "place holder" so to speak object for the *this parameter and then just obtain ECX and pass it?

  5. #5
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what you mean by placeholder.
    Say you're trying to call one of the CGUnit_C methods.. You just pass the address* of the unit object as the first parameter.
    You don't have to worry about manually setting registers. The compiler will know to pass the first parameter (pThis in your case) in ecx when you declare the function pointer as thiscall.

    *) There are tons of posts here on how to get these addresses. Just search for any of the object manager threads.

  6. #6
    lweid's Avatar Corporal
    Reputation
    1
    Join Date
    Mar 2011
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks _Mike, that all makes sense to me, I also have the location of this object already. So what I am still not sure on, is what the data type needs to be for the parameter of that first argument? can it just be an unsigned int*?

    so then the typedef would look like -

    typedef DWORD(__thiscall *mfunc)(DWORD *pThis, DWORD a1, DWORD a2);
    and the call would look like (after the function pointer has been assigned a proper location), and 0xdeadbeef is the object -

    dwFunc((DWORD*)0xdeadbeef,0,0)
    assuming what you said before, that the compiler knows to pass ecx the pointer to said object.

    or am i still brain dead :P

  7. #7
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lweid View Post
    thanks _Mike, that all makes sense to me, I also have the location of this object already. So what I am still not sure on, is what the data type needs to be for the parameter of that first argument? can it just be an unsigned int*?
    Technically it should be a class pointer of the type of class that the function is a member of. But any pointer type (or any data type with the same size as a pointer, but beware of portability issues) works.

    so then the typedef would look like -
    Code:
    typedef DWORD(__thiscall *mfunc)(DWORD *pThis, DWORD a1, DWORD a2);
    and the call would look like (after the function pointer has been assigned a proper location), and 0xdeadbeef is the object -
    Code:
    dwFunc((DWORD*)0xdeadbeef,0,0)
    assuming what you said before, that the compiler knows to pass ecx the pointer to said object.

    or am i still brain dead :P
    Correct for MSVC. GCC does it a bit differently, see Bananenbrot's link above for details if that's what you're using.

  8. #8
    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)
    Whenever I used a prototype as such, MSVC threw an error. I had to use inline asm to get the results I wanted. Completely possible that I was doin' it wrong though.

  9. #9
    lweid's Avatar Corporal
    Reputation
    1
    Join Date
    Mar 2011
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again _Mike, much appreciated.

    Also lanman, that happens to me too sometimes, to which i just resort to inline asm and it always works out in the end. Its a messy way of doing things but for me its just a hobby and a way to learn more.

  10. #10
    amadmonk's Avatar Active Member
    Reputation
    124
    Join Date
    Apr 2008
    Posts
    772
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Class inner method pointer typedefs have been pretty much a black art (at least until the advent of the STL function pointers wrappers). I'm not surprised the compiler puked. I did the testing on ISO compatibility for class inner pointers back on MSVC 2k3, and there were a LOT of ICE's (internal compiler errors) back in the day...
    Don't believe everything you think.

  11. #11
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by amadmonk View Post
    Class inner method pointer typedefs have been pretty much a black art (at least until the advent of the STL function pointers wrappers). I'm not surprised the compiler puked. I did the testing on ISO compatibility for class inner pointers back on MSVC 2k3, and there were a LOT of ICE's (internal compiler errors) back in the day...
    If you think the STL binders are cool, you should check out Phoenix v3.

Similar Threads

  1. [Question] Why injection doesnt work
    By sercankd in forum WoW Memory Editing
    Replies: 23
    Last Post: 07-17-2014, 08:40 PM
  2. [Question] Thread Injections Confused
    By adapa in forum WoW Memory Editing
    Replies: 10
    Last Post: 08-20-2011, 09:05 PM
  3. [Question] Assembly injection
    By Millow in forum WoW Memory Editing
    Replies: 3
    Last Post: 11-25-2010, 11:37 AM
  4. [Question]DLL Injection
    By hestas in forum WoW Memory Editing
    Replies: 12
    Last Post: 11-18-2009, 02:26 PM
  5. [Question] Create and inject your own model?
    By synthblade in forum WoW ME Questions and Requests
    Replies: 4
    Last Post: 05-21-2008, 01:13 AM
All times are GMT -5. The time now is 11:26 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search