1. Post #1
    high6's Avatar
    September 2008
    197 Posts
    Okay so what I am trying to do is create a base class for hooking a place in memory. Now you cannot have naked member functions so this is my idea for a work around.


    Basically,
    The call is redirected to the block of assembly.
    The block of assembly calls the "RawCallback" member function.
    The raw block of assembly returns the redirected call.

    So my problem is
    *(int*)(AsmDest + 0x8) = (int)(this->RawCallback);

    How do I get the address of a member function (in int form)? Also I plan on inheriting this base class so I need the function to grab the address of the inheriting RawCallBack. I am guessing I need to make it virtual? But the question still stands, how do you get it's address (in int form)?

  2. Post #2
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,691 Posts
    If RawCallback was made virtual, this would work:
    CHook* hook = new CHook(tar, des, tra);
    int* vtable = *(int**)hook;
    int rawCallbackAddr = *vtable; //"Safe" because it's the only virtual function.
    
    However, it relies on the fact that the hook and child classes all have RawCallback as the first virtual function, and there's no guarantee for that in any compiler.

    Are you sure member function pointers won't do in your case?

  3. Post #3
    high6's Avatar
    September 2008
    197 Posts
    How would you use member function pointers in this case?

    Do you mean to get the address? Or to use them for my overall goal instead of the hacky assembly?

  4. Post #4
    Gold Member
    jA_cOp's Avatar
    May 2006
    2,691 Posts
    How would you use member function pointers in this case?

    Do you mean to get the address? Or to use them for my overall goal instead of the hacky assembly?
    To store a callback function. I'm still not quite sure what you're trying to do, though.

    C++ member function pointers are very limited anyway, so they're probably useless in your case too.

  5. Post #5
    high6's Avatar
    September 2008
    197 Posts
    Ah I get what you are saying. I guess that will work for what I want :D. Thanks.