标题 简介 类型 公开时间
关联规则 关联知识 关联工具 关联文档 关联抓包
参考1(官网)
参考2
参考3
详情
[SAFE-ID: JIWO-2025-560]   作者: ecawen 发表于: [2017-09-07]

本文共 [424] 位读者顶过

最近有朋友问我libcef如何注入js,然后又谈到微信用了libcef云云。

捣腾了一下午,知道怎么注入js后,发现朋友是需要auto control ui

瞬间崩溃。。。。

诚然微信有些浏览器功能用到了cef,但是主界面是duilib写的

跟cef没毛关系,(libcef封装到qbcore.dll里面,想注入js需要hook libcef的导出函数

拿到browser,替换callback……)

[出自:jiwo.org]

话题回到pc端微信怎么auto control ui,以及如何拿到”控件“上面的信息


下面为原理截图,看不懂请参考duilib源码


CWindowWnd 指针可以通过GetWindowLongPtr获取


CWindowWnd指针 == WindowImplBase指针

然后通过

1
static_cast(pWinImplBase)

转换得到INotifyUI指针,再通过虚函数地址表就能找到Notify指针

最后替换Notify指针就能监控到所有duilib事件了


事件结构体,pSender是事件的触发者,我们后面通过获取root节点就能得到所有CControlUI

这个结构我们可以伪造出来,然后直接调用原始Notify回调就能模拟界面操作了


每一个xml创建CControlUI 树的时候,都会调用CDialogBuilder::Create

我们通过hook这个函数,返回就能得到root节点

这里是duilib的container节点原理,如果父亲是一个容器节点,就把自己添加到父亲里面


得到节点树之后,我们需要枚举所有节点

看看这些虚函数是不是很可爱,很方便,有没有想到com技术

这个虚函数更可爱,哈哈

可爱到我不需要判断数量,只需要判断结果是否为NULL就能知道是否枚举结束


原理图都贴了,最好自己看看duilib源码,pc端微信界面是duilib写的,基本的虚函数偏移没有变化,说明腾讯没有大改动duilib(添加虚函数)

当然,我发现有些结构被改动过,这里就不提了。

关于duilib的消息流动,自己可以好好看看源码。


以下为部分代码,自行完成完整版


1
2
3
4
5
6
7
8
9
10
//hook CDialogBuilder::Create
/*
CControlUI* CDialogBuilder::Create(IDialogBuilderCallback* pCallback, CPaintManagerUI* pManager, CControlUI* pParent)
*/
VOID WINAPI CDialogBuilder_Create_Ret(CControlUI* pControlUI)
{
    TRACE_LOG_INFO(_T("CDialogBuilder::Create Ret ..."));
    if (pControlUI)
        enumContainer(pControlUI);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//遍历控件的信息
void enumContainer(CControlUI * pControlUI)
{
    LPCTSTR lpcszClass = pControlUI->GetClass();
    LPCTSTR lpcszName = pControlUI->GetName();
    LPCTSTR lpcszText = pControlUI->GetText();
    if (lpcszClass)
        TRACE_LOG_INFO(_T("%s"), lpcszClass);
    if (lpcszName)
        TRACE_LOG_INFO(_T("%s"), lpcszName);
    if (lpcszText)
        TRACE_LOG_INFO(_T("%s"), lpcszText);
    if (CDuiString(_T("session_list")) == pControlUI->GetName())
    {
        g_session_list = pControlUI;
    }
    if (CDuiString(_T("contact_list")) == pControlUI->GetName())
    {
        g_contact_list = pControlUI;
    }
      
    IContainerUI *pContainerUI = static_cast(pControlUI->GetInterface(_T("IContainer")));
    if (pContainerUI)
    {
        int i = 0;
        CControlUI * pControlIter = NULL;
        while (pControlIter = pContainerUI->GetItemAt(i++))
        {
            enumContainer(pControlIter);
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//hook event notify
class CHookNotify : INotifyUI
{
public:
    typedef void(CHookNotify::*pfn_Notify)(TNotifyUI& msg);
    void Notify(TNotifyUI& msg)
    {
        extern CHookNotify::pfn_Notify g_pfn_oldnotify;
          
          
        return (this->*g_pfn_oldnotify)(msg);
    }
};
CHookNotify::pfn_Notify g_pfn_oldnotify = NULL;
DWORD WINAPI test_thread(
    LPVOID lpThreadParameter
    )
{
    MessageBox(NULL, NULL, NULL, MB_OK);
    HWND hMainWnd = FindWindow(_T("WeChatMainWndForPC"), NULL);
    if (!hMainWnd)
    {
        TRACE_LOG_INFO(_T("%s"), _T("FindWindow Error ..."));
        return 0;
    }
    CWindowWnd *pThis = reinterpret_cast(::GetWindowLongPtr(hMainWnd, GWLP_USERDATA));
    if (!pThis)
    {
        TRACE_LOG_INFO(_T("%s"), _T("Get CWindowWnd Pointer Error ..."));
        return 0;
    }
    HWND *phWnd = reinterpret_cast(((uintptr_t)pThis + sizeof(uintptr_t)));
    if (IsBadReadPtr(phWnd, sizeof(HWND)))
    {
        TRACE_LOG_INFO(_T("%s"), _T("Pointer Invalid Error ..."));
        return 0;
    }
    if (*phWnd != hMainWnd)
    {
        TRACE_LOG_INFO(_T("%s"), _T("Invalid CWindowWnd Pointer Error ..."));
        return 0;
    }
    //WindowImplBase * == CWindowWnd *
    WindowImplBase *pWinImplBase = reinterpret_cast(pThis);
    INotifyUI *pNotifyThis = static_cast(pWinImplBase);
    CHookNotify::pfn_Notify *p_pfn_oldnotify = *reinterpret_cast(pNotifyThis);
    //set virtual table hook
    g_pfn_oldnotify = *p_pfn_oldnotify;
    CHookNotify::pfn_Notify temp;
    __asm push CHookNotify::Notify;
    __asm pop temp;
    DWORD dwOldProtect = 0;
    VirtualProtect(p_pfn_oldnotify, sizeof(void *), PAGE_EXECUTE_READWRITE, &dwOldProtect);
    *p_pfn_oldnotify = temp;
    return 0;
}

最后来一张效果图

评论

暂无
发表评论
 返回顶部 
热度(424)
 关注微信