65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
using namespace std;
void print() {
cout << "asdf\n";
}
class tt;
typedef int (tt::*MM)() ;
class tt{
public:
void (*p) ();
tt() {
p = &(::print);
}
int a() {
cout << "public a function!\n";
return 1;
}
MM get_x() {
return &tt::x;
}
private:
int x() { cout << "private a function!\n";
return 1;
}
};
int main() {
cout << sizeof(tt) << endl; //4 not 1, void *p in class tt is a val, not a function! so sizeof is 4
tt a;
a.p();
cout << &tt::a << endl;
MM myf = &tt::a; //获取共有成员函数
(a.*myf)(); //like this
MM myf1 = a.get_x();
(a.*myf1)();
}
// 计算函数真实地址
unsigned char* funaddr= (unsigned char*)f;//void f(){}
if(funaddr[0]==0xE9)// 判断是否为虚拟函数地址,E9为jmp指令
{
unsigned long realaddr=(unsigned long)f;
realaddr += funaddr[2]*0x100 +funaddr[1] +5;
printf( "函数实际地址:0x%0X\n", realaddr);
}