This article will tell how to program how to program the password in the password box in the win2000 and remember that the password in the web password box in the application in the application, you can easily get the message to send a WM_GETTEXT to a password box. The password, Microsoft may already realize that this uneasy factor, in Win2000 / XP, write an application like that, to send a WM_GETTEXT message from the password box of other programs, reasons It is in the process between the processes, if the parameter window handle does not belong to the call thread, the function execution will fail, in order to solve this problem, we can use the hook function, and the hook function is generally in the dynamic link library. Win32 automatically maps the dynamic link library to its various processes, where other functions of this dynamic link library will also be mapped to the process of running. Such hook functions will also be integrated with its host program window. In such a process, since the DLL insert map makes the function parameter window handle HWnd belongs to the process, this is allowed by Win32. So write a DLL and inject it into a password, so you can see a process of the process, and then use WM_CopyData to perform the process of communication to send the password to the program we want to display. After the theory, I started to use VC to make a program. First create a dialog-based program getPass, and other options are default. Add an Edit control, its ID is IDC_EDIT1 to display the resulting password information. Add const cWnd * pwndinsertafter; pwndinsertafter = & wndtopmost; setWindowpos (PWNDINSERTAFTER, 0, 0, 0, 0, SWP_NOSIZE); // Place the window in the uppermost layer
SetTimer (1,100, null); // Get a password every 500 milliseconds.
BOOL K = IITHOK (THIS-> M_HWND); // Mount Hook IF (K == False) AFXMessageBox ("false"); reload the ONTIMER function, add the following code hWnd hwnd; cpoint mousepos; getCursorpos (& MousePos); / / Get the coordinates of the current mouse
HWnd = :: windowfromPoint (mousepos); // Get the handle getPasstext (hwnd, m_hwnd) of the corresponding window of the current coordinate; // Call this function to get a password
Starting classwzard WM_COPYDATA response message for the added function OnCopyData (CWnd * pWnd, COPYDATASTRUCT * pCopyDataStruct) add the following code to obtain code came dll: SetDlgItemText (IDC_EDIT1, (LPCTSTR) pCopyDataStruct-> lpData); our time compiler program There will be two errors as the following error C2065: 'IITHOK': undeclared Identifiererror C2065: 'getPassText': undeclared Identifier These two functions are we want to build in the DLL. So we create a new project, select the MFC AppWizard (DLL), and add to current workplace and select Add to Current Workspace. Other default values. First add variables and macro definitions on Password.cpp
#define MAX_TEXTLEN 1024 # define UM_GETPASS WM_USER 0x392HINSTANCE ghInstance = 0; #pragma data_seg ( "ALLDATA") HHOOK g_hHook = NULL; HINSTANCE g_hDllIns = NULL; HWND g_hHostWnd = NULL; #pragma data_seg () and then rewrite the code at its Password.def As follows: library "password" Description 'Password Windows Dynamic Link Library'Exports INITHOOK @ 1 ReleaseHook @ 2 getPassText @ 3sections AllData Shared
// we added manually to the function declaration variables to use classwzard CPasswordApp added CPasswordApp :: InitInstance () code therein is: g_hDllIns = AfxGetInstanceHandle (); then added after CPasswordApp theApp global variables in the Password.cpp; DisableThreadLibraryCalls (g_hDllIns) As follows: Lresult Callback getMsgProc (int code, wparam wparam, lparam lparam) {try {if (code> = 0) {lpmsg pmsg = (lpmsg) LParam; hwnd hshowpasswnd = (hwnd) PMSG-> LPARAM; IF (PMSG- > message == um_getpass && g_hhostwnd == hshowpassWnd) {// Get the content of the * number hwnd hPassWnd = (hwnd) PMSG-> wparam; // * window hWnd if (hpassWnd) {tchar szpasstext [max_textlen]; zeromeMory (szPassText, MAX_TEXTLEN); :: SendMessage (hPassWnd, WM_GETTEXT, MAX_TEXTLEN, (LPARAM) szPassText); // get content COPYDATASTRUCT cd; ZeroMemory (& cd, sizeof (cd)); cd.dwData = (DWORD) hPassWnd; cd. CBData = Strlen (Szpasstext) 1; cd.lpdata = szpasstext; sendMessage (HShowPassWnd, WM_COPYDATA, (WPARAM) HPASSWND, (LPARAM) & CD); // Send to showpass window}}} catch (...)}}} Return CallNexthookex (g_hhook, code, wparam, lParam);} BOOL InitHook (HWND hWnd) {try {if (hWnd) {return FALSE;!} g_hHostWnd = hWnd; g_hHook = SetWindowsHookEx (WH_GETMESSAGE, GetMsgProc, g_hDllIns, 0);! return g_hHook = NULL;} catch (. ..) {RETURN FALSE;}} hwnd winApi getParentfromhwnd (hwnd hwnd) {hwnd (hw {hparwnd; getparent (hwnd); if (hparwnd) {hwnd = hparwnd;}} while (hparwnd);} catch ...) {} return hWnd;} void GetPassText (HWND hWndPass, HWND hWndShowPass) {try {HWND hParWnd = GetParentFromHwnd (hWndPass); :: PostMessage (hParWnd, UM_GETPASS, (WPARAM) hWndPass, (LPARAM) hWndShowPass);
} Catch (...) {}} // unload BOOL ReleaseHook () {BOOL bSuccess = FALSE; try {if (g_hHook = NULL!) {BSuccess = UnhookWindowsHookEx (g_hHook) TRUE:? FALSE; g_hHook = NULL; g_hHostWnd = NULL;}} Catch (...) {} Return BsuCcess;} is added in password.h to join the function Export Declaration Extern "C" _Declspec (DLLEXPORT) Void getPassText (HWND HWNDPASS, HWND HWNDSHOWPASS); EXTERN "C" _Declspec DLLEXPORT) BOOL INITHOK (HWND HWND); Extern "C" _Declspec (DLLEXPORT) BOOL ReleaseHook (); final compile, link, copy the generated password.dll, password.lib to get the getPass Engineer, at getPass Enginee's getPassdlg The top of .CPP is added to the following code #pragma comment (lib, "password.lib") // implicit link EXTERN "C" _declspec (dllexport) Void getPassText (HWND HWNDPASS, HWND HWNDSHOWPASS); EXTERN "C" _Declspec (DLLEXPort ) BOOL INITHOK (HWND HWND); Extern "C" _Declspec (DLLEXPORT) BOOL ReleaseHook (); Finally, run the program, you can see the password of the mouse point to the application.
But when we point your mouse to the password box on the page, we can't get its content, because the webpage password box is not a general EDIT control, so you can't get the handle of the web page password box. To implement this feature, you have to pass the WebBrowser control related COM interface. So obtain these interfaces is the key to the entire program. You can find the ihtmldocument2 interface of the WebBrowser control in different processes on different processes. It is to send to the WebBrowser control (window class name is "Internet Explorer_server") a WM_HTML_GETOBJECT, then the return value is passed to Microsoft Active Accessibility (MSAA) function ObjectFromLresult, so you will have made a choreography (Marshaling) through the COM interface function shown as follows:. IHTMLDocument2 * GetDocInterface (HWND hWnd) {// we need The display will load oleacc.dll, so we know if there is any installation of MSAA Hinstance Hinst = :: LoadLibrary (_T ("Oleacc.dll")); htmldocument2 * pdoc2 = null; if (hinst! = Null) {if (hwnd! = NULL) {CComPtr
COUNITIALIZE () should then be called accordingly; so let's join the CGETPASSDLG :: OnNItPassdlg :: OnInitDialog () to add Coinitialize (Null); then load the WM_DESTROY message, add the following code in its corresponding function void cgetpassdlg :: OnInitialize (); // Uninstall the COM component KillTimer (1); // Uninstall the clock, we have achieved the htmldocument2 * interface, to obtain the password of the password box, have a total discount, now rewrite the Void CgetPassDLG we just get the getpass project :: ONTIMER (uint nidevent) function, after the contents are as follows: hwnd hwnd; cpoint mousepos; getcursorpos (& mousepos); // get the coordinate of the current mouse Static Tchar BUF [100]; hWnd = :: WindowFromPoint (mousepos); // Get the handle IF (hwnd! = Null) of the corresponding window of the current coordinate {:: getclassname (hwnd, (lptstr) & buf, 100); if (_TCSCMP (BUF, _T ("Internet Explorer_server")) == 0) // If it is IE, use other methods {Point IEPT = mousepos; :: screenToClient (hwnd, & iept); getPassword (GetDocinterface (hwnd),} else // If you are other windows, use the original method to get password GetPassText (hwnd, m_hWnd);} CDialog :: OnTimer (nIDEvent); CgetPassDlg added in two class member functions void CGetPassDlg :: GetPassword (IHTMLDocument2 * pDoc2, POINT pt) IHTMLDocument2 * CGetPassDlg :: GetDocInterface (HWND hWnd) IHTMLDOCUMENT2 * CGETPASSDLG :: GetDocinterface (HWND HWND) function code as previously mentioned Void CgetPas SDLG :: getPassword (ihtmldocument2 * pdoc2, point pt) is as follows: if (pdoc2 == null) return; ccomptr
0) {ccombstr msg = _t (""); msg = PWD; CSTRING STR (MSG); setdlgitemtext (IDC_EDIT1, STR); Updatedata (false);} else {setdlgitemtext (IDC_EDIT1, "password is empty); Updatedata False);}}}}}}} PDOC2-> Release (); Finally add the header file used in Stdafx.h to join the header file #include