How to hook a member function of some class in C++ ?
zsnjuts opened this issue · 2 comments
I want to hook a member function of some class in C++, for example, Helper::func()
class Helper {
public:
void func(){
// do something here...
}
}
But I have not found related document here. Is this possible with plthook? If I want to achieve this, what efforts do I need to make? Thanks in advance.
I have not tested the following. I hope it is correct.
-
Methods defined in .cpp files
Possible. The second argument ofplthook_replace()
must be the corresponding mangled name.// In a header file class Helper { public: void func(); // declaration };
// In .cpp file Helper::func() { // do something here... // definition }
-
Methods defined in header files
Impossible. The method definition may be inlined though plthook hooks only inter-module method calls.// In a header file class Helper { public: void func() { // declaration // do something here... // definition } }
-
Virtual methods
Impossible. It needs another technique.
Is it possible to call the original c++ member function in the hooked function using the original address without knowing the type of the C++ class?