home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Quantico / km / terminat.asm.txt < prev    next >
Encoding:
Text File  |  2000-05-25  |  19.4 KB  |  473 lines

  1. ; Started:  June 10, 1998
  2. ; Finished: June 13, 1998
  3. ;
  4. ;                        ╔═─────────────────────────────═╗
  5. ;                        │     Terminate 5.00 ∙kEYGEN∙   │
  6. ;                        │ Crack By Q [PhRoZeN CReW '98] │
  7. ;                        │        -1999 Strainer-        │
  8. ;                        ╚═─────────────────────────────═╝
  9.  
  10. Comment %
  11.  Use Tasm 16 bit compiler (Ver 2.0+) , to compiler to a 16bit COM file.
  12.    tasm keygen.asm
  13.    tlink /t keygen.obj
  14.  
  15.  I use COM instead of EXE because i will use the HEAP.
  16.  COM files are memory images,each COM file gets 1 segment (64kb) of memory
  17.  when loaded (so CS=DS=ES=SS). The image is loaded to cs:100h , and the stack
  18.  pointer points to the end of the segment (FFFFh) beacase SP is decreasing
  19.  when values are PUSHed to the stack. Even if ur file is less than 64kb, u
  20.  still have the whole segment allocated . The memory left from the END of the
  21.  image to the start of the stack is called HEAP. So if u have small COMs
  22.  (=small image) ,u have a rather large chank of memory to play with - the Heap.
  23.  
  24.  In exe , or the other hand , u need to ask DOS to allocate memroy as buffer.
  25.  (Int 21h/Ah=48h). This keygen is a small program, so we'll use COM.
  26.  
  27.  last notes: the code here is NOT optimized due to the simple reason - to be
  28.              readable. Many CODE and Data buffers are not nessercery , but
  29.              I used it anyway,to make the source more readable.
  30.  *(Much) More info in the essay..
  31.  That's it .. Enjoy .. :)
  32.         %
  33.  
  34. Code Segment Byte Public
  35. Assume   Ds:Code,Cs:Code
  36. Org  100h
  37.  
  38. Start: JMP Main
  39.  
  40. ;/--──────══════════════════════════════════════════════════───────---\
  41. ;                             Program Data
  42. ;\--──────══════════════════════════════════════════════════───────---/
  43.  
  44. Logo DB 9,9,"    ╔═─────────────────────────────═╗",10,13
  45.      DB 9,9,"    │     Terminate 5.00 ∙kEYGEN∙   │",10,13
  46.      DB 9,9,"    │ Crack By Q [PhRoZeN CReW '98] │",10,13
  47.      DB 9,9,"    │        -1999 Strainer-        │",10,13
  48.      DB 9,9,"    ╚═─────────────────────────────═╝",10,13,10,13
  49.      DB "■ 50 chars top for each of the following fields.",10,13,10,13
  50.      DB "   Name :    ",50 dup('_'), 10,13
  51.      DB "   Address : ",50 dup('_'), 10,13
  52.      DB "   Country : ",50 dup('_'), 10,13
  53.      DB "   Phone :   ",50 dup('_'),  '$'
  54. LineNumber  DB 0
  55.  
  56. File_Name   DB "terminat.key",0
  57. Fill_String DB "cRACK bY Q - 1999 +HCU Strainer -",10,13
  58. FString_tag DB 0
  59.  
  60. End_message DB 10,13,10,13," ■ Terminate kEYFILE created. Copy it to the main terminate directory."
  61.             DB 10,13,10,13," EnJoY! $"
  62.  
  63. Counter1 DW 0                   ;Holds the Block number in CRC procedure
  64. Counter2 DW 0                   ;Holds the OFFSET in the block , currently
  65.                                 ;in CRC procedure .
  66. CRC     DW 0,0                  ;CRC = 32 bit kEY.
  67.  
  68. Input_string  DB 51,53 dup(0)
  69.  
  70. Master_Encrypt_Table DB 070h,040h,001h,0DFh,0D6h,07Ch,079h,020h,065h,0DCh,072h,009h,098h,08Ah,001h,086h
  71.                      DB 010h,090h,0E2h,072h,015h,015h,07Fh,0B3h,038h,027h,086h,043h,002h,029h,0CBh,07Ah
  72.                      DB 037h,094h,0ECh,0B6h,08Bh,052h,08Bh,0D1h,086h,092h,0D6h,013h,007h,055h,0B5h,072h
  73.                      DB 059h,05Ch,030h,055h,008h,082h,0A3h,00Eh,0EFh,024h,039h,0F1h,075h,0AEh,034h,06Ch
  74.                      DB 007h,08Ah,07Dh,026h,08Ch,0C3h,031h,0B8h,04Fh,057h,0BFh,052h,061h,0BBh,0EDh,0A3h
  75.                      DB 019h,042h,0E6h,086h,090h,0B7h,08Dh,0BFh,06Ch,0C2h,0CFh,070h,062h,0B6h,076h,06Dh
  76.                      DB 0E0h,03Dh,0F8h,07Eh,0CDh,0FEh,0C9h,0E0h,064h,0DAh,039h,02Bh,00Ah,02Eh,0A0h,027h
  77.                      DB 09Dh,06Eh,054h,0DAh,08Eh,0FFh,014h,062h,01Ch,0FEh,03Ch,022h,0DFh,0C2h,0E5h,09Fh
  78.                      DB 026h,0DAh,099h,0A8h,03Bh,0DBh,0B9h,080h,03Ah,0FDh,0CDh,0E9h,034h,03Fh,09Eh,000h
  79.                      DB 076h,0B5h,018h,077h,0A2h,040h,0BEh,0E0h,03Bh,088h,0F2h,058h,067h,080h,006h,0A8h
  80.                      DB 09Ah,08Fh,09Ah,009h,097h,019h,041h,07Fh,016h,062h,001h,069h,0DFh,0C0h,024h,07Bh
  81.                      DB 0E3h,0F5h,016h,03Eh,00Ch,0BAh,026h,092h,0BAh,092h,09Dh,086h,0D4h,0E8h,0A1h,04Bh
  82.                      DB 093h,07Ah,051h,0AEh,04Fh,0D8h,0A1h,008h,049h,06Ah,042h,021h,0DAh,0F7h,076h,06Eh
  83.                      DB 032h,019h,0FFh,09Eh,067h,09Fh,091h,030h,052h,09Ch,000h,0B2h,059h,0E0h,022h,075h
  84.                      DB 09Dh,010h,07Bh,0B0h,069h,0CAh,0F6h,055h,00Bh,0FFh,0EDh,02Dh,0F8h,05Fh,0A1h,00Ah
  85.                      DB 075h,0C5h,012h,082h,0CBh,0AEh,0EBh,093h,0B3h,06Dh,075h,023h,013h,09Bh,08Dh,08Fh
  86.                      DB 0E4h,0C2h,0E1h,081h,078h,009h,06Fh
  87. Encrypt_Table_Length DW ($ - OFFSET Master_Encrypt_Table)
  88.  
  89.  
  90. CRC_Table       DB 000h,000h,000h,000h,096h,030h,007h,077h,02Ch,061h,00Eh,0EEh,0BAh,051h,009h,099h
  91.                 DB 019h,0C4h,06Dh,007h,08Fh,0F4h,06Ah,070h,035h,0A5h,063h,0E9h,0A3h,095h,064h,09Eh
  92.                 DB 032h,088h,0DBh,00Eh,0A4h,0B8h,0DCh,079h,01Eh,0E9h,0D5h,0E0h,088h,0D9h,0D2h,097h
  93.                 DB 02Bh,04Ch,0B6h,009h,0BDh,07Ch,0B1h,07Eh,007h,02Dh,0B8h,0E7h,091h,01Dh,0BFh,090h
  94.                 DB 064h,010h,0B7h,01Dh,0F2h,020h,0B0h,06Ah,048h,071h,0B9h,0F3h,0DEh,041h,0BEh,084h
  95.                 DB 07Dh,0D4h,0DAh,01Ah,0EBh,0E4h,0DDh,06Dh,051h,0B5h,0D4h,0F4h,0C7h,085h,0D3h,083h
  96.                 DB 056h,098h,06Ch,013h,0C0h,0A8h,06Bh,064h,07Ah,0F9h,062h,0FDh,0ECh,0C9h,065h,08Ah
  97.                 DB 04Fh,05Ch,001h,014h,0D9h,06Ch,006h,063h,063h,03Dh,00Fh,0FAh,0F5h,00Dh,008h,08Dh
  98.                 DB 0C8h,020h,06Eh,03Bh,05Eh,010h,069h,04Ch,0E4h,041h,060h,0D5h,072h,071h,067h,0A2h
  99.                 DB 0D1h,0E4h,003h,03Ch,047h,0D4h,004h,04Bh,0FDh,085h,00Dh,0D2h,06Bh,0B5h,00Ah,0A5h
  100.                 DB 0FAh,0A8h,0B5h,035h,06Ch,098h,0B2h,042h,0D6h,0C9h,0BBh,0DBh,040h,0F9h,0BCh,0ACh
  101.                 DB 0E3h,06Ch,0D8h,032h,075h,05Ch,0DFh,045h,0CFh,00Dh,0D6h,0DCh,059h,03Dh,0D1h,0ABh
  102.                 DB 0ACh,030h,0D9h,026h,03Ah,000h,0DEh,051h,080h,051h,0D7h,0C8h,016h,061h,0D0h,0BFh
  103.                 DB 0B5h,0F4h,0B4h,021h,023h,0C4h,0B3h,056h,099h,095h,0BAh,0CFh,00Fh,0A5h,0BDh,0B8h
  104.                 DB 09Eh,0B8h,002h,028h,008h,088h,005h,05Fh,0B2h,0D9h,00Ch,0C6h,024h,0E9h,00Bh,0B1h
  105.                 DB 087h,07Ch,06Fh,02Fh,011h,04Ch,068h,058h,0ABh,01Dh,061h,0C1h,03Dh,02Dh,066h,0B6h
  106.                 DB 090h,041h,0DCh,076h,006h,071h,0DBh,001h,0BCh,020h,0D2h,098h,02Ah,010h,0D5h,0EFh
  107.                 DB 089h,085h,0B1h,071h,01Fh,0B5h,0B6h,006h,0A5h,0E4h,0BFh,09Fh,033h,0D4h,0B8h,0E8h
  108.                 DB 0A2h,0C9h,007h,078h,034h,0F9h,000h,00Fh,08Eh,0A8h,009h,096h,018h,098h,00Eh,0E1h
  109.                 DB 0BBh,00Dh,06Ah,07Fh,02Dh,03Dh,06Dh,008h,097h,06Ch,064h,091h,001h,05Ch,063h,0E6h
  110.                 DB 0F4h,051h,06Bh,06Bh,062h,061h,06Ch,01Ch,0D8h,030h,065h,085h,04Eh,000h,062h,0F2h
  111.                 DB 0EDh,095h,006h,06Ch,07Bh,0A5h,001h,01Bh,0C1h,0F4h,008h,082h,057h,0C4h,00Fh,0F5h
  112.                 DB 0C6h,0D9h,0B0h,065h,050h,0E9h,0B7h,012h,0EAh,0B8h,0BEh,08Bh,07Ch,088h,0B9h,0FCh
  113.                 DB 0DFh,01Dh,0DDh,062h,049h,02Dh,0DAh,015h,0F3h,07Ch,0D3h,08Ch,065h,04Ch,0D4h,0FBh
  114.                 DB 058h,061h,0B2h,04Dh,0CEh,051h,0B5h,03Ah,074h,000h,0BCh,0A3h,0E2h,030h,0BBh,0D4h
  115.                 DB 041h,0A5h,0DFh,04Ah,0D7h,095h,0D8h,03Dh,06Dh,0C4h,0D1h,0A4h,0FBh,0F4h,0D6h,0D3h
  116.                 DB 06Ah,0E9h,069h,043h,0FCh,0D9h,06Eh,034h,046h,088h,067h,0ADh,0D0h,0B8h,060h,0DAh
  117.                 DB 073h,02Dh,004h,044h,0E5h,01Dh,003h,033h,05Fh,04Ch,00Ah,0AAh,0C9h,07Ch,00Dh,0DDh
  118.                 DB 03Ch,071h,005h,050h,0AAh,041h,002h,027h,010h,010h,00Bh,0BEh,086h,020h,00Ch,0C9h
  119.                 DB 025h,0B5h,068h,057h,0B3h,085h,06Fh,020h,009h,0D4h,066h,0B9h,09Fh,0E4h,061h,0CEh
  120.                 DB 00Eh,0F9h,0DEh,05Eh,098h,0C9h,0D9h,029h,022h,098h,0D0h,0B0h,0B4h,0A8h,0D7h,0C7h
  121.                 DB 017h,03Dh,0B3h,059h,081h,00Dh,0B4h,02Eh,03Bh,05Ch,0BDh,0B7h,0ADh,06Ch,0BAh,0C0h
  122.                 DB 020h,083h,0B8h,0EDh,0B6h,0B3h,0BFh,09Ah,00Ch,0E2h,0B6h,003h,09Ah,0D2h,0B1h,074h
  123.                 DB 039h,047h,0D5h,0EAh,0AFh,077h,0D2h,09Dh,015h,026h,0DBh,004h,083h,016h,0DCh,073h
  124.                 DB 012h,00Bh,063h,0E3h,084h,03Bh,064h,094h,03Eh,06Ah,06Dh,00Dh,0A8h,05Ah,06Ah,07Ah
  125.                 DB 00Bh,0CFh,00Eh,0E4h,09Dh,0FFh,009h,093h,027h,0AEh,000h,00Ah,0B1h,09Eh,007h,07Dh
  126.                 DB 044h,093h,00Fh,0F0h,0D2h,0A3h,008h,087h,068h,0F2h,001h,01Eh,0FEh,0C2h,006h,069h
  127.                 DB 05Dh,057h,062h,0F7h,0CBh,067h,065h,080h,071h,036h,06Ch,019h,0E7h,006h,06Bh,06Eh
  128.                 DB 076h,01Bh,0D4h,0FEh,0E0h,02Bh,0D3h,089h,05Ah,07Ah,0DAh,010h,0CCh,04Ah,0DDh,067h
  129.                 DB 06Fh,0DFh,0B9h,0F9h,0F9h,0EFh,0BEh,08Eh,043h,0BEh,0B7h,017h,0D5h,08Eh,0B0h,060h
  130.                 DB 0E8h,0A3h,0D6h,0D6h,07Eh,093h,0D1h,0A1h,0C4h,0C2h,0D8h,038h,052h,0F2h,0DFh,04Fh
  131.                 DB 0F1h,067h,0BBh,0D1h,067h,057h,0BCh,0A6h,0DDh,006h,0B5h,03Fh,04Bh,036h,0B2h,048h
  132.                 DB 0DAh,02Bh,00Dh,0D8h,04Ch,01Bh,00Ah,0AFh,0F6h,04Ah,003h,036h,060h,07Ah,004h,041h
  133.                 DB 0C3h,0EFh,060h,0DFh,055h,0DFh,067h,0A8h,0EFh,08Eh,06Eh,031h,079h,0BEh,069h,046h
  134.                 DB 08Ch,0B3h,061h,0CBh,01Ah,083h,066h,0BCh,0A0h,0D2h,06Fh,025h,036h,0E2h,068h,052h
  135.                 DB 095h,077h,00Ch,0CCh,003h,047h,00Bh,0BBh,0B9h,016h,002h,022h,02Fh,026h,005h,055h
  136.                 DB 0BEh,03Bh,0BAh,0C5h,028h,00Bh,0BDh,0B2h,092h,05Ah,0B4h,02Bh,004h,06Ah,0B3h,05Ch
  137.                 DB 0A7h,0FFh,0D7h,0C2h,031h,0CFh,0D0h,0B5h,08Bh,09Eh,0D9h,02Ch,01Dh,0AEh,0DEh,05Bh
  138.                 DB 0B0h,0C2h,064h,09Bh,026h,0F2h,063h,0ECh,09Ch,0A3h,06Ah,075h,00Ah,093h,06Dh,002h
  139.                 DB 0A9h,006h,009h,09Ch,03Fh,036h,00Eh,0EBh,085h,067h,007h,072h,013h,057h,000h,005h
  140.                 DB 082h,04Ah,0BFh,095h,014h,07Ah,0B8h,0E2h,0AEh,02Bh,0B1h,07Bh,038h,01Bh,0B6h,00Ch
  141.                 DB 09Bh,08Eh,0D2h,092h,00Dh,0BEh,0D5h,0E5h,0B7h,0EFh,0DCh,07Ch,021h,0DFh,0DBh,00Bh
  142.                 DB 0D4h,0D2h,0D3h,086h,042h,0E2h,0D4h,0F1h,0F8h,0B3h,0DDh,068h,06Eh,083h,0DAh,01Fh
  143.                 DB 0CDh,016h,0BEh,081h,05Bh,026h,0B9h,0F6h,0E1h,077h,0B0h,06Fh,077h,047h,0B7h,018h
  144.                 DB 0E6h,05Ah,008h,088h,070h,06Ah,00Fh,0FFh,0CAh,03Bh,006h,066h,05Ch,00Bh,001h,011h
  145.                 DB 0FFh,09Eh,065h,08Fh,069h,0AEh,062h,0F8h,0D3h,0FFh,06Bh,061h,045h,0CFh,06Ch,016h
  146.                 DB 078h,0E2h,00Ah,0A0h,0EEh,0D2h,00Dh,0D7h,054h,083h,004h,04Eh,0C2h,0B3h,003h,039h
  147.                 DB 061h,026h,067h,0A7h,0F7h,016h,060h,0D0h,04Dh,047h,069h,049h,0DBh,077h,06Eh,03Eh
  148.                 DB 04Ah,06Ah,0D1h,0AEh,0DCh,05Ah,0D6h,0D9h,066h,00Bh,0DFh,040h,0F0h,03Bh,0D8h,037h
  149.                 DB 053h,0AEh,0BCh,0A9h,0C5h,09Eh,0BBh,0DEh,07Fh,0CFh,0B2h,047h,0E9h,0FFh,0B5h,030h
  150.                 DB 01Ch,0F2h,0BDh,0BDh,08Ah,0C2h,0BAh,0CAh,030h,093h,0B3h,053h,0A6h,0A3h,0B4h,024h
  151.                 DB 005h,036h,0D0h,0BAh,093h,006h,0D7h,0CDh,029h,057h,0DEh,054h,0BFh,067h,0D9h,023h
  152.                 DB 02Eh,07Ah,066h,0B3h,0B8h,04Ah,061h,0C4h,002h,01Bh,068h,05Dh,094h,02Bh,06Fh,02Ah
  153.                 DB 037h,0BEh,00Bh,0B4h,0A1h,08Eh,00Ch,0C3h,01Bh,0DFh,005h,05Ah,08Dh,0EFh,002h,02Dh
  154.  
  155. ;/--──────══════════════════════════════════════════════════───────---\
  156. ;                           Program Procedures
  157. ;\--──────══════════════════════════════════════════════════───────---/
  158.  
  159. StartUp_Message         PROC
  160.         mov ax,3
  161.         int 10h                         ;Clear Screen
  162.  
  163.         mov ah,9
  164.         lea dx,Logo
  165.         int 21h                         ;Print Logo
  166.        RET
  167. StartUp_Message         ENDP
  168.  
  169. Zero_heap               PROC
  170.         lea DI, Heap_Location
  171.         mov cx,(162h*0Bh)                  ;KeyFile Size..
  172.         xor al,al
  173.         rep
  174.         stosb
  175.        RET
  176. Zero_heap               ENDP
  177.  
  178. GetInStr                PROC            ;Get input string from keyboard.
  179.  
  180.         mov ah,2                        ;Set Cursor position
  181.         mov bh,0
  182.         mov dh, LineNumber              ;Row (0-top)
  183.         mov dl,1                        ;Column (0-left)
  184.         int 10h                    ;We could also write directly to 40h:50h
  185.  
  186.         mov ah,2
  187.         mov dl,''
  188.         int 21h
  189.  
  190.         mov ah,2
  191.         mov bh,0
  192.         mov dh, LineNumber
  193.         mov dl,13
  194.         int 10h
  195.  
  196.         lea DI, (Input_string+1)
  197.         xor al,al
  198.         mov cx,50
  199.         rep
  200.         stosb                           ;Clear Input string
  201.  
  202.         mov ah,0Ah
  203.         lea dx, Input_string
  204.         int 21h
  205.        RET
  206. GetInStr                ENDP
  207.  
  208. Copy_InStr_to_Heap      PROC
  209.         mov bp,sp
  210.         mov ax, word ptr [bp+2]
  211.         lea SI, (Input_string+1)
  212.         lea DI, Heap_Location
  213.         Add di,(162h*3)                 ;Start Address of the 4th block..
  214.         Add di,ax                       ;Offset in 4th block..
  215.         Xor cx,cx
  216.         mov cl,byte ptr [SI]
  217.         inc cl
  218.         rep
  219.          Movsb
  220.        RET
  221. Copy_InStr_to_Heap      ENDP
  222.  
  223.  
  224. Fill_Rest               PROC
  225.         mov bp,sp
  226.         mov ax, word ptr [bp+2]
  227.         lea SI, Fill_String
  228.         lea DI, Heap_Location
  229.         Add DI, ax
  230.         Mov cx, word ptr [bp+4]
  231.  @Fill1:
  232.         Movsb
  233.         Cmp si, (OFFSET FString_tag)
  234.         Jnz @Fill2
  235.         lea SI, Fill_String
  236.  @Fill2:
  237.         Loop @Fill1
  238.        RET
  239. Fill_Rest               ENDP
  240.  
  241.  
  242. CRC_4th_Block           PROC
  243.         Mov word ptr [  CRC  ], -1
  244.         Mov word ptr [ CRC+2 ], -1
  245.         Mov word ptr [Counter2], 5Bh
  246.  
  247.  @CRC_loop:
  248.         Mov bx, word ptr [  CRC  ]
  249.         Mov dx, word ptr [ CRC+2 ]
  250.  
  251.         lea DI, Heap_Location
  252.         Add di, (162h*3)                ;Base Address of the 4th block..
  253.         Add di, word ptr [Counter2]
  254.  
  255.         mov al, byte ptr [di]
  256.         xor bl,al
  257.         xor bh,bh
  258.         Shl bx,1
  259.         Shl bx,1                        ;Shl bx,2 == Mul bx, 4
  260.  
  261.         Add bx, OFFSET CRC_Table
  262.         Mov ax, word ptr [BX]
  263.         Mov cx, word ptr [BX+2]
  264.  
  265.         Mov bx, word ptr [  CRC  ]
  266.         Mov dx, word ptr [ CRC+2 ]
  267.  
  268.         Push cx                         ;save cx
  269.         mov cx,8
  270.  @CRC1:
  271.         Shr DX,1
  272.         Rcr BX,1                        ;Shift right 32bit CRC value..
  273.         Loop @CRC1
  274.         Pop cx
  275.  
  276.         Xor ax, bx
  277.         Xor dx, cx
  278.  
  279.         Mov word ptr [  CRC  ],ax
  280.         Mov word ptr [ CRC+2 ],dx
  281.  
  282.         Inc word ptr [Counter2]
  283.         Cmp word ptr [Counter2], 15Dh
  284.         Jna @CRC_loop
  285.  
  286.         Mov ax, word ptr [  CRC  ]
  287.         Mov dx, word ptr [ CRC+2 ]
  288.  
  289.         lea DI, Heap_Location
  290.         Add di, (162h*4)                ;Base Address of the 5th block..
  291.         Sub di, 4                       ;END of 4th block - CRC location .
  292.  
  293.         Stosw
  294.         mov ax,dx
  295.         Stosw
  296.                                         ;5th block CRC should be
  297.                                         ;4th_block_CRC - 10    OR
  298.                                         ;4th_block_CRC + 10 .
  299.         Mov ax, word ptr [  CRC  ]
  300.         Mov dx, word ptr [ CRC+2 ]
  301.         Add ax, 10
  302.         Adc dx, 0                       ;Add 10 to a 32bit (integer) key ..
  303.  
  304.         lea DI, Heap_Location
  305.         Add di, (162h*5)                ;Base Address of the 6th block..
  306.         Sub di, 4                       ;END of 5th block - CRC location .
  307.  
  308.         Stosw
  309.         mov ax,dx
  310.         Stosw
  311.        RET
  312. CRC_4th_Block           ENDP
  313.  
  314.  
  315. Encrypt_4th_Block       PROC
  316.         lea SI, Master_Encrypt_Table
  317.         lea DI, Heap_Location
  318.         Add di, (162h*3)                ;Base Address of the 4th block..
  319.         Add di, 5Bh                     ;Offset of encrypted DATA
  320.         Mov CX, Encrypt_Table_Length
  321.  
  322.  @Encrypt_Loop:
  323.         Lodsb
  324.         Mov ah, byte ptr [DI]
  325.         XOR al,ah
  326.         Stosb
  327.         Loop @Encrypt_Loop
  328.        RET
  329. Encrypt_4th_Block       ENDP
  330.  
  331.  
  332. CRC_File                PROC
  333.         Mov word ptr [  CRC  ], -1
  334.         Mov word ptr [ CRC+2 ], -1
  335.         Mov word ptr [Counter1], 0
  336.  
  337.  @CRC_loop1:
  338.         Mov word ptr [Counter2], 0
  339.  @CRC_loop2:
  340.         Mov bx, word ptr [  CRC  ]
  341.         Mov dx, word ptr [ CRC+2 ]
  342.  
  343.         lea DI, Heap_Location
  344.         Mov cx, word ptr [Counter1]
  345.         Cmp Cx,0
  346.         Jz @calc_off
  347.  @calc_base:
  348.         Add di, 162h
  349.         Loop @calc_base
  350.  @calc_off:
  351.         Add di, word ptr [Counter2]
  352.  
  353.         mov al, byte ptr [di]
  354.         xor bl,al
  355.         xor bh,bh
  356.         Shl bx,1
  357.         Shl bx,1
  358.  
  359.         Add bx, OFFSET CRC_Table
  360.         Mov ax, word ptr [BX]
  361.         Mov cx, word ptr [BX+2]
  362.  
  363.         Mov bx, word ptr [  CRC  ]
  364.         Mov dx, word ptr [ CRC+2 ]
  365.  
  366.         Push cx
  367.         mov cx,8
  368.  @CRC_:
  369.         Shr DX,1
  370.         Rcr BX,1
  371.         Loop @CRC_
  372.         Pop cx
  373.  
  374.         Xor ax, bx
  375.         Xor dx, cx
  376.  
  377.         Mov word ptr [  CRC  ],ax
  378.         Mov word ptr [ CRC+2 ],dx
  379.  
  380.         Inc word ptr [Counter2]
  381.         Cmp word ptr [Counter2], 15Dh
  382.         Jna @CRC_loop2
  383.  
  384.         Inc word ptr [Counter1]
  385.         Cmp word ptr [Counter1], 0Bh
  386.         Jne @CRC_loop1
  387.  
  388.         Mov ax, word ptr [  CRC  ]
  389.         Mov dx, word ptr [ CRC+2 ]
  390.         lea DI, Heap_Location
  391.         Add di, (162h*0Bh -4)          ;END of 11th block - CRC location .
  392.         Stosw
  393.         mov ax,dx
  394.         Stosw
  395.        RET
  396. CRC_File                ENDP
  397.  
  398.  
  399.  
  400. Copy_Heap_to_File       PROC
  401.     mov ah,3ch                      ;Create kEY FILE
  402.     xor cx,cx
  403.     lea dx,File_Name
  404.     int 21h
  405.         mov bx,ax                       ;File handle in BX
  406.  
  407.         mov ah,40h                      ;Write to file
  408.         mov cx,(162h*0Bh)               ;Number of bytes to write
  409.         lea dx,Heap_Location            ;Address to write from
  410.         int 21h
  411.  
  412.     mov ah,3eh                      ;Close File
  413.     int 21h
  414.        RET
  415. Copy_Heap_to_File       ENDP
  416.  
  417. ;/--──────══════════════════════════════════════════════════───────---\
  418. ;                           Program Main Code
  419. ;\--──────══════════════════════════════════════════════════───────---/
  420.  
  421. Main:   Call StartUp_Message
  422.         Call Zero_heap
  423.  
  424.         Mov byte ptr [LineNumber] ,8
  425.         Call GetInStr                   ;Get Name
  426.         push word ptr 7Ah               ;Name location in the 4th block..
  427.         Call Copy_InStr_to_Heap         ;Copy from buffer to Heap
  428.  
  429.         Inc byte ptr [LineNumber]
  430.         Call GetInStr                   ;Get Address
  431.         push word ptr 0ADh              ;Address location in the 4th block ..
  432.         Call Copy_InStr_to_Heap         ;Copy from buffer to Heap
  433.  
  434.         Inc byte ptr [LineNumber]       ;And so on ..
  435.         Call GetInStr
  436.         push word ptr 0E0h
  437.         Call Copy_InStr_to_Heap
  438.  
  439.         Inc byte ptr [LineNumber]
  440.         Call GetInStr
  441.         push word ptr 113h
  442.         Call Copy_InStr_to_Heap
  443.  
  444.  
  445.         push word ptr (162h*3)
  446.         push word ptr 0
  447.         Call Fill_Rest                  ;fill first 3 blocks
  448.  
  449.         push word ptr (162h*7)
  450.         push word ptr (162h*4)          ;base address of the 5th block
  451.         Call Fill_Rest                  ;fill last 7 blocks
  452.  
  453.         Call CRC_4th_Block              ;Calculate CRC for the 4th block
  454.         Call Encrypt_4th_Block          ;XOR block #4 with Master_Table
  455.         Call CRC_File                   ;Calculate CRC for all 11 blocks
  456.  
  457.         Call Copy_Heap_to_File          ;Write to file
  458.  
  459.         mov ah,9                        ;Print End message
  460.         lea dx, End_message
  461.         Int 21h
  462.  
  463.     mov ax,4c00h                    ;Asta-lavista,baby!
  464.     int 21h
  465.  
  466. ;/--──────══════════════════════════════════════════════════───────---\
  467. ;                                 HEAP
  468. ;\--──────══════════════════════════════════════════════════───────---/
  469. Heap_Location:                    ;End of the COM (the image) , Heap starts
  470.  
  471. Code Ends
  472. End Start
  473.