(一)C# QQ讨论组广告群发工具——QQ登陆功能的实现上篇(附源码)
C# QQ登陆功能的实现源码,我不喜欢废话,上代码……C#/Java技术交流群:96020642,传送门:Rolends
涉及到知识点:
1、窗体查找(遍历桌面窗体);
2、控件查找(子窗体,句柄循环);
3、使用windows API实现发送消息,为窗体置顶,设置焦点;
C# Code By wuleba.com
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 |
/// <summary> /// 运行程序返回进程pid /// </summary> /// <param name="qqPath"></param> /// <returns></returns> static public int RunProgram (string qqPath) { int pid = 0; Process pro = Process.Start (qqPath); if (pro != null) { pid = pro.Id; } try { ChannelName = null; Console.WriteLine ("Register"); RemoteHooking.IpcCreateServer<HookedInterface> (ref ChannelName, WellKnownObjectMode.SingleCall); Console.WriteLine ("IpcCreateServer"); RemoteHooking.Inject (pid, "QqMonInject.dll", "QqMonInject.dll", ChannelName); HookedSender.Init(); WndManager.Init();} catch (Exception ExtInfo) return pid; |
上面的代码实现了运行QQ,并使用EasyHook加载钩子,由于。net无法实现全局钩子,故使用EasyHook来实现,EasyHook是一个开源项目,大家可以google
C# Code By wuleba.com
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
/// <summary> /// 登陆,成功后返回窗体句柄 /// </summary> /// <param name="mainQQ"></param> /// <param name="mainQQPwd"></param> /// <returns></returns> static public IntPtr Logon (string mainQQ, string mainQQPwd, ref string errorText) { IntPtr hWnd = IntPtr.Zero; string qqPath = SqliteHelper.GetValue ("select SC_QQPROPATH from sys_config").ToString(); int pid = RunProgram (qqPath); if (pid < 100) { errorText = "无法运行QQ进程"; WriteLog (errorText); return hWnd; } Thread.Sleep (SysConfig.QQProcessStartSleppTime); //bool ad = !false; //while (ad) { Thread.Sleep(2000); } IntPtr hLogonWnd = GetLogonWnd (pid); if (hLogonWnd == IntPtr.Zero) hLogonWnd = GetLogonWnd2 (pid); if (hLogonWnd == IntPtr.Zero) { errorText = "没有登陆窗口"; WriteLog (errorText); return hWnd; } var cons = WndHelper.GetVisableControl (hLogonWnd, "ATL:30A561F0"); if (cons.Count < 1) { errorText = "没有找到登陆QQ输入框"; WriteLog (errorText); return hWnd; } //没有找到QQ输入框 int retvar = WinAPIHelper.SendMessage (cons[0], WinAPIHelper.WM_SETTEXT, IntPtr.Zero, new StringBuilder (mainQQ) ); if (retvar == 0) { errorText = "无法设置登陆QQ号码"; WriteLog (errorText); return hWnd; }//无法设置登陆QQ号码 cons = WndHelper.GetVisableControl (hLogonWnd, "Edit"); if (cons.Count < 1) { errorText = "没有找到密码输入框"; WriteLog (errorText); return hWnd; }//没有找到密码输入框 SETPASSWARD: bool result = WinAPIHelper.SetForegroundWindow (hLogonWnd); "密码:" + mainQQPwd); "+", "{+}").Replace ("^", "{^}").Replace ("%", "{%}") ); |
登陆部分代码,关键点是WM_SETTEXT消息设置QQ号码,SendKeys.SendWait设置密码,然后模拟点击,实现登陆。
C# Code By wuleba.com
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
static public bool WaitLogon (int pid, ref string errorText) { DateTime beginTime = DateTime.Now; while (true) { TimeSpan ts = TimeSpan.FromTicks (DateTime.Now.Ticks - beginTime.Ticks); if (ts.TotalMilliseconds > SysConfig.QQLogonTimeOut) { KillProcess (pid); errorText = "登陆超时"; WriteLog (errorText); return false; } var wnds = WndManager.GetDesktopWnds (pid); WindowEventArgs pwdErrorWea = wnds.Find (p => p != null && p.Pid == pid && p.ClassName == "TXGuiFoundation" && p.Title == "密码验证错误"); if (pwdErrorWea != null) { bool result = WinAPIHelper.IsWindowVisible (pwdErrorWea.Hwnd); if (result) { KillProcess (pid); errorText = "密码错误"; WriteLog (errorText); return false; } }WindowEventArgs pwdErrorNet = wnds.Find (p => p != null && p.Pid == pid && p.ClassName == "TXGuiFoundation" && p.Title == "提示" && p.Size.Width == 350 && p.Size.Height == 160); null && p.Pid == pid && p.ClassName == "TXGuiFoundation" && p.Title == "帐号需解除限制后才能登录"); 1000); |
上面的代码是各种情况的判断。
今天到此为止,明天继续更新...下一篇的传送门:https://www.wuleba.com/4155.html
下载说明:① 请不要相信网站的任何广告;② 当你使用手机访问网盘时,网盘会诱导你下载他们的APP,大家不要去下载,直接把浏览器改成“电脑模式/PC模式”访问,然后免费普通下载即可;③ 123云盘限制,必须登录后才能下载,且限制每人每天下载流量1GB,下载 123云盘免流量破解工具
版权声明:
小编:吾乐吧软件站
链接:https://wuleba.com/4154.html
来源:吾乐吧软件站
本站资源仅供个人学习交流,请于下载后 24 小时内删除,不允许用于商业用途,否则法律问题自行承担。


funny
很有意思啊!
初学者
开源的,必须支持
momoyi
模拟得很到位,哈哈
早稻田的主人
找了很久了,可惜段位太低看不懂啊。求大神的完整工程文件!