home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Rising BBS / phoenixrising.zip / phoenixrising / vir-docs / crptlt19.arj / PASSCOM.ASM < prev    next >
Assembly Source File  |  1993-08-05  |  13KB  |  402 lines

  1. ;─────────────────────────────────────────────────────────────────────────────
  2. ;                   Black Wolf's File Protection Utilities 2.1s
  3. ;
  4. ;PassCOM - This program password protects the specified file by attaching
  5. ;          code from PW_COM onto the file so that it will check for passwords
  6. ;          each execution.  It utilizes ULTIMUTE .93ß to protect then PW_COM
  7. ;          code from easy manipulation.
  8. ;
  9. ;LISCENSE:
  10. ;    Released As Freeware - These files may be distributed freely.
  11. ;
  12. ;Any modifications made to this program should be listed below the solid line,
  13. ;along with the name of the programmer and the date the file was changed.
  14. ;Also - they should be commented where changed.
  15. ;
  16. ;NOTE THAT MODIFICATION PRIVILEDGES APPLY ONLY TO THIS VERSION (2.1s)!  
  17. ;I'd appreciate notification of any modifications if at all possible, 
  18. ;reach me through the address listed in the documentation file (bwfpu21s.doc).
  19. ;
  20. ;DISCLAIMER:  The author takes ABSOLUTELY NO RESPONSIBILITY for any damages
  21. ;resulting from the use/misuse of this program/file.  The user agrees to hold
  22. ;the author harmless for any consequences that may occur directly or 
  23. ;indirectly from the use of this program by utilizing this program/file
  24. ;in any manner.
  25. ;─────────────────────────────────────────────────────────────────────────────
  26. ;Modifications:
  27. ;       None as of 08/05/93 - Initial Release.
  28.  
  29. .model tiny
  30. .radix 16
  31. .code
  32.        
  33.        org 100
  34.  
  35.         extrn   _ULTMUTE:near, _END_ULTMUTE:byte
  36.  
  37. start:
  38.         call    GetFilename
  39.         call    Get_Passes
  40.         call    EncryptGP
  41.         call    Do_File
  42.         mov     ax,4c00
  43.         int     21
  44. ;---------------------------------------------------------------------------
  45. GetFilename:
  46.         mov     ah,09
  47.         mov     dx,offset Message
  48.         int     21
  49.  
  50.         mov     dx,offset Filename_Data
  51.         mov     al,60
  52.         call    gets
  53.         ret
  54. ;---------------------------------------------------------------------------
  55. Get_Passes:
  56.     Clear_Out_Passes:        
  57.         mov     di,offset Entered_Pass
  58.         mov     cx,0ch                   ;Clear out entered pass.
  59.         xor     ax,ax
  60.         repnz   stosb
  61.         mov     di,offset Password
  62.         mov     cx,0ch                   ;Clear out entered pass.
  63.         xor     ax,ax
  64.         repnz   stosb
  65.         
  66.         mov     ah,09
  67.         mov     dx,offset Req_Pass
  68.         int     21
  69.  
  70.         mov     di,offset Entered_Pass
  71.         mov     cx,0ch
  72.         call    GetPass
  73.  
  74.         mov     ah,09
  75.         mov     dx, offset Dup_Pass
  76.         int     21
  77.  
  78.         mov     di,offset Password
  79.         mov     cx,0ch
  80.         call    GetPass
  81.         
  82.         call    Check_Passwords
  83.         jc      Get_Passes
  84.         
  85.         mov     di,offset Entered_Pass
  86.         mov     cx,0dh                   ;Clear out entered pass.
  87.         xor     ax,ax
  88.         repnz   stosb
  89.  
  90. Randomize_Keys:
  91.         push    ds
  92.         xor     ax,ax
  93.         mov     ds,ax
  94.         mov     ax,word ptr ds:[46c]    ;Randomizes encryption
  95.         pop     ds
  96.         mov     word ptr [Key1],ax
  97.         xor     ax,1f3eh
  98.         ror     ax,1
  99.         mov     word ptr [Key2],ax
  100.         
  101.  
  102.  
  103. Encrypt_Password:                       ;This algorithm needs extra work...
  104.         mov     bx,word ptr [Key1]
  105.         mov     dx,word ptr [Key2]      ;Encrypt the password
  106.         mov     si,offset Password
  107.         mov     di,si
  108.         mov     cx,6
  109.   EncryptIt:      
  110.         lodsw
  111.         xor     ax,bx
  112.         add     bx,dx
  113.         stosw
  114.         loop    EncryptIt
  115.         ret
  116. ;---------------------------------------------------------------------------
  117. Message:
  118.         db      'PassCOM 2.0 (c) 1993 Black Wolf Enterprises.',0a,0dh
  119.         db      'Enter Filename To Protect -> $'
  120. ;---------------------------------------------------------------------------
  121. Req_Pass        db      0a,0dh,'Now Enter Password (up to 12 chars): $'
  122. Dup_Pass        db      0a,0dh,'Re-Enter Password: $'
  123. Passes_Not      db      0a,0dh,'Passwords do not match.  Try again.',0a,0dh,24
  124. ;---------------------------------------------------------------------------
  125. Check_Passwords:
  126.         mov     si,offset Entered_Pass
  127.         mov     di,offset Password
  128.         mov     cx,0c
  129.         repz    cmpsb
  130.         jcxz    Password_Good
  131.         stc
  132.         ret
  133. Password_Good:
  134.         clc
  135.         ret
  136. ;---------------------------------------------------------------------------
  137.  
  138.  
  139. gets:                   ;get string
  140.         mov     ah,0a
  141.         push    bx
  142.         mov     bx,dx
  143.         mov     byte ptr ds:[bx],al
  144.         mov     byte ptr ds:[bx+1],0
  145.         pop     bx
  146.         int     21
  147.         push    bx
  148.         mov     bx,dx
  149.         mov     al,byte ptr ds:[bx+1]
  150.         xor     ah,ah
  151.         add     bx,ax
  152.         mov     byte ptr ds:[bx+2],0
  153.         pop     bx
  154.         ret
  155. ;---------------------------------------------------------------------------
  156. GetPass:
  157.   KeyHit_Loop:          ;Load in password
  158.         push    cx
  159.         sub     ax,ax
  160.         int     16
  161.         cmp     al,0dh
  162.         je      HitReturn
  163.         stosb
  164.         pop     cx
  165.         loop    KeyHit_Loop
  166.         ret
  167.   HitReturn:
  168.         pop     cx
  169.         xor     al,al
  170.         repnz   stosb
  171.         ret        
  172.  
  173.  
  174. ;---------------------------------------------------------------------------
  175. Time    dw      0
  176. Date    dw      0
  177.  
  178. GetTime:
  179.         mov     ax,5700 ;Get file date/time from handle BX
  180.         int     21
  181.         mov     word ptr cs:[Time],cx
  182.         mov     word ptr cs:[Date],dx
  183.         ret
  184.  
  185. SetTime:                ;Set file date/time for handle BX
  186.         mov     ax,5701
  187.         mov     cx,word ptr cs:[Time]
  188.         mov     dx,word ptr cs:[Date]
  189.         int     21
  190.         ret
  191.  
  192. Do_File:        
  193.         mov     ax,3d02
  194.         mov     dx,offset Filename
  195.         int     21                      ;Open file read/write
  196.         jc      Terminate
  197.         xchg    bx,ax
  198.  
  199.         call    GetTime                 ;Get file date/time
  200.         call    BackupFile              ;make a copy....
  201.         
  202.         mov     ah,3f
  203.         mov     cx,4
  204.         mov     dx,offset Storage_Bytes ;Read in first four bytes for jump
  205.         int     21
  206.  
  207.         mov     ax,4202
  208.         xor     cx,cx
  209.         xor     dx,dx                   ;go to the end of the file
  210.         int     21
  211.  
  212.         sub     ax,3
  213.         mov     word ptr [JumpBytes+1],ax ;Save Jump size
  214.         
  215.         push    bx        
  216.         mov     si,offset begin_password        ;On Entry -> CS=DS=ES
  217.         mov     di,offset _END_ULTMUTE          ;SI=Source, DI=Destination
  218.         mov     bx,ax                           ;BX=Next Entry Point
  219.         add     bx,103
  220.         mov     cx,end_password-begin_password+1 ;CX=Size to Encrypt
  221.         mov     ax,1                             ;AX=Calling Style
  222.         
  223.         call    _ULTMUTE                        ;Encrypt Code
  224.                                                 
  225.                                                 ;On Return -> CX=New Size
  226.         pop     bx
  227.         
  228.         mov     dx,offset _END_ULTMUTE
  229.         mov     ah,40                           ;Write encrypted code and
  230.         int     21                              ;decryptor to end of file
  231.         
  232.         mov     ax,4200
  233.         xor     dx,dx                           ;Go back to beginning of file
  234.         xor     cx,cx
  235.         int     21
  236.         
  237.         mov     ah,40
  238.         mov     cx,4
  239.         mov     dx,offset JumpBytes             ;Write in jump to decryptor
  240.         int     21
  241.         
  242.         call    SetTime                         ;Restore file date/time
  243.  
  244.         mov     ah,3e
  245.         int     21                              ;close file
  246.         ret
  247.  
  248. Terminate:
  249.         mov     ah,09
  250.         mov     dx,offset BadFile
  251.         int     21
  252.         ret
  253. BadFile db      'Error Opening File.',07,0dh,0a,24
  254.  
  255. JumpBytes       db      0e9,0,0,'ß'
  256.  
  257. EncryptGP:                              ;Encrypt GoodPass routine in pw_com
  258.         xor     ax,ax                   ;with value from password itself...
  259.         mov     cx,0c
  260.         mov     si,offset Password
  261.  
  262. GetValue:        
  263.         lodsb
  264.         add     ah,al
  265.         ror     ah,1                    ;Get value to use for encrypt...
  266.         loop    GetValue
  267.  
  268.         mov     si,offset Goodpass
  269.         mov     cx,EndGoodPass-GoodPass
  270.        
  271. Decrypt_Restore:                ;This needs improvement....
  272.         mov     al,[si]
  273.         xor     al,ah
  274.         mov     [si],al
  275.         inc     si
  276.         loop    Decrypt_Restore
  277.         ret        
  278.  
  279. BackupFile:                             ;Create copy of file...
  280.         mov     si,offset Filename
  281.         mov     cx,80
  282.  
  283.   Find_Eofn:
  284.         lodsb
  285.         cmp     al,'.'          ;Find file extension
  286.         je      FoundDot
  287.         or      al,al
  288.         jz      FoundZero
  289.         loop    Find_Eofn
  290.         jmp     Terminate
  291. FoundZero:
  292.         mov     byte ptr [si-1],'.'
  293.         inc     si
  294. FoundDot:
  295.         mov     word ptr [si],'LO'
  296.         mov     byte ptr [si+2],'D'     ;Change extension to 'OLD'
  297.         mov     byte ptr [si+3],0
  298.  
  299.         
  300.         mov     dx,offset Filename
  301.         mov     word ptr [SourceF],bx
  302.         mov     ah,3c
  303.         xor     cx,cx
  304.         int     21
  305.         jnc     GCreate
  306.          jmp    Terminate
  307. GCreate:
  308.         mov     word ptr cs:[Destf],ax
  309. BackLoop:
  310.         mov     ah,3f
  311.         mov     bx,word ptr cs:[Sourcef]
  312.         mov     cx,400
  313.         mov     dx,offset FileBuffer            ;Copy file to backup
  314.         int     21
  315.  
  316.         mov     cx,ax
  317.         mov     ah,40
  318.         mov     bx,word ptr cs:[Destf]
  319.         mov     dx,offset Filebuffer
  320.         int     21
  321.  
  322.         cmp     ax,400
  323.         je      BackLoop
  324. DoneBack:
  325.         mov     bx,word ptr cs:[Destf]
  326.         call    SetTime                 ;Save original date/time stamp in 
  327.                                         ;backup
  328.         mov     ah,3e
  329.         mov     bx,word ptr cs:[Destf]
  330.         int     21                      ;Close file
  331.  
  332.         mov     ax,4200
  333.         xor     cx,cx
  334.         xor     dx,dx
  335.         mov     bx,word ptr cs:[Sourcef] ;Go back to the beginning of the
  336.         int     21                       ;source file
  337.         ret
  338.  
  339. SourceF dw      0
  340. DestF   dw      0
  341.  
  342.         ;This is code from PW_COM compiled converted to data bytes..
  343.         ;If you modify PW_COM, you must compile it and convert it, then
  344.         ;place it here.  Note that the byte 0ffh marks the beginning and
  345.         ;end of Goodpass for simplicity....
  346.  
  347. begin_password: 
  348. db 0e8h, 02dh, 01h, 02eh, 0c6h, 086h, 09h, 01h, 0eah, 0ebh
  349. db 06h, 00h, 0ebh, 011h, 090h, 0adh, 0deh, 0bbh, 021h, 01h
  350. db 03h, 0ddh, 053h, 02eh, 0c6h, 086h, 011h, 01h, 0c3h, 0ebh
  351. db 0edh, 0ebh, 0f0h, 0fah, 050h, 01eh, 033h, 0c0h, 08eh, 0d8h
  352. db 08dh, 086h, 01ch, 02h, 087h, 06h, 00h, 00h, 050h, 08ch
  353. db 0c8h, 087h, 06h, 02h, 00h, 050h, 01eh, 0eh, 01fh, 02eh
  354. db 0c7h, 086h, 044h, 01h, 090h, 090h, 033h, 0c9h, 0f7h, 0f1h
  355. db 01fh, 058h, 087h, 06h, 02h, 00h, 058h, 087h, 06h, 00h
  356. db 00h, 01fh, 058h, 0fbh, 0e8h, 0aah, 00h, 02eh, 080h, 086h
  357. db 05eh, 01h, 010h, 0ebh, 03h, 090h, 0eah, 09ah, 0e8h, 081h
  358. db 00h, 0e8h, 069h, 00h, 072h, 038h, 033h, 0c0h, 0b9h, 0ch
  359. db 00h, 08dh, 0b6h, 04eh, 02h, 0ach, 02h, 0e0h, 0d0h, 0cch
  360. db 0e2h, 0f9h, 08dh, 0b6h, 090h, 01h, 0b9h, 011h, 00h, 08ah
  361. db 04h, 032h, 0c4h, 088h, 04h, 046h, 0e2h, 0f7h, 0e8h, 039h
  362. db 00h, 0ebh, 01h, 0ffh 
  363.  
  364. GoodPass:
  365. db 0bfh, 00h, 01h, 057h, 08dh, 0b6h
  366. db 03eh, 02h, 0a5h, 0a5h, 033h, 0c0h, 08bh, 0f0h, 08bh, 0f8h
  367. db 0c3h 
  368. EndGoodPass:
  369.  
  370. db 0ffh, 0b4h, 09h, 08dh, 096h, 0afh, 01h, 0cdh, 021h
  371. db 0b8h, 01h, 04ch, 0cdh, 021h, 0ah, 0dh, 050h, 061h, 073h
  372. db 073h, 077h, 06fh, 072h, 064h, 020h, 049h, 06eh, 063h, 06fh
  373. db 072h, 072h, 065h, 063h, 074h, 02eh, 07h, 024h, 090h, 0ebh
  374. db 05h, 090h, 0eah, 0f8h, 0c3h, 09ah, 0fch, 0ebh, 0fah, 08dh
  375. db 0b6h, 04eh, 02h, 08dh, 0beh, 042h, 02h, 0b9h, 0ch, 00h
  376. db 0f3h, 0a6h, 0e3h, 03h, 0f9h, 0c3h, 0e9h, 0f8h, 0c3h, 00h
  377. db 08bh, 09eh, 03ah, 02h, 08bh, 096h, 03ch, 02h, 08dh, 0b6h
  378. db 04eh, 02h, 08bh, 0feh, 0b9h, 06h, 00h, 0adh, 033h, 0c3h
  379. db 03h, 0dah, 0abh, 0e2h, 0f8h, 0c3h, 0eah, 0b9h, 0ch, 00h
  380. db 08dh, 0beh, 04eh, 02h, 051h, 02bh, 0c0h, 0cdh, 016h, 03ch
  381. db 0dh, 074h, 05h, 0aah, 059h, 0e2h, 0f3h, 0c3h, 059h, 032h
  382. db 0c0h, 0f2h, 0aah, 0c3h, 0b4h, 09h, 08dh, 096h, 025h, 02h
  383. db 0cdh, 021h, 0cfh, 050h, 061h, 073h, 073h, 077h, 06fh, 072h
  384. db 064h, 02dh, 03eh, 024h, 05dh, 0ebh, 01h, 0eah, 055h, 081h
  385. db 0edh, 03h, 01h, 0c3h
  386. ;------------------------------------------------------------------------
  387. Key1            dw      0
  388. Key2            dw      0
  389. ;------------------------------------------------------------------------
  390. Storage_Bytes   db      90,90,0cdh,20
  391. ;------------------------------------------------------------------------
  392. Password        db      'Greetings to'
  393. Entered_Pass    db      'everyone!   '
  394. db      0,0,0,0,0,0,0
  395. end_password:
  396.                 dw      0
  397.                 dw      0
  398. Filename_data   dw      0
  399. Filename        db      80 dup(0)       ;These are stored as zeros to 
  400. FileBuffer      db      400 dup(0)      ;keep from overwriting ultimute...
  401. end start
  402.