home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CRYPT19.ZIP / EN_COM.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-08-05  |  5.0 KB  |  149 lines

  1. ;─────────────────────────────────────────────────────────────────────────────
  2. ;                   Black Wolf's File Protection Utilities 2.1s
  3. ;
  4. ;EN_COM - Decryption Code for COM file encryption protection in EncrCOM.
  5. ;         If modified, convert to data bytes and re-instate program into
  6. ;         EncrCOM.ASM, then recompile EncrCOM.
  7. ;      
  8. ;         Basically, this code is attached to a .COM file and, when executed,
  9. ;         decrypts the .COM file and continues execution.
  10. ;
  11. ;LISCENSE:
  12. ;    Released As Freeware - These files may be distributed freely.
  13. ;
  14. ;Any modifications made to this program should be listed below the solid line,
  15. ;along with the name of the programmer and the date the file was changed.
  16. ;Also - they should be commented where changed.
  17. ;
  18. ;NOTE THAT MODIFICATION PRIVILEDGES APPLY ONLY TO THIS VERSION (2.1s)!  
  19. ;I'd appreciate notification of any modifications if at all possible, 
  20. ;reach me through the address listed in the documentation file (bwfpu21s.doc).
  21. ;
  22. ;DISCLAIMER:  The author takes ABSOLUTELY NO RESPONSIBILITY for any damages
  23. ;resulting from the use/misuse of this program/file.  The user agrees to hold
  24. ;the author harmless for any consequences that may occur directly or 
  25. ;indirectly from the use of this program by utilizing this program/file
  26. ;in any manner.
  27. ;─────────────────────────────────────────────────────────────────────────────
  28. ;Modifications:
  29. ;       None as of 08/05/93 - Initial Release.
  30.  
  31. .model tiny
  32. .radix 16
  33. .code
  34.         org 100
  35. start:
  36.         call    Get_Offset
  37. Displaced:
  38.         lea     si,[Decrypt_COM+bp]  
  39.         lea     di,[Get_Offset+bp]   
  40.         mov     cx,(Get_Offset-Decrypt_COM)/2
  41.         cld
  42.         jmp     short EncrLoop      ;EncrLoop here isn't really much of an
  43.         db      0ea                 ;encryption, but disassemblers should
  44.                                     ;love it - it flips the code in memory.
  45.  
  46. EncrLoop:                           ;This part must be stepped through and
  47.         lodsb                       ;re-saved before using the resulting 
  48.         dec     di                  ;.COM as data for EncrCOM, otherwise
  49.         mov     ah,[di]             ;it will simply flip the memory image
  50.         mov     [si-1],ah           ;of the program and crash when run...
  51.         mov     [di],al
  52.         loop    EncrLoop
  53.         cmp     cs:[Counter+bp],4       ;Check if last Anti-debug trick was
  54.         jb      Yip                     ;skipped, if so, mess up user....
  55.         
  56.         sub     word ptr [bp+Decrypt_COM+1],100 ;another prefetch trick...
  57. Decrypt_COM:
  58.         mov     si,100
  59.         mov     di,si
  60.         mov     cx,bp
  61.         shr     cx,1
  62.         inc     cx
  63.  
  64. Decrypt_Loop:                   ;This could be LOTS better....
  65.         lodsw                   ;Suggestions on the algorithm?
  66.         xor     ax,[Key1+bp]
  67.         add     ax,[Key2+bp]
  68.         ror     ax,1
  69.         xor     ax,[Key3+bp]
  70.         sub     ax,[Key4+bp]
  71.         rol     ax,1
  72.         stosw
  73.         loop    Decrypt_Loop
  74.  
  75.         mov     byte ptr [bp+RestoreFile],0c3
  76. RestoreFile:
  77.         mov     di,100
  78.         push    di
  79.         lea     si,bp+Storage_Bytes      ;Restore control to COM.
  80.         movsw
  81.         movsw
  82.  
  83.         mov     ax,[Key1+bp]
  84.         xor     ds:[100h],ax
  85.         mov     ax,[Key2+bp]
  86.         xor     ds:[102h],ax
  87.  
  88.         xor     ax,ax
  89.         call    KillInt3
  90.         mov     si,ax
  91.         mov     di,ax
  92.         jmp     RestoreFile
  93.  
  94.  
  95. Yip:                            ;If you end up here... you messed up.
  96.         push    ax bx cx        
  97.         mov     ax,ss
  98.         mov     bx,sp           ;reverse words in stack - probably end up
  99.         push    ax              ;somewhere in BIOS ROM....
  100.         xchg    bx,ax
  101.         mov     ss,ax
  102.         mov     sp,bx
  103.         pop     ax
  104.         pop     cx bx ax
  105.         mov     byte ptr cs:[Thinker+bp],0c3    ;move a return w/prefetch
  106. Thinker:
  107.         db      0ea,0,0,0ff,0ff ;if they skipped prefetch... reboot cold.
  108.  
  109. ;------------------------------------------------------------------------
  110. Get_Offset:
  111.         pop     bp
  112.         jmp     short confuzzled
  113.         db      0ea
  114. confuzzled:
  115.         push    bp
  116.         sub     bp,offset Displaced
  117.         call    killInt3
  118.         ret
  119.  
  120. Killint3:                       ;Xor first 4 interrupts with 0d00dh...
  121.         push    ax es ds        ;not nice on debuggers if traced....
  122.         xor     ax,ax
  123.         mov     ds,ax
  124.         mov     es,ax
  125.         xor     si,si
  126.         xor     di,di
  127.         mov     cx,8
  128.  
  129. killints:        
  130.         lodsw
  131.         xor     ax,0d00dh
  132.         stosw
  133.         inc     word ptr cs:[Counter+bp]
  134.         loop    killints
  135.  
  136.         pop     ds es ax
  137.         ret
  138.  
  139. Counter dw      0
  140. ;------------------------------------------------------------------------
  141. Storage_Bytes   db      90,90,0cdh,20
  142. Key1            dw      0
  143. Key2            dw      0
  144. Key3            dw      0
  145. Key4            dw      0
  146. ;------------------------------------------------------------------------
  147. end_prog:
  148. end start
  149.