home *** CD-ROM | disk | FTP | other *** search
- ;**
- ;*
- ;* Name: kill.asm
- ;* Version: 1.1
- ;* Description: delete files anywhere on hard disk
- ;* Author: Paul Roub
- ;*
- ;* the commmand line syntax is: KILL <mask>, where mask is any valid
- ;* DOS filename, wildcards included (paths are allowed, but silly:
- ;* the results = DEL <mask>).
- ;*
- ;* note: KILL *.* is not allowed
- ;* only directories without extensions are searched, for speed
- ;* purposes - change 'stardot' if this is unsatisfactory
- ;* output is through video BIOS - again, for speed
- ;*
- ;* remember to use EXE2BIN, or better yet, EXE2COM
- ;*
- ;**
-
-
- cseg segment
- assume CS:cseg, DS:cseg, ES:cseg, SS:cseg
-
- ORG 80h
- ParamLen LABEL BYTE ; address of command-line length byte
-
- ORG 100h
- start: JMP kill
-
-
- ;**;
- ;**
- ;*
- ;* data area
- ;*
- ;**
- victim db 80 DUP (0) ; our target
-
- starstar db "*.*",0 ; for command-line comparison
- stardot db "*.",0 ; for directory searches
- dotdot db "..",0 ; for dropping back one directory
-
- LevelsIn db 0 ; subdirectory nesting level
- OldDTAofs dw 1 ; old DTA offset
-
- DTAofs dw stacktop + 1 ; offset of current DTA
-
- space db ' ' ; leading space for listing files
- drive db ' :' ; drive of killed file
- slash db '\'
- CurDir db 66 dup (0)
- tslash db '\', 0
- OldDirSl db '\'
- OldDir db 66 dup (0)
-
-
- MemErrMsg db 'KILL: Insufficient memory',13,10,0
- SuicideMsg db '"KILL *.*" not allowed',13,10,0
- BadParam db 'Syntax: KILL mask'
- crlf db 13,10,0
-
-
- ;**;
- ;**
- ;*
- ;* main routine
- ;*
- ;**
- kill proc near
- mov sp,offset stacktop ; adjust our memory allocation
- mov bx,offset progend
- mov cl,4
- shr bx,cl
- mov ah,4Ah
- int 21h
- jnb GotMem
-
- mov si,offset MemErrMsg ; if carry set, not enough mem.
- ErrExit: call WriteStr ; display error message
- mov ax,4C01h ; and quit with error code 1
- int 21h
-
- GotMem: mov cl,[ParamLen] ; get command line len
- or cl,cl
- jnz FindStart ; not zero, go on
-
- ParamErr: mov si,offset BadParam ; zero, so point to usage msg
- jmp ErrExit ; and quit
-
- FindStart: mov si,0082h ; start of usable cmd line
- cld
- NextFS: lodsb ; look for first non-space char
- cmp al,13 ; if it's CR, forget it
- jz ParamErr
-
- cmp al,20h
- jz NextFS ; if space, try again
-
- dec si
- push si
- FindEnd: lodsb ; now look for last char
- cmp al,20h
- jz GotParam
-
- cmp al,13
- jnz FindEnd
-
- GotParam: pop di ; ofs. of start
- xchg si,di
- dec di ; ofs of end
- sub di,si ; get length
- mov cx,di ; into CX
- mov di,offset victim
- cld
- repz movsb ; store it in 'victim'
- mov [di],cl ; cl is zero, why not use it?
- mov cl,4
- mov di,offset victim
- mov si,offset starstar ; compare to *.*
- repz cmpsb
- jcxz NoWay ; if it's equal, quit
-
- jmp ParamSafe
-
- NoWay: mov si,offset SuicideMsg ; explain quitting...
- jmp ErrExit
-
- ParamSafe: mov si,offset OldDir ; save starting dir
- mov ah,47h
- xor dl,dl
- int 21h
- mov dx,offset slash ; change to root
- call ChDir
-
- mov ah,2Fh ; save old DTA address
- int 21h
- mov OldDTAofs,bx
- call SetDta ; set DTA to current DTAofs
-
- FindFirstDir: mov dx,offset stardot ; look for subdirs
- mov cx,0030h
- mov ah,4Eh ; find first
- jmp FindFND
-
- FindNextDir: mov ah,4Fh ; find next
- FindFND: int 21h
- jb FindFirstFile ; no more dirs if carry set
-
- mov bx,DTAofs
- mov al,[bx + 21] ; attribute
- and al,10h ; is it a subdir?
- jz FindNextDir ; no, look for more
-
- cmp Byte Ptr [bx+30],'.' ; is it '.' or '..'
- jnz FoundDir ; no, so process it
-
- jmp FindNextDir ; yes, so try again
-
- FoundDir: mov dx,DTAofs ; point to dir name
- add dx,30
- call ChDir
-
- add DTAofs,43 ; move up one DTA level
- call SetDta
-
- inc LevelsIn ; one dir deeper
- jmp FindFirstDir ; look for MORE dirs
-
- FindFirstFile: mov ah,4Eh ; now we look for files
- mov dx,offset victim
- xor cx,cx
- FindFNF: int 21h
- jb CheckLevel ; if none, time to drop back
-
- mov si,offset CurDir ; get current dir name
- xor dl,dl
- mov ah,47h
- int 21h
-
- mov ah,19h ; get drive letter
- int 21h
-
- add al,41h
- mov drive,al
- mov si,offset space
- call WriteStr ; display the drive
-
- cmp CurDir, 0
- jz WriteFilName
-
- mov si,offset tslash ; write slash
- call WriteStr
-
- WriteFilName: mov si,DTAofs
- add si,30
- call WriteStr ; write file name
-
- mov si,offset crlf ; and CR
- call WriteStr
-
- mov dx,DTAofs ; finally, delete the bugger
- add dx,30
- mov ah,41h
- int 21h
- mov ah,4Fh ; and look for more matches
- jmp FindFNF
-
- CheckLevel: cmp LevelsIn,0 ; any more dirs to drop back?
- jz quit ; no, quit
-
- mov dx,offset dotdot ; yes, so CD ..
- call ChDir
-
- sub DTAofs,43 ; decrement DTA pointer to prev
- call SetDta
-
- dec LevelsIn
- jmp FindNextDir ; look for more directories
-
- quit: mov dx,OldDTAofs ; restore original DTA
- mov DTAofs,dx
- call SetDta
-
- mov dx,offset OldDirSl ; change to original dir
- call ChDir
- mov ax,4C00h ; exit with error code 0
- int 21h
- kill endp
-
-
- ;**;
- ;**
- ;*
- ;* SetDta
- ;*
- ;* sets DTA address to offset specified in 'DTAofs'
- ;*
- ;**
- SetDta proc near
- mov dx,DTAofs
- mov ah,1Ah
- int 21h
- ret
- SetDta endp
-
-
- ;**;
- ;**
- ;*
- ;* WriteStr
- ;*
- ;* uses BIOS calls to display (zero-terminated) string pointed to by
- ;* DS:SI
- ;*
- ;**
- WriteStr proc near
- mov ah,0Eh
- NextWS: lodsb
- or al,al
- jz exitWS
-
- int 10h
- jmp NextWS
-
- exitWS: ret
- WriteStr endp
-
-
- ;**;
- ;**
- ;*
- ;* ChDir
- ;*
- ;* changes to dir pointed to by DS:DX
- ;*
- ;**
- ChDir proc near
- mov ah,3Bh
- int 21h
- ret
- ChDir endp
-
-
- ;**;
- ;**
- ;*
- ;* equates for DTA storage and stuff - some of it stolen directly
- ;* from charles petzold
- ;*
- ;**
- stackbottom LABEL BYTE
- stacktop EQU stackbottom + 100h
- progend EQU stacktop + 43 * 32 + 1
-
- cseg ends
- end start
-
-