• Get member function address?
    4 replies, posted
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. [cpp][/cpp] 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)?
If RawCallback was made virtual, this would work: [cpp] CHook* hook = new CHook(tar, des, tra); int* vtable = *(int**)hook; int rawCallbackAddr = *vtable; //"Safe" because it's the only virtual function. [/cpp] 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?
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?
[QUOTE=high6;15989947]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?[/QUOTE] 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.
Ah I get what you are saying. I guess that will work for what I want :D. Thanks.
Sorry, you need to Log In to post a reply to this thread.