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

  1. ;─────────────────────────────────────────────────────────────────────────────
  2. ;                   Black Wolf's File Protection Utilities 2.1s
  3. ;
  4. ;EncrEXE - This program encrypts specified file and attaches the decryption
  5. ;          code from EN_EXE onto the file so that it will decrypt on
  6. ;          each execution.  It utilizes ULTIMUTE .93ß to protect then EN_EXE
  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, Init_Rand:near
  36.         extrn   Get_Rand:near
  37.  
  38. start:
  39.         call    GetFilename
  40.         call    Init_Rand
  41.         call    Get_Rand
  42.         mov     [Key1],ax
  43.         call    Get_Rand
  44.         mov     [Key2],ax
  45.         call    Get_Rand
  46.         mov     [Key3],ax
  47.         call    Get_Rand
  48.         mov     [Key4],ax
  49.         
  50.         call    Do_File
  51.         mov     ax,4c00
  52.         int     21
  53. ;---------------------------------------------------------------------------
  54. GetFilename:
  55.         mov     ah,09
  56.         mov     dx,offset Message
  57.         int     21
  58.  
  59.         mov     dx,offset Filename_Data
  60.         mov     al,60
  61.         call    gets
  62.         ret
  63. ;---------------------------------------------------------------------------
  64. ;---------------------------------------------------------------------------
  65. Message:
  66.         db      'EncrEXE 2.0 (c) 1993 Black Wolf Enterprises.',0a,0dh
  67.         db      'Enter Filename To Protect -> $'
  68. ;---------------------------------------------------------------------------
  69. gets:
  70.         mov     ah,0a
  71.         push    bx
  72.         mov     bx,dx
  73.         mov     byte ptr ds:[bx],al
  74.         mov     byte ptr ds:[bx+1],0
  75.         pop     bx
  76.         int     21
  77.         push    bx
  78.         mov     bx,dx
  79.         mov     al,byte ptr ds:[bx+1]   
  80.         xor     ah,ah
  81.         add     bx,ax
  82.         mov     byte ptr ds:[bx+2],0
  83.         pop     bx
  84.         ret
  85. ;---------------------------------------------------------------------------
  86. Save_Header:
  87.         mov     ax,word ptr [exeheader+0e]    ;Save old SS
  88.         mov     word ptr [Old_SS],ax
  89.         mov     ax,word ptr [exeheader+10]    ;Save old SP
  90.         mov     word ptr [Old_SP],ax
  91.         mov     ax,word ptr [exeheader+14]    ;Save old IP
  92.         mov     word ptr [Old_IP],ax
  93.         mov     ax,word ptr [exeheader+16]    ;Save old CS
  94.         mov     word ptr [Old_CS],ax
  95.         ret
  96.  
  97. Do_File:        
  98.         mov     ax,3d02
  99.         mov     dx,offset Filename
  100.         int     21
  101.         jnc      Terminate_NOT
  102.         jmp     Terminate
  103. Terminate_NOt:
  104.         xchg    bx,ax
  105.         
  106.         call    GetTime        
  107.         call    BackupFile
  108.  
  109.         mov     ah,3f
  110.         mov     cx,1a
  111.         mov     dx,offset EXEheader
  112.         int     21
  113.  
  114.         cmp     word ptr [EXEheader],'ZM'       ;not EXE file.
  115.         je      IsEXE
  116.         jmp     close_file
  117. IsEXE:
  118.         call    Save_Header
  119.         
  120.         mov     ax,4200
  121.         xor     cx,cx
  122.         xor     dx,dx                   ;Go back to beginning
  123.         int     21
  124.  
  125.         mov     ax,word ptr [EXEheader+08]
  126.         mov     cl,4                            ;convert header to bytes
  127.         shl     ax,cl
  128.  
  129.         mov     word ptr [HeaderSize],ax
  130.  
  131.         mov     cx,ax        
  132.         mov     dx,offset Header                ;Load header
  133.         mov     ah,3f
  134.         int     21
  135.         
  136.         call    Encrypt_Entire_File
  137.         
  138.         mov     ax,4202
  139.         xor     cx,cx                   ;Go end
  140.         xor     dx,dx
  141.         int     21
  142.  
  143.         mov     cl,4
  144.         shr     ax,cl
  145.         inc     ax
  146.         shl     ax,cl
  147.         mov     cx,dx           ;Pad file
  148.         mov     dx,ax
  149.         mov     ax,4200
  150.         int     21
  151.         
  152.         push    ax dx
  153.  
  154.         call    calculate_CSIP          ;calculate starting
  155.                                         ;point.
  156.  
  157.         mov     ah,40
  158.         mov     dx,offset Set_Segs
  159.         mov     cx,end_set_segs-set_segs
  160.         int     21
  161.  
  162.         push    bx        
  163.         mov     si,offset begin_password        ;On Entry -> CS=DS=ES
  164.         mov     di,offset _END_ULTMUTE          ;SI=Source, DI=Destination
  165.         
  166.         mov     bx,word ptr [exeheader+14]       ;BX=Next Entry Point
  167.         add     bx,end_set_segs-set_segs
  168.  
  169.         mov     cx,end_password-begin_password+1 ;CX=Size to Encrypt
  170.         add     cx,word ptr [headersize]         ;add in EXE header
  171.  
  172.         mov     ax,1                             ;AX=Calling Style
  173.         call    _ULTMUTE                
  174.                                                 ;On Return -> CX=New Size
  175.  
  176.         pop     bx
  177.         pop     dx ax                   ;DX:AX = unmodified
  178.                                         ;file size.
  179.         
  180.         push    cx bx
  181.         add     cx,end_set_segs-set_segs
  182.         call    calculate_size
  183.         pop     bx cx
  184.  
  185.         mov     dx,offset _END_ULTMUTE
  186.         mov     ah,40
  187.         int     21
  188.         
  189.         mov     ax,4200
  190.         xor     dx,dx
  191.         xor     cx,cx
  192.         int     21
  193.         
  194.         mov     ah,40
  195.         mov     cx,1a
  196.         mov     dx,offset EXEheader
  197.         int     21
  198.  
  199.         mov     cx,word ptr [headersize]        
  200.         sub     cx,1a
  201.         jz      Close_File
  202.  
  203. Zero_Header:
  204.         push    cx
  205.         mov     ah,40
  206.         mov     cx,1
  207.         mov     dx,offset zero
  208.         int     21
  209.         pop     cx
  210.         loop    Zero_Header
  211.         
  212. Close_File:
  213.         mov     ax,5701
  214.         mov     cx,word ptr cs:[Time]
  215.         mov     dx,word ptr cs:[Date]   ;restore date/time
  216.         int     21 
  217.  
  218.         mov     ah,3e
  219.         int     21
  220.         ret
  221.  
  222. GetTime:
  223.         mov     ax,5700
  224.         int     21
  225.         mov     word ptr cs:[Time],cx
  226.         mov     word ptr cs:[Date],dx
  227.         ret
  228.  
  229. Time    dw      0
  230. Date    dw      0
  231.  
  232. Terminate:
  233.         mov     ah,09
  234.         mov     dx,offset BadFile
  235.         int     21
  236.         ret
  237. BadFile db      'Error Opening File.',07,0dh,0a,24
  238. zero    db      0,0
  239. calculate_CSIP:
  240.         push    ax
  241.         mov     cl,4 
  242.         mov     ax,word ptr [exeheader+8]       ;Get header length
  243.                                                 ;and convert it to
  244.         shl     ax,cl                           ;bytes.
  245.         mov     cx,ax
  246.         pop     ax
  247.  
  248.         sub     ax,cx                           ;Subtract header
  249.         sbb     dx,0                            ;size from file
  250.                                                 ;size for memory
  251.                                                 ;adjustments
  252.  
  253.         mov     cl,0c                           ;Convert DX into
  254.         shl     dx,cl                           ;segment Address
  255.         mov     cl,4
  256.         push    ax                      ;Change offset (AX) into
  257.         shr     ax,cl                   ;segment, except for last
  258.         add     dx,ax                   ;digit.  Add to DX and
  259.         shl     ax,cl                   ;save DX as new CS, put
  260.         pop     cx                      ;left over into CX and
  261.         sub     cx,ax                   ;store as the new IP.
  262.         mov     word ptr [exeheader+16],dx    ;Set new CS:IP
  263.         mov     word ptr [exeheader+10],0fffe ;Set new SP
  264.         mov     word ptr [exeheader+0e],dx    ;Set new SS = CS
  265.         mov     word ptr [exeheader+14],cx
  266.         mov     word ptr [exeheader+6],0        ;Set 0 relocation items.
  267.         ret
  268.  
  269. calculate_size:
  270.         add     ax,cx                   ;Add virus size to DX:AX
  271.         adc     dx,0
  272.         
  273.         push    ax                      ;Save offset for later
  274.         mov     cl,7
  275.         shl     dx,cl                   ;convert DX to pages
  276.         mov     cl,9
  277.         shr     ax,cl
  278.         add     ax,dx
  279.         inc     ax
  280.         mov     word ptr [exeheader+04],ax  ;save # of pages
  281.  
  282.         pop     ax                              ;Get offset
  283.         mov     dx,ax
  284.         shr     ax,cl                           ;Calc remainder
  285.         shl     ax,cl                           ;in last page
  286.         sub     dx,ax
  287.         mov     word ptr [exeheader+02],dx ;save remainder
  288.         ret
  289.  
  290. Set_Segs:
  291.         push    es ds
  292.         push    cs cs
  293.         pop     es ds
  294.  End_Set_Segs:
  295.  
  296. Encrypt_Entire_File:
  297.         mov     ah,3f        
  298.         mov     cx,400
  299.         mov     dx,offset Encrypt_Buffer                ;Read in buffer full
  300.         int     21
  301.  
  302.         or      ax,ax
  303.         jz      Add_Protection_Code                     ;None left? leave...
  304.         
  305.         push    ax
  306.         call    EncryptBytes                            ;Encrypt buffer
  307.         pop     ax
  308.         push    ax
  309.  
  310.         xor     dx,dx
  311.         sub     dx,ax
  312.         mov     cx,0ffff                                ;Go back to where we
  313.         mov     ax,4201                                 ;read from
  314.         int     21
  315.  
  316.         mov     ah,40
  317.         pop     cx
  318.         mov     dx,offset Encrypt_Buffer                ;Write it back
  319.         int     21
  320.  
  321.         cmp     ax,400                                  ;Buffer full? loop...
  322.         je      Encrypt_Entire_File
  323. Add_Protection_Code:
  324.         ret
  325.  
  326. EncryptBytes:                           ;This algorithm needs help....
  327.         push    ax bx cx dx si di
  328.         
  329.         mov     si,offset Encrypt_Buffer
  330.         mov     di,si
  331.         mov     cx,200
  332.  
  333. Decrypt_Loop:        
  334.         lodsw
  335.         ror     ax,1
  336.         add     ax,[Key4]
  337.         xor     ax,[Key3]
  338.         rol     ax,1
  339.         sub     ax,[Key2]
  340.         xor     ax,[Key1]
  341.  
  342.         
  343.         stosw
  344.         loop    Decrypt_Loop
  345.         
  346.         pop     di si dx cx bx ax
  347.         ret
  348.                 dw      0
  349.                 dw      0
  350. Filename_data   dw      0
  351. Filename        db      80 dup(0)
  352. Exeheader       db      1a dup(0)
  353. Encrypt_Buffer  dw      400 dup(0)
  354. HeaderSize      dw      0
  355.  
  356.  
  357. BackupFile:
  358.         mov     si,offset Filename
  359.         mov     cx,80
  360.  
  361.   Find_Eofn:
  362.         lodsb
  363.         cmp     al,'.'
  364.         je      FoundDot
  365.         or      al,al
  366.         jz      FoundZero
  367.         loop    Find_Eofn
  368.         jmp     Terminate
  369. FoundZero:
  370.         mov     byte ptr [si-1],'.'
  371.         inc     si
  372. FoundDot:
  373.         mov     word ptr [si],'LO'
  374.         mov     byte ptr [si+2],'D'
  375.         mov     byte ptr [si+3],0
  376.  
  377.         
  378.         mov     dx,offset Filename
  379.         mov     word ptr [SourceF],bx
  380.         mov     ah,3c
  381.         xor     cx,cx
  382.         int     21
  383.         jnc     GCreate
  384.          jmp    Terminate
  385. GCreate:
  386.         mov     word ptr cs:[Destf],ax
  387. BackLoop:
  388.         mov     ah,3f
  389.         mov     bx,word ptr cs:[Sourcef]
  390.         mov     cx,400
  391.         mov     dx,offset Encrypt_Buffer
  392.         int     21
  393.  
  394.         mov     cx,ax
  395.         mov     ah,40
  396.         mov     bx,word ptr cs:[Destf]
  397.         mov     dx,offset Encrypt_Buffer
  398.         int     21
  399.  
  400.         cmp     ax,400
  401.         je      BackLoop
  402. DoneBack:
  403.         mov     ah,3e
  404.         mov     bx,word ptr cs:[Destf]
  405.         int     21
  406.  
  407.         mov     ax,4200
  408.         xor     cx,cx
  409.         xor     dx,dx
  410.         mov     bx,word ptr cs:[Sourcef]
  411.         int     21
  412.         ret
  413.  
  414. SourceF dw      0
  415. DestF   dw      0
  416.  
  417.  
  418. begin_password:         ;code from en_exe
  419. ;------------------------------------------------------------------------
  420. db 0e8h, 02dh, 01h, 058h, 050h, 02eh, 089h, 086h, 076h, 02h
  421. db 02eh, 089h, 086h, 0fh, 01h, 033h, 0dbh, 05h, 010h, 00h
  422. db 08ch, 0c9h, 02bh, 0c8h, 0d1h, 0e1h, 083h, 0d3h, 00h, 0ebh
  423. db 0ch, 090h, 0eah, 0d1h, 0e3h, 0d1h, 0e1h, 083h, 0d3h, 00h
  424. db 0ebh, 0bh, 0ffh, 0d1h, 0e3h, 0d1h, 0e1h, 083h, 0d3h, 00h
  425. db 0ebh, 0edh, 09ah, 08eh, 0c0h, 08eh, 0d8h, 033h, 0f6h, 033h
  426. db 0ffh, 0e8h, 0fbh, 00h, 0ebh, 01h, 0eah, 0adh, 033h, 086h
  427. db 080h, 02h, 03h, 086h, 082h, 02h, 0d1h, 0c8h, 033h, 086h
  428. db 084h, 02h, 02bh, 086h, 086h, 02h, 0d1h, 0c0h, 0abh, 053h
  429. db 051h, 08bh, 0c6h, 08bh, 0d8h, 0b1h, 04h, 0d3h, 0e8h, 0d3h
  430. db 0e0h, 03bh, 0c3h, 075h, 0dh, 083h, 0eeh, 010h, 083h, 0efh
  431. db 010h, 01eh, 058h, 040h, 08eh, 0d8h, 08eh, 0c0h, 059h, 05bh
  432. db 0e2h, 0c9h, 083h, 0fbh, 00h, 074h, 06h, 04bh, 0ebh, 0c1h
  433. db 0e8h, 0b6h, 00h, 050h, 01eh, 033h, 0c0h, 08eh, 0d8h, 08dh
  434. db 086h, 0d5h, 01h, 087h, 06h, 00h, 00h, 050h, 08ch, 0c8h
  435. db 087h, 06h, 02h, 00h, 050h, 033h, 0c9h, 02eh, 0c7h, 086h
  436. db 0a4h, 01h, 090h, 090h, 0f7h, 0f1h, 058h, 087h, 06h, 02h
  437. db 00h, 058h, 087h, 06h, 00h, 00h, 01fh, 058h, 07h, 01fh
  438. db 02eh, 08bh, 086h, 076h, 02h, 05h, 010h, 00h, 02eh, 03h
  439. db 086h, 07ch, 02h, 0fah, 08eh, 0d0h, 02eh, 08bh, 0a6h, 07eh
  440. db 02h, 0fbh, 033h, 0c0h, 08bh, 0f0h, 08bh, 0f8h, 02eh, 0ffh
  441. db 0aeh, 078h, 02h, 02eh, 08bh, 086h, 076h, 02h, 05h, 010h
  442. db 00h, 02eh, 01h, 086h, 07ah, 02h, 0e8h, 01h, 00h, 0cfh
  443. db 050h, 053h, 051h, 052h, 06h, 01eh, 056h, 057h, 055h, 08bh
  444. db 0ddh, 02eh, 08bh, 0afh, 0a0h, 02h, 02eh, 08bh, 08fh, 08eh
  445. db 02h, 0bh, 0c9h, 074h, 027h, 03h, 0ebh, 02eh, 0c5h, 0b6h
  446. db 088h, 02h, 02bh, 0ebh, 08ch, 0d8h, 02eh, 03h, 087h, 076h
  447. db 02h, 05h, 010h, 00h, 08eh, 0d8h, 02eh, 08bh, 087h, 076h
  448. db 02h, 05h, 010h, 00h, 01h, 04h, 083h, 0c5h, 04h, 0e8h
  449. db 017h, 00h, 0e2h, 0d9h, 05dh, 05fh, 05eh, 01fh, 07h, 05ah
  450. db 059h, 05bh, 058h, 0c3h, 05dh, 0ebh, 01h, 0eah, 055h, 081h
  451. db 0edh, 03h, 01h, 0c3h, 0c3h, 0ebh, 014h, 090h, 0eah, 0e8h
  452. db 02ch, 00h, 0ebh, 06h, 090h, 0e8h, 026h, 00h, 0ebh, 0f5h
  453. db 0bh, 0edh, 074h, 0f7h, 05dh, 0ebh, 0e9h, 055h, 033h, 0edh
  454. db 0ebh, 0efh, 050h, 072h, 06fh, 074h, 065h, 063h, 074h, 069h
  455. db 06fh, 06eh, 020h, 062h, 079h, 020h, 042h, 06ch, 061h, 063h
  456. db 06bh, 020h, 057h, 06fh, 06ch, 066h, 0e4h, 021h, 034h, 02h
  457. db 0e6h, 021h, 045h, 0c3h, 00h, 00h
  458. ;------------------------------------------------------------------------
  459. Old_IP  dw      0
  460. Old_CS  dw      0fff0
  461. Old_SS  dw      0fff0
  462. Old_SP  dw      0
  463. Key1    dw      0
  464. Key2    dw      0
  465. Key3    dw      0
  466. Key4    dw      0
  467. ;------------------------------------------------------------------------
  468. end_password:
  469. Header:
  470.         db     800 dup(0)       ;leave space for ultimute with db (0)'s
  471. end start
  472.