Let our text box more "smart and safety"
Question background:
Almost all monitoring programs are sent to get a WM_GetText message by entering the text box you enters the password, any text box will receive this message that it will tell the message to send the message to the content (it I don't know if it saves our important password.), "*" Is not to protect our password, is it a bit "smart and security" text box? ! Yes, we only need to intercept this message without letting the text box accept, any monitoring program cannot get the password. That is to define the two API functions of SETWINDOWLONG and CALLWINDOWPROC, then determine the message type, if it is the WM_GetText message, it is excluded, and does not process it (of course, you can also replace the subject to accept the message to deceive it) If this text box does not receive this message, it is of course not leaked.
related information:
The setWindowlong function declaration is as follows:
Declare function setwindowlong lib "user32" alias "setwindowlonga" (Byval Nindex as long, Byval Dwnewlong As long) AS Long
Role: Setting information for the specified window in the window structure
Parameters: HWND To set the window handle of the message function (can be a control)
NINDEX we use: GWL_WndProc Set the address of the message processing function for the window or control
The address of the DWNewlong message function (that is, addressof, such as Addressof WinProc)
Return Value: If successfully returns the address of the original message processing function, return 0
The CallWindowProc function declaration is as follows:
Public Declare Function CallWindowProc LIB "User32" Alias "CallWindowProca" (Byval Hwndfunc As Long, Byval Hwnd As Long, Byval Msg As Long, Byval WParam As Long) As long
Parameters: LPPREVWNDFUNC: Pointer to the front window or control process.
HWnd: Points the handle of the window or control process of the received message.
MSG: Specifies the message type.
WPARAM: Specify the rest, message-specific information. The content of this parameter is related to the MSG parameter value.
IParam: Specifies the rest, message-specific information. The content of this parameter is related to the MSG parameter value.
Return Value: Specifies the message processing result, which is related to the message sent.
Understanding these two functions We can do a "smart and safe" text box:
Example program production:
1. First open VB to establish a project, add a form, a module
2. Add the two functions of the above to the module, plus the declaration of the two variables is
Public const wm_gettext = & hd 'Messages for text box content
Public const gwl_wndproc (-4) 'Establishing a message processing function required by PUBLIC
Public OldProc as long 'The address of the old message processing function
3. Create a text box on the form, a command button, two checkbox modify its properties as follows:
Control Name: Properties: Property Value: Text Box PasswordChar *
Name text1
Command button Name Command1
CAPTION true password
Check box 1 name check1
CAPTION uses password protection
Check box 2 name check2
CAPTION uses password deception
4. Write the code:
Add the following code to FORM1:
Private sub check1_click ()
If Check1.Value = 1 THEN
OldProc = setWindowlong (TEXT1.HWND, GWL_WNDPROC, AddressOf Wnd) Sets the message processing function of Text1, OldProc is the address of the original function.
Else
SetWindowlong Text1.hWnd, GWL_WndProc, OldProc 'Restores the original message function address
Check2.Value = 0 'If you do not use password protection, you cannot use password spoof.
END IF
End Sub
Private sub check2_click ()
If Check2.Value = 1 THEN
If Check1.Value = 0 TEN 'If you use password spoof, you must use password protection.
OldProc = setWindowlong (Text1.hWnd, GWL_WNDPROC, Addressof WND)
Check1.value = 1
END IF
END IF
End Sub
Private submmand1_click ()
Msgbox text1.text 'The content in the real text box
End Sub
Private Sub Form_Unload (Cancel AS Integer)
Setwindowlong text1.hwnd, gwl_wndproc, oldproc 'Restores the original message processing function address
End Sub
Add message processing functions in the module:
Public Function WND (Byval Hwnd As Long, Byval MSG As Long, Byval WP as long, Byval LP As long) As long
'hwnd receives the control of the message, here is the TEXT1, MSG message type, WP and LP are additional parameter parameters
IF msg = wm_gettext the 'judgment is the message we want
If FORM1.CHECK2.VALUE = 1 THEN 'Whether deception
HWnd = form1.check2.hwnd
'Change the object of the received message Here we change to check2, then get the CAPTION value of Check2, a little lesson to those thiors, let them go back to try the password!
Else
EXIT FUNCTION 'does not do anything, return directly
END IF
END IF
WND = CallWindowProc (OldProc, HWND, MSG, WP, LP) 'If not the news we want, passes
END FUNCTION
Conclusion:
When this program is over, find a program for check "*", and when you don't choose "Use Password Protection", the content of the text box will be obtained. After selecting, try again, how is it, is there anything you can't get, and then you have to try "Use the password deception" to try it ?!