標籤:uia trojans virus console .net
很多人應該知道,QQ的子視窗控制代碼是無法被WinUser庫中提供的 函數可以得到的,
因為根本沒有NativeHandle 它是繪畫出的邏輯控件、DirectUI、WPF 不過DirectUI
並不是如WPF純種DirectX渲染幀、不過兩者概念相等,控制項只是邏輯上的 並不是真
正意義上存在的控制項,既然沒有那如何去擷取它的內容、很簡單微軟提供了兩套不同
的類庫,C++ 主要應用 Microsoft Active Accessibility / MSAA 你可不要認為是遊戲上
的MSAA / 消除鋸齒、也可以使用UI Automation / UI自動化、C#主要使用UIA、不過是
.NET上封裝過後的庫,如果需要原生的UIAutomationCore.dll在.NET上層中COM封裝
類庫為、Interop.UIAutomationClient但兩者意義並不大、.NET上層Wrapper後類庫只是
效能不如原生的快而已、你選那樣 都也差不多的、如果有興趣可以去看看Windows Automation API
上面只是一個運行後的結果、軟體已成功擷取到聊天紀錄
速度雖然不是很快、首先添加項目引用
UIAutomationClient.dll與UIAutomationTypes.dll兩枚子彈、
OK確認引用後再添加命名空間引用、
using System; using System.Text; using System.Windows.Automation; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Windows.Forms;
首先我們需要聲明關於所需要用的Win32Native函數與常量
public abstract partial class Win32Native{ [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EnumWindows(LPENUMWINDOWSPROC lpEnumFunc, int lParam); [DllImport("user32.dll", CharSet = CharSet.Ansi)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetClassName(int hWnd, StringBuilder buf, int nMaxCount); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern int GetWindowTextLength(int hWnd); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindow(IntPtr hWnd); private delegate bool LPENUMWINDOWSPROC(int hwnd, int lParam); public const int NULL = 0; private const int MAXBYTE = 255;}
下面我們編寫一個掃描案頭上 有多少QQ最上層視窗的代碼、
我們不去掃描被合并的視窗 只需要掃描最上層視窗那可以了
public abstract partial class Win32Native{ private static volatile List<int> hWndCollect; private static bool ScanSessionWindow(int hwnd, int lParam) { StringBuilder buf = new StringBuilder(MAXBYTE); if (GetClassName(hwnd, buf, MAXBYTE) && buf.ToString() == "TXGuiFoundation") if (GetWindowTextLength(hwnd) > 0 && GetWindowText(hwnd, buf, MAXBYTE)) { string str = buf.ToString(); if (str != "TXMenuWindow" && str != "QQ" && str != "增加時間長度") { Console.WriteLine("\t" + (hWndCollect.Count + 1) + ": " + str); hWndCollect.Add(hwnd); } } return true; } public static int[] GetSessionWindow() { hWndCollect = new List<int>(); EnumWindows(ScanSessionWindow, NULL); return hWndCollect.ToArray(); }}
我在上面增加了幾個條件,已經排除掉可能被枚舉出
但對我們無意義的視窗、
GetSessionWindow / 取會話視窗
SanSessionWindow / 掃描會話視窗
public static partial class Program{ private static void FindUserMessage(IntPtr hwnd) { if (!Win32Native.IsWindow(hwnd)) Console.WriteLine("QQ session window has been closed."); else { AutomationElement element = AutomationElement.FromHandle(hwnd); element = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "訊息")); if (element != null && element.Current.IsEnabled) { ValuePattern vpTextEdit = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; if (vpTextEdit != null) { string value = vpTextEdit.Current.Value; Console.WriteLine(value); MessageBox.Show(value); } } } }}
FindUserMessage / 尋找使用者訊息
在上面我們看到首先做了一次檢查視窗控制代碼是否有效 若有效在下面
創立了一個 AutomationElement / 自動化成員對象、我們如果需要
搜尋並返回單成員,那麼我們只需要使用 FindFirst 如果我們需要
搜尋並返回所有成員,那麼我們只需要使用 FindAll 、我們在上面
只使用一種Name屬性條件 PropertyCondition(AutomationElement.NameProperty, "訊息")
為什麼是訊息呢、那麼我們仔細看看
好吧、你現在應該發現了為什麼是“訊息”而不是其他的、對吧
public static partial class Program{ [STAThread] private static void Main(string[] args) { Console.Title = string.Empty; Console.WriteLine("scan the QQ user's session window."); int[] hWndOfSession = Win32Native.GetSessionWindow(); if (hWndOfSession.Length <= 0) Console.WriteLine("No scan to any available QQ message window."); else { Console.WriteLine("Look for the session record interface."); foreach (int hWnd in hWndOfSession) FindUserMessage((IntPtr)hWnd); } Console.WriteLine("Thank you for using, QQ conversations have been scanned."); Console.ReadKey(false); }}
上面的代碼主要是把幾個函數拼接在一起 完成我們需要做的事 首先取得案頭上有
多少QQ的繪話控制代碼、然後再迭代尋找使用者訊息、實際上這種東西 如果可以放在別
人電腦裡開機啟動 掃描到訊息後發送到自己郵箱或者更新到伺服器上 會是一種很好
玩的東西、但前提你必須可以把它弄到別人電腦裡去,開個小玩笑
想抓老公出軌證據富婆、呵呵、移動版或許才可以拯救於她、
原始碼: http://pan.baidu.com/s/1kTBxOdL
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
C# 取QQ會話記錄