home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
dskutl
/
passwrd6.arc
/
PW.8
< prev
next >
Wrap
Text File
|
1987-02-17
|
10KB
|
210 lines
; TITLE PW.8 - assembles to PW.SYS device driver (use A86 assembler)
; Rev by John R. Petrocelli 02/25/85
; Rev by John R. Petrocelli 04/30/85
; Rev by Durrell Drummond 10/10/86
; Completely redone by Bob Montgomery 1/10/87
Lf equ 0Ah ;Line feed char
Cr equ 0Dh ;Carriage return char
Esc equ 1Bh ;Escape char
Bell equ 7 ;Bell char
Tab equ 9 ;Tab char
org 0 ;Required for a device driver
Start:
dw -1,-1 ;=>only 1 device is defined in this file
dw 8000h ;=>char dev, non IOCTL
dw Strategy ;pointer to the installation procedure
dw Interupt ;pointer to the proc that handles all services
db 'PWXYZQPR' ;8-byte string of device name; should be something weird
; or strange things may happen if you have a file by this name.
;===========================================================================
; These are the program variables and constants.
RHoffset dw ? ;Request Header offset
RHseg dw ? ;Request Header segment
Password db 8,'PASSWORD' ;# chars and password (16 chars max)
Userword db 16 ;Max chars DOS to accept
Wordlen db ? ;# chars in user word
Wordbuff db 16 DUP(?) ;User word starts here
Tries db 3 ;Allow 3 tries before lockout
Breakoff dw ? ;Store old Break offset here
Breakseg dw ? ;Store old Break segment here
; Messages ==================================================================
MSG_1 db Esc,'[2J',ESC,'[9;1f' ;Clear screen and move to row 10, col 1
MSG1 db Esc,'[31;40m',Cr,Lf, ;make output visible, red on black
db 4 dup(Tab),'Enter Password' ;Move 32 columns right (Tab 4)
db Esc,'[8m$' ;make input invisible
MSG_2 db Esc,'[0m' ;make output visible
db Cr,Lf,4 dup(Tab) ;Move 32 columns right
db 'Password accepted',Esc,'[33;40m$' ;Print msg, make brown on black
MSG_3 db Esc,'[0m',Cr,Lf ;make output visible
db 4 dup(Tab),'Wrong-Try again$';Move 32 columns right
MSG_4 db Esc,'[0m',esc,'[2J' ;make output visible & cls
db Esc,'[12;26f' ;Move to row 12, col 26
db '3 STRIKES AND YOU ARE OUT...' ;Print message
db Esc,'[13;31f',ESC,'[31m',201,15 dup(205),187 ;Top border
db Esc,'[14;31f',186 ;Line 14, col 31 left border
db Esc,'[5m ACCESS DENIED ' ;Make output blink
db Esc,'[0;31m',186 ;Non-blink right border
db Esc,'[15;31f',200,15 dup(205),188 ;Row15, col 31 bottom border
db Esc,'[8m ',8,'$' ;Make invisible and bacspace
;=====================================================================
;Ctrl-Break vector is pointed here, so it does an IRET; disables Break.
Dummyret: iret ;Return from interrupt
;=====================================================================
; Subroutines
; --------------------------------------------------------------------
; The following disables Ctrl-Break by pointing it to a dummy IRET.
; Old break vector is saved so it may be restored later.
Askpw: mov ds,cs ;Set ds=cs
mov ax,351Bh ;Get Break (Int 1Bh) vector
int 21h ;from DOS
mov Breakoff,bx ;Save it for later
mov Breakseg,es
mov es,cs ;Set es=cs
mov dx,Dummyret ;Set Break vector to IRET
mov ax,251Bh ;in this code
int 21h ;thru DOS
; Now, prompt the user for the correct password and locks up system
; if not given in 'Tries' attempts.
; Set CL for allowed tries and point to message.
xor cx,cx ;Set Cx=0
mov cl,Tries ;Set Cl=# tries allowed
mov dx,offset Msg_1 ;Point to ANSI cursor command
jmp short prt_it ;Print it and prompt
;Come here for next retry if wrong password given.
Nxttry: mov al,Bell ;Bell char
mov ah,0Eh ;Sound bell
int 10h ;using video I/O
mov dx, offset Msg1 ;Point to prompt
Prt_it: push cx ;Save # tries
mov ah,9 ;Print it
int 21h ;using DOS service
;Clear buffer, and get user word; 2nd byte is # char, word starts 3rd byte.
mov dx,offset Userword ;Clear keyboard buffer
mov ah,12 ;using DOS function 12
mov al,10 ;and then get new user word up to CR.
int 21H ;using DOS function 10
mov si,offset Wordlen ;Point to # char in user word
mov di,offset Password ;Point to # char in password
xor cx,cx ;Set Cx=0
mov cl,[si] ;Get # chars in user word in cx
cmpsb ;Same as # in password (inc si & di)?
jne wrong ;No
call Convup ;Convert user word to upper case
repe cmpsb ;Compare while chars are equal
cmp cl,0 ;All chars same?
je OK ;Yes
; Wrong password was given, so say so and see if any tries left.
Wrong: pop cx ;Get # tries left
mov dx,offset msg_3 ;Print 'wrong password'
mov ah,9 ;using DOS function 9
int 21h
loopnz Nxttry ;Dec cx and try again if not 0
; All tries have been used, so lock up the system.
mov dx, offset Msg_4 ;Print '3 strikes out-access denied'
mov ah,9 ;using DOS funtion 9
int 21h
cli ;Disable interrupts (Cntrl-Alt-Del)
Locked: jmp Locked ;Put into an endless loop to lock-up
; Come here if correct password was given.
OK: pop cx ;Remove # tries from stack
mov dx,offset Msg_2 ;Print 'Password accepted'
mov ah,9 ;using DOS function 9
int 21h
; Now, restore the old Break vector.
mov ds,Breakseg ;Set old Break vector to enable Break
mov dx,Breakoff
mov ax,251Bh ;thru DOS
int 21h
ret ;and return
;----------------------------------------------------------------------
; This sub will convert the string at DS:SI to upper case; Cx=# chars.
Convup: push ax,cx,ds,es,si,di ;Save all
mov es,ds ;Set ES=DS
mov di,si ;Set DI=SI
Chkchr: lodsb ;Get char at DS:SI, inc SI
cmp al,'a' ;< a?
jl Stbyte ;Yes
cmp al,'z' ;> z?
jg Stbyte ;Yes
sub al,20h ;No, convert to upper case
Stbyte: stosb ;Store char at ES;DI, inc DI
loop Chkchr ;Do all chars (until Cx=0)
pop di,si,es,ds,cx,ax ;Restore all registers
ret ;and return
; End of subroutines
;======================================================================
; The program LOCK.COM enters here by calling INT 66h.
Lock1: push ds,es,ax,bx,cx,dx,si,di ;Save all
call Askpw ;Get password from user
Exit1: pop di,si,dx,cx,bx,ax,es,ds ;Restore all registers
retf ;and return to DOS
;======================================================================
; This is the procedure called by DOS to process the command in
; the Request Header. Should preserve the environment-restore when done.
Interupt: push ds,es,ax,bx,cx,dx,si,di ;Save all
mov ds,cs ;Set ds=cs
mov bx,RHoffset ;Point ES:Bx to Request Header
mov es,RHseg
es cmp b[bx+2],0 ;Command=0 (initialize)?
je Init ;Yes, do initialization
; Should only be called to initialize; any other is error so return 'done'.
Exit: es or w[bx+3],100h ;No, set status=done
jmp short Exit1 ;and exit to DOS
;=========================================================================
; This is the INITialize code; free memory starts here after initialize.
Init: mov dx,Lock1 ;Point to interrupt 66h routine
mov ax,2566h ;Save Int 66 vector thru DOS
int 21h
xor cx,cx ;Set Cx=0
mov si,offset Password ;Point to # char in password
lodsb ;Get # char in al, inc si
mov cl,al ;Cx=# chars
push es,bx ;Save RH header address
call Convup ;Convert password to upper case
call Askpw ;Get password from user
; The following sets the vector for INT 66h to the location of Lock
; so the LOCK.COM program can do a password check using the same code.
pop bx,es ;Restore RH pointer
es mov w[bx+14],Init ;Save pointer to Init as start of free
es mov w[bx+16],cs ;memory (after installation) in RH.
jmp Exit ;and return to DOS
;===========================================================================
; The STRATEGY proc stores the location of the Request Header (passed by DOS
; in ES:BX) here. The INTERUPT proc gets it to find the request from DOS.
; Request Header format:
; Offset Content
; 0 Byte-length (of request header)
; 1 Byte-unit code (if more than 1 device controlled)
; 2 Byte-command (0 thru Ch; 0=INITialize)
; 3,4 Word-status (Bit 8=done, bit 15=error, bits 0-3=error code)
; 5-D 8 bytes-reserved for DOS
; E- Data-ending address if code=0, otherwise data to transfer
Strategy: cs mov RHoffset,BX ;Save Request Header offset
cs mov RHseg,ES ;Save Request Header segment
Retf ;and return (far)
end Start