home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / sysutl / passwrd9.arc / PASSWORD.ASM < prev    next >
Assembly Source File  |  1989-03-15  |  17KB  |  575 lines

  1.     Title pw9.asm
  2.     ;Originally titled PW.8
  3.     ;Rev by John R. Petrocelli    02/25/85
  4.     ;Rev by John R. Petrocelli    04/30/85
  5.     ;Rev by Durrell Drummond    10/10/86
  6.     ;Re-written by Bob Montgomery    01/10/87
  7.     ;Re-written by John Jaeger    03/12/89
  8.  
  9.     ;Major changes include ready for assembly by MASM.
  10.  
  11.     ;Use without the ANSI.SYS driver for reasonable CRT
  12.     ;displays.
  13.  
  14.     ;Corrected source code.  The original dated 01/10/87
  15.     ;worked as stated when using the supplied object code,
  16.     ;However when I added all the necessary items to compile
  17.     ;with MASM, things didn't work so well.  That may be due
  18.     ;to the fact I am not acquainted with A86!
  19.  
  20.     ;Coding of the ASCII Password string so that if
  21.     ;viewed by such things as XTREE, nothing jumps out
  22.     ;and indicates a readable password.
  23.  
  24.     ;Coding of the "Prompt Strings" for the same reason
  25.     ;as noted above.  There is no evidence that this file
  26.     ;is the one to cause the Password Check to appear on the 
  27.     ;screen.
  28.  
  29. code    segment public    'CODE'
  30.  
  31.     assume cs:code,ds:code,es:code
  32.  
  33. driver    proc    near
  34.  
  35.     org    0                ;Required for Device Driver
  36.  
  37. ;======== Driver Device Header Area ========
  38.  
  39. header:    dd    -1                ;One device in this file
  40.     dw    8000h                ;Defines character device
  41.     dw    strategy            ;Pointer to install routine
  42.     dw    interrupt            ;pointer to proc that handles
  43.                         ;the services
  44.     db    'PWXYZQPR'            ;8 byte string that names the
  45.                         ;device.  Do not attempt to
  46.                         ;type from the Keyboard or
  47.                         ;anything could happen!!!!
  48.  
  49. ;============================================================================
  50.  
  51. ;======== Storage for header offset and segment ========
  52. rhoffset     dw    0
  53. rhseg        dw    0
  54. ;============================================================================
  55.  
  56. ;============================================================================
  57. ;Area below is for some variables used by the program that installs
  58. ;PASSWORD.SYS.  DO NOT change the relationship of the variable "area_length"
  59. ;to the DEVICE HEADER, or the location of the PASSWORD area!  You may add
  60. ;or delete to the Screen Message area, but do not move or remove the 
  61. ;"tries_left" variable in relation to the message area.
  62. ;============================================================================
  63. area_length    dw    tries_left-$
  64. password    db    0
  65. password_len    equ    $-password
  66. padd        db    16-password_len dup(20h)
  67. ;============================================================================
  68.  
  69. ;======== Screen message character area (Encrypted) ========
  70.  
  71. msg_1        db    'Enter Password:',15 dup(20h)    ;Enter Password
  72. msg_1_len    dw    $-msg_1                
  73. msg_2        db    '****** Password Accepted *****';Password Accepted
  74. msg_2_len    dw    $-msg_2
  75. msg_3        db    '** Wrong Password Try Again **';Wrong Password
  76. msg_3_len    dw    $-msg_3
  77. msg_4        db    '******** ACCESS DENIED *******';Access Denied
  78. msg_4_len    dw    $-msg_4
  79. msg_5        db    201,32 dup(205),187        ;Screen Box
  80. msg_6        db    186,32 dup(20h),186        ;Screen Box
  81. msg_7        db    200,32 dup(205),188        ;Screen Box
  82. ;============================================================================
  83. ;Miscellaneous Variable Storage
  84. ;============================================================================
  85. Tries_left    db    0
  86. wordlen        db    0
  87. wordbuff    db    15 dup(0)
  88. tries        db    3
  89. breakoff    dw    0
  90. breakseg    dw    0
  91. video_location    dw    0
  92. cursor_location    dw    0
  93. ;============================================================================
  94. dummyret:    iret                ;Pointer to Ctrl-Break vector
  95.                         ;inserted by this program to
  96.                         ;disable the Ctrl-Break 
  97. ;============================================================================
  98.  
  99. ;======== main portion of program to get the user password ========
  100.  
  101. ask_password:
  102.  
  103.     push    cs
  104.     pop    ds                ;Set ds=cs
  105.     mov    ax,351bh            ;Get break vector (Int 1Bh)
  106.     int    21h                ;from DOS
  107.     mov    breakoff,bx            ;Save it for later
  108.     mov    breakseg,es
  109.     push    cs
  110.     pop    es                ;Set es=cs
  111.     mov    dx,offset dummyret        ;Set Break vector to dummyret
  112.     mov    ax,251bh
  113.     int    21h                ;via DOS
  114.  
  115. check_video:                    ;See where video RAM is
  116.  
  117.     mov    ah,0fh                ;via video ROM
  118.     int    10h                
  119.     cmp    al,07h                ;See if Mono card installed
  120.     jz    set_mono            ;Jump to monochrome routine
  121.  
  122.     mov    video_location,0b800h        ;If not mono then Color RAM
  123.     jmp    video_done            ;Exit routine
  124.  
  125. set_mono:
  126.  
  127.     mov    video_location,0b000h        ;Set location to Mono RAM
  128.  
  129. video_done:
  130.  
  131.     call    clear_screen            ;Self explanatory
  132.  
  133.     call    box                ;Routine to build entry
  134.                         ;box on screen
  135.     xor    cx,cx                ;Set cx=0
  136.     mov    cl,tries            ;Store the number of tries
  137.     mov    tries_left,cl            ;for later
  138.  
  139. ;======== Prompt the user for the correct password ========
  140.  
  141. set_prompt:
  142.  
  143.     cmp    cl,0                ;See if tries has expired
  144.     jz    go_lock_out            ;Jump to routine to lock
  145.                         ;system if tried 3 times
  146.                         ;with wrong password!
  147.  
  148.     mov    tries_left,cl            ;Store the tries left
  149.     mov    bx,offset msg_1            ;Point to input prompt
  150.     mov    cx,msg_1_len            ;Prep for display
  151.     mov    ah,0fh                ;Set ah with the attribute
  152.                         ;that write_crt uses
  153.                         ;You may change this for
  154.                         ;different colors or intensity
  155.     mov    dx,0c19h            ;Load dx for start location
  156.     call    write_crt            ;to print on CRT and write it
  157.  
  158.     mov    dx,0b27h            ;Set CRT location for input
  159.                         ;field start
  160.     xor    bx,bx                ;Set bx to 0 (Page 0)
  161.     call    position_cursor            ;Set cursor to start of input
  162.                         ;line on CRT
  163.     mov    si,offset wordlen        ;Point to number of char. in
  164.     mov    byte ptr [si],0            ;entry and initialize to 0
  165.     mov    di,offset wordbuff        ;Point to number of char. in
  166.                         ;stored password
  167. ;======== Character input routine ========
  168.  
  169. in_char:                    ;Lets go get some input
  170.  
  171.     mov    ah,07h                ;Use none echoing input
  172.     int    21h                ;from DOS
  173.     cmp    al,08h                ;See if backspace?
  174.     jz    back_space            ;Jump to routine to del Char.
  175.     cmp    al,0dh                ;See if input is done?
  176.     jz    check_password            ;Check it out
  177.     cmp    byte ptr [si],15        ;See if password length has
  178.     jz    bell                ;been exceeded and ring bell
  179.     mov    [di],al                ;Store char in wordbuff and
  180.     inc    di                ;increment pointer
  181.     mov    al,0h                ;Store special char for the
  182.     call    write_cursor            ;display of an '*' on the CRT
  183.     jmp    in_char                ;Loop for the next Character
  184.  
  185. ;======== Intermediate launching point to lock the machine ========
  186.  
  187. go_lock_out:
  188.  
  189.     call    lock_out            ;Go lock up the machine
  190.  
  191. ;======== Routine to back space and erase on the crt ========
  192.  
  193. back_space:
  194.  
  195.     cmp    byte ptr [si],0            ;See if there are no char to
  196.     jz    bell                ;erase and sound bell if none
  197.     dec    byte ptr [si]            ;Set char count to one less
  198.     dec    di                ;Move pointer back one in
  199.                         ;wordbuff
  200.     mov    al,0ffh                ;Set erase code for erasing
  201.     call    write_cursor            ;'*' at cursor position
  202.     jmp    in_char                ;Loop back for next char
  203.  
  204. ;======== Ring the bell routine ========
  205.  
  206. Bell:    mov    al,07h                ;Ring the bell with DOS
  207.     mov    ah,0eh
  208.     int    10h
  209.     jmp    in_char                ;Back to input
  210.     
  211. ;============================================================================
  212. ;End of input routines, now lets go check what was entered!
  213. ;============================================================================
  214.  
  215. Check_password:
  216.  
  217.     mov    di,offset password        ;Point to length of our pre-
  218.     cmpsb                    ;set word and see if the 
  219.     jne    next_try            ;length is the same and spare
  220.                         ;the trouble if it is not
  221.  
  222.     xor    cx,cx                ;cx=0
  223.     mov    cl,wordlen            ;Total char. entered into cl
  224.     call    convert_up            ;Convert char. to upper case
  225.     repe    cmpsb                ;compare pointers si & di
  226.     cmp    cl,0                ;See if all matched
  227.     je    ok                ;Jump to exit if they were
  228.                         ;Fall through if not
  229.  
  230. ;======== Routine to display wrong word and reset for another word ========
  231.  
  232. next_try:
  233.  
  234.     call    off_screen            ;Move curser out of the box
  235.     mov    dx,0c19h            ;Cursor location for message
  236.     mov    bx,offset msg_3            ;Wrong Password message
  237.     mov    cx,msg_3_len            ;Message length
  238.     mov    ah,8fh                ;Blinking attribute
  239.     call    write_crt            ;Display message
  240.     mov    ax,0e07h            ;Ring bell
  241.     int    10h
  242.     mov    ah,07h                ;Ask for character input to
  243.     int    21h                ;hold screen. Any char allows
  244.                         ;continuation of the program
  245.     mov    cl,tries_left            ;Set up to reduce the number
  246.     dec    cl                ;of tries left and go back
  247.     jmp    set_prompt            ;for another turn
  248.  
  249. ;======== This is where we prepare to exit this program ========
  250.  
  251. ok:
  252.  
  253.     call    off_screen            ;Move cursor out of the box
  254.     mov    dx,0c19h            ;Location of message
  255.     mov    bx,offset msg_2            ;Point to Password Accepted
  256.     mov    cx,msg_2_len            ;Length of message
  257.     mov    ah,8fh                ;Set attribute
  258.     call    write_crt            ;Display successful message
  259.  
  260.     mov    ds,breakseg            ;Restore original Ctrl Break
  261.     mov    dx,breakoff            ;vectors through DOS
  262.     mov    ax,251bh
  263.     int    21h
  264.  
  265.     ret                    ;And return
  266.  
  267. ;============================================================================
  268. ;This subroutine converts all characters to upper case
  269. ;============================================================================
  270.  
  271. convert_up:
  272.  
  273.     push    ax                ;Save all registers
  274.     push    cx
  275.     push    ds
  276.     push    es
  277.     push    si
  278.     push    di
  279.     push    ds                ;es=ds
  280.     pop    es
  281.     mov    di,si                ;make di & si point to the
  282.                         ;same location
  283. check_char:
  284.  
  285.     lodsb                    ;Get char at si and inc si
  286.     cmp    al,'a'                ; < a ?
  287.     jl    store_byte            ; It's ok - store it
  288.     cmp    al,'z'                ; > z ?
  289.     jg    store_byte            ; It's ok - store it
  290.     sub    al,20h                ; Make it caps
  291.  
  292. Store_byte:
  293.  
  294.     stosb                    ;Store the byte at di
  295.     loop    Check_char            ;Do all until cx=0
  296.  
  297.     pop    di                ;Restore all registers
  298.     pop    si
  299.     pop    es
  300.     pop    ds
  301.     pop    cx
  302.     pop    ax
  303.  
  304.     ret                    ;And return
  305.  
  306. ;============================================================================
  307.  
  308. driver endp
  309.  
  310. ;============================================================================
  311. ;This routine locks up the machine completely.  If the program gets this far
  312. ;you will need to press the reset button ( If you have one ) or
  313. ;turn the power off!!
  314. ;============================================================================
  315.  
  316. lock_out    proc    near
  317.  
  318.     cli                    ;Disable any interrupts
  319.     mov    dx,0c19h            ;Location on CRT for message
  320.     mov    bx,offset msg_4            ;Sad message !!!
  321.     mov    cx,msg_4_len            ;Message length
  322.     mov    ah,8fh                ;Blinking Attribute
  323.     call    write_crt            ;Print Sad message
  324.     call    off_screen            ;Get cursor out of box
  325.                         ;        and
  326. locked:    jmp    locked                ;        die !
  327.  
  328. lock_out    endp
  329.  
  330. ;============================================================================
  331. ;The following routines are the direct CRT display code
  332. ;============================================================================
  333.  
  334. write_crt    proc    near
  335.  
  336.     push    es                ;Save original es
  337.     push    dx                ;Save location to write
  338.     push    ax                ;Save the attribute
  339.     push    cx                ;Save the character count
  340.     push    dx                ;Save for the moment
  341.     mov    cx,02h                ;Set the multiplier
  342.     mov    ax,video_location        ;Get the address of video RAM
  343.     mov    es,ax                ;Set the es register to RAM
  344.     mov    si,bx                ;Point si to the message
  345.     xor    ax,ax                ;Zero the ax
  346.     mov    al,dl                ;Move to al the column
  347.     sub    al,1                ;Adjust the al
  348.     imul    cx                ;Times to for actual column
  349.     pop    dx                ;Get the original location
  350.     mov    dl,al                ;Store column in dl
  351.     mov    al,dh                ;Move into ax the row
  352.     push    dx                ;Save for the moment
  353.     sub    ax,1                ;Adjust the ax
  354.     mov    cx,160                ;80 times 2 for actual offset
  355.     imul    cx
  356.     pop    dx                ;Get dx back
  357.     and    dh,00h                ;Zero the dh
  358.     add    ax,dx                ;Add the column offset to the
  359.     mov    di,ax                ;row and move di to the actual
  360.                         ;memory position
  361.     pop    cx                ;Restore character count
  362.     pop    ax                ;Restore the attribute
  363.  
  364. write_crt_1:
  365.  
  366.     lodsb                    ;Load a byte of message
  367.     stosw                    ;Store byte & attribute to RAM
  368.     loop    write_crt_1            ;Loop until cx=0
  369.     pop    dx                ;Restore original dx
  370.     pop    es                ;restore original es
  371.     ret                    ;And return
  372.  
  373. write_crt    endp
  374.  
  375. write_cursor    proc    near
  376.  
  377.     mov    bx,0fh                ;Load attribute in bl
  378.     mov    cx,1                ;Load # of characters
  379.     cmp    al,0ffh                ;See if back space
  380.     jz    erase_char            ;If so then erase prev char
  381.     mov    al,'*'                ;Set to display an * on CRT
  382.     mov    ah,09h                ;Call DOS to display '*'
  383.     int    10h
  384.     mov    dx,cursor_location        ;Where in the input string
  385.     inc    dl                ;the cursor resides and inc
  386.     inc    byte ptr [si]            ;Increase character count
  387.     xor    bx,bx                ;Zero the bx
  388.     jmp    position_cursor            ;Move cursor to the next pos
  389.  
  390. erase_char:
  391.  
  392.     mov    dx,cursor_location        ;Get the last position of the
  393.     dec    dl                ;cursor and back it up
  394.     call    position_cursor
  395.     mov    ah,09h                ;Set up to output a space
  396.     mov    al,' '                ;character over the last *
  397.     int    10h                ;Have DOS do it
  398.     ret                    ;And return
  399.  
  400. off_screen:
  401.  
  402.     xor    bx,bx                ;Zero bx (page 0) and set
  403.     xor    dx,dx                ;position to upper left corner
  404.                         
  405. position_cursor:
  406.  
  407.     mov    cursor_location,dx        ;Store the position for later
  408.     mov    ah,02h                ;Have DOS reset the cursor 
  409.     int    10h                ;where we want it
  410.     ret                    ;And return
  411.  
  412. clear_screen:
  413.  
  414.     mov    ax,0600h            ;Use DOS scroll to clear CRT
  415.     mov    bh,07                ;Set attribute
  416.     xor    cx,cx                ;Upper left corner 0,0
  417.     mov    dx,184fh            ;Lower right 24,79
  418.     int    10h
  419.     ret                    ;And return
  420.  
  421. write_cursor    endp
  422.  
  423. ;============================================================================
  424. ;This routine draws a box for an entry window
  425. ;============================================================================
  426.  
  427. box    proc    near
  428.  
  429.     mov    ah,04h                ;Set attribute for box
  430.     mov    bx,offset msg_5            ;Point to Upper portion
  431.     mov    cx,34                ;Horizontal Length
  432.     mov    dx,0b17h            ;Start at line 11, col 23
  433.     call    write_crt            ;Draw it
  434.     mov    bx,offset msg_6            ;Middle portion
  435.     mov    cx,34                ;Length
  436.     mov    dx,0c17h            ;Start next at 12 and 23
  437.     call    write_crt            ;Draw it
  438.     mov    bx,offset msg_7            ;Bottom portion
  439.     mov    cx,34                ;length
  440.     mov    dx,0d17h            ;Start next at 13 and 23
  441.     call    write_crt            ;Draw it
  442.     ret                    ;And return
  443.  
  444. box    endp
  445.  
  446. ;============================================================================
  447. ;The following procedure is where "Lock.Com" makes its entry
  448. ;It is far procedure ending with a Interrupt Return as Lock.Com
  449. ;gets here using an int 66.
  450. ;============================================================================
  451. lock    proc    far
  452.  
  453.     push    ds                ;Save Everything
  454.     push    es
  455.     push    ax
  456.     push    bx
  457.     push    cx
  458.     push    dx
  459.     push    si
  460.     push    di
  461.  
  462.     call    ask_password            ;Ask user for password
  463.  
  464.     pop    di                ;Restore Everything
  465.     pop    si
  466.     pop    dx
  467.     pop    cx
  468.     pop    bx
  469.     pop    ax
  470.     pop    es
  471.     pop    ds
  472.  
  473.     iret                    ;And return from interrupt
  474.  
  475. ;============================================================================
  476. ;This is the routine called by DOS to process the command in the request
  477. ;header.  Preserve the environment and restore when done
  478. ;============================================================================
  479.  
  480. interrupt:
  481.  
  482.     push    ds
  483.     push    es
  484.     push    ax
  485.     push    bx
  486.     push    cx
  487.     push    dx
  488.     push    si
  489.     push    di
  490.     push    cs
  491.     pop    ds                ;Set ds=cs
  492.     mov    bx,rhoffset            ;Get request header and
  493.     mov    es,rhseg            ;segment loaded
  494.     cmp    es:byte ptr [bx+2],0        ;Command 0? (Initialize)
  495.     je    init                ;Yes jump & initialize
  496.  
  497. exit:    or    es:word ptr [bx+3],100h        ;No Set status done
  498.  
  499.     pop    di                ;Restore environment
  500.     pop    si
  501.     pop    dx
  502.     pop    cx
  503.     pop    bx
  504.     pop    ax
  505.     pop    es
  506.     pop    ds
  507.  
  508.     ret
  509.  
  510. ;============================================================================
  511. ;The following code is the initialize code run once when DOS originally
  512. ;loads this device driver.  A code is passed back to DOS showing the
  513. ;beginning location of this code.  Once initialized, this code is 
  514. ;discarded.
  515. ;============================================================================
  516.  
  517. init:    mov    dx,offset lock            ;Point to entry of int 66
  518.     mov    ax,2566h            ;and save it through DOS
  519.     int    21h
  520.     push    es                ;Save es & bx received
  521.     push    bx                ;from DOS
  522.  
  523. ;============================================================================
  524. ;This is the area to restore the display and password area to their
  525. ;original ASCII numbers.
  526. ;============================================================================
  527.     xor    cx,cx                ;Zero the counter
  528.     mov    cx,area_length            ;Get the char count to decode
  529.     mov    al,40h                ;Set the al to the decode #
  530.     mov    bx,offset password        ;Point to the start position
  531. in_loop:                    ;
  532.     add    byte ptr [bx],al        ;Start decoding
  533.     inc    bx                ;Increment pointer
  534.     loop    in_loop                ;Do until done
  535. ;============================================================================
  536.     xor    cx,cx                ;Prep for conversion to 
  537.     mov    si,offset password        ;Uppercase.  Point to length
  538.     lodsb                    ;of password and move to al
  539.     mov    cl,al                ;Move char count to cl
  540.     call    convert_up            ;Convert to upper case
  541.     call    ask_password            ;Ask user for Password
  542.     pop    bx                ;Restore bx & es
  543.     pop    es
  544.     mov    es:[bx+14],offset init        ;Save pointer to init as
  545.     mov    es:[bx+16],cs            ;start of free memory
  546.  
  547.     jmp    exit                ;And return to DOS
  548.  
  549. lock    endp
  550. ;============================================================================
  551. ;The following Strategy procedure stores the location of the request
  552. ;header (passed by DOS in the es:bx) here.  The interrupt procedure
  553. ;gets it to find the request from DOS.
  554.  
  555. ;Request header format:
  556. ; Offset    Content
  557. ; 0        Byte-length (of request header)
  558. ; 1        Byte-unit code (If more than one device controlled)
  559. ; 2        Byte-command (0 thru 0ch; 0=Initialize)
  560. ; 3,4        Word-Status (Bit 8=done, bit 15=error, bits 0-3=error code)
  561. ; 5-D        8 Bytes - Reserved for DOS
  562. ; E-        Data-Ending address if code=0, otherwise data to transfer
  563.  
  564. strategy    proc    far
  565.  
  566.     mov    cs:rhoffset,bx            ;Save Request header offset
  567.     mov    cs:rhseg,es            ;Save request header segment
  568.     ret                    ;And do a far return
  569.  
  570. strategy    endp
  571.  
  572. code    ends
  573.  
  574.     end
  575.