MFC静态反编译GetMessageMap相关查找方法

发布时间 2023-10-14 15:26:41作者: Yofoo

MFC中
GetMessageMap包含对多数消息处理的结构, 界面菜单,按钮都在这, 找到GetMessageMap很关键
struct AFX_MSGMAP_ENTRY
{
UINT nMessage; // windows message
UINT nCode; // control code or WM_NOTIFY code
UINT nID; // control ID (or 0 for windows messages)
UINT nLastID; // used for entries specifying a range of control id's
UINT_PTR nSig; // signature type (action) or pointer to message #
AFX_PMSG pfn; // routine to call (or special value)
};
struct AFX_MSGMAP
{
const AFX_MSGMAP* (PASCAL* pfnGetBaseMap)();
const AFX_MSGMAP_ENTRY* lpEntries;
};
这个相关结构就是 GetMessageMap 相关的主要数据

  1. 在OnPaint函数一般会调用 CPaintDC::~CPaintDC, 对话框还有 DrawIcon, 从这特征找到OnPaint, 然后找到 AFX_MSGMAP_ENTRY
  2. 搜索WM_COMMAND: 0x111, 一个地方数据出现多个, 也可能是AFX_MSGMAP_ENTRY
  3. 搜索CWnd::OnDestroy的引用, 一般窗体的MSGMAP会有 WM_DESTROY, 函数会调用CWnd::OnDestroy, 或直接转跳
  4. 搜索WM_TIMER, 相关序列前5个一起搜, <WM_TIMER, 0, 0, 0, 0Dh, offset OnTimer>, 这个参数AfxSig不同版本不一样会有些不好用
  5. 找到CDialog::CDialog 再找到 CDialog::`vftable', 其中 CCmdTarget::GetTypeLib的下一个函数就是 GetMessageMap