虚函数数组

时间:2011-08-16 11:13:22

标签: c++ class reverse-engineering

在逆向工程和使用外部类时,我经常尝试在我的库中重新定义这些类:

class GameEngine // Exported with "GetGameEngine"
{
public:
    virtual void foo1() = 0;
    virtual void foo2() = 0;
    virtual void foo3() = 0;
    virtual void foo4() = 0;
    virtual void foo5() = 0;
    virtual void foo6() = 0;
    virtual void foo7() = 0;
    virtual void foo8() = 0;
    virtual void foo9() = 0;
    virtual void foo10() = 0;
    virtual void foo11() = 0;
    virtual void foo12() = 0;
    virtual int GetGameStatus() = 0; //0x30
    virtual void foo14() = 0;
    virtual void foo15() = 0;
    virtual void foo16() = 0;
    virtual int AnotherUsefulFunction() = 0; //0x40
};

基本上我从外部调用GetGameStatus函数。是否有一些结构或可能性允许我这样写:

class GameEngine // Exported with "GetGameEngine"
{
public:
    FUNCTABLE(12);
    virtual int GetGameStatus() = 0; //0x30
    FUNCTABLE(14,16);
    virtual int AnotherUsefulFunction() = 0; //0x40
};

它会清理我的代码。

1 个答案:

答案 0 :(得分:4)

查看boost::preprocessor,特别是REPEAT宏。{这样的事情应该有效:

#include <boost/preprocessor/repetition/repeat.hpp>

#define FUNC(fun_z, fun_n, fun_data) virtual void foo ## fun_n () = 0;
#define FUNCTABLE(count) BOOST_PP_REPEAT(count, FUNC, 0)