⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 superpwdspydlg.cpp

📁 利用钩子与API截获方法获取WEB网页及应用程序密码编辑框中的密码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

			UpdateGUI(hWnd, point);
			if(m_hPrevSpyWnd) HighlightWindow(m_hPrevSpyWnd,FALSE);
			if(hWnd) 
				HighlightWindow(hWnd,TRUE);
			//Check 
			if(IsPasswordEdit(hWnd))
			{
				HCURSOR hCursor = ::LoadCursor(AfxGetInstanceHandle(),
		         	MAKEINTRESOURCE(IDC_LOOK_CUR1));
		        SetCursor(hCursor); 

				m_strIsPwd.SetWindowText(_T("Yes"));
				SetHook(this->GetSafeHwnd(), hWnd, m_msg);
				QueryPasswordEdit();
				UnsetHook(this->GetSafeHwnd(), hWnd);
			}
			else if(IsBrowser(hWnd))
			{
				SetHook(this->GetSafeHwnd(), hWnd, m_msg);
				if(::IsPasswordPage() > 0)
				{
					HCURSOR hCursor = ::LoadCursor(AfxGetInstanceHandle(),
		         	    MAKEINTRESOURCE(IDC_LOOK_CUR1));
		            SetCursor(hCursor); 

					m_strIsPwd.SetWindowText(_T("Yes"));
					::QueryPasswordPage();
				}
				else
				{
					m_strIsPwd.SetWindowText(_T("No"));
				}
				UnsetHook(this->GetSafeHwnd(), hWnd);
			}
			else
				m_strIsPwd.SetWindowText(_T("No"));

        	m_hPrevSpyWnd = hWnd;
		}
	}
	else
	CDialog::OnMouseMove(nFlags, point);
}

void CSuperPwdSpyDlg::UpdateGUI(HWND hWnd, CPoint point)
{
	CString strMousePos, strHandle, strCtrlID, strCaption, strWndClass, strIsPwd, strPwd,
		    strExeName, strExePath, strPID;
	strMousePos.Format(_T("X = %d, Y = %d"), point.x, point.y);
    strHandle.Format(_T("0x%X"), hWnd);

	// Get the caption
	int nRet = ::GetWindowText(hWnd, strCaption.GetBuffer(MAX_PATH), MAX_PATH);
	strCaption.ReleaseBuffer(nRet);
			
	// Get the class name
	nRet = ::GetClassName(hWnd, strWndClass.GetBuffer(MAX_PATH), MAX_PATH);
	strWndClass.ReleaseBuffer(nRet);

	//get ctrl ID
    LONG_PTR nCtrlID = GetWindowLongPtr(hWnd, GWL_ID);
	strCtrlID.Format(_T("%d"), nCtrlID);
	
	
	DWORD dwPID;
	GetWindowThreadProcessId(hWnd, &dwPID);
	strPID.Format(_T("%d"), dwPID);

	CToolhelp th(TH32CS_SNAPALL, dwPID);

    // Show Process details
    PROCESSENTRY32 pe = { sizeof(pe) };
    BOOL fOk = th.ProcessFirst(&pe);
    for (; fOk; fOk = th.ProcessNext(&pe))
    {
		if (pe.th32ProcessID == dwPID)
		{
			strExeName = pe.szExeFile;			
			break;   // No need to continue looping
		}
    }

	MODULEENTRY32 me = { sizeof(me) };
    fOk = th.ModuleFirst(&me);
    for (; fOk; fOk = th.ModuleNext(&me)) 
	{
		CString str = me.szExePath;
		int pos = str.ReverseFind(TCHAR('\\'));
		if(pos != -1 && pos < str.GetLength() - 1)
		{
			str = str.Mid(pos + 1);
			if(str.CompareNoCase(strExeName) == 0)
			{
				str = me.szExePath;
				strExePath = str.Left(pos);
				break;
			}
		}
    }
	
	m_editWndClass.SetWindowText(strWndClass);
	m_editPwd.SetWindowText(strPwd);
	m_editPID.SetWindowText(strPID);
	m_editMousePos.SetWindowText(strMousePos);
	m_strIsPwd.SetWindowText(strIsPwd);
	m_editHandle.SetWindowText(strHandle);
	m_editCtrlID.SetWindowText(strCtrlID);
	//m_editExePath.SetWindowText(strExePath);
    m_editExePath.SetSel(0,-1);
	m_editExePath.ReplaceSel(strExePath);
	m_editExeName.SetWindowText(strExeName);
	m_editCaption.SetWindowText(strCaption);

	m_editExePath.UpdateWindow();
	m_editPwd.Invalidate(TRUE);

}

BOOL CSuperPwdSpyDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) 
{
	m_editPwd.SetSel(0, -1);
	m_editPwd.ReplaceSel(_T(""));

	if(//this->m_hwndSpying == (HWND)pCopyDataStruct->dwData &&
		::IsPasswordEdit((HWND)pCopyDataStruct->dwData))
	{
		TCHAR szBuffer[256] = {_T('\0')};
		DWORD dwSize = sizeof(szBuffer) * sizeof(TCHAR);
		if(pCopyDataStruct->cbData < dwSize)
			dwSize = pCopyDataStruct->cbData;

		CopyMemory(szBuffer, pCopyDataStruct->lpData, dwSize);
		m_editPwd.SetSel(0, -1);
	    m_editPwd.ReplaceSel(szBuffer);
	}
	else if(::IsBrowser((HWND)pCopyDataStruct->dwData))
	{
		LPBYTE lp = (LPBYTE)(pCopyDataStruct->lpData);
		DWORD dwRet;
		CopyMemory(&dwRet, lp, 4);
		lp += 4;
		for(int i = 0; i < (int)dwRet; i++)
		{
			RECT rect;
			CopyMemory(&rect, lp, 16);
			lp += 16; //coordinate
            
			TCHAR szPlace[32];
			_stprintf(szPlace, _T("No.%d(%d,%d-%d,%d)-"), i, rect.left, rect.top, 
				rect.right, rect.bottom);
            m_editPwd.SetSel(-1, -1);
			m_editPwd.ReplaceSel(szPlace);

			TCHAR sz[MAX_PATH];
			::lstrcpy(sz, (LPCTSTR)lp);
			m_editPwd.SetSel(-1, -1);
			m_editPwd.ReplaceSel(sz);
			m_editPwd.SetSel(-1, -1);
			m_editPwd.ReplaceSel(_T("\r\n"));
			lp += (::lstrlen(sz) + 1)*sizeof(TCHAR);
		}
		m_editPwd.LineScroll(-(int)dwRet, 0);
	}
	return CDialog::OnCopyData(pWnd, pCopyDataStruct);
}

BOOL CSuperPwdSpyDlg::OnEraseBkgnd(CDC* pDC) 
{
	CRect rct;
	GetClientRect(&rct);
	
	CBrush brNew;
	CBitmap bmpNew;

	BOOL bl = bmpNew.LoadBitmap(IDB_BACKGROUND);
	ASSERT(bl);
	
	bl = brNew.CreatePatternBrush(&bmpNew);
	ASSERT(bl);

	CBrush *pbrOld = pDC->SelectObject(&brNew);
	pDC->PatBlt(rct.left, rct.top, rct.Width(),
		rct.Height(), PATCOPY);
	
	pDC->SelectObject(pbrOld);
	bmpNew.DeleteObject();
	return TRUE;
	//return CDialog::OnEraseBkgnd(pDC);
}

HBRUSH CSuperPwdSpyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	switch(nCtlColor) 
	{
	    case CTLCOLOR_STATIC:
			// let static controls shine through
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(TOOLTIP_BK_COLOR);
			return HBRUSH(m_HollowBrush);
        case CTLCOLOR_EDIT:
			pDC->SetBkMode(TRANSPARENT);
			pDC->SetTextColor(TOOLTIP_BK_COLOR);
			pDC->SetBkColor(RGB(225,225,225));
			return HBRUSH(m_WhiteBrush);
		default:
			break;
	}

	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	return hbr;
}

//void CAboutDlg::OnGoUrl() 
//{
//	ShellExecute(NULL, _T("open"), 
//		_T("http://www.hcil.im.dendai.ac.jp/~zhang/SuperPasswordSpy.htm"),NULL,NULL, SW_SHOWNORMAL);
//	
//}

void CSuperPwdSpyDlg::RelayEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
	// This function will create a MSG structure, fill it in a pass it to
	// the ToolTip control, m_ttip.  Note that we ensure the point is in window
	// coordinates (relative to the control's window).
	if(NULL != m_tt.m_hWnd)
	{
		MSG msg;
		msg.hwnd = m_hWnd;
		msg.message = message;
		msg.wParam = wParam;
		msg.lParam = lParam;
		msg.time = 0;
		msg.pt.x = LOWORD(lParam);
		msg.pt.y = HIWORD(lParam);
		m_tt.RelayEvent(&msg);
	}
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	SetTimer(101, 500, NULL);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void GetSystemIconFont(CString& strFontName,int& nPointSize)
{
   LOGFONT lf;

   // get LOGFONT structure for the icon font
   SystemParametersInfo(SPI_GETICONTITLELOGFONT,sizeof(LOGFONT),&lf,0);
	
   // getting number of pixels per logical inch
   // along the display height
   HDC hDC    = ::GetDC(NULL);
   int nLPixY = GetDeviceCaps(hDC, LOGPIXELSY);
   ::ReleaseDC(NULL,hDC);

   // copy font parameters
   nPointSize  = -MulDiv(lf.lfHeight,72,nLPixY);
   strFontName = lf.lfFaceName;
}

#include <afxpriv.h>

int CSuperPwdSpyDlg::DoModal() 
{
	CDialogTemplate dlt;
    int             nResult;

    // load dialog template
    if (!dlt.Load(MAKEINTRESOURCE(CSuperPwdSpyDlg::IDD))) return -1;

    // set your own font, for example "Arial", 10 pts. 
    //dlt.SetFont(_T("Arial"), 10);
	
    // get pointer to the modified dialog template
    LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate);
	
    // let MFC know that you are using your own template
    m_lpszTemplateName = NULL;
    InitModalIndirect(pdata);

    // display dialog box
    nResult = CDialog::DoModal();

    // unlock memory object
    GlobalUnlock(dlt.m_hTemplate);

    return nResult;	

	//return CDialog::DoModal();
}

void CSuperPwdSpyDlg::OnCheckMore() 
{
	UpdateData(TRUE);
	ShowMoreInfo(m_bMore);
}

void CSuperPwdSpyDlg::ShowMoreInfo(BOOL b)
{
	CRect rect1, rect2;
	CWnd* pWnd1 = GetDlgItem(IDC_EDIT_PWD);
	pWnd1->GetWindowRect(&rect1);
	//this->ScreenToClient(&rect1);

	CWnd* pWnd2 = GetDlgItem(IDC_EDIT_EXE_PATH);
	pWnd2->GetWindowRect(&rect2);
	//this->ScreenToClient(&rect2);

	CRect rectSelf;
	this->GetWindowRect(&rectSelf);
	if(b)
	{
		rectSelf.bottom = rect2.bottom + 5;
	}
	else
	{
		rectSelf.bottom = rect1.bottom + 5;
	}
	this->MoveWindow(&rectSelf);
}

void CSuperPwdSpyDlg::OnSelchangeComboTransparent() 
{
	int sel = m_comboTransparent.GetCurSel();
	if(sel == CB_ERR) return;
	if(sel == 0) //not transparent
	{
		LONG lExStyle;
	    lExStyle=::GetWindowLong(m_hWnd,GWL_EXSTYLE);
        lExStyle &= ~0x80000;
	    ::SetWindowLong(m_hWnd,GWL_EXSTYLE,lExStyle);
	}
	else
	{
		LONG lExStyle;
	    lExStyle=::GetWindowLong(m_hWnd,GWL_EXSTYLE);
	    ::SetWindowLong(m_hWnd,GWL_EXSTYLE,lExStyle|0x80000);
	}

	HMODULE hDLL;
	typedef DWORD (WINAPI *PFUNC)(HWND,DWORD,BYTE,DWORD);
	PFUNC pFunc;

	hDLL=::LoadLibrary(_T("user32"));
	pFunc=(PFUNC)::GetProcAddress(hDLL,"SetLayeredWindowAttributes");
	if(!pFunc)
	{
		// SetLayeredWindowAttributes娭悢偼柍岠
		//::MessageBox(hWnd,"SetLayeredWindowAttributes娭悢偼柍岠",NULL,MB_OK);
		::FreeLibrary(hDLL);
		//::PopMsg(_T("Set Alpha Failed"));
		return;
	}
	else
		pFunc(this->GetSafeHwnd(),0,(BYTE)this->m_nTransparent[sel],2);
	::FreeLibrary(hDLL);

}

void CAboutDlg::OnTimer(UINT nIDEvent) 
{
	static BOOL b = TRUE;
	b = !b;
	if(b)
	{
		CStatic* p = (CStatic*)GetDlgItem(IDC_LOOK);
	    HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(), 
			MAKEINTRESOURCE(IDI_LOOK_ICON1));
		p->SetIcon(hIcon);
	}
	else
	{
		CStatic* p = (CStatic*)GetDlgItem(IDC_LOOK);
	    HICON hIcon = ::LoadIcon(AfxGetInstanceHandle(), 
			MAKEINTRESOURCE(IDI_LOOK_ICON2));
		p->SetIcon(hIcon);
	}
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -