获取重载运算符的内存地址

Get memory address of overloaded operator?

本文关键字:内存 地址 运算符 重载 获取      更新时间:2023-10-16

MyString类头文件的提取。

class MyString
{
...
public:
    bool IsEmpty(void) const;
    bool operator==(MyString const &)const;
    bool operator==(char const *)const;
...
};

现在我在汇编程序中调用MyString的一个方法,它工作得很好。

__declspec(naked)
void Injected() {
    __asm {
        //setup Call Parameters
        //...
        call MyString::IsEmpty  //bool IsEmpty(void) const;
    }
}

对该方法有效的东西对操作员无效。是否可以获取重载运算符的地址并在汇编程序中调用它?

__declspec(naked)
void Injected() {
    __asm {
        //setup Call Parameters
        //...
        call MyString::operator==  //bool operator==(char const *)const;
    }
}

根据msdn文档"__asm块只能调用未重载的全局C++函数。"

一种解决方案是添加一个可以从asm调用的辅助函数。类似于:

bool equalCharPtr(char const *str)const { return *this == str; }

当然,这只适用于Visual C++。其他编译器可能有所不同。