Can you hook class methods or class constructors?

Nov 12, 2014 at 7:08 PM
Sorry if I've missed a post that covers this topic, maybe I just couldn't cobble together the right search string.

But I'd like to know if its possible to hook class methods and constructors. Its easy to hook global functions out of a .dll like MessageBeep(), but I can't figure out how to hook into a class.

For example, the constructor Pen.Pen(const Color, REAL) and the method Pen.GetColor out of the gdiplus.dll library. How can I insert myself into these?

Just for clarification, everything I'm working with is in C++.
Nov 19, 2014 at 10:00 AM
Yes you can hook these methods. To hook class methods you need to determine the correct address (it is the same for all instances), if you are able to you can create an instance of the object, then check the VTable for the function index you are interested in to get the address. I'm fairly certain that the constructor will be there also.

Just be sure to add the "this" pointer argument to your function declaration as the first parameter.