home *** CD-ROM | disk | FTP | other *** search
- .8086
- .model small
- .stack 200h
- .code
- ResBeg label byte
- BuffPos dw 0
- BuffSize dw 100h
- Old21 dd ?
- status dd ?
- Off db 0
- path db 'C:\HISTORY.DAT',0
- db 112 dup (0)
- functions db 3ch,3dh,41h,4bh,5bh
- IFDEF FIND
- db 4eh
- ENDIF
- NFunc equ $ - functions
- OK db ?
- func_table dw CreateFil ;3ch - create handle
- dw OpenFil ;3dh - open handle
- dw DeleteFil ;41h - delete file
- dw Exec ;4bh - load & execute
- dw CreateNew ;5bh - create New File
- IFDEF FIND
- dw FindFile ;4eh - find file
- ENDIF
- MyPSP dw ?
- ;----------------- Program ---------------------
- IntHandler proc far
- cmp cs:[Off],1
- je Done
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- push es
- push ds
- push bp
- mov bp,sp
- ParDs equ ss: word ptr [bp+ 2]
- ParEs equ ss: word ptr [bp+ 4]
- ParDx equ ss: word ptr [bp+10]
- ParCx equ ss: word ptr [bp+12]
- ParBx equ ss: word ptr [bp+14]
- ParAx equ ss: word ptr [bp+16]
- ParFlg equ ss: word ptr [bp+22]
- cmp ax,0c6c6h
- jne PolCont
- mov ax,ParFlg
- or ax,1
- mov ParFlg,ax
- mov ax,cs
- add sp,18
- iret
- PolCont: mov ax,cs
- mov ds,ax
- mov ax,ParAx
- mov si,0
- next: cmp si,NFunc
- je cont
- cmp ah,functions[si]
- je subr
- inc si
- jmp next
- Subr: shl si,1
- call func_table[si]
- cont: mov sp,bp
- pop bp
- pop ds
- pop es
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- Done: jmp cs:[Old21]
- ;----------------------------------------------------------
- IntHandler ENDP
- ;---------------------------------------------------------
- CreateFil: call cont1
- db 'CreateFile : ',0
- CreateNew: call Cont1
- db 'CreateNew : ',0
- DeleteFil: call cont1
- db 'DeleteFile : ',0
- IFDEF FIND
- FindFile: call cont1
- db 'FindFile : ',0
- ENDIF
- ;---------------------------------------------------------
- OpenFil: mov ax,ParAX
- cmp al,0
- jne OpenFil1
- call cont1
- db 'OpenFile-R : ',0
- OpenFil1: cmp al,1
- jnz OpenFil2
- call cont1
- db 'OpenFile-W : ',0
- OpenFil2: call cont1
- db 'OpenFile-R/W: ',0
- ;---------------------------------------------------------
- Exec: call Exec1
- db 'Exec : ',0
- Exec1: pop si
- ExLop: lodsb
- or al,al
- jz ExCont
- call PutBuff
- jmp ExLop
- ExCont: call PutStr
- mov al,' '
- call PutBuff
- call PutParStr
- call PutCrLf
- call ApendTMP
- retn
- ;---------------------------------------------------------
- Cont1: pop si
- CoLop: lodsb
- or al,al
- jz CoCont
- call PutBuff
- jmp CoLop
- CoCont: call PutStr
- call PutCrLf
- call ApendTMP
- retn
- ;---------------------------------------------------------
- PutParStr: mov es,parES
- mov bx,parBX
- inc bx
- inc bx
- mov si,es:[bx]
- inc bx
- inc bx
- mov ax,es:[bx]
- mov ds,ax
- lodsb
- cmp al,0
- jz ParEnd
- xor ah,ah
- mov cx,ax
- Par1: lodsb
- cmp al,0
- jz ParEnd
- cmp al,0dh
- jz ParEnd
- call PutBuff
- loop Par1
- ParEnd: retn
- ;---------------------------------------------------------
- PutStr: mov ds,parDS
- mov si,parDX
- put1: lodsb
- cmp al,0
- jz StrEnd
- call PutBuff
- jmp Put1
- StrEnd: retn
- ;---------------------------------------------------------
- PutCrLf: mov al,0dh
- call PutBuff
- mov al,0ah
- call PutBuff
- retn
- ;---------------------------------------------------------
- putbuff proc near
- mov bx,cs:[BuffPos]
- inc bx
- cmp bx,cs:[BuffSize]
- je rret
- mov cs:[BuffPos],bx
- add bx,offset ResEnd
- dec bx
- mov cs:[bx],al
- rret: retn
- putbuff endp
- ;-----------------------------------------------------------
- ApendTMP proc near
- call SetCrit
- call DosOK
- jnz stop
- Call OpenFile
- JNB handleOk
- call CreateFile
- Call OpenFile
- jc stop
- handleOk: MOV BX,AX ;store file handle
- MOV AL,02h ;eof move
- MOV CX,0 ;file offset
- MOV DX,0 ;lo(offset)
- MOV AH,42h ;set file pointer
- pushf
- call cs:[Old21]
- WriteTMP: MOV DX,offset ResEnd
- mov ax,cs
- mov ds,ax
- mov cx,buffpos ;number of bytes
- MOV AH,40h ;write to the file
- pushf
- call cs:[Old21]
- MOV AH,3Eh ;close file
- pushf
- call cs:[Old21]
- mov buffpos,0
- stop: call RestoreCrit
- retn
- ApendTMP ENDP
- ;-----------------------------------------------------------
- OpenFile proc near
- PUSH CS
- POP DS
- MOV DX,offset path
- MOV AL,1 ;writing
- MOV AH,3Dh ;open file handle
- pushf
- call cs:[Old21]
- ret
- OpenFile endp
- ;----------------------------------------------------------
- CreateFile proc near
- call DosOK
- jz CreateCnt
- stc
- ret
- CreateCnt: push cs
- pop ds
- MOV DX,offset path
- MOV CX,0 ;file attribute
- MOV AH,5bh ;create new file
- pushf
- call cs:[Old21]
- jnb CreateCnt1
- stc
- ret
- CreateCnt1: MOV BX,AX ;store file handle
- MOV AH,3Eh ;close file handle
- pushf
- call cs:[Old21]
- clc
- ret
- CreateFile endp
- ;-----------------------------------------------------------
- DosOK proc near
- PUSH BX
- PUSH ES
- LES BX,cs:[status]
- CMP BYTE PTR es:[BX],0
- POP ES
- POP BX
- RETN
- DosOK ENDP
- ;----------------------------------------------------------
- SetCrit proc near
- pushf
- push ax
- push dx
- push es
- cli
- mov ax,0
- mov es,ax
- mov ax,Word Ptr es:[24h*4]
- mov Word Ptr cs:[Old24],ax
- mov ax,Word Ptr es:[24h*4+2]
- mov Word Ptr cs:[offset Old24 + 2],ax
- mov ax,cs
- mov Word Ptr es:[24h*4+2],ax
- mov ax,offset New24
- mov Word Ptr es:[24h*4],ax
- mov ax,3300h
- pushf
- call cs:Old21 ;get ctrl-break state
- mov cs:[CtrlC],dl
- sub dl,dl
- mov al,1
- pushf
- call cs:Old21 ;set ctrl-break off
- pop es
- pop dx
- pop ax
- popf
- ret
- SetCrit endp
- ;----------------------------------------------------------
- RestoreCrit proc near
- pushf
- push ax
- push dx
- push es
- cli
- mov ax,0
- mov es,ax
- mov ax,Word Ptr cs:[Old24]
- mov Word Ptr es:[24h*4],ax
- mov ax,Word Ptr cs:[offset Old24 + 2]
- mov Word Ptr es:[24h*4+2],ax
- mov ax,3301h
- mov dl,cs:[CtrlC]
- pushf
- call cs:[Old21]
- pop es
- pop dx
- pop ax
- popf
- ret
- RestoreCrit endp
- ;----------------------------------------------------------
- Old24 dd ?
- CtrlC db ?
- ;----------------------------------------------------------
- New24 proc far ;critical err.
- mov al,3 ;fail
- mov Byte Ptr CS:[Off],1
- iret
- ;----------------------------------------------------------
- New24 endp
- ;----------------------------------------------------------
- ResEnd label byte
- ;----------------------------------------------------------
- prompt db 'Runtime saving of file actions.',13,10
- db 'ver. 1.04',13,10
- db 'Petr Horák, Praha 1992',13,10
- db 'Usage: kgb [file] [/Options] ..',13,10
- db 'Options:',0dh,0ah
- db ' /u unload',0dh,0ah
- db ' /dX drive X (A-Z)',0dh,0ah
- db ' /on (off)',0dh,0ah,'$'
- ;----------------------------------------------------------
- UnloadReq db 0
- Default db 1
- ;----------------------------------------------------------
- ReadCmdLine: mov ax,6200h
- int 21h ;get PSP address
- mov ds,bx
- MOV si,81h
- MOV cl,Byte Ptr ds:[80h]
- xor ch,ch
- ReadLoop: call SkipSpace
- cmp al,'/'
- jnz ReadCont
- call Switch
- jmp ReadLoop
- ReadCont: cmp Byte Ptr cs:[Default],0
- je ReadLoop ;name
- push cx
- dec si
- call NameSet
- inc si
- pop cx
- jmp ReadLoop
- ;----------------------------------------------------------
- SkipSpace: cmp cx,0
- jz CmdEnd
- dec cx
- lodsb ;al <- ds:[si]
- cmp al,'/'
- jz SkipEnd
- cmp al,0dh
- jz CmdEnd
- cmp al,0
- jz CmdEnd
- cmp al,' '
- jnz SkipSpace
- SkipSpace1: cmp cx,0
- jz CmdEnd
- dec cx
- lodsb ;al <- ds:[si]
- cmp al,0dh
- jz CmdEnd
- cmp al,0
- jz CmdEnd
- cmp al,' '
- jz SkipSpace1
- SkipEnd: ret
- ;----------------------------------------------------------
- CmdEnd: pop ax
- ret
- ;----------------------------------------------------------
- Switch: cmp cx,0
- jz CmdEnd
- lodsb
- dec cx
- cmp al,'u'
- jnz Read4
- mov cs:[UnloadReq],1
- jmp CmdEnd
- Read4: cmp al,'d'
- jnz Read5
- cmp cs:[Default],0
- jz Read5
- call DriveSet
- ret
- Read5: cmp al,'o'
- jnz Read6
- call OnOffSet
- Read6: ret
- ;----------------------------------------------------------
- OnOffSet: mov al,ds:[si]
- cmp al,'f'
- jnz R6
- mov Byte Ptr cs:[Off],1
- R6: ret
- ;----------------------------------------------------------
- DriveSet: mov al,ds:[si]
- and al,0dfh
- cmp al,'A'
- jb DriveSetRet
- cmp al,'Z'
- ja DriveSetRet
- mov cs:Path,al
- mov cs:[Default],0
- DriveSetRet: ret
- ;----------------------------------------------------------
- NameSet: push cs
- pop es
- mov di,offset Path
- call FExpand
- mov cs:[Default],0
- NameSetRet: ret
- ;----------------------------------------------------------
- FExpand PROC
- push si ;preserve calling program's register
- push di ;variable, if any
- cld
- xor cx,cx
- push si
- StringCountLoop:
- lodsb ;get the next character
- and al,al
- jz EndStringCount
- cmp al,0dh
- jz EndStringCount
- cmp al,0ah
- jz EndStringCount
- cmp al,' '
- jz EndStringCount
- cmp al,'/'
- jz EndStringCount
- inc cx
- jmp StringCountLoop
- EndStringCount: pop si
- add cx,si
- lodsw
- cmp si,cx
- ja GetDrive
- cmp ah,3Ah
- jne GetDrive
- cmp al,'a'
- jb o33
- cmp al,'z'
- ja o33
- sub al,' '
- jmp o33
- GetDrive: dec si
- dec si
- mov ah,19h ;get drive
- int 21h
- add al,'A'
- mov ah,':'
- o33: stosw
- cmp si,cx
- je GetPath
- cmp byte ptr [si],'\'
- je o65
- GetPath: sub al,40h
- mov dl,al
- mov al,'\'
- stosb
- push si
- push ds
- mov ah,47h
- mov si,di
- push es
- pop ds
- int 21h ;get dir
- pop ds
- pop si
- jb o65
- cmp es:byte ptr [di],00
- je o65
- push cx
- mov cx,0FFFFh
- xor al,al
- repnz scasb
- dec di
- mov al,'\'
- stosb
- pop cx
- o65: sub cx,si
- rep movsb
- xor al,al
- stosb
- o6C: pop di ;restore si, di
- pop si
- push si ;and move back
- push di ;on stack
- mov di,si
- o73: lodsb
- or al,al
- je o89
- cmp al,'\'
- je o89
- cmp al,'a'
- jb o86
- cmp al,'z'
- ja o86
- sub al,20h
- o86: stosb
- jmp o73
- o89: cmp word ptr [di-02],2E5Ch ;'.\'
- jne o94
- dec di
- dec di
- jmp oB0
- o94: cmp word ptr [di-02],2E2Eh ;'..'
- jne oB0
- cmp byte ptr [di-03],'\'
- jne oB0
- sub di,3
- cmp byte ptr [di-01],':'
- je oB0
- oAA: dec di
- cmp byte ptr [di],'\'
- jne oAA
- oB0: or al,al
- jne o86
- cmp byte ptr [di-01],':'
- jne oBD
- mov al,'\'
- stosb
- oBD:; mov ax,di
- xor al,al
- stosb
- pop di ;restore calling si, di
- pop si
- ret
- FExpand ENDP
- ;----------------------------------------------------------
- Start PROC
- Call ReadCmdLine
- MOV AH,34h ;dos reentrancy status adress
- INT 21h
- MOV word ptr cs:[status+2],ES
- MOV word ptr cs:[status],BX
- mov dx,offset prompt
- call DisplayString
- call FindSec
- InstCont: mov ax,3521h
- int 21h
- mov word ptr cs:Old21,bx
- mov word ptr cs:Old21[2],es
- mov ax,2521h
- push cs
- pop ds
- mov dx,offset IntHandler
- int 21h
- Residence: mov ah,62h ;get PSP
- int 21h
- mov cs:[MyPSP],bx
- mov ds,bx
- mov ah,49h ;free alocated mem bl
- mov es,ds:[2ch] ;addr. dos enviroment
- int 21h ;free dos enviroment
- mov dx,ResEnd-ResBeg+100h
- add dx,cs:[BuffSize]
- mov cl,4
- shr dx,cl
- inc dx
- mov ax,3100h
- int 21h
- Start ENDP
- ;-----------------------------------------------------------
- KantUnload db 'Second Call, can''t uninstall.',13,10,'$'
- Unloadet db 'Second Call, uninstaled.',13,10,'$'
- MadeChanges db 'Second Call, made changes.',13,10,'$'
- FindSec proc near
- clc
- mov ax,0c6c6h
- int 21h
- jnb FindSec1
- cmp cs:[UnloadReq],1
- je Unload
- mov cx,1
- cmp cs:[Default],1
- je o8
- mov cx,129 ;délka path+off
- o8: push cs
- pop ds
- mov es,ax ;resident cs
- mov si,offset Off
- mov di,si
- repnz movsb
- mov dx,offset MadeChanges
- jmp SecDone
- Unload: push ax
- mov ax,3521h
- int 21h
- pop ax
- mov cx,es
- cmp ax,cx
- jne o3
- cmp bx,offset IntHandler
- jne o3
- mov ax,2521h
- lds dx,es:[Old21]
- int 21h
- mov ax,es:[MyPSP]
- mov es,ax
- mov ah,49h ;free mem. bl.
- int 21h
- jc o3
- mov dx,offset Unloadet
- jmp SecDone
- o3 : mov dx,offset KantUnload
- SecDone: call DisplayString
- mov ax,4c00h ;exit while found
- int 21h
- FindSec1: retn
- FindSec endp
- ;----------------------------------------------------------
- DisplayString: mov ax,cs
- mov ds,ax
- mov ah,9 ;display message
- int 21h
- ret
- ;----------------------------------------------------------
- END Start
- ;----------------------------------------------------------