Win32 assembly -- Host lock

Source: Internet
Author: User

Function:

1. Lock the screen and prohibit others from performing operations.

2. added the image display transparency to facilitate players to log on. (If the transparency is set to 0, all screens are displayed, but no operations can be performed on the computer)

3. added the MP3 playing function, so that you do not need to enable other players to listen to music after the host is mounted.

(To be modified: The image cannot be changed. You can add a function to load the image at a time so that you can set the hanging image on your own. Do not use Ctrl + Alt + Del to modify the registry .. Have time to study other methods)

. 386
. Model flat, stdcall
Option casemap: none

Include windows. inc
Include user32.inc
Includelib user32.lib
Include kernel32.inc
Includelib kernel32.lib
Include comdlg32.inc
Includelib comdlg32.lib
Include gdi32.inc
Includelib gdi32.lib
Include debug. inc; because the CTEXT macro is used, add debug. inc and debug. lib.
Includelib debug. lib
Include winmm. inc; uses the music playing Function
Includelib winmm. lib
Include advapi32.inc; the registry function is used.
Includelib advapi32.lib

KBDLLHOOKSTRUCT struct; the data structure used by the lower-layer keyboard hook, which is not included in RadASM and can only be defined by yourself
VkCode DWORD? _ LParam is the data structure in the LowLevelKeyboardProc Process
ScanCode DWORD?
Flags DWORD?
Time DWORD?
DwExtraInfo DWORD?
KBDLLHOOKSTRUCT ends

IDB_BMP equ1000
DLG_MAIN equ 1000
DLG_SHOW equ 1002
ICO_MAIN equ 1001
IDC1_SHOWTEXT equ1001
IDC1_PASS equ 1003
IDC1_REPASS equ 1002
IDC1_ OK equ 1004
IDC1_EXIT equ 1005
IDC2_ OK equ 1006
IDC2_PASS equ 1007
IDC1_ICO equ 1008
IDC1_PROMPT equ 1009
IDC1_SCROLL equ1010
IDC1_COUNT equ 1011
IDC1_ABOUT equ 1012
IDC1_FILE equ 1006
IDC1_BROWSE equ 1008
IDC1_PLAY equ 1013

. Data?
HInstance dd? ; Handle of the Main Window
HWinDlg1 dd? ; Handle of the Main Window
HInstance1 dd? ; Lock screen handle
HWinMain dd? ; Lock screen handle
HBitMap dd? ; Handle of the background image in the screen lock window
HIcon dd? ; Icon
HHook dd? ; Hook handle
DwFlag dd? Indicates whether the password is equal. 0 indicates that the password does not match, 1 indicates that the password is matched, and 2 indicates that the password is unintentional.
SzPassWordBuf db 128 dup (?) The Buffer in the first Password box of the main window, that is, the Buffer of IDC1_PASS.
DwLength dd? ; Used to store the entered password length
SzShowText db 128 dup (?) ; Buffer of the content displayed on the screen
DwPos dd? ; The position of the scroll bar

SzFileName db MAX_PATH dup (?)
HDevice dd?
DwFlag2 dd?

. Const
SzClassName db 'class', 0; Class Name
SzPassWordFmt db 'Remember your password: % s', 0
SzTaskBar db 'Shell _ traywnd', 0; string used to obtain the taskbar handle
SzAbout db 'by: no autumn leaves have fallen ', 0dh, 0ah, 'qq: 307727654', 0dh, 0ah, 'weinan * Division

', 0dh, 0ah, '2009.3.21', 0

SzSubKey db 'Software \ Microsoft \ windows \ CurrentVersion \ Policies \ system', 0
SzValueName db 'disabletaskmgr ', 0
SzValue db '1', 0; used to lock the Registry

SzFilter db 'mp3 File (*. Mp3) ', 0,' *. mp3', 0, 0
SzDevice db "MPEGVideo", 0

. Code
LowLevelKeyboardProc proc _ dwCode, _ wParam, _ lParam; hook Process

Invoke CallNextHookEx, hHook, _ dwCode, _ wParam, _ lParam
. If _ dwCode = HC_ACTION
Mov ebx, _ lParam
Assume ebx: ptr KBDLLHOOKSTRUCT; some system Keys are blocked
. If [ebx]. vkCode = VK_DELETE | [ebx]. vkCode = VK_LWIN | \
[Ebx]. vkCode = VK_TAB | [ebx]. vkCode = VK_SHIFT | \
[Ebx]. vkCode = VK_MENU | [ebx]. vkCode = VK_ESCAPE | \
[Ebx]. vkCode = VK_RWIN | [ebx]. vkCode = VK_CONTROL
Invoke FindWindow, addr szTaskBar, 0; get the taskbar handle
Invoke EnableWindow, eax, FALSE; set the taskbar to unavailable
Mov eax, 1
. Endif
. Endif
Ret

LowLevelKeyboardProc endp
_ CmpPassWord proc _ lpPassWord1, _ lpPassWord2, _ dwPassWordlength; the two passwords are the same

Pushad
Mov dwFlag, 2
Mov esi, _ lpPassWord1
Mov edi, _ lpPassWord2
Mov ecx, _ dwPassWordlength
Xor edx, edx
Cld
@@:
Lodsb
Cmp al, [edi + edx]
Jnz @ F
Dec ecx
Inc edx
Test ecx, ecx
Jnz @ B
Mov dwFlag, 1
Ret
@@:
Mov dwFlag, 0
Popad
Ret

_ CmpPassWord endp
_ ProcDlgMain1 proc uses ebx edi esi hWnd, uMsg, wParam, lParam;
LOCAL @ szRePassWord [128]: byte; Buffer in the second password box
LOCAL @ szBuffer [128]: byte; Buffer used to display passwords

Mov eax, uMsg
. If eax = WM_CLOSE
Invoke EndDialog, hWnd, NULL
Invoke ExitProcess, NULL
. Elseif eax = WM_INITDIALOG
Push hWnd
Pop hWinDlg1
Invoke LoadIcon, hInstance, ICO_MAIN; load the icon file
Mov hIcon, eax
Invoke SendMessage, hWnd, WM_SETICON, ICON_BIG, eax; set the icon
Invoke SetDlgItemText, hWnd, IDC1_SHOWTEXT ,\
CTEXT ("Please misoperate this computer! Thank you for your cooperation! "); Set the initial value of the displayed content on the screen.
Invoke CheckDlgButton, hWnd, IDC1_PROMPT, BST_CHECKED; the initial display shows that the password is in the selected status.
Invoke SendDlgItemMessage, hWnd, IDC1_SCROLL, SBM_SETRANGE, 0,255; initialize the scroll bar 0-255
Invoke SendDlgItemMessage, hWnd, IDC1_SCROLL, SBM_SETPOS, 100, TRUE; initialize the scroll bar position

Is 100
Invoke SetDlgItemInt, hWnd, IDC1_COUNT, 100, FALSE; initialized scroll bar count is 100
Mov dwPos, 100; the variable for initializing the scroll bar position is 100

. Elseif eax = WM_COMMAND
. If wParam = IDC1_ OK
Invoke GetDlgItemText, hWnd, IDC1_SHOWTEXT, addr szShowText ,\
Sizeof szShowText; get the text displayed on the screen
Invoke GetDlgItemText, hWnd, IDC1_PASS, addr szPassWordBuf ,\
Sizeof szPassWordBuf; obtain the password in the first Password box
Mov dwLength, eax
Invoke GetDlgItemText, hWnd, IDC1_REPASS, addr @ szRePassWord ,\
Sizeof @ szRePassWord; obtain the password in the second password box
. If eax! = DwLength; Determine whether the length of the two passwords is consistent
Invoke MessageBox, hWnd, CTEXT ("two input passwords are different "),\
CTEXT ("error"), MB_ OK or MB_ICONWARNING
Ret
. Elseif eax = 0
Invoke MessageBox, hWnd, CTEXT ("the password cannot be blank "),\
CTEXT ("error"), MB_ OK or MB_ICONEXCLAMATION
Ret
. Endif
Invoke _ CmpPassWord, addr szPassWordBuf ,\
Addr @ szRePassWord, dwLength; compare whether the password is a log
. If dwFlag = 0
Invoke MessageBox, hWnd, CTEXT ("two input passwords are different "),\
CTEXT ("error"), MB_ OK or MB_ICONWARNING
. Elseif dwFlag = 1
Invoke IsDlgButtonChecked, hWnd, IDC1_PROMPT; check display password options
. If eax = BST_CHECKED
Invoke wsprintf, addr @ szBuffer, addr szPassWordFmt ,\
Addr szPassWordBuf; used to display passwords
Invoke MessageBox, hWnd, addr @ szBuffer, CTEXT ("prompt "),\
MB_ OK or MB_ICONEXCLAMATION
. Endif
Invoke EndDialog, hWnd, NULL; close the dialog box
Call _ WinMain; display the hanging window
. Endif
Ret
. Elseif wParam = IDC1_EXIT
Invoke EndDialog, hWnd, NULL
Invoke ExitProcess, NULL
. Elseif wParam = IDC1_ABOUT
Invoke MessageBox, hWnd, offset szAbout, CTEXT ("hook lock v1.0"), MB_ OK
. Elseif wParam = IDC1_BROWSE
Call _ GetFile
. Elseif wParam = IDC1_PLAY
. If dwFlag2 = 0
Call _ PlayMP3
. Else
Call _ StopPlayMP3
. Endif
. Endif
. Elseif eax = WM_HSCROLL; the 16-bit height of wParam is the current position of the scroll bar.
Mov eax, wParam; the low 16-bit wParam is the scroll bar action code.
. If ax = SB_LINELEFT
Dec dwPos
. Elseif ax = SB_LINERIGHT
Inc dwPos
. Elseif ax = SB_PAGELEFT
Sub dwPos, 10
. Elseif ax = SB_PAGERIGHT
Add dwPos, 10
. Elseif ax = SB_THUMBPOSITION | ax = SB_THUMBTRACK
Mov eax, wParam
Shr eax, 16; the height of wParam is the current position of the scroll bar.
Mov dwPos, eax
. Else
Mov eax, TRUE
Ret
. Endif
Cmp dwPos, 0
Jge @ F
Mov dwPos, 0
@@:
Cmp dwPos, 255
Jle @ F
Mov dwPos, 255
@@:
Invoke SetDlgItemInt, hWnd, IDC1_COUNT, dwPos, FALSE
Invoke SendDlgItemMessage, hWnd, IDC1_SCROLL, SBM_SETPOS, dwPos, TRUE
. Else
Mov eax, FALSE
Ret
. Endif
Mov eax, TRUE
Ret
_ ProcDlgMain1 endp
_ ProcDlgMain2 proc uses ebx edi esi hWnd, uMsg, wParam, lParam; enter the password window
LOCAL @ szPassWord [128]: byte; enter the Buffer of the password
LOCAL @ stRect: RECT
LOCAL @ hKey

Mov eax, uMsg
. If eax = WM_CLOSE
Invoke EndDialog, hWnd, NULL
. Elseif eax = WM_INITDIALOG
Invoke GetWindowRect, hWnd, addr @ stRect; get the window size
Invoke ClipCursor, addr @ stRect; restrict the range of mouse movement

Invoke SendMessage, hWnd, WM_SETICON, ICON_BIG, hIcon; set the dialog box icon

. Elseif eax = WM_COMMAND
. If wParam = IDC2_ OK
Invoke GetDlgItemText, hWnd, IDC2_PASS, addr @ szPassWord ,\
Sizeof @ szPassWord
. If eax = 0
Invoke MessageBox, hWnd, CTEXT ("the password cannot be blank! "),\
CTEXT ("error"), MB_ OK or MB_ICONWARNING
Ret
. Elseif eax! = DwLength; Determine whether the password length is consistent
Invoke MessageBox, hWnd, CTEXT ("Incorrect password! "),\
CTEXT ("error"), MB_ OK or MB_ICONEXCLAMATION
Ret
. Endif
Invoke _ CmpPassWord, addr szPassWordBuf, addr @ szPassWord, eax
. If dwFlag = 0
Invoke MessageBox, hWnd, CTEXT ("Incorrect password! "),\
CTEXT ("error"), MB_ OK or MB_ICONWARNING
. Elseif dwFlag = 1
Invoke FindWindow, addr szTaskBar, 0; get the taskbar handle
Invoke EnableWindow, eax, TRUE; set the taskbar to available
Invoke UnhookWindowsHookEx, hHook; uninstall hook
; Invoke ExitProcess, NULL; exit the program
Invoke ShowWindow, hWinDlg1, SW_SHOWNORMAL
Invoke DestroyWindow, hWinMain
Invoke EndDialog, hWnd, NULL
Invoke GetWindowRect, hWnd, addr @ stRect
Invoke ClipCursor, addr @ stRect

Invoke RegOpenKeyEx, HKEY_CURRENT_USER, addr szSubKey ,\
0, KEY_ALL_ACCESS, addr @ hKey
Invoke RegDeleteValue, @ hKey, addr szValueName
Invoke RegCloseKey, @ hKey; used to unlock the Registry

. Endif
. Endif
. Else
Mov eax, FALSE
Ret
. Endif
Mov eax, TRUE
Ret

_ ProcDlgMain2 endp
_ WinMain proc; screen lock window
LOCAL @ stWndClass: WNDCLASSEX
LOCAL @ stMsg: MSG

Invoke GetModuleHandle, NULL
Mov hInstance1, eax
Invoke RtlZeroMemory, addr @ stWndClass, sizeof @ stWndClass
Push hInstance1
Pop @ stWndClass. hInstance
Mov @ stWndClass. cbSize, sizeof WNDCLASSEX
Mov @ stWndClass. lpfnWndProc, offset _ ProcWinMain
Mov @ stWndClass. lpszClassName, offset szClassName
Mov @ stWndClass. style, CS_DBLCLKS
Invoke LoadCursor, hWinMain, IDC_ARROW
Mov @ stWndClass. hCursor, eax
Invoke RegisterClassEx, addr @ stWndClass

Invoke createappswex, WS_EX_TOPMOST, offset

SzClassName, 0, WS_POPUPWINDOW, 0, 0, 0, 0, hInstance, 0
Mov hWinMain, eax
Invoke ShowWindow, eax, SW_SHOWMAXIMIZED
Invoke UpdateWindow, hWinMain

. While TRUE
Invoke GetMessage, addr @ stMsg, NULL, 0, 0
. Break. if eax = 0
Invoke TranslateMessage, addr @ stMsg
Invoke DispatchMessage, addr @ stMsg
. Endw
Ret

_ WinMain endp
_ ProcWinMain proc uses ebx edi esi hWnd, uMsg, wParam, lParam; screen lock Window Process
LOCAL @ stPs: PAINTSTRUCT
LOCAL @ hDc, @ hBmpDc
LOCAL @ stRect: RECT
LOCAL @ hKey, @ dwSize

Mov eax, uMsg
. If eax = WM_CLOSE
Invoke DestroyWindow, hWinMain
Invoke PostQuitMessage, NULL
. Elseif eax = WM_CREATE
Invoke LoadBitmap, hInstance1, IDB_BMP
Mov hBitMap, eax

Invoke GetWindowLong, hWnd, GWL_EXSTYLE; set the window transparency dwPos.
Or eax, WS_EX_LAYERED
Invoke SetWindowLong, hWnd, GWL_EXSTYLE, eax
Invoke SetLayeredWindowAttributes, hWnd, 0, dwPos, LWA_ALPHA

Invoke SetWindowsHookEx, WH_KEYBOARD_LL, LowLevelKeyboardProc ,\
HInstance, NULL; Hook Keyboard Message process is LowLevelKeyboardProc

Mov @ dwSize, sizeof szValue
Invoke RegCreateKeyEx, HKEY_CURRENT_USER, addr

SzSubKey, 0, NULL, NULL, KEY_ALL_ACCESS, NULL, addr @ hKey, NULL
Invoke RegSetValueEx, @ hKey, addr szValueName, 0, REG_SZ, addr szValue, @ dwSize
Invoke RegCloseKey, @ hKey; used to lock the Registry

. Elseif eax = WM_PAINT; displays the background image.
Invoke BeginPaint, hWinMain, addr @ stPs
Mov @ hDc, eax
Invoke CreateCompatibleDC, @ hDc
Mov @ hBmpDc, eax
Invoke SelectObject, @ hBmpDc, hBitMap
Invoke GetClientRect, hWinMain, addr @ stRect
Invoke BitBlt, @ hDc, @ stRect. right, @ stRect. bottom, @ hBmpDc, SRCCOPY
Invoke DrawText, @ hDc, addr szShowText,-1, addr @ stRect, DT_CENTER or \
DT_SINGLELINE or DT_VCENTER; display screen text
Invoke DeleteDC, @ hBmpDc
Invoke EndPaint, hWinMain, addr @ stPs
. Elseif eax = WM_LBUTTONDOWN
Invoke DialogBoxParam, hInstance, DLG_MAIN, hWnd, offset _ ProcDlgMain2, NULL

. Else
Invoke DefWindowProc, hWnd, uMsg, wParam, lParam
Ret
. Endif
Xor eax, eax
Ret

_ ProcWinMain endp
_ PlayMP3 proc
Local @ stMCIOpen: MCI_OPEN_PARMS
Local @ stMCIPlay: MCI_PLAY_PARMS

Mov @ stMCIOpen. lpstrDeviceType, offset szDevice
Mov @ stMCIOpen. lpstrElementName, offset szFileName
Invoke mciSendCommand, 0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, addr @ stMCIOpen
Mov eax, @ stMCIOpen. wDeviceID
Mov hDevice, eax
Mov eax, hWinDlg1
Mov @ stMCIPlay. dwCallback, eax
Invoke mciSendCommand, hDevice, MCI_PLAY, MCI_NOTIFY, addr @ stMCIPlay
. If eax = 0
Invoke SetDlgItemText, hWinDlg1, IDC1_PLAY, CTEXT ("stop ")
Mov dwFlag2, 1
. Endif
Ret

_ PlayMP3 endp
_ StopPlayMP3 proc
Local @ stMCIStop: MCI_GENERIC_PARMS

Mov eax, hWinDlg1
Mov @ stMCIStop. dwCallback, eax
Invoke mciSendCommand, hDevice, MCI_STOP, MCI_NOTIFY, addr @ stMCIStop
Invoke mciSendCommand, hDevice, MCI_CLOSE, MCI_NOTIFY, addr @ stMCIStop
Invoke SetDlgItemText, hWinDlg1, IDC1_PLAY, CTEXT ("play ")
Mov dwFlag2, 0
Ret

_ StopPlayMP3 endp
_ GetFile proc
LOCAL @ stOF: OPENFILENAME

Invoke RtlZeroMemory, addr @ stOF, sizeof @ stOF
Mov @ stOF. lStructSize, sizeof @ stOF
Push hWinDlg1
Pop @ stOF. hwndOwner
Mov @ stOF. lpstrFilter, offset szFilter
Mov @ stOF. lpstrFile, offset szFileName
Mov @ stOF. nMaxFile, MAX_PATH
Mov @ stOF. Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
Invoke GetOpenFileName, addr @ stOF
. If eax
Invoke SetDlgItemText, hWinDlg1, IDC1_FILE, addr szFileName
Call _ StopPlayMP3
. Endif
Ret

_ GetFile endp
Start:
Invoke GetModuleHandle, NULL
Mov hInstance, eax
Invoke DialogBoxParam, hInstance, DLG_SHOW, NULL, offset _ ProcDlgMain1, NULL
Invoke ExitProcess, NULL
End start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.