最新微信hook二次开发C#源码之获取通讯录

江南鹤微信hook二次开发之获取通讯录

【江南鹤微信hook二次开发c#源代码】中包含比较全面的功能。以后的日子里,我会逐一为大家详细讲解! 今天讲解的是用【江南鹤微信hook二次开发c#源代码】获取通讯录

用【江南鹤微信hook二次开发c#源代码】获取通讯录分以下几步:

1 发送获取通讯录的请求

private void btn_GetContact_Click(object sender, EventArgs e)
    {
        if(nmHeler.Socket_ConnId == 0)
           { MessageBox.Show("请选择一个操作账号!"); return; }
        nmCore.NM_GetContactList(nmHeler.Socket_ConnId);
    }
  /// <summary>
    /// 功能_读取通讯录列表
    /// </summary>
    /// <param name="ConnID"></param>
    public void NM_GetContactList(int ConnID)
    {
        JObject sendJson = new JObject {["PackType"] = NMHelper.NM_GetContactList};
        SendPacket(ConnID, sendJson.ToString());
    }

2 hook程序截获 微信服务器发来的请求结果

    HandleResult OnReceive(IServer sender, IntPtr connId, byte[] bytes)
    {
        string s_Recv = Encoding.Default.GetString(bytes);
        JObject RecvJson = JObject.Parse(s_Recv);
        int RecvType;
        if(nmHeler.Json_GetInt(RecvJson, "PackType",out RecvType) == true)
        {
            if (RecvType == NMHelper.NM_GetContactList)
            {
                Event_RecvContactList((int)connId, RecvJson);
            }
        }
        return HandleResult.Ok;
    }

3 对结果进行分析处理

 NMHelper.nmWxidInfo MemberInfo = new NMHelper.nmWxidInfo
  {
   Type = nmHeler.Json_GetIntEx((JObject) JtMember, "Type"),
   List = nmHeler.Json_GetIntEx((JObject) JtMember, "List"),
   Wxid = nmHeler.Json_GetString((JObject) JtMember, "Wxid", true),
   WxNo = nmHeler.Json_GetString((JObject) JtMember, "WxNo", true),
   Nick = nmHeler.Json_GetString((JObject) JtMember, "Nick", true),
   Mark = nmHeler.Json_GetString((JObject) JtMember, "Mark", true),
    HeadIMG = nmHeler.Json_GetString((JObject) JtMember, "HeadIMG", true)
};

4 分类列出通讯录列表

    void Event_RecvContactList(int ConnID, JObject RecvJson)
    {
        string outLog = "[通讯录列表]" + nmHeler.Json_GetString(RecvJson, "RecvWxid", true) + NewLine;
        int dwState = nmHeler.Json_GetIntEx(RecvJson, "State");
        if(dwState == 0)
        {
            outLog += "通讯录列表读取失败!";
            WriteLog(outLog);
            return;
        }
        JArray m_List = RecvJson.Value<JArray>("List");
        if(m_List != null)
        {
            list_Friend.BeginUpdate(); list_Group.BeginUpdate(); list_GHFriend.BeginUpdate();
            list_Friend.Items.Clear(); list_Group.Items.Clear(); list_GHFriend.Items.Clear();
            for (int i = 0; i < m_List.Count; i++) 
            {
                JToken JtMember = m_List.ElementAt(i);
                if(JtMember != null)
                {
                    NMHelper.nmWxidInfo MemberInfo = new NMHelper.nmWxidInfo
                    {
                        Type = nmHeler.Json_GetIntEx((JObject) JtMember, "Type"),
                        List = nmHeler.Json_GetIntEx((JObject) JtMember, "List"),
                        Wxid = nmHeler.Json_GetString((JObject) JtMember, "Wxid", true),
                        WxNo = nmHeler.Json_GetString((JObject) JtMember, "WxNo", true),
                        Nick = nmHeler.Json_GetString((JObject) JtMember, "Nick", true),
                        Mark = nmHeler.Json_GetString((JObject) JtMember, "Mark", true),
                        HeadIMG = nmHeler.Json_GetString((JObject) JtMember, "HeadIMG", true)
                    };
                    ListViewItem UserItem = new ListViewItem();

                    if (MemberInfo.Type == 8 || MemberInfo.Type == 24 || MemberInfo.Type == 29)
                    {
                        UserItem.Text = MemberInfo.Nick;
                        UserItem.SubItems.Add(MemberInfo.Wxid);
                        UserItem.SubItems.Add(MemberInfo.WxNo);
                        UserItem.SubItems.Add(MemberInfo.HeadIMG);
                        list_GHFriend.Items.Add(UserItem);
                    }
                    else if (MemberInfo.Wxid.LastIndexOf("@chatroom") != -1)
                    {
                        UserItem.Text = MemberInfo.Nick == string.Empty ? "群聊" : MemberInfo.Nick;
                        UserItem.SubItems.Add(MemberInfo.Wxid);
                        UserItem.SubItems.Add(MemberInfo.WxNo);
                        UserItem.SubItems.Add(MemberInfo.List.ToString());
                        UserItem.SubItems.Add(MemberInfo.HeadIMG);
                        list_Group.Items.Add(UserItem);
                    }
                    else if (MemberInfo.List != 2)
                    {
                        UserItem.Text = MemberInfo.Nick;
                        UserItem.SubItems.Add(MemberInfo.Mark);
                        UserItem.SubItems.Add(MemberInfo.Wxid);
                        UserItem.SubItems.Add(MemberInfo.WxNo);
                        UserItem.SubItems.Add(MemberInfo.HeadIMG);
                        list_Friend.Items.Add(UserItem);
                    }
                }
            }
            list_Friend.EndUpdate();
            list_Group.EndUpdate();
            list_GHFriend.EndUpdate();
            outLog += "通讯录列表读取成功";
            outLog += ",好友:" + list_Friend.Items.Count.ToString();
            outLog += ",群聊:" + list_Group.Items.Count.ToString();
            outLog += ",好友:" + list_GHFriend.Items.Count.ToString();
            WriteLog(outLog);
        }
    }

您可能还喜欢...