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

  1. ;============================================================================
  2. ;        Title - PWINIT           DATE: 3/15/89
  3. ;        This program is used with PASSWORD.ASM
  4. ;        and its resulting file PASSWORD.BIN after
  5. ;        compiling with MASM and converting it
  6. ;        to a binary image file using EXE2BIN.EXE.
  7. ;
  8. ;        The resulting EXE file will take an uninitialized
  9. ;        PASSWORD.BIN file and insert the password of
  10. ;        your choice and then encode the resulting
  11. ;        PASSWORD.SYS file to transfer under whatever
  12. ;        name you desire (as long as the name in CONFIG.SYS
  13. ;        matches ie:DEVICE=PASSWORD.SYS) to your boot disk.
  14. ;        I would suggest using a different name to conceal
  15. ;        your intentions!
  16.  
  17. ;============================================================================
  18. Dos    equ    21h
  19. ;============================================================================
  20. code segment                    ; Define code segment
  21. ;============================================================================
  22.  
  23. main    proc    far
  24.  
  25.     assume    cs:code,ds:data,es:file
  26.  
  27. start:                        ; Main starting address
  28.  
  29. ; Set ds to our data segment
  30.  
  31.     mov    ax,data                ;Data segment address
  32.     mov    ds,ax                ;Move into ds register
  33.     mov    ax,file                ;Get File segment
  34.     mov    es,ax                ;Set es: to file segment
  35.     call    check_video            ;See what type of monitor
  36.     mov    dx,offset org_file_name        ;Point to Uninit file name
  37.     call    open_file            ;Open file for read only
  38.     mov    old_handle,ax            ;Store the handle
  39.     mov    bx,ax                ;Set up for read
  40.     mov    dx,offset ds:file_buffer    ;Point to file buffer area
  41.     mov    cx,800h                ;Set number of characters
  42.     push    bx                ;Save the file handle
  43.     call    read_file            ;Read file into buffer
  44.     mov    file_size,ax            ;Store number of bytes in file
  45.     pop    bx                ;Restore the file handle
  46.     call    close_file            ;Close the old file
  47.     call    clear_screen            ;Clear the CRT
  48.     call    input_word            ;Ask user for PASSWORD
  49.     call    box                ;Clear the entry box
  50.     call    off_screen            ;Get cursor out of box
  51.     mov    ax,word ptr ds:file_buffer+22    ;Get count of char to encode
  52.     mov    scramble_count,ax        ;Store it for later
  53.     mov    ax,offset es:file+24        ;Point to PASSWORD address
  54.     mov    pass_location,ax        ;Store the offset
  55.     mov    di,ax                ;Move offset to di
  56.     push    di                ;Save it for the moment
  57.     xor    cx,cx                ;Zero the counter
  58.     mov    cl,password+1            ;Get user entered char. count
  59.     inc    cl                ;Account for char. count
  60.     mov    ax,offset password+1        ;Point to user password
  61.     mov    si,ax                ;Move pointer into si
  62.     rep    movsb                ;Move the PASSWORD into the
  63.                         ;new file area
  64.     pop    di                ;Restore es:offset to new
  65.                         ;file password area
  66.     mov    cx,scramble_count        ;Load the char count to encode
  67.     push    ds                ;Save original data segment
  68.     push    es
  69.     pop    ds                ;Make ds=es
  70.     mov    si,di                ;Make di & si point to the
  71. scramble:                    ;same bytes
  72.     lodsb                    ;Get a byte
  73.     sub    al,40h                ;Remove 40h
  74.     stosb                    ;Store the byte
  75.     loop    scramble            ;Loop until done
  76.     pop    ds                ;Restore the original ds
  77.     mov    dx,offset new_file_name        ;Point to the new file name
  78.     call    create_file            ;Create it
  79.     mov    bx,ax                ;Get the file handle into bx
  80.     push    bx                ;Save it
  81.     mov    cx,file_size            ;Load the cx with the file
  82.                         ;size
  83.     mov    dx,offset ds:file_buffer    ;Point to the file buffer
  84.     call    write_file            ;Write the new file
  85.     pop    bx                ;Restore the file handle
  86.     call    close_file            ;Close the new file
  87.     mov    ah,8fh                ;Set attribute for display
  88.     mov    bx,offset msg_4            ;Point to the complete msg.
  89.     mov    cx,msg_4_len            ;Length of message
  90.     mov    dx,0d1ch            ;Location to write it
  91.     call    write_crt            ;Display message
  92.  
  93. done:
  94.     mov    ax,4c00h
  95.     int    dos                ;Return to DOS
  96.  
  97. main    endp        ;End of main program
  98.  
  99. ;============================================================================
  100.  
  101. check_video    proc    near            ;See where video RAM is
  102.  
  103.     mov    ah,0fh                ;via video ROM
  104.     int    10h                
  105.     cmp    al,07h                ;See if Mono card installed
  106.     jz    set_mono            ;Jump to monochrome routine
  107.  
  108.     mov    video_location,0b800h        ;If not mono then Color RAM
  109.     jmp    video_done            ;Exit routine
  110.  
  111. set_mono:
  112.  
  113.     mov    video_location,0b000h        ;Set location to Mono RAM
  114.  
  115. video_done:
  116.  
  117.     ret
  118.  
  119. check_video    endp
  120.  
  121. ;============================================================================
  122. ;The following routines are the direct CRT display code
  123. ;============================================================================
  124.  
  125. write_crt    proc    near
  126.  
  127.     push    es                ;Save original es
  128.     push    dx                ;Save location to write
  129.     push    ax                ;Save the attribute
  130.     push    cx                ;Save the character count
  131.     push    dx                ;Save for the moment
  132.     mov    cx,02h                ;Set the multiplier
  133.     mov    ax,video_location        ;Get the address of video RAM
  134.     mov    es,ax                ;Set the es register to RAM
  135.     mov    si,bx                ;Point si to the message
  136.     xor    ax,ax                ;Zero the ax
  137.     mov    al,dl                ;Move to al the column
  138.     sub    al,1                ;Adjust the al
  139.     imul    cx                ;Times to for actual column
  140.     pop    dx                ;Get the original location
  141.     mov    dl,al                ;Store column in dl
  142.     mov    al,dh                ;Move into ax the row
  143.     push    dx                ;Save for the moment
  144.     sub    ax,1                ;Adjust the ax
  145.     mov    cx,160                ;80 times 2 for actual offset
  146.     imul    cx
  147.     pop    dx                ;Get dx back
  148.     and    dh,00h                ;Zero the dh
  149.     add    ax,dx                ;Add the column offset to the
  150.     mov    di,ax                ;row and move di to the actual
  151.                         ;memory position
  152.     pop    cx                ;Restore character count
  153.     pop    ax                ;Restore the attribute
  154.  
  155. write_crt_1:
  156.  
  157.     lodsb                    ;Load a byte of message
  158.     stosw                    ;Store byte & attribute to RAM
  159.     loop    write_crt_1            ;Loop until cx=0
  160.     pop    dx                ;Restore original dx
  161.     pop    es                ;restore original es
  162.     ret                    ;And return
  163.  
  164. write_crt    endp
  165. ;============================================================================
  166.  
  167. write_cursor    proc    near
  168.  
  169. off_screen:
  170.  
  171.     xor    bx,bx                ;Zero bx (page 0) and set
  172.     xor    dx,dx                ;position to upper left corner
  173.                         
  174. position_cursor:
  175.  
  176.     mov    ah,02h                ;Have DOS reset the cursor 
  177.     int    10h                ;where we want it
  178.     ret                    ;And return
  179.  
  180. clear_screen:
  181.  
  182.     mov    ax,0600h            ;Use DOS scroll to clear CRT
  183.     mov    bh,07                ;Set attribute
  184.     xor    cx,cx                ;Upper left corner 0,0
  185.     mov    dx,184fh            ;Lower right 24,79
  186.     int    10h
  187.     ret                    ;And return
  188.  
  189. write_cursor    endp
  190.  
  191. ;============================================================================
  192. ;Area to get the user password
  193. ;============================================================================
  194.  
  195. input_word    proc    near
  196.  
  197.     call    box                ;Make input display box
  198.     mov    ah,0fh                ;Set attribute for display
  199.     mov    bx,offset msg_1            ;Point to opening mess.
  200.     mov    cx,msg_1_len            ;Set message length
  201.     mov    dx,0d19h            ;Location on CRT
  202.     call    write_crt            ;Display it
  203.     mov    dx,0c27h            ;Address for cursor
  204.     xor    bx,bx                ;Zero bx : Page 0
  205.     call    position_cursor            ;set cursor to entry position
  206.     mov    ax,0c0ah            ;Set up to use DOS buffer
  207.     mov    dx,offset password        ;input routine (point to
  208.                         ;our buffer
  209.     int    DOS                ;Get input string
  210.     call    box                ;Clear the box
  211.     mov    ah,0fh                ;Load attribute
  212.     mov    bx,offset msg_2            ;Point to next message
  213.     mov    cx,msg_2_len            ;Load the length
  214.     mov    dx,0c19h            ;Load where to display it
  215.     call    write_crt            ;Write the display
  216.     xor    cx,cx                ;Zero the count register
  217.     mov    cl,password+1            ;Load # of char entered
  218.     mov    bx,offset password+2        ;Point to the string
  219.     mov    dx,0c27h            ;Address to display
  220.     mov    ah,8fh                ;Load attribute
  221.     call    write_crt            ;Display entered password
  222.                         ;for conformation
  223.     mov    ah,0fh                ;Load attribute
  224.     mov    bx,offset msg_3            ;Point to confirm message
  225.     mov    cx,msg_3_len            ;Length
  226.     mov    dx,0e19h            ;Location for display
  227.     call    write_crt            ;Display message
  228.  
  229. char_loop:
  230.  
  231.     mov    dx,0d33h            ;Location for cursor
  232.     xor    bx,bx                ;Page 0
  233.     call    position_cursor            ;Position cursor for input
  234.                         ;of a Y or N answer
  235.     mov    ah,0ah                ;Write a blank at the cursor
  236.     mov    al,' '                ;to erase a answer that is
  237.     mov    cx,01h                ;not a Y or N
  238.     int    10h
  239.     mov    ah,01h                ;Get one character
  240.     int    DOS
  241.     and    al,5fh                ;Convert to upper case
  242.     cmp    al,'Y'                ;If PASSWORD confirmed then
  243.     je    ok                ;jump to a return
  244.     cmp    al,'N'                ;If not, then ask for new 
  245.     je    input_word            ;password
  246.     mov    ax,0e07h            ;If neither then ring bell
  247.     int    10h                ;and ask for Y or N
  248.     jmp    char_loop
  249.  
  250. ok:    ret                    ;PASSWORD ok.  Set up
  251.                         ;PASSWORD.SYS
  252. input_word    endp
  253. ;============================================================================
  254.  
  255. ;============================================================================
  256. ;This routine draws a box for an entry window
  257. ;============================================================================
  258.  
  259. box    proc    near
  260.  
  261.     mov    ah,04h                ;Set attribute for box
  262.     mov    bx,offset msg_5            ;Point to Upper portion
  263.     mov    cx,34                ;Horizontal Length
  264.     mov    dx,0b17h            ;Start at line 11, col 23
  265.     call    write_crt            ;Draw it
  266.     mov    bx,offset msg_6            ;Middle portion
  267.     mov    cx,34                ;Length
  268.     mov    dx,0c17h            ;Start next at 12 and 23
  269.     call    write_crt            ;Draw it
  270.     mov    cx,34                ;Length
  271.     mov    dx,0d17h            ;Start next at 13 and 23
  272.     call    write_crt            ;Draw it
  273.     mov    cx,34
  274.     mov    dx,0e17h
  275.     call    write_crt
  276.     mov    bx,offset msg_7            ;Bottom portion
  277.     mov    cx,34                ;length
  278.     mov    dx,0f17h            ;Start next at 14 and 23
  279.     call    write_crt            ;Draw it
  280.     ret                    ;And return
  281.  
  282. box    endp
  283.  
  284. ;============================================================================
  285. disk_routines    proc    near
  286. ;============================================================================
  287.  
  288. open_file:                    ;Uses standard DOS function
  289.     mov    ax,3d00h            ;to open the file
  290.     int    DOS                ;PASSWORD.BIN
  291.     jc    error_1            ;Jump if does not exist
  292.     ret
  293.  
  294. close_file:                    ;Uses standard DOS function
  295.     mov    ah,3eh                ;to close files
  296.     int    DOS
  297.     jc    error_2                ;Jump if error in closing
  298.     ret
  299.  
  300. write_file:                    ;Uses standard DOS function
  301.     mov    ah,40h                ;to write buffer to file
  302.     int    DOS
  303.     jc    error_3                ;Jump if error writing
  304.     cmp    ax,cx                ;See if bytes written equal
  305.     jne    disk_full            ;filesize, if not then disk
  306.     ret                    ;is full
  307.  
  308. read_file:                    ;Uses standard DOS function
  309.     mov    ah,3fh                ;to read file
  310.     int    DOS
  311.     jc    error_4                ;Jump if error in reading
  312.     ret
  313.  
  314. create_file:                    ;Uses standard DOS function
  315.     mov    ah,3ch                ;to create a file
  316.     mov    cx,0                ;Set normal attribute
  317.     int    DOS
  318.     jc    error_5                ;Jump if error creating file
  319.     ret
  320.  
  321. error_1:
  322.     call    error_set_up
  323.     mov    dx,offset e_msg_1
  324.     jmp    error_exit
  325.  
  326. error_2:
  327.     call    error_set_up
  328.     mov    dx,offset e_msg_2
  329.     jmp    error_exit
  330.  
  331. error_3:
  332.     call    error_set_up
  333.     mov    dx,offset e_msg_3
  334.     jmp    error_exit
  335.  
  336. error_4:
  337.     call    error_set_up
  338.     mov    dx,offset e_msg_4
  339.     jmp    error_exit
  340.  
  341. error_5:
  342.     call    error_set_up
  343.     mov    dx,offset e_msg_5
  344.     jmp    error_exit
  345.  
  346. disk_full:
  347.     call    error_set_up
  348.     mov    dx,offset e_msg_6
  349.     jmp    error_exit
  350.  
  351. error_exit:
  352.     mov    ah,09h
  353.     int    DOS
  354.     call    off_screen
  355.     mov    ax,4c01h
  356.     int    DOS
  357.  
  358. error_set_up:
  359.  
  360.     call    box
  361.     mov    cx,30
  362.     mov    dx,0c19h
  363.     mov    bx,offset disk_error
  364.     mov    ah,8fh
  365.     call    write_crt
  366.     mov    cx,30
  367.     mov    dx,0d19h
  368.     mov    bx,offset blanks
  369.     call    write_crt
  370.     mov    cx,30
  371.     mov    dx,0e19h
  372.     mov    bx,offset terminate
  373.     call    write_crt
  374.     xor    bx,bx
  375.     mov    dx,0c18h
  376.     call    position_cursor
  377.     ret
  378.  
  379.  
  380. disk_routines    endp
  381. ;============================================================================
  382. ;============================================================================
  383. code    ends        ;End of code segment
  384. ;============================================================================
  385. ;    Program Stack Area
  386. ;============================================================================
  387. st_seg    segment    stack    ; Define Stack Area
  388. ;============================================================================
  389.     db    20 dup    ('Stack   ')
  390. ;============================================================================
  391. st_seg    ends
  392. ;============================================================================
  393. ;    Data Storage areas
  394. ;============================================================================
  395. data    segment        'DATA'        ; Define Data Segment
  396. ;============================================================================
  397.  
  398.  
  399.  
  400. msg_1        db    'Enter Password:',15 dup(20h)    ;Enter Password
  401. msg_1_len    dw    $-msg_1                
  402. msg_2        db    'Password is :                 ';Password Accepted
  403. msg_2_len    dw    $-msg_2
  404. msg_3        db    'Password Correct ?  (Y/N) :   ';Wrong Password
  405. msg_3_len    dw    $-msg_3
  406. msg_4        db    'Password.SYS is complete'    ;Access Denied
  407. msg_4_len    dw    $-msg_4
  408. msg_5        db    201,32 dup(205),187        ;Screen Box
  409. msg_6        db    186,32 dup(20h),186        ;Screen Box
  410. msg_7        db    200,32 dup(205),188        ;Screen Box
  411. blanks        db    '                              '
  412. e_msg_1        db    '        Opening A File$'
  413. e_msg_2        db    '        Closing A File$'
  414. e_msg_3        db    '        Writing A File$'
  415. e_msg_4        db    '        Reading A File$'
  416. e_msg_5        db    '       Creating A File$'
  417. e_msg_6        db    '          Disk Full$'
  418. disk_error    db    '    Disk Error Occurred On    '
  419. terminate    db    '      Program Terminated      '
  420. ;============================================================================
  421. password    db    16,00,16 dup(0)
  422. scramble_count    dw    0
  423. pass_location    dw    0
  424. org_file_name    db    'PASSWORD.BIN',0
  425. new_file_name    db    'PASSWORD.SYS',0
  426. old_handle    dw    0
  427. new_handle    dw    0
  428. video_location    dw    0
  429. file_size    dw    0
  430. ;============================================================================
  431. data    ends
  432. ;============================================================================
  433. ;    File Buffer Area for PASSWORD.BIN
  434. ;============================================================================
  435. file    segment    para    'DATA'
  436. ;============================================================================
  437. file_buffer    db    800h dup(?)
  438. ;============================================================================
  439. file    ends
  440. ;============================================================================
  441.  
  442.     end    start    ;End of assembly
  443.