C++ :获取函数虚拟“地址”;带成员函数指针
这个问题类似于 打印虚拟成员函数的地址
我想检索 a 的内存位置函数(在运行时),使用成员函数指针。目标是记录它们,并进行事后分析,使用 WinDbg 中的“ln”使用 PDB 符号检索它是哪个函数。
我无法使用堆栈遍历,因为我还没有进入我想要记录的函数。 (而且我不想修改数十亿个函数来返回它们的地址......)。
简短示例:
class AClass
{
public :
virtual AFunction(){;}
};
typedef void (AClass::*FxPtr)( void );
[...]
AClass oAClass;
AClass* pSelf = &oAClass;
FxPtr pf = &AClass::AFunction;
DWORD nFctAddress = ???
有人知道我如何检索地址吗?
&(pSelf->*pf)
给出“错误 C2298:”&“ :对指向成员函数表达式的指针进行非法操作'
我知道成员函数指针是'奇怪'的结构,但是由于我知道'this',有没有办法从vtable中查找潜在的虚拟函数?
问候,
参考:
This question is similar to
Print address of virtual member function
I would like to retrieve the memory location of a function (in runtime), using a member function pointer. The goal is to log them, and do a post-mortem analysis, using 'ln' in WinDbg to retrieve which function it was, using PDB symbols.
I can't use stack walking since I am not yet into the function I want to log.
(and I do not want to modify billions of functions to return me their address...).
Short sample:
class AClass
{
public :
virtual AFunction(){;}
};
typedef void (AClass::*FxPtr)( void );
[...]
AClass oAClass;
AClass* pSelf = &oAClass;
FxPtr pf = &AClass::AFunction;
DWORD nFctAddress = ???
Anyone has an idea how I can retrieve the address ?
&(pSelf->*pf)
gives 'error C2298: '&' : illegal operation on pointer to member function expression'
I know that member function pointers are 'weird' structures, but since I know the 'this', is there a way to look-up the potentially virtual function from the vtable ?
Regards,
refs:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
访问vtable很容易,但通过地址识别函数就没那么简单了。
一些选项:
1) 解析.map文件,加载并通过typeid(或通过map中的VMT实例)查找类名,然后通过其名称查找函数地址。
2)编写一个静态函数,为给定对象调用给定的虚方法,看看它是如何实现的
查看asm,并从其代码中检索函数在vtable中的偏移量,然后读取地址
3)有一些漂亮的选项,例如“/Gh启用_penter函数调用”,它允许检索
所有函数的地址,虽然在调用之后,但在函数实际执行任何操作之前。然后.map可以用来通过trace来识别函数。
Its easy to access vtable, but not so simple to identify the function by its address.
Some options:
1) Parse the .map file, load, and look up the class name by typeid (or by VMT instance from map), then function address by its name.
2) Write a static function calling a given virtual method for given object, see how it
looks in asm, and retrieve the function's offset in vtable from its code, then read the address
3) There're nifty options like "/Gh enable _penter function call", which allow to retrieve
addresses of all functions, after the call though, but before the function actually does anything. Then .map can be used to identify the function by the trace.
一切都在地图文件中。打开地图文件生成并享受。
It's all in the map file. Turn on map file generation and enjoy.